|
1 // Copyright (c) 2006-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 file implements the CIPv4Binder class, which handles the transmission |
|
15 // of IPv4 data to and from the TCP/IP stack. |
|
16 // |
|
17 // |
|
18 |
|
19 /** |
|
20 @file |
|
21 */ |
|
22 |
|
23 #include <etelpckt.h> |
|
24 #include <in_iface.h> |
|
25 #include "RawIPFlow.h" |
|
26 #include "IPv4Binder.h" |
|
27 #include <comms-infras/linkprovision.h> |
|
28 |
|
29 using namespace ESock; |
|
30 #ifdef WCDMA_STUB |
|
31 #include <networking/umtsnifcontrolif.h> |
|
32 #endif |
|
33 |
|
34 #define LOG_IP_ADDRESS(desc,addr) _LOG_L1C5(_L8(" " desc " = %d.%d.%d.%d"), \ |
|
35 addr >> 24, (addr >> 16) & 0xFF, (addr >> 8) & 0xFF, addr & 0xFF); |
|
36 |
|
37 CIPv4Binder::CIPv4Binder(CRawIPFlow& aFlow, CBttLogger* aTheLogger) |
|
38 /** |
|
39 * Constructor |
|
40 */ |
|
41 : CBinderBase(aFlow,aTheLogger), |
|
42 iSpeedMetric(KDefaultSpeedMetric) |
|
43 { |
|
44 } |
|
45 |
|
46 CIPv4Binder::~CIPv4Binder() |
|
47 /** |
|
48 * Destructor |
|
49 */ |
|
50 { |
|
51 } |
|
52 |
|
53 MLowerDataSender* CIPv4Binder::Bind(MUpperDataReceiver* aUpperReceiver, MUpperControl* aUpperControl) |
|
54 /** |
|
55 * Binds TCP/IP protocol to Flow |
|
56 * |
|
57 * @param aUpperReceiver A pointer to Upper layer Receive class |
|
58 * @param aUpperControl A pointer to Upper layer control class |
|
59 */ |
|
60 { |
|
61 CBinderBase::Bind(aUpperReceiver, aUpperControl); // Call the superclass's method. |
|
62 return this; |
|
63 } |
|
64 |
|
65 TInt CIPv4Binder::Control(TUint aLevel, TUint aName, TDes8& aOption) |
|
66 /** |
|
67 * The main function called by the TCP/IP protocol to control the interface. |
|
68 * Can perform a variety of general IP tasks (such as getting IP config) |
|
69 * and "3G" specific tasks (such as deleting the context). |
|
70 * |
|
71 * @param aLevel The level of the interface to control - always KSOLInterface |
|
72 * @param aName The command to perform |
|
73 * @param aOption Data to be input/output as a result of the command |
|
74 * @return Standard error codes |
|
75 */ |
|
76 { |
|
77 _LOG_L1C3(_L8("CIPv4Binder::Control [aLevel=%d, aName=%d]"), |
|
78 aLevel, aName); |
|
79 |
|
80 if (aLevel == KSOLInterface) |
|
81 { |
|
82 switch (aName) |
|
83 { |
|
84 case KSoIfHardwareAddr: |
|
85 // unsupported because we don't have a h/w address |
|
86 break; |
|
87 |
|
88 // 3G-specific configuration commands are below this point. |
|
89 #ifdef WCDMA_STUB |
|
90 case KRegisterEventHandler: |
|
91 // Raw IP NIF Events are not supported |
|
92 case KContextSetEvents: |
|
93 // Raw IP NIF Events are not supported |
|
94 break; |
|
95 |
|
96 case KContextCreate: |
|
97 // We don't support creating new secondary contexts. |
|
98 break; |
|
99 |
|
100 case KContextDelete: |
|
101 // Deletes the primary PDP context. This will shut down the Nif. |
|
102 return DeleteContext(aOption); |
|
103 |
|
104 case KContextActivate: |
|
105 // If the IPv4 interface is up, then the context will already have |
|
106 // been activated. So this command should fail with |
|
107 // KErrAlreadyExists |
|
108 { |
|
109 TUint8* ptr = CONST_CAST(TUint8*, aOption.Ptr()); |
|
110 TContextParameters* contextParams = |
|
111 REINTERPRET_CAST(TContextParameters*, ptr); |
|
112 |
|
113 if (contextParams->iContextInfo.iContextId != |
|
114 STATIC_CAST(TInt8, GetFlow().GetBcaController()->Nsapi())) |
|
115 { |
|
116 contextParams->iReasonCode = KErrNotFound; |
|
117 } |
|
118 else |
|
119 { |
|
120 contextParams->iContextInfo.iStatus = |
|
121 GetFlow().GetContextStatus(); |
|
122 contextParams->iReasonCode = KErrAlreadyExists; |
|
123 } |
|
124 return KErrNone; |
|
125 } |
|
126 |
|
127 case KNifSetDefaultQoS: |
|
128 case KContextQoSSet: |
|
129 // Setting the QoS is meaningless over GPRS, so we just return that |
|
130 // we don't support these operations. |
|
131 break; |
|
132 |
|
133 case KContextTFTModify: |
|
134 // As we only have one primary context, we don't support anything |
|
135 // to do with traffic flow templates, which are used by secondary |
|
136 // contexts. |
|
137 break; |
|
138 |
|
139 case KContextModifyActive: |
|
140 // This command is only valid aftermodifying TFT/QoS parameters. |
|
141 // As we don't support any of these operations, |
|
142 // this command is never valid. |
|
143 break; |
|
144 #endif |
|
145 default: |
|
146 (void)aOption; |
|
147 break; |
|
148 } |
|
149 } |
|
150 return KErrNotSupported; |
|
151 } |
|
152 |
|
153 TInt CIPv4Binder::GetConfig(TBinderConfig& aConfig) |
|
154 { |
|
155 _LOG_L1C1(_L8("CIPv4Binder::GetConfig")); |
|
156 |
|
157 TBinderConfig4* config = TBinderConfig::Cast<TBinderConfig4>(aConfig); |
|
158 |
|
159 if(config == NULL) |
|
160 { |
|
161 return KErrNotSupported; |
|
162 } |
|
163 |
|
164 config->iFamily = KAfInet; /* KAfInet - selects TBinderConfig4 */ |
|
165 |
|
166 config->iInfo.iFeatures = KIfCanBroadcast | KIfCanMulticast; /* Feature flags */ |
|
167 config->iInfo.iMtu = KDefaultMtu; /* Maximum transmission unit. */ |
|
168 config->iInfo.iRMtu = KDefaultMtu; /* Maximum transmission unit for receiving. */ |
|
169 config->iInfo.iSpeedMetric = iSpeedMetric; /* approximation of the interface speed in Kbps. */ |
|
170 |
|
171 LOG_IP_ADDRESS("Local IP address from TBinderConfig", iSettings.iLocalAddr); |
|
172 |
|
173 config->iAddress.SetAddress(iSettings.iLocalAddr); /* Interface IP address. */ |
|
174 config->iNetMask.SetAddress(iSettings.iNetMask); /* IP netmask. */ |
|
175 config->iBrdAddr.SetAddress(iSettings.iBroadcastAddr); /* IP broadcast address. */ |
|
176 config->iDefGate.SetAddress(iSettings.iDefGateway); /* IP default gateway or peer address (if known). */ |
|
177 config->iNameSer1.SetAddress(iSettings.iPrimaryDns); /* IP primary name server (if any). */ |
|
178 config->iNameSer2.SetAddress(iSettings.iSecondaryDns); /* IP secondary name server (if any). */ |
|
179 |
|
180 return KErrNone; |
|
181 } |
|
182 #ifdef WCDMA_STUB |
|
183 |
|
184 TInt CIPv4Binder::DeleteContext(TDes8& aContextParameters) |
|
185 /** |
|
186 * Deletes a context. As the NIF is responsible for one primary context, |
|
187 * this is equivalent to closing down the NIF. |
|
188 * |
|
189 * @param aContextParameters Parameters of the context to delete |
|
190 * @return KErrArgument if an incorrect structure is passed, otherwise KErrNone |
|
191 */ |
|
192 { |
|
193 _LOG_L1C1(_L8("CIPv4Binder::DeleteContext")); |
|
194 |
|
195 if (aContextParameters.Length() != sizeof(TContextParameters)) |
|
196 { |
|
197 return KErrArgument; |
|
198 } |
|
199 |
|
200 TUint8* ptr = CONST_CAST(TUint8*, aContextParameters.Ptr()); |
|
201 TContextParameters* params = REINTERPRET_CAST(TContextParameters*, ptr); |
|
202 |
|
203 if (params->iContextInfo.iContextId != |
|
204 STATIC_CAST(TInt8, GetFlow().GetBcaController()->Nsapi())) |
|
205 { |
|
206 params->iReasonCode = KErrBadName; |
|
207 } |
|
208 else |
|
209 { |
|
210 params->iReasonCode = KErrNone; |
|
211 GetFlow().Stop(KErrNone, MNifIfNotify::EDisconnect); |
|
212 } |
|
213 |
|
214 return KErrNone; |
|
215 } |
|
216 |
|
217 #endif |
|
218 /** |
|
219 * Called when the context has been activated to set our IP address and get |
|
220 * any other required settings from CommDB. |
|
221 * |
|
222 * @param aConfig The new context config |
|
223 */ |
|
224 void CIPv4Binder::UpdateContextConfigL(const TPacketDataConfigBase& aConfig) |
|
225 { |
|
226 _LOG_L1C1(_L8("CIPv4Binder::UpdateContextConfig")); |
|
227 |
|
228 // Get our IP address from the GPRS context config. |
|
229 TInetAddr address; |
|
230 |
|
231 TBuf<RPacketContext::KMaxPDPAddressLength> tempAddr; |
|
232 |
|
233 const RPacketContext::TProtocolConfigOptionV2* pco; |
|
234 TInt rel = const_cast<TPacketDataConfigBase&>(aConfig).ExtensionId(); |
|
235 if (rel == TPacketDataConfigBase::KConfigGPRS) |
|
236 { |
|
237 tempAddr.Copy(static_cast<const RPacketContext::TContextConfigGPRS&>(aConfig).iPdpAddress); |
|
238 pco = &static_cast<const RPacketContext::TContextConfigGPRS&>(aConfig).iProtocolConfigOption; |
|
239 } |
|
240 else |
|
241 { |
|
242 ASSERT(rel == TPacketDataConfigBase::KConfigRel99Rel4 || rel == TPacketDataConfigBase::KConfigRel5); |
|
243 tempAddr.Copy(static_cast<const RPacketContext::TContextConfigR99_R4&>(aConfig).iPdpAddress); |
|
244 pco = &static_cast<const RPacketContext::TContextConfigR99_R4&>(aConfig).iProtocolConfigOption; |
|
245 } |
|
246 TInt ret = address.Input(tempAddr); |
|
247 |
|
248 // We've got our IP address! Let's save it. |
|
249 if (ret == KErrNone) |
|
250 { |
|
251 iSettings.iLocalAddr = address.Address(); |
|
252 LOG_IP_ADDRESS("Got local IP address from context", iSettings.iLocalAddr); |
|
253 iSettings.iDefGateway = address.Address(); |
|
254 _LOG_L1C1(_L8("Set Default Gateway to local IP address")); |
|
255 } |
|
256 else |
|
257 { |
|
258 _LOG_L2C2(_L8("Couldn't get IP address from GPRS config (err: %d)"), |
|
259 ret); |
|
260 |
|
261 // Don't leave on this error: we may still be OK if we read some |
|
262 // settings from CommDB. |
|
263 } |
|
264 |
|
265 // @todo - is this correct. We can only get the DNS addresses |
|
266 // from the TSY using the iProtocolConfigOption data. Yet a client could |
|
267 // access those DNS config details without knowing about the state of the |
|
268 // iSettings.iGetDnsFromServer flag. |
|
269 |
|
270 if ((iSettings.iGetDnsFromServer) || |
|
271 ((iSettings.iPrimaryDns == 0) && |
|
272 (iSettings.iSecondaryDns == 0)) ) |
|
273 { |
|
274 TBuf<RPacketContext::KMaxPDPAddressLength> tempAddr; |
|
275 tempAddr.Copy(pco->iDnsAddresses.iPrimaryDns); |
|
276 ret = address.Input(tempAddr); |
|
277 |
|
278 if (ret == KErrNone) |
|
279 { |
|
280 iSettings.iPrimaryDns = address.Address(); |
|
281 LOG_IP_ADDRESS("Got primary DNS from context PCO", iSettings.iPrimaryDns); |
|
282 } |
|
283 else |
|
284 { |
|
285 _LOG_L2C2(_L8("Couldn't get primary DNS address from GPRS config (err: %d)"), |
|
286 ret); |
|
287 |
|
288 // Don't leave on this error: we may still be OK if we read some |
|
289 // settings from CommDB. |
|
290 } |
|
291 |
|
292 tempAddr.Copy(pco->iDnsAddresses.iSecondaryDns); |
|
293 ret = address.Input(tempAddr); |
|
294 |
|
295 if (ret == KErrNone) |
|
296 { |
|
297 iSettings.iSecondaryDns = address.Address(); |
|
298 LOG_IP_ADDRESS("Got secondary DNS from context PCO", iSettings.iPrimaryDns); |
|
299 } |
|
300 else |
|
301 { |
|
302 _LOG_L2C2(_L8("Couldn't get secondary DNS address from GPRS config (err: %d)"), |
|
303 ret); |
|
304 |
|
305 // Don't leave on this error: we may still be OK if we read some |
|
306 // settings from CommDB. |
|
307 } |
|
308 } |
|
309 else |
|
310 { |
|
311 LOG_IP_ADDRESS("Using CommDB DNS address - Primary ", iSettings.iPrimaryDns); |
|
312 LOG_IP_ADDRESS(" - Secondary ", iSettings.iSecondaryDns); |
|
313 } |
|
314 |
|
315 |
|
316 // TProtocolConfigOptionV2::iMiscBuffer is not the correct way to pass a gateway |
|
317 // address - data needs to be passed in TLV format but there are no TLV content tags |
|
318 // defined for a gateway address and any UMTS/GPRS hardware which claims to be able |
|
319 // to supply this address is erroneous (3gpp standard 24.008, section 10.5.6.3). |
|
320 // This misuse of iMiscBuffer was preventing other correctly formed parameters from |
|
321 // being passed (INC113612). |
|
322 /* if (iSettings.iGetGatewayFromServer) |
|
323 { |
|
324 tempAddr.Copy(aConfig.iProtocolConfigOption.iMiscBuffer); |
|
325 ret = address.Input(tempAddr); |
|
326 |
|
327 if (ret == KErrNone) |
|
328 { |
|
329 iSettings.iDefGateway = address.Address(); |
|
330 LOG_IP_ADDRESS("Got default gateway", iSettings.iDefGateway); |
|
331 } |
|
332 else |
|
333 { |
|
334 _LOG_L2C2(_L8("Couldn't get default gateway from GPRS config (err: %d)"), |
|
335 ret); |
|
336 } |
|
337 }*/ |
|
338 } |
|
339 |
|
340 void CIPv4Binder::UpdateConnectionSpeed(TUint aConnectionSpeed) |
|
341 /** |
|
342 * Sets the speed metric to return to TCP/IP, based on what the TSY tells us. |
|
343 * |
|
344 * @param aConnectionSpeed Our connection speed |
|
345 */ |
|
346 { |
|
347 _LOG_L1C1(_L8("CIPv4Binder::UpdateConnectionSpeed")); |
|
348 |
|
349 iSpeedMetric = aConnectionSpeed; |
|
350 } |
|
351 |
|
352 |
|
353 MLowerDataSender::TSendResult CIPv4Binder::Send(RMBufChain& aPdu) |
|
354 /** |
|
355 * Called by the protocol to send an outgoing IP packet to the network. |
|
356 * |
|
357 * @param aPdu The outgoing packet |
|
358 * @return Standard error codes |
|
359 */ |
|
360 { |
|
361 _LOG_L1C1(_L8("CIPv4Binder::Send")); |
|
362 |
|
363 #ifdef __BTT_LOGGING__ |
|
364 LogPacket(aPdu); |
|
365 #endif |
|
366 |
|
367 // Return <0: an error occurred |
|
368 // Return 0: no error, but don't send any more packets |
|
369 |
|
370 return static_cast<MLowerDataSender::TSendResult>(GetFlow().SendPacket(aPdu, NULL, KIp4FrameType)); |
|
371 } |
|
372 |
|
373 TInt CIPv4Binder::Notification(TAgentToNifEventType /*aEvent*/, |
|
374 void* /*aInfo*/) |
|
375 /** |
|
376 * The Nif will ignore any notification sent |
|
377 * |
|
378 * @param aEvent Not used |
|
379 * @param aInfo Not used |
|
380 */ |
|
381 { |
|
382 _LOG_L1C1(_L8("CIPv4Binder::Notification")); |
|
383 |
|
384 return KErrNone; |
|
385 } |
|
386 |
|
387 void CIPv4Binder::StartSending() |
|
388 /** |
|
389 * Indicates to the protocol layer that the NIF is ready to send packets. |
|
390 * |
|
391 * @param aProtocol A pointer to a protocol |
|
392 */ |
|
393 { |
|
394 _LOG_L1C1(_L8("CIPv4Binder::StartSending()")); |
|
395 |
|
396 CBinderBase::StartSending(); |
|
397 } |
|
398 |
|
399 TBool CIPv4Binder::WantsProtocol(TUint16 aProtocolCode) |
|
400 /** |
|
401 * Indicates the type of protocol implemented by this class. |
|
402 * |
|
403 * @param aProtocolCode The protocol type |
|
404 */ |
|
405 { |
|
406 _LOG_L1C2(_L8("CIPv4Binder::WantsProtocol [aProtocolCode=%X]"), |
|
407 aProtocolCode); |
|
408 |
|
409 #ifdef RAWIP_HEADER_APPENDED_TO_PACKETS |
|
410 return ((aProtocolCode & 0x00FF) == KIp4FrameType); |
|
411 #else |
|
412 (void) aProtocolCode; |
|
413 return ETrue; |
|
414 #endif // RAWIP_HEADER_APPENDED_TO_PACKETS |
|
415 } |
|
416 |
|
417 void CIPv4Binder::Process(RMBufChain& aPdu) |
|
418 /** |
|
419 * Called when an incoming IP packet has arrived. Send packets up to the |
|
420 * TCP/IP stack. |
|
421 * |
|
422 * @param aPdu The incoming packet |
|
423 */ |
|
424 { |
|
425 _LOG_L1C1(_L8("CIPv4Binder::Process")); |
|
426 |
|
427 #ifdef __BTT_LOGGING__ |
|
428 LogPacket(aPdu); |
|
429 #endif |
|
430 |
|
431 // Pass incoming packets up to the protocol, unless it hasn't |
|
432 // been bound yet. |
|
433 if (iUpperReceiver) // ASSERT(iUpperReceiver) ? |
|
434 { |
|
435 _LOG_L1C1(_L8("CIPv4Binder: Packet Sent to TCP/IP Protocol!!!")); |
|
436 iUpperReceiver->Process(aPdu); |
|
437 } |
|
438 else |
|
439 { |
|
440 _LOG_L2C1(_L8("WARNING: dumping incoming packet, no protocol bound")); |
|
441 aPdu.Free(); |
|
442 } |
|
443 } |
|
444 |
|
445 // |
|
446 // MLowerControl methods |
|
447 // |
|
448 |
|
449 TInt CIPv4Binder::GetName(TDes& aName) |
|
450 /** |
|
451 */ |
|
452 { |
|
453 WriteIfName(aName); |
|
454 return KErrNone; |
|
455 } |
|
456 |
|
457 // |
|
458 // CBinderBase methods |
|
459 // |
|
460 |
|
461 void CIPv4Binder::SetProvision(const CIPConfig& aProvision) |
|
462 /** |
|
463 Set provisioning information for IPv4 binder. |
|
464 |
|
465 Called from RawIP Flow. |
|
466 |
|
467 @param aProvision Provisioning structure from Control side. |
|
468 */ |
|
469 { |
|
470 _LOG_L1C1(_L8("CIPv4Binder::SetProvision")); |
|
471 |
|
472 iSettings.iLocalAddr = aProvision.GetIpAddress(); |
|
473 iSettings.iNetMask = aProvision.GetIpNetMask(); |
|
474 iSettings.iBroadcastAddr = aProvision.GetBroadCastAddr(); |
|
475 iSettings.iDefGateway = aProvision.GetIpGateway(); |
|
476 iSettings.iPrimaryDns = aProvision.GetIp4NameServer1(); |
|
477 iSettings.iSecondaryDns = aProvision.GetIp4NameServer2(); |
|
478 iSettings.iGetGatewayFromServer = aProvision.GetIpAddrFromServer(); |
|
479 iSettings.iGetDnsFromServer = aProvision.GetIp4DNSAddrFromServer(); |
|
480 |
|
481 LOG_IP_ADDRESS("Local IP address from Provisioning", iSettings.iLocalAddr); |
|
482 } |
|
483 |
|
484 #ifdef __BTT_LOGGING__ |
|
485 void CIPv4Binder::LogPacket(const RMBufChain& aPacket) |
|
486 /** |
|
487 * Logs packet information into log file. |
|
488 * |
|
489 * @param aPacket The packet |
|
490 */ |
|
491 { |
|
492 _LOG_L1C1(_L8("CIPv4Binder::LogPacket")); |
|
493 |
|
494 TInt mBufLength = aPacket.Length() - aPacket.First()->Length(); |
|
495 |
|
496 _LOG_L3C2(_L8("Analysis of %d byte packet:"), mBufLength); |
|
497 |
|
498 //Note: All the constants used on this method are a pragmatic guess of the |
|
499 //IP header fields. The only porpose of this method is logging. |
|
500 |
|
501 if (mBufLength < 20) |
|
502 { |
|
503 _LOG_L3C2(_L8(" -doesn't appear to be a valid IPv4 packet (length=%d)") |
|
504 , mBufLength); |
|
505 return; |
|
506 } |
|
507 |
|
508 // Get a pointer to the packet's payload. |
|
509 const TUint8* payloadPtr = aPacket.First()->Next()->Ptr(); |
|
510 |
|
511 if ((payloadPtr[0] & 0xF0) != 0x40) |
|
512 { |
|
513 _LOG_L3C2(_L8(" - doesn't appear to be an IPv4 packet (version=0x%X)"), |
|
514 (payloadPtr[0] & 0xF0) >> 4); |
|
515 return; |
|
516 } |
|
517 |
|
518 if ((payloadPtr[0] & 0xF) != 0x5) |
|
519 { |
|
520 _LOG_L3C2(_L8(" - doesn't have a standard IP header (length=0x%X)"), |
|
521 payloadPtr[0] & 0xF); |
|
522 return; |
|
523 } |
|
524 |
|
525 _LOG_L3C5(_L8(" - src addr: %d.%d.%d.%d"), payloadPtr[12], payloadPtr[13], |
|
526 payloadPtr[14], payloadPtr[15]); |
|
527 _LOG_L3C5(_L8(" - dst addr: %d.%d.%d.%d"), payloadPtr[16], payloadPtr[17], |
|
528 payloadPtr[18], payloadPtr[19]); |
|
529 |
|
530 if (payloadPtr[9] == 0x06) |
|
531 { |
|
532 _LOG_L3C1(_L8(" - appears to be a TCP packet")); |
|
533 if (mBufLength < 40) |
|
534 { |
|
535 _LOG_L3C2(_L8(" - but is too short (length=0x%X)"), mBufLength); |
|
536 return; |
|
537 } |
|
538 _LOG_L3C3(_L8(" - src port: %d, dst port: %d"), |
|
539 (payloadPtr[20] << 8) + payloadPtr[21], |
|
540 (payloadPtr[22] << 8) + payloadPtr[23]); |
|
541 _LOG_L3C3(_L8(" - seq #: 0x%08X, ack #: 0x%08X"), |
|
542 (payloadPtr[24] << 24) + (payloadPtr[25] << 16) + |
|
543 (payloadPtr[26] << 8) + payloadPtr[27], |
|
544 (payloadPtr[28] << 24) + (payloadPtr[29] << 16) + |
|
545 (payloadPtr[30] << 8) + payloadPtr[31]); |
|
546 |
|
547 TBuf8<100> flagsSet; |
|
548 flagsSet.Copy(_L8(" - flags set: ")); |
|
549 |
|
550 // Write description of payload's flags to "flagsSet" |
|
551 if (payloadPtr[33] & 0x01) |
|
552 { |
|
553 flagsSet.Append(_L8("FIN ")); |
|
554 } |
|
555 if (payloadPtr[33] & 0x02) |
|
556 { |
|
557 flagsSet.Append(_L8("SYN ")); |
|
558 } |
|
559 if (payloadPtr[33] & 0x04) |
|
560 { |
|
561 flagsSet.Append(_L8("RST ")); |
|
562 } |
|
563 if (payloadPtr[33] & 0x08) |
|
564 { |
|
565 flagsSet.Append(_L8("PSH ")); |
|
566 } |
|
567 if (payloadPtr[33] & 0x10) |
|
568 { |
|
569 flagsSet.Append(_L8("ACK ")); |
|
570 } |
|
571 if (payloadPtr[33] & 0x20) |
|
572 { |
|
573 flagsSet.Append(_L8("URG ")); |
|
574 } |
|
575 _LOG_L3C1(flagsSet); |
|
576 |
|
577 TInt dataOffset = payloadPtr[32] >> 2; // in bytes |
|
578 if ((dataOffset > 0) && (mBufLength > dataOffset + 30)) |
|
579 { |
|
580 TBuf8<100> data; |
|
581 data.Copy(_L8(" - data begins: ")); |
|
582 for (TInt i = dataOffset + 20; i < dataOffset + 100; i++) |
|
583 { |
|
584 // We skip some bytes at the end of the MBuf, as they're junk. |
|
585 if (i >= (mBufLength - 10)) |
|
586 { |
|
587 break; |
|
588 } |
|
589 if (TChar(payloadPtr[i]).IsPrint()) |
|
590 { |
|
591 data.Append(TChar(payloadPtr[i])); |
|
592 } |
|
593 else |
|
594 { |
|
595 data.Append(TChar('?')); |
|
596 } |
|
597 } |
|
598 _LOG_L3C1(data); |
|
599 } |
|
600 } |
|
601 else if (payloadPtr[9] == 0x01) |
|
602 { |
|
603 _LOG_L3C1(_L8(" - appears to be an ICMP packet")); |
|
604 if (mBufLength < 24) |
|
605 { |
|
606 _LOG_L3C2(_L8(" - but is too short (length=0x%X)"), mBufLength); |
|
607 return; |
|
608 } |
|
609 |
|
610 if (payloadPtr[20] == 0x8) |
|
611 { |
|
612 _LOG_L3C1(_L8(" - is an echo request")); |
|
613 } |
|
614 else if (payloadPtr[20] == 0x0) |
|
615 { |
|
616 _LOG_L3C1(_L8(" - is an echo reply")); |
|
617 } |
|
618 else |
|
619 { |
|
620 _LOG_L3C2(_L8(" - unknown type (0x%02X)"), payloadPtr[20]); |
|
621 return; |
|
622 } |
|
623 |
|
624 if (mBufLength >= 28) |
|
625 { |
|
626 _LOG_L3C3(_L8(" - ID: 0x%04X, seq #: 0x%04X"), |
|
627 (payloadPtr[24] << 8) + payloadPtr[25], |
|
628 (payloadPtr[26] << 8) + payloadPtr[27]); |
|
629 } |
|
630 } |
|
631 else if (payloadPtr[9] == 0x11) |
|
632 { |
|
633 _LOG_L3C1(_L8(" - appears to be a UDP packet")); |
|
634 if (mBufLength < 28) |
|
635 { |
|
636 _LOG_L3C2(_L8(" - but is too short (length=0x%X)"), mBufLength); |
|
637 return; |
|
638 } |
|
639 _LOG_L3C3(_L8(" - src port: %d, dst port: %d"), |
|
640 (payloadPtr[20] << 8) + payloadPtr[21], |
|
641 (payloadPtr[22] << 8) + payloadPtr[23]); |
|
642 } |
|
643 else |
|
644 { |
|
645 _LOG_L3C2(_L8(" - appears to be for an unknown protocol (0x%X)"), |
|
646 payloadPtr[9]); |
|
647 } |
|
648 } |
|
649 #endif // __BTT_LOGGING__ |