pcsc-lite 2.3.0
|
#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 <pthread.h>
#include <sys/wait.h>
#include <stdbool.h>
#include "misc.h"
#include "pcscd.h"
#include "winscard.h"
#include "debuglog.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 an Application Context on the Client side. More... | |
Macros | |
#define | COLOR_RED "\33[01;31m" |
#define | COLOR_GREEN "\33[32m" |
#define | COLOR_BLUE "\33[34m" |
#define | COLOR_MAGENTA "\33[35m" |
#define | COLOR_NORMAL "\33[0m" |
#define | API_TRACE_IN(...) |
#define | API_TRACE_OUT(...) |
#define | PROFILE_START |
#define | PROFILE_END(rv) |
Typedefs | |
typedef struct _psChannelMap | CHANNEL_MAP |
typedef struct _psContextMap | SCONTEXTMAP |
Represents an Application Context on the Client side. | |
Functions | |
static int | CHANNEL_MAP_seeker (const void *el, const void *key) |
static int | SCONTEXTMAP_seeker (const void *el, const void *key) |
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 SCONTEXTMAP * | SCardGetAndLockContext (SCARDCONTEXT hContext) |
Get the SCONTEXTMAP * from the Application Context vector _psContextMap for the passed context. | |
static SCONTEXTMAP * | SCardGetContextTH (SCARDCONTEXT hContext) |
Get the address from the Application Context list _psContextMap for the passed context. | |
static void | SCardRemoveContext (SCARDCONTEXT hContext) |
Removes an Application Context from a control vector. | |
static void | SCardCleanContext (SCONTEXTMAP *) |
static LONG | SCardAddHandle (SCARDHANDLE, SCONTEXTMAP *, LPCSTR) |
static LONG | SCardGetContextChannelAndLockFromHandle (SCARDHANDLE, SCONTEXTMAP **, CHANNEL_MAP **) |
static LONG | SCardGetContextAndChannelFromHandleTH (SCARDHANDLE, SCONTEXTMAP **, CHANNEL_MAP **) |
static void | SCardRemoveHandle (SCARDHANDLE) |
static LONG | SCardGetSetAttrib (SCARDHANDLE hCard, int command, DWORD dwAttrId, LPBYTE pbAttr, LPDWORD pcbAttrLen) |
static LONG | getReaderEvents (SCONTEXTMAP *currentContextMap, int *readerEvents) |
static LONG | getReaderStates (SCONTEXTMAP *currentContextMap) |
static LONG | getReaderStatesAndRegisterForEvents (SCONTEXTMAP *currentContextMap) |
static LONG | unregisterFromEvents (SCONTEXTMAP *currentContextMap) |
static void | SCardLockThread (void) |
Locks a mutex so another thread must wait to use this function. | |
static void | SCardUnlockThread (void) |
Unlocks a mutex so another thread may use the client. | |
static bool | SCardGetContextValidity (SCARDCONTEXT hContext) |
Tell if a context index from the Application Context vector _psContextMap is valid or not. | |
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. | |
static DESTRUCTOR void | destructor (void) |
static void | init_lib (void) |
LONG | SCardReleaseContext (SCARDCONTEXT hContext) |
Destroys a communication context to the PC/SC Resource Manager. | |
LONG | SCardConnect (SCARDCONTEXT hContext, LPCSTR szReader, DWORD dwShareMode, DWORD dwPreferredProtocols, LPSCARDHANDLE phCard, LPDWORD pdwActiveProtocol) |
Establishes a connection to the reader specified in * szReader. | |
LONG | SCardReconnect (SCARDHANDLE hCard, DWORD dwShareMode, DWORD dwPreferredProtocols, DWORD dwInitialization, LPDWORD pdwActiveProtocol) |
Reestablishes a connection to a reader that was previously connected to using SCardConnect(). | |
LONG | SCardDisconnect (SCARDHANDLE hCard, DWORD dwDisposition) |
Terminates a connection made through SCardConnect(). | |
LONG | SCardBeginTransaction (SCARDHANDLE hCard) |
Establishes a temporary exclusive access mode for doing a series of commands in a transaction. | |
LONG | SCardEndTransaction (SCARDHANDLE hCard, DWORD dwDisposition) |
Ends a previously begun transaction. | |
LONG | SCardStatus (SCARDHANDLE hCard, LPSTR szReaderName, LPDWORD pcchReaderLen, LPDWORD pdwState, LPDWORD pdwProtocol, LPBYTE pbAtr, LPDWORD pcbAtrLen) |
Returns the current status of the reader connected to by hCard . | |
LONG | SCardGetStatusChange (SCARDCONTEXT hContext, DWORD dwTimeout, SCARD_READERSTATE *rgReaderStates, DWORD cReaders) |
Blocks execution until the current availability of the cards in a specific set of readers changes. | |
LONG | SCardControl (SCARDHANDLE hCard, DWORD dwControlCode, LPCVOID pbSendBuffer, DWORD cbSendLength, LPVOID pbRecvBuffer, DWORD cbRecvLength, LPDWORD lpBytesReturned) |
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) |
Get an attribute from the IFD Handler (reader driver). | |
LONG | SCardSetAttrib (SCARDHANDLE hCard, DWORD dwAttrId, LPCBYTE pbAttr, DWORD cbAttrLen) |
Set an attribute of the IFD Handler. | |
LONG | SCardTransmit (SCARDHANDLE hCard, const SCARD_IO_REQUEST *pioSendPci, LPCBYTE pbSendBuffer, DWORD cbSendLength, SCARD_IO_REQUEST *pioRecvPci, LPBYTE pbRecvBuffer, LPDWORD pcbRecvLength) |
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) |
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) |
Returns a list of currently available reader groups on the system. | |
LONG | SCardCancel (SCARDCONTEXT hContext) |
Cancels a specific blocking SCardGetStatusChange() function. | |
LONG | SCardIsValidContext (SCARDCONTEXT hContext) |
Check if a SCARDCONTEXT is valid. | |
LONG | SCardCheckDaemonAvailability (void) |
Checks if the server is running. | |
Variables | |
static bool | sharing_shall_block = true |
static list_t | contextMapList |
static bool | isExecuted = false |
Make sure the initialization code is executed only once. | |
static pthread_once_t | init_lib_control = PTHREAD_ONCE_INIT |
static pthread_mutex_t | clientMutex = PTHREAD_MUTEX_INITIALIZER |
Ensure that some functions be accessed in thread-safe mode. | |
static READER_STATE | readerStates [PCSCLITE_MAX_READERS_CONTEXTS] |
Area used to read status information about the readers. | |
static pthread_mutex_t | readerStatesMutex = PTHREAD_MUTEX_INITIALIZER |
#define API_TRACE_IN | ( | ... | ) |
Definition at line 169 of file winscard_clnt.c.
#define API_TRACE_OUT | ( | ... | ) |
Definition at line 170 of file winscard_clnt.c.
#define COLOR_BLUE "\33[34m" |
Definition at line 142 of file winscard_clnt.c.
#define COLOR_GREEN "\33[32m" |
Definition at line 141 of file winscard_clnt.c.
#define COLOR_MAGENTA "\33[35m" |
Definition at line 143 of file winscard_clnt.c.
#define COLOR_NORMAL "\33[0m" |
Definition at line 144 of file winscard_clnt.c.
#define COLOR_RED "\33[01;31m" |
Definition at line 140 of file winscard_clnt.c.
#define PROFILE_END | ( | rv | ) |
Definition at line 265 of file winscard_clnt.c.
#define PROFILE_START |
Definition at line 264 of file winscard_clnt.c.
typedef struct _psChannelMap CHANNEL_MAP |
Definition at line 278 of file winscard_clnt.c.
typedef struct _psContextMap SCONTEXTMAP |
Represents an Application Context on the Client side.
typedef of _psContextMap
Definition at line 316 of file winscard_clnt.c.
|
static |
Definition at line 280 of file winscard_clnt.c.
|
static |
Definition at line 487 of file winscard_clnt.c.
|
static |
Definition at line 3606 of file winscard_clnt.c.
|
static |
Definition at line 3626 of file winscard_clnt.c.
|
static |
Definition at line 3643 of file winscard_clnt.c.
|
static |
Definition at line 497 of file winscard_clnt.c.
|
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 3309 of file winscard_clnt.c.
|
static |
Definition at line 3472 of file winscard_clnt.c.
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) |
Definition at line 3587 of file winscard_clnt.c.
|
static |
Definition at line 3425 of file winscard_clnt.c.
|
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 running (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) |
SCARD_W_SECURITY_VIOLATION | Access was denied by the daemon (Polkit issue?). (SCARD_W_SECURITY_VIOLATION) |
Definition at line 558 of file winscard_clnt.c.
|
static |
Get the SCONTEXTMAP * from the Application Context vector _psContextMap
for the passed context.
This function is a thread-safe wrapper to the function SCardGetContextTH().
If the context is valid then ¤tContextMap->mMutex
lock is acquired. The mutex lock needs to be released when the structure is no more used.
[in] | hContext | Application Context whose SCONTEXTMAP will be find. |
Definition at line 3377 of file winscard_clnt.c.
|
static |
Definition at line 3544 of file winscard_clnt.c.
|
static |
Definition at line 3524 of file winscard_clnt.c.
|
static |
Get the address from the Application Context list _psContextMap
for the passed context.
This functions is not thread-safe and should not be called. Instead, call the function SCardGetContext().
[in] | hContext | Application Context whose index will be find. |
Definition at line 3405 of file winscard_clnt.c.
|
static |
Tell if a context index from the Application Context vector _psContextMap
is valid or not.
[in] | hContext | Application Context whose index will be find. |
true
if the context exists false
if the context does not exist Definition at line 412 of file winscard_clnt.c.
|
static |
Definition at line 2582 of file winscard_clnt.c.
|
inlinestatic |
Locks a mutex so another thread must wait to use this function.
Wrapper to the function pthread_mutex_lock().
Definition at line 388 of file winscard_clnt.c.
|
static |
Removes an Application Context from a control vector.
[in] | hContext | Application Context to be removed. |
Definition at line 3416 of file winscard_clnt.c.
|
static |
Definition at line 3498 of file winscard_clnt.c.
|
inlinestatic |
Unlocks a mutex so another thread may use the client.
Wrapper to the function pthread_mutex_unlock().
Definition at line 398 of file winscard_clnt.c.
|
static |
Definition at line 320 of file winscard_clnt.c.
|
static |
Definition at line 3659 of file winscard_clnt.c.
|
static |
Ensure that some functions be accessed in thread-safe mode.
These function's names finishes with "TH".
Definition at line 349 of file winscard_clnt.c.
|
static |
Definition at line 318 of file winscard_clnt.c.
|
static |
Definition at line 342 of file winscard_clnt.c.
|
static |
Make sure the initialization code is executed only once.
Definition at line 341 of file winscard_clnt.c.
|
static |
Area used to read status information about the readers.
Definition at line 354 of file winscard_clnt.c.
|
static |
Definition at line 355 of file winscard_clnt.c.
|
static |
Definition at line 138 of file winscard_clnt.c.