javaextensions/satsa/apdu/src.s60/cstscmdapdu.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  "cstscmdapdu.h"
       
    21 #include "stsapduconstants.h"
       
    22 #include "logger.h"
       
    23 
       
    24 namespace java
       
    25 {
       
    26 namespace satsa
       
    27 {
       
    28 
       
    29 // CONSTANTS
       
    30 
       
    31 //Apdu instructions
       
    32 const TUint8 KSTSINSManageChannel = 0x70;
       
    33 const TUint8 KSTSINSSelectFile = 0xA4;
       
    34 const TUint8 KSTSINSDeactivateFile = 0x04;
       
    35 const TUint8 KSTSINSActivateFile = 0x44;
       
    36 
       
    37 const TUint8 KSTSP1SelectAID = 0x04;
       
    38 
       
    39 const TUint8 KSTSP1SelectByFileId = 0x00;
       
    40 const TUint8 KSTSP1SelectByPathFromMF = 0x08;
       
    41 const TUint8 KSTSP1SelectByPathFromCurrentDF = 0x09;
       
    42 
       
    43 const TInt KFileIdLength = 2;
       
    44 
       
    45 //Lc byte length is one (it is not part of the mandatory header and is not
       
    46 //part of the real data
       
    47 const TInt KSTSHeaderAndLcLength = KSTSApduMandatoryHeaderLen + 1;
       
    48 
       
    49 //Phone application's File Ids on the UICC card
       
    50 //according to ETSI TS 102 221
       
    51 _LIT8(KSTSFileIdDFTelecom, "\x7F\x10");
       
    52 _LIT8(KSTSFileIdDFGSM, "\x7F\x20");
       
    53 
       
    54 _LIT8(KSTSFileIdDFDCS1800, "\x7F\x21");
       
    55 _LIT8(KSTSFileIdDFIS_41, "\x7F\x22");
       
    56 _LIT8(KSTSFileIdDFFP_CTS, "\x7F\x23");
       
    57 _LIT8(KSTSFileIdDFTIA_EIA_136, "\x7F\x24");
       
    58 _LIT8(KSTSFileIdDFTIA_EIA_95, "\x7F\x25");
       
    59 _LIT8(KSTSFileIdDFRFU1, "\x7F\x26"); //Reserved For Future Use
       
    60 _LIT8(KSTSFileIdDFRFU2, "\x7F\x27");
       
    61 _LIT8(KSTSFileIdDFRFU3, "\x7F\x28");
       
    62 _LIT8(KSTSFileIdDFRFU4, "\x7F\x29");
       
    63 _LIT8(KSTSFileIdDFRFU5, "\x7F\x2A");
       
    64 _LIT8(KSTSFileIdDFRFU6, "\x7F\x2B");
       
    65 _LIT8(KSTSFileIdDFRFU7, "\x7F\x2C");
       
    66 _LIT8(KSTSFileIdDFRFU8, "\x7F\x2D");
       
    67 _LIT8(KSTSFileIdDFRFU9, "\x7F\x2E");
       
    68 _LIT8(KSTSFileIdDFRFU10, "\x7F\x2F");
       
    69 
       
    70 _LIT8(KSTSFileIdDFPDC, "\x7F\x80");
       
    71 _LIT8(KSTSFileIdDFTETRA, "\x7F\x90");
       
    72 _LIT8(KSTSFileIdDFIDEN, "\x7F\x31");
       
    73 
       
    74 //PKCS#15 DF files
       
    75 //should read from EF(DIR) file (hardcoded at the moment)
       
    76 _LIT8(KSTSFileIdDFPKCS15Gemplus, "\x7F\x50");
       
    77 _LIT8(KSTSFileIdDFPKCS15Orga, "\x50\x15");
       
    78 
       
    79 // ============================ MEMBER FUNCTIONS ===============================
       
    80 
       
    81 // -----------------------------------------------------------------------------
       
    82 // CSTSCmdApdu::CSTSCmdApdu
       
    83 // C++ default constructor can NOT contain any code, that
       
    84 // might leave.
       
    85 // -----------------------------------------------------------------------------
       
    86 //
       
    87 CSTSCmdApdu::CSTSCmdApdu()
       
    88 {
       
    89 }
       
    90 
       
    91 // -----------------------------------------------------------------------------
       
    92 // CSTSCmdApdu::NewLC
       
    93 // Two-phased constructor.
       
    94 // -----------------------------------------------------------------------------
       
    95 //
       
    96 CSTSCmdApdu* CSTSCmdApdu::NewLC(TDesC8& aApduBytes,
       
    97                                 CSTSApdu::TSTSApduStandard aStandard)
       
    98 {
       
    99     LOG(ESATSA, EInfo, "+ CSTSCmdApdu::NewLC");
       
   100     CSTSCmdApdu* self = new(ELeave) CSTSCmdApdu();
       
   101     CleanupStack::PushL(self);
       
   102     self->ConstructL(aApduBytes, aStandard);
       
   103     LOG(ESATSA, EInfo, "-- CSTSCmdApdu::NewLC");
       
   104     return self;
       
   105 }
       
   106 
       
   107 // -----------------------------------------------------------------------------
       
   108 // CSTSCmdApdu::NewL
       
   109 // Two-phased constructor.
       
   110 // -----------------------------------------------------------------------------
       
   111 //
       
   112 CSTSCmdApdu* CSTSCmdApdu::NewL(TDesC8& aApduBytes,
       
   113                                CSTSApdu::TSTSApduStandard aStandard)
       
   114 {
       
   115     LOG(ESATSA, EInfo, "+ CSTSCmdApdu::NewL() called");
       
   116     CSTSCmdApdu* self = CSTSCmdApdu::NewLC(aApduBytes, aStandard);
       
   117     CleanupStack::Pop(self);
       
   118     LOG(ESATSA, EInfo, "-- CSTSCmdApdu::NewL ");
       
   119     return self;
       
   120 }
       
   121 
       
   122 // Destructor
       
   123 CSTSCmdApdu::~CSTSCmdApdu()
       
   124 {
       
   125     delete iApduData;
       
   126 }
       
   127 
       
   128 // -----------------------------------------------------------------------------
       
   129 // CSTSCmdApdu::ConstructL
       
   130 // Symbian 2nd phase constructor can leave.
       
   131 // -----------------------------------------------------------------------------
       
   132 //
       
   133 void CSTSCmdApdu::ConstructL(TDesC8& aApduBytes,
       
   134                              CSTSApdu::TSTSApduStandard aStandard)
       
   135 {
       
   136     LOG(ESATSA, EInfo, "+ CSTSCmdApdu::ConstructL");
       
   137     iApduData = NULL;
       
   138     iApduData = CSTSApdu::NewL(aApduBytes, aStandard);
       
   139     if (!iApduData)
       
   140     {
       
   141         ELOG(ESATSA, "CSTSCmdApdu::ConstructL: failed to create iApduData");
       
   142     }
       
   143     LOG(ESATSA, EInfo, "-- CSTSCmdApdu::ConstructL");
       
   144 }
       
   145 
       
   146 // -----------------------------------------------------------------------------
       
   147 // CSTSCmdApdu::CheckL
       
   148 // Checks apdu data and leaves with proper error code
       
   149 // Checking is done according to JSR177 design document.
       
   150 // (other items were commented in a header).
       
   151 // -----------------------------------------------------------------------------
       
   152 void CSTSCmdApdu::CheckL(TInt aUsedChannel) const
       
   153 {
       
   154     LOG(ESATSA, EInfo, "+ CSTSCmdApdu::CheckL");
       
   155     CheckApduLengthL();
       
   156 
       
   157     TInt8 cla = ApduByte(ESTSCLA);
       
   158     TInt8 ins = ApduByte(ESTSINS);
       
   159 
       
   160     //contains a card selection APDU
       
   161     if ((ins == (TInt8) KSTSINSSelectFile) && (iApduData->ApduPtr()[ESTSP1]
       
   162             == KSTSP1SelectAID))
       
   163     {
       
   164         ELOG(ESATSA, "CSTSCmdApdu::CheckL:  Select AID: IllegalArgument");
       
   165         User::Leave(KSTSErrIllegalArgument + KSTSErrIASelectApp);
       
   166     }
       
   167 
       
   168     //contains a MANAGE CHANNEL command APDU
       
   169     if (((cla >= 0x00) || (cla <= 0x0F)) //b1 can be "anything", b2 must be 0
       
   170             && (ins == KSTSINSManageChannel))
       
   171     {
       
   172         ELOG(ESATSA, "CSTSCmdApdu::CheckL: Manage Channel: IllegalArgument");
       
   173         User::Leave(KSTSErrIllegalArgument + KSTSErrIAManageChannel);
       
   174     }
       
   175 
       
   176     //if the channel associated with the connection object is non-zero
       
   177     //and the CLA byte has a value other than 0x0X, 0x8X, 0x9X or 0xAX
       
   178     if (aUsedChannel != 0)
       
   179     {
       
   180         TUint8 claMask = 0xF0; //11110000
       
   181         TUint8 claLeft = (TUint8)(cla & claMask);  //ignore low order bits
       
   182         if ((claLeft != 0x00) && //The coding is according to ISO7816-4
       
   183                 (claLeft != 0x90) && (claLeft != 0xA0) && //Coded as ISO7816-4 unless stated otherwise
       
   184                 (claLeft != 0x80)) //Structured as ISO/IEC 7816-4 [12], coding
       
   185             //and meaning is defined in ETSI TS 102 221
       
   186         {
       
   187             ELOG(ESATSA, "CSTSCmdApdu::CheckL: aUsedChannel: IllegalArgument");
       
   188             User::Leave(KSTSErrIllegalArgument + KSTSErrIAOtherCLA);
       
   189         }
       
   190     }
       
   191     CheckPhoneAppSelectionL();
       
   192     LOG(ESATSA, EInfo, "-- CSTSCmdApdu::CheckL");
       
   193 }
       
   194 
       
   195 // -----------------------------------------------------------------------------
       
   196 // CSTSCmdApdu::ApduBytes
       
   197 //
       
   198 // (other items were commented in a header).
       
   199 // -----------------------------------------------------------------------------
       
   200 TPtr8& CSTSCmdApdu::ApduBytes() const
       
   201 {
       
   202     return iApduData->ApduPtr();
       
   203 }
       
   204 
       
   205 // -----------------------------------------------------------------------------
       
   206 // CSTSCmdApdu::CheckApduLengthL
       
   207 // Leaves if apdu length is not atleast same than standard apdu header length
       
   208 // (other items were commented in a header).
       
   209 // -----------------------------------------------------------------------------
       
   210 void CSTSCmdApdu::CheckApduLengthL() const
       
   211 {
       
   212     LOG(ESATSA, EInfo, "+ CSTSCmdApdu::CheckApduLengthL");
       
   213     //too short apdu
       
   214     TInt apduLength = iApduData->ApduPtr().Length();
       
   215     if (apduLength < KSTSApduMandatoryHeaderLen)
       
   216     {
       
   217         ELOG1(ESATSA, "Too short: KSTSErrIllegalArgument. apdulength is %d",
       
   218               apduLength);
       
   219         User::Leave(KSTSErrIllegalArgument + KSTSErrIAMalformedAPDU);
       
   220     }
       
   221 
       
   222     //if data length is not same than Lc
       
   223     //note: if there is no data, P3 means Le
       
   224     if (apduLength > KSTSHeaderAndLcLength + 1) // must be data or Le
       
   225     {
       
   226         TInt lengthAfterHeaderAndLc = apduLength - KSTSHeaderAndLcLength;
       
   227         TInt lc = ApduByte(ESTSLc);
       
   228         ILOG2(ESATSA, "Data length = %d, lc = %d",
       
   229               lengthAfterHeaderAndLc, lc);
       
   230         if ((lengthAfterHeaderAndLc != lc)
       
   231                 && (lengthAfterHeaderAndLc - lc != 1)) //there can be one Le byte
       
   232         {
       
   233             ELOG(ESATSA, "Incorrect data length: KSTSErrIllegalArgument");
       
   234             User::Leave(KSTSErrIllegalArgument + KSTSErrIAMalformedAPDU);
       
   235         }
       
   236     }
       
   237     LOG(ESATSA, EInfo, "-- CSTSCmdApdu::CheckApduLengthL");
       
   238 }
       
   239 
       
   240 // -----------------------------------------------------------------------------
       
   241 // CSTSCmdApdu::SetChannel
       
   242 // Adds gived channel to command APDU message's CLA byte
       
   243 // (other items were commented in a header).
       
   244 // -----------------------------------------------------------------------------
       
   245 void CSTSCmdApdu::SetChannel(TInt aChannel)
       
   246 {
       
   247 
       
   248     // mask for getting cla bytes six first bits
       
   249     TUint8 claMask = 0xFC; //11111100
       
   250     TUint8 channel = (TUint8) aChannel;
       
   251     TUint8 cla = ApduByte(ESTSCLA);
       
   252 
       
   253     // take cla byte's six first bits
       
   254     cla = (TUint8)(cla & claMask);
       
   255     // add channel to cla byte's two last bits
       
   256     cla = (TUint8)(cla | channel);
       
   257 
       
   258     SetApduByte(cla, ESTSCLA);
       
   259 }
       
   260 
       
   261 // -----------------------------------------------------------------------------
       
   262 // CSTSCmdApdu::SetHeader
       
   263 //
       
   264 // (other items were commented in a header).
       
   265 // -----------------------------------------------------------------------------
       
   266 void CSTSCmdApdu::SetHeader(TUint8 aCla, TUint8 aIns, TUint8 aP1, TUint8 aP2)
       
   267 {
       
   268 
       
   269     SetApduByte(aCla, ESTSCLA);
       
   270     SetApduByte(aIns, ESTSINS);
       
   271     SetApduByte(aP1, ESTSP1);
       
   272     SetApduByte(aP2, ESTSP2);
       
   273 }
       
   274 
       
   275 // -----------------------------------------------------------------------------
       
   276 // CSTSCmdApdu::Header
       
   277 //
       
   278 // (other items were commented in a header).
       
   279 // -----------------------------------------------------------------------------
       
   280 const TDesC8& CSTSCmdApdu::Header()
       
   281 {
       
   282     iHeaderPtr.Set(iApduData->ApduPtr().Mid(0, KSTSApduMandatoryHeaderLen));
       
   283     return iHeaderPtr;
       
   284 }
       
   285 
       
   286 // -----------------------------------------------------------------------------
       
   287 // CSTSCmdApdu::AppendDatabytesL
       
   288 //
       
   289 // (other items were commented in a header).
       
   290 // -----------------------------------------------------------------------------
       
   291 void CSTSCmdApdu::AppendDatabytesL(const TDesC8& aDataBytes)
       
   292 {
       
   293     TInt dataLength = aDataBytes.Length();
       
   294 
       
   295     //headerlength + Lc + Data
       
   296     TInt maxLength = KSTSApduMandatoryHeaderLen + 1 + dataLength;
       
   297     iApduData->ReAllocL(maxLength);
       
   298     iApduData->ApduPtr().Append((TUint8) dataLength); //Le
       
   299     iApduData->ApduPtr().Append(aDataBytes); //data
       
   300 }
       
   301 
       
   302 // -----------------------------------------------------------------------------
       
   303 // CSTSCmdApdu::SetLe
       
   304 //
       
   305 // (other items were commented in a header).
       
   306 // -----------------------------------------------------------------------------
       
   307 void CSTSCmdApdu::SetLe(TUint8 aLe)
       
   308 {
       
   309     TInt lenght = iApduData->ApduPtr().Length();
       
   310 
       
   311     //last byte is Le
       
   312     iApduData->ApduPtr()[lenght - 1] = aLe;
       
   313 }
       
   314 
       
   315 // -----------------------------------------------------------------------------
       
   316 // CSTSCmdApdu::ApduByte
       
   317 //
       
   318 // (other items were commented in a header).
       
   319 // -----------------------------------------------------------------------------
       
   320 TUint8 CSTSCmdApdu::ApduByte(TSTSApduByteType aByteType) const
       
   321 {
       
   322 
       
   323     return iApduData->ApduPtr()[aByteType];
       
   324 }
       
   325 
       
   326 // -----------------------------------------------------------------------------
       
   327 // CSTSCmdApdu::SetApduByte
       
   328 //
       
   329 // (other items were commented in a header).
       
   330 // -----------------------------------------------------------------------------
       
   331 void CSTSCmdApdu::SetApduByte(TUint8 aByte, TSTSApduByteType aByteType)
       
   332 {
       
   333     iApduData->ApduPtr()[aByteType] = aByte;
       
   334 }
       
   335 
       
   336 // -----------------------------------------------------------------------------
       
   337 // CSTSCmdApdu::CheckPhoneAppSelectionL
       
   338 // Checks if used apdu leads to selection of application/file or
       
   339 // other restricted file which is not allowed to be selected. Leaves with
       
   340 // security leave if it is true.
       
   341 // (other items were commented in a header).
       
   342 // -----------------------------------------------------------------------------
       
   343 void CSTSCmdApdu::CheckPhoneAppSelectionL() const
       
   344 {
       
   345     LOG(ESATSA, EInfo, "+ CSTSCmdApdu::CheckPhoneAppSelectionL, called");
       
   346     TInt dataLength = iApduData->ApduPtr().Length() - KSTSHeaderAndLcLength;
       
   347     LOG1(ESATSA, EInfo, "CSTSCmdApdu::CheckPhoneAppSelectionL, dataLength: %d", dataLength);
       
   348 
       
   349     //Checks does apdu lead to file selection
       
   350     if (IsProperFileSelectionApdu(dataLength))
       
   351     {
       
   352         LOG(ESATSA, EInfo, "is file selection apdu");
       
   353         //take data part from the apdu
       
   354         const TPtrC8 data(iApduData->ApduPtr().Ptr() + KSTSHeaderAndLcLength,
       
   355                           dataLength);
       
   356 
       
   357         //check that possible file id does not contain forbidden file id
       
   358         CheckFileIdL(data);
       
   359         //check that possible path does not contain forbidden file ids
       
   360         CheckPathL(data);
       
   361     }
       
   362 }
       
   363 
       
   364 // -----------------------------------------------------------------------------
       
   365 // CSTSCmdApdu::CheckIllegalFileIdL
       
   366 // Checks is file id forbidden or not. Leaves if it is forbidden.
       
   367 // (other items were commented in a header).
       
   368 // -----------------------------------------------------------------------------
       
   369 void CSTSCmdApdu::CheckIllegalFileIdL(const TDesC8& aFileId) const
       
   370 {
       
   371     LOG(ESATSA, EInfo, "CSTSCmdApdu::CheckIllegalFileIdL, called");
       
   372     //file id length should be 2
       
   373 
       
   374 
       
   375     if ((aFileId == KSTSFileIdDFTelecom()) || (aFileId == KSTSFileIdDFGSM())
       
   376             || (aFileId == KSTSFileIdDFDCS1800()) || (aFileId
       
   377                     == KSTSFileIdDFIS_41()) || (aFileId == KSTSFileIdDFFP_CTS())
       
   378             || (aFileId == KSTSFileIdDFTIA_EIA_136()) || (aFileId
       
   379                     == KSTSFileIdDFTIA_EIA_95()) || (aFileId == KSTSFileIdDFRFU1())
       
   380             || (aFileId == KSTSFileIdDFRFU2()) || (aFileId
       
   381                                                    == KSTSFileIdDFRFU3()) || (aFileId == KSTSFileIdDFRFU4())
       
   382             || (aFileId == KSTSFileIdDFRFU5()) || (aFileId
       
   383                                                    == KSTSFileIdDFRFU6()) || (aFileId == KSTSFileIdDFRFU7())
       
   384             || (aFileId == KSTSFileIdDFRFU8()) || (aFileId
       
   385                                                    == KSTSFileIdDFRFU9()) || (aFileId == KSTSFileIdDFRFU10())
       
   386             || (aFileId == KSTSFileIdDFPDC()) || (aFileId
       
   387                                                   == KSTSFileIdDFTETRA()) || (aFileId == KSTSFileIdDFIDEN())
       
   388             || (aFileId == KSTSFileIdDFPKCS15Gemplus()) || (aFileId
       
   389                     == KSTSFileIdDFPKCS15Orga()))
       
   390     {
       
   391         ELOG(ESATSA, "CSTSCmdApdu::CheckIllegalFileIdL, Is illegal!");
       
   392         User::Leave(KSTSErrSecurity + KSTSErrSECIllegalFileID);
       
   393     }
       
   394 }
       
   395 
       
   396 // -----------------------------------------------------------------------------
       
   397 // CSTSCmdApdu::IsProperFileSelectionApdu
       
   398 // Checks does apdu lead to file selection. SELECT FILE, DEACTIVATE FILE and
       
   399 // ACTIVATE FILE apdu will lead to file selection in case of successful
       
   400 // execution of the command,
       
   401 // (other items were commented in a header).
       
   402 // -----------------------------------------------------------------------------
       
   403 TBool CSTSCmdApdu::IsProperFileSelectionApdu(TInt aDataLength) const
       
   404 {
       
   405     LOG(ESATSA, EInfo, "CSTSCmdApdu::IsProperFileSelectionApdu, called");
       
   406 
       
   407     TBool returnValue = EFalse;
       
   408     //Check is it SELECT FILE apdu and contains data field
       
   409     if (ApduByte(ESTSINS) == KSTSINSSelectFile && aDataLength > 0)
       
   410     {
       
   411         returnValue = ETrue;
       
   412     }
       
   413     //Check is it DEACTIVATE FILE apdu and contains data field
       
   414     else if (ApduByte(ESTSINS) == KSTSINSDeactivateFile && aDataLength > 0)
       
   415     {
       
   416         returnValue = ETrue;
       
   417     }
       
   418     //Check is it ACTIVATE apdu and contains data field
       
   419     else if (ApduByte(ESTSINS) == KSTSINSActivateFile && aDataLength > 0)
       
   420     {
       
   421         returnValue = ETrue;
       
   422     }
       
   423 
       
   424     return returnValue;
       
   425 }
       
   426 
       
   427 // -----------------------------------------------------------------------------
       
   428 // CSTSCmdApdu::CheckPathL
       
   429 // Checks is there proper path and does it contain illegal file ids.
       
   430 // Leaves if there is illegal file ids.
       
   431 // Note that apdu must be SELECT FILE, DEACTIVATE FILE or ACTIVATE FILE apdu.
       
   432 // That can be checked with IsProperFileSelectionApdu method. P1 byte of those
       
   433 // apdus are the same in select by path from MF and select by path from current
       
   434 // DF case.
       
   435 // (other items were commented in a header).
       
   436 // -----------------------------------------------------------------------------
       
   437 void CSTSCmdApdu::CheckPathL(const TDesC8& aData) const
       
   438 {
       
   439     TUint8 p1 = ApduByte(ESTSP1);
       
   440     TInt dataLength = aData.Length();
       
   441 
       
   442     //check that path does not contain forbidden ids
       
   443     if ((p1 == KSTSP1SelectByPathFromMF) || (p1
       
   444             == KSTSP1SelectByPathFromCurrentDF))
       
   445     {
       
   446         LOG(ESATSA, EInfo, "CSTSCmdApdu::CheckPathL, is Path");
       
   447         TInt remainder;
       
   448         TInt tmpDataLength = dataLength;
       
   449         I64DIVMOD(tmpDataLength, KFileIdLength, remainder);
       
   450         //if data field does not contain concatenation of file ids
       
   451         if (remainder != 0)
       
   452         {
       
   453             ELOG(ESATSA, "CSTSCmdApdu::CheckPathL, Leave!!");
       
   454             User::Leave(KSTSErrIllegalArgument + KSTSErrIAMalformedAPDU);
       
   455         }
       
   456         else
       
   457         {
       
   458             LOG(ESATSA, EInfo, "CSTSCmdApdu::CheckPathL, go through in loop");
       
   459             //go through in loop all file ids in path
       
   460             for (TInt i = 0; i < dataLength; i += KFileIdLength)
       
   461             {
       
   462                 TPtrC8 currentFid(aData.Ptr() + i, KFileIdLength);
       
   463                 CheckIllegalFileIdL(currentFid);
       
   464             }
       
   465         }
       
   466     }
       
   467     //else no actions
       
   468 }
       
   469 
       
   470 // -----------------------------------------------------------------------------
       
   471 // CSTSCmdApdu::CheckFileIdL
       
   472 // Checks is there proper file id and is it illegal. Leaves if there is illegal
       
   473 // file id.
       
   474 // Note that apdu must be SELECT FILE, DEACTIVATE FILE or ACTIVATE FILE apdu.
       
   475 // That can be checked with IsProperFileSelectionApdu method. INS byte of those
       
   476 // apdus are the same in select by file id case.
       
   477 // (other items were commented in a header).
       
   478 // -----------------------------------------------------------------------------
       
   479 void CSTSCmdApdu::CheckFileIdL(const TDesC8& aData) const
       
   480 {
       
   481     TUint8 p1 = ApduByte(ESTSP1);
       
   482     TInt dataLength = aData.Length();
       
   483 
       
   484     //Check is file id used
       
   485     if (p1 == KSTSP1SelectByFileId)
       
   486     {
       
   487         //if data field does not contain file id, leave
       
   488         if (dataLength != KFileIdLength)
       
   489         {
       
   490             ELOG(ESATSA, "CSTSCmdApdu::CheckFileIdL, Leave !!");
       
   491             User::Leave(KSTSErrIllegalArgument + KSTSErrIAMalformedAPDU);
       
   492         }
       
   493         else
       
   494         {
       
   495             //check that file id is not forbidden
       
   496             CheckIllegalFileIdL(aData);
       
   497         }
       
   498     }
       
   499     //else no actions
       
   500 }
       
   501 
       
   502 } // namespace satsa
       
   503 } // namespace java
       
   504 //  End of File
       
   505