47 #include <sys/types.h> 65 #include "configfile.h" 75 static int maxReaderHandles = PCSC_MAX_READER_HANDLES;
76 static DWORD dwNumReadersContexts = 0;
78 static char *ConfigFile = NULL;
79 static int ConfigFileCRC = 0;
81 static pthread_mutex_t LockMutex = PTHREAD_MUTEX_INITIALIZER;
83 #define IDENTITY_SHIFT 16 86 static int RDR_CLIHANDLES_seeker(
const void *el,
const void *key)
90 if ((el == NULL) || (key == NULL))
92 Log3(PCSC_LOG_CRITICAL,
93 "RDR_CLIHANDLES_seeker called with NULL pointer: el=%p, key=%p",
127 removeReader(sReader);
132 LONG RFAllocateReaderSpace(
unsigned int customMaxReaderHandles)
136 if (customMaxReaderHandles != 0)
137 maxReaderHandles = customMaxReaderHandles;
143 sReadersContexts[i]->
vHandle = NULL;
146 memset(readerStates[i].readerName, 0, MAX_READERNAME);
154 sReadersContexts[i]->
readerState = &readerStates[i];
158 return EHInitializeEventStructures();
161 LONG RFAddReader(
const char *readerNameLong,
int port,
const char *library,
164 DWORD dwContext = 0, dwGetSize;
165 UCHAR ucGetData[1], ucThread[1];
169 char *readerName = NULL;
171 if ((readerNameLong == NULL) || (library == NULL) || (device == NULL))
175 const char *ro_filter = getenv(
"PCSCLITE_FILTER_IGNORE_READER_NAMES");
181 filter = alloca(strlen(ro_filter)+1);
182 strcpy(filter, ro_filter);
187 next = strchr(filter,
':');
195 if (*filter && strstr(readerNameLong, filter))
198 "Reader name \"%s\" contains \"%s\": ignored",
199 readerNameLong, filter);
214 readerName = alloca(strlen(readerNameLong)+1);
215 strcpy(readerName, readerNameLong);
218 if (strlen(readerName) > MAX_READERNAME -
sizeof(
" 00 00"))
221 "Reader name too long: %zd chars instead of max %zd. Truncating!",
222 strlen(readerName), MAX_READERNAME -
sizeof(
" 00 00"));
223 readerName[MAX_READERNAME -
sizeof(
" 00 00")] =
'\0';
227 if (dwNumReadersContexts != 0)
231 if (sReadersContexts[i]->vHandle != 0)
233 char lpcStripReader[MAX_READERNAME];
237 strncpy(lpcStripReader,
238 sReadersContexts[i]->readerState->readerName,
239 sizeof(lpcStripReader));
240 tmplen = strlen(lpcStripReader);
241 lpcStripReader[tmplen - 6] = 0;
243 if ((strcmp(readerName, lpcStripReader) == 0)
244 && (port == sReadersContexts[i]->port)
245 && (strcmp(device, sReadersContexts[i]->device) == 0))
247 Log1(PCSC_LOG_ERROR,
"Duplicate reader found.");
257 if (sReadersContexts[i]->vHandle == 0)
264 if (i == PCSCLITE_MAX_READERS_CONTEXTS)
271 parentNode = RFSetReaderName(sReadersContexts[dwContext], readerName,
276 sReadersContexts[dwContext]->
library = strdup(library);
277 sReadersContexts[dwContext]->
device = strdup(device);
278 sReadersContexts[dwContext]->
version = 0;
279 sReadersContexts[dwContext]->
port = port;
280 sReadersContexts[dwContext]->
mMutex = NULL;
281 sReadersContexts[dwContext]->
contexts = 0;
282 sReadersContexts[dwContext]->
pthThread = 0;
283 sReadersContexts[dwContext]->
hLockId = 0;
284 sReadersContexts[dwContext]->
LockCount = 0;
285 sReadersContexts[dwContext]->
vHandle = NULL;
286 sReadersContexts[dwContext]->
pFeeds = NULL;
287 sReadersContexts[dwContext]->
pMutex = NULL;
290 lrv = list_init(&sReadersContexts[dwContext]->handlesList);
293 Log2(PCSC_LOG_CRITICAL,
"list_init failed with return value: %d", lrv);
297 lrv = list_attributes_seeker(&sReadersContexts[dwContext]->handlesList,
298 RDR_CLIHANDLES_seeker);
301 Log2(PCSC_LOG_CRITICAL,
302 "list_attributes_seeker failed with return value: %d", lrv);
306 (void)pthread_mutex_init(&sReadersContexts[dwContext]->handlesList_lock,
309 (void)pthread_mutex_init(&sReadersContexts[dwContext]->powerState_lock,
314 (void)pthread_mutex_init(&sReadersContexts[dwContext]->reference_lock,
316 sReadersContexts[dwContext]->
reference = 1;
319 if (parentNode >= 0 && parentNode < PCSCLITE_MAX_READERS_CONTEXTS)
321 sReadersContexts[dwContext]->
pFeeds =
322 sReadersContexts[parentNode]->
pFeeds;
323 *(sReadersContexts[dwContext])->pFeeds += 1;
324 sReadersContexts[dwContext]->
vHandle =
325 sReadersContexts[parentNode]->
vHandle;
326 sReadersContexts[dwContext]->
mMutex =
327 sReadersContexts[parentNode]->
mMutex;
328 sReadersContexts[dwContext]->
pMutex =
329 sReadersContexts[parentNode]->
pMutex;
332 dwGetSize =
sizeof(ucThread);
336 if (rv ==
IFD_SUCCESS && dwGetSize == 1 && ucThread[0] == 1)
338 Log1(PCSC_LOG_INFO,
"Driver is thread safe");
339 sReadersContexts[dwContext]->
mMutex = NULL;
340 sReadersContexts[dwContext]->
pMutex = NULL;
343 *(sReadersContexts[dwContext])->pMutex += 1;
346 if (sReadersContexts[dwContext]->pFeeds == NULL)
348 sReadersContexts[dwContext]->
pFeeds = malloc(
sizeof(
int));
354 *(sReadersContexts[dwContext])->pFeeds = 1;
357 if (sReadersContexts[dwContext]->mMutex == 0)
359 sReadersContexts[dwContext]->
mMutex =
360 malloc(
sizeof(pthread_mutex_t));
361 (void)pthread_mutex_init(sReadersContexts[dwContext]->mMutex, NULL);
364 if (sReadersContexts[dwContext]->pMutex == NULL)
366 sReadersContexts[dwContext]->
pMutex = malloc(
sizeof(
int));
367 *(sReadersContexts[dwContext])->pMutex = 1;
370 dwNumReadersContexts += 1;
372 rv = RFInitializeReader(sReadersContexts[dwContext]);
376 Log2(PCSC_LOG_ERROR,
"%s init failed.", readerName);
377 (void)RFRemoveReader(readerName, port);
383 RESPONSECODE (*fct)(DWORD, int) = NULL;
385 dwGetSize =
sizeof(fct);
391 Log1(PCSC_LOG_INFO,
"Using the pcscd polling thread");
396 Log1(PCSC_LOG_INFO,
"Using the reader polling thread");
399 rv = EHSpawnEventHandler(sReadersContexts[dwContext]);
402 Log2(PCSC_LOG_ERROR,
"%s init failed.", readerName);
403 (void)RFRemoveReader(readerName, port);
409 dwGetSize =
sizeof(ucGetData);
413 if (rv !=
IFD_SUCCESS || dwGetSize != 1 || ucGetData[0] == 0)
418 if (rv ==
IFD_SUCCESS && dwGetSize == 1 && ucGetData[0] == 1)
428 for (j = 1; j < ucGetData[0]; j++)
430 char *tmpReader = NULL;
431 DWORD dwContextB = 0;
432 RESPONSECODE (*fct)(DWORD, int) = NULL;
437 if (sReadersContexts[i]->vHandle == 0)
444 if (i == PCSCLITE_MAX_READERS_CONTEXTS)
447 RFRemoveReader(readerName, port);
454 sReadersContexts[dwContext]->readerState->readerName,
456 snprintf(tmpReader + strlen(tmpReader) - 2, 3,
"%02X", j);
458 sReadersContexts[dwContextB]->
library =
459 sReadersContexts[dwContext]->
library;
460 sReadersContexts[dwContextB]->
device =
461 sReadersContexts[dwContext]->
device;
462 sReadersContexts[dwContextB]->
version =
463 sReadersContexts[dwContext]->
version;
464 sReadersContexts[dwContextB]->
port =
465 sReadersContexts[dwContext]->
port;
466 sReadersContexts[dwContextB]->
vHandle =
467 sReadersContexts[dwContext]->
vHandle;
468 sReadersContexts[dwContextB]->
mMutex =
469 sReadersContexts[dwContext]->
mMutex;
470 sReadersContexts[dwContextB]->
pMutex =
471 sReadersContexts[dwContext]->
pMutex;
472 sReadersContexts[dwContextB]->
slot =
473 sReadersContexts[dwContext]->
slot + j;
480 sReadersContexts[dwContextB]->
pFeeds =
481 sReadersContexts[dwContext]->
pFeeds;
484 *(sReadersContexts[dwContextB])->pFeeds += 1;
486 sReadersContexts[dwContextB]->
contexts = 0;
487 sReadersContexts[dwContextB]->
hLockId = 0;
488 sReadersContexts[dwContextB]->
LockCount = 0;
490 lrv = list_init(&sReadersContexts[dwContextB]->handlesList);
493 Log2(PCSC_LOG_CRITICAL,
"list_init failed with return value: %d", lrv);
497 lrv = list_attributes_seeker(&sReadersContexts[dwContextB]->handlesList,
498 RDR_CLIHANDLES_seeker);
501 Log2(PCSC_LOG_CRITICAL,
502 "list_attributes_seeker failed with return value: %d", lrv);
506 (void)pthread_mutex_init(&sReadersContexts[dwContextB]->handlesList_lock, NULL);
507 (void)pthread_mutex_init(&sReadersContexts[dwContextB]->powerState_lock,
512 (void)pthread_mutex_init(&sReadersContexts[dwContextB]->reference_lock,
514 sReadersContexts[dwContextB]->
reference = 1;
517 dwGetSize =
sizeof(ucThread);
521 if (rv ==
IFD_SUCCESS && dwGetSize == 1 && ucThread[0] == 1)
523 Log1(PCSC_LOG_INFO,
"Driver is slot thread safe");
525 sReadersContexts[dwContextB]->
library =
526 strdup(sReadersContexts[dwContext]->library);
527 sReadersContexts[dwContextB]->
device =
528 strdup(sReadersContexts[dwContext]->device);
529 sReadersContexts[dwContextB]->
mMutex =
530 malloc(
sizeof(pthread_mutex_t));
531 (void)pthread_mutex_init(sReadersContexts[dwContextB]->mMutex,
534 sReadersContexts[dwContextB]->
pMutex = malloc(
sizeof(
int));
535 *(sReadersContexts[dwContextB])->pMutex = 1;
538 *(sReadersContexts[dwContextB])->pMutex += 1;
540 dwNumReadersContexts += 1;
542 rv = RFInitializeReader(sReadersContexts[dwContextB]);
546 (void)RFRemoveReader(readerName, port);
551 dwGetSize =
sizeof(fct);
557 Log1(PCSC_LOG_INFO,
"Using the pcscd polling thread");
562 Log1(PCSC_LOG_INFO,
"Using the reader polling thread");
565 rv = EHSpawnEventHandler(sReadersContexts[dwContextB]);
568 Log2(PCSC_LOG_ERROR,
"%s init failed.", readerName);
569 (void)RFRemoveReader(readerName, port);
577 LONG RFRemoveReader(
const char *readerName,
int port)
579 char lpcStripReader[MAX_READERNAME];
586 if (readerName == NULL)
590 extend = getenv(
"PCSCLITE_FILTER_EXTEND_READER_NAMES");
592 extend_size = strlen(extend);
597 if (sReadersContexts[i]->vHandle != 0)
599 strncpy(lpcStripReader,
600 sReadersContexts[i]->readerState->readerName,
601 sizeof(lpcStripReader));
602 lpcStripReader[strlen(lpcStripReader) - 6 - extend_size] = 0;
605 if ((strncmp(readerName, lpcStripReader, MAX_READERNAME -
sizeof(
" 00 00")) == 0)
606 && (port == sReadersContexts[i]->port))
609 UNREF_READER(sReadersContexts[i])
620 if (sContext -> pthThread)
621 EHDestroyEventHandler(sContext);
623 if ((NULL == sContext->
pMutex) || (NULL == sContext->
pFeeds))
626 "Trying to remove an already removed driver");
630 RFUnInitializeReader(sContext);
635 if (0 == *sContext->
pMutex)
637 (void)pthread_mutex_destroy(sContext->
mMutex);
649 if (*sContext->
pFeeds == 0)
665 while (list_size(&sContext->handlesList) != 0)
670 currentHandle = list_get_at(&sContext->handlesList, 0);
671 lrv = list_delete_at(&sContext->handlesList, 0);
673 Log2(PCSC_LOG_CRITICAL,
674 "list_delete_at failed with return value: %d", lrv);
680 list_destroy(&sContext->handlesList);
681 dwNumReadersContexts -= 1;
689 LONG RFSetReaderName(
READER_CONTEXT * rContext,
const char *readerName,
690 const char *libraryName,
int port)
694 int currentDigit = -1;
695 int supportedChannels = 0;
698 const char *extend =
"";
702 usedDigits[i] = FALSE;
704 if (dwNumReadersContexts != 0)
708 if (sReadersContexts[i]->vHandle != 0)
710 if (strcmp(sReadersContexts[i]->library, libraryName) == 0)
716 valueLength =
sizeof(tagValue);
719 &valueLength, tagValue);
724 supportedChannels = tagValue[0];
726 "Support %d simultaneous readers", tagValue[0]);
729 supportedChannels = 1;
732 if ((((sReadersContexts[i]->port & 0xFFFF0000) ==
733 PCSCLITE_HP_BASE_PORT)
734 && (sReadersContexts[i]->port != port))
735 || (supportedChannels > 1))
751 currentDigit = strtol(reader + strlen(reader) - 5, NULL, 16);
754 usedDigits[currentDigit] = TRUE;
765 if (currentDigit != -1)
770 if (usedDigits[i] == FALSE)
774 if (i == PCSCLITE_MAX_READERS_CONTEXTS)
776 Log2(PCSC_LOG_ERROR,
"Max number of readers reached: %d", PCSCLITE_MAX_READERS_CONTEXTS);
780 if (i >= supportedChannels)
782 Log3(PCSC_LOG_ERROR,
"Driver %s does not support more than " 783 "%d reader(s). Maybe the driver should support " 784 "TAG_IFD_SIMULTANEOUS_ACCESS", libraryName, supportedChannels);
790 extend = getenv(
"PCSCLITE_FILTER_EXTEND_READER_NAMES");
797 readerName, extend, i);
800 rContext->
slot = i << 16;
805 LONG RFReaderInfo(
const char *readerName,
READER_CONTEXT ** sReader)
809 if (readerName == NULL)
814 if (sReadersContexts[i]->vHandle != 0)
816 if (strcmp(readerName,
817 sReadersContexts[i]->readerState->readerName) == 0)
820 REF_READER(sReadersContexts[i])
822 *sReader = sReadersContexts[i];
837 if (sReadersContexts[i]->vHandle != 0)
840 (void)pthread_mutex_lock(&sReadersContexts[i]->handlesList_lock);
841 currentHandle = list_seek(&sReadersContexts[i]->handlesList,
843 (void)pthread_mutex_unlock(&sReadersContexts[i]->handlesList_lock);
844 if (currentHandle != NULL)
847 REF_READER(sReadersContexts[i])
849 *sReader = sReadersContexts[i];
862 Log2(PCSC_LOG_INFO,
"Reusing already loaded driver for %s",
876 rv = DYN_GetAddress(rContext->
vHandle, &f,
"IFDHCreateChannelByName", TRUE);
880 rContext->
version = IFD_HVERSION_3_0;
884 rv = DYN_GetAddress(rContext->
vHandle, &f,
"IFDHCreateChannel", FALSE);
888 rContext->
version = IFD_HVERSION_2_0;
893 Log1(PCSC_LOG_CRITICAL,
"IFDHandler functions missing");
898 if (rContext->
version == IFD_HVERSION_2_0)
901 #define GET_ADDRESS_OPTIONALv2(s, code) \ 904 int rvl = DYN_GetAddress(rContext->vHandle, &f1, "IFDH" #s, FALSE); \ 905 if (SCARD_S_SUCCESS != rvl) \ 909 rContext->psFunctions.psFunctions_v2.pvf ## s = f1; \ 912 #define GET_ADDRESSv2(s) \ 913 GET_ADDRESS_OPTIONALv2(s, \ 914 Log1(PCSC_LOG_CRITICAL, "IFDHandler functions missing: " #s ); \ 917 Log1(PCSC_LOG_INFO,
"Loading IFD Handler 2.0");
919 GET_ADDRESSv2(CreateChannel)
920 GET_ADDRESSv2(CloseChannel)
921 GET_ADDRESSv2(GetCapabilities)
922 GET_ADDRESSv2(SetCapabilities)
923 GET_ADDRESSv2(PowerICC)
924 GET_ADDRESSv2(TransmitToICC)
925 GET_ADDRESSv2(ICCPresence)
926 GET_ADDRESS_OPTIONALv2(SetProtocolParameters, )
928 GET_ADDRESSv2(Control)
930 else if (rContext->version == IFD_HVERSION_3_0)
933 #define GET_ADDRESS_OPTIONALv3(s, code) \ 936 int rvl = DYN_GetAddress(rContext->vHandle, &f1, "IFDH" #s, FALSE); \ 937 if (SCARD_S_SUCCESS != rvl) \ 941 rContext->psFunctions.psFunctions_v3.pvf ## s = f1; \ 944 #define GET_ADDRESSv3(s) \ 945 GET_ADDRESS_OPTIONALv3(s, \ 946 Log1(PCSC_LOG_CRITICAL, "IFDHandler functions missing: " #s ); \ 949 Log1(PCSC_LOG_INFO,
"Loading IFD Handler 3.0");
951 GET_ADDRESSv2(CreateChannel)
952 GET_ADDRESSv2(CloseChannel)
953 GET_ADDRESSv2(GetCapabilities)
954 GET_ADDRESSv2(SetCapabilities)
955 GET_ADDRESSv2(PowerICC)
956 GET_ADDRESSv2(TransmitToICC)
957 GET_ADDRESSv2(ICCPresence)
958 GET_ADDRESS_OPTIONALv2(SetProtocolParameters, )
960 GET_ADDRESSv3(CreateChannelByName)
961 GET_ADDRESSv3(Control)
966 Log1(PCSC_LOG_CRITICAL,
"IFD Handler not 1.0/2.0 or 3.0");
984 if (*rContext->
pFeeds == 1)
986 Log1(PCSC_LOG_INFO,
"Unloading reader driver.");
987 (void)DYN_CloseLibrary(&rContext->
vHandle);
1007 (void)pthread_mutex_lock(&LockMutex);
1008 rv = RFCheckSharing(hCard, rContext);
1014 (void)pthread_mutex_unlock(&LockMutex);
1023 (void)pthread_mutex_lock(&LockMutex);
1024 rv = RFCheckSharing(hCard, rContext);
1047 (void)pthread_mutex_unlock(&LockMutex);
1056 (void)pthread_mutex_lock(&LockMutex);
1057 rv = RFCheckSharing(hCard, rContext);
1063 (void)pthread_mutex_unlock(&LockMutex);
1073 Log3(PCSC_LOG_INFO,
"Attempting startup of %s using %s",
1076 #ifndef PCSCLITE_STATIC_DRIVER 1078 rv = RFLoadReader(rContext);
1081 Log2(PCSC_LOG_ERROR,
"RFLoadReader failed: 0x%lX", rv);
1086 rv = RFBindFunctions(rContext);
1090 Log2(PCSC_LOG_ERROR,
"RFBindFunctions failed: 0x%lX", rv);
1091 (void)RFUnloadReader(rContext);
1096 rContext->
vHandle = RFInitializeReader;
1104 Log3(PCSC_LOG_CRITICAL,
"Open Port 0x%X Failed (%s)",
1108 rContext->
slot = -1;
1111 rContext->
slot = -1;
1124 Log2(PCSC_LOG_INFO,
"Attempting shutdown of %s.",
1128 if (rContext->
slot != -1)
1131 (void)RFUnBindFunctions(rContext);
1132 (void)RFUnloadReader(rContext);
1169 ret = RFReaderInfoById(randHandle, &dummy_reader);
1171 UNREF_READER(dummy_reader)
1182 int listLength, lrv;
1187 listLength = list_size(&rContext->handlesList);
1190 if (listLength >= maxReaderHandles)
1192 Log2(PCSC_LOG_CRITICAL,
1193 "Too many handles opened, exceeding configured max (%d)",
1200 if (NULL == newHandle)
1202 Log1(PCSC_LOG_CRITICAL,
"malloc failed");
1207 newHandle->
hCard = hCard;
1210 lrv = list_append(&rContext->handlesList, newHandle);
1214 Log2(PCSC_LOG_CRITICAL,
"list_append failed with return value: %d",
1230 currentHandle = list_seek(&rContext->handlesList, &hCard);
1231 if (NULL == currentHandle)
1233 Log2(PCSC_LOG_CRITICAL,
"list_seek failed to locate hCard=%lX", hCard);
1238 lrv = list_delete(&rContext->handlesList, currentHandle);
1240 Log2(PCSC_LOG_CRITICAL,
1241 "list_delete failed with return value: %d", lrv);
1243 free(currentHandle);
1252 void RFSetReaderEventState(
READER_CONTEXT * rContext, DWORD dwEvent)
1255 int list_index, listSize;
1259 listSize = list_size(&rContext->handlesList);
1261 for (list_index = 0; list_index < listSize; list_index++)
1263 currentHandle = list_get_at(&rContext->handlesList, list_index);
1264 if (NULL == currentHandle)
1266 Log2(PCSC_LOG_CRITICAL,
"list_get_at failed at index %d",
1291 currentHandle = list_seek(&rContext->handlesList, &hCard);
1293 if (NULL == currentHandle)
1296 Log2(PCSC_LOG_CRITICAL,
"list_seek failed for hCard 0x%lX", hCard);
1326 currentHandle = list_seek(&rContext->handlesList, &hCard);
1328 if (NULL == currentHandle)
1348 void RFCleanupReaders(
void)
1352 Log1(PCSC_LOG_INFO,
"entering cleaning function");
1355 if (sReadersContexts[i]->vHandle != 0)
1358 char lpcStripReader[MAX_READERNAME];
1360 Log2(PCSC_LOG_INFO,
"Stopping reader: %s",
1361 sReadersContexts[i]->readerState->readerName);
1363 strncpy(lpcStripReader,
1364 sReadersContexts[i]->readerState->readerName,
1365 sizeof(lpcStripReader));
1367 lpcStripReader[strlen(lpcStripReader) - 6] =
'\0';
1369 rv = RFRemoveReader(lpcStripReader, sReadersContexts[i]->port);
1372 Log2(PCSC_LOG_ERROR,
"RFRemoveReader error: 0x%08lX", rv);
1374 free(sReadersContexts[i]);
1392 void RFWaitForReaderInit(
void)
1394 int i, need_to_wait;
1398 need_to_wait = FALSE;
1402 if (sReadersContexts[i]->vHandle != NULL)
1406 == sReadersContexts[i]->readerState->cardAtrLength)
1408 Log2(PCSC_LOG_DEBUG,
"Waiting init for reader: %s",
1409 sReadersContexts[i]->readerState->readerName);
1410 need_to_wait = TRUE;
1417 }
while (need_to_wait);
1422 int RFStartSerialReaders(
const char *readerconf)
1428 ConfigFile = strdup(readerconf);
1430 rv = DBGetReaderListDir(readerconf, &reader_list);
1433 if (NULL == reader_list)
1440 (void)RFAddReader(reader_list[i].pcFriendlyname,
1441 reader_list[i].channelId,
1442 reader_list[i].pcLibpath, reader_list[i].pcDevicename);
1446 ConfigFileCRC += reader_list[i].pcFriendlyname[j];
1447 for (j=0; j<reader_list[i].
pcLibpath[j]; j++)
1448 ConfigFileCRC += reader_list[i].pcLibpath[j];
1450 ConfigFileCRC += reader_list[i].pcDevicename[j];
1453 free(reader_list[i].pcFriendlyname);
1454 free(reader_list[i].pcLibpath);
1455 free(reader_list[i].pcDevicename);
1462 void RFReCheckReaderConf(
void)
1467 (void)DBGetReaderListDir(ConfigFile, &reader_list);
1470 if (NULL == reader_list)
1480 crc += reader_list[i].pcFriendlyname[j];
1481 for (j=0; j<reader_list[i].
pcLibpath[j]; j++)
1482 crc += reader_list[i].pcLibpath[j];
1484 crc += reader_list[i].pcDevicename[j];
1488 if (crc != ConfigFileCRC)
1490 Log2(PCSC_LOG_CRITICAL,
1491 "configuration file: %s has been modified. Recheck canceled",
1499 char present = FALSE;
1501 Log2(PCSC_LOG_DEBUG,
"refresh reader: %s",
1502 reader_list[i].pcFriendlyname);
1507 if (sReadersContexts[r]->vHandle != 0)
1509 char lpcStripReader[MAX_READERNAME];
1513 strncpy(lpcStripReader,
1514 sReadersContexts[i]->readerState->readerName,
1515 sizeof(lpcStripReader));
1516 tmplen = strlen(lpcStripReader);
1517 lpcStripReader[tmplen - 6] = 0;
1519 if ((strcmp(reader_list[i].pcFriendlyname, lpcStripReader) == 0)
1520 && (reader_list[r].channelId == sReadersContexts[i]->port))
1531 Log2(PCSC_LOG_INFO,
"Reader %s disappeared",
1532 reader_list[i].pcFriendlyname);
1533 (void)RFRemoveReader(reader_list[i].pcFriendlyname,
1534 reader_list[r].channelId);
1543 (void)RFAddReader(reader_list[i].pcFriendlyname,
1544 reader_list[i].channelId, reader_list[i].pcLibpath,
1545 reader_list[i].pcDevicename);
1548 free(reader_list[i].pcFriendlyname);
1549 free(reader_list[i].pcLibpath);
1550 free(reader_list[i].pcDevicename);
LONG IFDStatusICC(READER_CONTEXT *rContext, PDWORD pdwStatus)
Provide statistical information about the IFD and ICC including insertions, atr, powering status/etc...
This abstracts dynamic library loading functions.
struct pubReaderStatesList * readerState
link to the reader state
#define SCARD_E_INVALID_VALUE
One or more of the supplied parameters values could not be properly interpreted.
uint32_t cardAtrLength
ATR length.
int32_t contexts
Number of open contexts.
#define IFD_NO_SUCH_DEVICE
The IFD_NO_SUCH_DEVICE error must be returned by the driver when it detects the reader is no more pre...
#define TAG_IFD_THREAD_SAFE
driver is thread safe
volatile SCARDHANDLE hLockId
Lock Id.
#define SCARD_S_SUCCESS
No error was encountered.
void EHSignalEventToClients(void)
Sends an asynchronous event to any waiting client.
pthread_t pthThread
Event polling thread.
#define SCARD_E_INVALID_TARGET
Registry startup information is missing or invalid.
LONG IFDGetCapabilities(READER_CONTEXT *rContext, DWORD dwTag, PDWORD pdwLength, PUCHAR pucValue)
Get's capabilities in the reader.
#define SCARD_UNKNOWN
Unknown state.
DWORD dwEventStatus
Recent event that must be sent.
RESPONSECODE(* pthCardEvent)(DWORD, int)
Card Event sync.
char readerName[MAX_READERNAME]
reader name
int32_t readerSharing
PCSCLITE_SHARING_* sharing status.
This handles abstract system level calls.
int slot
Current Reader Slot.
uint32_t eventCounter
number of card events
union ReaderContext::@3 psFunctions
driver functions
This wraps the dynamic ifdhandler functions.
int * pMutex
Number of client to mutex.
#define SCARD_E_NOT_TRANSACTED
An attempt was made to end a non-existent transaction.
pthread_mutex_t handlesList_lock
lock for the above list
int SYS_USleep(int)
Makes the current process sleep for some microseconds.
char * library
Library Path.
#define PCSCLITE_SHARING_EXCLUSIVE_CONTEXT
Reader used in exclusive mode.
#define SCARD_F_UNKNOWN_ERROR
An internal error has been detected, but the source is unknown.
#define SCARD_E_NO_MEMORY
Not enough memory available to complete this command.
#define SCARD_E_READER_UNAVAILABLE
The specified reader is not currently available for use.
#define SCARD_RESET
Card was reset.
#define PCSCLITE_MAX_READERS_CONTEXTS
Maximum readers context (a slot is count as a reader)
int * pFeeds
Number of shared client to lib.
#define TAG_IFD_SLOTS_NUMBER
number of slots of the reader
int version
IFD Handler version number.
#define SCARD_W_RESET_CARD
The smart card has been reset, so any shared state information is invalid.
pthread_mutex_t * mMutex
Mutex for this connection.
static READER_STATE readerStates[PCSCLITE_MAX_READERS_CONTEXTS]
Area used to read status information about the readers.
This handles card insertion/removal events, updates ATR, protocol, and status information.
LONG IFDCloseIFD(READER_CONTEXT *rContext)
Close a communication channel to the IFD.
#define TAG_IFD_SLOT_THREAD_SAFE
support access to different slots of the reader
#define SCARD_W_REMOVED_CARD
The smart card has been removed, so further communication is not possible.
int powerState
auto power off state
#define SCARD_PROTOCOL_UNDEFINED
protocol not set
UCHAR cardAtr[MAX_ATR_SIZE]
ATR.
int SYS_RandomInt(int, int)
Generate a pseudo random number.
LONG SCARDHANDLE
hCard returned by SCardConnect()
LONG IFDOpenIFD(READER_CONTEXT *rContext)
Open a communication channel to the IFD.
int LockCount
number of recursive locks
#define TAG_IFD_POLLING_THREAD_WITH_TIMEOUT
driver uses a polling thread with a timeout parameter
LPVOID vHandle
Dlopen handle.
This keeps a list of defines for pcsc-lite.
#define TAG_IFD_SIMULTANEOUS_ACCESS
number of reader the driver can manage
#define SCARD_E_DUPLICATE_READER
The reader driver did not produce a unique reader name.
pthread_mutex_t reference_lock
reference mutex
uint32_t cardProtocol
SCARD_PROTOCOL_* value.
Define an exported public reader state structure so each application gets instant notification of cha...
#define SCARD_E_SHARING_VIOLATION
The smart card cannot be accessed because of other connections outstanding.
char * device
Device Name.
This keeps track of a list of currently available reader structures.
#define MAX_ATR_SIZE
Maximum ATR size.
char * pcDevicename
DEVICENAME.
#define SCARD_E_UNKNOWN_READER
The specified reader name is not recognized.
uint32_t readerState
SCARD_* bit field.
int reference
number of users of the structure
This provides a search API for hot pluggble devices.
pthread_mutex_t powerState_lock
powerState mutex
char * pcFriendlyname
FRIENDLYNAME.
#define SCARD_E_INVALID_HANDLE
The supplied handle was invalid.
#define IFD_SUCCESS
no error
#define SCARD_REMOVED
Card was removed.
SCARDHANDLE hCard
hCard for this connection
#define READER_NOT_INITIALIZED
Special value to indicate that power up has not yet happen This is used to auto start mode to wait un...