|
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 "RawIP2Flow.h" |
|
26 #include "IPv4Binder.h" |
|
27 #include <comms-infras/linkprovision.h> |
|
28 |
|
29 #ifdef WCDMA_STUB |
|
30 #include <networking/umtsnifcontrolif.h> |
|
31 #endif |
|
32 |
|
33 #define LOG_IP_ADDRESS(desc,addr) _LOG_L1C5(_L8(" " desc " = %d.%d.%d.%d"), \ |
|
34 addr >> 24, (addr >> 16) & 0xFF, (addr >> 8) & 0xFF, addr & 0xFF); |
|
35 |
|
36 CIPv4Binder::CIPv4Binder(CRawIP2Flow& aFlow, CBttLogger* aTheLogger) |
|
37 /** |
|
38 * Constructor |
|
39 */ |
|
40 : CBinderBase(aFlow,aTheLogger), |
|
41 iSpeedMetric(KDefaultSpeedMetric) |
|
42 { |
|
43 } |
|
44 |
|
45 CIPv4Binder::~CIPv4Binder() |
|
46 /** |
|
47 * Destructor |
|
48 */ |
|
49 { |
|
50 } |
|
51 |
|
52 ESock::MLowerDataSender* CIPv4Binder::Bind(ESock::MUpperDataReceiver* aUpperReceiver, ESock::MUpperControl* aUpperControl) |
|
53 /** |
|
54 * Binds TCP/IP protocol to Flow |
|
55 * |
|
56 * @param aUpperReceiver A pointer to Upper layer Receive class |
|
57 * @param aUpperControl A pointer to Upper layer control class |
|
58 */ |
|
59 { |
|
60 CBinderBase::Bind(aUpperReceiver, aUpperControl); // Call the superclass's method. |
|
61 return this; |
|
62 } |
|
63 |
|
64 TInt CIPv4Binder::Control(TUint aLevel, TUint aName, TDes8& aOption) |
|
65 /** |
|
66 * The main function called by the TCP/IP protocol to control the interface. |
|
67 * Can perform a variety of general IP tasks (such as getting IP config) |
|
68 * and "3G" specific tasks (such as deleting the context). |
|
69 * |
|
70 * @param aLevel The level of the interface to control - always KSOLInterface |
|
71 * @param aName The command to perform |
|
72 * @param aOption Data to be input/output as a result of the command |
|
73 * @return Standard error codes |
|
74 */ |
|
75 { |
|
76 _LOG_L1C3(_L8("CIPv4Binder::Control [aLevel=%d, aName=%d]"), |
|
77 aLevel, aName); |
|
78 |
|
79 if (aLevel == KSOLInterface) |
|
80 { |
|
81 switch (aName) |
|
82 { |
|
83 case KSoIfHardwareAddr: |
|
84 // unsupported because we don't have a h/w address |
|
85 break; |
|
86 |
|
87 // 3G-specific configuration commands are below this point. |
|
88 |
|
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 |
|
146 default: |
|
147 (void)aOption; |
|
148 break; |
|
149 } |
|
150 } |
|
151 return KErrNotSupported; |
|
152 } |
|
153 |
|
154 TInt CIPv4Binder::GetConfig(TBinderConfig& aConfig) |
|
155 { |
|
156 _LOG_L1C1(_L8("CIPv4Binder::GetConfig")); |
|
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 LOG_IP_ADDRESS("Local IP address from TBinderConfig", iSettings.iLocalAddr); |
|
171 |
|
172 config->iAddress.SetAddress(iSettings.iLocalAddr); /* Interface IP address. */ |
|
173 config->iNetMask.SetAddress(iSettings.iNetMask); /* IP netmask. */ |
|
174 config->iBrdAddr.SetAddress(iSettings.iBroadcastAddr); /* IP broadcast address. */ |
|
175 config->iDefGate.SetAddress(iSettings.iDefGateway); /* IP default gateway or peer address (if known). */ |
|
176 config->iNameSer1.SetAddress(iSettings.iPrimaryDns); /* IP primary name server (if any). */ |
|
177 config->iNameSer2.SetAddress(iSettings.iSecondaryDns); /* IP secondary name server (if any). */ |
|
178 |
|
179 return KErrNone; |
|
180 } |
|
181 |
|
182 #ifdef WCDMA_STUB |
|
183 TInt CIPv4Binder::DeleteContext(TDes8& aContextParameters) |
|
184 /** |
|
185 * Deletes a context. As the NIF is responsible for one primary context, |
|
186 * this is equivalent to closing down the NIF. |
|
187 * |
|
188 * @param aContextParameters Parameters of the context to delete |
|
189 * @return KErrArgument if an incorrect structure is passed, otherwise KErrNone |
|
190 */ |
|
191 { |
|
192 _LOG_L1C1(_L8("CIPv4Binder::DeleteContext")); |
|
193 |
|
194 if (aContextParameters.Length() != sizeof(TContextParameters)) |
|
195 { |
|
196 return KErrArgument; |
|
197 } |
|
198 |
|
199 TUint8* ptr = CONST_CAST(TUint8*, aContextParameters.Ptr()); |
|
200 TContextParameters* params = REINTERPRET_CAST(TContextParameters*, ptr); |
|
201 |
|
202 if (params->iContextInfo.iContextId != |
|
203 STATIC_CAST(TInt8, GetFlow().GetBcaController()->Nsapi())) |
|
204 { |
|
205 params->iReasonCode = KErrBadName; |
|
206 } |
|
207 else |
|
208 { |
|
209 params->iReasonCode = KErrNone; |
|
210 GetFlow().Stop(KErrNone, MNifIfNotify::EDisconnect); |
|
211 } |
|
212 |
|
213 return KErrNone; |
|
214 } |
|
215 |
|
216 #endif |
|
217 |
|
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 ESock::MLowerDataSender::TSendResult CIPv4Binder::Send(RMBufChain& aPdu) |
|
353 { |
|
354 return Send(static_cast<RCommsBufChain&>(aPdu)); |
|
355 } |
|
356 |
|
357 ESock::MLowerDataSender::TSendResult CIPv4Binder::Send(RCommsBufChain& aPdu) |
|
358 /** |
|
359 * Called by the protocol to send an outgoing IP packet to the network. |
|
360 * |
|
361 * @param aPdu The outgoing packet |
|
362 * @return Standard error codes |
|
363 */ |
|
364 { |
|
365 _LOG_L1C1(_L8("CIPv4Binder::Send")); |
|
366 |
|
367 #ifdef __BTT_LOGGING__ |
|
368 LogPacket(static_cast<RMBufChain&>(aPdu)); |
|
369 #endif |
|
370 |
|
371 // Return <0: an error occurred |
|
372 // Return 0: no error, but don't send any more packets |
|
373 |
|
374 #ifdef RAWIP_HEADER_APPENDED_TO_PACKETS |
|
375 iIPTagHeader->AddHeader(aPdu); |
|
376 #endif // RAWIP_HEADER_APPENDED_TO_PACKETS |
|
377 |
|
378 return ESock::MLowerDataSender::TSendResult(iLowerDataSender->Send(aPdu)); |
|
379 } |
|
380 |
|
381 TInt CIPv4Binder::Notification(TAgentToNifEventType /*aEvent*/, |
|
382 void* /*aInfo*/) |
|
383 /** |
|
384 * The Nif will ignore any notification sent |
|
385 * |
|
386 * @param aEvent Not used |
|
387 * @param aInfo Not used |
|
388 */ |
|
389 { |
|
390 _LOG_L1C1(_L8("CIPv4Binder::Notification")); |
|
391 |
|
392 return KErrNone; |
|
393 } |
|
394 |
|
395 void CIPv4Binder::StartSending() |
|
396 /** |
|
397 * Indicates to the protocol layer that the NIF is ready to send packets. |
|
398 * |
|
399 * @param aProtocol A pointer to a protocol |
|
400 */ |
|
401 { |
|
402 _LOG_L1C1(_L8("CIPv4Binder::StartSending()")); |
|
403 |
|
404 CBinderBase::StartSending(); |
|
405 } |
|
406 |
|
407 TBool CIPv4Binder::WantsProtocol(TUint16 aProtocolCode) |
|
408 /** |
|
409 * Indicates the type of protocol implemented by this class. |
|
410 * |
|
411 * @param aProtocolCode The protocol type |
|
412 */ |
|
413 { |
|
414 _LOG_L1C2(_L8("CIPv4Binder::WantsProtocol [aProtocolCode=%X]"), |
|
415 aProtocolCode); |
|
416 |
|
417 #ifdef RAWIP_HEADER_APPENDED_TO_PACKETS |
|
418 return ((aProtocolCode & 0x00FF) == KIp4FrameType); |
|
419 #else |
|
420 (void) aProtocolCode; |
|
421 return ETrue; |
|
422 #endif // RAWIP_HEADER_APPENDED_TO_PACKETS |
|
423 } |
|
424 |
|
425 void CIPv4Binder::Process(RMBufChain& aPdu) |
|
426 { |
|
427 Process(static_cast<RCommsBufChain&>(aPdu)); |
|
428 } |
|
429 |
|
430 void CIPv4Binder::Process(RCommsBufChain& aPdu) |
|
431 /** |
|
432 * Called when an incoming IP packet has arrived. Send packets up to the |
|
433 * TCP/IP stack. |
|
434 * |
|
435 * @param aPdu The incoming packet |
|
436 */ |
|
437 { |
|
438 _LOG_L1C1(_L8("CIPv4Binder::Process")); |
|
439 |
|
440 #ifdef __BTT_LOGGING__ |
|
441 LogPacket(static_cast<RMBufChain&>(aPdu)); |
|
442 #endif |
|
443 |
|
444 #ifdef RAWIP_HEADER_APPENDED_TO_PACKETS |
|
445 TUint16 protocolCode = iIPTagHeader->RemoveHeader(aPdu); |
|
446 #else |
|
447 TUint16 protocolCode = 0; |
|
448 #endif // RAWIP_HEADER_APPENDED_TO_PACKETS |
|
449 |
|
450 |
|
451 // Pass incoming packets up to the protocol, unless it hasn't |
|
452 // been bound yet. |
|
453 if (iUpperReceiver && WantsProtocol(protocolCode)) |
|
454 { |
|
455 _LOG_L1C1(_L8("CIPv4Binder: Packet Sent to TCP/IP Protocol!!!")); |
|
456 iUpperReceiver->Process(static_cast<RMBufChain&>(aPdu)); |
|
457 } |
|
458 else |
|
459 { |
|
460 _LOG_L2C1(_L8("WARNING: dumping incoming packet, no protocol bound")); |
|
461 aPdu.Free(); |
|
462 } |
|
463 } |
|
464 |
|
465 // |
|
466 // MLowerControl methods |
|
467 // |
|
468 |
|
469 TInt CIPv4Binder::GetName(TDes& aName) |
|
470 /** |
|
471 */ |
|
472 { |
|
473 WriteIfName(aName); |
|
474 return KErrNone; |
|
475 } |
|
476 |
|
477 // |
|
478 // CBinderBase methods |
|
479 // |
|
480 |
|
481 void CIPv4Binder::SetProvision(const CIPConfig& aProvision) |
|
482 /** |
|
483 Set provisioning information for IPv4 binder. |
|
484 |
|
485 Called from RawIP Flow. |
|
486 |
|
487 @param aProvision Provisioning structure from Control side. |
|
488 */ |
|
489 { |
|
490 _LOG_L1C1(_L8("CIPv4Binder::SetProvision")); |
|
491 iSettings.iLocalAddr = aProvision.GetIpAddress(); |
|
492 iSettings.iNetMask = aProvision.GetIpNetMask(); |
|
493 iSettings.iBroadcastAddr = aProvision.GetBroadCastAddr(); |
|
494 iSettings.iDefGateway = aProvision.GetIpGateway(); |
|
495 iSettings.iPrimaryDns = aProvision.GetIp4NameServer1(); |
|
496 iSettings.iSecondaryDns = aProvision.GetIp4NameServer2(); |
|
497 iSettings.iGetGatewayFromServer = aProvision.GetIpAddrFromServer(); |
|
498 iSettings.iGetDnsFromServer = aProvision.GetIp4DNSAddrFromServer(); |
|
499 LOG_IP_ADDRESS("Local IP address from Provisioning", iSettings.iLocalAddr); |
|
500 } |
|
501 |
|
502 #ifdef __BTT_LOGGING__ |
|
503 void CIPv4Binder::LogPacket(const RMBufChain& aPacket) |
|
504 /** |
|
505 * Logs packet information into log file. |
|
506 * |
|
507 * @param aPacket The packet |
|
508 */ |
|
509 { |
|
510 _LOG_L1C1(_L8("CIPv4Binder::LogPacket")); |
|
511 |
|
512 TInt mBufLength = aPacket.Length() - aPacket.First()->Length(); |
|
513 |
|
514 _LOG_L3C2(_L8("Analysis of %d byte packet:"), mBufLength); |
|
515 |
|
516 //Note: All the constants used on this method are a pragmatic guess of the |
|
517 //IP header fields. The only porpose of this method is logging. |
|
518 |
|
519 if (mBufLength < 20) |
|
520 { |
|
521 _LOG_L3C2(_L8(" -doesn't appear to be a valid IPv4 packet (length=%d)") |
|
522 , mBufLength); |
|
523 return; |
|
524 } |
|
525 |
|
526 // Get a pointer to the packet's payload. |
|
527 const TUint8* payloadPtr = aPacket.First()->Next()->Ptr(); |
|
528 |
|
529 if ((payloadPtr[0] & 0xF0) != 0x40) |
|
530 { |
|
531 _LOG_L3C2(_L8(" - doesn't appear to be an IPv4 packet (version=0x%X)"), |
|
532 (payloadPtr[0] & 0xF0) >> 4); |
|
533 return; |
|
534 } |
|
535 |
|
536 if ((payloadPtr[0] & 0xF) != 0x5) |
|
537 { |
|
538 _LOG_L3C2(_L8(" - doesn't have a standard IP header (length=0x%X)"), |
|
539 payloadPtr[0] & 0xF); |
|
540 return; |
|
541 } |
|
542 |
|
543 _LOG_L3C5(_L8(" - src addr: %d.%d.%d.%d"), payloadPtr[12], payloadPtr[13], |
|
544 payloadPtr[14], payloadPtr[15]); |
|
545 _LOG_L3C5(_L8(" - dst addr: %d.%d.%d.%d"), payloadPtr[16], payloadPtr[17], |
|
546 payloadPtr[18], payloadPtr[19]); |
|
547 |
|
548 if (payloadPtr[9] == 0x06) |
|
549 { |
|
550 _LOG_L3C1(_L8(" - appears to be a TCP packet")); |
|
551 if (mBufLength < 40) |
|
552 { |
|
553 _LOG_L3C2(_L8(" - but is too short (length=0x%X)"), mBufLength); |
|
554 return; |
|
555 } |
|
556 _LOG_L3C3(_L8(" - src port: %d, dst port: %d"), |
|
557 (payloadPtr[20] << 8) + payloadPtr[21], |
|
558 (payloadPtr[22] << 8) + payloadPtr[23]); |
|
559 _LOG_L3C3(_L8(" - seq #: 0x%08X, ack #: 0x%08X"), |
|
560 (payloadPtr[24] << 24) + (payloadPtr[25] << 16) + |
|
561 (payloadPtr[26] << 8) + payloadPtr[27], |
|
562 (payloadPtr[28] << 24) + (payloadPtr[29] << 16) + |
|
563 (payloadPtr[30] << 8) + payloadPtr[31]); |
|
564 |
|
565 TBuf8<100> flagsSet; |
|
566 flagsSet.Copy(_L8(" - flags set: ")); |
|
567 |
|
568 // Write description of payload's flags to "flagsSet" |
|
569 if (payloadPtr[33] & 0x01) |
|
570 { |
|
571 flagsSet.Append(_L8("FIN ")); |
|
572 } |
|
573 if (payloadPtr[33] & 0x02) |
|
574 { |
|
575 flagsSet.Append(_L8("SYN ")); |
|
576 } |
|
577 if (payloadPtr[33] & 0x04) |
|
578 { |
|
579 flagsSet.Append(_L8("RST ")); |
|
580 } |
|
581 if (payloadPtr[33] & 0x08) |
|
582 { |
|
583 flagsSet.Append(_L8("PSH ")); |
|
584 } |
|
585 if (payloadPtr[33] & 0x10) |
|
586 { |
|
587 flagsSet.Append(_L8("ACK ")); |
|
588 } |
|
589 if (payloadPtr[33] & 0x20) |
|
590 { |
|
591 flagsSet.Append(_L8("URG ")); |
|
592 } |
|
593 _LOG_L3C1(flagsSet); |
|
594 |
|
595 TInt dataOffset = payloadPtr[32] >> 2; // in bytes |
|
596 if ((dataOffset > 0) && (mBufLength > dataOffset + 30)) |
|
597 { |
|
598 TBuf8<100> data; |
|
599 data.Copy(_L8(" - data begins: ")); |
|
600 for (TInt i = dataOffset + 20; i < dataOffset + 100; i++) |
|
601 { |
|
602 // We skip some bytes at the end of the MBuf, as they're junk. |
|
603 if (i >= (mBufLength - 10)) |
|
604 { |
|
605 break; |
|
606 } |
|
607 if (TChar(payloadPtr[i]).IsPrint()) |
|
608 { |
|
609 data.Append(TChar(payloadPtr[i])); |
|
610 } |
|
611 else |
|
612 { |
|
613 data.Append(TChar('?')); |
|
614 } |
|
615 } |
|
616 _LOG_L3C1(data); |
|
617 } |
|
618 } |
|
619 else if (payloadPtr[9] == 0x01) |
|
620 { |
|
621 _LOG_L3C1(_L8(" - appears to be an ICMP packet")); |
|
622 if (mBufLength < 24) |
|
623 { |
|
624 _LOG_L3C2(_L8(" - but is too short (length=0x%X)"), mBufLength); |
|
625 return; |
|
626 } |
|
627 |
|
628 if (payloadPtr[20] == 0x8) |
|
629 { |
|
630 _LOG_L3C1(_L8(" - is an echo request")); |
|
631 } |
|
632 else if (payloadPtr[20] == 0x0) |
|
633 { |
|
634 _LOG_L3C1(_L8(" - is an echo reply")); |
|
635 } |
|
636 else |
|
637 { |
|
638 _LOG_L3C2(_L8(" - unknown type (0x%02X)"), payloadPtr[20]); |
|
639 return; |
|
640 } |
|
641 |
|
642 if (mBufLength >= 28) |
|
643 { |
|
644 _LOG_L3C3(_L8(" - ID: 0x%04X, seq #: 0x%04X"), |
|
645 (payloadPtr[24] << 8) + payloadPtr[25], |
|
646 (payloadPtr[26] << 8) + payloadPtr[27]); |
|
647 } |
|
648 } |
|
649 else if (payloadPtr[9] == 0x11) |
|
650 { |
|
651 _LOG_L3C1(_L8(" - appears to be a UDP packet")); |
|
652 if (mBufLength < 28) |
|
653 { |
|
654 _LOG_L3C2(_L8(" - but is too short (length=0x%X)"), mBufLength); |
|
655 return; |
|
656 } |
|
657 _LOG_L3C3(_L8(" - src port: %d, dst port: %d"), |
|
658 (payloadPtr[20] << 8) + payloadPtr[21], |
|
659 (payloadPtr[22] << 8) + payloadPtr[23]); |
|
660 } |
|
661 else |
|
662 { |
|
663 _LOG_L3C2(_L8(" - appears to be for an unknown protocol (0x%X)"), |
|
664 payloadPtr[9]); |
|
665 } |
|
666 } |
|
667 #endif // __BTT_LOGGING__ |