telephonyprotocols/rawipnif/src/IPv6Binder.cpp
branchRCL_3
changeset 20 07a122eea281
parent 19 630d2f34d719
equal deleted inserted replaced
19:630d2f34d719 20:07a122eea281
    17 //
    17 //
    18 
    18 
    19 /**
    19 /**
    20  @file
    20  @file
    21 */
    21 */
    22 
       
    23 
       
    24 #include "OstTraceDefinitions.h"
       
    25 #ifdef OST_TRACE_COMPILER_IN_USE
       
    26 #include "IPv6BinderTraces.h"
       
    27 #endif
       
    28 
    22 
    29 #include <etelpckt.h>
    23 #include <etelpckt.h>
    30 #include <in_iface.h>
    24 #include <in_iface.h>
    31 #include "RawIPFlow.h"
    25 #include "RawIPFlow.h"
    32 #include "IPv6Binder.h"
    26 #include "IPv6Binder.h"
    37 using namespace ESock;
    31 using namespace ESock;
    38 #ifdef WCDMA_STUB
    32 #ifdef WCDMA_STUB
    39 #include <networking/umtsnifcontrolif.h>
    33 #include <networking/umtsnifcontrolif.h>
    40 #endif
    34 #endif
    41 
    35 
       
    36 #define LOG_IP_ADDRESS(desc,addr) _LOG_L2C5(_L8("    " desc " = %d:%d:%d:%d from context"), \
       
    37 			addr.u.iAddr32[3], addr.u.iAddr32[2], addr.u.iAddr32[1], addr.u.iAddr32[0]);
    42 
    38 
    43 #ifdef __EABI__
    39 #ifdef __EABI__
    44 // Patch data is used and KMtuIPv6 and KRMtuIPv6 can be modified to a different value in RawIpNif.iby file
    40 // Patch data is used and KMtuIPv6 and KRMtuIPv6 can be modified to a different value in RawIpNif.iby file
    45 extern const TInt KMtuIPv6 = KDefaultMtu;
    41 extern const TInt KMtuIPv6 = KDefaultMtu;
    46 extern const TInt KRMtuIPv6 = KDefaultMtu;
    42 extern const TInt KRMtuIPv6 = KDefaultMtu;
    47 #endif
    43 #endif
    48 
    44 
    49 CIPv6Binder::CIPv6Binder(CRawIPFlow& aFlow)
    45 CIPv6Binder::CIPv6Binder(CRawIPFlow& aFlow, CBttLogger* aTheLogger)
    50 /**
    46 /**
    51  * Constructor
    47  * Constructor
    52  */ 
    48  */ 
    53 	: CBinderBase(aFlow),
    49 	: CBinderBase(aFlow,aTheLogger),
       
    50 	  iTheLogger(aTheLogger),
    54 	  iSpeedMetric(KDefaultSpeedMetric)
    51 	  iSpeedMetric(KDefaultSpeedMetric)
    55 	{
    52 	{
    56 	}
    53 	}
    57 
    54 
    58 CIPv6Binder::~CIPv6Binder()
    55 CIPv6Binder::~CIPv6Binder()
    84  * @param aName The command to perform
    81  * @param aName The command to perform
    85  * @param aOption Data to be input/output as a result of the command
    82  * @param aOption Data to be input/output as a result of the command
    86  * @return Standard error codes
    83  * @return Standard error codes
    87  */
    84  */
    88 	{
    85 	{
    89 	OstTraceDefExt2(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CIPV6BINDER_CONTROL_1, "CIPv6Binder::Control [aLevel=%u, aName=%u]",aLevel, aName);
    86 	_LOG_L1C3(_L8("CIPv6Binder::Control [aLevel=%d, aName=%d]"),
       
    87 		aLevel, aName);
    90 
    88 
    91 	if (aLevel == KSOLInterface)
    89 	if (aLevel == KSOLInterface)
    92 		{
    90 		{
    93 		switch (aName)
    91 		switch (aName)
    94 			{
    92 			{
   205  *
   203  *
   206  * @param aContextParameters Parameters of the context to delete
   204  * @param aContextParameters Parameters of the context to delete
   207  * @return KErrArgument if an incorrect structure is passed, otherwise KErrNone
   205  * @return KErrArgument if an incorrect structure is passed, otherwise KErrNone
   208  */
   206  */
   209 	{
   207 	{
   210 	OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CIPV6BINDER_DELETECONTEXT_1, "CIPv6Binder::DeleteContext");
   208 	_LOG_L1C1(_L8("CIPv6Binder::DeleteContext"));
   211 
   209 
   212 	if (aContextParameters.Length() != sizeof(TContextParameters))
   210 	if (aContextParameters.Length() != sizeof(TContextParameters))
   213 		{
   211 		{
   214 		return KErrArgument;
   212 		return KErrArgument;
   215 		}
   213 		}
   239  *
   237  *
   240  * @param aConfig The new context config
   238  * @param aConfig The new context config
   241  */
   239  */
   242  void CIPv6Binder::UpdateContextConfigL(const TPacketDataConfigBase& aConfig)
   240  void CIPv6Binder::UpdateContextConfigL(const TPacketDataConfigBase& aConfig)
   243 	{
   241 	{
   244 	OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CIPV6BINDER_UPDATECONTEXTCONFIGL_1, "CIPv6Binder::UpdateContextConfig");
   242 	_LOG_L1C1(_L8("CIPv6Binder::UpdateContextConfig"));
   245 
   243 
   246 	// Get our IP address from the GPRS context config.
   244 	// Get our IP address from the GPRS context config.
   247 	TInetAddr address;
   245 	TInetAddr address;
   248 	
   246 	
   249 	TBuf<RPacketContext::KMaxPDPAddressLength> tempAddr;
   247 	TBuf<RPacketContext::KMaxPDPAddressLength> tempAddr;
   268 		{
   266 		{
   269 		const TUint8* addrTable = &address.Ip6Address().u.iAddr8[8];
   267 		const TUint8* addrTable = &address.Ip6Address().u.iAddr8[8];
   270 		
   268 		
   271 		iSettings.iLocalIfId.SetAddr(addrTable, 8);		
   269 		iSettings.iLocalIfId.SetAddr(addrTable, 8);		
   272 		
   270 		
   273 		OstTraceDefExt4(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CIPV6BINDER_UPDATECONTEXTCONFIGL_2, "Got local IP address = %u:%u:%u:%u from context", address.Ip6Address().u.iAddr32[3], address.Ip6Address().u.iAddr32[2], address.Ip6Address().u.iAddr32[1], address.Ip6Address().u.iAddr32[0]);
   271 		LOG_IP_ADDRESS("Got local IP address", address.Ip6Address());
   274 		}
   272 		}
   275 	else
   273 	else
   276 		{
   274 		{
   277 		OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CIPV6BINDER_UPDATECONTEXTCONFIGL_3, "Couldn't get IP address from GPRS config (err: %d)",ret);
   275 		_LOG_L2C2(_L8("Couldn't get IP address from GPRS config (err: %d)"),
       
   276 			ret);
   278 
   277 
   279 		// Don't leave on this error: we may still be OK if we read some
   278 		// Don't leave on this error: we may still be OK if we read some
   280 		// settings from CommDB.
   279 		// settings from CommDB.
   281 		}
   280 		}
   282 
   281 
   294 		ret = address.Input(tempAddr);
   293 		ret = address.Input(tempAddr);
   295 
   294 
   296 		if (ret == KErrNone)
   295 		if (ret == KErrNone)
   297 			{
   296 			{
   298 			iSettings.iPrimaryDns = address.Ip6Address();
   297 			iSettings.iPrimaryDns = address.Ip6Address();
   299 			OstTraceDefExt4(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CIPV6BINDER_UPDATECONTEXTCONFIGL_4, "Got primary DNS = %u:%u:%u:%u from context", iSettings.iPrimaryDns.u.iAddr32[3], iSettings.iPrimaryDns.u.iAddr32[2], iSettings.iPrimaryDns.u.iAddr32[1], iSettings.iPrimaryDns.u.iAddr32[0]);
   298 			LOG_IP_ADDRESS("Got primary DNS", iSettings.iPrimaryDns);
   300 			}
   299 			}
   301 		else
   300 		else
   302 			{
   301 			{
   303 			OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CIPV6BINDER_UPDATECONTEXTCONFIGL_5, "Couldn't get primary DNS address from GPRS config (err: %d)",ret);
   302 			_LOG_L2C2(_L8("Couldn't get primary DNS address from GPRS config (err: %d)"),
       
   303 				ret);
   304 
   304 
   305 			// Don't leave on this error: we may still be OK if we read some
   305 			// Don't leave on this error: we may still be OK if we read some
   306 			// settings from CommDB.
   306 			// settings from CommDB.
   307 			}
   307 			}
   308 
   308 
   310 		ret = address.Input(tempAddr);
   310 		ret = address.Input(tempAddr);
   311 
   311 
   312 		if (ret == KErrNone)
   312 		if (ret == KErrNone)
   313 			{
   313 			{
   314 			iSettings.iSecondaryDns = address.Ip6Address();
   314 			iSettings.iSecondaryDns = address.Ip6Address();
   315 			OstTraceDefExt4(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CIPV6BINDER_UPDATECONTEXTCONFIGL_6, "Got secondary DNS = %u:%u:%u:%u from context", iSettings.iSecondaryDns.u.iAddr32[3], iSettings.iSecondaryDns.u.iAddr32[2], iSettings.iSecondaryDns.u.iAddr32[1], iSettings.iSecondaryDns.u.iAddr32[0]);
   315 			LOG_IP_ADDRESS("Got secondary DNS", iSettings.iPrimaryDns);
   316 			}
   316 			}
   317 		else
   317 		else
   318 			{
   318 			{
   319 			OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CIPV6BINDER_UPDATECONTEXTCONFIGL_7, "Couldn't get secondary DNS address from GPRS config (err: %d)",ret);
   319 			_LOG_L2C2(_L8("Couldn't get secondary DNS address from GPRS config (err: %d)"),
       
   320 				ret);
   320 
   321 
   321 			// Don't leave on this error: we may still be OK if we read some
   322 			// Don't leave on this error: we may still be OK if we read some
   322 			// settings from CommDB.
   323 			// settings from CommDB.
   323 			}
   324 			}
   324 		}
   325 		}
   325 	else
   326 	else
   326 		{
   327 		{
   327         OstTraceDefExt4(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CIPV6BINDER_UPDATECONTEXTCONFIGL_8, "Using CommDB DNS address - Primary  = %u:%u:%u:%u", iSettings.iPrimaryDns.u.iAddr32[3], iSettings.iPrimaryDns.u.iAddr32[2], iSettings.iPrimaryDns.u.iAddr32[1], iSettings.iPrimaryDns.u.iAddr32[0]);
   328 		LOG_IP_ADDRESS("Using CommDB DNS address - Primary ", iSettings.iPrimaryDns);
   328         OstTraceDefExt4(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CIPV6BINDER_UPDATECONTEXTCONFIGL_9, "                         - Secondary = %u:%u:%u:%u", iSettings.iSecondaryDns.u.iAddr32[3], iSettings.iSecondaryDns.u.iAddr32[2], iSettings.iSecondaryDns.u.iAddr32[1], iSettings.iSecondaryDns.u.iAddr32[0]);
   329 		LOG_IP_ADDRESS("                         - Secondary ", iSettings.iSecondaryDns);
   329 		}
   330 		}
   330 	}
   331 	}
   331 
   332 
   332 void CIPv6Binder::UpdateConnectionSpeed(TUint aConnectionSpeed)
   333 void CIPv6Binder::UpdateConnectionSpeed(TUint aConnectionSpeed)
   333 /**
   334 /**
   334  * Sets the speed metric to return to TCP/IP, based on what the TSY tells us.
   335  * Sets the speed metric to return to TCP/IP, based on what the TSY tells us.
   335  *
   336  *
   336  * @param aConnectionSpeed Our connection speed
   337  * @param aConnectionSpeed Our connection speed
   337  */
   338  */
   338 	{
   339 	{
   339 	OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CIPV6BINDER_UPDATECONNECTIONSPEED_1, "CIPv6Binder::UpdateConnectionSpeed");
   340 	_LOG_L1C1(_L8("CIPv6Binder::UpdateConnectionSpeed"));
   340 
   341 
   341 	iSpeedMetric = aConnectionSpeed;
   342 	iSpeedMetric = aConnectionSpeed;
   342 	}
   343 	}
   343 
   344 
   344 
   345 
   348  *
   349  *
   349  * @param aPdu The outgoing packet
   350  * @param aPdu The outgoing packet
   350  * @return MLowerDataSender::ESendBlocked or ESendAccepted based on state of flow.
   351  * @return MLowerDataSender::ESendBlocked or ESendAccepted based on state of flow.
   351  */
   352  */
   352 	{
   353 	{
   353 	OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CIPV6BINDER_SEND_1, "CIPv6Binder::Send");
   354 	_LOG_L1C1(_L8("CIPv6Binder::Send"));
   354 
   355 
   355 #ifdef __BTT_LOGGING__
   356 #ifdef __BTT_LOGGING__
   356 	LogPacket(aPdu);
   357 	LogPacket(aPdu);
   357 #endif
   358 #endif
   358 
   359 
   369  *
   370  *
   370  * @param aEvent Not used
   371  * @param aEvent Not used
   371  * @param aInfo Not used 
   372  * @param aInfo Not used 
   372  */
   373  */
   373 	{
   374 	{
   374 	OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CIPV6BINDER_NOTIFICATION_1, "CIPv6Binder::Notification");
   375 	_LOG_L1C1(_L8("CIPv6Binder::Notification"));
   375 
   376 
   376 	return KErrNone;
   377 	return KErrNone;
   377 	}
   378 	}
   378 
   379 
   379 void CIPv6Binder::StartSending()
   380 void CIPv6Binder::StartSending()
   381  * Indicates to the protocol layer that the NIF is ready to send packets.
   382  * Indicates to the protocol layer that the NIF is ready to send packets.
   382  *
   383  *
   383  * @param aProtocol A pointer to a protocol
   384  * @param aProtocol A pointer to a protocol
   384  */
   385  */
   385 	{
   386 	{
   386 	OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CIPV6BINDER_STARTSENDING_1, "CIPv6Binder::StartSending()");
   387 	_LOG_L1C1(_L8("CIPv6Binder::StartSending()"));
   387 
   388 
   388 	CBinderBase::StartSending();
   389 	CBinderBase::StartSending();
   389 	}
   390 	}
   390 
   391 
   391 TBool CIPv6Binder::WantsProtocol(TUint16 aProtocolCode)
   392 TBool CIPv6Binder::WantsProtocol(TUint16 aProtocolCode)
   393  * Indicates the type of protocol implemented by this class.
   394  * Indicates the type of protocol implemented by this class.
   394  *
   395  *
   395  * @param aProtocolCode The protocol type
   396  * @param aProtocolCode The protocol type
   396  */
   397  */
   397 	{
   398 	{
   398 	OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CIPV6BINDER_WANTSPROTOCOL_1, "CIPv6Binder::WantsProtocol [aProtocolCode=%X]",aProtocolCode);
   399 	_LOG_L1C2(_L8("CIPv6Binder::WantsProtocol [aProtocolCode=%X]"),
       
   400 		aProtocolCode);
   399 
   401 
   400 #ifdef RAWIP_HEADER_APPENDED_TO_PACKETS
   402 #ifdef RAWIP_HEADER_APPENDED_TO_PACKETS
   401 	return ((aProtocolCode & 0x00FF) == KIp6FrameType);
   403 	return ((aProtocolCode & 0x00FF) == KIp6FrameType);
   402 #else
   404 #else
   403 	(void) aProtocolCode;
   405 	(void) aProtocolCode;
   411  * TCP/IP stack.
   413  * TCP/IP stack.
   412  *
   414  *
   413  * @param aPdu The incoming packet
   415  * @param aPdu The incoming packet
   414  */
   416  */
   415 	{
   417 	{
   416 	OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CIPV6BINDER_PROCESS_1, "CIPv6Binder::Process");
   418 	_LOG_L1C1(_L8("CIPv6Binder::Process"));
   417 
   419 
   418 #ifdef __BTT_LOGGING__
   420 #ifdef __BTT_LOGGING__
   419 	LogPacket(aPdu);
   421 	LogPacket(aPdu);
   420 #endif
   422 #endif
   421 
   423 
   422 	// Pass incoming packets up to the protocol, unless it hasn't
   424 	// Pass incoming packets up to the protocol, unless it hasn't
   423 	// been bound yet.
   425 	// been bound yet.
   424 	if (iUpperReceiver)						// ASSERT(iUpperReceiver) ?
   426 	if (iUpperReceiver)						// ASSERT(iUpperReceiver) ?
   425 		{
   427 		{
   426 		OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CIPV6BINDER_PROCESS_2, "CIPv6Binder: Packet Sent to TCP/IP Protocol!!!");
   428 		_LOG_L1C1(_L8("CIPv6Binder: Packet Sent to TCP/IP Protocol!!!"));
   427 		iUpperReceiver->Process(aPdu);
   429 		iUpperReceiver->Process(aPdu);
   428 		}
   430 		}
   429 	else 
   431 	else 
   430 		{
   432 		{
   431 		OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CIPV6BINDER_PROCESS_3, "WARNING: dumping incoming packet, no protocol bound");
   433 		_LOG_L2C1(_L8("WARNING: dumping incoming packet, no protocol bound"));
   432 		aPdu.Free();
   434 		aPdu.Free();
   433 		}
   435 		}
   434 	}
   436 	}
   435 
   437 
   436 //
   438 //
   504 * Logs packet information into log file.
   506 * Logs packet information into log file.
   505 *
   507 *
   506 * @param aPacket The packet 
   508 * @param aPacket The packet 
   507 */
   509 */
   508 	{
   510 	{
   509 	OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CIPV6BINDER_LOGPACKET_1, "CIPv6Binder::LogPacket");
   511 	_LOG_L1C1(_L8("CIPv6Binder::LogPacket"));
   510 
   512 
   511 	TInt mBufLength = aPacket.Length() - aPacket.First()->Length();
   513 	TInt mBufLength = aPacket.Length() - aPacket.First()->Length();
   512 
   514 
   513 	OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CIPV6BINDER_LOGPACKET_2, "Analysis of %d byte packet:", mBufLength);
   515 	_LOG_L3C2(_L8("Analysis of %d byte packet:"), mBufLength);
   514 
   516 
   515 	//Note: All the constants used on this method are a pragmatic guess of the
   517 	//Note: All the constants used on this method are a pragmatic guess of the
   516 	//IP header fields. The only porpose of this method is logging.
   518 	//IP header fields. The only porpose of this method is logging.
   517 
   519 
   518 	if (mBufLength < 40)
   520 	if (mBufLength < 40)
   519 		{
   521 		{
   520 		OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CIPV6BINDER_LOGPACKET_3, " -doesn't appear to be a valid IPv6 packet (length=%d)", mBufLength);
   522 		_LOG_L3C2(_L8(" -doesn't appear to be a valid IPv6 packet (length=%d)")
       
   523 			, mBufLength);
   521 		return;
   524 		return;
   522 		}
   525 		}
   523 
   526 
   524 	// Get a pointer to the packet's payload.
   527 	// Get a pointer to the packet's payload.
   525 	const TUint8* payloadPtr = aPacket.First()->Next()->Ptr();
   528 	const TUint8* payloadPtr = aPacket.First()->Next()->Ptr();
   526 
   529 
   527 	if ((payloadPtr[0] & 0xF0) != 0x60)
   530 	if ((payloadPtr[0] & 0xF0) != 0x60)
   528 		{
   531 		{
   529 		OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CIPV6BINDER_LOGPACKET_4, " - doesn't appear to be an IPv6 packet (version=0x%X)",(payloadPtr[0] & 0xF0) >> 4);
   532 		_LOG_L3C2(_L8(" - doesn't appear to be an IPv6 packet (version=0x%X)"),
       
   533 			(payloadPtr[0] & 0xF0) >> 4);
   530 		return;
   534 		return;
   531 		}
   535 		}
   532 
   536 
   533 	OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CIPV6BINDER_LOGPACKET_5, " - traffic class: 0x%X", ((payloadPtr[0] & 0xF) << 4) | ((payloadPtr[1] & 0xF0) >> 4));
   537 	_LOG_L3C2(_L8(" - traffic class: 0x%X"), 
   534 	OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CIPV6BINDER_LOGPACKET_6, " - flow label: 0x%X", ((payloadPtr[1] & 0x0F) << 16) | (payloadPtr[2] << 8) | payloadPtr[3]);
   538 					((payloadPtr[0] & 0xF) << 4) | ((payloadPtr[1] & 0xF0) >> 4));
   535 	OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CIPV6BINDER_LOGPACKET_7, " - payload length: 0x%X", (payloadPtr[4] << 16) | payloadPtr[5]);
   539 	_LOG_L3C2(_L8(" - flow label: 0x%X"), 
   536 	OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CIPV6BINDER_LOGPACKET_8, " - next header: 0x%08X", payloadPtr[6]);
   540 					((payloadPtr[1] & 0x0F) << 16) | (payloadPtr[2] << 8) | payloadPtr[3]);
   537 	OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CIPV6BINDER_LOGPACKET_9, " - hop limit: 0x%08X", payloadPtr[7]);
   541 	_LOG_L3C2(_L8(" - payload length: 0x%X"), 
       
   542 					(payloadPtr[4] << 16) | payloadPtr[5]);
       
   543 	_LOG_L3C2(_L8(" - next header: 0x%08X"), payloadPtr[6]);
       
   544 	_LOG_L3C2(_L8(" - hop limit: 0x%08X"), payloadPtr[7]);
   538 	}
   545 	}
   539 #endif // __BTT_LOGGING__
   546 #endif // __BTT_LOGGING__