65#include "configfile.h"
75static int maxReaderHandles = PCSC_MAX_READER_HANDLES;
76static DWORD dwNumReadersContexts = 0;
78static char *ConfigFile = NULL;
79static int ConfigFileCRC = 0;
81static pthread_mutex_t LockMutex = PTHREAD_MUTEX_INITIALIZER;
83#define IDENTITY_SHIFT 16
86static 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);
132LONG RFAllocateReaderSpace(
unsigned int customMaxReaderHandles)
136 if (customMaxReaderHandles != 0)
137 maxReaderHandles = customMaxReaderHandles;
143 sReadersContexts[i]->
vHandle = NULL;
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 (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]);
375 int log_level = PCSC_LOG_ERROR;
377 log_level = PCSC_LOG_INFO;
380 Log2(log_level,
"%s init failed.", readerName);
381 (void)RFRemoveReader(readerName, port);
387 RESPONSECODE (*fct)(DWORD, int) = NULL;
389 dwGetSize =
sizeof(fct);
395 Log1(PCSC_LOG_INFO,
"Using the pcscd polling thread");
400 Log1(PCSC_LOG_INFO,
"Using the reader polling thread");
403 rv = EHSpawnEventHandler(sReadersContexts[dwContext]);
406 Log2(PCSC_LOG_ERROR,
"%s init failed.", readerName);
407 (void)RFRemoveReader(readerName, port);
413 dwGetSize =
sizeof(ucGetData);
417 int nbSlots = ucGetData[0];
418 if (rv !=
IFD_SUCCESS || dwGetSize != 1 || nbSlots == 0)
433 for (j = 1; j < nbSlots; j++)
435 char *tmpReader = NULL;
436 DWORD dwContextB = 0;
437 RESPONSECODE (*fct)(DWORD, int) = NULL;
442 if (sReadersContexts[i]->vHandle == 0)
452 RFRemoveReader(readerName, port);
459 sReadersContexts[dwContext]->readerState->readerName,
460 sizeof(sReadersContexts[dwContextB]->readerState->readerName));
461 snprintf(tmpReader + strlen(tmpReader) - 2, 3,
"%02X", j);
463 sReadersContexts[dwContextB]->
library =
464 sReadersContexts[dwContext]->
library;
465 sReadersContexts[dwContextB]->
device =
466 sReadersContexts[dwContext]->
device;
467 sReadersContexts[dwContextB]->
version =
468 sReadersContexts[dwContext]->
version;
469 sReadersContexts[dwContextB]->
port =
470 sReadersContexts[dwContext]->
port;
471 sReadersContexts[dwContextB]->
vHandle =
472 sReadersContexts[dwContext]->
vHandle;
473 sReadersContexts[dwContextB]->
mMutex =
474 sReadersContexts[dwContext]->
mMutex;
475 sReadersContexts[dwContextB]->
pMutex =
476 sReadersContexts[dwContext]->
pMutex;
477 sReadersContexts[dwContextB]->
slot =
478 sReadersContexts[dwContext]->
slot + j;
485 sReadersContexts[dwContextB]->
pFeeds =
486 sReadersContexts[dwContext]->
pFeeds;
489 *(sReadersContexts[dwContextB])->pFeeds += 1;
491 sReadersContexts[dwContextB]->
contexts = 0;
492 sReadersContexts[dwContextB]->
hLockId = 0;
493 sReadersContexts[dwContextB]->
LockCount = 0;
495 lrv = list_init(&sReadersContexts[dwContextB]->handlesList);
498 Log2(PCSC_LOG_CRITICAL,
"list_init failed with return value: %d", lrv);
502 lrv = list_attributes_seeker(&sReadersContexts[dwContextB]->handlesList,
503 RDR_CLIHANDLES_seeker);
506 Log2(PCSC_LOG_CRITICAL,
507 "list_attributes_seeker failed with return value: %d", lrv);
511 (void)pthread_mutex_init(&sReadersContexts[dwContextB]->handlesList_lock, NULL);
512 (void)pthread_mutex_init(&sReadersContexts[dwContextB]->powerState_lock,
517 (void)pthread_mutex_init(&sReadersContexts[dwContextB]->reference_lock,
519 sReadersContexts[dwContextB]->
reference = 1;
522 dwGetSize =
sizeof(ucThread);
526 if (rv ==
IFD_SUCCESS && dwGetSize == 1 && ucThread[0] == 1)
528 Log1(PCSC_LOG_INFO,
"Driver is slot thread safe");
530 sReadersContexts[dwContextB]->
library =
531 strdup(sReadersContexts[dwContext]->library);
532 sReadersContexts[dwContextB]->
device =
533 strdup(sReadersContexts[dwContext]->device);
534 sReadersContexts[dwContextB]->
mMutex =
535 malloc(
sizeof(pthread_mutex_t));
536 (void)pthread_mutex_init(sReadersContexts[dwContextB]->mMutex,
539 sReadersContexts[dwContextB]->
pMutex = malloc(
sizeof(
int));
540 *(sReadersContexts[dwContextB])->pMutex = 1;
543 *(sReadersContexts[dwContextB])->pMutex += 1;
545 dwNumReadersContexts += 1;
547 rv = RFInitializeReader(sReadersContexts[dwContextB]);
551 (void)RFRemoveReader(readerName, port);
556 dwGetSize =
sizeof(fct);
562 Log1(PCSC_LOG_INFO,
"Using the pcscd polling thread");
567 Log1(PCSC_LOG_INFO,
"Using the reader polling thread");
570 rv = EHSpawnEventHandler(sReadersContexts[dwContextB]);
573 Log2(PCSC_LOG_ERROR,
"%s init failed.", readerName);
574 (void)RFRemoveReader(readerName, port);
582LONG RFRemoveReader(
const char *readerName,
int port)
584 char lpcStripReader[MAX_READERNAME];
591 if (readerName == NULL)
595 extend = getenv(
"PCSCLITE_FILTER_EXTEND_READER_NAMES");
597 extend_size = strlen(extend);
602 if (sReadersContexts[i] && (sReadersContexts[i]->vHandle != 0))
604 strncpy(lpcStripReader,
605 sReadersContexts[i]->readerState->readerName,
606 sizeof(lpcStripReader));
607 lpcStripReader[strlen(lpcStripReader) - 6 - extend_size] = 0;
610 if ((strncmp(readerName, lpcStripReader, MAX_READERNAME -
sizeof(
" 00 00")) == 0)
611 && (port == sReadersContexts[i]->port))
614 UNREF_READER(sReadersContexts[i])
625 if (sContext -> pthThread)
626 EHDestroyEventHandler(sContext);
628 if ((NULL == sContext->
pMutex) || (NULL == sContext->
pFeeds))
631 "Trying to remove an already removed driver");
635 RFUnInitializeReader(sContext);
640 if (0 == *sContext->
pMutex)
642 (void)pthread_mutex_destroy(sContext->
mMutex);
654 if (*sContext->
pFeeds == 0)
670 while (list_size(&sContext->handlesList) != 0)
675 currentHandle = list_get_at(&sContext->handlesList, 0);
676 lrv = list_delete_at(&sContext->handlesList, 0);
678 Log2(PCSC_LOG_CRITICAL,
679 "list_delete_at failed with return value: %d", lrv);
685 list_destroy(&sContext->handlesList);
686 dwNumReadersContexts -= 1;
694LONG RFSetReaderName(
READER_CONTEXT * rContext,
const char *readerName,
695 const char *libraryName,
int port)
699 int currentDigit = -1;
700 int supportedChannels = 0;
703 const char *extend =
"";
707 usedDigits[i] = FALSE;
709 if (dwNumReadersContexts != 0)
713 if (sReadersContexts[i]->vHandle != 0)
715 if (strcmp(sReadersContexts[i]->library, libraryName) == 0)
721 valueLength =
sizeof(tagValue);
724 &valueLength, tagValue);
729 supportedChannels = tagValue[0];
731 "Support %d simultaneous readers", tagValue[0]);
734 supportedChannels = 1;
737 if ((((sReadersContexts[i]->port & 0xFFFF0000) ==
738 PCSCLITE_HP_BASE_PORT)
739 && (sReadersContexts[i]->port != port))
740 || (supportedChannels > 1))
756 currentDigit = strtol(reader + strlen(reader) - 5, NULL, 16);
759 usedDigits[currentDigit] = TRUE;
770 if (currentDigit != -1)
775 if (usedDigits[i] == FALSE)
785 if (i >= supportedChannels)
787 Log3(PCSC_LOG_ERROR,
"Driver %s does not support more than "
788 "%d reader(s). Maybe the driver should support "
789 "TAG_IFD_SIMULTANEOUS_ACCESS", libraryName, supportedChannels);
795 extend = getenv(
"PCSCLITE_FILTER_EXTEND_READER_NAMES");
802 readerName, extend, i);
805 rContext->
slot = i << 16;
810LONG RFReaderInfo(
const char *readerName,
READER_CONTEXT ** sReader)
814 if (readerName == NULL)
819 if (sReadersContexts[i]->vHandle != 0)
821 if (strcmp(readerName,
822 sReadersContexts[i]->readerState->readerName) == 0)
825 REF_READER(sReadersContexts[i])
827 *sReader = sReadersContexts[i];
842 if (sReadersContexts[i]->vHandle != 0)
845 (void)pthread_mutex_lock(&sReadersContexts[i]->handlesList_lock);
846 currentHandle = list_seek(&sReadersContexts[i]->handlesList,
848 (void)pthread_mutex_unlock(&sReadersContexts[i]->handlesList_lock);
849 if (currentHandle != NULL)
852 REF_READER(sReadersContexts[i])
854 *sReader = sReadersContexts[i];
867 Log2(PCSC_LOG_INFO,
"Reusing already loaded driver for %s",
881 rv = DYN_GetAddress(rContext->
vHandle, &f,
"IFDHCreateChannelByName", TRUE);
885 rContext->
version = IFD_HVERSION_3_0;
889 rv = DYN_GetAddress(rContext->
vHandle, &f,
"IFDHCreateChannel", FALSE);
893 rContext->
version = IFD_HVERSION_2_0;
898 Log1(PCSC_LOG_CRITICAL,
"IFDHandler functions missing");
903 if (rContext->
version == IFD_HVERSION_2_0)
906#define GET_ADDRESS_OPTIONALv2(s, code) \
909 int rvl = DYN_GetAddress(rContext->vHandle, &f1, "IFDH" #s, FALSE); \
910 if (SCARD_S_SUCCESS != rvl) \
914 rContext->psFunctions.psFunctions_v2.pvf ## s = f1; \
917#define GET_ADDRESSv2(s) \
918 GET_ADDRESS_OPTIONALv2(s, \
919 Log1(PCSC_LOG_CRITICAL, "IFDHandler functions missing: " #s ); \
922 Log1(PCSC_LOG_INFO,
"Loading IFD Handler 2.0");
924 GET_ADDRESSv2(CreateChannel)
925 GET_ADDRESSv2(CloseChannel)
926 GET_ADDRESSv2(GetCapabilities)
927 GET_ADDRESSv2(SetCapabilities)
928 GET_ADDRESSv2(PowerICC)
929 GET_ADDRESSv2(TransmitToICC)
930 GET_ADDRESSv2(ICCPresence)
931 GET_ADDRESS_OPTIONALv2(SetProtocolParameters, )
933 GET_ADDRESSv2(Control)
935 else if (rContext->version == IFD_HVERSION_3_0)
938#define GET_ADDRESS_OPTIONALv3(s, code) \
941 int rvl = DYN_GetAddress(rContext->vHandle, &f1, "IFDH" #s, FALSE); \
942 if (SCARD_S_SUCCESS != rvl) \
946 rContext->psFunctions.psFunctions_v3.pvf ## s = f1; \
949#define GET_ADDRESSv3(s) \
950 GET_ADDRESS_OPTIONALv3(s, \
951 Log1(PCSC_LOG_CRITICAL, "IFDHandler functions missing: " #s ); \
954 Log1(PCSC_LOG_INFO,
"Loading IFD Handler 3.0");
956 GET_ADDRESSv2(CreateChannel)
957 GET_ADDRESSv2(CloseChannel)
958 GET_ADDRESSv2(GetCapabilities)
959 GET_ADDRESSv2(SetCapabilities)
960 GET_ADDRESSv2(PowerICC)
961 GET_ADDRESSv2(TransmitToICC)
962 GET_ADDRESSv2(ICCPresence)
963 GET_ADDRESS_OPTIONALv2(SetProtocolParameters, )
965 GET_ADDRESSv3(CreateChannelByName)
966 GET_ADDRESSv3(Control)
971 Log1(PCSC_LOG_CRITICAL,
"IFD Handler not 1.0/2.0 or 3.0");
989 if (*rContext->
pFeeds == 1)
991 Log1(PCSC_LOG_INFO,
"Unloading reader driver.");
992 (void)DYN_CloseLibrary(&rContext->
vHandle);
1012 (void)pthread_mutex_lock(&LockMutex);
1013 rv = RFCheckSharing(hCard, rContext);
1019 (void)pthread_mutex_unlock(&LockMutex);
1028 (void)pthread_mutex_lock(&LockMutex);
1029 rv = RFCheckSharing(hCard, rContext);
1052 (void)pthread_mutex_unlock(&LockMutex);
1061 (void)pthread_mutex_lock(&LockMutex);
1062 rv = RFCheckSharing(hCard, rContext);
1068 (void)pthread_mutex_unlock(&LockMutex);
1079 Log3(PCSC_LOG_INFO,
"Attempting startup of %s using %s",
1082#ifndef PCSCLITE_STATIC_DRIVER
1084 rv = RFLoadReader(rContext);
1087 Log2(PCSC_LOG_ERROR,
"RFLoadReader failed: 0x%lX", rv);
1092 rv = RFBindFunctions(rContext);
1096 Log2(PCSC_LOG_ERROR,
"RFBindFunctions failed: 0x%lX", rv);
1097 (void)RFUnloadReader(rContext);
1102 rContext->
vHandle = RFInitializeReader;
1110 int log_level = PCSC_LOG_CRITICAL;
1116 log_level = PCSC_LOG_INFO;
1120 Log3(log_level,
"Open Port 0x%X Failed (%s)",
1125 rContext->
slot = -1;
1133 Log2(PCSC_LOG_INFO,
"Attempting shutdown of %s.",
1137 if (rContext->
slot != -1)
1140 (void)RFUnBindFunctions(rContext);
1141 (void)RFUnloadReader(rContext);
1178 ret = RFReaderInfoById(randHandle, &dummy_reader);
1180 UNREF_READER(dummy_reader)
1191 int listLength, lrv;
1196 listLength = list_size(&rContext->handlesList);
1199 if (listLength >= maxReaderHandles)
1201 Log2(PCSC_LOG_CRITICAL,
1202 "Too many handles opened, exceeding configured max (%d)",
1209 if (NULL == newHandle)
1211 Log1(PCSC_LOG_CRITICAL,
"malloc failed");
1216 newHandle->
hCard = hCard;
1219 lrv = list_append(&rContext->handlesList, newHandle);
1223 Log2(PCSC_LOG_CRITICAL,
"list_append failed with return value: %d",
1239 currentHandle = list_seek(&rContext->handlesList, &hCard);
1240 if (NULL == currentHandle)
1242 Log2(PCSC_LOG_CRITICAL,
"list_seek failed to locate hCard=%lX", hCard);
1247 lrv = list_delete(&rContext->handlesList, currentHandle);
1249 Log2(PCSC_LOG_CRITICAL,
1250 "list_delete failed with return value: %d", lrv);
1252 free(currentHandle);
1261void RFSetReaderEventState(
READER_CONTEXT * rContext, DWORD dwEvent)
1264 int list_index, listSize;
1268 listSize = list_size(&rContext->handlesList);
1270 for (list_index = 0; list_index < listSize; list_index++)
1272 currentHandle = list_get_at(&rContext->handlesList, list_index);
1273 if (NULL == currentHandle)
1275 Log2(PCSC_LOG_CRITICAL,
"list_get_at failed at index %d",
1300 currentHandle = list_seek(&rContext->handlesList, &hCard);
1302 if (NULL == currentHandle)
1305 Log2(PCSC_LOG_CRITICAL,
"list_seek failed for hCard 0x%lX", hCard);
1335 currentHandle = list_seek(&rContext->handlesList, &hCard);
1337 if (NULL == currentHandle)
1357void RFCleanupReaders(
void)
1361 Log1(PCSC_LOG_INFO,
"entering cleaning function");
1364 if (sReadersContexts[i]->vHandle != 0)
1367 char lpcStripReader[MAX_READERNAME];
1369 Log2(PCSC_LOG_INFO,
"Stopping reader: %s",
1370 sReadersContexts[i]->readerState->readerName);
1372 strncpy(lpcStripReader,
1373 sReadersContexts[i]->readerState->readerName,
1374 sizeof(lpcStripReader));
1376 lpcStripReader[strlen(lpcStripReader) - 6] =
'\0';
1378 rv = RFRemoveReader(lpcStripReader, sReadersContexts[i]->port);
1381 Log2(PCSC_LOG_ERROR,
"RFRemoveReader error: 0x%08lX", rv);
1383 free(sReadersContexts[i]);
1385 sReadersContexts[i] = NULL;
1403void RFWaitForReaderInit(
void)
1405 int i, need_to_wait;
1409 need_to_wait = FALSE;
1413 if (sReadersContexts[i]->vHandle != NULL)
1417 == sReadersContexts[i]->readerState->cardAtrLength)
1419 Log2(PCSC_LOG_DEBUG,
"Waiting init for reader: %s",
1420 sReadersContexts[i]->readerState->readerName);
1421 need_to_wait = TRUE;
1428 }
while (need_to_wait);
1433int RFStartSerialReaders(
const char *readerconf)
1439 ConfigFile = strdup(readerconf);
1441 rv = DBGetReaderListDir(readerconf, &reader_list);
1444 if (NULL == reader_list)
1451 (void)RFAddReader(reader_list[i].pcFriendlyname,
1452 reader_list[i].channelId,
1453 reader_list[i].pcLibpath, reader_list[i].pcDevicename);
1457 ConfigFileCRC += reader_list[i].pcFriendlyname[j];
1458 for (j=0; j<reader_list[i].
pcLibpath[j]; j++)
1459 ConfigFileCRC += reader_list[i].pcLibpath[j];
1461 ConfigFileCRC += reader_list[i].pcDevicename[j];
1464 free(reader_list[i].pcFriendlyname);
1465 free(reader_list[i].pcLibpath);
1466 free(reader_list[i].pcDevicename);
1473void RFReCheckReaderConf(
void)
1478 (void)DBGetReaderListDir(ConfigFile, &reader_list);
1481 if (NULL == reader_list)
1491 crc += reader_list[i].pcFriendlyname[j];
1492 for (j=0; j<reader_list[i].
pcLibpath[j]; j++)
1493 crc += reader_list[i].pcLibpath[j];
1495 crc += reader_list[i].pcDevicename[j];
1499 if (crc != ConfigFileCRC)
1501 Log2(PCSC_LOG_CRITICAL,
1502 "configuration file: %s has been modified. Recheck canceled",
1510 char present = FALSE;
1512 Log2(PCSC_LOG_DEBUG,
"refresh reader: %s",
1513 reader_list[i].pcFriendlyname);
1518 if (sReadersContexts[r]->vHandle != 0)
1520 char lpcStripReader[MAX_READERNAME];
1524 strncpy(lpcStripReader,
1525 sReadersContexts[i]->readerState->readerName,
1526 sizeof(lpcStripReader));
1527 tmplen = strlen(lpcStripReader);
1528 lpcStripReader[tmplen - 6] = 0;
1530 if ((strcmp(reader_list[i].pcFriendlyname, lpcStripReader) == 0)
1531 && (reader_list[r].channelId == sReadersContexts[i]->port))
1542 Log2(PCSC_LOG_INFO,
"Reader %s disappeared",
1543 reader_list[i].pcFriendlyname);
1544 (void)RFRemoveReader(reader_list[i].pcFriendlyname,
1545 reader_list[r].channelId);
1554 (void)RFAddReader(reader_list[i].pcFriendlyname,
1555 reader_list[i].channelId, reader_list[i].pcLibpath,
1556 reader_list[i].pcDevicename);
1559 free(reader_list[i].pcFriendlyname);
1560 free(reader_list[i].pcLibpath);
1561 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
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.
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)
This keeps track of a list of currently available reader structures.
DWORD dwEventStatus
Recent event that must be sent.
SCARDHANDLE hCard
hCard for this connection
volatile SCARDHANDLE hLockId
Lock Id.
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
union ReaderContext::@3 psFunctions
driver functions
int slot
Current Reader Slot.
int * pFeeds
Number of shared client to lib.
int * pMutex
Number of client to mutex.
pthread_mutex_t reference_lock
reference mutex
int version
IFD Handler version number.
int reference
number of users of the structure
int32_t contexts
Number of open contexts.
pthread_mutex_t handlesList_lock
lock for the above list
char * library
Library Path.
struct pubReaderStatesList * readerState
link to the reader state
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(int, int)
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.