telephonyprotocols/rawipnif/rawipnif2/src/BcaController.cpp
branchRCL_3
changeset 20 07a122eea281
parent 19 630d2f34d719
equal deleted inserted replaced
19:630d2f34d719 20:07a122eea281
     1 // Copyright (c) 2004-2010 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2004-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  @file
    19  @file
    20 */
    20 */
    21 
    21 
    22 
       
    23 #include "OstTraceDefinitions.h"
       
    24 #ifdef OST_TRACE_COMPILER_IN_USE
       
    25 #include "BcaControllerTraces.h"
       
    26 #endif
       
    27 
       
    28 #include <e32uid.h>
    22 #include <e32uid.h>
    29 #include <nifmbuf.h>
    23 #include <nifmbuf.h>
    30 
    24 
    31 #include "Constants.h"
    25 #include "Constants.h"
    32 #include "BcaController.h"
    26 #include "BcaController.h"
    33 
    27 
    34 CBcaController::CBcaController(CRawIP2Flow& aRawIPFlow)
    28 CBcaController::CBcaController(CRawIP2Flow& aRawIPFlow,CBttLogger* aTheLogger)
    35 /**
    29 /**
    36  * Constructor. Performs standard active object initialisation.
    30  * Constructor. Performs standard active object initialisation.
    37  *
    31  *
    38  * @param aRawIPFlow Reference to the RawIp2Flow
    32  * @param aRawIPFlow Reference to the RawIp2Flow
    39  *
    33  * @param aTheLogger The logging object
    40  */
    34  */
    41 	: CActive(EPriorityStandard), 	  
    35 	: CActive(EPriorityStandard), 	  
       
    36 	  iTheLogger(aTheLogger),	 
    42 	  iMBca(NULL),	  
    37 	  iMBca(NULL),	  
    43 	  iState(EIdling),
    38 	  iState(EIdling),
    44 	  iRawIPFlow(aRawIPFlow),
    39 	  iRawIPFlow(aRawIPFlow),
    45 	  iUpperControl(NULL),
    40 	  iUpperControl(NULL),
    46 	  iUpperDataReceiver(NULL),	 
    41 	  iUpperDataReceiver(NULL),	 
    48 	  iBcaParams(NULL)
    43 	  iBcaParams(NULL)
    49 	{
    44 	{
    50 	CActiveScheduler::Add(this);
    45 	CActiveScheduler::Add(this);
    51 	}
    46 	}
    52 	 
    47 	 
    53 CBcaController* CBcaController::NewL(CRawIP2Flow& aRawIPFlow)
    48 CBcaController* CBcaController::NewL(CRawIP2Flow& aRawIPFlow,CBttLogger* aTheLogger)
    54 /**
    49 /**
    55  * Two-phase constructor. Creates a new CBcaController object, performs 
    50  * Two-phase constructor. Creates a new CBcaController object, performs 
    56  * second-phase construction, then returns it.
    51  * second-phase construction, then returns it.
    57  *
    52  *
    58  * @param aRawIPFlow Reference to the RawIp2Flow
    53  * @param aRawIPFlow Reference to the RawIp2Flow
       
    54  * @param aTheLogger The logging object
    59  * @return A newly constructed CBcaController object
    55  * @return A newly constructed CBcaController object
    60  */
    56  */
    61 	{
    57 	{
    62 	CBcaController* self = new (ELeave) CBcaController(aRawIPFlow);
    58 	CBcaController* self = new (ELeave) CBcaController(aRawIPFlow,aTheLogger);
    63 	CleanupStack::PushL(self);
    59 	CleanupStack::PushL(self);
    64 	self->ConstructL();
    60 	self->ConstructL();
    65 	CleanupStack::Pop(self);
    61 	CleanupStack::Pop(self);
    66 	return self;
    62 	return self;
    67 	}
    63 	}
    69 void CBcaController::ConstructL()
    65 void CBcaController::ConstructL()
    70 /**
    66 /**
    71  * Second-phase constructor. Creates all the state objects it owns.
    67  * Second-phase constructor. Creates all the state objects it owns.
    72  */
    68  */
    73 	{
    69 	{
    74 	OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROLLER_CONSTRUCTL_1, "CBcaController::ConstructL");
    70 	_LOG_L1C1(_L8("CBcaController::ConstructL"));
    75 	
    71 	
    76 	}
    72 	}
    77   
    73   
    78  
    74  
    79 CBcaController::~CBcaController()
    75 CBcaController::~CBcaController()
    94 /**
    90 /**
    95  *  AO async callback method. Called after request is completed. 
    91  *  AO async callback method. Called after request is completed. 
    96  *  
    92  *  
    97  */
    93  */
    98 	{
    94 	{
    99 	OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROLLER_RUNL_1, "CBcaControl::RunL() called");
    95 	_LOG_L1C1(_L8("CBcaControl::RunL() called"));
   100 	switch (iState)
    96 	switch (iState)
   101 		{
    97 		{
   102 		//in this state, Ioctl is called to set IAP ID, check the result of
    98 		//in this state, Ioctl is called to set IAP ID, check the result of
   103 		// Ioctl, then either set the BCA stack with another Ioctl call, 
    99 		// Ioctl, then either set the BCA stack with another Ioctl call, 
   104 		// open the BCA (if there's no BCA stack to set), or stop the NIF.
   100 		// open the BCA (if there's no BCA stack to set), or stop the NIF.
   106 			{
   102 			{
   107 			if(iStatus == KErrNone || iStatus == KErrNotSupported)
   103 			if(iStatus == KErrNone || iStatus == KErrNotSupported)
   108 				{
   104 				{
   109 				if(iStatus == KErrNotSupported)
   105 				if(iStatus == KErrNotSupported)
   110 					{
   106 					{
   111 					OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROLLER_RUNL_2, "This BCA does not support IAPID set");
   107 					_LOG_L1C1(_L8("This BCA does not support IAPID set"));
   112 					}
   108 					}
   113 				else
   109 				else
   114 					{
   110 					{
   115 					OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROLLER_RUNL_3, "This BCA supports IAPID set");
   111 					_LOG_L2C1(_L8("This BCA supports IAPID set"));
   116 					}
   112 					}
   117 				
   113 				
   118 				TPtrC bcaStack = iBCAProvisionConfig->GetBCAStack();
   114 				TPtrC bcaStack = iBCAProvisionConfig->GetBCAStack();
   119 				if(bcaStack.Length())
   115 				if(bcaStack.Length())
   120 					{
   116 					{
   130 				iState = EIAPSet;
   126 				iState = EIAPSet;
   131 				SetActive();	
   127 				SetActive();	
   132 				}
   128 				}
   133 			else
   129 			else
   134 				{
   130 				{
   135 				OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROLLER_RUNL_4, "ERROR in BCA IAPID set = %d", iStatus.Int());
   131 				_LOG_L1C2(_L8("ERROR in BCA IAPID set = %d"), iStatus.Int());
   136 				Stop(iStatus.Int());
   132 				Stop(iStatus.Int());
   137 				}
   133 				}
   138 			
   134 			
   139 			break;
   135 			break;
   140 			}			
   136 			}			
   144 			{
   140 			{
   145 			if(iStatus == KErrNotSupported || iStatus == KErrNone)
   141 			if(iStatus == KErrNotSupported || iStatus == KErrNone)
   146 				{
   142 				{
   147 				if(iStatus == KErrNotSupported)
   143 				if(iStatus == KErrNotSupported)
   148 					{
   144 					{
   149 					OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROLLER_RUNL_5, "This BCA does not support BCA stacking");
   145 					_LOG_L1C1(_L8("This BCA does not support BCA stacking"));
   150 					}
   146 					}
   151 				else
   147 				else
   152 					{
   148 					{
   153 					OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROLLER_RUNL_6, "This BCA supports BCA stacking");
   149 					_LOG_L2C1(_L8("This BCA supports BCA stacking"));
   154 					}
   150 					}
   155 				iBcaParams = new(ELeave) MBca2::TBcaParams(const_cast<CBCAProvision*>(iBCAProvisionConfig)->GetCommsPond(), iBCAProvisionConfig->GetPortName());
   151 				iBcaParams = new(ELeave) MBca2::TBcaParams(const_cast<CBCAProvision*>(iBCAProvisionConfig)->GetCommsPond(), iBCAProvisionConfig->GetPortName());
   156 			
   152 			
   157 				TInt aErr = iMBca->Open(*iUpperControl,*iUpperDataReceiver,*iBcaParams);
   153 				TInt aErr = iMBca->Open(*iUpperControl,*iUpperDataReceiver,*iBcaParams);
   158 				if ( aErr != KErrNone)
   154 				if ( aErr != KErrNone)
   159 					{					
   155 					{					
   160 					OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROLLER_RUNL_7, "ERROR in BCA Open = %d", aErr);
   156 					_LOG_L2C2(_L8("ERROR in BCA Open = %d"), aErr);
   161 					Stop(iStatus.Int());
   157 					Stop(iStatus.Int());
   162 					iState = EIdling;
   158 					iState = EIdling;
   163 					}
   159 					}
   164 				else
   160 				else
   165 					{
   161 					{
   166 					iMBca->Start();					
   162 					iMBca->Start();					
   167 					}
   163 					}
   168 				}
   164 				}
   169 			else
   165 			else
   170 				{
   166 				{
   171 				OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROLLER_RUNL_8, "ERROR in BCA stack set = %d", iStatus.Int());
   167 				_LOG_L2C2(_L8("ERROR in BCA stack set = %d"), iStatus.Int());
   172 				Stop(iStatus.Int());
   168 				Stop(iStatus.Int());
   173 				}
   169 				}
   174 			break;
   170 			break;
   175 			}
   171 			}
   176 		// Wrong state.
   172 		// Wrong state.
   177 		default:
   173 		default:
   178 			{
   174 			{
   179 			OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROLLER_RUNL_9, "ERROR CBcaControl::RunL(): Unknown state");
   175 			_LOG_L1C1(_L8("ERROR CBcaControl::RunL(): Unknown state"));
   180 			OstTraceDefExt2(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROLLER_RUNL_10, "PANIC: %S %d", KNifName, KBcaUnkownState);
   176 			_BTT_PANIC(KNifName, KBcaUnkownState);
   181 			User::Panic(KNifName, KBcaUnkownState);
       
   182 			break;
   177 			break;
   183 			}
   178 			}
   184 		}
   179 		}
   185 
   180 
   186 	}
   181 	}
   188 void CBcaController::DoCancel()
   183 void CBcaController::DoCancel()
   189 /**
   184 /**
   190  *	cancel active request. 
   185  *	cancel active request. 
   191  */
   186  */
   192 	{
   187 	{
   193 	OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROLLER_DOCANCEL_1, "CBcaControl::DoCancel called.");
   188 	_LOG_L1C1(_L8("CBcaControl::DoCancel called."));
   194 	OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROLLER_DOCANCEL_2, "iState value is %d", iState);
   189 	_LOG_L2C2(_L8("iState value is %d"), iState);
   195 	switch (iState)
   190 	switch (iState)
   196 		{
   191 		{
   197 		case EIdling:
   192 		case EIdling:
   198 		case EIAPSet:
   193 		case EIAPSet:
   199 			if(iMBca)
   194 			if(iMBca)
   201 				iMBca->CancelControl();
   196 				iMBca->CancelControl();
   202 				}
   197 				}
   203 			iState = EIdling;
   198 			iState = EIdling;
   204 			break;
   199 			break;
   205 		default:
   200 		default:
   206 			OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROLLER_DOCANCEL_3, "ERROR CBcaControl::DoCancel(): Unknown state");
   201 			_LOG_L2C1(_L8("ERROR CBcaControl::DoCancel(): Unknown state"));
   207 			OstTraceDefExt2(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROLLER_DOCANCEL_4, "PANIC: %S %d", KNifName, KBcaUnkownState);
   202 			_BTT_PANIC(KNifName, KBcaUnkownState);
   208 			User::Panic(KNifName, KBcaUnkownState);
       
   209 			break;
   203 			break;
   210 		}
   204 		}
   211 	}
   205 	}
   212 	
   206 	
   213 void CBcaController::StartLoadL(const CBCAProvision* aBCAProvisionConfig,MUpperControl* aControl, 
   207 void CBcaController::StartLoadL(const CBCAProvision* aBCAProvisionConfig,MUpperControl* aControl, 
   219  * @param aControl pointer to BasebandChannelAdaptation2::MUpperControl passed to the MBca2 to pass control information up the stack
   213  * @param aControl pointer to BasebandChannelAdaptation2::MUpperControl passed to the MBca2 to pass control information up the stack
   220  * * @param aData pointer to BasebandChannelAdaptation2::MUpperDataReceiver passed to the MBca2 to push packets up the stack
   214  * * @param aData pointer to BasebandChannelAdaptation2::MUpperDataReceiver passed to the MBca2 to push packets up the stack
   221  * @return none 
   215  * @return none 
   222  */
   216  */
   223 	{
   217 	{
   224 	OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROLLER_STARTLOADL_1, "CBcaControl::StartLoad");
   218 	_LOG_L1C1(_L8("CBcaControl::StartLoad"));
   225 
   219 
   226 	iBCAProvisionConfig = aBCAProvisionConfig;
   220 	iBCAProvisionConfig = aBCAProvisionConfig;
   227 	iUpperControl = aControl;
   221 	iUpperControl = aControl;
   228 	iUpperDataReceiver = aData;
   222 	iUpperDataReceiver = aData;
   229 	// Loads Bca Dll and creates a Bca instance;
   223 	// Loads Bca Dll and creates a Bca instance;
   230 	User::LeaveIfError(iBcaDll.iObj.Load(iBCAProvisionConfig->GetBCAName()));
   224 	User::LeaveIfError(iBcaDll.iObj.Load(iBCAProvisionConfig->GetBCAName()));
   231 	
   225 	
   232 	TNewBca2FactoryL newBca2FactoryProcL = (TNewBca2FactoryL)iBcaDll.iObj.Lookup(1);
   226 	TNewBca2FactoryL newBca2FactoryProcL = (TNewBca2FactoryL)iBcaDll.iObj.Lookup(1);
   233 	if (NULL == newBca2FactoryProcL)
   227 	if (NULL == newBca2FactoryProcL)
   234 		{
   228 		{
   235 		OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROLLER_STARTLOADL_2, "Library entry point found error %d", KErrBadLibraryEntryPoint);
   229 		_LOG_L1C2(_L8("Library entry point found error %d"), KErrBadLibraryEntryPoint);
   236 		User::Leave(KErrBadLibraryEntryPoint);	
   230 		User::Leave(KErrBadLibraryEntryPoint);	
   237 		}
   231 		}
   238 	
   232 	
   239 	MBca2Factory* bcaFactory = (*newBca2FactoryProcL)();
   233 	MBca2Factory* bcaFactory = (*newBca2FactoryProcL)();
   240 
   234 
   241 	if(!bcaFactory)
   235 	if(!bcaFactory)
   242 		{
   236 		{
   243 		OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROLLER_STARTLOADL_3, "BcaFactory creation error %d", KErrCompletion);
   237 		_LOG_L1C2(_L8("BcaFactory creation error %d"), KErrCompletion);
   244 		User::Leave(KErrCompletion);	
   238 		User::Leave(KErrCompletion);	
   245 		}
   239 		}
   246 	CleanupReleasePushL(*bcaFactory);
   240 	CleanupReleasePushL(*bcaFactory);
   247 	
   241 	
   248 	iMBca = bcaFactory->NewBcaL();
   242 	iMBca = bcaFactory->NewBcaL();
   259 /**
   253 /**
   260  *  Used to shutdown this module. This will cancel all the outstanding 
   254  *  Used to shutdown this module. This will cancel all the outstanding 
   261  *  requests on the active objects owned by this module and shutdown.
   255  *  requests on the active objects owned by this module and shutdown.
   262  */
   256  */
   263 	{
   257 	{
   264 	OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROLLER_STOP_1, "CBcaController::Stop is called.");
   258 	_LOG_L1C1(_L8("CBcaController::Stop is called."));
   265 
   259 
   266 	if(iMBca)
   260 	if(iMBca)
   267 		{
   261 		{
   268 		iMBca->Close();
   262 		iMBca->Close();
   269 		}
   263 		}
   270 	else 
   264 	else 
   271 		{
   265 		{
   272 		OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROLLER_STOP_2, "CBcaController::Stop Bca is not initialized. Bring the link layer down");
   266 		_LOG_L1C1(_L8("CBcaController::Stop Bca is not initialized. Bring the link layer down"));
   273 		iRawIPFlow.LinkLayerDown(aError);
   267 		iRawIPFlow.LinkLayerDown(aError);
   274 		}
   268 		}
   275   	}
   269   	}
   276 
   270 
   277 
   271 
   278 /** Panic function for RawIpNif 
   272 /** Panic function for RawIpNif 
   279 
   273 
   280 * @param aPanic panic code */
   274 * @param aPanic panic code */
   281 void Panic(TRawIP2NifPanic aPanic)
   275 void Panic(TRawIP2NifPanic aPanic)
   282 	{
   276 	{
   283 	OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROLLER_PANIC_1, "Panic code for RawIpNif = %d", aPanic);
   277 	_LOG_L2C2(_L8("Panic code for RawIpNif = %d"), aPanic);
   284 	User::Panic(KNifName,aPanic);
   278 	User::Panic(KNifName,aPanic);
   285 
   279 
   286 	}
   280 	}
   287 
   281