Main Page | Data Structures | File List | Data Fields | Globals | Related Pages

winscard_scf.c File Reference

This provides PC/SC to SCF shimming. More...

#include "config.h"
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/un.h>
#include <smartcard/scf.h>
#include <time.h>
#include "pcsclite.h"
#include "winscard.h"
#include "debug.h"
#include "thread_generic.h"
#include "readerfactory.h"
#include "eventhandler.h"
#include "sys_generic.h"

Go to the source code of this file.

Data Structures

struct  _psTransmitMap
struct  _psChannelMap
 Represents an Application Context Channel. More...
struct  _psContextMap
 Represents the an Application Context on the Client side. More...
struct  _psReaderMap

Defines

#define TRUE   1
#define FALSE   0
#define PCSCLITE_MAX_READERS_CONTEXTS   2

Functions

LONG isOCFServerRunning (void)
LONG SCardLockThread (void)
LONG SCardUnlockThread (void)
LONG SCardEventLock (void)
LONG SCardEventUnlock (void)
LONG PCSC_SCF_Initialize (void)
void EventCallback (SCF_Event_t eventType, SCF_Terminal_t hTerm, void *cbdata)
LONG PCSC_SCF_getATR (SCF_Card_t hCard, LPBYTE pcbAtr, LPDWORD pcbAtrLen)
LONG ConvertStatus (SCF_Status_t status)
LONG SCardGetReaderIndice (LPCSTR ReaderName)
LONG getNewContext (SCARDCONTEXT *phContext)
LONG SCardAddContext (SCARDCONTEXT hContext, SCF_Session_t hSession)
SCF_Session_t getSessionForContext (SCARDCONTEXT hContext)
LONG SCardRemoveContext (SCARDCONTEXT hContext)
LONG SCardGetContextIndice (SCARDCONTEXT hContext)
LONG getNewHandle (SCARDCONTEXT hContext, LPCSTR szReader, SCARDHANDLE *phCard, DWORD)
LONG getCardForHandle (SCARDHANDLE PSCS_hCard, SCF_Card_t *SCF_hCard)
LONG SCardRemoveHandle (SCARDHANDLE hCard)
LONG SCardAddHandle (SCARDHANDLE PCSC_hCard, SCARDCONTEXT hContext, SCF_Session_t hSession, SCF_Terminal_t hTerminal, SCF_Card_t SCF_hCard, int, DWORD)
LONG SCardGetHandleIndice (SCARDHANDLE hCard)
LONG isActiveContextPresent (void)
LONG SCardEstablishContextTH (DWORD dwScope, LPCVOID pvReserved1, LPCVOID pvReserved2, LPSCARDCONTEXT phContext)
LONG SCardEstablishContext (DWORD dwScope, LPCVOID pvReserved1, LPCVOID pvReserved2, LPSCARDCONTEXT phContext)
 Creates an Application Context for a client.
LONG SCardReleaseContextTH (SCARDCONTEXT hContext)
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 SCardListReadersTH (SCARDCONTEXT hContext, LPCSTR mszGroups, LPSTR mszReaders, LPDWORD pcchReaders)
LONG SCardListReaders (SCARDCONTEXT hContext, LPCSTR mszGroups, LPSTR mszReaders, LPDWORD pcchReaders)
 This function returns a list of currently available readers on the system.
LONG SCardConnectTH (SCARDCONTEXT hContext, LPCSTR szReader, DWORD dwShareMode, DWORD dwPreferredProtocols, LPSCARDHANDLE phCard, LPDWORD pdwActiveProtocol)
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 SCardDisconnectTH (SCARDHANDLE hCard, DWORD dwDisposition)
LONG SCardReconnectTH (SCARDHANDLE hCard, DWORD dwShareMode, DWORD dwPreferredProtocols, DWORD dwInitialization, LPDWORD pdwActiveProtocol)
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 SCardEndTransactionTH (SCARDHANDLE hCard, DWORD dwDisposition)
LONG SCardEndTransaction (SCARDHANDLE hCard, DWORD dwDisposition)
 This function ends a previously begun transaction.
LONG SCardCancelTransactionTH (SCARDHANDLE hCard)
LONG SCardCancelTransaction (SCARDHANDLE hCard)
LONG SCardStatusTH (SCARDHANDLE hCard, LPSTR mszReaderNames, LPDWORD pcchReaderLen, LPDWORD pdwState, LPDWORD pdwProtocol, LPBYTE pbAtr, LPDWORD pcbAtrLen)
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 SCardTransmitTH (SCARDHANDLE hCard, LPCSCARD_IO_REQUEST pioSendPci, LPCBYTE pbSendBuffer, DWORD cbSendLength, LPSCARD_IO_REQUEST pioRecvPci, LPBYTE pbRecvBuffer, LPDWORD pcbRecvLength)
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 SCardListReaderGroupsTH (SCARDCONTEXT hContext, LPSTR mszGroups, LPDWORD pcchGroups)
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 SCardCancelTH (SCARDCONTEXT hContext)
LONG SCardCancel (SCARDCONTEXT hContext)
 This function cancels all pending blocking requests on the SCardGetStatusChange() function.
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 SCardCheckReaderAvailability (LPSTR readerName, LONG errorCode)
void SCardUnload (void)
LONG SCardCheckDaemonAvailability (void)
 Checks if the Server is running.

Variables

SCF_Session_t g_hSession = NULL
SCARD_IO_REQUEST g_rgSCardT0Pci
SCARD_IO_REQUEST g_rgSCardT1Pci
SCARD_IO_REQUEST g_rgSCardRawPci
_psTransmitMap psTransmitMap [PCSCLITE_MAX_APPLICATION_CONTEXTS]
_psChannelMap psChannelMap [PCSCLITE_MAX_APPLICATION_CONTEXTS]
_psContextMap psContextMap [PCSCLITE_MAX_APPLICATION_CONTEXTS]
_psReaderMap psReaderMap [PCSCLITE_MAX_READERS_CONTEXTS]
PCSCLITE_MUTEX clientMutex = PTHREAD_MUTEX_INITIALIZER
PCSCLITE_MUTEX EventMutex = PTHREAD_MUTEX_INITIALIZER
PCSCLITE_MUTEX SCFInitMutex = PTHREAD_MUTEX_INITIALIZER
pthread_cond_t EventCondition = PTHREAD_COND_INITIALIZER
char PCSC_Initialized = 0


Detailed Description

This provides PC/SC to SCF shimming.

Definition in file winscard_scf.c.


Function Documentation

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.

Parameters:
[in] hCard Connection made from SCardConnect.
Returns:
Error code.
Return values:
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)

Test:
 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 478 of file winscard_scf.c.

References SCardLockThread(), and SCardUnlockThread().

Referenced by MSGFunctionDemarshall().

LONG SCardCancel SCARDCONTEXT  hContext  ) 
 

This function cancels all pending blocking requests on the SCardGetStatusChange() function.

Parameters:
[in] hContext Connection context to the PC/SC Resource Manager.
Returns:
Error code.
Return values:
SCARD_S_SUCCESS Successful (SCARD_S_SUCCESS)
SCARD_E_INVALID_HANDLE Invalid hContext handle (SCARD_E_INVALID_HANDLE)

Test:
 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 1185 of file winscard_scf.c.

References SCardLockThread(), and SCardUnlockThread().

LONG SCardCancelTransaction SCARDHANDLE  hCard  ) 
 

Deprecated:
This function is not in Microsoft(R) WinSCard API and is deprecated in pcsc-lite API.

Definition at line 576 of file winscard_scf.c.

References SCardLockThread(), and SCardUnlockThread().

Referenced by MSGFunctionDemarshall().

LONG SCardCheckDaemonAvailability void   ) 
 

Checks if the Server is running.

Returns:
Error code.
Return values:
SCARD_S_SUCCESS Server is running (SCARD_S_SUCCESS)
SCARD_E_NO_SERVICE Server is not running (SCARD_E_NO_SERVICE)

Definition at line 1943 of file winscard_scf.c.

Referenced by SCardBeginTransaction(), SCardCancelTransaction(), SCardConnect(), SCardControl(), SCardDisconnect(), SCardEndTransaction(), SCardEstablishContextTH(), 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.

Parameters:
[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. 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.
[out] phCard Handle to this connection.
[out] pdwActiveProtocol Established protocol to this connection.
Returns:
Error code.
Return values:
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)

Test:
 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 344 of file winscard_scf.c.

References PCSCLITE_STATUS_POLL_RATE, SCARD_PROTOCOL_T0, SCARD_PROTOCOL_UNSET, SCARD_SHARE_EXCLUSIVE, SCARD_SHARE_SHARED, SCardLockThread(), SCardUnlockThread(), and SYS_USleep().

Referenced by MSGFunctionDemarshall().

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.

Note:
the API of this function changed. In pcsc-lite 1.2.0 and before the API was not Windows(R) PC/SC compatible. This has been corrected.
Parameters:
[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.
Returns:
Error code.
Return values:
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)

Test:
 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 1013 of file winscard_scf.c.

Referenced by MSGFunctionDemarshall().

LONG SCardDisconnect SCARDHANDLE  hCard,
DWORD  dwDisposition
 

This function terminates a connection to the connection made through SCardConnect().

dwDisposition can have the following values:

Parameters:
[in] hCard Connection made from SCardConnect.
[in] dwDisposition Reader function to execute.
Returns:
Error code.
Return values:
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)

Test:
 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 467 of file winscard_scf.c.

References PCSCLITE_STATUS_POLL_RATE, SCARD_RESET, SCARD_RESET_CARD, SCardLockThread(), SCardUnlockThread(), and SYS_USleep().

Referenced by MSGFunctionDemarshall().

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.

Parameters:
[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.
Returns:
Error code.
Return values:
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)

Test:
 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 557 of file winscard_scf.c.

References SCARD_RESET, SCARD_RESET_CARD, SCardLockThread(), and SCardUnlockThread().

Referenced by MSGFunctionDemarshall().

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().

Parameters:
[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.
Returns:
Connection status.
Return values:
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)

Test:
 SCARDCONTEXT hContext;
 LONG rv;
 ...
 rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext);

Definition at line 160 of file winscard_scf.c.

References SCardLockThread(), and SCardUnlockThread().

Referenced by MSGFunctionDemarshall().

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.

Parameters:
[in] hCard Connection made from SCardConnect().
[in] dwAttrId Identifier for the attribute to get.
  • SCARD_ATTR_ASYNC_PROTOCOL_TYPES
  • SCARD_ATTR_ATR_STRING
  • SCARD_ATTR_CHANNEL_ID
  • SCARD_ATTR_CHARACTERISTICS
  • SCARD_ATTR_CURRENT_BWT
  • SCARD_ATTR_CURRENT_CLK
  • SCARD_ATTR_CURRENT_CWT
  • SCARD_ATTR_CURRENT_D
  • SCARD_ATTR_CURRENT_EBC_ENCODING
  • SCARD_ATTR_CURRENT_F
  • SCARD_ATTR_CURRENT_IFSC
  • SCARD_ATTR_CURRENT_IFSD
  • SCARD_ATTR_CURRENT_IO_STATE
  • SCARD_ATTR_CURRENT_N
  • SCARD_ATTR_CURRENT_PROTOCOL_TYPE
  • SCARD_ATTR_CURRENT_W
  • SCARD_ATTR_DEFAULT_CLK
  • SCARD_ATTR_DEFAULT_DATA_RATE
  • SCARD_ATTR_DEVICE_FRIENDLY_NAME_A
  • SCARD_ATTR_DEVICE_FRIENDLY_NAME_W
  • SCARD_ATTR_DEVICE_IN_USE
  • SCARD_ATTR_DEVICE_SYSTEM_NAME_A
  • SCARD_ATTR_DEVICE_SYSTEM_NAME_W
  • SCARD_ATTR_DEVICE_UNIT
  • SCARD_ATTR_ESC_AUTHREQUEST
  • SCARD_ATTR_ESC_CANCEL
  • SCARD_ATTR_ESC_RESET
  • SCARD_ATTR_EXTENDED_BWT
  • SCARD_ATTR_ICC_INTERFACE_STATUS
  • SCARD_ATTR_ICC_PRESENCE
  • SCARD_ATTR_ICC_TYPE_PER_ATR
  • SCARD_ATTR_MAX_CLK
  • SCARD_ATTR_MAX_DATA_RATE
  • SCARD_ATTR_MAX_IFSD
  • SCARD_ATTR_MAXINPUT
  • SCARD_ATTR_POWER_MGMT_SUPPORT
  • SCARD_ATTR_SUPRESS_T1_IFS_REQUEST
  • SCARD_ATTR_SYNC_PROTOCOL_TYPES
  • SCARD_ATTR_USER_AUTH_INPUT_DEVICE
  • SCARD_ATTR_USER_TO_CARD_AUTH_DEVICE
  • SCARD_ATTR_VENDOR_IFD_SERIAL_NO
  • SCARD_ATTR_VENDOR_IFD_TYPE
  • SCARD_ATTR_VENDOR_IFD_VERSION
  • SCARD_ATTR_VENDOR_NAME
Not all the dwAttrId values listed above may be implemented in the IFD Handler you are using. And some dwAttrId values not listed here may be implemented.

Parameters:
[out] pbAttr Pointer to a buffer that receives the attribute.
pcbAttrLen [inout] Length of the pbAttr buffer in bytes.
Returns:
Error code.
Return values:
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)

Test:
 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 1196 of file winscard_scf.c.

Referenced by MSGFunctionDemarshall().

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:

  • SCARD_STATE_UNAWARE The application is unaware of the current state, and would like to know. The use of this value results in an immediate return from state transition monitoring services. This is represented by all bits set to zero.
  • SCARD_STATE_IGNORE This reader should be ignored
  • SCARD_STATE_CHANGED There is a difference between the state believed by the application, and the state known by the resource manager. When this bit is set, the application may assume a significant state change has occurred on this reader.
  • SCARD_STATE_UNKNOWN The given reader name is not recognized by the resource manager. If this bit is set, then SCARD_STATE_CHANGED and SCARD_STATE_IGNORE will also be set
  • SCARD_STATE_UNAVAILABLE The actual state of this reader is not available. If this bit is set, then all the following bits are clear.
  • SCARD_STATE_EMPTY There is no card in the reader. If this bit is set, all the following bits will be clear
  • SCARD_STATE_PRESENT There is a card in the reader
  • SCARD_STATE_ATRMATCH There is a card in the reader with an ATR matching one of the target cards. If this bit is set, SCARD_STATE_PRESENT will also be set. This bit is only returned on the SCardLocateCards() function.
  • SCARD_STATE_EXCLUSIVE The card in the reader is allocated for exclusive use by another application. If this bit is set, SCARD_STATE_PRESENT will also be set.
  • SCARD_STATE_INUSE The card in the reader is in use by one or more other applications, but may be connected to in shared mode. If this bit is set, SCARD_STATE_PRESENT will also be set.
  • SCARD_STATE_MUTE There is an unresponsive card in the reader.

Parameters:
[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.
Returns:
Error code.
Return values:
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)

Test:
 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 688 of file winscard_scf.c.

References _psContextMap::contextBlockStatus, INFINITE, PCSCLITE_STATUS_WAIT, PREADER_STATE, SCARD_STATE_ATRMATCH, SCARD_STATE_CHANGED, SCARD_STATE_EXCLUSIVE, SCARD_STATE_PRESENT, SCARD_STATE_UNKNOWN, SCardLockThread(), SCardUnlockThread(), and SYS_USleep().

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".

Parameters:
[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.
Returns:
Error code.
Return values:
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)

Test:
 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 1156 of file winscard_scf.c.

References SCardLockThread(), and SCardUnlockThread().

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.

Parameters:
[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.
Returns:
Connection status.
Return values:
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)

Test:
 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 273 of file winscard_scf.c.

References SCardLockThread(), and SCardUnlockThread().

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.

Parameters:
[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.
Returns:
Error code.
Return values:
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)

Test:
 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 454 of file winscard_scf.c.

References PCSCLITE_STATUS_POLL_RATE, SCARD_E_INVALID_HANDLE, SCARD_E_INVALID_VALUE, SCARD_LEAVE_CARD, SCARD_PROTOCOL_T0, SCARD_PROTOCOL_UNSET, SCARD_RESET, SCARD_RESET_CARD, SCARD_SHARE_EXCLUSIVE, SCARD_SHARE_SHARED, SCARD_W_REMOVED_CARD, SCARD_W_RESET_CARD, SCardLockThread(), SCardUnlockThread(), and SYS_USleep().

Referenced by MSGFunctionDemarshall().

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.

Parameters:
[in] hContext Connection context to be closed.
Returns:
Connection status.
Return values:
SCARD_S_SUCCESS Successful (SCARD_S_SUCCESS)

Test:
 SCARDCONTEXT hContext;
 LONG rv;
 ...
 rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext);
 rv = SCardReleaseContext(hContext);

Definition at line 189 of file winscard_scf.c.

References SCardLockThread(), and SCardUnlockThread().

Referenced by MSGFunctionDemarshall().

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.

Parameters:
[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.
Returns:
Error code
Return values:
SCARD_S_SUCCESS Successful (SCARD_S_SUCCESS)
SCARD_E_NOT_TRANSACTED Data exchange not successful (SCARD_E_NOT_TRANSACTED)

Test:
 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 1202 of file winscard_scf.c.

Referenced by MSGFunctionDemarshall().

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.

Parameters:
[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:
  • SCARD_ABSENT - There is no card in the reader.
  • SCARD_PRESENT - There is a card in the reader, but it has not been moved into position for use.
  • SCARD_SWALLOWED - There is a card in the reader in position for use. The card is not powered.
  • SCARD_POWERED - Power is being provided to the card, but the reader driver is unaware of the mode of the card.
  • SCARD_NEGOTIABLE - The card has been reset and is awaiting PTS negotiation.
  • SCARD_SPECIFIC - The card has been reset and specific communication protocols have been established.
[out] pdwProtocol Current protocol of this reader.
[out] pbAtr Current ATR of a card in this reader.
[out] pcbAtrLen Length of ATR.
Returns:
Error code.
Return values:
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)

Test:
 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 675 of file winscard_scf.c.

References MAX_BUFFER_SIZE, SCardLockThread(), and SCardUnlockThread().

Referenced by MSGFunctionDemarshall().

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;

Parameters:
[in] hCard Connection made from SCardConnect().
pioSendPci [inout] Structure of protocol information.
  • SCARD_PCI_T0 - Pre-defined T=0 PCI structure.
  • SCARD_PCI_T1 - Pre-defined T=1 PCI structure.
[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.
Returns:
Error code.
Return values:
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)

Test:
 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 1111 of file winscard_scf.c.

References SCardLockThread(), and SCardUnlockThread().

Referenced by MSGFunctionDemarshall().


Generated on Fri Jan 26 22:54:55 2007 for pcsc-lite by  doxygen 1.3.9.1