pcsc-lite 2.1.0
Macros | Functions | Variables
libredirect.c File Reference

Redirect PC/SC calls to the delegate library. More...

#include <dlfcn.h>
#include <stdio.h>
#include <stdarg.h>
#include <fcntl.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include <sys/time.h>
#include <pthread.h>
#include "misc.h"
#include <winscard.h>
#include "sys_generic.h"

Go to the source code of this file.

Macros

#define DEBUG
 
#define p_SCardEstablishContext(fct)   LONG(fct)(DWORD dwScope, LPCVOID pvReserved1, LPCVOID pvReserved2, LPSCARDCONTEXT phContext)
 
#define p_SCardReleaseContext(fct)   LONG(fct)(SCARDCONTEXT hContext)
 
#define p_SCardIsValidContext(fct)   LONG(fct) (SCARDCONTEXT hContext)
 
#define p_SCardConnect(fct)   LONG(fct) (SCARDCONTEXT hContext, LPCSTR szReader, DWORD dwShareMode, DWORD dwPreferredProtocols, LPSCARDHANDLE phCard, LPDWORD pdwActiveProtocol)
 
#define p_SCardReconnect(fct)   LONG(fct) (SCARDHANDLE hCard, DWORD dwShareMode, DWORD dwPreferredProtocols, DWORD dwInitialization, LPDWORD pdwActiveProtocol)
 
#define p_SCardDisconnect(fct)   LONG(fct) (SCARDHANDLE hCard, DWORD dwDisposition)
 
#define p_SCardBeginTransaction(fct)   LONG(fct) (SCARDHANDLE hCard)
 
#define p_SCardEndTransaction(fct)   LONG(fct) (SCARDHANDLE hCard, DWORD dwDisposition)
 
#define p_SCardStatus(fct)   LONG(fct) (SCARDHANDLE hCard, LPSTR mszReaderName, LPDWORD pcchReaderLen, LPDWORD pdwState, LPDWORD pdwProtocol, LPBYTE pbAtr, LPDWORD pcbAtrLen)
 
#define p_SCardGetStatusChange(fct)   LONG(fct) (SCARDCONTEXT hContext, DWORD dwTimeout, LPSCARD_READERSTATE rgReaderStates, DWORD cReaders)
 
#define p_SCardControl(fct)   LONG(fct) (SCARDHANDLE hCard, DWORD dwControlCode, LPCVOID pbSendBuffer, DWORD cbSendLength, LPVOID pbRecvBuffer, DWORD cbRecvLength, LPDWORD lpBytesReturned)
 
#define p_SCardTransmit(fct)   LONG(fct) (SCARDHANDLE hCard, const SCARD_IO_REQUEST * pioSendPci, LPCBYTE pbSendBuffer, DWORD cbSendLength, SCARD_IO_REQUEST * pioRecvPci, LPBYTE pbRecvBuffer, LPDWORD pcbRecvLength)
 
#define p_SCardListReaderGroups(fct)   LONG(fct) (SCARDCONTEXT hContext, LPSTR mszGroups, LPDWORD pcchGroups)
 
#define p_SCardListReaders(fct)   LONG(fct) (SCARDCONTEXT hContext, LPCSTR mszGroups, LPSTR mszReaders, LPDWORD pcchReaders)
 
#define p_SCardFreeMemory(fct)   LONG(fct) (SCARDCONTEXT hContext, LPCVOID pvMem)
 
#define p_SCardCancel(fct)   LONG(fct) (SCARDCONTEXT hContext)
 
#define p_SCardGetAttrib(fct)   LONG(fct) (SCARDHANDLE hCard, DWORD dwAttrId, LPBYTE pbAttr, LPDWORD pcbAttrLen)
 
#define p_SCardSetAttrib(fct)   LONG(fct) (SCARDHANDLE hCard, DWORD dwAttrId, LPCBYTE pbAttr, DWORD cbAttrLen)
 
#define LIBPCSC   "libpcsclite_real.so.1"
 
#define get_symbol(s)   do { redirect.s = dlsym(Lib_handle, #s); if (NULL == redirect.s) { log_line("%s", dlerror()); return SCARD_F_INTERNAL_ERROR; } } while (0)
 

Functions

static LONG internal_error (void)
 
static void log_line (const char *fmt,...)
 
static LONG load_lib (void)
 
PCSC_API p_SCardEstablishContext (SCardEstablishContext)
 
PCSC_API p_SCardReleaseContext (SCardReleaseContext)
 
PCSC_API p_SCardIsValidContext (SCardIsValidContext)
 
PCSC_API p_SCardConnect (SCardConnect)
 
PCSC_API p_SCardReconnect (SCardReconnect)
 
PCSC_API p_SCardDisconnect (SCardDisconnect)
 
PCSC_API p_SCardBeginTransaction (SCardBeginTransaction)
 
PCSC_API p_SCardEndTransaction (SCardEndTransaction)
 
PCSC_API p_SCardStatus (SCardStatus)
 
PCSC_API p_SCardGetStatusChange (SCardGetStatusChange)
 
PCSC_API p_SCardControl (SCardControl)
 
PCSC_API p_SCardTransmit (SCardTransmit)
 
PCSC_API p_SCardListReaderGroups (SCardListReaderGroups)
 
PCSC_API p_SCardListReaders (SCardListReaders)
 
PCSC_API p_SCardFreeMemory (SCardFreeMemory)
 
PCSC_API p_SCardCancel (SCardCancel)
 
PCSC_API p_SCardGetAttrib (SCardGetAttrib)
 
PCSC_API p_SCardSetAttrib (SCardSetAttrib)
 

Variables

struct { 
 
   p_SCardEstablishContext *   SCardEstablishContext 
 
   p_SCardReleaseContext *   SCardReleaseContext 
 
   p_SCardIsValidContext *   SCardIsValidContext 
 
   p_SCardConnect *   SCardConnect 
 
   p_SCardReconnect *   SCardReconnect 
 
   p_SCardDisconnect *   SCardDisconnect 
 
   p_SCardBeginTransaction *   SCardBeginTransaction 
 
   p_SCardEndTransaction *   SCardEndTransaction 
 
   p_SCardStatus *   SCardStatus 
 
   p_SCardGetStatusChange *   SCardGetStatusChange 
 
   p_SCardControl *   SCardControl 
 
   p_SCardTransmit *   SCardTransmit 
 
   p_SCardListReaderGroups *   SCardListReaderGroups 
 
   p_SCardListReaders *   SCardListReaders 
 
   p_SCardFreeMemory *   SCardFreeMemory 
 
   p_SCardCancel *   SCardCancel 
 
   p_SCardGetAttrib *   SCardGetAttrib 
 
   p_SCardSetAttrib *   SCardSetAttrib 
 
redirect 
 
static voidLib_handle = NULL
 
PCSC_API const SCARD_IO_REQUEST g_rgSCardT0Pci = { SCARD_PROTOCOL_T0, sizeof(SCARD_IO_REQUEST) }
 Protocol Control Information for T=0.
 
PCSC_API const SCARD_IO_REQUEST g_rgSCardT1Pci = { SCARD_PROTOCOL_T1, sizeof(SCARD_IO_REQUEST) }
 Protocol Control Information for T=1.
 
PCSC_API const SCARD_IO_REQUEST g_rgSCardRawPci = { SCARD_PROTOCOL_RAW, sizeof(SCARD_IO_REQUEST) }
 Protocol Control Information for raw access.
 

Detailed Description

Redirect PC/SC calls to the delegate library.

Definition in file libredirect.c.

Macro Definition Documentation

◆ DEBUG

#define DEBUG

Definition at line 51 of file libredirect.c.

◆ p_SCardBeginTransaction

#define p_SCardBeginTransaction ( fct)    LONG(fct) (SCARDHANDLE hCard)

Definition at line 67 of file libredirect.c.

◆ p_SCardCancel

#define p_SCardCancel ( fct)    LONG(fct) (SCARDCONTEXT hContext)

Definition at line 85 of file libredirect.c.

◆ p_SCardConnect

#define p_SCardConnect ( fct)    LONG(fct) (SCARDCONTEXT hContext, LPCSTR szReader, DWORD dwShareMode, DWORD dwPreferredProtocols, LPSCARDHANDLE phCard, LPDWORD pdwActiveProtocol)

Definition at line 61 of file libredirect.c.

◆ p_SCardControl

#define p_SCardControl ( fct)    LONG(fct) (SCARDHANDLE hCard, DWORD dwControlCode, LPCVOID pbSendBuffer, DWORD cbSendLength, LPVOID pbRecvBuffer, DWORD cbRecvLength, LPDWORD lpBytesReturned)

Definition at line 75 of file libredirect.c.

◆ p_SCardDisconnect

#define p_SCardDisconnect ( fct)    LONG(fct) (SCARDHANDLE hCard, DWORD dwDisposition)

Definition at line 65 of file libredirect.c.

◆ p_SCardEndTransaction

#define p_SCardEndTransaction ( fct)    LONG(fct) (SCARDHANDLE hCard, DWORD dwDisposition)

Definition at line 69 of file libredirect.c.

◆ p_SCardEstablishContext

#define p_SCardEstablishContext ( fct)    LONG(fct)(DWORD dwScope, LPCVOID pvReserved1, LPCVOID pvReserved2, LPSCARDCONTEXT phContext)

Definition at line 55 of file libredirect.c.

◆ p_SCardFreeMemory

#define p_SCardFreeMemory ( fct)    LONG(fct) (SCARDCONTEXT hContext, LPCVOID pvMem)

Definition at line 83 of file libredirect.c.

◆ p_SCardGetAttrib

#define p_SCardGetAttrib ( fct)    LONG(fct) (SCARDHANDLE hCard, DWORD dwAttrId, LPBYTE pbAttr, LPDWORD pcbAttrLen)

Definition at line 87 of file libredirect.c.

◆ p_SCardGetStatusChange

#define p_SCardGetStatusChange ( fct)    LONG(fct) (SCARDCONTEXT hContext, DWORD dwTimeout, LPSCARD_READERSTATE rgReaderStates, DWORD cReaders)

Definition at line 73 of file libredirect.c.

◆ p_SCardIsValidContext

#define p_SCardIsValidContext ( fct)    LONG(fct) (SCARDCONTEXT hContext)

Definition at line 59 of file libredirect.c.

◆ p_SCardListReaderGroups

#define p_SCardListReaderGroups ( fct)    LONG(fct) (SCARDCONTEXT hContext, LPSTR mszGroups, LPDWORD pcchGroups)

Definition at line 79 of file libredirect.c.

◆ p_SCardListReaders

#define p_SCardListReaders ( fct)    LONG(fct) (SCARDCONTEXT hContext, LPCSTR mszGroups, LPSTR mszReaders, LPDWORD pcchReaders)

Definition at line 81 of file libredirect.c.

◆ p_SCardReconnect

#define p_SCardReconnect ( fct)    LONG(fct) (SCARDHANDLE hCard, DWORD dwShareMode, DWORD dwPreferredProtocols, DWORD dwInitialization, LPDWORD pdwActiveProtocol)

Definition at line 63 of file libredirect.c.

◆ p_SCardReleaseContext

#define p_SCardReleaseContext ( fct)    LONG(fct)(SCARDCONTEXT hContext)

Definition at line 57 of file libredirect.c.

◆ p_SCardSetAttrib

#define p_SCardSetAttrib ( fct)    LONG(fct) (SCARDHANDLE hCard, DWORD dwAttrId, LPCBYTE pbAttr, DWORD cbAttrLen)

Definition at line 89 of file libredirect.c.

◆ p_SCardStatus

#define p_SCardStatus ( fct)    LONG(fct) (SCARDHANDLE hCard, LPSTR mszReaderName, LPDWORD pcchReaderLen, LPDWORD pdwState, LPDWORD pdwProtocol, LPBYTE pbAtr, LPDWORD pcbAtrLen)

Definition at line 71 of file libredirect.c.

◆ p_SCardTransmit

#define p_SCardTransmit ( fct)    LONG(fct) (SCARDHANDLE hCard, const SCARD_IO_REQUEST * pioSendPci, LPCBYTE pbSendBuffer, DWORD cbSendLength, SCARD_IO_REQUEST * pioRecvPci, LPBYTE pbRecvBuffer, LPDWORD pcbRecvLength)

Definition at line 77 of file libredirect.c.

Function Documentation

◆ internal_error()

static LONG internal_error ( void )
static

Definition at line 92 of file libredirect.c.

◆ load_lib()

static LONG load_lib ( void )
static

Definition at line 161 of file libredirect.c.

◆ log_line()

static void log_line ( const char * fmt,
... )
static

Definition at line 146 of file libredirect.c.

◆ p_SCardBeginTransaction()

PCSC_API p_SCardBeginTransaction ( SCardBeginTransaction )

Definition at line 258 of file libredirect.c.

◆ p_SCardCancel()

PCSC_API p_SCardCancel ( SCardCancel )

Definition at line 307 of file libredirect.c.

◆ p_SCardConnect()

PCSC_API p_SCardConnect ( SCardConnect )

Definition at line 241 of file libredirect.c.

◆ p_SCardControl()

PCSC_API p_SCardControl ( SCardControl )

Definition at line 280 of file libredirect.c.

◆ p_SCardDisconnect()

PCSC_API p_SCardDisconnect ( SCardDisconnect )

Definition at line 253 of file libredirect.c.

◆ p_SCardEndTransaction()

PCSC_API p_SCardEndTransaction ( SCardEndTransaction )

Definition at line 263 of file libredirect.c.

◆ p_SCardEstablishContext()

PCSC_API p_SCardEstablishContext ( SCardEstablishContext )

Definition at line 211 of file libredirect.c.

◆ p_SCardFreeMemory()

PCSC_API p_SCardFreeMemory ( SCardFreeMemory )

Definition at line 302 of file libredirect.c.

◆ p_SCardGetAttrib()

PCSC_API p_SCardGetAttrib ( SCardGetAttrib )

Definition at line 312 of file libredirect.c.

◆ p_SCardGetStatusChange()

PCSC_API p_SCardGetStatusChange ( SCardGetStatusChange )

Definition at line 274 of file libredirect.c.

◆ p_SCardIsValidContext()

PCSC_API p_SCardIsValidContext ( SCardIsValidContext )

Definition at line 236 of file libredirect.c.

◆ p_SCardListReaderGroups()

PCSC_API p_SCardListReaderGroups ( SCardListReaderGroups )

Definition at line 292 of file libredirect.c.

◆ p_SCardListReaders()

PCSC_API p_SCardListReaders ( SCardListReaders )

Definition at line 297 of file libredirect.c.

◆ p_SCardReconnect()

PCSC_API p_SCardReconnect ( SCardReconnect )

Definition at line 247 of file libredirect.c.

◆ p_SCardReleaseContext()

PCSC_API p_SCardReleaseContext ( SCardReleaseContext )

Definition at line 231 of file libredirect.c.

◆ p_SCardSetAttrib()

PCSC_API p_SCardSetAttrib ( SCardSetAttrib )

Definition at line 317 of file libredirect.c.

◆ p_SCardStatus()

PCSC_API p_SCardStatus ( SCardStatus )

Definition at line 268 of file libredirect.c.

◆ p_SCardTransmit()

PCSC_API p_SCardTransmit ( SCardTransmit )

Definition at line 286 of file libredirect.c.

Variable Documentation

◆ g_rgSCardRawPci

Protocol Control Information for raw access.

Definition at line 327 of file libredirect.c.

◆ g_rgSCardT0Pci

Protocol Control Information for T=0.

Definition at line 323 of file libredirect.c.

◆ g_rgSCardT1Pci

Protocol Control Information for T=1.

Definition at line 325 of file libredirect.c.

◆ Lib_handle

void* Lib_handle = NULL
static

Definition at line 143 of file libredirect.c.

◆ [struct]

struct { ... } redirect
Initial value:
= {
.SCardEstablishContext = (p_SCardEstablishContext(*))internal_error,
.SCardReleaseContext = (p_SCardReleaseContext(*))internal_error,
.SCardIsValidContext = (p_SCardIsValidContext(*))internal_error,
.SCardConnect = (p_SCardConnect(*))internal_error,
.SCardReconnect = (p_SCardReconnect(*))internal_error,
.SCardDisconnect = (p_SCardDisconnect(*))internal_error,
.SCardBeginTransaction = (p_SCardBeginTransaction(*))internal_error,
.SCardEndTransaction = (p_SCardEndTransaction(*))internal_error,
.SCardStatus = (p_SCardStatus(*))internal_error,
.SCardGetStatusChange = (p_SCardGetStatusChange(*))internal_error,
.SCardControl = (p_SCardControl(*))internal_error,
.SCardTransmit = (p_SCardTransmit(*))internal_error,
.SCardListReaderGroups = (p_SCardListReaderGroups(*))internal_error,
.SCardListReaders = (p_SCardListReaders(*))internal_error,
.SCardFreeMemory = (p_SCardFreeMemory(*))internal_error,
.SCardCancel = (p_SCardCancel(*))internal_error,
.SCardGetAttrib = (p_SCardGetAttrib(*))internal_error,
.SCardSetAttrib = (p_SCardSetAttrib(*))internal_error,
}

◆ SCardBeginTransaction

p_SCardBeginTransaction* SCardBeginTransaction

Definition at line 108 of file libredirect.c.

◆ SCardCancel

p_SCardCancel* SCardCancel

Definition at line 117 of file libredirect.c.

◆ SCardConnect

p_SCardConnect* SCardConnect

Definition at line 105 of file libredirect.c.

◆ SCardControl

p_SCardControl* SCardControl

Definition at line 112 of file libredirect.c.

◆ SCardDisconnect

p_SCardDisconnect* SCardDisconnect

Definition at line 107 of file libredirect.c.

◆ SCardEndTransaction

p_SCardEndTransaction* SCardEndTransaction

Definition at line 109 of file libredirect.c.

◆ SCardEstablishContext

p_SCardEstablishContext* SCardEstablishContext

Definition at line 102 of file libredirect.c.

◆ SCardFreeMemory

p_SCardFreeMemory* SCardFreeMemory

Definition at line 116 of file libredirect.c.

◆ SCardGetAttrib

p_SCardGetAttrib* SCardGetAttrib

Definition at line 118 of file libredirect.c.

◆ SCardGetStatusChange

p_SCardGetStatusChange* SCardGetStatusChange

Definition at line 111 of file libredirect.c.

◆ SCardIsValidContext

p_SCardIsValidContext* SCardIsValidContext

Definition at line 104 of file libredirect.c.

◆ SCardListReaderGroups

p_SCardListReaderGroups* SCardListReaderGroups

Definition at line 114 of file libredirect.c.

◆ SCardListReaders

p_SCardListReaders* SCardListReaders

Definition at line 115 of file libredirect.c.

◆ SCardReconnect

p_SCardReconnect* SCardReconnect

Definition at line 106 of file libredirect.c.

◆ SCardReleaseContext

p_SCardReleaseContext* SCardReleaseContext

Definition at line 103 of file libredirect.c.

◆ SCardSetAttrib

p_SCardSetAttrib* SCardSetAttrib

Definition at line 119 of file libredirect.c.

◆ SCardStatus

p_SCardStatus* SCardStatus

Definition at line 110 of file libredirect.c.

◆ SCardTransmit

p_SCardTransmit* SCardTransmit

Definition at line 113 of file libredirect.c.