javaextensions/satsa/apdu/src.s60/cstsconnection.h
branchRCL_3
changeset 14 04becd199f91
equal deleted inserted replaced
13:f5050f1da672 14:04becd199f91
       
     1 /*
       
     2 * Copyright (c) 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 "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 #ifndef CSTSCONNECTION_H
       
    20 #define CSTSCONNECTION_H
       
    21 
       
    22 //  INCLUDES
       
    23 #include "functionserver.h"
       
    24 #include <e32base.h>
       
    25 #include "stsapduconstants.h"   // for TSTSNetworkType
       
    26 #include "cstsuri.h"            // for turitype
       
    27 #include "mstscloseobserver.h"
       
    28 
       
    29 using namespace java::util;
       
    30 
       
    31 namespace java
       
    32 {
       
    33 namespace satsa
       
    34 {
       
    35 
       
    36 // FORWARD DECLARATIONS
       
    37 class CSTSChannelManager;
       
    38 class CSTSSlotManager;
       
    39 class CSTSPinManager;
       
    40 class CSTSApduExchanger;
       
    41 class CSTSAccessControl;
       
    42 class CSTSCardOperationsFacade;
       
    43 class CSTSCardAppManager;
       
    44 class MSTSRespHandler;
       
    45 class CSTSCmdApdu;
       
    46 class CSTSMidletInfo;
       
    47 class CSTSBTSapListener;
       
    48 class CSTSCardStateListener;
       
    49 
       
    50 // CLASS DECLARATION
       
    51 /**
       
    52  *  SATSA-APDUs native side implementation's interface to JNI side.
       
    53  *  Handels communication with smart card.
       
    54  *
       
    55  *  @since 3.0
       
    56  */
       
    57 NONSHARABLE_CLASS(CSTSConnection) : public CBase, public MSTSCloseObserver, public FunctionServer
       
    58 {
       
    59 
       
    60 private: // Type definition
       
    61     enum TAidParserState
       
    62     {
       
    63         EFirstDigit,
       
    64         ESecondDigit,
       
    65         EDot,
       
    66         EERROR
       
    67     };
       
    68 
       
    69 public:
       
    70     enum TConnectionState
       
    71     {
       
    72         EOpened,
       
    73         EClosed,
       
    74         ECardRemoved,
       
    75         EBTSapInUse
       
    76     };
       
    77 
       
    78 public: // Constructors and destructor
       
    79 
       
    80     /**
       
    81      * Two-phased constructor.
       
    82      * @param aRespHandler When asynchronous exchange is ready, response will
       
    83      * be delivered to response handler. Ownership transferred.
       
    84      * @param aMidletInfo Information about midlet
       
    85      */
       
    86     static CSTSConnection* NewL(JNIEnv& aJni,
       
    87                                 jobject aPeer,MSTSRespHandler* aRespHandler,
       
    88                                 CSTSMidletInfo* aMidletInfo);
       
    89 
       
    90     /**
       
    91      * Destructor.
       
    92      */
       
    93     virtual ~CSTSConnection();
       
    94 
       
    95 public: // New functions
       
    96 
       
    97     /**
       
    98      * Opens a connection to smart card application. URI must be set before
       
    99      * this method is called.
       
   100      * @since 3.0
       
   101      */
       
   102     void OpenL();
       
   103 
       
   104     /**
       
   105      * To wrap the CallMethodL()
       
   106      */
       
   107     static void WrapOpenL(CSTSConnection* connection);
       
   108 
       
   109     /**
       
   110      * Closes a connection to smart card. Cancels all pending apdu sending.
       
   111      * @since 3.0
       
   112      */
       
   113     void CloseL();
       
   114 
       
   115     /**
       
   116      * To wrap the CallMethodL()
       
   117      */
       
   118     static void WrapCloseL(CSTSConnection* connection);
       
   119 
       
   120     /**
       
   121      * Pops up a UI that requests the user for an old or existing PIN value
       
   122      * and the new PIN value to change the value of the PIN.
       
   123      * @since 3.0
       
   124      * @param aPinID The type of PIN which is supposed to prompt the user
       
   125      * to change.
       
   126      * @param aResponseAPDU On return contains status word received from
       
   127      * the smart card in byte array. Null if the user cancels the request.
       
   128      */
       
   129     void ChangePinL(TInt aPinID);
       
   130 
       
   131     /**
       
   132      * To wrap the CallMethodL()
       
   133      */
       
   134     static void WrapChangePinL(CSTSConnection* connection, TInt aPinID);
       
   135 
       
   136     /**
       
   137      * Pops up a UI that requests the user to enter the value for the PIN
       
   138      * that is to be disabled.
       
   139      * @since 3.0
       
   140      * @param aPinID The type of PIN which is required to prompt the user
       
   141      * to enter.
       
   142      */
       
   143     void DisablePinL(TInt aPinID);
       
   144     /**
       
   145      * To wrap the CallMethodL()
       
   146      */
       
   147     static void WrapDisablePinL(CSTSConnection* connection, TInt aPinID);
       
   148 
       
   149     /**
       
   150      * Pops up a UI that requests the user to enter the value for the PIN
       
   151      * that is to be enabled.
       
   152      * @since 3.0
       
   153      * @param aPinID The type of PIN which is required to prompt the user
       
   154      * to enter.
       
   155      */
       
   156     void EnablePinL(TInt aPinID);
       
   157     /**
       
   158      * To wrap the CallMethodL()
       
   159      */
       
   160     static void WrapEnablePinL(CSTSConnection* connection, TInt aPinID);
       
   161 
       
   162     /**
       
   163      * Asks from the user PIN value for PIN verification purposes and sends
       
   164      * it to the card.
       
   165      * @since 3.0
       
   166      * @param aPinID The type of PIN which is supposed to prompt the user
       
   167      * to enter.
       
   168      */
       
   169     void EnterPinL(TInt aPinID);
       
   170     /**
       
   171      * To wrap the CallMethodL()
       
   172      */
       
   173     static void WrapEnterPinL(CSTSConnection* connection, TInt aPinID);
       
   174 
       
   175     /**
       
   176      * Pops up a UI that requests the user to enter the value for the
       
   177      * unblocking PIN and the new value for the blocked PIN.
       
   178      * @since 3.0
       
   179      * @param aBlockedPinID The ID of PIN that is to be unblocked.
       
   180      * @param aUnblockingPinID The ID of unblocking PIN.
       
   181      */
       
   182     void UnblockPinL(TInt aBlockedPinID, TInt aUnblockingPinID);
       
   183     /**
       
   184      * To wrap the CallMethodL()
       
   185      */
       
   186     static void WrapUnblockPinL(CSTSConnection* connection, TInt aBlockedPinID, TInt aUnblockingPinID);
       
   187     /**
       
   188      * Exchanges an APDU command with a smart card application.
       
   189      * @since 3.0
       
   190      * @param aCommandAPDU A byte encoded command for the smart card
       
   191      * application
       
   192      */
       
   193     void ExchangeAPDUL(TPtrC8 aCommandAPDU);
       
   194     /**
       
   195      * To wrap the CallMethodL()
       
   196      */
       
   197     static void WrapExchangeAPDUL(CSTSConnection* connection, TPtrC8 aCommandDes);
       
   198 
       
   199     /**
       
   200      * Returns the Answer To Reset (ATR) message sent by the smart card
       
   201      * in response to the reset operation.
       
   202      * @since 3.0
       
   203      * @param aATR On return contains the ATR message if the card
       
   204      * is inserted, or null if the card has been removed or the connection
       
   205      * has been closed.
       
   206      */
       
   207     std::wstring GetATRL();
       
   208     /**
       
   209      * To wrap the CallMethodL()
       
   210      */
       
   211     static std::wstring WrapGetATRL(CSTSConnection* connection);
       
   212 
       
   213     /**
       
   214      * Gets information of smart card slots.
       
   215      * @since 3.0
       
   216      * @param aResponseAPDU Return a information of smart cards slots in
       
   217      * string format.
       
   218      */
       
   219 
       
   220     std::wstring GetSlotsL();
       
   221     /**
       
   222      * To wrap the CallMethodL()
       
   223      */
       
   224     static std::wstring WrapGetSlotsL(CSTSConnection* connection);
       
   225 
       
   226     /**
       
   227      * Sets URI. Ownership transferred.
       
   228      * @since 3.0
       
   229      * @param aURI URI object.
       
   230      */
       
   231     void SetURI(TInt /*CSTSURI& */aURI);
       
   232     /**
       
   233      * To wrap the CallMethodL()
       
   234      */
       
   235     static void WrapSetURI(CSTSConnection* connection, CSTSURI* aURI);
       
   236 
       
   237 public: // Functions from base classes
       
   238 
       
   239     void NotifyClose(TInt aReason);
       
   240 
       
   241 private:
       
   242 
       
   243     // From FunctionServer
       
   244     virtual void vmAttached();
       
   245     virtual void doServerSideInit();
       
   246     void AddToScheduler();
       
   247 
       
   248     /**
       
   249      * C++ default constructor.
       
   250      */
       
   251     CSTSConnection(MSTSRespHandler* aRespHandler,
       
   252                    CSTSMidletInfo* aMidletInfo);
       
   253 
       
   254     /**
       
   255      * By default Symbian 2nd phase constructor is private.
       
   256      */
       
   257     void ConstructL();
       
   258 
       
   259     /**
       
   260      * Closes a connection to smart card. Cancels all pending apdu sending.
       
   261      * For destructor use.
       
   262      * @since 3.0
       
   263      */
       
   264     void Close();
       
   265 
       
   266     /**
       
   267      * Checks iState member variable and leaves if connetion is
       
   268      * closed or card is removed. Checks also iTarget member variable
       
   269      * and leaves if SAT connection is used and it is not allowed.
       
   270      */
       
   271     void CheckStateL(TBool aSATNotAllowed = EFalse);
       
   272 
       
   273     /**
       
   274      * Opens channel and selects card application. If selection fails
       
   275      * closes the channel and leaves with proper leave code.
       
   276      */
       
   277     void DoSelectApplicationL();
       
   278 
       
   279 private: // Data
       
   280 
       
   281     CSTSChannelManager* iChannelManager;//owned
       
   282     CSTSSlotManager* iSlotManager;//owned
       
   283     CSTSPinManager* iPinManager; //owned
       
   284     CSTSApduExchanger* iApduExchanger; //owned
       
   285     CSTSAccessControl* iAccessControl; //owned
       
   286     CSTSCardOperationsFacade* iCOFacade; //owned
       
   287     CSTSCardAppManager* iCardAppManager; //owned
       
   288 
       
   289     TInt iChannel;
       
   290     //Uri, owned
       
   291     CSTSURI* iURI;
       
   292 
       
   293     //SAT or AID connection
       
   294     CSTSURI::TURIType iURITarget;
       
   295     //is connection opened succesfully or not
       
   296     TConnectionState iState;
       
   297     //whether the phone is running in GSM or UMTS
       
   298     TSTSNetworkType iNetwork;
       
   299 
       
   300     //command apdu, owned
       
   301     CSTSCmdApdu* iCmdApdu;
       
   302     MSTSRespHandler* iRespHandler; //owned
       
   303 
       
   304     CSTSMidletInfo* iMidletInfo; //owned
       
   305 
       
   306     HBufC8* iATR; //owned
       
   307 
       
   308     //Bluetooth remote Sim Access Profile Listener
       
   309     CSTSBTSapListener* iBTSapListener; //owned
       
   310 
       
   311     //For listening is card available or not
       
   312     CSTSCardStateListener* iCardStateListener; //owned
       
   313     //JNIEnv* mJni;
       
   314     //jobject mPeer;
       
   315 
       
   316 };
       
   317 
       
   318 } // namespace satsa
       
   319 } // namespace java
       
   320 #endif // CSTSCONNECTION_H
       
   321 // End of File