adaptationlayer/dataport/dataport_csy/src/dpmif.cpp
changeset 0 63b37f68c1ce
child 5 8ccc39f9d787
equal deleted inserted replaced
-1:000000000000 0:63b37f68c1ce
       
     1 /*
       
     2 * Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <tisi.h>
       
    22 #include <nsisi.h>      // isi name
       
    23 #include <pipeisi.h>    // isi pipe
       
    24 #include <pipe_sharedisi.h>
       
    25 
       
    26 #include "dpdef.h"      // dataport definitions
       
    27 #include "dpdataport.h" // dataport main and c32 interface
       
    28 #include "dpmif.h"      // message interface mif
       
    29 #include "dppif.h"      // pipe interface pif
       
    30 #include "dpcommpep.h"  // comm pep interface. interaction with mif
       
    31 #include "dplog.h"      // dataport logging
       
    32 #include "osttracedefinitions.h"
       
    33 #ifdef OST_TRACE_COMPILER_IN_USE
       
    34 #include "dpmiftraces.h"
       
    35 #endif
       
    36 
       
    37 
       
    38 // EXTERNAL DATA STRUCTURES
       
    39 // none
       
    40 
       
    41 // EXTERNAL FUNCTION PROTOTYPES
       
    42 // none
       
    43 
       
    44 // CONSTANTS
       
    45 #ifdef OST_TRACE_COMPILER_IN_USE
       
    46 const TUint8 KBufferForOSTTracing = 100;
       
    47 #endif
       
    48 
       
    49 // MACROS
       
    50 // none
       
    51 
       
    52 // LOCAL CONSTANTS AND MACROS
       
    53 // none
       
    54 
       
    55 // MODULE DATA STRUCTURES
       
    56 // none
       
    57 
       
    58 // LOCAL FUNCTION PROTOTYPES
       
    59 // none
       
    60 
       
    61 // ============================= LOCAL FUNCTIONS ===============================
       
    62 
       
    63 // Local function for printing ISI message in OST
       
    64 #ifdef OST_TRACE_COMPILER_IN_USE
       
    65 static void OstPrintIsiMessage( const TDesC8& aBuf )
       
    66     {
       
    67     _LIT( KTraceSpace, " " );
       
    68     TInt length = aBuf.Length();
       
    69     TBuf8<KBufferForOSTTracing> trace_msg;
       
    70     TUint counter = 1;
       
    71     TBool firstTime = ETrue;
       
    72     for ( TInt i = 0; i < length; i++ )
       
    73         {
       
    74         trace_msg.AppendNumFixedWidthUC( aBuf[i], EHex, 2 );
       
    75         trace_msg.Append( KTraceSpace );
       
    76 
       
    77         if ( ( counter > 24 ) ||     // 25 bytes / line
       
    78            ( ( i + 1 ) == length ) ) // All bytes collected
       
    79             {
       
    80             if ( ( firstTime ) &&
       
    81                ( ( i + 1 ) == length ) ) // All bytes collected and traced
       
    82                 {
       
    83                 firstTime = EFalse;
       
    84                 OstTraceExt1( TRACE_NORMAL, DUP_OSTPRINTISIMESSAGE, "CDpMif:: ==> [ %s]", trace_msg );
       
    85                 trace_msg.SetLength( 0 );
       
    86                 }
       
    87             else if ( firstTime ) // 1st line of the trace
       
    88                 {
       
    89                 firstTime = EFalse;
       
    90                 OstTraceExt1( TRACE_NORMAL, DUP1_OSTPRINTISIMESSAGE, "CDpMif:: ==> [ %s", trace_msg );
       
    91                 trace_msg.SetLength( 0 );
       
    92                 }
       
    93             else if ( ( i + 1 ) == length ) // The last line
       
    94                 {
       
    95                 OstTraceExt1( TRACE_NORMAL, DUP2_OSTPRINTISIMESSAGE, "CDpMif:: ==>   %s]", trace_msg );
       
    96                 trace_msg.SetLength( 0 );
       
    97                 }
       
    98             else // just print bytes
       
    99                 {
       
   100                 OstTraceExt1( TRACE_NORMAL, DUP3_OSTPRINTISIMESSAGE, "CDpMif:: ==>   %s", trace_msg );
       
   101                 trace_msg.SetLength( 0 );
       
   102                 }
       
   103             counter = 0;
       
   104             }
       
   105         counter++;
       
   106         }
       
   107     }
       
   108 
       
   109 #else // OST_TRACE_COMPILER_IN_USE
       
   110 
       
   111 #define OstPrintIsiMessage(x)
       
   112 
       
   113 #endif // OST_TRACE_COMPILER_IN_USE
       
   114 
       
   115 
       
   116 
       
   117 // ============================ MEMBER FUNCTIONS ===============================
       
   118 
       
   119 // ---------------------------------------------------------
       
   120 // CDpMif::NewL
       
   121 // Static constructor.
       
   122 // ---------------------------------------------------------
       
   123 CDpMif* CDpMif::NewL(
       
   124     CDpDataPort& aDataPort )
       
   125     {
       
   126     OstTrace0( TRACE_NORMAL, CDPMIF_NEWL, "CDpMif::NewL" );
       
   127     LOGM(" CDpMif::NewL");
       
   128 
       
   129     CDpMif* self = new ( ELeave ) CDpMif( aDataPort );
       
   130 
       
   131     CleanupStack::PushL( self );
       
   132     self->ConstructL();
       
   133     CleanupStack::Pop( self );
       
   134 
       
   135     return self;
       
   136     }
       
   137 
       
   138 // ---------------------------------------------------------
       
   139 // CDpMif::ConstructL
       
   140 // Symbian 2nd phase constructor.
       
   141 // ---------------------------------------------------------
       
   142 void CDpMif::ConstructL()
       
   143     {
       
   144     OstTrace0( TRACE_NORMAL, CDPMIF_CONSTRUCTL, "CDpMif::ConstructL" );
       
   145     LOGM(" CDpMif::ConstructL");
       
   146 
       
   147     iMsgReceiveBuffer = HBufC8::NewL( ISI_HEADER_SIZE + KDpMaxMsgReceiveSize );
       
   148     _LIT(KPanicStr, "Dataport - CDpMif::ConstructL");
       
   149     __ASSERT_ALWAYS( iMsgReceiveBuffer,
       
   150         User::Panic( KPanicStr, KErrNoMemory ) );
       
   151     iReceiveMessage.Set( iMsgReceiveBuffer->Des() );
       
   152     iReceiveMessage.SetLength( 0 );
       
   153 
       
   154     iMessageSendBuffer = HBufC8::NewL( ISI_HEADER_SIZE + KDpMaxMsgSendSize );
       
   155     __ASSERT_ALWAYS( iMessageSendBuffer,
       
   156         User::Panic( KPanicStr, KErrNoMemory ) );
       
   157     iSendMessage.Set( iMessageSendBuffer->Des() );
       
   158     iSendMessage.SetLength( 0 );
       
   159     }
       
   160 
       
   161 // ---------------------------------------------------------
       
   162 // CDpMif::CDpMif
       
   163 // C++ default constructor.
       
   164 // ---------------------------------------------------------
       
   165 CDpMif::CDpMif(
       
   166     CDpDataPort& aDataPort ) :
       
   167     CActive( KDpMifPriority ),
       
   168     iDataPort( aDataPort ),
       
   169     iPifDcs( iDataPort.Pif() ),
       
   170     iCommPep( iDataPort.CommPep() ),
       
   171     iMsgReceiveBuffer( NULL ),
       
   172     iReceiveMessage( NULL, 0 ),
       
   173     iMessageSendBuffer( NULL ),
       
   174     iSendMessage( NULL, 0 )
       
   175     {
       
   176     OstTrace0( TRACE_NORMAL, CDPMIF_CDPMIF, "CDpMif::CDpMif" );
       
   177     LOGM(" CDpMif::CDpMif");
       
   178 
       
   179     CActiveScheduler::Add( this );
       
   180     }
       
   181 
       
   182 // ---------------------------------------------------------
       
   183 // CDpMif::~CDpMif
       
   184 // Destructor
       
   185 // ---------------------------------------------------------
       
   186 CDpMif::~CDpMif()
       
   187     {
       
   188     OstTrace0( TRACE_NORMAL, DUP1_CDPMIF_CDPMIF, "CDpMif::~CDpMif" );
       
   189     LOGM(" CDpMif::~CDpMif");
       
   190 
       
   191     if ( iMsgReceiveBuffer )
       
   192         {
       
   193         delete iMsgReceiveBuffer;
       
   194         }
       
   195     //no else
       
   196     iMsgReceiveBuffer = NULL;
       
   197     iReceiveMessage.Set( NULL, 0, 0 );
       
   198 
       
   199     if ( iMessageSendBuffer )
       
   200         {
       
   201         delete iMessageSendBuffer;
       
   202         }
       
   203     //no else
       
   204     iMessageSendBuffer = NULL;
       
   205     iSendMessage.Set( NULL, 0, 0 );
       
   206     }
       
   207 
       
   208 // ---------------------------------------------------------
       
   209 // CDpMif::RunL
       
   210 // This method handles received message from Isc Api and
       
   211 // renews read from Isc Api.
       
   212 // ---------------------------------------------------------
       
   213 //
       
   214 void CDpMif::RunL()
       
   215     {
       
   216     OstTrace0( TRACE_NORMAL, CDPMIF_RUNL, "CDpMif::RunL" );
       
   217     LOGM1("CDpMif::RunL - Port %d", iDataPort.PortUnit() );
       
   218 
       
   219     // we are always signaled from PhoNet ReceiveMessage
       
   220     if ( KErrNoMemory == iStatus.Int() )
       
   221         {
       
   222         LOGM(" ==> KErrNoMemory");
       
   223         OstTrace0( TRACE_NORMAL, DUP1_CDPMIF_RUNL, "CDpMif:: ==> KErrNoMemory" );
       
   224 
       
   225         // deallocate current message
       
   226         if ( iMsgReceiveBuffer )
       
   227             {
       
   228             delete iMsgReceiveBuffer;
       
   229             iMsgReceiveBuffer = NULL;
       
   230             iReceiveMessage.Set( NULL, 0, 0 );
       
   231             }
       
   232         //no else
       
   233 
       
   234         // ISA Handle receive
       
   235         // Trying to allocate a new message
       
   236         iMsgReceiveBuffer = HBufC8::NewL( ISI_HEADER_SIZE + iLen );
       
   237         _LIT( KPanicStr, "Dataport - CDpMif::RunL" );
       
   238         __ASSERT_ALWAYS( iMsgReceiveBuffer,
       
   239             User::Panic( KPanicStr, KErrNoMemory ) );
       
   240         iReceiveMessage.Set( iMsgReceiveBuffer->Des() );
       
   241         iLen = 0;
       
   242 
       
   243         if ( !IsActive() )
       
   244             {
       
   245             iDataPort.ISAHandle().Receive(
       
   246                 iStatus, iReceiveMessage, iLen );
       
   247 
       
   248             SetActive();
       
   249             }
       
   250         //no else
       
   251         }
       
   252      else
       
   253         {
       
   254         OstTrace0( TRACE_NORMAL, DUP2_CDPMIF_RUNL, "CDpMif:: ==> ISI-message received" );
       
   255         OstPrintIsiMessage( iReceiveMessage );
       
   256 
       
   257         LOGM(" ==> ISI-message received");
       
   258         LOGMESSAGE( iReceiveMessage );
       
   259 
       
   260         TIsiReceiveC receivedMsg( iReceiveMessage );
       
   261 
       
   262         TUint8 resource_id( receivedMsg.Get8bit(
       
   263             ISI_HEADER_OFFSET_RESOURCEID ) );
       
   264         TUint8 message_id( receivedMsg.Get8bit(
       
   265             ISI_HEADER_OFFSET_MESSAGEID ) );
       
   266 
       
   267         switch ( resource_id )
       
   268             {
       
   269             case PN_NAMESERVICE:
       
   270                 {
       
   271                 switch ( message_id )
       
   272                     {
       
   273                     case PNS_NAME_ADD_RESP:
       
   274                         {
       
   275                         LOG(" ==> PNS_NAME_ADD_RESP received");
       
   276                         OstTrace0( TRACE_NORMAL, DUP4_CDPMIF_RUNL, "CDpMif:: ==> PNS_NAME_ADD_RESP received" );
       
   277 
       
   278                         TUint8 reason( receivedMsg.Get8bit( ISI_HEADER_SIZE +
       
   279                             PNS_NAME_ADD_RESP_OFFSET_REASON ) );
       
   280                         TInt error( KErrNone );
       
   281 
       
   282                         switch ( reason )
       
   283                             {
       
   284                             case PN_NAME_OK:
       
   285                                 {
       
   286                                 LOG(" ==> PN_NAME_OK");
       
   287                                 OstTrace0( TRACE_NORMAL, DUP5_CDPMIF_RUNL, "CDpMif:: ==> PN_NAME_OK" );
       
   288 
       
   289                                 error = KErrNone;
       
   290                                 break;
       
   291                                 }
       
   292                             default:
       
   293                                 {
       
   294                                 LOG1(" ==> reason: %d", reason );
       
   295                                 OstTraceExt1( TRACE_NORMAL, DUP6_CDPMIF_RUNL, "CDpMif:: ==> reason: %hhu", reason );
       
   296 
       
   297                                 error = KErrGeneral;
       
   298                                 }
       
   299                             }
       
   300                             iDataPort.SignalPif( error );
       
   301                         break;
       
   302                         }
       
   303                     case PNS_NAME_REMOVE_RESP:
       
   304                         {
       
   305                         LOG(" ==> PNS_NAME_REMOVE_RESP received");
       
   306                         OstTrace0( TRACE_NORMAL, DUP7_CDPMIF_RUNL, "CDpMif:: ==> PNS_NAME_REMOVE_RESP received" );
       
   307                         break;
       
   308                         }
       
   309                     default:
       
   310                         {
       
   311                         LOG1(" ==> Unknown message received. ID: %d",
       
   312                             message_id );
       
   313                         OstTraceExt1( TRACE_NORMAL, DUP8_CDPMIF_RUNL, "CDpMif:: ==> Unknown message received. ID: %hhu", message_id );
       
   314                         }
       
   315                     }
       
   316                 break;
       
   317                 }
       
   318             case PN_PIPE:
       
   319                 {
       
   320                 switch ( message_id )
       
   321                     {
       
   322                     case PNS_PEP_CTRL_REQ:
       
   323                         {
       
   324                         LOG(" ==> PNS_PEP_CTRL_REQ received");
       
   325                         OstTrace0( TRACE_NORMAL, DUP9_CDPMIF_RUNL, "CDpMif:: ==> PNS_PEP_CTRL_REQ received" );
       
   326 
       
   327                         HandlePepCtrlReq( receivedMsg );
       
   328                         break;
       
   329                         }
       
   330                     case PNS_PEP_STATUS_IND:
       
   331                         {
       
   332                         LOG(" ==> PNS_PEP_STATUS_IND received");
       
   333                         OstTrace0( TRACE_NORMAL, DUP10_CDPMIF_RUNL, "CDpMif:: ==> PNS_PEP_STATUS_IND received" );
       
   334 
       
   335                         HandlePepStatusInd( receivedMsg );
       
   336                         break;
       
   337                         }
       
   338                     default:
       
   339                         {
       
   340                         LOG1(" ==> Unknown message received. ID: %d",
       
   341                             message_id );
       
   342                         OstTraceExt1( TRACE_NORMAL, DUP11_CDPMIF_RUNL, "CDpMif:: ==> Unknown message received. ID: %hhu", message_id );
       
   343                         }
       
   344                     }
       
   345                 break;
       
   346                 }
       
   347             default:
       
   348                 {
       
   349                 LOG1(" ==> Unknown message received. ID: %d", message_id );
       
   350                 OstTraceExt1( TRACE_NORMAL, DUP12_CDPMIF_RUNL, "CDpMif:: ==> Unknown message received. ID: %hhu", message_id );
       
   351                 }
       
   352             }
       
   353 
       
   354         iReceiveMessage.Zero();
       
   355 
       
   356         // Check if pipe is removed
       
   357         if ( PNS_NAME_REMOVE_RESP == message_id &&
       
   358             CDpPif::EDpPipeDisconnected == iPifDcs.PipeState() )
       
   359             {
       
   360             // Check if DataPort is ready to be deleted
       
   361             if ( iDataPort.IsReadyToDestruct() )
       
   362                 {
       
   363                 iDataPort.DeleteDataPort();
       
   364                 }
       
   365             //no else
       
   366             }
       
   367         else
       
   368             {
       
   369             // Renew read
       
   370             User::LeaveIfError( Read() );
       
   371             }
       
   372         }
       
   373     }
       
   374 
       
   375 // ---------------------------------------------------------
       
   376 // CDpMif::RunError
       
   377 // Leave in RunL() is handled here. Error code is returned,
       
   378 // when internal error has occured.
       
   379 // ---------------------------------------------------------
       
   380 //
       
   381 TInt CDpMif::RunError(
       
   382     TInt aError )
       
   383     {
       
   384     OstTrace0( TRACE_NORMAL, CDPMIF_RUNERROR, "CDpMif::RunError" );
       
   385     LOGM2("CDpMif::RunError - Port %d, error code: %d",
       
   386         iDataPort.PortUnit(), aError );
       
   387     OstTraceExt2( TRACE_NORMAL, DUP1_CDPMIF_RUNERROR, "CDpMif:: Port: %u, error code: %d", iDataPort.PortUnit(), aError );
       
   388 
       
   389     // Message was not necessarily freed, if leave happened.
       
   390     iReceiveMessage.Zero();
       
   391 
       
   392     return aError;
       
   393     }
       
   394 
       
   395 // ---------------------------------------------------------
       
   396 // CDpMif::DoCancel
       
   397 // This method cancels Isc Api receive.
       
   398 // ---------------------------------------------------------
       
   399 //
       
   400 void CDpMif::DoCancel()
       
   401     {
       
   402     OstTrace0( TRACE_NORMAL, CDPMIF_DOCANCEL, "CDpMif::DoCancel" );
       
   403     LOGM(" CDpMif::DoCancel");
       
   404 
       
   405     iDataPort.ISAHandle().ReceiveCancel();
       
   406     }
       
   407 
       
   408 // ---------------------------------------------------------
       
   409 // CDpMif::Read
       
   410 // Makes a receive request to ISAHandle
       
   411 // ---------------------------------------------------------
       
   412 //
       
   413 TInt CDpMif::Read()
       
   414     {
       
   415     OstTrace0( TRACE_NORMAL, CDPMIF_READ, "CDpMif::Read" );
       
   416     OstTrace1( TRACE_NORMAL, DUP1_CDPMIF_READ, "CDpMif:: Port: %u", iDataPort.PortUnit() );
       
   417 
       
   418     LOGM1("CDpMif::Read - Port %d", iDataPort.PortUnit() );
       
   419 
       
   420     TInt ret( KErrNone );
       
   421 
       
   422     // length of a message ptr indicates we are already reading
       
   423     if ( iReceiveMessage.Length() || IsActive() )
       
   424         {
       
   425         LOG(" CDpMif::Read, Fail - already reading");
       
   426         OstTrace0( TRACE_NORMAL, DUP2_CDPMIF_READ, "CDpMif:: Fail - already reading" );
       
   427 
       
   428         ret = KErrGeneral;
       
   429         }
       
   430     else
       
   431         {
       
   432         // IscApi receive
       
   433         iDataPort.ISAHandle().Receive(
       
   434             iStatus, iReceiveMessage, iLen );
       
   435 
       
   436         SetActive();
       
   437          }
       
   438 
       
   439     return ret;
       
   440     }
       
   441 
       
   442 // ---------------------------------------------------------
       
   443 // CDpMif::HandlePepCtrlReq
       
   444 // Handles PepCtrlReq messages
       
   445 // ---------------------------------------------------------
       
   446 //
       
   447 void CDpMif::HandlePepCtrlReq(
       
   448     TIsiReceiveC& aIsiMessage )
       
   449     {
       
   450     OstTrace0( TRACE_NORMAL, CDPMIF_HANDLEPEPCTRLREQ, "CDpMif::HandlePepCtrlReq" );
       
   451     LOGM(" CDpMif::HandlePepCtrlReq");
       
   452 
       
   453     // Transaction id
       
   454     TUint8 transactionId( aIsiMessage.Get8bit(
       
   455         ISI_HEADER_OFFSET_TRANSID ) );
       
   456 
       
   457     // Pipe Handle
       
   458     if ( PN_PIPE_INVALID_HANDLE == iPifDcs.PipeHandle() )
       
   459         {
       
   460         TUint8 pipeHandle( aIsiMessage.Get8bit(
       
   461             ISI_HEADER_SIZE + PNS_PEP_CTRL_REQ_OFFSET_PIPEHANDLE) );
       
   462         iPifDcs.SetPipeHandle( pipeHandle );
       
   463         }
       
   464 
       
   465     // PEP Type
       
   466     TUint8 pepType( aIsiMessage.Get8bit(
       
   467         ISI_HEADER_SIZE + PNS_PEP_CTRL_REQ_OFFSET_PEPTYPE ) );
       
   468     // PEP Control ID
       
   469     TUint8 ctrlId( aIsiMessage.Get8bit(
       
   470         ISI_HEADER_SIZE + PNS_PEP_CTRL_REQ_OFFSET_PEPCTRLID ) );
       
   471     // PEP Control Data
       
   472     TPtrC8 ctrlData;
       
   473     // Check if there is data (there is no data for all control id's)
       
   474     if ( ( ISI_HEADER_SIZE + SIZE_PNS_PEP_CTRL_REQ ) <=
       
   475          aIsiMessage.GetBuffer().Length() )
       
   476         {
       
   477         // Control Data length is 1 byte
       
   478         TInt ctrlDataLen( 1 );
       
   479         ctrlData.Set( aIsiMessage.GetData(
       
   480             ISI_HEADER_SIZE + PNS_PEP_CTRL_REQ_OFFSET_PEPCTRLDATA,
       
   481             ctrlDataLen ) );
       
   482         }
       
   483     // Get sender device
       
   484     TUint8 senderDevice( aIsiMessage.Get8bit(
       
   485         ISI_HEADER_OFFSET_SENDERDEVICE ) );
       
   486     // Get sender object
       
   487     TUint8 senderObject( aIsiMessage.Get8bit(
       
   488         ISI_HEADER_OFFSET_SENDEROBJECT ) );
       
   489 
       
   490     // E32 return value
       
   491     TInt return_E32( KErrNone );
       
   492     // PN_PIPE return value
       
   493     TInt ret( KErrNone );
       
   494 
       
   495     switch ( pepType )
       
   496         {
       
   497         case PN_PEP_TYPE_COMM:
       
   498         case PN_PEP_TYPE_BT_ACC:
       
   499             {
       
   500             // comm_pep handles ctrl_req
       
   501             // Something can go wrong in here. Leaving is not the best case in here.
       
   502             // We can send an response message with error value to NOS side and
       
   503             // hope for the best.
       
   504             return_E32 = iCommPep.HandlePepCtrlReq( ctrlId, ctrlData );
       
   505             break;
       
   506             }
       
   507 
       
   508         default: // Not supported pepType
       
   509             {
       
   510             LOG1("  ERROR - Unsupported pep type: %d", pepType );
       
   511             OstTraceExt1( TRACE_NORMAL, DUP1_CDPMIF_HANDLEPEPCTRLREQ, "CDpMif:: ERROR - Unsupported pep type: %hhu", pepType );
       
   512 
       
   513             return_E32 = KErrArgument;
       
   514             break;
       
   515             }
       
   516         }
       
   517 
       
   518     // do mapping from E32 error codes => PN_PIPE error codes
       
   519     switch ( return_E32 )
       
   520         {
       
   521         case KErrNone:
       
   522             {
       
   523             ret = PN_PIPE_NO_ERROR;
       
   524             break;
       
   525             }
       
   526         case KErrNotSupported:
       
   527             {
       
   528             // this error code should NOT be used according to specification
       
   529             LOG("  ERROR - Unsupported config (KErrNotSupported)");
       
   530             OstTrace0( TRACE_NORMAL, DUP2_CDPMIF_HANDLEPEPCTRLREQ, "CDpMif:: ERROR - Unsupported config (KErrNotSupported)" );
       
   531 
       
   532             ret = PN_PIPE_ERR_NOT_SUPPORTED;
       
   533             break;
       
   534             }
       
   535         case KErrArgument:
       
   536             {
       
   537             // this error code should NOT be used according to specification
       
   538             LOG("  ERROR - Invalid argument (KErrArgument)");
       
   539             OstTrace0( TRACE_NORMAL, DUP3_CDPMIF_HANDLEPEPCTRLREQ, "CDpMif:: ERROR - Invalid argument (KErrArgument)" );
       
   540 
       
   541             ret = PN_PIPE_ERR_INVALID_PARAM;
       
   542             break;
       
   543             }
       
   544         case KErrGeneral:
       
   545             {
       
   546             LOG("  ERROR - Invalid parameter (KErrGeneral)");
       
   547             OstTrace0( TRACE_NORMAL, DUP4_CDPMIF_HANDLEPEPCTRLREQ, "CDpMif:: ERROR - Invalid parameter (KErrGeneral)" );
       
   548 
       
   549             ret = PN_PIPE_ERR_INVALID_CTRL_ID;
       
   550             break;
       
   551             }
       
   552         default:
       
   553             {
       
   554             // this error code should NOT be used according to specification
       
   555             LOG1("  ERROR - Other error: %d", return_E32 );
       
   556             OstTrace1( TRACE_NORMAL, DUP5_CDPMIF_HANDLEPEPCTRLREQ, "CDpMif:: ERROR - Other error: %d", return_E32 );
       
   557 
       
   558             ret = PN_PIPE_ERR_GENERAL;
       
   559             break;
       
   560             }
       
   561         }
       
   562 
       
   563     // Create PNS_PEP_CTRL_RESP response
       
   564     TBuf8<SIZE_PNS_PEP_CTRL_RESP> messageData;
       
   565     // Pipe Handle
       
   566     messageData.Append( iPifDcs.PipeHandle() );
       
   567     // PEP Control ID
       
   568     messageData.Append( ctrlId );
       
   569     // PEP Type
       
   570     messageData.Append( pepType );
       
   571     // Error Code
       
   572     messageData.Append( static_cast<TUint8>( ret  ) );
       
   573     // Filler bytes
       
   574     messageData.Append( KDpPadding );
       
   575     messageData.Append( KDpPadding );
       
   576 
       
   577     // Send message, respond to sender
       
   578     return_E32 = SendMessage(
       
   579         senderDevice,
       
   580         senderObject,
       
   581         PN_PIPE,
       
   582         transactionId,
       
   583         PNS_PEP_CTRL_RESP,
       
   584         messageData );
       
   585 
       
   586     LOG1("  <== PNS_PEP_CTRL_RESP resp sent, error code = %d", ret );
       
   587     OstTrace1( TRACE_NORMAL, DUP6_CDPMIF_HANDLEPEPCTRLREQ, "CDpMif:: <== PNS_PEP_CTRL_RESP resp sent, error code = %d", ret );
       
   588 
       
   589 #if defined(_DEBUG)
       
   590     if (KErrNone != return_E32 )
       
   591         {
       
   592         LOG1("  Error isc api send %d", return_E32 );
       
   593         OstTrace1( TRACE_NORMAL, DUP7_CDPMIF_HANDLEPEPCTRLREQ, "CDpMif:: Error isc api send %d", return_E32 );
       
   594         }
       
   595     //no else
       
   596 #endif
       
   597 
       
   598     }
       
   599 
       
   600 // ---------------------------------------------------------
       
   601 // CDpMif::HandlePepStatusInd
       
   602 // Handles PepStatusInd messages
       
   603 // ---------------------------------------------------------
       
   604 //
       
   605 TInt CDpMif::HandlePepStatusInd(
       
   606     TIsiReceiveC& aIsiMessage )
       
   607     {
       
   608     OstTrace0( TRACE_NORMAL, CDPMIF_HANDLEPEPSTATUSIND, "CDpMif::HandlePepStatusInd" );
       
   609     LOGM(" CDpMif::HandlePepStatusInd");
       
   610 
       
   611     // PEP Type
       
   612     TUint8 pepType( aIsiMessage.Get8bit(
       
   613         ISI_HEADER_SIZE + PNS_PEP_STATUS_IND_OFFSET_PEPTYPE ) );
       
   614     // Indication ID
       
   615     TUint8 indId( aIsiMessage.Get8bit(
       
   616         ISI_HEADER_SIZE + PNS_PEP_STATUS_IND_OFFSET_INDICATIONID ) );
       
   617 
       
   618     // Indication Data
       
   619     TPtrC8 indData;
       
   620     TInt ret( KErrNone );
       
   621 
       
   622     if ( 15 < aIsiMessage.GetBuffer().Length() )
       
   623         {
       
   624         // Indication data length is 1 byte
       
   625         indData.Set( aIsiMessage.GetData(
       
   626             ISI_HEADER_SIZE + PNS_PEP_STATUS_IND_OFFSET_INDICATIONDATA, 1 ) );
       
   627         }
       
   628     else
       
   629         {
       
   630         ret = KErrGeneral;
       
   631         }
       
   632 
       
   633     if ( KErrNone == ret )
       
   634         {
       
   635         TInt result( KErrNone );
       
   636         switch ( pepType )
       
   637             {
       
   638             case PN_PEP_TYPE_COMM:
       
   639             case PN_PEP_TYPE_BT_ACC:
       
   640                 {
       
   641                 // comm_pep handles status_ind.
       
   642                 // If dataport doesn't understand the status msg
       
   643                 // it can't do nothing about it.
       
   644                 result = iCommPep.HandlePepStatusInd( indId, indData );
       
   645                 break;
       
   646                 }
       
   647             case PN_PEP_TYPE_COMMON:
       
   648                 {
       
   649                 // DO NOTHING
       
   650                 // This is handled in ISC
       
   651                 break;
       
   652                 }
       
   653             default:
       
   654                 {
       
   655                 // Dataport doesn't support the PNS_PEP_STATUS pep type
       
   656                 // Life's hard, can't do nothing. Don't need to leave
       
   657                 // in release code.
       
   658                 LOG1(" ERROR - Unsupported pep type: %d", result );
       
   659                 OstTrace1( TRACE_NORMAL, DUP1_CDPMIF_HANDLEPEPSTATUSIND, "CDpMif:: ERROR - Unsupported pep type: %d", result );
       
   660 
       
   661                 ret = KErrGeneral;
       
   662                 }
       
   663             }
       
   664 
       
   665         if ( KErrNone == result )
       
   666             {
       
   667             LOG1(" CDpMif::HandlePepStatusInd: %d", result );
       
   668             OstTrace1( TRACE_NORMAL, DUP2_CDPMIF_HANDLEPEPSTATUSIND, "CDpMif:: HandlePepStatusInd: %d", result );
       
   669             }
       
   670         //no else
       
   671         }
       
   672     //no else
       
   673 
       
   674     return ret;
       
   675     }
       
   676 
       
   677 // ---------------------------------------------------------
       
   678 // CDpMif::SendNameAddReqL
       
   679 // This method sends name add request to Name Service.
       
   680 // ---------------------------------------------------------
       
   681 //
       
   682 void CDpMif::SendNameAddReqL(
       
   683     const TUint aUnit )
       
   684     {
       
   685     OstTrace0( TRACE_NORMAL, CDPMIF_SENDNAMEADDREQL, "CDpMif::SendNameAddReqL" );
       
   686     LOGM(" CDpMif::SendNameAddReq");
       
   687 
       
   688     __ASSERT_ALWAYS( aUnit <= KDataPortCommHighUnit,
       
   689         User::Leave( KErrNotSupported ) );
       
   690 
       
   691     TBuf8<SIZE_PNS_NAME_ADD_REQ> messageData;
       
   692 
       
   693     // Add reserved bytes
       
   694     messageData.Append( KDpPadding );
       
   695     messageData.Append( KDpPadding );
       
   696 
       
   697     // Add 32bit name (Big-endian)
       
   698     switch ( aUnit )
       
   699         {
       
   700         case KDpCsdPort:
       
   701         case KDpPort6:
       
   702             {
       
   703             messageData.Append( aUnit );                //name
       
   704             messageData.Append( PN_PEP_SUB_TYPE_SYMBIAN_INTERNAL ); //name
       
   705             messageData.Append( PN_PEP_TYPE_COMM );     //name
       
   706             messageData.Append( PN_PIPE );              //name
       
   707             break;
       
   708             }
       
   709         case KDpDialUpPort:
       
   710         case KDpPort4:
       
   711         case KDpPort5:
       
   712             {
       
   713             messageData.Append( aUnit );                //name
       
   714             messageData.Append( KDpPadding );           //name
       
   715             messageData.Append( PN_PEP_TYPE_COMM );     //name
       
   716             messageData.Append( PN_PIPE );              //name
       
   717             break;
       
   718             }
       
   719         case KDpBtAccHfPort:
       
   720             {
       
   721             messageData.Append( KDpPadding );           //name
       
   722             messageData.Append( PN_PEP_SUB_TYPE_BT_ACC_HF ); //name
       
   723             messageData.Append( PN_PEP_TYPE_BT_ACC );   //name
       
   724             messageData.Append( PN_PIPE );              //name
       
   725             break;
       
   726             }
       
   727         case KDpBtAccHsPort:
       
   728             {
       
   729             messageData.Append( KDpPadding );           //name
       
   730             messageData.Append( PN_PEP_SUB_TYPE_BT_ACC_HS ); //name
       
   731             messageData.Append( PN_PEP_TYPE_BT_ACC );   //name
       
   732             messageData.Append( PN_PIPE );              //name
       
   733             break;
       
   734             }
       
   735         default:
       
   736             {
       
   737             User::Leave( KErrGeneral );
       
   738             }
       
   739         }
       
   740 
       
   741     // Add Device id
       
   742     messageData.Append( THIS_DEVICE );
       
   743 
       
   744     // Create Object id
       
   745     TUint8 channelId( 0 );
       
   746 
       
   747     switch ( aUnit )
       
   748         {
       
   749         case KDpCsdPort:
       
   750             {
       
   751             channelId = EIscNokiaDataport1;
       
   752             break;
       
   753             }
       
   754         case KDpDialUpPort:
       
   755             {
       
   756             channelId = EIscNokiaDataport2;
       
   757             break;
       
   758             }
       
   759         case KDpBtAccHfPort:
       
   760         case KDpBtAccHsPort:
       
   761             {
       
   762             channelId = EIscNokiaBtAppl;
       
   763             break;
       
   764             }
       
   765         case KDpPort4:
       
   766             {
       
   767             channelId = EIscNokiaDataport3;
       
   768             break;
       
   769             }
       
   770         case KDpPort5:
       
   771             {
       
   772             channelId = EIscNokiaDataport4;
       
   773             break;
       
   774             }
       
   775         case KDpPort6:
       
   776             {
       
   777             channelId = EIscNokiaDataport5;
       
   778             break;
       
   779             }
       
   780         default:
       
   781             {
       
   782             //Do nothing
       
   783             break;
       
   784             }
       
   785         }
       
   786 
       
   787     TBuf8<2> data;
       
   788     TInt ret( iDataPort.ISAHandle().GetChannelInfo( channelId, data ) );
       
   789 
       
   790     _LIT(KPanicStr, "Dataport::SendNameAddReqL");
       
   791     __ASSERT_ALWAYS( KErrNone == ret, User::Panic( KPanicStr, 0 ) );
       
   792 
       
   793     // Set obj id
       
   794     TUint16 obj( static_cast<TUint16>(
       
   795         ( static_cast<TUint16>( data[0] ) << 8 ) + data[1] ) );
       
   796 
       
   797     LOG1(" Dataport::SendNameAddReqL obj = 0x%x", obj );
       
   798     OstTraceExt1( TRACE_NORMAL, DUP1_CDPMIF_SENDNAMEADDREQL, "CDpMif:: obj = 0x%hx", obj );
       
   799 
       
   800     // Add Object id
       
   801     messageData.Append( obj );
       
   802     // Add Record flags
       
   803     messageData.Append( PN_NAME_CLEARED );
       
   804     //fill
       
   805     messageData.Append( KDpPadding );
       
   806 
       
   807 #if defined(_DEBUG)
       
   808     ret =
       
   809 #endif
       
   810     SendMessage(
       
   811         PN_NAMESERVICE,
       
   812         iDataPort.CreateTransactionId(),
       
   813         PNS_NAME_ADD_REQ,
       
   814         messageData );
       
   815 
       
   816     LOG1("  <== PNS_NAME_ADD_REQ req sent, obj id: %x", obj );
       
   817     OstTraceExt1( TRACE_NORMAL, DUP2_CDPMIF_SENDNAMEADDREQL, "CDpMif:: <== PNS_NAME_ADD_REQ req sent, obj id: %hx", obj );
       
   818 
       
   819 #if defined(_DEBUG)
       
   820     if (KErrNone != ret )
       
   821         {
       
   822         LOG1("  Error isc api send %d", ret );
       
   823         OstTrace1( TRACE_NORMAL, DUP3_CDPMIF_SENDNAMEADDREQL, "CDpMif:: Error isc api send %d", ret );
       
   824         }
       
   825     //no else
       
   826 #endif
       
   827     }
       
   828 
       
   829 // ---------------------------------------------------------
       
   830 // CDpMif::SendNameRemoveReqL
       
   831 // This method sends name remove request to Name Service.
       
   832 // ---------------------------------------------------------
       
   833 //
       
   834 void CDpMif::SendNameRemoveReqL(
       
   835     const TUint aUnit )
       
   836     {
       
   837     OstTrace0( TRACE_NORMAL, CDPMIF_SENDNAMEREMOVEREQL, "CDpMif::SendNameRemoveReqL" );
       
   838     LOGM(" CDpMif::SendNameRemoveReq");
       
   839 
       
   840     TBuf8<SIZE_PNS_NAME_REMOVE_REQ> messageData;
       
   841 
       
   842     // Add reserved bytes
       
   843     messageData.Append( KDpPadding );
       
   844     messageData.Append( KDpPadding );
       
   845 
       
   846     // Add 32bit name (Big-endian)
       
   847     switch ( aUnit )
       
   848         {
       
   849         case KDpCsdPort:
       
   850         case KDpPort6:
       
   851             {
       
   852             messageData.Append( aUnit );                //name
       
   853             messageData.Append( PN_PEP_SUB_TYPE_SYMBIAN_INTERNAL ); //name
       
   854             messageData.Append( PN_PEP_TYPE_COMM );     //name
       
   855             messageData.Append( PN_PIPE );              //name
       
   856             break;
       
   857             }
       
   858         case KDpDialUpPort:
       
   859         case KDpPort4:
       
   860         case KDpPort5:
       
   861             {
       
   862             messageData.Append( aUnit );                //name
       
   863             messageData.Append( KDpPadding );           //name
       
   864             messageData.Append( PN_PEP_TYPE_COMM );     //name
       
   865             messageData.Append( PN_PIPE );              //name
       
   866             break;
       
   867             }
       
   868         case KDpBtAccHfPort:
       
   869             {
       
   870             messageData.Append( KDpPadding );           //name
       
   871             messageData.Append( PN_PEP_SUB_TYPE_BT_ACC_HF ); //name
       
   872             messageData.Append( PN_PEP_TYPE_BT_ACC );   //name
       
   873             messageData.Append( PN_PIPE );              //name
       
   874             break;
       
   875             }
       
   876         case KDpBtAccHsPort:
       
   877             {
       
   878             messageData.Append( KDpPadding );           //name
       
   879             messageData.Append( PN_PEP_SUB_TYPE_BT_ACC_HS ); //name
       
   880             messageData.Append( PN_PEP_TYPE_BT_ACC );   //name
       
   881             messageData.Append( PN_PIPE );              //name
       
   882             break;
       
   883             }
       
   884         default:
       
   885             {
       
   886             User::Leave( KErrGeneral );
       
   887             }
       
   888         }
       
   889 
       
   890 #if defined(_DEBUG)
       
   891     TInt ret =
       
   892 #endif
       
   893     SendMessage(
       
   894         PN_NAMESERVICE,
       
   895         iDataPort.CreateTransactionId(),
       
   896         PNS_NAME_REMOVE_REQ,
       
   897         messageData );
       
   898 
       
   899     LOG("  <== PNS_NAME_REMOVE_REQ req sent");
       
   900     OstTrace0( TRACE_NORMAL, DUP1_CDPMIF_SENDNAMEREMOVEREQL, "CDpMif:: <== PNS_NAME_REMOVE_REQ req sent" );
       
   901 
       
   902 #if defined(_DEBUG)
       
   903     if ( KErrNone != ret )
       
   904         {
       
   905         LOG1("Error isc api send %d", ret );
       
   906         OstTrace1( TRACE_NORMAL, DUP2_CDPMIF_SENDNAMEREMOVEREQL, "CDpMif:: Error isc api send %d", ret );
       
   907         }
       
   908     //no else
       
   909 #endif
       
   910     }
       
   911 
       
   912 // ---------------------------------------------------------
       
   913 // CDpMif::SendMessage
       
   914 // Send ISI message, given resource, transaction id,
       
   915 // message id and message.
       
   916 // (other items were commented in a header).
       
   917 // ---------------------------------------------------------
       
   918 //
       
   919 TInt CDpMif::SendMessage(
       
   920     TUint8 aResource,
       
   921     TUint8 aTransactionId,
       
   922     TUint8 aMessageId,
       
   923     const TDesC8& aMessage )
       
   924     {
       
   925     OstTrace0( TRACE_NORMAL, CDPMIF_SENDMESSAGE, "CDpMif::SendMessage" );
       
   926     OstTrace1( TRACE_NORMAL, DUP2_CDPMIF_SENDMESSAGE, "CDpMif:: Port: %u", iDataPort.PortUnit() );
       
   927     OstTraceExt1( TRACE_NORMAL, DUP3_CDPMIF_SENDMESSAGE, "CDpMif:: ==> resource: 0x%hhx", aResource );
       
   928     OstTraceExt1( TRACE_NORMAL, DUP4_CDPMIF_SENDMESSAGE, "CDpMif:: ==> tra id: 0x%hhx", aTransactionId );
       
   929     OstTraceExt1( TRACE_NORMAL, DUP5_CDPMIF_SENDMESSAGE, "CDpMif:: ==> msg id: 0x%hhx", aMessageId );
       
   930 
       
   931     LOGM1(" CDpMif::SendMessage - Port %d", iDataPort.PortUnit() );
       
   932     LOGM1("  ==> resource: 0x%x", aResource );
       
   933     LOGM1("  ==> tra id: 0x%x", aTransactionId );
       
   934     LOGM1("  ==> msg id: 0x%x", aMessageId );
       
   935 
       
   936     // We shall use send buffer
       
   937     iSendMessage.Zero();
       
   938     TIsiSend msg( iSendMessage );
       
   939     msg.Set8bit( ISI_HEADER_OFFSET_RESOURCEID, aResource );
       
   940     msg.Set8bit( ISI_HEADER_OFFSET_TRANSID, aTransactionId );
       
   941     msg.Set8bit( ISI_HEADER_OFFSET_MESSAGEID, aMessageId );
       
   942     // Copy message data (+2 => after msgid and traid)
       
   943     msg.CopyData( ISI_HEADER_SIZE + 2, aMessage );
       
   944 
       
   945     // Add paddings
       
   946     while ( iSendMessage.Length() % 4 )
       
   947         {
       
   948         iSendMessage.Append( 0x00 );
       
   949         }
       
   950     OstTrace1( TRACE_NORMAL, DUP6_CDPMIF_SENDMESSAGE, "CDpMif:: ==> message length: %d", iSendMessage.Length() );
       
   951     OstPrintIsiMessage( iSendMessage );
       
   952 
       
   953     LOGM1("  ==> message length: %d", iSendMessage.Length() );
       
   954     LOGMESSAGE( iSendMessage );
       
   955 
       
   956     return iDataPort.ISAHandle().Send( msg.Complete() );
       
   957     }
       
   958 
       
   959 // ---------------------------------------------------------
       
   960 // CDpMif::SendMessage
       
   961 // Send ISI message, given receiver device, receiver object,
       
   962 // resource, transaction id, message id and message.
       
   963 // (other items were commented in a header).
       
   964 // ---------------------------------------------------------
       
   965 //
       
   966 TInt CDpMif::SendMessage(
       
   967     TUint8 aRecDevice,
       
   968     TUint8 aRecObject,
       
   969     TUint8 aResource,
       
   970     TUint8 aTransactionId,
       
   971     TUint8 aMessageId,
       
   972     const TDesC8& aMessage )
       
   973     {
       
   974     OstTrace0( TRACE_NORMAL, DUP1_CDPMIF_SENDMESSAGE, "CDpMif::SendMessage" );
       
   975     OstTrace1( TRACE_NORMAL, DUP15_CDPMIF_SENDMESSAGE, "CDpMif:: Port: %u", iDataPort.PortUnit() );
       
   976     OstTraceExt1( TRACE_NORMAL, DUP14_CDPMIF_SENDMESSAGE, "CDpMif:: ==> receiver dev.: 0x%hhx", aRecDevice );
       
   977     OstTraceExt1( TRACE_NORMAL, DUP13_CDPMIF_SENDMESSAGE, "CDpMif:: ==> receiver obj.: 0x%hhx", aRecObject );
       
   978     OstTraceExt1( TRACE_NORMAL, DUP12_CDPMIF_SENDMESSAGE, "CDpMif:: ==> resource: 0x%hhx", aResource );
       
   979     OstTraceExt1( TRACE_NORMAL, DUP11_CDPMIF_SENDMESSAGE, "CDpMif:: ==> tra id: 0x%hhx", aTransactionId );
       
   980     OstTraceExt1( TRACE_NORMAL, DUP10_CDPMIF_SENDMESSAGE, "CDpMif:: ==> msg id: 0x%hhx", aMessageId );
       
   981 
       
   982     LOGM1(" CDpMif::SendMessage - Port %d", iDataPort.PortUnit() );
       
   983     LOGM1("  ==> receiver dev.: 0x%x", aRecDevice );
       
   984     LOGM1("  ==> receiver obj.: 0x%x", aRecObject );
       
   985     LOGM1("  ==> resource: 0x%x", aResource );
       
   986     LOGM1("  ==> tra id: 0x%x", aTransactionId );
       
   987     LOGM1("  ==> msg id: 0x%x", aMessageId );
       
   988 
       
   989     // We shall use send buffer
       
   990     iSendMessage.Zero();
       
   991     TIsiSend msg( iSendMessage );
       
   992     msg.Set8bit( ISI_HEADER_OFFSET_RECEIVERDEVICE, aRecDevice );
       
   993     msg.Set8bit( ISI_HEADER_OFFSET_RESOURCEID, aResource );
       
   994     msg.Set8bit( ISI_HEADER_OFFSET_RECEIVEROBJECT, aRecObject );
       
   995     msg.Set8bit( ISI_HEADER_OFFSET_TRANSID, aTransactionId );
       
   996     msg.Set8bit( ISI_HEADER_OFFSET_MESSAGEID, aMessageId );
       
   997     // Copy message data (+2 => after msgid and traid)
       
   998     msg.CopyData( ISI_HEADER_SIZE + 2, aMessage );
       
   999 
       
  1000     // Add paddings
       
  1001     while ( iSendMessage.Length() % 4 )
       
  1002         {
       
  1003         iSendMessage.Append( 0x00 );
       
  1004         }
       
  1005 
       
  1006     OstTrace1( TRACE_NORMAL, DUP8_CDPMIF_SENDMESSAGE, "CDpMif:: ==> message length: %d", iSendMessage.Length() );
       
  1007     OstPrintIsiMessage( iSendMessage );
       
  1008 
       
  1009     LOGM1("  ==> message length: %d", iSendMessage.Length() );
       
  1010     LOGMESSAGE( iSendMessage );
       
  1011 
       
  1012     return iDataPort.ISAHandle().Send( msg.Complete() );
       
  1013     }
       
  1014 
       
  1015 // ================= OTHER EXPORTED FUNCTIONS ==============
       
  1016 // none
       
  1017 
       
  1018 //  End of File