26 #include <sys/types.h>
42 #include "configfile.h"
52 static int maxReaderHandles = PCSC_MAX_READER_HANDLES;
53 static DWORD dwNumReadersContexts = 0;
55 static char *ConfigFile = NULL;
56 static int ConfigFileCRC = 0;
58 static pthread_mutex_t LockMutex = PTHREAD_MUTEX_INITIALIZER;
60 #define IDENTITY_SHIFT 16
63 static int RDR_CLIHANDLES_seeker(
const void *el,
const void *key)
67 if ((el == NULL) || (key == NULL))
69 Log3(PCSC_LOG_CRITICAL,
70 "RDR_CLIHANDLES_seeker called with NULL pointer: el=%p, key=%p",
104 removeReader(sReader);
109 LONG RFAllocateReaderSpace(
unsigned int customMaxReaderHandles)
113 if (customMaxReaderHandles != 0)
114 maxReaderHandles = customMaxReaderHandles;
120 sReadersContexts[i]->
vHandle = NULL;
123 memset(readerStates[i].readerName, 0, MAX_READERNAME);
130 sReadersContexts[i]->
readerState = &readerStates[i];
134 return EHInitializeEventStructures();
137 LONG RFAddReader(
const char *readerNameLong,
int port,
const char *library,
140 DWORD dwContext = 0, dwGetSize;
141 UCHAR ucGetData[1], ucThread[1];
145 char *readerName = NULL;
147 if ((readerNameLong == NULL) || (library == NULL) || (device == NULL))
151 readerName = alloca(strlen(readerNameLong)+1);
152 strcpy(readerName, readerNameLong);
155 if (strlen(readerName) > MAX_READERNAME -
sizeof(
" 00 00"))
158 "Reader name too long: %zd chars instead of max %zd. Truncating!",
159 strlen(readerName), MAX_READERNAME -
sizeof(
" 00 00"));
160 readerName[MAX_READERNAME -
sizeof(
" 00 00")] =
'\0';
164 if (dwNumReadersContexts != 0)
168 if (sReadersContexts[i]->vHandle != 0)
170 char lpcStripReader[MAX_READERNAME];
174 strncpy(lpcStripReader,
175 sReadersContexts[i]->readerState->readerName,
176 sizeof(lpcStripReader));
177 tmplen = strlen(lpcStripReader);
178 lpcStripReader[tmplen - 6] = 0;
180 if ((strcmp(readerName, lpcStripReader) == 0) &&
181 (port == sReadersContexts[i]->port))
183 Log1(PCSC_LOG_ERROR,
"Duplicate reader found.");
193 if (sReadersContexts[i]->vHandle == 0)
200 if (i == PCSCLITE_MAX_READERS_CONTEXTS)
207 parentNode = RFSetReaderName(sReadersContexts[dwContext], readerName,
212 sReadersContexts[dwContext]->
library = strdup(library);
213 sReadersContexts[dwContext]->
device = strdup(device);
214 sReadersContexts[dwContext]->
version = 0;
215 sReadersContexts[dwContext]->
port = port;
216 sReadersContexts[dwContext]->
mMutex = NULL;
217 sReadersContexts[dwContext]->
contexts = 0;
218 sReadersContexts[dwContext]->
pthThread = 0;
219 sReadersContexts[dwContext]->
hLockId = 0;
220 sReadersContexts[dwContext]->
LockCount = 0;
221 sReadersContexts[dwContext]->
vHandle = NULL;
222 sReadersContexts[dwContext]->
pFeeds = NULL;
223 sReadersContexts[dwContext]->
pMutex = NULL;
226 lrv = list_init(&sReadersContexts[dwContext]->handlesList);
229 Log2(PCSC_LOG_CRITICAL,
"list_init failed with return value: %d", lrv);
233 lrv = list_attributes_seeker(&sReadersContexts[dwContext]->handlesList,
234 RDR_CLIHANDLES_seeker);
237 Log2(PCSC_LOG_CRITICAL,
238 "list_attributes_seeker failed with return value: %d", lrv);
242 (void)pthread_mutex_init(&sReadersContexts[dwContext]->handlesList_lock,
245 (void)pthread_mutex_init(&sReadersContexts[dwContext]->powerState_lock,
250 (void)pthread_mutex_init(&sReadersContexts[dwContext]->reference_lock,
252 sReadersContexts[dwContext]->
reference = 1;
255 if (parentNode >= 0 && parentNode < PCSCLITE_MAX_READERS_CONTEXTS)
257 sReadersContexts[dwContext]->
pFeeds =
258 sReadersContexts[parentNode]->
pFeeds;
259 *(sReadersContexts[dwContext])->pFeeds += 1;
260 sReadersContexts[dwContext]->
vHandle =
261 sReadersContexts[parentNode]->
vHandle;
262 sReadersContexts[dwContext]->
mMutex =
263 sReadersContexts[parentNode]->
mMutex;
264 sReadersContexts[dwContext]->
pMutex =
265 sReadersContexts[parentNode]->
pMutex;
268 dwGetSize =
sizeof(ucThread);
272 if (rv ==
IFD_SUCCESS && dwGetSize == 1 && ucThread[0] == 1)
274 Log1(PCSC_LOG_INFO,
"Driver is thread safe");
275 sReadersContexts[dwContext]->
mMutex = NULL;
276 sReadersContexts[dwContext]->
pMutex = NULL;
279 *(sReadersContexts[dwContext])->pMutex += 1;
282 if (sReadersContexts[dwContext]->pFeeds == NULL)
284 sReadersContexts[dwContext]->
pFeeds = malloc(
sizeof(
int));
290 *(sReadersContexts[dwContext])->pFeeds = 1;
293 if (sReadersContexts[dwContext]->mMutex == 0)
295 sReadersContexts[dwContext]->
mMutex =
296 malloc(
sizeof(pthread_mutex_t));
297 (void)pthread_mutex_init(sReadersContexts[dwContext]->mMutex, NULL);
300 if (sReadersContexts[dwContext]->pMutex == NULL)
302 sReadersContexts[dwContext]->
pMutex = malloc(
sizeof(
int));
303 *(sReadersContexts[dwContext])->pMutex = 1;
306 dwNumReadersContexts += 1;
308 rv = RFInitializeReader(sReadersContexts[dwContext]);
312 Log2(PCSC_LOG_ERROR,
"%s init failed.", readerName);
313 (void)RFRemoveReader(readerName, port);
319 RESPONSECODE (*fct)(DWORD, int) = NULL;
321 dwGetSize =
sizeof(fct);
327 Log1(PCSC_LOG_INFO,
"Using the pcscd polling thread");
332 Log1(PCSC_LOG_INFO,
"Using the reader polling thread");
335 rv = EHSpawnEventHandler(sReadersContexts[dwContext]);
338 Log2(PCSC_LOG_ERROR,
"%s init failed.", readerName);
339 (void)RFRemoveReader(readerName, port);
345 dwGetSize =
sizeof(ucGetData);
349 if (rv !=
IFD_SUCCESS || dwGetSize != 1 || ucGetData[0] == 0)
354 if (rv ==
IFD_SUCCESS && dwGetSize == 1 && ucGetData[0] == 1)
364 for (j = 1; j < ucGetData[0]; j++)
366 char *tmpReader = NULL;
367 DWORD dwContextB = 0;
368 RESPONSECODE (*fct)(DWORD, int) = NULL;
373 if (sReadersContexts[i]->vHandle == 0)
380 if (i == PCSCLITE_MAX_READERS_CONTEXTS)
383 RFRemoveReader(readerName, port);
389 (void)strlcpy(tmpReader,
390 sReadersContexts[dwContext]->readerState->readerName,
392 snprintf(tmpReader + strlen(tmpReader) - 2, 3,
"%02X", j);
394 sReadersContexts[dwContextB]->
library =
395 sReadersContexts[dwContext]->
library;
396 sReadersContexts[dwContextB]->
device =
397 sReadersContexts[dwContext]->
device;
398 sReadersContexts[dwContextB]->
version =
399 sReadersContexts[dwContext]->
version;
400 sReadersContexts[dwContextB]->
port =
401 sReadersContexts[dwContext]->
port;
402 sReadersContexts[dwContextB]->
vHandle =
403 sReadersContexts[dwContext]->
vHandle;
404 sReadersContexts[dwContextB]->
mMutex =
405 sReadersContexts[dwContext]->
mMutex;
406 sReadersContexts[dwContextB]->
pMutex =
407 sReadersContexts[dwContext]->
pMutex;
408 sReadersContexts[dwContextB]->
slot =
409 sReadersContexts[dwContext]->
slot + j;
416 sReadersContexts[dwContextB]->
pFeeds =
417 sReadersContexts[dwContext]->
pFeeds;
420 *(sReadersContexts[dwContextB])->pFeeds += 1;
422 sReadersContexts[dwContextB]->
contexts = 0;
423 sReadersContexts[dwContextB]->
hLockId = 0;
424 sReadersContexts[dwContextB]->
LockCount = 0;
426 lrv = list_init(&sReadersContexts[dwContextB]->handlesList);
429 Log2(PCSC_LOG_CRITICAL,
"list_init failed with return value: %d", lrv);
433 lrv = list_attributes_seeker(&sReadersContexts[dwContextB]->handlesList,
434 RDR_CLIHANDLES_seeker);
437 Log2(PCSC_LOG_CRITICAL,
438 "list_attributes_seeker failed with return value: %d", lrv);
442 (void)pthread_mutex_init(&sReadersContexts[dwContextB]->handlesList_lock, NULL);
443 (void)pthread_mutex_init(&sReadersContexts[dwContextB]->powerState_lock,
448 (void)pthread_mutex_init(&sReadersContexts[dwContextB]->reference_lock,
450 sReadersContexts[dwContextB]->
reference = 1;
453 dwGetSize =
sizeof(ucThread);
457 if (rv ==
IFD_SUCCESS && dwGetSize == 1 && ucThread[0] == 1)
459 Log1(PCSC_LOG_INFO,
"Driver is slot thread safe");
461 sReadersContexts[dwContextB]->
library =
462 strdup(sReadersContexts[dwContext]->library);
463 sReadersContexts[dwContextB]->
device =
464 strdup(sReadersContexts[dwContext]->device);
465 sReadersContexts[dwContextB]->
mMutex =
466 malloc(
sizeof(pthread_mutex_t));
467 (void)pthread_mutex_init(sReadersContexts[dwContextB]->mMutex,
470 sReadersContexts[dwContextB]->
pMutex = malloc(
sizeof(
int));
471 *(sReadersContexts[dwContextB])->pMutex = 1;
474 *(sReadersContexts[dwContextB])->pMutex += 1;
476 dwNumReadersContexts += 1;
478 rv = RFInitializeReader(sReadersContexts[dwContextB]);
482 (void)RFRemoveReader(readerName, port);
487 dwGetSize =
sizeof(fct);
493 Log1(PCSC_LOG_INFO,
"Using the pcscd polling thread");
498 Log1(PCSC_LOG_INFO,
"Using the reader polling thread");
501 rv = EHSpawnEventHandler(sReadersContexts[dwContextB]);
504 Log2(PCSC_LOG_ERROR,
"%s init failed.", readerName);
505 (void)RFRemoveReader(readerName, port);
513 LONG RFRemoveReader(
const char *readerName,
int port)
515 char lpcStripReader[MAX_READERNAME];
518 if (readerName == NULL)
523 if (sReadersContexts[i]->vHandle != 0)
525 strncpy(lpcStripReader,
526 sReadersContexts[i]->readerState->readerName,
527 sizeof(lpcStripReader));
528 lpcStripReader[strlen(lpcStripReader) - 6] = 0;
531 if ((strncmp(readerName, lpcStripReader, MAX_READERNAME -
sizeof(
" 00 00")) == 0)
532 && (port == sReadersContexts[i]->port))
535 UNREF_READER(sReadersContexts[i])
549 if (sContext -> pthThread)
550 (void)EHDestroyEventHandler(sContext);
552 if ((NULL == sContext->
pMutex) || (NULL == sContext->
pFeeds))
555 "Trying to remove an already removed driver");
559 rv = RFUnInitializeReader(sContext);
566 if (0 == *sContext->
pMutex)
568 (void)pthread_mutex_destroy(sContext->
mMutex);
580 if (*sContext->
pFeeds == 0)
596 while (list_size(&sContext->handlesList) != 0)
601 currentHandle = list_get_at(&sContext->handlesList, 0);
602 lrv = list_delete_at(&sContext->handlesList, 0);
604 Log2(PCSC_LOG_CRITICAL,
605 "list_delete_at failed with return value: %d", lrv);
611 list_destroy(&sContext->handlesList);
612 dwNumReadersContexts -= 1;
621 LONG RFSetReaderName(
READER_CONTEXT * rContext,
const char *readerName,
622 const char *libraryName,
int port)
626 int currentDigit = -1;
627 int supportedChannels = 0;
633 usedDigits[i] = FALSE;
635 if (dwNumReadersContexts != 0)
639 if (sReadersContexts[i]->vHandle != 0)
641 if (strcmp(sReadersContexts[i]->library, libraryName) == 0)
647 valueLength =
sizeof(tagValue);
650 &valueLength, tagValue);
655 supportedChannels = tagValue[0];
657 "Support %d simultaneous readers", tagValue[0]);
660 supportedChannels = 1;
663 if ((((sReadersContexts[i]->port & 0xFFFF0000) ==
664 PCSCLITE_HP_BASE_PORT)
665 && (sReadersContexts[i]->port != port))
666 || (supportedChannels > 1))
682 currentDigit = strtol(reader + strlen(reader) - 5, NULL, 16);
685 usedDigits[currentDigit] = TRUE;
696 if (currentDigit != -1)
701 if (usedDigits[i] == FALSE)
705 if (i == PCSCLITE_MAX_READERS_CONTEXTS)
707 Log2(PCSC_LOG_ERROR,
"Max number of readers reached: %d", PCSCLITE_MAX_READERS_CONTEXTS);
711 if (i >= supportedChannels)
713 Log3(PCSC_LOG_ERROR,
"Driver %s does not support more than "
714 "%d reader(s). Maybe the driver should support "
715 "TAG_IFD_SIMULTANEOUS_ACCESS", libraryName, supportedChannels);
725 rContext->
slot = i << 16;
730 LONG RFReaderInfo(
const char *readerName,
READER_CONTEXT ** sReader)
734 if (readerName == NULL)
739 if (sReadersContexts[i]->vHandle != 0)
741 if (strcmp(readerName,
742 sReadersContexts[i]->readerState->readerName) == 0)
745 REF_READER(sReadersContexts[i])
747 *sReader = sReadersContexts[i];
762 if (sReadersContexts[i]->vHandle != 0)
765 (void)pthread_mutex_lock(&sReadersContexts[i]->handlesList_lock);
766 currentHandle = list_seek(&sReadersContexts[i]->handlesList,
768 (void)pthread_mutex_unlock(&sReadersContexts[i]->handlesList_lock);
769 if (currentHandle != NULL)
772 REF_READER(sReadersContexts[i])
774 *sReader = sReadersContexts[i];
787 Log2(PCSC_LOG_INFO,
"Reusing already loaded driver for %s",
801 rv = DYN_GetAddress(rContext->
vHandle, &f,
"IFDHCreateChannelByName");
805 rContext->
version = IFD_HVERSION_3_0;
809 rv = DYN_GetAddress(rContext->
vHandle, &f,
"IFDHCreateChannel");
813 rContext->
version = IFD_HVERSION_2_0;
818 Log1(PCSC_LOG_CRITICAL,
"IFDHandler functions missing");
823 if (rContext->
version == IFD_HVERSION_2_0)
826 #define GET_ADDRESS_OPTIONALv2(s, code) \
829 int rvl = DYN_GetAddress(rContext->vHandle, &f1, "IFDH" #s); \
830 if (SCARD_S_SUCCESS != rvl) \
834 rContext->psFunctions.psFunctions_v2.pvf ## s = f1; \
837 #define GET_ADDRESSv2(s) \
838 GET_ADDRESS_OPTIONALv2(s, \
839 Log1(PCSC_LOG_CRITICAL, "IFDHandler functions missing: " #s ); \
842 Log1(PCSC_LOG_INFO,
"Loading IFD Handler 2.0");
844 GET_ADDRESSv2(CreateChannel)
845 GET_ADDRESSv2(CloseChannel)
846 GET_ADDRESSv2(GetCapabilities)
847 GET_ADDRESSv2(SetCapabilities)
848 GET_ADDRESSv2(PowerICC)
849 GET_ADDRESSv2(TransmitToICC)
850 GET_ADDRESSv2(ICCPresence)
851 GET_ADDRESS_OPTIONALv2(SetProtocolParameters, )
853 GET_ADDRESSv2(Control)
855 else if (rContext->version == IFD_HVERSION_3_0)
858 #define GET_ADDRESS_OPTIONALv3(s, code) \
861 int rvl = DYN_GetAddress(rContext->vHandle, &f1, "IFDH" #s); \
862 if (SCARD_S_SUCCESS != rvl) \
866 rContext->psFunctions.psFunctions_v3.pvf ## s = f1; \
869 #define GET_ADDRESSv3(s) \
870 GET_ADDRESS_OPTIONALv3(s, \
871 Log1(PCSC_LOG_CRITICAL, "IFDHandler functions missing: " #s ); \
874 Log1(PCSC_LOG_INFO,
"Loading IFD Handler 3.0");
876 GET_ADDRESSv2(CreateChannel)
877 GET_ADDRESSv2(CloseChannel)
878 GET_ADDRESSv2(GetCapabilities)
879 GET_ADDRESSv2(SetCapabilities)
880 GET_ADDRESSv2(PowerICC)
881 GET_ADDRESSv2(TransmitToICC)
882 GET_ADDRESSv2(ICCPresence)
883 GET_ADDRESS_OPTIONALv2(SetProtocolParameters, )
885 GET_ADDRESSv3(CreateChannelByName)
886 GET_ADDRESSv3(Control)
891 Log1(PCSC_LOG_CRITICAL,
"IFD Handler not 1.0/2.0 or 3.0");
909 if (*rContext->
pFeeds == 1)
911 Log1(PCSC_LOG_INFO,
"Unloading reader driver.");
912 (void)DYN_CloseLibrary(&rContext->
vHandle);
932 (void)pthread_mutex_lock(&LockMutex);
933 rv = RFCheckSharing(hCard, rContext);
939 (void)pthread_mutex_unlock(&LockMutex);
948 (void)pthread_mutex_lock(&LockMutex);
949 rv = RFCheckSharing(hCard, rContext);
962 (void)pthread_mutex_unlock(&LockMutex);
971 (void)pthread_mutex_lock(&LockMutex);
972 rv = RFCheckSharing(hCard, rContext);
978 (void)pthread_mutex_unlock(&LockMutex);
988 Log3(PCSC_LOG_INFO,
"Attempting startup of %s using %s",
991 #ifndef PCSCLITE_STATIC_DRIVER
993 rv = RFLoadReader(rContext);
996 Log2(PCSC_LOG_ERROR,
"RFLoadReader failed: 0x%lX", rv);
1001 rv = RFBindFunctions(rContext);
1005 Log2(PCSC_LOG_ERROR,
"RFBindFunctions failed: 0x%lX", rv);
1006 (void)RFUnloadReader(rContext);
1011 rContext->
vHandle = RFInitializeReader;
1019 Log3(PCSC_LOG_CRITICAL,
"Open Port 0x%X Failed (%s)",
1023 rContext->
slot = -1;
1026 rContext->
slot = -1;
1039 Log2(PCSC_LOG_INFO,
"Attempting shutdown of %s.",
1043 if (rContext->
slot != -1)
1046 (void)RFUnBindFunctions(rContext);
1047 (void)RFUnloadReader(rContext);
1081 randHandle = SYS_RandomInt(0, -1);
1084 ret = RFReaderInfoById(randHandle, &dummy_reader);
1086 UNREF_READER(dummy_reader)
1103 int listLength, lrv;
1108 listLength = list_size(&rContext->handlesList);
1111 if (listLength >= maxReaderHandles)
1113 Log2(PCSC_LOG_CRITICAL,
1114 "Too many handles opened, exceeding configured max (%d)",
1121 if (NULL == newHandle)
1123 Log1(PCSC_LOG_CRITICAL,
"malloc failed");
1128 newHandle->
hCard = hCard;
1131 lrv = list_append(&rContext->handlesList, newHandle);
1135 Log2(PCSC_LOG_CRITICAL,
"list_append failed with return value: %d",
1151 currentHandle = list_seek(&rContext->handlesList, &hCard);
1152 if (NULL == currentHandle)
1154 Log2(PCSC_LOG_CRITICAL,
"list_seek failed to locate hCard=%lX", hCard);
1159 lrv = list_delete(&rContext->handlesList, currentHandle);
1161 Log2(PCSC_LOG_CRITICAL,
1162 "list_delete failed with return value: %d", lrv);
1164 free(currentHandle);
1173 LONG RFSetReaderEventState(
READER_CONTEXT * rContext, DWORD dwEvent)
1176 int list_index, listSize;
1180 listSize = list_size(&rContext->handlesList);
1182 for (list_index = 0; list_index < listSize; list_index++)
1184 currentHandle = list_get_at(&rContext->handlesList, list_index);
1185 if (NULL == currentHandle)
1187 Log2(PCSC_LOG_CRITICAL,
"list_get_at failed at index %d",
1212 currentHandle = list_seek(&rContext->handlesList, &hCard);
1214 if (NULL == currentHandle)
1217 Log2(PCSC_LOG_CRITICAL,
"list_seek failed for hCard 0x%lX", hCard);
1247 currentHandle = list_seek(&rContext->handlesList, &hCard);
1249 if (NULL == currentHandle)
1269 void RFCleanupReaders(
void)
1273 Log1(PCSC_LOG_INFO,
"entering cleaning function");
1276 if (sReadersContexts[i]->vHandle != 0)
1279 char lpcStripReader[MAX_READERNAME];
1281 Log2(PCSC_LOG_INFO,
"Stopping reader: %s",
1282 sReadersContexts[i]->readerState->readerName);
1284 strncpy(lpcStripReader,
1285 sReadersContexts[i]->readerState->readerName,
1286 sizeof(lpcStripReader));
1288 lpcStripReader[strlen(lpcStripReader) - 6] =
'\0';
1290 rv = RFRemoveReader(lpcStripReader, sReadersContexts[i]->port);
1293 Log2(PCSC_LOG_ERROR,
"RFRemoveReader error: 0x%08lX", rv);
1295 free(sReadersContexts[i]);
1313 void RFWaitForReaderInit(
void)
1315 int i, need_to_wait;
1319 need_to_wait = FALSE;
1323 if (sReadersContexts[i]->vHandle != NULL)
1327 == sReadersContexts[i]->readerState->cardAtrLength)
1329 Log2(PCSC_LOG_DEBUG,
"Waiting init for reader: %s",
1330 sReadersContexts[i]->readerState->readerName);
1331 need_to_wait = TRUE;
1338 }
while (need_to_wait);
1343 int RFStartSerialReaders(
const char *readerconf)
1349 ConfigFile = strdup(readerconf);
1351 rv = DBGetReaderListDir(readerconf, &reader_list);
1354 if (NULL == reader_list)
1361 (void)RFAddReader(reader_list[i].pcFriendlyname,
1362 reader_list[i].channelId,
1363 reader_list[i].pcLibpath, reader_list[i].pcDevicename);
1367 ConfigFileCRC += reader_list[i].pcFriendlyname[j];
1368 for (j=0; j<reader_list[i].
pcLibpath[j]; j++)
1369 ConfigFileCRC += reader_list[i].pcLibpath[j];
1371 ConfigFileCRC += reader_list[i].pcDevicename[j];
1374 free(reader_list[i].pcFriendlyname);
1375 free(reader_list[i].pcLibpath);
1376 free(reader_list[i].pcDevicename);
1383 void RFReCheckReaderConf(
void)
1388 (void)DBGetReaderListDir(ConfigFile, &reader_list);
1391 if (NULL == reader_list)
1401 crc += reader_list[i].pcFriendlyname[j];
1402 for (j=0; j<reader_list[i].
pcLibpath[j]; j++)
1403 crc += reader_list[i].pcLibpath[j];
1405 crc += reader_list[i].pcDevicename[j];
1409 if (crc != ConfigFileCRC)
1411 Log2(PCSC_LOG_CRITICAL,
1412 "configuration file: %s has been modified. Recheck canceled",
1420 char present = FALSE;
1422 Log2(PCSC_LOG_DEBUG,
"refresh reader: %s",
1423 reader_list[i].pcFriendlyname);
1428 if (sReadersContexts[r]->vHandle != 0)
1430 char lpcStripReader[MAX_READERNAME];
1434 strncpy(lpcStripReader,
1435 sReadersContexts[i]->readerState->readerName,
1436 sizeof(lpcStripReader));
1437 tmplen = strlen(lpcStripReader);
1438 lpcStripReader[tmplen - 6] = 0;
1440 if ((strcmp(reader_list[i].pcFriendlyname, lpcStripReader) == 0)
1441 && (reader_list[r].channelId == sReadersContexts[i]->port))
1452 Log2(PCSC_LOG_INFO,
"Reader %s disappeared",
1453 reader_list[i].pcFriendlyname);
1454 (void)RFRemoveReader(reader_list[i].pcFriendlyname,
1455 reader_list[r].channelId);
1464 (void)RFAddReader(reader_list[i].pcFriendlyname,
1465 reader_list[i].channelId, reader_list[i].pcLibpath,
1466 reader_list[i].pcDevicename);
1469 free(reader_list[i].pcFriendlyname);
1470 free(reader_list[i].pcLibpath);
1471 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...