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