|
1 /* |
|
2 * Copyright (c) 2003 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: Class for APDU response header |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "SwimApduRespHeader.h" |
|
22 #include "WimTrace.h" // for trace logging |
|
23 |
|
24 #ifdef _DEBUG |
|
25 #include <flogger.h> |
|
26 #endif |
|
27 |
|
28 // ============================ MEMBER FUNCTIONS =============================== |
|
29 |
|
30 // ----------------------------------------------------------------------------- |
|
31 // TSwimApduRespHeader::TSwimApduRespHeader |
|
32 // Constructor |
|
33 // ----------------------------------------------------------------------------- |
|
34 // |
|
35 TSwimApduRespHeader::TSwimApduRespHeader( const TDesC8& aData ) |
|
36 { |
|
37 _WIMTRACE(_L("WIM|SwimReader|TSwimApduRespHeader::TSwimApduRespHeader|Begin")); |
|
38 Copy( aData ); |
|
39 } |
|
40 |
|
41 // ----------------------------------------------------------------------------- |
|
42 // TSwimApduRespHeader::AnyByte |
|
43 // Return byte in given index |
|
44 // ----------------------------------------------------------------------------- |
|
45 // |
|
46 TUint8 TSwimApduRespHeader::AnyByte( TUint8 aIndex ) |
|
47 { |
|
48 _WIMTRACE(_L("WIM|SwimReader|TSwimApduRespHeader::AnyByte|Begin")); |
|
49 if ( iData.Length() > aIndex ) |
|
50 { |
|
51 return iData[aIndex]; |
|
52 } |
|
53 else |
|
54 { |
|
55 return 0; |
|
56 } |
|
57 } |
|
58 |
|
59 // ----------------------------------------------------------------------------- |
|
60 // TSwimApduRespHeader::Copy |
|
61 // Copy data |
|
62 // ----------------------------------------------------------------------------- |
|
63 // |
|
64 void TSwimApduRespHeader::Copy( const TDesC8& aData ) |
|
65 { |
|
66 _WIMTRACE(_L("WIM|SwimReader|TSwimApduRespHeader::Copy|Begin")); |
|
67 // If max length is shorter than length of given data, |
|
68 // copy only max length amount of data. |
|
69 if ( KMaxApduHeaderLen >= aData.Length() ) |
|
70 { |
|
71 iData = aData; |
|
72 } |
|
73 else |
|
74 { |
|
75 iData = aData.Left( KMaxApduHeaderLen ); |
|
76 } |
|
77 } |
|
78 |
|
79 // ----------------------------------------------------------------------------- |
|
80 // TSwimApduRespHeader::DataLength |
|
81 // Return data length |
|
82 // ----------------------------------------------------------------------------- |
|
83 // |
|
84 TUint16 TSwimApduRespHeader::DataLength() |
|
85 { |
|
86 _WIMTRACE(_L("WIM|SwimReader|TSwimApduRespHeader::DataLength|Begin")); |
|
87 TUint8 serviceType, shortRet; |
|
88 TUint16 ret = 0; |
|
89 |
|
90 serviceType = ServiceType(); |
|
91 |
|
92 if ( serviceType == KList ) |
|
93 { |
|
94 shortRet = ShortDataLength(); |
|
95 ret = shortRet; |
|
96 } |
|
97 else if ( iData.Length() > 13 ) |
|
98 { |
|
99 ret = TUint16( iData[12] << 8 ); |
|
100 ret = TUint16( ret | iData[13] ); |
|
101 } |
|
102 |
|
103 return ret; |
|
104 } |
|
105 |
|
106 // ----------------------------------------------------------------------------- |
|
107 // TSwimApduRespHeader::operator= |
|
108 // Operator = |
|
109 // ----------------------------------------------------------------------------- |
|
110 // |
|
111 void TSwimApduRespHeader::operator=( const TDesC8& aData ) |
|
112 { |
|
113 _WIMTRACE(_L("WIM|SwimReader|TSwimApduRespHeader::operator=|Begin")); |
|
114 Copy( aData ); |
|
115 } |
|
116 |
|
117 // ----------------------------------------------------------------------------- |
|
118 // TSwimApduRespHeader::ServiceType |
|
119 // Return Service type byte |
|
120 // ----------------------------------------------------------------------------- |
|
121 // |
|
122 TUint8 TSwimApduRespHeader::ServiceType() |
|
123 { |
|
124 _WIMTRACE(_L("WIM|SwimReader|TSwimApduRespHeader::ServiceType|Begin")); |
|
125 return AnyByte( KIndexRespServiceType ); |
|
126 } |
|
127 |
|
128 // ----------------------------------------------------------------------------- |
|
129 // TSwimApduRespHeader::ShortDataLength |
|
130 // Return ShortDataLength byte |
|
131 // ----------------------------------------------------------------------------- |
|
132 // |
|
133 TUint8 TSwimApduRespHeader::ShortDataLength() |
|
134 { |
|
135 _WIMTRACE(_L("WIM|SwimReader|TSwimApduRespHeader::ShortDataLength|Begin")); |
|
136 if ( ServiceType() == KSendApdu ) |
|
137 { |
|
138 return 0; |
|
139 } |
|
140 else |
|
141 { |
|
142 return AnyByte( KIndexRespSDataLength ); |
|
143 } |
|
144 } |
|
145 |
|
146 // ----------------------------------------------------------------------------- |
|
147 // TSwimApduRespHeader::Status |
|
148 // Return status byte |
|
149 // ----------------------------------------------------------------------------- |
|
150 // |
|
151 TUint8 TSwimApduRespHeader::Status() |
|
152 { |
|
153 _WIMTRACE2(_L("WIM|SwimReader|TSwimApduRespHeader::Status|status=%d"), AnyByte(KIndexRespStatus)); |
|
154 return AnyByte( KIndexRespStatus ); |
|
155 } |
|
156 |
|
157 // End of File |