wim/WimServer/src/WimTokenHandler.cpp
changeset 0 164170e6151a
equal deleted inserted replaced
-1:000000000000 0:164170e6151a
       
     1 /*
       
     2 * Copyright (c) 2002-2009 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:  Methods for token handling
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include    "WimTokenHandler.h"
       
    22 #include    "WimMemMgmt.h"
       
    23 #include    "WimClsv.h"
       
    24 #include    "WimSession.h"
       
    25 #include    "WimTimer.h"
       
    26 #include    "WimSession.h"
       
    27 #include    "WimUtilityFuncs.h"
       
    28 #include    "Wimi.h"            //WIMI definitions
       
    29 #include    "WimTrace.h"
       
    30 
       
    31 
       
    32 // ============================ MEMBER FUNCTIONS ===============================
       
    33 
       
    34 // -----------------------------------------------------------------------------
       
    35 // CWimTokenHandler::CWimTokenHandler
       
    36 // C++ default constructor can NOT contain any code, that
       
    37 // might leave.
       
    38 // -----------------------------------------------------------------------------
       
    39 //
       
    40 CWimTokenHandler::CWimTokenHandler()
       
    41     {
       
    42     _WIMTRACE(_L("WIM | WIMServer | CWimTokenHandler::CWimTokenHandler | Begin"));
       
    43     }
       
    44 
       
    45 // -----------------------------------------------------------------------------
       
    46 // CWimTokenHandler::ConstructL
       
    47 // Symbian 2nd phase constructor can leave.
       
    48 // -----------------------------------------------------------------------------
       
    49 //
       
    50 void CWimTokenHandler::ConstructL()
       
    51     {
       
    52     _WIMTRACE(_L("WIM | WIMServer | CWimTokenHandler::ConstructL | Begin"));
       
    53     iWimUtilFuncs = CWimUtilityFuncs::NewL();
       
    54     }
       
    55 
       
    56 // -----------------------------------------------------------------------------
       
    57 // CWimTokenHandler::NewL
       
    58 // Two-phased constructor.
       
    59 // -----------------------------------------------------------------------------
       
    60 //
       
    61 CWimTokenHandler* CWimTokenHandler::NewL()
       
    62     {
       
    63     _WIMTRACE(_L("WIM | WIMServer | CWimTokenHandler::NewL | Begin"));
       
    64     CWimTokenHandler* self = new( ELeave ) CWimTokenHandler;
       
    65     CleanupStack::PushL( self );
       
    66     self->ConstructL();
       
    67     CleanupStack::Pop( self );
       
    68     return self;
       
    69     }
       
    70 
       
    71 // Destructor
       
    72 CWimTokenHandler::~CWimTokenHandler()
       
    73     {
       
    74     _WIMTRACE(_L("WIM | WIMServer | CWimTokenHandler::~CWimTokenHandler | Begin"));
       
    75     delete iWimUtilFuncs;
       
    76     }
       
    77 
       
    78 // -----------------------------------------------------------------------------
       
    79 // CWimTokenHandler::GetWIMInfoL
       
    80 // Fetches WIM info from wimlib
       
    81 // -----------------------------------------------------------------------------
       
    82 //
       
    83 void CWimTokenHandler::GetWIMInfoL(
       
    84     const RMessage2& aMessage,
       
    85     CWimMemMgmt* const aWimMgmt ) const
       
    86     {
       
    87     _WIMTRACE(_L("WIM | WIMServer | CWimTokenHandler::GetWIMInfoL | Begin"));
       
    88     WIMI_Ref_pt pWimRef = const_cast<WIMI_Ref_pt>( aMessage.Ptr0() ); 
       
    89     
       
    90     __ASSERT_ALWAYS( pWimRef, User::Leave( KErrArgument ) );
       
    91     __ASSERT_ALWAYS( aWimMgmt, User::Leave( KErrArgument ) );
       
    92     if ( !aWimMgmt->ValidateWIMRefL( pWimRef ) )
       
    93         {
       
    94         _WIMTRACE(_L("WIM | WIMServer | CWimTokenHandler::GetWIMInfoL | KErrArgument"));
       
    95         User::LeaveIfError( KErrArgument ); 
       
    96         }
       
    97     WIMI_STAT status = WIMI_Ok;
       
    98     
       
    99     WIMI_Ref_pt pinRef;
       
   100     TUint16 flags;
       
   101     TUint8 seSet;
       
   102     TUint8 version;
       
   103     WIMI_BinData_t ptWimID;
       
   104     WIMI_BinData_t ptManufacturerID;
       
   105     WIMI_BinData_t ptLabel;
       
   106     TUint8 reader = 0; 
       
   107     TBool sim; 
       
   108     TPckgBuf<TWimSecModuleStruct> infoPckg;
       
   109     aMessage.ReadL( 1, infoPckg );
       
   110     
       
   111     status = WIMI_GetWIMInfo( pWimRef,
       
   112                               &flags,
       
   113                               &seSet,
       
   114                               &ptWimID,
       
   115                               &ptManufacturerID,
       
   116                               &ptLabel,
       
   117                               &reader, 
       
   118                               &pinRef, 
       
   119                               &sim, 
       
   120                               &version );
       
   121     if ( status == WIMI_Ok )
       
   122         {
       
   123         // Code MAY NOT leave before ptLabel.pb_buf, ptManufacturerID.pb_buf,
       
   124         // and ptWimID.pb_buf are deallocated. Next AppendWIMRefL() takes the
       
   125         // ownership of pinRef struct.
       
   126         TRAPD( err, aWimMgmt->AppendWIMRefL( pinRef ) );
       
   127         if( err )
       
   128             {
       
   129             WSL_OS_Free( ptLabel.pb_buf );
       
   130             WSL_OS_Free( ptManufacturerID.pb_buf );
       
   131             WSL_OS_Free( ptWimID.pb_buf );
       
   132             // Code can leave after this point.
       
   133             User::Leave( err );
       
   134             }
       
   135         infoPckg().iRefPinG = reinterpret_cast< TUint32 >( pinRef );
       
   136         
       
   137         TBuf<KLabelLen> label;
       
   138         label.Copy( TPtr8( 
       
   139                 ptLabel.pb_buf,
       
   140                 ptLabel.ui_buf_length,
       
   141                 ptLabel.ui_buf_length ) );
       
   142         
       
   143         TBuf<KManufacturerLen> manufacturer;
       
   144         manufacturer.Copy( TPtr8(
       
   145                 ptManufacturerID.pb_buf,
       
   146                 ptManufacturerID.ui_buf_length,
       
   147                 ptManufacturerID.ui_buf_length ) );
       
   148 
       
   149         TBuf<KSerialNumberLen> serialnumber;
       
   150         serialnumber.Copy( TPtr8(
       
   151                 ptWimID.pb_buf,
       
   152                 ptWimID.ui_buf_length,
       
   153                 ptWimID.ui_buf_length ) );
       
   154 
       
   155         infoPckg().iVersion = version;
       
   156         infoPckg().iReader = reader;
       
   157         infoPckg().iLabel = label;
       
   158         infoPckg().iManufacturer = manufacturer;
       
   159         infoPckg().iSerialNumber = serialnumber;
       
   160 
       
   161         WSL_OS_Free( ptLabel.pb_buf );
       
   162         WSL_OS_Free( ptManufacturerID.pb_buf );
       
   163         WSL_OS_Free( ptWimID.pb_buf );
       
   164         // Code can leave after this point.
       
   165 
       
   166         aMessage.WriteL( 1, infoPckg );
       
   167         }
       
   168 
       
   169     aMessage.Complete( CWimUtilityFuncs::MapWIMError( status ) );
       
   170     }
       
   171 
       
   172 // -----------------------------------------------------------------------------
       
   173 // CWimTokenHandler::IsWIMOpenL
       
   174 // Checks if the WIM is already opened.
       
   175 // -----------------------------------------------------------------------------
       
   176 //
       
   177 void CWimTokenHandler::IsWIMOpenL(
       
   178     const RMessage2& aMessage,
       
   179     CWimTimer* const aTimer,
       
   180     CWimMemMgmt* const aWimMgmt ) const
       
   181     {
       
   182     _WIMTRACE(_L("WIM | WIMServer | CWimTokenHandler::IsWIMOpenL | Begin"));
       
   183     WIMI_Ref_pt pWimRef = const_cast<WIMI_Ref_pt>( aMessage.Ptr0() );
       
   184     
       
   185     __ASSERT_ALWAYS( pWimRef, User::Leave( KErrArgument ) );
       
   186     __ASSERT_ALWAYS( aTimer, User::Leave( KErrArgument ) );
       
   187     if ( !aWimMgmt->ValidateWIMRefL( pWimRef ) ) 
       
   188         {
       
   189         _WIMTRACE(_L("WIM | WIMServer | CWimTokenHandler::IsWIMOpenL | KErrArgument"));
       
   190         User::LeaveIfError( KErrArgument ); 
       
   191         }
       
   192 
       
   193     TPckgBuf<TBool> pckg;
       
   194     
       
   195     if ( WIMI_IsWIMOpened( pWimRef ) )
       
   196         {
       
   197         pckg() = ETrue;
       
   198         aTimer->ResetTimer();
       
   199         }
       
   200     else
       
   201         {
       
   202         pckg() = EFalse;
       
   203         }
       
   204 
       
   205     aMessage.WriteL( 1, pckg );
       
   206     aMessage.Complete( KErrNone );
       
   207     }
       
   208 
       
   209 // -----------------------------------------------------------------------------
       
   210 // CWimTokenHandler::CloseWIM
       
   211 // Closes connection to WIM card.
       
   212 // -----------------------------------------------------------------------------
       
   213 //
       
   214 void CWimTokenHandler::CloseWIM( const RMessage2& aMessage ) const
       
   215     {
       
   216     _WIMTRACE(_L("WIM | WIMServer | CWimTokenHandler::CloseWIM | Begin"));
       
   217     WIMI_STAT status = KErrNone;
       
   218     WIMI_Ref_pt wimRef = const_cast<WIMI_Ref_pt>( aMessage.Ptr0() );
       
   219 
       
   220     if ( wimRef )
       
   221         {
       
   222         status = WIMI_CloseWIM( wimRef );
       
   223         }
       
   224     else
       
   225         {
       
   226         status = WIMI_ERR_BadParameters;
       
   227         }
       
   228     aMessage.Complete( CWimUtilityFuncs::MapWIMError( status ) );
       
   229     }
       
   230 
       
   231 //  End of File