|
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: A connection to a smart card. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #ifndef CSCARDCONNECTOR_H |
|
21 #define CSCARDCONNECTOR_H |
|
22 |
|
23 // INCLUDE FILES |
|
24 #include "ScardSession.h" |
|
25 #include "ScardEventStack.h" |
|
26 |
|
27 // CONSTANTS |
|
28 const TUint8 KOpenReader = 0x40; |
|
29 |
|
30 //FORWARD DECLARATIONS |
|
31 class CScardAccessControlRegistry; |
|
32 class CScardAccessControl; |
|
33 class CScardConnectionRegistry; |
|
34 class CScardConnectionTimer; |
|
35 //class TScardATR; |
|
36 |
|
37 // STRUCTURES |
|
38 struct TConnectionParameter |
|
39 { |
|
40 TPtr* iReaderName; |
|
41 TScardReaderName* iExcluded; |
|
42 |
|
43 TScardATR* iATRBytes; |
|
44 TPtr8* iAIDBytes; |
|
45 |
|
46 TBool iNewCardOnly; |
|
47 TBool iNewReaderOnly; |
|
48 |
|
49 TConnectionParameter(); |
|
50 }; |
|
51 |
|
52 // Handle to a complete connection attempt |
|
53 struct TConnection |
|
54 { |
|
55 // Access controller for that reader |
|
56 CScardAccessControl* iCtrl; |
|
57 // The reader object this connection is attached and it's ID |
|
58 MScardReader* iReader; |
|
59 TReaderID iReaderID; |
|
60 // This connection's session id |
|
61 TInt iSessionID; |
|
62 // Constructor added for convenience |
|
63 TConnection(); |
|
64 }; |
|
65 |
|
66 // Little shortcut to use when comparing two connections |
|
67 TBool operator==( const TConnection&, const TConnection& ); |
|
68 |
|
69 // The states the connection process can be in |
|
70 enum TScardConnectionState |
|
71 { |
|
72 EActive = 1, // actively pursuing new connections |
|
73 // all clear, a clean connection was established (or an error occurred) |
|
74 EConnectionComplete, |
|
75 // one stage completed, waiting for the client to confirm |
|
76 EWaitingForConfirm, |
|
77 EReconnecting, // Rrunning the while loop inside ReconnectToReaderL() |
|
78 EInitialising, // Initialising the reader(s) |
|
79 // connection was established inside the while loop, |
|
80 // imminent suicide as soon as possible |
|
81 EDying, |
|
82 ETimedOut // Hit a timeout. Die ASAP. |
|
83 }; |
|
84 |
|
85 // CLASS DECLARATION |
|
86 |
|
87 /** |
|
88 * Actual connector class. |
|
89 * |
|
90 * @lib Scard.lib |
|
91 * @since Series60 2.1 |
|
92 */ |
|
93 class CScardConnector : public CScardSession |
|
94 { |
|
95 public: // Constructors and destructor |
|
96 |
|
97 /** |
|
98 * Two-phased constructor. |
|
99 * @param aConnRegistry Pointer to connection registry |
|
100 * @param aClient Client thread |
|
101 * @param aMessage Client message |
|
102 */ |
|
103 static CScardConnector* NewL( CScardConnectionRegistry* aConnRegistry, |
|
104 RThread& aClient, |
|
105 const RMessage2& aMessage ); |
|
106 |
|
107 /** |
|
108 * Destructor. |
|
109 */ |
|
110 virtual ~CScardConnector(); |
|
111 |
|
112 public: // New functions |
|
113 |
|
114 /** |
|
115 * The timer has sent a signal indicating that this connection |
|
116 * attempt has timed out |
|
117 * @return void |
|
118 */ |
|
119 void ConnectionTimedOut(); |
|
120 |
|
121 /** |
|
122 * Cancel connection. It appears this connection is not wanted after all. |
|
123 * @return void |
|
124 */ |
|
125 void Cancel(); |
|
126 |
|
127 public: // Functions from base classes |
|
128 |
|
129 /** |
|
130 * From CScardSession Override ConnectToReader. |
|
131 * @return void |
|
132 */ |
|
133 void ConnectToReaderL(); |
|
134 |
|
135 /** |
|
136 * From CScardSession Override CardEvent |
|
137 * Handles card events. Panics if there is no connection to reader. |
|
138 * @param aEvent Scard event |
|
139 * @param aATR ATR bytes |
|
140 * @param aReaderID Reader ID |
|
141 * @return void |
|
142 */ |
|
143 virtual void CardEvent( const TScardServiceStatus aEvent, |
|
144 const TScardATR& aATR, |
|
145 const TReaderID& aReaderID ); |
|
146 |
|
147 /** |
|
148 * From CScardSession All clear, a connection has been established. |
|
149 * @param aReaderID ReaderID |
|
150 * @param aErrorCode Error code |
|
151 * @return void |
|
152 */ |
|
153 void ConnectionDone( const TReaderID aReaderID, |
|
154 const TInt& aErrorCode ); |
|
155 |
|
156 |
|
157 /** |
|
158 * From CSharableSession. Return client message. |
|
159 * @return RMessage |
|
160 */ |
|
161 RMessage2& Message(); |
|
162 |
|
163 private: |
|
164 |
|
165 /** |
|
166 * C++ default constructor. |
|
167 * @param aConnRegistry Pointer to connection registry |
|
168 * @param aClient Client thread |
|
169 */ |
|
170 CScardConnector( CScardConnectionRegistry* aConnRegistry, |
|
171 RThread& aClient ); |
|
172 |
|
173 /** |
|
174 * By default Symbian 2nd phase constructor is private. |
|
175 * @param aMessage Client message |
|
176 */ |
|
177 void ConstructL( const RMessage2& aMessage ); |
|
178 |
|
179 /** |
|
180 * Parse the message to get limiting factors |
|
181 * @return void |
|
182 */ |
|
183 void ReadLimitsL(); |
|
184 |
|
185 /** |
|
186 * Check all conditions set for the new card. This method checks if |
|
187 * ATR bytes and AID bytes match with given values in connection |
|
188 * requirements. Currently AID and ATR bytes are not supported. |
|
189 * @param aConnection Connection |
|
190 * @param aATR ATR bytes |
|
191 * @return ETrue if connection conditions are met, else EFalse |
|
192 */ |
|
193 TBool CheckConditions( TConnection& aConnection, |
|
194 const TScardATR* aATR ); |
|
195 |
|
196 /** |
|
197 * Make and add to list a new connection. |
|
198 * @param aMessage Client message |
|
199 * @param aReaderID Reader ID |
|
200 * @return ETrue if connectin succesfully created, otherwise EFalse. |
|
201 */ |
|
202 TBool NewConnectionL( const RMessage2 aMessage, |
|
203 const TReaderID aReaderID ); |
|
204 |
|
205 /** |
|
206 * Find connection for giben reader |
|
207 * @param aReaderID Reader ID |
|
208 * @return Reference to TConnection object |
|
209 */ |
|
210 TConnection& FindReaderConnectionL( const TReaderID& aReaderID ); |
|
211 |
|
212 private: // Data |
|
213 // Container for all connection attempt handles. Owned. |
|
214 CArrayFixFlat<TConnection>* iConnections; |
|
215 // Pointer to connection registry. Not owned. |
|
216 CScardConnectionRegistry* iConnectionRegistry; |
|
217 // The message from the client |
|
218 RMessage2* iClientMessage; |
|
219 // Storage for card events to be handled later. Owned. |
|
220 CScardEventStack* iStack; |
|
221 // Life status indicator |
|
222 TInt iState; |
|
223 // Contacting a single reader or many? |
|
224 TBool iOneReaderMode; |
|
225 // Timer for this connector. Owned. |
|
226 CScardConnectionTimer* iTimer; |
|
227 // The parameter block for this connection attempt |
|
228 TConnectionParameter iParameters; |
|
229 }; |
|
230 |
|
231 #endif // CSCARDCONNECTOR_H |
|
232 |
|
233 // End of File |