47 #include <sys/types.h>
62 #include "configfile.h"
72 static int maxReaderHandles = PCSC_MAX_READER_HANDLES;
73 static DWORD dwNumReadersContexts = 0;
75 static char *ConfigFile = NULL;
76 static int ConfigFileCRC = 0;
78 static pthread_mutex_t LockMutex = PTHREAD_MUTEX_INITIALIZER;
80 #define IDENTITY_SHIFT 16
83 static int RDR_CLIHANDLES_seeker(
const void *el,
const void *key)
87 if ((el == NULL) || (key == NULL))
89 Log3(PCSC_LOG_CRITICAL,
90 "RDR_CLIHANDLES_seeker called with NULL pointer: el=%p, key=%p",
124 removeReader(sReader);
129 LONG RFAllocateReaderSpace(
unsigned int customMaxReaderHandles)
133 if (customMaxReaderHandles != 0)
134 maxReaderHandles = customMaxReaderHandles;
140 sReadersContexts[i]->
vHandle = NULL;
143 memset(readerStates[i].readerName, 0, MAX_READERNAME);
151 sReadersContexts[i]->
readerState = &readerStates[i];
155 return EHInitializeEventStructures();
158 LONG RFAddReader(
const char *readerNameLong,
int port,
const char *library,
161 DWORD dwContext = 0, dwGetSize;
162 UCHAR ucGetData[1], ucThread[1];
166 char *readerName = NULL;
168 if ((readerNameLong == NULL) || (library == NULL) || (device == NULL))
172 const char *ro_filter = getenv(
"PCSCLITE_FILTER_IGNORE_READER_NAMES");
178 filter = alloca(strlen(ro_filter)+1);
179 strcpy(filter, ro_filter);
184 next = strchr(filter,
':');
192 if (*filter && strstr(readerNameLong, filter))
195 "Reader name \"%s\" contains \"%s\": ignored",
196 readerNameLong, filter);
211 readerName = alloca(strlen(readerNameLong)+1);
212 strcpy(readerName, readerNameLong);
215 if (strlen(readerName) > MAX_READERNAME -
sizeof(
" 00 00"))
218 "Reader name too long: %zd chars instead of max %zd. Truncating!",
219 strlen(readerName), MAX_READERNAME -
sizeof(
" 00 00"));
220 readerName[MAX_READERNAME -
sizeof(
" 00 00")] =
'\0';
224 if (dwNumReadersContexts != 0)
228 if (sReadersContexts[i]->vHandle != 0)
230 char lpcStripReader[MAX_READERNAME];
234 strncpy(lpcStripReader,
235 sReadersContexts[i]->readerState->readerName,
236 sizeof(lpcStripReader));
237 tmplen = strlen(lpcStripReader);
238 lpcStripReader[tmplen - 6] = 0;
240 if ((strcmp(readerName, lpcStripReader) == 0) &&
241 (port == sReadersContexts[i]->port))
243 Log1(PCSC_LOG_ERROR,
"Duplicate reader found.");
253 if (sReadersContexts[i]->vHandle == 0)
260 if (i == PCSCLITE_MAX_READERS_CONTEXTS)
267 parentNode = RFSetReaderName(sReadersContexts[dwContext], readerName,
272 sReadersContexts[dwContext]->
library = strdup(library);
273 sReadersContexts[dwContext]->
device = strdup(device);
274 sReadersContexts[dwContext]->
version = 0;
275 sReadersContexts[dwContext]->
port = port;
276 sReadersContexts[dwContext]->
mMutex = NULL;
277 sReadersContexts[dwContext]->
contexts = 0;
278 sReadersContexts[dwContext]->
pthThread = 0;
279 sReadersContexts[dwContext]->
hLockId = 0;
280 sReadersContexts[dwContext]->
LockCount = 0;
281 sReadersContexts[dwContext]->
vHandle = NULL;
282 sReadersContexts[dwContext]->
pFeeds = NULL;
283 sReadersContexts[dwContext]->
pMutex = NULL;
286 lrv = list_init(&sReadersContexts[dwContext]->handlesList);
289 Log2(PCSC_LOG_CRITICAL,
"list_init failed with return value: %d", lrv);
293 lrv = list_attributes_seeker(&sReadersContexts[dwContext]->handlesList,
294 RDR_CLIHANDLES_seeker);
297 Log2(PCSC_LOG_CRITICAL,
298 "list_attributes_seeker failed with return value: %d", lrv);
302 (void)pthread_mutex_init(&sReadersContexts[dwContext]->handlesList_lock,
305 (void)pthread_mutex_init(&sReadersContexts[dwContext]->powerState_lock,
310 (void)pthread_mutex_init(&sReadersContexts[dwContext]->reference_lock,
312 sReadersContexts[dwContext]->
reference = 1;
315 if (parentNode >= 0 && parentNode < PCSCLITE_MAX_READERS_CONTEXTS)
317 sReadersContexts[dwContext]->
pFeeds =
318 sReadersContexts[parentNode]->
pFeeds;
319 *(sReadersContexts[dwContext])->pFeeds += 1;
320 sReadersContexts[dwContext]->
vHandle =
321 sReadersContexts[parentNode]->
vHandle;
322 sReadersContexts[dwContext]->
mMutex =
323 sReadersContexts[parentNode]->
mMutex;
324 sReadersContexts[dwContext]->
pMutex =
325 sReadersContexts[parentNode]->
pMutex;
328 dwGetSize =
sizeof(ucThread);
332 if (rv ==
IFD_SUCCESS && dwGetSize == 1 && ucThread[0] == 1)
334 Log1(PCSC_LOG_INFO,
"Driver is thread safe");
335 sReadersContexts[dwContext]->
mMutex = NULL;
336 sReadersContexts[dwContext]->
pMutex = NULL;
339 *(sReadersContexts[dwContext])->pMutex += 1;
342 if (sReadersContexts[dwContext]->pFeeds == NULL)
344 sReadersContexts[dwContext]->
pFeeds = malloc(
sizeof(
int));
350 *(sReadersContexts[dwContext])->pFeeds = 1;
353 if (sReadersContexts[dwContext]->mMutex == 0)
355 sReadersContexts[dwContext]->
mMutex =
356 malloc(
sizeof(pthread_mutex_t));
357 (void)pthread_mutex_init(sReadersContexts[dwContext]->mMutex, NULL);
360 if (sReadersContexts[dwContext]->pMutex == NULL)
362 sReadersContexts[dwContext]->
pMutex = malloc(
sizeof(
int));
363 *(sReadersContexts[dwContext])->pMutex = 1;
366 dwNumReadersContexts += 1;
368 rv = RFInitializeReader(sReadersContexts[dwContext]);
372 Log2(PCSC_LOG_ERROR,
"%s init failed.", readerName);
373 (void)RFRemoveReader(readerName, port);
379 RESPONSECODE (*fct)(DWORD, int) = NULL;
381 dwGetSize =
sizeof(fct);
387 Log1(PCSC_LOG_INFO,
"Using the pcscd polling thread");
392 Log1(PCSC_LOG_INFO,
"Using the reader polling thread");
395 rv = EHSpawnEventHandler(sReadersContexts[dwContext]);
398 Log2(PCSC_LOG_ERROR,
"%s init failed.", readerName);
399 (void)RFRemoveReader(readerName, port);
405 dwGetSize =
sizeof(ucGetData);
409 if (rv !=
IFD_SUCCESS || dwGetSize != 1 || ucGetData[0] == 0)
414 if (rv ==
IFD_SUCCESS && dwGetSize == 1 && ucGetData[0] == 1)
424 for (j = 1; j < ucGetData[0]; j++)
426 char *tmpReader = NULL;
427 DWORD dwContextB = 0;
428 RESPONSECODE (*fct)(DWORD, int) = NULL;
433 if (sReadersContexts[i]->vHandle == 0)
440 if (i == PCSCLITE_MAX_READERS_CONTEXTS)
443 RFRemoveReader(readerName, port);
450 sReadersContexts[dwContext]->readerState->readerName,
452 snprintf(tmpReader + strlen(tmpReader) - 2, 3,
"%02X", j);
454 sReadersContexts[dwContextB]->
library =
455 sReadersContexts[dwContext]->
library;
456 sReadersContexts[dwContextB]->
device =
457 sReadersContexts[dwContext]->
device;
458 sReadersContexts[dwContextB]->
version =
459 sReadersContexts[dwContext]->
version;
460 sReadersContexts[dwContextB]->
port =
461 sReadersContexts[dwContext]->
port;
462 sReadersContexts[dwContextB]->
vHandle =
463 sReadersContexts[dwContext]->
vHandle;
464 sReadersContexts[dwContextB]->
mMutex =
465 sReadersContexts[dwContext]->
mMutex;
466 sReadersContexts[dwContextB]->
pMutex =
467 sReadersContexts[dwContext]->
pMutex;
468 sReadersContexts[dwContextB]->
slot =
469 sReadersContexts[dwContext]->
slot + j;
476 sReadersContexts[dwContextB]->
pFeeds =
477 sReadersContexts[dwContext]->
pFeeds;
480 *(sReadersContexts[dwContextB])->pFeeds += 1;
482 sReadersContexts[dwContextB]->
contexts = 0;
483 sReadersContexts[dwContextB]->
hLockId = 0;
484 sReadersContexts[dwContextB]->
LockCount = 0;
486 lrv = list_init(&sReadersContexts[dwContextB]->handlesList);
489 Log2(PCSC_LOG_CRITICAL,
"list_init failed with return value: %d", lrv);
493 lrv = list_attributes_seeker(&sReadersContexts[dwContextB]->handlesList,
494 RDR_CLIHANDLES_seeker);
497 Log2(PCSC_LOG_CRITICAL,
498 "list_attributes_seeker failed with return value: %d", lrv);
502 (void)pthread_mutex_init(&sReadersContexts[dwContextB]->handlesList_lock, NULL);
503 (void)pthread_mutex_init(&sReadersContexts[dwContextB]->powerState_lock,
508 (void)pthread_mutex_init(&sReadersContexts[dwContextB]->reference_lock,
510 sReadersContexts[dwContextB]->
reference = 1;
513 dwGetSize =
sizeof(ucThread);
517 if (rv ==
IFD_SUCCESS && dwGetSize == 1 && ucThread[0] == 1)
519 Log1(PCSC_LOG_INFO,
"Driver is slot thread safe");
521 sReadersContexts[dwContextB]->
library =
522 strdup(sReadersContexts[dwContext]->library);
523 sReadersContexts[dwContextB]->
device =
524 strdup(sReadersContexts[dwContext]->device);
525 sReadersContexts[dwContextB]->
mMutex =
526 malloc(
sizeof(pthread_mutex_t));
527 (void)pthread_mutex_init(sReadersContexts[dwContextB]->mMutex,
530 sReadersContexts[dwContextB]->
pMutex = malloc(
sizeof(
int));
531 *(sReadersContexts[dwContextB])->pMutex = 1;
534 *(sReadersContexts[dwContextB])->pMutex += 1;
536 dwNumReadersContexts += 1;
538 rv = RFInitializeReader(sReadersContexts[dwContextB]);
542 (void)RFRemoveReader(readerName, port);
547 dwGetSize =
sizeof(fct);
553 Log1(PCSC_LOG_INFO,
"Using the pcscd polling thread");
558 Log1(PCSC_LOG_INFO,
"Using the reader polling thread");
561 rv = EHSpawnEventHandler(sReadersContexts[dwContextB]);
564 Log2(PCSC_LOG_ERROR,
"%s init failed.", readerName);
565 (void)RFRemoveReader(readerName, port);
573 LONG RFRemoveReader(
const char *readerName,
int port)
575 char lpcStripReader[MAX_READERNAME];
582 if (readerName == NULL)
586 extend = getenv(
"PCSCLITE_FILTER_EXTEND_READER_NAMES");
588 extend_size = strlen(extend);
593 if (sReadersContexts[i]->vHandle != 0)
595 strncpy(lpcStripReader,
596 sReadersContexts[i]->readerState->readerName,
597 sizeof(lpcStripReader));
598 lpcStripReader[strlen(lpcStripReader) - 6 - extend_size] = 0;
601 if ((strncmp(readerName, lpcStripReader, MAX_READERNAME -
sizeof(
" 00 00")) == 0)
602 && (port == sReadersContexts[i]->port))
605 UNREF_READER(sReadersContexts[i])
619 if (sContext -> pthThread)
620 (void)EHDestroyEventHandler(sContext);
622 if ((NULL == sContext->
pMutex) || (NULL == sContext->
pFeeds))
625 "Trying to remove an already removed driver");
629 rv = RFUnInitializeReader(sContext);
636 if (0 == *sContext->
pMutex)
638 (void)pthread_mutex_destroy(sContext->
mMutex);
650 if (*sContext->
pFeeds == 0)
666 while (list_size(&sContext->handlesList) != 0)
671 currentHandle = list_get_at(&sContext->handlesList, 0);
672 lrv = list_delete_at(&sContext->handlesList, 0);
674 Log2(PCSC_LOG_CRITICAL,
675 "list_delete_at failed with return value: %d", lrv);
681 list_destroy(&sContext->handlesList);
682 dwNumReadersContexts -= 1;
691 LONG RFSetReaderName(
READER_CONTEXT * rContext,
const char *readerName,
692 const char *libraryName,
int port)
696 int currentDigit = -1;
697 int supportedChannels = 0;
700 const char *extend =
"";
704 usedDigits[i] = FALSE;
706 if (dwNumReadersContexts != 0)
710 if (sReadersContexts[i]->vHandle != 0)
712 if (strcmp(sReadersContexts[i]->library, libraryName) == 0)
718 valueLength =
sizeof(tagValue);
721 &valueLength, tagValue);
726 supportedChannels = tagValue[0];
728 "Support %d simultaneous readers", tagValue[0]);
731 supportedChannels = 1;
734 if ((((sReadersContexts[i]->port & 0xFFFF0000) ==
735 PCSCLITE_HP_BASE_PORT)
736 && (sReadersContexts[i]->port != port))
737 || (supportedChannels > 1))
753 currentDigit = strtol(reader + strlen(reader) - 5, NULL, 16);
756 usedDigits[currentDigit] = TRUE;
767 if (currentDigit != -1)
772 if (usedDigits[i] == FALSE)
776 if (i == PCSCLITE_MAX_READERS_CONTEXTS)
778 Log2(PCSC_LOG_ERROR,
"Max number of readers reached: %d", PCSCLITE_MAX_READERS_CONTEXTS);
782 if (i >= supportedChannels)
784 Log3(PCSC_LOG_ERROR,
"Driver %s does not support more than "
785 "%d reader(s). Maybe the driver should support "
786 "TAG_IFD_SIMULTANEOUS_ACCESS", libraryName, supportedChannels);
792 extend = getenv(
"PCSCLITE_FILTER_EXTEND_READER_NAMES");
799 readerName, extend, i);
802 rContext->
slot = i << 16;
807 LONG RFReaderInfo(
const char *readerName,
READER_CONTEXT ** sReader)
811 if (readerName == NULL)
816 if (sReadersContexts[i]->vHandle != 0)
818 if (strcmp(readerName,
819 sReadersContexts[i]->readerState->readerName) == 0)
822 REF_READER(sReadersContexts[i])
824 *sReader = sReadersContexts[i];
839 if (sReadersContexts[i]->vHandle != 0)
842 (void)pthread_mutex_lock(&sReadersContexts[i]->handlesList_lock);
843 currentHandle = list_seek(&sReadersContexts[i]->handlesList,
845 (void)pthread_mutex_unlock(&sReadersContexts[i]->handlesList_lock);
846 if (currentHandle != NULL)
849 REF_READER(sReadersContexts[i])
851 *sReader = sReadersContexts[i];
864 Log2(PCSC_LOG_INFO,
"Reusing already loaded driver for %s",
878 rv = DYN_GetAddress(rContext->
vHandle, &f,
"IFDHCreateChannelByName", TRUE);
882 rContext->
version = IFD_HVERSION_3_0;
886 rv = DYN_GetAddress(rContext->
vHandle, &f,
"IFDHCreateChannel", FALSE);
890 rContext->
version = IFD_HVERSION_2_0;
895 Log1(PCSC_LOG_CRITICAL,
"IFDHandler functions missing");
900 if (rContext->
version == IFD_HVERSION_2_0)
903 #define GET_ADDRESS_OPTIONALv2(s, code) \
906 int rvl = DYN_GetAddress(rContext->vHandle, &f1, "IFDH" #s, FALSE); \
907 if (SCARD_S_SUCCESS != rvl) \
911 rContext->psFunctions.psFunctions_v2.pvf ## s = f1; \
914 #define GET_ADDRESSv2(s) \
915 GET_ADDRESS_OPTIONALv2(s, \
916 Log1(PCSC_LOG_CRITICAL, "IFDHandler functions missing: " #s ); \
919 Log1(PCSC_LOG_INFO,
"Loading IFD Handler 2.0");
921 GET_ADDRESSv2(CreateChannel)
922 GET_ADDRESSv2(CloseChannel)
923 GET_ADDRESSv2(GetCapabilities)
924 GET_ADDRESSv2(SetCapabilities)
925 GET_ADDRESSv2(PowerICC)
926 GET_ADDRESSv2(TransmitToICC)
927 GET_ADDRESSv2(ICCPresence)
928 GET_ADDRESS_OPTIONALv2(SetProtocolParameters, )
930 GET_ADDRESSv2(Control)
932 else if (rContext->version == IFD_HVERSION_3_0)
935 #define GET_ADDRESS_OPTIONALv3(s, code) \
938 int rvl = DYN_GetAddress(rContext->vHandle, &f1, "IFDH" #s, FALSE); \
939 if (SCARD_S_SUCCESS != rvl) \
943 rContext->psFunctions.psFunctions_v3.pvf ## s = f1; \
946 #define GET_ADDRESSv3(s) \
947 GET_ADDRESS_OPTIONALv3(s, \
948 Log1(PCSC_LOG_CRITICAL, "IFDHandler functions missing: " #s ); \
951 Log1(PCSC_LOG_INFO,
"Loading IFD Handler 3.0");
953 GET_ADDRESSv2(CreateChannel)
954 GET_ADDRESSv2(CloseChannel)
955 GET_ADDRESSv2(GetCapabilities)
956 GET_ADDRESSv2(SetCapabilities)
957 GET_ADDRESSv2(PowerICC)
958 GET_ADDRESSv2(TransmitToICC)
959 GET_ADDRESSv2(ICCPresence)
960 GET_ADDRESS_OPTIONALv2(SetProtocolParameters, )
962 GET_ADDRESSv3(CreateChannelByName)
963 GET_ADDRESSv3(Control)
968 Log1(PCSC_LOG_CRITICAL,
"IFD Handler not 1.0/2.0 or 3.0");
986 if (*rContext->
pFeeds == 1)
988 Log1(PCSC_LOG_INFO,
"Unloading reader driver.");
989 (void)DYN_CloseLibrary(&rContext->
vHandle);
1009 (void)pthread_mutex_lock(&LockMutex);
1010 rv = RFCheckSharing(hCard, rContext);
1016 (void)pthread_mutex_unlock(&LockMutex);
1025 (void)pthread_mutex_lock(&LockMutex);
1026 rv = RFCheckSharing(hCard, rContext);
1039 (void)pthread_mutex_unlock(&LockMutex);
1048 (void)pthread_mutex_lock(&LockMutex);
1049 rv = RFCheckSharing(hCard, rContext);
1055 (void)pthread_mutex_unlock(&LockMutex);
1065 Log3(PCSC_LOG_INFO,
"Attempting startup of %s using %s",
1068 #ifndef PCSCLITE_STATIC_DRIVER
1070 rv = RFLoadReader(rContext);
1073 Log2(PCSC_LOG_ERROR,
"RFLoadReader failed: 0x%lX", rv);
1078 rv = RFBindFunctions(rContext);
1082 Log2(PCSC_LOG_ERROR,
"RFBindFunctions failed: 0x%lX", rv);
1083 (void)RFUnloadReader(rContext);
1088 rContext->
vHandle = RFInitializeReader;
1096 Log3(PCSC_LOG_CRITICAL,
"Open Port 0x%X Failed (%s)",
1100 rContext->
slot = -1;
1103 rContext->
slot = -1;
1116 Log2(PCSC_LOG_INFO,
"Attempting shutdown of %s.",
1120 if (rContext->
slot != -1)
1123 (void)RFUnBindFunctions(rContext);
1124 (void)RFUnloadReader(rContext);
1158 randHandle = SYS_RandomInt(0, -1);
1161 ret = RFReaderInfoById(randHandle, &dummy_reader);
1163 UNREF_READER(dummy_reader)
1180 int listLength, lrv;
1185 listLength = list_size(&rContext->handlesList);
1188 if (listLength >= maxReaderHandles)
1190 Log2(PCSC_LOG_CRITICAL,
1191 "Too many handles opened, exceeding configured max (%d)",
1198 if (NULL == newHandle)
1200 Log1(PCSC_LOG_CRITICAL,
"malloc failed");
1205 newHandle->
hCard = hCard;
1208 lrv = list_append(&rContext->handlesList, newHandle);
1212 Log2(PCSC_LOG_CRITICAL,
"list_append failed with return value: %d",
1228 currentHandle = list_seek(&rContext->handlesList, &hCard);
1229 if (NULL == currentHandle)
1231 Log2(PCSC_LOG_CRITICAL,
"list_seek failed to locate hCard=%lX", hCard);
1236 lrv = list_delete(&rContext->handlesList, currentHandle);
1238 Log2(PCSC_LOG_CRITICAL,
1239 "list_delete failed with return value: %d", lrv);
1241 free(currentHandle);
1250 LONG RFSetReaderEventState(
READER_CONTEXT * rContext, DWORD dwEvent)
1253 int list_index, listSize;
1257 listSize = list_size(&rContext->handlesList);
1259 for (list_index = 0; list_index < listSize; list_index++)
1261 currentHandle = list_get_at(&rContext->handlesList, list_index);
1262 if (NULL == currentHandle)
1264 Log2(PCSC_LOG_CRITICAL,
"list_get_at failed at index %d",
1289 currentHandle = list_seek(&rContext->handlesList, &hCard);
1291 if (NULL == currentHandle)
1294 Log2(PCSC_LOG_CRITICAL,
"list_seek failed for hCard 0x%lX", hCard);
1324 currentHandle = list_seek(&rContext->handlesList, &hCard);
1326 if (NULL == currentHandle)
1346 void RFCleanupReaders(
void)
1350 Log1(PCSC_LOG_INFO,
"entering cleaning function");
1353 if (sReadersContexts[i]->vHandle != 0)
1356 char lpcStripReader[MAX_READERNAME];
1358 Log2(PCSC_LOG_INFO,
"Stopping reader: %s",
1359 sReadersContexts[i]->readerState->readerName);
1361 strncpy(lpcStripReader,
1362 sReadersContexts[i]->readerState->readerName,
1363 sizeof(lpcStripReader));
1365 lpcStripReader[strlen(lpcStripReader) - 6] =
'\0';
1367 rv = RFRemoveReader(lpcStripReader, sReadersContexts[i]->port);
1370 Log2(PCSC_LOG_ERROR,
"RFRemoveReader error: 0x%08lX", rv);
1372 free(sReadersContexts[i]);
1390 void RFWaitForReaderInit(
void)
1392 int i, need_to_wait;
1396 need_to_wait = FALSE;
1400 if (sReadersContexts[i]->vHandle != NULL)
1404 == sReadersContexts[i]->readerState->cardAtrLength)
1406 Log2(PCSC_LOG_DEBUG,
"Waiting init for reader: %s",
1407 sReadersContexts[i]->readerState->readerName);
1408 need_to_wait = TRUE;
1415 }
while (need_to_wait);
1420 int RFStartSerialReaders(
const char *readerconf)
1426 ConfigFile = strdup(readerconf);
1428 rv = DBGetReaderListDir(readerconf, &reader_list);
1431 if (NULL == reader_list)
1438 (void)RFAddReader(reader_list[i].pcFriendlyname,
1439 reader_list[i].channelId,
1440 reader_list[i].pcLibpath, reader_list[i].pcDevicename);
1444 ConfigFileCRC += reader_list[i].pcFriendlyname[j];
1445 for (j=0; j<reader_list[i].
pcLibpath[j]; j++)
1446 ConfigFileCRC += reader_list[i].pcLibpath[j];
1448 ConfigFileCRC += reader_list[i].pcDevicename[j];
1451 free(reader_list[i].pcFriendlyname);
1452 free(reader_list[i].pcLibpath);
1453 free(reader_list[i].pcDevicename);
1460 void RFReCheckReaderConf(
void)
1465 (void)DBGetReaderListDir(ConfigFile, &reader_list);
1468 if (NULL == reader_list)
1478 crc += reader_list[i].pcFriendlyname[j];
1479 for (j=0; j<reader_list[i].
pcLibpath[j]; j++)
1480 crc += reader_list[i].pcLibpath[j];
1482 crc += reader_list[i].pcDevicename[j];
1486 if (crc != ConfigFileCRC)
1488 Log2(PCSC_LOG_CRITICAL,
1489 "configuration file: %s has been modified. Recheck canceled",
1497 char present = FALSE;
1499 Log2(PCSC_LOG_DEBUG,
"refresh reader: %s",
1500 reader_list[i].pcFriendlyname);
1505 if (sReadersContexts[r]->vHandle != 0)
1507 char lpcStripReader[MAX_READERNAME];
1511 strncpy(lpcStripReader,
1512 sReadersContexts[i]->readerState->readerName,
1513 sizeof(lpcStripReader));
1514 tmplen = strlen(lpcStripReader);
1515 lpcStripReader[tmplen - 6] = 0;
1517 if ((strcmp(reader_list[i].pcFriendlyname, lpcStripReader) == 0)
1518 && (reader_list[r].channelId == sReadersContexts[i]->port))
1529 Log2(PCSC_LOG_INFO,
"Reader %s disappeared",
1530 reader_list[i].pcFriendlyname);
1531 (void)RFRemoveReader(reader_list[i].pcFriendlyname,
1532 reader_list[r].channelId);
1541 (void)RFAddReader(reader_list[i].pcFriendlyname,
1542 reader_list[i].channelId, reader_list[i].pcLibpath,
1543 reader_list[i].pcDevicename);
1546 free(reader_list[i].pcFriendlyname);
1547 free(reader_list[i].pcLibpath);
1548 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 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.
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...