telephonyprotocols/rawipnif/version1/src/RawIPNifMain.cpp
changeset 68 d0d9cc530d21
parent 62 8ef833fbf5aa
child 75 f45cd1ad4667
equal deleted inserted replaced
62:8ef833fbf5aa 68:d0d9cc530d21
     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 // Implements the CRawIPNifMain class, which provides a central point for the NIF
       
    15 // to communicate with NifMan and the BCA controllers. This class creates an interface
       
    16 // to the IPv4 protocol when it is required.
       
    17 // 
       
    18 //
       
    19 
       
    20 /**
       
    21  @file
       
    22 */
       
    23 
       
    24 #include <f32file.h>
       
    25 #include <nifman.h>
       
    26 #include <nifmbuf.h>
       
    27 #include <in_iface.h>
       
    28 #include <nifvar.h>
       
    29 #include "IPv4ProtocolIf.h"
       
    30 #include "IPv6ProtocolIf.h"
       
    31 #include "RawIPNifMain.h"
       
    32 
       
    33 #ifdef __FLOG_ACTIVE
       
    34 //These variables are used only if flog is active.
       
    35 _LIT8(KTcpDumpFirstTag,"TcpDump");
       
    36 static const TUint16 KTcpDumpLinkType = 12;
       
    37 #endif
       
    38 
       
    39 CRawIPNifMain::CRawIPNifMain(CNifIfFactory& aFactory, MNifIfNotify* aNotify, CBttLogger* aTheLogger)
       
    40 /**
       
    41  * Constructor.
       
    42  *
       
    43  * @param aFactory Reference to the factory which created this object.
       
    44  * @param aTheLogger The logging object, ownership is passed to this object
       
    45  */
       
    46 	: CNifIfLink(aFactory), 
       
    47 	  iTheLogger(aTheLogger),
       
    48 	  iInitError(KErrNone), 
       
    49 	  iState(EIfDown)
       
    50 	{
       
    51 	// To aid debugging.
       
    52 	iNotify = aNotify;
       
    53 	}
       
    54 
       
    55 void CRawIPNifMain::Info(TNifIfInfo& aInfo) const
       
    56 /**
       
    57  * Provides information about the NIF.
       
    58  *
       
    59  * @param aInfo Information structure to be filled in
       
    60  */
       
    61 	{
       
    62 	_LOG_L1C1(_L8("CRawIPNifMain::Info"));
       
    63 
       
    64 	aInfo.iVersion = TVersion(KNifMajorVersionNumber, KNifMinorVersionNumber,
       
    65 		KNifBuildVersionNumber);
       
    66 	aInfo.iFlags = KNifIfIsBase | 
       
    67 				   KNifIfUsesNotify | 
       
    68 				   KNifIfIsLink |
       
    69 	               KNifIfCreatedByFactory |
       
    70 				   KNifIfCreatesBinder;
       
    71 	aInfo.iName = KRawIPNifName;
       
    72 	aInfo.iProtocolSupported = KProtocolUnknown;
       
    73 	}
       
    74 
       
    75 void CRawIPNifMain::ConstructL(const TDesC& /*aName*/)
       
    76 /**
       
    77  * Second-phase constructor. Creates the Etel
       
    78  * control engine
       
    79  *
       
    80  * @param aName The name of the NIF (unused)
       
    81  */
       
    82 	{
       
    83 	_LOG_L1C1(_L8("CRawIPNifMain::ConstructL"));
       
    84 
       
    85 	iBcaController = CBcaIoController::NewL(*this, iTheLogger);
       
    86 	}
       
    87 
       
    88 CRawIPNifMain::~CRawIPNifMain()
       
    89 /**
       
    90  * Destructor. Cancels and deletes all owned active objects.
       
    91  */
       
    92 	{
       
    93 	// Note that we don't delete iProtocolIf because it's not owned by us.
       
    94 	delete iBcaController;
       
    95 	// This class also deletes the logging object
       
    96 	delete iTheLogger;
       
    97 	// Cleanup when stop was not called - harmless as it null's the pointer
       
    98 	__PACKETLOG_DELETE;
       
    99 	}
       
   100 
       
   101 TInt CRawIPNifMain::Control(TUint /*aLevel*/, TUint /*aName*/,
       
   102                              TDes8& /*aOption*/, TAny* /*aSource*/)
       
   103 /**
       
   104  * Method to set up NIF parameters. This is unused; instead, the Control()
       
   105  * method on the IPv4 interface will be called to configure the NIF.
       
   106  *
       
   107  * @param aLevel The network level of the parameter to be set (unused)
       
   108  * @param aName The name of the parameter to be set (unused)
       
   109  * @param aOption The parameter to be written to (unused)
       
   110  * @param aSource The source of the method call (unused)
       
   111  * @return Always KErrNotSupported
       
   112  */
       
   113 	{
       
   114 	_LOG_L1C1(_L8("CRawIPNifMain::Control"));
       
   115 
       
   116 	return KErrNotSupported;
       
   117 	}
       
   118 
       
   119 TInt CRawIPNifMain::State()
       
   120 /**
       
   121  * Returns the current state of the NIF. This will be one of EIfUp or EIfDown.
       
   122  *
       
   123  * @return The state of the NIF
       
   124  */
       
   125 	{
       
   126 	_LOG_L1C1(_L8("CRawIPNifMain::State"));
       
   127 
       
   128 	return iState;
       
   129 	}
       
   130 
       
   131 TInt CRawIPNifMain::Start()
       
   132 /**
       
   133  * Starts the NIF up. This process involves connecting to the BCA.  When startup is
       
   134  * complete, LinkLayerUp() will be called.
       
   135  *
       
   136  * @return Allways KErrNone
       
   137  */
       
   138 	{
       
   139 	_LOG_L1C1(_L8("CRawIPNifMain::Start"));
       
   140 
       
   141 	TRAPD(err1,InitialiseL(MControllerObserver::EStart, KErrNone));
       
   142 	if (err1)
       
   143 		{
       
   144 		return err1;
       
   145 		}
       
   146 	
       
   147 	
       
   148 	//the name calculation should be done only if logging is enabled
       
   149 #ifdef __FLOG_ACTIVE
       
   150 	const TUint KModemNameLen = KCommsDbSvrMaxColumnNameLength + 10;  // need enough for ppp-XXX.txt - e.g. ppp-comm-1.txt, ppp-btcomm-10.txt etc
       
   151 	TBuf8<KModemNameLen> modemName;
       
   152 	
       
   153 	//first add modem name
       
   154 	_LIT(KModemPortName, "ModemBearer\\PortName");
       
   155 	_LIT8(KStupidCharacters, "::");
       
   156 	iNotify->ReadDes(KModemPortName, modemName);
       
   157 	const TInt pos = modemName.FindC((const TDesC8&)KStupidCharacters);
       
   158 	if(pos != KErrNotFound)
       
   159 		{
       
   160 		modemName.Delete(pos, 2);
       
   161 		}
       
   162 		
       
   163 	//append time stamp
       
   164 	const TUint KTimeStampLen = 8;
       
   165 	TBuf8<KTimeStampLen> logFileName;
       
   166 	
       
   167 	_LIT8(KTimeFormat, "%08X");
       
   168 	TUint32 counter = User::FastCounter();
       
   169 	logFileName.Format(KTimeFormat, counter);
       
   170 		
       
   171 	TRAPD(err,__PACKETLOG_NEWL(KTcpDumpFirstTag, logFileName, CPacketLogger::ETcpDump, KTcpDumpLinkType));
       
   172 	if (err)
       
   173 		{
       
   174 		_LOG_L1C1(_L8("Trapped leave from __PACKETLOG_NEWL"));
       
   175 		}
       
   176 	
       
   177 	const TUint KLogTextLen = KModemNameLen+KTimeStampLen+30;
       
   178 	TBuf8<KLogTextLen> logText;
       
   179 	_LIT8(KLogTimeText, "TcpDump log file time stamp:");
       
   180 	_LIT8(KLogModemText, " for modem:");
       
   181 	logText.Append(KLogTimeText);
       
   182 	logText.Append(logFileName);
       
   183 	logText.Append(KLogModemText);
       
   184 	logText.Append(modemName);
       
   185 	_LOG_L1C1(logText);
       
   186 #endif
       
   187 
       
   188 	return KErrNone;
       
   189 	}
       
   190 
       
   191 
       
   192 void CRawIPNifMain::LinkLayerUp()
       
   193 /**
       
   194  * This function is called when initialisation is complete and the NIF is
       
   195  * ready to send/receive data. It notifies NifMan and the IP interface that it's
       
   196  * ready to go.
       
   197  */
       
   198 	{
       
   199 	_LOG_L1C1(_L8("CRawIPNifMain::LinkLayerUp"));
       
   200 
       
   201 	iState = EIfUp;
       
   202 	iNotify->LinkLayerUp();
       
   203 
       
   204 	iNotify->IfProgress(KLinkLayerOpen, KErrNone);
       
   205 
       
   206 	iProtocolIf->StartSending(reinterpret_cast<CProtocolBase*>(this));
       
   207 	}
       
   208 
       
   209 void CRawIPNifMain::LinkLayerDown(TInt aError)
       
   210 /**
       
   211  * This function is called when the context has been deactivated and the NIF
       
   212  * is ready to be deleted, or if there is an error on startup. Its job is to
       
   213  * notify NifMan that the link has gone down, so it can delete the NIF.
       
   214  *
       
   215  * @param aError An error code to propagate to NifMan
       
   216  */
       
   217 	{
       
   218 	_LOG_L1C2(_L8("CRawIPNifMain::LinkLayerDown [aError=%d]"), aError);
       
   219 
       
   220 	iState = EIfDown;
       
   221 
       
   222 	iNotify->IfProgress(KLinkLayerClosed, aError);
       
   223 
       
   224 	iNotify->LinkLayerDown(aError, MNifIfNotify::EDisconnect);
       
   225 	}
       
   226 
       
   227 void CRawIPNifMain::Stop(TInt aError, MNifIfNotify::TAction /*aAction*/)
       
   228 /**
       
   229  * This function is called by NifMan to bring down the link. It starts
       
   230  * the asynchronous context deactivation process; LinkLayerDown() will be
       
   231  * called when the context has been deactivated.
       
   232  *
       
   233  * @param aError A code specifying why the link is to be brought down
       
   234  * @param aAction The action to take: disconnect or reconnect
       
   235  */
       
   236 	{
       
   237 	_LOG_L1C2(_L8("CRawIPNifMain::Stop [aError=%d]"), aError);
       
   238 	__PACKETLOG_DELETE;
       
   239 	ShutDown(MControllerObserver::EInitialised, aError);
       
   240 	}
       
   241 
       
   242 void CRawIPNifMain::Restart(CNifIfBase* /*aIf*/)
       
   243 /**
       
   244  * This is just an empty implementation of the CNifIfLink derived method.
       
   245  * It is used as part of functionality to allow a NIF to specify that
       
   246  * one of its binders has gone down but the link layer has not.
       
   247  *
       
   248  * @param Pointer to the protocol interface object
       
   249  */
       
   250 	{
       
   251 	_LOG_L1C1(_L8("CRawIPNifMain::Restart called"));
       
   252 	}
       
   253 
       
   254 TInt CRawIPNifMain::Send(RMBufChain& /*aPdu*/, TAny* /*aProtocol*/)
       
   255 /**
       
   256  * Unused. The Send() method on the IPv4 protocol interface should be used
       
   257  * to send IPv4 packets.
       
   258  *
       
   259  * @return Always KErrNotSupported
       
   260  */
       
   261 	{
       
   262 	_LOG_L1C1(_L8("CRawIPNifMain::Send"));
       
   263 
       
   264 	// Only the bearers' Send functions should be called.
       
   265 	return KErrNotSupported;
       
   266 	}
       
   267 
       
   268 TInt CRawIPNifMain::SendPacket(RMBufChain& aPdu, TAny* /*aProtocol*/,
       
   269 							   TUint16 /*aType*/)
       
   270 /**
       
   271  * Sends a packet, via the BCA controller. This method is protocol-agnostic,
       
   272  * and is called by the IPv4 protocol interface to actually send packets.
       
   273  *
       
   274  * @param aPdu The packet to send
       
   275  * @return A standard error code
       
   276  */
       
   277 	{
       
   278 	_LOG_L1C2(_L8("CRawIPNifMain::SendPacket [length=%d]"),
       
   279 		aPdu.Length() - aPdu.First()->Length());
       
   280 
       
   281 	__PACKETLOG_WRITE_PACKET(aPdu, 0);
       
   282 	TInt ret = iBcaController->Send(aPdu);
       
   283 	
       
   284 	return ret;
       
   285 	}
       
   286 
       
   287 void CRawIPNifMain::Process(RMBufChain& aPdu, TUint16 aProtocolCode)
       
   288 /**
       
   289  * Handles incoming packets which have been passed up from the BCA controller.
       
   290  * If the IPv4 interface wants to process the packet, it hands it on; otherwise,
       
   291  * the packet is binned.
       
   292  *
       
   293  * @param aPdu The incoming packet
       
   294  */
       
   295 	{
       
   296 	_LOG_L1C2(_L8("CRawIPNifMain::Process [aPdu length=%d]"),
       
   297 		aPdu.Length() - aPdu.First()->Length());
       
   298 
       
   299 	// If the packet has zero or negative length, bin it.
       
   300 	if ((aPdu.Length() - aPdu.First()->Length()) <= 0)
       
   301 		{
       
   302 		_LOG_L1C1(_L8("Dumped packet: illegal length"));
       
   303 		aPdu.Free();
       
   304 		return;
       
   305 		}
       
   306 
       
   307 	// See if the protocol interface wants the packet.
       
   308 	if (iProtocolIf->WantsProtocol(aProtocolCode)) 
       
   309 		{
       
   310 		__PACKETLOG_WRITE_PACKET(aPdu, 0);
       
   311 		iProtocolIf->Process(aPdu);
       
   312 		}
       
   313 	else
       
   314 		{
       
   315 		// The protocol didn't want the packet, so bin it.
       
   316 		_LOG_L1C2(_L8("Packet was not processed: freeing (protocol code: %X)"),
       
   317 			aProtocolCode);
       
   318 		aPdu.Free();
       
   319 		}
       
   320 	}
       
   321 
       
   322 void CRawIPNifMain::ResumeSending()
       
   323 /**
       
   324  * Notifies the protocol interface that it can resume sending packets.
       
   325  */
       
   326 	{
       
   327 	_LOG_L1C1(_L8("CRawIPNifMain::ResumeSending"));
       
   328 
       
   329 	iProtocolIf->StartSending(reinterpret_cast<CProtocolBase*>(this));
       
   330 	}
       
   331 
       
   332 void CRawIPNifMain::AuthenticateComplete(TInt /*aResult*/)
       
   333 /**
       
   334  * Notifies NifMan when authentication is complete. This function is never
       
   335  * actually called.
       
   336  *
       
   337  * @param aResult The result of the authentication (unused)
       
   338  */
       
   339 	{
       
   340 	_LOG_L1C1(_L8("CRawIPNifMain::AuthenticateComplete"));
       
   341 	}
       
   342 
       
   343 TInt CRawIPNifMain::Notification(TAgentToNifEventType aEvent,
       
   344 								  void* aInfo)
       
   345 /**
       
   346  * Provides a mechanism for the notification of events. 
       
   347  *
       
   348  * @param aEvent The event type (unused)
       
   349  * @param aInfo Event information (unused)
       
   350  */
       
   351 	{
       
   352 	_LOG_L1C2(_L8("CRawIPNifMain::Notification [%d]"), aEvent);
       
   353 
       
   354 	
       
   355 	switch (aEvent)
       
   356 	{
       
   357 	case (EAgentToNifEventTypeDisableTimers) : //GPRS suspension
       
   358 		{
       
   359 		_LOG_L1C1(_L8("CRawIPNifMain::Received Suspend from Agent..."));
       
   360 
       
   361 		// Let the BCA controller know that data can no longer be sent over
       
   362 		// the PDP context.
       
   363 		iBcaController->UpdateContextStateFlag(EFalse);
       
   364 
       
   365 		break;
       
   366 		}
       
   367 				
       
   368 	case (EAgentToNifEventTypeEnableTimers) : //GPRS resumption
       
   369 		{
       
   370 		_LOG_L1C1(_L8("CRawIPNifMain::Received Resume from Agent..."));
       
   371 		iBcaController->UpdateContextStateFlag(ETrue);
       
   372 
       
   373 		break;
       
   374 		}
       
   375 			
       
   376 	case (EAgentToNifEventTsyConfig) : 
       
   377 		{
       
   378 		_LOG_L1C1(_L8("CRawIPNifMain::Received context config from Agent..."));
       
   379 		
       
   380 		RPacketContext::TContextConfigGPRS* localPtr = (reinterpret_cast<RPacketContext::TContextConfigGPRS*>(aInfo));
       
   381 
       
   382 		TRAPD(err, GetProtocolIf()->UpdateContextConfigL(*localPtr));
       
   383 
       
   384 		if (err)
       
   385 			{
       
   386 			_LOG_L1C1(_L8("Trapped leave from UpdateContextConfigL"));
       
   387 			}
       
   388 		break;
       
   389 		}
       
   390 			
       
   391 	case (EAgentToNifEventTsyConnectionSpeed) : 
       
   392 		{
       
   393 		TUint connectionSpeed = reinterpret_cast<TUint>(aInfo);
       
   394 		_LOG_L1C2(_L8("CRawIPNifMain::Connection Speed Received [%d]"), connectionSpeed);
       
   395 
       
   396 		GetProtocolIf()->UpdateConnectionSpeed(connectionSpeed);
       
   397 		break;
       
   398 		}
       
   399 			
       
   400 	case (EAgentToNifEventTypeDisableConnection) :
       
   401 		{
       
   402 		// This is handled by NIFMAN and passed to NifMain as a Stop() call
       
   403 		_LOG_L1C1(_L8("CRawIPNifMain::Received Disable connection from Agent..."));
       
   404 		break;
       
   405 		}
       
   406 			
       
   407 	case (EAgentToNifEventTypeGetDataTransfer) :
       
   408 		{
       
   409 		_LOG_L1C1(_L8("CRawIPNifMain::Received Get Data Transfer from Agent..."));
       
   410 		break;
       
   411 		}
       
   412 			
       
   413 	default : 
       
   414 		{
       
   415 		_LOG_L1C2(_L8("CRawIPNifMain::Received Notification [%d] from Agent..."), aEvent);
       
   416 		break;
       
   417 		}
       
   418 	}
       
   419 
       
   420 	return KErrNone;
       
   421 	}
       
   422 
       
   423 void CRawIPNifMain::BindL(TAny *aId)
       
   424 /**
       
   425  * Called by NifMan to bind the NIF to a specific protocol. This is never
       
   426  * actually called; instead, the BindL() function of the IPv4 interface is used.
       
   427  *
       
   428  * @param aId A pointer to the protocol to be bound to
       
   429  * @leave KErrAlreadyExists when already bound
       
   430  */
       
   431 	{
       
   432 	_LOG_L1C2(_L8("CRawIPNifMain::BindL [aId=%X]"), aId);
       
   433 	
       
   434 	if (iProtocol)
       
   435 		{
       
   436 		User::Leave(KErrAlreadyExists);
       
   437 		}
       
   438 	iProtocol = reinterpret_cast<CProtocolBase*>(aId);
       
   439 	}
       
   440 
       
   441 CNifIfBase* CRawIPNifMain::GetBinderL(const TDesC& aName)
       
   442 /**
       
   443  * Creates a new protocol interface, for supported protocols. This is currently
       
   444  * only IPv4 and ICMP, both of which use the IPv4 protocol interface class.
       
   445  *
       
   446  * @param aName The name of the protocol
       
   447  * @return A newly created protocol interface object
       
   448  * @leave KErrNotSupported if protocol is not supported
       
   449  */
       
   450 	{
       
   451 #ifdef __BTT_LOGGING__
       
   452 	TBuf8<256> debugBuffer;
       
   453 	debugBuffer.Copy(aName);
       
   454 	_LOG_L1C2(_L8("CRawIPNifMain::GetBinderL [aName=%S]"), &debugBuffer);
       
   455 #endif
       
   456 
       
   457 	// IPv4 and ICMP Protocols.
       
   458 	if (!aName.CompareF(KDescIp) || !aName.CompareF(KDescIcmp))
       
   459 		{
       
   460 		if (!iProtocolIf)
       
   461 			{
       
   462 			iProtocolIf = new (ELeave) CIPv4ProtocolIf(*this, iTheLogger);
       
   463 #ifdef RAWIP_HEADER_APPENDED_TO_PACKETS			
       
   464 			iBcaController->SetType(KIp4FrameType);
       
   465 #endif // RAWIP_HEADER_APPENDED_TO_PACKETS
       
   466 			}
       
   467 		}
       
   468 	// IPv6 Protocol
       
   469 	else if (!aName.CompareF(KDescIp6))
       
   470 		{
       
   471 		if (!iProtocolIf)
       
   472 			{
       
   473 			iProtocolIf = new (ELeave) CIPv6ProtocolIf(*this, iTheLogger);
       
   474 #ifdef RAWIP_HEADER_APPENDED_TO_PACKETS			
       
   475 			iBcaController->SetType(KIp6FrameType);
       
   476 #endif // RAWIP_HEADER_APPENDED_TO_PACKETS
       
   477 			}
       
   478 		}		
       
   479 	else
       
   480 		{
       
   481 		User::Leave(KErrNotSupported);
       
   482 		}
       
   483 
       
   484     return iProtocolIf;
       
   485 	}
       
   486 
       
   487 void CRawIPNifMain::InitialiseL(TInitialisationState aState, TInt aError)
       
   488 /**
       
   489  * This method controls the initialisation sequence of the different modules
       
   490  * in the NIF. When a module completes all the initialisation tasks it will 
       
   491  * call again this method with the new state. If an error occurs then the 
       
   492  * ShutDown() method will be called.
       
   493  *  
       
   494  * @param aState The current initialisation step
       
   495  * @param aError A possible error
       
   496  */	
       
   497 	{
       
   498 	_LOG_L1C3(_L8("CRawIPNifMain::InitialiseL [aState=%d ,aError=%d]"),
       
   499 		aState, aError);
       
   500 
       
   501 	if (aError != KErrNone)
       
   502 		{
       
   503 		_LOG_L2C2(_L8("  *** FAILED to initialise NIF *** Error =%d"),aError);
       
   504 	
       
   505 		// Initialise shutdown sequence
       
   506 		switch (aState)
       
   507 		{
       
   508 		case MControllerObserver::EBcaController:
       
   509 			ShutDown(MControllerObserver::EInitialised, aError);
       
   510 			break;
       
   511 		default:
       
   512 			_LOG_L2C3(_L8("ERROR CRawIPNifMain: Unknown state:%d in NIF: %S"), aState, &KNifName);
       
   513 			User::Leave(KErrUnknown);	
       
   514 			break;
       
   515 			}
       
   516 		return;
       
   517 		}
       
   518 	
       
   519 	switch (aState)
       
   520 		{
       
   521 	case MControllerObserver::EStart:
       
   522 		{
       
   523 		_LOG_L1C1(_L8("Calling Agent for TSY Config"));
       
   524 
       
   525 		GetAgent()->Notification(ENifToAgentEventTsyConfig, NULL);
       
   526 
       
   527 		_LOG_L1C1(_L8("Calling Agent for TSY Connection Speed"));
       
   528 		GetAgent()->Notification(ENifToAgentEventTsyConnectionSpeed, NULL);
       
   529 
       
   530 		//Read the port name from CommDB.
       
   531 		_LOG_L1C1(_L8("Attempting to read Port Name..."));
       
   532 		TBuf<2*KCommsDbSvrMaxColumnNameLength> columnName;
       
   533 		_LIT(KModemNameFormatText,"%s\\%s");
       
   534 		columnName.Format(KModemNameFormatText ,MODEM_BEARER,MODEM_PORT_NAME);
       
   535 		TName tempBuf;
       
   536 		GetAgent()->ReadDes(columnName,tempBuf);
       
   537 
       
   538 		_LOG_L1C2(_L8("Port details %S"),&tempBuf);
       
   539 		iBcaController->SetPort(tempBuf);
       
   540 
       
   541 		//Read the BCA name from CommDB.
       
   542 		columnName.Format(KModemNameFormatText ,MODEM_BEARER,BCA_STACK);
       
   543         tempBuf.SetLength(0); // Clear the buffer in case the next ReadDes() fails
       
   544 		GetAgent()->ReadDes(columnName,tempBuf);
       
   545 		
       
   546 		_LOG_L1C2(_L8("bcaName details %S"),&tempBuf);
       
   547 		iBcaController->SetBcaStackAndName(tempBuf);
       
   548 
       
   549 		//Read IAPID from CommDB.
       
   550 		//IAP ID is used in BCA Ioctl method to set IapId for accessing CommDB.
       
   551 		TUint32 iapId(0);
       
   552 		columnName.Format(KModemNameFormatText ,IAP,COMMDB_ID);
       
   553 		GetAgent()->ReadInt(columnName,iapId);
       
   554 		_LOG_L1C2(_L8("IAP ID details %u"),iapId);
       
   555 		iBcaController->SetIapId(iapId);
       
   556 		
       
   557 		UpdateContextState(RPacketContext::EStatusActive, KErrNone);
       
   558 
       
   559 		iBcaController->StartL();
       
   560 		}
       
   561 		break;
       
   562 	case MControllerObserver::EBcaController:
       
   563 		_LOG_L1C1(_L8("  ***** NIF INITIALISED *****"));
       
   564 		LinkLayerUp();
       
   565 		break;
       
   566 	default:
       
   567 		_LOG_L2C3(_L8("ERROR CRawIPNifMain: Unknown state:%d in NIF: %S"), aState, &KNifName);
       
   568 		User::Leave(KErrUnknown);	
       
   569 		break;
       
   570 		}
       
   571 	}
       
   572 
       
   573 void CRawIPNifMain::ShutDown(TInitialisationState aState, TInt aError)
       
   574 /**
       
   575  * This method controls the shutdown sequence of the different modules
       
   576  * in the NIF. When a module completes all the shutdown tasks it will 
       
   577  * call again this method with the new state. 
       
   578  * 
       
   579  * @param aState The current state
       
   580  * @param aError A possible error (only during initialisation)
       
   581  */	
       
   582 	{
       
   583 	_LOG_L1C3(_L8("CRawIPNifMain::ShutDown [aState=%d ,aError=%d]"),
       
   584 		aState, aError);
       
   585 
       
   586 	if (aError != KErrNone)
       
   587 		{
       
   588 		// NIF is shutting down due to an error. 
       
   589 		// The error code must be stored in order to call linklayer down 
       
   590 		// passing that value
       
   591 		iInitError = aError;
       
   592 		}
       
   593 
       
   594 	switch (aState)
       
   595 		{
       
   596 	case MControllerObserver::EInitialised:
       
   597 		iBcaController->Stop(aError);
       
   598 		break;
       
   599 	case MControllerObserver::EBcaController:
       
   600 		LinkLayerDown(iInitError);
       
   601 		break;
       
   602 	default:
       
   603 		_LOG_L2C1(_L8("ERROR CRawIPNifMain: Unknown Shutdown step"));
       
   604 		_BTT_PANIC(KNifName,KNifUnknownShutDownState);
       
   605 		break;
       
   606 		}
       
   607 	}
       
   608 
       
   609 MNifIfNotify* CRawIPNifMain::GetAgent()
       
   610 /**
       
   611  * Returns a pointer to the MNifIfNotify class used to comunicate with the Agent 
       
   612  * 
       
   613  * @return a pointer to MNifIfNotify
       
   614  */
       
   615 	{
       
   616 	return iNotify;
       
   617 	}
       
   618 	
       
   619 CProtocolIfBase* CRawIPNifMain::GetProtocolIf()
       
   620 /**
       
   621  * Returns a pointer to the CIPv4ProtocolIf class
       
   622  * 
       
   623  * @return a pointer to a CProtocolIfBase derived class
       
   624  */
       
   625 	{
       
   626 	return iProtocolIf; 
       
   627 	}
       
   628 
       
   629 CBcaIoController* CRawIPNifMain::GetBcaController()
       
   630 /**
       
   631  * Returns a pointer to the CBcaIoController class
       
   632  * 
       
   633  * @return a pointer to CBcaIoController 
       
   634  */
       
   635 	{
       
   636 	return iBcaController;
       
   637 	}
       
   638 
       
   639 void CRawIPNifMain::UpdateContextState(
       
   640 	RPacketContext::TContextStatus aState, TInt /*aError*/)
       
   641 /**
       
   642  * Updates the state of the iContextState variable 
       
   643  * 
       
   644  * @param aState The new state
       
   645  * @param aError A possible error
       
   646  */
       
   647 	{
       
   648 	_LOG_L1C2(_L8("CRawIPNifMain::UpdateContextState [State=%d]"), aState);
       
   649 
       
   650 	// Note that we do not need to close the NIF down if there's been an
       
   651 	// error, as the context state machine will do this for us.
       
   652 	
       
   653 	iContextStatus = aState;
       
   654 	}
       
   655 
       
   656 void CRawIPNifMain::UpdateContextConfig(
       
   657 	RPacketContext::TContextConfigGPRS aConfig)
       
   658 /**
       
   659  * Updates the state of the iContextConfig variable 
       
   660  * 
       
   661  * @param aConfig The new config
       
   662  */
       
   663 	{
       
   664 	_LOG_L1C1(_L8("CRawIPNifMain::UpdateContextConfig"));
       
   665 
       
   666 	// Note that we do not need to close the NIF down if there's been an
       
   667 	// error, as the context state machine will do this for us.
       
   668 	
       
   669 	iContextConfig = aConfig;
       
   670 	}