#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 |
typedef _psChannelMap * | PCHANNEL_MAP |
Functions | |
static LONG | SCardAddContext (SCARDCONTEXT hContext, DWORD dwClientID) |
Adds an Application Context to the vector psContextMap . | |
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 | SCardAddHandle (SCARDHANDLE, DWORD, LPSTR) |
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) |
static LONG | SCardCheckDaemonAvailability (void) |
Checks if the Server is running. | |
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 for a client. | |
LONG | SCardReleaseContext (SCARDCONTEXT hContext) |
This function destroys a communication context to the PC/SC Resource Manager. | |
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. | |
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. | |
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 | |
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 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 } |
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.
static LONG SCardAddContext | ( | SCARDCONTEXT | hContext, | |
DWORD | dwClientID | |||
) | [static] |
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 3119 of file winscard_clnt.c.
References BLOCK_STATUS_RESUME, _psContextMap::contextBlockStatus, _psContextMap::dwClientID, _psContextMap::mMutex, PCSCLITE_MAX_APPLICATION_CONTEXTS, PCSCLITE_MUTEX, psContextMap, SCARD_E_NO_MEMORY, SCARD_S_SUCCESS, and SYS_MutexInit().
Referenced by getNewContext(), and SCardEstablishContextTH().
LONG SCardBeginTransaction | ( | SCARDHANDLE | hCard | ) |
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.
[in] | hCard | Connection made from SCardConnect. |
SCARD_S_SUCCESS | Successful (SCARD_S_SUCCESS) | |
SCARD_E_INVALID_HANDLE | Invalid hCard handle (SCARD_E_INVALID_HANDLE) | |
SCARD_E_SHARING_VIOLATION | Someone else has exclusive rights (SCARD_E_SHARING_VIOLATION) | |
SCARD_E_READER_UNAVAILABLE | The reader has been removed (SCARD_E_READER_UNAVAILABLE) |
SCARDCONTEXT hContext; SCARDHANDLE hCard; DWORD dwActiveProtocol; LONG rv; ... rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext); rv = SCardConnect(hContext, "Reader X", SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0, &hCard, &dwActiveProtocol); rv = SCardBeginTransaction(hCard); ... / * Do some transmit commands * /
Definition at line 1017 of file winscard_clnt.c.
References rxSharedSegment::data, begin_struct::hCard, PCSCLITE_CLIENT_ATTEMPTS, PCSCLITE_MAX_READERS_CONTEXTS, PROFILE_END, PROFILE_START, psContextMap, readerStates, begin_struct::rv, SCARD_E_INVALID_HANDLE, SCARD_E_NO_SERVICE, SCARD_E_READER_UNAVAILABLE, SCARD_E_SHARING_VIOLATION, SCARD_F_COMM_ERROR, SCARD_S_SUCCESS, SCardCheckDaemonAvailability(), SCardGetIndicesFromHandle(), SHMClientRead(), SYS_MutexLock(), SYS_MutexUnLock(), SYS_RandomInt(), SYS_USleep(), and WrapSHMWrite().
LONG SCardCancel | ( | SCARDCONTEXT | hContext | ) |
This function cancels all pending blocking requests on the SCardGetStatusChange() function.
[in] | hContext | Connection context to the PC/SC Resource Manager. |
SCARD_S_SUCCESS | Successful (SCARD_S_SUCCESS) | |
SCARD_E_INVALID_HANDLE | Invalid hContext handle (SCARD_E_INVALID_HANDLE) |
SCARDCONTEXT hContext; DWORD cReaders; SCARD_READERSTATE rgReaderStates; LONG rv; ... rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext); rgReaderStates.szReader = strdup("Reader X"); rgReaderStates.dwCurrentState = SCARD_STATE_EMPTY; ... / * Spawn off thread for following function * / ... rv = SCardGetStatusChange(hContext, 0, rgReaderStates, cReaders); rv = SCardCancel(hContext);
Definition at line 3037 of file winscard_clnt.c.
References BLOCK_STATUS_RESUME, _psContextMap::contextBlockStatus, PROFILE_END, PROFILE_START, psContextMap, SCARD_E_INVALID_HANDLE, SCARD_S_SUCCESS, and SCardGetContextIndice().
LONG SCardCancelTransaction | ( | SCARDHANDLE | hCard | ) |
Definition at line 1258 of file winscard_clnt.c.
References rxSharedSegment::data, cancel_struct::hCard, PCSCLITE_CLIENT_ATTEMPTS, PCSCLITE_MAX_READERS_CONTEXTS, PROFILE_END, PROFILE_START, psContextMap, readerStates, SCARD_E_INVALID_HANDLE, SCARD_E_NO_SERVICE, SCARD_E_READER_UNAVAILABLE, SCARD_F_COMM_ERROR, SCARD_S_SUCCESS, SCardCheckDaemonAvailability(), SCardGetIndicesFromHandle(), SHMClientRead(), SYS_MutexLock(), SYS_MutexUnLock(), and WrapSHMWrite().
static LONG SCardCheckDaemonAvailability | ( | void | ) | [static] |
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 3340 of file winscard_clnt.c.
References Log1, PCSCLITE_PUBSHM_FILE, SCARD_E_NO_SERVICE, SCARD_S_SUCCESS, and SYS_Stat().
Referenced by SCardBeginTransaction(), SCardCancelTransaction(), SCardConnect(), SCardControl(), SCardDisconnect(), SCardEndTransaction(), SCardEstablishContextTH(), SCardGetSetAttrib(), SCardGetStatusChange(), SCardListReaderGroups(), SCardListReaders(), SCardReconnect(), SCardReleaseContext(), SCardStatus(), and SCardTransmit().
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.
The first connection will power up and perform a reset on the card.
[in] | hContext | Connection context to the PC/SC Resource Manager. |
[in] | szReader | Reader name to connect to. |
[in] | dwShareMode | Mode of connection type: exclusive or shared.
|
[in] | dwPreferredProtocols | Desired protocol use.
|
[out] | phCard | Handle to this connection. |
[out] | pdwActiveProtocol | Established protocol to this connection. |
SCARD_S_SUCCESS | Successful (SCARD_S_SUCCESS) | |
SCARD_E_INVALID_HANDLE | Invalid hContext handle (SCARD_E_INVALID_HANDLE) | |
SCARD_E_INVALID_VALUE | Invalid sharing mode, requested protocol, or reader name (SCARD_E_INVALID_VALUE) | |
SCARD_E_NOT_READY | Could not allocate the desired port (SCARD_E_NOT_READY) | |
SCARD_E_READER_UNAVAILABLE | Could not power up the reader or card (SCARD_E_READER_UNAVAILABLE) | |
SCARD_E_SHARING_VIOLATION | Someone else has exclusive rights (SCARD_E_SHARING_VIOLATION) | |
SCARD_E_UNSUPPORTED_FEATURE | Protocol not supported (SCARD_E_UNSUPPORTED_FEATURE) |
SCARDCONTEXT hContext; SCARDHANDLE hCard; DWORD dwActiveProtocol; LONG rv; ... rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext); rv = SCardConnect(hContext, "Reader X", SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0, &hCard, &dwActiveProtocol);
Definition at line 622 of file winscard_clnt.c.
References rxSharedSegment::data, connect_struct::dwPreferredProtocols, connect_struct::dwShareMode, connect_struct::hContext, MAX_READERNAME, PCSCLITE_CLIENT_ATTEMPTS, connect_struct::pdwActiveProtocol, connect_struct::phCard, PROFILE_END, PROFILE_START, psContextMap, SCARD_E_INVALID_HANDLE, SCARD_E_INVALID_PARAMETER, SCARD_E_INVALID_VALUE, SCARD_E_NO_SERVICE, SCARD_E_UNKNOWN_READER, SCARD_F_COMM_ERROR, SCARD_PROTOCOL_ANY_OLD, SCARD_PROTOCOL_RAW, SCARD_PROTOCOL_T0, SCARD_PROTOCOL_T1, SCARD_S_SUCCESS, SCardAddHandle(), SCardCheckDaemonAvailability(), SCardGetContextIndice(), SHMClientRead(), SYS_MutexLock(), SYS_MutexUnLock(), connect_struct::szReader, and WrapSHMWrite().
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.
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.
[in] | hCard | Connection made from SCardConnect. |
[in] | dwControlCode | Control code for the operation. Click here for a list of supported commands by some drivers. |
[in] | pbSendBuffer | Command to send to the reader. |
[in] | cbSendLength | Length of the command. |
[out] | pbRecvBuffer | Response from the reader. |
[in] | cbRecvLength | Length of the response buffer. |
[out] | lpBytesReturned | Length of the response. |
SCARD_S_SUCCESS | Successful (SCARD_S_SUCCESS) | |
SCARD_E_NOT_TRANSACTED | Data exchange not successful (SCARD_E_NOT_TRANSACTED) | |
SCARD_E_INVALID_HANDLE | Invalid hCard handle (SCARD_E_INVALID_HANDLE) | |
SCARD_E_INVALID_VALUE | Invalid value was presented (SCARD_E_INVALID_VALUE) | |
SCARD_E_READER_UNAVAILABLE | The reader has been removed(SCARD_E_READER_UNAVAILABLE) | |
SCARD_W_RESET_CARD | The card has been reset by another application (SCARD_W_RESET_CARD) | |
SCARD_W_REMOVED_CARD | The card has been removed from the reader(SCARD_W_REMOVED_CARD) |
LONG rv; SCARDCONTEXT hContext; SCARDHANDLE hCard; DWORD dwActiveProtocol, dwSendLength, dwRecvLength; BYTE pbRecvBuffer[10]; BYTE pbSendBuffer[] = { 0x06, 0x00, 0x0A, 0x01, 0x01, 0x10 0x00 }; ... rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext); rv = SCardConnect(hContext, "Reader X", SCARD_SHARE_SHARED, SCARD_PROTOCOL_RAW &hCard, &dwActiveProtocol); dwSendLength = sizeof(pbSendBuffer); dwRecvLength = sizeof(pbRecvBuffer); rv = SCardControl(hCard, 0x42000001, pbSendBuffer, dwSendLength, pbRecvBuffer, sizeof(pbRecvBuffer), &dwRecvLength);
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, _psContextMap::dwClientID, control_struct::dwControlCode, control_struct_extended::dwControlCode, control_struct::hCard, control_struct_extended::hCard, MAX_BUFFER_SIZE, MAX_BUFFER_SIZE_EXTENDED, control_struct::pbSendBuffer, PCSCLITE_CLIENT_ATTEMPTS, PCSCLITE_MAX_MESSAGE_SIZE, PROFILE_END, PROFILE_START, psContextMap, readerStates, SCARD_E_INSUFFICIENT_BUFFER, SCARD_E_INVALID_HANDLE, SCARD_E_NO_SERVICE, SCARD_E_READER_UNAVAILABLE, SCARD_F_COMM_ERROR, SCARD_S_SUCCESS, SCardCheckDaemonAvailability(), SCardGetIndicesFromHandle(), SHMClientRead(), SHMMessageReceive(), control_struct_extended::size, SYS_MutexLock(), SYS_MutexUnLock(), and WrapSHMWrite().
LONG SCardDisconnect | ( | SCARDHANDLE | hCard, | |
DWORD | dwDisposition | |||
) |
This function terminates a connection to the connection made through SCardConnect().
dwDisposition can have the following values:
[in] | hCard | Connection made from SCardConnect. |
[in] | dwDisposition | Reader function to execute.
|
SCARD_S_SUCCESS | Successful(SCARD_S_SUCCESS) | |
SCARD_E_INVALID_HANDLE | Invalid hCard handle (SCARD_E_INVALID_HANDLE) | |
SCARD_E_INVALID_VALUE | - Invalid dwDisposition (SCARD_E_INVALID_VALUE) |
SCARDCONTEXT hContext; SCARDHANDLE hCard; DWORD dwActiveProtocol; LONG rv; ... rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext); rv = SCardConnect(hContext, "Reader X", SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0, &hCard, &dwActiveProtocol); rv = SCardDisconnect(hCard, SCARD_UNPOWER_CARD);
Definition at line 919 of file winscard_clnt.c.
References rxSharedSegment::data, disconnect_struct::dwDisposition, disconnect_struct::hCard, PCSCLITE_CLIENT_ATTEMPTS, PROFILE_END, PROFILE_START, psContextMap, SCARD_E_INVALID_HANDLE, SCARD_E_INVALID_VALUE, SCARD_E_NO_SERVICE, SCARD_EJECT_CARD, SCARD_F_COMM_ERROR, SCARD_LEAVE_CARD, SCARD_RESET_CARD, SCARD_S_SUCCESS, SCARD_UNPOWER_CARD, SCardCheckDaemonAvailability(), SCardGetIndicesFromHandle(), SCardRemoveHandle(), SHMClientRead(), SYS_MutexLock(), SYS_MutexUnLock(), and WrapSHMWrite().
LONG SCardEndTransaction | ( | SCARDHANDLE | hCard, | |
DWORD | dwDisposition | |||
) |
This function ends a previously begun transaction.
The calling application must be the owner of the previously begun transaction or an error will occur.
[in] | hCard | Connection made from SCardConnect. |
[in] | dwDisposition | Action to be taken on the reader. The disposition action is not currently used in this release.
|
SCARD_S_SUCCESS | Successful (SCARD_S_SUCCESS) | |
SCARD_E_INVALID_HANDLE | Invalid hCard handle (SCARD_E_INVALID_HANDLE) | |
SCARD_E_SHARING_VIOLATION | Someone else has exclusive rights (SCARD_E_SHARING_VIOLATION) | |
SCARD_E_READER_UNAVAILABLE | The reader has been removed (SCARD_E_READER_UNAVAILABLE) |
SCARDCONTEXT hContext; SCARDHANDLE hCard; DWORD dwActiveProtocol; LONG rv; ... rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext); rv = SCardConnect(hContext, "Reader X", SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0, &hCard, &dwActiveProtocol); rv = SCardBeginTransaction(hCard); ... / * Do some transmit commands * / ... rv = SCardEndTransaction(hCard, SCARD_LEAVE_CARD);
Definition at line 1163 of file winscard_clnt.c.
References rxSharedSegment::data, end_struct::dwDisposition, end_struct::hCard, PCSCLITE_CLIENT_ATTEMPTS, PCSCLITE_MAX_READERS_CONTEXTS, PROFILE_END, PROFILE_START, psContextMap, readerStates, SCARD_E_INVALID_HANDLE, SCARD_E_INVALID_VALUE, SCARD_E_NO_SERVICE, SCARD_E_READER_UNAVAILABLE, SCARD_EJECT_CARD, SCARD_F_COMM_ERROR, SCARD_LEAVE_CARD, SCARD_RESET_CARD, SCARD_S_SUCCESS, SCARD_UNPOWER_CARD, SCardCheckDaemonAvailability(), SCardGetIndicesFromHandle(), SHMClientRead(), SYS_MutexLock(), SYS_MutexUnLock(), SYS_RandomInt(), SYS_USleep(), and WrapSHMWrite().
LONG SCardEstablishContext | ( | DWORD | dwScope, | |
LPCVOID | pvReserved1, | |||
LPCVOID | pvReserved2, | |||
LPSCARDCONTEXT | phContext | |||
) |
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().
[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 Application Context. |
SCARD_S_SUCCESS | Successful (SCARD_S_SUCCESS) | |
SCARD_E_NO_SERVICE | The server is not runing (SCARD_E_NO_SERVICE) | |
SCARD_E_INVALID_VALUE | Invalid scope type passed (SCARD_E_INVALID_VALUE ) | |
SCARD_E_INVALID_PARAMETER | phContext is null (SCARD_E_INVALID_PARAMETER) |
SCARDCONTEXT hContext; LONG rv; ... rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext);
Definition at line 237 of file winscard_clnt.c.
References PROFILE_END, PROFILE_START, SCardEstablishContextTH(), SCardLockThread(), and SCardUnlockThread().
static LONG SCardEstablishContextTH | ( | DWORD | dwScope, | |
LPCVOID | pvReserved1, | |||
LPCVOID | pvReserved2, | |||
LPSCARDCONTEXT | phContext | |||
) | [static] |
Creates a communication context to the PC/SC Resource Manager.
This function shuld 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_NO_SERVICE | The server is not runing (SCARD_E_NO_SERVICE) | |
SCARD_E_INVALID_PARAMETER | phContext is null. (SCARD_E_INVALID_PARAMETER) | |
SCARD_E_INVALID_VALUE | Invalid scope type passed (SCARD_E_INVALID_VALUE) |
Definition at line 279 of file winscard_clnt.c.
References BLOCK_STATUS_RESUME, _psContextMap::contextBlockStatus, rxSharedSegment::data, _psContextMap::dwClientID, establish_struct::dwScope, _psContextMap::hContext, Log1, Log2, Log3, 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, PCSCLITE_PUBSHM_FILE, establish_struct::phContext, PROTOCOL_VERSION_MAJOR, PROTOCOL_VERSION_MINOR, _psContextMap::psChannelMap, psContextMap, _psChannelMap::readerName, readerStates, establish_struct::rv, version_struct::rv, SCARD_E_INVALID_PARAMETER, SCARD_E_INVALID_VALUE, SCARD_E_NO_MEMORY, SCARD_E_NO_SERVICE, SCARD_F_COMM_ERROR, SCARD_F_INTERNAL_ERROR, SCARD_S_SUCCESS, SCARD_SCOPE_GLOBAL, SCARD_SCOPE_SYSTEM, SCARD_SCOPE_TERMINAL, SCARD_SCOPE_USER, SCardAddContext(), SCardCheckDaemonAvailability(), SHMClientRead(), SHMClientSetupSession(), SHMMessageReceive(), SHMMessageSend(), SYS_CloseFile(), SYS_GetGID(), SYS_GetPageSize(), SYS_GetUID(), SYS_Initialize(), SYS_OpenFile(), SYS_PublicMemoryMap(), and WrapSHMWrite().
Referenced by SCardEstablishContext().
LONG SCardGetAttrib | ( | SCARDHANDLE | hCard, | |
DWORD | dwAttrId, | |||
LPBYTE | pbAttr, | |||
LPDWORD | pcbAttrLen | |||
) |
This function get an attribute from the IFD Handler.
The list of possible attributes is available in the file pcsclite.h
.
[out] | pbAttr | Pointer to a buffer that receives the attribute. |
pcbAttrLen | [inout] Length of the pbAttr buffer in bytes. |
SCARD_S_SUCCESS | Successful (SCARD_S_SUCCESS) | |
SCARD_E_NOT_TRANSACTED | Data exchange not successful (SCARD_E_NOT_TRANSACTED) | |
SCARD_E_INSUFFICIENT_BUFFER | Reader buffer not large enough (SCARD_E_INSUFFICIENT_BUFFER) |
LONG rv; SCARDCONTEXT hContext; SCARDHANDLE hCard; DWORD dwActiveProtocol; unsigned char pbAtr[MAX_ATR_SIZE]; DWORD dwAtrLen; ... rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext); rv = SCardConnect(hContext, "Reader X", SCARD_SHARE_SHARED, SCARD_PROTOCOL_RAW &hCard, &dwActiveProtocol); rv = SCardGetAttrib(hCard, SCARD_ATTR_ATR_STRING, pbAtr, &dwAtrLen);
Definition at line 2406 of file winscard_clnt.c.
References MAX_BUFFER_SIZE, PROFILE_END, PROFILE_START, SCARD_E_INVALID_PARAMETER, and SCardGetSetAttrib().
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 3151 of file winscard_clnt.c.
References SCardGetContextIndiceTH(), SCardLockThread(), and SCardUnlockThread().
Referenced by getNewContext(), getSessionForContext(), SCardCancel(), SCardCancelTH(), SCardConnect(), SCardConnectTH(), SCardGetStatusChange(), SCardIsValidContext(), SCardListReaderGroups(), SCardListReaderGroupsTH(), SCardListReaders(), SCardListReadersTH(), SCardReleaseContext(), and SCardRemoveContext().
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 3174 of file winscard_clnt.c.
References PCSCLITE_MAX_APPLICATION_CONTEXTS, and psContextMap.
Referenced by SCardGetContextIndice(), and SCardRemoveContext().
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.
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:
[in] | hContext | Connection context to the PC/SC Resource Manager. |
[in] | dwTimeout | Maximum waiting time (in miliseconds) for status change, zero (or INFINITE) for infinite. |
rgReaderStates | [inout] Structures of readers with current states. | |
[in] | cReaders | Number of structures. |
SCARD_S_SUCCESS | Successful (SCARD_S_SUCCESS) | |
SCARD_E_INVALID_VALUE | Invalid States, reader name, etc (SCARD_E_INVALID_VALUE) | |
SCARD_E_INVALID_HANDLE | Invalid hContext handle (SCARD_E_INVALID_HANDLE) | |
SCARD_E_READER_UNAVAILABLE | The reader is unavailable (SCARD_E_READER_UNAVAILABLE) |
SCARDCONTEXT hContext; SCARD_READERSTATE_A rgReaderStates[1]; LONG rv; ... rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext); ... rgReaderStates[0].szReader = "Reader X"; rgReaderStates[0].dwCurrentState = SCARD_STATE_UNAWARE; ... rv = SCardGetStatusChange(hContext, INFINITE, rgReaderStates, 1); printf("reader state: 0x%04X\n", rgReaderStates[0].dwEventState);
Definition at line 1613 of file winscard_clnt.c.
References INFINITE, PCSCLITE_MAX_READERS_CONTEXTS, PCSCLITE_STATUS_WAIT, PROFILE_END, PROFILE_START, psContextMap, readerStates, SCARD_E_INVALID_HANDLE, SCARD_E_INVALID_PARAMETER, SCARD_E_INVALID_VALUE, SCARD_E_NO_SERVICE, SCARD_E_READER_UNAVAILABLE, SCARD_E_TIMEOUT, SCARD_S_SUCCESS, SCardCheckDaemonAvailability(), SCardGetContextIndice(), SYS_MutexLock(), SYS_MutexUnLock(), SYS_USleep(), and SCARD_READERSTATE_A::szReader.
LONG SCardIsValidContext | ( | SCARDCONTEXT | hContext | ) |
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.
[in] | hContext | Connection context to the PC/SC Resource Manager. |
SCARD_S_SUCCESS | Successful (SCARD_S_SUCCESS) | |
SCARD_E_INVALID_HANDLE | Invalid Handle (SCARD_E_INVALID_HANDLE) |
SCARDCONTEXT hContext; LONG rv; ... rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext); rv = SCardIsValidContext(hContext);
Definition at line 3082 of file winscard_clnt.c.
References PROFILE_END, PROFILE_START, SCARD_E_INVALID_HANDLE, SCARD_S_SUCCESS, and SCardGetContextIndice().
Referenced by main().
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.
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".
[in] | hContext | Connection context to the PC/SC Resource Manager. |
[out] | mszGroups | List of groups to list readers. |
pcchGroups | [inout] Size of multi-string buffer including NULL's. |
SCARD_S_SUCCESS | Successful (SCARD_S_SUCCESS) | |
SCARD_E_INVALID_HANDLE | Invalid Scope Handle (SCARD_E_INVALID_HANDLE) | |
SCARD_E_INSUFFICIENT_BUFFER | Reader buffer not large enough (SCARD_E_INSUFFICIENT_BUFFER) |
SCARDCONTEXT hContext; LPSTR mszGroups; DWORD dwGroups; LONG rv; ... rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext); rv = SCardListReaderGroups(hContext, NULL, &dwGroups); mszGroups = malloc(sizeof(char)*dwGroups); rv = SCardListReaderGroups(hContext, mszGroups, &dwGroups);
Definition at line 2966 of file winscard_clnt.c.
References PROFILE_END, PROFILE_START, psContextMap, SCARD_E_INSUFFICIENT_BUFFER, SCARD_E_INVALID_HANDLE, SCARD_E_NO_SERVICE, SCARD_S_SUCCESS, SCardCheckDaemonAvailability(), SCardGetContextIndice(), SYS_MutexLock(), and SYS_MutexUnLock().
LONG SCardListReaders | ( | SCARDCONTEXT | hContext, | |
LPCSTR | mszGroups, | |||
LPSTR | mszReaders, | |||
LPDWORD | pcchReaders | |||
) |
This function returns a list of currently available readers on the system.
mszReaders
is a pointer to a character string that is allocated by the application. If the application sends mszGroups and mszReaders as NULL then this function will return the size of the buffer needed to allocate in pcchReaders.
[in] | hContext | Connection context to the PC/SC Resource Manager. |
[in] | mszGroups | List of groups to list readers (not used). |
[out] | mszReaders | Multi-string with list of readers. |
pcchReaders | [inout] Size of multi-string buffer including NULL's. |
SCARD_S_SUCCESS | Successful (SCARD_S_SUCCESS) | |
SCARD_E_INVALID_HANDLE | Invalid Scope Handle (SCARD_E_INVALID_HANDLE) | |
SCARD_E_INSUFFICIENT_BUFFER | Reader buffer not large enough (SCARD_E_INSUFFICIENT_BUFFER) |
SCARDCONTEXT hContext; LPSTR mszReaders; DWORD dwReaders; LONG rv; ... rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext); rv = SCardListReaders(hContext, NULL, NULL, &dwReaders); mszReaders = malloc(sizeof(char)*dwReaders); rv = SCardListReaders(hContext, NULL, mszReaders, &dwReaders);
Definition at line 2862 of file winscard_clnt.c.
References PROFILE_END, PROFILE_START, psContextMap, readerStates, SCARD_E_INSUFFICIENT_BUFFER, SCARD_E_INVALID_HANDLE, SCARD_E_INVALID_PARAMETER, SCARD_E_NO_SERVICE, SCARD_S_SUCCESS, SCardCheckDaemonAvailability(), SCardGetContextIndice(), SYS_MutexLock(), and SYS_MutexUnLock().
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 3318 of file winscard_clnt.c.
References SYS_MutexLock().
Referenced by SCardBeginTransaction(), SCardCancel(), SCardCancelTransaction(), SCardConnect(), SCardDisconnect(), SCardEndTransaction(), SCardEstablishContext(), SCardGetContextIndice(), SCardGetIndicesFromHandle(), SCardGetStatusChange(), SCardListReaderGroups(), SCardListReaders(), SCardReconnect(), SCardReleaseContext(), SCardStatus(), and SCardTransmit().
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().
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.
[in] | hCard | Handle to a previous call to connect. |
[in] | dwShareMode | Mode of connection type: exclusive/shared.
|
[in] | dwPreferredProtocols | Desired protocol use.
dwPreferredProtocols is a bit mask of acceptable protocols for the connection. You can use (SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1) if you do not have a preferred protocol. |
[in] | dwInitialization | Desired action taken on the card/reader.
|
[out] | pdwActiveProtocol | Established protocol to this connection. |
SCARD_S_SUCCESS | Successful (SCARD_S_SUCCESS) | |
SCARD_E_INVALID_HANDLE | Invalid hCard handle (SCARD_E_INVALID_HANDLE) | |
SCARD_E_NOT_READY | Could not allocate the desired port (SCARD_E_NOT_READY) | |
SCARD_E_INVALID_VALUE | Invalid sharing mode, requested protocol, or reader name (SCARD_E_INVALID_VALUE) | |
SCARD_E_READER_UNAVAILABLE | The reader has been removed (SCARD_E_READER_UNAVAILABLE) | |
SCARD_E_UNSUPPORTED_FEATURE | Protocol not supported (SCARD_E_UNSUPPORTED_FEATURE) | |
SCARD_E_SHARING_VIOLATION | Someone else has exclusive rights (SCARD_E_SHARING_VIOLATION) |
SCARDCONTEXT hContext; SCARDHANDLE hCard; DWORD dwActiveProtocol, dwSendLength, dwRecvLength; LONG rv; BYTE pbRecvBuffer[10]; BYTE pbSendBuffer[] = {0xC0, 0xA4, 0x00, 0x00, 0x02, 0x3F, 0x00}; ... rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext); rv = SCardConnect(hContext, "Reader X", SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0, &hCard, &dwActiveProtocol); ... dwSendLength = sizeof(pbSendBuffer); dwRecvLength = sizeof(pbRecvBuffer); rv = SCardTransmit(hCard, SCARD_PCI_T0, pbSendBuffer, dwSendLength, &pioRecvPci, pbRecvBuffer, &dwRecvLength); / * Card has been reset by another application * / if (rv == SCARD_W_RESET_CARD) { rv = SCardReconnect(hCard, SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0, SCARD_RESET_CARD, &dwActiveProtocol); }
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, PCSCLITE_MAX_READERS_CONTEXTS, reconnect_struct::pdwActiveProtocol, PROFILE_END, PROFILE_START, psContextMap, readerStates, SCARD_E_INVALID_HANDLE, SCARD_E_INVALID_PARAMETER, SCARD_E_INVALID_VALUE, SCARD_E_NO_SERVICE, SCARD_E_READER_UNAVAILABLE, SCARD_EJECT_CARD, SCARD_F_COMM_ERROR, SCARD_LEAVE_CARD, SCARD_PROTOCOL_ANY_OLD, SCARD_PROTOCOL_RAW, SCARD_PROTOCOL_T0, SCARD_PROTOCOL_T1, SCARD_RESET_CARD, SCARD_S_SUCCESS, SCARD_UNPOWER_CARD, SCardCheckDaemonAvailability(), SCardGetIndicesFromHandle(), SHMClientRead(), SYS_MutexLock(), SYS_MutexUnLock(), and WrapSHMWrite().
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.
[in] | hContext | Connection context to be closed. |
SCARD_S_SUCCESS | Successful (SCARD_S_SUCCESS) |
SCARDCONTEXT hContext; LONG rv; ... rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext); rv = SCardReleaseContext(hContext);
Definition at line 491 of file winscard_clnt.c.
References rxSharedSegment::data, release_struct::hContext, PCSCLITE_CLIENT_ATTEMPTS, PCSCLITE_MCLIENT_ATTEMPTS, PROFILE_END, PROFILE_START, psContextMap, release_struct::rv, SCARD_E_INVALID_HANDLE, SCARD_E_NO_SERVICE, SCARD_F_COMM_ERROR, SCARD_S_SUCCESS, SCardCheckDaemonAvailability(), SCardGetContextIndice(), SCardLockThread(), SCardRemoveContext(), SCardUnlockThread(), SHMClientRead(), SYS_MutexLock(), SYS_MutexUnLock(), and WrapSHMWrite().
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 3199 of file winscard_clnt.c.
References BLOCK_STATUS_RESUME, _psContextMap::contextBlockStatus, _psContextMap::dwClientID, _psContextMap::hContext, _psContextMap::mMutex, PCSCLITE_MAX_APPLICATION_CONTEXT_CHANNELS, _psContextMap::psChannelMap, psContextMap, _psChannelMap::readerName, SCARD_E_INVALID_HANDLE, SCARD_S_SUCCESS, SCardGetContextIndiceTH(), and SHMClientCloseSession().
Referenced by SCardReleaseContext(), and SCardReleaseContextTH().
LONG SCardSetAttrib | ( | SCARDHANDLE | hCard, | |
DWORD | dwAttrId, | |||
LPCBYTE | pbAttr, | |||
DWORD | cbAttrLen | |||
) |
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.
[in] | hCard | Connection made from SCardConnect(). |
[in] | dwAttrId | Identifier for the attribute to set. |
[in] | pbAttr | Pointer to a buffer that receives the attribute. |
[in] | cbAttrLen | Length of the pbAttr buffer in bytes. |
SCARD_S_SUCCESS | Successful (SCARD_S_SUCCESS) | |
SCARD_E_NOT_TRANSACTED | Data exchange not successful (SCARD_E_NOT_TRANSACTED) |
LONG rv; SCARDCONTEXT hContext; SCARDHANDLE hCard; DWORD dwActiveProtocol; unsigned char pbAtr[MAX_ATR_SIZE]; DWORD dwAtrLen; ... rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext); rv = SCardConnect(hContext, "Reader X", SCARD_SHARE_SHARED, SCARD_PROTOCOL_RAW &hCard, &dwActiveProtocol); rv = SCardSetAttrib(hCard, 0x42000001, "\x12\x34\x56", 3);
Definition at line 2455 of file winscard_clnt.c.
References PROFILE_END, PROFILE_START, SCARD_E_INVALID_PARAMETER, and SCardGetSetAttrib().
LONG SCardSetTimeout | ( | SCARDCONTEXT | hContext, | |
DWORD | dwTimeout | |||
) |
[in] | hContext | Connection context to the PC/SC Resource Manager. |
[in] | dwTimeout | New timeout value. |
SCARD_S_SUCCESS | Successful (SCARD_S_SUCCESS) |
Definition at line 563 of file winscard_clnt.c.
References SCARD_S_SUCCESS.
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.
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.
[in] | hCard | Connection made from SCardConnect. |
mszReaderNames | [inout] Friendly name of this reader. | |
pcchReaderLen | [inout] Size of the szReaderName multistring. | |
[out] | pdwState | Current state of this reader. pdwState is a DWORD possibly OR'd with the following values:
|
[out] | pdwProtocol | Current protocol of this reader.
|
[out] | pbAtr | Current ATR of a card in this reader. |
[out] | pcbAtrLen | Length of ATR. |
SCARD_S_SUCCESS | Successful (SCARD_S_SUCCESS) | |
SCARD_E_INVALID_HANDLE | Invalid hCard handle (SCARD_E_INVALID_HANDLE) | |
SCARD_E_INSUFFICIENT_BUFFER | Not enough allocated memory for szReaderName or for pbAtr (SCARD_E_INSUFFICIENT_BUFFER) | |
SCARD_E_READER_UNAVAILABLE | The reader has been removed (SCARD_E_READER_UNAVAILABLE) |
SCARDCONTEXT hContext; SCARDHANDLE hCard; DWORD dwActiveProtocol; DWORD dwState, dwProtocol, dwAtrLen, dwReaderLen; BYTE pbAtr[MAX_ATR_SIZE]; ... rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext); rv = SCardConnect(hContext, "Reader X", SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0, &hCard, &dwActiveProtocol); ... dwAtrLen = sizeof(pbAtr); rv=SCardStatus(hCard, NULL, &dwReaderLen, &dwState, &dwProtocol, pbAtr, &dwAtrLen);
Definition at line 1385 of file winscard_clnt.c.
References rxSharedSegment::data, min, PCSCLITE_CLIENT_ATTEMPTS, PCSCLITE_MAX_READERS_CONTEXTS, PROFILE_END, PROFILE_START, _psContextMap::psChannelMap, psContextMap, _psChannelMap::readerName, readerStates, SCARD_E_INSUFFICIENT_BUFFER, SCARD_E_INVALID_HANDLE, SCARD_E_INVALID_PARAMETER, SCARD_E_NO_SERVICE, SCARD_E_READER_UNAVAILABLE, SCARD_F_COMM_ERROR, SCARD_S_SUCCESS, SCardCheckDaemonAvailability(), SCardGetIndicesFromHandle(), SHMClientRead(), SYS_MutexLock(), SYS_MutexUnLock(), and WrapSHMWrite().
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().
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;
[in] | hCard | Connection made from SCardConnect(). |
pioSendPci | [inout] Structure of protocol information.
| |
[in] | pbSendBuffer | APDU to send to the card. |
[in] | cbSendLength | Length of the APDU. |
pioRecvPci | [inout] Structure of protocol information. | |
[out] | pbRecvBuffer | Response from the card. |
pcbRecvLength | [inout] Length of the response. |
SCARD_S_SUCCESS | Successful (SCARD_S_SUCCESS) | |
SCARD_E_INVALID_HANDLE | Invalid hCard handle (SCARD_E_INVALID_HANDLE) | |
SCARD_E_NOT_TRANSACTED | APDU exchange not successful (SCARD_E_NOT_TRANSACTED) | |
SCARD_E_PROTO_MISMATCH | Connect protocol is different than desired (SCARD_E_PROTO_MISMATCH) | |
SCARD_E_INVALID_VALUE | Invalid Protocol, reader name, etc (SCARD_E_INVALID_VALUE) | |
SCARD_E_READER_UNAVAILABLE | The reader has been removed (SCARD_E_READER_UNAVAILABLE) | |
SCARD_W_RESET_CARD | The card has been reset by another application (SCARD_W_RESET_CARD) | |
SCARD_W_REMOVED_CARD | The card has been removed from the reader (SCARD_W_REMOVED_CARD) |
LONG rv; SCARDCONTEXT hContext; SCARDHANDLE hCard; DWORD dwActiveProtocol, dwSendLength, dwRecvLength; SCARD_IO_REQUEST pioRecvPci; BYTE pbRecvBuffer[10]; BYTE pbSendBuffer[] = { 0xC0, 0xA4, 0x00, 0x00, 0x02, 0x3F, 0x00 }; ... rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext); rv = SCardConnect(hContext, "Reader X", SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0, &hCard, &dwActiveProtocol); dwSendLength = sizeof(pbSendBuffer); dwRecvLength = sizeof(pbRecvBuffer); rv = SCardTransmit(hCard, SCARD_PCI_T0, pbSendBuffer, dwSendLength, &pioRecvPci, pbRecvBuffer, &dwRecvLength);
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, _SCARD_IO_REQUEST::dwProtocol, transmit_struct::hCard, transmit_struct_extended::hCard, MAX_BUFFER_SIZE, MAX_BUFFER_SIZE_EXTENDED, 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, PROFILE_END, PROFILE_START, psContextMap, readerStates, SCARD_E_INSUFFICIENT_BUFFER, SCARD_E_INVALID_HANDLE, SCARD_E_INVALID_PARAMETER, SCARD_E_NO_SERVICE, SCARD_E_READER_UNAVAILABLE, SCARD_F_COMM_ERROR, SCARD_PROTOCOL_ANY, SCARD_S_SUCCESS, SCardCheckDaemonAvailability(), SCardGetIndicesFromHandle(), SHMClientRead(), SHMMessageReceive(), transmit_struct_extended::size, SYS_MutexLock(), SYS_MutexUnLock(), and WrapSHMWrite().
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 3365 of file winscard_clnt.c.
References PCSCLITE_MAX_APPLICATION_CONTEXT_CHANNELS, readerStates, SYS_CloseFile(), and SYS_PublicMemoryUnmap().
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 3328 of file winscard_clnt.c.
References SYS_MutexUnLock().
Referenced by SCardBeginTransaction(), SCardCancel(), SCardCancelTransaction(), SCardConnect(), SCardDisconnect(), SCardEndTransaction(), SCardEstablishContext(), SCardGetContextIndice(), SCardGetIndicesFromHandle(), SCardGetStatusChange(), SCardListReaderGroups(), SCardListReaders(), SCardReconnect(), SCardReleaseContext(), SCardStatus(), and SCardTransmit().
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 167 of file winscard_clnt.c.
Referenced by SCardLockThread(), and SCardUnlockThread().
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 161 of file winscard_clnt.c.
Referenced by SCardUnload().
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 getSessionForContext(), isActiveContextPresent(), PCSC_SCF_Initialize(), SCardAddContext(), SCardAddHandle(), SCardBeginTransaction(), SCardCancel(), SCardCancelTH(), SCardCancelTransaction(), SCardConnect(), SCardControl(), SCardDisconnect(), SCardEndTransaction(), SCardEstablishContextTH(), SCardGetContextIndice(), SCardGetContextIndiceTH(), SCardGetIndicesFromHandleTH(), SCardGetSetAttrib(), SCardGetStatusChange(), SCardListReaderGroups(), SCardListReaders(), SCardReconnect(), SCardReleaseContext(), SCardRemoveContext(), SCardRemoveHandle(), 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 175 of file winscard_clnt.c.