connectivitylayer/isce/isirouter_dll/src/isicltransceiver.cpp
changeset 9 8486d82aef45
parent 7 fa67e03b87df
equal deleted inserted replaced
8:6295dc2169f3 9:8486d82aef45
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 
    18 
    19 
    19 
    20 #include <kernel.h>               // For Kern
    20 #include <kernel.h>                 // For Kern
    21 #include "isirouter.h"            // For DISIRouter
    21 #include <pn_const.h>               // For PN_OBJ_ROUTING_REQ
    22 #include "isiroutertrace.h"       // For C_TRACE, ASSERT_RESET.. and fault codes
    22 #include <phonetisi.h>              // For ISI_HEADER_OFFSET_...
    23 #include "misirouterlinkif.h"     // For MISIRouterLinkIf
    23 #include <commisi.h>                // For COMMON_ISA_...
    24 #include "isihelpers.h"           // For GET_SENDER_DEV...
    24 
    25 #include "memapi.h"               // For MemApi
    25 #include "isirouter.h"              // For DISIRouter
    26 #include <trxdefs.h>              // For ETrxTest...
    26 #include "isiroutertrace.h"         // For C_TRACE, ASSERT_RESET.. and fault codes
    27 #include "isicltransceiver.h"     // For DISICLTransceiver
    27 #include "misirouterlinkif.h"       // For MISIRouterLinkIf
    28 #include <nsisi.h>                // For PN_NAMESERVICE... TODO:Remove this
    28 #include "isihelpers.h"             // For GET_SENDER_DEV...
    29 
    29 #include "memapi.h"                 // For MemApi
    30 #define PN_MEDIA_TEST 0xBB //not real
    30 #include <trxdefs.h>                // For ETrxTest...
    31 //#define PN_DEV_MODEM 0x12
    31 #include "isicltransceiver.h"       // For DISICLTransceiver
    32 #define PN_DEV_DUMMYIST 0x13
    32 #include <nsisi.h>                  // For PN_NAMESERVICE...
    33 #define PN_DEV_OWN 0x6C
    33 #include "isirouterservice.h"       // For DIsiRouterService
    34 
    34 #include "isimsgqueue.h"            // For DISIMsgQueue
    35 // CONSTS
    35 #include "iscnokiadefinitions.h"    // For EIscNokiaUsbPhonetLink
    36 DISICLTransceiver* DISICLTransceiver::iThisPtr = NULL;
    36 #ifdef USE_MEDIAAPI  
    37 
    37 #include <pn_isimedia_const.h>      // For PN_DEV_PC 
       
    38 #endif /* USE_MEDIAAPI */
    38 
    39 
    39 // Faults
    40 // Faults
    40 enum TISICLTransceiverFaults
    41 enum TISICLTransceiverFaults
    41     {
    42     {
    42     EISICLTransceiverMemAllocFailure = 0x01,
    43     EISICLTransceiverMemAllocFailure = 0x01,
    43     EISICLTransceiverMemAllocFailure1,
    44     EISICLTransceiverMemAllocFailure1,
       
    45     EISICLTransceiverMemAllocFailure2,
       
    46     EISICLTransceiverMemAllocFailure3,
       
    47     EISICLTransceiverMemAllocFailure4,
       
    48     EISICLTransceiverMemAllocFailure5,
       
    49     EISICLTransceiverMemAllocFailure6,
       
    50     EISICLTransceiverMemAllocFailure7,
       
    51     EISICLTransceiverMemAllocFailure8,
       
    52 #ifdef USE_MEDIAAPI 	
       
    53     EISICLTransceiverMemAllocFailure9,
       
    54     EISICLTransceiverMemAllocFailure10,  
       
    55 #endif /* USE_MEDIAAPI */  
    44     EISICLTransceiverNotSupportedMedia,
    56     EISICLTransceiverNotSupportedMedia,
    45     EISICLTransceiverOverTheLimits,
    57     EISICLTransceiverOverTheLimits,
    46     EISICLTransceiverNULLPtr,
    58     EISICLTransceiverNULLPtr,
       
    59     EISICLTransceiverNULLPtr2,
       
    60     EISICLTransceiverNULLPtr3,
       
    61     EISICLTransceiverNULLPtr4,
       
    62     EISICLTransceiverNULLPtr5,
       
    63     EISICLTransceiverNULLPtr6,
       
    64     EISICLTransceiverNULLPtr7,
    47     EISICLTransceiverNotSupportedDevice,
    65     EISICLTransceiverNotSupportedDevice,
       
    66     EISICLTransceiverDeviceConnection,
       
    67     EISICLTransceiverCommIsaEntityNotReachableResp,
       
    68     EISICLTransceiverNotThreadContext,
       
    69     EISICLTransceiverMutexCreateFailed,
       
    70     EISICLTransceiverMutexWaitFailed,
       
    71     EISICLTransceiverMutexWaitFailed2,
    48     };
    72     };
    49 
    73 
    50 DISICLTransceiver::DISICLTransceiver( DISIRouter* aPtr )
    74 // Constants
    51     : iRouter( aPtr )
    75 const TInt KDfcPriority( 5 );
       
    76 
       
    77 DMutex* DISICLTransceiver::iDynamicDeviceTableMutex = NULL;
       
    78 _LIT8( KISICLTransceiverMutex, "ISICLTransceiverMutex" );
       
    79 
       
    80 DISICLTransceiver::DISICLTransceiver(
       
    81         DISIRouter& aRouter,
       
    82         TDfcQue* aThreadPtr
       
    83         )
       
    84     : iShRouter( aRouter )
    52     {
    85     {
    53     C_TRACE( ( _T( "DISICLTransceiver::DISICLTransceiver>" ) ) );
    86     C_TRACE( ( _T( "DISICLTransceiver::DISICLTransceiver>" ) ) );
    54     iLinksArray = new MISIRouterLinkIf*[ EISIAmountOfMedias ];
    87     ASSERT_RESET_ALWAYS( aThreadPtr, ( EISICLTransceiverNULLPtr7 | EDISICLTransceiverTraceId << KClassIdentifierShift ) );
    55     ASSERT_RESET_ALWAYS( iLinksArray, ( EISICLTransceiverMemAllocFailure | EDISICLTransceiverTraceId << KClassIdentifierShift ) );
    88     iShStateChangedDfc = new TDfc( StateChangedDfc, this, aThreadPtr, KDfcPriority );
    56     // Initialize links
    89     ASSERT_RESET_ALWAYS( iShStateChangedDfc, ( EISICLTransceiverMemAllocFailure6 | EDISICLTransceiverTraceId << KClassIdentifierShift ) );
    57     for( TInt i( 0 ); i < EISIAmountOfMedias; i++ )
    90     
    58         {
    91     iRxQueueDfc = new TDfc( RxQueueDfc, this, aThreadPtr, KDfcPriority );
    59         iLinksArray[ i ] = NULL;
    92     ASSERT_RESET_ALWAYS( iShStateChangedDfc, ( EISICLTransceiverMemAllocFailure8 | EDISICLTransceiverTraceId << KClassIdentifierShift ) );
    60         }
    93             
    61     //TODO add real media and trx when known
    94     DISIDevice* dev = new DISIDevice( PN_DEV_MODEM,
    62     iLinksArray[ EISIMediaTest ] = MISIRouterLinkIf::CreateLinkF( this, PN_MEDIA_TEST, ETrxTest );
    95                                       MISIRouterLinkIf::CreateLinkF( this, PN_MEDIA_MODEM_HOST_IF, ETrxSharedMemory)
       
    96                                       );
       
    97     ASSERT_RESET_ALWAYS( dev, ( EISICLTransceiverMemAllocFailure3 | EDISICLTransceiverTraceId << KClassIdentifierShift ) );
       
    98     iShDevices.Append( dev );
       
    99 #ifdef USE_MEDIAAPI 
       
   100     DISIDevice* dev2 = new DISIDevice( PN_DEV_PC,  // append to dynamic table if needed
       
   101                                        MISIRouterLinkIf::CreateLinkF( this, PN_MEDIA_USB, ETrxUSB )
       
   102                                       );
       
   103     ASSERT_RESET_ALWAYS( dev2, ( EISICLTransceiverMemAllocFailure9 | EDISICLTransceiverTraceId << KClassIdentifierShift ) );
       
   104     iShDevices.Append( dev2 );
       
   105     
       
   106     DISIDevice* dev4 = new DISIDevice( PN_DEV_PC,  // append to dynamic table if needed
       
   107                                        MISIRouterLinkIf::CreateLinkF( this, PN_MEDIA_BT, ETrxBT )
       
   108                                       );
       
   109     ASSERT_RESET_ALWAYS( dev4, ( EISICLTransceiverMemAllocFailure10 | EDISICLTransceiverTraceId << KClassIdentifierShift ) );
       
   110     iShDevices.Append( dev4 );
       
   111  #endif /* USE_MEDIAAPI */
       
   112 	  DISIDevice* dev3 = new DISIDevice( PN_DEV_DUMMYIST,
       
   113                                        MISIRouterLinkIf::CreateLinkF( this, PN_MEDIA_TEST, ETrxTest )
       
   114                                       );                                      
       
   115     ASSERT_RESET_ALWAYS( dev3, ( EISICLTransceiverMemAllocFailure5 | EDISICLTransceiverTraceId << KClassIdentifierShift ) );
       
   116     iShDevices.Append( dev3 );
       
   117 
       
   118     iRouterService = new DIsiRouterService( *this );
       
   119     ASSERT_RESET_ALWAYS( iRouterService, ( EISICLTransceiverMemAllocFailure2 | EDISICLTransceiverTraceId << KClassIdentifierShift ) );
       
   120     
       
   121     iRxQueue = new DISIMsgQueue( KISIMainRxQueueSize );
       
   122     ASSERT_RESET_ALWAYS( iRxQueue, ( EISICLTransceiverMemAllocFailure7 | EDISICLTransceiverTraceId << KClassIdentifierShift ) );
       
   123     
       
   124     TInt err( Kern::MutexCreate( iDynamicDeviceTableMutex, KISICLTransceiverMutex, KMutexOrdGeneral0 ) );
       
   125     ASSERT_RESET_ALWAYS( ( KErrNone == err ), ( EISICLTransceiverMutexCreateFailed | EDISICLTransceiverTraceId << KClassIdentifierShift ) );
       
   126 #ifdef USE_MEDIAAPI 
       
   127     iDevPcLastSendTrxId = EAmountOfTrxs;  //put a maxvalue	
       
   128     iDevPcLastActiveTrxId = EAmountOfTrxs;  //put a maxvalue
       
   129 #endif /* USE_MEDIAAPI */
    63     C_TRACE( ( _T( "DISICLTransceiver::DISICLTransceiver<" ) ) );
   130     C_TRACE( ( _T( "DISICLTransceiver::DISICLTransceiver<" ) ) );
    64     }
   131     }
    65 
   132 
    66 DISICLTransceiver::~DISICLTransceiver()
   133 DISICLTransceiver::~DISICLTransceiver()
    67     {
   134     {
    68     C_TRACE( ( _T( "DISICLTransceiver::~DISICLTransceiver>" ) ) );
   135     C_TRACE( ( _T( "DISICLTransceiver::~DISICLTransceiver>" ) ) );
    69     for( TUint8 i( 0 ); i < EISIAmountOfMedias; i++ )
   136     
    70         {
   137     iShDevices.ResetAndDestroy();
    71         MISIRouterLinkIf* tmp = iLinksArray[ i ];
   138     
    72         if( tmp )
   139     if ( iRouterService )
    73             {
   140         {            
    74             tmp->Release();
   141         delete iRouterService;
    75             tmp = NULL;
   142         iRouterService = NULL;
    76             iLinksArray[ i ] = NULL;
   143         }
    77             }
   144         
    78         }
   145     if ( iShStateChangedDfc )
    79     delete []iLinksArray;
   146         { 
       
   147         iShStateChangedDfc->Cancel();
       
   148         delete iShStateChangedDfc;
       
   149         iShStateChangedDfc = NULL;
       
   150         }
       
   151     
       
   152     if( iRxQueue )
       
   153         {
       
   154         C_TRACE( ( _T( "DISICLTransceiver::ResetQueues 0x%x iRxQueue 0x%x" ), this, iRxQueue ) );
       
   155         while( iRxQueue->Count() )
       
   156             {
       
   157             MemApi::DeallocBlock( iRxQueue->Get() );
       
   158             }
       
   159         }
       
   160         
       
   161     if( iRxQueueDfc )
       
   162         {
       
   163         C_TRACE( ( _T( "DISIUserChannel::~DISIUserChannel 0x%x iRxQueueDfc 0x%x" ), this, iRxQueueDfc ) );
       
   164         iRxQueueDfc->Cancel();
       
   165         delete iRxQueueDfc;
       
   166         iRxQueueDfc = NULL;
       
   167         }
       
   168 
    80     C_TRACE( ( _T( "DISICLTransceiver::~DISICLTransceiver<" ) ) );
   169     C_TRACE( ( _T( "DISICLTransceiver::~DISICLTransceiver<" ) ) );
    81     }
   170 
    82 
   171     }
    83 TInt DISICLTransceiver::SendCommIsaEntityNotReachableResp( TDes8& aMessage )
   172 
    84     {
   173 TInt DISICLTransceiver::SendCommIsaEntityNotReachableResp(
    85     C_TRACE( ( _T( "DISICLTransceiver::SendCommIsaEntityNotReachableResp 0x%x>" ), &aMessage ) );
   174         TDes8& aNotDeliveredMessage
    86     const TUint8* msgTmpPtr( aMessage.Ptr() );
   175         )
       
   176     {
       
   177     C_TRACE( ( _T( "DISICLTransceiver::SendCommIsaEntityNotReachableResp 0x%x>" ), &aNotDeliveredMessage ) );
       
   178     const TUint8* notDeliveredMsgPtr( aNotDeliveredMessage.Ptr() );
    87     TInt error = KErrAlreadyExists;
   179     TInt error = KErrAlreadyExists;
    88 
   180     // Avoid COMM_ISA_ENTITY_NOT_REACHABLE_RESP loop.
    89     // To avoid COMM_ISA_ENTITY_NOT_REACHABLE_RESP loop
   181     if( ( notDeliveredMsgPtr[ ISI_HEADER_OFFSET_MESSAGEID ] == COMMON_MESSAGE ) &&
    90     if( msgTmpPtr[ ISI_HEADER_OFFSET_MESSAGEID ] != COMMON_MESSAGE &&
   182         ( ( notDeliveredMsgPtr[ ISI_HEADER_OFFSET_SUBMESSAGEID ] == COMM_ISA_ENTITY_NOT_REACHABLE_RESP ) || 
    91         msgTmpPtr[ ISI_HEADER_OFFSET_SUBMESSAGEID ] != COMM_ISA_ENTITY_NOT_REACHABLE_RESP )
   183           ( notDeliveredMsgPtr[ ISI_HEADER_OFFSET_SUBMESSAGEID ] == COMM_SERVICE_NOT_IDENTIFIED_RESP ) ) )
    92         {
   184         {
    93         // Make channel opening request followinfg COMM specification: 000.026
   185         C_TRACE( ( _T( "DISICLTransceiver Not sending another CommIsaEntityNotReachableResp 0x%x 0x%x" ), &aNotDeliveredMessage, notDeliveredMsgPtr[ ISI_HEADER_OFFSET_SUBMESSAGEID ] ) );
    94         // Length is sixteen bytes.
   186         }
    95 		    TUint8 length( 16 );
   187     else
    96 		    TDes8& tempPtr = MemApi::AllocBlock( ISI_HEADER_SIZE + SIZE_COMMON_MESSAGE_COMM_ISA_ENTITY_NOT_REACHABLE_RESP );
   188         {
    97 		    ASSERT_RESET_ALWAYS( &tempPtr, ( EISICLTransceiverMemAllocFailure1 | EDISICLTransceiverTraceId << KClassIdentifierShift ) );
   189         // Follows COMM specification: 000.031
    98   	    ASSERT_RESET_ALWAYS( ISI_HEADER_SIZE + SIZE_COMMON_MESSAGE_COMM_ISA_ENTITY_NOT_REACHABLE_RESP > ISI_HEADER_OFFSET_MESSAGEID, ( EISICLTransceiverOverTheLimits | EDISICLTransceiverTraceId << KClassIdentifierShift ) );
   190         TUint8 length( ISI_HEADER_SIZE + SIZE_COMMON_MESSAGE_COMM_ISA_ENTITY_NOT_REACHABLE_RESP );
    99   	    TUint8* ptr = const_cast<TUint8*>( tempPtr.Ptr() );
   191         TDes8& respMsg = MemApi::AllocBlock( length );
   100   	    // We start to append from transaction id.
   192         ASSERT_RESET_ALWAYS( length > ISI_HEADER_OFFSET_MESSAGEID, ( EISICLTransceiverOverTheLimits | EDISICLTransceiverTraceId << KClassIdentifierShift ) );
   101   	    tempPtr.SetLength( ISI_HEADER_OFFSET_TRANSID );
   193         TUint8* respMsgPtr = const_cast<TUint8*>( respMsg.Ptr() );
   102   	    // Get the header until messageid from prev. message.
   194         // We start to append from transaction id.
   103 		    // Just turn receiver and sender device and object vice versa.
   195         respMsg.SetLength( ISI_HEADER_OFFSET_TRANSID );
   104 		    ptr[ ISI_HEADER_OFFSET_MEDIA ] = msgTmpPtr[ ISI_HEADER_OFFSET_MEDIA ];
   196         // Get the header until messageid from prev. message.
   105 		    SET_RECEIVER_DEV( ptr, GET_SENDER_DEV( aMessage ) );
   197         // Just turn receiver and sender device and object vice versa.
   106 		    SET_SENDER_DEV  ( ptr, GET_RECEIVER_DEV( aMessage ) );
   198         respMsgPtr[ ISI_HEADER_OFFSET_MEDIA ] = notDeliveredMsgPtr[ ISI_HEADER_OFFSET_MEDIA ];
   107 		    ptr[ ISI_HEADER_OFFSET_RESOURCEID ] = msgTmpPtr[ ISI_HEADER_OFFSET_RESOURCEID ];
   199         SET_RECEIVER_DEV( respMsgPtr, GET_SENDER_DEV( aNotDeliveredMessage ) );
   108 		    SET_LENGTH( ptr, length - PN_HEADER_SIZE );
   200         SET_SENDER_DEV  ( respMsgPtr, GET_RECEIVER_DEV( aNotDeliveredMessage ) );
   109 		    SET_RECEIVER_OBJ( ptr, GET_SENDER_OBJ( aMessage ) );
   201         respMsgPtr[ ISI_HEADER_OFFSET_RESOURCEID ] = notDeliveredMsgPtr[ ISI_HEADER_OFFSET_RESOURCEID ];
   110 		    SET_SENDER_OBJ( ptr, GET_RECEIVER_OBJ( aMessage ) );
   202         SET_LENGTH( respMsgPtr, ( length - PN_HEADER_SIZE ) );
   111 		    // Transactionid. Set to 0x01 since this is the first.
   203         SET_RECEIVER_OBJ( respMsgPtr, GET_SENDER_OBJ( aNotDeliveredMessage ) );
   112 		    tempPtr.Append( msgTmpPtr[ ISI_HEADER_OFFSET_TRANSID ] );
   204         SET_SENDER_OBJ( respMsgPtr, GET_RECEIVER_OBJ( aNotDeliveredMessage ) );
   113 		    // Message ID
   205         // Set from undelivered message
   114 		    tempPtr.Append( ISI_HEADER_OFFSET_MESSAGEID );
   206         respMsg.Append( notDeliveredMsgPtr[ ISI_HEADER_OFFSET_TRANSID ] );
   115 		    // Sub message ID.
   207         // Message Identifier
   116 		    tempPtr.Append( COMM_ISA_ENTITY_NOT_REACHABLE_RESP );
   208         respMsg.Append( COMMON_MESSAGE );
   117 		    // Not Delivered Message from original req.
   209         // Sub message Identifier.
   118 		    tempPtr.Append( msgTmpPtr[ ISI_HEADER_OFFSET_MESSAGEID ] );
   210         respMsg.Append( COMM_ISA_ENTITY_NOT_REACHABLE_RESP );
   119 		    // Status - COMM_ISA_ENTITY_NOT_AVAILABLE
   211         // Not Delivered Message from original message.
   120 		    tempPtr.Append( 0x00 );
   212         respMsg.Append( notDeliveredMsgPtr[ ISI_HEADER_OFFSET_MESSAGEID ] );
   121 		    // Filler
   213         // Status
   122 		    tempPtr.Append( 0x00 );
   214         respMsg.Append( COMM_ISA_ENTITY_NOT_AVAILABLE );//  different status in a case of device not existing
   123 		    // Filler
   215         // Filler
   124 		    tempPtr.Append( 0x00 );
   216         const TUint8 KFiller( 0x00 );
   125 		    // Filler
   217         respMsg.Append( KFiller );
   126             tempPtr.Append( 0x00 );
   218         // Filler
   127             error = RouteISIMessage( tempPtr );
   219         respMsg.Append( KFiller );
   128    		    }
   220         // Filler
   129 		else
   221         respMsg.Append( KFiller );
   130 		    {
   222         error = RouteISIMessage( respMsg, EFalse );
   131 		    C_TRACE( ( _T( "DISICLTransceiver Not sending another CommIsaEntityNotReachableResp" ) ) );
   223         // Programming error in this function if below assert is raised
   132 		    }
   224         ASSERT_RESET_ALWAYS( KErrNone == error, ( EISICLTransceiverCommIsaEntityNotReachableResp | EDISICLTransceiverTraceId << KClassIdentifierShift ) );        
   133     C_TRACE( ( _T( "DISICLTransceiver::SendCommIsaEntityNotReachableResp 0x%x<" ), &aMessage ) );
   225         }
       
   226     MemApi::DeallocBlock( aNotDeliveredMessage );
       
   227     C_TRACE( ( _T( "DISICLTransceiver::SendCommIsaEntityNotReachableResp 0x%x<" ), &aNotDeliveredMessage ) );
   134     return error;
   228     return error;
   135     }
   229 
   136 
   230     }
   137 TInt DISICLTransceiver::RouteISIMessage( TDes8& aMessage )
   231 
   138     {
   232 // This is called in 1...N thread contextes
   139 	 C_TRACE( ( _T( "DISICLTransceiver::RouteISIMessage 0x%x>" ), &aMessage ) );
   233 void DISICLTransceiver::ReceiveISIMessage(
   140 	TInt error( ValidateISIMessage( aMessage ) );
   234         const TDesC8& aMessage,
   141     TBool sendOk( EFalse );
   235         const TUint8 aTrxId
   142     if(GET_RECEIVER_DEV( aMessage ) == PN_DEV_OWN )
   236         )
   143         {
   237     {
   144         C_TRACE( ( _T( "DISIRouter msg to PN_DEV_APE" ) ) );
   238     C_TRACE( ( _T( "DISICLTransceiver::ReceiveMsg 0x%x 0x%x 0x%x>" ), this, &aMessage, aTrxId ) );
   145         sendOk = iRouter->Receive( aMessage, GET_RECEIVER_OBJ( aMessage ) );
   239     // Can only be called from thread context.
   146         C_TRACE( ( _T( "DISIRouter router sendOk %d" ), sendOk ) );
   240     ASSERT_THREAD_CONTEXT_ALWAYS( ( EISICLTransceiverNotThreadContext | EDISIUserChannelTraceId << KClassIdentifierShift ) );
       
   241     
       
   242     TUint8 txDevId = GET_SENDER_DEV( aMessage.Ptr() );    
       
   243     if ( DynamicDevice( txDevId ) )
       
   244         {
       
   245         TUint8 staticDevId(0);
       
   246         const TInt count( iShDevices.Count() );        
       
   247         TInt index(0);
       
   248         TBool staticDeviceFound(EFalse);
       
   249         MISIRouterLinkIf* Link = NULL;
       
   250         while( !staticDeviceFound && ( index < count ) )
       
   251             {
       
   252             C_TRACE( ( _T( "DISICLTransceiver::ReceiveMsg find static device for trx 0x%x index %d" ), aTrxId, index ) );
       
   253             DISIDevice* tmpDevice = iShDevices[ index ];
       
   254             ASSERT_RESET_ALWAYS( tmpDevice, ( EISICLTransceiverNULLPtr4 | EDISICLTransceiverTraceId << KClassIdentifierShift ) );
       
   255             tmpDevice->LockDeviceFM();
       
   256             Link = tmpDevice->GetLink();
       
   257             if( Link->GetTrxId() == aTrxId )
       
   258                 {                
       
   259                 staticDevId = tmpDevice->GetDeviceIdentifier();
       
   260                 tmpDevice->FreeDeviceFM();
       
   261                 C_TRACE( ( _T( "DISICLTransceiver::ReceiveMsg static device 0x%x trx 0x%x" ), this, &aMessage, aTrxId ) );
       
   262                 staticDeviceFound = ETrue;
       
   263                 }
       
   264             else
       
   265                 {
       
   266                 tmpDevice->FreeDeviceFM();
       
   267                 }
       
   268             index++;
       
   269             } 
       
   270 #ifdef USE_MEDIAAPI 		 
       
   271         if ( PN_DEV_PC == GET_SENDER_DEV( aMessage.Ptr() ))
       
   272             {
       
   273             C_TRACE( ( _T( "DISICLTransceiver::ReceiveMsg 0x%x 0x%x trx id = %d<" ), this, &aMessage, (Link->GetTrxId())  ) ); 
       
   274             iDevPcLastActiveTrxId = iDevPcLastSendTrxId;                  	
       
   275             iDevPcLastSendTrxId =	Link->GetTrxId();                       	    
       
   276             }		     
       
   277 #endif /* USE_MEDIAAPI */  			
       
   278         UpdateDynamicDeviceTable( txDevId, staticDevId );
       
   279         }
       
   280     // else static device. No need to save trxId
       
   281 
       
   282     iRxQueue->Add( aMessage );
       
   283     iRxQueueDfc->Enque();
       
   284     C_TRACE( ( _T( "DISICLTransceiver::ReceiveMsg 0x%x 0x%x 0x%x<" ), this, &aMessage, aTrxId ) );
       
   285     }
       
   286 
       
   287 void DISICLTransceiver::RxQueueDfc(
       
   288         TAny* aPtr  // Pointer to this object.
       
   289         )
       
   290     {
       
   291     C_TRACE( ( _T( "DISICLTransceiver::RxQueueDfc ->" ) ) );
       
   292     
       
   293     DISICLTransceiver& tmp = *reinterpret_cast<DISICLTransceiver*>( aPtr );
       
   294     if( tmp.iRxQueue->Count() > 0 )
       
   295         {
       
   296         TDes8& msg( tmp.iRxQueue->Get() );
       
   297         
       
   298         tmp.RouteISIMessage( msg, EFalse );
       
   299         // Check here too to avoid unnecessary dfc queuing.
       
   300         if( tmp.iRxQueue->Count() > 0 )
       
   301             {
       
   302             C_TRACE( ( _T( "DISICLTransceiver::RxQueueDfc enque RxQueueDfc" ) ) );
       
   303             tmp.iRxQueueDfc->Enque();
       
   304             }
       
   305         }
       
   306     C_TRACE( ( _T( "DISICLTransceiver::RxQueueDfc <-" ) ) );
       
   307     }
       
   308     
       
   309 
       
   310 TInt DISICLTransceiver::RouteISIMessage(
       
   311         TDes8& aMessage,
       
   312         TBool aDynamicSenderCheckNeeded
       
   313         )
       
   314     {
       
   315     C_TRACE( ( _T( "DISICLTransceiver::RouteISIMessage 0x%x 0x%x> len %d" ), &aMessage, aDynamicSenderCheckNeeded, aMessage.Length() ) );
       
   316     const TUint8* msgPtr = aMessage.Ptr();
       
   317     ISIMESSAGE_TRACE( aMessage );
       
   318     TInt error( ValidateISIMessage( aMessage ) );
       
   319     if( KErrNone != error )
       
   320         {
       
   321         TRACE_ASSERT_ALWAYS;
       
   322         C_TRACE( ( _T( "DISICLTransceiver::RouteISIMessage invalid message 0x%x" ), &aMessage ) );
       
   323         MemApi::DeallocBlock( aMessage );
   147         }
   324         }
   148     else
   325     else
   149         {
   326         {
   150          C_TRACE( ( _T( "DISIRouter msg to other device" ) ) );
   327         TBool sendOk( EFalse );
   151          TUint8 linkId = MapDeviceToMedia( GET_RECEIVER_DEV( aMessage ) );
   328         if ( aDynamicSenderCheckNeeded )// Save dynamic device ids from PN_DEV_OWN
   152 	       ASSERT_RESET_ALWAYS( linkId < EISIAmountOfMedias, ( EISICLTransceiverNotSupportedMedia | EDISICLTransceiverTraceId << KClassIdentifierShift ) );
   329             {
   153          MISIRouterLinkIf* link = iLinksArray[ linkId ];
   330             C_TRACE( ( _T( "DISICLTransceiver::RouteISIMessage from ISI Router" ) ) );
   154          ASSERT_RESET_ALWAYS( link, ( EISICLTransceiverNULLPtr | EDISICLTransceiverTraceId << KClassIdentifierShift ) );
   331             TUint8 txDeviceIdentifier = GET_SENDER_DEV( aMessage );
   155          sendOk = link->Send( aMessage );
   332             if ( DynamicDevice( txDeviceIdentifier ) )
   156          C_TRACE( ( _T( "DISIRouter link sendOk %d" ), sendOk ) );
   333                 {
   157          }   
   334                 C_TRACE( ( _T( "DISICLTransceiver::RouteISIMessage from ISI Router Dynamic Dev" ) ) );                
   158     if( !sendOk )
   335                 UpdateDynamicDeviceTable( txDeviceIdentifier, PN_DEV_OWN );
   159         {
   336 #ifndef USE_MEDIAAPI 				
   160         SendCommIsaEntityNotReachableResp( aMessage );
   337                 ASSERT_RESET_ALWAYS( txDeviceIdentifier == PN_DEV_PC, 0xdeaddead );// only supported PN_DEV_PC with EIscNokiaUsbPhonetLink
   161         MemApi::DeallocBlock( aMessage );
   338 #endif /* USE_MEDIAAPI */  					
   162         }
   339                 }
   163 	  C_TRACE( ( _T( "DISICLTransceiver::RouteISIMessage 0x%x<" ), &aMessage ) );
   340             }
       
   341 
       
   342         TUint8 rxDeviceIdentifier = GET_RECEIVER_DEV( aMessage );
       
   343         C_TRACE( ( _T( "DISICLTransceiver::RouteISIMessage rxDeviceIdentifier 0x%x" ), rxDeviceIdentifier ) );
       
   344         
       
   345         if ( DynamicDevice( rxDeviceIdentifier ) )
       
   346             {            
       
   347             DynamicToStaticDevice( rxDeviceIdentifier );            
       
   348             C_TRACE( ( _T( "DISICLTransceiver::RouteISIMessage rxDeviceIdentifier after 0x%x" ), rxDeviceIdentifier ) );
       
   349             }
       
   350 
       
   351 
       
   352         if( rxDeviceIdentifier == PN_DEV_OWN )
       
   353             {
       
   354             C_TRACE( ( _T( "DISICLTransceiver::RouteISIMessage PN_DEV_OWN 0x%x" ), &aMessage ) );
       
   355             TUint16 objId(0xffff);
       
   356 #ifndef USE_MEDIAAPI 
       
   357             if ( GET_RECEIVER_DEV( aMessage ) == PN_DEV_PC )
       
   358                 {
       
   359                 C_TRACE( ( _T( "DISICLTransceiver::RouteISIMessage to PN_DEV_PC in PN_DEV_OWN" )) );
       
   360                 objId = EIscNokiaUsbPhonetLink;
       
   361                 }
       
   362             else
       
   363                 {
       
   364                 objId = GET_RECEIVER_OBJ( aMessage );
       
   365                 }
       
   366 #endif /* USE_MEDIAAPI */  					
       
   367 #ifdef USE_MEDIAAPI 
       
   368             objId = GET_RECEIVER_OBJ( aMessage );
       
   369 #endif /* USE_MEDIAAPI */  				
       
   370             sendOk = iShRouter.Receive( aMessage, objId );
       
   371             C_TRACE( ( _T( "DISICLTransceiver::RouteISIMessage PN_DEV_OWN 0x%x ok %d" ), &aMessage, sendOk ) );
       
   372             }        
       
   373         else
       
   374             {
       
   375             C_TRACE( ( _T( "DISICLTransceiver::RouteISIMessage Not PN_DEV_OWN 0x%x" ), &aMessage ) );
       
   376             MISIRouterLinkIf* link = NULL;
       
   377 
       
   378 
       
   379             const TInt count( iShDevices.Count() );
       
   380             for( TInt index( 0 ); index < count; index++ )
       
   381                 {
       
   382                 DISIDevice* tmpDevice = iShDevices[ index ];
       
   383                 ASSERT_RESET_ALWAYS( tmpDevice, ( EISICLTransceiverNULLPtr4 | EDISICLTransceiverTraceId << KClassIdentifierShift ) );
       
   384                 tmpDevice->LockDeviceFM();
       
   385                 if( tmpDevice->GetDeviceIdentifier() == rxDeviceIdentifier ) 
       
   386                     {
       
   387                     link = tmpDevice->GetLink();
       
   388                     tmpDevice->FreeDeviceFM();
       
   389 #ifndef USE_MEDIAAPI 					
       
   390                     sendOk = link->Send( aMessage );
       
   391                     break;
       
   392 #endif /* USE_MEDIAAPI */  	
       
   393 #ifdef USE_MEDIAAPI 						
       
   394                     if ( GET_RECEIVER_DEV( aMessage ) == PN_DEV_PC )
       
   395                         {
       
   396                         C_TRACE( ( _T( "DISICLTransceiver::RouteISIMessage PN_DEV_PC %d, %d" ), link->GetTrxId(), iDevPcLastSendTrxId ) ); 	
       
   397                         if(iDevPcLastSendTrxId < EAmountOfTrxs)
       
   398                             {	
       
   399                             if ( link->GetTrxId() ==	iDevPcLastSendTrxId )
       
   400                                 {
       
   401                                 if (link->StateConnected())
       
   402                                     {
       
   403                                     C_TRACE( ( _T( "DISICLTransceiver::RouteISIMessage PN_DEV_PC %d, Msg mediaid 0x%x" ), link->GetTrxId(), msgPtr[ ISI_HEADER_OFFSET_MEDIA ] ) ); 
       
   404                                     sendOk = link->Send( aMessage );
       
   405                                     break;
       
   406                                     }
       
   407                                 }
       
   408                             }    
       
   409                         else
       
   410                             {
       
   411                             break;	
       
   412                             }		   	
       
   413 		                 }
       
   414                     else
       
   415                     	{    			
       
   416                         sendOk = link->Send( aMessage );
       
   417                         break;
       
   418                         }
       
   419 #endif /* USE_MEDIAAPI */  							
       
   420                     }    
       
   421                 else
       
   422                     {
       
   423                     tmpDevice->FreeDeviceFM();
       
   424                     }
       
   425                 }
       
   426             C_TRACE( ( _T( "DISICLTransceiver::RouteISIMessage Not PN_DEV_OWN ok %d" ), &aMessage, sendOk ) );
       
   427             }
       
   428         if( !sendOk )
       
   429             {
       
   430             TRACE_ASSERT_ALWAYS;
       
   431             error = SendCommIsaEntityNotReachableResp( aMessage );
       
   432             }
       
   433         }
       
   434     C_TRACE( ( _T( "DISICLTransceiver::RouteISIMessage 0x%x<" ), &aMessage ) );
   164     return error;
   435     return error;
       
   436     }
       
   437 
       
   438 void DISICLTransceiver::GetDeviceConnectionStates(
       
   439         RArray<TUint8>& aDeviceIdentifierList,
       
   440         const TBool aConnectedDevice
       
   441         )
       
   442     {
       
   443     C_TRACE( ( _T( "DISICLTransceiver::GetDeviceConnectionStates 0x%x 0x%x>" ), &aDeviceIdentifierList, aConnectedDevice ) );
       
   444 
       
   445     const TInt count( iShDevices.Count() );
       
   446     for( TInt index( 0 ); index < count; index++ )
       
   447         {
       
   448         DISIDevice* tmpDevice = iShDevices[ index ];
       
   449         ASSERT_RESET_ALWAYS( tmpDevice, ( EISICLTransceiverNULLPtr3 | EDISICLTransceiverTraceId << KClassIdentifierShift ) );
       
   450         tmpDevice->LockDeviceFM();
       
   451         if( tmpDevice->GetDeviceState() == aConnectedDevice )
       
   452             {
       
   453             const TUint8 deviceIdentifier( tmpDevice->GetDeviceIdentifier() );
       
   454             tmpDevice->FreeDeviceFM();
       
   455             aDeviceIdentifierList.Append( deviceIdentifier );
       
   456             }
       
   457         else
       
   458             {
       
   459             tmpDevice->FreeDeviceFM();
       
   460             }
       
   461         }
       
   462     C_TRACE( ( _T( "DISICLTransceiver::GetDeviceConnectionStates 0x%x 0x%x<" ), &aDeviceIdentifierList, aConnectedDevice ) );
   165     }
   463     }
   166 
   464 
   167 // KErrBadDescriptor, if message length too small
   465 // KErrBadDescriptor, if message length too small
   168 // KErrUnderFlow, if message length too big.
   466 // KErrUnderFlow, if message length too big.
   169 // KErrCouldNotConnect, if receiver object is out of scope.
   467 // KErrCouldNotConnect, if receiver object is out of scope.
   170 TInt DISICLTransceiver::ValidateISIMessage(
   468 TInt DISICLTransceiver::ValidateISIMessage(
   171         TDes8& aMessage
   469         TDes8& aMessage
   172         )
   470         )
   173     {
   471     {
       
   472 
   174     C_TRACE( ( _T( "DISICLTransceiver::ValidateISIMessage 0x%x>" ), &aMessage ) );
   473     C_TRACE( ( _T( "DISICLTransceiver::ValidateISIMessage 0x%x>" ), &aMessage ) );
   175     const TUint16 descLength( aMessage.Length() );
   474     const TUint16 descLength( aMessage.Length() );
   176     TInt msgOk( KErrNone );
   475     TInt msgOk( KErrNone );
   177     msgOk = ( ISI_HEADER_OFFSET_MESSAGEID >= descLength ) ? KErrBadDescriptor : msgOk;
   476     msgOk = ( ISI_HEADER_OFFSET_MESSAGEID >= descLength ) ? KErrBadDescriptor : msgOk;
   178     TRACE_ASSERT_INFO( msgOk == KErrNone, msgOk );
   477     TRACE_ASSERT_INFO( msgOk == KErrNone, msgOk );
   186     msgOk = ( ( msgOk == KErrNone && isiMsgLength > KMaxISIMsgSize ) ? KErrUnderflow : msgOk );
   485     msgOk = ( ( msgOk == KErrNone && isiMsgLength > KMaxISIMsgSize ) ? KErrUnderflow : msgOk );
   187     TRACE_ASSERT_INFO( msgOk == KErrNone, msgOk );
   486     TRACE_ASSERT_INFO( msgOk == KErrNone, msgOk );
   188     // If the ISI message length with PN_HEADER_SIZE is less or equal than ISI_HEADER_OFFSET_MESSAGEID.
   487     // If the ISI message length with PN_HEADER_SIZE is less or equal than ISI_HEADER_OFFSET_MESSAGEID.
   189     msgOk = ( ( msgOk == KErrNone && isiMsgLength <= ISI_HEADER_OFFSET_MESSAGEID ) ? KErrUnderflow : msgOk );
   488     msgOk = ( ( msgOk == KErrNone && isiMsgLength <= ISI_HEADER_OFFSET_MESSAGEID ) ? KErrUnderflow : msgOk );
   190     TRACE_ASSERT_INFO( msgOk == KErrNone, msgOk );
   489     TRACE_ASSERT_INFO( msgOk == KErrNone, msgOk );
   191     TRACE_ASSERT_INFO( msgOk == KErrNone, msgOk );
       
   192     TRACE_ASSERT_INFO( msgOk == KErrNone, isiMsgLength );
   490     TRACE_ASSERT_INFO( msgOk == KErrNone, isiMsgLength );
   193     TRACE_ASSERT_INFO( msgOk == KErrNone, descLength );
   491     TRACE_ASSERT_INFO( msgOk == KErrNone, descLength );
   194     TRACE_ASSERT_INFO( msgOk == KErrNone, msgOk );
       
   195     C_TRACE( ( _T( "DISICLTransceiver::ValidateISIMessage %d<" ), msgOk ) );
   492     C_TRACE( ( _T( "DISICLTransceiver::ValidateISIMessage %d<" ), msgOk ) );
   196     return msgOk;
   493     return msgOk;
   197     }
   494     }
   198 
   495 
   199 TUint8 DISICLTransceiver::MapDeviceToMedia(
   496 // NOTE!! Called with FM held. Not allowed to block or nothing. Not even print traces!
   200         const TUint8 aDevice
   497 // Called in N Thread context
   201         )
   498 void DISICLTransceiver::StateChanged(
   202     {
   499         // None
   203     C_TRACE( ( _T( "DISICLTransceiver::MapDeviceToMedia aDevice %d>" ), aDevice ) );
   500         )
   204     TUint8 media( KErrNone );
   501     {
   205     switch( aDevice )
   502 
   206         {
   503     iShStateChangedDfc->Enque();
       
   504 
       
   505     }
       
   506 
       
   507 void DISICLTransceiver::StateChangedDfc(
       
   508         TAny* aPtr
       
   509         )
       
   510     {
       
   511     C_TRACE( ( _T( "DISICLTransceiver::StateChangedDfc>" ) ) );
       
   512     DISICLTransceiver* self = reinterpret_cast<DISICLTransceiver*>( aPtr );
       
   513     ASSERT_RESET_ALWAYS( self, ( EISICLTransceiverNULLPtr5 | EDISICLTransceiverTraceId << KClassIdentifierShift ) );
       
   514     self->ReadStateChanges();
       
   515     C_TRACE( ( _T( "DISICLTransceiver::StateChangedDfc<" ) ) );
       
   516     }
       
   517 
       
   518 void DISICLTransceiver::ReadStateChanges(
       
   519         // None
       
   520         )
       
   521     {
       
   522 
       
   523     C_TRACE( ( _T( "DISICLTransceiver::ReadStateChanges>" ) ) );
       
   524 
       
   525     const TInt count( iShDevices.Count() );
       
   526     for( TInt index( 0 ); index < count; index++ )
       
   527         {
       
   528         DISIDevice* tmpDevice = iShDevices[ index ];
       
   529         ASSERT_RESET_ALWAYS( tmpDevice, ( EISICLTransceiverNULLPtr6 | EDISICLTransceiverTraceId << KClassIdentifierShift ) );
       
   530         tmpDevice->LockDeviceFM();
       
   531         const TBool connected = tmpDevice->GetDeviceState();//  tee paremmaksi
       
   532 	
       
   533 #ifdef USE_MEDIAAPI 		
       
   534         MISIRouterLinkIf* link = NULL;     
       
   535         link = tmpDevice->GetLink();
       
   536 #endif /* USE_MEDIAAPI */                       	
       
   537         if( connected != tmpDevice->GetDeviceOldState() )
       
   538             {
       
   539             tmpDevice->SetDeviceOldState( connected );
       
   540             const TUint8 deviceIdentifier = tmpDevice->GetDeviceIdentifier();
       
   541             tmpDevice->FreeDeviceFM();
       
   542 #ifdef USE_MEDIAAPI 
       
   543             C_TRACE( ( _T( "DISICLTransceiver::ReadStateChanges trxid 0x%x state changed>" ),link->GetTrxId() ) );   
       
   544             if( (link->GetTrxId() == iDevPcLastSendTrxId) && (!connected) )
       
   545                 {
       
   546                 C_TRACE( ( _T( "DISICLTransceiver::ReadStateChanges trxid 0x%x disconneted>" ),link->GetTrxId() ) );   	
       
   547          	      iDevPcLastSendTrxId = iDevPcLastActiveTrxId;
       
   548          	      iDevPcLastActiveTrxId = EAmountOfTrxs;  //put a maxvalue	
       
   549                 } 
       
   550 #endif /* USE_MEDIAAPI */   					 
       
   551             iRouterService->SendDeviceConnectionStateChangedInd( connected, deviceIdentifier );
       
   552             }
       
   553         else
       
   554             {
       
   555             tmpDevice->FreeDeviceFM();
       
   556             }
       
   557         }
       
   558     C_TRACE( ( _T( "DISICLTransceiver::ReadStateChanges<" ) ) );
       
   559     }
       
   560 
       
   561 TBool DISICLTransceiver::DynamicDevice( const TUint8 aDevId )
       
   562     {
       
   563     C_TRACE( ( _T( "DISICLTransceiver::DynamicDevice 0x%x>" ), aDevId ) );
       
   564     TBool dynamicDevice(EFalse);
       
   565     switch( aDevId )
       
   566         {        
   207         case PN_DEV_MODEM:
   567         case PN_DEV_MODEM:
   208             {
   568         case PN_DEV_DUMMYIST:
   209             media = EISIMediaSharedMemory;
   569         case PN_DEV_OWN:
       
   570             {
       
   571             //already set as EFalse
   210             break;
   572             break;
   211             }
   573             }
   212         case PN_DEV_DUMMYIST:
   574         default:
   213             {
   575             {
   214             media = EISIMediaTest;
   576             dynamicDevice = ETrue;
   215             break;
   577             break;
   216             }
   578             }
   217         // Not supported device
   579         }
   218         default:
   580     C_TRACE( ( _T( "DISICLTransceiver::DynamicDevice 0x%x<" ), dynamicDevice ) );
   219             {
   581     return dynamicDevice;
   220            	ASSERT_RESET_ALWAYS( 0, ( EISICLTransceiverNotSupportedDevice | EDISICLTransceiverTraceId << KClassIdentifierShift ) );
   582     }
       
   583     
       
   584 void DISICLTransceiver::UpdateDynamicDeviceTable( const TUint8 aDynamicDevId, const TUint8 aStaticDevId )
       
   585     {
       
   586     C_TRACE( ( _T( "DISICLTransceiver::UpdateDynamicDeviceTable 0x%x 0x%x>" ), aDynamicDevId, aStaticDevId) );
       
   587     TBool deviceExist(EFalse);
       
   588     TInt count(iDynamicDeviceTable.Count());
       
   589     TInt err( Kern::MutexWait( *iDynamicDeviceTableMutex ) );
       
   590     ASSERT_RESET_ALWAYS( ( err == KErrNone ), ( EISICLTransceiverMutexWaitFailed2 | EDISICLTransceiverTraceId << KClassIdentifierShift ) );
       
   591     for( TUint8 i = 0; i < count; i++ )
       
   592         {
       
   593         C_TRACE( ( _T( "DISICLTransceiver::UpdateDynamicDeviceTable find dynamic device %d" ), i) );
       
   594         if( iDynamicDeviceTable[ i ]->iDynamicDevId == aDynamicDevId )
       
   595             {                    
       
   596             C_TRACE( ( _T( "DISICLTransceiver::UpdateDynamicDeviceTable dyn dev exist i = %d aDynamicDevId 0x%x staticDevId 0x%x previous 0x%x" ), i, iDynamicDeviceTable[ i ]->iDynamicDevId, aStaticDevId, iDynamicDeviceTable[ i ]->iStaticDevId ) );
       
   597             iDynamicDeviceTable[ i ]->iStaticDevId = aStaticDevId;
       
   598             deviceExist = ETrue;
   221             break;
   599             break;
   222             }
   600             }
   223         }
   601         }
   224     C_TRACE( ( _T( "DISICLTransceiver::MapDeviceToMedia media %d<" ), media ) );
   602         
   225     return media;
   603     if ( !deviceExist )
   226     }
   604         {
   227 
   605         C_TRACE( ( _T( "DISICLTransceiver::UpdateDynamicDeviceTable new dynamic device added 0x%x 0x%x" ), aDynamicDevId, aStaticDevId ) );
       
   606         iDynamicDeviceTable.Append( new TDynamicDevice( aDynamicDevId, aStaticDevId ) );
       
   607         }
       
   608     Kern::MutexSignal( *iDynamicDeviceTableMutex );
       
   609     C_TRACE( ( _T( "DISICLTransceiver::UpdateDynamicDeviceTable 0x%x 0x%x<" ), aDynamicDevId, aStaticDevId) );
       
   610     }
       
   611 
       
   612 void DISICLTransceiver::DynamicToStaticDevice( TUint8& aRxDev )
       
   613     {
       
   614     C_TRACE( ( _T( "DISICLTransceiver::DynamicToStaticDevice aRxDev>" ), &aRxDev ) );
       
   615     TInt err( Kern::MutexWait( *iDynamicDeviceTableMutex ) );
       
   616     ASSERT_RESET_ALWAYS( ( err == KErrNone ), ( EISICLTransceiverMutexWaitFailed | EDISICLTransceiverTraceId << KClassIdentifierShift ) );
       
   617     for( TUint8 i = 0; i < iDynamicDeviceTable.Count(); i++ )
       
   618         {
       
   619         if( iDynamicDeviceTable[ i ]->iDynamicDevId == aRxDev )
       
   620             {                    
       
   621             C_TRACE( ( _T( "DISICLTransceiver::DynamicToStaticDevice dyn dev exist i = %d iDynamicDevId 0x%x iStaticDevId 0x%x" ), i, iDynamicDeviceTable[ i ]->iDynamicDevId, iDynamicDeviceTable[ i ]->iStaticDevId) );
       
   622             aRxDev = iDynamicDeviceTable[ i ]->iStaticDevId;
       
   623             break;
       
   624             }
       
   625         }
       
   626     Kern::MutexSignal( *iDynamicDeviceTableMutex );
       
   627     C_TRACE( ( _T( "DISICLTransceiver::DynamicToStaticDevice aRxDev<" ), &aRxDev ) );
       
   628     }
       
   629         
       
   630 
       
   631 DISICLTransceiver::DISIDevice::DISIDevice(
       
   632         const TUint8 aDeviceIdentifier,
       
   633         MISIRouterLinkIf* aLink
       
   634         )
       
   635     {
       
   636     C_TRACE( ( _T( "DISICLTransceiver::DISIDevice::DISIDevice 0x%x 0x%x 0x%x>" ), aDeviceIdentifier, aLink ) );
       
   637     iShDeviceIdentifier = aDeviceIdentifier;
       
   638     iShOldDeviceConnectedState = EFalse;
       
   639     ASSERT_RESET_ALWAYS( aLink, ( EISICLTransceiverNULLPtr2 | EDISICLTransceiverTraceId << KClassIdentifierShift ) );
       
   640     iShLink = aLink;
       
   641     iShDeviceMutex = new NFastMutex();
       
   642     ASSERT_RESET_ALWAYS( iShDeviceMutex, EISICLTransceiverNULLPtr6 | EDISICLTransceiverTraceId << KClassIdentifierShift );
       
   643     C_TRACE( ( _T( "DISICLTransceiver::DISIDevice::DISIDevice<" ) ) );
       
   644     }
       
   645 
       
   646 DISICLTransceiver::DISIDevice::~DISIDevice()
       
   647     {
       
   648     C_TRACE( ( _T( "DISICLTransceiver::DISIDevice::~DISIDevice>" ) ) );
       
   649     iShLink->Release();
       
   650     iShLink = NULL;
       
   651     // If not exists faulted already.
       
   652     delete iShDeviceMutex;
       
   653     iShDeviceMutex = NULL;
       
   654     C_TRACE( ( _T( "DISICLTransceiver::DISIDevice::~DISIDevice<" ) ) );
       
   655     }
       
   656 
       
   657 MISIRouterLinkIf* DISICLTransceiver::DISIDevice::GetLink()
       
   658     {
       
   659 //    C_TRACE( ( _T( "DISICLTransceiver::DISIDevice::GetLink<> 0x%x" ), iShLink ) );
       
   660     return iShLink;
       
   661     }
       
   662 
       
   663 TUint8 DISICLTransceiver::DISIDevice::GetDeviceIdentifier()
       
   664     {
       
   665 //    C_TRACE( ( _T( "DISICLTransceiver::DISIDevice::GetDeviceIdentifier<> 0x%x" ), iShDeviceIdentifier ) );
       
   666     return iShDeviceIdentifier;
       
   667     }
       
   668 
       
   669 TBool DISICLTransceiver::DISIDevice::GetDeviceState()
       
   670     {
       
   671 //    C_TRACE( ( _T( "DISICLTransceiver::DISIDevice::GetDeviceState<>" ) ) );
       
   672     return iShLink->StateConnected();
       
   673     }
       
   674 
       
   675 TBool DISICLTransceiver::DISIDevice::GetDeviceOldState()
       
   676     {
       
   677 //    C_TRACE( ( _T( "DISICLTransceiver::DISIDevice::GetDeviceOldState<> 0x%x" ), iShOldDeviceConnectedState ) );
       
   678     return iShOldDeviceConnectedState;
       
   679     }
       
   680 
       
   681 void DISICLTransceiver::DISIDevice::SetDeviceOldState(
       
   682         TBool aConnected
       
   683         )
       
   684    {
       
   685 //   C_TRACE( ( _T( "DISICLTransceiver::DISIDevice::SetDeviceOldState<> 0x%x 0x%x" ), iShOldDeviceConnectedState, aConnected ) );
       
   686    iShOldDeviceConnectedState = aConnected;    
       
   687    }
       
   688 
       
   689 void DISICLTransceiver::DISIDevice::LockDeviceFM(
       
   690         // None
       
   691         )
       
   692     {
       
   693     C_TRACE( ( _T( "DISICLTransceiver::DISIDevice::LockDeviceFM<>" ) ) );    
       
   694     NKern::FMWait( iShDeviceMutex );
       
   695     }
       
   696 
       
   697 void DISICLTransceiver::DISIDevice::FreeDeviceFM(
       
   698         // None
       
   699         )
       
   700     {
       
   701     NKern::FMSignal( iShDeviceMutex );
       
   702     C_TRACE( ( _T( "DISICLTransceiver::DISIDevice::FreeDeviceFM<>" ) ) );    
       
   703     }