wim/SwimReader/inc/SwimReader.h
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:  For reading SWIM
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef CSWIMREADER_H
       
    20 #define CSWIMREADER_H
       
    21 
       
    22 //  INCLUDES
       
    23 #include "ScardDefs.h"          // KMaxATRHistoricalBytes
       
    24 #include "SwimEtelApdu.h"       // RApdu
       
    25 #include "SwimReaderConsts.h"
       
    26 #include "SwimApduRespHeader.h"
       
    27 #include "SwimApduReqHeader.h"
       
    28 
       
    29 
       
    30 //  FORWARD DECLARATIONS
       
    31 class CSwimReaderIF;
       
    32 
       
    33 // CLASS DECLARATION
       
    34 
       
    35 /**
       
    36 *  Functional level of SwimReader
       
    37 *  
       
    38 *
       
    39 *  @lib SwimReader.lib
       
    40 *  @since Series60 2.1
       
    41 */
       
    42 class CSwimReader : public CActive
       
    43     {
       
    44     public:  // Constructors and destructor
       
    45     
       
    46         /**
       
    47         * Two-phased constructor.
       
    48         * @param aInterface Pointer to SwimReaderIF
       
    49         */
       
    50         static CSwimReader* NewL( CSwimReaderIF* aInterface );
       
    51          
       
    52         /**
       
    53         * Destructor.
       
    54         */
       
    55         virtual ~CSwimReader();
       
    56         
       
    57     public: // New functions
       
    58 
       
    59         /**
       
    60         * APDU Request
       
    61         * @param aStatus Status of request
       
    62         * @param aCommandAPDU Command APDU 
       
    63         * @param aResponseAPDU Response APDU
       
    64         * @param aServiceType Service type
       
    65         * @param aCardReader Card reader
       
    66         * @param aAppType Application type
       
    67         * @param aPaddingByte Padding byte
       
    68         * @return
       
    69         */
       
    70         void APDUReqL( TRequestStatus& aStatus,
       
    71                        const TPtrC8& aCommandAPDU,
       
    72                        TPtr8& aResponseAPDU,
       
    73                        TUint8 aServiceType = KSendApdu,
       
    74                        TUint8 aCardReader = KNoPreferredReader,
       
    75                        TUint8 aAppType = KAPDUAppTypeWIM,
       
    76                        TUint8 aPaddingByte = 0 );
       
    77         
       
    78         /**
       
    79         * Close Etel and CustomAPI connection
       
    80         * @return void
       
    81         */
       
    82         void Close();
       
    83         
       
    84         /**
       
    85         * Get preferred reader status from PreferredReaderStatus member
       
    86         * @param aReaderStatus Reader's status
       
    87         * @return void
       
    88         */
       
    89         void PreferredReaderStatus( TUint8& aReaderStatus );
       
    90         
       
    91         /**
       
    92         * From given status bytes, select a card reader,
       
    93         * which is present, and card is also present in the reader.
       
    94         * @param aReaderStatuses Reader statys bytes
       
    95         * @param aPreferredReaderStatus Preferred reader status
       
    96         * @param aOldPreferredReader Old preferred reader
       
    97         * @return Reader number which was selected
       
    98         */
       
    99         static TUint8 SelectCardReader(
       
   100             TDesC8&  aReaderStatuses,
       
   101             TUint8& aPreferredReaderStatus,
       
   102             TUint8  aOldPreferredReader = KNoPreferredReader );
       
   103         
       
   104         /**
       
   105         * Sets iCardInserted member variable according the attribute.
       
   106         * @param aIsInserted is the card inserted (ETrue / EFalse)
       
   107         * @return void
       
   108         */
       
   109         void SetCardInserted( TBool aIsInserted );
       
   110         
       
   111         /**
       
   112         * Initializes the reader. Also make APDU_LIST to get all 
       
   113         * statuses of card readers attached to the device.
       
   114         * @param aStatus Request status
       
   115         * @param aHistoricals Historical ATR bytes
       
   116         * @return void
       
   117         */
       
   118         void WakeUpL( TRequestStatus& aStatus, TDes8& aHistoricals );
       
   119 
       
   120     private:
       
   121 
       
   122         /**
       
   123         * C++ default constructor.
       
   124         * @param aInterface Pointer to SwimReaderIF
       
   125         */
       
   126         CSwimReader( CSwimReaderIF* aInterface );
       
   127          
       
   128         /**
       
   129         * Symbian 2nd phase constructor.
       
   130         */
       
   131         void ConstructL();
       
   132 
       
   133         /**
       
   134         * APDU request
       
   135         * @param aCommandAPDU Command APDU
       
   136         * @param aResponseAPDU Response APDU
       
   137         * @param aServiceType Service type
       
   138         * @param aCardReader Card reader number
       
   139         * @param aAppType Application type
       
   140         * @param aPaddingByte Padding byte
       
   141         * @return void
       
   142         */
       
   143         void APDUReqL( const TPtrC8& aCommandAPDU,
       
   144                        TPtr8& aResponseAPDU,
       
   145                        TUint8 aServiceType = KSendApdu,
       
   146                        TUint8 aCardReader = KNoPreferredReader,
       
   147                        TUint8 aAppType = KAPDUAppTypeWIM,
       
   148                        TUint8 aPaddingByte = 0 );
       
   149 
       
   150         /**
       
   151         * APDU request
       
   152         * @param aCommandAPDU Command APDU
       
   153         * @param aResponseAPDU Response APDU
       
   154         * @param aReqHeader APDU request header
       
   155         * @return void
       
   156         */
       
   157         void APDUReqL( const TPtrC8& aCommandAPDU,
       
   158                        TPtr8& aResponseAPDU,
       
   159                        TSwimApduReqHeader& aReqHeader );
       
   160 
       
   161         /**
       
   162         * Cleanup all allocated stuff
       
   163         * @return void
       
   164         */
       
   165         void CleanUp();
       
   166         
       
   167         /**
       
   168         * Handle APDU request
       
   169         * @return Scard error code
       
   170         */
       
   171         TInt HandleAPDUReq();
       
   172         
       
   173         /**
       
   174         * Handle open APDU request
       
   175         * @return Scard error code
       
   176         */
       
   177         TInt HandleOpenAPDUReq();
       
   178         
       
   179         /**
       
   180         * From CActive RunL
       
   181         * @return void
       
   182         */
       
   183         void RunL();
       
   184 
       
   185         /**
       
   186         * From CActive Cancel request 
       
   187         * @return void
       
   188         */
       
   189         void DoCancel();
       
   190 
       
   191     private:    // Data
       
   192         // Enumerator for reader phase
       
   193         enum TReaderPhase
       
   194             {
       
   195             EWakeUpAPDURequest,
       
   196             EAPDURequest
       
   197             };
       
   198 
       
   199         // RApdu class
       
   200         RApdu                       iApdu;
       
   201         // Status for Apdu
       
   202         TUint8                      iApduStatus;
       
   203         // Is the card inserted
       
   204         TBool                       iCardInserted;
       
   205         // Pointer for client status. Not owned.
       
   206         TRequestStatus*             iClientStatus;
       
   207         // Cmd bytes
       
   208         TBufC8<1>                   iCmdBytes;
       
   209         // Pointer to Etel server. Owned.
       
   210         RTelServer*                 iEtelServer;
       
   211         // Header for APDU
       
   212         TSwimApduReqHeader          iHeader;
       
   213         //
       
   214         TBuf8<KMaxATRHistoricalBytes> iHistoricals;
       
   215         // Pointer for SwimReaderIF object. Not owned.
       
   216         CSwimReaderIF*              iInterface;
       
   217         // Phase of reader operations
       
   218         TReaderPhase                iPhase;
       
   219         // Max length of APDU
       
   220         TInt                        iMaxLen;
       
   221         // Pointer to TApdu message. Owned.
       
   222         RMmCustomAPI::TApdu*        iMsg;
       
   223         // Is reader open
       
   224         TBool                       iOpen;
       
   225         // Prefferred reader
       
   226         TUint8                      iPreferredReader;
       
   227         // Prefferred reader status
       
   228         TUint8                      iPreferredReaderStatus;
       
   229         // Is reader attached
       
   230         TBool                       iReaderAttached;
       
   231         // Buffer for reader statusses
       
   232         HBufC8*                     iReaderStatuses;
       
   233         // Pointer to reader statusses. Owned.
       
   234         TPtr8*                      iReaderStatusesPtr;
       
   235         // Request header
       
   236         TSwimApduReqHeader*         iReqHeader;
       
   237         // Pointer to Response APDU. Not owned.
       
   238         TPtr8*                      iResponseAPDU;
       
   239         // Temporary buffer. Owned.
       
   240         HBufC8*                     iTempBuf;
       
   241         // Pointer to Temporary buffer
       
   242         TPtr8*                      iTempPtr;
       
   243     };
       
   244 
       
   245 #endif      // CSWIMREADER_H
       
   246 
       
   247 // End of File