pcsc-lite 2.3.0
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 DLSYM_DECLARE(symbol)    typeof(symbol)* symbol
 
#define DLSYM_SET_VALUE(symbol)    .symbol = (typeof(symbol)(*))internal_error
 
#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 LONG SCardEstablishContext (DWORD dwScope, LPCVOID pvReserved1, LPCVOID pvReserved2, LPSCARDCONTEXT phContext)
 
PCSC_API LONG SCardReleaseContext (SCARDCONTEXT hContext)
 
PCSC_API LONG SCardIsValidContext (SCARDCONTEXT hContext)
 
PCSC_API LONG SCardConnect (SCARDCONTEXT hContext, LPCSTR szReader, DWORD dwShareMode, DWORD dwPreferredProtocols, LPSCARDHANDLE phCard, LPDWORD pdwActiveProtocol)
 
PCSC_API LONG SCardReconnect (SCARDHANDLE hCard, DWORD dwShareMode, DWORD dwPreferredProtocols, DWORD dwInitialization, LPDWORD pdwActiveProtocol)
 
PCSC_API LONG SCardDisconnect (SCARDHANDLE hCard, DWORD dwDisposition)
 
PCSC_API LONG SCardBeginTransaction (SCARDHANDLE hCard)
 
PCSC_API LONG SCardEndTransaction (SCARDHANDLE hCard, DWORD dwDisposition)
 
PCSC_API LONG SCardStatus (SCARDHANDLE hCard, LPSTR mszReaderName, LPDWORD pcchReaderLen, LPDWORD pdwState, LPDWORD pdwProtocol, LPBYTE pbAtr, LPDWORD pcbAtrLen)
 
PCSC_API LONG SCardGetStatusChange (SCARDCONTEXT hContext, DWORD dwTimeout, SCARD_READERSTATE *rgReaderStates, DWORD cReaders)
 
PCSC_API LONG SCardControl (SCARDHANDLE hCard, DWORD dwControlCode, LPCVOID pbSendBuffer, DWORD cbSendLength, LPVOID pbRecvBuffer, DWORD cbRecvLength, LPDWORD lpBytesReturned)
 
PCSC_API LONG SCardTransmit (SCARDHANDLE hCard, const SCARD_IO_REQUEST *pioSendPci, LPCBYTE pbSendBuffer, DWORD cbSendLength, SCARD_IO_REQUEST *pioRecvPci, LPBYTE pbRecvBuffer, LPDWORD pcbRecvLength)
 
PCSC_API LONG SCardListReaderGroups (SCARDCONTEXT hContext, LPSTR mszGroups, LPDWORD pcchGroups)
 
PCSC_API LONG SCardListReaders (SCARDCONTEXT hContext, LPCSTR mszGroups, LPSTR mszReaders, LPDWORD pcchReaders)
 
PCSC_API LONG SCardFreeMemory (SCARDCONTEXT hContext, LPCVOID pvMem)
 
PCSC_API LONG SCardCancel (SCARDCONTEXT hContext)
 
PCSC_API LONG SCardGetAttrib (SCARDHANDLE hCard, DWORD dwAttrId, LPBYTE pbAttr, LPDWORD pcbAttrLen)
 
PCSC_API LONG SCardSetAttrib (SCARDHANDLE hCard, DWORD dwAttrId, LPCBYTE pbAttr, DWORD cbAttrLen)
 

Variables

struct { 
 
redirect 
 
static void * Lib_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.

◆ DLSYM_DECLARE

#define DLSYM_DECLARE ( symbol)     typeof(symbol)* symbol

Definition at line 53 of file libredirect.c.

◆ DLSYM_SET_VALUE

#define DLSYM_SET_VALUE ( symbol)     .symbol = (typeof(symbol)(*))internal_error

Definition at line 55 of file libredirect.c.

Function Documentation

◆ internal_error()

static LONG internal_error ( void )
static

Definition at line 59 of file libredirect.c.

◆ load_lib()

static LONG load_lib ( void )
static

Definition at line 128 of file libredirect.c.

◆ log_line()

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

Definition at line 113 of file libredirect.c.

◆ SCardBeginTransaction()

PCSC_API LONG SCardBeginTransaction ( SCARDHANDLE hCard)

Definition at line 237 of file libredirect.c.

◆ SCardCancel()

PCSC_API LONG SCardCancel ( SCARDCONTEXT hContext)

Definition at line 314 of file libredirect.c.

◆ SCardConnect()

PCSC_API LONG SCardConnect ( SCARDCONTEXT hContext,
LPCSTR szReader,
DWORD dwShareMode,
DWORD dwPreferredProtocols,
LPSCARDHANDLE phCard,
LPDWORD pdwActiveProtocol )

Definition at line 210 of file libredirect.c.

◆ SCardControl()

PCSC_API LONG SCardControl ( SCARDHANDLE hCard,
DWORD dwControlCode,
LPCVOID pbSendBuffer,
DWORD cbSendLength,
LPVOID pbRecvBuffer,
DWORD cbRecvLength,
LPDWORD lpBytesReturned )

Definition at line 269 of file libredirect.c.

◆ SCardDisconnect()

PCSC_API LONG SCardDisconnect ( SCARDHANDLE hCard,
DWORD dwDisposition )

Definition at line 231 of file libredirect.c.

◆ SCardEndTransaction()

PCSC_API LONG SCardEndTransaction ( SCARDHANDLE hCard,
DWORD dwDisposition )

Definition at line 242 of file libredirect.c.

◆ SCardEstablishContext()

PCSC_API LONG SCardEstablishContext ( DWORD dwScope,
LPCVOID pvReserved1,
LPCVOID pvReserved2,
LPSCARDCONTEXT phContext )

Definition at line 178 of file libredirect.c.

◆ SCardFreeMemory()

PCSC_API LONG SCardFreeMemory ( SCARDCONTEXT hContext,
LPCVOID pvMem )

Definition at line 308 of file libredirect.c.

◆ SCardGetAttrib()

PCSC_API LONG SCardGetAttrib ( SCARDHANDLE hCard,
DWORD dwAttrId,
LPBYTE pbAttr,
LPDWORD pcbAttrLen )

Definition at line 319 of file libredirect.c.

◆ SCardGetStatusChange()

PCSC_API LONG SCardGetStatusChange ( SCARDCONTEXT hContext,
DWORD dwTimeout,
SCARD_READERSTATE * rgReaderStates,
DWORD cReaders )

Definition at line 260 of file libredirect.c.

◆ SCardIsValidContext()

PCSC_API LONG SCardIsValidContext ( SCARDCONTEXT hContext)

Definition at line 205 of file libredirect.c.

◆ SCardListReaderGroups()

PCSC_API LONG SCardListReaderGroups ( SCARDCONTEXT hContext,
LPSTR mszGroups,
LPDWORD pcchGroups )

Definition at line 293 of file libredirect.c.

◆ SCardListReaders()

PCSC_API LONG SCardListReaders ( SCARDCONTEXT hContext,
LPCSTR mszGroups,
LPSTR mszReaders,
LPDWORD pcchReaders )

Definition at line 300 of file libredirect.c.

◆ SCardReconnect()

PCSC_API LONG SCardReconnect ( SCARDHANDLE hCard,
DWORD dwShareMode,
DWORD dwPreferredProtocols,
DWORD dwInitialization,
LPDWORD pdwActiveProtocol )

Definition at line 221 of file libredirect.c.

◆ SCardReleaseContext()

PCSC_API LONG SCardReleaseContext ( SCARDCONTEXT hContext)

Definition at line 200 of file libredirect.c.

◆ SCardSetAttrib()

PCSC_API LONG SCardSetAttrib ( SCARDHANDLE hCard,
DWORD dwAttrId,
LPCBYTE pbAttr,
DWORD cbAttrLen )

Definition at line 327 of file libredirect.c.

◆ SCardStatus()

PCSC_API LONG SCardStatus ( SCARDHANDLE hCard,
LPSTR mszReaderName,
LPDWORD pcchReaderLen,
LPDWORD pdwState,
LPDWORD pdwProtocol,
LPBYTE pbAtr,
LPDWORD pcbAtrLen )

Definition at line 248 of file libredirect.c.

◆ SCardTransmit()

PCSC_API LONG SCardTransmit ( SCARDHANDLE hCard,
const SCARD_IO_REQUEST * pioSendPci,
LPCBYTE pbSendBuffer,
DWORD cbSendLength,
SCARD_IO_REQUEST * pioRecvPci,
LPBYTE pbRecvBuffer,
LPDWORD pcbRecvLength )

Definition at line 281 of file libredirect.c.

Variable Documentation

◆ g_rgSCardRawPci

PCSC_API const SCARD_IO_REQUEST g_rgSCardRawPci = { SCARD_PROTOCOL_RAW, sizeof(SCARD_IO_REQUEST) }

Protocol Control Information for raw access.

Definition at line 340 of file libredirect.c.

◆ g_rgSCardT0Pci

PCSC_API const SCARD_IO_REQUEST g_rgSCardT0Pci = { SCARD_PROTOCOL_T0, sizeof(SCARD_IO_REQUEST) }

Protocol Control Information for T=0.

Definition at line 336 of file libredirect.c.

◆ g_rgSCardT1Pci

PCSC_API const SCARD_IO_REQUEST g_rgSCardT1Pci = { SCARD_PROTOCOL_T1, sizeof(SCARD_IO_REQUEST) }

Protocol Control Information for T=1.

Definition at line 338 of file libredirect.c.

◆ Lib_handle

void* Lib_handle = NULL
static

Definition at line 110 of file libredirect.c.

◆ [struct]

struct { ... } redirect
Initial value:
= {
DLSYM_SET_VALUE(SCardEstablishContext),
DLSYM_SET_VALUE(SCardReleaseContext),
DLSYM_SET_VALUE(SCardIsValidContext),
DLSYM_SET_VALUE(SCardConnect),
DLSYM_SET_VALUE(SCardReconnect),
DLSYM_SET_VALUE(SCardDisconnect),
DLSYM_SET_VALUE(SCardBeginTransaction),
DLSYM_SET_VALUE(SCardEndTransaction),
DLSYM_SET_VALUE(SCardStatus),
DLSYM_SET_VALUE(SCardGetStatusChange),
DLSYM_SET_VALUE(SCardControl),
DLSYM_SET_VALUE(SCardTransmit),
DLSYM_SET_VALUE(SCardListReaderGroups),
DLSYM_SET_VALUE(SCardListReaders),
DLSYM_SET_VALUE(SCardFreeMemory),
DLSYM_SET_VALUE(SCardCancel),
DLSYM_SET_VALUE(SCardGetAttrib),
}