Go to the documentation of this file.
40 #include <sys/types.h>
66 LONG EHRegisterClientForEvent(int32_t filedes)
72 (void)MSGSendReaderStates(filedes);
108 Log2(PCSC_LOG_ERROR,
"Can't remove client: %d", filedes);
135 LONG EHInitializeEventStructures(
void)
150 LONG 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);
LONG EHUnregisterClientForEvent(int32_t filedes)
Unregister a client and log an error if the client is not found.
uint32_t readerState
SCARD_* bit field.
LONG IFDStatusICC(READER_CONTEXT *rContext, PDWORD pdwStatus)
Provide statistical information about the IFD and ICC including insertions, atr, powering status/etc.
#define TAG_IFD_POLLING_THREAD_KILLABLE
the polling thread can be killed
#define SCARD_POWERED
Card is powered.
uint32_t cardProtocol
SCARD_PROTOCOL_* value.
int slot
Current Reader Slot.
char readerName[MAX_READERNAME]
reader name
This abstracts dynamic library loading functions.
#define SCARD_S_SUCCESS
No error was encountered.
uint32_t eventCounter
number of card events
#define SCARD_PROTOCOL_UNDEFINED
protocol not set
int SYS_USleep(int)
Makes the current process sleep for some microseconds.
#define SCARD_ABSENT
Card is absent.
RESPONSECODE IFDGetCapabilities(READER_CONTEXT *rContext, DWORD dwTag, PDWORD pdwLength, PUCHAR pucValue)
Gets capabilities in the reader.
This handles abstract system level calls.
#define SCARD_UNKNOWN
Unknown state.
This keeps track of a list of currently available reader structures.
This handles card insertion/removal events, updates ATR, protocol, and status information.
This demarshalls functions over the message queue and keeps track of clients and their handles.
This handles protocol defaults, PTS, etc.
struct pubReaderStatesList * readerState
link to the reader state
void EHSignalEventToClients(void)
Sends an asynchronous event to any waiting client.
pthread_mutex_t powerState_lock
powerState mutex
_Atomic int32_t contexts
Number of open contexts.
#define SCARD_SWALLOWED
Card not powered.
int powerState
auto power off state
static list_t ClientsWaitingForEvent
list of client file descriptors
#define IFD_SUCCESS
no error
pthread_mutex_t ClientsWaitingForEvent_lock
lock for the above list
#define TAG_IFD_STOP_POLLING_THREAD
method used to stop the polling thread (instead of just pthread_kill())
RESPONSECODE IFDPowerICC(READER_CONTEXT *rContext, DWORD dwAction, PUCHAR pucAtr, PDWORD pdwAtrLen)
Power up/down or reset's an ICC located in the IFD.
#define IFD_POWER_UP
power up the card
#define SCARD_E_NO_MEMORY
Not enough memory available to complete this command.
#define IFD_POWER_DOWN
power down the card
RESPONSECODE(* pthCardEvent)(DWORD, int)
Card Event sync.
#define SCARD_NEGOTIABLE
Ready for PTS.
#define SCARD_F_UNKNOWN_ERROR
An internal error has been detected, but the source is unknown.
UCHAR cardAtr[MAX_ATR_SIZE]
ATR.
_Atomic int32_t readerSharing
PCSCLITE_SHARING_* sharing status.
This wraps the dynamic ifdhandler functions.
int RFGetPowerState(READER_CONTEXT *rContext)
Wait until all connected readers have a chance to power up a possibly inserted card.
_Atomic uint32_t cardAtrLength
ATR length.
#define SCARD_PRESENT
Card is present.
pthread_t pthThread
Event polling thread.
#define SCARD_F_INTERNAL_ERROR
An internal consistency check failed.
LONG EHTryToUnregisterClientForEvent(int32_t filedes)
Try to unregister a client If no client is found then do not log an error.
_Atomic SCARDHANDLE hLockId
Lock Id.