19 #include <sys/types.h>
46 LONG EHRegisterClientForEvent(int32_t filedes)
50 (void)list_append(&ClientsWaitingForEvent, &filedes);
68 ret = list_delete(&ClientsWaitingForEvent, &filedes);
86 Log2(PCSC_LOG_ERROR,
"Can't remove client: %d", filedes);
101 (void)list_iterator_start(&ClientsWaitingForEvent);
102 while (list_iterator_hasnext(&ClientsWaitingForEvent))
104 filedes = *(int32_t *)list_iterator_next(&ClientsWaitingForEvent);
107 (void)list_iterator_stop(&ClientsWaitingForEvent);
109 (void)list_clear(&ClientsWaitingForEvent);
116 LONG EHInitializeEventStructures(
void)
118 (void)list_init(&ClientsWaitingForEvent);
121 (void)list_attributes_copy(&ClientsWaitingForEvent, list_meter_int32_t, 1);
124 (void)list_attributes_comparator(&ClientsWaitingForEvent, list_comparator_int32_t);
139 Log1(PCSC_LOG_INFO,
"Thread already stomped.");
148 Log1(PCSC_LOG_INFO,
"Stomping thread.");
151 dwGetSize =
sizeof(ucGetData);
153 &dwGetSize, ucGetData);
155 #ifdef HAVE_PTHREAD_CANCEL
156 if ((
IFD_SUCCESS == rv) && (1 == dwGetSize) && ucGetData[0])
158 Log1(PCSC_LOG_INFO,
"Killing polling thread");
159 (void)pthread_cancel(rContext->
pthThread);
165 RESPONSECODE (*fct)(DWORD) = NULL;
167 dwGetSize =
sizeof(fct);
169 &dwGetSize, (PUCHAR)&fct);
171 if ((
IFD_SUCCESS == rv) && (dwGetSize ==
sizeof(fct)))
173 Log1(PCSC_LOG_INFO,
"Request stopping of polling thread");
177 Log1(PCSC_LOG_INFO,
"Waiting polling thread");
181 rv = pthread_join(rContext->
pthThread, NULL);
183 Log2(PCSC_LOG_ERROR,
"pthread_join failed: %s", strerror(rv));
188 Log1(PCSC_LOG_INFO,
"Thread stomped.");
201 Log2(PCSC_LOG_ERROR,
"Initial Check Failed on %s",
206 rv = ThreadCreate(&rContext->
pthThread, 0,
207 (PCSCLITE_THREAD_FUNCTION( ))EHStatusHandlerThread, (LPVOID) rContext);
210 Log2(PCSC_LOG_ERROR,
"ThreadCreate failed: %s", strerror(rv));
220 const char *readerName;
222 uint32_t readerState;
223 int32_t readerSharing;
224 DWORD dwCurrentState;
238 #ifdef DISABLE_AUTO_POWER_ON
242 Log1(PCSC_LOG_INFO,
"Skip card power on");
256 Log1(PCSC_LOG_DEBUG,
"powerState: POWER_STATE_POWERED");
260 LogXxd(PCSC_LOG_INFO,
"Card ATR: ",
265 Log1(PCSC_LOG_INFO,
"Card ATR: (NULL)");
271 Log1(PCSC_LOG_DEBUG,
"powerState: POWER_STATE_UNPOWERED");
272 Log3(PCSC_LOG_ERROR,
"Error powering up card: %ld 0x%04lX", rv, rv);
303 Log2(PCSC_LOG_ERROR,
"Error communicating to: %s", readerName);
319 if (dwCurrentState == SCARD_PRESENT ||
325 Log2(PCSC_LOG_INFO,
"Card Removed From %s", readerName);
342 else if (dwStatus & SCARD_PRESENT)
344 if (dwCurrentState == SCARD_ABSENT ||
347 #ifdef DISABLE_AUTO_POWER_ON
352 Log1(PCSC_LOG_DEBUG,
"powerState: POWER_STATE_UNPOWERED");
355 Log1(PCSC_LOG_INFO,
"Skip card power on");
372 Log1(PCSC_LOG_DEBUG,
"powerState: POWER_STATE_POWERED");
378 Log1(PCSC_LOG_DEBUG,
"powerState: POWER_STATE_UNPOWERED");
387 Log2(PCSC_LOG_INFO,
"Card inserted into %s", readerName);
395 LogXxd(PCSC_LOG_INFO,
"Card ATR: ",
400 Log1(PCSC_LOG_INFO,
"Card ATR: (NULL)");
403 Log1(PCSC_LOG_ERROR,
"Error powering up card.");
410 if (readerSharing != rContext->
contexts)
422 #ifndef DISABLE_ON_DEMAND_POWER_ON
438 #ifndef DISABLE_ON_DEMAND_POWER_ON
446 Log1(PCSC_LOG_DEBUG,
"powerState: POWER_STATE_UNPOWERED");
458 Log1(PCSC_LOG_DEBUG,
"powerState: POWER_STATE_POWERED");
463 if (rContext->
hLockId == 0xFFFF)
469 Log1(PCSC_LOG_INFO,
"Die");
471 (void)pthread_exit(NULL);
LONG EHUnregisterClientForEvent(int32_t filedes)
Unregister a client and log an error if the client is not found.
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.
volatile SCARDHANDLE hLockId
Lock Id.
#define TAG_IFD_STOP_POLLING_THREAD
method used to stop the polling thread (instead of just pthread_kill())
pthread_t pthThread
Event polling thread.
RESPONSECODE(* pthCardEvent)(DWORD, int)
Card Event sync.
LONG IFDGetCapabilities(READER_CONTEXT *rContext, DWORD dwTag, PDWORD pdwLength, PUCHAR pucValue)
Get's capabilities in the reader.
#define SCARD_UNKNOWN
Unknown state.
char readerName[MAX_READERNAME]
reader name
int32_t readerSharing
PCSCLITE_SHARING_* sharing status.
This handles protocol defaults, PTS, etc.
This handles abstract system level calls.
int slot
Current Reader Slot.
uint32_t eventCounter
number of card events
LONG EHSignalEventToClients(void)
Sends an asynchronous event to any waiting client.
This wraps the dynamic ifdhandler functions.
This demarshalls functions over the message queue and keeps track of clients and their handles...
#define SCARD_F_UNKNOWN_ERROR
An internal error has been detected, but the source is unknown.
#define SCARD_PRESENT
Card is present.
int SYS_USleep(int)
Makes the current process sleep for some microseconds.
#define SCARD_NEGOTIABLE
Ready for PTS.
prototypes of strlcpy()/strlcat() imported from OpenBSD
#define IFD_POWER_DOWN
power down the card
static list_t ClientsWaitingForEvent
list of client file descriptors
#define PCSCLITE_STATUS_POLL_RATE
Status polling rate.
LONG EHTryToUnregisterClientForEvent(int32_t filedes)
Try to unregisted a client If no client is found then do not log an error.
This handles card insertion/removal events, updates ATR, protocol, and status information.
pthread_mutex_t ClientsWaitingForEvent_lock
lock for the above list
#define SCARD_SWALLOWED
Card not powered.
int powerState
auto power off state
#define SCARD_PROTOCOL_UNDEFINED
protocol not set
UCHAR cardAtr[MAX_ATR_SIZE]
ATR.
LONG IFDPowerICC(READER_CONTEXT *rContext, DWORD dwAction, PUCHAR pucAtr, PDWORD pdwAtrLen)
Power up/down or reset's an ICC located in the IFD.
#define PCSCLITE_STATUS_EVENT_TIMEOUT
normal timeout for pthCardEvent driver function when no card or card in use
#define SCARD_POWERED
Card is powered.
#define PCSCLITE_POWER_OFF_GRACE_PERIOD
time to wait before powering down an unused card
This keeps a list of defines for pcsc-lite.
#define SCARD_ABSENT
Card is absent.
uint32_t cardProtocol
SCARD_PROTOCOL_* value.
#define SCARD_E_NO_MEMORY
Not enough memory available to complete this command.
This keeps track of a list of currently available reader structures.
uint32_t readerState
SCARD_* bit field.
pthread_mutex_t powerState_lock
powerState mutex
#define SCARD_S_SUCCESS
error codes from http://msdn.microsoft.com/en-us/library/aa924526.aspx
#define IFD_POWER_UP
power up the card
#define TAG_IFD_POLLING_THREAD_KILLABLE
the polling thread can be killed
#define IFD_SUCCESS
no error
#define SCARD_REMOVED
Card was removed.
#define SCARD_F_INTERNAL_ERROR
An internal consistency check failed.