|
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: Implementation of SIM/WIM reader interface class |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "SwimReaderIF.h" |
|
21 #include "SwimReader.h" |
|
22 |
|
23 #ifdef _TIMER_TRIGGERED_EVENT // Timer triggered card event simulation enabled |
|
24 #include "SwimSysAgentObserver_TimerTriggered.h" |
|
25 #else |
|
26 #include "SwimSysAgentObserver.h" |
|
27 #endif |
|
28 |
|
29 #include "WimTrace.h" // for trace logging |
|
30 |
|
31 #ifdef _DEBUG |
|
32 #include <flogger.h> |
|
33 #endif |
|
34 |
|
35 |
|
36 // ============================ MEMBER FUNCTIONS =============================== |
|
37 |
|
38 // ----------------------------------------------------------------------------- |
|
39 // CSwimReaderIF::NewL |
|
40 // Two-phased constructor. |
|
41 // ----------------------------------------------------------------------------- |
|
42 // |
|
43 CSwimReaderIF* CSwimReaderIF::NewL( |
|
44 MScardNotifyObserver* aNotifyObserver, |
|
45 TReaderID aReaderID, |
|
46 CSwimReaderLauncher* aLauncher ) |
|
47 { |
|
48 _WIMTRACE(_L("WIM|SwimReader|CSwimReaderIF::NewL|Begin")); |
|
49 CSwimReaderIF* self = new( ELeave ) CSwimReaderIF( aNotifyObserver, |
|
50 aReaderID, aLauncher ); |
|
51 CleanupStack::PushL( self ); |
|
52 self->ConstructL(); |
|
53 CleanupStack::Pop( self ); |
|
54 |
|
55 return self; |
|
56 } |
|
57 |
|
58 |
|
59 // Destructor |
|
60 CSwimReaderIF::~CSwimReaderIF() |
|
61 { |
|
62 _WIMTRACE(_L("WIM|SwimReader|CSwimReaderIF::~CSwimReaderIF|Begin")); |
|
63 delete iFunctionalLevel; |
|
64 if ( iSysAgentObserver ) |
|
65 { |
|
66 iSysAgentObserver->Cancel(); |
|
67 } |
|
68 delete iSysAgentObserver; |
|
69 Cancel(); |
|
70 } |
|
71 |
|
72 // ----------------------------------------------------------------------------- |
|
73 // CSwimReaderIF::CSwimReaderIF |
|
74 // C++ default constructor can NOT contain any code, that |
|
75 // might leave. |
|
76 // ----------------------------------------------------------------------------- |
|
77 // |
|
78 CSwimReaderIF::CSwimReaderIF( |
|
79 MScardNotifyObserver* aNotifyObserver, |
|
80 TReaderID aReaderID, |
|
81 CSwimReaderLauncher* aLauncher ) |
|
82 : CActive( EPriorityNormal ) |
|
83 { |
|
84 _WIMTRACE(_L("WIM|SwimReader|CSwimReaderIF::CSwimReaderIF|Begin")); |
|
85 CActiveScheduler::Add( this ); |
|
86 iLauncher = aLauncher; |
|
87 iNotifyObserver = aNotifyObserver; |
|
88 iID = aReaderID; |
|
89 } |
|
90 |
|
91 // ----------------------------------------------------------------------------- |
|
92 // CSwimReaderIF::ConstructL |
|
93 // Symbian 2nd phase constructor can leave. |
|
94 // ----------------------------------------------------------------------------- |
|
95 // |
|
96 void CSwimReaderIF::ConstructL() |
|
97 { |
|
98 _WIMTRACE(_L("WIM|SwimReader|CSwimReaderIF::ConstructL|Begin")); |
|
99 iFunctionalLevel = CSwimReader::NewL( this ); |
|
100 iSysAgentObserver = CSwimSysAgentObserver::NewL( this ); |
|
101 iSysAgentObserver->Start(); //Start Listening |
|
102 } |
|
103 |
|
104 // ----------------------------------------------------------------------------- |
|
105 // CSwimReaderIF::CancelTransmit |
|
106 // Cancel transmit |
|
107 // ----------------------------------------------------------------------------- |
|
108 // |
|
109 void CSwimReaderIF::CancelTransmit() |
|
110 { |
|
111 _WIMTRACE(_L("WIM|SwimReader|CSwimReaderIF::CancelTransmit|Begin")); |
|
112 Cancel(); |
|
113 } |
|
114 |
|
115 // ----------------------------------------------------------------------------- |
|
116 // CSwimReaderIF::CancelTransmit |
|
117 // Close ETEL server connection. |
|
118 // ----------------------------------------------------------------------------- |
|
119 // |
|
120 TInt CSwimReaderIF::Close() |
|
121 { |
|
122 _WIMTRACE(_L("WIM|SwimReader|CSwimReaderIF::Close|Begin")); |
|
123 Cancel(); |
|
124 iFunctionalLevel->Close(); |
|
125 return KErrNone; |
|
126 } |
|
127 |
|
128 // ----------------------------------------------------------------------------- |
|
129 // CSwimReaderIF::DoCancel |
|
130 // Asyncronous call cancelled |
|
131 // ----------------------------------------------------------------------------- |
|
132 // |
|
133 void CSwimReaderIF::DoCancel() |
|
134 { |
|
135 _WIMTRACE(_L("WIM|SwimReader|CSwimReaderIF::DoCancel|Begin")); |
|
136 iFunctionalLevel->Cancel(); |
|
137 User::RequestComplete( iClientStatus, KErrCancel ); |
|
138 } |
|
139 |
|
140 // ----------------------------------------------------------------------------- |
|
141 // CSwimReaderIF::GetATR |
|
142 // Not supported in Series 60 |
|
143 // ----------------------------------------------------------------------------- |
|
144 // |
|
145 TInt CSwimReaderIF::GetATR( TScardATR& /*anATR*/ ) |
|
146 { |
|
147 _WIMTRACE(_L("WIM|SwimReader|CSwimReaderIF::GetATR|Begin")); |
|
148 return KScErrNotSupported; |
|
149 } |
|
150 |
|
151 // ----------------------------------------------------------------------------- |
|
152 // CSwimReaderIF::GetCapabilities |
|
153 // Get card status or precense bits according to aTag parameter |
|
154 // ----------------------------------------------------------------------------- |
|
155 // |
|
156 TBool CSwimReaderIF::GetCapabilities( |
|
157 TRequestStatus& aStatus, |
|
158 const TInt32 aTag, |
|
159 TPtr8& aValue, |
|
160 const TInt32 /*aTimeout*/ ) |
|
161 { |
|
162 _WIMTRACE(_L("WIM|SwimReader|CSwimReaderIF::GetCapabilities|Begin")); |
|
163 iClientStatus = &aStatus; |
|
164 aStatus = KRequestPending; |
|
165 |
|
166 switch ( aTag ) |
|
167 { |
|
168 case KCardPrecence: |
|
169 { |
|
170 TUint8 tempstatus; |
|
171 iFunctionalLevel->PreferredReaderStatus( tempstatus ); |
|
172 tempstatus = tempstatus && 0x02; |
|
173 aValue.Copy( &tempstatus, 1 ); |
|
174 aValue.SetLength( 1 ); |
|
175 User::RequestComplete( iClientStatus, KErrNone ); |
|
176 break; |
|
177 } |
|
178 case KCardStatus: |
|
179 { |
|
180 TUint8 temp; |
|
181 iFunctionalLevel->PreferredReaderStatus( temp ); |
|
182 #ifdef _DEBUG |
|
183 RFileLogger::WriteFormat( KSwimReaderLogDir, |
|
184 KSwimReaderLogFileName, EFileLoggingModeAppend, |
|
185 _L( "CSwimReaderIF::GetCapabilities: %d" ), temp ); |
|
186 #endif |
|
187 aValue.Copy( &temp, 1 ); |
|
188 aValue.SetLength( 1 ); |
|
189 User::RequestComplete( iClientStatus, KErrNone ); |
|
190 break; |
|
191 } |
|
192 default: |
|
193 { |
|
194 #ifdef _DEBUG |
|
195 RFileLogger::WriteFormat( KSwimReaderLogDir, |
|
196 KSwimReaderLogFileName, EFileLoggingModeAppend, |
|
197 _L( "CSwimReaderIF::GetCapabilities: unsupported tag 0x%x" ), |
|
198 aTag ); |
|
199 #endif |
|
200 User::RequestComplete( iClientStatus, KErrNotSupported ); |
|
201 } |
|
202 } |
|
203 return ETrue; |
|
204 } |
|
205 |
|
206 // ----------------------------------------------------------------------------- |
|
207 // CSwimReaderIF::Notify |
|
208 // Notify notifyObserver about card event |
|
209 // ----------------------------------------------------------------------------- |
|
210 // |
|
211 void CSwimReaderIF::Notify( TScardServiceStatus aStatus ) |
|
212 { |
|
213 _WIMTRACE2(_L("WIM|SwimReader|CSwimReaderIF::Notify|Begin aStatus = %d"), aStatus); |
|
214 iNotifyObserver->NotifyCardEvent( aStatus, iID ); |
|
215 } |
|
216 |
|
217 // ----------------------------------------------------------------------------- |
|
218 // CSwimReaderIF::Open |
|
219 // Uses CSwimReader::WakeUpL to initialize a connection to the ETEL server. |
|
220 // ----------------------------------------------------------------------------- |
|
221 // |
|
222 void CSwimReaderIF::Open( TRequestStatus& aStatus ) |
|
223 { |
|
224 _WIMTRACE(_L("WIM|SwimReader|CSwimReaderIF::Open|Begin")); |
|
225 iClientStatus = &aStatus; |
|
226 aStatus = KRequestPending; |
|
227 |
|
228 #ifdef _DEBUG |
|
229 RFileLogger::WriteFormat( KSwimReaderLogDir, KSwimReaderLogFileName, |
|
230 EFileLoggingModeAppend, |
|
231 _L( "CSwimReaderIF::Open: Opening Reader..." ) ); |
|
232 #endif |
|
233 |
|
234 TRAPD( err, iFunctionalLevel->WakeUpL( iStatus, iHistoricals ) ); |
|
235 if ( err ) |
|
236 { |
|
237 #ifdef _DEBUG |
|
238 RFileLogger::WriteFormat( KSwimReaderLogDir, KSwimReaderLogFileName, |
|
239 EFileLoggingModeAppend, |
|
240 _L( "CSwimReaderIF::Open: WakeUpL leaves with %d !!!" ), err ); |
|
241 #endif |
|
242 User::RequestComplete( iClientStatus, err ); |
|
243 } |
|
244 else |
|
245 { |
|
246 iIFPhase = EOpen; |
|
247 SetActive(); |
|
248 } |
|
249 |
|
250 } |
|
251 |
|
252 // ----------------------------------------------------------------------------- |
|
253 // CSwimReaderIF::TransmitToCard |
|
254 // Transmits given CommandAPDU message to card and |
|
255 // gets response to ResponseAPDU message. |
|
256 // ----------------------------------------------------------------------------- |
|
257 // |
|
258 void CSwimReaderIF::TransmitToCard( |
|
259 TRequestStatus& aStatus, |
|
260 const TPtrC8& aCommandAPDU, |
|
261 TPtr8& aResponseAPDU, |
|
262 const TInt32 /*aTimeout*/ ) |
|
263 { |
|
264 _WIMTRACE(_L("WIM|SwimReader|CSwimReaderIF::TransmitToCard|Begin")); |
|
265 iClientStatus = &aStatus; |
|
266 aStatus = KRequestPending; |
|
267 |
|
268 #ifdef _DEBUG |
|
269 RFileLogger::WriteFormat( KSwimReaderLogDir, KSwimReaderLogFileName, |
|
270 EFileLoggingModeAppend, |
|
271 _L( "CSwimReaderIF::TransmitToCard: Sending APDU to card..." ) ); |
|
272 #endif |
|
273 TRAPD( err, iFunctionalLevel->APDUReqL( iStatus, aCommandAPDU, |
|
274 aResponseAPDU ) ); |
|
275 if ( err ) |
|
276 { |
|
277 #ifdef _DEBUG |
|
278 RFileLogger::WriteFormat( KSwimReaderLogDir, KSwimReaderLogFileName, |
|
279 EFileLoggingModeAppend, |
|
280 _L( "CSwimReaderIF::TransmitToCard: APDUReqL leaves with %d !!!" ), |
|
281 err ); |
|
282 #endif |
|
283 User::RequestComplete( iClientStatus, err ); |
|
284 } |
|
285 else |
|
286 { |
|
287 iIFPhase = ETransmitToCard; |
|
288 SetActive(); |
|
289 } |
|
290 } |
|
291 |
|
292 // PRIVATE FUNCTIONS: |
|
293 |
|
294 // ----------------------------------------------------------------------------- |
|
295 // CSwimReaderIF::HandleOpen |
|
296 // Handle open request |
|
297 // ----------------------------------------------------------------------------- |
|
298 // |
|
299 void CSwimReaderIF::HandleOpen() |
|
300 { |
|
301 _WIMTRACE2(_L("WIM|SwimReader|CSwimReaderIF::HandleOpen|Begin iStatus=%d"), iStatus.Int() ); |
|
302 if ( iStatus.Int() != KErrNone ) // a system-spes. error has occ, map to own |
|
303 { |
|
304 switch ( iStatus.Int() ) |
|
305 { |
|
306 // The reader or smart card did not respond in time |
|
307 case KErrTimedOut: |
|
308 iErr = KScReaderErrResponseTimeout; |
|
309 break; |
|
310 // Access denied occurs if the comm port could not be opened, i.e. |
|
311 // someone else is using it. |
|
312 case KErrAccessDenied: |
|
313 iErr = KScReaderErrCommunicationFailure; |
|
314 break; |
|
315 // (Some of the) memory allocations failed |
|
316 case KErrNoMemory: |
|
317 iErr = KScErrNoMemory; |
|
318 break; |
|
319 // Something else happened... |
|
320 default: |
|
321 iErr = KScErrGeneral; |
|
322 break; |
|
323 } |
|
324 } |
|
325 else |
|
326 { |
|
327 iErr = KErrNone; |
|
328 } |
|
329 User::RequestComplete( iClientStatus, iStatus.Int() ); |
|
330 } |
|
331 |
|
332 // ----------------------------------------------------------------------------- |
|
333 // CSwimReaderIF::RunL |
|
334 // Handle asyncronous response |
|
335 // ----------------------------------------------------------------------------- |
|
336 // |
|
337 void CSwimReaderIF::RunL() |
|
338 { |
|
339 _WIMTRACE(_L("WIM|SwimReader|CSwimReaderIF::RunL|Begin")); |
|
340 switch ( iIFPhase ) |
|
341 { |
|
342 case EOpen: |
|
343 { |
|
344 #ifdef _DEBUG |
|
345 RFileLogger::WriteFormat( KSwimReaderLogDir, KSwimReaderLogFileName, |
|
346 EFileLoggingModeAppend, |
|
347 _L( "CSwimReaderIF::RunL: Open completed with %d" ), |
|
348 iStatus.Int() ); |
|
349 #endif |
|
350 HandleOpen(); |
|
351 if ( iErr == KErrNone ) |
|
352 { |
|
353 Notify( EScardInserted ); |
|
354 iFunctionalLevel->SetCardInserted( ETrue ); |
|
355 } |
|
356 else |
|
357 { |
|
358 Notify( EScardRemoved ); |
|
359 iFunctionalLevel->SetCardInserted( EFalse ); |
|
360 } |
|
361 |
|
362 break; |
|
363 } |
|
364 case ETransmitToCard: |
|
365 { |
|
366 #ifdef _DEBUG |
|
367 RFileLogger::WriteFormat( KSwimReaderLogDir, KSwimReaderLogFileName, |
|
368 EFileLoggingModeAppend, |
|
369 _L( "CSwimReaderIF::RunL: TransmitToCard completed with %d" ), |
|
370 iStatus.Int() ); |
|
371 #endif |
|
372 User::RequestComplete( iClientStatus, iStatus.Int() ); |
|
373 break; |
|
374 } |
|
375 |
|
376 default: |
|
377 { |
|
378 #ifdef _DEBUG |
|
379 RFileLogger::WriteFormat( KSwimReaderLogDir, KSwimReaderLogFileName, |
|
380 EFileLoggingModeAppend, |
|
381 _L( "CSwimReaderIF::RunL: Invalid phase %d!" ), |
|
382 iIFPhase ); |
|
383 #endif |
|
384 User::RequestComplete( iClientStatus, iStatus.Int() ); |
|
385 break; |
|
386 } |
|
387 } |
|
388 _WIMTRACE3(_L("WIM|SwimReader|CSwimReaderIF::RunL|End iIFPhase=%d iErr=%d"), iIFPhase, iErr); |
|
389 } |
|
390 |
|
391 // End of File |