telephonyprotocols/rawipnif/src/BcaIoController.cpp
changeset 73 70d75957b98f
parent 44 8b72faa1200f
equal deleted inserted replaced
69:b982c3e940f3 73:70d75957b98f
    27 
    27 
    28 #include <e32uid.h>
    28 #include <e32uid.h>
    29 #include <nifmbuf.h>
    29 #include <nifmbuf.h>
    30 #include <e32svr.h>
    30 #include <e32svr.h>
    31 #include <u32hal.h>
    31 #include <u32hal.h>
       
    32 #include <rawip_const.h>
    32 
    33 
    33 #include "Constants.h"
    34 #include "Constants.h"
    34 #include "BcaIoController.h"
    35 #include "BcaIoController.h"
    35 #include "Sender.h"
    36 #include "Sender.h"
    36 #include "Receiver.h"
    37 #include "Receiver.h"
    37 
    38 
       
    39 #ifndef __EABI__
    38 const TUint KDefaultSendQueueSize=5;
    40 const TUint KDefaultSendQueueSize=5;
    39 
       
    40 #ifdef __EABI__
       
    41 // Patch data is used and KMaxTxIPPacketSize and KMaxRxIPPacketSize can be modified to a different value in RawIpNif.iby file
       
    42 extern const TInt KMaxSendQueueLen = KDefaultSendQueueSize;
       
    43 extern const TInt KMaxTxIPPacketSize = KMaxIPPacket + KIPTagHeaderLength;
       
    44 extern const TInt KMaxRxIPPacketSize = KMaxIPPacket + KIPTagHeaderLength;
       
    45 #endif
    41 #endif
    46 
    42 
    47 CBcaIoController::CBcaIoController(MControllerObserver& aObserver)
    43 CBcaIoController::CBcaIoController(MControllerObserver& aObserver)
    48 /**
    44 /**
    49  * Constructor. 
    45  * Constructor. 
    88     iIPTagHeader = new (ELeave) CIPTagHeader(iTheLogger);
    84     iIPTagHeader = new (ELeave) CIPTagHeader(iTheLogger);
    89 #endif // RAWIP_HEADER_APPENDED_TO_PACKETS
    85 #endif // RAWIP_HEADER_APPENDED_TO_PACKETS
    90 
    86 
    91 #if defined __EABI__
    87 #if defined __EABI__
    92     // Default value for queue length
    88     // Default value for queue length
    93     iMaxSendQueueLen = KMaxSendQueueLen;
    89     iMaxSendQueueLen = RawIPConst::KMaxSendQueueLen;
    94     // Default value for Tx and Rx packet size
    90     // Default value for Tx and Rx packet size
    95     iMaxTxPacketSize = KMaxTxIPPacketSize;
    91     iMaxTxPacketSize = RawIPConst::KMaxTxIPPacketSize;
    96     iMaxRxPacketSize = KMaxRxIPPacketSize;
    92     iMaxRxPacketSize = RawIPConst::KMaxRxIPPacketSize;
    97 #else // WINS
    93 #else // WINS
    98     // Set default values in case patch is not present in epocrawip.ini
    94     // Set default values in case patch is not present in epocrawip.ini
    99     iMaxSendQueueLen = KDefaultSendQueueSize;    
    95     iMaxSendQueueLen = KDefaultSendQueueSize;    
   100     iMaxTxPacketSize = KMaxIPPacket + KIPTagHeaderLength;
    96     iMaxTxPacketSize = KMaxIPPacket + KIPTagHeaderLength;
   101     iMaxRxPacketSize = KMaxIPPacket + KIPTagHeaderLength;
    97     iMaxRxPacketSize = KMaxIPPacket + KIPTagHeaderLength;
   105     UserSvr::HalFunction(EHalGroupEmulator,EEmulatorHalIntProperty,(TAny*)"rawip_KMaxTxIPPacketSize",&iMaxTxPacketSize);
   101     UserSvr::HalFunction(EHalGroupEmulator,EEmulatorHalIntProperty,(TAny*)"rawip_KMaxTxIPPacketSize",&iMaxTxPacketSize);
   106     UserSvr::HalFunction(EHalGroupEmulator,EEmulatorHalIntProperty,(TAny*)"rawip_KMaxRxIPPacketSize",&iMaxRxPacketSize);
   102     UserSvr::HalFunction(EHalGroupEmulator,EEmulatorHalIntProperty,(TAny*)"rawip_KMaxRxIPPacketSize",&iMaxRxPacketSize);
   107 #endif
   103 #endif
   108     
   104     
   109     // end note
   105     // end note
   110     
   106     //explicit casts required otherwise compiler fails with ambiguous function calls
       
   107     OstTraceDefExt3( OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCAIOCONTROLLER_CONSTRUCTL_2, "CBcaIoController::ConstructL;iMaxSendQueueLen=%d;iMaxTxPacketSize=%d;iMaxRxPacketSize=%d", (TInt32)iMaxSendQueueLen, (TInt32)iMaxTxPacketSize, (TInt32)iMaxRxPacketSize );
       
   108 
   111     iSender = CSender::NewL(*this, iMaxTxPacketSize);
   109     iSender = CSender::NewL(*this, iMaxTxPacketSize);
   112     iReceiver = CReceiver::NewL(*this, iMaxRxPacketSize);
   110     iReceiver = CReceiver::NewL(*this, iMaxRxPacketSize);
   113     iLoader = new (ELeave) CBcaControl(*this);
   111     iLoader = new (ELeave) CBcaControl(*this);
   114     }
   112     }
   115 	
   113 	
   136 
   134 
   137 * @param aBcaStack Text composed of bca stack and next bca names
   135 * @param aBcaStack Text composed of bca stack and next bca names
   138 */	
   136 */	
   139 void CBcaIoController::SetBcaStackAndName(const TDesC& aBcaStack, const TDesC& aBcaName)
   137 void CBcaIoController::SetBcaStackAndName(const TDesC& aBcaStack, const TDesC& aBcaName)
   140 	{
   138 	{
       
   139     OstTraceDefExt2(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCAIOCONTROLLER_SETBCASTACKANDNAME_1, "BcaStack [%S] BcaName [%S]", aBcaStack, aBcaName);
   141 	iBcaName.Set(aBcaName);
   140 	iBcaName.Set(aBcaName);
   142 	iBcaStack.Set(aBcaStack);
   141 	iBcaStack.Set(aBcaStack);
   143 	}
   142 	}
   144 	
   143 	
   145 
   144 
   478 /**
   477 /**
   479  *  Called after request is completed. 
   478  *  Called after request is completed. 
   480  *  
   479  *  
   481  */
   480  */
   482 	{
   481 	{
   483 	OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROL_RUNL_1, "CBcaControl::RunL() called");
   482 	OstTraceDefExt2(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROL_RUNL_1, "RunL() called with iState [%d] iStatus [%d]", iState, iStatus.Int());
   484 	switch (iState)
   483 	switch (iState)
   485 		{
   484 		{
   486 		//in this state, Ioctl is called to set IAP ID, check the result of
   485 		//in this state, Ioctl is called to set IAP ID, check the result of
   487 		// Ioctl, then either set the BCA stack with another Ioctl call, 
   486 		// Ioctl, then either set the BCA stack with another Ioctl call, 
   488 		// open the BCA (if there's no BCA stack to set), or stop the NIF.
   487 		// open the BCA (if there's no BCA stack to set), or stop the NIF.
   489 		case EIdling:
   488 		case EIdling:
   490 			{
   489 			{
   491 			if(iStatus == KErrNone || iStatus == KErrNotSupported)
   490 			if(iStatus == KErrNone || iStatus == KErrNotSupported)
   492 				{
   491 				{				
   493 				if(iStatus == KErrNotSupported)
       
   494 					{
       
   495 					OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROL_RUNL_2, "This BCA does not support IAPID set");
       
   496 					}
       
   497 				else
       
   498 					{
       
   499 					OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROL_RUNL_3, "This BCA supports IAPID set");
       
   500 					}
       
   501 				
       
   502 				TPtrC bcaStack = iObserver.BcaStack();
   492 				TPtrC bcaStack = iObserver.BcaStack();
   503 				if(bcaStack.Length())
   493 				if(bcaStack.Length())
   504 					{
   494 					{
   505 					TBuf8<KMaxName> remainingBcaStack8;
   495 					TBuf8<KMaxName> remainingBcaStack8;
   506 					remainingBcaStack8.Copy(bcaStack);
   496 					remainingBcaStack8.Copy(bcaStack);
       
   497 					OstTraceDefExt1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROL_RUNL_2, "Setting BCA Stack [%S]", bcaStack);
   507 					iMBca->Ioctl(iStatus, KBcaOptLevelGeneric,KBCASetBcaStack,remainingBcaStack8);
   498 					iMBca->Ioctl(iStatus, KBcaOptLevelGeneric,KBCASetBcaStack,remainingBcaStack8);
   508 					}
   499 					}
   509 				else
   500 				else
   510 					{
   501 					{
   511 					TRequestStatus* statusPtr=&iStatus;
   502 					TRequestStatus* statusPtr=&iStatus;
   512 					User::RequestComplete(statusPtr,KErrNone);
   503 					User::RequestComplete(statusPtr,KErrNone);
   513 					}
   504 					}
   514 				iState = EIAPSet;
   505 				iState = EIAPSet;
   515 				SetActive();	
   506 				SetActive();
   516 				}
   507 				}
   517 			else
   508 			else
   518 				{
   509 				{
   519 				OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROL_RUNL_4, "ERROR in BCA IAPID set = %d", iStatus.Int());
       
   520 				iObserver.Stop(iStatus.Int());
   510 				iObserver.Stop(iStatus.Int());
   521 				}
   511 				}
   522 			
   512 			
   523 			break;
   513 			break;
   524 			}
   514 			}
   527 		// Check the result of Ioctl, then Open the Bca or stop the NIF
   517 		// Check the result of Ioctl, then Open the Bca or stop the NIF
   528 		case EIAPSet:
   518 		case EIAPSet:
   529 			{
   519 			{
   530 			if(iStatus == KErrNotSupported || iStatus == KErrNone)
   520 			if(iStatus == KErrNotSupported || iStatus == KErrNone)
   531 				{
   521 				{
   532 				if(iStatus == KErrNotSupported)
   522                 OstTraceDefExt1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROL_RUNL_3, "Opening Port [%S]", iObserver.Port());
   533 					{
       
   534 					OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROL_RUNL_5, "This BCA does not support BCA stacking");
       
   535 					}
       
   536 				else
       
   537 					{
       
   538 					OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROL_RUNL_6, "This BCA supports BCA stacking");
       
   539 					}
       
   540 				iMBca->Open(iStatus, iObserver.Port());
   523 				iMBca->Open(iStatus, iObserver.Port());
   541 				iState = EBcaStackSet;
   524 				iState = EBcaStackSet;
   542 				SetActive();	
   525 				SetActive();	
   543 				}
   526 				}
   544 			else
   527 			else
   545 				{
   528 				{
   546 				OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROL_RUNL_7, "ERROR in BCA stack set = %d", iStatus.Int());
       
   547 				iObserver.Stop(iStatus.Int());
   529 				iObserver.Stop(iStatus.Int());
   548 				}
   530 				}
   549 			break;
   531 			break;
   550 			}
   532 			}
   551 		
   533 		
   553 		// If it is successful,then start the NIF. Otherwise stops the NIF.
   535 		// If it is successful,then start the NIF. Otherwise stops the NIF.
   554 		case EBcaStackSet:
   536 		case EBcaStackSet:
   555 			{
   537 			{
   556 			if(iStatus != KErrNone && iStatus !=  KErrAlreadyExists)
   538 			if(iStatus != KErrNone && iStatus !=  KErrAlreadyExists)
   557 				{
   539 				{
   558 				OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROL_RUNL_8, "ERROR in BCA Open = %d", iStatus.Int());
       
   559 				iObserver.Stop(iStatus.Int());
   540 				iObserver.Stop(iStatus.Int());
   560 				}
   541 				}
   561 			else
   542 			else
   562 				{
   543 				{
   563                 iState = EBcaOpened;
   544                 iState = EBcaOpened;
   564                 //Activate the receiver Active Object
   545                 //Activate the receiver Active Object
   565 				iObserver.Receiver().StartListening();
   546 				iObserver.Receiver().StartListening();
   566 				OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROL_RUNL_9, "CBcaIoController Is Initialised");
   547 				OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROL_RUNL_4, "CBcaIoController Is Initialised");
   567 				TRAPD(err, iObserver.GetObserver().InitialiseL(MRawIPObserverBase::EBcaController,KErrNone));
   548 				TRAPD(err, iObserver.GetObserver().InitialiseL(MRawIPObserverBase::EBcaController,KErrNone));
   568 				if(err != KErrNone)
   549 				if(err != KErrNone)
   569 					{
   550 					{
   570 					OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROL_RUNL_10, "ERROR in BCA Open Initialise observer = %d", err);
   551 					OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROL_RUNL_5, "ERROR in BCA Open Initialise observer = %d", err);
   571 					iObserver.Stop(err);
   552 					iObserver.Stop(err);
   572 					}
   553 					}
   573 				}
   554 				}
   574 			break;
   555 			break;
   575 			}
   556 			}
   577 		//in this state, BCA is Shutdown, shutdown the NIF.
   558 		//in this state, BCA is Shutdown, shutdown the NIF.
   578 		case EClosing:
   559 		case EClosing:
   579 			{
   560 			{
   580 			// linklayer shutdown
   561 			// linklayer shutdown
   581 			iState = EIdling;
   562 			iState = EIdling;
       
   563 			OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROL_RUNL_6, "Shutting down with error = %d", iError);
   582 			iObserver.GetObserver().ShutDown(MControllerObserver::EBcaController, iError);
   564 			iObserver.GetObserver().ShutDown(MControllerObserver::EBcaController, iError);
   583 			break;
   565 			break;
   584 			}
   566 			}
   585 		// Wrong state.
   567 		// Wrong state.
   586 		default:
   568 		default:
   587 			{
   569 			{
   588 			OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROL_RUNL_11, "ERROR CBcaControl::RunL(): Unknown state");
   570 			OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROL_RUNL_7, "ERROR CBcaControl::RunL(): Unknown state");
   589 	        OstTraceDefExt2(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROL_RUNL_12, "PANIC: %S %d", KNifName, KBcaUnkownState);
   571 	        OstTraceDefExt2(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROL_RUNL_8, "PANIC: %S %d", KNifName, KBcaUnkownState);
   590 	        User::Panic(KNifName, KBcaUnkownState);
   572 	        User::Panic(KNifName, KBcaUnkownState);
   591 			break;
   573 			break;
   592 			}
   574 			}
   593 		}
   575 		}
   594 
   576 
   597 void CBcaControl::DoCancel()
   579 void CBcaControl::DoCancel()
   598 /**
   580 /**
   599  *	cancel active request. 
   581  *	cancel active request. 
   600  */
   582  */
   601 	{
   583 	{
   602 	OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROL_DOCANCEL_1, "CBcaControl::DoCancel called.");
   584 	OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROL_DOCANCEL_1, "Cancel called with iState value [%d]", iState);
   603 	OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROL_DOCANCEL_2, "iState value is %d", iState);
       
   604 	switch (iState)
   585 	switch (iState)
   605 		{
   586 		{
   606 		case EIdling:
   587 		case EIdling:
   607 		case EIAPSet:
   588 		case EIAPSet:
   608 	    case EBcaStackSet:
   589 	    case EBcaStackSet:
   614 			break;
   595 			break;
   615 		case EClosing:
   596 		case EClosing:
   616             iState = EIdling;		    
   597             iState = EIdling;		    
   617             break;    
   598             break;    
   618 		default:
   599 		default:
   619 			OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROL_DOCANCEL_3, "ERROR CBcaControl::DoCancel(): Unknown state");
   600 			OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROL_DOCANCEL_2, "ERROR CBcaControl::DoCancel(): Unknown state");
   620 	        OstTraceDefExt2(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROL_DOCANCEL_4, "PANIC: %S %d", KNifName, KBcaUnkownState);
   601 	        OstTraceDefExt2(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROL_DOCANCEL_3, "PANIC: %S %d", KNifName, KBcaUnkownState);
   621 	        User::Panic(KNifName, KBcaUnkownState);
   602 	        User::Panic(KNifName, KBcaUnkownState);
   622 			break;
   603 			break;
   623 		}
   604 		}
   624 	}
   605 	}
   625 	
   606 
   626 void CBcaControl::StartLoadL()
   607 void CBcaControl::StartLoadL()
   627 /**
   608 /**
   628  *  This method loads the C32BCA library and uses Ioctl to set the Bca iIapId. 
   609  *  This method loads the C32BCA library and uses Ioctl to set the Bca iIapId. 
   629  */
   610  */
   630 	{
   611 	{
   666 	iMBca = bcaFactory->NewBcaL();
   647 	iMBca = bcaFactory->NewBcaL();
   667 	CleanupStack::PopAndDestroy(bcaFactory);
   648 	CleanupStack::PopAndDestroy(bcaFactory);
   668 	
   649 	
   669 	iObserver.SetBca(iMBca); //Pass BCA pointer.
   650 	iObserver.SetBca(iMBca); //Pass BCA pointer.
   670 
   651 
       
   652 	OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROL_STARTLOADL_4, "Setting IAP Id [%d]", iObserver.IapId());
   671 	TPckg<TUint32> aOpt(iObserver.IapId());
   653 	TPckg<TUint32> aOpt(iObserver.IapId());
   672 	iMBca->Ioctl(iStatus,KBcaOptLevelGeneric,KBCASetIapId,aOpt);
   654 	iMBca->Ioctl(iStatus,KBcaOptLevelGeneric,KBCASetIapId,aOpt);
   673 	
   655 	
   674 	iState = EIdling;
   656 	iState = EIdling;
   675 	SetActive();
   657 	SetActive();
   683  *  @param aError the error code to shutdown the NIF. 
   665  *  @param aError the error code to shutdown the NIF. 
   684  */
   666  */
   685 	{
   667 	{
   686 	__ASSERT_DEBUG(iMBca,Panic(KBcaNotExist));
   668 	__ASSERT_DEBUG(iMBca,Panic(KBcaNotExist));
   687 	Cancel();
   669 	Cancel();
   688         
   670 
       
   671 	OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CBCACONTROL_SHUTDOWNBCA_4, "Error Code [%d]", aError);
   689     //We should only call shutdown or close if we have successfully opened a BCA Channel
   672     //We should only call shutdown or close if we have successfully opened a BCA Channel
   690     if((iMBca) && (EBcaOpened == iState))
   673     if((iMBca) && (EBcaOpened == iState))
   691         {
   674         {
   692         if(aError == KErrConnectionTerminated )
   675         if(aError == KErrConnectionTerminated )
   693             {
   676             {