|
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: Registry of Smart Card readers |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 |
|
22 #include "ScardReaderRegistry.h" |
|
23 #include "ScardReaderLauncher.h" |
|
24 #include "ScardServer.h" |
|
25 #include "ScardAccessControlRegistry.h" |
|
26 #include "WimTrace.h" |
|
27 |
|
28 #ifdef _DEBUG // for logging |
|
29 #include "ScardLogs.h" |
|
30 #include <flogger.h> |
|
31 #endif |
|
32 |
|
33 // ============================ MEMBER FUNCTIONS =============================== |
|
34 |
|
35 // ----------------------------------------------------------------------------- |
|
36 // TLauncherStruct::TLauncherStruct |
|
37 // C++ default constructor can NOT contain any code, that |
|
38 // might leave. |
|
39 // ----------------------------------------------------------------------------- |
|
40 // |
|
41 TLauncherStruct::TLauncherStruct() |
|
42 : iGroupID( 0 ), |
|
43 iReaderID( 0 ), |
|
44 iLauncher( NULL ) |
|
45 { |
|
46 } |
|
47 |
|
48 // ----------------------------------------------------------------------------- |
|
49 // CScardReaderRegistry::CScardReaderRegistry |
|
50 // C++ default constructor can NOT contain any code, that |
|
51 // might leave. |
|
52 // ----------------------------------------------------------------------------- |
|
53 // |
|
54 CScardReaderRegistry::CScardReaderRegistry( CScardServer* aServer ) |
|
55 : iServer( aServer ), |
|
56 iLaunchersInUse( NULL ) |
|
57 { |
|
58 _WIMTRACE(_L("WIM|Scard|CScardReaderRegistry::CScardReaderRegistry|Begin")); |
|
59 } |
|
60 |
|
61 // ----------------------------------------------------------------------------- |
|
62 // CScardReaderRegistry::ConstructL |
|
63 // Symbian 2nd phase constructor can leave. |
|
64 // ----------------------------------------------------------------------------- |
|
65 // |
|
66 void CScardReaderRegistry::ConstructL() |
|
67 { |
|
68 _WIMTRACE(_L("WIM|Scard|CScardReaderRegistry::ConstructL|Begin")); |
|
69 iLaunchersInUse = new( ELeave ) CArrayFixFlat<TLauncherStruct>( 1 ); |
|
70 } |
|
71 |
|
72 // ----------------------------------------------------------------------------- |
|
73 // CScardReaderRegistry::NewL |
|
74 // Two-phased constructor. |
|
75 // ----------------------------------------------------------------------------- |
|
76 // |
|
77 CScardReaderRegistry* CScardReaderRegistry::NewL( |
|
78 CScardServer *aServer ) |
|
79 { |
|
80 _WIMTRACE(_L("WIM|Scard|CScardReaderRegistry::NewL|Begin")); |
|
81 CScardReaderRegistry* self = new( ELeave ) CScardReaderRegistry( aServer ); |
|
82 |
|
83 CleanupStack::PushL( self ); |
|
84 self->ConstructL(); |
|
85 CleanupStack::Pop( self ); |
|
86 |
|
87 return self; |
|
88 } |
|
89 |
|
90 |
|
91 // Destructor |
|
92 CScardReaderRegistry::~CScardReaderRegistry() |
|
93 { |
|
94 _WIMTRACE(_L("WIM|Scard|CScardReaderRegistry::~CScardReaderRegistry|Begin")); |
|
95 // remove all currently used readers |
|
96 while ( iLaunchersInUse->Count() ) |
|
97 { |
|
98 delete (*iLaunchersInUse)[0].iLauncher; |
|
99 (*iLaunchersInUse)[0].iLibrary.Close(); |
|
100 (*iLaunchersInUse)[0].iSession.Close(); |
|
101 iLaunchersInUse->Delete( 0 ); |
|
102 } |
|
103 |
|
104 delete iLaunchersInUse; |
|
105 } |
|
106 |
|
107 |
|
108 // ----------------------------------------------------------------------------- |
|
109 // CScardReaderRegistry::ReaderID |
|
110 // Get ID for name |
|
111 // ----------------------------------------------------------------------------- |
|
112 // |
|
113 TReaderID CScardReaderRegistry::ReaderID( |
|
114 const TScardReaderName& aReaderName ) |
|
115 { |
|
116 _WIMTRACE(_L("WIM|Scard|CScardReaderRegistry::ReaderID|Begin")); |
|
117 TReaderID readerID( 0 ); |
|
118 |
|
119 TScardReaderName readerName( KReaderName ); //Only supported is "SwimReader" |
|
120 |
|
121 if ( aReaderName.Compare( readerName ) ) //Compare names |
|
122 { |
|
123 readerID = 0; //Not equal |
|
124 } |
|
125 else |
|
126 { |
|
127 readerID = KReaderID; |
|
128 } |
|
129 |
|
130 return readerID; |
|
131 } |
|
132 |
|
133 // ----------------------------------------------------------------------------- |
|
134 // CScardReaderRegistry::CloseReaderL |
|
135 // Unload the reader module with given ID. Also unloads the launcher |
|
136 // module if it's no longer needed |
|
137 // ----------------------------------------------------------------------------- |
|
138 // |
|
139 void CScardReaderRegistry::CloseReader( const TReaderID aReaderID ) |
|
140 { |
|
141 _WIMTRACE(_L("WIM|Scard|CScardReaderRegistry::CloseReaderL|Begin")); |
|
142 // first retrieve the launcher structure |
|
143 TLauncherStruct launcher; |
|
144 TInt index( 0 ); |
|
145 for ( ; index < iLaunchersInUse->Count(); index++ ) |
|
146 { |
|
147 if ( iLaunchersInUse->At( index ).iReaderID == aReaderID ) |
|
148 { |
|
149 launcher = iLaunchersInUse->At( index ); |
|
150 break; |
|
151 } |
|
152 } |
|
153 |
|
154 // Couldn't find it!! (So assume it's closed ok) |
|
155 if ( index >= iLaunchersInUse->Count() ) |
|
156 { |
|
157 return; |
|
158 } |
|
159 |
|
160 // Instuct the launcher to cleanup the reader.. |
|
161 launcher.iLauncher->DeleteReader( aReaderID ); |
|
162 |
|
163 // ..and never mind any error codes, just close the library... |
|
164 delete launcher.iLauncher; |
|
165 launcher.iLibrary.Close(); |
|
166 launcher.iSession.Close(); |
|
167 |
|
168 // Finally remove the launcher from our records |
|
169 iLaunchersInUse->Delete( index ); |
|
170 } |
|
171 |
|
172 // ----------------------------------------------------------------------------- |
|
173 // CScardReaderRegistry::IsSupported |
|
174 // Is the given reader supported |
|
175 // ----------------------------------------------------------------------------- |
|
176 // |
|
177 TBool CScardReaderRegistry::IsSupported( |
|
178 const TScardReaderName& aReaderName ) |
|
179 { |
|
180 _WIMTRACE(_L("WIM|Scard|CScardReaderRegistry::IsSupported|Begin")); |
|
181 TScardReaderName readerName( KReaderName ); //Only supported is "SwimReader" |
|
182 |
|
183 if ( aReaderName.Compare( readerName ) ) //Compare names |
|
184 { |
|
185 return EFalse; |
|
186 } |
|
187 else |
|
188 { |
|
189 return ETrue; |
|
190 } |
|
191 } |
|
192 |
|
193 // ----------------------------------------------------------------------------- |
|
194 // CScardReaderRegistry::ListOpenReaders |
|
195 // List all open readers |
|
196 // ----------------------------------------------------------------------------- |
|
197 // |
|
198 void CScardReaderRegistry::ListOpenReadersL( |
|
199 CArrayFix<CScardAccessControl*>* aACList ) |
|
200 { |
|
201 _WIMTRACE(_L("WIM|Scard|CScardReaderRegistry::ListOpenReadersL|Begin")); |
|
202 CScardAccessControl* ac = |
|
203 iServer->AccessRegistry()->FindAccessController( KReaderID ); |
|
204 if ( ac ) |
|
205 { |
|
206 aACList->AppendL( ac ); |
|
207 } |
|
208 } |
|
209 |
|
210 // ----------------------------------------------------------------------------- |
|
211 // CScardReaderRegistry::ListClosedReaders |
|
212 // List closed readers |
|
213 // ----------------------------------------------------------------------------- |
|
214 // |
|
215 void CScardReaderRegistry::ListClosedReadersL( CArrayFix<TReaderID>* aIDList ) |
|
216 { |
|
217 _WIMTRACE(_L("WIM|Scard|CScardReaderRegistry::ListClosedReadersL|Begin")); |
|
218 // See if it has already an access controller (aka it's been opened already) |
|
219 CScardAccessControl* ac = |
|
220 iServer->AccessRegistry()->FindAccessController( KReaderID ); |
|
221 if ( !ac ) |
|
222 { |
|
223 aIDList->AppendL( KReaderID ); |
|
224 } |
|
225 } |
|
226 |
|
227 // ----------------------------------------------------------------------------- |
|
228 // CScardReaderRegistry::FriendlyName |
|
229 // Get friendly name of reader |
|
230 // ----------------------------------------------------------------------------- |
|
231 // |
|
232 const TScardReaderName CScardReaderRegistry::FriendlyName( |
|
233 const TReaderID aReaderID ) |
|
234 { |
|
235 _WIMTRACE(_L("WIM|Scard|CScardReaderRegistry::FriendlyName|Begin")); |
|
236 TScardReaderName name; |
|
237 if ( aReaderID == KReaderID ) //Only supported is 1 |
|
238 { |
|
239 name.Copy( KReaderName ); |
|
240 } |
|
241 return name; |
|
242 |
|
243 } |
|
244 |
|
245 // ----------------------------------------------------------------------------- |
|
246 // CScardReaderRegistry::LoadReaderL |
|
247 // Load reader |
|
248 // ----------------------------------------------------------------------------- |
|
249 // |
|
250 MScardReader* CScardReaderRegistry::LoadReaderL( const TReaderID aReaderID ) |
|
251 { |
|
252 _WIMTRACE(_L("WIM|Scard|CScardReaderRegistry::LoadReaderL|Begin")); |
|
253 TGroupID groupID( 0 ); |
|
254 if ( aReaderID == KReaderID ) |
|
255 { |
|
256 groupID = KGroupID; |
|
257 } |
|
258 |
|
259 // load the group launcher's module |
|
260 #ifdef _DEBUG |
|
261 RFileLogger::WriteFormat( KScardLogDir, KScardLogFileName, |
|
262 EFileLoggingModeAppend, |
|
263 _L("CScardReaderRegistry::LoadReaderL loading launcher module...\n") ); |
|
264 #endif |
|
265 MScardReaderLauncher* launcher = NULL; |
|
266 |
|
267 launcher = LoadFactoryModuleL( groupID, aReaderID ); |
|
268 |
|
269 MScardReader* reader = NULL; |
|
270 |
|
271 // create the reader |
|
272 #ifdef _DEBUG |
|
273 RFileLogger::WriteFormat( KScardLogDir, KScardLogFileName, |
|
274 EFileLoggingModeAppend, |
|
275 _L( "CScardReaderRegistry::LoadReaderL creating reader...\n" ) ); |
|
276 #endif |
|
277 reader = (/*(CSwimReaderLauncher*)*/launcher)->CreateReaderL( aReaderID ); |
|
278 |
|
279 return reader; |
|
280 } |
|
281 |
|
282 // ----------------------------------------------------------------------------- |
|
283 // CScardReaderRegistry::LoadFactoryModuleL |
|
284 // Load factory module (SwimReader.dll) |
|
285 // ----------------------------------------------------------------------------- |
|
286 // |
|
287 MScardReaderLauncher* CScardReaderRegistry::LoadFactoryModuleL( |
|
288 const TGroupID aGroupID, |
|
289 const TReaderID aReaderID ) |
|
290 { |
|
291 _WIMTRACE(_L("WIM|Scard|CScardReaderRegistry::LoadFactoryModuleL|Begin")); |
|
292 //Check ID's, only supported ID's in Series 60 are |
|
293 // KGroupID and KReaderID |
|
294 if ( aGroupID != KGroupID || aReaderID != KReaderID ) |
|
295 { |
|
296 User::Leave( KErrArgument ); |
|
297 } |
|
298 TLauncherStruct launcher; |
|
299 launcher.iGroupID = KGroupID; //This is always 1 |
|
300 launcher.iReaderID = KReaderID; //This is always 1 |
|
301 launcher.iSession.Connect(); |
|
302 |
|
303 User::LeaveIfError( launcher.iLibrary.Load( KSwimReaderDLL ) ); |
|
304 |
|
305 // Create the actual CScardReaderLauncher object |
|
306 #ifdef _DEBUG |
|
307 RFileLogger::WriteFormat( KScardLogDir, KScardLogFileName, |
|
308 EFileLoggingModeAppend, |
|
309 _L( "CScardReaderRegistry::LoadFactoryModuleL creating\ |
|
310 CScardReaderLauncher object...\n" ) ); |
|
311 #endif |
|
312 TLibraryFunction entry = launcher.iLibrary.Lookup( 1 ); |
|
313 |
|
314 if ( entry ) // entry found |
|
315 { |
|
316 launcher.iLauncher = reinterpret_cast< MScardReaderLauncher* > |
|
317 ( entry() ); |
|
318 } |
|
319 else |
|
320 { |
|
321 //delete launcher.iLauncher; // (?) why delete |
|
322 launcher.iLibrary.Close(); |
|
323 launcher.iSession.Close(); |
|
324 User::Leave( KErrNotFound ); |
|
325 } |
|
326 |
|
327 // Initialise the launcher and append it to the list |
|
328 #ifdef _DEBUG |
|
329 RFileLogger::WriteFormat( KScardLogDir, KScardLogFileName, |
|
330 EFileLoggingModeAppend, |
|
331 _L( "CScardReaderRegistry::LoadFactoryModuleL initialising\ |
|
332 launcher...\n" ) ); |
|
333 #endif |
|
334 TRAPD( initialisationError, launcher.iLauncher->ConstructL( |
|
335 iServer->ReaderService() ) ); |
|
336 if ( initialisationError ) |
|
337 { |
|
338 delete launcher.iLauncher; |
|
339 launcher.iLibrary.Close(); |
|
340 launcher.iSession.Close(); |
|
341 User::Leave( initialisationError ); |
|
342 } |
|
343 |
|
344 iLaunchersInUse->AppendL( launcher ); |
|
345 return launcher.iLauncher; |
|
346 } |
|
347 |
|
348 // End of File |