javaextensions/satsa/apdu/src.s60/cstsmanagechannel.cpp
branchRCL_3
changeset 19 04becd199f91
equal deleted inserted replaced
16:f5050f1da672 19: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 
       
    21 #include  "cstsmanagechannel.h"
       
    22 
       
    23 namespace java
       
    24 {
       
    25 namespace satsa
       
    26 {
       
    27 
       
    28 // CONSTANTS
       
    29 const TUint8 KSTSP1OpenChannel = 0x00;
       
    30 const TUint8 KSTSP1CloseChannel = 0x80;
       
    31 const TUint8 KSTSP2AnyChannel = 0x00;
       
    32 const TUint8 KSTSINSManageChannel = 0x70;
       
    33 
       
    34 // ============================ MEMBER FUNCTIONS ===============================
       
    35 
       
    36 // -----------------------------------------------------------------------------
       
    37 // CSTSManageChannel::CSTSManageChannel
       
    38 // C++ default constructor can NOT contain any code, that
       
    39 // might leave.
       
    40 // -----------------------------------------------------------------------------
       
    41 //
       
    42 CSTSManageChannel::CSTSManageChannel()
       
    43 {
       
    44 }
       
    45 
       
    46 // -----------------------------------------------------------------------------
       
    47 // CSTSManageChannel::ConstructL
       
    48 // Symbian 2nd phase constructor can leave.
       
    49 // Constructs Manage Channel apdu for opening or closing channel
       
    50 // If opening channel, aChannel variable is not used.
       
    51 // -----------------------------------------------------------------------------
       
    52 //
       
    53 void CSTSManageChannel::ConstructL(TInt aChannel,
       
    54                                    TSTSManageChannelApduType aType, CSTSApdu::TSTSApduStandard aStandard)
       
    55 {
       
    56     TUint8 p1 = 0x00;
       
    57     TUint8 p2 = 0x00;
       
    58 
       
    59     TInt maxLength = KSTSApduMandatoryHeaderLen + 1;
       
    60 
       
    61     GenerateP1P2(p1, p2, aChannel, aType);
       
    62 
       
    63     iApduData = CSTSApdu::NewL(maxLength, aStandard);
       
    64 
       
    65     // fills whole area with zeros
       
    66     iApduData->ApduPtr().FillZ(maxLength);
       
    67 
       
    68     SetHeader(KSTSCLABasicUMTS, KSTSINSManageChannel, p1, p2);
       
    69 
       
    70     // we expect 1 byte long response, which contains channel number
       
    71     if (aType == ESTSOpenChannel)
       
    72     {
       
    73         SetLe(0x01);
       
    74     }
       
    75     // else no response expected, Le is zero
       
    76 }
       
    77 // -----------------------------------------------------------------------------
       
    78 // CSTSManageChannel::NewLC
       
    79 // Two-phased constructor.
       
    80 // -----------------------------------------------------------------------------
       
    81 //
       
    82 CSTSManageChannel* CSTSManageChannel::NewLC(TInt aChannel,
       
    83         TSTSManageChannelApduType aType, CSTSApdu::TSTSApduStandard aStandard)
       
    84 {
       
    85     CSTSManageChannel* self = new(ELeave) CSTSManageChannel();
       
    86     CleanupStack::PushL(self);
       
    87     self->ConstructL(aChannel, aType, aStandard);
       
    88     return self;
       
    89 }
       
    90 
       
    91 // -----------------------------------------------------------------------------
       
    92 // CSTSManageChannel::NewL
       
    93 // Two-phased constructor.
       
    94 // -----------------------------------------------------------------------------
       
    95 //
       
    96 CSTSManageChannel* CSTSManageChannel::NewL(TInt aChannel,
       
    97         TSTSManageChannelApduType aType, CSTSApdu::TSTSApduStandard aStandard)
       
    98 {
       
    99     CSTSManageChannel* self = CSTSManageChannel::NewLC(aChannel, aType,
       
   100                               aStandard);
       
   101     CleanupStack::Pop(self);
       
   102 
       
   103     return self;
       
   104 }
       
   105 
       
   106 // -----------------------------------------------------------------------------
       
   107 // CSTSManageChannel::SetApduType
       
   108 //
       
   109 // -----------------------------------------------------------------------------
       
   110 //
       
   111 void CSTSManageChannel::SetApduType(TSTSManageChannelApduType aType,
       
   112                                     TInt aChannel)
       
   113 {
       
   114     iType = aType;
       
   115 
       
   116     TUint8 p1;
       
   117     TUint8 p2;
       
   118     GenerateP1P2(p1, p2, aChannel, aType);
       
   119     SetApduByte(p1, ESTSP1);
       
   120     SetApduByte(p2, ESTSP2);
       
   121 
       
   122     // we expect 1 byte long response, which contains channel number
       
   123     if (aType == ESTSOpenChannel)
       
   124     {
       
   125         SetLe(0x01);
       
   126     }
       
   127     else
       
   128     {
       
   129         // no response expected, Le is zero
       
   130         SetLe(0x00);
       
   131     }
       
   132 }
       
   133 
       
   134 // -----------------------------------------------------------------------------
       
   135 // CSTSManageChannel::GenerateP1P2
       
   136 //
       
   137 // -----------------------------------------------------------------------------
       
   138 //
       
   139 void CSTSManageChannel::GenerateP1P2(TUint8& aP1, TUint8& aP2, TInt aChannel,
       
   140                                      TSTSManageChannelApduType aType)
       
   141 {
       
   142 
       
   143     switch (aType)
       
   144     {
       
   145     case ESTSOpenChannel:
       
   146     {
       
   147         aP1 = KSTSP1OpenChannel;
       
   148         aP2 = KSTSP2AnyChannel;
       
   149         break;
       
   150     }
       
   151     case ESTSCloseChannel:
       
   152     {
       
   153         aP1 = KSTSP1CloseChannel;
       
   154         aP2 = (TUint8) aChannel;
       
   155         break;
       
   156     }
       
   157     default:
       
   158     {
       
   159         break;
       
   160     }
       
   161     }
       
   162 }
       
   163 
       
   164 } // namespace satsa
       
   165 } // namespace java
       
   166 //  End of File