|
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 CIPv6Binder class, which handles the transmission |
|
15 // of IPv6 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 "IPv6Binder.h" |
|
27 #include <comms-infras/linkprovision.h> |
|
28 |
|
29 |
|
30 #ifdef WCDMA_STUB |
|
31 #include <networking/umtsnifcontrolif.h> |
|
32 #endif |
|
33 |
|
34 #define LOG_IP_ADDRESS(desc,addr) _LOG_L2C5(_L8(" " desc " = %d:%d:%d:%d from context"), \ |
|
35 addr.u.iAddr32[3], addr.u.iAddr32[2], addr.u.iAddr32[1], addr.u.iAddr32[0]); |
|
36 |
|
37 CIPv6Binder::CIPv6Binder(CRawIP2Flow& aFlow, CBttLogger* aTheLogger) |
|
38 /** |
|
39 * Constructor |
|
40 */ |
|
41 : CBinderBase(aFlow,aTheLogger), |
|
42 iTheLogger(aTheLogger), |
|
43 iSpeedMetric(KDefaultSpeedMetric) |
|
44 { |
|
45 } |
|
46 |
|
47 CIPv6Binder::~CIPv6Binder() |
|
48 /** |
|
49 * Destructor |
|
50 */ |
|
51 { |
|
52 } |
|
53 |
|
54 ESock::MLowerDataSender* CIPv6Binder::Bind(ESock::MUpperDataReceiver* aUpperReceiver, ESock::MUpperControl* aUpperControl) |
|
55 /** |
|
56 * Binds TCP/IP protocol to Flow |
|
57 * |
|
58 * @param aUpperReceiver A pointer to Upper layer Receive class |
|
59 * @param aUpperControl A pointer to Upper layer control class |
|
60 */ |
|
61 { |
|
62 CBinderBase::Bind(aUpperReceiver, aUpperControl); // Call the superclass's method. |
|
63 return this; |
|
64 } |
|
65 |
|
66 TInt CIPv6Binder::Control(TUint aLevel, TUint aName, TDes8& /*aOption*/) |
|
67 /** |
|
68 * The main function called by the TCP/IP protocol to control the interface. |
|
69 * Can perform a variety of general IP tasks (such as getting IP config) |
|
70 * and "3G" specific tasks (such as deleting the context). |
|
71 * |
|
72 * @param aLevel The level of the interface to control - always KSOLInterface |
|
73 * @param aName The command to perform |
|
74 * @param aOption Data to be input/output as a result of the command |
|
75 * @return Standard error codes |
|
76 */ |
|
77 { |
|
78 _LOG_L1C3(_L8("CIPv6Binder::Control [aLevel=%d, aName=%d]"), |
|
79 aLevel, aName); |
|
80 |
|
81 if (aLevel == KSOLInterface) |
|
82 { |
|
83 switch (aName) |
|
84 { |
|
85 case KSoIfHardwareAddr: |
|
86 // unsupported because we don't have a h/w address |
|
87 break; |
|
88 |
|
89 // 3G-specific configuration commands are below this point. |
|
90 |
|
91 #ifdef WCDMA_STUB |
|
92 case KRegisterEventHandler: |
|
93 // Raw IP NIF Events are not supported |
|
94 case KContextSetEvents: |
|
95 // Raw IP NIF Events are not supported |
|
96 break; |
|
97 |
|
98 case KContextCreate: |
|
99 // We don't support creating new secondary contexts. |
|
100 break; |
|
101 |
|
102 case KContextDelete: |
|
103 // Deletes the primary PDP context. This will shut down the Nif. |
|
104 return DeleteContext(aOption); |
|
105 |
|
106 case KContextActivate: |
|
107 // If the IPv6 interface is up, then the context will already have |
|
108 // been activated. So this command should fail with |
|
109 // KErrAlreadyExists |
|
110 { |
|
111 TUint8* ptr = CONST_CAST(TUint8*, aOption.Ptr()); |
|
112 TContextParameters* contextParams = |
|
113 REINTERPRET_CAST(TContextParameters*, ptr); |
|
114 |
|
115 if (contextParams->iContextInfo.iContextId != |
|
116 STATIC_CAST(TInt8, GetFlow().GetBcaController()->Nsapi())) |
|
117 { |
|
118 contextParams->iReasonCode = KErrNotFound; |
|
119 } |
|
120 else |
|
121 { |
|
122 contextParams->iContextInfo.iStatus = |
|
123 GetFlow().GetContextStatus(); |
|
124 contextParams->iReasonCode = KErrAlreadyExists; |
|
125 } |
|
126 return KErrNone; |
|
127 } |
|
128 |
|
129 case KNifSetDefaultQoS: |
|
130 case KContextQoSSet: |
|
131 // Setting the QoS is meaningless over GPRS, so we just return that |
|
132 // we don't support these operations. |
|
133 break; |
|
134 |
|
135 case KContextTFTModify: |
|
136 // As we only have one primary context, we don't support anything |
|
137 // to do with traffic flow templates, which are used by secondary |
|
138 // contexts. |
|
139 break; |
|
140 |
|
141 case KContextModifyActive: |
|
142 // This command is only valid aftermodifying TFT/QoS parameters. |
|
143 // As we don't support any of these operations, |
|
144 // this command is never valid. |
|
145 break; |
|
146 #endif |
|
147 |
|
148 default: |
|
149 break; |
|
150 } |
|
151 } |
|
152 return KErrNotSupported; |
|
153 } |
|
154 |
|
155 TInt CIPv6Binder::GetConfig(TBinderConfig& aConfig) |
|
156 { |
|
157 TBinderConfig6* config = TBinderConfig::Cast<TBinderConfig6>(aConfig); |
|
158 |
|
159 if(config == NULL) |
|
160 { |
|
161 return KErrNotSupported; |
|
162 } |
|
163 |
|
164 config->iFamily = KAfInet6; /* KAfInet6 - selects TBinderConfig6 */ |
|
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 TEui64Addr& localId = TEui64Addr::Cast(config->iLocalId); |
|
172 localId = iSettings.iLocalIfId; |
|
173 config->iNameSer1.SetAddress(iSettings.iPrimaryDns); /* IP primary name server (if any). */ |
|
174 config->iNameSer2.SetAddress(iSettings.iSecondaryDns); /* IP secondary name server (if any). */ |
|
175 |
|
176 return KErrNone; |
|
177 } |
|
178 |
|
179 #ifdef WCDMA_STUB |
|
180 |
|
181 TInt CIPv6Binder::DeleteContext(TDes8& aContextParameters) |
|
182 /** |
|
183 * Deletes a context. As the NIF is responsible for one primary context, |
|
184 * this is equivalent to closing down the NIF. |
|
185 * |
|
186 * @param aContextParameters Parameters of the context to delete |
|
187 * @return KErrArgument if an incorrect structure is passed, otherwise KErrNone |
|
188 */ |
|
189 { |
|
190 _LOG_L1C1(_L8("CIPv6Binder::DeleteContext")); |
|
191 |
|
192 if (aContextParameters.Length() != sizeof(TContextParameters)) |
|
193 { |
|
194 return KErrArgument; |
|
195 } |
|
196 |
|
197 TUint8* ptr = CONST_CAST(TUint8*, aContextParameters.Ptr()); |
|
198 TContextParameters* params = REINTERPRET_CAST(TContextParameters*, ptr); |
|
199 |
|
200 if (params->iContextInfo.iContextId != |
|
201 STATIC_CAST(TInt8, GetFlow().GetBcaController()->Nsapi())) |
|
202 { |
|
203 params->iReasonCode = KErrBadName; |
|
204 } |
|
205 else |
|
206 { |
|
207 params->iReasonCode = KErrNone; |
|
208 GetFlow().Stop(KErrNone, MNifIfNotify::EDisconnect); |
|
209 } |
|
210 |
|
211 return KErrNone; |
|
212 } |
|
213 |
|
214 #endif |
|
215 |
|
216 /** |
|
217 * Called when the context has been activated to set our IP address and get |
|
218 * any other required settings from CommDB. |
|
219 * |
|
220 * @param aConfig The new context config |
|
221 */ |
|
222 void CIPv6Binder::UpdateContextConfigL(const TPacketDataConfigBase& aConfig) |
|
223 { |
|
224 _LOG_L1C1(_L8("CIPv6Binder::UpdateContextConfig")); |
|
225 |
|
226 // Get our IP address from the GPRS context config. |
|
227 TInetAddr address; |
|
228 |
|
229 TBuf<RPacketContext::KMaxPDPAddressLength> tempAddr; |
|
230 |
|
231 const RPacketContext::TProtocolConfigOptionV2* pco; |
|
232 TInt rel = const_cast<TPacketDataConfigBase&>(aConfig).ExtensionId(); |
|
233 if (rel == TPacketDataConfigBase::KConfigGPRS) |
|
234 { |
|
235 tempAddr.Copy(static_cast<const RPacketContext::TContextConfigGPRS&>(aConfig).iPdpAddress); |
|
236 pco = &static_cast<const RPacketContext::TContextConfigGPRS&>(aConfig).iProtocolConfigOption; |
|
237 } |
|
238 else |
|
239 { |
|
240 ASSERT(rel == TPacketDataConfigBase::KConfigRel99Rel4 || rel == TPacketDataConfigBase::KConfigRel5); |
|
241 tempAddr.Copy(static_cast<const RPacketContext::TContextConfigR99_R4&>(aConfig).iPdpAddress); |
|
242 pco = &static_cast<const RPacketContext::TContextConfigR99_R4&>(aConfig).iProtocolConfigOption; |
|
243 } |
|
244 TInt ret = address.Input(tempAddr); |
|
245 |
|
246 // We've got our IP address! Let's save it. |
|
247 if (ret == KErrNone) |
|
248 { |
|
249 iSettings.iLocalAddr = address.Ip6Address(); |
|
250 LOG_IP_ADDRESS("Got local IP address", iSettings.iLocalAddr); |
|
251 } |
|
252 else |
|
253 { |
|
254 _LOG_L2C2(_L8("Couldn't get IP address from GPRS config (err: %d)"), |
|
255 ret); |
|
256 |
|
257 // Don't leave on this error: we may still be OK if we read some |
|
258 // settings from CommDB. |
|
259 } |
|
260 |
|
261 // @todo - is this correct. We can only get the DNS addresses |
|
262 // from the TSY using the iProtocolConfigOption data. Yet a client could |
|
263 // access those DNS config details without knowing about the state of the |
|
264 // iSettings.iGetDnsFromServer flag. |
|
265 |
|
266 if ((iSettings.iGetDnsFromServer) || |
|
267 ((iSettings.iPrimaryDns.IsUnspecified()) && |
|
268 (iSettings.iSecondaryDns.IsUnspecified())) ) |
|
269 { |
|
270 TBuf<RPacketContext::KMaxPDPAddressLength> tempAddr; |
|
271 tempAddr.Copy(pco->iDnsAddresses.iPrimaryDns); |
|
272 ret = address.Input(tempAddr); |
|
273 |
|
274 if (ret == KErrNone) |
|
275 { |
|
276 iSettings.iPrimaryDns = address.Ip6Address(); |
|
277 LOG_IP_ADDRESS("Got primary DNS", iSettings.iPrimaryDns); |
|
278 } |
|
279 else |
|
280 { |
|
281 _LOG_L2C2(_L8("Couldn't get primary DNS address from GPRS config (err: %d)"), |
|
282 ret); |
|
283 |
|
284 // Don't leave on this error: we may still be OK if we read some |
|
285 // settings from CommDB. |
|
286 } |
|
287 |
|
288 tempAddr.Copy(pco->iDnsAddresses.iSecondaryDns); |
|
289 ret = address.Input(tempAddr); |
|
290 |
|
291 if (ret == KErrNone) |
|
292 { |
|
293 iSettings.iSecondaryDns = address.Ip6Address(); |
|
294 LOG_IP_ADDRESS("Got secondary DNS", iSettings.iPrimaryDns); |
|
295 } |
|
296 else |
|
297 { |
|
298 _LOG_L2C2(_L8("Couldn't get secondary DNS address from GPRS config (err: %d)"), |
|
299 ret); |
|
300 |
|
301 // Don't leave on this error: we may still be OK if we read some |
|
302 // settings from CommDB. |
|
303 } |
|
304 } |
|
305 else |
|
306 { |
|
307 LOG_IP_ADDRESS("Using CommDB DNS address - Primary ", iSettings.iPrimaryDns); |
|
308 LOG_IP_ADDRESS(" - Secondary ", iSettings.iSecondaryDns); |
|
309 } |
|
310 } |
|
311 |
|
312 void CIPv6Binder::UpdateConnectionSpeed(TUint aConnectionSpeed) |
|
313 /** |
|
314 * Sets the speed metric to return to TCP/IP, based on what the TSY tells us. |
|
315 * |
|
316 * @param aConnectionSpeed Our connection speed |
|
317 */ |
|
318 { |
|
319 _LOG_L1C1(_L8("CIPv6Binder::UpdateConnectionSpeed")); |
|
320 |
|
321 iSpeedMetric = aConnectionSpeed; |
|
322 } |
|
323 |
|
324 ESock::MLowerDataSender::TSendResult CIPv6Binder::Send(RMBufChain& aPdu) |
|
325 { |
|
326 return Send(static_cast<RCommsBufChain&>(aPdu)); |
|
327 } |
|
328 |
|
329 ESock::MLowerDataSender::TSendResult CIPv6Binder::Send(RCommsBufChain& aPdu) |
|
330 /** |
|
331 * Called by the protocol to send an outgoing IP packet to the network. |
|
332 * |
|
333 * @param aPdu The outgoing packet |
|
334 * @return Standard error codes |
|
335 */ |
|
336 { |
|
337 _LOG_L1C1(_L8("CIPv6Binder::Send")); |
|
338 |
|
339 #ifdef __BTT_LOGGING__ |
|
340 LogPacket(static_cast<RMBufChain&>(aPdu)); |
|
341 #endif |
|
342 |
|
343 // Return <0: an error occurred |
|
344 // Return 0: no error, but don't send any more packets |
|
345 |
|
346 #ifdef RAWIP_HEADER_APPENDED_TO_PACKETS |
|
347 iIPTagHeader->AddHeader(aPdu); |
|
348 #endif // RAWIP_HEADER_APPENDED_TO_PACKETS |
|
349 |
|
350 return ESock::MLowerDataSender::TSendResult(iLowerDataSender->Send(aPdu)); |
|
351 |
|
352 } |
|
353 |
|
354 TInt CIPv6Binder::Notification(TAgentToNifEventType /*aEvent*/, |
|
355 void* /*aInfo*/) |
|
356 /** |
|
357 * The Nif will ignore any notification sent |
|
358 * |
|
359 * @param aEvent Not used |
|
360 * @param aInfo Not used |
|
361 */ |
|
362 { |
|
363 _LOG_L1C1(_L8("CIPv6Binder::Notification")); |
|
364 |
|
365 return KErrNone; |
|
366 } |
|
367 |
|
368 void CIPv6Binder::StartSending() |
|
369 /** |
|
370 * Indicates to the protocol layer that the NIF is ready to send packets. |
|
371 * |
|
372 * @param aProtocol A pointer to a protocol |
|
373 */ |
|
374 { |
|
375 _LOG_L1C1(_L8("CIPv6Binder::StartSending()")); |
|
376 CBinderBase::StartSending(); |
|
377 } |
|
378 |
|
379 TBool CIPv6Binder::WantsProtocol(TUint16 aProtocolCode) |
|
380 /** |
|
381 * Indicates the type of protocol implemented by this class. |
|
382 * |
|
383 * @param aProtocolCode The protocol type |
|
384 */ |
|
385 { |
|
386 _LOG_L1C2(_L8("CIPv6Binder::WantsProtocol [aProtocolCode=%X]"), |
|
387 aProtocolCode); |
|
388 |
|
389 #ifdef RAWIP_HEADER_APPENDED_TO_PACKETS |
|
390 return ((aProtocolCode & 0x00FF) == KIp6FrameType); |
|
391 #else |
|
392 (void) aProtocolCode; |
|
393 return ETrue; |
|
394 #endif // RAWIP_HEADER_APPENDED_TO_PACKETS |
|
395 } |
|
396 |
|
397 void CIPv6Binder::Process(RMBufChain& aPdu) |
|
398 { |
|
399 Process(static_cast<RCommsBufChain&>(aPdu)); |
|
400 } |
|
401 |
|
402 void CIPv6Binder::Process(RCommsBufChain& aPdu) |
|
403 /** |
|
404 * Called when an incoming IP packet has arrived. Send packets up to the |
|
405 * TCP/IP stack. |
|
406 * |
|
407 * @param aPdu The incoming packet |
|
408 */ |
|
409 { |
|
410 _LOG_L1C1(_L8("CIPv6Binder::Process")); |
|
411 |
|
412 #ifdef __BTT_LOGGING__ |
|
413 LogPacket(static_cast<RMBufChain&>(aPdu)); |
|
414 #endif |
|
415 |
|
416 #ifdef RAWIP_HEADER_APPENDED_TO_PACKETS |
|
417 TUint16 protocolCode = iIPTagHeader->RemoveHeader(aPdu); |
|
418 #else |
|
419 TUint16 protocolCode = 0; |
|
420 #endif // RAWIP_HEADER_APPENDED_TO_PACKETS |
|
421 |
|
422 |
|
423 |
|
424 // Pass incoming packets up to the protocol, unless it hasn't |
|
425 // been bound yet. |
|
426 if (iUpperReceiver && WantsProtocol(protocolCode)) |
|
427 { |
|
428 _LOG_L1C1(_L8("CIPv6Binder: Packet Sent to TCP/IP Protocol!!!")); |
|
429 iUpperReceiver->Process(static_cast<RMBufChain&>(aPdu)); |
|
430 } |
|
431 else |
|
432 { |
|
433 _LOG_L2C1(_L8("WARNING: dumping incoming packet, no protocol bound")); |
|
434 aPdu.Free(); |
|
435 } |
|
436 |
|
437 } |
|
438 |
|
439 // |
|
440 // MLowerControl methods |
|
441 // |
|
442 |
|
443 TInt CIPv6Binder::GetName(TDes& aName) |
|
444 /** |
|
445 */ |
|
446 { |
|
447 WriteIfName(aName); |
|
448 return KErrNone; |
|
449 } |
|
450 |
|
451 // |
|
452 // CBinderBase methods |
|
453 // |
|
454 |
|
455 void CIPv6Binder::SetProvision(const CIPConfig& aProvision) |
|
456 /** |
|
457 Set provisioning information for IPv6 binder. |
|
458 |
|
459 Called from RawIP Flow. |
|
460 |
|
461 @param aProvision Provisioning structure from Control side. |
|
462 */ |
|
463 { |
|
464 iSettings.iPrimaryDns = aProvision.GetIp6NameServer1(); |
|
465 iSettings.iSecondaryDns = aProvision.GetIp6NameServer2(); |
|
466 iSettings.iGetDnsFromServer = aProvision.GetIp6DNSAddrFromServer(); |
|
467 |
|
468 // Read whether to get IPv4 address from the server |
|
469 // This is only needed for the integration tests. If it's true then |
|
470 // the IPv4 address will be used to build up the IPv6 address. |
|
471 iSettings.iGetIpFromServer = aProvision.GetIpAddrFromServer(); |
|
472 |
|
473 if (iSettings.iGetIpFromServer == EFalse) |
|
474 { |
|
475 // Sets the IPv6 Link-local address from IpAddr. |
|
476 // LocalId is derived from IpAddr and it's further used to set the Link-local |
|
477 // address elsewhere by adding a prefix (FE80::) in front. |
|
478 // For IpAddr: 192.168.1.1, link-local address will be FE80::C0A8:101. |
|
479 TUint32 ipAddr = aProvision.GetIpAddress(); |
|
480 const TUint8 constantId[8] = { 0, 0, 0, 0, |
|
481 ipAddr >> 24, (ipAddr >> 16) & 0xFF, |
|
482 (ipAddr >> 8) & 0xFF, ipAddr & 0xFF }; |
|
483 iSettings.iLocalIfId.SetAddr(constantId, sizeof (constantId)); |
|
484 } |
|
485 else |
|
486 { |
|
487 // |
|
488 // Use the 64 bit id of MARM machines as our interface id |
|
489 // |
|
490 TMachineInfoV1Buf machineInfo; |
|
491 UserHal::MachineInfo(machineInfo); |
|
492 iSettings.iLocalIfId.SetAddr(machineInfo().iMachineUniqueId); |
|
493 iSettings.iLocalIfId.SetUniversalBit(0); |
|
494 // |
|
495 // In WINS environment the id is zero which is no-no |
|
496 // |
|
497 if (iSettings.iLocalIfId.IsZero()) |
|
498 { |
|
499 iSettings.iLocalIfId.SetAddrRandomNZ(); |
|
500 } |
|
501 } |
|
502 } |
|
503 |
|
504 #ifdef __BTT_LOGGING__ |
|
505 void CIPv6Binder::LogPacket(const RMBufChain& aPacket) |
|
506 /** |
|
507 * Logs packet information into log file. |
|
508 * |
|
509 * @param aPacket The packet |
|
510 */ |
|
511 { |
|
512 _LOG_L1C1(_L8("CIPv6Binder::LogPacket")); |
|
513 |
|
514 TInt mBufLength = aPacket.Length() - aPacket.First()->Length(); |
|
515 |
|
516 _LOG_L3C2(_L8("Analysis of %d byte packet:"), mBufLength); |
|
517 |
|
518 //Note: All the constants used on this method are a pragmatic guess of the |
|
519 //IP header fields. The only porpose of this method is logging. |
|
520 |
|
521 if (mBufLength < 40) |
|
522 { |
|
523 _LOG_L3C2(_L8(" -doesn't appear to be a valid IPv6 packet (length=%d)") |
|
524 , mBufLength); |
|
525 return; |
|
526 } |
|
527 |
|
528 // Get a pointer to the packet's payload. |
|
529 const TUint8* payloadPtr = aPacket.First()->Next()->Ptr(); |
|
530 |
|
531 if ((payloadPtr[0] & 0xF0) != 0x60) |
|
532 { |
|
533 _LOG_L3C2(_L8(" - doesn't appear to be an IPv6 packet (version=0x%X)"), |
|
534 (payloadPtr[0] & 0xF0) >> 4); |
|
535 return; |
|
536 } |
|
537 |
|
538 _LOG_L3C2(_L8(" - traffic class: 0x%X"), |
|
539 ((payloadPtr[0] & 0xF) << 4) | ((payloadPtr[1] & 0xF0) >> 4)); |
|
540 _LOG_L3C2(_L8(" - flow label: 0x%X"), |
|
541 ((payloadPtr[1] & 0x0F) << 16) | (payloadPtr[2] << 8) | payloadPtr[3]); |
|
542 _LOG_L3C2(_L8(" - payload length: 0x%X"), |
|
543 (payloadPtr[4] << 16) | payloadPtr[5]); |
|
544 _LOG_L3C2(_L8(" - next header: 0x%08X"), payloadPtr[6]); |
|
545 _LOG_L3C2(_L8(" - hop limit: 0x%08X"), payloadPtr[7]); |
|
546 } |
|
547 #endif // __BTT_LOGGING__ |