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"

Include dependency graph for winscard_scf.c:

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
 Reader Map to handle Status and GetStatusChange. More...

Defines

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

Functions

static LONG isOCFServerRunning (void)
LONG SCardLockThread (void)
LONG SCardUnlockThread (void)
LONG SCardEventLock (void)
LONG SCardEventUnlock (void)
static LONG PCSC_SCF_Initialize (void)
static void EventCallback (SCF_Event_t eventType, SCF_Terminal_t hTerm, void *cbdata)
static LONG PCSC_SCF_getATR (SCF_Card_t hCard, LPBYTE pcbAtr, LPDWORD pcbAtrLen)
static LONG ConvertStatus (SCF_Status_t status)
static LONG SCardGetReaderIndice (LPCSTR ReaderName)
static LONG getNewContext (SCARDCONTEXT *phContext)
static LONG SCardAddContext (SCARDCONTEXT hContext, SCF_Session_t hSession)
static SCF_Session_t getSessionForContext (SCARDCONTEXT hContext)
static LONG SCardRemoveContext (SCARDCONTEXT hContext)
static LONG SCardGetContextIndice (SCARDCONTEXT hContext)
static LONG getNewHandle (SCARDCONTEXT hContext, LPCSTR szReader, SCARDHANDLE *phCard, DWORD)
static LONG getCardForHandle (SCARDHANDLE PSCS_hCard, SCF_Card_t *SCF_hCard)
static LONG SCardRemoveHandle (SCARDHANDLE hCard)
static LONG SCardAddHandle (SCARDHANDLE PCSC_hCard, SCARDCONTEXT hContext, SCF_Session_t hSession, SCF_Terminal_t hTerminal, SCF_Card_t SCF_hCard, int, DWORD)
static LONG SCardGetHandleIndice (SCARDHANDLE hCard)
static LONG isActiveContextPresent (void)
static 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.
static LONG SCardReleaseContextTH (SCARDCONTEXT hContext)
LONG SCardReleaseContext (SCARDCONTEXT hContext)
 This function destroys a communication context to the PC/SC Resource Manager.
static 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.
static 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.
static LONG SCardDisconnectTH (SCARDHANDLE hCard, DWORD dwDisposition)
static 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.
static LONG SCardEndTransactionTH (SCARDHANDLE hCard, DWORD dwDisposition)
LONG SCardEndTransaction (SCARDHANDLE hCard, DWORD dwDisposition)
 This function ends a previously begun transaction.
static LONG SCardCancelTransactionTH (SCARDHANDLE hCard)
LONG SCardCancelTransaction (SCARDHANDLE hCard)
static 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.
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.
static 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().
static 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.
static 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)
 free resources allocated by the library You _shall_ call this function if you use dlopen/dlclose to load/unload the library.
LONG SCardCheckDaemonAvailability (void)
 Checks if the Server is running.

Variables

static SCF_Session_t g_hSession = NULL
 Global session to manage Readers, Card events.
SCARD_IO_REQUEST g_rgSCardT0Pci
 Have to define this because they are defined in pcsclite.h as externs.
SCARD_IO_REQUEST g_rgSCardT1Pci
SCARD_IO_REQUEST g_rgSCardRawPci
static struct _psTransmitMap psTransmitMap [PCSCLITE_MAX_APPLICATION_CONTEXTS]
static struct _psChannelMap psChannelMap [PCSCLITE_MAX_APPLICATION_CONTEXTS]
 Channel Map to manage Card Connections.
static struct _psContextMap psContextMap [PCSCLITE_MAX_APPLICATION_CONTEXTS]
 Context Map to manage contexts and sessions.
static struct _psReaderMap psReaderMap [PCSCLITE_MAX_READERS_CONTEXTS]
 Reader Map to handle Status and GetStatusChange.
static PCSCLITE_MUTEX clientMutex = PTHREAD_MUTEX_INITIALIZER
static PCSCLITE_MUTEX EventMutex = PTHREAD_MUTEX_INITIALIZER
 Mutex for the Smardcard Event Handling, different from client Mutex because event reporting from the ocfserver is done using a single thread, so to get lock on the clientMutex may affect the performance of the ocf server.
static PCSCLITE_MUTEX SCFInitMutex = PTHREAD_MUTEX_INITIALIZER
static pthread_cond_t EventCondition = PTHREAD_COND_INITIALIZER
static char PCSC_Initialized = 0


Detailed Description

This provides PC/SC to SCF shimming.

Definition in file winscard_scf.c.


Function Documentation

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)
SCARD_E_INVALID_HANDLE Server was restarted or after fork() (SCARD_E_INVALID_HANDLE)

Definition at line 1943 of file winscard_scf.c.

References SCARD_E_NO_SERVICE, and SCARD_S_SUCCESS.

void 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 1896 of file winscard_scf.c.

References g_hSession, isExecuted, mapAddr, psReaderMap, SHMClientCloseSession(), SYS_CloseFile(), and SYS_PublicMemoryUnmap().

Referenced by SCardCheckDaemonAvailability().

Here is the call graph for this function:


Variable Documentation

SCF_Session_t g_hSession = NULL [static]

Global session to manage Readers, Card events.

Definition at line 45 of file winscard_scf.c.

Referenced by SCardUnload().

struct _psChannelMap psChannelMap[PCSCLITE_MAX_APPLICATION_CONTEXTS] [static]

Channel Map to manage Card Connections.

Referenced by SCardStatus().

struct _psContextMap psContextMap[PCSCLITE_MAX_APPLICATION_CONTEXTS] [static]

Context Map to manage contexts and sessions.

struct _psReaderMap psReaderMap[PCSCLITE_MAX_READERS_CONTEXTS] [static]

Reader Map to handle Status and GetStatusChange.

Referenced by SCardGetStatusChange(), and SCardUnload().


Generated on Thu Aug 28 20:15:00 2008 for pcsc-lite by  doxygen 1.5.6