|
1 // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // This module contains the code for the dummy PPP Nif class which communicates with the upper PPP Nif |
|
15 // via PPP "proxy" |
|
16 // |
|
17 // |
|
18 |
|
19 #include <comms-infras/nifif.h> |
|
20 #include <nifvar.h> |
|
21 #include <nifutl.h> |
|
22 #include <es_mbuf.h> |
|
23 #include <comms-infras/commsdebugutility.h> |
|
24 #include <connectprog.h> |
|
25 #include <in_chk.h> |
|
26 #include <commsdattypeinfov1_1.h> |
|
27 |
|
28 //New ppp progress states file |
|
29 #include "PppProg.h" |
|
30 |
|
31 #include "dummypppnif.h" |
|
32 #include "DummyPPPNifVar.h" |
|
33 |
|
34 |
|
35 const TInt KLoWatMark = 2; |
|
36 const TInt KHiWatMark = 6; |
|
37 |
|
38 |
|
39 // Internal flag bits used |
|
40 const TUint KDummyPPPSendBusy = 0x00001000; |
|
41 const TUint KDummyPPPApplyPending = 0x00010000; |
|
42 |
|
43 //only for generating the logs |
|
44 _LIT(KCodeTextString," %s [0x%02x]"); |
|
45 _LIT(KCodeTextWithoutSpacesString," %s [0x%02x]"); |
|
46 _LIT(KIdentifierLengthString," Id = 0x%02x, Len = %d"); |
|
47 _LIT(KLengthString," Length = %d"); |
|
48 _LIT(KLengthString2," Length = 0x%02x"); |
|
49 _LIT(KTCPLengthString," Length = %d, Hdr len = %d"); |
|
50 _LIT(KUDPLengthPortString," Length = %d, Src port = %d, Dst port = %d"); |
|
51 _LIT(KBytesRemainingString," %d byte%s remaining"); |
|
52 _LIT(KLcpCodeString," Code = %s [0x%02x]"); |
|
53 _LIT(KCodeString," Code = 0x%02x"); |
|
54 _LIT(KCodeString2," Code = 0x%04x"); |
|
55 _LIT(KProtocolString," Protocol = 0x%04x"); |
|
56 _LIT(KNumberString," Number = 0x%08x"); |
|
57 _LIT(KSecondsString," Seconds = %d"); |
|
58 _LIT(KSizeString," Size = %d"); |
|
59 _LIT(KMapString," Map = 0x%08x"); |
|
60 _LIT(KProtocolTextString," Protocol = %s [0x%04x]"); |
|
61 _LIT(KLcpOptFcsTypeString," Types =%s%s%s"); |
|
62 _LIT(KMaximumBytesString," Maximum bytes = %d"); |
|
63 _LIT(KUserNameString," Username = \"%S\""); |
|
64 _LIT(KPasswordString," Password = \"%S\""); |
|
65 _LIT(KMessageString," Message = \"%S\""); |
|
66 _LIT(KDelayString," Delay=%d\n"); |
|
67 _LIT(KNameString," Name = \"%S\""); |
|
68 _LIT(KChangeMaskString," Change Mask = 0x%x: "); |
|
69 _LIT(KChecksumString," Checksum = 0x%x"); |
|
70 _LIT(KChecksumString3," Chksum = 0x%04x (0x%04x) !!!"); |
|
71 _LIT(KConnectionString," Connection = 0x%x"); |
|
72 _LIT(KHdrLengthString," Length = %d, Hdr len = %d"); |
|
73 _LIT(KIDFragmentString," Id = 0x%04x, Fragment = %d %s%s%s"); |
|
74 _LIT(KSrcDstAddrString," Src = %d.%d.%d.%d, Dst = %d.%d.%d.%d"); |
|
75 _LIT(KIpv6SrcAddress," Src = %x:%x:%x:%x:%x:%x:%x:%x"); |
|
76 _LIT(KIpv6DstAddress," Dst = %x:%x:%x:%x:%x:%x:%x:%x"); |
|
77 _LIT(KIpv6Class," Class = %d"); |
|
78 _LIT(KIpv6FlowLabel," FlowLabel = %d"); |
|
79 _LIT(KIpv6PayloadLen," Payload = %d words"); |
|
80 _LIT(KIpv6NextHeadType," Next Header type is [%d]"); |
|
81 _LIT(KIpv6HopLimit," Hop Limit is %d"); |
|
82 _LIT(KIpv6UnknownHeadType," Unknown next header: [%d]"); |
|
83 _LIT(KConnectionNoString," Connection number [0x%02x]"); |
|
84 _LIT(KRemoteAddrString," Remote Address = %d.%d.%d.%d"); |
|
85 _LIT(KOurAddrString," Our Address = %d.%d.%d.%d"); |
|
86 _LIT(KMaxSlotString," Max Slot Id = %d"); |
|
87 _LIT(KCompSlotString," Comp Slot Id = %d"); |
|
88 _LIT(KAddrString," Address = %d.%d.%d.%d"); |
|
89 _LIT(KPortString," Src port = %d, Dst port = %d"); |
|
90 _LIT(KWindowUrgentString," Window = %d, Urgent = %d"); |
|
91 _LIT(KSeqAckString," Seq = 0x%08x, Ack = 0x%08x"); |
|
92 _LIT(KFlagsString," Flags = %s%s%s%s%s%s"); |
|
93 |
|
94 #define EIGHT_SPACE_MARGIN _S(" ") |
|
95 #define FOURTEEN_SPACE_MARGIN _S(" ") |
|
96 |
|
97 /* |
|
98 * This sections defines a whole load of constants etc... not very exciting |
|
99 */ |
|
100 #ifdef __FLOG_ACTIVE |
|
101 _LIT8(KDummyPppLogFolder ,"dummypppnif"); |
|
102 _LIT8(KDummyPppLogFile, "dummypppnif.txt"); |
|
103 #endif // #ifdef __FLOG_ACTIVE |
|
104 |
|
105 _LIT(KEndOfLine, "\n"); |
|
106 |
|
107 /* |
|
108 * The Link class |
|
109 */ |
|
110 |
|
111 CDummyPPPLink::CDummyPPPLink(CNifIfFactory& aFactory) |
|
112 : CNifIfLink(aFactory) |
|
113 { |
|
114 CDummyNifLog::Printf(_L("Dummy PPP Link Created\r\n")); |
|
115 } |
|
116 |
|
117 CDummyPPPLink::~CDummyPPPLink() |
|
118 { |
|
119 CDummyNifLog::Printf(_L("Dummy PPP Link Destroyed\r\n")); |
|
120 TimerDelete(); |
|
121 iNifIf->End(); |
|
122 iNifIf->CloseLog(); |
|
123 } |
|
124 |
|
125 void CDummyPPPLink::OpenL() |
|
126 // |
|
127 // Start connect establishment |
|
128 // |
|
129 { |
|
130 switch (iState) |
|
131 { |
|
132 case EDummyPPPLinkConnecting: |
|
133 case EDummyPPPLinkOpen: |
|
134 return; |
|
135 case EDummyPPPLinkClosed: |
|
136 iState = EDummyPPPLinkConnecting; |
|
137 break; |
|
138 default: |
|
139 return; |
|
140 } |
|
141 CDummyNifLog::Printf(_L("Dummy PPP LinkOpen\r\n")); |
|
142 } |
|
143 |
|
144 void CDummyPPPLink::LinkDown(TInt /*aStatus*/) |
|
145 // |
|
146 // Link down - drop out of packet mode |
|
147 // and notify reason |
|
148 // |
|
149 { |
|
150 CDummyNifLog::Printf(_L("Dummy PPP LinkDown\r\n")); |
|
151 iState = EDummyPPPLinkClosed; |
|
152 } |
|
153 |
|
154 TInt CDummyPPPLink::Send(RMBufChain& aPdu, TAny* aSource) |
|
155 { |
|
156 CDummyNifLog::Printf(_L("Dummy PPP LinkSend\r\n")); |
|
157 |
|
158 return iNifIf->Send(aPdu, aSource); |
|
159 } |
|
160 TInt CDummyPPPIf::Send(RMBufChain& aPacket, TAny* ) |
|
161 { |
|
162 |
|
163 //To send over serial port to NTRAS |
|
164 //return Send(aPacket, iDummyPPPId); |
|
165 |
|
166 CDummyNifLog::Write(_L("DummyPPP::RecvdfromPPP\n")); |
|
167 CDummyNifLog::Printf(_L("Dummy PPP Send\r\n")); |
|
168 logUser->Dump(aPacket, KDummyPPPRecvChannel); |
|
169 |
|
170 //Added to send to PPP interface directly |
|
171 if(!ProcessPPPPacket(aPacket)) |
|
172 { |
|
173 if(SwitchIPHeaders(*ptrTransPktPPP)) |
|
174 { |
|
175 SendtoPPP(*ptrTransPktPPP); |
|
176 } |
|
177 |
|
178 } |
|
179 return iSendFlowOn; |
|
180 } |
|
181 |
|
182 TInt CDummyPPPIf::SwitchIPHeaders(RMBufChain& aPacket) |
|
183 { |
|
184 CDummyNifLog::Printf(_L("DummyPPP::SwitchIPHeaders\r\n")); |
|
185 TInt iResult = 0; |
|
186 // this received data has already been looped back... |
|
187 // get the ip header from the RMBufChain |
|
188 TInet6HeaderIP4* ip4 = (TInet6HeaderIP4*) aPacket.First()->Next()->Ptr(); |
|
189 // get the udp header as well - assume only udp traffic here |
|
190 TInet6HeaderUDP* udp = (TInet6HeaderUDP*) ip4->EndPtr(); |
|
191 |
|
192 TUint dstPort = udp->DstPort(); |
|
193 if(KDummyPppNifCmdPort == dstPort) |
|
194 { |
|
195 // let's use the first payload byte as the command byte |
|
196 if(*(udp->EndPtr())== KForceDisconnect) |
|
197 { |
|
198 CDummyNifLog::Printf(_L("DummyPPP::Sending LinkLayerDown signal\r\n")); |
|
199 // do some action |
|
200 iNotify->IfProgress(KLinkLayerClosed, KErrCommsLineFail); |
|
201 iNotify->LinkLayerDown(KErrCommsLineFail, MNifIfNotify::EDisconnect); |
|
202 } |
|
203 } |
|
204 else |
|
205 { |
|
206 |
|
207 // update the headers (addresses, checksums etc) to UpdateHeaders(ip4, udp); |
|
208 // swap over the destination and source addresses |
|
209 TUint32 tempSrc,tempDest; |
|
210 tempSrc = ip4->SrcAddr(); |
|
211 tempDest = ip4->DstAddr(); |
|
212 |
|
213 ip4->SetSrcAddr(tempDest); |
|
214 ip4->SetDstAddr(tempSrc); |
|
215 |
|
216 TUint tempChksum; |
|
217 tempChksum = ip4->Checksum(); |
|
218 // we've changed the ip hdr so need to recalculate the ip hdr checksum |
|
219 ip4->SetChecksum(0); |
|
220 tempChksum = TChecksum::Calculate((TUint16*)ip4, ip4->HeaderLength()); |
|
221 tempChksum = TChecksum::ComplementedFold(tempChksum); |
|
222 ip4->SetChecksum(tempChksum); |
|
223 //ip4->SetChecksum(TChecksum::ComplementedFold(TChecksum::Calculate((TUint16*)ip4, ip4->HeaderLength()))); |
|
224 |
|
225 // also want to set the udp checksum to zero cos it will be wrong now that we have |
|
226 // changed the ip hdr - just set to zero and it is ignored |
|
227 udp->SetChecksum(0); |
|
228 iResult = 1; |
|
229 } |
|
230 return iResult; |
|
231 } |
|
232 void CDummyPPPIf::SendtoPPP(RMBufChain& aPacket) |
|
233 { |
|
234 CDummyNifLog::Printf(_L("Dummy PPP SendtoPPP\r\n")); |
|
235 iSendNumBufs += aPacket.NumBufs(); |
|
236 iLink->iSendQ.Append(aPacket); |
|
237 |
|
238 switch (iLink->iState) |
|
239 { |
|
240 case EDummyPPPLinkConnecting: |
|
241 aPacket.Free(); |
|
242 break; |
|
243 case EDummyPPPLinkOpen: |
|
244 if (iSendFlowOn && iSendNumBufs>=iSendHiWat) |
|
245 { |
|
246 iSendFlowOn = EFalse; |
|
247 CDummyNifLog::Printf(_L("DummyPPP::SendtoPPP() Flow off, iSendNumBufs %d"), iSendNumBufs); |
|
248 } |
|
249 else if (!(iFlags & KDummyPPPSendBusy)) |
|
250 DoSendtoPPP(); |
|
251 break; |
|
252 case EDummyPPPLinkClosed: |
|
253 { |
|
254 TRAPD(err, iLink->OpenL()); |
|
255 aPacket.Free(); |
|
256 } |
|
257 break; |
|
258 default: |
|
259 aPacket.Free(); |
|
260 break; |
|
261 } |
|
262 |
|
263 iSendCallBack->CallBack(); |
|
264 } |
|
265 |
|
266 TInt CDummyPPPIf::SendCallBack(TAny* aCProtocol) |
|
267 { |
|
268 ((CDummyPPPIf*)aCProtocol)->DoSendtoPPP(); |
|
269 return 0; |
|
270 } |
|
271 void CDummyPPPIf::DoSendtoPPP() |
|
272 { |
|
273 if (iFlags & KDummyPPPSendBusy) |
|
274 return; |
|
275 |
|
276 if (ipktRecvPPP.IsEmpty()) |
|
277 { |
|
278 RMBufPacket pkt; |
|
279 if (!iLink->iSendQ.Remove(pkt)) |
|
280 { |
|
281 iSendNumBufs=0; // Must be so |
|
282 return; |
|
283 } |
|
284 |
|
285 CDummyNifLog::Write(_L("DummyPPP::DoSendtoPPP()\n")); |
|
286 logUser->Dump(pkt, KDummyPPPSendChannel); |
|
287 |
|
288 // Get next packet from send queue |
|
289 do |
|
290 { |
|
291 iFlags |= KDummyPPPSendBusy; |
|
292 iSendNumBufs -= pkt.NumBufs(); |
|
293 iProtocol->Process(pkt, (CProtocolBase*)this); |
|
294 |
|
295 // the following Free() may not actually do anything if the packet has already been freed. |
|
296 pkt.Free(); |
|
297 |
|
298 if (!iSendFlowOn && iSendNumBufs<iSendLoWat) |
|
299 { |
|
300 CDummyNifLog::Printf(_L("DummyPPP::DoSendtoPPP(): Flow on, iSendNumBufs %d"), iSendNumBufs); |
|
301 iSendFlowOn = ETrue; |
|
302 //for CppLcp's LinkFlowOn() |
|
303 iProtocol->StartSending(iProtocol); |
|
304 } |
|
305 } while (iLink->iSendQ.Remove(pkt)); |
|
306 iFlags &= ~KDummyPPPSendBusy; |
|
307 } |
|
308 } |
|
309 |
|
310 TInt CDummyPPPIf::ProcessPPPPacket(RMBufChain& aPacket) |
|
311 /** |
|
312 * Processes all packets received from PPP |
|
313 * |
|
314 * @param RMBufChain& aPacket |
|
315 * @returns nonzero if completed task |
|
316 * @returns 0 if need to send it to PPP |
|
317 */ |
|
318 { |
|
319 // Check if Handle ConfigRequest, ConfigAck, ConfigNak |
|
320 //not responding to ConfigReject |
|
321 CDummyNifLog::Printf(_L("Dummy PPP ProcessPPPPacket\r\n")); |
|
322 TUint result = 0; |
|
323 |
|
324 result = DecodePacket(aPacket); |
|
325 if(result == 1) |
|
326 { if(iCodeRec == KPppLcpConfigReject) |
|
327 { |
|
328 //Panic as DpppLink does not respond to protocol reject |
|
329 } |
|
330 else |
|
331 { |
|
332 if(((iCodeRec == KPppLcpConfigAck) |
|
333 ||(iCodeRec == KPppLcpConfigNak) |
|
334 ||(iCodeRec == KPppLcpConfigRequest)) |
|
335 &&(iDummyPPPState<EDummyPPPFsmOpened)) |
|
336 { |
|
337 ProcessConfig(); |
|
338 } |
|
339 else |
|
340 { |
|
341 ProcessPAPandIPCP(); |
|
342 } |
|
343 } |
|
344 ipktRecvPPP.Free(); |
|
345 } |
|
346 if(result == 0) |
|
347 { |
|
348 //Added to initialize the SendPPP index |
|
349 ipktRecvPPP.Pack(); |
|
350 ptrTransPktPPP = &ipktRecvPPP; |
|
351 SetupSendPPP(); |
|
352 } |
|
353 return result; |
|
354 } |
|
355 |
|
356 TInt CDummyPPPIf::DecodePacket(RMBufChain& aPacket) |
|
357 /** |
|
358 * Decodes RMBufChain received from PPP |
|
359 * |
|
360 * @param RMBufChain& aPacket |
|
361 * @returns 1 if need processing further |
|
362 * @returns 0 if need to send it to PPP |
|
363 * @returns 2 if packet is discarded |
|
364 */ |
|
365 { |
|
366 TInt result = 0; |
|
367 |
|
368 // N.B. ipktRecvPPP must be freed at the end of the previous receive / send sequence. |
|
369 // Freeing it here merely covers for a defect where it is not freed as expected. |
|
370 // Doubly freeing RMBufChain does not result in error. |
|
371 ipktRecvPPP.Free(); |
|
372 |
|
373 // If ipktRecvPPP not Freed, Assign Panics. |
|
374 ipktRecvPPP.Assign(aPacket); |
|
375 ipktRecvPPP.Unpack(); |
|
376 RMBufPktInfo* info = ipktRecvPPP.Info(); |
|
377 |
|
378 CDummyNifLog::Printf(_L("Dummy PPP DecodePacket\r\n")); |
|
379 // Extract and drop LCP header |
|
380 ipktRecvPPP.Align(4); |
|
381 TUint8* ptr = ipktRecvPPP.First()->Ptr(); |
|
382 iCodeRec = *ptr++; |
|
383 iIdRec = *ptr++; |
|
384 iLenRec = BigEndian::Get16(ptr); |
|
385 |
|
386 // Check packet length is OK |
|
387 if (info->iLength<iLenRec || info->iLength<4 || info->iLength!=iLenRec) |
|
388 { |
|
389 // Too short! |
|
390 ipktRecvPPP.Free(); |
|
391 return result; |
|
392 } |
|
393 else |
|
394 { |
|
395 if (info->iLength>iLenRec) |
|
396 ipktRecvPPP.TrimEnd(iLenRec); |
|
397 } |
|
398 |
|
399 if(iCodeRec == KPppLcpConfigReject) |
|
400 { |
|
401 //not responding to protocol reject |
|
402 return result; |
|
403 } |
|
404 |
|
405 // If op is unknown |
|
406 switch (iCodeRec) |
|
407 { |
|
408 case KPppLcpConfigAck: |
|
409 case KPppLcpConfigNak: |
|
410 // Filter out bad acks |
|
411 if (iDummyPPPState>=EDummyPPPFsmReqSent && iIdRec!=iDummyPPPRequestId) |
|
412 break; |
|
413 else |
|
414 iDummyPPPRequestId |= KPppRequestIdAnswered; |
|
415 // fall through ... |
|
416 case KPppLcpConfigRequest: |
|
417 // Option negotiation ops |
|
418 // Split the MBuf chain in separate options |
|
419 |
|
420 //if(len<=4) |
|
421 if(iLenRec<4) |
|
422 break; |
|
423 |
|
424 // |
|
425 // Hmmm sometimes we receive a Config request of Length 4 |
|
426 // i.e. no options Send a Config ACK |
|
427 // |
|
428 if ( (iLenRec == 4) && (iCodeRec == KPppLcpConfigRequest)) |
|
429 { |
|
430 result = 1; |
|
431 break; |
|
432 } |
|
433 if (iLenRec == 4) |
|
434 { |
|
435 break; |
|
436 } |
|
437 else |
|
438 { |
|
439 ipktRecvPPP.TrimStart(4); |
|
440 //ProcessConfig(op, id, len-4, pkt); |
|
441 result = 1; |
|
442 break; |
|
443 } |
|
444 case KPppLcpTerminateAck: |
|
445 //To be opened only in case if Dummy PPPNif sends Terminate Request so blocked |
|
446 |
|
447 // Filter out bad acks |
|
448 //if ((iDummyPPPState==EPppFsmClosing || iDummyPPPState==EPppFsmStopping) && id!=iTerminateId) |
|
449 // break; |
|
450 //else |
|
451 // iTerminateId |= KPppRequestIdAnswered; |
|
452 // fall through ... |
|
453 case KPppLcpTerminateRequest: |
|
454 if(iLenRec<4) |
|
455 break; |
|
456 |
|
457 ipktRecvPPP.TrimStart(4); |
|
458 ProcessTerminate(); |
|
459 result = 2; |
|
460 break; |
|
461 |
|
462 default: |
|
463 break; |
|
464 } |
|
465 //pkt.Free(); |
|
466 if(iDummyPPPState==EDummyPPPFsmIPOpen) |
|
467 result = 0; |
|
468 return result; |
|
469 |
|
470 } |
|
471 |
|
472 void CDummyPPPIf::ProcessConfig() |
|
473 { |
|
474 |
|
475 // Split the recvd packet into separate options |
|
476 // placing each option in a queue where it can be |
|
477 // easily parsed and manipulated in the upcall handlers. |
|
478 RPppOptionList rcvlist; // Recvd list of options |
|
479 |
|
480 |
|
481 RPppOptionList acklist; // List of Ack'd options - only valid of the following are empty |
|
482 RPppOptionList naklist; // List of Nak'd options - only valid of the following is empty |
|
483 RPppOptionList rejlist; // List of Rejected options |
|
484 |
|
485 CDummyNifLog::Printf(_L("Dummy PPP ProcessConfig\r\n")); |
|
486 |
|
487 enum TDummyPPPResult { ENop, EAck, ENak, ERej }; |
|
488 |
|
489 TDummyPPPResult reply = ENop; |
|
490 |
|
491 TRAPD(err, rcvlist.SetL(ipktRecvPPP)); |
|
492 if (err!=KErrNone) |
|
493 return; |
|
494 |
|
495 if (iCodeRec == KPppLcpConfigRequest) |
|
496 { |
|
497 // About to drop out of opened state to need to reset things |
|
498 // BEFORE the new request is processed. |
|
499 if (iDummyPPPState == EDummyPPPFsmOpened) |
|
500 { |
|
501 TRAPD(err, InitialiseConfigRequestL()); |
|
502 if (err != KErrNone) |
|
503 { |
|
504 CDummyNifLog::Printf(_L("Dummy PPP InitialiseConfigRequestL failed\r\n")); |
|
505 return; |
|
506 } |
|
507 } |
|
508 |
|
509 // Check options, and split into list of OK, Bad and Unknown |
|
510 // Note - the naklist options will have been updated to |
|
511 // contain acceptable values. |
|
512 if (iCodeRec==KPppLcpConfigRequest) |
|
513 CheckRecvConfigRequest(rcvlist, acklist, naklist, rejlist); |
|
514 |
|
515 if (!rejlist.IsEmpty()) |
|
516 { |
|
517 reply = ERej; |
|
518 naklist.Free(); |
|
519 acklist.Free(); |
|
520 } |
|
521 else if (!naklist.IsEmpty()) |
|
522 { |
|
523 reply = ENak; |
|
524 acklist.Free(); |
|
525 } |
|
526 else if (!acklist.IsEmpty()) |
|
527 { |
|
528 reply = EAck; |
|
529 SetupConfigRequest(acklist); |
|
530 } |
|
531 |
|
532 //Added to initialize the SendPPP index |
|
533 ipktRecvPPP.Pack(); |
|
534 ptrTransPktPPP = &ipktRecvPPP; |
|
535 } |
|
536 |
|
537 // State processing |
|
538 |
|
539 switch (iDummyPPPState) |
|
540 { |
|
541 |
|
542 case EDummyPPPFsmInitial: |
|
543 case EDummyPPPFsmStarting: |
|
544 TRAPD(err, InitialiseConfigRequestL()); |
|
545 if (err==KErrNone) |
|
546 SendConfigRequest(); |
|
547 SetState(EDummyPPPFsmReqSent); |
|
548 case EDummyPPPFsmClosing: |
|
549 case EDummyPPPFsmStopping: |
|
550 break; |
|
551 case EDummyPPPFsmClosed: |
|
552 SetPppId(KPppIdLcp); |
|
553 SendTerminateAck(); |
|
554 break; |
|
555 |
|
556 case EDummyPPPFsmStopped: |
|
557 switch (iCodeRec) |
|
558 { |
|
559 case KPppLcpConfigRequest: |
|
560 TRAPD(err, InitialiseConfigRequestL()); |
|
561 if (err==KErrNone) |
|
562 { |
|
563 SendConfigRequest(); |
|
564 SetPppId(KPppIdLcp); |
|
565 } |
|
566 switch (reply) |
|
567 { |
|
568 case EAck: |
|
569 SendConfigReply(acklist, KPppLcpConfigAck); |
|
570 SetState(EDummyPPPFsmAckSent); |
|
571 break; |
|
572 case ENak: |
|
573 SendConfigReply(naklist, KPppLcpConfigNak); |
|
574 SetState(EDummyPPPFsmReqSent); |
|
575 break; |
|
576 case ERej: |
|
577 SendConfigReply(rejlist, KPppLcpConfigReject); |
|
578 SetState(EDummyPPPFsmReqSent); |
|
579 break; |
|
580 default: |
|
581 break; |
|
582 } |
|
583 break; |
|
584 case KPppLcpConfigAck: |
|
585 case KPppLcpConfigNak: |
|
586 //Not responding to a reject |
|
587 //case KPppLcpConfigReject: |
|
588 SetPppId(KPppIdLcp); |
|
589 SendTerminateAck(); |
|
590 break; |
|
591 } |
|
592 break; |
|
593 |
|
594 case EDummyPPPFsmReqSent: |
|
595 switch (iCodeRec) |
|
596 { |
|
597 case KPppLcpConfigRequest: |
|
598 switch (reply) |
|
599 { |
|
600 case EAck: |
|
601 SendConfigReply(acklist, KPppLcpConfigAck); |
|
602 SetState(EDummyPPPFsmAckSent); |
|
603 break; |
|
604 case ENak: |
|
605 // RFC 1661 4.6 |
|
606 if(CheckMaxFailureExceeded() == TRUE) |
|
607 SendConfigReply(naklist, KPppLcpConfigReject); |
|
608 else |
|
609 { |
|
610 DecrementDummyPPPMaxFailureCount(); |
|
611 SendConfigReply(naklist, KPppLcpConfigNak); |
|
612 } |
|
613 break; |
|
614 case ERej: |
|
615 SendConfigReply(rejlist, KPppLcpConfigReject); |
|
616 SetState(EDummyPPPFsmReqSent); |
|
617 break; |
|
618 default: |
|
619 break; |
|
620 } |
|
621 break; |
|
622 case KPppLcpConfigAck: |
|
623 InitRestartCountForConfig(); |
|
624 CheckRecvConfigAck(rcvlist); |
|
625 SetState(EDummyPPPFsmAckRecvd); |
|
626 break; |
|
627 case KPppLcpConfigNak: |
|
628 InitRestartCountForConfig(); |
|
629 CheckRecvConfigNak(rcvlist, iDummyPPPRequestList); |
|
630 //SendConfigRequestAfterNak(rcvlist); |
|
631 SetNewId(); |
|
632 SendConfigRequest(); |
|
633 break; |
|
634 case KPppLcpConfigReject: |
|
635 //Not responding to a reject |
|
636 //InitRestartCountForConfig(); |
|
637 //CheckRecvConfigReject(rcvlist, iDummyPPPRequestList); |
|
638 //SendConfigRequestAfterReject(rcvlist); |
|
639 //SetNewId(); |
|
640 //SendConfigRequest(); |
|
641 break; |
|
642 } |
|
643 break; |
|
644 |
|
645 case EDummyPPPFsmAckRecvd: |
|
646 switch (iCodeRec) |
|
647 { |
|
648 case KPppLcpConfigRequest: |
|
649 switch (reply) |
|
650 { |
|
651 case EAck: |
|
652 SendConfigReply(acklist, KPppLcpConfigAck); |
|
653 SetState(EDummyPPPFsmOpened); |
|
654 //As external option negotiation complete |
|
655 iFlags |= KDummyPPPApplyPending; |
|
656 break; |
|
657 case ENak: |
|
658 // RFC 1661 4.6 |
|
659 if(CheckMaxFailureExceeded() == TRUE) |
|
660 SendConfigReply(naklist, KPppLcpConfigReject); |
|
661 else |
|
662 { |
|
663 DecrementDummyPPPMaxFailureCount(); |
|
664 SendConfigReply(naklist, KPppLcpConfigNak); |
|
665 } |
|
666 break; |
|
667 case ERej: |
|
668 SendConfigReply(rejlist, KPppLcpConfigReject); |
|
669 break; |
|
670 default: |
|
671 break; |
|
672 } |
|
673 break; |
|
674 case KPppLcpConfigAck: |
|
675 //InitRestartCountForConfig(); |
|
676 //CheckRecvConfigAck(rcvlist); |
|
677 //SetState(EDummyPPPFsmOpened); |
|
678 //As external option negotiation complete |
|
679 //iFlags |= KDummyPPPApplyPending; |
|
680 break; |
|
681 case KPppLcpConfigNak: |
|
682 //Not responding to a reject |
|
683 //case KPppLcpConfigReject: |
|
684 SendConfigRequest(); |
|
685 SetState(EDummyPPPFsmReqSent); |
|
686 break; |
|
687 } |
|
688 break; |
|
689 |
|
690 case EDummyPPPFsmAckSent: |
|
691 switch (iCodeRec) |
|
692 { |
|
693 case KPppLcpConfigRequest: |
|
694 switch (reply) |
|
695 { |
|
696 case EAck: |
|
697 SendConfigReply(acklist, KPppLcpConfigAck); |
|
698 break; |
|
699 case ENak: |
|
700 // RFC 1661 4.6 |
|
701 if(CheckMaxFailureExceeded() == TRUE) |
|
702 SendConfigReply(naklist, KPppLcpConfigReject); |
|
703 else |
|
704 { |
|
705 DecrementDummyPPPMaxFailureCount(); |
|
706 SendConfigReply(naklist, KPppLcpConfigNak); |
|
707 } |
|
708 SetState(EDummyPPPFsmReqSent); |
|
709 break; |
|
710 case ERej: |
|
711 SendConfigReply(rejlist, KPppLcpConfigReject); |
|
712 SetState(EDummyPPPFsmReqSent); |
|
713 break; |
|
714 default: |
|
715 break; |
|
716 } |
|
717 break; |
|
718 case KPppLcpConfigAck: |
|
719 InitRestartCountForConfig(); |
|
720 CheckRecvConfigAck(rcvlist); |
|
721 SetState(EDummyPPPFsmOpened); |
|
722 //As external option negotiation complete |
|
723 iFlags |= KDummyPPPApplyPending; |
|
724 break; |
|
725 case KPppLcpConfigNak: |
|
726 InitRestartCountForConfig(); |
|
727 CheckRecvConfigNak(rcvlist, iDummyPPPRequestList); |
|
728 //SendConfigRequestAfterNak(rcvlist); |
|
729 SetNewId(); |
|
730 SendConfigRequest(); |
|
731 break; |
|
732 case KPppLcpConfigReject: |
|
733 //Not responding to a reject |
|
734 //InitRestartCountForConfig(); |
|
735 //CheckRecvConfigReject(rcvlist, iDummyPPPRequestList); |
|
736 //SendConfigRequestAfterReject(rcvlist); |
|
737 //SetNewId(); |
|
738 //SendConfigRequest(); |
|
739 break; |
|
740 } |
|
741 break; |
|
742 |
|
743 case EDummyPPPFsmOpened: |
|
744 // Config Reset done above |
|
745 switch (iCodeRec) |
|
746 { |
|
747 case KPppLcpConfigRequest: |
|
748 SendConfigRequest(); |
|
749 switch (reply) |
|
750 { |
|
751 case EAck: |
|
752 SendConfigReply(acklist, KPppLcpConfigAck); |
|
753 SetState(EDummyPPPFsmAckSent); |
|
754 break; |
|
755 case ENak: |
|
756 SendConfigReply(naklist, KPppLcpConfigNak); |
|
757 SetState(EDummyPPPFsmReqSent); |
|
758 break; |
|
759 case ERej: |
|
760 SendConfigReply(rejlist, KPppLcpConfigReject); |
|
761 SetState(EDummyPPPFsmReqSent); |
|
762 break; |
|
763 default: |
|
764 break; |
|
765 } |
|
766 break; |
|
767 case KPppLcpConfigAck: |
|
768 SendConfigRequest(); |
|
769 CheckRecvConfigAck(rcvlist); |
|
770 SetState(EDummyPPPFsmReqSent); |
|
771 break; |
|
772 case KPppLcpConfigNak: |
|
773 CheckRecvConfigNak(rcvlist, iDummyPPPRequestList); |
|
774 //SendConfigRequestAfterNak(rcvlist); |
|
775 SetNewId(); |
|
776 SendConfigRequest(); |
|
777 SetState(EDummyPPPFsmReqSent); |
|
778 break; |
|
779 case KPppLcpConfigReject: |
|
780 //Not responding to the reject |
|
781 //CheckRecvConfigReject(rcvlist, iDummyPPPRequestList); |
|
782 //SendConfigRequestAfterReject(rcvlist); |
|
783 //SetNewId(); |
|
784 //SendConfigRequest(); |
|
785 //SetState(EDummyPPPFsmReqSent); |
|
786 break; |
|
787 } |
|
788 break; |
|
789 default: |
|
790 //Do nothing |
|
791 break; |
|
792 } |
|
793 |
|
794 rcvlist.Free(); |
|
795 acklist.Free(); |
|
796 naklist.Free(); |
|
797 rejlist.Free(); |
|
798 |
|
799 } |
|
800 |
|
801 void CDummyPPPIf::ProcessPAPandIPCP() |
|
802 { |
|
803 CDummyNifLog::Printf(_L("Dummy PPP ProcessPAPandIPCP\r\n")); |
|
804 // Split the recvd packet into separate options |
|
805 // placing each option in a queue where it can be |
|
806 // easily parsed and manipulated in the upcall handlers. |
|
807 RPppOptionList rcvlist; // Recvd list of options |
|
808 enum TDummyPPPResult { ENop, EAck, ENak, ERej }; |
|
809 |
|
810 RPppOptionList acklist; // List of Ack'd options - only valid of the following are empty |
|
811 RPppOptionList naklist; // List of Nak'd options - only valid of the following is empty |
|
812 RPppOptionList rejlist; // List of Rejected options |
|
813 |
|
814 |
|
815 TDummyPPPResult reply = ENop; |
|
816 |
|
817 TRAPD(err, rcvlist.SetL(ipktRecvPPP)); |
|
818 if (err!=KErrNone) |
|
819 return; |
|
820 |
|
821 TInt iAction = ENop; |
|
822 |
|
823 //For overriding PAP |
|
824 if (iDummyPPPState == EDummyPPPFsmOpened) |
|
825 { |
|
826 SetPppId(KPppIdIpcp); |
|
827 SetState(EDummyPPPFsmPapAckSent); |
|
828 } |
|
829 if(iDummyPPPState < EDummyPPPFsmPapAuthAckRecvd) |
|
830 { |
|
831 if (iDummyPPPState == EDummyPPPFsmOpened) |
|
832 { |
|
833 //Just for testing Nak packet |
|
834 //SendPapRequest(); |
|
835 //SendPapNak(rcvlist); |
|
836 //SetState(EDummyPPPFsmPapAuthReqSent); |
|
837 } |
|
838 |
|
839 iAction = CheckRecvPapReq(); |
|
840 reply = (iAction == KPppPapNak)?ENak:reply; |
|
841 reply = (iAction == KPppPapAck)?EAck:reply; |
|
842 |
|
843 } |
|
844 else |
|
845 CheckRecvIPCPReq(rcvlist, acklist, naklist, rejlist); |
|
846 |
|
847 if (!rejlist.IsEmpty()) |
|
848 { |
|
849 reply = ERej; |
|
850 naklist.Free(); |
|
851 acklist.Free(); |
|
852 } |
|
853 else if (!naklist.IsEmpty()) |
|
854 { |
|
855 reply = ENak; |
|
856 acklist.Free(); |
|
857 } |
|
858 else if (!acklist.IsEmpty()) |
|
859 { |
|
860 reply = EAck; |
|
861 //SetupConfigRequest(acklist); |
|
862 } |
|
863 |
|
864 |
|
865 //Added to initialize the SendPPP index |
|
866 ipktRecvPPP.Pack(); |
|
867 ptrTransPktPPP = &ipktRecvPPP; |
|
868 |
|
869 // State processing |
|
870 |
|
871 switch (iDummyPPPState) |
|
872 { |
|
873 case EDummyPPPFsmOpened: |
|
874 //Commenting Pap nego for the time being as PPP is rejecting it. |
|
875 //so skipping to IPCP Nego state |
|
876 //SetPppId(KPppIdPap); |
|
877 //SendPapRequest(); |
|
878 //SetState(EDummyPPPFsmPapAuthReqSent); |
|
879 SetPppId(KPppIdIpcp); |
|
880 SetState(EDummyPPPFsmPapAckSent); |
|
881 |
|
882 break; |
|
883 case EDummyPPPFsmPapAuthAckRecvd: |
|
884 if(reply == EAck) |
|
885 { |
|
886 SendConfigReply(acklist, KPppLcpConfigAck); |
|
887 SetPppId(KPppIdIpcp); |
|
888 SetState(EDummyPPPFsmPapAckSent); |
|
889 break; |
|
890 } |
|
891 if(reply == ENak) |
|
892 { |
|
893 SendConfigReply(naklist, KPppLcpConfigNak); |
|
894 break; |
|
895 } |
|
896 break; |
|
897 case EDummyPPPFsmPapAckSent: |
|
898 if(iCodeRec == KPppLcpConfigRequest) |
|
899 { |
|
900 switch(reply) |
|
901 { |
|
902 case EAck: |
|
903 SendConfigReply(acklist, KPppLcpConfigAck); |
|
904 SetPppId(KPppIdIpcp); |
|
905 SendIPCPReq(); |
|
906 SetState(EDummyPPPIPCPReqSent); |
|
907 break; |
|
908 case ENak: |
|
909 default: |
|
910 SetPppId(KPppIdIpcp); |
|
911 SendIPCPDummyNak(); |
|
912 break; |
|
913 } |
|
914 } |
|
915 else |
|
916 { |
|
917 switch(reply) |
|
918 { |
|
919 case EAck: |
|
920 SetPppId(KPppIdIpcp); |
|
921 SendConfigReply(acklist, KPppLcpConfigAck); |
|
922 SetState(EDummyPPPFsmIPOpen); |
|
923 break; |
|
924 case ENak: |
|
925 default: |
|
926 SetPppId(KPppIdIpcp); |
|
927 SendIPCPDummyNak(); |
|
928 break; |
|
929 } |
|
930 } |
|
931 break; |
|
932 case EDummyPPPIPCPReqSent: |
|
933 switch(reply) |
|
934 { |
|
935 case EAck: |
|
936 SendConfigReply(acklist, KPppLcpConfigAck); |
|
937 SetState(EDummyPPPFsmIPOpen); |
|
938 break; |
|
939 |
|
940 case ENak: |
|
941 default: |
|
942 SetPppId(KPppIdIpcp); |
|
943 SendIPCPReq(); |
|
944 break; |
|
945 } |
|
946 break; |
|
947 default: |
|
948 //Do nothing |
|
949 break; |
|
950 } |
|
951 |
|
952 } |
|
953 |
|
954 void CDummyPPPIf::ProcessTerminate() |
|
955 { |
|
956 if (iCodeRec==KPppLcpTerminateRequest) |
|
957 { |
|
958 switch (iDummyPPPState) |
|
959 { |
|
960 case EDummyPPPFsmInitial: |
|
961 case EDummyPPPFsmStarting: |
|
962 // bad event |
|
963 break; |
|
964 case EDummyPPPFsmClosed: |
|
965 case EDummyPPPFsmStopped: |
|
966 case EDummyPPPFsmClosing: |
|
967 case EDummyPPPFsmStopping: |
|
968 SendTerminateAck(); |
|
969 break; |
|
970 case EDummyPPPFsmReqSent: |
|
971 case EDummyPPPFsmAckRecvd: |
|
972 case EDummyPPPFsmAckSent: |
|
973 iNotify->LinkLayerDown(KErrTimedOut, MNifIfNotify::EDisconnect); |
|
974 iLink->LinkDown(KErrCouldNotConnect); |
|
975 SendTerminateAck(); |
|
976 SetState(EDummyPPPFsmReqSent); |
|
977 break; |
|
978 case EDummyPPPFsmOpened: |
|
979 case EDummyPPPFsmPapAuthReqSent: |
|
980 case EDummyPPPFsmPapAuthAckRecvd: |
|
981 case EDummyPPPFsmPapAckSent: |
|
982 case EDummyPPPIPCPReqSent: |
|
983 //SendTerminateAck(); |
|
984 case EDummyPPPFsmIPOpen: |
|
985 // Fix for DEF002615 |
|
986 // Dummy PPP should not convey KErrCommsLineFail to PPP when a Terminate Request |
|
987 // is received. So blocking these two lines. |
|
988 //iLink->Stop(KErrCommsLineFail,MNifIfNotify::EDisconnect); |
|
989 //iLink->LinkDown(KErrCommsLineFail); |
|
990 iDummyPPPRestartCount = 0; |
|
991 SetState(EDummyPPPFsmInitial); |
|
992 break; |
|
993 } |
|
994 } |
|
995 else // KPppLcpTerminateAck |
|
996 { |
|
997 { |
|
998 switch (iDummyPPPState) |
|
999 { |
|
1000 case EDummyPPPFsmInitial: |
|
1001 case EDummyPPPFsmStarting: |
|
1002 // bad event |
|
1003 break; |
|
1004 case EDummyPPPFsmClosed: |
|
1005 case EDummyPPPFsmStopped: |
|
1006 iLink->LinkDown(KErrCommsLineFail); |
|
1007 iNotify->LinkLayerDown(KErrNone, MNifIfNotify::EDisconnect); |
|
1008 break; |
|
1009 case EDummyPPPFsmClosing: |
|
1010 iLink->LinkDown(KErrCommsLineFail); |
|
1011 SetState(EDummyPPPFsmClosed); |
|
1012 break; |
|
1013 case EDummyPPPFsmStopping: |
|
1014 iLink->LinkDown(KErrCommsLineFail); |
|
1015 SetState(EDummyPPPFsmStopped); |
|
1016 iNotify->LinkLayerDown(KErrNone, MNifIfNotify::EDisconnect); |
|
1017 break; |
|
1018 case EDummyPPPFsmReqSent: |
|
1019 case EDummyPPPFsmAckSent: |
|
1020 break; |
|
1021 case EDummyPPPFsmAckRecvd: |
|
1022 SetState(EDummyPPPFsmReqSent); |
|
1023 break; |
|
1024 case EDummyPPPFsmOpened: |
|
1025 case EDummyPPPFsmPapAuthReqSent: |
|
1026 case EDummyPPPFsmPapAuthAckRecvd: |
|
1027 case EDummyPPPFsmPapAckSent: |
|
1028 case EDummyPPPIPCPReqSent: |
|
1029 case EDummyPPPFsmIPOpen: |
|
1030 iLink->Stop(KErrCommsLineFail,MNifIfNotify::EDisconnect); |
|
1031 SendConfigRequest(); |
|
1032 SetState(EDummyPPPFsmReqSent); |
|
1033 break; |
|
1034 } |
|
1035 } |
|
1036 } |
|
1037 |
|
1038 } |
|
1039 void CDummyPPPIf::SetupSendPPP() |
|
1040 { |
|
1041 CDummyNifLog::Printf(_L("Dummy PPP SetupSendPPP\r\n")); |
|
1042 if(ipktRecvPPP.IsEmpty()) |
|
1043 { |
|
1044 |
|
1045 //Storing data received into Recv Q |
|
1046 iRecvQ.Append(ipktRecvPPP); |
|
1047 //iSendNumBufs += ipktRecvPPP.NumBufs(); |
|
1048 |
|
1049 iRecvQ.Remove(*ptrTransPktPPP); |
|
1050 |
|
1051 //ptrTransPktPPP = &ipktRecvPPP; |
|
1052 |
|
1053 } |
|
1054 } |
|
1055 |
|
1056 void CDummyPPPIf::SendPapRequest() |
|
1057 { |
|
1058 CDummyNifLog::Printf(_L("Dummy PPP SendPapRequest\r\n")); |
|
1059 #ifdef _UNICODE |
|
1060 TBuf8<256> user,pass; |
|
1061 |
|
1062 //Only for testing |
|
1063 //ConvertTo8Bit(user, iLink->UserName()); |
|
1064 //ConvertTo8Bit(pass, iProtocol->PassWord()); |
|
1065 |
|
1066 user = _L8("EpochUser"); |
|
1067 pass = _L8("EpochPass"); |
|
1068 |
|
1069 #else |
|
1070 TPtrC8 user, pass; |
|
1071 user.Set(iProtocol->UserName()); |
|
1072 pass.Set(iProtocol->PassWord()); |
|
1073 #endif |
|
1074 |
|
1075 RMBufPacket pkt; |
|
1076 RMBufPktInfo* info = NULL; |
|
1077 |
|
1078 TInt len = 4+user.Length()+1+pass.Length()+1; |
|
1079 TRAPD(err, pkt.AllocL(len)); |
|
1080 if (err!=KErrNone) |
|
1081 return; |
|
1082 TRAP(err, info = pkt.NewInfoL()); |
|
1083 if (err!=KErrNone) |
|
1084 { |
|
1085 pkt.Free(); |
|
1086 return; |
|
1087 } |
|
1088 TUint8* ptr = pkt.First()->Ptr(); |
|
1089 *ptr++ = KPppPapRequest; |
|
1090 //Considering it as a New request |
|
1091 //if (aNewRequest) |
|
1092 // { |
|
1093 iDummyPPPTryCount = KDummyPPPPapRetries; |
|
1094 if (++iCurrentDummyPPPId==0) |
|
1095 ++iCurrentDummyPPPId; |
|
1096 // } |
|
1097 *ptr++ = iCurrentDummyPPPId; |
|
1098 BigEndian::Put16(ptr, (TUint16)len); |
|
1099 ptr += 2; |
|
1100 *ptr++ = (TUint8)user.Length(); |
|
1101 Mem::Copy(ptr, (TUint8*)user.Ptr(), user.Length()); |
|
1102 ptr += user.Length(); |
|
1103 *ptr++ = (TUint8)pass.Length(); |
|
1104 Mem::Copy(ptr, (TUint8*)pass.Ptr(), pass.Length()); |
|
1105 ptr += pass.Length(); |
|
1106 info->iLength = len; |
|
1107 TPppAddr::Cast((info->iDstAddr)).SetProtocol(KPppIdPap); |
|
1108 pkt.Pack(); |
|
1109 SendtoPPP(pkt); |
|
1110 iLink->TimerCancel(); |
|
1111 iLink->TimerAfter(KDummyPPPPapWaitTime*1000); |
|
1112 --iDummyPPPTryCount; |
|
1113 |
|
1114 } |
|
1115 void CDummyPPPIf::SendPapAck(RPppOptionList& aReplyList) |
|
1116 { |
|
1117 |
|
1118 CDummyNifLog::Printf(_L("Dummy PPP SendPapAck\r\n")); |
|
1119 RPppOption opt; |
|
1120 RMBufPacket pkt; |
|
1121 RPppOptionList iAckList; // List of Ack'd options - only valid of the following are empty |
|
1122 |
|
1123 while (aReplyList.Remove(opt)) |
|
1124 { |
|
1125 opt.OptType(); |
|
1126 iAckList.Append(opt); |
|
1127 } |
|
1128 |
|
1129 TRAPD(err, iAckList.CreatePacketL(pkt, KPppIdPap, KPppPapAck, iIdRec)); |
|
1130 if (err==KErrNone) |
|
1131 { |
|
1132 SendtoPPP(pkt); |
|
1133 } |
|
1134 } |
|
1135 void CDummyPPPIf::SendPapNak(RPppOptionList& aReplyList) |
|
1136 { |
|
1137 |
|
1138 CDummyNifLog::Printf(_L("SendPapNak\r\n")); |
|
1139 RPppOption opt; |
|
1140 RMBufPacket pkt; |
|
1141 RMBufPacket* Packet; |
|
1142 RPppOptionList iNakList; // List of Nak'd options - only valid of the following is empty |
|
1143 |
|
1144 while (aReplyList.Remove(opt)) |
|
1145 { |
|
1146 opt.OptType(); |
|
1147 iNakList.Append(opt); |
|
1148 } |
|
1149 TRAPD(err, iNakList.CreatePacketL(pkt, KPppIdPap, KPppPapNak, iIdRec)); |
|
1150 if (err==KErrNone) |
|
1151 { |
|
1152 Packet = (RMBufPacket*)&pkt; |
|
1153 RMBufPktInfo*info = Packet->Unpack(); |
|
1154 TPppAddr::Cast((info->iDstAddr)).SetProtocol(KPppIdPap); |
|
1155 TPppAddr::Cast(info->iDstAddr).SetAddress(iLocalAddr); |
|
1156 Packet->Pack(); |
|
1157 SendtoPPP(pkt); |
|
1158 } |
|
1159 } |
|
1160 |
|
1161 TInt CDummyPPPIf::CheckRecvPapReq() |
|
1162 { |
|
1163 CDummyNifLog::Printf(_L("Dummy PPP CheckRecvPapReq\r\n")); |
|
1164 switch (iCodeRec) |
|
1165 { |
|
1166 case KPppPapRequest: |
|
1167 { |
|
1168 TPtrC8 user; |
|
1169 TPtrC8 pass; |
|
1170 user.Set(&iCodeRec,sizeof(iCodeRec)); |
|
1171 pass.Set(&iIdRec,sizeof(iIdRec)); |
|
1172 } |
|
1173 return 0; |
|
1174 case KPppPapAck: |
|
1175 if (iIdRec==iCurrentDummyPPPId) |
|
1176 { |
|
1177 iLink->TimerCancel(); |
|
1178 //Fix for DEF03548 Changing progress states to match that in pppprog.h |
|
1179 iNotify->IfProgress(EPppProgressAuthenticationComplete,KErrNone); |
|
1180 return KPppPapNak; |
|
1181 } |
|
1182 else |
|
1183 { |
|
1184 return KPppPapAck; |
|
1185 } |
|
1186 case KPppPapNak: |
|
1187 if (iIdRec==iCurrentDummyPPPId) |
|
1188 { |
|
1189 iLink->TimerCancel(); |
|
1190 //Fix for DEF03548 Changing progress states to match that in pppprog.h |
|
1191 iNotify->IfProgress(EPppProgressAuthenticationComplete,KErrIfAuthenticationFailure); |
|
1192 } |
|
1193 else |
|
1194 { |
|
1195 return KPppPapNak; |
|
1196 } |
|
1197 break; |
|
1198 default: |
|
1199 return KPppPapNak; |
|
1200 } |
|
1201 return KPppPapRequest; |
|
1202 } |
|
1203 void CDummyPPPIf::SendIPCPDummyNak() |
|
1204 { |
|
1205 CDummyNifLog::Printf(_L("Dummy PPP SendIPCPDummyNak\r\n")); |
|
1206 TRAPD(err, InitializeIPCPConfigRequestL()); |
|
1207 if (err==KErrNone) |
|
1208 { |
|
1209 if (iDummyPPPRequestList.IsEmpty()) |
|
1210 { |
|
1211 CDummyNifLog::Printf(_L("Request list empty\r\n")); |
|
1212 return; |
|
1213 } |
|
1214 |
|
1215 RMBufPacket Packet; |
|
1216 //iDummyPPPRequestId = iIdRec; |
|
1217 TRAPD(err, iDummyPPPRequestList.CreatePacketL(Packet, KPppIdIpcp, KPppLcpConfigNak, (TUint8)iIdRec)); |
|
1218 if (err!=KErrNone) |
|
1219 { |
|
1220 //__DEBUGGER(); |
|
1221 return; |
|
1222 } |
|
1223 |
|
1224 ptrTransPktPPP = &Packet; |
|
1225 |
|
1226 RMBufPktInfo*info = Packet.Unpack(); |
|
1227 |
|
1228 TPppAddr::Cast((info->iDstAddr)).SetProtocol(KPppIdIpcp); |
|
1229 TPppAddr::Cast(info->iDstAddr).SetAddress(iLocalAddr); |
|
1230 Packet.Pack(); |
|
1231 |
|
1232 SendtoPPP(*ptrTransPktPPP); |
|
1233 } |
|
1234 } |
|
1235 void CDummyPPPIf::InitializeIPCPConfigRequestL() |
|
1236 { |
|
1237 CDummyNifLog::Printf(_L("Dummy PPP InitializeIPCPConfigRequestL()\r\n")); |
|
1238 SetNewId(); |
|
1239 InitRestartCountForConfig(); |
|
1240 |
|
1241 if (!iDummyPPPRequestList.IsEmpty()) |
|
1242 iDummyPPPRequestList.Free(); |
|
1243 |
|
1244 iDummyPPPRequestList.CreateAndAddL(KPppIpcpOptIpAddress, iLocalAddr); |
|
1245 |
|
1246 //BigEndian::Put32(opt.ValuePtr(), iRemoteAddr); |
|
1247 //iDummyPPPRequestList.CreateAndAddL(KPppIpcpOptPrimaryDnsAddress, iPrimaryDns); |
|
1248 //iDummyPPPRequestList.CreateAndAddL(KPppIpcpOptSecondaryDnsAddress, iSecondaryDns); |
|
1249 |
|
1250 } |
|
1251 void CDummyPPPIf::SendIPCPReq() |
|
1252 { |
|
1253 CDummyNifLog::Printf(_L("Dummy PPP SendIPCPReq\r\n")); |
|
1254 TRAPD(err, InitializeIPCPConfigRequestL()); |
|
1255 if (err==KErrNone) |
|
1256 { |
|
1257 if (iDummyPPPRequestList.IsEmpty()) |
|
1258 { |
|
1259 CDummyNifLog::Printf(_L("Request list empty\r\n")); |
|
1260 return; |
|
1261 } |
|
1262 |
|
1263 RMBufPacket Packet; |
|
1264 //iDummyPPPRequestId = iIdRec; |
|
1265 TRAPD(err, iDummyPPPRequestList.CreatePacketL(Packet, KPppIdIpcp, KPppLcpConfigRequest, (TUint8)iIdRec)); |
|
1266 if (err!=KErrNone) |
|
1267 { |
|
1268 //__DEBUGGER(); |
|
1269 return; |
|
1270 } |
|
1271 |
|
1272 ptrTransPktPPP = &Packet; |
|
1273 |
|
1274 RMBufPktInfo*info = Packet.Unpack(); |
|
1275 |
|
1276 TPppAddr::Cast((info->iDstAddr)).SetProtocol(KPppIdIpcp); |
|
1277 TPppAddr::Cast(info->iDstAddr).SetAddress(iLocalAddr); |
|
1278 Packet.Pack(); |
|
1279 |
|
1280 SendtoPPP(*ptrTransPktPPP); |
|
1281 } |
|
1282 } |
|
1283 void CDummyPPPIf::CheckRecvIPCPReq(RPppOptionList& aRequestList, RPppOptionList& aAckList, RPppOptionList& aNakList, RPppOptionList& aRejList) |
|
1284 { |
|
1285 RPppOption opt; |
|
1286 TUint8 temp; |
|
1287 CDummyNifLog::Printf(_L("Dummy PPP CheckRecvIPCPReq\r\n")); |
|
1288 while (aRequestList.Remove(opt)) |
|
1289 { |
|
1290 temp = opt.OptType(); |
|
1291 switch (temp) |
|
1292 { |
|
1293 case KPppIpcpOptIpAddress: |
|
1294 { |
|
1295 TUint32 addr = BigEndian::Get32(opt.ValuePtr()); |
|
1296 if (addr==0) |
|
1297 { |
|
1298 aNakList.Append(opt); |
|
1299 } |
|
1300 else |
|
1301 aAckList.Append(opt); |
|
1302 } |
|
1303 break; |
|
1304 case KPppIpcpOptIpAddresses: |
|
1305 { |
|
1306 TUint32 remoteAddr = BigEndian::Get32(opt.ValuePtr()); |
|
1307 TUint32 addr = BigEndian::Get32(opt.ValuePtr()+4); |
|
1308 |
|
1309 if (remoteAddr == 0) |
|
1310 { |
|
1311 aRejList.Append(opt); |
|
1312 } |
|
1313 else if (addr == 0) |
|
1314 { |
|
1315 aNakList.Append(opt); |
|
1316 } |
|
1317 else |
|
1318 { |
|
1319 iRemoteAddr = remoteAddr; |
|
1320 aAckList.Append(opt); |
|
1321 } |
|
1322 } |
|
1323 break; |
|
1324 } |
|
1325 } |
|
1326 } |
|
1327 |
|
1328 void CDummyPPPIf::SetState(TDummyPPPToPPPFsmState aState) |
|
1329 { |
|
1330 CDummyNifLog::Write(_L("DummyPPP::SetState()")); |
|
1331 |
|
1332 _LIT(KStateString,"State %s -> %s"); |
|
1333 |
|
1334 |
|
1335 CDummyNifLog::Printf(KStateString,CDummyNifLog::StateToText(iDummyPPPState), CDummyNifLog::StateToText(aState)); |
|
1336 |
|
1337 iDummyPPPState = aState; |
|
1338 } |
|
1339 void CDummyPPPIf::SetPppId(TUint aProt) |
|
1340 { |
|
1341 CDummyNifLog::Printf(_L("DummyPPP::SetPppId to %d\n"),aProt); |
|
1342 iSendPppId = aProt; |
|
1343 } |
|
1344 |
|
1345 void CDummyPPPIf::InitRestartCountForConfig() |
|
1346 { |
|
1347 CDummyNifLog::Printf(_L("Dummy PPP InitRestartCountForConfig\r\n")); |
|
1348 // RFC 1661 4.6 Max-Configure |
|
1349 iDummyPPPWaitTime = KDummyPPPWaitTimeConfig; |
|
1350 iDummyPPPRestartCount = KDummyPPPMaxRestartConfig; |
|
1351 } |
|
1352 |
|
1353 void CDummyPPPIf::SetNewId() |
|
1354 { |
|
1355 TUint8 id = ++iCurrentDummyPPPId; |
|
1356 if (iCurrentDummyPPPId==0) |
|
1357 ++iCurrentDummyPPPId; |
|
1358 iDummyPPPRequestId = id; |
|
1359 CDummyNifLog::Printf(_L("Dummy PPP SetNewId %d\r\n"),iDummyPPPRequestId); |
|
1360 } |
|
1361 |
|
1362 void CDummyPPPIf::InitialiseConfigRequestL() |
|
1363 { |
|
1364 TUint32 iDummyPPPRecvEscMap = 0; |
|
1365 SetNewId(); |
|
1366 InitRestartCountForConfig(); |
|
1367 SetPppId(KPppIdLcp); |
|
1368 |
|
1369 CDummyNifLog::Printf(_L("Dummy PPP InitialiseConfigRequest\r\n")); |
|
1370 if (!iDummyPPPRequestList.IsEmpty()) |
|
1371 iDummyPPPRequestList.Free(); |
|
1372 |
|
1373 // Create a new magic number |
|
1374 iPPPRemMagicNumber = 0; |
|
1375 |
|
1376 if (iDummyPPPLocMagicNumber == 0) |
|
1377 { |
|
1378 //CPppLcp::NewMagicNumber(iDummyPPPLocMagicNumber); |
|
1379 //Only for testing |
|
1380 iDummyPPPLocMagicNumber = 54321; |
|
1381 } |
|
1382 |
|
1383 iDummyPPPRequestList.CreateAndAddL(KPppLcpOptMagicNumber, (TUint32)iDummyPPPLocMagicNumber); |
|
1384 if ((iOrigConfig().iHandshake & KConfigSendXoff)!=0 |
|
1385 || (iOrigConfig().iHandshake & KConfigSendXoff)!=0) |
|
1386 { |
|
1387 if (iOrigConfig().iXonChar<32) |
|
1388 iDummyPPPRecvEscMap |= 1<<iOrigConfig().iXonChar; |
|
1389 if (iOrigConfig().iXoffChar<32) |
|
1390 iDummyPPPRecvEscMap |= 1<<iOrigConfig().iXoffChar; |
|
1391 } |
|
1392 //for testing options |
|
1393 //iDummyPPPRequestList.CreateAndAddL(KPppLcpOptEscapeCharMap,iDummyPPPRecvEscMap); |
|
1394 //iDummyPPPRequestList.CreateAndAddL(KPppLcpOptProtocolCompress); |
|
1395 //iDummyPPPRequestList.CreateAndAddL(KPppLcpOptAddrCtrlCompress); |
|
1396 |
|
1397 } |
|
1398 |
|
1399 void CDummyPPPIf::SetupConfigRequest(RPppOptionList& aRequestList) |
|
1400 // |
|
1401 // Apply options in a recvd config request (that was ACK'd) |
|
1402 // |
|
1403 { |
|
1404 CDummyNifLog::Printf(_L("Dummy PPP SetupConfigRequest\r\n")); |
|
1405 TMBufPktQIter iter(aRequestList); |
|
1406 RPppOption opt; |
|
1407 |
|
1408 while (opt = iter++, !opt.IsEmpty()) |
|
1409 { |
|
1410 switch (opt.OptType()) |
|
1411 { |
|
1412 case KPppLcpOptMaxRecvUnit: |
|
1413 //iMaxSendSize = BigEndian::Get16(opt.ValuePtr()); |
|
1414 break; |
|
1415 case KPppLcpOptMagicNumber: |
|
1416 iPPPRemMagicNumber = BigEndian::Get32(opt.ValuePtr()); |
|
1417 break; |
|
1418 default: |
|
1419 //ExtOptApplyConfigRequest(opt); |
|
1420 break; |
|
1421 } |
|
1422 } |
|
1423 } |
|
1424 |
|
1425 void CDummyPPPIf::CheckRecvConfigRequest(RPppOptionList& aRequestList, RPppOptionList& aAckList, RPppOptionList& aNakList, RPppOptionList& aRejList) |
|
1426 // |
|
1427 // Check options in a recvd config request |
|
1428 // |
|
1429 { |
|
1430 CDummyNifLog::Printf(_L("Dummy PPP CheckRecvConfigRequest\r\n")); |
|
1431 RPppOption opt; |
|
1432 //only for debugging |
|
1433 TUint8 temp; |
|
1434 |
|
1435 while (aRequestList.Remove(opt)) |
|
1436 { |
|
1437 temp = opt.OptType(); |
|
1438 switch (temp) |
|
1439 { |
|
1440 case KPppLcpOptMaxRecvUnit: |
|
1441 if (opt.ValueLength()<0) |
|
1442 aNakList.Append(opt); |
|
1443 else |
|
1444 { |
|
1445 if (opt.ValueLength()<2) |
|
1446 aRejList.Append(opt); |
|
1447 else |
|
1448 aAckList.Append(opt); |
|
1449 } |
|
1450 break; |
|
1451 |
|
1452 case KPppLcpOptMagicNumber: |
|
1453 if (opt.ValueLength()<0) |
|
1454 aNakList.Append(opt); |
|
1455 else |
|
1456 { |
|
1457 if (opt.ValueLength()!=4) |
|
1458 aRejList.Append(opt); |
|
1459 else |
|
1460 { |
|
1461 iPPPRemMagicNumber = BigEndian::Get32(opt.ValuePtr()); |
|
1462 if (iPPPRemMagicNumber!=iDummyPPPLocMagicNumber) |
|
1463 { |
|
1464 aAckList.Append(opt); |
|
1465 } |
|
1466 else |
|
1467 { |
|
1468 //CPppLcp::NewMagicNumber(iPPPRemMagicNumber); |
|
1469 //Only for testing |
|
1470 iPPPRemMagicNumber = 11111; |
|
1471 BigEndian::Put32(opt.ValuePtr(), iPPPRemMagicNumber); |
|
1472 aNakList.Append(opt); |
|
1473 } |
|
1474 } |
|
1475 } |
|
1476 break; |
|
1477 case KPppLcpOptMultiLinkEndPointDescriminator: |
|
1478 aAckList.Append(opt); |
|
1479 break; |
|
1480 |
|
1481 default: |
|
1482 //ExtOptCheckConfigRequest(aPacket, (CProtocolBase*)this); |
|
1483 iPppOptions->ExtOptCheckConfigRequest(opt, aAckList, aNakList, aRejList); |
|
1484 } |
|
1485 } |
|
1486 } |
|
1487 |
|
1488 void CDummyPPPIf::CheckRecvConfigAck(RPppOptionList& aReplyList) |
|
1489 // |
|
1490 // Recvd a Config Ack - apply the options |
|
1491 // |
|
1492 { |
|
1493 CDummyNifLog::Printf(_L("Dummy PPP CheckRecvConfigAck\r\n")); |
|
1494 TMBufPktQIter iter(aReplyList); |
|
1495 RPppOption opt; |
|
1496 |
|
1497 while (opt = iter++, !opt.IsEmpty()) |
|
1498 { |
|
1499 switch (opt.OptType()) |
|
1500 { |
|
1501 case KPppLcpOptMaxRecvUnit: |
|
1502 //iMaxRecvSize = BigEndian::Get16(opt.ValuePtr()); |
|
1503 break; |
|
1504 case KPppLcpOptMagicNumber: |
|
1505 // Magic number is OK |
|
1506 //SendDummyPPPIdentification(); |
|
1507 break; |
|
1508 default: |
|
1509 iPppOptions->ExtOptRecvConfigAck(opt); |
|
1510 break; |
|
1511 } |
|
1512 } |
|
1513 } |
|
1514 |
|
1515 void CDummyPPPIf::CheckRecvConfigNak(RPppOptionList& aReplyList, RPppOptionList& aReqList) |
|
1516 // |
|
1517 // Recvd a Config Nak - The associated original request is in aReqList |
|
1518 // |
|
1519 { |
|
1520 CDummyNifLog::Printf(_L("DummyPPP::CheckRecvConfigNak\r\n")); |
|
1521 TMBufPktQIter iter(aReplyList); |
|
1522 RPppOption opt; |
|
1523 |
|
1524 while (opt = iter++, !opt.IsEmpty()) |
|
1525 { |
|
1526 switch (opt.OptType()) |
|
1527 { |
|
1528 case KPppLcpOptMaxRecvUnit: |
|
1529 aReqList.ReplaceOption(opt); |
|
1530 break; |
|
1531 case KPppLcpOptMagicNumber: |
|
1532 { |
|
1533 iDummyPPPLocMagicNumber = BigEndian::Get32(opt.ValuePtr()); |
|
1534 aReqList.ReplaceOption(opt); |
|
1535 } |
|
1536 break; |
|
1537 default: |
|
1538 iPppOptions->ExtOptRecvConfigNak(opt, aReqList); |
|
1539 break; |
|
1540 } |
|
1541 } |
|
1542 } |
|
1543 |
|
1544 void CDummyPPPIf::CheckRecvConfigReject(RPppOptionList& aReplyList, RPppOptionList& aReqList) |
|
1545 // |
|
1546 // Recvd a Config Reject - The associated original request is in aReqList |
|
1547 // |
|
1548 { |
|
1549 TMBufPktQIter iter(aReplyList); |
|
1550 RPppOption opt; |
|
1551 CDummyNifLog::Printf(_L("Dummy PPP CheckRecvConfigReject\r\n")); |
|
1552 |
|
1553 while (opt = iter++, !opt.IsEmpty()) |
|
1554 { |
|
1555 switch (opt.OptType()) |
|
1556 { |
|
1557 case KPppLcpOptMaxRecvUnit: |
|
1558 aReqList.RemoveOption(opt); |
|
1559 break; |
|
1560 case KPppLcpOptMagicNumber: |
|
1561 aReqList.RemoveOption(opt); |
|
1562 break; |
|
1563 default: |
|
1564 iPppOptions->ExtOptRecvConfigReject(opt, aReqList); |
|
1565 break; |
|
1566 } |
|
1567 } |
|
1568 } |
|
1569 |
|
1570 |
|
1571 void CDummyPPPIf::SendConfigRequest() |
|
1572 // |
|
1573 // Send the config request in iDummyPPPRequestList |
|
1574 // |
|
1575 { |
|
1576 |
|
1577 if (iDummyPPPRequestList.IsEmpty()) |
|
1578 { |
|
1579 CDummyNifLog::Write(_L("DummyPPP Request list empty\r\n")); |
|
1580 return; |
|
1581 } |
|
1582 |
|
1583 CDummyNifLog::Printf(_L("Dummy PPP SendConfigRequest\r\n")); |
|
1584 RMBufPacket pkt; |
|
1585 iDummyPPPRequestId &= 0xff; |
|
1586 TRAPD(err, iDummyPPPRequestList.CreatePacketL(pkt, iSendPppId, KPppLcpConfigRequest, (TUint8)iDummyPPPRequestId)); |
|
1587 if (err==KErrNone) |
|
1588 { |
|
1589 SendtoPPP(pkt); |
|
1590 --iDummyPPPRestartCount; |
|
1591 iLink->TimerCancel(); |
|
1592 TInt temp=iDummyPPPWaitTime; |
|
1593 iLink->TimerAfter(iDummyPPPWaitTime*1000); |
|
1594 iDummyPPPWaitTime=temp; |
|
1595 } |
|
1596 } |
|
1597 |
|
1598 void CDummyPPPIf::SendConfigReply(RPppOptionList& aOptList,TUint8 aType) |
|
1599 { |
|
1600 RMBufPacket pkt; |
|
1601 CDummyNifLog::Printf(_L("Dummy PPP SendConfigReply\r\n")); |
|
1602 TRAPD(err, aOptList.CreatePacketL(pkt, iSendPppId, aType, iIdRec)); |
|
1603 if (err==KErrNone) |
|
1604 { |
|
1605 SendtoPPP(pkt); |
|
1606 iLink->TimerCancel(); |
|
1607 TInt temp=iDummyPPPWaitTime; |
|
1608 iLink->TimerAfter(iDummyPPPWaitTime*1000); |
|
1609 iDummyPPPWaitTime=temp; |
|
1610 } |
|
1611 } |
|
1612 |
|
1613 void CDummyPPPIf::SendTerminateAck() |
|
1614 { |
|
1615 RMBufPacket pkt; |
|
1616 RMBufPktInfo* info=NULL; |
|
1617 CDummyNifLog::Printf(_L("Dummy PPP SendTerminateAck\r\n")); |
|
1618 TRAPD(err, pkt.AllocL(4)); |
|
1619 if (err ==KErrNone) |
|
1620 { |
|
1621 TRAP(err,info = pkt.NewInfoL()); |
|
1622 } |
|
1623 if (err ==KErrNone) |
|
1624 { |
|
1625 info->iLength = 4; |
|
1626 TPppAddr::Cast((info->iDstAddr)).SetProtocol(iSendPppId); |
|
1627 TUint8* ptr = pkt.First()->Ptr(); |
|
1628 *ptr++ = KPppLcpTerminateAck; |
|
1629 *ptr++ = iIdRec; |
|
1630 BigEndian::Put16(ptr, (TUint16)4); |
|
1631 pkt.Pack(); |
|
1632 SendtoPPP(pkt); |
|
1633 } |
|
1634 else |
|
1635 { |
|
1636 pkt.Free(); |
|
1637 __ASSERT_DEBUG(EFalse,User::Invariant()); |
|
1638 } |
|
1639 } |
|
1640 |
|
1641 void CDummyPPPIf::SendDummyPPPIdentification() |
|
1642 { |
|
1643 |
|
1644 CDummyNifLog::Printf(_L("Dummy PPP SendDummyPPPIdentification\r\n")); |
|
1645 TInt err; |
|
1646 TPtrC8 id = _L8("Symbian Epoc!"); |
|
1647 RMBufPacket pkt; |
|
1648 RMBufPktInfo* info = NULL; |
|
1649 TRAP(err, info = pkt.NewInfoL()); |
|
1650 if (err!=KErrNone) |
|
1651 return; |
|
1652 info->iLength = 4+4+id.Length(); |
|
1653 TRAP(err, pkt.AllocL(info->iLength)); |
|
1654 if (err!=KErrNone) |
|
1655 { |
|
1656 pkt.FreeInfo(); |
|
1657 return; |
|
1658 } |
|
1659 TUint8* ptr = pkt.First()->Ptr(); |
|
1660 *ptr++ = (TUint8)KPppLcpIdentification; |
|
1661 SetNewId(); |
|
1662 *ptr++ = iDummyPPPRequestId; |
|
1663 BigEndian::Put16(ptr, (TUint16)info->iLength); |
|
1664 BigEndian::Put32(ptr+2, (TUint32)iDummyPPPLocMagicNumber); |
|
1665 pkt.CopyIn(id, 8); |
|
1666 pkt.Pack(); |
|
1667 SendtoPPP(pkt); |
|
1668 } |
|
1669 TInt CDummyPPPLink::Start() |
|
1670 { |
|
1671 CDummyNifLog::Printf(_L("Dummy PPP Link::Start\r\n")); |
|
1672 |
|
1673 //As CreateL is not called before Start calling it here |
|
1674 TRAPD(err, iNifIf->CreateL()); |
|
1675 if (err != KErrNone) |
|
1676 return err; |
|
1677 iState = EDummyPPPLinkOpen; |
|
1678 |
|
1679 iNotify->IfProgress(KLinkLayerOpen, KErrNone); |
|
1680 iNotify->LinkLayerUp(); |
|
1681 |
|
1682 iNifIf->OpenFSM(); |
|
1683 iNifIf->InitRestartCountForConfig(); |
|
1684 //Setting iSendFlowOn to start |
|
1685 iNifIf->SetFlowOnFlag(ETrue); |
|
1686 iNifIf->iProtocol->StartSending((CProtocolBase*)iNifIf); |
|
1687 |
|
1688 return KErrNone; |
|
1689 } |
|
1690 void CDummyPPPIf::CloseFSM() |
|
1691 { |
|
1692 CDummyNifLog::Printf(_L("Dummy PPP Close FSM Request\r\n")); |
|
1693 |
|
1694 //Setting response to PPP state machine |
|
1695 if((iDummyPPPState == EDummyPPPFsmInitial) |
|
1696 ||(iDummyPPPState == EDummyPPPFsmStarting)) |
|
1697 { |
|
1698 //Do nothing |
|
1699 } |
|
1700 if((iDummyPPPState == EDummyPPPFsmClosed) |
|
1701 ||(iDummyPPPState == EDummyPPPFsmClosing)) |
|
1702 { |
|
1703 SetState(EDummyPPPFsmInitial); |
|
1704 } |
|
1705 if((iDummyPPPState == EDummyPPPFsmStopped) |
|
1706 ||(iDummyPPPState == EDummyPPPFsmStopping) |
|
1707 ||(iDummyPPPState == EDummyPPPFsmReqSent) |
|
1708 ||(iDummyPPPState == EDummyPPPFsmAckRecvd) |
|
1709 ||(iDummyPPPState == EDummyPPPFsmAckSent) |
|
1710 ||(iDummyPPPState == EDummyPPPFsmOpened)) |
|
1711 { |
|
1712 SetState(EDummyPPPFsmStarting); |
|
1713 } |
|
1714 } |
|
1715 void CDummyPPPIf::ChangeStateforTimerComplete() |
|
1716 { |
|
1717 |
|
1718 CDummyNifLog::Printf(_L("Dummy PPP Timer Expired %d \r\n"),iDummyPPPRestartCount); |
|
1719 if((iDummyPPPState == EDummyPPPFsmInitial) |
|
1720 ||(iDummyPPPState == EDummyPPPFsmStarting) |
|
1721 ||(iDummyPPPState == EDummyPPPFsmClosed) |
|
1722 ||(iDummyPPPState == EDummyPPPFsmStopped) |
|
1723 ||(iDummyPPPState == EDummyPPPFsmOpened)) |
|
1724 // Bad Event |
|
1725 return; |
|
1726 |
|
1727 if (iDummyPPPRestartCount>0) |
|
1728 { |
|
1729 switch (iDummyPPPState) |
|
1730 { |
|
1731 case EDummyPPPFsmClosing: |
|
1732 case EDummyPPPFsmStopping: |
|
1733 //SendTerminateRequest(); |
|
1734 break; |
|
1735 case EDummyPPPFsmReqSent: |
|
1736 case EDummyPPPFsmAckRecvd: |
|
1737 case EDummyPPPFsmAckSent: |
|
1738 //PG RFC 1661 4.6 double timeout period |
|
1739 //if (iDummyPPPWaitTime*2<KDummyPPPFsmRequestMaxTimeout) |
|
1740 // iDummyPPPWaitTime = iDummyPPPWaitTime*2; |
|
1741 //SendConfigRequest(); |
|
1742 |
|
1743 //if(iDummyPPPState == EDummyPPPFsmAckRecvd) |
|
1744 // SetState(EDummyPPPFsmReqSent); |
|
1745 break; |
|
1746 default: |
|
1747 break; |
|
1748 } |
|
1749 } |
|
1750 else |
|
1751 { |
|
1752 |
|
1753 switch (iDummyPPPState) |
|
1754 { |
|
1755 case EDummyPPPFsmClosing: |
|
1756 SetState(EDummyPPPFsmClosed); |
|
1757 break; |
|
1758 case EDummyPPPFsmStopping: |
|
1759 case EDummyPPPFsmReqSent: |
|
1760 case EDummyPPPFsmAckRecvd: |
|
1761 case EDummyPPPFsmAckSent: |
|
1762 SetState(EDummyPPPFsmStopped); |
|
1763 break; |
|
1764 default: |
|
1765 break; |
|
1766 } |
|
1767 } |
|
1768 |
|
1769 if (iDummyPPPTryCount>0) |
|
1770 SendPapRequest(); |
|
1771 } |
|
1772 |
|
1773 void CDummyPPPLink::TimerComplete(TInt) |
|
1774 { |
|
1775 |
|
1776 CDummyNifLog::Write(_L("DummyPPP Link::TimerComplete()")); |
|
1777 |
|
1778 // |
|
1779 // Upcall from Timer |
|
1780 // |
|
1781 iNifIf->ChangeStateforTimerComplete(); |
|
1782 |
|
1783 //Here while closing down it crashes! |
|
1784 //iNifIf->CloseFSM(); |
|
1785 //iNotify->LinkLayerDown(KErrTimedOut, MNifIfNotify::EDisconnect); |
|
1786 |
|
1787 } |
|
1788 |
|
1789 |
|
1790 void CDummyPPPLink::Stop(TInt aError, MNifIfNotify::TAction aAction) |
|
1791 { |
|
1792 switch (iState) |
|
1793 { |
|
1794 case EDummyPPPLinkClosed: |
|
1795 return; |
|
1796 case EDummyPPPLinkConnecting: |
|
1797 iState = EDummyPPPLinkClosed; |
|
1798 break; |
|
1799 case EDummyPPPLinkOpen: |
|
1800 //iNifIf->PacketModeOff(); |
|
1801 iState = EDummyPPPLinkClosed; |
|
1802 break; |
|
1803 default: |
|
1804 break; |
|
1805 } |
|
1806 CDummyNifLog::Printf(_L("DummyPPP Link::Stop(aError %d, TAction %d)"), aError, aAction); |
|
1807 //Commenting as this has to be conveyed by PPP and not DummyPPP Nif |
|
1808 //iNotify->IfProgress(KLinkLayerClosed, aError); |
|
1809 iNifIf->CloseFSM(); |
|
1810 //Commenting as this has to be conveyed by PPP and not DummyPPP Nif |
|
1811 iNotify->LinkLayerDown(aError, aAction); |
|
1812 |
|
1813 } |
|
1814 |
|
1815 void CDummyPPPLink::IfProgress(TInt /*aResult*/) |
|
1816 { |
|
1817 } |
|
1818 void CDummyPPPIf::BindL(TAny *aId) |
|
1819 { |
|
1820 CDummyNifLog::Printf(_L("BindL(aId %x)\r\n"),aId); |
|
1821 if (iProtocol) |
|
1822 User::Leave(KErrAlreadyExists); |
|
1823 iProtocol = (CProtocolBase*)aId; |
|
1824 } |
|
1825 |
|
1826 void CDummyPPPIf::SetFlowOnFlag(TBool aFlag) |
|
1827 { |
|
1828 CDummyNifLog::Printf(_L("Dummy PPP SetFlowOnFlag\r\n")); |
|
1829 iSendFlowOn = aFlag; |
|
1830 } |
|
1831 |
|
1832 CNifIfBase* CDummyPPPLink::GetBinderL(const TDesC& aName) |
|
1833 { |
|
1834 CDummyNifLog::Printf(_L("DummyPPP LinkGetBinderL(%S)"), &aName); |
|
1835 |
|
1836 iNifIf = new(ELeave) CDummyPPPIf(this); |
|
1837 return iNifIf; |
|
1838 |
|
1839 } |
|
1840 |
|
1841 TInt CDummyPPPLink::Notification(TAgentToNifEventType aEvent,void* aInfo) |
|
1842 { |
|
1843 CDummyNifLog::Printf(_L("Dummy PPP LinkNotification\r\n")); |
|
1844 if ((aEvent!=EAgentToNifEventTypeDisableTimers) |
|
1845 || (aInfo!=NULL)) |
|
1846 return KErrUnknown; |
|
1847 return KErrNone; |
|
1848 } |
|
1849 |
|
1850 void CDummyPPPLink::Restart(CNifIfBase*) |
|
1851 {} |
|
1852 |
|
1853 CDummyPPPIf::CDummyPPPIf(CDummyPPPLink* aLink) |
|
1854 : CNifIfBase(*aLink) |
|
1855 { |
|
1856 CDummyNifLog::Printf(_L("DummyPPP Constructed")); |
|
1857 |
|
1858 //__DECLARE_FSM_NAME(_S("DUMMY_PPP FSM")); |
|
1859 |
|
1860 iLink = aLink; |
|
1861 |
|
1862 //Settings for flow control |
|
1863 iSendLoWat = KLoWatMark; |
|
1864 iSendHiWat = KHiWatMark; |
|
1865 |
|
1866 // generate my local ip address (ip4) - vals potentially will be overwritten by any derived classes |
|
1867 iLocalAddress = KDummyPppNifLocalAddressBase;//0x0A220C1BB; //+ ((TUint32)this)%255; |
|
1868 |
|
1869 //For IPCP Nego. |
|
1870 //PresetAddr(iLocalAddr, TPtrC(KCDTypeNameIpAddr)); |
|
1871 iLocalAddr = iLocalAddress; |
|
1872 |
|
1873 //PresetAddr(iPrimaryDns, TPtrC(KCDTypeNameIpNameServer1)); |
|
1874 //PresetAddr(iSecondaryDns, TPtrC(KCDTypeNameIpNameServer2)); |
|
1875 //iPrimaryNbns = IPADDR(0,0,0,0); |
|
1876 //iSecondaryNbns = IPADDR(0,0,0,0); |
|
1877 //PresetAddr(iNetworkMask, TPtrC(KCDTypeNameIpNetMask)); |
|
1878 |
|
1879 // need to give each if a unique id so we will number and count them as we create them |
|
1880 //++iNumOfIfs; |
|
1881 //iIfNum = iNumOfIfs; |
|
1882 |
|
1883 //Even if this is given, when the identification command for the nif is given |
|
1884 //it always turns up as a ipcp.comm as PPP Nif gives the information overlooking this. |
|
1885 iIfName.Format(_L("dummypppnif[0x%08x]"), this); |
|
1886 |
|
1887 |
|
1888 |
|
1889 } |
|
1890 TInt CDummyPPPIf::PresetAddr(TUint32& aAddr, const TDesC& aVarName) |
|
1891 /** |
|
1892 * Preset IP adress in aAddr with value from CommDB. The field name |
|
1893 * is given in aVarName. Examples are "IpAddr" and "IpNameServer1" |
|
1894 * |
|
1895 * @param aAddr IP address to be set |
|
1896 * @param aVarName name of CommDB field |
|
1897 * @return KErrNone if success, global error code otherwise |
|
1898 */ |
|
1899 { |
|
1900 if (aAddr!=0) |
|
1901 return KErrNone; |
|
1902 |
|
1903 TBuf<KCommsDbSvrMaxFieldLength> name; |
|
1904 TInetAddr addr; |
|
1905 |
|
1906 |
|
1907 (void)iNotify->ReadDes(aVarName, name); // ignore return value |
|
1908 |
|
1909 const TInt ret = addr.Input(name); |
|
1910 if (ret==KErrNone) |
|
1911 aAddr = addr.Address(); |
|
1912 |
|
1913 return ret; |
|
1914 } |
|
1915 |
|
1916 |
|
1917 void CDummyPPPIf::Info(TNifIfInfo& aInfo) const |
|
1918 { |
|
1919 CDummyNifLog::Printf(_L("Dummy PPP Info\r\n")); |
|
1920 aInfo.iVersion = TVersion(1,1,1); |
|
1921 aInfo.iFlags = KNifIfIsBase | KNifIfUsesNotify | KNifIfCreatedByLink; |
|
1922 aInfo.iName.Copy(iIfName); |
|
1923 aInfo.iProtocolSupported = 0; |
|
1924 } |
|
1925 |
|
1926 void CDummyPPPLink::FillInInfo(TNifIfInfo& aInfo, TAny* aPtr) |
|
1927 { |
|
1928 aInfo.iProtocolSupported=0; |
|
1929 aInfo.iVersion = TVersion(1,1,1); |
|
1930 aInfo.iFlags = KNifIfIsBase | KNifIfIsLink | KNifIfUsesNotify | KNifIfCreatedByFactory; |
|
1931 aInfo.iName = _L("dummyppplink"); |
|
1932 aInfo.iName.AppendFormat(_L("[0x%08x]"), aPtr); |
|
1933 aInfo.iFlags |= KNifIfCreatesBinder; |
|
1934 } |
|
1935 |
|
1936 void CDummyPPPLink::Info(TNifIfInfo& aInfo) const |
|
1937 { |
|
1938 FillInInfo(aInfo,(TAny*) this); |
|
1939 CDummyNifLog::Printf(_L("Dummy PPP LinkInfo\r\n")); |
|
1940 } |
|
1941 |
|
1942 TInt CDummyPPPIf::Control(TUint aLevel, TUint aName, TDes8& aOption, TAny* /* aSource */) |
|
1943 { |
|
1944 CDummyNifLog::Printf(_L("DummyPPP::Control(aLevel %x, aName %x, ...)"), aLevel, aName); |
|
1945 |
|
1946 if (aLevel==KSOLInterface) |
|
1947 { |
|
1948 switch (aName) |
|
1949 { |
|
1950 case KSoIfInfo: |
|
1951 { |
|
1952 TSoIfInfo& opt = *(TSoIfInfo*)aOption.Ptr(); |
|
1953 |
|
1954 _LIT(KName, "MyName"); |
|
1955 opt.iName.Copy(KName); |
|
1956 opt.iFeatures = KIfCanBroadcast | KIfCanMulticast; |
|
1957 opt.iMtu = 1500; |
|
1958 opt.iSpeedMetric = 0; |
|
1959 return KErrNone; |
|
1960 } |
|
1961 |
|
1962 case KSoIfHardwareAddr: |
|
1963 return KErrNotSupported; |
|
1964 |
|
1965 case KSoIfConfig: |
|
1966 { |
|
1967 TSoInetIfConfig& opt = *(TSoInetIfConfig*)aOption.Ptr(); |
|
1968 if (opt.iFamily!=KAfInet) |
|
1969 return KErrNotSupported; |
|
1970 |
|
1971 TUint32 address; |
|
1972 const TInt KPort = 65; |
|
1973 |
|
1974 opt.iConfig.iAddress.SetAddress(iLocalAddress); |
|
1975 opt.iConfig.iAddress.SetPort(KPort); |
|
1976 |
|
1977 // network mask |
|
1978 opt.iConfig.iNetMask.Input(KNetworkMask); |
|
1979 opt.iConfig.iNetMask.SetPort(KPort); |
|
1980 |
|
1981 // broadcast address |
|
1982 address = KDummyPppNifLocalAddressBase + KBroadcastAddressSuffix; |
|
1983 opt.iConfig.iBrdAddr.SetAddress(address); |
|
1984 opt.iConfig.iBrdAddr.SetPort(KPort); |
|
1985 |
|
1986 // default gateway |
|
1987 address = KDummyPppNifLocalAddressBase + KDefaultGatewayAddressSuffix; |
|
1988 opt.iConfig.iDefGate.SetAddress(address); |
|
1989 opt.iConfig.iDefGate.SetPort(KPort); |
|
1990 |
|
1991 // primary DNS, just make same as default gateway |
|
1992 opt.iConfig.iNameSer1.SetAddress(address); |
|
1993 opt.iConfig.iNameSer1.SetPort(KPort); |
|
1994 |
|
1995 // secondary DNS |
|
1996 address = KDummyPppNifLocalAddressBase + KSecondaryDnsAddressSuffix; |
|
1997 opt.iConfig.iNameSer2.SetAddress(address); |
|
1998 opt.iConfig.iNameSer2.SetPort(KPort); |
|
1999 |
|
2000 return KErrNone; |
|
2001 } |
|
2002 |
|
2003 case KSoIfGetConnectionInfo: |
|
2004 TSoIfConnectionInfo& opt = *(TSoIfConnectionInfo*)aOption.Ptr(); |
|
2005 TInt err = KErrNone; |
|
2006 TBuf<2*KCommsDbSvrMaxColumnNameLength+1> fieldName; |
|
2007 _LIT(KSlashChar, "\\"); |
|
2008 |
|
2009 fieldName.Copy(TPtrC(KCDTypeNameIAP)); |
|
2010 fieldName.Append(KSlashChar); |
|
2011 fieldName.Append(TPtrC(KCDTypeNameRecordTag)); |
|
2012 if ((err = iNotify->ReadInt(fieldName, opt.iIAPId)) != KErrNone) |
|
2013 return err; |
|
2014 |
|
2015 fieldName.Copy(TPtrC(IAP)); |
|
2016 fieldName.Append(KSlashChar); |
|
2017 fieldName.Append(TPtrC(KCDTypeNameIAPNetwork)); |
|
2018 if ((err = iNotify->ReadInt(fieldName, opt.iNetworkId)) != KErrNone) |
|
2019 return err; |
|
2020 |
|
2021 return KErrNone; |
|
2022 } |
|
2023 } |
|
2024 return KErrNotSupported; |
|
2025 } |
|
2026 |
|
2027 TInt CDummyPPPIf::Notification(TAgentToNifEventType /*aEvent*/, void * /*aInfo*/) |
|
2028 { |
|
2029 CDummyNifLog::Printf(_L("Dummy PPP Notification\r\n")); |
|
2030 return KErrNone; |
|
2031 } |
|
2032 |
|
2033 void CDummyNifLog::Write(const TDesC& aDes) |
|
2034 // |
|
2035 // Write aText to the log |
|
2036 // |
|
2037 { |
|
2038 #ifndef __FLOG_ACTIVE |
|
2039 (void)aDes; |
|
2040 #else |
|
2041 __FLOG_STATIC0(KDummyPppLogFolder, KDummyPppLogFile, aDes); |
|
2042 #endif |
|
2043 } |
|
2044 |
|
2045 void CDummyNifLog::Printf(TRefByValue<const TDesC> aFmt,...) |
|
2046 // |
|
2047 // Write a mulitple argument list to the log, trapping and ignoring any leave |
|
2048 // |
|
2049 { |
|
2050 #ifndef __FLOG_ACTIVE |
|
2051 (void)aFmt; |
|
2052 #else |
|
2053 VA_LIST list; |
|
2054 VA_START(list, aFmt); |
|
2055 |
|
2056 TBuf <1024> LineBuf; |
|
2057 LineBuf.AppendFormatList( aFmt, list); |
|
2058 |
|
2059 __FLOG_STATIC0(KDummyPppLogFolder, KDummyPppLogFile, LineBuf); |
|
2060 #endif // #ifdef __FLOG_ACTIVE |
|
2061 } |
|
2062 |
|
2063 void CDummyNifLog::HexDump(const TText* aHeader, const TText* aMargin, const TUint8* aPtr, TInt aLen, TInt aWidth) |
|
2064 { |
|
2065 TBuf<0x100> buf; |
|
2066 TInt i = 0; |
|
2067 const TText* p = aHeader; |
|
2068 while (aLen>0) |
|
2069 { |
|
2070 TInt n = aLen>aWidth ? aWidth : aLen; |
|
2071 if (p!=NULL) |
|
2072 { |
|
2073 _LIT(string1,"%s%04x : "); |
|
2074 buf.AppendFormat(string1, p, i); |
|
2075 } |
|
2076 TInt j; |
|
2077 _LIT(string2,"%02x "); |
|
2078 for (j=0; j<n; j++) |
|
2079 buf.AppendFormat(string2, aPtr[i+j]); |
|
2080 _LIT(string3," "); |
|
2081 while (j++<KHexDumpWidth) |
|
2082 buf.Append(string3); |
|
2083 _LIT(string4," "); |
|
2084 buf.Append(string4); |
|
2085 _LIT(string5,"%c"); |
|
2086 for (j=0; j<n; j++) |
|
2087 buf.AppendFormat(string5, aPtr[i+j]<32 || aPtr[i+j]>126 ? '.' : aPtr[i+j]); |
|
2088 buf.Append(KEndOfLine); |
|
2089 Write(buf); |
|
2090 buf.SetLength(0); |
|
2091 aLen -= n; |
|
2092 i += n; |
|
2093 p = aMargin; |
|
2094 } |
|
2095 } |
|
2096 |
|
2097 |
|
2098 |
|
2099 void CDummyPPPIf::CreateL() |
|
2100 { |
|
2101 CDummyNifLog::Printf(_L("Dummy PPP CreateL")); |
|
2102 logUser = new(ELeave) CDummyNifLog; |
|
2103 TCallBack scb(SendCallBack, this); |
|
2104 iSendCallBack = new(ELeave) CAsyncCallBack(scb, KDummyPPPSendPriority); |
|
2105 } |
|
2106 |
|
2107 void CDummyPPPIf::OpenFSM() |
|
2108 { |
|
2109 logUser->Printf(_L("Open FSM Request\r\n")); |
|
2110 |
|
2111 iDummyPPPMaxFailureCount = KDummyPPPMaxRestartConfig; |
|
2112 |
|
2113 if(iDummyPPPState == EDummyPPPFsmInitial) |
|
2114 { |
|
2115 SetState(EDummyPPPFsmStarting); |
|
2116 TRAPD(err, InitialiseConfigRequestL()); |
|
2117 if (err==KErrNone) |
|
2118 SendConfigRequest(); |
|
2119 SetState(EDummyPPPFsmReqSent); |
|
2120 } |
|
2121 } |
|
2122 |
|
2123 void CDummyPPPIf::CloseLog() |
|
2124 { |
|
2125 logUser->Printf(_L("Dummy PPP CloseLog\r\n")); |
|
2126 delete logUser; |
|
2127 } |
|
2128 void CDummyPPPIf::End() |
|
2129 { |
|
2130 CDummyNifLog::Printf(_L("Dummy PPP End\r\n")); |
|
2131 ipktRecvPPP.Free(); |
|
2132 delete iSendCallBack; |
|
2133 iSendCallBack = NULL; |
|
2134 } |
|
2135 |
|
2136 //The following code is for logs only |
|
2137 const TText* CDummyNifLog::StateToText(TDummyPPPToPPPFsmState aState) |
|
2138 { |
|
2139 |
|
2140 // States |
|
2141 switch (aState) |
|
2142 { |
|
2143 case EDummyPPPFsmInitial: |
|
2144 return _S("INITIAL"); |
|
2145 case EDummyPPPFsmStarting: |
|
2146 return _S("STARTING"); |
|
2147 case EDummyPPPFsmClosed: |
|
2148 return _S("CLOSED"); |
|
2149 case EDummyPPPFsmStopped: |
|
2150 return _S("STOPPED"); |
|
2151 case EDummyPPPFsmStopping: |
|
2152 return _S("STOPPING"); |
|
2153 case EDummyPPPFsmClosing: |
|
2154 return _S("CLOSING"); |
|
2155 case EDummyPPPFsmReqSent: |
|
2156 return _S("REQUEST SENT"); |
|
2157 case EDummyPPPFsmAckRecvd: |
|
2158 return _S("ACK RECEIVED"); |
|
2159 case EDummyPPPFsmAckSent: |
|
2160 return _S("ACK SENT"); |
|
2161 case EDummyPPPFsmOpened: |
|
2162 return _S("OPENED"); |
|
2163 case EDummyPPPFsmPapAuthReqSent: |
|
2164 return _S("PAP REQUEST SENT"); |
|
2165 case EDummyPPPFsmPapAuthAckRecvd: |
|
2166 return _S("PAP ACK RECEIVED"); |
|
2167 case EDummyPPPFsmPapAckSent: |
|
2168 return _S("PAP ACK SENT"); |
|
2169 case EDummyPPPIPCPReqSent: |
|
2170 return _S("IPCP REQUEST SENT"); |
|
2171 case EDummyPPPFsmIPOpen: |
|
2172 return _S("IP OPENED"); |
|
2173 default: // Should never happen in theory! |
|
2174 return _S("UNKNOWN"); |
|
2175 } |
|
2176 } |
|
2177 |
|
2178 |
|
2179 const TText* CDummyNifLog::LcpCodeToText(TUint aValue) |
|
2180 { |
|
2181 |
|
2182 // LCP Codes |
|
2183 switch (aValue) |
|
2184 { |
|
2185 case KPppLcpEchoRequest: |
|
2186 return _S("Echo request"); |
|
2187 case KPppLcpEchoReply: |
|
2188 return _S("Echo reply"); |
|
2189 case KPppLcpDiscardRequest: |
|
2190 return _S("Discard request"); |
|
2191 case KPppLcpIdentification: |
|
2192 return _S("Identification"); |
|
2193 case KPppLcpTimeRemaining: |
|
2194 return _S("Time remaining"); |
|
2195 default: |
|
2196 return FsmCodeToText(aValue); |
|
2197 } |
|
2198 } |
|
2199 |
|
2200 const TText* CDummyNifLog::FsmCodeToText(TUint aValue) |
|
2201 { |
|
2202 |
|
2203 // LCP Codes |
|
2204 switch (aValue) |
|
2205 { |
|
2206 case KPppLcpConfigRequest: |
|
2207 return _S("Config Request"); |
|
2208 case KPppLcpConfigAck: |
|
2209 return _S("Config ACK"); |
|
2210 case KPppLcpConfigNak: |
|
2211 return _S("Config NAK"); |
|
2212 case KPppLcpConfigReject: |
|
2213 return _S("Config Reject"); |
|
2214 case KPppLcpTerminateRequest: |
|
2215 return _S("Terminate request"); |
|
2216 case KPppLcpTerminateAck: |
|
2217 return _S("Terminate ACK"); |
|
2218 case KPppLcpCodeReject: |
|
2219 return _S("Code Reject"); |
|
2220 case KPppLcpProtocolReject: |
|
2221 return _S("Protocol Reject"); |
|
2222 case KPppCcpResetReq: |
|
2223 // Only used by CCP, but this is the easiest place to put it |
|
2224 return _S("Reset Request"); |
|
2225 case KPppCcpResetAck: |
|
2226 // Only used by CCP, but this is the easiest place to put it |
|
2227 //__DEBUGGER(); |
|
2228 return _S("Reset Ack"); |
|
2229 default: |
|
2230 return _S("Unknown"); |
|
2231 } |
|
2232 } |
|
2233 |
|
2234 const TText* CDummyNifLog::PapCodeToText(TUint aValue) |
|
2235 { |
|
2236 |
|
2237 // PAP Codes |
|
2238 switch (aValue) |
|
2239 { |
|
2240 case 1: |
|
2241 return _S("Authenticate Request"); |
|
2242 case 2: |
|
2243 return _S("Authenticate ACK"); |
|
2244 case 3: |
|
2245 return _S("Authenticate NAK"); |
|
2246 default: |
|
2247 return _S("Unknown"); |
|
2248 } |
|
2249 } |
|
2250 |
|
2251 const TText* CDummyNifLog::CbcpCodeToText(TUint aValue) |
|
2252 { |
|
2253 |
|
2254 // CHAP Codes |
|
2255 switch (aValue) |
|
2256 { |
|
2257 case 1: |
|
2258 return _S("Callback Request"); |
|
2259 case 2: |
|
2260 return _S("Callback Response"); |
|
2261 case 3: |
|
2262 return _S("Callback Ack"); |
|
2263 default: |
|
2264 return _S("Unknown"); |
|
2265 } |
|
2266 } |
|
2267 |
|
2268 const TText* CDummyNifLog::ChapCodeToText(TUint aValue) |
|
2269 { |
|
2270 |
|
2271 // CHAP Codes |
|
2272 switch (aValue) |
|
2273 { |
|
2274 case 1: |
|
2275 return _S("Challenge"); |
|
2276 case 2: |
|
2277 return _S("Response"); |
|
2278 case 3: |
|
2279 return _S("Success"); |
|
2280 case 4: |
|
2281 return _S("Failure"); |
|
2282 default: |
|
2283 return _S("Unknown"); |
|
2284 } |
|
2285 } |
|
2286 |
|
2287 const TText* CDummyNifLog::IpProtocolToText(TUint aValue) |
|
2288 { |
|
2289 |
|
2290 // IP Protocols |
|
2291 switch (aValue) |
|
2292 { |
|
2293 case 1: |
|
2294 return _S("ICMP"); |
|
2295 case 58: |
|
2296 return _S("ICMPv6"); |
|
2297 case 17: |
|
2298 return _S("UDP"); |
|
2299 case 6: |
|
2300 return _S("TCP"); |
|
2301 |
|
2302 default: |
|
2303 return _S("Unknown"); |
|
2304 } |
|
2305 } |
|
2306 |
|
2307 const TText* CDummyNifLog::IpcpCodeToText(TUint aValue) |
|
2308 { |
|
2309 |
|
2310 // IPCP Codes |
|
2311 switch (aValue) |
|
2312 { |
|
2313 case KPppIpcpOptIpAddresses: |
|
2314 return _S("IP Addresses"); |
|
2315 case KPppIpcpOptIpCompressionProtocol: |
|
2316 return _S("IP Compression Protocol"); |
|
2317 case KPppIpcpOptIpAddress: |
|
2318 return _S("IP Address"); |
|
2319 case KPppIpcpOptPrimaryDnsAddress: |
|
2320 return _S("Primary DNS Address"); |
|
2321 case KPppIpcpOptSecondaryDnsAddress: |
|
2322 return _S("Secondary DNS Address"); |
|
2323 case KPppIpcpOptPrimaryNbnsAddress: |
|
2324 return _S("Primary NBNS Address"); |
|
2325 case KPppIpcpOptSecondaryNbnsAddress: |
|
2326 return _S("Secondary NBNS Address"); |
|
2327 default: |
|
2328 return _S("Unknown"); |
|
2329 } |
|
2330 } |
|
2331 |
|
2332 const TText* CDummyNifLog::Ip6cpCodeToText(TUint aValue) |
|
2333 { |
|
2334 // IP6CP Codes |
|
2335 switch (aValue) |
|
2336 { |
|
2337 case KPppIp6cpOptInterfaceIdentifier: |
|
2338 return _S("Interface Identifier"); |
|
2339 case KPppIp6cpOptCompressionProtocol: |
|
2340 return _S("Compression Protocol"); |
|
2341 default: |
|
2342 return _S("Unknown"); |
|
2343 } |
|
2344 } |
|
2345 const TText* CDummyNifLog::CcpCodeToText(TUint aValue) |
|
2346 { |
|
2347 |
|
2348 // CCP Codes |
|
2349 switch (aValue) |
|
2350 { |
|
2351 case KPppCcpOptOui: |
|
2352 return _S("OUI"); |
|
2353 case KPppCcpOptPred1: |
|
2354 return _S("Predictor type1"); |
|
2355 case KPppCcpOptPred2: |
|
2356 return _S("Predictor type2"); |
|
2357 case KPppCcpOptPuddle: |
|
2358 return _S("Puddle"); |
|
2359 case KPppCcpOptHP: |
|
2360 return _S("HP PPC"); |
|
2361 case KPppCcpOptStac: |
|
2362 return _S("Stac LZS"); |
|
2363 case KPppCcpOptMsoft: |
|
2364 return _S("Microsoft PPC"); |
|
2365 case KPppCcpOptGandalf: |
|
2366 return _S("Gandalf"); |
|
2367 case KPppCcpOptV42bis: |
|
2368 return _S("V42bis"); |
|
2369 case KPppCcpOptReserved: |
|
2370 return _S("Reserved"); |
|
2371 case 4: |
|
2372 case 5: |
|
2373 case 6: |
|
2374 case 7: |
|
2375 case 8: |
|
2376 case 9: |
|
2377 case 10: |
|
2378 case 11: |
|
2379 case 12: |
|
2380 case 13: |
|
2381 case 14: |
|
2382 case 15: |
|
2383 return _S("unassigned"); |
|
2384 default: |
|
2385 return _S("Unknown"); |
|
2386 } |
|
2387 } |
|
2388 |
|
2389 |
|
2390 TInt CDummyNifLog::DumpLcp(TPtrC8& aDes) |
|
2391 { |
|
2392 |
|
2393 TUint8* ptr = (TUint8*)aDes.Ptr(); |
|
2394 TUint8 code = *ptr++; |
|
2395 TUint8 id = *ptr++; |
|
2396 TInt len = BigEndian::Get16(ptr); |
|
2397 if(len>aDes.Length()) |
|
2398 { |
|
2399 Printf(_L("WARNING: Length reported in header was more than actual frame length\n")); |
|
2400 return len; |
|
2401 } |
|
2402 else if (len<aDes.Length()) |
|
2403 Printf(_L("WARNING: Length reported in header was less than actual frame length!\n")); |
|
2404 |
|
2405 ptr += 2; |
|
2406 aDes.Set(ptr, aDes.Length()-4); |
|
2407 |
|
2408 Printf(KCodeTextString, LcpCodeToText(code), code); |
|
2409 Printf(KIdentifierLengthString, id, len); |
|
2410 |
|
2411 switch (code) |
|
2412 { |
|
2413 case KPppLcpConfigRequest: |
|
2414 case KPppLcpConfigAck: |
|
2415 case KPppLcpConfigNak: |
|
2416 case KPppLcpConfigReject: |
|
2417 { |
|
2418 TInt n = len-4; |
|
2419 TInt tmp = 0; |
|
2420 while (n>0 && aDes.Length()>0) |
|
2421 { |
|
2422 tmp = DumpLcpOption(aDes); |
|
2423 if (tmp == 0) //Check for an error in the DumpLcpOption (0 is interpreted as an error) |
|
2424 { |
|
2425 Printf(_L("WARNING: Length reported in LCP Option was incorrect! Dumping data instead\n")); |
|
2426 DumpBytes(EIGHT_SPACE_MARGIN, ptr, len-4); |
|
2427 break; |
|
2428 } |
|
2429 n=n-tmp; |
|
2430 } |
|
2431 |
|
2432 if (n>0) |
|
2433 Printf(KBytesRemainingString, n, (n>1)?"s":""); |
|
2434 } |
|
2435 |
|
2436 break; |
|
2437 case KPppLcpTerminateRequest: |
|
2438 case KPppLcpTerminateAck: |
|
2439 { |
|
2440 if (len>4) |
|
2441 DumpBytes(EIGHT_SPACE_MARGIN, ptr, len-4); |
|
2442 } |
|
2443 break; |
|
2444 case KPppLcpCodeReject: |
|
2445 { |
|
2446 TUint val = *ptr; |
|
2447 Printf(KCodeString, val); |
|
2448 } |
|
2449 break; |
|
2450 case KPppLcpProtocolReject: |
|
2451 { |
|
2452 TUint val = BigEndian::Get16(ptr); |
|
2453 Printf(KProtocolString, val); |
|
2454 } |
|
2455 break; |
|
2456 case KPppLcpEchoRequest: |
|
2457 { |
|
2458 TUint val = BigEndian::Get32(ptr); |
|
2459 Printf(KNumberString, val); |
|
2460 if (len>0) |
|
2461 DumpBytes(EIGHT_SPACE_MARGIN, ptr+4, len-8); |
|
2462 } |
|
2463 break; |
|
2464 case KPppLcpEchoReply: |
|
2465 { |
|
2466 TUint val = BigEndian::Get32(ptr); |
|
2467 Printf(KNumberString, val); |
|
2468 if (len>0) |
|
2469 DumpBytes(EIGHT_SPACE_MARGIN, ptr+4, len-8); |
|
2470 } |
|
2471 break; |
|
2472 case KPppLcpDiscardRequest: |
|
2473 { |
|
2474 TUint val = BigEndian::Get32(ptr); |
|
2475 Printf(KNumberString, val); |
|
2476 if (len>0) |
|
2477 DumpBytes(EIGHT_SPACE_MARGIN, ptr+4, len-8); |
|
2478 } |
|
2479 break; |
|
2480 case KPppLcpIdentification: |
|
2481 { |
|
2482 TUint val = BigEndian::Get32(ptr); |
|
2483 Printf(KNumberString, val); |
|
2484 if (len>0) |
|
2485 DumpBytes(EIGHT_SPACE_MARGIN, ptr+4, len-8); |
|
2486 } |
|
2487 break; |
|
2488 case KPppLcpTimeRemaining: |
|
2489 { |
|
2490 TUint val = BigEndian::Get32(ptr); |
|
2491 ptr+=4; |
|
2492 Printf(KNumberString, val); |
|
2493 val = BigEndian::Get32(ptr); |
|
2494 Printf(KSecondsString, val); |
|
2495 } |
|
2496 break; |
|
2497 default: |
|
2498 break; |
|
2499 } |
|
2500 |
|
2501 return len; |
|
2502 } |
|
2503 |
|
2504 TInt CDummyNifLog::DumpLcpOption(TPtrC8& aDes) |
|
2505 { |
|
2506 |
|
2507 TUint8* ptr = (TUint8*)aDes.Ptr(); |
|
2508 TUint8 opt = *ptr++; |
|
2509 TUint8 len = *ptr++; |
|
2510 |
|
2511 if(len > aDes.Length()) |
|
2512 { |
|
2513 Printf(_L("WARNING: Length reported in option header was more than actual frame length\n")); |
|
2514 return 0; //Return an incorrect length to flag this error. |
|
2515 } |
|
2516 |
|
2517 if(len < 2) |
|
2518 { |
|
2519 Printf(_L("WARNING: Length reported in option header was less than a correct frame length\n")); |
|
2520 return 0; //Return an incorrect length. (the minimum correct length of an option is 2) |
|
2521 } |
|
2522 |
|
2523 Printf(KLcpCodeString, LcpOptToText(opt), opt); |
|
2524 Printf(KLengthString, len); |
|
2525 |
|
2526 switch (opt) |
|
2527 { |
|
2528 case KPppLcpOptMaxRecvUnit: |
|
2529 { |
|
2530 TUint val = BigEndian::Get16(ptr); |
|
2531 Printf(KSizeString, val); |
|
2532 } |
|
2533 break; |
|
2534 case KPppLcpOptEscapeCharMap: |
|
2535 { |
|
2536 TUint val = BigEndian::Get32(ptr); |
|
2537 Printf(KMapString, val); |
|
2538 } |
|
2539 break; |
|
2540 case KPppLcpOptAuthenticationProtocol: |
|
2541 { |
|
2542 TUint val = BigEndian::Get16(ptr); |
|
2543 |
|
2544 Printf(KProtocolTextString, ProtocolToText(val), val); |
|
2545 if (val != KPppIdChap) |
|
2546 { |
|
2547 if (len>4) |
|
2548 DumpBytes(EIGHT_SPACE_MARGIN, ptr+2, len-4); |
|
2549 } |
|
2550 else |
|
2551 { |
|
2552 if(len>4) |
|
2553 DumpChapType(ptr+2); |
|
2554 } |
|
2555 } |
|
2556 break; |
|
2557 case KPppLcpOptQualityProtocol: |
|
2558 { |
|
2559 TUint val = BigEndian::Get16(ptr); |
|
2560 Printf(KProtocolTextString, ProtocolToText(val), val); |
|
2561 if (len>4) |
|
2562 DumpBytes(EIGHT_SPACE_MARGIN, ptr+2, len-4); |
|
2563 } |
|
2564 break; |
|
2565 case KPppLcpOptMagicNumber: |
|
2566 { |
|
2567 TUint val = BigEndian::Get32(ptr); |
|
2568 Printf(KNumberString, val); |
|
2569 } |
|
2570 break; |
|
2571 case KPppLcpOptProtocolCompress: |
|
2572 case KPppLcpOptAddrCtrlCompress: |
|
2573 break; |
|
2574 case KPppLcpOptFcsType: |
|
2575 { |
|
2576 TUint val = *ptr++; |
|
2577 //only for display |
|
2578 //Printf(KLcpOptFcsTypeString, (val&KPppDummyPPPFcs0Flag)?_S(" None"):_S(""), (val&KPppDummyPPPFcs16Flag)?_S(" 16 bit"):_S(""), (val&KPppDummyPPPFcs32Flag)?_S(" 32 bit"):_S("")); |
|
2579 Printf(KLcpOptFcsTypeString, val?_S(" None"):_S("")); |
|
2580 } |
|
2581 break; |
|
2582 case KPppLcpOptPadding: |
|
2583 { |
|
2584 TUint val = *ptr++; |
|
2585 Printf(KMaximumBytesString, val); |
|
2586 } |
|
2587 break; |
|
2588 case KPppLcpOptCallback: |
|
2589 { |
|
2590 TUint val = *ptr++; |
|
2591 Printf(KCodeTextString, CallbackOpToText(val), val); |
|
2592 if (len>3) |
|
2593 DumpBytes(EIGHT_SPACE_MARGIN, ptr+3, len-3); |
|
2594 } |
|
2595 break; |
|
2596 case KPppLcpOptCompoundFrames: |
|
2597 break; |
|
2598 } |
|
2599 aDes.Set((TUint8*)aDes.Ptr()+len, aDes.Length()-len); |
|
2600 return len; |
|
2601 } |
|
2602 |
|
2603 TInt CDummyNifLog::DumpPap(TPtrC8& aDes) |
|
2604 { |
|
2605 |
|
2606 TUint8* ptr = (TUint8*)aDes.Ptr(); |
|
2607 TUint8 code = *ptr++; |
|
2608 TUint8 id = *ptr++; |
|
2609 TInt len = BigEndian::Get16(ptr); |
|
2610 ptr += 2; |
|
2611 |
|
2612 Printf(KCodeTextString, PapCodeToText(code), code); |
|
2613 Printf(KIdentifierLengthString, id, len); |
|
2614 |
|
2615 if (code==1) |
|
2616 { |
|
2617 TInt n = *ptr++; |
|
2618 TPtrC8 v; |
|
2619 v.Set(ptr, n); ptr += n; |
|
2620 TBuf16<KLogBufferSize> temp; |
|
2621 temp.Copy(v.Left(Min(v.Length(),KLogBufferSize))); |
|
2622 Printf(KUserNameString, &temp); |
|
2623 n = *ptr++; |
|
2624 v.Set(ptr, n); ptr += n; |
|
2625 temp.Copy(v.Left(Min(v.Length(),KLogBufferSize))); |
|
2626 Printf(KPasswordString, &temp); |
|
2627 } |
|
2628 else if (code==2 || code==3) |
|
2629 { |
|
2630 TInt n = *ptr++; |
|
2631 TPtrC8 v; |
|
2632 v.Set(ptr, n); ptr += n; |
|
2633 TBuf16<KLogBufferSize> temp; |
|
2634 temp.Copy(v.Left(Min(v.Length(),KLogBufferSize))); |
|
2635 Printf(KMessageString, &temp); |
|
2636 } |
|
2637 |
|
2638 aDes.Set(aDes.Ptr()+len, aDes.Length()-len); |
|
2639 return len; |
|
2640 } |
|
2641 |
|
2642 TInt CDummyNifLog::DumpCbcp(TPtrC8& aDes) |
|
2643 { |
|
2644 |
|
2645 TUint8* ptr = (TUint8*)aDes.Ptr(); |
|
2646 TUint8 code = *ptr++; |
|
2647 TUint8 id = *ptr++; |
|
2648 TInt len = BigEndian::Get16(ptr); |
|
2649 TInt length = len; |
|
2650 ptr += 2; |
|
2651 |
|
2652 Printf(KCodeTextString, CbcpCodeToText(code), code); |
|
2653 Printf(KIdentifierLengthString, id, len); |
|
2654 |
|
2655 // |
|
2656 // OK we can be offered many options at once, so |
|
2657 // loop for the length and decode them. |
|
2658 // |
|
2659 len -= 4; // Subtract the stuff we know about |
|
2660 |
|
2661 TUint8 type; |
|
2662 TUint typeLen; |
|
2663 while (len) |
|
2664 { |
|
2665 // Yes I know we can have a permanent loop but I just don't care |
|
2666 type = *ptr++; |
|
2667 switch(type) |
|
2668 { |
|
2669 case 1: |
|
2670 { |
|
2671 _LIT(string1," No CallBack\n"); |
|
2672 Write(string1); |
|
2673 } |
|
2674 break; |
|
2675 case 2: |
|
2676 { |
|
2677 _LIT(string2," Callback to a user specified No.\n"); |
|
2678 Write(string2); |
|
2679 } |
|
2680 break; |
|
2681 case 3: |
|
2682 { |
|
2683 _LIT(string3," Callback to a pre specified No.\n"); |
|
2684 Write(string3); |
|
2685 } |
|
2686 break; |
|
2687 case 4: |
|
2688 { |
|
2689 _LIT(string4," Callback to one of a list of numbers\n"); |
|
2690 Write(string4); |
|
2691 } |
|
2692 break; |
|
2693 default: |
|
2694 { |
|
2695 _LIT(string5," Unknown Callback type\n"); |
|
2696 Write(string5); |
|
2697 } |
|
2698 break; |
|
2699 } |
|
2700 |
|
2701 if (len == 1) |
|
2702 len = 0; |
|
2703 |
|
2704 typeLen = *ptr++; |
|
2705 Printf(KLengthString,typeLen); |
|
2706 |
|
2707 if (typeLen > 2) |
|
2708 Printf(KDelayString,*ptr++); |
|
2709 |
|
2710 if (typeLen > 3) |
|
2711 { |
|
2712 // |
|
2713 // Dump the Address Type field |
|
2714 // |
|
2715 if (*ptr++ == 1) |
|
2716 { |
|
2717 _LIT(string6," PSTN/ISDN\n"); |
|
2718 Write(string6); |
|
2719 } |
|
2720 else |
|
2721 { |
|
2722 _LIT(string7," Other\n"); |
|
2723 Write(string7); |
|
2724 } |
|
2725 } |
|
2726 |
|
2727 // |
|
2728 // Dump the NULL terminated ASCII string |
|
2729 // |
|
2730 DumpBytes(EIGHT_SPACE_MARGIN, ptr, (typeLen-4)); |
|
2731 len -= typeLen; |
|
2732 } |
|
2733 |
|
2734 aDes.Set(aDes.Ptr()+length, aDes.Length()-length); |
|
2735 return length; |
|
2736 } |
|
2737 |
|
2738 TInt CDummyNifLog::DumpChap(TPtrC8& aDes) |
|
2739 { |
|
2740 |
|
2741 TUint8* ptr = (TUint8*)aDes.Ptr(); |
|
2742 TUint8 code = *ptr++; |
|
2743 TUint8 id = *ptr++; |
|
2744 TInt len = BigEndian::Get16(ptr); |
|
2745 ptr += 2; |
|
2746 |
|
2747 Printf(KCodeTextWithoutSpacesString,FsmCodeToText(code), code); |
|
2748 Printf(KIdentifierLengthString, id, len); |
|
2749 |
|
2750 if (code==1 || code==2) |
|
2751 { |
|
2752 TInt n = *ptr++; |
|
2753 DumpBytes(EIGHT_SPACE_MARGIN, ptr, n); |
|
2754 ptr += n; |
|
2755 |
|
2756 n = len-(4+1+n); |
|
2757 TPtrC8 v; |
|
2758 v.Set(ptr, n); ptr += n; |
|
2759 TBuf16<KLogBufferSize> temp; |
|
2760 temp.Copy(v); |
|
2761 Printf(KNameString, &temp); |
|
2762 } |
|
2763 else if (code==3 || code==4) |
|
2764 { |
|
2765 TInt n = (len-4); |
|
2766 TPtrC8 v; |
|
2767 v.Set(ptr, n); |
|
2768 ptr += n; |
|
2769 TBuf16<KLogBufferSize> temp; |
|
2770 temp.Copy(v); |
|
2771 Printf(KMessageString, &temp); |
|
2772 } |
|
2773 |
|
2774 aDes.Set(aDes.Ptr()+len, aDes.Length()-len); |
|
2775 return len; |
|
2776 } |
|
2777 |
|
2778 |
|
2779 TInt CDummyNifLog::DumpCcp(TPtrC8& aDes) |
|
2780 { |
|
2781 |
|
2782 TUint8* ptr = (TUint8*)aDes.Ptr(); |
|
2783 TUint8 code = *ptr++; |
|
2784 TUint8 id = *ptr++; |
|
2785 TInt len = BigEndian::Get16(ptr); |
|
2786 ptr += 2; |
|
2787 aDes.Set(ptr, aDes.Length()-4); |
|
2788 |
|
2789 Printf(KCodeTextWithoutSpacesString,FsmCodeToText(code), code); |
|
2790 Printf(KIdentifierLengthString, id, len); |
|
2791 |
|
2792 switch (code) |
|
2793 { |
|
2794 case KPppLcpConfigRequest: |
|
2795 case KPppLcpConfigAck: |
|
2796 case KPppLcpConfigNak: |
|
2797 case KPppLcpConfigReject: |
|
2798 { |
|
2799 TInt n = len-4; |
|
2800 TInt tmp = 0; |
|
2801 while (n>0 && aDes.Length()>0) |
|
2802 { |
|
2803 tmp = DumpCcpOption(aDes); |
|
2804 if (tmp == 0) //Check for an error in the DumpCcpOption (0 is interpreted as an error) |
|
2805 { |
|
2806 Printf(_L("WARNING: Length reported in CCP Option was incorrect! Dumping data instead\n")); |
|
2807 DumpBytes(EIGHT_SPACE_MARGIN, ptr, len-4); |
|
2808 break; |
|
2809 } |
|
2810 n=n-tmp; |
|
2811 } |
|
2812 |
|
2813 if (n>0) |
|
2814 Printf(KBytesRemainingString, n, (n>1)?"s":""); |
|
2815 } |
|
2816 break; |
|
2817 case KPppLcpTerminateRequest: |
|
2818 case KPppLcpTerminateAck: |
|
2819 { |
|
2820 if (len>4) |
|
2821 DumpBytes(EIGHT_SPACE_MARGIN, ptr, len-4); |
|
2822 } |
|
2823 break; |
|
2824 case KPppLcpCodeReject: |
|
2825 { |
|
2826 TUint val = BigEndian::Get16(ptr); |
|
2827 Printf(KCodeString, val); |
|
2828 } |
|
2829 break; |
|
2830 case KPppLcpProtocolReject: |
|
2831 { |
|
2832 TUint val = BigEndian::Get16(ptr); |
|
2833 Printf(KProtocolString, val); |
|
2834 } |
|
2835 break; |
|
2836 } |
|
2837 return len; |
|
2838 } |
|
2839 |
|
2840 TInt CDummyNifLog::DumpCcpOption(TPtrC8& aDes) |
|
2841 { |
|
2842 |
|
2843 TUint8* ptr = (TUint8*)aDes.Ptr(); |
|
2844 TUint8 opt = *ptr++; |
|
2845 TUint8 len = *ptr++; |
|
2846 |
|
2847 if(len > aDes.Length()) |
|
2848 { |
|
2849 Printf(_L("WARNING: Length reported in option header was more than actual frame length\n")); |
|
2850 return 0; //Return an incorrect length to flag this error. |
|
2851 } |
|
2852 |
|
2853 if(len < 2) |
|
2854 { |
|
2855 Printf(_L("WARNING: Length reported in option header was less than a correct frame length\n")); |
|
2856 return 0; //Return an incorrect length. (the minimum correct length of an option is 2) |
|
2857 } |
|
2858 |
|
2859 Printf(KCodeTextString, CcpCodeToText(opt), opt); |
|
2860 Printf(KLengthString, len); |
|
2861 |
|
2862 DumpBytes(FOURTEEN_SPACE_MARGIN, ptr, len-2); |
|
2863 aDes.Set((TUint8*)aDes.Ptr()+len, aDes.Length()-len); |
|
2864 return len; |
|
2865 } |
|
2866 |
|
2867 TInt CDummyNifLog::DumpIp6cp(TPtrC8& aDes) |
|
2868 { |
|
2869 |
|
2870 TUint8* ptr = (TUint8*)aDes.Ptr(); |
|
2871 TUint8 code = *ptr++; |
|
2872 TUint8 id = *ptr++; |
|
2873 TInt len = BigEndian::Get16(ptr); |
|
2874 ptr += 2; |
|
2875 aDes.Set(ptr, aDes.Length()-4); |
|
2876 |
|
2877 Printf(KCodeTextWithoutSpacesString, FsmCodeToText(code), code); |
|
2878 Printf(KIdentifierLengthString, id, len); |
|
2879 |
|
2880 switch (code) |
|
2881 { |
|
2882 case KPppLcpConfigRequest: |
|
2883 case KPppLcpConfigAck: |
|
2884 case KPppLcpConfigNak: |
|
2885 case KPppLcpConfigReject: |
|
2886 { |
|
2887 TInt n = len-4; |
|
2888 //only for testing display |
|
2889 //while (n>0 && aDes.Length()>0) |
|
2890 // n -= DumpIp6cpOption(aDes); |
|
2891 if (n>0) |
|
2892 Printf(KBytesRemainingString, n, (n>1)?"s":""); |
|
2893 } |
|
2894 break; |
|
2895 case KPppLcpTerminateRequest: |
|
2896 case KPppLcpTerminateAck: |
|
2897 { |
|
2898 if (len>4) |
|
2899 DumpBytes(EIGHT_SPACE_MARGIN, ptr, len-4); |
|
2900 } |
|
2901 break; |
|
2902 case KPppLcpCodeReject: |
|
2903 { |
|
2904 TUint val = BigEndian::Get16(ptr); |
|
2905 Printf(KCodeString2, val); |
|
2906 } |
|
2907 break; |
|
2908 case KPppLcpProtocolReject: |
|
2909 { |
|
2910 TUint val = BigEndian::Get16(ptr); |
|
2911 Printf(KProtocolString, val); |
|
2912 } |
|
2913 break; |
|
2914 } |
|
2915 return len; |
|
2916 } |
|
2917 TInt CDummyNifLog::DumpIp(TPtrC8& aDes) |
|
2918 { |
|
2919 |
|
2920 TUint8* ptr = (TUint8*)aDes.Ptr(); |
|
2921 TUint8 c = *ptr++; |
|
2922 // TUint ver = c >> 4; |
|
2923 TUint hlen = (c & 0xf) << 2; |
|
2924 // TUint8 tos = *ptr; |
|
2925 ptr++; |
|
2926 TUint16 len = ByteOrder::Swap16((TUint16)(*ptr | *(ptr+1)<<8)); |
|
2927 ptr+=2; |
|
2928 TUint16 id = ByteOrder::Swap16((TUint16)(*ptr | *(ptr+1)<<8)); |
|
2929 ptr+=2; |
|
2930 TUint16 frag = ByteOrder::Swap16((TUint16)(*ptr | *(ptr+1)<<8)); |
|
2931 ptr+=2; |
|
2932 TBool zf = (frag & 0x8000); |
|
2933 TBool df = (frag & 0x4000); |
|
2934 TBool mf = (frag & 0x2000); |
|
2935 frag = (TUint16)((frag & 0x1fff)<<3); |
|
2936 // TUint8 ttl = *ptr; |
|
2937 ptr++; |
|
2938 TUint8 proto = *ptr++; |
|
2939 // TUint16 chksum = ByteOrder::Swap16((TUint16)(*ptr | *(ptr+1)<<8)); |
|
2940 ptr+=2; |
|
2941 TUint32 srca = ByteOrder::Swap32(*ptr | (*(ptr+1)<<8) | (*(ptr+2)<<16) | (*(ptr+3)<<24)); |
|
2942 ptr+=4; |
|
2943 TUint32 dsta = ByteOrder::Swap32(*ptr | (*(ptr+1)<<8) | (*(ptr+2)<<16) | (*(ptr+3)<<24)); |
|
2944 ptr+=4; |
|
2945 // TBool opts = (hlen>20); |
|
2946 |
|
2947 Printf(KHdrLengthString, len, hlen); |
|
2948 Printf(KSrcDstAddrString,(srca&0xff000000)>>24,(srca&0x00ff0000)>>16,(srca&0x0000ff00)>>8,(srca&0x000000ff), |
|
2949 (dsta&0xff000000)>>24,(dsta&0x00ff0000)>>16,(dsta&0x0000ff00)>>8,(dsta&0x000000ff)); |
|
2950 Printf(KIDFragmentString, id, frag, df?_S("<DF>"):_S(""), mf?_S("<MF>"):_S(""), zf?_S("<Z>"):_S("")); |
|
2951 // Printf(KTOSTTLChksumString, tos, ttl, chksum); |
|
2952 Printf(KCodeTextString, IpProtocolToText(proto), proto); |
|
2953 |
|
2954 if (hlen>20) |
|
2955 ptr += (hlen-20); |
|
2956 |
|
2957 TInt n = (TInt)ptr-(TInt)aDes.Ptr(); |
|
2958 TInt tlen = aDes.Length()-n; |
|
2959 aDes.Set(ptr, tlen); |
|
2960 |
|
2961 switch (proto) |
|
2962 { |
|
2963 case 1: |
|
2964 return n+DumpIcmp(aDes, tlen); |
|
2965 case 6: |
|
2966 return n+DumpTcp(aDes, srca, dsta, tlen); |
|
2967 case 17: |
|
2968 return n+DumpUdp(aDes, srca, dsta, tlen); |
|
2969 default: |
|
2970 return n; |
|
2971 } |
|
2972 } |
|
2973 |
|
2974 TInt CDummyNifLog::DumpIpcp(TPtrC8& aDes) |
|
2975 { |
|
2976 |
|
2977 TUint8* ptr = (TUint8*)aDes.Ptr(); |
|
2978 TUint8 code = *ptr++; |
|
2979 TUint8 id = *ptr++; |
|
2980 TInt len = BigEndian::Get16(ptr); |
|
2981 ptr += 2; |
|
2982 aDes.Set(ptr, aDes.Length()-4); |
|
2983 |
|
2984 Printf(KCodeTextWithoutSpacesString, FsmCodeToText(code), code); |
|
2985 Printf(KIdentifierLengthString, id, len); |
|
2986 |
|
2987 switch (code) |
|
2988 { |
|
2989 case KPppLcpConfigRequest: |
|
2990 case KPppLcpConfigAck: |
|
2991 case KPppLcpConfigNak: |
|
2992 case KPppLcpConfigReject: |
|
2993 { |
|
2994 TInt n = len-4; |
|
2995 TInt tmp = 0; |
|
2996 while (n>0 && aDes.Length()>0) |
|
2997 { |
|
2998 tmp = DumpIpcpOption(aDes); |
|
2999 if (tmp == 0) //Check for an error in the DumpIpcpOption (0 is interpreted as an error) |
|
3000 { |
|
3001 Printf(_L("WARNING: Length reported in IPCP Option was incorrect! Dumping data instead\n")); |
|
3002 DumpBytes(EIGHT_SPACE_MARGIN, ptr, len-4); |
|
3003 break; |
|
3004 } |
|
3005 n=n-tmp; |
|
3006 } |
|
3007 |
|
3008 if (n>0) |
|
3009 Printf(KBytesRemainingString, n, (n>1)?"s":""); |
|
3010 } |
|
3011 break; |
|
3012 case KPppLcpTerminateRequest: |
|
3013 case KPppLcpTerminateAck: |
|
3014 { |
|
3015 if (len>4) |
|
3016 DumpBytes(EIGHT_SPACE_MARGIN, ptr, len-4); |
|
3017 } |
|
3018 break; |
|
3019 case KPppLcpCodeReject: |
|
3020 { |
|
3021 TUint val = BigEndian::Get16(ptr); |
|
3022 Printf(KCodeString2, val); |
|
3023 } |
|
3024 break; |
|
3025 case KPppLcpProtocolReject: |
|
3026 { |
|
3027 TUint val = BigEndian::Get16(ptr); |
|
3028 Printf(KProtocolString, val); |
|
3029 } |
|
3030 break; |
|
3031 } |
|
3032 return len; |
|
3033 } |
|
3034 |
|
3035 TInt CDummyNifLog::DumpIpcpOption(TPtrC8& aDes) |
|
3036 { |
|
3037 |
|
3038 TUint8* ptr = (TUint8*)aDes.Ptr(); |
|
3039 TUint8 opt = *ptr++; |
|
3040 TUint8 len = *ptr++; |
|
3041 |
|
3042 if(len > aDes.Length()) |
|
3043 { |
|
3044 Printf(_L("WARNING: Length reported in option header was more than actual frame length\n")); |
|
3045 return 0; //Return an incorrect length to flag this error. |
|
3046 } |
|
3047 |
|
3048 if(len < 2) |
|
3049 { |
|
3050 Printf(_L("WARNING: Length reported in option header was less than a correct frame length\n")); |
|
3051 return 0; //Return an incorrect length. (the minimum correct length of an option is 2) |
|
3052 } |
|
3053 |
|
3054 Printf(KCodeTextString, IpcpCodeToText(opt), opt); |
|
3055 Printf(KLengthString2, len); |
|
3056 |
|
3057 TUint32 val; |
|
3058 |
|
3059 switch (opt) |
|
3060 { |
|
3061 case KPppIpcpOptIpAddresses: |
|
3062 val = BigEndian::Get32(ptr); |
|
3063 Printf(KRemoteAddrString,(val&0xff000000)>>24,(val&0x00ff0000)>>16,(val&0x0000ff00)>>8,(val&0x000000ff)); |
|
3064 val = BigEndian::Get32(ptr+4); |
|
3065 Printf(KOurAddrString,(val&0xff000000)>>24,(val&0x00ff0000)>>16,(val&0x0000ff00)>>8,(val&0x000000ff)); |
|
3066 break; |
|
3067 case KPppIpcpOptIpCompressionProtocol: |
|
3068 { |
|
3069 TUint prot = BigEndian::Get16(ptr); |
|
3070 ptr += 2; |
|
3071 Printf(KProtocolTextString, ProtocolToText(prot), prot); |
|
3072 if (len>4) |
|
3073 { |
|
3074 switch (prot) |
|
3075 { |
|
3076 case KPppIdVjCompTcp: |
|
3077 Printf(KMaxSlotString, *ptr++); |
|
3078 Printf(KCompSlotString, *ptr++); |
|
3079 break; |
|
3080 default: |
|
3081 DumpBytes(FOURTEEN_SPACE_MARGIN, ptr+4, len-4); |
|
3082 break; |
|
3083 } |
|
3084 } |
|
3085 } |
|
3086 break; |
|
3087 case KPppIpcpOptIpAddress: |
|
3088 case KPppIpcpOptPrimaryDnsAddress: |
|
3089 case KPppIpcpOptSecondaryDnsAddress: |
|
3090 case KPppIpcpOptPrimaryNbnsAddress: |
|
3091 case KPppIpcpOptSecondaryNbnsAddress: |
|
3092 { |
|
3093 val = BigEndian::Get32(ptr); |
|
3094 Printf(KAddrString,(val&0xff000000)>>24,(val&0x00ff0000)>>16,(val&0x0000ff00)>>8,(val&0x000000ff)); |
|
3095 } |
|
3096 break; |
|
3097 } |
|
3098 aDes.Set((TUint8*)aDes.Ptr()+len, aDes.Length()-len); |
|
3099 return len; |
|
3100 } |
|
3101 |
|
3102 TInt CDummyNifLog::DumpIp6(TPtrC8& aDes) |
|
3103 { |
|
3104 // This dumps the main IPv6 Header, no support for option headers |
|
3105 // IPv6 Headers are FIXED length, but are chainable... |
|
3106 TUint16* ptr = (TUint16*)aDes.Ptr(); |
|
3107 |
|
3108 // First 32 bits contain version(4), class(8), Flow Label(20) |
|
3109 |
|
3110 TUint32 first = ByteOrder::Swap32((TUint32) *ptr); |
|
3111 //TUint8 ver = (TUint8)((first >> 28) & 0xf); |
|
3112 TUint8 cls = (TUint8)((first >> 20) & 0xff); |
|
3113 TUint32 flowLab = (first & 0xfffff); |
|
3114 ptr+=2; |
|
3115 |
|
3116 // Second 32 bits contain payload length (16), next header type (8), hop limit (8) |
|
3117 TUint16 payLoadLen = ByteOrder::Swap16( *ptr++ ); |
|
3118 TUint16 next = ByteOrder::Swap16( *ptr++ ); |
|
3119 TUint8 nextHead = (TUint8)((next >> 8) & 0xff); |
|
3120 TUint8 hopLimit = (TUint8)(next & 0xff); |
|
3121 |
|
3122 // Source address (128 bits) |
|
3123 TUint16 s1 = ByteOrder::Swap16( *ptr++ ); |
|
3124 TUint16 s2 = ByteOrder::Swap16( *ptr++ ); |
|
3125 TUint16 s3 = ByteOrder::Swap16( *ptr++ ); |
|
3126 TUint16 s4 = ByteOrder::Swap16( *ptr++ ); |
|
3127 TUint16 s5 = ByteOrder::Swap16( *ptr++ ); |
|
3128 TUint16 s6 = ByteOrder::Swap16( *ptr++ ); |
|
3129 TUint16 s7 = ByteOrder::Swap16( *ptr++ ); |
|
3130 TUint16 s8 = ByteOrder::Swap16( *ptr++ ); |
|
3131 |
|
3132 // Destination address (128 bits) |
|
3133 TUint16 a1 = ByteOrder::Swap16( *ptr++ ); |
|
3134 TUint16 a2 = ByteOrder::Swap16( *ptr++ ); |
|
3135 TUint16 a3 = ByteOrder::Swap16( *ptr++ ); |
|
3136 TUint16 a4 = ByteOrder::Swap16( *ptr++ ); |
|
3137 TUint16 a5 = ByteOrder::Swap16( *ptr++ ); |
|
3138 TUint16 a6 = ByteOrder::Swap16( *ptr++ ); |
|
3139 TUint16 a7 = ByteOrder::Swap16( *ptr++ ); |
|
3140 TUint16 a8 = ByteOrder::Swap16( *ptr++ ); |
|
3141 |
|
3142 //Printf(_L(" Version is %d"),ver); // Should be 6 for IPv6 !! |
|
3143 Printf(KIpv6Class, cls); |
|
3144 Printf(KIpv6FlowLabel, flowLab); |
|
3145 Printf(KIpv6PayloadLen, payLoadLen); |
|
3146 Printf(KIpv6NextHeadType, nextHead); |
|
3147 Printf(KIpv6HopLimit, hopLimit); |
|
3148 Printf(KIpv6SrcAddress, s1,s2,s3,s4,s5,s6,s7,s8); |
|
3149 Printf(KIpv6DstAddress, a1,a2,a3,a4,a5,a6,a7,a8); |
|
3150 |
|
3151 TInt n = (TInt)ptr-(TInt)aDes.Ptr(); |
|
3152 TInt tlen = aDes.Length()-n; |
|
3153 aDes.Set( (TUint8*) ptr, tlen); |
|
3154 |
|
3155 switch (nextHead) |
|
3156 { |
|
3157 case 6: // TCP Packet |
|
3158 Printf(_L(" TCP Data")); |
|
3159 //DumpTcp(aDes); |
|
3160 HexDump(EIGHT_SPACE_MARGIN,EIGHT_SPACE_MARGIN, aDes.Ptr(), tlen); |
|
3161 break; |
|
3162 case 17: // UDP Packet |
|
3163 Printf(_L(" UDP Data")); |
|
3164 DumpUdp(aDes,s8,a8,tlen); |
|
3165 break; |
|
3166 case 43: // Routing Header |
|
3167 Printf(_L(" Routing Header")); |
|
3168 //DumpRouter |
|
3169 HexDump(EIGHT_SPACE_MARGIN,EIGHT_SPACE_MARGIN, aDes.Ptr(), tlen); |
|
3170 break; |
|
3171 case 44: // Fragment Header |
|
3172 Printf(_L(" Packet Fragment")); |
|
3173 //DumpFragment |
|
3174 HexDump(EIGHT_SPACE_MARGIN,EIGHT_SPACE_MARGIN, aDes.Ptr(), tlen); |
|
3175 break; |
|
3176 case 50: // ESP Payload |
|
3177 Printf(_L(" ESP Payload")); |
|
3178 HexDump(EIGHT_SPACE_MARGIN,EIGHT_SPACE_MARGIN, aDes.Ptr(), tlen); |
|
3179 break; |
|
3180 case 58: // ICMPv6 |
|
3181 Printf(_L(" ICMPv6")); |
|
3182 DumpIcmp(aDes,tlen); |
|
3183 break; |
|
3184 case 59: // No Next Header |
|
3185 Printf(_L(" NO NEXT HEADER")); |
|
3186 HexDump(EIGHT_SPACE_MARGIN,EIGHT_SPACE_MARGIN, aDes.Ptr(), tlen); |
|
3187 break; |
|
3188 default: |
|
3189 Printf(KIpv6UnknownHeadType, nextHead); |
|
3190 HexDump(EIGHT_SPACE_MARGIN,EIGHT_SPACE_MARGIN, aDes.Ptr(), tlen); |
|
3191 } |
|
3192 |
|
3193 return n; |
|
3194 } |
|
3195 |
|
3196 TInt CDummyNifLog::DumpVjCompTcp(TPtrC8& aDes) |
|
3197 { |
|
3198 |
|
3199 TUint8* ptr = (TUint8*)aDes.Ptr(); |
|
3200 TUint16 change = *ptr++; |
|
3201 TUint8 urgent=0; |
|
3202 TInt16 window=0; |
|
3203 TUint16 ack=0; |
|
3204 TUint16 sequence=0; |
|
3205 TBuf<50> changeMaskBuf;; |
|
3206 TUint8 connection=0; |
|
3207 |
|
3208 changeMaskBuf.Append(KChangeMaskString); |
|
3209 |
|
3210 if (change & KVjCompMaskConn) |
|
3211 { |
|
3212 _LIT(string7,"C"); |
|
3213 changeMaskBuf.Append(string7); |
|
3214 connection = *ptr++; |
|
3215 } |
|
3216 |
|
3217 TUint16 checksum = BigEndian::Get16(ptr); |
|
3218 ptr += 2; |
|
3219 |
|
3220 if (change & KVjCompMaskPush) |
|
3221 { |
|
3222 _LIT(string8,"P"); |
|
3223 changeMaskBuf.Append(string8); |
|
3224 } |
|
3225 |
|
3226 /* |
|
3227 * Don't reorder SpecialI && SpecialD, they are like this |
|
3228 * as SpecialD is the SWAU bits and SpecialI is SWU |
|
3229 * |
|
3230 */ |
|
3231 |
|
3232 if ((change & KVjCompMaskSpecials) == KVjCompMaskSpecialD) |
|
3233 { |
|
3234 _LIT(string1," Special D"); |
|
3235 Write(string1); |
|
3236 } |
|
3237 else if ((change & KVjCompMaskSpecials) == KVjCompMaskSpecialI) |
|
3238 { |
|
3239 _LIT(string2," Special I"); |
|
3240 Write(string2); |
|
3241 } |
|
3242 else |
|
3243 { |
|
3244 if (change & KVjCompMaskUrgent) |
|
3245 { |
|
3246 _LIT(string3,"U"); |
|
3247 changeMaskBuf.Append(string3); |
|
3248 urgent = *ptr++; |
|
3249 } |
|
3250 |
|
3251 if (change & KVjCompMaskWindow ) |
|
3252 { |
|
3253 //only for display |
|
3254 //window = (TInt16)DecodeSignedDelta(ptr); |
|
3255 _LIT(string4,"W"); |
|
3256 changeMaskBuf.Append(string4); |
|
3257 } |
|
3258 |
|
3259 if (change & KVjCompMaskAck ) |
|
3260 { |
|
3261 //only for display |
|
3262 //ack = DecodeDelta(ptr); |
|
3263 _LIT(string5,"A"); |
|
3264 changeMaskBuf.Append(string5); |
|
3265 } |
|
3266 |
|
3267 if (change & KVjCompMaskSeq) |
|
3268 { |
|
3269 //only for display |
|
3270 //sequence = DecodeDelta(ptr); |
|
3271 _LIT(string6,"S"); |
|
3272 changeMaskBuf.Append(string6); |
|
3273 } |
|
3274 } |
|
3275 |
|
3276 |
|
3277 TUint16 ipId=0; |
|
3278 if (change & KVjCompMaskIp) |
|
3279 { |
|
3280 //only for display |
|
3281 //ipId = DecodeDelta(ptr); |
|
3282 _LIT(string9,"I"); |
|
3283 changeMaskBuf.Append(string9); |
|
3284 } |
|
3285 |
|
3286 Printf(TRefByValue<const TDesC>(changeMaskBuf), change); |
|
3287 |
|
3288 Printf(KChecksumString, checksum); |
|
3289 |
|
3290 if (change & KVjCompMaskConn) |
|
3291 { |
|
3292 Printf(KConnectionString,connection); |
|
3293 } |
|
3294 |
|
3295 if (urgent) |
|
3296 { |
|
3297 _LIT(string10," Urgent Delta = 0x%x"); |
|
3298 Printf(string10,urgent); |
|
3299 } |
|
3300 |
|
3301 if (window) |
|
3302 { |
|
3303 _LIT(string11," Window Delta = %d"); |
|
3304 Printf(string11,window); |
|
3305 } |
|
3306 |
|
3307 if (ack) |
|
3308 { |
|
3309 _LIT(string12," Ack Delta = 0x%x"); |
|
3310 Printf(string12,ack); |
|
3311 } |
|
3312 |
|
3313 if (sequence) |
|
3314 { |
|
3315 _LIT(string13," Sequence Delta = 0x%x"); |
|
3316 Printf(string13,sequence); |
|
3317 } |
|
3318 |
|
3319 if (ipId) |
|
3320 { |
|
3321 _LIT(string14," IPId = 0x%x"); |
|
3322 Printf(string14,ipId); |
|
3323 } |
|
3324 |
|
3325 return 1; |
|
3326 } |
|
3327 TInt CDummyNifLog::DumpVjUncompTcp(TPtrC8& aDes) |
|
3328 { |
|
3329 |
|
3330 TUint8* ptr = (TUint8*)aDes.Ptr(); |
|
3331 TUint8 c = *ptr++; |
|
3332 // TUint ver = c >> 4; |
|
3333 TUint hlen = (c & 0xf) << 2; |
|
3334 // TUint8 tos = *ptr; |
|
3335 ptr++; |
|
3336 TUint16 len = ByteOrder::Swap16((TUint16)(*ptr++ | *ptr++<<8)); |
|
3337 TUint16 id = ByteOrder::Swap16((TUint16)(*ptr++ | *ptr++<<8)); |
|
3338 TUint16 frag = ByteOrder::Swap16((TUint16)(*ptr++ | *ptr++<<8)); |
|
3339 TBool zf = (frag & 0x8000); |
|
3340 TBool df = (frag & 0x4000); |
|
3341 TBool mf = (frag & 0x2000); |
|
3342 frag = (TUint16)((frag & 0x1fff)<<3); |
|
3343 // TUint8 ttl = *ptr; |
|
3344 ptr++; |
|
3345 TUint8 proto = *ptr++; |
|
3346 // TUint16 chksum = ByteOrder::Swap16((TUint16)(*ptr | *(ptr+1)<<8)); |
|
3347 ptr+=2; |
|
3348 TUint32 srca = ByteOrder::Swap32(*ptr | (*(ptr+1)<<8) | (*(ptr+2)<<16) | (*(ptr+3)<<24)); |
|
3349 ptr+=4; |
|
3350 TUint32 dsta = ByteOrder::Swap32(*ptr | (*(ptr+1)<<8) | (*(ptr+2)<<16) | (*(ptr+3)<<24)); |
|
3351 ptr+=4; |
|
3352 // TBool opts = (hlen>20); |
|
3353 |
|
3354 Printf(KHdrLengthString, len, hlen); |
|
3355 Printf(KSrcDstAddrString, (srca&0xff000000)>>24,(srca&0x00ff0000)>>16,(srca&0x0000ff00)>>8,(srca&0x000000ff), |
|
3356 (dsta&0xff000000)>>24,(dsta&0x00ff0000)>>16,(dsta&0x0000ff00)>>8,(dsta&0x000000ff)); |
|
3357 Printf(KIDFragmentString, id, frag, df?_S("<DF>"):_S(""), mf?_S("<MF>"):_S(""), zf?_S("<Z>"):_S("")); |
|
3358 // Printf(KTOSTTLChksumString, tos, ttl, chksum); |
|
3359 Printf(KConnectionNoString, proto); |
|
3360 |
|
3361 if (hlen>20) |
|
3362 ptr += (hlen-20); |
|
3363 |
|
3364 TInt n = (TInt)ptr-(TInt)aDes.Ptr(); |
|
3365 TInt tlen = aDes.Length()-n; |
|
3366 aDes.Set(ptr, tlen); |
|
3367 return n+DumpTcp(aDes, srca, dsta, tlen); |
|
3368 } |
|
3369 |
|
3370 TInt CDummyNifLog::DumpTcp(TPtrC8& aDes, TUint32 aSrcA, TUint32 aDstA, TInt aLength) |
|
3371 { |
|
3372 |
|
3373 TInt n = Min(aLength, aDes.Length()); |
|
3374 TInt len = n; |
|
3375 |
|
3376 TUint8* ptr = (TUint8*)aDes.Ptr(); |
|
3377 TUint8 osum0 = ptr[16]; |
|
3378 ptr[16] = 0; |
|
3379 TUint8 osum1 = ptr[17]; |
|
3380 ptr[17] = 0; |
|
3381 |
|
3382 TUint32 sum = 0; |
|
3383 sum += (aSrcA >> 16); |
|
3384 sum += (aSrcA & 0xffff); |
|
3385 sum += (aDstA >> 16); |
|
3386 sum += (aDstA & 0xffff); |
|
3387 sum += 6; |
|
3388 sum += n; |
|
3389 while (n>1) |
|
3390 { |
|
3391 sum += (ptr[0]<<8); |
|
3392 sum += (ptr[1]); |
|
3393 ptr += 2; |
|
3394 n -= 2; |
|
3395 } |
|
3396 if (n>0) |
|
3397 sum += (ptr[0]<<8); |
|
3398 while (sum>0xffff) |
|
3399 { |
|
3400 sum = (sum & 0xffff) + (sum>>16); |
|
3401 } |
|
3402 sum = ~sum & 0xffff; |
|
3403 ptr = (TUint8*)aDes.Ptr(); |
|
3404 ptr[16] = osum0; |
|
3405 ptr[17] = osum1; |
|
3406 |
|
3407 TUint srcp = ByteOrder::Swap16((TUint16)(*ptr | (*(ptr+1)<<8))); |
|
3408 ptr +=2; |
|
3409 TUint dstp = ByteOrder::Swap16((TUint16)(*ptr | (*(ptr+1)<<8))); |
|
3410 ptr +=2; |
|
3411 TUint32 seqnum = ByteOrder::Swap32(*ptr | (*(ptr+1)<<8) | (*(ptr+2)<<16) | (*(ptr+3)<<24)); |
|
3412 ptr+=4; |
|
3413 TUint32 acknum = ByteOrder::Swap32(*ptr | (*(ptr+1)<<8) | (*(ptr+2)<<16) | (*(ptr+3)<<24)); |
|
3414 ptr+=4; |
|
3415 |
|
3416 TUint8 c = *ptr++; |
|
3417 TUint hlen = (c>>4)<<2; |
|
3418 |
|
3419 c = *ptr++; |
|
3420 TUint urgf = c & 0x20; |
|
3421 TUint ackf = c & 0x10; |
|
3422 TUint pshf = c & 0x08; |
|
3423 TUint rstf = c & 0x04; |
|
3424 TUint synf = c & 0x02; |
|
3425 TUint finf = c & 0x01; |
|
3426 |
|
3427 TUint window = ByteOrder::Swap16((TUint16)(*ptr | (*(ptr+1)<<8))); |
|
3428 ptr+=2; |
|
3429 TUint chksum = ByteOrder::Swap16((TUint16)(*ptr | (*(ptr+1)<<8))); |
|
3430 ptr+=2; |
|
3431 TUint urgptr = ByteOrder::Swap16((TUint16)(*ptr | (*(ptr+1)<<8))); |
|
3432 ptr+=2; |
|
3433 |
|
3434 Printf(KTCPLengthString, len, hlen); |
|
3435 Printf(KPortString, srcp, dstp); |
|
3436 // Printf(KDestPortString, dstp); |
|
3437 // Printf(KTCPHeaderLengthString, hlen); |
|
3438 Printf(KSeqAckString, seqnum, acknum); |
|
3439 Printf(KFlagsString, urgf?_S(" <URG>"):_S(""), ackf?_S(" <ACK>"):_S(""), pshf?_S(" <PSH>"):_S(""), |
|
3440 rstf?_S(" <RST>"):_S(""), synf?_S(" <SYN>"):_S(""), finf?_S(" <FIN>"):_S("")); |
|
3441 Printf(KWindowUrgentString, window, urgptr); |
|
3442 if (chksum != sum) |
|
3443 Printf(KChecksumString3, chksum, sum); |
|
3444 |
|
3445 if (hlen>20) |
|
3446 { |
|
3447 _LIT(string2," TCP Options %d bytes"); |
|
3448 Printf(string2, hlen-20); |
|
3449 TInt h, i, opt, optlen=0; |
|
3450 h = hlen-20; |
|
3451 for (i=0; i<h; i+=optlen) |
|
3452 { |
|
3453 opt = ptr[i]; |
|
3454 if (opt == 0) // KTcpOptEol |
|
3455 break; |
|
3456 if (opt == 1) // KTcpOptNop |
|
3457 optlen = 1; |
|
3458 else |
|
3459 { |
|
3460 if (i+1 >= h) |
|
3461 break; |
|
3462 optlen = ptr[i+1]; |
|
3463 if (optlen < 2) |
|
3464 optlen = 2; |
|
3465 } |
|
3466 |
|
3467 switch (opt) |
|
3468 { |
|
3469 case 1: |
|
3470 { |
|
3471 _LIT(string3," NOP"); |
|
3472 Write(string3); |
|
3473 } |
|
3474 break; |
|
3475 case 2: |
|
3476 { |
|
3477 _LIT(string4," Max Seg Size = %d"); |
|
3478 Printf(string4, BigEndian::Get16(ptr+i+2)); |
|
3479 } |
|
3480 break; |
|
3481 default: |
|
3482 { |
|
3483 _LIT(string5," Unknown [0x%02x]"); |
|
3484 Printf(string5, opt); |
|
3485 } |
|
3486 break; |
|
3487 } |
|
3488 } |
|
3489 } |
|
3490 |
|
3491 ptr += (hlen-20); |
|
3492 TInt n1 = (TInt)aDes.Ptr()-(TInt)ptr; |
|
3493 aDes.Set(ptr, aDes.Length()-n1); |
|
3494 return n1; |
|
3495 } |
|
3496 |
|
3497 TInt CDummyNifLog::DumpIcmp(TPtrC8& aDes, TInt aLength) |
|
3498 { |
|
3499 |
|
3500 if (aLength < 2) |
|
3501 return 0; |
|
3502 |
|
3503 TUint8* ptr = (TUint8*)aDes.Ptr(); |
|
3504 |
|
3505 _LIT(string1," Type = %d, Code = %d\n"); |
|
3506 Printf(string1, *ptr, *(ptr+1)); |
|
3507 HexDump(FOURTEEN_SPACE_MARGIN, FOURTEEN_SPACE_MARGIN, ptr, aLength); |
|
3508 return 0; |
|
3509 } |
|
3510 |
|
3511 TInt CDummyNifLog::DumpUdp(TPtrC8& aDes, TUint32 /* aSrcA */, TUint32 /*aDstA */, TInt aLength) |
|
3512 { |
|
3513 if (aLength < 6) |
|
3514 return 0; |
|
3515 |
|
3516 TUint8* ptr = (TUint8*)aDes.Ptr(); |
|
3517 TUint srcp = ByteOrder::Swap16((TUint16)(*ptr | (*(ptr+1)<<8))); |
|
3518 ptr +=2; |
|
3519 TUint dstp = ByteOrder::Swap16((TUint16)(*ptr | (*(ptr+1)<<8))); |
|
3520 ptr +=2; |
|
3521 TUint16 len = ByteOrder::Swap16((TUint16)(*ptr | (*(ptr+1)<<8))); |
|
3522 ptr += 2; |
|
3523 |
|
3524 ptr += 2; // skip checksum |
|
3525 Printf(KUDPLengthPortString, len, srcp, dstp); |
|
3526 //Printf(KPortString, srcp, dstp); |
|
3527 |
|
3528 //for testing only |
|
3529 return 0; |
|
3530 } |
|
3531 |
|
3532 void CDummyNifLog::Dump(RMBufChain& aPacket, TInt aChannel) |
|
3533 { |
|
3534 |
|
3535 RMBufPktInfo* info = RMBufPacket::PeekInfoInChain(aPacket); |
|
3536 TUint prot = TPppAddr::Cast(info->iDstAddr).GetProtocol(); |
|
3537 |
|
3538 TBuf8<1536> buf; |
|
3539 buf.SetMax(); |
|
3540 aPacket.CopyOut(buf, aPacket.First()->Length()); |
|
3541 |
|
3542 if (aChannel==KDummyPPPSendChannel) |
|
3543 { |
|
3544 _LIT(string1,"Dummy PPP Send %d bytes"); |
|
3545 Printf(string1, info->iLength); |
|
3546 } |
|
3547 else if (aChannel==KDummyPPPRecvChannel) |
|
3548 { |
|
3549 _LIT(string2,"Dummy PPP Recv %d bytes"); |
|
3550 Printf(string2, info->iLength); |
|
3551 } |
|
3552 else |
|
3553 { |
|
3554 _LIT(string3,"Dummy PPP %d bytes"); |
|
3555 Printf(string3, info->iLength); |
|
3556 } |
|
3557 |
|
3558 TPtrC8 des(buf); |
|
3559 switch (prot) |
|
3560 { |
|
3561 case KPppIdLcp: |
|
3562 DumpLcp(des); |
|
3563 break; |
|
3564 case KPppIdPap: |
|
3565 DumpPap(des); |
|
3566 break; |
|
3567 case KPppIdChap: |
|
3568 DumpChap(des); |
|
3569 break; |
|
3570 case KPppIdIpcp: |
|
3571 DumpIpcp(des); |
|
3572 break; |
|
3573 case KPppIdIp6cp: |
|
3574 DumpIp6cp(des); |
|
3575 break; |
|
3576 case KPppIdIp: |
|
3577 DumpIp(des); |
|
3578 break; |
|
3579 case KPppIdIp6: |
|
3580 DumpIp6(des); |
|
3581 break; |
|
3582 case KPppIdVjCompTcp: |
|
3583 DumpVjCompTcp(des); |
|
3584 break; |
|
3585 case KPppIdVjUncompTcp: |
|
3586 DumpVjUncompTcp(des); |
|
3587 break; |
|
3588 |
|
3589 default: |
|
3590 Printf(_L("Raw Bytes:")); |
|
3591 HexDump(NULL,_S(""),des.Ptr(), des.Length(),8); |
|
3592 Write(KEndOfLine); |
|
3593 } |
|
3594 } |
|
3595 |
|
3596 void CDummyNifLog::DumpChapType(const TUint8* aPtr) |
|
3597 { |
|
3598 |
|
3599 switch (*aPtr) |
|
3600 { |
|
3601 case 5: |
|
3602 { |
|
3603 _LIT(string1," Algorithm=MD5\n"); |
|
3604 Write(string1); |
|
3605 } |
|
3606 break; |
|
3607 case 0x80: |
|
3608 { |
|
3609 _LIT(string2," Algorithm=Microsoft\n"); |
|
3610 Write(string2); |
|
3611 } |
|
3612 break; |
|
3613 default: |
|
3614 { |
|
3615 _LIT(string3," Algorithm=Unknown\n"); |
|
3616 Write(string3); |
|
3617 } |
|
3618 break; |
|
3619 } |
|
3620 } |
|
3621 |
|
3622 const TText* CDummyNifLog::CallbackOpToText(TUint aValue) |
|
3623 { |
|
3624 |
|
3625 // CB Codes |
|
3626 switch (aValue) |
|
3627 { |
|
3628 case 0: |
|
3629 return _S("Location preset"); |
|
3630 case 1: |
|
3631 return _S("Dialing string"); |
|
3632 case 2: |
|
3633 return _S("Location identifier"); |
|
3634 case 3: |
|
3635 return _S("E.164 number"); |
|
3636 case 4: |
|
3637 return _S("Distinguished name"); |
|
3638 case 5: |
|
3639 return _S("E.165 number"); |
|
3640 case 6: |
|
3641 return _S("MS CBCP"); |
|
3642 default: |
|
3643 return _S("Unknown operation"); |
|
3644 } |
|
3645 } |
|
3646 |
|
3647 const TText* CDummyNifLog::LcpOptToText(TUint aValue) |
|
3648 { |
|
3649 |
|
3650 // LCP Options |
|
3651 switch (aValue) |
|
3652 { |
|
3653 case KPppLcpOptMaxRecvUnit: |
|
3654 return _S("Max receive size"); |
|
3655 case KPppLcpOptEscapeCharMap: |
|
3656 return _S("Escape char map"); |
|
3657 case KPppLcpOptAuthenticationProtocol: |
|
3658 return _S("Authentication protocol"); |
|
3659 case KPppLcpOptQualityProtocol: |
|
3660 return _S("Quality protocol"); |
|
3661 case KPppLcpOptMagicNumber: |
|
3662 return _S("Magic number"); |
|
3663 case KPppLcpOptProtocolCompress: |
|
3664 return _S("Protocol field compression"); |
|
3665 case KPppLcpOptAddrCtrlCompress: |
|
3666 return _S("Addr & Ctrl field compression"); |
|
3667 case KPppLcpOptFcsType: |
|
3668 return _S("Fcs Type"); |
|
3669 case KPppLcpOptPadding: |
|
3670 return _S("Padding"); |
|
3671 case KPppLcpOptCallback: |
|
3672 return _S("Callback protocol"); |
|
3673 case KPppLcpOptCompoundFrames: |
|
3674 return _S("Compound frames"); |
|
3675 case KPppLcpOptMRRU: |
|
3676 return _S("MRRU"); |
|
3677 case KPppLcpOptMultiLinkEndPointDescriminator: |
|
3678 return _S("Multi-link End-Point Descriminator"); |
|
3679 default: |
|
3680 return _S("Unknown"); |
|
3681 } |
|
3682 } |
|
3683 |
|
3684 const TText* CDummyNifLog::ProtocolToText(TUint aValue) |
|
3685 { |
|
3686 |
|
3687 // Protocols |
|
3688 switch (aValue) |
|
3689 { |
|
3690 case KPppIdLcp: |
|
3691 return _S("LCP"); |
|
3692 case KPppIdPap: |
|
3693 return _S("PAP"); |
|
3694 case KPppIdChap: |
|
3695 return _S("CHAP"); |
|
3696 case KPppIdMsCbcp: |
|
3697 return _S("MSCBCP"); |
|
3698 case KPppIdIpcp: |
|
3699 return _S("IPCP"); |
|
3700 case KPppIdIp6cp: |
|
3701 return _S("IP6CP"); |
|
3702 case KPppIdIp: |
|
3703 return _S("IP"); |
|
3704 case KPppIdIp6: |
|
3705 return _S("IPv6"); |
|
3706 case KPppIdVjCompTcp: |
|
3707 return _S("VJ Comp tcp"); |
|
3708 case KPppIdVjUncompTcp: |
|
3709 return _S("VJ Uncomp tcp"); |
|
3710 case KPppIdCcp: |
|
3711 return _S("CCP"); |
|
3712 case KPppIdCompressed: |
|
3713 return _S("PPP Compressed"); |
|
3714 default: |
|
3715 return _S("Unknown"); |
|
3716 } |
|
3717 } |
|
3718 |
|
3719 void CDummyNifLog::LogUserData(RMBufChain& aPacket, TInt aChannel) |
|
3720 // |
|
3721 // Stores the current total of data transferred |
|
3722 // |
|
3723 { |
|
3724 TBuf8<1536> buf; |
|
3725 buf.SetMax(); |
|
3726 aPacket.CopyOut(buf, aPacket.First()->Length()); |
|
3727 |
|
3728 TPtrC8 des(buf); |
|
3729 |
|
3730 TUint8* ptr = (TUint8*)des.Ptr(); |
|
3731 ptr+=2; |
|
3732 TUint16 len = ByteOrder::Swap16((TUint16)(*ptr | *(ptr+1)<<8)); |
|
3733 |
|
3734 if (aChannel==KDummyPPPSendChannel) |
|
3735 { |
|
3736 iSentData+=len; |
|
3737 } |
|
3738 else |
|
3739 { |
|
3740 if (aChannel==KDummyPPPRecvChannel) |
|
3741 iRecvdData+=len; |
|
3742 } |
|
3743 |
|
3744 } |
|
3745 |
|
3746 void CDummyNifLog::DumpBytes(const TText* aMargin, const TUint8* aPtr, TInt aLen) |
|
3747 { |
|
3748 HexDump(NULL,aMargin,aPtr,aLen,8); |
|
3749 } |