|
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: Session for the Scard server, to a single client-side session. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #ifndef CSCARDSESSION_H |
|
21 #define CSCARDSESSION_H |
|
22 |
|
23 // INCLUDES |
|
24 #include "ScardDefs.h" |
|
25 #include <f32file.h> // f32file header needed for loading dlls |
|
26 |
|
27 // CONSTANTS |
|
28 const TInt KOpenChannelResponseLength = 3; |
|
29 const TInt KApduHeaderLength = 4; |
|
30 |
|
31 const TInt KCLA = 0; // class byte |
|
32 const TInt KINS = 1; // instruction code |
|
33 const TInt KP1 = 2; // control parameter 1 |
|
34 const TInt KP2 = 3; // control parameter 2 |
|
35 const TInt KLcHigh = 4; // command length high byte |
|
36 const TInt KLcLow = 5; // command length low byte |
|
37 |
|
38 const TInt8 KNoChannel = 0; |
|
39 const TInt8 KChannelByCard = 1; |
|
40 const TInt8 KChannelByCID = 2; |
|
41 |
|
42 |
|
43 // FORWARD DECLARATIONS |
|
44 class CScardAccessControl; |
|
45 class CScardServer; |
|
46 class MScardReader; |
|
47 class CScardNotifyRegistry; |
|
48 |
|
49 // CLASS DECLARATION |
|
50 |
|
51 /** |
|
52 * Session for the Scard server, to a single client-side session |
|
53 * |
|
54 * @lib Scard.lib |
|
55 * @since Series60 2.1 |
|
56 */ |
|
57 class CScardSession : public CSession2 |
|
58 { |
|
59 public: // Constructors and destructor |
|
60 |
|
61 /** |
|
62 * Two-phased constructor. |
|
63 * @param aServer Pointer to ScardServer object |
|
64 */ |
|
65 static CScardSession* NewL( CScardServer* aServer ); |
|
66 |
|
67 /** |
|
68 * Destructor. |
|
69 */ |
|
70 virtual ~CScardSession(); |
|
71 |
|
72 public: // New functions |
|
73 |
|
74 /** |
|
75 * Clean up the reader event listeners. |
|
76 * @param aMessage Client message |
|
77 * @return void |
|
78 */ |
|
79 void CloseSession( const RMessage2& aMessage ); |
|
80 |
|
81 /** |
|
82 * Wrapper for the actual ServiceL() (this needed only because of |
|
83 * connector class) |
|
84 * @param aMessageHandle Handle to client message |
|
85 * @return void |
|
86 */ |
|
87 virtual void ServiceL( const TMessageHandle& aMessageHandle ); |
|
88 |
|
89 /** |
|
90 * Asynchronous operation completed |
|
91 * @param aMessageHandle Handle to client message |
|
92 * @param aErrorCode Error code |
|
93 * @return void |
|
94 */ |
|
95 virtual void AsynchronousServiceComplete( |
|
96 const TMessageHandle& aMessageHandle, |
|
97 const TInt aErrorCode ); |
|
98 |
|
99 /** |
|
100 * This is here only for derivative class CScardConnector |
|
101 * It implements and needs this function |
|
102 * @param aServiceStatus Service status |
|
103 * @param aATR ATR bytes |
|
104 * @param aReaderID Reader ID from which event comes |
|
105 * @return void |
|
106 */ |
|
107 virtual void CardEvent( const TScardServiceStatus aServiceStatus, |
|
108 const TScardATR& aATR, |
|
109 const TReaderID& aReaderID ); |
|
110 |
|
111 /** |
|
112 * A reader has finally been contacted. |
|
113 * @param aReaderID Reader ID |
|
114 * @param aMessage Client essage |
|
115 * @param aErrorCode Error code |
|
116 * @return void |
|
117 */ |
|
118 void ConnectionDone( const TReaderID& aReaderID, |
|
119 const RMessage2& aMessage, |
|
120 const TInt aErrorCode ); |
|
121 |
|
122 /** |
|
123 * Detach this session from the reader |
|
124 * @return void |
|
125 */ |
|
126 void DisconnectFromReader(); |
|
127 |
|
128 protected: |
|
129 |
|
130 /** |
|
131 * C++ default constructor. |
|
132 */ |
|
133 CScardSession(); |
|
134 |
|
135 protected: // Functions from base classes |
|
136 |
|
137 /** |
|
138 * From CSharableSession. Service a request message |
|
139 * @param aMessage Message |
|
140 * @return void |
|
141 */ |
|
142 void ServiceL( const RMessage2& aMessage ); |
|
143 |
|
144 private: |
|
145 /** |
|
146 * By default Symbian 2nd phase constructor is private. |
|
147 */ |
|
148 void ConstructL( CScardServer* aServer ); |
|
149 |
|
150 /** |
|
151 * Connect to reader |
|
152 * @param aMessage Message |
|
153 * @return void |
|
154 */ |
|
155 void ConnectToReaderL( const RMessage2& aMessage ); |
|
156 |
|
157 /** |
|
158 * Get reader/card capabilities |
|
159 * @param aMessage Message |
|
160 * @return void |
|
161 */ |
|
162 void GetCapabilities( const RMessage2& aMessage ); |
|
163 |
|
164 /** |
|
165 * Send data to card |
|
166 * @param aMessage Message |
|
167 * @return void |
|
168 */ |
|
169 void TransmitToCard( const RMessage2& aMessage ); |
|
170 |
|
171 /** |
|
172 * Cancel everything |
|
173 * @return void |
|
174 */ |
|
175 void CancelTransmitL(); |
|
176 |
|
177 /** |
|
178 * Open/close channel, get channel status |
|
179 * @param aMessage Message |
|
180 * @return void |
|
181 */ |
|
182 void ManageChannel( const RMessage2& aMessage ); |
|
183 |
|
184 /** |
|
185 * Helper function for ManageChannel. Create and send a |
|
186 * manage channel apdu according to parameters |
|
187 * @param aMessage Message |
|
188 * @param aCommand Command |
|
189 * @param aP2 Control parameter 2 |
|
190 * @param aCommandLength Command APDU length |
|
191 * @param aResponseLength Response APDU length |
|
192 * @param aTimeOut Timeout |
|
193 * @param aChannel Channel used to transmit APDU |
|
194 * @return void |
|
195 */ |
|
196 void DoCommandAndTransmit( const RMessage2& aMessage, |
|
197 const TUint8 aCommand, |
|
198 const TUint8 aP2, |
|
199 const TInt8 aCommandLength, |
|
200 const TUint8 aResponseLength, |
|
201 const TInt32 aTimeOut, |
|
202 const TUint8 aChannel ); |
|
203 |
|
204 /** |
|
205 * Helper function for ManageChannel. Create and send a |
|
206 * manage channel apdu according to parameters |
|
207 * @param aMessage Message |
|
208 * @param aCommand Command |
|
209 * @param aP2 Control parameter 2 |
|
210 * @param aCommandLength Command APDU length |
|
211 * @param aResponseLength Response APDU length |
|
212 * @param aTimeOut Timeout |
|
213 * @param aChannel Channel used to transmit APDU |
|
214 * @return void |
|
215 */ |
|
216 void DoCommandAndTransmitL( const RMessage2& aMessage, |
|
217 const TUint8 aCommand, |
|
218 const TUint8 aP2, |
|
219 const TInt8 aCommandLength, |
|
220 const TUint8 aResponseLength, |
|
221 const TInt32 aTimeOut, |
|
222 const TUint8 aChannel ); |
|
223 |
|
224 /** |
|
225 * Write descriptors to client thread. 8 bit version. |
|
226 * @param aMessage Message |
|
227 * @param aResponseBuffer Response Buffer |
|
228 * @param aPtrIndex Pointer index |
|
229 * @return void |
|
230 */ |
|
231 void WriteToClient( const RMessage2& aMessage, |
|
232 const TDesC8& aResponseBuffer, |
|
233 const TInt aPtrIndex ); |
|
234 |
|
235 /** |
|
236 * Read descriptors from client thread. 8 bit version. |
|
237 * @param aMessage Message |
|
238 * @param aBuffer Buffer for data |
|
239 * @param aPointer Pointer to buffer data |
|
240 * @param aPtrIndex Pointer index |
|
241 * @return Symbian or Scard error code |
|
242 */ |
|
243 TInt ReadFromClient( const RMessage2& aMessage, |
|
244 HBufC8*& aBuffer, |
|
245 TPtr8*& aPointer, |
|
246 const TInt aPtrIndex ); |
|
247 |
|
248 /** |
|
249 * Write descriptors to client thread. 16 bit version. |
|
250 * @param aMessage Message |
|
251 * @param aResponseBuffer |
|
252 * @param aPtrIndex |
|
253 * @return void |
|
254 */ |
|
255 void WriteToClient( const RMessage2& aMessage, |
|
256 const TDesC16& aResponseBuffer, |
|
257 const TInt aPtrIndex ); |
|
258 |
|
259 /** |
|
260 * Allocate space for the internal response buffer. The lenght of the |
|
261 * necessary space is deduced from the message. |
|
262 * @param aMessage Message |
|
263 * @param aPtrIndex Pointer index of message. |
|
264 * @return TInt |
|
265 */ |
|
266 TInt AllocateResponse( const RMessage2& aMessage, |
|
267 const TInt aPtrIndex ); |
|
268 |
|
269 /** |
|
270 * Allocate space for the internal response buffer. The lenght of the |
|
271 * necessary space is deduced from the message. |
|
272 * @param aDesLen Length of buffer to be allocated. |
|
273 * @return void |
|
274 */ |
|
275 void AllocateResponseL( TInt aDesLen ); |
|
276 |
|
277 /** |
|
278 * Delete all internal buffers |
|
279 * @return void |
|
280 */ |
|
281 void DeleteBuffers(); |
|
282 |
|
283 /** |
|
284 * Return pointer to wanted slot of client message |
|
285 * @param aMessage Message |
|
286 * @param aPtrIndex Pointer index of message. |
|
287 * @return Pointer to message slot |
|
288 */ |
|
289 TAny* MessagePointer( const RMessage2& aMessage, const TInt aPtrIndex ); |
|
290 |
|
291 /** |
|
292 * Return length of descriptor in client message |
|
293 * @param aMessage Message |
|
294 * @param aPtrIndex Pointer index of message. |
|
295 * @param aMaxLength ETrue: get maxlength of descriptor |
|
296 * EFalse: get length of descriptor |
|
297 * @return Length of descriptor (MaxLength or just Length) |
|
298 */ |
|
299 TInt DesLength( const RMessage2& aMessage, |
|
300 const TInt aPtrIndex, |
|
301 const TBool aMaxLength ); |
|
302 |
|
303 private: // Data |
|
304 // Pointer to owning server. Not owned. |
|
305 CScardServer* iServer; |
|
306 // Pointer to notify registry. Owned by server |
|
307 CScardNotifyRegistry* iNotifyRegistry; |
|
308 // Reader handler associated with this session |
|
309 MScardReader* iReader; |
|
310 // Reader access controller for this session's reader |
|
311 CScardAccessControl* iAccessCtrl; |
|
312 // This is, obviously, the session's ID number |
|
313 TInt iSessionID; |
|
314 // Pointers to command and response parameters. Owned. |
|
315 TPtr8* iResponse; |
|
316 TPtr8* iCommand; |
|
317 |
|
318 // Heap pointers containing the buffers. Owned. |
|
319 HBufC8* iResponseBuffer; |
|
320 HBufC8* iCommandBuffer; |
|
321 |
|
322 // Flag to tell if connected to readed |
|
323 TBool iConnectedToReader; |
|
324 |
|
325 // Client thread |
|
326 RThread iClient; |
|
327 |
|
328 }; |
|
329 |
|
330 #endif // CSCARDSESSION_H |
|
331 |
|
332 // End of File |