wim/WimServer/src/WimCallbackImpl.cpp
changeset 0 164170e6151a
equal deleted inserted replaced
-1:000000000000 0:164170e6151a
       
     1 /*
       
     2 * Copyright (c) 2003 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 "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:  This file contain the implementation of CWimCallBack class.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include    "WimCallbackImpl.h"
       
    22 #include    "WimSession.h"
       
    23 #include    "WimServer.h"
       
    24 #include    "WimResponse.h"
       
    25 #include    "WimApduImpl.h"
       
    26 #include    "WimSimFileHandler.h"
       
    27 #include    "WimUtilityFuncs.h"
       
    28 #include    "WimConsts.h"
       
    29 #include    "WimTrace.h"
       
    30 #include    <x509cert.h>
       
    31 
       
    32 // These variables are static because static function calls from WIMI
       
    33 static CWimApdu* gApdu = NULL;
       
    34 static CWimSimFileHandler* gSimFileHandler = NULL;
       
    35 static TRequestStatus* gStatus = NULL;
       
    36 
       
    37 // ============================ MEMBER FUNCTIONS ===============================
       
    38 
       
    39 // -----------------------------------------------------------------------------
       
    40 // CWimCallBack::InitOkResp
       
    41 // Respond to InitOK operation
       
    42 // -----------------------------------------------------------------------------
       
    43 //
       
    44 void CWimCallBack::InitOkResp( WIMI_STAT aStatus )
       
    45     {
       
    46     _WIMTRACE2(_L("WIM|WIMServer|CWimCallBack::InitOkResp|Begin aStatus=%d"), aStatus);
       
    47     CWimServer::iWimStatus = CWimUtilityFuncs::MapWIMError( aStatus );   
       
    48     
       
    49     if ( aStatus == WIMI_Ok )
       
    50         {
       
    51         CWimServer::SetWimInitialized( ETrue, KErrNone ); // WIM has initialized
       
    52         _WIMTRACE(_L("WIM|WIMServer|CWimCallBack::InitOkResp|Initialized=True"));
       
    53         }
       
    54     else
       
    55         {
       
    56         if( aStatus == WIMI_ERR_UserCancelled )
       
    57 	        {
       
    58 	        CWimServer::iWimStatus = KErrCancel;
       
    59 	        CWimServer::SetWimInitialized( EFalse, KErrCancel );
       
    60             WIMI_CloseDownReq();
       
    61 	        }
       
    62         else
       
    63 	        {
       
    64 	        CWimServer::SetWimInitialized( EFalse, CWimServer::iWimStatus ); // WIM has not initialized	
       
    65             WIMI_CloseDownReq();
       
    66 	        }
       
    67         
       
    68         _WIMTRACE(_L("WIM|WIMServer|CWimCallBack::InitOkResp|Initialized=False"));
       
    69         }
       
    70     }
       
    71 
       
    72 // -----------------------------------------------------------------------------
       
    73 // CWimCallBack::CloseDownResp
       
    74 // Respond to CloseDown operation
       
    75 // -----------------------------------------------------------------------------
       
    76 //
       
    77 void CWimCallBack::CloseDownResp( WIMI_STAT aStatus )
       
    78     {
       
    79     _WIMTRACE(_L("WIM | WIMServer | CWimCallBack::CloseDownResp | Begin"));
       
    80     CWimServer::iWimStatus = CWimUtilityFuncs::MapWIMError( aStatus );
       
    81     CWimServer::SetWimInitialized( EFalse, CWimServer::iWimStatus ); // WIM has not initialized
       
    82     delete gSimFileHandler; // Close connection to CustomAPI
       
    83     gSimFileHandler = NULL;
       
    84     }
       
    85 
       
    86 // -----------------------------------------------------------------------------
       
    87 // CWimCallBack::CompleteResponse
       
    88 // Complete response
       
    89 // -----------------------------------------------------------------------------
       
    90 //
       
    91 void CWimCallBack::CompleteResponse(
       
    92     WIMI_TransactId_t aTrId,
       
    93     WIMI_STAT aStatus )
       
    94     {
       
    95     _WIMTRACE(_L("WIM | WIMServer | CWimCallBack::CompleteResponse | Begin"));
       
    96     TWimReqTrId* trIdType = ( TWimReqTrId* )aTrId;
       
    97     CWimResponse* pTrId = ( CWimResponse* )( trIdType->iReqTrId );
       
    98     pTrId->iStatus = aStatus;
       
    99     pTrId->CompleteMsgAndDelete();
       
   100     delete trIdType;
       
   101     }
       
   102 
       
   103 /* ------------ Digital signature ------------------------------------------- */
       
   104 
       
   105 // -----------------------------------------------------------------------------
       
   106 // CWimCallBack::SetSignTextRequestStatus
       
   107 // Set RequestStatus of SignTextHandler
       
   108 // -----------------------------------------------------------------------------
       
   109 //
       
   110 void CWimCallBack::SetSignTextRequestStatus( TRequestStatus* aStatus )
       
   111     {
       
   112     gStatus = aStatus;
       
   113     }
       
   114 
       
   115 // -----------------------------------------------------------------------------
       
   116 // CWimCallBack::SignResp
       
   117 // Respond to the digital signature operation
       
   118 // -----------------------------------------------------------------------------
       
   119 //
       
   120 void CWimCallBack::SignResp(
       
   121     WIMI_TransactId_t aTrId, 
       
   122     WIMI_STAT aStatus,
       
   123     TUint8 aSignLen,
       
   124     TUint8* aSign )
       
   125     {
       
   126     _WIMTRACE(_L("WIM | WIMServer | CWimCallBack::SignResp | Begin"));
       
   127 
       
   128     TWimReqTrId* trIdType = ( TWimReqTrId* )aTrId;
       
   129     CWimResponse* trId = ( CWimResponse* )( trIdType->iReqTrId );
       
   130     trId->iStatus = aStatus;
       
   131 
       
   132     // In case PIN was incorrect try ask PIN again, don't complete message
       
   133     // If PIN is blocked show note and don't complete message yet.
       
   134     if ( aStatus != WIMI_ERR_BadPIN && aStatus != WIMI_ERR_PINBlocked && aStatus != WIMI_ERR_CardIOError )
       
   135         {
       
   136         if ( trId->iStatus == WIMI_Ok )
       
   137             {
       
   138             TRAP( trId->iError, SignRespL( trId, aSignLen, aSign ) );
       
   139             }
       
   140         WIMI_Ref_pt pWimRefTemp = NULL;
       
   141         pWimRefTemp = WIMI_GetWIMRef( 0 );
       
   142         if ( pWimRefTemp )  // Close the WIM
       
   143             {
       
   144             WIMI_CloseWIM( pWimRefTemp );
       
   145             free_WIMI_Ref_t( pWimRefTemp );
       
   146             }
       
   147         trId->CompleteMsgAndDelete(); 
       
   148         delete trIdType;
       
   149         }
       
   150 
       
   151     // Complete SignTextHandler status
       
   152     if ( gStatus )
       
   153         {
       
   154         User::RequestComplete( gStatus, aStatus );
       
   155         }
       
   156     else // SignTextHandler not active, complete message with error if not done
       
   157         {
       
   158         if ( aStatus == WIMI_ERR_BadPIN || aStatus == WIMI_ERR_PINBlocked || aStatus == WIMI_ERR_CardIOError )
       
   159             {
       
   160             trId->CompleteMsgAndDelete();
       
   161             delete trIdType;
       
   162             }
       
   163         }
       
   164     }
       
   165 
       
   166 // -----------------------------------------------------------------------------
       
   167 // CWimCallBack::SignRespL
       
   168 // Write signed text to client memory. Signature allocated in WIMI is freed 
       
   169 // also by WIMI.
       
   170 // -----------------------------------------------------------------------------
       
   171 //
       
   172 void CWimCallBack::SignRespL(
       
   173     CWimResponse* aTrId,
       
   174     TUint8 aSignLen,
       
   175     TUint8* aSign )
       
   176     {
       
   177     _WIMTRACE(_L("WIM | WIMServer | CWimCallBack::SignRespL | Begin"));
       
   178 
       
   179     RMessage2& message = aTrId->iMessage;
       
   180 
       
   181     TPtr8 signaturePtr( aSign, aSignLen, aSignLen );
       
   182 
       
   183     message.WriteL( 3, signaturePtr );
       
   184     }
       
   185 
       
   186 /* ------------ Certificate management -------------------------------------- */
       
   187 
       
   188 // -----------------------------------------------------------------------------
       
   189 // CWimCallBack::CertificateResp
       
   190 // Respond to Certificate fetch operation
       
   191 // -----------------------------------------------------------------------------
       
   192 //
       
   193 void CWimCallBack::CertificateResp( 
       
   194     WIMI_TransactId_t aTrId,
       
   195     WIMI_STAT aStatus,
       
   196     WIMI_Ref_t* aCertRef,
       
   197     TUint16 aCertlen,
       
   198     TUint8* aCert )
       
   199     {
       
   200     if ( aTrId )
       
   201     	{
       
   202         _WIMTRACE(_L("WIM | WIMServer | CWimCallBack::CertificateResp | Begin"));
       
   203         TWimReqTrId* trIdType = ( TWimReqTrId* )aTrId;
       
   204         CWimResponse* pTrId = ( CWimResponse* )( trIdType->iReqTrId );
       
   205         pTrId->iStatus = aStatus;
       
   206         if ( pTrId->iStatus == WIMI_Ok)
       
   207             {
       
   208             TRAP( pTrId->iError,
       
   209                 CertificateRespL( pTrId, aStatus, aCertRef, aCertlen, aCert ) );
       
   210             }
       
   211         pTrId->CompleteMsgAndDelete(); 
       
   212         delete trIdType;
       
   213     	}
       
   214     else
       
   215     	{
       
   216     	_WIMTRACE(_L("WIM | WIMServer | CWimCallBack::CertificateResp | certhandler starts this"));
       
   217     	if ( gStatus )
       
   218 	        {
       
   219 	        TPtrC8 certPtr( aCert, aCertlen );
       
   220 	        CX509Certificate* cert = NULL;
       
   221 	        TRAPD( err, cert =  CX509Certificate::NewL( certPtr ) );
       
   222 	        _WIMTRACE2(_L("WIM | WIMServer | CWimCallBack::CertificateResp | x509 err %d"), err );
       
   223 	        User::RequestComplete( gStatus, err );
       
   224 	        delete cert;
       
   225 	        cert = NULL;
       
   226 	        }
       
   227     	}
       
   228     }
       
   229 
       
   230 // -----------------------------------------------------------------------------
       
   231 // CWimCallBack::CertificateRespL
       
   232 // Respond to the certificate fetch operation
       
   233 // -----------------------------------------------------------------------------
       
   234 //
       
   235 void CWimCallBack::CertificateRespL(
       
   236     CWimResponse* aTrId,
       
   237     WIMI_STAT /*aStatus*/,
       
   238     WIMI_Ref_t* /*aWimiRef*/,
       
   239     TUint16 aCertLen,
       
   240     TUint8* aCert )
       
   241     {
       
   242     _WIMTRACE(_L("WIM | WIMServer | CertificateRespL | Begin"));
       
   243     _WIMTRACE2(_L("WIM | WIMServer | The length of certificate is %d"), aCertLen);
       
   244     
       
   245     RMessage2& message = aTrId->iMessage;
       
   246         
       
   247     if ( aTrId->iStatus == WIMI_Ok )
       
   248         {
       
   249         TPtr8 certPtr( aCert, aCertLen, aCertLen );
       
   250         message.WriteL( 2, certPtr );
       
   251         }
       
   252     }
       
   253 
       
   254 // -----------------------------------------------------------------------------
       
   255 // CWimCallBack::CertificateDeleteResp
       
   256 // Respond to the certificate delete operation
       
   257 // -----------------------------------------------------------------------------
       
   258 //
       
   259 void CWimCallBack::CertificateDeleteResp( 
       
   260     WIMI_TransactId_t aTrId,
       
   261     WIMI_STAT aStatus )
       
   262     {
       
   263     _WIMTRACE(_L("WIM | WIMServer | CWimCallBack::CertificateDeleteResp | Begin"));
       
   264     CompleteResponse( aTrId, aStatus );
       
   265     }
       
   266 
       
   267 // -----------------------------------------------------------------------------
       
   268 // CWimCallBack::CertificateStoreResp
       
   269 // Respond to the certificate store operation
       
   270 // -----------------------------------------------------------------------------
       
   271 //
       
   272 void CWimCallBack::CertificateStoreResp(
       
   273     WIMI_TransactId_t aTrId,
       
   274     WIMI_STAT aStatus,
       
   275     WIMI_Ref_t* /*aCertRef*/ )
       
   276     {
       
   277     _WIMTRACE(_L("WIM | WIMServer | CWimCallBack::CertificateStoreResp | Begin"));
       
   278     TWimReqTrId* trIdType = ( TWimReqTrId* )aTrId;
       
   279     CWimResponse* pTrId = (CWimResponse*)( trIdType->iReqTrId );
       
   280     pTrId->iStatus = aStatus;
       
   281 
       
   282     pTrId->CompleteMsgAndDelete();
       
   283     delete trIdType;
       
   284     }
       
   285 
       
   286 /* ------------ PIN management ---------------------------------------------- */
       
   287 
       
   288 // -----------------------------------------------------------------------------
       
   289 // CWimCallBack::VerifyPINResp
       
   290 // Respond to Verify PIN operation
       
   291 // -----------------------------------------------------------------------------
       
   292 //
       
   293 void CWimCallBack::VerifyPINResp( WIMI_TransactId_t aTrId, WIMI_STAT aStatus )
       
   294     {
       
   295     _WIMTRACE(_L("WIM | WIMServer | CWimCallBack::VerifyPINResp | Begin"));
       
   296     if( aTrId )
       
   297 	    {
       
   298 	    TWimReqTrId* trIdType = ( TWimReqTrId* )aTrId;
       
   299 	    CWimResponse* trId = ( CWimResponse* )( trIdType->iReqTrId );
       
   300 	    trId->iStatus = aStatus;
       
   301 
       
   302 	    // In case PIN was incorrect try ask PIN again, don't complete message
       
   303 	    // If PIN is blocked show note and don't complete message yet.
       
   304         if ( aStatus != WIMI_ERR_BadPIN && aStatus != WIMI_ERR_PINBlocked && aStatus != WIMI_ERR_CardIOError )
       
   305 	        { 	
       
   306 	        trId->CompleteMsgAndDelete(); 
       
   307 	        delete trIdType;
       
   308 	        }
       
   309 	        
       
   310 	    if ( gStatus )
       
   311 	        {
       
   312 	        User::RequestComplete( gStatus, aStatus );
       
   313 	        }
       
   314 	    else // SignTextHandler not active, complete message with error if not done
       
   315 	        {
       
   316 	        if ( aStatus == WIMI_ERR_BadPIN || aStatus == WIMI_ERR_PINBlocked || aStatus == WIMI_ERR_CardIOError )
       
   317 	            {
       
   318 	            trId->CompleteMsgAndDelete();
       
   319 	            delete trIdType;
       
   320 	            }
       
   321 	        }
       
   322 	    }
       
   323     else
       
   324         {
       
   325     	if ( gStatus )
       
   326 	        {
       
   327 	        User::RequestComplete( gStatus, CWimUtilityFuncs::MapWIMError( aStatus ) );
       
   328 	        }
       
   329         }    	 	
       
   330     }
       
   331     
       
   332 
       
   333 // -----------------------------------------------------------------------------
       
   334 // CWimCallBack::ChangePINResp
       
   335 // Respond to Change PIN operation
       
   336 // -----------------------------------------------------------------------------
       
   337 //
       
   338 void CWimCallBack::ChangePINResp( WIMI_TransactId_t aTrId, WIMI_STAT aStatus )
       
   339     {
       
   340     _WIMTRACE(_L("WIM | WIMServer | CWimCallBack::ChangePINResp | Begin"));
       
   341 
       
   342     TWimReqTrId* trIdType = ( TWimReqTrId* )aTrId;
       
   343     CWimResponse* trId = ( CWimResponse* )( trIdType->iReqTrId );
       
   344     trId->iStatus = aStatus;
       
   345 
       
   346     // In case PIN was incorrect try ask PIN again, don't complete message
       
   347     // If PIN is blocked show note and don't complete message yet.
       
   348     if ( aStatus != WIMI_ERR_BadPIN && aStatus != WIMI_ERR_PINBlocked && aStatus != WIMI_ERR_CardIOError )
       
   349         {
       
   350         if( CWimServer::Server()->WimTimer()->TimeRemaining() == 0 )
       
   351             {
       
   352             _WIMTRACE(_L("WIM | WIMServer | CWimCallBack::ChangePINResp | TimeRemaing =0 "));
       
   353             WIMI_Ref_pt pWimRefTemp = NULL;
       
   354             pWimRefTemp = WIMI_GetWIMRef( 0 );
       
   355             if ( pWimRefTemp )  // Close the WIM
       
   356                 {
       
   357                 WIMI_CloseWIM( pWimRefTemp );
       
   358                 free_WIMI_Ref_t( pWimRefTemp );
       
   359                 }
       
   360             }    	
       
   361         trId->CompleteMsgAndDelete(); 
       
   362         delete trIdType;
       
   363         }
       
   364     
       
   365      
       
   366     // Complete SignTextHandler status
       
   367     if ( gStatus )
       
   368         {
       
   369         User::RequestComplete( gStatus, aStatus );
       
   370         }
       
   371     else // SignTextHandler not active, complete message with error if not done
       
   372         {
       
   373         if ( aStatus == WIMI_ERR_BadPIN || aStatus == WIMI_ERR_PINBlocked || aStatus == WIMI_ERR_CardIOError )
       
   374             {
       
   375             trId->CompleteMsgAndDelete();
       
   376             delete trIdType;
       
   377             }
       
   378         }
       
   379       _WIMTRACE(_L("WIM | WIMServer | CWimCallBack::ChangePINResp | 10"));   
       
   380     }
       
   381 
       
   382 // -----------------------------------------------------------------------------
       
   383 // CWimCallBack::UnblockPINResp
       
   384 // Respond to Unblock PIN operation
       
   385 // -----------------------------------------------------------------------------
       
   386 //
       
   387 void CWimCallBack::UnblockPINResp( WIMI_TransactId_t aTrId, WIMI_STAT aStatus )
       
   388     {
       
   389     _WIMTRACE(_L("WIM | WIMServer | CWimCallBack::UnblockPINResp | Begin"));
       
   390 
       
   391     TWimReqTrId* trIdType = ( TWimReqTrId* )aTrId;
       
   392     CWimResponse* trId = ( CWimResponse* )( trIdType->iReqTrId );
       
   393     trId->iStatus = aStatus;
       
   394 
       
   395     // In case PIN was incorrect try ask PIN again, don't complete message
       
   396     // If PIN is blocked show note and don't complete message yet.
       
   397   
       
   398     if ( aStatus != WIMI_ERR_BadPIN && aStatus != WIMI_ERR_PINBlocked && aStatus != WIMI_ERR_CardIOError )
       
   399         {
       
   400         _WIMTRACE(_L("WIM | WIMServer | CWimCallBack::SignResp | TimeRemaing =0 "));
       
   401         WIMI_Ref_pt pWimRefTemp = NULL;
       
   402         pWimRefTemp = WIMI_GetWIMRef( 0 );
       
   403  
       
   404         if ( pWimRefTemp )  // Close the WIM
       
   405             {
       
   406             WIMI_CloseWIM( pWimRefTemp );
       
   407             free_WIMI_Ref_t( pWimRefTemp );
       
   408             }
       
   409         
       
   410         //  WIMI_InitializeReq( &CWimServer::Server()->iWimCallBack );
       
   411         
       
   412         trId->CompleteMsgAndDelete(); 
       
   413         delete trIdType;
       
   414         }
       
   415 
       
   416     // Complete SignTextHandler status
       
   417     if ( gStatus )
       
   418         {
       
   419         User::RequestComplete( gStatus, aStatus );
       
   420         }
       
   421     else // SignTextHandler not active, complete message with error if not done
       
   422         {
       
   423         if ( aStatus == WIMI_ERR_BadPIN || aStatus == WIMI_ERR_PINBlocked || aStatus == WIMI_ERR_CardIOError )
       
   424             {
       
   425             trId->CompleteMsgAndDelete();
       
   426             delete trIdType;
       
   427             }
       
   428         }
       
   429     }
       
   430 
       
   431 // -----------------------------------------------------------------------------
       
   432 // CWimCallBack::EnablePINResp
       
   433 // Respond to Enable PIN Response
       
   434 // -----------------------------------------------------------------------------
       
   435 //
       
   436 void CWimCallBack::EnablePINResp( WIMI_TransactId_t aTrId, WIMI_STAT aStatus )
       
   437     {
       
   438     _WIMTRACE(_L("WIM | WIMServer | CWimCallBack::EnablePINResp | Begin"));
       
   439      
       
   440     TWimReqTrId* trIdType = ( TWimReqTrId* )aTrId;
       
   441     CWimResponse* trId = ( CWimResponse* )( trIdType->iReqTrId );
       
   442     trId->iStatus = aStatus;
       
   443 
       
   444     // In case PIN was incorrect try ask PIN again, don't complete message
       
   445     // If PIN is blocked show note and don't complete message yet.
       
   446     if ( aStatus != WIMI_ERR_BadPIN && aStatus != WIMI_ERR_PINBlocked && aStatus != WIMI_ERR_CardIOError )
       
   447         {
       
   448         if( CWimServer::Server()->WimTimer()->TimeRemaining() == 0 )
       
   449             {
       
   450             _WIMTRACE(_L("WIM | WIMServer | CWimCallBack::SignResp | TimeRemaing =0 "));
       
   451             WIMI_Ref_pt pWimRefTemp = NULL;
       
   452             pWimRefTemp = WIMI_GetWIMRef( 0 );
       
   453             if ( pWimRefTemp )  // Close the WIM
       
   454                 {
       
   455                 WIMI_CloseWIM( pWimRefTemp );
       
   456                 free_WIMI_Ref_t( pWimRefTemp );
       
   457                 }
       
   458             }    	
       
   459         trId->CompleteMsgAndDelete(); 
       
   460         delete trIdType;
       
   461         }
       
   462 
       
   463     // Complete SignTextHandler status
       
   464     if ( gStatus )
       
   465         {
       
   466         User::RequestComplete( gStatus, aStatus );
       
   467         }
       
   468     else // SignTextHandler not active, complete message with error if not done
       
   469         {
       
   470         if ( aStatus == WIMI_ERR_BadPIN || aStatus == WIMI_ERR_PINBlocked || aStatus == WIMI_ERR_CardIOError )
       
   471             {
       
   472             trId->CompleteMsgAndDelete();
       
   473             delete trIdType;
       
   474             }
       
   475         }
       
   476     }
       
   477 
       
   478 /* ------------ Hardware driver support ------------------------------------- */
       
   479 // -----------------------------------------------------------------------------
       
   480 // CWimCallBack::CardInsertedResp
       
   481 // Respond to CardInserted operation
       
   482 // -----------------------------------------------------------------------------
       
   483 //
       
   484 void CWimCallBack::CardInsertedResp(
       
   485     TUint8 /*aReader*/,
       
   486     WIMI_STAT /*aStatus*/,
       
   487     WIMI_Ref_t* /*aWIMRef*/ )
       
   488     {
       
   489     _WIMTRACE(_L("WIM | WIMServer | CWimCallBack::CardInsertedResp | Begin"));
       
   490     }
       
   491 
       
   492 // -----------------------------------------------------------------------------
       
   493 // CWimCallBack::Open
       
   494 // Open connection to card
       
   495 // -----------------------------------------------------------------------------
       
   496 //
       
   497 TUint8 CWimCallBack::Open( TUint8 aReader )
       
   498     {
       
   499     _WIMTRACE(_L("WIM | WIMServer | CWimCallBack::Open | Begin"));
       
   500     __ASSERT_ALWAYS( gApdu, User::Panic( _L( "Null pointer" ), KErrGeneral ) );
       
   501     return gApdu->Open( aReader );
       
   502     }
       
   503 
       
   504 // -----------------------------------------------------------------------------
       
   505 // CWimCallBack::Close
       
   506 // Close connection to card
       
   507 // -----------------------------------------------------------------------------
       
   508 //
       
   509 TUint8 CWimCallBack::Close( TUint8 aReader )
       
   510     {
       
   511     _WIMTRACE(_L("WIM | WIMServer | CWimCallBack::Close | Begin"));
       
   512     __ASSERT_ALWAYS( gApdu, User::Panic( _L( "Null pointer" ), KErrGeneral ) );
       
   513 
       
   514     TUint8 ret;
       
   515     ret = gApdu->Close( aReader );
       
   516     
       
   517      _WIMTRACE(_L("WIM | WIMServer | CWimCallBack::Close | 1"));
       
   518     return ret;
       
   519     }
       
   520 
       
   521 // -----------------------------------------------------------------------------
       
   522 // CWimCallBack::APDUReq
       
   523 // APDU Request
       
   524 // -----------------------------------------------------------------------------
       
   525 //
       
   526 void CWimCallBack::APDUReq( TUint8 aReader, TUint8* aApdu, TUint16 aApdulen )
       
   527     {
       
   528     _WIMTRACE(_L("WIM | WIMServer | CWimCallBack::APDUReq | Begin"));
       
   529     __ASSERT_ALWAYS( gApdu, User::Panic( _L( "Null pointer" ), KErrGeneral ) );
       
   530     
       
   531     WIMI_BinData_t* ret_apdu =
       
   532         ( WIMI_BinData_t* )WSL_OS_Malloc( sizeof( WIMI_BinData_t ) );
       
   533     TUint16 sw;
       
   534 
       
   535     TUint8 status = gApdu->SendAPDU( aReader, aApdu, aApdulen );
       
   536     
       
   537     sw = gApdu->ResponseSW();
       
   538     TPtrC8 ptr = gApdu->ResponseApdu();
       
   539     ret_apdu->pb_buf = ( TUint8* )ptr.Ptr();
       
   540     ret_apdu->ui_buf_length = ( TUint16 )ptr.Length();
       
   541     
       
   542     WIMI_APDUResp( aReader, status, ret_apdu, sw );
       
   543     WSL_OS_Free( ret_apdu );
       
   544     }
       
   545 
       
   546 // -----------------------------------------------------------------------------
       
   547 // CWimCallBack::GetATRReq
       
   548 // Not supported in Series 60
       
   549 // -----------------------------------------------------------------------------
       
   550 //
       
   551 void CWimCallBack::GetATRReq( TUint8 /*aReader*/ )
       
   552     {
       
   553     _WIMTRACE(_L("WIM | WIMServer | CWimCallBack::GetATRReq | Begin"));
       
   554     }
       
   555 
       
   556 // -----------------------------------------------------------------------------
       
   557 // CWimCallBack::GetReaderListReq
       
   558 // Get reader list request
       
   559 // -----------------------------------------------------------------------------
       
   560 //
       
   561 void CWimCallBack::GetReaderListReq()
       
   562     {
       
   563     _WIMTRACE(_L("WIM | WIMServer | CWimCallBack::GetReaderListReq | Begin"));
       
   564     WIMI_BinData_t* list = 
       
   565         ( WIMI_BinData_t * )WSL_OS_Malloc( sizeof( WIMI_BinData_t ) ) ;
       
   566 
       
   567     TInt ret = KErrNone;
       
   568     TUint8 retval = KErrNone;
       
   569 
       
   570     if ( !gApdu )
       
   571         {
       
   572         TRAP( ret, gApdu = CWimApdu::NewL() ); // New CWimApdu
       
   573         }
       
   574 
       
   575     if ( ret != KErrNone )
       
   576         {
       
   577         _WIMTRACE2(_L("WIM|WIMServer|CWimCallBack::GetReaderListReq|CWimApdu::NewL() leaved with %d"), ret);
       
   578         retval = KWimStatusIOError;
       
   579         list->ui_buf_length = 0;
       
   580         list->pb_buf = NULL;
       
   581         }
       
   582     else
       
   583         {
       
   584         TRAP( ret, retval = gApdu->RequestListL() );
       
   585     
       
   586         if ( ret != KErrNone )
       
   587             {
       
   588             retval = KWimStatusIOError;
       
   589             }
       
   590         list->ui_buf_length = gApdu->StatusListLength();
       
   591         _WIMTRACE2(_L("WIM|WIMServer|CWimCallBack::GetReaderListReq|statuslistlength=%d"), list->ui_buf_length);
       
   592         list->pb_buf = (TUint8*)gApdu->StatusList().Ptr();
       
   593         }
       
   594     _WIMTRACE2(_L("WIM|WIMServer|CWimCallBack::GetReaderListReq|retval=%d"), retval);
       
   595 
       
   596     if ( retval == KErrNone )
       
   597         {
       
   598         WIMI_GetReaderListResp( WIMI_APDU_OK, list );
       
   599         }
       
   600     else
       
   601         {
       
   602         WIMI_GetReaderListResp( WIMI_APDU_TRANSMISSION_ERROR, list );
       
   603         }
       
   604     WSL_OS_Free( list );
       
   605     }
       
   606 
       
   607 /* ------------ SIM file reading and OMA Provisioning ----------------------- */
       
   608 
       
   609 // -----------------------------------------------------------------------------
       
   610 // CWimCallBack::ReadSimFileReq
       
   611 // Read SIM file request
       
   612 // -----------------------------------------------------------------------------
       
   613 //
       
   614 void CWimCallBack::ReadSimFileReq( TUint8 aReaderId,
       
   615                                    TUint8* aPath,
       
   616                                    TUint16 aOffset,          
       
   617                                    TUint16 aSize )
       
   618     {
       
   619     _WIMTRACE(_L("WIM | WIMServer | CWimCallBack::ReadSimFileReq | Begin"));
       
   620 
       
   621     TRAPD( ret, DoReadSimFileReqL( aReaderId, aPath, aOffset, aSize ) );
       
   622 
       
   623     if ( ret != KErrNone )  // DoReadSimFileReq leaved
       
   624         {
       
   625         _WIMTRACE2(_L("WIM | WIMServer | CWimCallBack::ReadSimFileReq | Trapped Leave, ret = %d"), ret );
       
   626 
       
   627         WIMI_BinData_t responseBytes;
       
   628         responseBytes.pb_buf = NULL;
       
   629         responseBytes.ui_buf_length = 0;
       
   630         TUint8 status = WIMI_Err;
       
   631         // WIMI call with zero buffer
       
   632         WIMI_SIM_ReadFileResp( aReaderId, status, &responseBytes );
       
   633         }
       
   634     }
       
   635 
       
   636 // -----------------------------------------------------------------------------
       
   637 // CWimCallBack::ReadSimFileReq
       
   638 // Read SIM file request
       
   639 // -----------------------------------------------------------------------------
       
   640 //
       
   641 void CWimCallBack::DoReadSimFileReqL( TUint8 aReaderId,
       
   642                                       TUint8* aPath,
       
   643                                       TUint16 aOffset,          
       
   644                                       TUint16 aSize )
       
   645     {
       
   646     _WIMTRACE(_L("WIM | WIMServer | CWimCallBack::DoReadSimFileReqL | Begin"));
       
   647 
       
   648     if ( !gSimFileHandler ) 
       
   649         {
       
   650         gSimFileHandler = CWimSimFileHandler::NewL();
       
   651         }
       
   652 
       
   653     RMmCustomAPI::TSimFilePath filePath;
       
   654     filePath.Copy( aPath, KSimFilePathLength ); // SIM file path is 8 bytes
       
   655 
       
   656     gSimFileHandler->ReadSimFileL( aReaderId,
       
   657                                    filePath,
       
   658                                    aOffset,
       
   659                                    aSize );
       
   660 
       
   661     _WIMTRACE(_L("WIM | WIMServer | CWimCallBack::DoReadSimFileReqL | End"));
       
   662     }
       
   663 
       
   664 // -----------------------------------------------------------------------------
       
   665 // CWimCallBack::OmaProvisioningResp
       
   666 // Response to OMA Provisioning Smart Card file request
       
   667 // -----------------------------------------------------------------------------
       
   668 //
       
   669 void CWimCallBack::OmaProvisioningResp( WIMI_TransactId_t aTrId,
       
   670                                         WIMI_STAT aStatus,
       
   671                                         TUint16 aFileLen,
       
   672                                         TUint8* aFile )
       
   673     {
       
   674     _WIMTRACE2(_L("WIM | WIMServer | CWimCallBack::OmaProvisioningResp, aFileLen = %d"), aFileLen);
       
   675 
       
   676     TWimReqTrId* trIdType = ( TWimReqTrId* )aTrId;
       
   677     CWimResponse* pTrId = ( CWimResponse* )( trIdType->iReqTrId );
       
   678     pTrId->iStatus = aStatus;
       
   679 
       
   680     if ( pTrId->iStatus == WIMI_Ok )
       
   681         {
       
   682         TRAP( pTrId->iError, OmaProvisioningRespL( pTrId, aFileLen, aFile ) );
       
   683         _WIMTRACE2(_L("WIM | WIMServer | CWimCallBack::OmaProvisioningResp, TRAP(OmaProvisioningRespL)=%d"), pTrId->iError);
       
   684         }
       
   685 
       
   686     pTrId->CompleteMsgAndDelete(); 
       
   687     delete trIdType;
       
   688     _WIMTRACE(_L("WIM | WIMServer | CWimCallBack::OmaProvisioningResp | End"));
       
   689     }
       
   690 
       
   691 // -----------------------------------------------------------------------------
       
   692 // CWimCallBack::OmaProvisioningRespL
       
   693 // Write OMA Provisioning Smart Card file to client memory
       
   694 // -----------------------------------------------------------------------------
       
   695 //
       
   696 void CWimCallBack::OmaProvisioningRespL( CWimResponse* aTrId,
       
   697                                          TUint16 aFileLen,
       
   698                                          TUint8* aFile )
       
   699     {
       
   700     _WIMTRACE2(_L("WIM | WIMServer | CWimCallBack::OmaProvisioningRespL, aFileLen = %d"), aFileLen);
       
   701 
       
   702     RMessage2& message = aTrId->iMessage;
       
   703         
       
   704     TOmaProv omaProvisioning;
       
   705     omaProvisioning.iSize = aFileLen;
       
   706 
       
   707     TPckgBuf<TOmaProv> omaFilePckg( omaProvisioning );
       
   708     message.ReadL( 0, omaFilePckg );
       
   709 
       
   710     TPtr8 omaFilePtr( aFile, aFileLen, aFileLen );
       
   711     message.WriteL( 1, omaFilePtr );
       
   712     }
       
   713 
       
   714 // -----------------------------------------------------------------------------
       
   715 // CWimCallBack::CancelPinOperation
       
   716 // Cancel pin operation by stop apdu sending
       
   717 // -----------------------------------------------------------------------------
       
   718 //
       
   719 void CWimCallBack::CancelPinOperation()
       
   720     {
       
   721     _WIMTRACE(_L("WIM | WIMServer | CWimCallBack::CancelPinOperation Begin"));
       
   722 	gApdu->CancelApduSending();
       
   723 	
       
   724 	WIMI_APDUResp( 0, WIMI_ERR_UserCancelled, NULL, 0 );
       
   725 	
       
   726 	_WIMTRACE(_L("WIM | WIMServer | CWimCallBack::CancelPinOperation End"));
       
   727     }
       
   728 
       
   729 // -----------------------------------------------------------------------------
       
   730 // CWimCallBack::CancelWimInitialize
       
   731 // Cancel Wim Initialize by stop apdu sending
       
   732 // -----------------------------------------------------------------------------
       
   733 //    
       
   734 void CWimCallBack::CancelWimInitialize()
       
   735     {
       
   736 	 _WIMTRACE(_L("WIM | WIMServer | CWimCallBack::CancelWimInitialize Begin"));
       
   737 	gApdu->CancelApduSending();
       
   738 	
       
   739 	WIMI_APDUResp( 0, WIMI_ERR_UserCancelled, NULL, 0 );
       
   740 	
       
   741 	_WIMTRACE(_L("WIM | WIMServer | CWimCallBack::CancelWimInitialize End"));
       
   742     }
       
   743     
       
   744 // -----------------------------------------------------------------------------
       
   745 // CWimCallBack::DeletegApdu
       
   746 //
       
   747 // -----------------------------------------------------------------------------
       
   748 //
       
   749 void CWimCallBack::DeletegApdu()
       
   750     {
       
   751 	if ( gApdu )
       
   752 	    {
       
   753 		delete gApdu;
       
   754 		gApdu= NULL;
       
   755 	    }
       
   756     }
       
   757 
       
   758 // End of File