#include "config.h"
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/un.h>
#include <errno.h>
#include "misc.h"
#include "pcsclite.h"
#include "winscard.h"
#include "debug.h"
#include "thread_generic.h"
#include "readerfactory.h"
#include "eventhandler.h"
#include "sys_generic.h"
#include "winscard_msg.h"
Go to the source code of this file.
Data Structures | |
struct | _psChannelMap |
Represents an Application Context Channel. More... | |
struct | _psContextMap |
Represents the an Application Context on the Client side. More... | |
Defines | |
#define | SCARD_PROTOCOL_ANY_OLD 0x1000 |
used for backward compatibility | |
#define | min(a, b) (((a) < (b)) ? (a) : (b)) |
#define | TRUE 1 |
#define | FALSE 0 |
#define | PROFILE_START |
#define | PROFILE_END |
Typedefs | |
typedef _psChannelMap CHANNEL_MAP * | PCHANNEL_MAP |
Functions | |
LONG | SCardAddContext (SCARDCONTEXT, DWORD) |
Adds an Application Context to the vector psContextMap . | |
LONG | SCardGetContextIndice (SCARDCONTEXT) |
Get the index from the Application Context vector psContextMap for the passed context. | |
LONG | SCardGetContextIndiceTH (SCARDCONTEXT) |
Get the index from the Application Context vector psContextMap for the passed context. | |
LONG | SCardRemoveContext (SCARDCONTEXT) |
Removes an Application Context from a control vector. | |
LONG | SCardAddHandle (SCARDHANDLE, DWORD, LPSTR) |
LONG | SCardGetIndicesFromHandle (SCARDHANDLE, PDWORD, PDWORD) |
LONG | SCardGetIndicesFromHandleTH (SCARDHANDLE, PDWORD, PDWORD) |
LONG | SCardRemoveHandle (SCARDHANDLE) |
LONG | SCardGetSetAttrib (SCARDHANDLE hCard, int command, DWORD dwAttrId, LPBYTE pbAttr, LPDWORD pcbAttrLen) |
LONG | SCardCheckDaemonAvailability (void) |
Checks if the Server is running. | |
LONG | SCardLockThread (void) |
This function locks a mutex so another thread must wait to use this function. | |
LONG | SCardUnlockThread (void) |
This function unlocks a mutex so another thread may use the client. | |
LONG | SCardEstablishContextTH (DWORD, LPCVOID, LPCVOID, LPSCARDCONTEXT) |
Creates a communication context to the PC/SC Resource Manager. | |
LONG | SCardEstablishContext (DWORD dwScope, LPCVOID pvReserved1, LPCVOID pvReserved2, LPSCARDCONTEXT phContext) |
Creates an Application Context for a client. | |
LONG | SCardReleaseContext (SCARDCONTEXT hContext) |
This function destroys a communication context to the PC/SC Resource Manager. This must be the last function called in a PC/SC application. | |
LONG | SCardSetTimeout (SCARDCONTEXT hContext, DWORD dwTimeout) |
LONG | SCardConnect (SCARDCONTEXT hContext, LPCSTR szReader, DWORD dwShareMode, DWORD dwPreferredProtocols, LPSCARDHANDLE phCard, LPDWORD pdwActiveProtocol) |
This function establishes a connection to the friendly name of the reader specified in szReader. | |
LONG | SCardReconnect (SCARDHANDLE hCard, DWORD dwShareMode, DWORD dwPreferredProtocols, DWORD dwInitialization, LPDWORD pdwActiveProtocol) |
This function reestablishes a connection to a reader that was previously connected to using SCardConnect(). | |
LONG | SCardDisconnect (SCARDHANDLE hCard, DWORD dwDisposition) |
This function terminates a connection to the connection made through SCardConnect(). | |
LONG | SCardBeginTransaction (SCARDHANDLE hCard) |
This function establishes a temporary exclusive access mode for doing a series of commands or transaction. | |
LONG | SCardEndTransaction (SCARDHANDLE hCard, DWORD dwDisposition) |
This function ends a previously begun transaction. | |
LONG | SCardCancelTransaction (SCARDHANDLE hCard) |
LONG | SCardStatus (SCARDHANDLE hCard, LPSTR mszReaderNames, LPDWORD pcchReaderLen, LPDWORD pdwState, LPDWORD pdwProtocol, LPBYTE pbAtr, LPDWORD pcbAtrLen) |
This function returns the current status of the reader connected to by hCard. | |
LONG | SCardGetStatusChange (SCARDCONTEXT hContext, DWORD dwTimeout, LPSCARD_READERSTATE_A rgReaderStates, DWORD cReaders) |
This function receives a structure or list of structures containing reader names. It then blocks for a change in state to occur on any of the OR'd values contained in dwCurrentState for a maximum blocking time of dwTimeout or forever if INFINITE is used. | |
LONG | SCardControl (SCARDHANDLE hCard, DWORD dwControlCode, LPCVOID pbSendBuffer, DWORD cbSendLength, LPVOID pbRecvBuffer, DWORD cbRecvLength, LPDWORD lpBytesReturned) |
This function sends a command directly to the IFD Handler to be processed by the reader. | |
LONG | SCardGetAttrib (SCARDHANDLE hCard, DWORD dwAttrId, LPBYTE pbAttr, LPDWORD pcbAttrLen) |
This function get an attribute from the IFD Handler. | |
LONG | SCardSetAttrib (SCARDHANDLE hCard, DWORD dwAttrId, LPCBYTE pbAttr, DWORD cbAttrLen) |
This function set an attribute of the IFD Handler. | |
LONG | SCardTransmit (SCARDHANDLE hCard, LPCSCARD_IO_REQUEST pioSendPci, LPCBYTE pbSendBuffer, DWORD cbSendLength, LPSCARD_IO_REQUEST pioRecvPci, LPBYTE pbRecvBuffer, LPDWORD pcbRecvLength) |
This function sends an APDU to the smart card contained in the reader connected to by SCardConnect(). | |
LONG | SCardListReaders (SCARDCONTEXT hContext, LPCSTR mszGroups, LPSTR mszReaders, LPDWORD pcchReaders) |
This function returns a list of currently available readers on the system. | |
LONG | SCardListReaderGroups (SCARDCONTEXT hContext, LPSTR mszGroups, LPDWORD pcchGroups) |
This function returns a list of currently available reader groups on the system. mszGroups is a pointer to a character string that is allocated by the application. If the application sends mszGroups as NULL then this function will return the size of the buffer needed to allocate in pcchGroups. | |
LONG | SCardCancel (SCARDCONTEXT hContext) |
This function cancels all pending blocking requests on the SCardGetStatusChange() function. | |
LONG | SCardIsValidContext (SCARDCONTEXT hContext) |
check if a SCARDCONTEXT is valid. | |
void DESTRUCTOR | SCardUnload (void) |
free resources allocated by the library You _shall_ call this function if you use dlopen/dlclose to load/unload the library. | |
Variables | |
_psContextMap | psContextMap [PCSCLITE_MAX_APPLICATION_CONTEXTS] |
Represents the an Application Context on the Client side. | |
short | isExecuted = 0 |
Make sure the initialization code is executed only once. | |
int | mapAddr = 0 |
Memory mapped address used to read status information about the readers. | |
PCSCLITE_MUTEX | clientMutex = PTHREAD_MUTEX_INITIALIZER |
Ensure that some functions be accessed in thread-safe mode. | |
PREADER_STATE | readerStates [PCSCLITE_MAX_READERS_CONTEXTS] |
Pointers to a memory mapped area used to read status information about the readers. | |
PCSC_API SCARD_IO_REQUEST | g_rgSCardT0Pci = { SCARD_PROTOCOL_T0, 8 } |
PCSC_API SCARD_IO_REQUEST | g_rgSCardT1Pci = { SCARD_PROTOCOL_T1, 8 } |
PCSC_API SCARD_IO_REQUEST | g_rgSCardRawPci = { SCARD_PROTOCOL_RAW, 8 } |
Here is exposed the API for client applications.
Definition in file winscard_clnt.c.
|
Adds an Application Context to the vector
Definition at line 3119 of file winscard_clnt.c. References _psContextMap::contextBlockStatus, _psContextMap::dwClientID, _psContextMap::hContext, _psContextMap::mMutex, psContextMap, SCardAddContext(), and SYS_MutexInit(). Referenced by SCardAddContext(), and SCardEstablishContextTH(). |
|
This function establishes a temporary exclusive access mode for doing a series of commands or transaction. You might want to use this when you are selecting a few files and then writing a large file so you can make sure that another application will not change the current file. If another application has a lock on this reader or this application is in SCARD_SHARE_EXCLUSIVE there will be no action taken.
Definition at line 1017 of file winscard_clnt.c. References rxSharedSegment::data, begin_struct::hCard, PCSCLITE_CLIENT_ATTEMPTS, _psContextMap::psChannelMap, psContextMap, readerStates, begin_struct::rv, SCardCheckDaemonAvailability(), sharedSegmentMsg, SHMClientRead(), SYS_MutexLock(), SYS_MutexUnLock(), SYS_USleep(), and WrapSHMWrite(). |
|
This function cancels all pending blocking requests on the SCardGetStatusChange() function.
Definition at line 3037 of file winscard_clnt.c. References _psContextMap::contextBlockStatus, psContextMap, and SCardGetContextIndice(). |
|
Definition at line 1258 of file winscard_clnt.c. References rxSharedSegment::data, cancel_struct::hCard, PCSCLITE_CLIENT_ATTEMPTS, _psContextMap::psChannelMap, psContextMap, readerStates, cancel_struct::rv, SCardCheckDaemonAvailability(), sharedSegmentMsg, SHMClientRead(), SYS_MutexLock(), SYS_MutexUnLock(), and WrapSHMWrite(). |
|
Checks if the Server is running.
Definition at line 3340 of file winscard_clnt.c. Referenced by SCardBeginTransaction(), SCardCancelTransaction(), SCardConnect(), SCardControl(), SCardDisconnect(), SCardEndTransaction(), SCardEstablishContextTH(), SCardGetStatusChange(), SCardListReaderGroups(), SCardListReaders(), SCardReconnect(), SCardReleaseContext(), SCardStatus(), and SCardTransmit(). |
|
This function establishes a connection to the friendly name of the reader specified in szReader. The first connection will power up and perform a reset on the card.
Definition at line 622 of file winscard_clnt.c. References rxSharedSegment::data, connect_struct::dwPreferredProtocols, connect_struct::dwShareMode, connect_struct::hContext, PCSCLITE_CLIENT_ATTEMPTS, connect_struct::pdwActiveProtocol, connect_struct::phCard, psContextMap, connect_struct::rv, SCardCheckDaemonAvailability(), SCardGetContextIndice(), sharedSegmentMsg, SHMClientRead(), SYS_MutexLock(), SYS_MutexUnLock(), connect_struct::szReader, and WrapSHMWrite(). |
|
This function sends a command directly to the IFD Handler to be processed by the reader. This is useful for creating client side reader drivers for functions like PIN pads, biometrics, or other extensions to the normal smart card reader that are not normally handled by PC/SC.
Definition at line 2152 of file winscard_clnt.c. References control_struct::cbRecvLength, control_struct_extended::cbRecvLength, control_struct::cbSendLength, control_struct_extended::cbSendLength, rxSharedSegment::data, control_struct_extended::data, control_struct::dwBytesReturned, _psContextMap::dwClientID, control_struct::dwControlCode, control_struct_extended::dwControlCode, control_struct::hCard, control_struct_extended::hCard, control_struct::pbSendBuffer, PCSCLITE_CLIENT_ATTEMPTS, PCSCLITE_MAX_MESSAGE_SIZE, _psContextMap::psChannelMap, psContextMap, psharedSegmentMsg, readerStates, control_struct::rv, SCardCheckDaemonAvailability(), sharedSegmentMsg, SHMClientRead(), SHMMessageReceive(), control_struct_extended::size, SYS_MutexLock(), SYS_MutexUnLock(), and WrapSHMWrite(). |
|
This function terminates a connection to the connection made through SCardConnect(). dwDisposition can have the following values:
Definition at line 919 of file winscard_clnt.c. References rxSharedSegment::data, disconnect_struct::dwDisposition, disconnect_struct::hCard, PCSCLITE_CLIENT_ATTEMPTS, psContextMap, disconnect_struct::rv, SCARD_LEAVE_CARD, SCARD_RESET_CARD, SCARD_UNPOWER_CARD, SCardCheckDaemonAvailability(), sharedSegmentMsg, SHMClientRead(), SYS_MutexLock(), SYS_MutexUnLock(), and WrapSHMWrite(). |
|
This function ends a previously begun transaction. The calling application must be the owner of the previously begun transaction or an error will occur.
Definition at line 1163 of file winscard_clnt.c. References rxSharedSegment::data, end_struct::dwDisposition, end_struct::hCard, PCSCLITE_CLIENT_ATTEMPTS, _psContextMap::psChannelMap, psContextMap, readerStates, end_struct::rv, SCARD_LEAVE_CARD, SCARD_RESET_CARD, SCARD_UNPOWER_CARD, SCardCheckDaemonAvailability(), sharedSegmentMsg, SHMClientRead(), SYS_MutexLock(), SYS_MutexUnLock(), SYS_USleep(), and WrapSHMWrite(). |
|
Creates an Application Context for a client. This must be the first function called in a PC/SC application. This is a thread-safe wrapper to the function SCardEstablishContextTH().
Definition at line 237 of file winscard_clnt.c. References SCardEstablishContextTH(), SCardLockThread(), and SCardUnlockThread(). |
|
|
This function get an attribute from the IFD Handler.
The list of possible attributes is available in the file
Definition at line 2406 of file winscard_clnt.c. |
|
Get the index from the Application Context vector This function is a thread-safe wrapper to the function SCardGetContextIndiceTH().
Definition at line 3151 of file winscard_clnt.c. References SCardGetContextIndice(), SCardGetContextIndiceTH(), SCardLockThread(), and SCardUnlockThread(). Referenced by SCardCancel(), SCardConnect(), SCardGetContextIndice(), SCardGetStatusChange(), SCardIsValidContext(), SCardListReaderGroups(), SCardListReaders(), and SCardReleaseContext(). |
|
Get the index from the Application Context vector This functions is not thread-safe and should not be called. Instead, call the function SCardGetContextIndice().
Definition at line 3174 of file winscard_clnt.c. References _psContextMap::hContext, and psContextMap. Referenced by SCardGetContextIndice(), and SCardRemoveContext(). |
|
This function receives a structure or list of structures containing reader names. It then blocks for a change in state to occur on any of the OR'd values contained in dwCurrentState for a maximum blocking time of dwTimeout or forever if INFINITE is used. The new event state will be contained in dwEventState. A status change might be a card insertion or removal event, a change in ATR, etc. This function will block for reader availability if cReaders is equal to zero and rgReaderStates is NULL.
typedef struct { LPCSTR szReader; // Reader name LPVOID pvUserData; // User defined data DWORD dwCurrentState; // Current state of reader DWORD dwEventState; // Reader state after a state change DWORD cbAtr; // ATR Length, usually MAX_ATR_SIZE BYTE rgbAtr[MAX_ATR_SIZE]; // ATR Value } SCARD_READERSTATE; ... typedef SCARD_READERSTATE *PSCARD_READERSTATE, **LPSCARD_READERSTATE; ... Value of dwCurrentState and dwEventState:
Definition at line 1613 of file winscard_clnt.c. References pubReaderStatesList::cardAtr, pubReaderStatesList::cardAtrLength, _psContextMap::contextBlockStatus, INFINITE, PCSCLITE_STATUS_POLL_RATE, PCSCLITE_STATUS_WAIT, PREADER_STATE, psContextMap, pubReaderStatesList::readerSharing, pubReaderStatesList::readerState, readerStates, SCARD_STATE_ATRMATCH, SCARD_STATE_CHANGED, SCARD_STATE_EXCLUSIVE, SCARD_STATE_PRESENT, SCARD_STATE_UNKNOWN, SCardCheckDaemonAvailability(), SCardGetContextIndice(), SYS_MutexLock(), SYS_MutexUnLock(), and SYS_USleep(). |
|
check if a SCARDCONTEXT is valid. Call this function to determine whether a smart card context handle is still valid. After a smart card context handle has been set by SCardEstablishContext, it may become not valid if the resource manager service has been shut down.
Definition at line 3082 of file winscard_clnt.c. References SCardGetContextIndice(). |
|
This function returns a list of currently available reader groups on the system. The group names is a multi-string and separated by a nul character ('\0') and ended by a double nul character. "SCard$DefaultReaders\\0Group 2\\0\\0".
Definition at line 2966 of file winscard_clnt.c. References psContextMap, SCardCheckDaemonAvailability(), SCardGetContextIndice(), SYS_MutexLock(), and SYS_MutexUnLock(). |
|
This function returns a list of currently available readers on the system.
Definition at line 2862 of file winscard_clnt.c. References psContextMap, readerStates, SCardCheckDaemonAvailability(), SCardGetContextIndice(), SYS_MutexLock(), and SYS_MutexUnLock(). |
|
This function locks a mutex so another thread must wait to use this function. Wrapper to the function SYS_MutexLock(). Definition at line 3318 of file winscard_clnt.c. References clientMutex, and SYS_MutexLock(). Referenced by SCardBeginTransaction(), SCardCancel(), SCardCancelTransaction(), SCardConnect(), SCardDisconnect(), SCardEndTransaction(), SCardEstablishContext(), SCardGetContextIndice(), SCardGetStatusChange(), SCardListReaderGroups(), SCardListReaders(), SCardReconnect(), SCardReleaseContext(), SCardStatus(), and SCardTransmit(). |
|
This function reestablishes a connection to a reader that was previously connected to using SCardConnect(). In a multi application environment it is possible for an application to reset the card in shared mode. When this occurs any other application trying to access certain commands will be returned the value SCARD_W_RESET_CARD. When this occurs SCardReconnect() must be called in order to acknowledge that the card was reset and allow it to change it's state accordingly.
Definition at line 791 of file winscard_clnt.c. References rxSharedSegment::data, reconnect_struct::dwInitialization, reconnect_struct::dwPreferredProtocols, reconnect_struct::dwShareMode, reconnect_struct::hCard, PCSCLITE_CLIENT_ATTEMPTS, reconnect_struct::pdwActiveProtocol, _psContextMap::psChannelMap, psContextMap, readerStates, reconnect_struct::rv, SCARD_LEAVE_CARD, SCARD_RESET_CARD, SCARD_UNPOWER_CARD, SCardCheckDaemonAvailability(), sharedSegmentMsg, SHMClientRead(), SYS_MutexLock(), SYS_MutexUnLock(), and WrapSHMWrite(). |
|
This function destroys a communication context to the PC/SC Resource Manager. This must be the last function called in a PC/SC application.
Definition at line 491 of file winscard_clnt.c. References rxSharedSegment::data, release_struct::hContext, PCSCLITE_CLIENT_ATTEMPTS, PCSCLITE_MCLIENT_ATTEMPTS, psContextMap, release_struct::rv, SCardCheckDaemonAvailability(), SCardGetContextIndice(), SCardLockThread(), SCardRemoveContext(), SCardUnlockThread(), sharedSegmentMsg, SHMClientRead(), SYS_MutexLock(), SYS_MutexUnLock(), and WrapSHMWrite(). |
|
Removes an Application Context from a control vector.
Definition at line 3199 of file winscard_clnt.c. References _psContextMap::contextBlockStatus, _psContextMap::dwClientID, _psContextMap::hContext, _psContextMap::mMutex, _psContextMap::psChannelMap, psContextMap, SCardGetContextIndiceTH(), SCardRemoveContext(), and SHMClientCloseSession(). Referenced by SCardReleaseContext(), and SCardRemoveContext(). |
|
This function set an attribute of the IFD Handler. The list of attributes you can set is dependent on the IFD Handler you are using.
Definition at line 2455 of file winscard_clnt.c. |
|
Definition at line 563 of file winscard_clnt.c. |
|
This function returns the current status of the reader connected to by hCard. It's friendly name will be stored in szReaderName. pcchReaderLen will be the size of the allocated buffer for szReaderName, while pcbAtrLen will be the size of the allocated buffer for pbAtr. If either of these is too small, the function will return with SCARD_E_INSUFFICIENT_BUFFER and the necessary size in pcchReaderLen and pcbAtrLen. The current state, and protocol will be stored in pdwState and pdwProtocol respectively.
Definition at line 1385 of file winscard_clnt.c. References rxSharedSegment::data, PCSCLITE_CLIENT_ATTEMPTS, _psContextMap::psChannelMap, psContextMap, readerStates, SCardCheckDaemonAvailability(), sharedSegmentMsg, SHMClientRead(), SYS_MutexLock(), SYS_MutexUnLock(), and WrapSHMWrite(). |
|
This function sends an APDU to the smart card contained in the reader connected to by SCardConnect(). The card responds from the APDU and stores this response in pbRecvBuffer and it's length in SpcbRecvLength. SSendPci and SRecvPci are structures containing the following: typedef struct { DWORD dwProtocol; // SCARD_PROTOCOL_T0 or SCARD_PROTOCOL_T1 DWORD cbPciLength; // Length of this structure - not used } SCARD_IO_REQUEST;
Definition at line 2623 of file winscard_clnt.c. References transmit_struct::cbSendLength, transmit_struct_extended::cbSendLength, rxSharedSegment::data, transmit_struct_extended::data, _psContextMap::dwClientID, transmit_struct::hCard, transmit_struct_extended::hCard, transmit_struct::pbSendBuffer, transmit_struct::pcbRecvLength, transmit_struct_extended::pcbRecvLength, PCSCLITE_CLIENT_ATTEMPTS, PCSCLITE_MAX_MESSAGE_SIZE, transmit_struct::pioRecvPci, transmit_struct_extended::pioRecvPci, transmit_struct::pioSendPci, transmit_struct_extended::pioSendPci, _psContextMap::psChannelMap, psContextMap, psharedSegmentMsg, readerStates, transmit_struct::rv, SCardCheckDaemonAvailability(), sharedSegmentMsg, SHMClientRead(), SHMMessageReceive(), transmit_struct_extended::size, SYS_MutexLock(), SYS_MutexUnLock(), and WrapSHMWrite(). |
|
free resources allocated by the library You _shall_ call this function if you use dlopen/dlclose to load/unload the library. Otherwise you will exhaust the ressources available. Definition at line 3365 of file winscard_clnt.c. References isExecuted, mapAddr, READER_STATE, readerStates, SYS_CloseFile(), and SYS_PublicMemoryUnmap(). |
|
This function unlocks a mutex so another thread may use the client. Wrapper to the function SYS_MutexUnLock(). Definition at line 3328 of file winscard_clnt.c. References clientMutex, and SYS_MutexUnLock(). Referenced by SCardBeginTransaction(), SCardCancel(), SCardCancelTransaction(), SCardConnect(), SCardDisconnect(), SCardEndTransaction(), SCardEstablishContext(), SCardGetContextIndice(), SCardGetStatusChange(), SCardListReaderGroups(), SCardListReaders(), SCardReconnect(), SCardReleaseContext(), SCardStatus(), and SCardTransmit(). |
|
Ensure that some functions be accessed in thread-safe mode. These function's names finishes with "TH". Definition at line 167 of file winscard_clnt.c. Referenced by SCardLockThread(), and SCardUnlockThread(). |
|
Memory mapped address used to read status information about the readers. Each element in the vector readerStates makes references to a part of the memory mapped. Definition at line 161 of file winscard_clnt.c. Referenced by SCardEstablishContextTH(), and SCardUnload(). |
|
Represents the an Application Context on the Client side.
An Application Context contains Channels ( Referenced by SCardAddContext(), SCardBeginTransaction(), SCardCancel(), SCardCancelTransaction(), SCardConnect(), SCardControl(), SCardDisconnect(), SCardEndTransaction(), SCardEstablishContextTH(), SCardGetContextIndiceTH(), SCardGetStatusChange(), SCardListReaderGroups(), SCardListReaders(), SCardReconnect(), SCardReleaseContext(), SCardRemoveContext(), SCardStatus(), and SCardTransmit(). |
|
Pointers to a memory mapped area used to read status information about the readers. Each element in the vector readerStates makes references to a part of the memory mapped mapAddr. Definition at line 175 of file winscard_clnt.c. Referenced by SCardBeginTransaction(), SCardCancelTransaction(), SCardControl(), SCardEndTransaction(), SCardEstablishContextTH(), SCardGetStatusChange(), SCardListReaders(), SCardReconnect(), SCardStatus(), SCardTransmit(), and SCardUnload(). |