javaextensions/satsa/apdu/src.s60/cstscardoperationsfacade.cpp
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 //  INCLUDE FILES
       
    20 #include "rmmcustomapi.h"
       
    21 #include "cstscardoperationsfacade.h"
       
    22 #include <mmtsy_names.h>// TSY and Phone name
       
    23 #include "logger.h"
       
    24 
       
    25 namespace java
       
    26 {
       
    27 namespace satsa
       
    28 {
       
    29 
       
    30 //  CONSTANTS
       
    31 //TApdu info and data
       
    32 const TUint8 KSTSTApduInfoLength = 16;
       
    33 
       
    34 //service types, used for RMmCustomAPI's TApdu info part
       
    35 const TUint8 KSTSSendApdu = 79;
       
    36 const TUint8 KSTSGetATR = 80;
       
    37 
       
    38 //application type, used for RMmCustomAPI's TApdu info part
       
    39 const TUint8 KSTSAPDUAppTypeJavaApp = 3;
       
    40 
       
    41 //Empty
       
    42 const TUint8 KSTSEmpty = 0x00;
       
    43 
       
    44 //header + lc + data +le
       
    45 const TInt KSTSApduDataMaxLength = 4 + 1 + 0xFF + 1;
       
    46 
       
    47 // ============================ MEMBER FUNCTIONS ===============================
       
    48 
       
    49 // -----------------------------------------------------------------------------
       
    50 // CSTSCardOperationsFacade::CSTSCardOperationsFacade
       
    51 // C++ default constructor can NOT contain any code, that
       
    52 // might leave.
       
    53 // -----------------------------------------------------------------------------
       
    54 //
       
    55 CSTSCardOperationsFacade::CSTSCardOperationsFacade() :
       
    56         iCustomAPI(), iInfoPtr(NULL, 0), iDataPtr(NULL, 0), iGSMNetwork(EFalse)
       
    57 {
       
    58 
       
    59 }
       
    60 
       
    61 // -----------------------------------------------------------------------------
       
    62 // CSTSCardOperationsFacade::ConstructL
       
    63 // Symbian 2nd phase constructor can leave.
       
    64 // -----------------------------------------------------------------------------
       
    65 //
       
    66 void CSTSCardOperationsFacade::ConstructL()
       
    67 {
       
    68     User::LeaveIfError(iSession.Connect());
       
    69     //Load in the phone device driver
       
    70     User::LeaveIfError(iSession.LoadPhoneModule(KMmTsyModuleName));
       
    71 
       
    72     User::LeaveIfError(iPhone.Open(iSession, KMmTsyPhoneName));
       
    73 
       
    74     User::LeaveIfError(iCustomAPI.Open(iPhone));
       
    75 
       
    76     //find out which network mode phone is using
       
    77     RMobilePhone::TMobilePhoneNetworkMode networkMode;
       
    78     TInt err = iPhone.GetCurrentMode(networkMode);
       
    79 
       
    80     if (err == KErrNone && networkMode == RMobilePhone::ENetworkModeGsm)
       
    81     {
       
    82         iGSMNetwork = ETrue;
       
    83     }
       
    84 
       
    85     iPhone.Close();
       
    86 
       
    87     iInfoBuf = HBufC8::NewL(KSTSTApduInfoLength);
       
    88     iDataBuf = HBufC8::NewL(KSTSApduDataMaxLength);
       
    89 
       
    90     iApduReq = new(ELeave) RMmCustomAPI::TApdu();
       
    91 }
       
    92 
       
    93 // -----------------------------------------------------------------------------
       
    94 // CSTSCardOperationsFacade::NewL
       
    95 // Two-phased constructor.
       
    96 // -----------------------------------------------------------------------------
       
    97 //
       
    98 CSTSCardOperationsFacade* CSTSCardOperationsFacade::NewL()
       
    99 {
       
   100     CSTSCardOperationsFacade* self = new(ELeave) CSTSCardOperationsFacade;
       
   101     CleanupStack::PushL(self);
       
   102     self->ConstructL();
       
   103     CleanupStack::Pop(self);
       
   104     return self;
       
   105 }
       
   106 
       
   107 // Destructor
       
   108 CSTSCardOperationsFacade::~CSTSCardOperationsFacade()
       
   109 {
       
   110     delete iApduReq;
       
   111     delete iDataBuf;
       
   112     delete iInfoBuf;
       
   113 
       
   114     iCustomAPI.Close();
       
   115     iSession.Close();
       
   116 
       
   117     //is constructor has leaved, this is not closed so do it again
       
   118     iPhone.Close();
       
   119 }
       
   120 
       
   121 // -----------------------------------------------------------------------------
       
   122 // CSTSCardOperationsFacade::SendAPDUReq
       
   123 //
       
   124 // -----------------------------------------------------------------------------
       
   125 //
       
   126 void CSTSCardOperationsFacade::SendAPDUReq(TRequestStatus& aStatus,
       
   127         TUint8 aCardReaderId, TDes8* aCmdData)
       
   128 {
       
   129     LOG(ESATSA, EInfo, "CSTSCardOperationsFacade::SendAPDUReq() called");
       
   130     DoSend(aStatus, KSTSSendApdu, aCardReaderId, aCmdData);
       
   131 }
       
   132 
       
   133 // -----------------------------------------------------------------------------
       
   134 // CSTSCardOperationsFacade::GetResponseBytes
       
   135 //
       
   136 // -----------------------------------------------------------------------------
       
   137 //
       
   138 void CSTSCardOperationsFacade::GetResponseBytes(TDes8* aRspData)
       
   139 {
       
   140     *aRspData = *iApduReq->iData;
       
   141 }
       
   142 
       
   143 // -----------------------------------------------------------------------------
       
   144 // CSTSCardOperationsFacade::CancelAPDUReq
       
   145 //
       
   146 // -----------------------------------------------------------------------------
       
   147 //
       
   148 void CSTSCardOperationsFacade::CancelAPDUReq()
       
   149 {
       
   150     iCustomAPI.CancelAsyncRequest(ECustomSendAPDUReqIPC);
       
   151 }
       
   152 
       
   153 // -----------------------------------------------------------------------------
       
   154 // CSTSCardOperationsFacade::GetATRL
       
   155 //
       
   156 // -----------------------------------------------------------------------------
       
   157 //
       
   158 void CSTSCardOperationsFacade::GetATR(TDes8& aATR, TUint8 aReader)
       
   159 {
       
   160     LOG(ESATSA, EInfo, "CSTSCardOperationsFacade::GetATRL called!");
       
   161     TRequestStatus status;
       
   162     DoSend(status, KSTSGetATR, aReader, &aATR);
       
   163     User::WaitForRequest(status);
       
   164     LOG1(ESATSA, EInfo, "status: %d", status.Int());
       
   165     if (status.Int() != KErrNone)
       
   166     {
       
   167         //null will be returned, if some error occured
       
   168         aATR = KNullDesC8();
       
   169     }
       
   170     else
       
   171     {
       
   172         LOG(ESATSA, EInfo, "Copy the response");
       
   173         //copy ATR data
       
   174         aATR = *iApduReq->iData;
       
   175         LOG(ESATSA, EInfo, "After copying the response");
       
   176 
       
   177     }
       
   178 
       
   179 }
       
   180 
       
   181 // -----------------------------------------------------------------------------
       
   182 // CSTSCardOperationsFacade::DoSend
       
   183 //
       
   184 // -----------------------------------------------------------------------------
       
   185 //
       
   186 void CSTSCardOperationsFacade::DoSend(TRequestStatus& aStatus,
       
   187                                       TUint8 aServiceType, TUint8 aReader, TDes8* aCmdData)
       
   188 {
       
   189     LOG(ESATSA, EInfo, "CSTSCardOperationsFacade::DoSend() called");
       
   190 
       
   191     _LIT(KSTSBufferTooSmall,
       
   192          "CSTSCardOperationsFacade::DoSend: iInfoBuf too small");
       
   193     __ASSERT_ALWAYS((iInfoBuf->Des().MaxLength() >= KSTSTApduInfoLength),
       
   194                     User::Panic(KSTSBufferTooSmall, KErrArgument));
       
   195 
       
   196     LOG(ESATSA, EInfo, "Check Comand Data");
       
   197 
       
   198     _LIT(KSTSEmptyCommand, "CSTSCardOperationsFacade::DoSend: aCmdData is NULL");
       
   199     __ASSERT_ALWAYS((aCmdData), User::Panic(KSTSEmptyCommand, KErrArgument));
       
   200 
       
   201     LOG(ESATSA, EInfo, "Set Info Part");
       
   202     //set info part
       
   203     iInfoBuf->Des().SetLength(0);
       
   204     iInfoBuf->Des().Append(aServiceType);
       
   205     iInfoBuf->Des().Append(aReader);
       
   206     iInfoBuf->Des().Append(KSTSAPDUAppTypeJavaApp);
       
   207     iInfoBuf->Des().Append(KSTSEmpty); //Padding byte, always zero
       
   208 
       
   209     iInfoPtr.Set(iInfoBuf->Des());
       
   210     iApduReq->iInfo = &iInfoPtr;
       
   211 
       
   212     LOG(ESATSA, EInfo, "Set Data Part");
       
   213     //set data part
       
   214     iDataBuf->Des().SetLength(0);
       
   215     iDataBuf->Des().Append(*aCmdData);
       
   216 
       
   217     iDataPtr.Set(iDataBuf->Des());
       
   218     iApduReq->iData = &iDataPtr;
       
   219     LOG(ESATSA, EInfo, "Calling iCustomAPI.SendAPDUReq");
       
   220     iCustomAPI.SendAPDUReq(aStatus, *iApduReq);
       
   221     LOG(ESATSA, EInfo, "--- CSTSCardOperationsFacade::DoSend() ");
       
   222 }
       
   223 
       
   224 // -----------------------------------------------------------------------------
       
   225 // CSTSCardOperationsFacade::IsGSMNetwork
       
   226 //
       
   227 // -----------------------------------------------------------------------------
       
   228 //
       
   229 TBool CSTSCardOperationsFacade::IsGSMNetwork() const
       
   230 {
       
   231     return iGSMNetwork;
       
   232 }
       
   233 
       
   234 } // namespace satsa
       
   235 } // namespace java
       
   236 //  End of File
       
   237