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];
878 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);
1027 (void)pthread_mutex_lock(&LockMutex);
1028 rv = RFCheckSharing(hCard, rContext);
1034 (void)pthread_mutex_unlock(&LockMutex);
1043 (void)pthread_mutex_lock(&LockMutex);
1044 rv = RFCheckSharing(hCard, rContext);
1067 (void)pthread_mutex_unlock(&LockMutex);
1076 (void)pthread_mutex_lock(&LockMutex);
1077 rv = RFCheckSharing(hCard, rContext);
1083 (void)pthread_mutex_unlock(&LockMutex);
1094 Log3(PCSC_LOG_INFO,
"Attempting startup of %s using %s",
1097#ifndef PCSCLITE_STATIC_DRIVER
1099 rv = RFLoadReader(rContext);
1102 Log2(PCSC_LOG_ERROR,
"RFLoadReader failed: 0x%lX", rv);
1107 rv = RFBindFunctions(rContext);
1111 Log2(PCSC_LOG_ERROR,
"RFBindFunctions failed: 0x%lX", rv);
1112 (void)RFUnloadReader(rContext);
1117 rContext->
vHandle = RFInitializeReader;
1125 int log_level = PCSC_LOG_CRITICAL;
1131 log_level = PCSC_LOG_INFO;
1135 Log3(log_level,
"Open Port 0x%X Failed (%s)",
1140 rContext->
slot = -1;
1148 Log2(PCSC_LOG_INFO,
"Attempting shutdown of %s.",
1152 if (rContext->
slot != -1)
1155 (void)RFUnBindFunctions(rContext);
1156 (void)RFUnloadReader(rContext);
1194 ret = RFReaderInfoById(randHandle, &dummy_reader);
1196 UNREF_READER(dummy_reader)
1207 int listLength, lrv;
1212 listLength = list_size(&rContext->handlesList);
1215 if (listLength >= maxReaderHandles)
1217 Log2(PCSC_LOG_CRITICAL,
1218 "Too many handles opened, exceeding configured max (%d)",
1225 if (NULL == newHandle)
1227 Log1(PCSC_LOG_CRITICAL,
"malloc failed");
1232 newHandle->
hCard = hCard;
1235 lrv = list_append(&rContext->handlesList, newHandle);
1239 Log2(PCSC_LOG_CRITICAL,
"list_append failed with return value: %d",
1255 currentHandle = list_seek(&rContext->handlesList, &hCard);
1256 if (NULL == currentHandle)
1258 Log2(PCSC_LOG_CRITICAL,
"list_seek failed to locate hCard=%lX", hCard);
1263 lrv = list_delete(&rContext->handlesList, currentHandle);
1265 Log2(PCSC_LOG_CRITICAL,
1266 "list_delete failed with return value: %d", lrv);
1268 free(currentHandle);
1277void RFSetReaderEventState(
READER_CONTEXT * rContext, DWORD dwEvent)
1280 int list_index, listSize;
1284 listSize = list_size(&rContext->handlesList);
1286 for (list_index = 0; list_index < listSize; list_index++)
1288 currentHandle = list_get_at(&rContext->handlesList, list_index);
1289 if (NULL == currentHandle)
1291 Log2(PCSC_LOG_CRITICAL,
"list_get_at failed at index %d",
1314 DWORD dwEventStatus;
1317 currentHandle = list_seek(&rContext->handlesList, &hCard);
1319 if (NULL == currentHandle)
1322 Log2(PCSC_LOG_CRITICAL,
"list_seek failed for hCard 0x%lX", hCard);
1327 switch(dwEventStatus)
1353 currentHandle = list_seek(&rContext->handlesList, &hCard);
1355 if (NULL == currentHandle)
1375void RFCleanupReaders(
void)
1379 Log1(PCSC_LOG_INFO,
"entering cleaning function");
1382 if (sReadersContexts[i]->vHandle != 0)
1385 char lpcStripReader[MAX_READERNAME];
1387 Log2(PCSC_LOG_INFO,
"Stopping reader: %s",
1388 sReadersContexts[i]->readerState->readerName);
1390 strncpy(lpcStripReader,
1391 sReadersContexts[i]->readerState->readerName,
1392 sizeof(lpcStripReader));
1394 lpcStripReader[strlen(lpcStripReader) - 6] =
'\0';
1396 rv = RFRemoveReader(lpcStripReader, sReadersContexts[i]->port,
1397 REMOVE_READER_NO_FLAG);
1400 Log2(PCSC_LOG_ERROR,
"RFRemoveReader error: %s", rv2text(rv));
1403 free(sReadersContexts[i]);
1404 sReadersContexts[i] = NULL;
1421void RFWaitForReaderInit(
void)
1427 need_to_wait =
false;
1431 if (sReadersContexts[i] && sReadersContexts[i]->vHandle != NULL)
1435 == sReadersContexts[i]->readerState->cardAtrLength)
1437 Log2(PCSC_LOG_DEBUG,
"Waiting init for reader: %s",
1438 sReadersContexts[i]->readerState->readerName);
1439 need_to_wait =
true;
1446 }
while (need_to_wait);
1451int RFStartSerialReaders(
const char *readerconf)
1457 ConfigFile = strdup(readerconf);
1459 rv = DBGetReaderListDir(readerconf, &reader_list);
1462 if (NULL == reader_list)
1469 (void)RFAddReader(reader_list[i].pcFriendlyname,
1470 reader_list[i].channelId,
1471 reader_list[i].pcLibpath, reader_list[i].pcDevicename);
1475 ConfigFileCRC += reader_list[i].pcFriendlyname[j];
1476 for (j=0; j<reader_list[i].
pcLibpath[j]; j++)
1477 ConfigFileCRC += reader_list[i].pcLibpath[j];
1479 ConfigFileCRC += reader_list[i].pcDevicename[j];
1482 free(reader_list[i].pcFriendlyname);
1483 free(reader_list[i].pcLibpath);
1484 free(reader_list[i].pcDevicename);
1491void RFReCheckReaderConf(
void)
1496 (void)DBGetReaderListDir(ConfigFile, &reader_list);
1499 if (NULL == reader_list)
1509 crc += reader_list[i].pcFriendlyname[j];
1510 for (j=0; j<reader_list[i].
pcLibpath[j]; j++)
1511 crc += reader_list[i].pcLibpath[j];
1513 crc += reader_list[i].pcDevicename[j];
1517 if (crc != ConfigFileCRC)
1519 Log2(PCSC_LOG_CRITICAL,
1520 "configuration file: %s has been modified. Recheck canceled",
1528 char present =
false;
1530 Log2(PCSC_LOG_DEBUG,
"refresh reader: %s",
1531 reader_list[i].pcFriendlyname);
1536 if (sReadersContexts[r]->vHandle != 0)
1538 char lpcStripReader[MAX_READERNAME];
1542 strncpy(lpcStripReader,
1543 sReadersContexts[i]->readerState->readerName,
1544 sizeof(lpcStripReader));
1545 tmplen = strlen(lpcStripReader);
1546 lpcStripReader[tmplen - 6] = 0;
1548 if ((strcmp(reader_list[i].pcFriendlyname, lpcStripReader) == 0)
1549 && (reader_list[r].channelId == sReadersContexts[i]->port))
1560 Log2(PCSC_LOG_INFO,
"Reader %s disappeared",
1561 reader_list[i].pcFriendlyname);
1562 (void)RFRemoveReader(reader_list[i].pcFriendlyname,
1563 reader_list[r].channelId, REMOVE_READER_NO_FLAG);
1572 (void)RFAddReader(reader_list[i].pcFriendlyname,
1573 reader_list[i].channelId, reader_list[i].pcLibpath,
1574 reader_list[i].pcDevicename);
1577 free(reader_list[i].pcFriendlyname);
1578 free(reader_list[i].pcLibpath);
1579 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
pthread_t pthThread
Event polling thread.
_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
_Atomic int LockCount
number of recursive locks
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.
_Atomic LPVOID vHandle
Dlopen handle.
char * pcFriendlyname
FRIENDLYNAME.
char * pcDevicename
DEVICENAME.
Define an exported public reader state structure so each application gets instant notification of cha...
_Atomic int32_t readerSharing
PCSCLITE_SHARING_* sharing status.
char readerName[MAX_READERNAME]
reader name
uint32_t cardProtocol
SCARD_PROTOCOL_* value.
UCHAR cardAtr[MAX_ATR_SIZE]
ATR.
uint32_t eventCounter
number of card events
_Atomic uint32_t cardAtrLength
ATR length.
uint32_t readerState
SCARD_* bit field.
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.