53#define DLSYM_DECLARE(symbol) \
54 typeof(symbol)* symbol
55#define DLSYM_SET_VALUE(symbol) \
56 .symbol = (typeof(symbol)(*))internal_error
59static LONG internal_error(
void)
64#pragma GCC diagnostic push
65#pragma GCC diagnostic ignored "-Wcast-function-type"
69 DLSYM_DECLARE(SCardEstablishContext);
70 DLSYM_DECLARE(SCardReleaseContext);
71 DLSYM_DECLARE(SCardIsValidContext);
72 DLSYM_DECLARE(SCardConnect);
73 DLSYM_DECLARE(SCardReconnect);
74 DLSYM_DECLARE(SCardDisconnect);
75 DLSYM_DECLARE(SCardBeginTransaction);
76 DLSYM_DECLARE(SCardEndTransaction);
77 DLSYM_DECLARE(SCardStatus);
78 DLSYM_DECLARE(SCardGetStatusChange);
79 DLSYM_DECLARE(SCardControl);
80 DLSYM_DECLARE(SCardTransmit);
81 DLSYM_DECLARE(SCardListReaderGroups);
82 DLSYM_DECLARE(SCardListReaders);
83 DLSYM_DECLARE(SCardFreeMemory);
84 DLSYM_DECLARE(SCardCancel);
85 DLSYM_DECLARE(SCardGetAttrib);
86 DLSYM_DECLARE(SCardSetAttrib);
89 DLSYM_SET_VALUE(SCardEstablishContext),
90 DLSYM_SET_VALUE(SCardReleaseContext),
91 DLSYM_SET_VALUE(SCardIsValidContext),
92 DLSYM_SET_VALUE(SCardConnect),
93 DLSYM_SET_VALUE(SCardReconnect),
94 DLSYM_SET_VALUE(SCardDisconnect),
95 DLSYM_SET_VALUE(SCardBeginTransaction),
96 DLSYM_SET_VALUE(SCardEndTransaction),
97 DLSYM_SET_VALUE(SCardStatus),
98 DLSYM_SET_VALUE(SCardGetStatusChange),
99 DLSYM_SET_VALUE(SCardControl),
100 DLSYM_SET_VALUE(SCardTransmit),
101 DLSYM_SET_VALUE(SCardListReaderGroups),
102 DLSYM_SET_VALUE(SCardListReaders),
103 DLSYM_SET_VALUE(SCardFreeMemory),
104 DLSYM_SET_VALUE(SCardCancel),
105 DLSYM_SET_VALUE(SCardGetAttrib),
106 DLSYM_SET_VALUE(SCardSetAttrib)
108#pragma GCC diagnostic pop
110static void *Lib_handle = NULL;
113static void log_line(
const char *fmt, ...)
118 vfprintf(stderr, fmt, args);
119 fprintf(stderr,
"\n");
123static void log_line(
const char *fmt, ...)
128static LONG load_lib(
void)
130#define LIBPCSC "libpcsclite_real.so.1"
139 Lib_handle = dlopen(lib, RTLD_LAZY);
140 if (NULL == Lib_handle)
142 log_line(
"loading \"%s\" failed: %s", lib, dlerror());
146#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)
148 if (SCardEstablishContext == dlsym(Lib_handle,
"SCardEstablishContext"))
150 log_line(
"Symbols dlsym error");
154 get_symbol(SCardEstablishContext);
155 get_symbol(SCardReleaseContext);
156 get_symbol(SCardIsValidContext);
157 get_symbol(SCardConnect);
158 get_symbol(SCardReconnect);
159 get_symbol(SCardDisconnect);
160 get_symbol(SCardBeginTransaction);
161 get_symbol(SCardEndTransaction);
162 get_symbol(SCardStatus);
163 get_symbol(SCardGetStatusChange);
164 get_symbol(SCardControl);
165 get_symbol(SCardTransmit);
166 get_symbol(SCardListReaderGroups);
167 get_symbol(SCardListReaders);
168 get_symbol(SCardFreeMemory);
169 get_symbol(SCardCancel);
170 get_symbol(SCardGetAttrib);
171 get_symbol(SCardSetAttrib);
178PCSC_API LONG SCardEstablishContext(DWORD dwScope,
181 LPSCARDCONTEXT phContext)
196 return redirect.SCardEstablishContext(dwScope, pvReserved1, pvReserved2,
202 return redirect.SCardReleaseContext(hContext);
207 return redirect.SCardIsValidContext(hContext);
213 DWORD dwPreferredProtocols,
214 LPSCARDHANDLE phCard,
215 LPDWORD pdwActiveProtocol)
217 return redirect.SCardConnect(hContext, szReader, dwShareMode,
218 dwPreferredProtocols, phCard, pdwActiveProtocol);
223 DWORD dwPreferredProtocols,
224 DWORD dwInitialization,
225 LPDWORD pdwActiveProtocol)
227 return redirect.SCardReconnect(hCard, dwShareMode, dwPreferredProtocols,
228 dwInitialization, pdwActiveProtocol);
234 return redirect.SCardDisconnect(hCard, dwDisposition);
237PCSC_API LONG SCardBeginTransaction(
SCARDHANDLE hCard)
239 return redirect.SCardBeginTransaction(hCard);
242PCSC_API LONG SCardEndTransaction(
SCARDHANDLE hCard,
245 return redirect.SCardEndTransaction(hCard, dwDisposition);
250 LPDWORD pcchReaderLen,
256 return redirect.SCardStatus(hCard, mszReaderName, pcchReaderLen, pdwState,
257 pdwProtocol, pbAtr, pcbAtrLen);
260PCSC_API LONG SCardGetStatusChange(
SCARDCONTEXT hContext,
265 return redirect.SCardGetStatusChange(hContext, dwTimeout, rgReaderStates,
271 LPCVOID pbSendBuffer,
275 LPDWORD lpBytesReturned)
277 return redirect.SCardControl(hCard, dwControlCode, pbSendBuffer, cbSendLength,
278 pbRecvBuffer, cbRecvLength, lpBytesReturned);
283 LPCBYTE pbSendBuffer,
287 LPDWORD pcbRecvLength)
289 return redirect.SCardTransmit(hCard, pioSendPci, pbSendBuffer, cbSendLength,
290 pioRecvPci, pbRecvBuffer, pcbRecvLength);
293PCSC_API LONG SCardListReaderGroups(
SCARDCONTEXT hContext,
297 return redirect.SCardListReaderGroups(hContext, mszGroups, pcchGroups);
305 return redirect.SCardListReaders(hContext, mszGroups, mszReaders, pcchReaders);
311 return redirect.SCardFreeMemory(hContext, pvMem);
316 return redirect.SCardCancel(hContext);
324 return redirect.SCardGetAttrib(hCard, dwAttrId, pbAttr, pcbAttrLen);
332 return redirect.SCardSetAttrib(hCard, dwAttrId, pbAttr, cbAttrLen);
#define SCARD_F_INTERNAL_ERROR
An internal consistency check failed.
#define SCARD_S_SUCCESS
No error was encountered.
PCSC_API const SCARD_IO_REQUEST g_rgSCardRawPci
Protocol Control Information for raw access.
PCSC_API const SCARD_IO_REQUEST g_rgSCardT1Pci
Protocol Control Information for T=1.
PCSC_API const SCARD_IO_REQUEST g_rgSCardT0Pci
Protocol Control Information for T=0.
LONG SCARDCONTEXT
hContext returned by SCardEstablishContext()
#define SCARD_PROTOCOL_T1
T=1 active protocol.
#define SCARD_PROTOCOL_T0
T=0 active protocol.
#define SCARD_PROTOCOL_RAW
Raw active protocol.
LONG SCARDHANDLE
hCard returned by SCardConnect()
Protocol Control Information (PCI)
This handles abstract system level calls.
const char * SYS_GetEnv(const char *name)
(More) secure version of getenv(3)
This handles smart card reader communications.