52 #include <sys/types.h>
68 #include "configfile.h"
78 static int maxReaderHandles = PCSC_MAX_READER_HANDLES;
79 static DWORD dwNumReadersContexts = 0;
81 static char *ConfigFile = NULL;
82 static int ConfigFileCRC = 0;
84 static pthread_mutex_t LockMutex = PTHREAD_MUTEX_INITIALIZER;
86 #define IDENTITY_SHIFT 16
89 static int RDR_CLIHANDLES_seeker(
const void *el,
const void *key)
93 if ((el == NULL) || (key == NULL))
95 Log3(PCSC_LOG_CRITICAL,
96 "RDR_CLIHANDLES_seeker called with NULL pointer: el=%p, key=%p",
130 removeReader(sReader);
135 LONG RFAllocateReaderSpace(
unsigned int customMaxReaderHandles)
139 if (customMaxReaderHandles != 0)
140 maxReaderHandles = customMaxReaderHandles;
146 sReadersContexts[i]->
vHandle = NULL;
149 memset(readerStates[i].readerName, 0, MAX_READERNAME);
156 sReadersContexts[i]->
readerState = &readerStates[i];
160 return EHInitializeEventStructures();
163 LONG RFAddReader(
const char *readerNameLong,
int port,
const char *library,
166 DWORD dwContext = 0, dwGetSize;
167 UCHAR ucGetData[1], ucThread[1];
171 char *readerName = NULL;
173 if ((readerNameLong == NULL) || (library == NULL) || (device == NULL))
177 readerName = alloca(strlen(readerNameLong)+1);
178 strcpy(readerName, readerNameLong);
181 if (strlen(readerName) > MAX_READERNAME -
sizeof(
" 00 00"))
184 "Reader name too long: %zd chars instead of max %zd. Truncating!",
185 strlen(readerName), MAX_READERNAME -
sizeof(
" 00 00"));
186 readerName[MAX_READERNAME -
sizeof(
" 00 00")] =
'\0';
190 if (dwNumReadersContexts != 0)
194 if (sReadersContexts[i]->vHandle != 0)
196 char lpcStripReader[MAX_READERNAME];
200 strncpy(lpcStripReader,
201 sReadersContexts[i]->readerState->readerName,
202 sizeof(lpcStripReader));
203 tmplen = strlen(lpcStripReader);
204 lpcStripReader[tmplen - 6] = 0;
206 if ((strcmp(readerName, lpcStripReader) == 0) &&
207 (port == sReadersContexts[i]->port))
209 Log1(PCSC_LOG_ERROR,
"Duplicate reader found.");
219 if (sReadersContexts[i]->vHandle == 0)
226 if (i == PCSCLITE_MAX_READERS_CONTEXTS)
233 parentNode = RFSetReaderName(sReadersContexts[dwContext], readerName,
238 sReadersContexts[dwContext]->
library = strdup(library);
239 sReadersContexts[dwContext]->
device = strdup(device);
240 sReadersContexts[dwContext]->
version = 0;
241 sReadersContexts[dwContext]->
port = port;
242 sReadersContexts[dwContext]->
mMutex = NULL;
243 sReadersContexts[dwContext]->
contexts = 0;
244 sReadersContexts[dwContext]->
pthThread = 0;
245 sReadersContexts[dwContext]->
hLockId = 0;
246 sReadersContexts[dwContext]->
LockCount = 0;
247 sReadersContexts[dwContext]->
vHandle = NULL;
248 sReadersContexts[dwContext]->
pFeeds = NULL;
249 sReadersContexts[dwContext]->
pMutex = NULL;
252 lrv = list_init(&sReadersContexts[dwContext]->handlesList);
255 Log2(PCSC_LOG_CRITICAL,
"list_init failed with return value: %d", lrv);
259 lrv = list_attributes_seeker(&sReadersContexts[dwContext]->handlesList,
260 RDR_CLIHANDLES_seeker);
263 Log2(PCSC_LOG_CRITICAL,
264 "list_attributes_seeker failed with return value: %d", lrv);
268 (void)pthread_mutex_init(&sReadersContexts[dwContext]->handlesList_lock,
271 (void)pthread_mutex_init(&sReadersContexts[dwContext]->powerState_lock,
276 (void)pthread_mutex_init(&sReadersContexts[dwContext]->reference_lock,
278 sReadersContexts[dwContext]->
reference = 1;
281 if (parentNode >= 0 && parentNode < PCSCLITE_MAX_READERS_CONTEXTS)
283 sReadersContexts[dwContext]->
pFeeds =
284 sReadersContexts[parentNode]->
pFeeds;
285 *(sReadersContexts[dwContext])->pFeeds += 1;
286 sReadersContexts[dwContext]->
vHandle =
287 sReadersContexts[parentNode]->
vHandle;
288 sReadersContexts[dwContext]->
mMutex =
289 sReadersContexts[parentNode]->
mMutex;
290 sReadersContexts[dwContext]->
pMutex =
291 sReadersContexts[parentNode]->
pMutex;
294 dwGetSize =
sizeof(ucThread);
298 if (rv ==
IFD_SUCCESS && dwGetSize == 1 && ucThread[0] == 1)
300 Log1(PCSC_LOG_INFO,
"Driver is thread safe");
301 sReadersContexts[dwContext]->
mMutex = NULL;
302 sReadersContexts[dwContext]->
pMutex = NULL;
305 *(sReadersContexts[dwContext])->pMutex += 1;
308 if (sReadersContexts[dwContext]->pFeeds == NULL)
310 sReadersContexts[dwContext]->
pFeeds = malloc(
sizeof(
int));
316 *(sReadersContexts[dwContext])->pFeeds = 1;
319 if (sReadersContexts[dwContext]->mMutex == 0)
321 sReadersContexts[dwContext]->
mMutex =
322 malloc(
sizeof(pthread_mutex_t));
323 (void)pthread_mutex_init(sReadersContexts[dwContext]->mMutex, NULL);
326 if (sReadersContexts[dwContext]->pMutex == NULL)
328 sReadersContexts[dwContext]->
pMutex = malloc(
sizeof(
int));
329 *(sReadersContexts[dwContext])->pMutex = 1;
332 dwNumReadersContexts += 1;
334 rv = RFInitializeReader(sReadersContexts[dwContext]);
338 Log2(PCSC_LOG_ERROR,
"%s init failed.", readerName);
339 (void)RFRemoveReader(readerName, port);
345 RESPONSECODE (*fct)(DWORD, int) = NULL;
347 dwGetSize =
sizeof(fct);
353 Log1(PCSC_LOG_INFO,
"Using the pcscd polling thread");
358 Log1(PCSC_LOG_INFO,
"Using the reader polling thread");
361 rv = EHSpawnEventHandler(sReadersContexts[dwContext]);
364 Log2(PCSC_LOG_ERROR,
"%s init failed.", readerName);
365 (void)RFRemoveReader(readerName, port);
371 dwGetSize =
sizeof(ucGetData);
375 if (rv !=
IFD_SUCCESS || dwGetSize != 1 || ucGetData[0] == 0)
380 if (rv ==
IFD_SUCCESS && dwGetSize == 1 && ucGetData[0] == 1)
390 for (j = 1; j < ucGetData[0]; j++)
392 char *tmpReader = NULL;
393 DWORD dwContextB = 0;
394 RESPONSECODE (*fct)(DWORD, int) = NULL;
399 if (sReadersContexts[i]->vHandle == 0)
406 if (i == PCSCLITE_MAX_READERS_CONTEXTS)
409 RFRemoveReader(readerName, port);
415 (void)strlcpy(tmpReader,
416 sReadersContexts[dwContext]->readerState->readerName,
418 snprintf(tmpReader + strlen(tmpReader) - 2, 3,
"%02X", j);
420 sReadersContexts[dwContextB]->
library =
421 sReadersContexts[dwContext]->
library;
422 sReadersContexts[dwContextB]->
device =
423 sReadersContexts[dwContext]->
device;
424 sReadersContexts[dwContextB]->
version =
425 sReadersContexts[dwContext]->
version;
426 sReadersContexts[dwContextB]->
port =
427 sReadersContexts[dwContext]->
port;
428 sReadersContexts[dwContextB]->
vHandle =
429 sReadersContexts[dwContext]->
vHandle;
430 sReadersContexts[dwContextB]->
mMutex =
431 sReadersContexts[dwContext]->
mMutex;
432 sReadersContexts[dwContextB]->
pMutex =
433 sReadersContexts[dwContext]->
pMutex;
434 sReadersContexts[dwContextB]->
slot =
435 sReadersContexts[dwContext]->
slot + j;
442 sReadersContexts[dwContextB]->
pFeeds =
443 sReadersContexts[dwContext]->
pFeeds;
446 *(sReadersContexts[dwContextB])->pFeeds += 1;
448 sReadersContexts[dwContextB]->
contexts = 0;
449 sReadersContexts[dwContextB]->
hLockId = 0;
450 sReadersContexts[dwContextB]->
LockCount = 0;
452 lrv = list_init(&sReadersContexts[dwContextB]->handlesList);
455 Log2(PCSC_LOG_CRITICAL,
"list_init failed with return value: %d", lrv);
459 lrv = list_attributes_seeker(&sReadersContexts[dwContextB]->handlesList,
460 RDR_CLIHANDLES_seeker);
463 Log2(PCSC_LOG_CRITICAL,
464 "list_attributes_seeker failed with return value: %d", lrv);
468 (void)pthread_mutex_init(&sReadersContexts[dwContextB]->handlesList_lock, NULL);
469 (void)pthread_mutex_init(&sReadersContexts[dwContextB]->powerState_lock,
474 (void)pthread_mutex_init(&sReadersContexts[dwContextB]->reference_lock,
476 sReadersContexts[dwContextB]->
reference = 1;
479 dwGetSize =
sizeof(ucThread);
483 if (rv ==
IFD_SUCCESS && dwGetSize == 1 && ucThread[0] == 1)
485 Log1(PCSC_LOG_INFO,
"Driver is slot thread safe");
487 sReadersContexts[dwContextB]->
library =
488 strdup(sReadersContexts[dwContext]->library);
489 sReadersContexts[dwContextB]->
device =
490 strdup(sReadersContexts[dwContext]->device);
491 sReadersContexts[dwContextB]->
mMutex =
492 malloc(
sizeof(pthread_mutex_t));
493 (void)pthread_mutex_init(sReadersContexts[dwContextB]->mMutex,
496 sReadersContexts[dwContextB]->
pMutex = malloc(
sizeof(
int));
497 *(sReadersContexts[dwContextB])->pMutex = 1;
500 *(sReadersContexts[dwContextB])->pMutex += 1;
502 dwNumReadersContexts += 1;
504 rv = RFInitializeReader(sReadersContexts[dwContextB]);
508 (void)RFRemoveReader(readerName, port);
513 dwGetSize =
sizeof(fct);
519 Log1(PCSC_LOG_INFO,
"Using the pcscd polling thread");
524 Log1(PCSC_LOG_INFO,
"Using the reader polling thread");
527 rv = EHSpawnEventHandler(sReadersContexts[dwContextB]);
530 Log2(PCSC_LOG_ERROR,
"%s init failed.", readerName);
531 (void)RFRemoveReader(readerName, port);
539 LONG RFRemoveReader(
const char *readerName,
int port)
541 char lpcStripReader[MAX_READERNAME];
544 if (readerName == NULL)
549 if (sReadersContexts[i]->vHandle != 0)
551 strncpy(lpcStripReader,
552 sReadersContexts[i]->readerState->readerName,
553 sizeof(lpcStripReader));
554 lpcStripReader[strlen(lpcStripReader) - 6] = 0;
557 if ((strncmp(readerName, lpcStripReader, MAX_READERNAME -
sizeof(
" 00 00")) == 0)
558 && (port == sReadersContexts[i]->port))
561 UNREF_READER(sReadersContexts[i])
575 if (sContext -> pthThread)
576 (void)EHDestroyEventHandler(sContext);
578 if ((NULL == sContext->
pMutex) || (NULL == sContext->
pFeeds))
581 "Trying to remove an already removed driver");
585 rv = RFUnInitializeReader(sContext);
592 if (0 == *sContext->
pMutex)
594 (void)pthread_mutex_destroy(sContext->
mMutex);
606 if (*sContext->
pFeeds == 0)
622 while (list_size(&sContext->handlesList) != 0)
627 currentHandle = list_get_at(&sContext->handlesList, 0);
628 lrv = list_delete_at(&sContext->handlesList, 0);
630 Log2(PCSC_LOG_CRITICAL,
631 "list_delete_at failed with return value: %d", lrv);
637 list_destroy(&sContext->handlesList);
638 dwNumReadersContexts -= 1;
647 LONG RFSetReaderName(
READER_CONTEXT * rContext,
const char *readerName,
648 const char *libraryName,
int port)
652 int currentDigit = -1;
653 int supportedChannels = 0;
659 usedDigits[i] = FALSE;
661 if (dwNumReadersContexts != 0)
665 if (sReadersContexts[i]->vHandle != 0)
667 if (strcmp(sReadersContexts[i]->library, libraryName) == 0)
673 valueLength =
sizeof(tagValue);
676 &valueLength, tagValue);
681 supportedChannels = tagValue[0];
683 "Support %d simultaneous readers", tagValue[0]);
686 supportedChannels = 1;
689 if ((((sReadersContexts[i]->port & 0xFFFF0000) ==
690 PCSCLITE_HP_BASE_PORT)
691 && (sReadersContexts[i]->port != port))
692 || (supportedChannels > 1))
708 currentDigit = strtol(reader + strlen(reader) - 5, NULL, 16);
711 usedDigits[currentDigit] = TRUE;
722 if (currentDigit != -1)
727 if (usedDigits[i] == FALSE)
731 if (i == PCSCLITE_MAX_READERS_CONTEXTS)
733 Log2(PCSC_LOG_ERROR,
"Max number of readers reached: %d", PCSCLITE_MAX_READERS_CONTEXTS);
737 if (i >= supportedChannels)
739 Log3(PCSC_LOG_ERROR,
"Driver %s does not support more than "
740 "%d reader(s). Maybe the driver should support "
741 "TAG_IFD_SIMULTANEOUS_ACCESS", libraryName, supportedChannels);
751 rContext->
slot = i << 16;
756 LONG RFReaderInfo(
const char *readerName,
READER_CONTEXT ** sReader)
760 if (readerName == NULL)
765 if (sReadersContexts[i]->vHandle != 0)
767 if (strcmp(readerName,
768 sReadersContexts[i]->readerState->readerName) == 0)
771 REF_READER(sReadersContexts[i])
773 *sReader = sReadersContexts[i];
788 if (sReadersContexts[i]->vHandle != 0)
791 (void)pthread_mutex_lock(&sReadersContexts[i]->handlesList_lock);
792 currentHandle = list_seek(&sReadersContexts[i]->handlesList,
794 (void)pthread_mutex_unlock(&sReadersContexts[i]->handlesList_lock);
795 if (currentHandle != NULL)
798 REF_READER(sReadersContexts[i])
800 *sReader = sReadersContexts[i];
813 Log2(PCSC_LOG_INFO,
"Reusing already loaded driver for %s",
827 rv = DYN_GetAddress(rContext->
vHandle, &f,
"IFDHCreateChannelByName", TRUE);
831 rContext->
version = IFD_HVERSION_3_0;
835 rv = DYN_GetAddress(rContext->
vHandle, &f,
"IFDHCreateChannel", FALSE);
839 rContext->
version = IFD_HVERSION_2_0;
844 Log1(PCSC_LOG_CRITICAL,
"IFDHandler functions missing");
849 if (rContext->
version == IFD_HVERSION_2_0)
852 #define GET_ADDRESS_OPTIONALv2(s, code) \
855 int rvl = DYN_GetAddress(rContext->vHandle, &f1, "IFDH" #s, FALSE); \
856 if (SCARD_S_SUCCESS != rvl) \
860 rContext->psFunctions.psFunctions_v2.pvf ## s = f1; \
863 #define GET_ADDRESSv2(s) \
864 GET_ADDRESS_OPTIONALv2(s, \
865 Log1(PCSC_LOG_CRITICAL, "IFDHandler functions missing: " #s ); \
868 Log1(PCSC_LOG_INFO,
"Loading IFD Handler 2.0");
870 GET_ADDRESSv2(CreateChannel)
871 GET_ADDRESSv2(CloseChannel)
872 GET_ADDRESSv2(GetCapabilities)
873 GET_ADDRESSv2(SetCapabilities)
874 GET_ADDRESSv2(PowerICC)
875 GET_ADDRESSv2(TransmitToICC)
876 GET_ADDRESSv2(ICCPresence)
877 GET_ADDRESS_OPTIONALv2(SetProtocolParameters, )
879 GET_ADDRESSv2(Control)
881 else if (rContext->version == IFD_HVERSION_3_0)
884 #define GET_ADDRESS_OPTIONALv3(s, code) \
887 int rvl = DYN_GetAddress(rContext->vHandle, &f1, "IFDH" #s, FALSE); \
888 if (SCARD_S_SUCCESS != rvl) \
892 rContext->psFunctions.psFunctions_v3.pvf ## s = f1; \
895 #define GET_ADDRESSv3(s) \
896 GET_ADDRESS_OPTIONALv3(s, \
897 Log1(PCSC_LOG_CRITICAL, "IFDHandler functions missing: " #s ); \
900 Log1(PCSC_LOG_INFO,
"Loading IFD Handler 3.0");
902 GET_ADDRESSv2(CreateChannel)
903 GET_ADDRESSv2(CloseChannel)
904 GET_ADDRESSv2(GetCapabilities)
905 GET_ADDRESSv2(SetCapabilities)
906 GET_ADDRESSv2(PowerICC)
907 GET_ADDRESSv2(TransmitToICC)
908 GET_ADDRESSv2(ICCPresence)
909 GET_ADDRESS_OPTIONALv2(SetProtocolParameters, )
911 GET_ADDRESSv3(CreateChannelByName)
912 GET_ADDRESSv3(Control)
917 Log1(PCSC_LOG_CRITICAL,
"IFD Handler not 1.0/2.0 or 3.0");
935 if (*rContext->
pFeeds == 1)
937 Log1(PCSC_LOG_INFO,
"Unloading reader driver.");
938 (void)DYN_CloseLibrary(&rContext->
vHandle);
958 (void)pthread_mutex_lock(&LockMutex);
959 rv = RFCheckSharing(hCard, rContext);
965 (void)pthread_mutex_unlock(&LockMutex);
974 (void)pthread_mutex_lock(&LockMutex);
975 rv = RFCheckSharing(hCard, rContext);
988 (void)pthread_mutex_unlock(&LockMutex);
997 (void)pthread_mutex_lock(&LockMutex);
998 rv = RFCheckSharing(hCard, rContext);
1004 (void)pthread_mutex_unlock(&LockMutex);
1014 Log3(PCSC_LOG_INFO,
"Attempting startup of %s using %s",
1017 #ifndef PCSCLITE_STATIC_DRIVER
1019 rv = RFLoadReader(rContext);
1022 Log2(PCSC_LOG_ERROR,
"RFLoadReader failed: 0x%lX", rv);
1027 rv = RFBindFunctions(rContext);
1031 Log2(PCSC_LOG_ERROR,
"RFBindFunctions failed: 0x%lX", rv);
1032 (void)RFUnloadReader(rContext);
1037 rContext->
vHandle = RFInitializeReader;
1045 Log3(PCSC_LOG_CRITICAL,
"Open Port 0x%X Failed (%s)",
1049 rContext->
slot = -1;
1052 rContext->
slot = -1;
1065 Log2(PCSC_LOG_INFO,
"Attempting shutdown of %s.",
1069 if (rContext->
slot != -1)
1072 (void)RFUnBindFunctions(rContext);
1073 (void)RFUnloadReader(rContext);
1107 randHandle = SYS_RandomInt(0, -1);
1110 ret = RFReaderInfoById(randHandle, &dummy_reader);
1112 UNREF_READER(dummy_reader)
1129 int listLength, lrv;
1134 listLength = list_size(&rContext->handlesList);
1137 if (listLength >= maxReaderHandles)
1139 Log2(PCSC_LOG_CRITICAL,
1140 "Too many handles opened, exceeding configured max (%d)",
1147 if (NULL == newHandle)
1149 Log1(PCSC_LOG_CRITICAL,
"malloc failed");
1154 newHandle->
hCard = hCard;
1157 lrv = list_append(&rContext->handlesList, newHandle);
1161 Log2(PCSC_LOG_CRITICAL,
"list_append failed with return value: %d",
1177 currentHandle = list_seek(&rContext->handlesList, &hCard);
1178 if (NULL == currentHandle)
1180 Log2(PCSC_LOG_CRITICAL,
"list_seek failed to locate hCard=%lX", hCard);
1185 lrv = list_delete(&rContext->handlesList, currentHandle);
1187 Log2(PCSC_LOG_CRITICAL,
1188 "list_delete failed with return value: %d", lrv);
1190 free(currentHandle);
1199 LONG RFSetReaderEventState(
READER_CONTEXT * rContext, DWORD dwEvent)
1202 int list_index, listSize;
1206 listSize = list_size(&rContext->handlesList);
1208 for (list_index = 0; list_index < listSize; list_index++)
1210 currentHandle = list_get_at(&rContext->handlesList, list_index);
1211 if (NULL == currentHandle)
1213 Log2(PCSC_LOG_CRITICAL,
"list_get_at failed at index %d",
1238 currentHandle = list_seek(&rContext->handlesList, &hCard);
1240 if (NULL == currentHandle)
1243 Log2(PCSC_LOG_CRITICAL,
"list_seek failed for hCard 0x%lX", hCard);
1273 currentHandle = list_seek(&rContext->handlesList, &hCard);
1275 if (NULL == currentHandle)
1295 void RFCleanupReaders(
void)
1299 Log1(PCSC_LOG_INFO,
"entering cleaning function");
1302 if (sReadersContexts[i]->vHandle != 0)
1305 char lpcStripReader[MAX_READERNAME];
1307 Log2(PCSC_LOG_INFO,
"Stopping reader: %s",
1308 sReadersContexts[i]->readerState->readerName);
1310 strncpy(lpcStripReader,
1311 sReadersContexts[i]->readerState->readerName,
1312 sizeof(lpcStripReader));
1314 lpcStripReader[strlen(lpcStripReader) - 6] =
'\0';
1316 rv = RFRemoveReader(lpcStripReader, sReadersContexts[i]->port);
1319 Log2(PCSC_LOG_ERROR,
"RFRemoveReader error: 0x%08lX", rv);
1321 free(sReadersContexts[i]);
1339 void RFWaitForReaderInit(
void)
1341 int i, need_to_wait;
1345 need_to_wait = FALSE;
1349 if (sReadersContexts[i]->vHandle != NULL)
1353 == sReadersContexts[i]->readerState->cardAtrLength)
1355 Log2(PCSC_LOG_DEBUG,
"Waiting init for reader: %s",
1356 sReadersContexts[i]->readerState->readerName);
1357 need_to_wait = TRUE;
1364 }
while (need_to_wait);
1369 int RFStartSerialReaders(
const char *readerconf)
1375 ConfigFile = strdup(readerconf);
1377 rv = DBGetReaderListDir(readerconf, &reader_list);
1380 if (NULL == reader_list)
1387 (void)RFAddReader(reader_list[i].pcFriendlyname,
1388 reader_list[i].channelId,
1389 reader_list[i].pcLibpath, reader_list[i].pcDevicename);
1393 ConfigFileCRC += reader_list[i].pcFriendlyname[j];
1394 for (j=0; j<reader_list[i].
pcLibpath[j]; j++)
1395 ConfigFileCRC += reader_list[i].pcLibpath[j];
1397 ConfigFileCRC += reader_list[i].pcDevicename[j];
1400 free(reader_list[i].pcFriendlyname);
1401 free(reader_list[i].pcLibpath);
1402 free(reader_list[i].pcDevicename);
1409 void RFReCheckReaderConf(
void)
1414 (void)DBGetReaderListDir(ConfigFile, &reader_list);
1417 if (NULL == reader_list)
1427 crc += reader_list[i].pcFriendlyname[j];
1428 for (j=0; j<reader_list[i].
pcLibpath[j]; j++)
1429 crc += reader_list[i].pcLibpath[j];
1431 crc += reader_list[i].pcDevicename[j];
1435 if (crc != ConfigFileCRC)
1437 Log2(PCSC_LOG_CRITICAL,
1438 "configuration file: %s has been modified. Recheck canceled",
1446 char present = FALSE;
1448 Log2(PCSC_LOG_DEBUG,
"refresh reader: %s",
1449 reader_list[i].pcFriendlyname);
1454 if (sReadersContexts[r]->vHandle != 0)
1456 char lpcStripReader[MAX_READERNAME];
1460 strncpy(lpcStripReader,
1461 sReadersContexts[i]->readerState->readerName,
1462 sizeof(lpcStripReader));
1463 tmplen = strlen(lpcStripReader);
1464 lpcStripReader[tmplen - 6] = 0;
1466 if ((strcmp(reader_list[i].pcFriendlyname, lpcStripReader) == 0)
1467 && (reader_list[r].channelId == sReadersContexts[i]->port))
1478 Log2(PCSC_LOG_INFO,
"Reader %s disappeared",
1479 reader_list[i].pcFriendlyname);
1480 (void)RFRemoveReader(reader_list[i].pcFriendlyname,
1481 reader_list[r].channelId);
1490 (void)RFAddReader(reader_list[i].pcFriendlyname,
1491 reader_list[i].channelId, reader_list[i].pcLibpath,
1492 reader_list[i].pcDevicename);
1495 free(reader_list[i].pcFriendlyname);
1496 free(reader_list[i].pcLibpath);
1497 free(reader_list[i].pcDevicename);
LONG IFDStatusICC(READER_CONTEXT *rContext, PDWORD pdwStatus)
Provide statistical information about the IFD and ICC including insertions, atr, powering status/etc...
This abstracts dynamic library loading functions.
struct pubReaderStatesList * readerState
link to the reader state
uint32_t cardAtrLength
ATR length.
int32_t contexts
Number of open contexts.
#define IFD_NO_SUCH_DEVICE
The IFD_NO_SUCH_DEVICE error must be returned by the driver when it detects the reader is no more pre...
#define TAG_IFD_THREAD_SAFE
driver is thread safe
volatile SCARDHANDLE hLockId
Lock Id.
pthread_t pthThread
Event polling thread.
#define SCARD_E_READER_UNAVAILABLE
The specified reader is not currently available for use.
RESPONSECODE(* pthCardEvent)(DWORD, int)
Card Event sync.
#define SCARD_E_DUPLICATE_READER
The reader driver did not produce a unique reader name.
LONG IFDGetCapabilities(READER_CONTEXT *rContext, DWORD dwTag, PDWORD pdwLength, PUCHAR pucValue)
Get's capabilities in the reader.
#define SCARD_UNKNOWN
Unknown state.
DWORD dwEventStatus
Recent event that must be sent.
char readerName[MAX_READERNAME]
reader name
int32_t readerSharing
PCSCLITE_SHARING_* sharing status.
#define SCARD_E_NOT_TRANSACTED
An attempt was made to end a non-existent transaction.
This handles abstract system level calls.
int slot
Current Reader Slot.
union ReaderContext::@3 psFunctions
driver functions
LONG EHSignalEventToClients(void)
Sends an asynchronous event to any waiting client.
This wraps the dynamic ifdhandler functions.
int * pMutex
Number of client to mutex.
pthread_mutex_t handlesList_lock
lock for the above list
#define SCARD_F_UNKNOWN_ERROR
An internal error has been detected, but the source is unknown.
#define SCARD_E_INVALID_HANDLE
The supplied handle was invalid.
int SYS_USleep(int)
Makes the current process sleep for some microseconds.
char * library
Library Path.
#define SCARD_E_INVALID_VALUE
One or more of the supplied parameters values could not be properly interpreted.
#define SCARD_RESET
Card was reset.
#define PCSCLITE_MAX_READERS_CONTEXTS
Maximum readers context (a slot is count as a reader)
prototypes of strlcpy()/strlcat() imported from OpenBSD
int * pFeeds
Number of shared client to lib.
#define TAG_IFD_SLOTS_NUMBER
number of slots of the reader
int version
IFD Handler version number.
pthread_mutex_t * mMutex
Mutex for this connection.
static READER_STATE readerStates[PCSCLITE_MAX_READERS_CONTEXTS]
Area used to read status information about the readers.
This handles card insertion/removal events, updates ATR, protocol, and status information.
LONG IFDCloseIFD(READER_CONTEXT *rContext)
Close a communication channel to the IFD.
#define SCARD_W_REMOVED_CARD
The smart card has been removed, so further communication is not possible.
#define TAG_IFD_SLOT_THREAD_SAFE
support access to different slots of the reader
int powerState
auto power off state
#define SCARD_PROTOCOL_UNDEFINED
protocol not set
UCHAR cardAtr[MAX_ATR_SIZE]
ATR.
LONG SCARDHANDLE
hCard returned by SCardConnect()
LONG IFDOpenIFD(READER_CONTEXT *rContext)
Open a communication channel to the IFD.
int LockCount
number of recursive locks
#define TAG_IFD_POLLING_THREAD_WITH_TIMEOUT
driver uses a polling thread with a timeout parameter
LPVOID vHandle
Dlopen handle.
This keeps a list of defines for pcsc-lite.
#define TAG_IFD_SIMULTANEOUS_ACCESS
number of reader the driver can manage
pthread_mutex_t reference_lock
reference mutex
#define SCARD_W_RESET_CARD
The smart card has been reset, so any shared state information is invalid.
#define SCARD_E_SHARING_VIOLATION
The smart card cannot be accessed because of other connections outstanding.
uint32_t cardProtocol
SCARD_PROTOCOL_* value.
Define an exported public reader state structure so each application gets instant notification of cha...
char * device
Device Name.
#define SCARD_E_NO_MEMORY
Not enough memory available to complete this command.
This keeps track of a list of currently available reader structures.
#define MAX_ATR_SIZE
Maximum ATR size.
char * pcDevicename
DEVICENAME.
uint32_t readerState
SCARD_* bit field.
int reference
number of users of the structure
This provides a search API for hot pluggble devices.
pthread_mutex_t powerState_lock
powerState mutex
#define SCARD_E_INVALID_TARGET
Registry startup information is missing or invalid.
char * pcFriendlyname
FRIENDLYNAME.
#define SCARD_E_UNKNOWN_READER
The specified reader name is not recognized.
#define SCARD_S_SUCCESS
error codes from http://msdn.microsoft.com/en-us/library/aa924526.aspx
#define IFD_SUCCESS
no error
#define SCARD_REMOVED
Card was removed.
SCARDHANDLE hCard
hCard for this connection
#define READER_NOT_INITIALIZED
Special value to indicate that power up has not yet happen This is used to auto start mode to wait un...