|
1 // Copyright (c) 1997-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 // |
|
15 |
|
16 #include "PPPLOG.H" |
|
17 |
|
18 #if defined (ESOCK_LOGGING_ACTIVE) |
|
19 |
|
20 #include "PPPHDLC.H" |
|
21 #include "ncpip.h" |
|
22 #include "ncpip6.h" |
|
23 #include "VJ.H" |
|
24 #include "PPPCCP.H" |
|
25 |
|
26 #include "PPPCHAP.H" |
|
27 |
|
28 static const TUint KDnsPort = 53; |
|
29 |
|
30 _LIT(KPppLogFolder,"Ppp"); |
|
31 _LIT(KPppLogFile,"Ppp.txt"); |
|
32 _LIT8(KTcpDumpFirstTag,"TcpDump"); |
|
33 _LIT8(KPppTcpDump,"TcpDump.log"); |
|
34 |
|
35 _LIT(KEndOfLine,"\n"); |
|
36 _LIT(KStateString1,"%s State -> %s"); |
|
37 _LIT(KStateString2,"%s State %s -> %s"); |
|
38 _LIT(KPhaseString1,"PPP Phase -> %s"); |
|
39 _LIT(KPhaseString2,"PPP Phase %s -> %s"); |
|
40 _LIT(KCodeTextString," %s [0x%02x]"); |
|
41 _LIT(KCodeTextWithoutSpacesString," %s [0x%02x]"); |
|
42 _LIT(KIdentifierLengthString," Id = 0x%02x, Len = %d"); |
|
43 _LIT(KLengthString," Length = %d"); |
|
44 _LIT(KLengthString2," Length = 0x%02x"); |
|
45 _LIT(KTCPLengthString," Length = %d, Hdr len = %d"); |
|
46 _LIT(KUDPLengthPortString," Length = %d, Src port = %d, Dst port = %d"); |
|
47 _LIT(KBytesRemainingString," %d byte(s) remaining"); |
|
48 _LIT(KLcpCodeString," Code = %s [0x%02x]"); |
|
49 _LIT(KCodeString," Code = 0x%02x"); |
|
50 _LIT(KCodeString2," Code = 0x%04x"); |
|
51 _LIT(KProtocolString," Protocol = 0x%04x"); |
|
52 _LIT(KNumberString," Number = 0x%08x"); |
|
53 _LIT(KSecondsString," Seconds = %d"); |
|
54 _LIT(KSizeString," Size = %d"); |
|
55 _LIT(KMapString," Map = 0x%08x"); |
|
56 _LIT(KProtocolTextString," Protocol = %s [0x%04x]"); |
|
57 _LIT(KLcpOptFcsTypeString," Types =%s%s%s"); |
|
58 _LIT(KMaximumBytesString," Maximum bytes = %d"); |
|
59 _LIT(KUserNameString," Username = \"%S\""); |
|
60 _LIT(KPasswordString," Password = \"%S\""); |
|
61 _LIT(KMessageString," Message = \"%S\""); |
|
62 _LIT(KDelayString," Delay=%d\n"); |
|
63 _LIT(KNameString," Name = \"%S\""); |
|
64 _LIT(KChangeMaskString," Change Mask = 0x%x: "); |
|
65 _LIT(KChecksumString," Checksum = 0x%x"); |
|
66 //_LIT(KChecksumString2," Checksum = 0x%04x"); |
|
67 _LIT(KChecksumString3," Chksum = 0x%04x (0x%04x) !!!"); |
|
68 _LIT(KConnectionString," Connection = 0x%x"); |
|
69 _LIT(KHdrLengthString," Length = %d, Hdr len = %d"); |
|
70 //_LIT(KTOSTTLChksumString," TOS = 0x%02x, TTL = %d, Chksum = 0x%04x"); |
|
71 _LIT(KIDFragmentString," Id = 0x%04x, Fragment = %d %s%s%s"); |
|
72 _LIT(KSrcDstAddrString," Src = %d.%d.%d.%d, Dst = %d.%d.%d.%d"); |
|
73 _LIT(KIpv6SrcAddress," Src = %x:%x:%x:%x:%x:%x:%x:%x"); |
|
74 _LIT(KIpv6DstAddress," Dst = %x:%x:%x:%x:%x:%x:%x:%x"); |
|
75 _LIT(KIpv6IfIdent," EUI64 = %x:%x:%x:%x"); |
|
76 _LIT(KIpv6Class," Class = %d"); |
|
77 _LIT(KIpv6FlowLabel," FlowLabel = %d"); |
|
78 _LIT(KIpv6PayloadLen," Payload = %d words"); |
|
79 _LIT(KIpv6NextHeadType," Next Header type is [%d]"); |
|
80 _LIT(KIpv6HopLimit," Hop Limit is %d"); |
|
81 _LIT(KIpv6UnknownHeadType," Unknown next header: [%d]"); |
|
82 _LIT(KConnectionNoString," Connection number [0x%02x]"); |
|
83 _LIT(KRemoteAddrString," Remote Address = %d.%d.%d.%d"); |
|
84 _LIT(KOurAddrString," Our Address = %d.%d.%d.%d"); |
|
85 _LIT(KMaxSlotString," Max Slot Id = %d"); |
|
86 _LIT(KCompSlotString," Comp Slot Id = %d"); |
|
87 _LIT(KAddrString," Address = %d.%d.%d.%d"); |
|
88 _LIT(KPortString," Src port = %d, Dst port = %d"); |
|
89 _LIT(KWindowUrgentString," Window = %d, Urgent = %d"); |
|
90 _LIT(KSeqAckString," Seq = 0x%08x, Ack = 0x%08x"); |
|
91 _LIT(KFlagsString," Flags = 0x%04x (%s%s%s%s%s%s%s%s)"); |
|
92 |
|
93 #define EIGHT_SPACE_MARGIN _S(" ") |
|
94 #define FOURTEEN_SPACE_MARGIN _S(" ") |
|
95 |
|
96 |
|
97 /** Record types in the pppdump log file */ |
|
98 enum |
|
99 { |
|
100 EpppDumpLogRecSentData = 1, |
|
101 EpppDumpLogRecRcvData = 2, |
|
102 EpppDumpLogRecRcvDelim = 4, |
|
103 EpppDumpLogRecTimeStepLong = 5, |
|
104 EpppDumpLogRecTimeStepShort = 6, |
|
105 EpppDumpLogRecResetTime = 7 |
|
106 }; |
|
107 |
|
108 // |
|
109 // PppLog |
|
110 // |
|
111 |
|
112 CPppLog::CPppLog() |
|
113 {} |
|
114 |
|
115 CPppLog::~CPppLog() |
|
116 { |
|
117 __FLOG_CLOSE; |
|
118 delete iLogFileName; |
|
119 } |
|
120 |
|
121 CPppLog* CPppLog::NewL() |
|
122 { |
|
123 CPppLog* self = new (ELeave) CPppLog; |
|
124 CleanupStack::PushL(self); |
|
125 self->ConstructL(); |
|
126 CleanupStack::Pop(); // self |
|
127 return self; |
|
128 } |
|
129 |
|
130 void CPppLog::ConstructL() |
|
131 { |
|
132 TFileName defFileName(KPppLogFile); |
|
133 iTcpDumpLogFileName = KPppTcpDump; |
|
134 iLogFileName = defFileName.AllocL(); |
|
135 iTimeOrigin.UniversalTime(); |
|
136 __FLOG_OPEN(KTcpDumpFirstTag,KPppTcpDump); |
|
137 } |
|
138 |
|
139 void CPppLog::SetLogFileNameL(const TDesC& aName) |
|
140 { |
|
141 if(aName.Length() == 0) |
|
142 //Nothing to do, keep logging to ppp.txt |
|
143 return; |
|
144 delete iLogFileName; |
|
145 |
|
146 // Create ppp log file name |
|
147 TFileName logFileName(aName); |
|
148 const TChar KColonChar(':'); |
|
149 TInt colonPos = logFileName.Locate(KColonChar); |
|
150 _LIT(KHyphenChar, "-"); |
|
151 if (colonPos != KErrNotFound) |
|
152 { |
|
153 logFileName.Replace(colonPos, 2, KHyphenChar); |
|
154 } |
|
155 _LIT(KLogFileExtension, ".txt"); |
|
156 logFileName.Append(KLogFileExtension); |
|
157 logFileName.LowerCase(); |
|
158 iLogFileName = logFileName.AllocL(); |
|
159 |
|
160 //Set tcpdump log file name |
|
161 iTcpDumpLogFileName = _L8(""); |
|
162 iTcpDumpLogFileName.Append(aName); |
|
163 colonPos = iTcpDumpLogFileName.Locate(KColonChar); |
|
164 _LIT8(KHyphenChar8, "-"); |
|
165 if (colonPos != KErrNotFound) |
|
166 { |
|
167 iTcpDumpLogFileName.Replace(colonPos, 2, KHyphenChar8); |
|
168 } |
|
169 _LIT8(KTcpDumpLogFileExtension, ".log"); |
|
170 iTcpDumpLogFileName.Append(KTcpDumpLogFileExtension); |
|
171 iTcpDumpLogFileName.LowerCase(); |
|
172 |
|
173 __FLOG_SET_TAGS(KTcpDumpFirstTag,iTcpDumpLogFileName); |
|
174 } |
|
175 |
|
176 void CPppLog::Write(const TDesC& aDes) |
|
177 /** |
|
178 Writes aDes to the log. |
|
179 |
|
180 @param aDes String descriptor |
|
181 */ |
|
182 { |
|
183 #ifdef __FLOG_ACTIVE |
|
184 RFileLogger::Write(KPppLogFolder(), *iLogFileName, EFileLoggingModeAppend, aDes); |
|
185 #else |
|
186 // Preventing unused variable warnings. |
|
187 (void)aDes; |
|
188 #endif //__FLOG_ACTIVE |
|
189 } |
|
190 |
|
191 void CPppLog::Printf(const TRefByValue<const TDesC> aFmt,...) |
|
192 /** |
|
193 Writes a multiple argument list to the log, trapping and ignoring any leave. |
|
194 |
|
195 @param aFmt printf-style format string |
|
196 */ |
|
197 { |
|
198 #ifdef __FLOG_ACTIVE |
|
199 VA_LIST list; |
|
200 VA_START(list,aFmt); |
|
201 RFileLogger::WriteFormat(KPppLogFolder(), *iLogFileName, EFileLoggingModeAppend, aFmt, list); |
|
202 VA_END(list); |
|
203 #else |
|
204 // Preventing unused variable warnings. |
|
205 (void)aFmt; |
|
206 #endif //__FLOG_ACTIVE |
|
207 } |
|
208 |
|
209 //First attempt below was following the libcap |
|
210 //packet capture format. This format was originally used to facilitate |
|
211 //running a tcptrace stream analysis on the captured data, but further |
|
212 //investigation revealed that raw HDLC frames are not decoded by libpcap |
|
213 //programs (even type 50 libpcap data files). Improvements to Ethereal also |
|
214 //allowed its tcptrace to be run using pppdump format capture files, |
|
215 //making libpcap format files pretty well unnecessary. |
|
216 //void PppLog::LibcapDumpFileHeader() |
|
217 /* |
|
218 Dumps file header in a format compatible with Libcap. |
|
219 Unfortunately, Ethereal cannot cope with HDLC packet including |
|
220 0x7e flag char and 0x7d escape char. |
|
221 Format is: |
|
222 @code |
|
223 struct FileHeader { |
|
224 TUint32 magic; |
|
225 TUint16 version_major; |
|
226 TUint16 version_minor; |
|
227 TUint32 thiszone; // gmt to local correction |
|
228 TUint32 sigfigs; // accuracy of timestamps |
|
229 TUint32 snaplen; // max length saved portion of each pkt |
|
230 TUint32 linktype; // data link type (LINKTYPE_*) |
|
231 9 PPP, 50 PPP HDLC, 12 Raw IP |
|
232 }; |
|
233 @endcode |
|
234 Note LINKTYPE specified in libpcap/bpf/net/bpf.h (see www.tcpdump.org) |
|
235 byte ordering is little endian. |
|
236 */ |
|
237 // { |
|
238 // TBuf8<sizeof(TUint32)*5+sizeof(TUint16)*2> fileHeader; |
|
239 // *((TUint32*) &(fileHeader.Ptr()[0])) = 0xa1b2c3d4; |
|
240 // *((TUint16*) &(fileHeader.Ptr()[4])) = 0x02; |
|
241 // *((TUint16*) &(fileHeader.Ptr()[6])) = 0x04; |
|
242 // *((TUint32*) &(fileHeader.Ptr()[8])) = 0x00; |
|
243 // *((TUint32*) &(fileHeader.Ptr()[12])) = 0x00; |
|
244 // *((TUint32*) &(fileHeader.Ptr()[16])) = 0xffff; |
|
245 // *((TUint32*) &(fileHeader.Ptr()[20])) = 50; |
|
246 // fileHeader.SetLength(fileHeader.MaxLength()); |
|
247 // RFileLogger::Write(KPppLogFolder(),KPppTcpDump(),EFileLoggingModeOverwriteRaw,fileHeader); |
|
248 // } |
|
249 |
|
250 //void PppLog::LibcapDump(TPppHdlcBuf& aBuffer) |
|
251 /* |
|
252 Dumps a packet in a format compatible with Libcap. |
|
253 For each record the format is: |
|
254 @code |
|
255 struct record |
|
256 { |
|
257 TUint32 sec; // time stamp - secs |
|
258 TUint32 usec; // time stamp - microsecs |
|
259 TUint32 captureLen; // length packet captured |
|
260 TUint32 packetLen; // total length of packet |
|
261 }; |
|
262 @endcode |
|
263 Byte ordering of the header is little endian |
|
264 Byte ordering of the packet is network byte order (big endian) |
|
265 |
|
266 @param aBuffer Buffer to dump |
|
267 */ |
|
268 // { |
|
269 // |
|
270 //Unfortunately ethereal gets confused by the 0x7e separator |
|
271 //So we need to strip it from the buffer before logging it |
|
272 // TInt startOffset = 0; |
|
273 // TInt endOffset =0; |
|
274 // if(aBuffer[0] == 0x7e) |
|
275 // startOffset = 1; |
|
276 // if(aBuffer[aBuffer.Length()-1] == 0x7e) |
|
277 // endOffset = 1; |
|
278 // if(startOffset && aBuffer.Length() ==1) |
|
279 // return; |
|
280 // TPppHdlcBuf dumpBuf; |
|
281 // dumpBuf.Copy(aBuffer.Ptr()+startOffset,aBuffer.Length()-startOffset-endOffset); |
|
282 // |
|
283 // TBuf8<sizeof(TUint32)*4> recordHeader; |
|
284 // *((TUint32*) &(recordHeader.Ptr()[0])) = 0x01; |
|
285 // *((TUint32*) &(recordHeader.Ptr()[4])) = 0x0; |
|
286 // *((TUint32*) &(recordHeader.Ptr()[8])) = dumpBuf.Length(); |
|
287 // *((TUint32*) &(recordHeader.Ptr()[12])) = dumpBuf.Length(); |
|
288 // recordHeader.SetLength(recordHeader.MaxLength()); |
|
289 // RFileLogger::Write(KPppLogFolder(),KPppTcpDump(),EFileLoggingModeAppendRaw,recordHeader); |
|
290 // |
|
291 // RFileLogger::Write(KPppLogFolder(),KPppTcpDump(),EFileLoggingModeAppendRaw,dumpBuf); |
|
292 // } |
|
293 |
|
294 |
|
295 //Second attempt wih pppdump packet dump format |
|
296 void CPppLog::PppDumpFileHeader() |
|
297 /** |
|
298 Dumps file header in a format compatible with pppdump. |
|
299 As a file header just drop a 0x07|t3|t2|t1|t0 record followed by a |
|
300 0x05|t3|t2|t1|t0 record, that seems common practice. |
|
301 Since this "header" is actually a regular record, it can be |
|
302 appended to an existing file. |
|
303 */ |
|
304 { |
|
305 _LIT(Ktime_tOrigin,"19700000:000000.000000"); |
|
306 TTime time_t_Origin(Ktime_tOrigin); |
|
307 TTimeIntervalSeconds secs; |
|
308 TTime timeNow; |
|
309 timeNow.UniversalTime(); |
|
310 timeNow.SecondsFrom(time_t_Origin,secs); |
|
311 TBuf8<10> fileHeader; |
|
312 fileHeader.SetLength(fileHeader.MaxLength()); |
|
313 |
|
314 fileHeader[0] = EpppDumpLogRecResetTime; |
|
315 BigEndian::Put32(&fileHeader[1], secs.Int()); |
|
316 |
|
317 fileHeader[5] = EpppDumpLogRecTimeStepLong; |
|
318 BigEndian::Put32(&fileHeader[6], 0); |
|
319 |
|
320 __FLOG_BINARY(fileHeader); |
|
321 } |
|
322 |
|
323 void CPppLog::PppDumpFrame(TInt aDirection, TUint32 aTimeStep, const TDesC8& aBuffer) |
|
324 /** |
|
325 Dumps a packet in a pppdump format (see www.ethereal.com) |
|
326 For each record the format is: |
|
327 @code |
|
328 0x07|t3|t2|t1|t0 Reset time t = time_t (UNIX: secs since 01/01/1970) |
|
329 0x06|t0 Time step (short) - ts = time step (tenths) |
|
330 0x05|t3|t2|t1|t0 Time step (short) - ts = time step (tenths) |
|
331 0x04 Receive deliminator (not seen in practice) |
|
332 0x02|n1|n0 Received data - n = number of bytes following |
|
333 0x01|n1|n0 Sent data - n = number of bytes following |
|
334 @endcode |
|
335 Byte ordering of the header is little endian |
|
336 Byte ordering of the packet is network byte order (big endian) |
|
337 |
|
338 @param aDirection 01:in/02:out (as documented by pppdump packet trace format) |
|
339 @param aTimeStep Delta time from last dumped frame |
|
340 @param aBuffer Buffer to dump |
|
341 */ |
|
342 { |
|
343 TBuf8<2+6> recordHeader; |
|
344 int i=0; |
|
345 if (aTimeStep > 0xff) |
|
346 { |
|
347 // 32-bit differential time record |
|
348 recordHeader.SetLength(8); |
|
349 recordHeader[i++] = EpppDumpLogRecTimeStepLong; |
|
350 BigEndian::Put32(&recordHeader[i], aTimeStep); |
|
351 i += 4; |
|
352 } |
|
353 else if (aTimeStep > 0) |
|
354 { |
|
355 // 8-bit differential time record |
|
356 recordHeader.SetLength(5); |
|
357 recordHeader[i++] = EpppDumpLogRecTimeStepShort; |
|
358 recordHeader[i++] = (TUint8) aTimeStep; |
|
359 } |
|
360 else |
|
361 { |
|
362 recordHeader.SetLength(3); |
|
363 } |
|
364 recordHeader[i++] = (TUint8) aDirection; |
|
365 BigEndian::Put16(&recordHeader[i], (TUint16)aBuffer.Length()); |
|
366 i += 2; |
|
367 __FLOG_BINARY(recordHeader); |
|
368 __FLOG_BINARY(aBuffer); |
|
369 } |
|
370 |
|
371 void CPppLog::DumpFrameFileHeader(TInt aLogFormat, TInt aLogType) |
|
372 /** |
|
373 Specifies the file format to use for the frame log and writes the file header. |
|
374 |
|
375 @param aLogFormat Network log file format; EpppDumpLogFormat for pppdump |
|
376 @param aLogType EpppLogLinkFormat to log all frames, |
|
377 ErawIpLogLinkFormat to just log IP frames |
|
378 */ |
|
379 { |
|
380 iLogFormat = aLogFormat; |
|
381 iLogType = aLogType; |
|
382 if (iLogFormat == EpppDumpLogFormat) |
|
383 { |
|
384 PppDumpFileHeader(); |
|
385 } |
|
386 // else unknown format |
|
387 |
|
388 Printf(_L("Note: the format of PPP log has changed\n")); |
|
389 Printf(_L("The level of logging is now specified in the file: \\system\\data\\ppp.ini\n")); |
|
390 Printf(_L("In the section [log], the entry: level= n specifies the level of logging\n")); |
|
391 Printf(_L("n=0 :\tFinite State Machine transition are logged\n")); |
|
392 Printf(_L("n=1 :\tReserved for future use\n")); |
|
393 Printf(_L("n=2 :\tReserved for future use\n")); |
|
394 Printf(_L("n=3 :\tReserved for future use\n")); |
|
395 Printf(_L("n=4 :\tLog parsed PPP packets *SLOW* (superseded by TcpDump)\n")); |
|
396 Printf(_L("n=5 :\tHexDump of PPP packets *VERY SLOW* (superseded by TcpDump)\n")); |
|
397 Printf(_L("\tA new binary log is generated with the TcpDump tag, and after being\n")); |
|
398 Printf(_L("\textracted with splitlog.bat, it can be used as an input file for Ethereal.\n")); |
|
399 Printf(_L("Ethereal is a general purpose packet analyser that can parse a wide variety of protocols.\n")); |
|
400 Printf(_L("\tIt is freeware and can be fetched from: http://www.ethereal.com\n")); |
|
401 |
|
402 iLogHeaderDone=ETrue; |
|
403 } |
|
404 |
|
405 void CPppLog::DumpFrame(TInt aDirection, const TDesC8& aBuffer) |
|
406 /** |
|
407 Dumps frame in the configured format. |
|
408 |
|
409 @param aDirection EpppDirectionSend or EpppDirectionReceive |
|
410 (as documented by pppdump packet trace format) |
|
411 @param aBuffer Buffer to dump |
|
412 */ |
|
413 { |
|
414 if(iLogFormat==EpppDumpLogFormat) |
|
415 { |
|
416 if(!iLogHeaderDone) |
|
417 { |
|
418 PppDumpFileHeader(); |
|
419 iLogHeaderDone=ETrue; |
|
420 } |
|
421 //Find absolute time now |
|
422 TUint32 timeStep; |
|
423 TTime timeNow; |
|
424 timeNow.UniversalTime(); |
|
425 TTimeIntervalMicroSeconds us= timeNow.MicroSecondsFrom(iTimeOrigin); |
|
426 //Round to the number of 1/10 secs within the hour |
|
427 timeStep = I64LOW(us.Int64()); |
|
428 timeStep /= 100000; |
|
429 if(timeStep) |
|
430 iTimeOrigin=timeNow; |
|
431 PppDumpFrame(aDirection,timeStep,aBuffer); |
|
432 } |
|
433 // else unknown log format |
|
434 } |
|
435 |
|
436 void CPppLog::HexDump(const TText* aHeader, const TText* aMargin, const TUint8* aPtr, TInt aLen, TInt aWidth) |
|
437 { |
|
438 |
|
439 TBuf<0x100> buf; |
|
440 TInt i = 0; |
|
441 const TText* p = aHeader; |
|
442 while (aLen>0) |
|
443 { |
|
444 TInt n = aLen>aWidth ? aWidth : aLen; |
|
445 if (p!=NULL) |
|
446 { |
|
447 _LIT(string1,"%s%04x : "); |
|
448 buf.AppendFormat(string1, p, i); |
|
449 } |
|
450 TInt j; |
|
451 _LIT(string2,"%02x "); |
|
452 for (j=0; j<n; j++) |
|
453 buf.AppendFormat(string2, aPtr[i+j]); |
|
454 _LIT(string3," "); |
|
455 while (j++<KHexDumpWidth) |
|
456 buf.Append(string3); |
|
457 _LIT(string4," "); |
|
458 buf.Append(string4); |
|
459 _LIT(string5,"%c"); |
|
460 for (j=0; j<n; j++) |
|
461 buf.AppendFormat(string5, aPtr[i+j]<32 || aPtr[i+j]>126 ? '.' : aPtr[i+j]); |
|
462 buf.Append(KEndOfLine); |
|
463 Write(buf); |
|
464 buf.SetLength(0); |
|
465 aLen -= n; |
|
466 i += n; |
|
467 p = aMargin; |
|
468 } |
|
469 } |
|
470 |
|
471 void CPppLog::Dump(RMBufChain& aPacket, TInt aChannel) |
|
472 { |
|
473 RMBufPktInfo* info = RMBufPacket::PeekInfoInChain(aPacket); |
|
474 TUint prot = TPppAddr::Cast(info->iDstAddr).GetProtocol(); |
|
475 |
|
476 HBufC8* hbuf = 0; |
|
477 TRAPD(err, hbuf = HBufC8::NewL(aPacket.Length()+1)); |
|
478 if(err != KErrNone) |
|
479 { |
|
480 _LIT(string0,"CPppLog::Dump error = %d"); |
|
481 Printf(string0, err); |
|
482 } |
|
483 else |
|
484 { |
|
485 TPtr8 buf = hbuf->Des(); |
|
486 buf.SetMax(); |
|
487 aPacket.CopyOut(buf, aPacket.First()->Length()); |
|
488 |
|
489 if (aChannel==KPppHdlcSendChannel) |
|
490 { |
|
491 _LIT(string1,"PPP Send %d bytes"); |
|
492 Printf(string1, info->iLength); |
|
493 } |
|
494 else if (aChannel==KPppHdlcRecvChannel) |
|
495 { |
|
496 _LIT(string2,"PPP Recv %d bytes"); |
|
497 Printf(string2, info->iLength); |
|
498 } |
|
499 else |
|
500 { |
|
501 _LIT(string3,"PPP %d bytes"); |
|
502 Printf(string3, info->iLength); |
|
503 } |
|
504 |
|
505 _LIT(string4," %s [0x%04x] "); |
|
506 Printf(string4, ProtocolToText(prot), prot); |
|
507 |
|
508 TPtrC8 des(buf); |
|
509 switch (prot) |
|
510 { |
|
511 case KPppIdLcp: |
|
512 DumpLcp(des); |
|
513 break; |
|
514 case KPppIdPap: |
|
515 DumpPap(des); |
|
516 break; |
|
517 case KPppIdChap: |
|
518 DumpChap(des); |
|
519 break; |
|
520 case KPppIdIpcp: |
|
521 DumpIpcp(des); |
|
522 break; |
|
523 case KPppIdIp6cp: |
|
524 DumpIp6cp(des); |
|
525 break; |
|
526 case KPppIdIp: |
|
527 DumpIp(des); |
|
528 break; |
|
529 case KPppIdIp6: |
|
530 DumpIp6(des); |
|
531 break; |
|
532 case KPppIdVjCompTcp: |
|
533 DumpVjCompTcp(des); |
|
534 break; |
|
535 case KPppIdVjUncompTcp: |
|
536 DumpVjUncompTcp(des); |
|
537 break; |
|
538 case KPppIdMsCbcp: |
|
539 DumpCbcp(des); |
|
540 break; |
|
541 case KPppIdCcp: |
|
542 DumpCcp(des); |
|
543 break; |
|
544 case KPppIdCompressed: |
|
545 break; |
|
546 default: |
|
547 Printf(_L("Raw Bytes:")); |
|
548 DumpBytes(_S(""), des.Ptr(), des.Length()); |
|
549 Write(KEndOfLine); |
|
550 break; |
|
551 } |
|
552 } |
|
553 delete hbuf; |
|
554 } |
|
555 |
|
556 void CPppLog::DumpState(const TText* aFsm, TPppFsmState aOldState, TPppFsmState aNewState) |
|
557 { |
|
558 |
|
559 if (aNewState==aOldState) |
|
560 Printf(KStateString1, aFsm, StateToText(aNewState)); |
|
561 else |
|
562 Printf(KStateString2, aFsm, StateToText(aOldState), StateToText(aNewState)); |
|
563 } |
|
564 |
|
565 void CPppLog::DumpPhase(TPppPhase aOldPhase, TPppPhase aNewPhase) |
|
566 { |
|
567 |
|
568 if (aNewPhase==aOldPhase) |
|
569 Printf(KPhaseString1, PhaseToText(aNewPhase)); |
|
570 else |
|
571 Printf(KPhaseString2, PhaseToText(aOldPhase), PhaseToText(aNewPhase)); |
|
572 } |
|
573 |
|
574 // Private functions |
|
575 |
|
576 void CPppLog::DumpChapType(const TUint8* aPtr) |
|
577 { |
|
578 |
|
579 switch (*aPtr) |
|
580 { |
|
581 case 5: |
|
582 { |
|
583 _LIT(string1," Algorithm=MD5"); |
|
584 Write(string1); |
|
585 } |
|
586 break; |
|
587 |
|
588 case 0x80: |
|
589 { |
|
590 _LIT(string2," Algorithm=MS-CHAP-V1"); |
|
591 Write(string2); |
|
592 } |
|
593 break; |
|
594 |
|
595 case 0x81: |
|
596 { |
|
597 _LIT(string2," Algorithm=MS-CHAP-V2"); |
|
598 Write(string2); |
|
599 } |
|
600 break; |
|
601 |
|
602 default: |
|
603 { |
|
604 _LIT(string3," Algorithm=Unknown"); |
|
605 Write(string3); |
|
606 } |
|
607 break; |
|
608 } |
|
609 } |
|
610 |
|
611 void CPppLog::DumpBytes(const TText* aMargin, const TUint8* aPtr, TInt aLen) |
|
612 { |
|
613 |
|
614 HexDump(NULL,aMargin,aPtr,aLen,8); |
|
615 } |
|
616 |
|
617 |
|
618 TInt CPppLog::DumpLcp(TPtrC8& aDes) |
|
619 { |
|
620 |
|
621 TUint8* ptr = (TUint8*)aDes.Ptr(); |
|
622 TUint8 code = *ptr++; |
|
623 TUint8 id = *ptr++; |
|
624 TInt len = BigEndian::Get16(ptr); |
|
625 if(len>aDes.Length()) |
|
626 { |
|
627 Printf(_L("WARNING: Length reported in header was more than actual frame length")); |
|
628 return len; |
|
629 } |
|
630 else if (len<aDes.Length()) |
|
631 Printf(_L("WARNING: Length reported in header was less than actual frame length!")); |
|
632 |
|
633 ptr += 2; |
|
634 aDes.Set(ptr, aDes.Length()-4); |
|
635 |
|
636 Printf(KCodeTextString, LcpCodeToText(code), code); |
|
637 Printf(KIdentifierLengthString, id, len); |
|
638 |
|
639 switch (code) |
|
640 { |
|
641 case KPppLcpConfigRequest: |
|
642 case KPppLcpConfigAck: |
|
643 case KPppLcpConfigNak: |
|
644 case KPppLcpConfigReject: |
|
645 { |
|
646 TInt n = len-4; |
|
647 TInt tmp = 0; |
|
648 while (n>0 && aDes.Length()>0) |
|
649 { |
|
650 tmp = DumpLcpOption(aDes); |
|
651 if (tmp == 0) //Check for an error in the DumpLcpOption (0 is interpreted as an error) |
|
652 { |
|
653 Printf(_L("WARNING: Length reported in LCP Option was incorrect! Dumping data instead")); |
|
654 DumpBytes(EIGHT_SPACE_MARGIN, ptr, len-4); |
|
655 break; |
|
656 } |
|
657 n=n-tmp; |
|
658 } |
|
659 |
|
660 if (n>0) |
|
661 Printf(KBytesRemainingString, n); |
|
662 } |
|
663 |
|
664 break; |
|
665 case KPppLcpTerminateRequest: |
|
666 case KPppLcpTerminateAck: |
|
667 { |
|
668 if (len>4) |
|
669 DumpBytes(EIGHT_SPACE_MARGIN, ptr, len-4); |
|
670 } |
|
671 break; |
|
672 case KPppLcpCodeReject: |
|
673 { |
|
674 TUint val = *ptr; |
|
675 Printf(KCodeString, val); |
|
676 } |
|
677 break; |
|
678 case KPppLcpProtocolReject: |
|
679 { |
|
680 TUint val = BigEndian::Get16(ptr); |
|
681 Printf(KProtocolString, val); |
|
682 } |
|
683 break; |
|
684 case KPppLcpEchoRequest: |
|
685 { |
|
686 TUint val = BigEndian::Get32(ptr); |
|
687 Printf(KNumberString, val); |
|
688 if (len>0) |
|
689 DumpBytes(EIGHT_SPACE_MARGIN, ptr+4, len-8); |
|
690 } |
|
691 break; |
|
692 case KPppLcpEchoReply: |
|
693 { |
|
694 TUint val = BigEndian::Get32(ptr); |
|
695 Printf(KNumberString, val); |
|
696 if (len>0) |
|
697 DumpBytes(EIGHT_SPACE_MARGIN, ptr+4, len-8); |
|
698 } |
|
699 break; |
|
700 case KPppLcpDiscardRequest: |
|
701 { |
|
702 TUint val = BigEndian::Get32(ptr); |
|
703 Printf(KNumberString, val); |
|
704 if (len>0) |
|
705 DumpBytes(EIGHT_SPACE_MARGIN, ptr+4, len-8); |
|
706 } |
|
707 break; |
|
708 case KPppLcpIdentification: |
|
709 { |
|
710 TUint val = BigEndian::Get32(ptr); |
|
711 Printf(KNumberString, val); |
|
712 if (len>0) |
|
713 DumpBytes(EIGHT_SPACE_MARGIN, ptr+4, len-8); |
|
714 } |
|
715 break; |
|
716 case KPppLcpTimeRemaining: |
|
717 { |
|
718 TUint val = BigEndian::Get32(ptr); |
|
719 ptr+=4; |
|
720 Printf(KNumberString, val); |
|
721 val = BigEndian::Get32(ptr); |
|
722 Printf(KSecondsString, val); |
|
723 } |
|
724 break; |
|
725 default: |
|
726 break; |
|
727 } |
|
728 |
|
729 return len; |
|
730 } |
|
731 |
|
732 TInt CPppLog::DumpLcpOption(TPtrC8& aDes) |
|
733 { |
|
734 |
|
735 TUint8* ptr = (TUint8*)aDes.Ptr(); |
|
736 TUint8 opt = *ptr++; |
|
737 TUint8 len = *ptr++; |
|
738 |
|
739 if(len > aDes.Length()) |
|
740 { |
|
741 Printf(_L("WARNING: Length reported in option header was more than actual frame length")); |
|
742 return 0; //Return an incorrect length to flag this error. |
|
743 } |
|
744 |
|
745 if(len < 2) |
|
746 { |
|
747 Printf(_L("WARNING: Length reported in option header was less than a correct frame length")); |
|
748 return 0; //Return an incorrect length. (the minimum correct length of an option is 2) |
|
749 } |
|
750 |
|
751 Printf(KLcpCodeString, LcpOptToText(opt), opt); |
|
752 Printf(KLengthString, len); |
|
753 |
|
754 switch (opt) |
|
755 { |
|
756 case KPppLcpOptMaxRecvUnit: |
|
757 { |
|
758 TUint val = BigEndian::Get16(ptr); |
|
759 Printf(KSizeString, val); |
|
760 } |
|
761 break; |
|
762 case KPppLcpOptEscapeCharMap: |
|
763 { |
|
764 TUint val = BigEndian::Get32(ptr); |
|
765 Printf(KMapString, val); |
|
766 } |
|
767 break; |
|
768 case KPppLcpOptAuthenticationProtocol: |
|
769 { |
|
770 TUint val = BigEndian::Get16(ptr); |
|
771 |
|
772 Printf(KProtocolTextString, ProtocolToText(val), val); |
|
773 if (val != KPppIdChap) |
|
774 { |
|
775 if (len>4) |
|
776 DumpBytes(EIGHT_SPACE_MARGIN, ptr+2, len-4); |
|
777 } |
|
778 else |
|
779 { |
|
780 if(len>4) |
|
781 DumpChapType(ptr+2); |
|
782 } |
|
783 } |
|
784 break; |
|
785 case KPppLcpOptQualityProtocol: |
|
786 { |
|
787 TUint val = BigEndian::Get16(ptr); |
|
788 Printf(KProtocolTextString, ProtocolToText(val), val); |
|
789 if (len>4) |
|
790 DumpBytes(EIGHT_SPACE_MARGIN, ptr+2, len-4); |
|
791 } |
|
792 break; |
|
793 case KPppLcpOptMagicNumber: |
|
794 { |
|
795 TUint val = BigEndian::Get32(ptr); |
|
796 Printf(KNumberString, val); |
|
797 } |
|
798 break; |
|
799 case KPppLcpOptProtocolCompress: |
|
800 case KPppLcpOptAddrCtrlCompress: |
|
801 break; |
|
802 case KPppLcpOptFcsType: |
|
803 { |
|
804 TUint val = *ptr++; |
|
805 Printf(KLcpOptFcsTypeString, (val&KPppHdlcFcs0Flag)?_S(" None"):_S(""), (val&KPppHdlcFcs16Flag)?_S(" 16 bit"):_S(""), (val&KPppHdlcFcs32Flag)?_S(" 32 bit"):_S("")); |
|
806 } |
|
807 break; |
|
808 case KPppLcpOptPadding: |
|
809 { |
|
810 TUint val = *ptr++; |
|
811 Printf(KMaximumBytesString, val); |
|
812 } |
|
813 break; |
|
814 case KPppLcpOptCallback: |
|
815 { |
|
816 TUint val = *ptr++; |
|
817 Printf(KCodeTextString, CallbackOpToText(val), val); |
|
818 if (len>3) |
|
819 DumpBytes(EIGHT_SPACE_MARGIN, ptr+3, len-3); |
|
820 } |
|
821 break; |
|
822 case KPppLcpOptCompoundFrames: |
|
823 break; |
|
824 default: |
|
825 break; |
|
826 } |
|
827 aDes.Set((TUint8*)aDes.Ptr()+len, aDes.Length()-len); |
|
828 return len; |
|
829 } |
|
830 |
|
831 TInt CPppLog::DumpPap(TPtrC8& aDes) |
|
832 { |
|
833 |
|
834 TUint8* ptr = (TUint8*)aDes.Ptr(); |
|
835 TUint8 code = *ptr++; |
|
836 TUint8 id = *ptr++; |
|
837 TInt len = BigEndian::Get16(ptr); |
|
838 ptr += 2; |
|
839 |
|
840 Printf(KCodeTextString, PapCodeToText(code), code); |
|
841 Printf(KIdentifierLengthString, id, len); |
|
842 |
|
843 if (code==1) |
|
844 { |
|
845 TInt n = *ptr++; |
|
846 TPtrC8 v; |
|
847 v.Set(ptr, n); ptr += n; |
|
848 TBuf16<KLogBufferSize> temp; |
|
849 temp.Copy(v.Left(Min(v.Length(),KLogBufferSize))); |
|
850 Printf(KUserNameString, &temp); |
|
851 n = *ptr++; |
|
852 v.Set(ptr, n); ptr += n; |
|
853 temp.Copy(v.Left(Min(v.Length(),KLogBufferSize))); |
|
854 Printf(KPasswordString, &temp); |
|
855 } |
|
856 else if (code==2 || code==3) |
|
857 { |
|
858 TInt n = *ptr++; |
|
859 TPtrC8 v; |
|
860 v.Set(ptr, n); ptr += n; |
|
861 TBuf16<KLogBufferSize> temp; |
|
862 temp.Copy(v.Left(Min(v.Length(),KLogBufferSize))); |
|
863 Printf(KMessageString, &temp); |
|
864 } |
|
865 |
|
866 aDes.Set(aDes.Ptr()+len, aDes.Length()-len); |
|
867 return len; |
|
868 } |
|
869 |
|
870 TInt CPppLog::DumpCbcp(TPtrC8& aDes) |
|
871 { |
|
872 |
|
873 TUint8* ptr = (TUint8*)aDes.Ptr(); |
|
874 TUint8 code = *ptr++; |
|
875 TUint8 id = *ptr++; |
|
876 TInt len = BigEndian::Get16(ptr); |
|
877 TInt length = len; |
|
878 ptr += 2; |
|
879 |
|
880 Printf(KCodeTextString, CbcpCodeToText(code), code); |
|
881 Printf(KIdentifierLengthString, id, len); |
|
882 |
|
883 // |
|
884 // OK we can be offered many options at once, so |
|
885 // loop for the length and decode them. |
|
886 // |
|
887 len -= 4; // Subtract the stuff we know about |
|
888 |
|
889 TUint8 type; |
|
890 TUint typeLen; |
|
891 while (len) |
|
892 { |
|
893 // Yes I know we can have a permanent loop but I just don't care |
|
894 type = *ptr++; |
|
895 switch(type) |
|
896 { |
|
897 case 1: |
|
898 { |
|
899 _LIT(string1," No CallBack"); |
|
900 Write(string1); |
|
901 } |
|
902 break; |
|
903 case 2: |
|
904 { |
|
905 _LIT(string2," Callback to a user specified No."); |
|
906 Write(string2); |
|
907 } |
|
908 break; |
|
909 case 3: |
|
910 { |
|
911 _LIT(string3," Callback to a pre specified No."); |
|
912 Write(string3); |
|
913 } |
|
914 break; |
|
915 case 4: |
|
916 { |
|
917 _LIT(string4," Callback to one of a list of numbers"); |
|
918 Write(string4); |
|
919 } |
|
920 break; |
|
921 default: |
|
922 { |
|
923 _LIT(string5," Unknown Callback type"); |
|
924 Write(string5); |
|
925 } |
|
926 break; |
|
927 } |
|
928 |
|
929 if (len == 1) |
|
930 len = 0; |
|
931 |
|
932 typeLen = *ptr++; |
|
933 Printf(KLengthString,typeLen); |
|
934 |
|
935 if (typeLen > 2) |
|
936 Printf(KDelayString,*ptr++); |
|
937 |
|
938 if (typeLen > 3) |
|
939 { |
|
940 // |
|
941 // Dump the Address Type field |
|
942 // |
|
943 if (*ptr++ == 1) |
|
944 { |
|
945 _LIT(string6," PSTN/ISDN"); |
|
946 Write(string6); |
|
947 } |
|
948 else |
|
949 { |
|
950 _LIT(string7," Other"); |
|
951 Write(string7); |
|
952 } |
|
953 } |
|
954 |
|
955 // |
|
956 // Dump the NUL-terminated ASCII string |
|
957 // |
|
958 DumpBytes(EIGHT_SPACE_MARGIN, ptr, (typeLen-4)); |
|
959 len -= typeLen; |
|
960 } |
|
961 |
|
962 aDes.Set(aDes.Ptr()+length, aDes.Length()-length); |
|
963 return length; |
|
964 } |
|
965 |
|
966 TInt Advance(TPtrC8& aPacket, const TUint8* aPos) |
|
967 { |
|
968 aPacket.Set(aPos, aPacket.Length() - (aPacket.Ptr() - aPos)); |
|
969 return aPacket.Ptr() - aPos; |
|
970 } |
|
971 |
|
972 TInt CPppLog::DumpChap(TPtrC8& aPacket) |
|
973 { |
|
974 if (aPacket.Length() < KPppChapCodeFieldSize) |
|
975 return 0; |
|
976 |
|
977 const TUint8* ptr = aPacket.Ptr(); |
|
978 TInt packLength = aPacket.Length(); |
|
979 TUint8 code = *ptr; |
|
980 |
|
981 Printf(KCodeTextWithoutSpacesString,ChapCodeToText(code), code); |
|
982 ptr += KPppChapCodeFieldSize; |
|
983 |
|
984 if (packLength < KPppChapCodeFieldSize + |
|
985 KPppChapIdFieldSize + |
|
986 KPppChapLengthFieldSize) |
|
987 return Advance(aPacket, ptr); |
|
988 |
|
989 TUint8 id = *ptr; |
|
990 ptr += KPppChapIdFieldSize; |
|
991 TUint16 length = BigEndian::Get16(ptr); |
|
992 ptr += KPppChapLengthFieldSize; |
|
993 |
|
994 Printf(KIdentifierLengthString, id, length); |
|
995 |
|
996 if (packLength > length) |
|
997 packLength = length; |
|
998 |
|
999 if (code == KPppChapChallengeCode || code == KPppChapResponseCode) |
|
1000 { |
|
1001 if (packLength < KPppChapCodeFieldSize + |
|
1002 KPppChapIdFieldSize + |
|
1003 KPppChapLengthFieldSize + |
|
1004 KPppChapValueSizeFieldSize + |
|
1005 KPppChapMinValueSize) |
|
1006 return Advance(aPacket, ptr); |
|
1007 |
|
1008 TUint8 valueSize = *ptr; |
|
1009 if (valueSize < KPppChapMinValueSize) |
|
1010 return Advance(aPacket, ptr); |
|
1011 ptr += KPppChapValueSizeFieldSize; |
|
1012 if (valueSize > packLength - |
|
1013 KPppChapCodeFieldSize - |
|
1014 KPppChapIdFieldSize - |
|
1015 KPppChapLengthFieldSize - |
|
1016 KPppChapValueSizeFieldSize) |
|
1017 return Advance(aPacket, ptr); |
|
1018 DumpBytes(EIGHT_SPACE_MARGIN, ptr, valueSize); |
|
1019 ptr += valueSize; |
|
1020 |
|
1021 // length will contain the length of the CHAP Name field next |
|
1022 ASSERT(packLength <= length); |
|
1023 length = static_cast<TUint16>(packLength - |
|
1024 KPppChapCodeFieldSize - |
|
1025 KPppChapIdFieldSize - |
|
1026 KPppChapLengthFieldSize - |
|
1027 KPppChapValueSizeFieldSize - |
|
1028 valueSize); |
|
1029 if (length < KPppChapMinNameSize) |
|
1030 return Advance(aPacket, ptr); |
|
1031 |
|
1032 if (length > KLogBufferSize) |
|
1033 length = KLogBufferSize; |
|
1034 |
|
1035 TPtrC8 name(ptr, length); |
|
1036 |
|
1037 HBufC16* uniName=NULL; |
|
1038 TRAPD(err, uniName = HBufC16::NewL(length)); |
|
1039 if (err==KErrNone) |
|
1040 { |
|
1041 // Convert the string to a 16 bit descriptor |
|
1042 uniName->Des().Copy(name); |
|
1043 Printf(KNameString, uniName); |
|
1044 delete uniName; |
|
1045 } |
|
1046 ptr += length; |
|
1047 } |
|
1048 else if (code == KPppChapSuccessCode || code == KPppChapFailureCode) |
|
1049 { |
|
1050 // length will contain the length of the message next |
|
1051 ASSERT(packLength <= length); |
|
1052 length = static_cast<TUint16>(packLength - |
|
1053 KPppChapCodeFieldSize - |
|
1054 KPppChapIdFieldSize - |
|
1055 KPppChapLengthFieldSize); |
|
1056 if (length == 0) |
|
1057 return Advance(aPacket, ptr); |
|
1058 |
|
1059 TPtrC8 msg(ptr, length); |
|
1060 |
|
1061 HBufC16* uniMsg=NULL; |
|
1062 TRAPD(err, uniMsg = HBufC16::NewL(length)); |
|
1063 if (err==KErrNone) |
|
1064 { |
|
1065 // Convert the string to a 16 bit descriptor |
|
1066 uniMsg->Des().Copy(msg); |
|
1067 Printf(KMessageString, uniMsg); |
|
1068 delete uniMsg; |
|
1069 } |
|
1070 ptr += length; |
|
1071 } |
|
1072 |
|
1073 return Advance(aPacket, ptr); |
|
1074 } |
|
1075 |
|
1076 |
|
1077 TInt CPppLog::DumpCcp(TPtrC8& aDes) |
|
1078 { |
|
1079 |
|
1080 TUint8* ptr = (TUint8*)aDes.Ptr(); |
|
1081 TUint8 code = *ptr++; |
|
1082 TUint8 id = *ptr++; |
|
1083 TInt len = BigEndian::Get16(ptr); |
|
1084 ptr += 2; |
|
1085 aDes.Set(ptr, aDes.Length()-4); |
|
1086 |
|
1087 Printf(KCodeTextWithoutSpacesString,FsmCodeToText(code), code); |
|
1088 Printf(KIdentifierLengthString, id, len); |
|
1089 |
|
1090 switch (code) |
|
1091 { |
|
1092 case KPppLcpConfigRequest: |
|
1093 case KPppLcpConfigAck: |
|
1094 case KPppLcpConfigNak: |
|
1095 case KPppLcpConfigReject: |
|
1096 { |
|
1097 TInt n = len-4; |
|
1098 TInt tmp = 0; |
|
1099 while (n>0 && aDes.Length()>0) |
|
1100 { |
|
1101 tmp = DumpCcpOption(aDes); |
|
1102 if (tmp == 0) //Check for an error in the DumpCcpOption (0 is interpreted as an error) |
|
1103 { |
|
1104 Printf(_L("WARNING: Length reported in CCP Option was incorrect! Dumping data instead")); |
|
1105 DumpBytes(EIGHT_SPACE_MARGIN, ptr, len-4); |
|
1106 break; |
|
1107 } |
|
1108 n=n-tmp; |
|
1109 } |
|
1110 |
|
1111 if (n>0) |
|
1112 Printf(KBytesRemainingString, n); |
|
1113 } |
|
1114 break; |
|
1115 case KPppLcpTerminateRequest: |
|
1116 case KPppLcpTerminateAck: |
|
1117 { |
|
1118 if (len>4) |
|
1119 DumpBytes(EIGHT_SPACE_MARGIN, ptr, len-4); |
|
1120 } |
|
1121 break; |
|
1122 case KPppLcpCodeReject: |
|
1123 { |
|
1124 TUint val = BigEndian::Get16(ptr); |
|
1125 Printf(KCodeString, val); |
|
1126 } |
|
1127 break; |
|
1128 case KPppLcpProtocolReject: |
|
1129 { |
|
1130 TUint val = BigEndian::Get16(ptr); |
|
1131 Printf(KProtocolString, val); |
|
1132 } |
|
1133 break; |
|
1134 default: |
|
1135 break; |
|
1136 } |
|
1137 return len; |
|
1138 } |
|
1139 |
|
1140 TInt CPppLog::DumpCcpOption(TPtrC8& aDes) |
|
1141 { |
|
1142 |
|
1143 TUint8* ptr = (TUint8*)aDes.Ptr(); |
|
1144 TUint8 opt = *ptr++; |
|
1145 TUint8 len = *ptr++; |
|
1146 |
|
1147 if(len > aDes.Length()) |
|
1148 { |
|
1149 Printf(_L("WARNING: Length reported in option header was more than actual frame length")); |
|
1150 return 0; //Return an incorrect length to flag this error. |
|
1151 } |
|
1152 |
|
1153 if(len < 2) |
|
1154 { |
|
1155 Printf(_L("WARNING: Length reported in option header was less than a correct frame length")); |
|
1156 return 0; //Return an incorrect length. (the minimum correct length of an option is 2) |
|
1157 } |
|
1158 |
|
1159 Printf(KCodeTextString, CcpCodeToText(opt), opt); |
|
1160 Printf(KLengthString, len); |
|
1161 |
|
1162 DumpBytes(FOURTEEN_SPACE_MARGIN, ptr, len-2); |
|
1163 aDes.Set((TUint8*)aDes.Ptr()+len, aDes.Length()-len); |
|
1164 return len; |
|
1165 } |
|
1166 |
|
1167 const TText* CPppLog::CcpCodeToText(TUint aValue) |
|
1168 { |
|
1169 |
|
1170 // CCP Codes |
|
1171 switch (aValue) |
|
1172 { |
|
1173 case KPppCcpOptOui: |
|
1174 return _S("OUI"); |
|
1175 case KPppCcpOptPred1: |
|
1176 return _S("Predictor type1"); |
|
1177 case KPppCcpOptPred2: |
|
1178 return _S("Predictor type2"); |
|
1179 case KPppCcpOptPuddle: |
|
1180 return _S("Puddle"); |
|
1181 case KPppCcpOptHP: |
|
1182 return _S("HP PPC"); |
|
1183 case KPppCcpOptStac: |
|
1184 return _S("Stac LZS"); |
|
1185 case KPppCcpOptMsoft: |
|
1186 return _S("Microsoft PPC"); |
|
1187 case KPppCcpOptGandalf: |
|
1188 return _S("Gandalf"); |
|
1189 case KPppCcpOptV42bis: |
|
1190 return _S("V42bis"); |
|
1191 case KPppCcpOptBSDLzw: |
|
1192 return _S("BSD LZW"); |
|
1193 case KPppCcpOptMagnalink: |
|
1194 return _S("Magnalink (or bad deflate)"); |
|
1195 case KPppCcpOptDeflate: |
|
1196 return _S("Deflate"); |
|
1197 case KPppCcpOptReserved: |
|
1198 return _S("Reserved"); |
|
1199 case 4: |
|
1200 case 5: |
|
1201 case 6: |
|
1202 case 7: |
|
1203 case 8: |
|
1204 case 9: |
|
1205 case 10: |
|
1206 case 11: |
|
1207 case 12: |
|
1208 case 13: |
|
1209 case 14: |
|
1210 case 15: |
|
1211 return _S("unassigned"); |
|
1212 default: |
|
1213 return _S("Unknown"); |
|
1214 } |
|
1215 } |
|
1216 |
|
1217 TInt CPppLog::DumpVjCompTcp(TPtrC8& aDes) |
|
1218 /** |
|
1219 Dump a Van Jacobson compressed TCP/IP packet. |
|
1220 @see DumpVjUncompTcp |
|
1221 */ |
|
1222 { |
|
1223 |
|
1224 TUint8* ptr = (TUint8*)aDes.Ptr(); |
|
1225 TUint16 change = *ptr++; |
|
1226 TUint8 urgent=0; |
|
1227 TInt16 window=0; |
|
1228 TUint16 ack=0; |
|
1229 TUint16 sequence=0; |
|
1230 TBuf<50> changeMaskBuf; |
|
1231 TUint8 connection=0; |
|
1232 |
|
1233 changeMaskBuf.Append(KChangeMaskString); |
|
1234 |
|
1235 if (change & KVjCompMaskConn) |
|
1236 { |
|
1237 _LIT(string7,"C"); |
|
1238 changeMaskBuf.Append(string7); |
|
1239 connection = *ptr++; |
|
1240 } |
|
1241 |
|
1242 TUint16 checksum = BigEndian::Get16(ptr); |
|
1243 ptr += 2; |
|
1244 |
|
1245 if (change & KVjCompMaskPush) |
|
1246 { |
|
1247 _LIT(string8,"P"); |
|
1248 changeMaskBuf.Append(string8); |
|
1249 } |
|
1250 |
|
1251 /* |
|
1252 * Don't reorder SpecialI && SpecialD, they are like this |
|
1253 * as SpecialD is the SWAU bits and SpecialI is SWU |
|
1254 * |
|
1255 */ |
|
1256 |
|
1257 if ((change & KVjCompMaskSpecials) == KVjCompMaskSpecialD) |
|
1258 { |
|
1259 _LIT(string1," Special D"); |
|
1260 Write(string1); |
|
1261 } |
|
1262 else if ((change & KVjCompMaskSpecials) == KVjCompMaskSpecialI) |
|
1263 { |
|
1264 _LIT(string2," Special I"); |
|
1265 Write(string2); |
|
1266 } |
|
1267 else |
|
1268 { |
|
1269 if (change & KVjCompMaskUrgent) |
|
1270 { |
|
1271 _LIT(string3,"U"); |
|
1272 changeMaskBuf.Append(string3); |
|
1273 urgent = *ptr++; |
|
1274 } |
|
1275 |
|
1276 if (change & KVjCompMaskWindow ) |
|
1277 { |
|
1278 window = (TInt16)DecodeSignedDelta(ptr); |
|
1279 _LIT(string4,"W"); |
|
1280 changeMaskBuf.Append(string4); |
|
1281 } |
|
1282 |
|
1283 if (change & KVjCompMaskAck ) |
|
1284 { |
|
1285 ack = DecodeDelta(ptr); |
|
1286 _LIT(string5,"A"); |
|
1287 changeMaskBuf.Append(string5); |
|
1288 } |
|
1289 |
|
1290 if (change & KVjCompMaskSeq) |
|
1291 { |
|
1292 sequence = DecodeDelta(ptr); |
|
1293 _LIT(string6,"S"); |
|
1294 changeMaskBuf.Append(string6); |
|
1295 } |
|
1296 } |
|
1297 |
|
1298 |
|
1299 TUint16 ipId=0; |
|
1300 if (change & KVjCompMaskIp) |
|
1301 { |
|
1302 ipId = DecodeDelta(ptr); |
|
1303 _LIT(string9,"I"); |
|
1304 changeMaskBuf.Append(string9); |
|
1305 } |
|
1306 |
|
1307 Printf(TRefByValue<const TDesC>(changeMaskBuf), change); |
|
1308 |
|
1309 Printf(KChecksumString, checksum); |
|
1310 |
|
1311 if (change & KVjCompMaskConn) |
|
1312 { |
|
1313 Printf(KConnectionString,connection); |
|
1314 } |
|
1315 |
|
1316 if (urgent) |
|
1317 { |
|
1318 _LIT(string10," Urgent Delta = 0x%x"); |
|
1319 Printf(string10,urgent); |
|
1320 } |
|
1321 |
|
1322 if (window) |
|
1323 { |
|
1324 _LIT(string11," Window Delta = %d"); |
|
1325 Printf(string11,window); |
|
1326 } |
|
1327 |
|
1328 if (ack) |
|
1329 { |
|
1330 _LIT(string12," Ack Delta = 0x%x"); |
|
1331 Printf(string12,ack); |
|
1332 } |
|
1333 |
|
1334 if (sequence) |
|
1335 { |
|
1336 _LIT(string13," Sequence Delta = 0x%x"); |
|
1337 Printf(string13,sequence); |
|
1338 } |
|
1339 |
|
1340 if (ipId) |
|
1341 { |
|
1342 _LIT(string14," IPId = 0x%x"); |
|
1343 Printf(string14,ipId); |
|
1344 } |
|
1345 |
|
1346 return 1; |
|
1347 } |
|
1348 |
|
1349 TUint16 CPppLog::DecodeDelta(TUint8*& aPtr) |
|
1350 { |
|
1351 |
|
1352 TUint16 wordValue; |
|
1353 TUint8 byteValue = *aPtr++; |
|
1354 if (byteValue != 0) |
|
1355 return (TUint16)byteValue; |
|
1356 else |
|
1357 { |
|
1358 /* |
|
1359 * Zero is an extender |
|
1360 */ |
|
1361 wordValue = BigEndian::Get16(aPtr); |
|
1362 aPtr += 2; |
|
1363 return wordValue; |
|
1364 } |
|
1365 } |
|
1366 |
|
1367 TInt16 CPppLog::DecodeSignedDelta(TUint8*& aPtr) |
|
1368 { |
|
1369 |
|
1370 TInt16 wordValue; |
|
1371 TUint8 byteValue = *aPtr++; |
|
1372 if (byteValue != 0) |
|
1373 return (TInt16)byteValue; |
|
1374 else |
|
1375 { |
|
1376 /* |
|
1377 * Zero is an extender |
|
1378 */ |
|
1379 wordValue = BigEndian::Get16(aPtr); |
|
1380 aPtr += 2; |
|
1381 return wordValue; |
|
1382 } |
|
1383 } |
|
1384 |
|
1385 TInt CPppLog::DumpVjUncompTcp(TPtrC8& aDes) |
|
1386 /** |
|
1387 Dump a Van Jacobson uncompressed TCP/IP packet. |
|
1388 @see DumpIp is almost identical |
|
1389 @see DumpVjCompTcp |
|
1390 */ |
|
1391 { |
|
1392 |
|
1393 TUint8* ptr = (TUint8*)aDes.Ptr(); |
|
1394 TUint8 c = *ptr++; |
|
1395 // TUint ver = c >> 4; |
|
1396 TUint hlen = (c & 0xf) << 2; |
|
1397 // TUint8 tos = *ptr; |
|
1398 ptr++; |
|
1399 TUint16 len = ByteOrder::Swap16((TUint16)(*ptr | *(ptr+1)<<8)); |
|
1400 ptr+=2; |
|
1401 TUint16 id = ByteOrder::Swap16((TUint16)(*ptr | *(ptr+1)<<8)); |
|
1402 ptr+=2; |
|
1403 TUint16 frag = ByteOrder::Swap16((TUint16)(*ptr | *(ptr+1)<<8)); |
|
1404 ptr+=2; |
|
1405 TBool zf = (frag & 0x8000); |
|
1406 TBool df = (frag & 0x4000); |
|
1407 TBool mf = (frag & 0x2000); |
|
1408 frag = (TUint16)((frag & 0x1fff)<<3); |
|
1409 // TUint8 ttl = *ptr; |
|
1410 ptr++; |
|
1411 TUint8 proto = *ptr++; |
|
1412 // TUint16 chksum = ByteOrder::Swap16((TUint16)(*ptr | *(ptr+1)<<8)); |
|
1413 ptr+=2; |
|
1414 TUint32 srca = ByteOrder::Swap32(*ptr | (*(ptr+1)<<8) | (*(ptr+2)<<16) | (*(ptr+3)<<24)); |
|
1415 ptr+=4; |
|
1416 TUint32 dsta = ByteOrder::Swap32(*ptr | (*(ptr+1)<<8) | (*(ptr+2)<<16) | (*(ptr+3)<<24)); |
|
1417 ptr+=4; |
|
1418 // TBool opts = (hlen>20); |
|
1419 |
|
1420 Printf(KHdrLengthString, len, hlen); |
|
1421 Printf(KSrcDstAddrString, (srca&0xff000000)>>24,(srca&0x00ff0000)>>16,(srca&0x0000ff00)>>8,(srca&0x000000ff), |
|
1422 (dsta&0xff000000)>>24,(dsta&0x00ff0000)>>16,(dsta&0x0000ff00)>>8,(dsta&0x000000ff)); |
|
1423 Printf(KIDFragmentString, id, frag, df?_S("<DF>"):_S(""), mf?_S("<MF>"):_S(""), zf?_S("<Z>"):_S("")); |
|
1424 // Printf(KTOSTTLChksumString, tos, ttl, chksum); |
|
1425 Printf(KConnectionNoString, proto); |
|
1426 |
|
1427 if (hlen>20) |
|
1428 ptr += (hlen-20); |
|
1429 |
|
1430 TInt n = (TInt)ptr-(TInt)aDes.Ptr(); |
|
1431 TInt tlen = aDes.Length()-n; |
|
1432 aDes.Set(ptr, tlen); |
|
1433 |
|
1434 Printf(KCodeTextString, IpProtocolToText(6), 6); |
|
1435 return n+DumpTcp(aDes, srca, dsta, tlen); |
|
1436 } |
|
1437 |
|
1438 TInt CPppLog::DumpIp6cp(TPtrC8& aDes) |
|
1439 { |
|
1440 |
|
1441 TUint8* ptr = (TUint8*)aDes.Ptr(); |
|
1442 TUint8 code = *ptr++; |
|
1443 TUint8 id = *ptr++; |
|
1444 TInt len = BigEndian::Get16(ptr); |
|
1445 ptr += 2; |
|
1446 aDes.Set(ptr, aDes.Length()-4); |
|
1447 |
|
1448 Printf(KCodeTextWithoutSpacesString, FsmCodeToText(code), code); |
|
1449 Printf(KIdentifierLengthString, id, len); |
|
1450 |
|
1451 switch (code) |
|
1452 { |
|
1453 case KPppLcpConfigRequest: |
|
1454 case KPppLcpConfigAck: |
|
1455 case KPppLcpConfigNak: |
|
1456 case KPppLcpConfigReject: |
|
1457 { |
|
1458 TInt n = len-4; |
|
1459 while (n>0 && aDes.Length()>0) |
|
1460 n -= DumpIp6cpOption(aDes); |
|
1461 if (n>0) |
|
1462 Printf(KBytesRemainingString, n); |
|
1463 } |
|
1464 break; |
|
1465 case KPppLcpTerminateRequest: |
|
1466 case KPppLcpTerminateAck: |
|
1467 { |
|
1468 if (len>4) |
|
1469 DumpBytes(EIGHT_SPACE_MARGIN, ptr, len-4); |
|
1470 } |
|
1471 break; |
|
1472 case KPppLcpCodeReject: |
|
1473 { |
|
1474 TUint val = BigEndian::Get16(ptr); |
|
1475 Printf(KCodeString2, val); |
|
1476 } |
|
1477 break; |
|
1478 case KPppLcpProtocolReject: |
|
1479 { |
|
1480 TUint val = BigEndian::Get16(ptr); |
|
1481 Printf(KProtocolString, val); |
|
1482 } |
|
1483 break; |
|
1484 default: |
|
1485 break; |
|
1486 } |
|
1487 return len; |
|
1488 } |
|
1489 |
|
1490 TInt CPppLog::DumpIpcp(TPtrC8& aDes) |
|
1491 { |
|
1492 |
|
1493 TUint8* ptr = (TUint8*)aDes.Ptr(); |
|
1494 TUint8 code = *ptr++; |
|
1495 TUint8 id = *ptr++; |
|
1496 TInt len = BigEndian::Get16(ptr); |
|
1497 ptr += 2; |
|
1498 aDes.Set(ptr, aDes.Length()-4); |
|
1499 |
|
1500 Printf(KCodeTextWithoutSpacesString, FsmCodeToText(code), code); |
|
1501 Printf(KIdentifierLengthString, id, len); |
|
1502 |
|
1503 switch (code) |
|
1504 { |
|
1505 case KPppLcpConfigRequest: |
|
1506 case KPppLcpConfigAck: |
|
1507 case KPppLcpConfigNak: |
|
1508 case KPppLcpConfigReject: |
|
1509 { |
|
1510 TInt n = len-4; |
|
1511 TInt tmp = 0; |
|
1512 while (n>0 && aDes.Length()>0) |
|
1513 { |
|
1514 tmp = DumpIpcpOption(aDes); |
|
1515 if (tmp == 0) //Check for an error in the DumpIpcpOption (0 is interpreted as an error) |
|
1516 { |
|
1517 Printf(_L("WARNING: Length reported in IPCP Option was incorrect! Dumping data instead")); |
|
1518 DumpBytes(EIGHT_SPACE_MARGIN, ptr, len-4); |
|
1519 break; |
|
1520 } |
|
1521 n=n-tmp; |
|
1522 } |
|
1523 |
|
1524 if (n>0) |
|
1525 Printf(KBytesRemainingString, n); |
|
1526 } |
|
1527 break; |
|
1528 case KPppLcpTerminateRequest: |
|
1529 case KPppLcpTerminateAck: |
|
1530 { |
|
1531 if (len>4) |
|
1532 DumpBytes(EIGHT_SPACE_MARGIN, ptr, len-4); |
|
1533 } |
|
1534 break; |
|
1535 case KPppLcpCodeReject: |
|
1536 { |
|
1537 TUint val = BigEndian::Get16(ptr); |
|
1538 Printf(KCodeString2, val); |
|
1539 } |
|
1540 break; |
|
1541 case KPppLcpProtocolReject: |
|
1542 { |
|
1543 TUint val = BigEndian::Get16(ptr); |
|
1544 Printf(KProtocolString, val); |
|
1545 } |
|
1546 break; |
|
1547 default: |
|
1548 break; |
|
1549 } |
|
1550 return len; |
|
1551 } |
|
1552 |
|
1553 TInt CPppLog::DumpIpcpOption(TPtrC8& aDes) |
|
1554 { |
|
1555 |
|
1556 TUint8* ptr = (TUint8*)aDes.Ptr(); |
|
1557 TUint8 opt = *ptr++; |
|
1558 TUint8 len = *ptr++; |
|
1559 |
|
1560 if(len > aDes.Length()) |
|
1561 { |
|
1562 Printf(_L("WARNING: Length reported in option header was more than actual frame length")); |
|
1563 return 0; //Return an incorrect length to flag this error. |
|
1564 } |
|
1565 |
|
1566 if(len < 2) |
|
1567 { |
|
1568 Printf(_L("WARNING: Length reported in option header was less than a correct frame length")); |
|
1569 return 0; //Return an incorrect length. (the minimum correct length of an option is 2) |
|
1570 } |
|
1571 |
|
1572 Printf(KCodeTextString, IpcpCodeToText(opt), opt); |
|
1573 Printf(KLengthString2, len); |
|
1574 |
|
1575 TUint32 val; |
|
1576 |
|
1577 switch (opt) |
|
1578 { |
|
1579 case KPppIpcpOptIpAddresses: |
|
1580 val = BigEndian::Get32(ptr); |
|
1581 Printf(KRemoteAddrString,(val&0xff000000)>>24,(val&0x00ff0000)>>16,(val&0x0000ff00)>>8,(val&0x000000ff)); |
|
1582 val = BigEndian::Get32(ptr+4); |
|
1583 Printf(KOurAddrString,(val&0xff000000)>>24,(val&0x00ff0000)>>16,(val&0x0000ff00)>>8,(val&0x000000ff)); |
|
1584 break; |
|
1585 case KPppIpcpOptIpCompressionProtocol: |
|
1586 { |
|
1587 TUint prot = BigEndian::Get16(ptr); |
|
1588 ptr += 2; |
|
1589 Printf(KProtocolTextString, ProtocolToText(prot), prot); |
|
1590 if (len>4) |
|
1591 { |
|
1592 switch (prot) |
|
1593 { |
|
1594 case KPppIdVjCompTcp: |
|
1595 Printf(KMaxSlotString, *ptr++); |
|
1596 Printf(KCompSlotString, *ptr++); |
|
1597 break; |
|
1598 default: |
|
1599 DumpBytes(FOURTEEN_SPACE_MARGIN, ptr+4, len-4); |
|
1600 break; |
|
1601 } |
|
1602 } |
|
1603 } |
|
1604 break; |
|
1605 case KPppIpcpOptIpAddress: |
|
1606 case KPppIpcpOptPrimaryDnsAddress: |
|
1607 case KPppIpcpOptSecondaryDnsAddress: |
|
1608 case KPppIpcpOptPrimaryNbnsAddress: |
|
1609 case KPppIpcpOptSecondaryNbnsAddress: |
|
1610 { |
|
1611 val = BigEndian::Get32(ptr); |
|
1612 Printf(KAddrString,(val&0xff000000)>>24,(val&0x00ff0000)>>16,(val&0x0000ff00)>>8,(val&0x000000ff)); |
|
1613 } |
|
1614 break; |
|
1615 default: |
|
1616 break; |
|
1617 } |
|
1618 aDes.Set((TUint8*)aDes.Ptr()+len, aDes.Length()-len); |
|
1619 return len; |
|
1620 } |
|
1621 |
|
1622 |
|
1623 TInt CPppLog::DumpIp6cpOption(TPtrC8& aDes) |
|
1624 { |
|
1625 |
|
1626 TUint8* ptr = (TUint8*)aDes.Ptr(); |
|
1627 TUint8 opt = *ptr++; |
|
1628 TUint8 len = *ptr++; |
|
1629 |
|
1630 Printf(KCodeTextString, Ip6cpCodeToText(opt), opt); |
|
1631 Printf(KLengthString2, len); |
|
1632 |
|
1633 |
|
1634 switch (opt) |
|
1635 { |
|
1636 case KPppIp6cpOptInterfaceIdentifier: |
|
1637 { |
|
1638 TUint16 s1 = BigEndian::Get16( ptr ); |
|
1639 ptr+=2; |
|
1640 TUint16 s2 = BigEndian::Get16( ptr ); |
|
1641 ptr+=2; |
|
1642 TUint16 s3 = BigEndian::Get16( ptr ); |
|
1643 ptr+=2; |
|
1644 TUint16 s4 = BigEndian::Get16( ptr ); |
|
1645 ptr+=2; |
|
1646 Printf(KIpv6IfIdent, s1,s2,s3,s4); |
|
1647 break; |
|
1648 } |
|
1649 case KPppIp6cpOptCompressionProtocol: |
|
1650 { |
|
1651 TUint16 prot = BigEndian::Get16(ptr); |
|
1652 ptr += 2; |
|
1653 Printf(KProtocolTextString, ProtocolToText(prot), prot); |
|
1654 if (len>4) |
|
1655 { |
|
1656 switch (prot) |
|
1657 { |
|
1658 case KPppIdVjCompTcp: |
|
1659 Printf(KMaxSlotString, *ptr++); |
|
1660 Printf(KCompSlotString, *ptr++); |
|
1661 break; |
|
1662 default: |
|
1663 DumpBytes(FOURTEEN_SPACE_MARGIN, ptr+4, len-4); |
|
1664 break; |
|
1665 } |
|
1666 } |
|
1667 break; |
|
1668 } |
|
1669 default: |
|
1670 break; |
|
1671 } |
|
1672 aDes.Set((TUint8*)aDes.Ptr()+len, aDes.Length()-len); |
|
1673 return len; |
|
1674 } |
|
1675 |
|
1676 const TText* CPppLog::ProtocolToText(TUint aValue) |
|
1677 { |
|
1678 |
|
1679 // Protocols |
|
1680 switch (aValue) |
|
1681 { |
|
1682 case KPppIdLcp: |
|
1683 return _S("LCP"); |
|
1684 case KPppIdPap: |
|
1685 return _S("PAP"); |
|
1686 case KPppIdChap: |
|
1687 return _S("CHAP"); |
|
1688 case KPppIdMsCbcp: |
|
1689 return _S("MSCBCP"); |
|
1690 case KPppIdIpcp: |
|
1691 return _S("IPCP"); |
|
1692 case KPppIdIp6cp: |
|
1693 return _S("IP6CP"); |
|
1694 case KPppIdIp: |
|
1695 return _S("IP"); |
|
1696 case KPppIdIp6: |
|
1697 return _S("IPv6"); |
|
1698 case KPppIdVjCompTcp: |
|
1699 return _S("VJ Comp tcp"); |
|
1700 case KPppIdVjUncompTcp: |
|
1701 return _S("VJ Uncomp tcp"); |
|
1702 case KPppIdCcp: |
|
1703 return _S("CCP"); |
|
1704 case KPppIdCompressed: |
|
1705 return _S("PPP Compressed"); |
|
1706 default: |
|
1707 return _S("Unknown"); |
|
1708 } |
|
1709 } |
|
1710 |
|
1711 const TText* CPppLog::StateToText(TPppFsmState aState) |
|
1712 { |
|
1713 |
|
1714 // States |
|
1715 switch (aState) |
|
1716 { |
|
1717 case EPppFsmInitial: |
|
1718 return _S("INITIAL"); |
|
1719 case EPppFsmStarting: |
|
1720 return _S("STARTING"); |
|
1721 case EPppFsmClosed: |
|
1722 return _S("CLOSED"); |
|
1723 case EPppFsmStopped: |
|
1724 return _S("STOPPED"); |
|
1725 case EPppFsmStopping: |
|
1726 return _S("STOPPING"); |
|
1727 case EPppFsmClosing: |
|
1728 return _S("CLOSING"); |
|
1729 case EPppFsmReqSent: |
|
1730 return _S("REQUEST SENT"); |
|
1731 case EPppFsmAckRecvd: |
|
1732 return _S("ACK RECEIVED"); |
|
1733 case EPppFsmAckSent: |
|
1734 return _S("ACK SENT"); |
|
1735 case EPppFsmOpened: |
|
1736 return _S("OPENED"); |
|
1737 default: // Should never happen in theory! |
|
1738 return _S("UNKNOWN"); |
|
1739 } |
|
1740 } |
|
1741 |
|
1742 const TText* CPppLog::PhaseToText(TPppPhase aPhase) |
|
1743 { |
|
1744 |
|
1745 // Phases |
|
1746 switch (aPhase) |
|
1747 { |
|
1748 case EPppPhaseTerminate: |
|
1749 return _S("TERMINATE"); |
|
1750 case EPppPhaseEstablish: |
|
1751 return _S("ESTABLISH"); |
|
1752 case EPppPhaseEarlyCallback: |
|
1753 return _S("EARLY CALLBACK"); |
|
1754 case EPppPhaseAuthenticate: |
|
1755 return _S("AUTHENTICATE"); |
|
1756 case EPppPhaseLateCallback: |
|
1757 return _S("LATE CALLBACK"); |
|
1758 case EPppPhaseNetwork: |
|
1759 return _S("NETWORK"); |
|
1760 default: // Should never happen in theory! |
|
1761 return _S("UNKNOWN"); |
|
1762 } |
|
1763 } |
|
1764 |
|
1765 const TText* CPppLog::LcpCodeToText(TUint aValue) |
|
1766 { |
|
1767 |
|
1768 // LCP Codes |
|
1769 switch (aValue) |
|
1770 { |
|
1771 case KPppLcpEchoRequest: |
|
1772 return _S("Echo request"); |
|
1773 case KPppLcpEchoReply: |
|
1774 return _S("Echo reply"); |
|
1775 case KPppLcpDiscardRequest: |
|
1776 return _S("Discard request"); |
|
1777 case KPppLcpIdentification: |
|
1778 return _S("Identification"); |
|
1779 case KPppLcpTimeRemaining: |
|
1780 return _S("Time remaining"); |
|
1781 default: |
|
1782 return FsmCodeToText(aValue); |
|
1783 } |
|
1784 } |
|
1785 |
|
1786 const TText* CPppLog::FsmCodeToText(TUint aValue) |
|
1787 { |
|
1788 |
|
1789 // LCP Codes |
|
1790 switch (aValue) |
|
1791 { |
|
1792 case KPppLcpConfigRequest: |
|
1793 return _S("Config Request"); |
|
1794 case KPppLcpConfigAck: |
|
1795 return _S("Config ACK"); |
|
1796 case KPppLcpConfigNak: |
|
1797 return _S("Config NAK"); |
|
1798 case KPppLcpConfigReject: |
|
1799 return _S("Config Reject"); |
|
1800 case KPppLcpTerminateRequest: |
|
1801 return _S("Terminate request"); |
|
1802 case KPppLcpTerminateAck: |
|
1803 return _S("Terminate ACK"); |
|
1804 case KPppLcpCodeReject: |
|
1805 return _S("Code Reject"); |
|
1806 case KPppLcpProtocolReject: |
|
1807 return _S("Protocol Reject"); |
|
1808 case KPppCcpResetReq: |
|
1809 // Only used by CCP, but this is the easiest place to put it |
|
1810 return _S("Reset Request"); |
|
1811 case KPppCcpResetAck: |
|
1812 // Only used by CCP, but this is the easiest place to put it |
|
1813 //__DEBUGGER(); |
|
1814 return _S("Reset Ack"); |
|
1815 default: |
|
1816 return _S("Unknown"); |
|
1817 } |
|
1818 } |
|
1819 |
|
1820 const TText* CPppLog::LcpOptToText(TUint aValue) |
|
1821 { |
|
1822 |
|
1823 // LCP Options |
|
1824 switch (aValue) |
|
1825 { |
|
1826 case KPppLcpOptMaxRecvUnit: |
|
1827 return _S("Max receive size"); |
|
1828 case KPppLcpOptEscapeCharMap: |
|
1829 return _S("Escape char map"); |
|
1830 case KPppLcpOptAuthenticationProtocol: |
|
1831 return _S("Authentication protocol"); |
|
1832 case KPppLcpOptQualityProtocol: |
|
1833 return _S("Quality protocol"); |
|
1834 case KPppLcpOptMagicNumber: |
|
1835 return _S("Magic number"); |
|
1836 case KPppLcpOptProtocolCompress: |
|
1837 return _S("Protocol field compression"); |
|
1838 case KPppLcpOptAddrCtrlCompress: |
|
1839 return _S("Addr & Ctrl field compression"); |
|
1840 case KPppLcpOptFcsType: |
|
1841 return _S("Fcs Type"); |
|
1842 case KPppLcpOptPadding: |
|
1843 return _S("Padding"); |
|
1844 case KPppLcpOptCallback: |
|
1845 return _S("Callback protocol"); |
|
1846 case KPppLcpOptCompoundFrames: |
|
1847 return _S("Compound frames"); |
|
1848 case KPppLcpOptMRRU: |
|
1849 return _S("MRRU"); |
|
1850 case KPppLcpOptMultiLinkEndPointDescriminator: |
|
1851 return _S("Multi-link End-Point Descriminator"); |
|
1852 default: |
|
1853 return _S("Unknown"); |
|
1854 } |
|
1855 } |
|
1856 |
|
1857 const TText* CPppLog::CallbackOpToText(TUint aValue) |
|
1858 { |
|
1859 |
|
1860 // CB Codes |
|
1861 switch (aValue) |
|
1862 { |
|
1863 case 0: |
|
1864 return _S("Location preset"); |
|
1865 case 1: |
|
1866 return _S("Dialing string"); |
|
1867 case 2: |
|
1868 return _S("Location identifier"); |
|
1869 case 3: |
|
1870 return _S("E.164 number"); |
|
1871 case 4: |
|
1872 return _S("Distinguished name"); |
|
1873 case 5: |
|
1874 return _S("E.165 number"); |
|
1875 case 6: |
|
1876 return _S("MS CBCP"); |
|
1877 default: |
|
1878 return _S("Unknown operation"); |
|
1879 } |
|
1880 } |
|
1881 |
|
1882 const TText* CPppLog::PapCodeToText(TUint aValue) |
|
1883 { |
|
1884 |
|
1885 // PAP Codes |
|
1886 switch (aValue) |
|
1887 { |
|
1888 case 1: |
|
1889 return _S("Authenticate Request"); |
|
1890 case 2: |
|
1891 return _S("Authenticate ACK"); |
|
1892 case 3: |
|
1893 return _S("Authenticate NAK"); |
|
1894 default: |
|
1895 return _S("Unknown"); |
|
1896 } |
|
1897 } |
|
1898 |
|
1899 const TText* CPppLog::CbcpCodeToText(TUint aValue) |
|
1900 { |
|
1901 |
|
1902 // CBCP Codes |
|
1903 switch (aValue) |
|
1904 { |
|
1905 case 1: |
|
1906 return _S("Callback Request"); |
|
1907 case 2: |
|
1908 return _S("Callback Response"); |
|
1909 case 3: |
|
1910 return _S("Callback Ack"); |
|
1911 default: |
|
1912 return _S("Unknown"); |
|
1913 } |
|
1914 } |
|
1915 |
|
1916 const TText* CPppLog::ChapCodeToText(TUint aValue) |
|
1917 { |
|
1918 |
|
1919 // CHAP Codes |
|
1920 switch (aValue) |
|
1921 { |
|
1922 case 1: |
|
1923 return _S("Challenge"); |
|
1924 case 2: |
|
1925 return _S("Response"); |
|
1926 case 3: |
|
1927 return _S("Success"); |
|
1928 case 4: |
|
1929 return _S("Failure"); |
|
1930 default: |
|
1931 return _S("Unknown"); |
|
1932 } |
|
1933 } |
|
1934 |
|
1935 const TText* CPppLog::IpProtocolToText(TUint aValue) |
|
1936 { |
|
1937 |
|
1938 // IP Protocols |
|
1939 switch (aValue) |
|
1940 { |
|
1941 case 1: |
|
1942 return _S("ICMP"); |
|
1943 case 58: |
|
1944 return _S("ICMPv6"); |
|
1945 case 17: |
|
1946 return _S("UDP"); |
|
1947 case 6: |
|
1948 return _S("TCP"); |
|
1949 |
|
1950 default: |
|
1951 return _S("Unknown"); |
|
1952 } |
|
1953 } |
|
1954 |
|
1955 const TText* CPppLog::IpcpCodeToText(TUint aValue) |
|
1956 { |
|
1957 |
|
1958 // IPCP Codes |
|
1959 switch (aValue) |
|
1960 { |
|
1961 case KPppIpcpOptIpAddresses: |
|
1962 return _S("IP Addresses"); |
|
1963 case KPppIpcpOptIpCompressionProtocol: |
|
1964 return _S("IP Compression Protocol"); |
|
1965 case KPppIpcpOptIpAddress: |
|
1966 return _S("IP Address"); |
|
1967 case KPppIpcpOptPrimaryDnsAddress: |
|
1968 return _S("Primary DNS Address"); |
|
1969 case KPppIpcpOptSecondaryDnsAddress: |
|
1970 return _S("Secondary DNS Address"); |
|
1971 case KPppIpcpOptPrimaryNbnsAddress: |
|
1972 return _S("Primary NBNS Address"); |
|
1973 case KPppIpcpOptSecondaryNbnsAddress: |
|
1974 return _S("Secondary NBNS Address"); |
|
1975 default: |
|
1976 return _S("Unknown"); |
|
1977 } |
|
1978 } |
|
1979 |
|
1980 const TText* CPppLog::Ip6cpCodeToText(TUint aValue) |
|
1981 { |
|
1982 // IP6CP Codes |
|
1983 switch (aValue) |
|
1984 { |
|
1985 case KPppIp6cpOptInterfaceIdentifier: |
|
1986 return _S("Interface Identifier"); |
|
1987 case KPppIp6cpOptCompressionProtocol: |
|
1988 return _S("Compression Protocol"); |
|
1989 default: |
|
1990 return _S("Unknown"); |
|
1991 } |
|
1992 } |
|
1993 |
|
1994 TInt CPppLog::DumpIp(TPtrC8& aDes) |
|
1995 { |
|
1996 |
|
1997 TUint8* ptr = (TUint8*)aDes.Ptr(); |
|
1998 TUint8 c = *ptr++; |
|
1999 // TUint ver = c >> 4; |
|
2000 TUint hlen = (c & 0xf) << 2; |
|
2001 // TUint8 tos = *ptr; |
|
2002 ptr++; |
|
2003 TUint16 len = ByteOrder::Swap16((TUint16)(*ptr | *(ptr+1)<<8)); |
|
2004 ptr+=2; |
|
2005 TUint16 id = ByteOrder::Swap16((TUint16)(*ptr | *(ptr+1)<<8)); |
|
2006 ptr+=2; |
|
2007 TUint16 frag = ByteOrder::Swap16((TUint16)(*ptr | *(ptr+1)<<8)); |
|
2008 ptr+=2; |
|
2009 TBool zf = (frag & 0x8000); |
|
2010 TBool df = (frag & 0x4000); |
|
2011 TBool mf = (frag & 0x2000); |
|
2012 frag = (TUint16)((frag & 0x1fff)<<3); |
|
2013 // TUint8 ttl = *ptr; |
|
2014 ptr++; |
|
2015 TUint8 proto = *ptr++; |
|
2016 // TUint16 chksum = ByteOrder::Swap16((TUint16)(*ptr | *(ptr+1)<<8)); |
|
2017 ptr+=2; |
|
2018 TUint32 srca = ByteOrder::Swap32(*ptr | (*(ptr+1)<<8) | (*(ptr+2)<<16) | (*(ptr+3)<<24)); |
|
2019 ptr+=4; |
|
2020 TUint32 dsta = ByteOrder::Swap32(*ptr | (*(ptr+1)<<8) | (*(ptr+2)<<16) | (*(ptr+3)<<24)); |
|
2021 ptr+=4; |
|
2022 // TBool opts = (hlen>20); |
|
2023 |
|
2024 Printf(KHdrLengthString, len, hlen); |
|
2025 Printf(KSrcDstAddrString,(srca&0xff000000)>>24,(srca&0x00ff0000)>>16,(srca&0x0000ff00)>>8,(srca&0x000000ff), |
|
2026 (dsta&0xff000000)>>24,(dsta&0x00ff0000)>>16,(dsta&0x0000ff00)>>8,(dsta&0x000000ff)); |
|
2027 Printf(KIDFragmentString, id, frag, df?_S("<DF>"):_S(""), mf?_S("<MF>"):_S(""), zf?_S("<Z>"):_S("")); |
|
2028 // Printf(KTOSTTLChksumString, tos, ttl, chksum); |
|
2029 Printf(KCodeTextString, IpProtocolToText(proto), proto); |
|
2030 |
|
2031 if (hlen>20) |
|
2032 ptr += (hlen-20); |
|
2033 |
|
2034 TInt n = (TInt)ptr-(TInt)aDes.Ptr(); |
|
2035 TInt tlen = aDes.Length()-n; |
|
2036 aDes.Set(ptr, tlen); |
|
2037 |
|
2038 if (tlen > 0) |
|
2039 { |
|
2040 switch (proto) |
|
2041 { |
|
2042 case 1: |
|
2043 return n+DumpIcmp(aDes, tlen); |
|
2044 case 6: |
|
2045 return n+DumpTcp(aDes, srca, dsta, tlen); |
|
2046 case 17: |
|
2047 return n+DumpUdp(aDes, srca, dsta, tlen); |
|
2048 default: |
|
2049 break; |
|
2050 } |
|
2051 } |
|
2052 return n; |
|
2053 } |
|
2054 |
|
2055 TInt CPppLog::DumpIp6(TPtrC8& aDes) |
|
2056 { |
|
2057 // This dumps the main IPv6 Header, no support for option headers |
|
2058 // IPv6 Headers are FIXED length, but are chainable... |
|
2059 TUint16* ptr = (TUint16*)aDes.Ptr(); |
|
2060 |
|
2061 // First 32 bits contain version(4), class(8), Flow Label(20) |
|
2062 |
|
2063 TUint32 first = ByteOrder::Swap32((TUint32) *ptr); |
|
2064 //TUint8 ver = (TUint8)((first >> 28) & 0xf); |
|
2065 TUint8 cls = (TUint8)((first >> 20) & 0xff); |
|
2066 TUint32 flowLab = (first & 0xfffff); |
|
2067 ptr+=2; |
|
2068 |
|
2069 // Second 32 bits contain payload length (16), next header type (8), hop limit (8) |
|
2070 TUint16 payLoadLen = ByteOrder::Swap16( *ptr++ ); |
|
2071 TUint16 next = ByteOrder::Swap16( *ptr++ ); |
|
2072 TUint8 nextHead = (TUint8)((next >> 8) & 0xff); |
|
2073 TUint8 hopLimit = (TUint8)(next & 0xff); |
|
2074 |
|
2075 // Source address (128 bits) |
|
2076 TUint16 s1 = ByteOrder::Swap16( *ptr++ ); |
|
2077 TUint16 s2 = ByteOrder::Swap16( *ptr++ ); |
|
2078 TUint16 s3 = ByteOrder::Swap16( *ptr++ ); |
|
2079 TUint16 s4 = ByteOrder::Swap16( *ptr++ ); |
|
2080 TUint16 s5 = ByteOrder::Swap16( *ptr++ ); |
|
2081 TUint16 s6 = ByteOrder::Swap16( *ptr++ ); |
|
2082 TUint16 s7 = ByteOrder::Swap16( *ptr++ ); |
|
2083 TUint16 s8 = ByteOrder::Swap16( *ptr++ ); |
|
2084 |
|
2085 // Destination address (128 bits) |
|
2086 TUint16 a1 = ByteOrder::Swap16( *ptr++ ); |
|
2087 TUint16 a2 = ByteOrder::Swap16( *ptr++ ); |
|
2088 TUint16 a3 = ByteOrder::Swap16( *ptr++ ); |
|
2089 TUint16 a4 = ByteOrder::Swap16( *ptr++ ); |
|
2090 TUint16 a5 = ByteOrder::Swap16( *ptr++ ); |
|
2091 TUint16 a6 = ByteOrder::Swap16( *ptr++ ); |
|
2092 TUint16 a7 = ByteOrder::Swap16( *ptr++ ); |
|
2093 TUint16 a8 = ByteOrder::Swap16( *ptr++ ); |
|
2094 |
|
2095 //Printf(_L(" Version is %d"),ver); // Should be 6 for IPv6 !! |
|
2096 Printf(KIpv6Class, cls); |
|
2097 Printf(KIpv6FlowLabel, flowLab); |
|
2098 Printf(KIpv6PayloadLen, payLoadLen); |
|
2099 Printf(KIpv6NextHeadType, nextHead); |
|
2100 Printf(KIpv6HopLimit, hopLimit); |
|
2101 Printf(KIpv6SrcAddress, s1,s2,s3,s4,s5,s6,s7,s8); |
|
2102 Printf(KIpv6DstAddress, a1,a2,a3,a4,a5,a6,a7,a8); |
|
2103 |
|
2104 TInt n = (TInt)ptr-(TInt)aDes.Ptr(); |
|
2105 TInt tlen = aDes.Length()-n; |
|
2106 aDes.Set( (TUint8*) ptr, tlen); |
|
2107 |
|
2108 switch (nextHead) |
|
2109 { |
|
2110 case 6: // TCP Packet |
|
2111 Printf(_L(" TCP Data")); |
|
2112 //DumpTcp(aDes); |
|
2113 HexDump(EIGHT_SPACE_MARGIN,EIGHT_SPACE_MARGIN, aDes.Ptr(), tlen); |
|
2114 break; |
|
2115 case 17: // UDP Packet |
|
2116 Printf(_L(" UDP Data")); |
|
2117 DumpUdp(aDes,s8,a8,tlen); |
|
2118 break; |
|
2119 case 43: // Routing Header |
|
2120 Printf(_L(" Routing Header")); |
|
2121 //DumpRouter |
|
2122 HexDump(EIGHT_SPACE_MARGIN,EIGHT_SPACE_MARGIN, aDes.Ptr(), tlen); |
|
2123 break; |
|
2124 case 44: // Fragment Header |
|
2125 Printf(_L(" Packet Fragment")); |
|
2126 //DumpFragment |
|
2127 HexDump(EIGHT_SPACE_MARGIN,EIGHT_SPACE_MARGIN, aDes.Ptr(), tlen); |
|
2128 break; |
|
2129 case 50: // ESP Payload |
|
2130 Printf(_L(" ESP Payload")); |
|
2131 HexDump(EIGHT_SPACE_MARGIN,EIGHT_SPACE_MARGIN, aDes.Ptr(), tlen); |
|
2132 break; |
|
2133 case 58: // ICMPv6 |
|
2134 Printf(_L(" ICMPv6")); |
|
2135 DumpIcmp(aDes,tlen); |
|
2136 break; |
|
2137 case 59: // No Next Header |
|
2138 Printf(_L(" NO NEXT HEADER")); |
|
2139 HexDump(EIGHT_SPACE_MARGIN,EIGHT_SPACE_MARGIN, aDes.Ptr(), tlen); |
|
2140 break; |
|
2141 default: |
|
2142 Printf(KIpv6UnknownHeadType, nextHead); |
|
2143 HexDump(EIGHT_SPACE_MARGIN,EIGHT_SPACE_MARGIN, aDes.Ptr(), tlen); |
|
2144 } |
|
2145 |
|
2146 return n; |
|
2147 } |
|
2148 |
|
2149 TInt CPppLog::DumpTcp(TPtrC8& aDes, TUint32 aSrcA, TUint32 aDstA, TInt aLength) |
|
2150 { |
|
2151 |
|
2152 TInt n = Min(aLength, aDes.Length()); |
|
2153 TInt len = n; |
|
2154 |
|
2155 TUint8* ptr = (TUint8*)aDes.Ptr(); |
|
2156 TUint8 osum0 = ptr[16]; |
|
2157 ptr[16] = 0; |
|
2158 TUint8 osum1 = ptr[17]; |
|
2159 ptr[17] = 0; |
|
2160 |
|
2161 TUint32 sum = 0; |
|
2162 sum += (aSrcA >> 16); |
|
2163 sum += (aSrcA & 0xffff); |
|
2164 sum += (aDstA >> 16); |
|
2165 sum += (aDstA & 0xffff); |
|
2166 sum += 6; |
|
2167 sum += n; |
|
2168 while (n>1) |
|
2169 { |
|
2170 sum += (ptr[0]<<8); |
|
2171 sum += (ptr[1]); |
|
2172 ptr += 2; |
|
2173 n -= 2; |
|
2174 } |
|
2175 if (n>0) |
|
2176 sum += (ptr[0]<<8); |
|
2177 while (sum>0xffff) |
|
2178 { |
|
2179 sum = (sum & 0xffff) + (sum>>16); |
|
2180 } |
|
2181 sum = ~sum & 0xffff; |
|
2182 ptr = (TUint8*)aDes.Ptr(); |
|
2183 ptr[16] = osum0; |
|
2184 ptr[17] = osum1; |
|
2185 |
|
2186 TUint srcp = ByteOrder::Swap16((TUint16)(*ptr | (*(ptr+1)<<8))); |
|
2187 ptr +=2; |
|
2188 TUint dstp = ByteOrder::Swap16((TUint16)(*ptr | (*(ptr+1)<<8))); |
|
2189 ptr +=2; |
|
2190 TUint32 seqnum = ByteOrder::Swap32(*ptr | (*(ptr+1)<<8) | (*(ptr+2)<<16) | (*(ptr+3)<<24)); |
|
2191 ptr+=4; |
|
2192 TUint32 acknum = ByteOrder::Swap32(*ptr | (*(ptr+1)<<8) | (*(ptr+2)<<16) | (*(ptr+3)<<24)); |
|
2193 ptr+=4; |
|
2194 |
|
2195 TUint16 hlenflag = ByteOrder::Swap16((TUint16)(*ptr | *(ptr+1)<<8)); |
|
2196 |
|
2197 TUint hlen = (hlenflag>>12)<<2; |
|
2198 TUint flag = (hlenflag & 0x0fff); |
|
2199 TBool cwrf = (hlenflag & 0x0080); |
|
2200 TBool ecef = (hlenflag & 0x0040); |
|
2201 TBool urgf = (hlenflag & 0x0020); |
|
2202 TBool ackf = (hlenflag & 0x0010); |
|
2203 TBool pshf = (hlenflag & 0x0008); |
|
2204 TBool rstf = (hlenflag & 0x0004); |
|
2205 TBool synf = (hlenflag & 0x0002); |
|
2206 TBool finf = (hlenflag & 0x0001); |
|
2207 ptr+=2; |
|
2208 TUint window = ByteOrder::Swap16((TUint16)(*ptr | (*(ptr+1)<<8))); |
|
2209 ptr+=2; |
|
2210 TUint chksum = ByteOrder::Swap16((TUint16)(*ptr | (*(ptr+1)<<8))); |
|
2211 ptr+=2; |
|
2212 TUint urgptr = ByteOrder::Swap16((TUint16)(*ptr | (*(ptr+1)<<8))); |
|
2213 ptr+=2; |
|
2214 |
|
2215 Printf(KTCPLengthString, len, hlen); |
|
2216 Printf(KPortString, srcp, dstp); |
|
2217 // Printf(KDestPortString, dstp); |
|
2218 // Printf(KTCPHeaderLengthString, hlen); |
|
2219 Printf(KSeqAckString, seqnum, acknum); |
|
2220 Printf(KFlagsString, flag, cwrf?_S(" <CWR>"):_S(""),ecef?_S(" <ECE>"):_S(""),urgf?_S(" <URG>"):_S(""), ackf?_S(" <ACK>"):_S(""), pshf?_S(" <PSH>"):_S(""), |
|
2221 rstf?_S(" <RST>"):_S(""), synf?_S(" <SYN>"):_S(""), finf?_S(" <FIN>"):_S("")); |
|
2222 Printf(KWindowUrgentString, window, urgptr); |
|
2223 if (chksum != sum) |
|
2224 Printf(KChecksumString3, chksum, sum); |
|
2225 |
|
2226 if (hlen>20) |
|
2227 { |
|
2228 _LIT(string2," TCP Options %d bytes"); |
|
2229 Printf(string2, hlen-20); |
|
2230 TInt h, i, opt, optlen=0; |
|
2231 h = hlen-20; |
|
2232 for (i=0; i<h; i+=optlen) |
|
2233 { |
|
2234 opt = ptr[i]; |
|
2235 if (opt == 0) // KTcpOptEol |
|
2236 break; |
|
2237 if (opt == 1) // KTcpOptNop |
|
2238 optlen = 1; |
|
2239 else |
|
2240 { |
|
2241 if (i+1 >= h) |
|
2242 break; |
|
2243 optlen = ptr[i+1]; |
|
2244 if (optlen < 2) |
|
2245 optlen = 2; |
|
2246 } |
|
2247 |
|
2248 switch (opt) |
|
2249 { |
|
2250 case 1: |
|
2251 { |
|
2252 _LIT(string3," NOP"); |
|
2253 Write(string3); |
|
2254 } |
|
2255 break; |
|
2256 case 2: |
|
2257 { |
|
2258 _LIT(string4," Max Seg Size = %d"); |
|
2259 Printf(string4, BigEndian::Get16(ptr+i+2)); |
|
2260 } |
|
2261 break; |
|
2262 default: |
|
2263 { |
|
2264 _LIT(string5," Unknown [0x%02x]"); |
|
2265 Printf(string5, opt); |
|
2266 } |
|
2267 break; |
|
2268 } |
|
2269 } |
|
2270 } |
|
2271 |
|
2272 ptr += (hlen-20); |
|
2273 TInt n1 = (TInt)aDes.Ptr()-(TInt)ptr; |
|
2274 aDes.Set(ptr, aDes.Length()-n1); |
|
2275 return n1; |
|
2276 } |
|
2277 |
|
2278 TInt CPppLog::DumpIcmp(TPtrC8& aDes, TInt aLength) |
|
2279 { |
|
2280 |
|
2281 if (aLength < 2) |
|
2282 return 0; |
|
2283 |
|
2284 const TUint8* ptr = aDes.Ptr(); |
|
2285 |
|
2286 _LIT(string1," Type = %d, Code = %d"); |
|
2287 Printf(string1, *ptr, *(ptr+1)); |
|
2288 HexDump(FOURTEEN_SPACE_MARGIN, FOURTEEN_SPACE_MARGIN, ptr, aLength); |
|
2289 return 0; |
|
2290 } |
|
2291 |
|
2292 TInt CPppLog::DumpUdp(TPtrC8& aDes, TUint32 /* aSrcA */, TUint32 /*aDstA */, TInt aLength) |
|
2293 { |
|
2294 if (aLength < 6) |
|
2295 return 0; |
|
2296 |
|
2297 TUint8* ptr = (TUint8*)aDes.Ptr(); |
|
2298 TUint srcp = ByteOrder::Swap16((TUint16)(*ptr | (*(ptr+1)<<8))); |
|
2299 ptr +=2; |
|
2300 TUint dstp = ByteOrder::Swap16((TUint16)(*ptr | (*(ptr+1)<<8))); |
|
2301 ptr +=2; |
|
2302 TUint16 len = ByteOrder::Swap16((TUint16)(*ptr | (*(ptr+1)<<8))); |
|
2303 ptr += 2; |
|
2304 |
|
2305 ptr += 2; // skip checksum |
|
2306 Printf(KUDPLengthPortString, len, srcp, dstp); |
|
2307 //Printf(KPortString, srcp, dstp); |
|
2308 |
|
2309 if (srcp == KDnsPort || dstp == KDnsPort) |
|
2310 { |
|
2311 UpdatePtr(aDes, ptr); |
|
2312 return DumpDns(aDes); |
|
2313 } |
|
2314 |
|
2315 // aDes.Set(remptr, remlen); |
|
2316 return 0; |
|
2317 } |
|
2318 |
|
2319 TInt CPppLog::UpdatePtr(TPtrC8& aDes, TUint8* ptr) |
|
2320 { |
|
2321 TInt n = (TInt)ptr - (TInt)aDes.Ptr(); |
|
2322 TInt tlen = aDes.Length() - n; |
|
2323 aDes.Set(ptr, tlen); |
|
2324 return tlen; |
|
2325 } |
|
2326 |
|
2327 // |
|
2328 // Dump DNS request/response |
|
2329 // |
|
2330 |
|
2331 TInt CPppLog::DumpDns(TPtrC8& aDes) |
|
2332 { |
|
2333 if (aDes.Length()< 12) |
|
2334 return 0; |
|
2335 |
|
2336 TUint8* ptr = (TUint8*)aDes.Ptr(); |
|
2337 |
|
2338 _LIT(KDnsHdrString, "\t\tDNS Id = 0x%02x, Flags = 0x%02x"); |
|
2339 _LIT(KDnsQuestionString, "\t\tQuestions = %d"); |
|
2340 _LIT(KDnsAnswerString, "\t\tAnswers = %d"); |
|
2341 _LIT(KDnsAuthAddString, "\t\tAuthorities = %d, Additionals = %d"); |
|
2342 |
|
2343 TUint Id = ByteOrder::Swap16((TUint16)(*ptr | (*(ptr+1)<<8))); |
|
2344 ptr += 2; |
|
2345 TUint Flags = ByteOrder::Swap16((TUint16)(*ptr | (*(ptr+1)<<8))); |
|
2346 ptr += 2; |
|
2347 |
|
2348 Printf(KDnsHdrString, Id, Flags); |
|
2349 |
|
2350 TUint nques = ByteOrder::Swap16((TUint16)(*ptr | (*(ptr+1)<<8))); |
|
2351 ptr += 2; |
|
2352 TUint nans = ByteOrder::Swap16((TUint16)(*ptr | (*(ptr+1)<<8))); |
|
2353 ptr += 2; |
|
2354 TUint nauth = ByteOrder::Swap16((TUint16)(*ptr | (*(ptr+1)<<8))); |
|
2355 ptr += 2; |
|
2356 TUint nadd = ByteOrder::Swap16((TUint16)(*ptr | (*(ptr+1)<<8))); |
|
2357 ptr += 2; |
|
2358 |
|
2359 UpdatePtr(aDes, ptr); |
|
2360 |
|
2361 // Only deal with one query for now due to difficulty of testing |
|
2362 |
|
2363 if (nques > 0) |
|
2364 { |
|
2365 Printf(KDnsQuestionString, nques); |
|
2366 if (DumpDnsQuery(aDes) < 0) |
|
2367 return 0; |
|
2368 } |
|
2369 |
|
2370 if (nques > 1) |
|
2371 return 0; |
|
2372 |
|
2373 if (nans > 0) |
|
2374 { |
|
2375 Printf(KDnsAnswerString, nans); |
|
2376 while (nans-- > 0) |
|
2377 if (DumpDnsAnswer(aDes) < 0) |
|
2378 return 0; |
|
2379 } |
|
2380 |
|
2381 if (nauth > 0 || nadd > 0) |
|
2382 Printf(KDnsAuthAddString, nauth, nadd); |
|
2383 |
|
2384 // Write(KEndOfLine); |
|
2385 |
|
2386 // aDes.Set(remptr, remlen); |
|
2387 return 0; |
|
2388 } |
|
2389 |
|
2390 TInt CPppLog::DumpDnsQuery(TPtrC8& aDes) |
|
2391 { |
|
2392 if (DumpDnsNameAndType(aDes) < 0 || aDes.Length() < 2) |
|
2393 return -1; |
|
2394 |
|
2395 UpdatePtr(aDes, (TUint8*) aDes.Ptr() + 2); // skip over class |
|
2396 |
|
2397 return 0; |
|
2398 } |
|
2399 |
|
2400 TInt CPppLog::DumpDnsAnswer(TPtrC8& aDes) |
|
2401 { |
|
2402 _LIT(KDnsAnswerResource, "\t\t Resource = %d.%d.%d.%d"); |
|
2403 |
|
2404 if (DumpDnsNameAndType(aDes) < 0 || aDes.Length() < 8) |
|
2405 return -1; |
|
2406 |
|
2407 // above check guarantees at least Class, TTL and Resource Data Length |
|
2408 // fields are present |
|
2409 |
|
2410 TUint8* ptr = (TUint8*)aDes.Ptr(); |
|
2411 |
|
2412 ptr += 6; // skip over class and ttl |
|
2413 |
|
2414 TUint resourceLen = ByteOrder::Swap16((TUint16)(*ptr | (*(ptr+1)<<8))); |
|
2415 ptr += 2; |
|
2416 |
|
2417 if ((TUint) aDes.Length() < 8 + resourceLen) |
|
2418 return -1; |
|
2419 |
|
2420 if (resourceLen == 4) |
|
2421 { |
|
2422 // IPv4 address |
|
2423 TUint addr = ByteOrder::Swap32(*ptr | (*(ptr+1)<<8) | (*(ptr+2)<<16) | (*(ptr+3)<<24)); |
|
2424 Printf(KDnsAnswerResource, (addr&0xff000000)>>24,(addr&0x00ff0000)>>16,(addr&0x0000ff00)>>8,(addr&0x000000ff)); |
|
2425 } |
|
2426 |
|
2427 ptr += resourceLen; |
|
2428 |
|
2429 UpdatePtr(aDes, ptr); |
|
2430 |
|
2431 return 0; |
|
2432 } |
|
2433 |
|
2434 TInt CPppLog::DumpDnsNameAndType(TPtrC8& aDes) |
|
2435 { |
|
2436 TBuf<120>buf; |
|
2437 TUint8* ptr = (TUint8*)aDes.Ptr(); |
|
2438 TInt length = aDes.Length(); |
|
2439 TUint count; |
|
2440 |
|
2441 _LIT(KDnsNameString, "\t\t Name = "); |
|
2442 _LIT(KDnsDot, "."); |
|
2443 _LIT(KDnsNameCompString, "<%d>"); |
|
2444 _LIT(KDnsType, ", Type = %d"); |
|
2445 |
|
2446 const TInt KDnsNameCompStringMaxLen = 7; |
|
2447 buf.Append(KDnsNameString); |
|
2448 |
|
2449 if (length < 1) |
|
2450 return -1; |
|
2451 |
|
2452 count = *ptr++; |
|
2453 length--; |
|
2454 |
|
2455 while (count > 0) |
|
2456 { |
|
2457 |
|
2458 // Not dealing with compression yet |
|
2459 |
|
2460 if (count & 0xc0) |
|
2461 { |
|
2462 if (length > 0) |
|
2463 { |
|
2464 count = ((count & ~0xc0) << 8) | *ptr++; |
|
2465 length--; |
|
2466 if (buf.Length() + KDnsNameCompStringMaxLen >= buf.MaxLength()) |
|
2467 return -1; |
|
2468 else |
|
2469 { |
|
2470 buf.AppendFormat(KDnsNameCompString, count); |
|
2471 break; |
|
2472 } |
|
2473 } |
|
2474 else |
|
2475 return -1; |
|
2476 } |
|
2477 |
|
2478 if (count > 63) |
|
2479 return -1; |
|
2480 |
|
2481 if ((TUint)length < count) |
|
2482 return -1; |
|
2483 length -= count; |
|
2484 |
|
2485 while (count-- > 0) |
|
2486 { |
|
2487 if (buf.Length() >= buf.MaxLength()) |
|
2488 return -1; |
|
2489 buf.Append(*ptr); |
|
2490 ptr++; |
|
2491 } |
|
2492 |
|
2493 if (length > 0) |
|
2494 { |
|
2495 count = *ptr++; |
|
2496 length--; |
|
2497 if (count > 0) |
|
2498 { |
|
2499 if (buf.Length() >= buf.MaxLength()) |
|
2500 return -1; |
|
2501 buf.Append(KDnsDot); |
|
2502 } |
|
2503 } |
|
2504 } |
|
2505 |
|
2506 TUint type = ByteOrder::Swap16((TUint16)(*ptr | (*(ptr+1)<<8))); |
|
2507 ptr += 2; |
|
2508 buf.AppendFormat(KDnsType, type); |
|
2509 |
|
2510 Write(buf); |
|
2511 |
|
2512 UpdatePtr(aDes, ptr); |
|
2513 |
|
2514 return 0; |
|
2515 } |
|
2516 |
|
2517 #endif //ESOCK_LOGGING_ACTIVE |