telephonyprotocols/rawipnif/rawipnif2/src/IPv6Binder.cpp
branchRCL_3
changeset 65 630d2f34d719
parent 14 7ef16719d8cb
child 66 07a122eea281
equal deleted inserted replaced
61:17af172ffa5f 65:630d2f34d719
     1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2006-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
    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
    22 
    28 
    23 #include <etelpckt.h>
    29 #include <etelpckt.h>
    24 #include <in_iface.h>
    30 #include <in_iface.h>
    25 #include "RawIP2Flow.h"
    31 #include "RawIP2Flow.h"
    26 #include "IPv6Binder.h"
    32 #include "IPv6Binder.h"
    31 
    37 
    32 #ifdef WCDMA_STUB
    38 #ifdef WCDMA_STUB
    33 #include <networking/umtsnifcontrolif.h>
    39 #include <networking/umtsnifcontrolif.h>
    34 #endif
    40 #endif
    35 
    41 
    36 #define LOG_IP_ADDRESS(desc,addr) _LOG_L2C5(_L8("    " desc " = %d:%d:%d:%d from context"), \
    42 
    37 			addr.u.iAddr32[3], addr.u.iAddr32[2], addr.u.iAddr32[1], addr.u.iAddr32[0]);
    43 CIPv6Binder::CIPv6Binder(CRawIP2Flow& aFlow)
    38 
       
    39 CIPv6Binder::CIPv6Binder(CRawIP2Flow& aFlow, CBttLogger* aTheLogger)
       
    40 /**
    44 /**
    41  * Constructor
    45  * Constructor
    42  */ 
    46  */ 
    43 	: CBinderBase(aFlow,aTheLogger),
    47 	: CBinderBase(aFlow),
    44 	  iTheLogger(aTheLogger),
       
    45 	  iSpeedMetric(KDefaultSpeedMetric)
    48 	  iSpeedMetric(KDefaultSpeedMetric)
    46 	{
    49 	{
    47 	}
    50 	}
    48 
    51 
    49 CIPv6Binder::~CIPv6Binder()
    52 CIPv6Binder::~CIPv6Binder()
    75  * @param aName The command to perform
    78  * @param aName The command to perform
    76  * @param aOption Data to be input/output as a result of the command
    79  * @param aOption Data to be input/output as a result of the command
    77  * @return Standard error codes
    80  * @return Standard error codes
    78  */
    81  */
    79 	{
    82 	{
    80 	_LOG_L1C3(_L8("CIPv6Binder::Control [aLevel=%d, aName=%d]"),
    83 	OstTraceDefExt2(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CIPV6BINDER_CONTROL_1, "CIPv6Binder::Control [aLevel=%u, aName=%u]",aLevel, aName);
    81 		aLevel, aName);
       
    82 
    84 
    83 	if (aLevel == KSOLInterface)
    85 	if (aLevel == KSOLInterface)
    84 		{
    86 		{
    85 		switch (aName)
    87 		switch (aName)
    86 			{
    88 			{
   187  *
   189  *
   188  * @param aContextParameters Parameters of the context to delete
   190  * @param aContextParameters Parameters of the context to delete
   189  * @return KErrArgument if an incorrect structure is passed, otherwise KErrNone
   191  * @return KErrArgument if an incorrect structure is passed, otherwise KErrNone
   190  */
   192  */
   191 	{
   193 	{
   192 	_LOG_L1C1(_L8("CIPv6Binder::DeleteContext"));
   194 	OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CIPV6BINDER_DELETECONTEXT_1, "CIPv6Binder::DeleteContext");
   193 
   195 
   194 	if (aContextParameters.Length() != sizeof(TContextParameters))
   196 	if (aContextParameters.Length() != sizeof(TContextParameters))
   195 		{
   197 		{
   196 		return KErrArgument;
   198 		return KErrArgument;
   197 		}
   199 		}
   221  *
   223  *
   222  * @param aConfig The new context config
   224  * @param aConfig The new context config
   223  */
   225  */
   224  void CIPv6Binder::UpdateContextConfigL(const TPacketDataConfigBase& aConfig)
   226  void CIPv6Binder::UpdateContextConfigL(const TPacketDataConfigBase& aConfig)
   225 	{
   227 	{
   226 	_LOG_L1C1(_L8("CIPv6Binder::UpdateContextConfig"));
   228 	OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CIPV6BINDER_UPDATECONTEXTCONFIGL_1, "CIPv6Binder::UpdateContextConfig");
   227 
   229 
   228 	// Get our IP address from the GPRS context config.
   230 	// Get our IP address from the GPRS context config.
   229 	TInetAddr address;
   231 	TInetAddr address;
   230 	
   232 	
   231 	TBuf<RPacketContext::KMaxPDPAddressLength> tempAddr;
   233 	TBuf<RPacketContext::KMaxPDPAddressLength> tempAddr;
   247 
   249 
   248 	// We've got our IP address! Let's save it.
   250 	// We've got our IP address! Let's save it.
   249 	if (ret == KErrNone)
   251 	if (ret == KErrNone)
   250 		{
   252 		{
   251 		iSettings.iLocalAddr = address.Ip6Address();
   253 		iSettings.iLocalAddr = address.Ip6Address();
   252 		LOG_IP_ADDRESS("Got local IP address", iSettings.iLocalAddr);
   254 		OstTraceDefExt4(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CIPV6BINDER_UPDATECONTEXTCONFIGL_2, "Got local IP address = %u:%u:%u:%u from context", iSettings.iLocalAddr.u.iAddr32[3], iSettings.iLocalAddr.u.iAddr32[2], iSettings.iLocalAddr.u.iAddr32[1], iSettings.iLocalAddr.u.iAddr32[0]);
   253 		}
   255 		}
   254 	else
   256 	else
   255 		{
   257 		{
   256 		_LOG_L2C2(_L8("Couldn't get IP address from GPRS config (err: %d)"),
   258 		OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CIPV6BINDER_UPDATECONTEXTCONFIGL_3, "Couldn't get IP address from GPRS config (err: %d)",ret);
   257 			ret);
       
   258 
   259 
   259 		// Don't leave on this error: we may still be OK if we read some
   260 		// Don't leave on this error: we may still be OK if we read some
   260 		// settings from CommDB.
   261 		// settings from CommDB.
   261 		}
   262 		}
   262 
   263 
   274 		ret = address.Input(tempAddr);
   275 		ret = address.Input(tempAddr);
   275 
   276 
   276 		if (ret == KErrNone)
   277 		if (ret == KErrNone)
   277 			{
   278 			{
   278 			iSettings.iPrimaryDns = address.Ip6Address();
   279 			iSettings.iPrimaryDns = address.Ip6Address();
   279 			LOG_IP_ADDRESS("Got primary DNS", iSettings.iPrimaryDns);
   280 			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]);
   280 			}
   281 			}
   281 		else
   282 		else
   282 			{
   283 			{
   283 			_LOG_L2C2(_L8("Couldn't get primary DNS address from GPRS config (err: %d)"),
   284 			OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CIPV6BINDER_UPDATECONTEXTCONFIGL_5, "Couldn't get primary DNS address from GPRS config (err: %d)",ret);
   284 				ret);
       
   285 
   285 
   286 			// Don't leave on this error: we may still be OK if we read some
   286 			// Don't leave on this error: we may still be OK if we read some
   287 			// settings from CommDB.
   287 			// settings from CommDB.
   288 			}
   288 			}
   289 
   289 
   291 		ret = address.Input(tempAddr);
   291 		ret = address.Input(tempAddr);
   292 
   292 
   293 		if (ret == KErrNone)
   293 		if (ret == KErrNone)
   294 			{
   294 			{
   295 			iSettings.iSecondaryDns = address.Ip6Address();
   295 			iSettings.iSecondaryDns = address.Ip6Address();
   296 			LOG_IP_ADDRESS("Got secondary DNS", iSettings.iPrimaryDns);
   296 			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]);
   297 			}
   297 			}
   298 		else
   298 		else
   299 			{
   299 			{
   300 			_LOG_L2C2(_L8("Couldn't get secondary DNS address from GPRS config (err: %d)"),
   300 			OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CIPV6BINDER_UPDATECONTEXTCONFIGL_7, "Couldn't get secondary DNS address from GPRS config (err: %d)",ret);
   301 				ret);
       
   302 
   301 
   303 			// Don't leave on this error: we may still be OK if we read some
   302 			// Don't leave on this error: we may still be OK if we read some
   304 			// settings from CommDB.
   303 			// settings from CommDB.
   305 			}
   304 			}
   306 		}
   305 		}
   307 	else
   306 	else
   308 		{
   307 		{
   309 		LOG_IP_ADDRESS("Using CommDB DNS address - Primary ", iSettings.iPrimaryDns);
   308         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]);
   310 		LOG_IP_ADDRESS("                         - Secondary ", iSettings.iSecondaryDns);
   309         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]);
   311 		}
   310 		}
   312 	}
   311 	}
   313 
   312 
   314 void CIPv6Binder::UpdateConnectionSpeed(TUint aConnectionSpeed)
   313 void CIPv6Binder::UpdateConnectionSpeed(TUint aConnectionSpeed)
   315 /**
   314 /**
   316  * Sets the speed metric to return to TCP/IP, based on what the TSY tells us.
   315  * Sets the speed metric to return to TCP/IP, based on what the TSY tells us.
   317  *
   316  *
   318  * @param aConnectionSpeed Our connection speed
   317  * @param aConnectionSpeed Our connection speed
   319  */
   318  */
   320 	{
   319 	{
   321 	_LOG_L1C1(_L8("CIPv6Binder::UpdateConnectionSpeed"));
   320 	OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CIPV6BINDER_UPDATECONNECTIONSPEED_1, "CIPv6Binder::UpdateConnectionSpeed");
   322 
   321 
   323 	iSpeedMetric = aConnectionSpeed;
   322 	iSpeedMetric = aConnectionSpeed;
   324 	}
   323 	}
   325 
   324 
   326 ESock::MLowerDataSender::TSendResult CIPv6Binder::Send(RMBufChain& aPdu)
   325 ESock::MLowerDataSender::TSendResult CIPv6Binder::Send(RMBufChain& aPdu)
   334  *
   333  *
   335  * @param aPdu The outgoing packet
   334  * @param aPdu The outgoing packet
   336  * @return Standard error codes
   335  * @return Standard error codes
   337  */
   336  */
   338 	{
   337 	{
   339 	_LOG_L1C1(_L8("CIPv6Binder::Send"));
   338 	OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CIPV6BINDER_SEND1_1, "CIPv6Binder::Send");
   340 
   339 
   341 #ifdef __BTT_LOGGING__
   340 #ifdef __BTT_LOGGING__
   342 		LogPacket(static_cast<RMBufChain&>(aPdu));
   341 		LogPacket(static_cast<RMBufChain&>(aPdu));
   343 #endif
   342 #endif
   344 	
   343 	
   360  *
   359  *
   361  * @param aEvent Not used
   360  * @param aEvent Not used
   362  * @param aInfo Not used 
   361  * @param aInfo Not used 
   363  */
   362  */
   364 	{
   363 	{
   365 	_LOG_L1C1(_L8("CIPv6Binder::Notification"));
   364 	OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CIPV6BINDER_NOTIFICATION_1, "CIPv6Binder::Notification");
   366 
   365 
   367 	return KErrNone;
   366 	return KErrNone;
   368 	}
   367 	}
   369 
   368 
   370 void CIPv6Binder::StartSending()
   369 void CIPv6Binder::StartSending()
   372  * Indicates to the protocol layer that the NIF is ready to send packets.
   371  * Indicates to the protocol layer that the NIF is ready to send packets.
   373  *
   372  *
   374  * @param aProtocol A pointer to a protocol
   373  * @param aProtocol A pointer to a protocol
   375  */
   374  */
   376 	{
   375 	{
   377 	_LOG_L1C1(_L8("CIPv6Binder::StartSending()"));
   376 	OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CIPV6BINDER_STARTSENDING_1, "CIPv6Binder::StartSending()");
   378 	CBinderBase::StartSending();
   377 	CBinderBase::StartSending();
   379 	}
   378 	}
   380 
   379 
   381 TBool CIPv6Binder::WantsProtocol(TUint16 aProtocolCode)
   380 TBool CIPv6Binder::WantsProtocol(TUint16 aProtocolCode)
   382 /**
   381 /**
   383  * Indicates the type of protocol implemented by this class.
   382  * Indicates the type of protocol implemented by this class.
   384  *
   383  *
   385  * @param aProtocolCode The protocol type
   384  * @param aProtocolCode The protocol type
   386  */
   385  */
   387 	{
   386 	{
   388 	_LOG_L1C2(_L8("CIPv6Binder::WantsProtocol [aProtocolCode=%X]"),
   387 	OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CIPV6BINDER_WANTSPROTOCOL_1, "CIPv6Binder::WantsProtocol [aProtocolCode=%X]",aProtocolCode);
   389 		aProtocolCode);
       
   390 
   388 
   391 #ifdef RAWIP_HEADER_APPENDED_TO_PACKETS
   389 #ifdef RAWIP_HEADER_APPENDED_TO_PACKETS
   392 	return ((aProtocolCode & 0x00FF) == KIp6FrameType);
   390 	return ((aProtocolCode & 0x00FF) == KIp6FrameType);
   393 #else
   391 #else
   394 	(void) aProtocolCode;
   392 	(void) aProtocolCode;
   407  * TCP/IP stack.
   405  * TCP/IP stack.
   408  *
   406  *
   409  * @param aPdu The incoming packet
   407  * @param aPdu The incoming packet
   410  */
   408  */
   411 	{
   409 	{
   412 	_LOG_L1C1(_L8("CIPv6Binder::Process"));
   410 	OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CIPV6BINDER_PROCESS1_1, "CIPv6Binder::Process");
   413 
   411 
   414 #ifdef __BTT_LOGGING__
   412 #ifdef __BTT_LOGGING__
   415 	LogPacket(static_cast<RMBufChain&>(aPdu));
   413 	LogPacket(static_cast<RMBufChain&>(aPdu));
   416 #endif
   414 #endif
   417 
   415 
   425 	
   423 	
   426 	// Pass incoming packets up to the protocol, unless it hasn't
   424 	// Pass incoming packets up to the protocol, unless it hasn't
   427 	// been bound yet.
   425 	// been bound yet.
   428 	if (iUpperReceiver && WantsProtocol(protocolCode))
   426 	if (iUpperReceiver && WantsProtocol(protocolCode))
   429 		{		
   427 		{		
   430 		_LOG_L1C1(_L8("CIPv6Binder: Packet Sent to TCP/IP Protocol!!!"));
   428 		OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CIPV6BINDER_PROCESS1_2, "CIPv6Binder: Packet Sent to TCP/IP Protocol!!!");
   431 		iUpperReceiver->Process(static_cast<RMBufChain&>(aPdu));
   429 		iUpperReceiver->Process(static_cast<RMBufChain&>(aPdu));
   432 		}
   430 		}
   433 	else 
   431 	else 
   434 		{
   432 		{
   435 		_LOG_L2C1(_L8("WARNING: dumping incoming packet, no protocol bound"));
   433 		OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CIPV6BINDER_PROCESS1_3, "WARNING: dumping incoming packet, no protocol bound");
   436 		aPdu.Free();
   434 		aPdu.Free();
   437 		}
   435 		}
   438 
   436 
   439 	}
   437 	}
   440 
   438 
   509 * Logs packet information into log file.
   507 * Logs packet information into log file.
   510 *
   508 *
   511 * @param aPacket The packet 
   509 * @param aPacket The packet 
   512 */
   510 */
   513 	{
   511 	{
   514 	_LOG_L1C1(_L8("CIPv6Binder::LogPacket"));
   512 	OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CIPV6BINDER_LOGPACKET_1, "CIPv6Binder::LogPacket");
   515 
   513 
   516 	TInt mBufLength = aPacket.Length() - aPacket.First()->Length();
   514 	TInt mBufLength = aPacket.Length() - aPacket.First()->Length();
   517 
   515 
   518 	_LOG_L3C2(_L8("Analysis of %d byte packet:"), mBufLength);
   516 	OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CIPV6BINDER_LOGPACKET_2, "Analysis of %d byte packet:", mBufLength);
   519 
   517 
   520 	//Note: All the constants used on this method are a pragmatic guess of the
   518 	//Note: All the constants used on this method are a pragmatic guess of the
   521 	//IP header fields. The only porpose of this method is logging.
   519 	//IP header fields. The only porpose of this method is logging.
   522 
   520 
   523 	if (mBufLength < 40)
   521 	if (mBufLength < 40)
   524 		{
   522 		{
   525 		_LOG_L3C2(_L8(" -doesn't appear to be a valid IPv6 packet (length=%d)")
   523 		OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CIPV6BINDER_LOGPACKET_3, " -doesn't appear to be a valid IPv6 packet (length=%d)", mBufLength);
   526 			, mBufLength);
       
   527 		return;
   524 		return;
   528 		}
   525 		}
   529 
   526 
   530 	// Get a pointer to the packet's payload.
   527 	// Get a pointer to the packet's payload.
   531 	const TUint8* payloadPtr = aPacket.First()->Next()->Ptr();
   528 	const TUint8* payloadPtr = aPacket.First()->Next()->Ptr();
   532 
   529 
   533 	if ((payloadPtr[0] & 0xF0) != 0x60)
   530 	if ((payloadPtr[0] & 0xF0) != 0x60)
   534 		{
   531 		{
   535 		_LOG_L3C2(_L8(" - doesn't appear to be an IPv6 packet (version=0x%X)"),
   532 		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);
   536 			(payloadPtr[0] & 0xF0) >> 4);
       
   537 		return;
   533 		return;
   538 		}
   534 		}
   539 
   535 
   540 	_LOG_L3C2(_L8(" - traffic class: 0x%X"), 
   536 	OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CIPV6BINDER_LOGPACKET_5, " - traffic class: 0x%X", ((payloadPtr[0] & 0xF) << 4) | ((payloadPtr[1] & 0xF0) >> 4));
   541 					((payloadPtr[0] & 0xF) << 4) | ((payloadPtr[1] & 0xF0) >> 4));
   537 	OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CIPV6BINDER_LOGPACKET_6, " - flow label: 0x%X", ((payloadPtr[1] & 0x0F) << 16) | (payloadPtr[2] << 8) | payloadPtr[3]);
   542 	_LOG_L3C2(_L8(" - flow label: 0x%X"), 
   538 	OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CIPV6BINDER_LOGPACKET_7, " - payload length: 0x%X", (payloadPtr[4] << 16) | payloadPtr[5]);
   543 					((payloadPtr[1] & 0x0F) << 16) | (payloadPtr[2] << 8) | payloadPtr[3]);
   539 	OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CIPV6BINDER_LOGPACKET_8, " - next header: 0x%08X", payloadPtr[6]);
   544 	_LOG_L3C2(_L8(" - payload length: 0x%X"), 
   540 	OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CIPV6BINDER_LOGPACKET_9, " - hop limit: 0x%08X", payloadPtr[7]);
   545 					(payloadPtr[4] << 16) | payloadPtr[5]);
       
   546 	_LOG_L3C2(_L8(" - next header: 0x%08X"), payloadPtr[6]);
       
   547 	_LOG_L3C2(_L8(" - hop limit: 0x%08X"), payloadPtr[7]);
       
   548 	}
   541 	}
   549 #endif // __BTT_LOGGING__
   542 #endif // __BTT_LOGGING__