67#include "configfile.h"
72static int maxReaderHandles = PCSC_MAX_READER_HANDLES;
73static DWORD dwNumReadersContexts = 0;
75static char *ConfigFile = NULL;
76static int ConfigFileCRC = 0;
78static pthread_mutex_t LockMutex = PTHREAD_MUTEX_INITIALIZER;
80#define IDENTITY_SHIFT 16
83static 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",
120 removeReader(sReader);
125LONG RFAllocateReaderSpace(
unsigned int customMaxReaderHandles)
129 if (customMaxReaderHandles != 0)
130 maxReaderHandles = customMaxReaderHandles;
136 sReadersContexts[i]->
vHandle = NULL;
137 atomic_init(&sReadersContexts[i]->hLockId, 0);
138 atomic_init(&sReadersContexts[i]->contexts, 0);
139 atomic_init(&sReadersContexts[i]->reference, 0);
142 memset(readerStates[i].readerName, 0, MAX_READERNAME);
150 sReadersContexts[i]->
readerState = &readerStates[i];
154 return EHInitializeEventStructures();
157LONG RFAddReader(
const char *readerNameLong,
int port,
const char *library,
160 DWORD dwContext = 0, dwGetSize;
161 UCHAR ucGetData[1], ucThread[1];
165 char *readerName = NULL;
167 if ((readerNameLong == NULL) || (library == NULL) || (device == NULL))
171 const char *ro_filter = getenv(
"PCSCLITE_FILTER_IGNORE_READER_NAMES");
177 filter = alloca(strlen(ro_filter)+1);
178 strcpy(filter, ro_filter);
183 next = strchr(filter,
':');
191 if (*filter && strstr(readerNameLong, filter))
194 "Reader name \"%s\" contains \"%s\": ignored",
195 readerNameLong, filter);
210 readerName = alloca(strlen(readerNameLong)+1);
211 strcpy(readerName, readerNameLong);
214 if (strlen(readerName) > MAX_READERNAME -
sizeof(
" 00 00"))
217 "Reader name too long: %zd chars instead of max %zd. Truncating!",
218 strlen(readerName), MAX_READERNAME -
sizeof(
" 00 00"));
219 readerName[MAX_READERNAME -
sizeof(
" 00 00")] =
'\0';
223 if (dwNumReadersContexts != 0)
227 if (sReadersContexts[i]->vHandle != 0)
229 char lpcStripReader[MAX_READERNAME];
233 strncpy(lpcStripReader,
234 sReadersContexts[i]->readerState->readerName,
235 sizeof(lpcStripReader));
236 tmplen = strlen(lpcStripReader);
237 lpcStripReader[tmplen - 6] = 0;
239 if ((strcmp(readerName, lpcStripReader) == 0)
240 && (port == sReadersContexts[i]->port)
241 && (strcmp(device, sReadersContexts[i]->device) == 0))
243 Log1(PCSC_LOG_ERROR,
"Duplicate reader found.");
253 if (sReadersContexts[i]->vHandle == 0)
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 sReadersContexts[dwContext]->
reference = 1;
315 sReadersContexts[dwContext]->
pFeeds =
316 sReadersContexts[parentNode]->
pFeeds;
317 *(sReadersContexts[dwContext])->pFeeds += 1;
318 sReadersContexts[dwContext]->
vHandle =
319 sReadersContexts[parentNode]->
vHandle;
320 sReadersContexts[dwContext]->
mMutex =
321 sReadersContexts[parentNode]->
mMutex;
322 sReadersContexts[dwContext]->
pMutex =
323 sReadersContexts[parentNode]->
pMutex;
326 dwGetSize =
sizeof(ucThread);
330 if (rv ==
IFD_SUCCESS && dwGetSize == 1 && ucThread[0] == 1)
332 Log1(PCSC_LOG_INFO,
"Driver is thread safe");
333 sReadersContexts[dwContext]->
mMutex = NULL;
334 sReadersContexts[dwContext]->
pMutex = NULL;
337 *(sReadersContexts[dwContext])->pMutex += 1;
340 if (sReadersContexts[dwContext]->pFeeds == NULL)
342 sReadersContexts[dwContext]->
pFeeds = malloc(
sizeof(
int));
348 *(sReadersContexts[dwContext])->pFeeds = 1;
351 if (sReadersContexts[dwContext]->mMutex == 0)
353 sReadersContexts[dwContext]->
mMutex =
354 malloc(
sizeof(pthread_mutex_t));
355 (void)pthread_mutex_init(sReadersContexts[dwContext]->mMutex, NULL);
358 if (sReadersContexts[dwContext]->pMutex == NULL)
360 sReadersContexts[dwContext]->
pMutex = malloc(
sizeof(
int));
361 *(sReadersContexts[dwContext])->pMutex = 1;
364 dwNumReadersContexts += 1;
366 rv = RFInitializeReader(sReadersContexts[dwContext]);
369 int log_level = PCSC_LOG_ERROR;
371 log_level = PCSC_LOG_INFO;
374 Log2(log_level,
"%s init failed.", readerName);
375 (void)RFRemoveReader(readerName, port, REMOVE_READER_NO_FLAG);
381 RESPONSECODE (*fct)(DWORD, int) = NULL;
383 dwGetSize =
sizeof(fct);
389 Log1(PCSC_LOG_INFO,
"Using the pcscd polling thread");
394 Log1(PCSC_LOG_INFO,
"Using the reader polling thread");
397 rv = EHSpawnEventHandler(sReadersContexts[dwContext]);
400 Log2(PCSC_LOG_ERROR,
"%s init failed.", readerName);
401 (void)RFRemoveReader(readerName, port, REMOVE_READER_NO_FLAG);
407 dwGetSize =
sizeof(ucGetData);
411 int nbSlots = ucGetData[0];
412 if (rv !=
IFD_SUCCESS || dwGetSize != 1 || nbSlots == 0)
427 for (j = 1; j < nbSlots; j++)
429 char *tmpReader = NULL;
430 DWORD dwContextB = 0;
431 RESPONSECODE (*fct)(DWORD, int) = NULL;
436 if (sReadersContexts[i]->vHandle == 0)
446 RFRemoveReader(readerName, port, REMOVE_READER_NO_FLAG);
453 sReadersContexts[dwContext]->readerState->readerName,
454 sizeof(sReadersContexts[dwContextB]->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 sReadersContexts[dwContextB]->
reference = 1;
514 dwGetSize =
sizeof(ucThread);
518 if (rv ==
IFD_SUCCESS && dwGetSize == 1 && ucThread[0] == 1)
520 Log1(PCSC_LOG_INFO,
"Driver is slot thread safe");
522 sReadersContexts[dwContextB]->
library =
523 strdup(sReadersContexts[dwContext]->library);
524 sReadersContexts[dwContextB]->
device =
525 strdup(sReadersContexts[dwContext]->device);
526 sReadersContexts[dwContextB]->
mMutex =
527 malloc(
sizeof(pthread_mutex_t));
528 (void)pthread_mutex_init(sReadersContexts[dwContextB]->mMutex,
531 sReadersContexts[dwContextB]->
pMutex = malloc(
sizeof(
int));
532 *(sReadersContexts[dwContextB])->pMutex = 1;
535 *(sReadersContexts[dwContextB])->pMutex += 1;
537 dwNumReadersContexts += 1;
539 rv = RFInitializeReader(sReadersContexts[dwContextB]);
543 (void)RFRemoveReader(readerName, port, REMOVE_READER_NO_FLAG);
548 dwGetSize =
sizeof(fct);
554 Log1(PCSC_LOG_INFO,
"Using the pcscd polling thread");
559 Log1(PCSC_LOG_INFO,
"Using the reader polling thread");
562 rv = EHSpawnEventHandler(sReadersContexts[dwContextB]);
565 Log2(PCSC_LOG_ERROR,
"%s init failed.", readerName);
566 (void)RFRemoveReader(readerName, port, REMOVE_READER_NO_FLAG);
574LONG RFRemoveReader(
const char *readerName,
int port,
int flags)
576 char lpcStripReader[MAX_READERNAME];
583 if (readerName == NULL)
587 extend = getenv(
"PCSCLITE_FILTER_EXTEND_READER_NAMES");
589 extend_size = strlen(extend);
594 if (sReadersContexts[i] && (sReadersContexts[i]->vHandle != 0))
596 strncpy(lpcStripReader,
597 sReadersContexts[i]->readerState->readerName,
598 sizeof(lpcStripReader));
599 lpcStripReader[strlen(lpcStripReader) - 6 - extend_size] = 0;
602 if ((strncmp(readerName, lpcStripReader, MAX_READERNAME -
sizeof(
" 00 00")) == 0)
603 && (port == sReadersContexts[i]->port))
605 if (flags & REMOVE_READER_FLAG_REMOVED)
612 valueLength =
sizeof(tagValue);
624 UNREF_READER(sReadersContexts[i])
635 if (sContext -> pthThread)
636 EHDestroyEventHandler(sContext);
638 if ((NULL == sContext->
pMutex) || (NULL == sContext->
pFeeds))
641 "Trying to remove an already removed driver");
645 RFUnInitializeReader(sContext);
650 if (0 == *sContext->
pMutex)
652 (void)pthread_mutex_destroy(sContext->
mMutex);
664 if (*sContext->
pFeeds == 0)
680 while (list_size(&sContext->handlesList) != 0)
685 currentHandle = list_get_at(&sContext->handlesList, 0);
686 lrv = list_delete_at(&sContext->handlesList, 0);
688 Log2(PCSC_LOG_CRITICAL,
689 "list_delete_at failed with return value: %d", lrv);
695 list_destroy(&sContext->handlesList);
696 dwNumReadersContexts -= 1;
704LONG RFSetReaderName(
READER_CONTEXT * rContext,
const char *readerName,
705 const char *libraryName,
int port)
709 int currentDigit = -1;
710 int supportedChannels = 0;
713 const char *extend =
"";
717 usedDigits[i] =
false;
719 if (dwNumReadersContexts != 0)
723 if (sReadersContexts[i]->vHandle != 0)
725 if (strcmp(sReadersContexts[i]->library, libraryName) == 0)
731 valueLength =
sizeof(tagValue);
734 &valueLength, tagValue);
739 supportedChannels = tagValue[0];
741 "Support %d simultaneous readers", tagValue[0]);
744 supportedChannels = 1;
747 if ((((sReadersContexts[i]->port & 0xFFFF0000) ==
748 PCSCLITE_HP_BASE_PORT)
749 && (sReadersContexts[i]->port != port))
750 || (supportedChannels > 1))
766 currentDigit = strtol(reader + strlen(reader) - 5, NULL, 16);
769 usedDigits[currentDigit] =
true;
780 if (currentDigit != -1)
785 if (usedDigits[i] ==
false)
795 if (i >= supportedChannels)
797 Log3(PCSC_LOG_ERROR,
"Driver %s does not support more than "
798 "%d reader(s). Maybe the driver should support "
799 "TAG_IFD_SIMULTANEOUS_ACCESS", libraryName, supportedChannels);
805 extend = getenv(
"PCSCLITE_FILTER_EXTEND_READER_NAMES");
812 readerName, extend, i);
815 rContext->
slot = i << 16;
820LONG RFReaderInfo(
const char *readerName,
READER_CONTEXT ** sReader)
824 if (readerName == NULL)
829 if (sReadersContexts[i]->vHandle != 0)
831 if (strcmp(readerName,
832 sReadersContexts[i]->readerState->readerName) == 0)
835 REF_READER(sReadersContexts[i])
837 *sReader = sReadersContexts[i];
852 if (sReadersContexts[i]->vHandle != 0)
855 (void)pthread_mutex_lock(&sReadersContexts[i]->handlesList_lock);
856 currentHandle = list_seek(&sReadersContexts[i]->handlesList,
858 (void)pthread_mutex_unlock(&sReadersContexts[i]->handlesList_lock);
859 if (currentHandle != NULL)
862 REF_READER(sReadersContexts[i])
864 *sReader = sReadersContexts[i];
877 Log2(PCSC_LOG_INFO,
"Reusing already loaded driver for %s",
891 rv = DYN_GetAddress(rContext->
vHandle, &f,
"IFDHCreateChannelByName",
true);
895 rContext->
version = IFD_HVERSION_3_0;
899 rv = DYN_GetAddress(rContext->
vHandle, &f,
"IFDHCreateChannel",
false);
903 rContext->
version = IFD_HVERSION_2_0;
908 Log1(PCSC_LOG_CRITICAL,
"IFDHandler functions missing");
913 if (rContext->
version == IFD_HVERSION_2_0)
916#define GET_ADDRESS_OPTIONALv2(s, code) \
919 int rvl = DYN_GetAddress(rContext->vHandle, &f1, "IFDH" #s, false); \
920 if (SCARD_S_SUCCESS != rvl) \
924 rContext->psFunctions.psFunctions_v2.pvf ## s = f1; \
927#define GET_ADDRESSv2(s) \
928 GET_ADDRESS_OPTIONALv2(s, \
929 Log1(PCSC_LOG_CRITICAL, "IFDHandler functions missing: " #s ); \
932 Log1(PCSC_LOG_INFO,
"Loading IFD Handler 2.0");
934 GET_ADDRESSv2(CreateChannel)
935 GET_ADDRESSv2(CloseChannel)
936 GET_ADDRESSv2(GetCapabilities)
937 GET_ADDRESSv2(SetCapabilities)
938 GET_ADDRESSv2(PowerICC)
939 GET_ADDRESSv2(TransmitToICC)
940 GET_ADDRESSv2(ICCPresence)
941 GET_ADDRESS_OPTIONALv2(SetProtocolParameters, )
943 GET_ADDRESSv2(Control)
945 else if (rContext->version == IFD_HVERSION_3_0)
948#define GET_ADDRESS_OPTIONALv3(s, code) \
951 int rvl = DYN_GetAddress(rContext->vHandle, &f1, "IFDH" #s, false); \
952 if (SCARD_S_SUCCESS != rvl) \
956 rContext->psFunctions.psFunctions_v3.pvf ## s = f1; \
959#define GET_ADDRESSv3(s) \
960 GET_ADDRESS_OPTIONALv3(s, \
961 Log1(PCSC_LOG_CRITICAL, "IFDHandler functions missing: " #s ); \
964 Log1(PCSC_LOG_INFO,
"Loading IFD Handler 3.0");
966 GET_ADDRESSv2(CreateChannel)
967 GET_ADDRESSv2(CloseChannel)
968 GET_ADDRESSv2(GetCapabilities)
969 GET_ADDRESSv2(SetCapabilities)
970 GET_ADDRESSv2(PowerICC)
971 GET_ADDRESSv2(TransmitToICC)
972 GET_ADDRESSv2(ICCPresence)
973 GET_ADDRESS_OPTIONALv2(SetProtocolParameters, )
975 GET_ADDRESSv3(CreateChannelByName)
976 GET_ADDRESSv3(Control)
981 Log1(PCSC_LOG_CRITICAL,
"IFD Handler not 1.0/2.0 or 3.0");
999 if (*rContext->
pFeeds == 1)
1001 Log1(PCSC_LOG_INFO,
"Unloading reader driver.");
1002 (void)DYN_CloseLibrary(&rContext->
vHandle);
1022 (void)pthread_mutex_lock(&LockMutex);
1023 rv = RFCheckSharing(hCard, rContext);
1029 (void)pthread_mutex_unlock(&LockMutex);
1038 (void)pthread_mutex_lock(&LockMutex);
1039 rv = RFCheckSharing(hCard, rContext);
1062 (void)pthread_mutex_unlock(&LockMutex);
1071 (void)pthread_mutex_lock(&LockMutex);
1072 rv = RFCheckSharing(hCard, rContext);
1078 (void)pthread_mutex_unlock(&LockMutex);
1089 Log3(PCSC_LOG_INFO,
"Attempting startup of %s using %s",
1092#ifndef PCSCLITE_STATIC_DRIVER
1094 rv = RFLoadReader(rContext);
1097 Log2(PCSC_LOG_ERROR,
"RFLoadReader failed: 0x%lX", rv);
1102 rv = RFBindFunctions(rContext);
1106 Log2(PCSC_LOG_ERROR,
"RFBindFunctions failed: 0x%lX", rv);
1107 (void)RFUnloadReader(rContext);
1112 rContext->
vHandle = RFInitializeReader;
1120 int log_level = PCSC_LOG_CRITICAL;
1126 log_level = PCSC_LOG_INFO;
1130 Log3(log_level,
"Open Port 0x%X Failed (%s)",
1135 rContext->
slot = -1;
1143 Log2(PCSC_LOG_INFO,
"Attempting shutdown of %s.",
1147 if (rContext->
slot != -1)
1150 (void)RFUnBindFunctions(rContext);
1151 (void)RFUnloadReader(rContext);
1189 ret = RFReaderInfoById(randHandle, &dummy_reader);
1191 UNREF_READER(dummy_reader)
1202 int listLength, lrv;
1207 listLength = list_size(&rContext->handlesList);
1210 if (listLength >= maxReaderHandles)
1212 Log2(PCSC_LOG_CRITICAL,
1213 "Too many handles opened, exceeding configured max (%d)",
1220 if (NULL == newHandle)
1222 Log1(PCSC_LOG_CRITICAL,
"malloc failed");
1227 newHandle->
hCard = hCard;
1230 lrv = list_append(&rContext->handlesList, newHandle);
1234 Log2(PCSC_LOG_CRITICAL,
"list_append failed with return value: %d",
1250 currentHandle = list_seek(&rContext->handlesList, &hCard);
1251 if (NULL == currentHandle)
1253 Log2(PCSC_LOG_CRITICAL,
"list_seek failed to locate hCard=%lX", hCard);
1258 lrv = list_delete(&rContext->handlesList, currentHandle);
1260 Log2(PCSC_LOG_CRITICAL,
1261 "list_delete failed with return value: %d", lrv);
1263 free(currentHandle);
1272void RFSetReaderEventState(
READER_CONTEXT * rContext, DWORD dwEvent)
1275 int list_index, listSize;
1279 listSize = list_size(&rContext->handlesList);
1281 for (list_index = 0; list_index < listSize; list_index++)
1283 currentHandle = list_get_at(&rContext->handlesList, list_index);
1284 if (NULL == currentHandle)
1286 Log2(PCSC_LOG_CRITICAL,
"list_get_at failed at index %d",
1309 DWORD dwEventStatus;
1312 currentHandle = list_seek(&rContext->handlesList, &hCard);
1314 if (NULL == currentHandle)
1317 Log2(PCSC_LOG_CRITICAL,
"list_seek failed for hCard 0x%lX", hCard);
1322 switch(dwEventStatus)
1348 currentHandle = list_seek(&rContext->handlesList, &hCard);
1350 if (NULL == currentHandle)
1370void RFCleanupReaders(
void)
1374 Log1(PCSC_LOG_INFO,
"entering cleaning function");
1377 if (sReadersContexts[i]->vHandle != 0)
1380 char lpcStripReader[MAX_READERNAME];
1382 Log2(PCSC_LOG_INFO,
"Stopping reader: %s",
1383 sReadersContexts[i]->readerState->readerName);
1385 strncpy(lpcStripReader,
1386 sReadersContexts[i]->readerState->readerName,
1387 sizeof(lpcStripReader));
1389 lpcStripReader[strlen(lpcStripReader) - 6] =
'\0';
1391 rv = RFRemoveReader(lpcStripReader, sReadersContexts[i]->port,
1392 REMOVE_READER_NO_FLAG);
1395 Log2(PCSC_LOG_ERROR,
"RFRemoveReader error: %s", rv2text(rv));
1398 free(sReadersContexts[i]);
1399 sReadersContexts[i] = NULL;
1416void RFWaitForReaderInit(
void)
1422 need_to_wait =
false;
1426 if (sReadersContexts[i]->vHandle != NULL)
1430 == sReadersContexts[i]->readerState->cardAtrLength)
1432 Log2(PCSC_LOG_DEBUG,
"Waiting init for reader: %s",
1433 sReadersContexts[i]->readerState->readerName);
1434 need_to_wait =
true;
1441 }
while (need_to_wait);
1446int RFStartSerialReaders(
const char *readerconf)
1452 ConfigFile = strdup(readerconf);
1454 rv = DBGetReaderListDir(readerconf, &reader_list);
1457 if (NULL == reader_list)
1464 (void)RFAddReader(reader_list[i].pcFriendlyname,
1465 reader_list[i].channelId,
1466 reader_list[i].pcLibpath, reader_list[i].pcDevicename);
1470 ConfigFileCRC += reader_list[i].pcFriendlyname[j];
1471 for (j=0; j<reader_list[i].
pcLibpath[j]; j++)
1472 ConfigFileCRC += reader_list[i].pcLibpath[j];
1474 ConfigFileCRC += reader_list[i].pcDevicename[j];
1477 free(reader_list[i].pcFriendlyname);
1478 free(reader_list[i].pcLibpath);
1479 free(reader_list[i].pcDevicename);
1486void RFReCheckReaderConf(
void)
1491 (void)DBGetReaderListDir(ConfigFile, &reader_list);
1494 if (NULL == reader_list)
1504 crc += reader_list[i].pcFriendlyname[j];
1505 for (j=0; j<reader_list[i].
pcLibpath[j]; j++)
1506 crc += reader_list[i].pcLibpath[j];
1508 crc += reader_list[i].pcDevicename[j];
1512 if (crc != ConfigFileCRC)
1514 Log2(PCSC_LOG_CRITICAL,
1515 "configuration file: %s has been modified. Recheck canceled",
1523 char present =
false;
1525 Log2(PCSC_LOG_DEBUG,
"refresh reader: %s",
1526 reader_list[i].pcFriendlyname);
1531 if (sReadersContexts[r]->vHandle != 0)
1533 char lpcStripReader[MAX_READERNAME];
1537 strncpy(lpcStripReader,
1538 sReadersContexts[i]->readerState->readerName,
1539 sizeof(lpcStripReader));
1540 tmplen = strlen(lpcStripReader);
1541 lpcStripReader[tmplen - 6] = 0;
1543 if ((strcmp(reader_list[i].pcFriendlyname, lpcStripReader) == 0)
1544 && (reader_list[r].channelId == sReadersContexts[i]->port))
1555 Log2(PCSC_LOG_INFO,
"Reader %s disappeared",
1556 reader_list[i].pcFriendlyname);
1557 (void)RFRemoveReader(reader_list[i].pcFriendlyname,
1558 reader_list[r].channelId, REMOVE_READER_NO_FLAG);
1567 (void)RFAddReader(reader_list[i].pcFriendlyname,
1568 reader_list[i].channelId, reader_list[i].pcLibpath,
1569 reader_list[i].pcDevicename);
1572 free(reader_list[i].pcFriendlyname);
1573 free(reader_list[i].pcLibpath);
1574 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)
Gets 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.