javaextensions/satsa/apdu/src.s60/cstsrespapdu.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  "cstsrespapdu.h"
       
    21 
       
    22 namespace java
       
    23 {
       
    24 namespace satsa
       
    25 {
       
    26 
       
    27 // CONSTANTS
       
    28 const TUint8 KSTSNormalEndingSW1 = 0x90;
       
    29 const TUint8 KSTSNormalEndingSW2 = 0x00;
       
    30 const TUint8 KSTSNormalEndingSW1WithExtraInfo = 0x91;
       
    31 const TUint8 KSTSGetResponseSW1Normal = 0x61;
       
    32 const TUint8 KSTSGetResponseSW1USIM1 = 0x9E;
       
    33 const TUint8 KSTSGetResponseSW1USIM2 = 0x9F;
       
    34 const TUint8 KSTSGetResponseSW1EmtpyLe = 0x62;
       
    35 const TUint8 KSTSGetResponseSW1EmtpyLe2 = 0x63;
       
    36 const TUint8 KSTSResendSW1 = 0x6C;
       
    37 
       
    38 // ============================ MEMBER FUNCTIONS ===============================
       
    39 
       
    40 
       
    41 CSTSRespApdu::CSTSRespApdu()
       
    42 {
       
    43     iConnTarget = ESTSAID;
       
    44 }
       
    45 
       
    46 void CSTSRespApdu::ConstructL(TInt aMaxLength,
       
    47                               CSTSApdu::TSTSApduStandard aStandard)
       
    48 {
       
    49     iRespData = CSTSApdu::NewL(aMaxLength, aStandard);
       
    50 }
       
    51 
       
    52 CSTSRespApdu* CSTSRespApdu::NewLC(TInt aMaxLength,
       
    53                                   CSTSApdu::TSTSApduStandard aStandard)
       
    54 {
       
    55     CSTSRespApdu* self = new(ELeave) CSTSRespApdu();
       
    56     CleanupStack::PushL(self);
       
    57     self->ConstructL(aMaxLength, aStandard);
       
    58     return self;
       
    59 }
       
    60 
       
    61 CSTSRespApdu* CSTSRespApdu::NewL(TInt aMaxLength,
       
    62                                  CSTSApdu::TSTSApduStandard aStandard)
       
    63 {
       
    64     CSTSRespApdu* self = CSTSRespApdu::NewLC(aMaxLength, aStandard);
       
    65     CleanupStack::Pop(self);
       
    66     return self;
       
    67 }
       
    68 
       
    69 CSTSRespApdu::~CSTSRespApdu()
       
    70 {
       
    71     delete iRespData;
       
    72 }
       
    73 
       
    74 // -----------------------------------------------------------------------------
       
    75 // CSTSRespApdu::IsNormalEnding
       
    76 // Panics, if apdu data buffer contains too little information.
       
    77 // Checks if SW1 and SW2 bytes of data contain normal ending information.
       
    78 // (other items were commented in a header).
       
    79 // -----------------------------------------------------------------------------
       
    80 TBool CSTSRespApdu::IsNormalEnding() const
       
    81 {
       
    82     TBool returnValue = EFalse;
       
    83     TUint8 sw1 = GetSW1();
       
    84 
       
    85     if ((sw1 == KSTSNormalEndingSW1 && GetSW2() == KSTSNormalEndingSW2) || (sw1
       
    86             == KSTSNormalEndingSW1WithExtraInfo))
       
    87     {
       
    88         returnValue = ETrue;
       
    89     }
       
    90 
       
    91     return returnValue;
       
    92 }
       
    93 
       
    94 // -----------------------------------------------------------------------------
       
    95 // CSTSRespApdu::GetResponseNeeded
       
    96 // Panics, if apdu data buffer contains too little information.
       
    97 // Checks if SW1 byte contain information that GET RESPONSE APDU is needed.
       
    98 // Saves to reference parameter new expected response lenth.
       
    99 // Implementation is done according to JSR177 SATSA-APDU part.
       
   100 // (other items were commented in a header).
       
   101 // -----------------------------------------------------------------------------
       
   102 TBool CSTSRespApdu::GetResponseNeeded(TUint8& aNewLength) const
       
   103 {
       
   104 
       
   105     TBool returnValue = EFalse;
       
   106     TUint8 sw1 = GetSW1();
       
   107     // get response is needed with new length
       
   108     if ((sw1 == KSTSGetResponseSW1Normal) || // both AID/USAT OR
       
   109             ((iConnTarget == ESTSUSAT) && // only in USAT
       
   110              ((sw1 == KSTSGetResponseSW1USIM1) || (sw1
       
   111                                                    == KSTSGetResponseSW1USIM2))))
       
   112     {
       
   113         returnValue = ETrue;
       
   114         aNewLength = GetSW2();
       
   115     }
       
   116     // get response is needed with empty length in USAT connection
       
   117     else if ((iConnTarget == ESTSUSAT) && ((sw1 == KSTSGetResponseSW1EmtpyLe)
       
   118                                            || (sw1 == KSTSGetResponseSW1EmtpyLe2)))
       
   119     {
       
   120         returnValue = ETrue;
       
   121         aNewLength = 0x00; // must be emtpy in this case
       
   122     }
       
   123     return returnValue;
       
   124 }
       
   125 
       
   126 // -----------------------------------------------------------------------------
       
   127 // CSTSRespApdu::ResendNeeded
       
   128 // Panics, if apdu data buffer contains too little information.
       
   129 // Checks if SW1 byte contain information that apdu resending is needed.
       
   130 // Saves to reference parameter new expected response lenth.
       
   131 // Implementation is done according to JSR177 SATSA-APDU part.
       
   132 // (other items were commented in a header).
       
   133 // -----------------------------------------------------------------------------
       
   134 TBool CSTSRespApdu::ResendNeeded(TUint8& aNewLength) const
       
   135 {
       
   136 
       
   137     TBool returnValue = EFalse;
       
   138     // resend is needed with new length
       
   139     if (GetSW1() == KSTSResendSW1)
       
   140     {
       
   141         returnValue = ETrue;
       
   142         aNewLength = GetSW2();
       
   143     }
       
   144     return returnValue;
       
   145 }
       
   146 
       
   147 // -----------------------------------------------------------------------------
       
   148 // CSTSRespApdu::GetSW1
       
   149 // Panics, if apdu data buffer contains too little information.
       
   150 // Second last byte of data is SW1
       
   151 // (other items were commented in a header).
       
   152 // -----------------------------------------------------------------------------
       
   153 TUint8 CSTSRespApdu::GetSW1() const
       
   154 {
       
   155     // SW1 is second last byte
       
   156     return iRespData->ApduPtr().Ptr()[iRespData->ApduPtr().Length() - 2];
       
   157 }
       
   158 
       
   159 // -----------------------------------------------------------------------------
       
   160 // CSTSRespApdu::GetSW2
       
   161 // Panics, if apdu data buffer contains too little information.
       
   162 // Last byte of data is SW2
       
   163 // (other items were commented in a header).
       
   164 // -----------------------------------------------------------------------------
       
   165 TUint8 CSTSRespApdu::GetSW2() const
       
   166 {
       
   167     // SW2 is last byte
       
   168     return iRespData->ApduPtr().Ptr()[iRespData->ApduPtr().Length() - 1];
       
   169 }
       
   170 
       
   171 // -----------------------------------------------------------------------------
       
   172 // CSTSRespApdu::ResponseBytes
       
   173 //
       
   174 // (other items were commented in a header).
       
   175 // -----------------------------------------------------------------------------
       
   176 TPtr8& CSTSRespApdu::ResponseBytes() const
       
   177 {
       
   178     return iRespData->ApduPtr();
       
   179 }
       
   180 
       
   181 // -----------------------------------------------------------------------------
       
   182 // CSTSRespApdu::SetConnectionTarget
       
   183 //
       
   184 // (other items were commented in a header).
       
   185 // -----------------------------------------------------------------------------
       
   186 void CSTSRespApdu::SetConnectionTarget(TSTSConnectionTarget aConnTarget)
       
   187 {
       
   188     iConnTarget = aConnTarget;
       
   189 }
       
   190 
       
   191 } // namespace satsa
       
   192 } // namespace java
       
   193 //  End of File