66#include "configfile.h"
76static int maxReaderHandles = PCSC_MAX_READER_HANDLES;
77static DWORD dwNumReadersContexts = 0;
79static char *ConfigFile = NULL;
80static int ConfigFileCRC = 0;
82static pthread_mutex_t LockMutex = PTHREAD_MUTEX_INITIALIZER;
84#define IDENTITY_SHIFT 16
87static int RDR_CLIHANDLES_seeker(
const void *el,
const void *key)
91 if ((el == NULL) || (key == NULL))
93 Log3(PCSC_LOG_CRITICAL,
94 "RDR_CLIHANDLES_seeker called with NULL pointer: el=%p, key=%p",
124 removeReader(sReader);
129LONG RFAllocateReaderSpace(
unsigned int customMaxReaderHandles)
133 if (customMaxReaderHandles != 0)
134 maxReaderHandles = customMaxReaderHandles;
140 sReadersContexts[i]->
vHandle = NULL;
141 atomic_init(&sReadersContexts[i]->hLockId, 0);
142 atomic_init(&sReadersContexts[i]->contexts, 0);
143 atomic_init(&sReadersContexts[i]->reference, 0);
158 return EHInitializeEventStructures();
161LONG 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 sReadersContexts[dwContext]->
reference = 1;
319 sReadersContexts[dwContext]->
pFeeds =
320 sReadersContexts[parentNode]->
pFeeds;
321 *(sReadersContexts[dwContext])->pFeeds += 1;
322 sReadersContexts[dwContext]->
vHandle =
323 sReadersContexts[parentNode]->
vHandle;
324 sReadersContexts[dwContext]->
mMutex =
325 sReadersContexts[parentNode]->
mMutex;
326 sReadersContexts[dwContext]->
pMutex =
327 sReadersContexts[parentNode]->
pMutex;
330 dwGetSize =
sizeof(ucThread);
334 if (rv ==
IFD_SUCCESS && dwGetSize == 1 && ucThread[0] == 1)
336 Log1(PCSC_LOG_INFO,
"Driver is thread safe");
337 sReadersContexts[dwContext]->
mMutex = NULL;
338 sReadersContexts[dwContext]->
pMutex = NULL;
341 *(sReadersContexts[dwContext])->pMutex += 1;
344 if (sReadersContexts[dwContext]->pFeeds == NULL)
346 sReadersContexts[dwContext]->
pFeeds = malloc(
sizeof(
int));
352 *(sReadersContexts[dwContext])->pFeeds = 1;
355 if (sReadersContexts[dwContext]->mMutex == 0)
357 sReadersContexts[dwContext]->
mMutex =
358 malloc(
sizeof(pthread_mutex_t));
359 (void)pthread_mutex_init(sReadersContexts[dwContext]->mMutex, NULL);
362 if (sReadersContexts[dwContext]->pMutex == NULL)
364 sReadersContexts[dwContext]->
pMutex = malloc(
sizeof(
int));
365 *(sReadersContexts[dwContext])->pMutex = 1;
368 dwNumReadersContexts += 1;
370 rv = RFInitializeReader(sReadersContexts[dwContext]);
373 int log_level = PCSC_LOG_ERROR;
375 log_level = PCSC_LOG_INFO;
378 Log2(log_level,
"%s init failed.", readerName);
379 (void)RFRemoveReader(readerName, port, REMOVE_READER_NO_FLAG);
385 RESPONSECODE (*fct)(DWORD, int) = NULL;
387 dwGetSize =
sizeof(fct);
393 Log1(PCSC_LOG_INFO,
"Using the pcscd polling thread");
398 Log1(PCSC_LOG_INFO,
"Using the reader polling thread");
401 rv = EHSpawnEventHandler(sReadersContexts[dwContext]);
404 Log2(PCSC_LOG_ERROR,
"%s init failed.", readerName);
405 (void)RFRemoveReader(readerName, port, REMOVE_READER_NO_FLAG);
411 dwGetSize =
sizeof(ucGetData);
415 int nbSlots = ucGetData[0];
416 if (rv !=
IFD_SUCCESS || dwGetSize != 1 || nbSlots == 0)
431 for (j = 1; j < nbSlots; j++)
433 char *tmpReader = NULL;
434 DWORD dwContextB = 0;
435 RESPONSECODE (*fct)(DWORD, int) = NULL;
440 if (sReadersContexts[i]->vHandle == 0)
450 RFRemoveReader(readerName, port, REMOVE_READER_NO_FLAG);
457 sReadersContexts[dwContext]->readerState->readerName,
458 sizeof(sReadersContexts[dwContextB]->readerState->readerName));
459 snprintf(tmpReader + strlen(tmpReader) - 2, 3,
"%02X", j);
461 sReadersContexts[dwContextB]->
library =
462 sReadersContexts[dwContext]->
library;
463 sReadersContexts[dwContextB]->
device =
464 sReadersContexts[dwContext]->
device;
465 sReadersContexts[dwContextB]->
version =
466 sReadersContexts[dwContext]->
version;
467 sReadersContexts[dwContextB]->
port =
468 sReadersContexts[dwContext]->
port;
469 sReadersContexts[dwContextB]->
vHandle =
470 sReadersContexts[dwContext]->
vHandle;
471 sReadersContexts[dwContextB]->
mMutex =
472 sReadersContexts[dwContext]->
mMutex;
473 sReadersContexts[dwContextB]->
pMutex =
474 sReadersContexts[dwContext]->
pMutex;
475 sReadersContexts[dwContextB]->
slot =
476 sReadersContexts[dwContext]->
slot + j;
483 sReadersContexts[dwContextB]->
pFeeds =
484 sReadersContexts[dwContext]->
pFeeds;
487 *(sReadersContexts[dwContextB])->pFeeds += 1;
489 sReadersContexts[dwContextB]->
contexts = 0;
490 sReadersContexts[dwContextB]->
hLockId = 0;
491 sReadersContexts[dwContextB]->
LockCount = 0;
493 lrv = list_init(&sReadersContexts[dwContextB]->handlesList);
496 Log2(PCSC_LOG_CRITICAL,
"list_init failed with return value: %d", lrv);
500 lrv = list_attributes_seeker(&sReadersContexts[dwContextB]->handlesList,
501 RDR_CLIHANDLES_seeker);
504 Log2(PCSC_LOG_CRITICAL,
505 "list_attributes_seeker failed with return value: %d", lrv);
509 (void)pthread_mutex_init(&sReadersContexts[dwContextB]->handlesList_lock, NULL);
510 (void)pthread_mutex_init(&sReadersContexts[dwContextB]->powerState_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, REMOVE_READER_NO_FLAG);
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, REMOVE_READER_NO_FLAG);
578LONG RFRemoveReader(
const char *readerName,
int port,
int flags)
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] && (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))
609 if (flags & REMOVE_READER_FLAG_REMOVED)
616 valueLength =
sizeof(tagValue);
628 UNREF_READER(sReadersContexts[i])
639 if (sContext -> pthThread)
640 EHDestroyEventHandler(sContext);
642 if ((NULL == sContext->
pMutex) || (NULL == sContext->
pFeeds))
645 "Trying to remove an already removed driver");
649 RFUnInitializeReader(sContext);
654 if (0 == *sContext->
pMutex)
656 (void)pthread_mutex_destroy(sContext->
mMutex);
668 if (*sContext->
pFeeds == 0)
684 while (list_size(&sContext->handlesList) != 0)
689 currentHandle = list_get_at(&sContext->handlesList, 0);
690 lrv = list_delete_at(&sContext->handlesList, 0);
692 Log2(PCSC_LOG_CRITICAL,
693 "list_delete_at failed with return value: %d", lrv);
699 list_destroy(&sContext->handlesList);
700 dwNumReadersContexts -= 1;
708LONG RFSetReaderName(
READER_CONTEXT * rContext,
const char *readerName,
709 const char *libraryName,
int port)
713 int currentDigit = -1;
714 int supportedChannels = 0;
717 const char *extend =
"";
721 usedDigits[i] = FALSE;
723 if (dwNumReadersContexts != 0)
727 if (sReadersContexts[i]->vHandle != 0)
729 if (strcmp(sReadersContexts[i]->library, libraryName) == 0)
735 valueLength =
sizeof(tagValue);
738 &valueLength, tagValue);
743 supportedChannels = tagValue[0];
745 "Support %d simultaneous readers", tagValue[0]);
748 supportedChannels = 1;
751 if ((((sReadersContexts[i]->port & 0xFFFF0000) ==
752 PCSCLITE_HP_BASE_PORT)
753 && (sReadersContexts[i]->port != port))
754 || (supportedChannels > 1))
770 currentDigit = strtol(reader + strlen(reader) - 5, NULL, 16);
773 usedDigits[currentDigit] = TRUE;
784 if (currentDigit != -1)
789 if (usedDigits[i] == FALSE)
799 if (i >= supportedChannels)
801 Log3(PCSC_LOG_ERROR,
"Driver %s does not support more than "
802 "%d reader(s). Maybe the driver should support "
803 "TAG_IFD_SIMULTANEOUS_ACCESS", libraryName, supportedChannels);
809 extend = getenv(
"PCSCLITE_FILTER_EXTEND_READER_NAMES");
816 readerName, extend, i);
819 rContext->
slot = i << 16;
824LONG RFReaderInfo(
const char *readerName,
READER_CONTEXT ** sReader)
828 if (readerName == NULL)
833 if (sReadersContexts[i]->vHandle != 0)
835 if (strcmp(readerName,
836 sReadersContexts[i]->readerState->readerName) == 0)
839 REF_READER(sReadersContexts[i])
841 *sReader = sReadersContexts[i];
856 if (sReadersContexts[i]->vHandle != 0)
859 (void)pthread_mutex_lock(&sReadersContexts[i]->handlesList_lock);
860 currentHandle = list_seek(&sReadersContexts[i]->handlesList,
862 (void)pthread_mutex_unlock(&sReadersContexts[i]->handlesList_lock);
863 if (currentHandle != NULL)
866 REF_READER(sReadersContexts[i])
868 *sReader = sReadersContexts[i];
881 Log2(PCSC_LOG_INFO,
"Reusing already loaded driver for %s",
895 rv = DYN_GetAddress(rContext->
vHandle, &f,
"IFDHCreateChannelByName", TRUE);
899 rContext->
version = IFD_HVERSION_3_0;
903 rv = DYN_GetAddress(rContext->
vHandle, &f,
"IFDHCreateChannel", FALSE);
907 rContext->
version = IFD_HVERSION_2_0;
912 Log1(PCSC_LOG_CRITICAL,
"IFDHandler functions missing");
917 if (rContext->
version == IFD_HVERSION_2_0)
920#define GET_ADDRESS_OPTIONALv2(s, code) \
923 int rvl = DYN_GetAddress(rContext->vHandle, &f1, "IFDH" #s, FALSE); \
924 if (SCARD_S_SUCCESS != rvl) \
928 rContext->psFunctions.psFunctions_v2.pvf ## s = f1; \
931#define GET_ADDRESSv2(s) \
932 GET_ADDRESS_OPTIONALv2(s, \
933 Log1(PCSC_LOG_CRITICAL, "IFDHandler functions missing: " #s ); \
936 Log1(PCSC_LOG_INFO,
"Loading IFD Handler 2.0");
938 GET_ADDRESSv2(CreateChannel)
939 GET_ADDRESSv2(CloseChannel)
940 GET_ADDRESSv2(GetCapabilities)
941 GET_ADDRESSv2(SetCapabilities)
942 GET_ADDRESSv2(PowerICC)
943 GET_ADDRESSv2(TransmitToICC)
944 GET_ADDRESSv2(ICCPresence)
945 GET_ADDRESS_OPTIONALv2(SetProtocolParameters, )
947 GET_ADDRESSv2(Control)
949 else if (rContext->version == IFD_HVERSION_3_0)
952#define GET_ADDRESS_OPTIONALv3(s, code) \
955 int rvl = DYN_GetAddress(rContext->vHandle, &f1, "IFDH" #s, FALSE); \
956 if (SCARD_S_SUCCESS != rvl) \
960 rContext->psFunctions.psFunctions_v3.pvf ## s = f1; \
963#define GET_ADDRESSv3(s) \
964 GET_ADDRESS_OPTIONALv3(s, \
965 Log1(PCSC_LOG_CRITICAL, "IFDHandler functions missing: " #s ); \
968 Log1(PCSC_LOG_INFO,
"Loading IFD Handler 3.0");
970 GET_ADDRESSv2(CreateChannel)
971 GET_ADDRESSv2(CloseChannel)
972 GET_ADDRESSv2(GetCapabilities)
973 GET_ADDRESSv2(SetCapabilities)
974 GET_ADDRESSv2(PowerICC)
975 GET_ADDRESSv2(TransmitToICC)
976 GET_ADDRESSv2(ICCPresence)
977 GET_ADDRESS_OPTIONALv2(SetProtocolParameters, )
979 GET_ADDRESSv3(CreateChannelByName)
980 GET_ADDRESSv3(Control)
985 Log1(PCSC_LOG_CRITICAL,
"IFD Handler not 1.0/2.0 or 3.0");
1003 if (*rContext->
pFeeds == 1)
1005 Log1(PCSC_LOG_INFO,
"Unloading reader driver.");
1006 (void)DYN_CloseLibrary(&rContext->
vHandle);
1026 (void)pthread_mutex_lock(&LockMutex);
1027 rv = RFCheckSharing(hCard, rContext);
1033 (void)pthread_mutex_unlock(&LockMutex);
1042 (void)pthread_mutex_lock(&LockMutex);
1043 rv = RFCheckSharing(hCard, rContext);
1066 (void)pthread_mutex_unlock(&LockMutex);
1075 (void)pthread_mutex_lock(&LockMutex);
1076 rv = RFCheckSharing(hCard, rContext);
1082 (void)pthread_mutex_unlock(&LockMutex);
1093 Log3(PCSC_LOG_INFO,
"Attempting startup of %s using %s",
1096#ifndef PCSCLITE_STATIC_DRIVER
1098 rv = RFLoadReader(rContext);
1101 Log2(PCSC_LOG_ERROR,
"RFLoadReader failed: 0x%lX", rv);
1106 rv = RFBindFunctions(rContext);
1110 Log2(PCSC_LOG_ERROR,
"RFBindFunctions failed: 0x%lX", rv);
1111 (void)RFUnloadReader(rContext);
1116 rContext->
vHandle = RFInitializeReader;
1124 int log_level = PCSC_LOG_CRITICAL;
1130 log_level = PCSC_LOG_INFO;
1134 Log3(log_level,
"Open Port 0x%X Failed (%s)",
1139 rContext->
slot = -1;
1147 Log2(PCSC_LOG_INFO,
"Attempting shutdown of %s.",
1151 if (rContext->
slot != -1)
1154 (void)RFUnBindFunctions(rContext);
1155 (void)RFUnloadReader(rContext);
1192 ret = RFReaderInfoById(randHandle, &dummy_reader);
1194 UNREF_READER(dummy_reader)
1205 int listLength, lrv;
1210 listLength = list_size(&rContext->handlesList);
1213 if (listLength >= maxReaderHandles)
1215 Log2(PCSC_LOG_CRITICAL,
1216 "Too many handles opened, exceeding configured max (%d)",
1223 if (NULL == newHandle)
1225 Log1(PCSC_LOG_CRITICAL,
"malloc failed");
1230 newHandle->
hCard = hCard;
1233 lrv = list_append(&rContext->handlesList, newHandle);
1237 Log2(PCSC_LOG_CRITICAL,
"list_append failed with return value: %d",
1253 currentHandle = list_seek(&rContext->handlesList, &hCard);
1254 if (NULL == currentHandle)
1256 Log2(PCSC_LOG_CRITICAL,
"list_seek failed to locate hCard=%lX", hCard);
1261 lrv = list_delete(&rContext->handlesList, currentHandle);
1263 Log2(PCSC_LOG_CRITICAL,
1264 "list_delete failed with return value: %d", lrv);
1266 free(currentHandle);
1275void RFSetReaderEventState(
READER_CONTEXT * rContext, DWORD dwEvent)
1278 int list_index, listSize;
1282 listSize = list_size(&rContext->handlesList);
1284 for (list_index = 0; list_index < listSize; list_index++)
1286 currentHandle = list_get_at(&rContext->handlesList, list_index);
1287 if (NULL == currentHandle)
1289 Log2(PCSC_LOG_CRITICAL,
"list_get_at failed at index %d",
1312 DWORD dwEventStatus;
1315 currentHandle = list_seek(&rContext->handlesList, &hCard);
1317 if (NULL == currentHandle)
1320 Log2(PCSC_LOG_CRITICAL,
"list_seek failed for hCard 0x%lX", hCard);
1325 switch(dwEventStatus)
1351 currentHandle = list_seek(&rContext->handlesList, &hCard);
1353 if (NULL == currentHandle)
1373void RFCleanupReaders(
void)
1377 Log1(PCSC_LOG_INFO,
"entering cleaning function");
1380 if (sReadersContexts[i]->vHandle != 0)
1383 char lpcStripReader[MAX_READERNAME];
1385 Log2(PCSC_LOG_INFO,
"Stopping reader: %s",
1386 sReadersContexts[i]->readerState->readerName);
1388 strncpy(lpcStripReader,
1389 sReadersContexts[i]->readerState->readerName,
1390 sizeof(lpcStripReader));
1392 lpcStripReader[strlen(lpcStripReader) - 6] =
'\0';
1394 rv = RFRemoveReader(lpcStripReader, sReadersContexts[i]->port,
1395 REMOVE_READER_NO_FLAG);
1398 Log2(PCSC_LOG_ERROR,
"RFRemoveReader error: 0x%08lX", rv);
1401 free(sReadersContexts[i]);
1402 sReadersContexts[i] = NULL;
1419void RFWaitForReaderInit(
void)
1421 int i, need_to_wait;
1425 need_to_wait = FALSE;
1429 if (sReadersContexts[i]->vHandle != NULL)
1433 == sReadersContexts[i]->readerState->cardAtrLength)
1435 Log2(PCSC_LOG_DEBUG,
"Waiting init for reader: %s",
1436 sReadersContexts[i]->readerState->readerName);
1437 need_to_wait = TRUE;
1444 }
while (need_to_wait);
1449int RFStartSerialReaders(
const char *readerconf)
1455 ConfigFile = strdup(readerconf);
1457 rv = DBGetReaderListDir(readerconf, &reader_list);
1460 if (NULL == reader_list)
1467 (void)RFAddReader(reader_list[i].pcFriendlyname,
1468 reader_list[i].channelId,
1469 reader_list[i].pcLibpath, reader_list[i].pcDevicename);
1473 ConfigFileCRC += reader_list[i].pcFriendlyname[j];
1474 for (j=0; j<reader_list[i].
pcLibpath[j]; j++)
1475 ConfigFileCRC += reader_list[i].pcLibpath[j];
1477 ConfigFileCRC += reader_list[i].pcDevicename[j];
1480 free(reader_list[i].pcFriendlyname);
1481 free(reader_list[i].pcLibpath);
1482 free(reader_list[i].pcDevicename);
1489void RFReCheckReaderConf(
void)
1494 (void)DBGetReaderListDir(ConfigFile, &reader_list);
1497 if (NULL == reader_list)
1507 crc += reader_list[i].pcFriendlyname[j];
1508 for (j=0; j<reader_list[i].
pcLibpath[j]; j++)
1509 crc += reader_list[i].pcLibpath[j];
1511 crc += reader_list[i].pcDevicename[j];
1515 if (crc != ConfigFileCRC)
1517 Log2(PCSC_LOG_CRITICAL,
1518 "configuration file: %s has been modified. Recheck canceled",
1526 char present = FALSE;
1528 Log2(PCSC_LOG_DEBUG,
"refresh reader: %s",
1529 reader_list[i].pcFriendlyname);
1534 if (sReadersContexts[r]->vHandle != 0)
1536 char lpcStripReader[MAX_READERNAME];
1540 strncpy(lpcStripReader,
1541 sReadersContexts[i]->readerState->readerName,
1542 sizeof(lpcStripReader));
1543 tmplen = strlen(lpcStripReader);
1544 lpcStripReader[tmplen - 6] = 0;
1546 if ((strcmp(reader_list[i].pcFriendlyname, lpcStripReader) == 0)
1547 && (reader_list[r].channelId == sReadersContexts[i]->port))
1558 Log2(PCSC_LOG_INFO,
"Reader %s disappeared",
1559 reader_list[i].pcFriendlyname);
1560 (void)RFRemoveReader(reader_list[i].pcFriendlyname,
1561 reader_list[r].channelId, REMOVE_READER_NO_FLAG);
1570 (void)RFAddReader(reader_list[i].pcFriendlyname,
1571 reader_list[i].channelId, reader_list[i].pcLibpath,
1572 reader_list[i].pcDevicename);
1575 free(reader_list[i].pcFriendlyname);
1576 free(reader_list[i].pcLibpath);
1577 free(reader_list[i].pcDevicename);
This abstracts dynamic library loading functions.
void EHSignalEventToClients(void)
Sends an asynchronous event to any waiting client.
This handles card insertion/removal events, updates ATR, protocol, and status information.
#define PCSCLITE_SHARING_EXCLUSIVE_CONTEXT
Reader used in exclusive mode.
#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...
#define SCARD_E_INVALID_HANDLE
The supplied handle was invalid.
#define SCARD_E_UNKNOWN_READER
The specified reader name is not recognized.
#define SCARD_W_RESET_CARD
The smart card has been reset, so any shared state information is invalid.
#define SCARD_F_UNKNOWN_ERROR
An internal error has been detected, but the source is unknown.
#define SCARD_E_INVALID_TARGET
Registry startup information is missing or invalid.
#define SCARD_S_SUCCESS
No error was encountered.
#define SCARD_E_NO_MEMORY
Not enough memory available to complete this command.
#define SCARD_E_SHARING_VIOLATION
The smart card cannot be accessed because of other connections outstanding.
#define SCARD_E_DUPLICATE_READER
The reader driver did not produce a unique reader name.
#define SCARD_E_INVALID_VALUE
One or more of the supplied parameters values could not be properly interpreted.
#define SCARD_W_REMOVED_CARD
The smart card has been removed, so further communication is not possible.
#define SCARD_E_NOT_TRANSACTED
An attempt was made to end a non-existent transaction.
#define SCARD_E_READER_UNAVAILABLE
The specified reader is not currently available for use.
This provides a search API for hot pluggble devices.
#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_SIMULTANEOUS_ACCESS
number of reader the driver can manage
#define TAG_IFD_THREAD_SAFE
driver is thread safe
#define TAG_IFD_SLOTS_NUMBER
number of slots of the reader
#define TAG_IFD_POLLING_THREAD_WITH_TIMEOUT
driver uses a polling thread with a timeout parameter
#define TAG_IFD_SLOT_THREAD_SAFE
support access to different slots of the reader
#define IFD_SUCCESS
no error
#define TAG_IFD_DEVICE_REMOVED
signals the reader has been removed
RESPONSECODE IFDCloseIFD(READER_CONTEXT *rContext)
Close a communication channel to the IFD.
RESPONSECODE IFDOpenIFD(READER_CONTEXT *rContext)
Open a communication channel to the IFD.
RESPONSECODE IFDGetCapabilities(READER_CONTEXT *rContext, DWORD dwTag, PDWORD pdwLength, PUCHAR pucValue)
Get's capabilities in the reader.
LONG IFDStatusICC(READER_CONTEXT *rContext, PDWORD pdwStatus)
Provide statistical information about the IFD and ICC including insertions, atr, powering status/etc.
RESPONSECODE IFDSetCapabilities(READER_CONTEXT *rContext, DWORD dwTag, DWORD dwLength, PUCHAR pucValue)
Set capabilities in the reader.
This wraps the dynamic ifdhandler functions.
This keeps a list of defines for pcsc-lite.
@ POWER_STATE_UNPOWERED
auto power off
#define SCARD_RESET
Card was reset.
#define SCARD_REMOVED
Card was removed.
#define SCARD_PROTOCOL_UNDEFINED
protocol not set
#define MAX_ATR_SIZE
Maximum ATR size.
#define SCARD_UNKNOWN
Unknown state.
LONG SCARDHANDLE
hCard returned by SCardConnect()
#define PCSCLITE_MAX_READERS_CONTEXTS
Maximum readers context (a slot is count as a reader)
int RFGetPowerState(READER_CONTEXT *rContext)
Wait until all connected readers have a chance to power up a possibly inserted card.
This keeps track of a list of currently available reader structures.
SCARDHANDLE hCard
hCard for this connection
_Atomic DWORD dwEventStatus
Recent event that must be sent.
RESPONSECODE(* pthCardEvent)(DWORD, int)
Card Event sync.
pthread_mutex_t * mMutex
Mutex for this connection.
pthread_mutex_t powerState_lock
powerState mutex
LPVOID vHandle
Dlopen handle.
pthread_t pthThread
Event polling thread.
int LockCount
number of recursive locks
_Atomic int32_t contexts
Number of open contexts.
union ReaderContext::@3 psFunctions
driver functions
int slot
Current Reader Slot.
int * pFeeds
Number of shared client to lib.
_Atomic SCARDHANDLE hLockId
Lock Id.
int * pMutex
Number of client to mutex.
int version
IFD Handler version number.
pthread_mutex_t handlesList_lock
lock for the above list
char * library
Library Path.
struct pubReaderStatesList * readerState
link to the reader state
_Atomic int reference
number of users of the structure
int powerState
auto power off state
char * device
Device Name.
char * pcFriendlyname
FRIENDLYNAME.
char * pcDevicename
DEVICENAME.
Define an exported public reader state structure so each application gets instant notification of cha...
char readerName[MAX_READERNAME]
reader name
int32_t readerSharing
PCSCLITE_SHARING_* sharing status.
uint32_t cardProtocol
SCARD_PROTOCOL_* value.
UCHAR cardAtr[MAX_ATR_SIZE]
ATR.
uint32_t eventCounter
number of card events
uint32_t readerState
SCARD_* bit field.
uint32_t cardAtrLength
ATR length.
This handles abstract system level calls.
int SYS_RandomInt(void)
Generate a pseudo random number.
int SYS_USleep(int)
Makes the current process sleep for some microseconds.
static READER_STATE readerStates[PCSCLITE_MAX_READERS_CONTEXTS]
Area used to read status information about the readers.