55#ifdef PCSCLITE_STATIC_DRIVER
58 #if ! (defined(IFDHANDLERv2) || defined(IFDHANDLERv3))
59 #error IFDHANDLER version not defined
67RESPONSECODE
IFDSetPTS(READER_CONTEXT * rContext, DWORD dwProtocol,
68 UCHAR ucFlags, UCHAR ucPTS1, UCHAR ucPTS2, UCHAR ucPTS3)
72#ifndef PCSCLITE_STATIC_DRIVER
73 RESPONSECODE(*IFDH_set_protocol_parameters) (DWORD, DWORD, UCHAR,
74 UCHAR, UCHAR, UCHAR) = NULL;
76 IFDH_set_protocol_parameters = (RESPONSECODE(*)(DWORD, DWORD, UCHAR,
80 if (NULL == IFDH_set_protocol_parameters)
91#ifndef PCSCLITE_STATIC_DRIVER
92 rv = (*IFDH_set_protocol_parameters) (rContext->
slot,
93 dwProtocol, ucFlags, ucPTS1, ucPTS2, ucPTS3);
96 ucPTS1, ucPTS2, ucPTS3);
109#ifndef PCSCLITE_STATIC_DRIVER
110 RESPONSECODE(*IFDH_create_channel) (DWORD, DWORD) = NULL;
111 RESPONSECODE(*IFDH_create_channel_by_name) (DWORD, LPSTR) = NULL;
113 if (rContext->
version == IFD_HVERSION_2_0)
114 IFDH_create_channel =
118 IFDH_create_channel =
120 IFDH_create_channel_by_name =
126 (void)pthread_mutex_lock(rContext->
mMutex);
128#ifndef PCSCLITE_STATIC_DRIVER
129 if (IFDH_create_channel_by_name)
131 if (rContext->
device[0] !=
'\0')
132 rv = (*IFDH_create_channel_by_name) (rContext->
slot, rContext->
device);
134 rv = (*IFDH_create_channel) (rContext->
slot, rContext->
port);
137 rv = (*IFDH_create_channel) (rContext->
slot, rContext->
port);
139#if defined(IFDHANDLERv2)
144 if (rContext->
device[0] !=
'\0')
153 (void)pthread_mutex_unlock(rContext->
mMutex);
165 bool do_unlock =
true;
167#ifndef PCSCLITE_STATIC_DRIVER
168 RESPONSECODE(*IFDH_close_channel) (DWORD) = NULL;
176 rv = pthread_mutex_trylock(rContext->
mMutex);
179 Log2(PCSC_LOG_ERROR,
"Locking failed. %d tries remaining.", repeat);
191#ifndef PCSCLITE_STATIC_DRIVER
192 rv = (*IFDH_close_channel) (rContext->
slot);
199 (void)pthread_mutex_unlock(rContext->
mMutex);
208 DWORD dwLength, PUCHAR pucValue)
212#ifndef PCSCLITE_STATIC_DRIVER
213 RESPONSECODE(*IFDH_set_capabilities) (DWORD, DWORD, DWORD, PUCHAR) = NULL;
223#ifndef PCSCLITE_STATIC_DRIVER
224 rv = (*IFDH_set_capabilities) (rContext->
slot, dwTag,
239 PDWORD pdwLength, PUCHAR pucValue)
243#ifndef PCSCLITE_STATIC_DRIVER
244 RESPONSECODE(*IFDH_get_capabilities) (DWORD, DWORD, PDWORD, PUCHAR) = NULL;
246 IFDH_get_capabilities =
251 (void)pthread_mutex_lock(rContext->
mMutex);
253#ifndef PCSCLITE_STATIC_DRIVER
254 rv = (*IFDH_get_capabilities) (rContext->
slot, dwTag, pdwLength, pucValue);
260 (void)pthread_mutex_unlock(rContext->
mMutex);
268RESPONSECODE
IFDPowerICC(READER_CONTEXT * rContext, DWORD dwAction,
269 PUCHAR pucAtr, PDWORD pdwAtrLen)
274 DWORD dummyAtrLen =
sizeof(dummyAtr);
276#ifndef PCSCLITE_STATIC_DRIVER
277 RESPONSECODE(*IFDH_power_icc) (DWORD, DWORD, PUCHAR, PDWORD) = NULL;
287 if (NULL == pdwAtrLen)
288 pdwAtrLen = &dummyAtrLen;
299#ifndef PCSCLITE_STATIC_DRIVER
304 (void)pthread_mutex_lock(rContext->
mMutex);
306#ifndef PCSCLITE_STATIC_DRIVER
307 rv = (*IFDH_power_icc) (rContext->
slot, dwAction, pucAtr, pdwAtrLen);
313 (void)pthread_mutex_unlock(rContext->
mMutex);
323 (void)SendHotplugSignal();
332 Log3(PCSC_LOG_CRITICAL,
333 "Driver reported ATR length %lu exceeds maximum of %u",
346LONG
IFDStatusICC(READER_CONTEXT * rContext, PDWORD pdwStatus,
bool hotplug)
349 DWORD dwCardStatus = 0;
351#ifndef PCSCLITE_STATIC_DRIVER
352 RESPONSECODE(*IFDH_icc_presence) (DWORD) = NULL;
358 (void)pthread_mutex_lock(rContext->
mMutex);
360#ifndef PCSCLITE_STATIC_DRIVER
361 rv = (*IFDH_icc_presence) (rContext->
slot);
367 (void)pthread_mutex_unlock(rContext->
mMutex);
376 Log2(PCSC_LOG_ERROR,
"Card not transacted: %ld", rv);
382 (void)SendHotplugSignal();
389 *pdwStatus = dwCardStatus;
404LONG IFDControl_v2(READER_CONTEXT * rContext, PUCHAR TxBuffer,
405 DWORD TxLength, PUCHAR RxBuffer, PDWORD RxLength)
409#ifndef PCSCLITE_STATIC_DRIVER
410 RESPONSECODE(*IFDH_control_v2) (DWORD, PUCHAR, DWORD, PUCHAR,
414 if (rContext->
version != IFD_HVERSION_2_0)
417#ifndef PCSCLITE_STATIC_DRIVER
422 (void)pthread_mutex_lock(rContext->
mMutex);
424#ifndef PCSCLITE_STATIC_DRIVER
425 rv = (*IFDH_control_v2) (rContext->
slot, TxBuffer, TxLength,
427#elif defined(IFDHANDLERv2)
433 (void)pthread_mutex_unlock(rContext->
mMutex);
439 Log2(PCSC_LOG_ERROR,
"Card not transacted: %ld", rv);
440 LogXxd(PCSC_LOG_DEBUG,
"TxBuffer ", TxBuffer, TxLength);
441 LogXxd(PCSC_LOG_DEBUG,
"RxBuffer ", RxBuffer, *RxLength);
456 LPCVOID TxBuffer, DWORD TxLength, LPVOID RxBuffer, DWORD RxLength,
457 LPDWORD BytesReturned)
461#ifndef PCSCLITE_STATIC_DRIVER
462 RESPONSECODE(*IFDH_control) (DWORD, DWORD, LPCVOID, DWORD, LPVOID, DWORD, LPDWORD);
465 if (rContext->
version < IFD_HVERSION_3_0)
468#ifndef PCSCLITE_STATIC_DRIVER
473 (void)pthread_mutex_lock(rContext->
mMutex);
475#ifndef PCSCLITE_STATIC_DRIVER
476 rv = (*IFDH_control) (rContext->
slot, ControlCode, TxBuffer,
477 TxLength, RxBuffer, RxLength, BytesReturned);
478#elif defined(IFDHANDLERv3)
480 TxLength, RxBuffer, RxLength, BytesReturned);
484 (void)pthread_mutex_unlock(rContext->
mMutex);
490 Log2(PCSC_LOG_ERROR,
"Card not transacted: %ld", rv);
491 Log3(PCSC_LOG_DEBUG,
"ControlCode: 0x%.8lX BytesReturned: %ld",
492 ControlCode, *BytesReturned);
493 LogXxd(PCSC_LOG_DEBUG,
"TxBuffer ", TxBuffer, TxLength);
494 LogXxd(PCSC_LOG_DEBUG,
"RxBuffer ", RxBuffer, *BytesReturned);
498 (void)SendHotplugSignal();
516 PUCHAR pucTxBuffer, DWORD dwTxLength, PUCHAR pucRxBuffer,
517 PDWORD pdwRxLength, PSCARD_IO_HEADER pioRxPci)
521#ifndef PCSCLITE_STATIC_DRIVER
523 DWORD, PUCHAR, PDWORD, PSCARD_IO_HEADER) = NULL;
527 DebugLogCategory(DEBUG_CATEGORY_APDU, pucTxBuffer, dwTxLength);
529#ifndef PCSCLITE_STATIC_DRIVER
530 IFDH_transmit_to_icc =
535 (void)pthread_mutex_lock(rContext->
mMutex);
537#ifndef PCSCLITE_STATIC_DRIVER
538 rv = (*IFDH_transmit_to_icc) (rContext->
slot, pioTxPci, (LPBYTE)
539 pucTxBuffer, dwTxLength, pucRxBuffer, pdwRxLength, pioRxPci);
542 (LPBYTE) pucTxBuffer, dwTxLength,
543 pucRxBuffer, pdwRxLength, pioRxPci);
547 (void)pthread_mutex_unlock(rContext->
mMutex);
550 DebugLogCategory(DEBUG_CATEGORY_SW, pucRxBuffer, *pdwRxLength);
556 Log2(PCSC_LOG_ERROR,
"Card not transacted: %ld", rv);
560 (void)SendHotplugSignal();
This keeps track of smart card protocols, timing issues and Answer to Reset ATR handling.
This abstracts dynamic library loading functions.
#define SCARD_S_SUCCESS
No error was encountered.
#define SCARD_W_REMOVED_CARD
The smart card has been removed, so further communication is not possible.
#define SCARD_E_INSUFFICIENT_BUFFER
The data buffer to receive returned data is too small for the returned data.
#define SCARD_E_NO_SMARTCARD
The operation requires a Smart Card, but no Smart Card is currently in the device.
#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.
#define SCARD_E_UNSUPPORTED_FEATURE
This smart card does not support the requested feature.
RESPONSECODE IFDHCloseChannel(DWORD Lun)
This function should close the reader communication channel for the particular reader.
RESPONSECODE IFDHGetCapabilities(DWORD Lun, DWORD Tag, PDWORD Length, PUCHAR Value)
This function should get the slot/card capabilities for a particular slot/card specified by Lun.
RESPONSECODE IFDHSetProtocolParameters(DWORD Lun, DWORD Protocol, UCHAR Flags, UCHAR PTS1, UCHAR PTS2, UCHAR PTS3)
This function should set the Protocol Type Selection (PTS) of a particular card/slot using the three ...
RESPONSECODE IFDHSetCapabilities(DWORD Lun, DWORD Tag, DWORD Length, PUCHAR Value)
This function should set the slot/card capabilities for a particular slot/card specified by Lun.
RESPONSECODE IFDHCreateChannelByName(DWORD Lun, LPSTR DeviceName)
This function is required to open a communications channel to the port listed by DeviceName.
RESPONSECODE IFDHControl(DWORD Lun, DWORD dwControlCode, PUCHAR TxBuffer, DWORD TxLength, PUCHAR RxBuffer, DWORD RxLength, LPDWORD pdwBytesReturned)
This function performs a data exchange with the reader (not the card) specified by Lun.
RESPONSECODE IFDHICCPresence(DWORD Lun)
This function returns the status of the card inserted in the reader/slot specified by Lun.
RESPONSECODE IFDHTransmitToICC(DWORD Lun, SCARD_IO_HEADER SendPci, PUCHAR TxBuffer, DWORD TxLength, PUCHAR RxBuffer, PDWORD RxLength, PSCARD_IO_HEADER RecvPci)
This function performs an APDU exchange with the card/slot specified by Lun.
RESPONSECODE IFDHCreateChannel(DWORD Lun, DWORD Channel)
This function is required to open a communications channel to the port listed by Channel.
RESPONSECODE IFDHPowerICC(DWORD Lun, DWORD Action, PUCHAR Atr, PDWORD AtrLength)
This function controls the power and reset signals of the smart card reader at the particular reader/...
#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 IFD_NOT_SUPPORTED
request is not supported
struct _SCARD_IO_HEADER SCARD_IO_HEADER
Use by SCardTransmit().
#define IFD_ERROR_INSUFFICIENT_BUFFER
buffer is too small
#define IFD_ICC_PRESENT
card is present
#define IFD_ICC_NOT_PRESENT
card is absent
#define IFD_SUCCESS
no error
RESPONSECODE IFDCloseIFD(READER_CONTEXT *rContext)
Close a communication channel to the IFD.
LONG IFDStatusICC(READER_CONTEXT *rContext, PDWORD pdwStatus, bool hotplug)
Provide statistical information about the IFD and ICC including insertions, atr, powering status/etc.
RESPONSECODE IFDOpenIFD(READER_CONTEXT *rContext)
Open a communication channel to the IFD.
LONG IFDControl(READER_CONTEXT *rContext, DWORD ControlCode, LPCVOID TxBuffer, DWORD TxLength, LPVOID RxBuffer, DWORD RxLength, LPDWORD BytesReturned)
Provide a means for toggling a specific action on the reader such as swallow, eject,...
RESPONSECODE IFDGetCapabilities(READER_CONTEXT *rContext, DWORD dwTag, PDWORD pdwLength, PUCHAR pucValue)
Gets capabilities in the reader.
LONG IFDTransmit(READER_CONTEXT *rContext, SCARD_IO_HEADER pioTxPci, PUCHAR pucTxBuffer, DWORD dwTxLength, PUCHAR pucRxBuffer, PDWORD pdwRxLength, PSCARD_IO_HEADER pioRxPci)
Transmit an APDU to the ICC.
RESPONSECODE IFDSetCapabilities(READER_CONTEXT *rContext, DWORD dwTag, DWORD dwLength, PUCHAR pucValue)
Set capabilities in the reader.
RESPONSECODE IFDSetPTS(READER_CONTEXT *rContext, DWORD dwProtocol, UCHAR ucFlags, UCHAR ucPTS1, UCHAR ucPTS2, UCHAR ucPTS3)
Set the protocol type selection (PTS).
RESPONSECODE IFDPowerICC(READER_CONTEXT *rContext, DWORD dwAction, PUCHAR pucAtr, PDWORD pdwAtrLen)
Power up/down or reset's an ICC located in the IFD.
This wraps the dynamic ifdhandler functions.
#define SCARD_PRESENT
Card is present.
#define MAX_ATR_SIZE
Maximum ATR size.
#define SCARD_ABSENT
Card is absent.
#define SCARD_UNKNOWN
Unknown state.
This keeps track of a list of currently available reader structures.
pthread_mutex_t * mMutex
Mutex for this connection.
union ReaderContext::@326266165201103155124353152063316062370301160101 psFunctions
driver functions
FCT_MAP_V3 psFunctions_v3
API V3.0.
int slot
Current Reader Slot.
int version
IFD Handler version number.
FCT_MAP_V2 psFunctions_v2
API V2.0.
char * device
Device Name.
This handles abstract system level calls.
int SYS_USleep(int)
Makes the current process sleep for some microseconds.