66LONG EHRegisterClientForEvent(int32_t filedes)
72 (void)MSGSendReaderStates(filedes);
108 Log2(PCSC_LOG_ERROR,
"Can't remove client: %d", filedes);
135LONG EHInitializeEventStructures(
void)
150LONG EHDeinitializeEventStructures(
void)
166 Log1(PCSC_LOG_INFO,
"Thread already stomped.");
175 Log1(PCSC_LOG_INFO,
"Stomping thread.");
178 dwGetSize =
sizeof(ucGetData);
180 &dwGetSize, ucGetData);
182 if ((
IFD_SUCCESS == rv) && (1 == dwGetSize) && ucGetData[0])
184 Log1(PCSC_LOG_INFO,
"Killing polling thread");
185 (void)pthread_cancel(rContext->
pthThread);
190 RESPONSECODE (*fct)(DWORD) = NULL;
192 dwGetSize =
sizeof(fct);
194 &dwGetSize, (PUCHAR)&fct);
196 if ((
IFD_SUCCESS == rv) && (dwGetSize ==
sizeof(fct)))
198 Log1(PCSC_LOG_INFO,
"Request stopping of polling thread");
202 Log1(PCSC_LOG_INFO,
"Waiting polling thread");
206 rv = pthread_join(rContext->
pthThread, NULL);
208 Log2(PCSC_LOG_ERROR,
"pthread_join failed: %s", strerror(rv));
213 Log1(PCSC_LOG_INFO,
"Thread stomped.");
226 Log2(PCSC_LOG_ERROR,
"Initial Check Failed on %s",
231 rv = ThreadCreate(&rContext->
pthThread, 0,
232 (PCSCLITE_THREAD_FUNCTION( ))EHStatusHandlerThread, (LPVOID) rContext);
235 Log2(PCSC_LOG_ERROR,
"ThreadCreate failed: %s", strerror(rv));
246 const char *readerName;
249 uint32_t readerState;
250 int32_t readerSharing;
251 DWORD dwCurrentState;
252#ifndef DISABLE_AUTO_POWER_ON
269#ifdef DISABLE_AUTO_POWER_ON
273 Log1(PCSC_LOG_INFO,
"Skip card power on");
286 RFSetPowerState(rContext, POWER_STATE_POWERED);
287 Log1(PCSC_LOG_DEBUG,
"powerState: POWER_STATE_POWERED");
291 LogXxd(PCSC_LOG_INFO,
"Card ATR: ",
296 Log1(PCSC_LOG_INFO,
"Card ATR: (NULL)");
301 RFSetPowerState(rContext, POWER_STATE_UNPOWERED);
302 Log1(PCSC_LOG_DEBUG,
"powerState: POWER_STATE_UNPOWERED");
303 Log2(PCSC_LOG_ERROR,
"Error powering up card: %s", rv2text(rv));
334 Log2(PCSC_LOG_ERROR,
"Error communicating to: %s", readerName);
356 Log2(PCSC_LOG_INFO,
"Card Removed From %s", readerName);
360 (void)RFSetReaderEventState(rContext, SCARD_REMOVED);
380#ifdef DISABLE_AUTO_POWER_ON
384 RFSetPowerState(rContext, POWER_STATE_UNPOWERED);
385 Log1(PCSC_LOG_DEBUG,
"powerState: POWER_STATE_UNPOWERED");
387 Log1(PCSC_LOG_INFO,
"Skip card power on");
403 RFSetPowerState(rContext, POWER_STATE_POWERED);
404 Log1(PCSC_LOG_DEBUG,
"powerState: POWER_STATE_POWERED");
409 RFSetPowerState(rContext, POWER_STATE_UNPOWERED);
410 Log1(PCSC_LOG_DEBUG,
"powerState: POWER_STATE_UNPOWERED");
421 Log2(PCSC_LOG_INFO,
"Card inserted into %s", readerName);
429 LogXxd(PCSC_LOG_INFO,
"Card ATR: ",
434 Log1(PCSC_LOG_INFO,
"Card ATR: (NULL)");
437 Log1(PCSC_LOG_ERROR,
"Error powering up card.");
444 if (readerSharing != rContext->
contexts)
456#ifndef DISABLE_ON_DEMAND_POWER_ON
459 timeout = PCSCLITE_POWER_OFF_GRACE_PERIOD;
463 timeout = PCSCLITE_STATUS_EVENT_TIMEOUT;
472#ifndef DISABLE_ON_DEMAND_POWER_ON
475 if (POWER_STATE_POWERED == rContext->
powerState)
480 Log1(PCSC_LOG_DEBUG,
"powerState: POWER_STATE_UNPOWERED");
487 if (POWER_STATE_GRACE_PERIOD == rContext->
powerState)
492 Log1(PCSC_LOG_DEBUG,
"powerState: POWER_STATE_POWERED");
497 if (rContext->
hLockId == 0xFFFF)
502 Log1(PCSC_LOG_INFO,
"Die");
504 (void)pthread_exit(NULL);
This abstracts dynamic library loading functions.
static list_t ClientsWaitingForEvent
list of client file descriptors
LONG EHTryToUnregisterClientForEvent(int32_t filedes)
Try to unregister a client If no client is found then do not log an error.
void EHSignalEventToClients(void)
Sends an asynchronous event to any waiting client.
pthread_mutex_t ClientsWaitingForEvent_lock
lock for the above list
LONG EHUnregisterClientForEvent(int32_t filedes)
Unregister a client and log an error if the client is not found.
This handles card insertion/removal events, updates ATR, protocol, and status information.
#define SCARD_F_INTERNAL_ERROR
An internal consistency check failed.
#define SCARD_F_UNKNOWN_ERROR
An internal error has been detected, but the source is unknown.
#define SCARD_S_SUCCESS
No error was encountered.
#define SCARD_E_NO_MEMORY
Not enough memory available to complete this command.
#define IFD_POWER_UP
power up the card
#define TAG_IFD_STOP_POLLING_THREAD
method used to stop the polling thread (instead of just pthread_kill())
#define IFD_POWER_DOWN
power down the card
#define TAG_IFD_POLLING_THREAD_KILLABLE
the polling thread can be killed
#define IFD_SUCCESS
no error
RESPONSECODE IFDGetCapabilities(READER_CONTEXT *rContext, DWORD dwTag, PDWORD pdwLength, PUCHAR pucValue)
Gets capabilities in the reader.
LONG IFDStatusICC(READER_CONTEXT *rContext, PDWORD pdwStatus)
Provide statistical information about the IFD and ICC including insertions, atr, powering status/etc.
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_SWALLOWED
Card not powered.
#define SCARD_PROTOCOL_UNDEFINED
protocol not set
#define SCARD_PRESENT
Card is present.
#define SCARD_POWERED
Card is powered.
#define SCARD_ABSENT
Card is absent.
#define SCARD_UNKNOWN
Unknown state.
#define SCARD_NEGOTIABLE
Ready for PTS.
This handles protocol defaults, PTS, etc.
int RFGetPowerState(READER_CONTEXT *rContext)
Wait until all connected readers have a chance to power up a possibly inserted card.
This keeps track of a list of currently available reader structures.
RESPONSECODE(* pthCardEvent)(DWORD, int)
Card Event sync.
pthread_mutex_t powerState_lock
powerState mutex
pthread_t pthThread
Event polling thread.
_Atomic int32_t contexts
Number of open contexts.
int slot
Current Reader Slot.
_Atomic SCARDHANDLE hLockId
Lock Id.
struct pubReaderStatesList * readerState
link to the reader state
int powerState
auto power off state
_Atomic int32_t readerSharing
PCSCLITE_SHARING_* sharing status.
char readerName[MAX_READERNAME]
reader name
uint32_t cardProtocol
SCARD_PROTOCOL_* value.
UCHAR cardAtr[MAX_ATR_SIZE]
ATR.
uint32_t eventCounter
number of card events
_Atomic uint32_t cardAtrLength
ATR length.
uint32_t readerState
SCARD_* bit field.
This handles abstract system level calls.
int SYS_USleep(int)
Makes the current process sleep for some microseconds.
This demarshalls functions over the message queue and keeps track of clients and their handles.