49 #include <sys/types.h>
64 #include "configfile.h"
74 static int maxReaderHandles = PCSC_MAX_READER_HANDLES;
75 static DWORD dwNumReadersContexts = 0;
77 static char *ConfigFile = NULL;
78 static int ConfigFileCRC = 0;
80 static pthread_mutex_t LockMutex = PTHREAD_MUTEX_INITIALIZER;
82 #define IDENTITY_SHIFT 16
85 static int RDR_CLIHANDLES_seeker(
const void *el,
const void *key)
89 if ((el == NULL) || (key == NULL))
91 Log3(PCSC_LOG_CRITICAL,
92 "RDR_CLIHANDLES_seeker called with NULL pointer: el=%p, key=%p",
126 removeReader(sReader);
131 LONG RFAllocateReaderSpace(
unsigned int customMaxReaderHandles)
135 if (customMaxReaderHandles != 0)
136 maxReaderHandles = customMaxReaderHandles;
142 sReadersContexts[i]->
vHandle = NULL;
145 memset(readerStates[i].readerName, 0, MAX_READERNAME);
153 sReadersContexts[i]->
readerState = &readerStates[i];
157 return EHInitializeEventStructures();
160 LONG RFAddReader(
const char *readerNameLong,
int port,
const char *library,
163 DWORD dwContext = 0, dwGetSize;
164 UCHAR ucGetData[1], ucThread[1];
168 char *readerName = NULL;
170 if ((readerNameLong == NULL) || (library == NULL) || (device == NULL))
174 readerName = alloca(strlen(readerNameLong)+1);
175 strcpy(readerName, readerNameLong);
178 if (strlen(readerName) > MAX_READERNAME -
sizeof(
" 00 00"))
181 "Reader name too long: %zd chars instead of max %zd. Truncating!",
182 strlen(readerName), MAX_READERNAME -
sizeof(
" 00 00"));
183 readerName[MAX_READERNAME -
sizeof(
" 00 00")] =
'\0';
187 if (dwNumReadersContexts != 0)
191 if (sReadersContexts[i]->vHandle != 0)
193 char lpcStripReader[MAX_READERNAME];
197 strncpy(lpcStripReader,
198 sReadersContexts[i]->readerState->readerName,
199 sizeof(lpcStripReader));
200 tmplen = strlen(lpcStripReader);
201 lpcStripReader[tmplen - 6] = 0;
203 if ((strcmp(readerName, lpcStripReader) == 0) &&
204 (port == sReadersContexts[i]->port))
206 Log1(PCSC_LOG_ERROR,
"Duplicate reader found.");
216 if (sReadersContexts[i]->vHandle == 0)
223 if (i == PCSCLITE_MAX_READERS_CONTEXTS)
230 parentNode = RFSetReaderName(sReadersContexts[dwContext], readerName,
235 sReadersContexts[dwContext]->
library = strdup(library);
236 sReadersContexts[dwContext]->
device = strdup(device);
237 sReadersContexts[dwContext]->
version = 0;
238 sReadersContexts[dwContext]->
port = port;
239 sReadersContexts[dwContext]->
mMutex = NULL;
240 sReadersContexts[dwContext]->
contexts = 0;
241 sReadersContexts[dwContext]->
pthThread = 0;
242 sReadersContexts[dwContext]->
hLockId = 0;
243 sReadersContexts[dwContext]->
LockCount = 0;
244 sReadersContexts[dwContext]->
vHandle = NULL;
245 sReadersContexts[dwContext]->
pFeeds = NULL;
246 sReadersContexts[dwContext]->
pMutex = NULL;
249 lrv = list_init(&sReadersContexts[dwContext]->handlesList);
252 Log2(PCSC_LOG_CRITICAL,
"list_init failed with return value: %d", lrv);
256 lrv = list_attributes_seeker(&sReadersContexts[dwContext]->handlesList,
257 RDR_CLIHANDLES_seeker);
260 Log2(PCSC_LOG_CRITICAL,
261 "list_attributes_seeker failed with return value: %d", lrv);
265 (void)pthread_mutex_init(&sReadersContexts[dwContext]->handlesList_lock,
268 (void)pthread_mutex_init(&sReadersContexts[dwContext]->powerState_lock,
273 (void)pthread_mutex_init(&sReadersContexts[dwContext]->reference_lock,
275 sReadersContexts[dwContext]->
reference = 1;
278 if (parentNode >= 0 && parentNode < PCSCLITE_MAX_READERS_CONTEXTS)
280 sReadersContexts[dwContext]->
pFeeds =
281 sReadersContexts[parentNode]->
pFeeds;
282 *(sReadersContexts[dwContext])->pFeeds += 1;
283 sReadersContexts[dwContext]->
vHandle =
284 sReadersContexts[parentNode]->
vHandle;
285 sReadersContexts[dwContext]->
mMutex =
286 sReadersContexts[parentNode]->
mMutex;
287 sReadersContexts[dwContext]->
pMutex =
288 sReadersContexts[parentNode]->
pMutex;
291 dwGetSize =
sizeof(ucThread);
295 if (rv ==
IFD_SUCCESS && dwGetSize == 1 && ucThread[0] == 1)
297 Log1(PCSC_LOG_INFO,
"Driver is thread safe");
298 sReadersContexts[dwContext]->
mMutex = NULL;
299 sReadersContexts[dwContext]->
pMutex = NULL;
302 *(sReadersContexts[dwContext])->pMutex += 1;
305 if (sReadersContexts[dwContext]->pFeeds == NULL)
307 sReadersContexts[dwContext]->
pFeeds = malloc(
sizeof(
int));
313 *(sReadersContexts[dwContext])->pFeeds = 1;
316 if (sReadersContexts[dwContext]->mMutex == 0)
318 sReadersContexts[dwContext]->
mMutex =
319 malloc(
sizeof(pthread_mutex_t));
320 (void)pthread_mutex_init(sReadersContexts[dwContext]->mMutex, NULL);
323 if (sReadersContexts[dwContext]->pMutex == NULL)
325 sReadersContexts[dwContext]->
pMutex = malloc(
sizeof(
int));
326 *(sReadersContexts[dwContext])->pMutex = 1;
329 dwNumReadersContexts += 1;
331 rv = RFInitializeReader(sReadersContexts[dwContext]);
335 Log2(PCSC_LOG_ERROR,
"%s init failed.", readerName);
336 (void)RFRemoveReader(readerName, port);
342 RESPONSECODE (*fct)(DWORD, int) = NULL;
344 dwGetSize =
sizeof(fct);
350 Log1(PCSC_LOG_INFO,
"Using the pcscd polling thread");
355 Log1(PCSC_LOG_INFO,
"Using the reader polling thread");
358 rv = EHSpawnEventHandler(sReadersContexts[dwContext]);
361 Log2(PCSC_LOG_ERROR,
"%s init failed.", readerName);
362 (void)RFRemoveReader(readerName, port);
368 dwGetSize =
sizeof(ucGetData);
372 if (rv !=
IFD_SUCCESS || dwGetSize != 1 || ucGetData[0] == 0)
377 if (rv ==
IFD_SUCCESS && dwGetSize == 1 && ucGetData[0] == 1)
387 for (j = 1; j < ucGetData[0]; j++)
389 char *tmpReader = NULL;
390 DWORD dwContextB = 0;
391 RESPONSECODE (*fct)(DWORD, int) = NULL;
396 if (sReadersContexts[i]->vHandle == 0)
403 if (i == PCSCLITE_MAX_READERS_CONTEXTS)
406 RFRemoveReader(readerName, port);
413 sReadersContexts[dwContext]->readerState->readerName,
415 snprintf(tmpReader + strlen(tmpReader) - 2, 3,
"%02X", j);
417 sReadersContexts[dwContextB]->
library =
418 sReadersContexts[dwContext]->
library;
419 sReadersContexts[dwContextB]->
device =
420 sReadersContexts[dwContext]->
device;
421 sReadersContexts[dwContextB]->
version =
422 sReadersContexts[dwContext]->
version;
423 sReadersContexts[dwContextB]->
port =
424 sReadersContexts[dwContext]->
port;
425 sReadersContexts[dwContextB]->
vHandle =
426 sReadersContexts[dwContext]->
vHandle;
427 sReadersContexts[dwContextB]->
mMutex =
428 sReadersContexts[dwContext]->
mMutex;
429 sReadersContexts[dwContextB]->
pMutex =
430 sReadersContexts[dwContext]->
pMutex;
431 sReadersContexts[dwContextB]->
slot =
432 sReadersContexts[dwContext]->
slot + j;
439 sReadersContexts[dwContextB]->
pFeeds =
440 sReadersContexts[dwContext]->
pFeeds;
443 *(sReadersContexts[dwContextB])->pFeeds += 1;
445 sReadersContexts[dwContextB]->
contexts = 0;
446 sReadersContexts[dwContextB]->
hLockId = 0;
447 sReadersContexts[dwContextB]->
LockCount = 0;
449 lrv = list_init(&sReadersContexts[dwContextB]->handlesList);
452 Log2(PCSC_LOG_CRITICAL,
"list_init failed with return value: %d", lrv);
456 lrv = list_attributes_seeker(&sReadersContexts[dwContextB]->handlesList,
457 RDR_CLIHANDLES_seeker);
460 Log2(PCSC_LOG_CRITICAL,
461 "list_attributes_seeker failed with return value: %d", lrv);
465 (void)pthread_mutex_init(&sReadersContexts[dwContextB]->handlesList_lock, NULL);
466 (void)pthread_mutex_init(&sReadersContexts[dwContextB]->powerState_lock,
471 (void)pthread_mutex_init(&sReadersContexts[dwContextB]->reference_lock,
473 sReadersContexts[dwContextB]->
reference = 1;
476 dwGetSize =
sizeof(ucThread);
480 if (rv ==
IFD_SUCCESS && dwGetSize == 1 && ucThread[0] == 1)
482 Log1(PCSC_LOG_INFO,
"Driver is slot thread safe");
484 sReadersContexts[dwContextB]->
library =
485 strdup(sReadersContexts[dwContext]->library);
486 sReadersContexts[dwContextB]->
device =
487 strdup(sReadersContexts[dwContext]->device);
488 sReadersContexts[dwContextB]->
mMutex =
489 malloc(
sizeof(pthread_mutex_t));
490 (void)pthread_mutex_init(sReadersContexts[dwContextB]->mMutex,
493 sReadersContexts[dwContextB]->
pMutex = malloc(
sizeof(
int));
494 *(sReadersContexts[dwContextB])->pMutex = 1;
497 *(sReadersContexts[dwContextB])->pMutex += 1;
499 dwNumReadersContexts += 1;
501 rv = RFInitializeReader(sReadersContexts[dwContextB]);
505 (void)RFRemoveReader(readerName, port);
510 dwGetSize =
sizeof(fct);
516 Log1(PCSC_LOG_INFO,
"Using the pcscd polling thread");
521 Log1(PCSC_LOG_INFO,
"Using the reader polling thread");
524 rv = EHSpawnEventHandler(sReadersContexts[dwContextB]);
527 Log2(PCSC_LOG_ERROR,
"%s init failed.", readerName);
528 (void)RFRemoveReader(readerName, port);
536 LONG RFRemoveReader(
const char *readerName,
int port)
538 char lpcStripReader[MAX_READERNAME];
541 if (readerName == NULL)
546 if (sReadersContexts[i]->vHandle != 0)
548 strncpy(lpcStripReader,
549 sReadersContexts[i]->readerState->readerName,
550 sizeof(lpcStripReader));
551 lpcStripReader[strlen(lpcStripReader) - 6] = 0;
554 if ((strncmp(readerName, lpcStripReader, MAX_READERNAME -
sizeof(
" 00 00")) == 0)
555 && (port == sReadersContexts[i]->port))
558 UNREF_READER(sReadersContexts[i])
572 if (sContext -> pthThread)
573 (void)EHDestroyEventHandler(sContext);
575 if ((NULL == sContext->
pMutex) || (NULL == sContext->
pFeeds))
578 "Trying to remove an already removed driver");
582 rv = RFUnInitializeReader(sContext);
589 if (0 == *sContext->
pMutex)
591 (void)pthread_mutex_destroy(sContext->
mMutex);
603 if (*sContext->
pFeeds == 0)
619 while (list_size(&sContext->handlesList) != 0)
624 currentHandle = list_get_at(&sContext->handlesList, 0);
625 lrv = list_delete_at(&sContext->handlesList, 0);
627 Log2(PCSC_LOG_CRITICAL,
628 "list_delete_at failed with return value: %d", lrv);
634 list_destroy(&sContext->handlesList);
635 dwNumReadersContexts -= 1;
644 LONG RFSetReaderName(
READER_CONTEXT * rContext,
const char *readerName,
645 const char *libraryName,
int port)
649 int currentDigit = -1;
650 int supportedChannels = 0;
656 usedDigits[i] = FALSE;
658 if (dwNumReadersContexts != 0)
662 if (sReadersContexts[i]->vHandle != 0)
664 if (strcmp(sReadersContexts[i]->library, libraryName) == 0)
670 valueLength =
sizeof(tagValue);
673 &valueLength, tagValue);
678 supportedChannels = tagValue[0];
680 "Support %d simultaneous readers", tagValue[0]);
683 supportedChannels = 1;
686 if ((((sReadersContexts[i]->port & 0xFFFF0000) ==
687 PCSCLITE_HP_BASE_PORT)
688 && (sReadersContexts[i]->port != port))
689 || (supportedChannels > 1))
705 currentDigit = strtol(reader + strlen(reader) - 5, NULL, 16);
708 usedDigits[currentDigit] = TRUE;
719 if (currentDigit != -1)
724 if (usedDigits[i] == FALSE)
728 if (i == PCSCLITE_MAX_READERS_CONTEXTS)
730 Log2(PCSC_LOG_ERROR,
"Max number of readers reached: %d", PCSCLITE_MAX_READERS_CONTEXTS);
734 if (i >= supportedChannels)
736 Log3(PCSC_LOG_ERROR,
"Driver %s does not support more than "
737 "%d reader(s). Maybe the driver should support "
738 "TAG_IFD_SIMULTANEOUS_ACCESS", libraryName, supportedChannels);
748 rContext->
slot = i << 16;
753 LONG RFReaderInfo(
const char *readerName,
READER_CONTEXT ** sReader)
757 if (readerName == NULL)
762 if (sReadersContexts[i]->vHandle != 0)
764 if (strcmp(readerName,
765 sReadersContexts[i]->readerState->readerName) == 0)
768 REF_READER(sReadersContexts[i])
770 *sReader = sReadersContexts[i];
785 if (sReadersContexts[i]->vHandle != 0)
788 (void)pthread_mutex_lock(&sReadersContexts[i]->handlesList_lock);
789 currentHandle = list_seek(&sReadersContexts[i]->handlesList,
791 (void)pthread_mutex_unlock(&sReadersContexts[i]->handlesList_lock);
792 if (currentHandle != NULL)
795 REF_READER(sReadersContexts[i])
797 *sReader = sReadersContexts[i];
810 Log2(PCSC_LOG_INFO,
"Reusing already loaded driver for %s",
824 rv = DYN_GetAddress(rContext->
vHandle, &f,
"IFDHCreateChannelByName", TRUE);
828 rContext->
version = IFD_HVERSION_3_0;
832 rv = DYN_GetAddress(rContext->
vHandle, &f,
"IFDHCreateChannel", FALSE);
836 rContext->
version = IFD_HVERSION_2_0;
841 Log1(PCSC_LOG_CRITICAL,
"IFDHandler functions missing");
846 if (rContext->
version == IFD_HVERSION_2_0)
849 #define GET_ADDRESS_OPTIONALv2(s, code) \
852 int rvl = DYN_GetAddress(rContext->vHandle, &f1, "IFDH" #s, FALSE); \
853 if (SCARD_S_SUCCESS != rvl) \
857 rContext->psFunctions.psFunctions_v2.pvf ## s = f1; \
860 #define GET_ADDRESSv2(s) \
861 GET_ADDRESS_OPTIONALv2(s, \
862 Log1(PCSC_LOG_CRITICAL, "IFDHandler functions missing: " #s ); \
865 Log1(PCSC_LOG_INFO,
"Loading IFD Handler 2.0");
867 GET_ADDRESSv2(CreateChannel)
868 GET_ADDRESSv2(CloseChannel)
869 GET_ADDRESSv2(GetCapabilities)
870 GET_ADDRESSv2(SetCapabilities)
871 GET_ADDRESSv2(PowerICC)
872 GET_ADDRESSv2(TransmitToICC)
873 GET_ADDRESSv2(ICCPresence)
874 GET_ADDRESS_OPTIONALv2(SetProtocolParameters, )
876 GET_ADDRESSv2(Control)
878 else if (rContext->version == IFD_HVERSION_3_0)
881 #define GET_ADDRESS_OPTIONALv3(s, code) \
884 int rvl = DYN_GetAddress(rContext->vHandle, &f1, "IFDH" #s, FALSE); \
885 if (SCARD_S_SUCCESS != rvl) \
889 rContext->psFunctions.psFunctions_v3.pvf ## s = f1; \
892 #define GET_ADDRESSv3(s) \
893 GET_ADDRESS_OPTIONALv3(s, \
894 Log1(PCSC_LOG_CRITICAL, "IFDHandler functions missing: " #s ); \
897 Log1(PCSC_LOG_INFO,
"Loading IFD Handler 3.0");
899 GET_ADDRESSv2(CreateChannel)
900 GET_ADDRESSv2(CloseChannel)
901 GET_ADDRESSv2(GetCapabilities)
902 GET_ADDRESSv2(SetCapabilities)
903 GET_ADDRESSv2(PowerICC)
904 GET_ADDRESSv2(TransmitToICC)
905 GET_ADDRESSv2(ICCPresence)
906 GET_ADDRESS_OPTIONALv2(SetProtocolParameters, )
908 GET_ADDRESSv3(CreateChannelByName)
909 GET_ADDRESSv3(Control)
914 Log1(PCSC_LOG_CRITICAL,
"IFD Handler not 1.0/2.0 or 3.0");
932 if (*rContext->
pFeeds == 1)
934 Log1(PCSC_LOG_INFO,
"Unloading reader driver.");
935 (void)DYN_CloseLibrary(&rContext->
vHandle);
955 (void)pthread_mutex_lock(&LockMutex);
956 rv = RFCheckSharing(hCard, rContext);
962 (void)pthread_mutex_unlock(&LockMutex);
971 (void)pthread_mutex_lock(&LockMutex);
972 rv = RFCheckSharing(hCard, rContext);
985 (void)pthread_mutex_unlock(&LockMutex);
994 (void)pthread_mutex_lock(&LockMutex);
995 rv = RFCheckSharing(hCard, rContext);
1001 (void)pthread_mutex_unlock(&LockMutex);
1011 Log3(PCSC_LOG_INFO,
"Attempting startup of %s using %s",
1014 #ifndef PCSCLITE_STATIC_DRIVER
1016 rv = RFLoadReader(rContext);
1019 Log2(PCSC_LOG_ERROR,
"RFLoadReader failed: 0x%lX", rv);
1024 rv = RFBindFunctions(rContext);
1028 Log2(PCSC_LOG_ERROR,
"RFBindFunctions failed: 0x%lX", rv);
1029 (void)RFUnloadReader(rContext);
1034 rContext->
vHandle = RFInitializeReader;
1042 Log3(PCSC_LOG_CRITICAL,
"Open Port 0x%X Failed (%s)",
1046 rContext->
slot = -1;
1049 rContext->
slot = -1;
1062 Log2(PCSC_LOG_INFO,
"Attempting shutdown of %s.",
1066 if (rContext->
slot != -1)
1069 (void)RFUnBindFunctions(rContext);
1070 (void)RFUnloadReader(rContext);
1104 randHandle = SYS_RandomInt(0, -1);
1107 ret = RFReaderInfoById(randHandle, &dummy_reader);
1109 UNREF_READER(dummy_reader)
1126 int listLength, lrv;
1131 listLength = list_size(&rContext->handlesList);
1134 if (listLength >= maxReaderHandles)
1136 Log2(PCSC_LOG_CRITICAL,
1137 "Too many handles opened, exceeding configured max (%d)",
1144 if (NULL == newHandle)
1146 Log1(PCSC_LOG_CRITICAL,
"malloc failed");
1151 newHandle->
hCard = hCard;
1154 lrv = list_append(&rContext->handlesList, newHandle);
1158 Log2(PCSC_LOG_CRITICAL,
"list_append failed with return value: %d",
1174 currentHandle = list_seek(&rContext->handlesList, &hCard);
1175 if (NULL == currentHandle)
1177 Log2(PCSC_LOG_CRITICAL,
"list_seek failed to locate hCard=%lX", hCard);
1182 lrv = list_delete(&rContext->handlesList, currentHandle);
1184 Log2(PCSC_LOG_CRITICAL,
1185 "list_delete failed with return value: %d", lrv);
1187 free(currentHandle);
1196 LONG RFSetReaderEventState(
READER_CONTEXT * rContext, DWORD dwEvent)
1199 int list_index, listSize;
1203 listSize = list_size(&rContext->handlesList);
1205 for (list_index = 0; list_index < listSize; list_index++)
1207 currentHandle = list_get_at(&rContext->handlesList, list_index);
1208 if (NULL == currentHandle)
1210 Log2(PCSC_LOG_CRITICAL,
"list_get_at failed at index %d",
1235 currentHandle = list_seek(&rContext->handlesList, &hCard);
1237 if (NULL == currentHandle)
1240 Log2(PCSC_LOG_CRITICAL,
"list_seek failed for hCard 0x%lX", hCard);
1270 currentHandle = list_seek(&rContext->handlesList, &hCard);
1272 if (NULL == currentHandle)
1292 void RFCleanupReaders(
void)
1296 Log1(PCSC_LOG_INFO,
"entering cleaning function");
1299 if (sReadersContexts[i]->vHandle != 0)
1302 char lpcStripReader[MAX_READERNAME];
1304 Log2(PCSC_LOG_INFO,
"Stopping reader: %s",
1305 sReadersContexts[i]->readerState->readerName);
1307 strncpy(lpcStripReader,
1308 sReadersContexts[i]->readerState->readerName,
1309 sizeof(lpcStripReader));
1311 lpcStripReader[strlen(lpcStripReader) - 6] =
'\0';
1313 rv = RFRemoveReader(lpcStripReader, sReadersContexts[i]->port);
1316 Log2(PCSC_LOG_ERROR,
"RFRemoveReader error: 0x%08lX", rv);
1318 free(sReadersContexts[i]);
1336 void RFWaitForReaderInit(
void)
1338 int i, need_to_wait;
1342 need_to_wait = FALSE;
1346 if (sReadersContexts[i]->vHandle != NULL)
1350 == sReadersContexts[i]->readerState->cardAtrLength)
1352 Log2(PCSC_LOG_DEBUG,
"Waiting init for reader: %s",
1353 sReadersContexts[i]->readerState->readerName);
1354 need_to_wait = TRUE;
1361 }
while (need_to_wait);
1366 int RFStartSerialReaders(
const char *readerconf)
1372 ConfigFile = strdup(readerconf);
1374 rv = DBGetReaderListDir(readerconf, &reader_list);
1377 if (NULL == reader_list)
1384 (void)RFAddReader(reader_list[i].pcFriendlyname,
1385 reader_list[i].channelId,
1386 reader_list[i].pcLibpath, reader_list[i].pcDevicename);
1390 ConfigFileCRC += reader_list[i].pcFriendlyname[j];
1391 for (j=0; j<reader_list[i].
pcLibpath[j]; j++)
1392 ConfigFileCRC += reader_list[i].pcLibpath[j];
1394 ConfigFileCRC += reader_list[i].pcDevicename[j];
1397 free(reader_list[i].pcFriendlyname);
1398 free(reader_list[i].pcLibpath);
1399 free(reader_list[i].pcDevicename);
1406 void RFReCheckReaderConf(
void)
1411 (void)DBGetReaderListDir(ConfigFile, &reader_list);
1414 if (NULL == reader_list)
1424 crc += reader_list[i].pcFriendlyname[j];
1425 for (j=0; j<reader_list[i].
pcLibpath[j]; j++)
1426 crc += reader_list[i].pcLibpath[j];
1428 crc += reader_list[i].pcDevicename[j];
1432 if (crc != ConfigFileCRC)
1434 Log2(PCSC_LOG_CRITICAL,
1435 "configuration file: %s has been modified. Recheck canceled",
1443 char present = FALSE;
1445 Log2(PCSC_LOG_DEBUG,
"refresh reader: %s",
1446 reader_list[i].pcFriendlyname);
1451 if (sReadersContexts[r]->vHandle != 0)
1453 char lpcStripReader[MAX_READERNAME];
1457 strncpy(lpcStripReader,
1458 sReadersContexts[i]->readerState->readerName,
1459 sizeof(lpcStripReader));
1460 tmplen = strlen(lpcStripReader);
1461 lpcStripReader[tmplen - 6] = 0;
1463 if ((strcmp(reader_list[i].pcFriendlyname, lpcStripReader) == 0)
1464 && (reader_list[r].channelId == sReadersContexts[i]->port))
1475 Log2(PCSC_LOG_INFO,
"Reader %s disappeared",
1476 reader_list[i].pcFriendlyname);
1477 (void)RFRemoveReader(reader_list[i].pcFriendlyname,
1478 reader_list[r].channelId);
1487 (void)RFAddReader(reader_list[i].pcFriendlyname,
1488 reader_list[i].channelId, reader_list[i].pcLibpath,
1489 reader_list[i].pcDevicename);
1492 free(reader_list[i].pcFriendlyname);
1493 free(reader_list[i].pcLibpath);
1494 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.
#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.
RESPONSECODE(* pthCardEvent)(DWORD, int)
Card Event sync.
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.
uint32_t eventCounter
number of card events
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)
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...