telephonyprotocols/rawipnif/version1/src/IPv6ProtocolIf.cpp
changeset 0 3553901f7fa8
child 24 6638e7f4bd8f
equal deleted inserted replaced
-1:000000000000 0:3553901f7fa8
       
     1 // Copyright (c) 2002-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 CIPv6ProtocolIf 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 <e32hal.h>	// UserHal::MachineInfo()
       
    24 #include <etelpckt.h>
       
    25 #include <in_iface.h>
       
    26 #include <in6_if.h>
       
    27 #include "RawIPNifMain.h"
       
    28 #include "IPv6ProtocolIf.h"
       
    29 #ifdef WCDMA_STUB
       
    30 #include <UMTSNifControlIf.h>
       
    31 #endif
       
    32 #define LOG_IP_ADDRESS(desc,addr) _LOG_L2C5(_L8("    " desc " = %d:%d:%d:%d from context"), \
       
    33 			addr[3], addr[2], addr[1], addr[0]);
       
    34 
       
    35 CIPv6ProtocolIf::CIPv6ProtocolIf(CRawIPNifMain& aNifMain, CBttLogger* aTheLogger)
       
    36 /**
       
    37  * Constructor
       
    38  */ 
       
    39 	: CProtocolIfBase(aNifMain,aTheLogger),
       
    40 	  iTheLogger(aTheLogger), 
       
    41 	  iSpeedMetric(KDefaultSpeedMetric)
       
    42 	{
       
    43 	}
       
    44 
       
    45 CIPv6ProtocolIf::~CIPv6ProtocolIf()
       
    46 /**
       
    47  *	Destructor
       
    48  */
       
    49 	{
       
    50 	}
       
    51 
       
    52 void CIPv6ProtocolIf::BindL(TAny* aId)
       
    53 /**
       
    54  *	Binds protocol to the Nif
       
    55  *
       
    56  *	@param aId A point the the protocol(TCP/IP)
       
    57  */
       
    58 	{
       
    59 	_LOG_L1C2(_L8("CIPv6ProtocolIf::BindL [aId=%X]"), aId);
       
    60 
       
    61 	CProtocolIfBase::BindL(aId); // Call the superclass's method.
       
    62 	iNotify = iNifMain.Notify();
       
    63 	}
       
    64 
       
    65 TInt CIPv6ProtocolIf::Control(TUint aLevel, TUint aName, TDes8& aOption,
       
    66 							TAny* /*aSource*/)
       
    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  * @param aSource The source of the command (unused)
       
    76  * @return Standard error codes
       
    77  */
       
    78 	{
       
    79 	_LOG_L1C3(_L8("CIPv6ProtocolIf::Control [aLevel=%d, aName=%d]"),
       
    80 		aLevel, aName);
       
    81 
       
    82 	if (aLevel == KSOLInterface)
       
    83 		{
       
    84 		switch (aName)
       
    85 			{
       
    86 		// General IP configuration commands are below this point.
       
    87 
       
    88 		case KSoIfInfo6:
       
    89 			// Gets information about the interface, such as name and MTU.
       
    90 			return WriteIfInfo(aOption);
       
    91 
       
    92 		case KSoIfConfig:
       
    93 			// Gets interface configuration, eg. IP address and DNS servers.
       
    94 			return WriteIfConfig(aOption);
       
    95 
       
    96 		case KSoIfGetConnectionInfo:
       
    97 			// Gets IAP and network information.
       
    98 			return WriteConnectionInfo(aOption);
       
    99 
       
   100 		case KSoIfHardwareAddr:
       
   101 			// unsupported because we don't have a h/w address
       
   102 		case KSoIfCompareAddr:
       
   103 			// this never actually appears to be called
       
   104 			break;
       
   105 
       
   106 		// 3G-specific configuration commands are below this point.
       
   107 #ifdef WCDMA_STUB
       
   108 		case KRegisterEventHandler:
       
   109 			// Raw IP NIF Events are not supported
       
   110 		case KContextSetEvents:
       
   111 			// Raw IP NIF Events are not supported
       
   112 			break;
       
   113 
       
   114 		case KContextCreate:
       
   115 			// We don't support creating new secondary contexts.
       
   116 			break;
       
   117 
       
   118 		case KContextDelete:
       
   119 			// Deletes the primary PDP context. This will shut down the Nif.
       
   120 			return DeleteContext(aOption);
       
   121 
       
   122 		case KContextActivate:
       
   123 			// If the IPv6 interface is up, then the context will already have
       
   124 			// been activated. So this command should fail with 
       
   125 			// KErrAlreadyExists
       
   126 			{
       
   127 			TUint8* ptr = CONST_CAST(TUint8*, aOption.Ptr()); 
       
   128 			TContextParameters* contextParams =
       
   129 				REINTERPRET_CAST(TContextParameters*, ptr);
       
   130 
       
   131 			if (contextParams->iContextInfo.iContextId != 
       
   132 				STATIC_CAST(TInt8, GetNifMain().GetBcaController()->Nsapi()))
       
   133 				{
       
   134 				contextParams->iReasonCode = KErrNotFound;
       
   135 				}
       
   136 			else
       
   137 				{
       
   138 				contextParams->iContextInfo.iStatus =
       
   139 					GetNifMain().GetContextStatus();
       
   140 				contextParams->iReasonCode = KErrAlreadyExists;
       
   141 				}
       
   142 			return KErrNone;
       
   143 			}
       
   144 
       
   145 		case KNifSetDefaultQoS:
       
   146 		case KContextQoSSet:
       
   147 			// Setting the QoS is meaningless over GPRS, so we just return that
       
   148 			// we don't support these operations.
       
   149 			break;
       
   150 
       
   151 		case KContextTFTModify:
       
   152 			// As we only have one primary context, we don't support anything
       
   153 			// to do with traffic flow templates, which are used by secondary
       
   154 			// contexts.
       
   155 			break;
       
   156 
       
   157 		case KContextModifyActive:
       
   158 			// This command is only valid aftermodifying TFT/QoS parameters. 
       
   159 			// As we don't support any of these operations,
       
   160 			// this command is never valid.
       
   161 			break;
       
   162 #endif
       
   163 		default:
       
   164 			break;
       
   165 			}
       
   166 		}
       
   167 	return KErrNotSupported;
       
   168 	}
       
   169 
       
   170 TInt CIPv6ProtocolIf::WriteIfConfig(TDes8& aIfConfig)
       
   171 /**
       
   172  * Writes the configuration of the interface (eg. IP address, DNS servers)
       
   173  * into the supplied descriptor.
       
   174  *
       
   175  * @param aIfConfig Will contain the interface configuration
       
   176  * @return KErrNotSupported if an incorrect structure is passed, 
       
   177  * otherwise KErrNone
       
   178  */
       
   179 	{
       
   180 	_LOG_L1C1(_L8("CIPv6ProtocolIf::WriteIfConfig"));
       
   181 	__ASSERT_DEBUG((TUint)aIfConfig.MaxLength() >= sizeof (TSoInet6IfConfig), User::Panic(KIPv6ProtocolIfName, 0));
       
   182 
       
   183 	if ((TUint)aIfConfig.MaxLength() < sizeof(TSoInet6IfConfig))
       
   184 		{
       
   185 		return KErrArgument;
       
   186 		}
       
   187 
       
   188 	TUint8* ptr = CONST_CAST(TUint8*, aIfConfig.Ptr());
       
   189 	TSoInet6IfConfig* config = REINTERPRET_CAST(TSoInet6IfConfig*, ptr);
       
   190 
       
   191 	TEui64Addr& localId = TEui64Addr::Cast(config->iLocalId);
       
   192 	localId = iSettings.iLocalIfId;
       
   193 
       
   194 	// If required, configure static DNS addresses
       
   195 	if (!iSettings.iPrimaryDns.IsUnspecified())
       
   196 		{
       
   197 		config->iNameSer1.SetAddress(iSettings.iPrimaryDns);
       
   198 		if (!iSettings.iSecondaryDns.IsUnspecified())
       
   199 			config->iNameSer2.SetAddress(iSettings.iSecondaryDns);
       
   200 		}
       
   201 		
       
   202 	config->idPaddingBits = 0;
       
   203 
       
   204 	return KErrNone;
       
   205 	}
       
   206 
       
   207 TInt CIPv6ProtocolIf::WriteIfInfo(TDes8& aIfInfo)
       
   208 /**
       
   209  * Writes information about the interface into the supplied descriptor.
       
   210  *
       
   211  * @param aIfInfo Will contain the interface information
       
   212  * @return KErrArgument if an incorrect structure is passed, otherwise KErrNone
       
   213  */
       
   214 	{
       
   215 	_LOG_L1C1(_L8("CIPv6ProtocolIf::WriteIfInfo"));
       
   216 	__ASSERT_DEBUG((TUint)aIfInfo.MaxLength() >= sizeof (TSoIfInfo6), User::Panic(KIPv6ProtocolIfName, 0));
       
   217 
       
   218 	if ((TUint)aIfInfo.MaxLength() < sizeof(TSoIfInfo6))
       
   219 		{
       
   220 		return KErrArgument;
       
   221 		}
       
   222 
       
   223 	TSoIfInfo6* info = (TSoIfInfo6*) aIfInfo.Ptr();
       
   224 	info->iFeatures = KIfCanBroadcast | KIfCanMulticast;
       
   225 	info->iSpeedMetric = iSpeedMetric;
       
   226 	info->iMtu = KDefaultMtu;
       
   227 	info->iRMtu = KDefaultMtu;
       
   228 	WriteIfName(info->iName);
       
   229 
       
   230 	return KErrNone;
       
   231 	}
       
   232 
       
   233 TInt CIPv6ProtocolIf::WriteConnectionInfo(TDes8& aConnectionInfo)
       
   234 /**
       
   235  * Writes information about the IAP and network we're associated with. This
       
   236  * is used to route data in a multi-homing environment.
       
   237  *
       
   238  * @param aConnectionInfo Will contain the connection information
       
   239  * @return Standard CommDB error codes
       
   240  */
       
   241 	{
       
   242 	_LOG_L1C1(_L8("CIPv6ProtocolIf::WriteConnectionInfo"));
       
   243 
       
   244 	TSoIfConnectionInfo* connectionInfo =
       
   245 		(TSoIfConnectionInfo*) aConnectionInfo.Ptr();
       
   246 
       
   247 	TInt err;
       
   248 	// Append the 2 commdb filed into this descriptor
       
   249 	TBuf<2*KCommsDbSvrMaxColumnNameLength+1> fieldName;
       
   250 
       
   251 	fieldName.Copy(TPtrC(IAP));
       
   252 	fieldName.Append(KSlashChar);
       
   253 	fieldName.Append(TPtrC(COMMDB_ID));
       
   254 	err = GetNifMain().GetAgent()->ReadInt(fieldName, connectionInfo->iIAPId);
       
   255 	if (err != KErrNone)
       
   256 		{
       
   257 		return err;
       
   258 		}
       
   259 
       
   260 	fieldName.Copy(TPtrC(IAP));
       
   261 	fieldName.Append(KSlashChar);
       
   262 	fieldName.Append(TPtrC(IAP_NETWORK));
       
   263 	err = GetNifMain().GetAgent()->ReadInt(fieldName, connectionInfo->iNetworkId);
       
   264 	if (err != KErrNone)
       
   265 		{
       
   266 		return err;
       
   267 		}
       
   268 
       
   269 	return KErrNone;
       
   270 	}
       
   271 #ifdef WCDMA_STUB
       
   272 
       
   273 TInt CIPv6ProtocolIf::DeleteContext(TDes8& aContextParameters)
       
   274 /**
       
   275  * Deletes a context. As the NIF is responsible for one primary context,
       
   276  * this is equivalent to closing down the NIF.
       
   277  *
       
   278  * @param aContextParameters Parameters of the context to delete
       
   279  * @return KErrArgument if an incorrect structure is passed, otherwise KErrNone
       
   280  */
       
   281 	{
       
   282 	_LOG_L1C1(_L8("CIPv6ProtocolIf::DeleteContext"));
       
   283 
       
   284 	if (aContextParameters.Length() != sizeof(TContextParameters))
       
   285 		{
       
   286 		return KErrArgument;
       
   287 		}
       
   288 
       
   289 	TUint8* ptr = CONST_CAST(TUint8*, aContextParameters.Ptr());
       
   290 	TContextParameters* params = REINTERPRET_CAST(TContextParameters*, ptr);
       
   291 
       
   292 	if (params->iContextInfo.iContextId != 
       
   293 		STATIC_CAST(TInt8, GetNifMain().GetBcaController()->Nsapi()))
       
   294 		{
       
   295 		params->iReasonCode = KErrBadName;
       
   296 		}
       
   297 	else
       
   298 		{
       
   299 		params->iReasonCode = KErrNone; 
       
   300 		GetNifMain().Stop(KErrNone, MNifIfNotify::EDisconnect);
       
   301 		}
       
   302 
       
   303 	return KErrNone;
       
   304 	}
       
   305 
       
   306 #endif
       
   307 
       
   308 void CIPv6ProtocolIf::ReadCommDbGprsSettingsL()
       
   309 /**
       
   310  * Reads GPRS IP settings from CommDB via the agent.
       
   311  */
       
   312 	{
       
   313 	_LOG_L1C1(_L8("CIPv6ProtocolIf::ReadCommDbGprsSettings"));
       
   314 	
       
   315 	// Read he DNS addresses..
       
   316 	ReadIPv6SettingL(TPtrC(GPRS_IP6_NAME_SERVER1), iSettings.iPrimaryDns);
       
   317 	ReadIPv6SettingL(TPtrC(GPRS_IP6_NAME_SERVER2), iSettings.iSecondaryDns);	
       
   318 	// Read whether to get the DNS addresses from the server.
       
   319 	_BTT_LEAVEIFERROR(GetNifMain().GetAgent()->ReadBool(
       
   320 		TPtrC(GPRS_IP6_DNS_ADDR_FROM_SERVER),
       
   321 		iSettings.iGetDnsFromServer));
       
   322 	
       
   323 	// Read whether to get IPv4 address from the server
       
   324 	// This is only needed for the integration tests. If it's true then 
       
   325 	// the IPv4 address will be used to build up the IPv6 address. 
       
   326 	_BTT_LEAVEIFERROR(GetNifMain().GetAgent()->ReadBool(
       
   327 		TPtrC(GPRS_IP_ADDR_FROM_SERVER),
       
   328 		iSettings.iGetIpFromServer));
       
   329 		
       
   330 
       
   331 	if (iSettings.iGetIpFromServer == EFalse)
       
   332 		{
       
   333 		// Sets the IPv6 Link-local address from IpAddr.
       
   334 		// LocalId is derived from IpAddr and it's further used to set the Link-local
       
   335 		// address elsewhere by adding a prefix (FE80::) in front.
       
   336 		// For IpAddr: 192.168.1.1, link-local address will be FE80::C0A8:101.
       
   337 		TUint32 ipAddr;	
       
   338 		ReadIPv4SettingL(TPtrC(GPRS_IP_ADDR), ipAddr);
       
   339 		const TUint8 constantId[8] = { 0, 0, 0, 0, 
       
   340 									ipAddr >> 24, (ipAddr >> 16) & 0xFF, 
       
   341 									(ipAddr >> 8) & 0xFF, ipAddr & 0xFF }; 
       
   342 		iSettings.iLocalIfId.SetAddr(constantId, sizeof (constantId));
       
   343 		}
       
   344 	else
       
   345 		{
       
   346 			
       
   347 		//
       
   348 		// Use the 64 bit id of MARM machines as our interface id
       
   349 		//
       
   350 		TMachineInfoV1Buf machineInfo;	
       
   351 		UserHal::MachineInfo(machineInfo);
       
   352 		iSettings.iLocalIfId.SetAddr(machineInfo().iMachineUniqueId);
       
   353 		iSettings.iLocalIfId.SetUniversalBit(0);
       
   354 		//
       
   355 		// In WINS environment the id is zero which is no-no
       
   356 		//
       
   357 		if (iSettings.iLocalIfId.IsZero())
       
   358 			{
       
   359 			iSettings.iLocalIfId.SetAddrRandomNZ();
       
   360 			}		
       
   361 
       
   362 		}
       
   363 	}
       
   364 
       
   365 void CIPv6ProtocolIf::UpdateContextConfigL(const
       
   366 										  RPacketContext::TContextConfigGPRS&
       
   367 										  aConfig)
       
   368 /**
       
   369  * Called when the context has been activated to set our IP address and get
       
   370  * any other required settings from CommDB.
       
   371  *
       
   372  * @param aConfig The new context config
       
   373  */
       
   374 	{
       
   375 	_LOG_L1C1(_L8("CIPv6ProtocolIf::UpdateContextConfig"));
       
   376 
       
   377 	// Get the settings which are stored in CommDB.
       
   378 	ReadCommDbGprsSettingsL();
       
   379 
       
   380 	// Get our IP address from the GPRS context config.
       
   381 	TInetAddr address;
       
   382 	
       
   383 	TBuf<RPacketContext::KMaxPDPAddressLength> tempAddr;
       
   384 	tempAddr.Copy(aConfig.iPdpAddress);
       
   385 	TInt ret = address.Input(tempAddr);
       
   386 
       
   387 	// We've got our IP address! Let's save it.
       
   388 	if (ret == KErrNone)
       
   389 		{
       
   390 		iSettings.iLocalAddr = address.Ip6Address();
       
   391 		LOG_IP_ADDRESS("Got local IP address", iSettings.iLocalAddr);
       
   392 		}
       
   393 	else
       
   394 		{
       
   395 		_LOG_L2C2(_L8("Couldn't get IP address from GPRS config (err: %d)"),
       
   396 			ret);
       
   397 
       
   398 		// Don't leave on this error: we may still be OK if we read some
       
   399 		// settings from CommDB.
       
   400 		}
       
   401 
       
   402 	// @todo - is this correct. We can only get the DNS addresses
       
   403 	// from the TSY using the iProtocolConfigOption data. Yet a client could
       
   404 	// access those DNS config details without knowing about the state of the
       
   405 	// iSettings.iGetDnsFromServer flag.
       
   406 
       
   407 	if ((iSettings.iGetDnsFromServer) ||
       
   408 		((iSettings.iPrimaryDns.IsUnspecified()) &&
       
   409 		 (iSettings.iSecondaryDns.IsUnspecified())) ) 
       
   410 		{
       
   411 		TBuf<RPacketContext::KMaxPDPAddressLength> tempAddr;
       
   412 		tempAddr.Copy(aConfig.iProtocolConfigOption.iDnsAddresses.iPrimaryDns);
       
   413 		ret = address.Input(tempAddr);
       
   414 
       
   415 		if (ret == KErrNone)
       
   416 			{
       
   417 			iSettings.iPrimaryDns = address.Ip6Address();
       
   418 			LOG_IP_ADDRESS("Got primary DNS", iSettings.iPrimaryDns);
       
   419 			}
       
   420 		else
       
   421 			{
       
   422 			_LOG_L2C2(_L8("Couldn't get primary DNS address from GPRS config (err: %d)"),
       
   423 				ret);
       
   424 
       
   425 			// Don't leave on this error: we may still be OK if we read some
       
   426 			// settings from CommDB.
       
   427 			}
       
   428 
       
   429 		tempAddr.Copy(aConfig.iProtocolConfigOption.iDnsAddresses.iSecondaryDns);
       
   430 		ret = address.Input(tempAddr);
       
   431 
       
   432 		if (ret == KErrNone)
       
   433 			{
       
   434 			iSettings.iSecondaryDns = address.Ip6Address();
       
   435 			LOG_IP_ADDRESS("Got secondary DNS", iSettings.iPrimaryDns);
       
   436 			}
       
   437 		else
       
   438 			{
       
   439 			_LOG_L2C2(_L8("Couldn't get secondary DNS address from GPRS config (err: %d)"),
       
   440 				ret);
       
   441 
       
   442 			// Don't leave on this error: we may still be OK if we read some
       
   443 			// settings from CommDB.
       
   444 			}
       
   445 		}
       
   446 	else
       
   447 		{
       
   448 		LOG_IP_ADDRESS("Using CommDB DNS address - Primary ", iSettings.iPrimaryDns);
       
   449 		LOG_IP_ADDRESS("                         - Secondary ", iSettings.iSecondaryDns);
       
   450 		}
       
   451 	}
       
   452 
       
   453 void CIPv6ProtocolIf::UpdateConnectionSpeed(TUint aConnectionSpeed)
       
   454 /**
       
   455  * Sets the speed metric to return to TCP/IP, based on what the TSY tells us.
       
   456  *
       
   457  * @param aConnectionSpeed Our connection speed
       
   458  */
       
   459 	{
       
   460 	_LOG_L1C1(_L8("CIPv6ProtocolIf::UpdateConnectionSpeed"));
       
   461 
       
   462 	iSpeedMetric = aConnectionSpeed;
       
   463 	}
       
   464 
       
   465 void CIPv6ProtocolIf::ReadIPv4SettingL(const TDesC& aFieldName,
       
   466 									   TUint32& aIpAddr)
       
   467 /**
       
   468  * Reads an IPv4 address from CommDB, via the TRP agent. It leaves if an error
       
   469  * other than KErrNotFound occurs.
       
   470  *
       
   471  * @param aFieldName The name of the field to read
       
   472  * @param aIpAddr Will contain the IP address
       
   473  */
       
   474 	{
       
   475 #ifdef __BTT_LOGGING__
       
   476 	TBuf8<256> debugBuffer;
       
   477 	debugBuffer.Copy(aFieldName);
       
   478 	_LOG_L1C2(_L8("CIPv6ProtocolIf::ReadIp4Setting [aFieldName=%S]"),
       
   479 		&debugBuffer);
       
   480 #endif
       
   481 
       
   482 	TBuf<KCommsDbSvrMaxFieldLength> name;
       
   483 	TInetAddr ip4Addr;
       
   484 
       
   485 	TInt ret = GetNifMain().GetAgent()->ReadDes(aFieldName, name);
       
   486 
       
   487 	if (ret == KErrNone)
       
   488 		{
       
   489 		// We've successfully read an IP address, so convert it into a number.
       
   490 		ip4Addr.Input(name);
       
   491 		aIpAddr = ip4Addr.Address();
       
   492 		}
       
   493 	else
       
   494 		{
       
   495 		// We couldn't get the IP address, so set it to 0.0.0.0. Note that we
       
   496 		// only leave here if we got a more serious error than "not found".
       
   497 		aIpAddr = 0;
       
   498 		if (ret != KErrNotFound)
       
   499 			{
       
   500 			_BTT_LEAVEIFERROR(ret);
       
   501 			}
       
   502 		}
       
   503 	}
       
   504 
       
   505 void CIPv6ProtocolIf::ReadIPv6SettingL(const TDesC& aFieldName,
       
   506 									   TIp6Addr& aIpAddr)
       
   507 /**
       
   508  * Reads an IPv6 address from CommDB, via the TRP agent. It leaves if an error
       
   509  * other than KErrNotFound occurs.
       
   510  *
       
   511  * @param aFieldName The name of the field to read
       
   512  * @param aIpAddr Will contain the IP address
       
   513  */
       
   514 	{
       
   515 #ifdef __BTT_LOGGING__
       
   516 	TBuf8<256> debugBuffer;
       
   517 	debugBuffer.Copy(aFieldName);
       
   518 	_LOG_L1C2(_L8("CIPv6ProtocolIf::ReadIp6Setting [aFieldName=%S]"),
       
   519 		&debugBuffer);
       
   520 #endif
       
   521 
       
   522 	TBuf<KCommsDbSvrMaxFieldLength> name;
       
   523 	TInetAddr ip6Addr;
       
   524 
       
   525 	TInt ret = GetNifMain().GetAgent()->ReadDes(aFieldName, name);
       
   526 
       
   527 	if (ret == KErrNone)
       
   528 		{
       
   529 		// We've successfully read an IP address, so convert it into a number.
       
   530 		ip6Addr.Input(name);
       
   531 		aIpAddr = ip6Addr.Ip6Address();
       
   532 		}
       
   533 	else
       
   534 		{
       
   535 		// We couldn't get the IP address, so set it to 0.0.0.0. Note that we
       
   536 		// only leave here if we got a more serious error than "not found".
       
   537 		aIpAddr = KInet6AddrNone;
       
   538 		if (ret != KErrNotFound)
       
   539 			{
       
   540 			_BTT_LEAVEIFERROR(ret);
       
   541 			}
       
   542 		}
       
   543 	}
       
   544 
       
   545 TInt CIPv6ProtocolIf::Send(RMBufChain& aPdu, TAny* aSource)
       
   546 /**
       
   547  * Called by the protocol to send an outgoing IP packet to the network.
       
   548  *
       
   549  * @param aPdu The outgoing packet
       
   550  * @param aSource The source of the packet
       
   551  * @return Standard error codes
       
   552  */
       
   553 	{
       
   554 	_LOG_L1C1(_L8("CIPv6ProtocolIf::Send"));
       
   555 
       
   556 #ifdef __BTT_LOGGING__
       
   557 	LogPacket(aPdu);
       
   558 #endif
       
   559 
       
   560 	// Return <0: an error occurred
       
   561 	// Return  0: no error, but don't send any more packets
       
   562 
       
   563 	return GetNifMain().SendPacket(aPdu, aSource, KIp6FrameType);
       
   564 	}
       
   565 
       
   566 void CIPv6ProtocolIf::Info(TNifIfInfo& aInfo) const
       
   567 /**
       
   568  * Called by the protocol to get information about the NIF.
       
   569  *
       
   570  * @param aInfo Will contain NIF information
       
   571  */
       
   572 	{
       
   573 	_LOG_L1C1(_L8("CIPv6ProtocolIf::Info"));
       
   574 
       
   575 	// The parent class sets everything except the name...
       
   576 	CProtocolIfBase::Info(aInfo);
       
   577 	// ...which we set here.
       
   578 	WriteIfName(aInfo.iName);
       
   579 	}
       
   580 
       
   581 TInt CIPv6ProtocolIf::Notification(TAgentToNifEventType /*aEvent*/, 
       
   582 	void* /*aInfo*/)
       
   583 /**
       
   584  * The Nif will ignore any notification sent
       
   585  *
       
   586  * @param aEvent Not used
       
   587  * @param aInfo Not used 
       
   588  */
       
   589 	{
       
   590 	_LOG_L1C1(_L8("CIPv6ProtocolIf::Notification"));
       
   591 
       
   592 	return KErrNone;
       
   593 	}
       
   594 
       
   595 void CIPv6ProtocolIf::StartSending(CProtocolBase* aProtocol)
       
   596 /**
       
   597  * Indicates to the protocol layer that the NIF is ready to send packets.
       
   598  *
       
   599  * @param aProtocol A pointer to a protocol
       
   600  */
       
   601 	{
       
   602 	_LOG_L1C2(_L8("CIPv6ProtocolIf::StartSending [aProtocol=%X]"), aProtocol);
       
   603 
       
   604 	CProtocolIfBase::StartSending(aProtocol);
       
   605 	}
       
   606 
       
   607 TBool CIPv6ProtocolIf::WantsProtocol(TUint16 aProtocolCode)
       
   608 /**
       
   609  * Indicates the type of protocol implemented by this class.
       
   610  *
       
   611  * @param aProtocolCode The protocol type
       
   612  */
       
   613 	{
       
   614 	_LOG_L1C2(_L8("CIPv6ProtocolIf::WantsProtocol [aProtocolCode=%X]"),
       
   615 		aProtocolCode);
       
   616 
       
   617 #ifdef RAWIP_HEADER_APPENDED_TO_PACKETS
       
   618 	return ((aProtocolCode & 0x00FF) == KIp6FrameType);
       
   619 #else
       
   620 	(void) aProtocolCode; // disable compiler warning
       
   621 	return ETrue;
       
   622 #endif // RAWIP_HEADER_APPENDED_TO_PACKETS
       
   623 	}
       
   624 
       
   625 void CIPv6ProtocolIf::Process(RMBufChain& aPdu)
       
   626 /**
       
   627  * Called when an incoming IP packet has arrived. Send packets up to the
       
   628  * TCP/IP stack.
       
   629  *
       
   630  * @param aPdu The incoming packet
       
   631  */
       
   632 	{
       
   633 	_LOG_L1C1(_L8("CIPv6ProtocolIf::Process"));
       
   634 
       
   635 #ifdef __BTT_LOGGING__
       
   636 	LogPacket(aPdu);
       
   637 #endif
       
   638 
       
   639 	// Pass incoming packets up to the protocol, unless it hasn't
       
   640 	// been bound yet.
       
   641 	if (iProtocol)
       
   642 		{
       
   643 		_LOG_L1C1(_L8("CIPv6ProtocolIf: Packet Sent to TCP/IP Protocol!!!"));
       
   644 		iProtocol->Process(aPdu, reinterpret_cast<CProtocolBase*>(this));
       
   645 		}
       
   646 	else 
       
   647 		{
       
   648 		_LOG_L2C1(_L8("WARNING: dumping incoming packet, no protocol bound"));
       
   649 		aPdu.Free();
       
   650 		}
       
   651 	}
       
   652 
       
   653 #ifdef __BTT_LOGGING__
       
   654 void CIPv6ProtocolIf::LogPacket(const RMBufChain& aPacket)
       
   655 /**
       
   656 * Logs packet information into log file.
       
   657 *
       
   658 * @param aPacket The packet 
       
   659 */
       
   660 	{
       
   661 	_LOG_L1C1(_L8("CIPv6ProtocolIf::LogPacket"));
       
   662 
       
   663 	TInt mBufLength = aPacket.Length() - aPacket.First()->Length();
       
   664 
       
   665 	_LOG_L3C2(_L8("Analysis of %d byte packet:"), mBufLength);
       
   666 
       
   667 	//Note: All the constants used on this method are a pragmatic guess of the
       
   668 	//IP header fields. The only porpose of this method is logging.
       
   669 
       
   670 	if (mBufLength < 40)
       
   671 		{
       
   672 		_LOG_L3C2(_L8(" -doesn't appear to be a valid IPv6 packet (length=%d)")
       
   673 			, mBufLength);
       
   674 		return;
       
   675 		}
       
   676 
       
   677 	// Get a pointer to the packet's payload.
       
   678 	const TUint8* payloadPtr = aPacket.First()->Next()->Ptr();
       
   679 
       
   680 	if ((payloadPtr[0] & 0xF0) != 0x60)
       
   681 		{
       
   682 		_LOG_L3C2(_L8(" - doesn't appear to be an IPv6 packet (version=0x%X)"),
       
   683 			(payloadPtr[0] & 0xF0) >> 4);
       
   684 		return;
       
   685 		}
       
   686 
       
   687 	_LOG_L3C2(_L8(" - traffic class: 0x%X"), 
       
   688 					((payloadPtr[0] & 0xF) << 4) | ((payloadPtr[1] & 0xF0) >> 4));
       
   689 	_LOG_L3C2(_L8(" - flow label: 0x%X"), 
       
   690 					((payloadPtr[1] & 0x0F) << 16) | (payloadPtr[2] << 8) | payloadPtr[3]);
       
   691 	_LOG_L3C2(_L8(" - payload length: 0x%X"), 
       
   692 					(payloadPtr[4] << 16) | payloadPtr[5]);
       
   693 	_LOG_L3C2(_L8(" - next header: 0x%08X"), payloadPtr[6]);
       
   694 	_LOG_L3C2(_L8(" - hop limit: 0x%08X"), payloadPtr[7]);
       
   695 	}
       
   696 #endif // __BTT_LOGGING__