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;
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)
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;
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 int nbSlots = ucGetData[0];
414 if (rv !=
IFD_SUCCESS || dwGetSize != 1 || nbSlots == 0)
429 for (j = 1; j < nbSlots; j++)
431 char *tmpReader = NULL;
432 DWORD dwContextB = 0;
433 RESPONSECODE (*fct)(DWORD, int) = NULL;
438 if (sReadersContexts[i]->vHandle == 0)
448 RFRemoveReader(readerName, port);
455 sReadersContexts[dwContext]->readerState->readerName,
456 sizeof(sReadersContexts[dwContextB]->readerState->readerName));
457 snprintf(tmpReader + strlen(tmpReader) - 2, 3,
"%02X", j);
459 sReadersContexts[dwContextB]->
library =
460 sReadersContexts[dwContext]->
library;
461 sReadersContexts[dwContextB]->
device =
462 sReadersContexts[dwContext]->
device;
463 sReadersContexts[dwContextB]->
version =
464 sReadersContexts[dwContext]->
version;
465 sReadersContexts[dwContextB]->
port =
466 sReadersContexts[dwContext]->
port;
467 sReadersContexts[dwContextB]->
vHandle =
468 sReadersContexts[dwContext]->
vHandle;
469 sReadersContexts[dwContextB]->
mMutex =
470 sReadersContexts[dwContext]->
mMutex;
471 sReadersContexts[dwContextB]->
pMutex =
472 sReadersContexts[dwContext]->
pMutex;
473 sReadersContexts[dwContextB]->
slot =
474 sReadersContexts[dwContext]->
slot + j;
481 sReadersContexts[dwContextB]->
pFeeds =
482 sReadersContexts[dwContext]->
pFeeds;
485 *(sReadersContexts[dwContextB])->pFeeds += 1;
487 sReadersContexts[dwContextB]->
contexts = 0;
488 sReadersContexts[dwContextB]->
hLockId = 0;
489 sReadersContexts[dwContextB]->
LockCount = 0;
491 lrv = list_init(&sReadersContexts[dwContextB]->handlesList);
494 Log2(PCSC_LOG_CRITICAL,
"list_init failed with return value: %d", lrv);
498 lrv = list_attributes_seeker(&sReadersContexts[dwContextB]->handlesList,
499 RDR_CLIHANDLES_seeker);
502 Log2(PCSC_LOG_CRITICAL,
503 "list_attributes_seeker failed with return value: %d", lrv);
507 (void)pthread_mutex_init(&sReadersContexts[dwContextB]->handlesList_lock, NULL);
508 (void)pthread_mutex_init(&sReadersContexts[dwContextB]->powerState_lock,
513 (void)pthread_mutex_init(&sReadersContexts[dwContextB]->reference_lock,
515 sReadersContexts[dwContextB]->
reference = 1;
518 dwGetSize =
sizeof(ucThread);
522 if (rv ==
IFD_SUCCESS && dwGetSize == 1 && ucThread[0] == 1)
524 Log1(PCSC_LOG_INFO,
"Driver is slot thread safe");
526 sReadersContexts[dwContextB]->
library =
527 strdup(sReadersContexts[dwContext]->library);
528 sReadersContexts[dwContextB]->
device =
529 strdup(sReadersContexts[dwContext]->device);
530 sReadersContexts[dwContextB]->
mMutex =
531 malloc(
sizeof(pthread_mutex_t));
532 (void)pthread_mutex_init(sReadersContexts[dwContextB]->mMutex,
535 sReadersContexts[dwContextB]->
pMutex = malloc(
sizeof(
int));
536 *(sReadersContexts[dwContextB])->pMutex = 1;
539 *(sReadersContexts[dwContextB])->pMutex += 1;
541 dwNumReadersContexts += 1;
543 rv = RFInitializeReader(sReadersContexts[dwContextB]);
547 (void)RFRemoveReader(readerName, port);
552 dwGetSize =
sizeof(fct);
558 Log1(PCSC_LOG_INFO,
"Using the pcscd polling thread");
563 Log1(PCSC_LOG_INFO,
"Using the reader polling thread");
566 rv = EHSpawnEventHandler(sReadersContexts[dwContextB]);
569 Log2(PCSC_LOG_ERROR,
"%s init failed.", readerName);
570 (void)RFRemoveReader(readerName, port);
578 LONG RFRemoveReader(
const char *readerName,
int port)
580 char lpcStripReader[MAX_READERNAME];
587 if (readerName == NULL)
591 extend = getenv(
"PCSCLITE_FILTER_EXTEND_READER_NAMES");
593 extend_size = strlen(extend);
598 if (sReadersContexts[i]->vHandle != 0)
600 strncpy(lpcStripReader,
601 sReadersContexts[i]->readerState->readerName,
602 sizeof(lpcStripReader));
603 lpcStripReader[strlen(lpcStripReader) - 6 - extend_size] = 0;
606 if ((strncmp(readerName, lpcStripReader, MAX_READERNAME -
sizeof(
" 00 00")) == 0)
607 && (port == sReadersContexts[i]->port))
610 UNREF_READER(sReadersContexts[i])
621 if (sContext -> pthThread)
622 EHDestroyEventHandler(sContext);
624 if ((NULL == sContext->
pMutex) || (NULL == sContext->
pFeeds))
627 "Trying to remove an already removed driver");
631 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;
690 LONG RFSetReaderName(
READER_CONTEXT * rContext,
const char *readerName,
691 const char *libraryName,
int port)
695 int currentDigit = -1;
696 int supportedChannels = 0;
699 const char *extend =
"";
703 usedDigits[i] = FALSE;
705 if (dwNumReadersContexts != 0)
709 if (sReadersContexts[i]->vHandle != 0)
711 if (strcmp(sReadersContexts[i]->library, libraryName) == 0)
717 valueLength =
sizeof(tagValue);
720 &valueLength, tagValue);
725 supportedChannels = tagValue[0];
727 "Support %d simultaneous readers", tagValue[0]);
730 supportedChannels = 1;
733 if ((((sReadersContexts[i]->port & 0xFFFF0000) ==
734 PCSCLITE_HP_BASE_PORT)
735 && (sReadersContexts[i]->port != port))
736 || (supportedChannels > 1))
752 currentDigit = strtol(reader + strlen(reader) - 5, NULL, 16);
755 usedDigits[currentDigit] = TRUE;
766 if (currentDigit != -1)
771 if (usedDigits[i] == FALSE)
781 if (i >= supportedChannels)
783 Log3(PCSC_LOG_ERROR,
"Driver %s does not support more than " 784 "%d reader(s). Maybe the driver should support " 785 "TAG_IFD_SIMULTANEOUS_ACCESS", libraryName, supportedChannels);
791 extend = getenv(
"PCSCLITE_FILTER_EXTEND_READER_NAMES");
798 readerName, extend, i);
801 rContext->
slot = i << 16;
806 LONG RFReaderInfo(
const char *readerName,
READER_CONTEXT ** sReader)
810 if (readerName == NULL)
815 if (sReadersContexts[i]->vHandle != 0)
817 if (strcmp(readerName,
818 sReadersContexts[i]->readerState->readerName) == 0)
821 REF_READER(sReadersContexts[i])
823 *sReader = sReadersContexts[i];
838 if (sReadersContexts[i]->vHandle != 0)
841 (void)pthread_mutex_lock(&sReadersContexts[i]->handlesList_lock);
842 currentHandle = list_seek(&sReadersContexts[i]->handlesList,
844 (void)pthread_mutex_unlock(&sReadersContexts[i]->handlesList_lock);
845 if (currentHandle != NULL)
848 REF_READER(sReadersContexts[i])
850 *sReader = sReadersContexts[i];
863 Log2(PCSC_LOG_INFO,
"Reusing already loaded driver for %s",
877 rv = DYN_GetAddress(rContext->
vHandle, &f,
"IFDHCreateChannelByName", TRUE);
881 rContext->
version = IFD_HVERSION_3_0;
885 rv = DYN_GetAddress(rContext->
vHandle, &f,
"IFDHCreateChannel", FALSE);
889 rContext->
version = IFD_HVERSION_2_0;
894 Log1(PCSC_LOG_CRITICAL,
"IFDHandler functions missing");
899 if (rContext->
version == IFD_HVERSION_2_0)
902 #define GET_ADDRESS_OPTIONALv2(s, code) \ 905 int rvl = DYN_GetAddress(rContext->vHandle, &f1, "IFDH" #s, FALSE); \ 906 if (SCARD_S_SUCCESS != rvl) \ 910 rContext->psFunctions.psFunctions_v2.pvf ## s = f1; \ 913 #define GET_ADDRESSv2(s) \ 914 GET_ADDRESS_OPTIONALv2(s, \ 915 Log1(PCSC_LOG_CRITICAL, "IFDHandler functions missing: " #s ); \ 918 Log1(PCSC_LOG_INFO,
"Loading IFD Handler 2.0");
920 GET_ADDRESSv2(CreateChannel)
921 GET_ADDRESSv2(CloseChannel)
922 GET_ADDRESSv2(GetCapabilities)
923 GET_ADDRESSv2(SetCapabilities)
924 GET_ADDRESSv2(PowerICC)
925 GET_ADDRESSv2(TransmitToICC)
926 GET_ADDRESSv2(ICCPresence)
927 GET_ADDRESS_OPTIONALv2(SetProtocolParameters, )
929 GET_ADDRESSv2(Control)
931 else if (rContext->version == IFD_HVERSION_3_0)
934 #define GET_ADDRESS_OPTIONALv3(s, code) \ 937 int rvl = DYN_GetAddress(rContext->vHandle, &f1, "IFDH" #s, FALSE); \ 938 if (SCARD_S_SUCCESS != rvl) \ 942 rContext->psFunctions.psFunctions_v3.pvf ## s = f1; \ 945 #define GET_ADDRESSv3(s) \ 946 GET_ADDRESS_OPTIONALv3(s, \ 947 Log1(PCSC_LOG_CRITICAL, "IFDHandler functions missing: " #s ); \ 950 Log1(PCSC_LOG_INFO,
"Loading IFD Handler 3.0");
952 GET_ADDRESSv2(CreateChannel)
953 GET_ADDRESSv2(CloseChannel)
954 GET_ADDRESSv2(GetCapabilities)
955 GET_ADDRESSv2(SetCapabilities)
956 GET_ADDRESSv2(PowerICC)
957 GET_ADDRESSv2(TransmitToICC)
958 GET_ADDRESSv2(ICCPresence)
959 GET_ADDRESS_OPTIONALv2(SetProtocolParameters, )
961 GET_ADDRESSv3(CreateChannelByName)
962 GET_ADDRESSv3(Control)
967 Log1(PCSC_LOG_CRITICAL,
"IFD Handler not 1.0/2.0 or 3.0");
985 if (*rContext->
pFeeds == 1)
987 Log1(PCSC_LOG_INFO,
"Unloading reader driver.");
988 (void)DYN_CloseLibrary(&rContext->
vHandle);
1008 (void)pthread_mutex_lock(&LockMutex);
1009 rv = RFCheckSharing(hCard, rContext);
1015 (void)pthread_mutex_unlock(&LockMutex);
1024 (void)pthread_mutex_lock(&LockMutex);
1025 rv = RFCheckSharing(hCard, rContext);
1048 (void)pthread_mutex_unlock(&LockMutex);
1057 (void)pthread_mutex_lock(&LockMutex);
1058 rv = RFCheckSharing(hCard, rContext);
1064 (void)pthread_mutex_unlock(&LockMutex);
1074 Log3(PCSC_LOG_INFO,
"Attempting startup of %s using %s",
1077 #ifndef PCSCLITE_STATIC_DRIVER 1079 rv = RFLoadReader(rContext);
1082 Log2(PCSC_LOG_ERROR,
"RFLoadReader failed: 0x%lX", rv);
1087 rv = RFBindFunctions(rContext);
1091 Log2(PCSC_LOG_ERROR,
"RFBindFunctions failed: 0x%lX", rv);
1092 (void)RFUnloadReader(rContext);
1097 rContext->
vHandle = RFInitializeReader;
1105 Log3(PCSC_LOG_CRITICAL,
"Open Port 0x%X Failed (%s)",
1109 rContext->
slot = -1;
1112 rContext->
slot = -1;
1125 Log2(PCSC_LOG_INFO,
"Attempting shutdown of %s.",
1129 if (rContext->
slot != -1)
1132 (void)RFUnBindFunctions(rContext);
1133 (void)RFUnloadReader(rContext);
1170 ret = RFReaderInfoById(randHandle, &dummy_reader);
1172 UNREF_READER(dummy_reader)
1183 int listLength, lrv;
1188 listLength = list_size(&rContext->handlesList);
1191 if (listLength >= maxReaderHandles)
1193 Log2(PCSC_LOG_CRITICAL,
1194 "Too many handles opened, exceeding configured max (%d)",
1201 if (NULL == newHandle)
1203 Log1(PCSC_LOG_CRITICAL,
"malloc failed");
1208 newHandle->
hCard = hCard;
1211 lrv = list_append(&rContext->handlesList, newHandle);
1215 Log2(PCSC_LOG_CRITICAL,
"list_append failed with return value: %d",
1231 currentHandle = list_seek(&rContext->handlesList, &hCard);
1232 if (NULL == currentHandle)
1234 Log2(PCSC_LOG_CRITICAL,
"list_seek failed to locate hCard=%lX", hCard);
1239 lrv = list_delete(&rContext->handlesList, currentHandle);
1241 Log2(PCSC_LOG_CRITICAL,
1242 "list_delete failed with return value: %d", lrv);
1244 free(currentHandle);
1253 void RFSetReaderEventState(
READER_CONTEXT * rContext, DWORD dwEvent)
1256 int list_index, listSize;
1260 listSize = list_size(&rContext->handlesList);
1262 for (list_index = 0; list_index < listSize; list_index++)
1264 currentHandle = list_get_at(&rContext->handlesList, list_index);
1265 if (NULL == currentHandle)
1267 Log2(PCSC_LOG_CRITICAL,
"list_get_at failed at index %d",
1292 currentHandle = list_seek(&rContext->handlesList, &hCard);
1294 if (NULL == currentHandle)
1297 Log2(PCSC_LOG_CRITICAL,
"list_seek failed for hCard 0x%lX", hCard);
1327 currentHandle = list_seek(&rContext->handlesList, &hCard);
1329 if (NULL == currentHandle)
1349 void RFCleanupReaders(
void)
1353 Log1(PCSC_LOG_INFO,
"entering cleaning function");
1356 if (sReadersContexts[i]->vHandle != 0)
1359 char lpcStripReader[MAX_READERNAME];
1361 Log2(PCSC_LOG_INFO,
"Stopping reader: %s",
1362 sReadersContexts[i]->readerState->readerName);
1364 strncpy(lpcStripReader,
1365 sReadersContexts[i]->readerState->readerName,
1366 sizeof(lpcStripReader));
1368 lpcStripReader[strlen(lpcStripReader) - 6] =
'\0';
1370 rv = RFRemoveReader(lpcStripReader, sReadersContexts[i]->port);
1373 Log2(PCSC_LOG_ERROR,
"RFRemoveReader error: 0x%08lX", rv);
1375 free(sReadersContexts[i]);
1393 void RFWaitForReaderInit(
void)
1395 int i, need_to_wait;
1399 need_to_wait = FALSE;
1403 if (sReadersContexts[i]->vHandle != NULL)
1407 == sReadersContexts[i]->readerState->cardAtrLength)
1409 Log2(PCSC_LOG_DEBUG,
"Waiting init for reader: %s",
1410 sReadersContexts[i]->readerState->readerName);
1411 need_to_wait = TRUE;
1418 }
while (need_to_wait);
1423 int RFStartSerialReaders(
const char *readerconf)
1429 ConfigFile = strdup(readerconf);
1431 rv = DBGetReaderListDir(readerconf, &reader_list);
1434 if (NULL == reader_list)
1441 (void)RFAddReader(reader_list[i].pcFriendlyname,
1442 reader_list[i].channelId,
1443 reader_list[i].pcLibpath, reader_list[i].pcDevicename);
1447 ConfigFileCRC += reader_list[i].pcFriendlyname[j];
1448 for (j=0; j<reader_list[i].
pcLibpath[j]; j++)
1449 ConfigFileCRC += reader_list[i].pcLibpath[j];
1451 ConfigFileCRC += reader_list[i].pcDevicename[j];
1454 free(reader_list[i].pcFriendlyname);
1455 free(reader_list[i].pcLibpath);
1456 free(reader_list[i].pcDevicename);
1463 void RFReCheckReaderConf(
void)
1468 (void)DBGetReaderListDir(ConfigFile, &reader_list);
1471 if (NULL == reader_list)
1481 crc += reader_list[i].pcFriendlyname[j];
1482 for (j=0; j<reader_list[i].
pcLibpath[j]; j++)
1483 crc += reader_list[i].pcLibpath[j];
1485 crc += reader_list[i].pcDevicename[j];
1489 if (crc != ConfigFileCRC)
1491 Log2(PCSC_LOG_CRITICAL,
1492 "configuration file: %s has been modified. Recheck canceled",
1500 char present = FALSE;
1502 Log2(PCSC_LOG_DEBUG,
"refresh reader: %s",
1503 reader_list[i].pcFriendlyname);
1508 if (sReadersContexts[r]->vHandle != 0)
1510 char lpcStripReader[MAX_READERNAME];
1514 strncpy(lpcStripReader,
1515 sReadersContexts[i]->readerState->readerName,
1516 sizeof(lpcStripReader));
1517 tmplen = strlen(lpcStripReader);
1518 lpcStripReader[tmplen - 6] = 0;
1520 if ((strcmp(reader_list[i].pcFriendlyname, lpcStripReader) == 0)
1521 && (reader_list[r].channelId == sReadersContexts[i]->port))
1532 Log2(PCSC_LOG_INFO,
"Reader %s disappeared",
1533 reader_list[i].pcFriendlyname);
1534 (void)RFRemoveReader(reader_list[i].pcFriendlyname,
1535 reader_list[r].channelId);
1544 (void)RFAddReader(reader_list[i].pcFriendlyname,
1545 reader_list[i].channelId, reader_list[i].pcLibpath,
1546 reader_list[i].pcDevicename);
1549 free(reader_list[i].pcFriendlyname);
1550 free(reader_list[i].pcLibpath);
1551 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...