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))
246 Log1(PCSC_LOG_ERROR,
"Duplicate reader found.");
256 if (sReadersContexts[i]->vHandle == 0)
263 if (i == PCSCLITE_MAX_READERS_CONTEXTS)
270 parentNode = RFSetReaderName(sReadersContexts[dwContext], readerName,
275 sReadersContexts[dwContext]->
library = strdup(library);
276 sReadersContexts[dwContext]->
device = strdup(device);
277 sReadersContexts[dwContext]->
version = 0;
278 sReadersContexts[dwContext]->
port = port;
279 sReadersContexts[dwContext]->
mMutex = NULL;
280 sReadersContexts[dwContext]->
contexts = 0;
281 sReadersContexts[dwContext]->
pthThread = 0;
282 sReadersContexts[dwContext]->
hLockId = 0;
283 sReadersContexts[dwContext]->
LockCount = 0;
284 sReadersContexts[dwContext]->
vHandle = NULL;
285 sReadersContexts[dwContext]->
pFeeds = NULL;
286 sReadersContexts[dwContext]->
pMutex = NULL;
289 lrv = list_init(&sReadersContexts[dwContext]->handlesList);
292 Log2(PCSC_LOG_CRITICAL,
"list_init failed with return value: %d", lrv);
296 lrv = list_attributes_seeker(&sReadersContexts[dwContext]->handlesList,
297 RDR_CLIHANDLES_seeker);
300 Log2(PCSC_LOG_CRITICAL,
301 "list_attributes_seeker failed with return value: %d", lrv);
305 (void)pthread_mutex_init(&sReadersContexts[dwContext]->handlesList_lock,
308 (void)pthread_mutex_init(&sReadersContexts[dwContext]->powerState_lock,
313 (void)pthread_mutex_init(&sReadersContexts[dwContext]->reference_lock,
315 sReadersContexts[dwContext]->
reference = 1;
318 if (parentNode >= 0 && parentNode < PCSCLITE_MAX_READERS_CONTEXTS)
320 sReadersContexts[dwContext]->
pFeeds =
321 sReadersContexts[parentNode]->
pFeeds;
322 *(sReadersContexts[dwContext])->pFeeds += 1;
323 sReadersContexts[dwContext]->
vHandle =
324 sReadersContexts[parentNode]->
vHandle;
325 sReadersContexts[dwContext]->
mMutex =
326 sReadersContexts[parentNode]->
mMutex;
327 sReadersContexts[dwContext]->
pMutex =
328 sReadersContexts[parentNode]->
pMutex;
331 dwGetSize =
sizeof(ucThread);
335 if (rv ==
IFD_SUCCESS && dwGetSize == 1 && ucThread[0] == 1)
337 Log1(PCSC_LOG_INFO,
"Driver is thread safe");
338 sReadersContexts[dwContext]->
mMutex = NULL;
339 sReadersContexts[dwContext]->
pMutex = NULL;
342 *(sReadersContexts[dwContext])->pMutex += 1;
345 if (sReadersContexts[dwContext]->pFeeds == NULL)
347 sReadersContexts[dwContext]->
pFeeds = malloc(
sizeof(
int));
353 *(sReadersContexts[dwContext])->pFeeds = 1;
356 if (sReadersContexts[dwContext]->mMutex == 0)
358 sReadersContexts[dwContext]->
mMutex =
359 malloc(
sizeof(pthread_mutex_t));
360 (void)pthread_mutex_init(sReadersContexts[dwContext]->mMutex, NULL);
363 if (sReadersContexts[dwContext]->pMutex == NULL)
365 sReadersContexts[dwContext]->
pMutex = malloc(
sizeof(
int));
366 *(sReadersContexts[dwContext])->pMutex = 1;
369 dwNumReadersContexts += 1;
371 rv = RFInitializeReader(sReadersContexts[dwContext]);
375 Log2(PCSC_LOG_ERROR,
"%s init failed.", readerName);
376 (void)RFRemoveReader(readerName, port);
382 RESPONSECODE (*fct)(DWORD, int) = NULL;
384 dwGetSize =
sizeof(fct);
390 Log1(PCSC_LOG_INFO,
"Using the pcscd polling thread");
395 Log1(PCSC_LOG_INFO,
"Using the reader polling thread");
398 rv = EHSpawnEventHandler(sReadersContexts[dwContext]);
401 Log2(PCSC_LOG_ERROR,
"%s init failed.", readerName);
402 (void)RFRemoveReader(readerName, port);
408 dwGetSize =
sizeof(ucGetData);
412 if (rv !=
IFD_SUCCESS || dwGetSize != 1 || ucGetData[0] == 0)
417 if (rv ==
IFD_SUCCESS && dwGetSize == 1 && ucGetData[0] == 1)
427 for (j = 1; j < ucGetData[0]; j++)
429 char *tmpReader = NULL;
430 DWORD dwContextB = 0;
431 RESPONSECODE (*fct)(DWORD, int) = NULL;
436 if (sReadersContexts[i]->vHandle == 0)
443 if (i == PCSCLITE_MAX_READERS_CONTEXTS)
446 RFRemoveReader(readerName, port);
453 sReadersContexts[dwContext]->readerState->readerName,
455 snprintf(tmpReader + strlen(tmpReader) - 2, 3,
"%02X", j);
457 sReadersContexts[dwContextB]->
library =
458 sReadersContexts[dwContext]->
library;
459 sReadersContexts[dwContextB]->
device =
460 sReadersContexts[dwContext]->
device;
461 sReadersContexts[dwContextB]->
version =
462 sReadersContexts[dwContext]->
version;
463 sReadersContexts[dwContextB]->
port =
464 sReadersContexts[dwContext]->
port;
465 sReadersContexts[dwContextB]->
vHandle =
466 sReadersContexts[dwContext]->
vHandle;
467 sReadersContexts[dwContextB]->
mMutex =
468 sReadersContexts[dwContext]->
mMutex;
469 sReadersContexts[dwContextB]->
pMutex =
470 sReadersContexts[dwContext]->
pMutex;
471 sReadersContexts[dwContextB]->
slot =
472 sReadersContexts[dwContext]->
slot + j;
479 sReadersContexts[dwContextB]->
pFeeds =
480 sReadersContexts[dwContext]->
pFeeds;
483 *(sReadersContexts[dwContextB])->pFeeds += 1;
485 sReadersContexts[dwContextB]->
contexts = 0;
486 sReadersContexts[dwContextB]->
hLockId = 0;
487 sReadersContexts[dwContextB]->
LockCount = 0;
489 lrv = list_init(&sReadersContexts[dwContextB]->handlesList);
492 Log2(PCSC_LOG_CRITICAL,
"list_init failed with return value: %d", lrv);
496 lrv = list_attributes_seeker(&sReadersContexts[dwContextB]->handlesList,
497 RDR_CLIHANDLES_seeker);
500 Log2(PCSC_LOG_CRITICAL,
501 "list_attributes_seeker failed with return value: %d", lrv);
505 (void)pthread_mutex_init(&sReadersContexts[dwContextB]->handlesList_lock, NULL);
506 (void)pthread_mutex_init(&sReadersContexts[dwContextB]->powerState_lock,
511 (void)pthread_mutex_init(&sReadersContexts[dwContextB]->reference_lock,
513 sReadersContexts[dwContextB]->
reference = 1;
516 dwGetSize =
sizeof(ucThread);
520 if (rv ==
IFD_SUCCESS && dwGetSize == 1 && ucThread[0] == 1)
522 Log1(PCSC_LOG_INFO,
"Driver is slot thread safe");
524 sReadersContexts[dwContextB]->
library =
525 strdup(sReadersContexts[dwContext]->library);
526 sReadersContexts[dwContextB]->
device =
527 strdup(sReadersContexts[dwContext]->device);
528 sReadersContexts[dwContextB]->
mMutex =
529 malloc(
sizeof(pthread_mutex_t));
530 (void)pthread_mutex_init(sReadersContexts[dwContextB]->mMutex,
533 sReadersContexts[dwContextB]->
pMutex = malloc(
sizeof(
int));
534 *(sReadersContexts[dwContextB])->pMutex = 1;
537 *(sReadersContexts[dwContextB])->pMutex += 1;
539 dwNumReadersContexts += 1;
541 rv = RFInitializeReader(sReadersContexts[dwContextB]);
545 (void)RFRemoveReader(readerName, port);
550 dwGetSize =
sizeof(fct);
556 Log1(PCSC_LOG_INFO,
"Using the pcscd polling thread");
561 Log1(PCSC_LOG_INFO,
"Using the reader polling thread");
564 rv = EHSpawnEventHandler(sReadersContexts[dwContextB]);
567 Log2(PCSC_LOG_ERROR,
"%s init failed.", readerName);
568 (void)RFRemoveReader(readerName, port);
576 LONG RFRemoveReader(
const char *readerName,
int port)
578 char lpcStripReader[MAX_READERNAME];
585 if (readerName == NULL)
589 extend = getenv(
"PCSCLITE_FILTER_EXTEND_READER_NAMES");
591 extend_size = strlen(extend);
596 if (sReadersContexts[i]->vHandle != 0)
598 strncpy(lpcStripReader,
599 sReadersContexts[i]->readerState->readerName,
600 sizeof(lpcStripReader));
601 lpcStripReader[strlen(lpcStripReader) - 6 - extend_size] = 0;
604 if ((strncmp(readerName, lpcStripReader, MAX_READERNAME -
sizeof(
" 00 00")) == 0)
605 && (port == sReadersContexts[i]->port))
608 UNREF_READER(sReadersContexts[i])
622 if (sContext -> pthThread)
623 (void)EHDestroyEventHandler(sContext);
625 if ((NULL == sContext->
pMutex) || (NULL == sContext->
pFeeds))
628 "Trying to remove an already removed driver");
632 rv = RFUnInitializeReader(sContext);
639 if (0 == *sContext->
pMutex)
641 (void)pthread_mutex_destroy(sContext->
mMutex);
653 if (*sContext->
pFeeds == 0)
669 while (list_size(&sContext->handlesList) != 0)
674 currentHandle = list_get_at(&sContext->handlesList, 0);
675 lrv = list_delete_at(&sContext->handlesList, 0);
677 Log2(PCSC_LOG_CRITICAL,
678 "list_delete_at failed with return value: %d", lrv);
684 list_destroy(&sContext->handlesList);
685 dwNumReadersContexts -= 1;
694 LONG RFSetReaderName(
READER_CONTEXT * rContext,
const char *readerName,
695 const char *libraryName,
int port)
699 int currentDigit = -1;
700 int supportedChannels = 0;
703 const char *extend =
"";
707 usedDigits[i] = FALSE;
709 if (dwNumReadersContexts != 0)
713 if (sReadersContexts[i]->vHandle != 0)
715 if (strcmp(sReadersContexts[i]->library, libraryName) == 0)
721 valueLength =
sizeof(tagValue);
724 &valueLength, tagValue);
729 supportedChannels = tagValue[0];
731 "Support %d simultaneous readers", tagValue[0]);
734 supportedChannels = 1;
737 if ((((sReadersContexts[i]->port & 0xFFFF0000) ==
738 PCSCLITE_HP_BASE_PORT)
739 && (sReadersContexts[i]->port != port))
740 || (supportedChannels > 1))
756 currentDigit = strtol(reader + strlen(reader) - 5, NULL, 16);
759 usedDigits[currentDigit] = TRUE;
770 if (currentDigit != -1)
775 if (usedDigits[i] == FALSE)
779 if (i == PCSCLITE_MAX_READERS_CONTEXTS)
781 Log2(PCSC_LOG_ERROR,
"Max number of readers reached: %d", PCSCLITE_MAX_READERS_CONTEXTS);
785 if (i >= supportedChannels)
787 Log3(PCSC_LOG_ERROR,
"Driver %s does not support more than " 788 "%d reader(s). Maybe the driver should support " 789 "TAG_IFD_SIMULTANEOUS_ACCESS", libraryName, supportedChannels);
795 extend = getenv(
"PCSCLITE_FILTER_EXTEND_READER_NAMES");
802 readerName, extend, i);
805 rContext->
slot = i << 16;
810 LONG RFReaderInfo(
const char *readerName,
READER_CONTEXT ** sReader)
814 if (readerName == NULL)
819 if (sReadersContexts[i]->vHandle != 0)
821 if (strcmp(readerName,
822 sReadersContexts[i]->readerState->readerName) == 0)
825 REF_READER(sReadersContexts[i])
827 *sReader = sReadersContexts[i];
842 if (sReadersContexts[i]->vHandle != 0)
845 (void)pthread_mutex_lock(&sReadersContexts[i]->handlesList_lock);
846 currentHandle = list_seek(&sReadersContexts[i]->handlesList,
848 (void)pthread_mutex_unlock(&sReadersContexts[i]->handlesList_lock);
849 if (currentHandle != NULL)
852 REF_READER(sReadersContexts[i])
854 *sReader = sReadersContexts[i];
867 Log2(PCSC_LOG_INFO,
"Reusing already loaded driver for %s",
881 rv = DYN_GetAddress(rContext->
vHandle, &f,
"IFDHCreateChannelByName", TRUE);
885 rContext->
version = IFD_HVERSION_3_0;
889 rv = DYN_GetAddress(rContext->
vHandle, &f,
"IFDHCreateChannel", FALSE);
893 rContext->
version = IFD_HVERSION_2_0;
898 Log1(PCSC_LOG_CRITICAL,
"IFDHandler functions missing");
903 if (rContext->
version == IFD_HVERSION_2_0)
906 #define GET_ADDRESS_OPTIONALv2(s, code) \ 909 int rvl = DYN_GetAddress(rContext->vHandle, &f1, "IFDH" #s, FALSE); \ 910 if (SCARD_S_SUCCESS != rvl) \ 914 rContext->psFunctions.psFunctions_v2.pvf ## s = f1; \ 917 #define GET_ADDRESSv2(s) \ 918 GET_ADDRESS_OPTIONALv2(s, \ 919 Log1(PCSC_LOG_CRITICAL, "IFDHandler functions missing: " #s ); \ 922 Log1(PCSC_LOG_INFO,
"Loading IFD Handler 2.0");
924 GET_ADDRESSv2(CreateChannel)
925 GET_ADDRESSv2(CloseChannel)
926 GET_ADDRESSv2(GetCapabilities)
927 GET_ADDRESSv2(SetCapabilities)
928 GET_ADDRESSv2(PowerICC)
929 GET_ADDRESSv2(TransmitToICC)
930 GET_ADDRESSv2(ICCPresence)
931 GET_ADDRESS_OPTIONALv2(SetProtocolParameters, )
933 GET_ADDRESSv2(Control)
935 else if (rContext->version == IFD_HVERSION_3_0)
938 #define GET_ADDRESS_OPTIONALv3(s, code) \ 941 int rvl = DYN_GetAddress(rContext->vHandle, &f1, "IFDH" #s, FALSE); \ 942 if (SCARD_S_SUCCESS != rvl) \ 946 rContext->psFunctions.psFunctions_v3.pvf ## s = f1; \ 949 #define GET_ADDRESSv3(s) \ 950 GET_ADDRESS_OPTIONALv3(s, \ 951 Log1(PCSC_LOG_CRITICAL, "IFDHandler functions missing: " #s ); \ 954 Log1(PCSC_LOG_INFO,
"Loading IFD Handler 3.0");
956 GET_ADDRESSv2(CreateChannel)
957 GET_ADDRESSv2(CloseChannel)
958 GET_ADDRESSv2(GetCapabilities)
959 GET_ADDRESSv2(SetCapabilities)
960 GET_ADDRESSv2(PowerICC)
961 GET_ADDRESSv2(TransmitToICC)
962 GET_ADDRESSv2(ICCPresence)
963 GET_ADDRESS_OPTIONALv2(SetProtocolParameters, )
965 GET_ADDRESSv3(CreateChannelByName)
966 GET_ADDRESSv3(Control)
971 Log1(PCSC_LOG_CRITICAL,
"IFD Handler not 1.0/2.0 or 3.0");
989 if (*rContext->
pFeeds == 1)
991 Log1(PCSC_LOG_INFO,
"Unloading reader driver.");
992 (void)DYN_CloseLibrary(&rContext->
vHandle);
1012 (void)pthread_mutex_lock(&LockMutex);
1013 rv = RFCheckSharing(hCard, rContext);
1019 (void)pthread_mutex_unlock(&LockMutex);
1028 (void)pthread_mutex_lock(&LockMutex);
1029 rv = RFCheckSharing(hCard, rContext);
1052 (void)pthread_mutex_unlock(&LockMutex);
1061 (void)pthread_mutex_lock(&LockMutex);
1062 rv = RFCheckSharing(hCard, rContext);
1068 (void)pthread_mutex_unlock(&LockMutex);
1078 Log3(PCSC_LOG_INFO,
"Attempting startup of %s using %s",
1081 #ifndef PCSCLITE_STATIC_DRIVER 1083 rv = RFLoadReader(rContext);
1086 Log2(PCSC_LOG_ERROR,
"RFLoadReader failed: 0x%lX", rv);
1091 rv = RFBindFunctions(rContext);
1095 Log2(PCSC_LOG_ERROR,
"RFBindFunctions failed: 0x%lX", rv);
1096 (void)RFUnloadReader(rContext);
1101 rContext->
vHandle = RFInitializeReader;
1109 Log3(PCSC_LOG_CRITICAL,
"Open Port 0x%X Failed (%s)",
1113 rContext->
slot = -1;
1116 rContext->
slot = -1;
1129 Log2(PCSC_LOG_INFO,
"Attempting shutdown of %s.",
1133 if (rContext->
slot != -1)
1136 (void)RFUnBindFunctions(rContext);
1137 (void)RFUnloadReader(rContext);
1174 ret = RFReaderInfoById(randHandle, &dummy_reader);
1176 UNREF_READER(dummy_reader)
1193 int listLength, lrv;
1198 listLength = list_size(&rContext->handlesList);
1201 if (listLength >= maxReaderHandles)
1203 Log2(PCSC_LOG_CRITICAL,
1204 "Too many handles opened, exceeding configured max (%d)",
1211 if (NULL == newHandle)
1213 Log1(PCSC_LOG_CRITICAL,
"malloc failed");
1218 newHandle->
hCard = hCard;
1221 lrv = list_append(&rContext->handlesList, newHandle);
1225 Log2(PCSC_LOG_CRITICAL,
"list_append failed with return value: %d",
1241 currentHandle = list_seek(&rContext->handlesList, &hCard);
1242 if (NULL == currentHandle)
1244 Log2(PCSC_LOG_CRITICAL,
"list_seek failed to locate hCard=%lX", hCard);
1249 lrv = list_delete(&rContext->handlesList, currentHandle);
1251 Log2(PCSC_LOG_CRITICAL,
1252 "list_delete failed with return value: %d", lrv);
1254 free(currentHandle);
1263 LONG RFSetReaderEventState(
READER_CONTEXT * rContext, DWORD dwEvent)
1266 int list_index, listSize;
1270 listSize = list_size(&rContext->handlesList);
1272 for (list_index = 0; list_index < listSize; list_index++)
1274 currentHandle = list_get_at(&rContext->handlesList, list_index);
1275 if (NULL == currentHandle)
1277 Log2(PCSC_LOG_CRITICAL,
"list_get_at failed at index %d",
1302 currentHandle = list_seek(&rContext->handlesList, &hCard);
1304 if (NULL == currentHandle)
1307 Log2(PCSC_LOG_CRITICAL,
"list_seek failed for hCard 0x%lX", hCard);
1337 currentHandle = list_seek(&rContext->handlesList, &hCard);
1339 if (NULL == currentHandle)
1359 void RFCleanupReaders(
void)
1363 Log1(PCSC_LOG_INFO,
"entering cleaning function");
1366 if (sReadersContexts[i]->vHandle != 0)
1369 char lpcStripReader[MAX_READERNAME];
1371 Log2(PCSC_LOG_INFO,
"Stopping reader: %s",
1372 sReadersContexts[i]->readerState->readerName);
1374 strncpy(lpcStripReader,
1375 sReadersContexts[i]->readerState->readerName,
1376 sizeof(lpcStripReader));
1378 lpcStripReader[strlen(lpcStripReader) - 6] =
'\0';
1380 rv = RFRemoveReader(lpcStripReader, sReadersContexts[i]->port);
1383 Log2(PCSC_LOG_ERROR,
"RFRemoveReader error: 0x%08lX", rv);
1385 free(sReadersContexts[i]);
1403 void RFWaitForReaderInit(
void)
1405 int i, need_to_wait;
1409 need_to_wait = FALSE;
1413 if (sReadersContexts[i]->vHandle != NULL)
1417 == sReadersContexts[i]->readerState->cardAtrLength)
1419 Log2(PCSC_LOG_DEBUG,
"Waiting init for reader: %s",
1420 sReadersContexts[i]->readerState->readerName);
1421 need_to_wait = TRUE;
1428 }
while (need_to_wait);
1433 int RFStartSerialReaders(
const char *readerconf)
1439 ConfigFile = strdup(readerconf);
1441 rv = DBGetReaderListDir(readerconf, &reader_list);
1444 if (NULL == reader_list)
1451 (void)RFAddReader(reader_list[i].pcFriendlyname,
1452 reader_list[i].channelId,
1453 reader_list[i].pcLibpath, reader_list[i].pcDevicename);
1457 ConfigFileCRC += reader_list[i].pcFriendlyname[j];
1458 for (j=0; j<reader_list[i].
pcLibpath[j]; j++)
1459 ConfigFileCRC += reader_list[i].pcLibpath[j];
1461 ConfigFileCRC += reader_list[i].pcDevicename[j];
1464 free(reader_list[i].pcFriendlyname);
1465 free(reader_list[i].pcLibpath);
1466 free(reader_list[i].pcDevicename);
1473 void RFReCheckReaderConf(
void)
1478 (void)DBGetReaderListDir(ConfigFile, &reader_list);
1481 if (NULL == reader_list)
1491 crc += reader_list[i].pcFriendlyname[j];
1492 for (j=0; j<reader_list[i].
pcLibpath[j]; j++)
1493 crc += reader_list[i].pcLibpath[j];
1495 crc += reader_list[i].pcDevicename[j];
1499 if (crc != ConfigFileCRC)
1501 Log2(PCSC_LOG_CRITICAL,
1502 "configuration file: %s has been modified. Recheck canceled",
1510 char present = FALSE;
1512 Log2(PCSC_LOG_DEBUG,
"refresh reader: %s",
1513 reader_list[i].pcFriendlyname);
1518 if (sReadersContexts[r]->vHandle != 0)
1520 char lpcStripReader[MAX_READERNAME];
1524 strncpy(lpcStripReader,
1525 sReadersContexts[i]->readerState->readerName,
1526 sizeof(lpcStripReader));
1527 tmplen = strlen(lpcStripReader);
1528 lpcStripReader[tmplen - 6] = 0;
1530 if ((strcmp(reader_list[i].pcFriendlyname, lpcStripReader) == 0)
1531 && (reader_list[r].channelId == sReadersContexts[i]->port))
1542 Log2(PCSC_LOG_INFO,
"Reader %s disappeared",
1543 reader_list[i].pcFriendlyname);
1544 (void)RFRemoveReader(reader_list[i].pcFriendlyname,
1545 reader_list[r].channelId);
1554 (void)RFAddReader(reader_list[i].pcFriendlyname,
1555 reader_list[i].channelId, reader_list[i].pcLibpath,
1556 reader_list[i].pcDevicename);
1559 free(reader_list[i].pcFriendlyname);
1560 free(reader_list[i].pcLibpath);
1561 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.
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
LONG EHSignalEventToClients(void)
Sends an asynchronous event to any waiting client.
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...