25
27
#include "eventhandler.h"
26
28
#include "dyn_generic.h"
27
29
#include "sys_generic.h"
28
#include "ifdhandler.h"
30
#include "ifdhandler.h"
29
31
#include "ifdwrapper.h"
30
32
#include "debuglog.h"
31
33
#include "prothandler.h"
33
static PREADER_STATES readerStates[PCSCLITE_MAX_CONTEXTS];
35
void EHStatusHandlerThread( PREADER_CONTEXT );
38
LONG EHInitializeEventStructures( ) {
42
fd=0; i=0; pageSize=0;
44
SYS_RemoveFile( PCSCLITE_PUBSHM_FILE );
46
fd = SYS_OpenFile( PCSCLITE_PUBSHM_FILE, O_RDWR | O_CREAT, 00644 );
48
DebugLogA("Error: Cannot open public shared file");
52
SYS_Chmod( PCSCLITE_PUBSHM_FILE, S_IRGRP | S_IREAD | S_IWRITE | S_IROTH );
54
pageSize = SYS_GetPageSize();
56
/* Jump to end of file space and allocate zero's */
57
SYS_SeekFile( fd, pageSize * PCSCLITE_MAX_CONTEXTS );
58
SYS_WriteFile( fd, "", 1 );
60
/* Allocate each reader structure */
61
for ( i=0; i < PCSCLITE_MAX_CONTEXTS; i++ ) {
62
readerStates[i] = (PREADER_STATES)
63
SYS_MemoryMap( sizeof(READER_STATES),
65
if ( readerStates[i] == 0 ) {
66
DebugLogA("Error: Cannot public memory map");
70
/* Zero out each value in the struct */
71
memset((readerStates[i])->readerName, 0, MAX_READERNAME);
72
memset((readerStates[i])->cardAtr, 0, MAX_ATR_SIZE);
73
(readerStates[i])->readerID = 0;
74
(readerStates[i])->readerState = 0;
75
(readerStates[i])->lockState = 0;
76
(readerStates[i])->readerSharing = 0;
77
(readerStates[i])->cardAtrLength = 0;
78
(readerStates[i])->cardProtocol = 0;
81
return SCARD_S_SUCCESS;
84
LONG EHDestroyEventHandler( PREADER_CONTEXT rContext ) {
91
/* Set the thread to 0 to exit thread */
92
rContext->dwLockId = 0xFFFF;
94
DebugLogA("EHDestroyEventHandler: Stomping thread.");
97
/* Wait 0.05 seconds for the child to respond */
99
} while ( rContext->dwLockId == 0xFFFF );
102
/* Zero out the public status struct to allow
103
it to be recycled and used again
106
i = rContext->dwPublicID;
107
memset((readerStates[i])->readerName, 0, MAX_READERNAME);
108
memset((readerStates[i])->cardAtr, 0, MAX_ATR_SIZE);
109
(readerStates[i])->readerID = 0;
110
(readerStates[i])->readerState = 0;
111
(readerStates[i])->lockState = 0;
112
(readerStates[i])->readerSharing = 0;
113
(readerStates[i])->cardAtrLength = 0;
114
(readerStates[i])->cardProtocol = 0;
116
DebugLogA("EHDestroyEventHandler: Thread stomped.");
118
return SCARD_S_SUCCESS;
121
LONG EHSpawnEventHandler( PREADER_CONTEXT rContext ) {
125
DWORD dwStatus, dwProtocol;
128
/* Zero out everything */
129
rv=0; lpcReader=0; dwStatus=0; dwProtocol=0; i=0;
131
lpcReader = rContext->lpcReader;
133
rv = IFDStatusICC( rContext, &dwStatus,
134
&dwProtocol, rContext->ucAtr,
135
&rContext->dwAtrLen );
137
if ( rv != SCARD_S_SUCCESS ) {
138
DebugLogB("EHSpawnEventHandler: Initial Check Failed on %s", lpcReader);
139
return SCARD_F_UNKNOWN_ERROR;
142
/* Find an empty reader slot and insert the new reader */
143
for (i=0; i < PCSCLITE_MAX_CONTEXTS; i++) {
144
if ( (readerStates[i])->readerID == 0 ) {
149
if ( i == PCSCLITE_MAX_CONTEXTS ) {
150
return SCARD_F_INTERNAL_ERROR;
154
/* Set all the attributes to this reader */
155
strcpy((readerStates[i])->readerName, rContext->lpcReader);
156
memcpy((readerStates[i])->cardAtr, rContext->ucAtr, rContext->dwAtrLen);
157
(readerStates[i])->readerID = i+100;
158
(readerStates[i])->readerState = rContext->dwStatus;
159
(readerStates[i])->readerSharing = rContext->dwContexts;
160
(readerStates[i])->cardAtrLength = rContext->dwAtrLen;
161
(readerStates[i])->cardProtocol = rContext->dwProtocol;
162
/* So the thread can access this array indice */
163
rContext->dwPublicID = i;
165
rv = SYS_ThreadCreate( &rContext->pthThread, NULL,
166
(LPVOID)EHStatusHandlerThread,
169
return SCARD_S_SUCCESS;
171
return SCARD_E_NO_MEMORY;
177
void EHStatusHandlerThread( PREADER_CONTEXT rContext ) {
181
DWORD dwStatus, dwProtocol, dwReaderSharing;
182
DWORD dwErrorCount, dwCurrentState;
185
/* Zero out everything */
186
rv=0; lpcReader=0; dwStatus=0; dwProtocol=0; dwReaderSharing=0;
187
dwCurrentState=0; dwErrorCount=0; i=0; pageSize=0;
189
lpcReader = rContext->lpcReader;
190
i = rContext->dwPublicID;
192
pageSize = SYS_GetPageSize();
194
rv = IFDStatusICC( rContext, &dwStatus,
195
&dwProtocol, rContext->ucAtr,
196
&rContext->dwAtrLen );
198
if ( dwStatus & SCARD_PRESENT ) {
200
rv = IFDPowerICC( rContext, IFD_POWER_UP,
202
&rContext->dwAtrLen );
204
if ( rv == IFD_SUCCESS ) {
205
rContext->dwProtocol = PHGetDefaultProtocol( rContext->ucAtr,
206
rContext->dwAtrLen );
207
rContext->dwStatus |= SCARD_PRESENT;
208
rContext->dwStatus &= ~SCARD_ABSENT;
209
rContext->dwStatus |= SCARD_POWERED;
210
rContext->dwStatus |= SCARD_NEGOTIABLE;
211
rContext->dwStatus &= ~SCARD_SPECIFIC;
212
rContext->dwStatus &= ~SCARD_SWALLOWED;
213
rContext->dwStatus &= ~SCARD_UNKNOWN;
215
rContext->dwStatus |= SCARD_PRESENT;
216
rContext->dwStatus &= ~SCARD_ABSENT;
217
rContext->dwStatus |= SCARD_SWALLOWED;
218
rContext->dwStatus &= ~SCARD_POWERED;
219
rContext->dwStatus &= ~SCARD_NEGOTIABLE;
220
rContext->dwStatus &= ~SCARD_SPECIFIC;
221
rContext->dwStatus &= ~SCARD_UNKNOWN;
222
rContext->dwProtocol = 0;
223
rContext->dwAtrLen = 0;
226
dwCurrentState = SCARD_PRESENT;
229
dwCurrentState = SCARD_ABSENT;
230
rContext->dwStatus |= SCARD_ABSENT;
231
rContext->dwStatus &= ~SCARD_PRESENT;
232
rContext->dwStatus &= ~SCARD_POWERED;
233
rContext->dwStatus &= ~SCARD_NEGOTIABLE;
234
rContext->dwStatus &= ~SCARD_SPECIFIC;
235
rContext->dwStatus &= ~SCARD_SWALLOWED;
236
rContext->dwStatus &= ~SCARD_UNKNOWN;
237
rContext->dwAtrLen = 0;
238
rContext->dwProtocol = 0;
241
/* Set all the public attributes to this reader */
242
(readerStates[i])->readerState = rContext->dwStatus;
243
(readerStates[i])->cardAtrLength = rContext->dwAtrLen;
244
(readerStates[i])->cardProtocol = rContext->dwProtocol;
245
(readerStates[i])->readerSharing = dwReaderSharing = rContext->dwContexts;
246
memcpy((readerStates[i])->cardAtr, rContext->ucAtr,
249
SYS_MMapSynchronize( (void *)readerStates[i], pageSize );
255
rv = IFDStatusICC( rContext, &dwStatus,
256
&dwProtocol, rContext->ucAtr,
257
&rContext->dwAtrLen );
259
if ( rv != SCARD_S_SUCCESS ) {
260
DebugLogB("EHSpawnEventHandler: Error communicating to: %s", lpcReader);
262
/* Set error status on this reader while errors occur */
264
rContext->dwStatus &= ~SCARD_ABSENT;
265
rContext->dwStatus &= ~SCARD_PRESENT;
266
rContext->dwStatus &= ~SCARD_POWERED;
267
rContext->dwStatus &= ~SCARD_NEGOTIABLE;
268
rContext->dwStatus &= ~SCARD_SPECIFIC;
269
rContext->dwStatus &= ~SCARD_SWALLOWED;
270
rContext->dwStatus |= SCARD_UNKNOWN;
271
rContext->dwAtrLen = 0;
272
rContext->dwProtocol = 0;
274
dwCurrentState = SCARD_UNKNOWN;
276
/* Set all the public attributes to this reader */
277
(readerStates[i])->readerState = rContext->dwStatus;
278
(readerStates[i])->cardAtrLength = rContext->dwAtrLen;
279
(readerStates[i])->cardProtocol = rContext->dwProtocol;
280
memcpy((readerStates[i])->cardAtr, rContext->ucAtr,
283
SYS_MMapSynchronize( (void *)readerStates[i], pageSize );
285
/* This code causes race conditions on
286
G4's with USB insertion */
291
/* After 10 seconds of errors, try to reinitialize the reader
292
This sometimes helps bring readers out of *crazy* states.
295
if ( dwErrorCount == 10 ) {
296
RFUnInitializeReader( rContext );
297
RFInitializeReader( rContext );
35
static PREADER_STATES readerStates[PCSCLITE_MAX_READERS_CONTEXTS];
37
void EHStatusHandlerThread(PREADER_CONTEXT);
39
LONG EHInitializeEventStructures()
47
SYS_RemoveFile(PCSCLITE_PUBSHM_FILE);
49
fd = SYS_OpenFile(PCSCLITE_PUBSHM_FILE, O_RDWR | O_CREAT, 00644);
52
DebugLogC("Cannot create public shared file %s: %s",
53
PCSCLITE_PUBSHM_FILE, strerror(errno));
57
SYS_Chmod(PCSCLITE_PUBSHM_FILE,
58
S_IRGRP | S_IREAD | S_IWRITE | S_IROTH);
60
pageSize = SYS_GetPageSize();
63
* Jump to end of file space and allocate zero's
65
SYS_SeekFile(fd, pageSize * PCSCLITE_MAX_READERS_CONTEXTS);
66
SYS_WriteFile(fd, "", 1);
69
* Allocate each reader structure
71
for (i = 0; i < PCSCLITE_MAX_READERS_CONTEXTS; i++)
73
readerStates[i] = (PREADER_STATES)
74
SYS_MemoryMap(sizeof(READER_STATES), fd, (i * pageSize));
75
if (readerStates[i] == 0)
77
DebugLogC("Cannot memory map public shared file %s: %s",
78
PCSCLITE_PUBSHM_FILE, strerror(errno));
83
* Zero out each value in the struct
85
memset((readerStates[i])->readerName, 0, MAX_READERNAME);
86
memset((readerStates[i])->cardAtr, 0, MAX_ATR_SIZE);
87
(readerStates[i])->readerID = 0;
88
(readerStates[i])->readerState = 0;
89
(readerStates[i])->lockState = 0;
90
(readerStates[i])->readerSharing = 0;
91
(readerStates[i])->cardAtrLength = 0;
92
(readerStates[i])->cardProtocol = 0;
95
return SCARD_S_SUCCESS;
98
LONG EHDestroyEventHandler(PREADER_CONTEXT rContext)
107
i = rContext->dwPublicID;
108
if ((readerStates[i])->readerName[0] == 0)
110
DebugLogA("Thread already stomped.");
111
return SCARD_S_SUCCESS;
115
* Set the thread to 0 to exit thread
117
rContext->dwLockId = 0xFFFF;
119
DebugLogA("Stomping thread.");
124
* Wait 0.05 seconds for the child to respond
128
while (rContext->dwLockId == 0xFFFF);
130
* Zero out the public status struct to allow it to be recycled and
134
memset((readerStates[i])->readerName, 0, MAX_READERNAME);
135
memset((readerStates[i])->cardAtr, 0, MAX_ATR_SIZE);
136
(readerStates[i])->readerID = 0;
137
(readerStates[i])->readerState = 0;
138
(readerStates[i])->lockState = 0;
139
(readerStates[i])->readerSharing = 0;
140
(readerStates[i])->cardAtrLength = 0;
141
(readerStates[i])->cardProtocol = 0;
143
/* Zero the thread */
144
rContext->pthThread = 0;
146
DebugLogA("Thread stomped.");
148
return SCARD_S_SUCCESS;
151
LONG EHSpawnEventHandler(PREADER_CONTEXT rContext)
155
DWORD dwStatus, dwProtocol;
159
* Zero out everything
167
lpcReader = rContext->lpcReader;
169
rv = IFDStatusICC(rContext, &dwStatus,
170
&dwProtocol, rContext->ucAtr, &rContext->dwAtrLen);
172
if (rv != SCARD_S_SUCCESS)
174
DebugLogB("Initial Check Failed on %s", lpcReader);
175
return SCARD_F_UNKNOWN_ERROR;
179
* Find an empty reader slot and insert the new reader
181
for (i = 0; i < PCSCLITE_MAX_READERS_CONTEXTS; i++)
183
if ((readerStates[i])->readerID == 0)
187
if (i == PCSCLITE_MAX_READERS_CONTEXTS)
188
return SCARD_F_INTERNAL_ERROR;
191
* Set all the attributes to this reader
193
strcpy((readerStates[i])->readerName, rContext->lpcReader);
194
memcpy((readerStates[i])->cardAtr, rContext->ucAtr,
196
(readerStates[i])->readerID = i + 100;
197
(readerStates[i])->readerState = rContext->dwStatus;
198
(readerStates[i])->readerSharing = rContext->dwContexts;
199
(readerStates[i])->cardAtrLength = rContext->dwAtrLen;
200
(readerStates[i])->cardProtocol = rContext->dwProtocol;
202
* So the thread can access this array indice
204
rContext->dwPublicID = i;
206
rv = SYS_ThreadCreate(&rContext->pthThread, NULL,
207
(LPVOID) EHStatusHandlerThread, (LPVOID) rContext);
209
return SCARD_S_SUCCESS;
211
return SCARD_E_NO_MEMORY;
214
void EHStatusHandlerThread(PREADER_CONTEXT rContext)
218
DWORD dwStatus, dwProtocol, dwReaderSharing;
219
DWORD dwErrorCount, dwCurrentState;
223
* Zero out everything
298
231
dwErrorCount = 0;
302
/* End of race condition code block */
307
if ( dwStatus & SCARD_ABSENT ) {
308
if ( dwCurrentState == SCARD_PRESENT ||
309
dwCurrentState == SCARD_UNKNOWN ) {
311
/* Change the status structure */
312
DebugLogB("EHSpawnEventHandler: Card Removed From %s", lpcReader);
313
/* Notify the card has been removed */
314
RFSetReaderEventState( rContext, SCARD_REMOVED );
316
rContext->dwAtrLen = 0;
317
rContext->dwProtocol = 0;
318
rContext->dwStatus |= SCARD_ABSENT;
319
rContext->dwStatus &= ~SCARD_UNKNOWN;
320
rContext->dwStatus &= ~SCARD_PRESENT;
321
rContext->dwStatus &= ~SCARD_POWERED;
322
rContext->dwStatus &= ~SCARD_NEGOTIABLE;
323
rContext->dwStatus &= ~SCARD_SWALLOWED;
324
rContext->dwStatus &= ~SCARD_SPECIFIC;
325
dwCurrentState = SCARD_ABSENT;
327
/* Set all the public attributes to this reader */
328
(readerStates[i])->readerState = rContext->dwStatus;
329
(readerStates[i])->cardAtrLength = rContext->dwAtrLen;
330
(readerStates[i])->cardProtocol = rContext->dwProtocol;
331
memcpy((readerStates[i])->cardAtr, rContext->ucAtr,
334
SYS_MMapSynchronize( (void *)readerStates[i], pageSize );
337
} else if ( dwStatus & SCARD_PRESENT ) {
338
if ( dwCurrentState == SCARD_ABSENT ||
339
dwCurrentState == SCARD_UNKNOWN ) {
341
/* Power and reset the card */
342
SYS_USleep( PCSCLITE_STATUS_WAIT );
343
rv = IFDPowerICC( rContext, IFD_POWER_UP,
345
&rContext->dwAtrLen );
347
if ( rv == IFD_SUCCESS ) {
348
rContext->dwProtocol = PHGetDefaultProtocol( rContext->ucAtr,
349
rContext->dwAtrLen );
350
rContext->dwStatus |= SCARD_PRESENT;
351
rContext->dwStatus &= ~SCARD_ABSENT;
352
rContext->dwStatus |= SCARD_POWERED;
353
rContext->dwStatus |= SCARD_NEGOTIABLE;
354
rContext->dwStatus &= ~SCARD_SPECIFIC;
355
rContext->dwStatus &= ~SCARD_UNKNOWN;
356
rContext->dwStatus &= ~SCARD_SWALLOWED;
359
/* Notify the card has been reset */
360
/* RFSetReaderEventState( rContext, SCARD_RESET ); */
362
rContext->dwStatus |= SCARD_PRESENT;
363
rContext->dwStatus &= ~SCARD_ABSENT;
364
rContext->dwStatus |= SCARD_SWALLOWED;
365
rContext->dwStatus &= ~SCARD_POWERED;
366
rContext->dwStatus &= ~SCARD_NEGOTIABLE;
367
rContext->dwStatus &= ~SCARD_SPECIFIC;
368
rContext->dwStatus &= ~SCARD_UNKNOWN;
369
rContext->dwAtrLen = 0;
370
rContext->dwProtocol = 0;
373
dwCurrentState = SCARD_PRESENT;
375
/* Set all the public attributes to this reader */
376
(readerStates[i])->readerState = rContext->dwStatus;
377
(readerStates[i])->cardAtrLength = rContext->dwAtrLen;
378
(readerStates[i])->cardProtocol = rContext->dwProtocol;
379
memcpy((readerStates[i])->cardAtr, rContext->ucAtr,
382
SYS_MMapSynchronize( (void *)readerStates[i], pageSize );
385
DebugLogB("EHSpawnEventHandler: Card inserted into %s", lpcReader);
387
if ( rv == IFD_SUCCESS ) {
388
if ( rContext->dwAtrLen > 0 ) {
389
DebugXxd("EHSpawnEventHandler: Card ATR: ",
390
rContext->ucAtr, rContext->dwAtrLen);
392
DebugLogA("EHSpawnEventHandler: Card ATR: (NULL)");
396
DebugLogA("EHSpawnEventHandler: Error powering up card.");
401
if ( rContext->dwLockId == 0xFFFF) {
402
/* Exit and notify the caller */
403
rContext->dwLockId = 0;
404
SYS_ThreadDetach( rContext->pthThread );
408
/* Sharing may change w/o an event pass it on */
410
if ( dwReaderSharing != rContext->dwContexts ) {
411
dwReaderSharing = rContext->dwContexts;
412
(readerStates[i])->readerSharing = dwReaderSharing;
413
SYS_MMapSynchronize( (void *)readerStates[i], pageSize );
416
SYS_USleep( PCSCLITE_STATUS_POLL_RATE );
235
lpcReader = rContext->lpcReader;
236
i = rContext->dwPublicID;
238
pageSize = SYS_GetPageSize();
240
rv = IFDStatusICC(rContext, &dwStatus,
241
&dwProtocol, rContext->ucAtr, &rContext->dwAtrLen);
243
if (dwStatus & SCARD_PRESENT)
245
rv = IFDPowerICC(rContext, IFD_POWER_UP,
246
rContext->ucAtr, &rContext->dwAtrLen);
248
if (rv == IFD_SUCCESS)
250
rContext->dwProtocol = PHGetDefaultProtocol(rContext->ucAtr,
252
rContext->dwStatus |= SCARD_PRESENT;
253
rContext->dwStatus &= ~SCARD_ABSENT;
254
rContext->dwStatus |= SCARD_POWERED;
255
rContext->dwStatus |= SCARD_NEGOTIABLE;
256
rContext->dwStatus &= ~SCARD_SPECIFIC;
257
rContext->dwStatus &= ~SCARD_SWALLOWED;
258
rContext->dwStatus &= ~SCARD_UNKNOWN;
262
rContext->dwStatus |= SCARD_PRESENT;
263
rContext->dwStatus &= ~SCARD_ABSENT;
264
rContext->dwStatus |= SCARD_SWALLOWED;
265
rContext->dwStatus &= ~SCARD_POWERED;
266
rContext->dwStatus &= ~SCARD_NEGOTIABLE;
267
rContext->dwStatus &= ~SCARD_SPECIFIC;
268
rContext->dwStatus &= ~SCARD_UNKNOWN;
269
rContext->dwProtocol = 0;
270
rContext->dwAtrLen = 0;
273
dwCurrentState = SCARD_PRESENT;
278
dwCurrentState = SCARD_ABSENT;
279
rContext->dwStatus |= SCARD_ABSENT;
280
rContext->dwStatus &= ~SCARD_PRESENT;
281
rContext->dwStatus &= ~SCARD_POWERED;
282
rContext->dwStatus &= ~SCARD_NEGOTIABLE;
283
rContext->dwStatus &= ~SCARD_SPECIFIC;
284
rContext->dwStatus &= ~SCARD_SWALLOWED;
285
rContext->dwStatus &= ~SCARD_UNKNOWN;
286
rContext->dwAtrLen = 0;
287
rContext->dwProtocol = 0;
291
* Set all the public attributes to this reader
293
(readerStates[i])->readerState = rContext->dwStatus;
294
(readerStates[i])->cardAtrLength = rContext->dwAtrLen;
295
(readerStates[i])->cardProtocol = rContext->dwProtocol;
296
(readerStates[i])->readerSharing = dwReaderSharing =
297
rContext->dwContexts;
298
memcpy((readerStates[i])->cardAtr, rContext->ucAtr,
301
SYS_MMapSynchronize((void *) readerStates[i], pageSize);
307
rv = IFDStatusICC(rContext, &dwStatus,
308
&dwProtocol, rContext->ucAtr, &rContext->dwAtrLen);
310
if (rv != SCARD_S_SUCCESS)
312
DebugLogB("Error communicating to: %s", lpcReader);
315
* Set error status on this reader while errors occur
318
rContext->dwStatus &= ~SCARD_ABSENT;
319
rContext->dwStatus &= ~SCARD_PRESENT;
320
rContext->dwStatus &= ~SCARD_POWERED;
321
rContext->dwStatus &= ~SCARD_NEGOTIABLE;
322
rContext->dwStatus &= ~SCARD_SPECIFIC;
323
rContext->dwStatus &= ~SCARD_SWALLOWED;
324
rContext->dwStatus |= SCARD_UNKNOWN;
325
rContext->dwAtrLen = 0;
326
rContext->dwProtocol = 0;
328
dwCurrentState = SCARD_UNKNOWN;
331
* Set all the public attributes to this reader
333
(readerStates[i])->readerState = rContext->dwStatus;
334
(readerStates[i])->cardAtrLength = rContext->dwAtrLen;
335
(readerStates[i])->cardProtocol = rContext->dwProtocol;
336
memcpy((readerStates[i])->cardAtr, rContext->ucAtr,
339
SYS_MMapSynchronize((void *) readerStates[i], pageSize);
342
* This code causes race conditions on G4's with USB
346
* dwErrorCount += 1; SYS_Sleep(1);
349
* After 10 seconds of errors, try to reinitialize the reader
350
* This sometimes helps bring readers out of *crazy* states.
353
* if ( dwErrorCount == 10 ) { RFUnInitializeReader( rContext
354
* ); RFInitializeReader( rContext ); dwErrorCount = 0; }
358
* End of race condition code block
362
if (dwStatus & SCARD_ABSENT)
364
if (dwCurrentState == SCARD_PRESENT ||
365
dwCurrentState == SCARD_UNKNOWN)
368
* Change the status structure
370
DebugLogB("Card Removed From %s", lpcReader);
372
* Notify the card has been removed
374
RFSetReaderEventState(rContext, SCARD_REMOVED);
376
rContext->dwAtrLen = 0;
377
rContext->dwProtocol = 0;
378
rContext->dwStatus |= SCARD_ABSENT;
379
rContext->dwStatus &= ~SCARD_UNKNOWN;
380
rContext->dwStatus &= ~SCARD_PRESENT;
381
rContext->dwStatus &= ~SCARD_POWERED;
382
rContext->dwStatus &= ~SCARD_NEGOTIABLE;
383
rContext->dwStatus &= ~SCARD_SWALLOWED;
384
rContext->dwStatus &= ~SCARD_SPECIFIC;
385
dwCurrentState = SCARD_ABSENT;
388
* Set all the public attributes to this reader
390
(readerStates[i])->readerState = rContext->dwStatus;
391
(readerStates[i])->cardAtrLength = rContext->dwAtrLen;
392
(readerStates[i])->cardProtocol = rContext->dwProtocol;
393
memcpy((readerStates[i])->cardAtr, rContext->ucAtr,
396
SYS_MMapSynchronize((void *) readerStates[i], pageSize);
400
else if (dwStatus & SCARD_PRESENT)
402
if (dwCurrentState == SCARD_ABSENT ||
403
dwCurrentState == SCARD_UNKNOWN)
406
* Power and reset the card
408
SYS_USleep(PCSCLITE_STATUS_WAIT);
409
rv = IFDPowerICC(rContext, IFD_POWER_UP,
410
rContext->ucAtr, &rContext->dwAtrLen);
412
if (rv == IFD_SUCCESS)
414
rContext->dwProtocol =
415
PHGetDefaultProtocol(rContext->ucAtr,
417
rContext->dwStatus |= SCARD_PRESENT;
418
rContext->dwStatus &= ~SCARD_ABSENT;
419
rContext->dwStatus |= SCARD_POWERED;
420
rContext->dwStatus |= SCARD_NEGOTIABLE;
421
rContext->dwStatus &= ~SCARD_SPECIFIC;
422
rContext->dwStatus &= ~SCARD_UNKNOWN;
423
rContext->dwStatus &= ~SCARD_SWALLOWED;
426
* Notify the card has been reset
429
* RFSetReaderEventState( rContext, SCARD_RESET );
434
rContext->dwStatus |= SCARD_PRESENT;
435
rContext->dwStatus &= ~SCARD_ABSENT;
436
rContext->dwStatus |= SCARD_SWALLOWED;
437
rContext->dwStatus &= ~SCARD_POWERED;
438
rContext->dwStatus &= ~SCARD_NEGOTIABLE;
439
rContext->dwStatus &= ~SCARD_SPECIFIC;
440
rContext->dwStatus &= ~SCARD_UNKNOWN;
441
rContext->dwAtrLen = 0;
442
rContext->dwProtocol = 0;
445
dwCurrentState = SCARD_PRESENT;
448
* Set all the public attributes to this reader
450
(readerStates[i])->readerState = rContext->dwStatus;
451
(readerStates[i])->cardAtrLength = rContext->dwAtrLen;
452
(readerStates[i])->cardProtocol = rContext->dwProtocol;
453
memcpy((readerStates[i])->cardAtr, rContext->ucAtr,
456
SYS_MMapSynchronize((void *) readerStates[i], pageSize);
458
DebugLogB("Card inserted into %s", lpcReader);
460
if (rv == IFD_SUCCESS)
462
if (rContext->dwAtrLen > 0)
464
DebugXxd("Card ATR: ",
465
rContext->ucAtr, rContext->dwAtrLen);
468
DebugLogA("Card ATR: (NULL)");
471
DebugLogA("Error powering up card.");
475
if (rContext->dwLockId == 0xFFFF)
478
* Exit and notify the caller
480
rContext->dwLockId = 0;
481
SYS_ThreadDetach(rContext->pthThread);
486
* Sharing may change w/o an event pass it on
489
if (dwReaderSharing != rContext->dwContexts)
491
dwReaderSharing = rContext->dwContexts;
492
(readerStates[i])->readerSharing = dwReaderSharing;
493
SYS_MMapSynchronize((void *) readerStates[i], pageSize);
496
SYS_USleep(PCSCLITE_STATUS_POLL_RATE);
420
void EHSetSharingEvent( PREADER_CONTEXT rContext, DWORD dwValue ) {
422
(readerStates[rContext->dwPublicID])->lockState = dwValue;
500
void EHSetSharingEvent(PREADER_CONTEXT rContext, DWORD dwValue)
502
(readerStates[rContext->dwPublicID])->lockState = dwValue;