#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 <stddef.h>#include <sys/time.h>#include "misc.h"#include "pcscd.h"#include "winscard.h"#include "debug.h"#include "thread_generic.h"#include "strlcpycat.h"#include "readerfactory.h"#include "eventhandler.h"#include "sys_generic.h"#include "winscard_msg.h"#include "utils.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 | BLOCK_STATUS_CANCEL 0x0001 |
| #define | PROFILE_START |
| #define | PROFILE_END(rv) |
Typedefs | |
| typedef struct _psChannelMap | CHANNEL_MAP |
| typedef struct _psChannelMap * | PCHANNEL_MAP |
Functions | |
| static long int | time_sub (struct timeval *a, struct timeval *b) |
| static LONG | SCardAddContext (SCARDCONTEXT hContext, DWORD dwClientID) |
| Functions for managing instances of SCardEstablishContext() These functions keep track of Context handles and associate the blocking variable contextBlockStatus to an hContext. | |
| static LONG | SCardGetContextIndice (SCARDCONTEXT hContext) |
Get the index from the Application Context vector _psContextMap for the passed context. | |
| static LONG | SCardGetContextIndiceTH (SCARDCONTEXT hContext) |
Get the index from the Application Context vector _psContextMap for the passed context. | |
| static LONG | SCardRemoveContext (SCARDCONTEXT hContext) |
| Removes an Application Context from a control vector. | |
| static LONG | SCardCleanContext (LONG indice) |
| static LONG | SCardAddHandle (SCARDHANDLE, DWORD, LPCSTR) |
| static LONG | SCardGetIndicesFromHandle (SCARDHANDLE, PDWORD, PDWORD) |
| static LONG | SCardGetIndicesFromHandleTH (SCARDHANDLE, PDWORD, PDWORD) |
| static LONG | SCardRemoveHandle (SCARDHANDLE) |
| static LONG | SCardGetSetAttrib (SCARDHANDLE hCard, int command, DWORD dwAttrId, LPBYTE pbAttr, LPDWORD pcbAttrLen) |
| void DESTRUCTOR | SCardUnload (void) |
| Free resources allocated by the library. | |
| static LONG | SCardLockThread (void) |
| This function locks a mutex so another thread must wait to use this function. | |
| static LONG | SCardUnlockThread (void) |
| This function unlocks a mutex so another thread may use the client. | |
| static LONG | SCardEstablishContextTH (DWORD dwScope,LPCVOID pvReserved1,LPCVOID pvReserved2, LPSCARDCONTEXT phContext) |
| Creates a communication context to the PC/SC Resource Manager. | |
| LONG | SCardEstablishContext (DWORD dwScope, LPCVOID pvReserved1, LPCVOID pvReserved2, LPSCARDCONTEXT phContext) |
| Creates an Application Context to the PC/SC Resource Manager. | |
| LONG | SCardReleaseContext (SCARDCONTEXT hContext) |
| This function destroys a communication context to the PC/SC Resource Manager. | |
| LONG | SCardSetTimeout (SCARDCONTEXT hContext, DWORD dwTimeout) |
| The function does not do anything except returning SCARD_S_SUCCESS. | |
| LONG | SCardConnect (SCARDCONTEXT hContext, LPCSTR szReader, DWORD dwShareMode, DWORD dwPreferredProtocols, LPSCARDHANDLE phCard, LPDWORD pdwActiveProtocol) |
This function establishes a connection to 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 made through SCardConnect(). | |
| LONG | SCardBeginTransaction (SCARDHANDLE hCard) |
| This function establishes a temporary exclusive access mode for doing a serie of commands in a transaction. | |
| LONG | SCardEndTransaction (SCARDHANDLE hCard, DWORD dwDisposition) |
| This function ends a previously begun transaction. | |
| LONG | SCardCancelTransaction (SCARDHANDLE hCard) |
| LONG | SCardStatus (SCARDHANDLE hCard, LPSTR mszReaderName, LPDWORD pcchReaderLen, LPDWORD pdwState, LPDWORD pdwProtocol, LPBYTE pbAtr, LPDWORD pcbAtrLen) |
This function returns the current status of the reader connected to by hCard. | |
| static long | WaitForPcscdEvent (SCARDCONTEXT hContext, long dwTime) |
| LONG | SCardGetStatusChange (SCARDCONTEXT hContext, DWORD dwTimeout, LPSCARD_READERSTATE_A rgReaderStates, DWORD cReaders) |
| This function receives a structure or list of structures containing reader names. | |
| 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 (reader driver) 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 (reader driver). | |
| 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 | SCardFreeMemory (SCARDCONTEXT hContext, LPCVOID pvMem) |
| Releases memory that has been returned from the resource manager using the SCARD_AUTOALLOCATE length designator. | |
| LONG | SCardListReaderGroups (SCARDCONTEXT hContext, LPSTR mszGroups, LPDWORD pcchGroups) |
| This function returns a list of currently available reader groups on the system. | |
| 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. | |
| LONG | SCardCheckDaemonAvailability (void) |
| Checks if the server is running. | |
Variables | |
| static struct _psContextMap | psContextMap [PCSCLITE_MAX_APPLICATION_CONTEXTS] |
| Represents the an Application Context on the Client side. | |
| static short | isExecuted = 0 |
| Make sure the initialization code is executed only once. | |
| static time_t | daemon_ctime = 0 |
| creation time of pcscd PCSCLITE_PUBSHM_FILE file | |
| static pid_t | daemon_pid = 0 |
| static pid_t | client_pid = 0 |
| PID of the client application. | |
| static int | mapAddr = 0 |
| Memory mapped address used to read status information about the readers. | |
| static PCSCLITE_MUTEX | clientMutex = PTHREAD_MUTEX_INITIALIZER |
| Ensure that some functions be accessed in thread-safe mode. | |
| static 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 } |
| Protocol Control Information for T=0. | |
| PCSC_API SCARD_IO_REQUEST | g_rgSCardT1Pci = { SCARD_PROTOCOL_T1, 8 } |
| Protocol Control Information for T=1. | |
| PCSC_API SCARD_IO_REQUEST | g_rgSCardRawPci = { SCARD_PROTOCOL_RAW, 8 } |
| Protocol Control Information for raw access. | |
Definition in file winscard_clnt.c.
| static LONG SCardAddContext | ( | SCARDCONTEXT | hContext, | |
| DWORD | dwClientID | |||
| ) | [static] |
Functions for managing instances of SCardEstablishContext() These functions keep track of Context handles and associate the blocking variable contextBlockStatus to an hContext.
Adds an Application Context to the vector _psContextMap.
| [in] | hContext | Application Context ID. |
| [in] | dwClientID | Client connection ID. |
| SCARD_S_SUCCESS | Success (SCARD_S_SUCCESS) | |
| SCARD_E_NO_MEMORY | There is no free slot to store hContext (SCARD_E_NO_MEMORY) |
Definition at line 3611 of file winscard_clnt.c.
References BLOCK_STATUS_RESUME, _psContextMap::dwClientID, _psContextMap::hContext, _psContextMap::mMutex, PCSCLITE_MAX_APPLICATION_CONTEXTS, psContextMap, SCARD_E_NO_MEMORY, and SCARD_S_SUCCESS.
Referenced by SCardEstablishContextTH().
| LONG SCardCheckDaemonAvailability | ( | void | ) |
Checks if the server is running.
| SCARD_S_SUCCESS | Server is running (SCARD_S_SUCCESS) | |
| SCARD_E_NO_SERVICE | Server is not running (SCARD_E_NO_SERVICE) | |
| SCARD_E_INVALID_HANDLE | Server was restarted or after fork() (SCARD_E_INVALID_HANDLE) |
Definition at line 3816 of file winscard_clnt.c.
References psContextMap, SCARD_E_INVALID_HANDLE, SCARD_E_NO_SERVICE, SCARD_S_SUCCESS, SCardLockThread(), SCardUnload(), and SCardUnlockThread().
Referenced by SCardBeginTransaction(), SCardCancelTransaction(), SCardConnect(), SCardControl(), SCardDisconnect(), SCardEndTransaction(), SCardEstablishContext(), SCardFreeMemory(), SCardGetStatusChange(), SCardIsValidContext(), SCardListReaderGroups(), SCardListReaders(), SCardReconnect(), SCardReleaseContext(), SCardStatus(), SCardTransmit(), and SHMMessageReceive().
| static LONG SCardEstablishContextTH | ( | DWORD | dwScope, | |
| LPCVOID | pvReserved1, | |||
| LPCVOID | pvReserved2, | |||
| LPSCARDCONTEXT | phContext | |||
| ) | [static] |
Creates a communication context to the PC/SC Resource Manager.
This function should not be called directly. Instead, the thread-safe function SCardEstablishContext() should be called.
| [in] | dwScope | Scope of the establishment. This can either be a local or remote connection.
|
| [in] | pvReserved1 | Reserved for future use. Can be used for remote connection. |
| [in] | pvReserved2 | Reserved for future use. |
| [out] | phContext | Returned reference to this connection. |
| SCARD_S_SUCCESS | Successful (SCARD_S_SUCCESS) | |
| SCARD_E_INVALID_PARAMETER | phContext is null. (SCARD_E_INVALID_PARAMETER) | |
| SCARD_E_INVALID_VALUE | Invalid scope type passed (SCARD_E_INVALID_VALUE) | |
| SCARD_E_NO_MEMORY | There is no free slot to store hContext (SCARD_E_NO_MEMORY) | |
| SCARD_E_NO_SERVICE | The server is not runing (SCARD_E_NO_SERVICE) | |
| SCARD_F_COMM_ERROR | An internal communications error has been detected (SCARD_F_COMM_ERROR) | |
| SCARD_F_INTERNAL_ERROR | An internal consistency check failed (SCARD_F_INTERNAL_ERROR) |
Definition at line 358 of file winscard_clnt.c.
References BLOCK_STATUS_RESUME, CMD_VERSION, rxSharedSegment::date, _psContextMap::dwClientID, _psContextMap::hContext, version_struct::major, version_struct::minor, _psContextMap::mMutex, PCSCLITE_CLIENT_ATTEMPTS, PCSCLITE_MAX_APPLICATION_CONTEXT_CHANNELS, PCSCLITE_MAX_APPLICATION_CONTEXTS, PCSCLITE_MAX_READERS_CONTEXTS, PCSCLITE_MCLIENT_ATTEMPTS, PROTOCOL_VERSION_MAJOR, PROTOCOL_VERSION_MINOR, psContextMap, SCARD_E_INVALID_PARAMETER, SCARD_E_NO_MEMORY, SCARD_E_NO_SERVICE, SCARD_ESTABLISH_CONTEXT, SCARD_F_COMM_ERROR, SCARD_F_INTERNAL_ERROR, SCARD_S_SUCCESS, SCardAddContext(), SHMClientRead(), SHMClientSetupSession(), SHMMessageReceive(), SHMMessageSend(), SYS_CloseFile(), SYS_GetPageSize(), SYS_Initialize(), SYS_OpenFile(), SYS_PublicMemoryMap(), rxSharedSegment::user_id, and WrapSHMWrite().
Referenced by SCardEstablishContext().
| static LONG SCardGetContextIndice | ( | SCARDCONTEXT | hContext | ) | [static] |
Get the index from the Application Context vector _psContextMap for the passed context.
This function is a thread-safe wrapper to the function SCardGetContextIndiceTH().
| [in] | hContext | Application Context whose index will be find. |
Definition at line 3643 of file winscard_clnt.c.
References SCardGetContextIndiceTH(), SCardLockThread(), and SCardUnlockThread().
Referenced by SCardCancel(), SCardConnect(), SCardFreeMemory(), SCardGetStatusChange(), SCardIsValidContext(), SCardListReaderGroups(), SCardListReaders(), and SCardReleaseContext().
| static LONG SCardGetContextIndiceTH | ( | SCARDCONTEXT | hContext | ) | [static] |
Get the index from the Application Context vector _psContextMap for the passed context.
This functions is not thread-safe and should not be called. Instead, call the function SCardGetContextIndice().
| [in] | hContext | Application Context whose index will be find. |
Definition at line 3666 of file winscard_clnt.c.
References PCSCLITE_MAX_APPLICATION_CONTEXTS, and psContextMap.
Referenced by SCardGetContextIndice(), and SCardRemoveContext().
| static LONG SCardLockThread | ( | void | ) | [inline, static] |
This function locks a mutex so another thread must wait to use this function.
Wrapper to the function SYS_MutexLock().
Definition at line 256 of file winscard_clnt.c.
Referenced by SCardCheckDaemonAvailability(), SCardEstablishContext(), SCardGetContextIndice(), and SCardReleaseContext().
| static LONG SCardRemoveContext | ( | SCARDCONTEXT | hContext | ) | [static] |
Removes an Application Context from a control vector.
| [in] | hContext | Application Context to be removed. |
| SCARD_S_SUCCESS | Success (SCARD_S_SUCCESS) | |
| SCARD_E_INVALID_HANDLE | The context hContext was not found (SCARD_E_INVALID_HANDLE) |
Definition at line 3691 of file winscard_clnt.c.
References SCARD_E_INVALID_HANDLE, and SCardGetContextIndiceTH().
Referenced by SCardReleaseContext().
| 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. Otherwise you will exhaust the ressources available.
Definition at line 3890 of file winscard_clnt.c.
References SYS_CloseFile(), and SYS_PublicMemoryUnmap().
Referenced by SCardCheckDaemonAvailability().
| static LONG SCardUnlockThread | ( | void | ) | [inline, static] |
This function unlocks a mutex so another thread may use the client.
Wrapper to the function SYS_MutexUnLock().
Definition at line 266 of file winscard_clnt.c.
Referenced by SCardCheckDaemonAvailability(), SCardEstablishContext(), SCardGetContextIndice(), and SCardReleaseContext().
pid_t client_pid = 0 [static] |
PID of the client application.
Used to detect fork() and disable handles in the child process
Definition at line 201 of file winscard_clnt.c.
PCSCLITE_MUTEX clientMutex = PTHREAD_MUTEX_INITIALIZER [static] |
Ensure that some functions be accessed in thread-safe mode.
These function's names finishes with "TH".
Definition at line 214 of file winscard_clnt.c.
int mapAddr = 0 [static] |
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 208 of file winscard_clnt.c.
struct _psContextMap psContextMap[PCSCLITE_MAX_APPLICATION_CONTEXTS] [static] |
Represents the an Application Context on the Client side.
An Application Context contains Channels (_psChannelMap).
Referenced by SCardAddContext(), SCardBeginTransaction(), SCardCancel(), SCardCancelTransaction(), SCardCheckDaemonAvailability(), SCardConnect(), SCardControl(), SCardDisconnect(), SCardEndTransaction(), SCardEstablishContextTH(), SCardGetContextIndiceTH(), SCardGetStatusChange(), SCardListReaderGroups(), SCardListReaders(), SCardReconnect(), SCardReleaseContext(), SCardStatus(), and SCardTransmit().
PREADER_STATE readerStates[PCSCLITE_MAX_READERS_CONTEXTS] [static] |
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 222 of file winscard_clnt.c.
1.6.1