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