FreeRDP
smartcard.c
1 
22 #include <winpr/config.h>
23 
24 #include <winpr/crt.h>
25 #include <winpr/library.h>
26 #include <winpr/smartcard.h>
27 #include <winpr/synch.h>
28 #include <winpr/wlog.h>
29 #include <winpr/assert.h>
30 
31 #include "../log.h"
32 
33 #include "smartcard.h"
34 
35 #if defined(WITH_SMARTCARD_INSPECT)
36 #include "smartcard_inspect.h"
37 #endif
38 
39 static INIT_ONCE g_Initialized = INIT_ONCE_STATIC_INIT;
40 static const SCardApiFunctionTable* g_SCardApi = NULL;
41 
42 #define TAG WINPR_TAG("smartcard")
43 
44 #define xstr(s) str(s)
45 #define str(s) #s
46 
47 #define SCARDAPI_STUB_CALL_LONG(_name, ...) \
48  InitOnceExecuteOnce(&g_Initialized, InitializeSCardApiStubs, NULL, NULL); \
49  if (!g_SCardApi || !g_SCardApi->pfn##_name) \
50  { \
51  WLog_DBG(TAG, "Missing function pointer g_SCardApi=%p->" xstr(pfn##_name) "=%p", \
52  g_SCardApi, g_SCardApi ? g_SCardApi->pfn##_name : NULL); \
53  return SCARD_E_NO_SERVICE; \
54  } \
55  return g_SCardApi->pfn##_name(__VA_ARGS__)
56 
57 #define SCARDAPI_STUB_CALL_HANDLE(_name) \
58  InitOnceExecuteOnce(&g_Initialized, InitializeSCardApiStubs, NULL, NULL); \
59  if (!g_SCardApi || !g_SCardApi->pfn##_name) \
60  { \
61  WLog_DBG(TAG, "Missing function pointer g_SCardApi=%p->" xstr(pfn##_name) "=%p", \
62  g_SCardApi, g_SCardApi ? g_SCardApi->pfn##_name : NULL); \
63  return NULL; \
64  } \
65  return g_SCardApi->pfn##_name()
66 
67 #define SCARDAPI_STUB_CALL_VOID(_name) \
68  InitOnceExecuteOnce(&g_Initialized, InitializeSCardApiStubs, NULL, NULL); \
69  if (!g_SCardApi || !g_SCardApi->pfn##_name) \
70  { \
71  WLog_DBG(TAG, "Missing function pointer g_SCardApi=%p->" xstr(pfn##_name) "=%p", \
72  g_SCardApi, g_SCardApi ? g_SCardApi->pfn##_name : NULL); \
73  return; \
74  } \
75  g_SCardApi->pfn##_name()
76 
81 const SCARD_IO_REQUEST g_rgSCardT0Pci = { SCARD_PROTOCOL_T0, 8 };
82 const SCARD_IO_REQUEST g_rgSCardT1Pci = { SCARD_PROTOCOL_T1, 8 };
83 const SCARD_IO_REQUEST g_rgSCardRawPci = { SCARD_PROTOCOL_RAW, 8 };
84 
85 static BOOL CALLBACK InitializeSCardApiStubs(PINIT_ONCE once, PVOID param, PVOID* context)
86 {
87 #ifdef _WIN32
88  if (Windows_InitializeSCardApi() >= 0)
89  g_SCardApi = Windows_GetSCardApiFunctionTable();
90 #else
91 #if defined(WITH_SMARTCARD_PCSC)
92  if (PCSC_InitializeSCardApi() >= 0)
93  g_SCardApi = PCSC_GetSCardApiFunctionTable();
94 #endif
95 #endif
96 
97 #if defined(WITH_SMARTCARD_INSPECT)
98  g_SCardApi = Inspect_RegisterSCardApi(g_SCardApi);
99 #endif
100  return TRUE;
101 }
102 
103 WINSCARDAPI LONG WINAPI SCardEstablishContext(DWORD dwScope, LPCVOID pvReserved1,
104  LPCVOID pvReserved2, LPSCARDCONTEXT phContext)
105 {
106  SCARDAPI_STUB_CALL_LONG(SCardEstablishContext, dwScope, pvReserved1, pvReserved2, phContext);
107 }
108 
109 WINSCARDAPI LONG WINAPI SCardReleaseContext(SCARDCONTEXT hContext)
110 {
111  SCARDAPI_STUB_CALL_LONG(SCardReleaseContext, hContext);
112 }
113 
114 WINSCARDAPI LONG WINAPI SCardIsValidContext(SCARDCONTEXT hContext)
115 {
116  SCARDAPI_STUB_CALL_LONG(SCardIsValidContext, hContext);
117 }
118 
119 WINSCARDAPI LONG WINAPI SCardListReaderGroupsA(SCARDCONTEXT hContext, LPSTR mszGroups,
120  LPDWORD pcchGroups)
121 {
122  SCARDAPI_STUB_CALL_LONG(SCardListReaderGroupsA, hContext, mszGroups, pcchGroups);
123 }
124 
125 WINSCARDAPI LONG WINAPI SCardListReaderGroupsW(SCARDCONTEXT hContext, LPWSTR mszGroups,
126  LPDWORD pcchGroups)
127 {
128  SCARDAPI_STUB_CALL_LONG(SCardListReaderGroupsW, hContext, mszGroups, pcchGroups);
129 }
130 
131 WINSCARDAPI LONG WINAPI SCardListReadersA(SCARDCONTEXT hContext, LPCSTR mszGroups, LPSTR mszReaders,
132  LPDWORD pcchReaders)
133 {
134  SCARDAPI_STUB_CALL_LONG(SCardListReadersA, hContext, mszGroups, mszReaders, pcchReaders);
135 }
136 
137 WINSCARDAPI LONG WINAPI SCardListReadersW(SCARDCONTEXT hContext, LPCWSTR mszGroups,
138  LPWSTR mszReaders, LPDWORD pcchReaders)
139 {
140  SCARDAPI_STUB_CALL_LONG(SCardListReadersW, hContext, mszGroups, mszReaders, pcchReaders);
141 }
142 
143 WINSCARDAPI LONG WINAPI SCardListCardsA(SCARDCONTEXT hContext, LPCBYTE pbAtr,
144  LPCGUID rgquidInterfaces, DWORD cguidInterfaceCount,
145  CHAR* mszCards, LPDWORD pcchCards)
146 {
147  SCARDAPI_STUB_CALL_LONG(SCardListCardsA, hContext, pbAtr, rgquidInterfaces, cguidInterfaceCount,
148  mszCards, pcchCards);
149 }
150 
151 WINSCARDAPI LONG WINAPI SCardListCardsW(SCARDCONTEXT hContext, LPCBYTE pbAtr,
152  LPCGUID rgquidInterfaces, DWORD cguidInterfaceCount,
153  WCHAR* mszCards, LPDWORD pcchCards)
154 {
155  SCARDAPI_STUB_CALL_LONG(SCardListCardsW, hContext, pbAtr, rgquidInterfaces, cguidInterfaceCount,
156  mszCards, pcchCards);
157 }
158 
159 WINSCARDAPI LONG WINAPI SCardListInterfacesA(SCARDCONTEXT hContext, LPCSTR szCard,
160  LPGUID pguidInterfaces, LPDWORD pcguidInterfaces)
161 {
162  SCARDAPI_STUB_CALL_LONG(SCardListInterfacesA, hContext, szCard, pguidInterfaces,
163  pcguidInterfaces);
164 }
165 
166 WINSCARDAPI LONG WINAPI SCardListInterfacesW(SCARDCONTEXT hContext, LPCWSTR szCard,
167  LPGUID pguidInterfaces, LPDWORD pcguidInterfaces)
168 {
169  SCARDAPI_STUB_CALL_LONG(SCardListInterfacesW, hContext, szCard, pguidInterfaces,
170  pcguidInterfaces);
171 }
172 
173 WINSCARDAPI LONG WINAPI SCardGetProviderIdA(SCARDCONTEXT hContext, LPCSTR szCard,
174  LPGUID pguidProviderId)
175 {
176  SCARDAPI_STUB_CALL_LONG(SCardGetProviderIdA, hContext, szCard, pguidProviderId);
177 }
178 
179 WINSCARDAPI LONG WINAPI SCardGetProviderIdW(SCARDCONTEXT hContext, LPCWSTR szCard,
180  LPGUID pguidProviderId)
181 {
182  SCARDAPI_STUB_CALL_LONG(SCardGetProviderIdW, hContext, szCard, pguidProviderId);
183 }
184 
185 WINSCARDAPI LONG WINAPI SCardGetCardTypeProviderNameA(SCARDCONTEXT hContext, LPCSTR szCardName,
186  DWORD dwProviderId, CHAR* szProvider,
187  LPDWORD pcchProvider)
188 {
189  SCARDAPI_STUB_CALL_LONG(SCardGetCardTypeProviderNameA, hContext, szCardName, dwProviderId,
190  szProvider, pcchProvider);
191 }
192 
193 WINSCARDAPI LONG WINAPI SCardGetCardTypeProviderNameW(SCARDCONTEXT hContext, LPCWSTR szCardName,
194  DWORD dwProviderId, WCHAR* szProvider,
195  LPDWORD pcchProvider)
196 {
197  SCARDAPI_STUB_CALL_LONG(SCardGetCardTypeProviderNameW, hContext, szCardName, dwProviderId,
198  szProvider, pcchProvider);
199 }
200 
201 WINSCARDAPI LONG WINAPI SCardIntroduceReaderGroupA(SCARDCONTEXT hContext, LPCSTR szGroupName)
202 {
203  SCARDAPI_STUB_CALL_LONG(SCardIntroduceReaderGroupA, hContext, szGroupName);
204 }
205 
206 WINSCARDAPI LONG WINAPI SCardIntroduceReaderGroupW(SCARDCONTEXT hContext, LPCWSTR szGroupName)
207 {
208  SCARDAPI_STUB_CALL_LONG(SCardIntroduceReaderGroupW, hContext, szGroupName);
209 }
210 
211 WINSCARDAPI LONG WINAPI SCardForgetReaderGroupA(SCARDCONTEXT hContext, LPCSTR szGroupName)
212 {
213  SCARDAPI_STUB_CALL_LONG(SCardForgetReaderGroupA, hContext, szGroupName);
214 }
215 
216 WINSCARDAPI LONG WINAPI SCardForgetReaderGroupW(SCARDCONTEXT hContext, LPCWSTR szGroupName)
217 {
218  SCARDAPI_STUB_CALL_LONG(SCardForgetReaderGroupW, hContext, szGroupName);
219 }
220 
221 WINSCARDAPI LONG WINAPI SCardIntroduceReaderA(SCARDCONTEXT hContext, LPCSTR szReaderName,
222  LPCSTR szDeviceName)
223 {
224  SCARDAPI_STUB_CALL_LONG(SCardIntroduceReaderA, hContext, szReaderName, szDeviceName);
225 }
226 
227 WINSCARDAPI LONG WINAPI SCardIntroduceReaderW(SCARDCONTEXT hContext, LPCWSTR szReaderName,
228  LPCWSTR szDeviceName)
229 {
230  SCARDAPI_STUB_CALL_LONG(SCardIntroduceReaderW, hContext, szReaderName, szDeviceName);
231 }
232 
233 WINSCARDAPI LONG WINAPI SCardForgetReaderA(SCARDCONTEXT hContext, LPCSTR szReaderName)
234 {
235  SCARDAPI_STUB_CALL_LONG(SCardForgetReaderA, hContext, szReaderName);
236 }
237 
238 WINSCARDAPI LONG WINAPI SCardForgetReaderW(SCARDCONTEXT hContext, LPCWSTR szReaderName)
239 {
240  SCARDAPI_STUB_CALL_LONG(SCardForgetReaderW, hContext, szReaderName);
241 }
242 
243 WINSCARDAPI LONG WINAPI SCardAddReaderToGroupA(SCARDCONTEXT hContext, LPCSTR szReaderName,
244  LPCSTR szGroupName)
245 {
246  SCARDAPI_STUB_CALL_LONG(SCardAddReaderToGroupA, hContext, szReaderName, szGroupName);
247 }
248 
249 WINSCARDAPI LONG WINAPI SCardAddReaderToGroupW(SCARDCONTEXT hContext, LPCWSTR szReaderName,
250  LPCWSTR szGroupName)
251 {
252  SCARDAPI_STUB_CALL_LONG(SCardAddReaderToGroupW, hContext, szReaderName, szGroupName);
253 }
254 
255 WINSCARDAPI LONG WINAPI SCardRemoveReaderFromGroupA(SCARDCONTEXT hContext, LPCSTR szReaderName,
256  LPCSTR szGroupName)
257 {
258  SCARDAPI_STUB_CALL_LONG(SCardRemoveReaderFromGroupA, hContext, szReaderName, szGroupName);
259 }
260 
261 WINSCARDAPI LONG WINAPI SCardRemoveReaderFromGroupW(SCARDCONTEXT hContext, LPCWSTR szReaderName,
262  LPCWSTR szGroupName)
263 {
264  SCARDAPI_STUB_CALL_LONG(SCardRemoveReaderFromGroupW, hContext, szReaderName, szGroupName);
265 }
266 
267 WINSCARDAPI LONG WINAPI SCardIntroduceCardTypeA(SCARDCONTEXT hContext, LPCSTR szCardName,
268  LPCGUID pguidPrimaryProvider,
269  LPCGUID rgguidInterfaces, DWORD dwInterfaceCount,
270  LPCBYTE pbAtr, LPCBYTE pbAtrMask, DWORD cbAtrLen)
271 {
272  SCARDAPI_STUB_CALL_LONG(SCardIntroduceCardTypeA, hContext, szCardName, pguidPrimaryProvider,
273  rgguidInterfaces, dwInterfaceCount, pbAtr, pbAtrMask, cbAtrLen);
274 }
275 
276 WINSCARDAPI LONG WINAPI SCardIntroduceCardTypeW(SCARDCONTEXT hContext, LPCWSTR szCardName,
277  LPCGUID pguidPrimaryProvider,
278  LPCGUID rgguidInterfaces, DWORD dwInterfaceCount,
279  LPCBYTE pbAtr, LPCBYTE pbAtrMask, DWORD cbAtrLen)
280 {
281  SCARDAPI_STUB_CALL_LONG(SCardIntroduceCardTypeW, hContext, szCardName, pguidPrimaryProvider,
282  rgguidInterfaces, dwInterfaceCount, pbAtr, pbAtrMask, cbAtrLen);
283 }
284 
285 WINSCARDAPI LONG WINAPI SCardSetCardTypeProviderNameA(SCARDCONTEXT hContext, LPCSTR szCardName,
286  DWORD dwProviderId, LPCSTR szProvider)
287 {
288  SCARDAPI_STUB_CALL_LONG(SCardSetCardTypeProviderNameA, hContext, szCardName, dwProviderId,
289  szProvider);
290 }
291 
292 WINSCARDAPI LONG WINAPI SCardSetCardTypeProviderNameW(SCARDCONTEXT hContext, LPCWSTR szCardName,
293  DWORD dwProviderId, LPCWSTR szProvider)
294 {
295  SCARDAPI_STUB_CALL_LONG(SCardSetCardTypeProviderNameW, hContext, szCardName, dwProviderId,
296  szProvider);
297 }
298 
299 WINSCARDAPI LONG WINAPI SCardForgetCardTypeA(SCARDCONTEXT hContext, LPCSTR szCardName)
300 {
301  SCARDAPI_STUB_CALL_LONG(SCardForgetCardTypeA, hContext, szCardName);
302 }
303 
304 WINSCARDAPI LONG WINAPI SCardForgetCardTypeW(SCARDCONTEXT hContext, LPCWSTR szCardName)
305 {
306  SCARDAPI_STUB_CALL_LONG(SCardForgetCardTypeW, hContext, szCardName);
307 }
308 
309 WINSCARDAPI LONG WINAPI SCardFreeMemory(SCARDCONTEXT hContext, LPVOID pvMem)
310 {
311  SCARDAPI_STUB_CALL_LONG(SCardFreeMemory, hContext, pvMem);
312 }
313 
314 WINSCARDAPI HANDLE WINAPI SCardAccessStartedEvent(void)
315 {
316  SCARDAPI_STUB_CALL_HANDLE(SCardAccessStartedEvent);
317 }
318 
319 WINSCARDAPI void WINAPI SCardReleaseStartedEvent(void)
320 {
321  SCARDAPI_STUB_CALL_VOID(SCardReleaseStartedEvent);
322 }
323 
324 WINSCARDAPI LONG WINAPI SCardLocateCardsA(SCARDCONTEXT hContext, LPCSTR mszCards,
325  LPSCARD_READERSTATEA rgReaderStates, DWORD cReaders)
326 {
327  SCARDAPI_STUB_CALL_LONG(SCardLocateCardsA, hContext, mszCards, rgReaderStates, cReaders);
328 }
329 
330 WINSCARDAPI LONG WINAPI SCardLocateCardsW(SCARDCONTEXT hContext, LPCWSTR mszCards,
331  LPSCARD_READERSTATEW rgReaderStates, DWORD cReaders)
332 {
333  SCARDAPI_STUB_CALL_LONG(SCardLocateCardsW, hContext, mszCards, rgReaderStates, cReaders);
334 }
335 
336 WINSCARDAPI LONG WINAPI SCardLocateCardsByATRA(SCARDCONTEXT hContext, LPSCARD_ATRMASK rgAtrMasks,
337  DWORD cAtrs, LPSCARD_READERSTATEA rgReaderStates,
338  DWORD cReaders)
339 {
340  SCARDAPI_STUB_CALL_LONG(SCardLocateCardsByATRA, hContext, rgAtrMasks, cAtrs, rgReaderStates,
341  cReaders);
342 }
343 
344 WINSCARDAPI LONG WINAPI SCardLocateCardsByATRW(SCARDCONTEXT hContext, LPSCARD_ATRMASK rgAtrMasks,
345  DWORD cAtrs, LPSCARD_READERSTATEW rgReaderStates,
346  DWORD cReaders)
347 {
348  SCARDAPI_STUB_CALL_LONG(SCardLocateCardsByATRW, hContext, rgAtrMasks, cAtrs, rgReaderStates,
349  cReaders);
350 }
351 
352 WINSCARDAPI LONG WINAPI SCardGetStatusChangeA(SCARDCONTEXT hContext, DWORD dwTimeout,
353  LPSCARD_READERSTATEA rgReaderStates, DWORD cReaders)
354 {
355  SCARDAPI_STUB_CALL_LONG(SCardGetStatusChangeA, hContext, dwTimeout, rgReaderStates, cReaders);
356 }
357 
358 WINSCARDAPI LONG WINAPI SCardGetStatusChangeW(SCARDCONTEXT hContext, DWORD dwTimeout,
359  LPSCARD_READERSTATEW rgReaderStates, DWORD cReaders)
360 {
361  SCARDAPI_STUB_CALL_LONG(SCardGetStatusChangeW, hContext, dwTimeout, rgReaderStates, cReaders);
362 }
363 
364 WINSCARDAPI LONG WINAPI SCardCancel(SCARDCONTEXT hContext)
365 {
366  SCARDAPI_STUB_CALL_LONG(SCardCancel, hContext);
367 }
368 
369 WINSCARDAPI LONG WINAPI SCardConnectA(SCARDCONTEXT hContext, LPCSTR szReader, DWORD dwShareMode,
370  DWORD dwPreferredProtocols, LPSCARDHANDLE phCard,
371  LPDWORD pdwActiveProtocol)
372 {
373  SCARDAPI_STUB_CALL_LONG(SCardConnectA, hContext, szReader, dwShareMode, dwPreferredProtocols,
374  phCard, pdwActiveProtocol);
375 }
376 
377 WINSCARDAPI LONG WINAPI SCardConnectW(SCARDCONTEXT hContext, LPCWSTR szReader, DWORD dwShareMode,
378  DWORD dwPreferredProtocols, LPSCARDHANDLE phCard,
379  LPDWORD pdwActiveProtocol)
380 {
381  SCARDAPI_STUB_CALL_LONG(SCardConnectW, hContext, szReader, dwShareMode, dwPreferredProtocols,
382  phCard, pdwActiveProtocol);
383 }
384 
385 WINSCARDAPI LONG WINAPI SCardReconnect(SCARDHANDLE hCard, DWORD dwShareMode,
386  DWORD dwPreferredProtocols, DWORD dwInitialization,
387  LPDWORD pdwActiveProtocol)
388 {
389  SCARDAPI_STUB_CALL_LONG(SCardReconnect, hCard, dwShareMode, dwPreferredProtocols,
390  dwInitialization, pdwActiveProtocol);
391 }
392 
393 WINSCARDAPI LONG WINAPI SCardDisconnect(SCARDHANDLE hCard, DWORD dwDisposition)
394 {
395  SCARDAPI_STUB_CALL_LONG(SCardDisconnect, hCard, dwDisposition);
396 }
397 
398 WINSCARDAPI LONG WINAPI SCardBeginTransaction(SCARDHANDLE hCard)
399 {
400  SCARDAPI_STUB_CALL_LONG(SCardBeginTransaction, hCard);
401 }
402 
403 WINSCARDAPI LONG WINAPI SCardEndTransaction(SCARDHANDLE hCard, DWORD dwDisposition)
404 {
405  SCARDAPI_STUB_CALL_LONG(SCardEndTransaction, hCard, dwDisposition);
406 }
407 
408 WINSCARDAPI LONG WINAPI SCardCancelTransaction(SCARDHANDLE hCard)
409 {
410  SCARDAPI_STUB_CALL_LONG(SCardCancelTransaction, hCard);
411 }
412 
413 WINSCARDAPI LONG WINAPI SCardState(SCARDHANDLE hCard, LPDWORD pdwState, LPDWORD pdwProtocol,
414  LPBYTE pbAtr, LPDWORD pcbAtrLen)
415 {
416  SCARDAPI_STUB_CALL_LONG(SCardState, hCard, pdwState, pdwProtocol, pbAtr, pcbAtrLen);
417 }
418 
419 WINSCARDAPI LONG WINAPI SCardStatusA(SCARDHANDLE hCard, LPSTR mszReaderNames, LPDWORD pcchReaderLen,
420  LPDWORD pdwState, LPDWORD pdwProtocol, LPBYTE pbAtr,
421  LPDWORD pcbAtrLen)
422 {
423  SCARDAPI_STUB_CALL_LONG(SCardStatusA, hCard, mszReaderNames, pcchReaderLen, pdwState,
424  pdwProtocol, pbAtr, pcbAtrLen);
425 }
426 
427 WINSCARDAPI LONG WINAPI SCardStatusW(SCARDHANDLE hCard, LPWSTR mszReaderNames,
428  LPDWORD pcchReaderLen, LPDWORD pdwState, LPDWORD pdwProtocol,
429  LPBYTE pbAtr, LPDWORD pcbAtrLen)
430 {
431  SCARDAPI_STUB_CALL_LONG(SCardStatusW, hCard, mszReaderNames, pcchReaderLen, pdwState,
432  pdwProtocol, pbAtr, pcbAtrLen);
433 }
434 
435 WINSCARDAPI LONG WINAPI SCardTransmit(SCARDHANDLE hCard, LPCSCARD_IO_REQUEST pioSendPci,
436  LPCBYTE pbSendBuffer, DWORD cbSendLength,
437  LPSCARD_IO_REQUEST pioRecvPci, LPBYTE pbRecvBuffer,
438  LPDWORD pcbRecvLength)
439 {
440  SCARDAPI_STUB_CALL_LONG(SCardTransmit, hCard, pioSendPci, pbSendBuffer, cbSendLength,
441  pioRecvPci, pbRecvBuffer, pcbRecvLength);
442 }
443 
444 WINSCARDAPI LONG WINAPI SCardGetTransmitCount(SCARDHANDLE hCard, LPDWORD pcTransmitCount)
445 {
446  SCARDAPI_STUB_CALL_LONG(SCardGetTransmitCount, hCard, pcTransmitCount);
447 }
448 
449 WINSCARDAPI LONG WINAPI SCardControl(SCARDHANDLE hCard, DWORD dwControlCode, LPCVOID lpInBuffer,
450  DWORD cbInBufferSize, LPVOID lpOutBuffer,
451  DWORD cbOutBufferSize, LPDWORD lpBytesReturned)
452 {
453  SCARDAPI_STUB_CALL_LONG(SCardControl, hCard, dwControlCode, lpInBuffer, cbInBufferSize,
454  lpOutBuffer, cbOutBufferSize, lpBytesReturned);
455 }
456 
457 WINSCARDAPI LONG WINAPI SCardGetAttrib(SCARDHANDLE hCard, DWORD dwAttrId, LPBYTE pbAttr,
458  LPDWORD pcbAttrLen)
459 {
460  SCARDAPI_STUB_CALL_LONG(SCardGetAttrib, hCard, dwAttrId, pbAttr, pcbAttrLen);
461 }
462 
463 WINSCARDAPI LONG WINAPI SCardSetAttrib(SCARDHANDLE hCard, DWORD dwAttrId, LPCBYTE pbAttr,
464  DWORD cbAttrLen)
465 {
466  SCARDAPI_STUB_CALL_LONG(SCardSetAttrib, hCard, dwAttrId, pbAttr, cbAttrLen);
467 }
468 
469 WINSCARDAPI LONG WINAPI SCardUIDlgSelectCardA(LPOPENCARDNAMEA_EX pDlgStruc)
470 {
471  SCARDAPI_STUB_CALL_LONG(SCardUIDlgSelectCardA, pDlgStruc);
472 }
473 
474 WINSCARDAPI LONG WINAPI SCardUIDlgSelectCardW(LPOPENCARDNAMEW_EX pDlgStruc)
475 {
476  SCARDAPI_STUB_CALL_LONG(SCardUIDlgSelectCardW, pDlgStruc);
477 }
478 
479 WINSCARDAPI LONG WINAPI GetOpenCardNameA(LPOPENCARDNAMEA pDlgStruc)
480 {
481  SCARDAPI_STUB_CALL_LONG(GetOpenCardNameA, pDlgStruc);
482 }
483 
484 WINSCARDAPI LONG WINAPI GetOpenCardNameW(LPOPENCARDNAMEW pDlgStruc)
485 {
486  SCARDAPI_STUB_CALL_LONG(GetOpenCardNameW, pDlgStruc);
487 }
488 
489 WINSCARDAPI LONG WINAPI SCardDlgExtendedError(void)
490 {
491  SCARDAPI_STUB_CALL_LONG(SCardDlgExtendedError);
492 }
493 
494 WINSCARDAPI LONG WINAPI SCardReadCacheA(SCARDCONTEXT hContext, UUID* CardIdentifier,
495  DWORD FreshnessCounter, LPSTR LookupName, PBYTE Data,
496  DWORD* DataLen)
497 {
498  SCARDAPI_STUB_CALL_LONG(SCardReadCacheA, hContext, CardIdentifier, FreshnessCounter, LookupName,
499  Data, DataLen);
500 }
501 
502 WINSCARDAPI LONG WINAPI SCardReadCacheW(SCARDCONTEXT hContext, UUID* CardIdentifier,
503  DWORD FreshnessCounter, LPWSTR LookupName, PBYTE Data,
504  DWORD* DataLen)
505 {
506  SCARDAPI_STUB_CALL_LONG(SCardReadCacheW, hContext, CardIdentifier, FreshnessCounter, LookupName,
507  Data, DataLen);
508 }
509 
510 WINSCARDAPI LONG WINAPI SCardWriteCacheA(SCARDCONTEXT hContext, UUID* CardIdentifier,
511  DWORD FreshnessCounter, LPSTR LookupName, PBYTE Data,
512  DWORD DataLen)
513 {
514  SCARDAPI_STUB_CALL_LONG(SCardWriteCacheA, hContext, CardIdentifier, FreshnessCounter,
515  LookupName, Data, DataLen);
516 }
517 
518 WINSCARDAPI LONG WINAPI SCardWriteCacheW(SCARDCONTEXT hContext, UUID* CardIdentifier,
519  DWORD FreshnessCounter, LPWSTR LookupName, PBYTE Data,
520  DWORD DataLen)
521 {
522  SCARDAPI_STUB_CALL_LONG(SCardWriteCacheW, hContext, CardIdentifier, FreshnessCounter,
523  LookupName, Data, DataLen);
524 }
525 
526 WINSCARDAPI LONG WINAPI SCardGetReaderIconA(SCARDCONTEXT hContext, LPCSTR szReaderName,
527  LPBYTE pbIcon, LPDWORD pcbIcon)
528 {
529  SCARDAPI_STUB_CALL_LONG(SCardGetReaderIconA, hContext, szReaderName, pbIcon, pcbIcon);
530 }
531 
532 WINSCARDAPI LONG WINAPI SCardGetReaderIconW(SCARDCONTEXT hContext, LPCWSTR szReaderName,
533  LPBYTE pbIcon, LPDWORD pcbIcon)
534 {
535  SCARDAPI_STUB_CALL_LONG(SCardGetReaderIconW, hContext, szReaderName, pbIcon, pcbIcon);
536 }
537 
538 WINSCARDAPI LONG WINAPI SCardGetDeviceTypeIdA(SCARDCONTEXT hContext, LPCSTR szReaderName,
539  LPDWORD pdwDeviceTypeId)
540 {
541  SCARDAPI_STUB_CALL_LONG(SCardGetDeviceTypeIdA, hContext, szReaderName, pdwDeviceTypeId);
542 }
543 
544 WINSCARDAPI LONG WINAPI SCardGetDeviceTypeIdW(SCARDCONTEXT hContext, LPCWSTR szReaderName,
545  LPDWORD pdwDeviceTypeId)
546 {
547  SCARDAPI_STUB_CALL_LONG(SCardGetDeviceTypeIdW, hContext, szReaderName, pdwDeviceTypeId);
548 }
549 
550 WINSCARDAPI LONG WINAPI SCardGetReaderDeviceInstanceIdA(SCARDCONTEXT hContext, LPCSTR szReaderName,
551  LPSTR szDeviceInstanceId,
552  LPDWORD pcchDeviceInstanceId)
553 {
554  SCARDAPI_STUB_CALL_LONG(SCardGetReaderDeviceInstanceIdA, hContext, szReaderName,
555  szDeviceInstanceId, pcchDeviceInstanceId);
556 }
557 
558 WINSCARDAPI LONG WINAPI SCardGetReaderDeviceInstanceIdW(SCARDCONTEXT hContext, LPCWSTR szReaderName,
559  LPWSTR szDeviceInstanceId,
560  LPDWORD pcchDeviceInstanceId)
561 {
562  SCARDAPI_STUB_CALL_LONG(SCardGetReaderDeviceInstanceIdW, hContext, szReaderName,
563  szDeviceInstanceId, pcchDeviceInstanceId);
564 }
565 
566 WINSCARDAPI LONG WINAPI SCardListReadersWithDeviceInstanceIdA(SCARDCONTEXT hContext,
567  LPCSTR szDeviceInstanceId,
568  LPSTR mszReaders, LPDWORD pcchReaders)
569 {
570  SCARDAPI_STUB_CALL_LONG(SCardListReadersWithDeviceInstanceIdA, hContext, szDeviceInstanceId,
571  mszReaders, pcchReaders);
572 }
573 
574 WINSCARDAPI LONG WINAPI SCardListReadersWithDeviceInstanceIdW(SCARDCONTEXT hContext,
575  LPCWSTR szDeviceInstanceId,
576  LPWSTR mszReaders,
577  LPDWORD pcchReaders)
578 {
579  SCARDAPI_STUB_CALL_LONG(SCardListReadersWithDeviceInstanceIdW, hContext, szDeviceInstanceId,
580  mszReaders, pcchReaders);
581 }
582 
583 WINSCARDAPI LONG WINAPI SCardAudit(SCARDCONTEXT hContext, DWORD dwEvent)
584 {
585  SCARDAPI_STUB_CALL_LONG(SCardAudit, hContext, dwEvent);
586 }
587 
592 WINSCARDAPI const char* WINAPI SCardGetErrorString(LONG errorCode)
593 {
594  switch (errorCode)
595  {
596  case SCARD_S_SUCCESS:
597  return "SCARD_S_SUCCESS";
598 
599  case SCARD_F_INTERNAL_ERROR:
600  return "SCARD_F_INTERNAL_ERROR";
601 
602  case SCARD_E_CANCELLED:
603  return "SCARD_E_CANCELLED";
604 
605  case SCARD_E_INVALID_HANDLE:
606  return "SCARD_E_INVALID_HANDLE";
607 
608  case SCARD_E_INVALID_PARAMETER:
609  return "SCARD_E_INVALID_PARAMETER";
610 
611  case SCARD_E_INVALID_TARGET:
612  return "SCARD_E_INVALID_TARGET";
613 
614  case SCARD_E_NO_MEMORY:
615  return "SCARD_E_NO_MEMORY";
616 
617  case SCARD_F_WAITED_TOO_LONG:
618  return "SCARD_F_WAITED_TOO_LONG";
619 
620  case SCARD_E_INSUFFICIENT_BUFFER:
621  return "SCARD_E_INSUFFICIENT_BUFFER";
622 
623  case SCARD_E_UNKNOWN_READER:
624  return "SCARD_E_UNKNOWN_READER";
625 
626  case SCARD_E_TIMEOUT:
627  return "SCARD_E_TIMEOUT";
628 
629  case SCARD_E_SHARING_VIOLATION:
630  return "SCARD_E_SHARING_VIOLATION";
631 
632  case SCARD_E_NO_SMARTCARD:
633  return "SCARD_E_NO_SMARTCARD";
634 
635  case SCARD_E_UNKNOWN_CARD:
636  return "SCARD_E_UNKNOWN_CARD";
637 
638  case SCARD_E_CANT_DISPOSE:
639  return "SCARD_E_CANT_DISPOSE";
640 
641  case SCARD_E_PROTO_MISMATCH:
642  return "SCARD_E_PROTO_MISMATCH";
643 
644  case SCARD_E_NOT_READY:
645  return "SCARD_E_NOT_READY";
646 
647  case SCARD_E_INVALID_VALUE:
648  return "SCARD_E_INVALID_VALUE";
649 
650  case SCARD_E_SYSTEM_CANCELLED:
651  return "SCARD_E_SYSTEM_CANCELLED";
652 
653  case SCARD_F_COMM_ERROR:
654  return "SCARD_F_COMM_ERROR";
655 
656  case SCARD_F_UNKNOWN_ERROR:
657  return "SCARD_F_UNKNOWN_ERROR";
658 
659  case SCARD_E_INVALID_ATR:
660  return "SCARD_E_INVALID_ATR";
661 
662  case SCARD_E_NOT_TRANSACTED:
663  return "SCARD_E_NOT_TRANSACTED";
664 
665  case SCARD_E_READER_UNAVAILABLE:
666  return "SCARD_E_READER_UNAVAILABLE";
667 
668  case SCARD_P_SHUTDOWN:
669  return "SCARD_P_SHUTDOWN";
670 
671  case SCARD_E_PCI_TOO_SMALL:
672  return "SCARD_E_PCI_TOO_SMALL";
673 
674  case SCARD_E_READER_UNSUPPORTED:
675  return "SCARD_E_READER_UNSUPPORTED";
676 
677  case SCARD_E_DUPLICATE_READER:
678  return "SCARD_E_DUPLICATE_READER";
679 
680  case SCARD_E_CARD_UNSUPPORTED:
681  return "SCARD_E_CARD_UNSUPPORTED";
682 
683  case SCARD_E_NO_SERVICE:
684  return "SCARD_E_NO_SERVICE";
685 
686  case SCARD_E_SERVICE_STOPPED:
687  return "SCARD_E_SERVICE_STOPPED";
688 
689  case SCARD_E_UNEXPECTED:
690  return "SCARD_E_UNEXPECTED";
691 
692  case SCARD_E_ICC_INSTALLATION:
693  return "SCARD_E_ICC_INSTALLATION";
694 
695  case SCARD_E_ICC_CREATEORDER:
696  return "SCARD_E_ICC_CREATEORDER";
697 
698  case SCARD_E_UNSUPPORTED_FEATURE:
699  return "SCARD_E_UNSUPPORTED_FEATURE";
700 
701  case SCARD_E_DIR_NOT_FOUND:
702  return "SCARD_E_DIR_NOT_FOUND";
703 
704  case SCARD_E_FILE_NOT_FOUND:
705  return "SCARD_E_FILE_NOT_FOUND";
706 
707  case SCARD_E_NO_DIR:
708  return "SCARD_E_NO_DIR";
709 
710  case SCARD_E_NO_FILE:
711  return "SCARD_E_NO_FILE";
712 
713  case SCARD_E_NO_ACCESS:
714  return "SCARD_E_NO_ACCESS";
715 
716  case SCARD_E_WRITE_TOO_MANY:
717  return "SCARD_E_WRITE_TOO_MANY";
718 
719  case SCARD_E_BAD_SEEK:
720  return "SCARD_E_BAD_SEEK";
721 
722  case SCARD_E_INVALID_CHV:
723  return "SCARD_E_INVALID_CHV";
724 
725  case SCARD_E_UNKNOWN_RES_MNG:
726  return "SCARD_E_UNKNOWN_RES_MNG";
727 
728  case SCARD_E_NO_SUCH_CERTIFICATE:
729  return "SCARD_E_NO_SUCH_CERTIFICATE";
730 
731  case SCARD_E_CERTIFICATE_UNAVAILABLE:
732  return "SCARD_E_CERTIFICATE_UNAVAILABLE";
733 
734  case SCARD_E_NO_READERS_AVAILABLE:
735  return "SCARD_E_NO_READERS_AVAILABLE";
736 
737  case SCARD_E_COMM_DATA_LOST:
738  return "SCARD_E_COMM_DATA_LOST";
739 
740  case SCARD_E_NO_KEY_CONTAINER:
741  return "SCARD_E_NO_KEY_CONTAINER";
742 
743  case SCARD_E_SERVER_TOO_BUSY:
744  return "SCARD_E_SERVER_TOO_BUSY";
745 
746  case SCARD_E_PIN_CACHE_EXPIRED:
747  return "SCARD_E_PIN_CACHE_EXPIRED";
748 
749  case SCARD_E_NO_PIN_CACHE:
750  return "SCARD_E_NO_PIN_CACHE";
751 
752  case SCARD_E_READ_ONLY_CARD:
753  return "SCARD_E_READ_ONLY_CARD";
754 
755  case SCARD_W_UNSUPPORTED_CARD:
756  return "SCARD_W_UNSUPPORTED_CARD";
757 
758  case SCARD_W_UNRESPONSIVE_CARD:
759  return "SCARD_W_UNRESPONSIVE_CARD";
760 
761  case SCARD_W_UNPOWERED_CARD:
762  return "SCARD_W_UNPOWERED_CARD";
763 
764  case SCARD_W_RESET_CARD:
765  return "SCARD_W_RESET_CARD";
766 
767  case SCARD_W_REMOVED_CARD:
768  return "SCARD_W_REMOVED_CARD";
769 
770  case SCARD_W_SECURITY_VIOLATION:
771  return "SCARD_W_SECURITY_VIOLATION";
772 
773  case SCARD_W_WRONG_CHV:
774  return "SCARD_W_WRONG_CHV";
775 
776  case SCARD_W_CHV_BLOCKED:
777  return "SCARD_W_CHV_BLOCKED";
778 
779  case SCARD_W_EOF:
780  return "SCARD_W_EOF";
781 
782  case SCARD_W_CANCELLED_BY_USER:
783  return "SCARD_W_CANCELLED_BY_USER";
784 
785  case SCARD_W_CARD_NOT_AUTHENTICATED:
786  return "SCARD_W_CARD_NOT_AUTHENTICATED";
787 
788  case SCARD_W_CACHE_ITEM_NOT_FOUND:
789  return "SCARD_W_CACHE_ITEM_NOT_FOUND";
790 
791  case SCARD_W_CACHE_ITEM_STALE:
792  return "SCARD_W_CACHE_ITEM_STALE";
793 
794  case SCARD_W_CACHE_ITEM_TOO_BIG:
795  return "SCARD_W_CACHE_ITEM_TOO_BIG";
796 
797  default:
798  return "SCARD_E_UNKNOWN";
799  }
800 }
801 
802 WINSCARDAPI const char* WINAPI SCardGetAttributeString(DWORD dwAttrId)
803 {
804  switch (dwAttrId)
805  {
806  case SCARD_ATTR_VENDOR_NAME:
807  return "SCARD_ATTR_VENDOR_NAME";
808 
809  case SCARD_ATTR_VENDOR_IFD_TYPE:
810  return "SCARD_ATTR_VENDOR_IFD_TYPE";
811 
812  case SCARD_ATTR_VENDOR_IFD_VERSION:
813  return "SCARD_ATTR_VENDOR_IFD_VERSION";
814 
815  case SCARD_ATTR_VENDOR_IFD_SERIAL_NO:
816  return "SCARD_ATTR_VENDOR_IFD_SERIAL_NO";
817 
818  case SCARD_ATTR_CHANNEL_ID:
819  return "SCARD_ATTR_CHANNEL_ID";
820 
821  case SCARD_ATTR_PROTOCOL_TYPES:
822  return "SCARD_ATTR_PROTOCOL_TYPES";
823 
824  case SCARD_ATTR_DEFAULT_CLK:
825  return "SCARD_ATTR_DEFAULT_CLK";
826 
827  case SCARD_ATTR_MAX_CLK:
828  return "SCARD_ATTR_MAX_CLK";
829 
830  case SCARD_ATTR_DEFAULT_DATA_RATE:
831  return "SCARD_ATTR_DEFAULT_DATA_RATE";
832 
833  case SCARD_ATTR_MAX_DATA_RATE:
834  return "SCARD_ATTR_MAX_DATA_RATE";
835 
836  case SCARD_ATTR_MAX_IFSD:
837  return "SCARD_ATTR_MAX_IFSD";
838 
839  case SCARD_ATTR_POWER_MGMT_SUPPORT:
840  return "SCARD_ATTR_POWER_MGMT_SUPPORT";
841 
842  case SCARD_ATTR_USER_TO_CARD_AUTH_DEVICE:
843  return "SCARD_ATTR_USER_TO_CARD_AUTH_DEVICE";
844 
845  case SCARD_ATTR_USER_AUTH_INPUT_DEVICE:
846  return "SCARD_ATTR_USER_AUTH_INPUT_DEVICE";
847 
848  case SCARD_ATTR_CHARACTERISTICS:
849  return "SCARD_ATTR_CHARACTERISTICS";
850 
851  case SCARD_ATTR_CURRENT_PROTOCOL_TYPE:
852  return "SCARD_ATTR_CURRENT_PROTOCOL_TYPE";
853 
854  case SCARD_ATTR_CURRENT_CLK:
855  return "SCARD_ATTR_CURRENT_CLK";
856 
857  case SCARD_ATTR_CURRENT_F:
858  return "SCARD_ATTR_CURRENT_F";
859 
860  case SCARD_ATTR_CURRENT_D:
861  return "SCARD_ATTR_CURRENT_D";
862 
863  case SCARD_ATTR_CURRENT_N:
864  return "SCARD_ATTR_CURRENT_N";
865 
866  case SCARD_ATTR_CURRENT_W:
867  return "SCARD_ATTR_CURRENT_W";
868 
869  case SCARD_ATTR_CURRENT_IFSC:
870  return "SCARD_ATTR_CURRENT_IFSC";
871 
872  case SCARD_ATTR_CURRENT_IFSD:
873  return "SCARD_ATTR_CURRENT_IFSD";
874 
875  case SCARD_ATTR_CURRENT_BWT:
876  return "SCARD_ATTR_CURRENT_BWT";
877 
878  case SCARD_ATTR_CURRENT_CWT:
879  return "SCARD_ATTR_CURRENT_CWT";
880 
881  case SCARD_ATTR_CURRENT_EBC_ENCODING:
882  return "SCARD_ATTR_CURRENT_EBC_ENCODING";
883 
884  case SCARD_ATTR_EXTENDED_BWT:
885  return "SCARD_ATTR_EXTENDED_BWT";
886 
887  case SCARD_ATTR_ICC_PRESENCE:
888  return "SCARD_ATTR_ICC_PRESENCE";
889 
890  case SCARD_ATTR_ICC_INTERFACE_STATUS:
891  return "SCARD_ATTR_ICC_INTERFACE_STATUS";
892 
893  case SCARD_ATTR_CURRENT_IO_STATE:
894  return "SCARD_ATTR_CURRENT_IO_STATE";
895 
896  case SCARD_ATTR_ATR_STRING:
897  return "SCARD_ATTR_ATR_STRING";
898 
899  case SCARD_ATTR_ICC_TYPE_PER_ATR:
900  return "SCARD_ATTR_ICC_TYPE_PER_ATR";
901 
902  case SCARD_ATTR_ESC_RESET:
903  return "SCARD_ATTR_ESC_RESET";
904 
905  case SCARD_ATTR_ESC_CANCEL:
906  return "SCARD_ATTR_ESC_CANCEL";
907 
908  case SCARD_ATTR_ESC_AUTHREQUEST:
909  return "SCARD_ATTR_ESC_AUTHREQUEST";
910 
911  case SCARD_ATTR_MAXINPUT:
912  return "SCARD_ATTR_MAXINPUT";
913 
914  case SCARD_ATTR_DEVICE_UNIT:
915  return "SCARD_ATTR_DEVICE_UNIT";
916 
917  case SCARD_ATTR_DEVICE_IN_USE:
918  return "SCARD_ATTR_DEVICE_IN_USE";
919 
920  case SCARD_ATTR_DEVICE_FRIENDLY_NAME_A:
921  return "SCARD_ATTR_DEVICE_FRIENDLY_NAME_A";
922 
923  case SCARD_ATTR_DEVICE_SYSTEM_NAME_A:
924  return "SCARD_ATTR_DEVICE_SYSTEM_NAME_A";
925 
926  case SCARD_ATTR_DEVICE_FRIENDLY_NAME_W:
927  return "SCARD_ATTR_DEVICE_FRIENDLY_NAME_W";
928 
929  case SCARD_ATTR_DEVICE_SYSTEM_NAME_W:
930  return "SCARD_ATTR_DEVICE_SYSTEM_NAME_W";
931 
932  case SCARD_ATTR_SUPRESS_T1_IFS_REQUEST:
933  return "SCARD_ATTR_SUPRESS_T1_IFS_REQUEST";
934 
935  default:
936  return "SCARD_ATTR_UNKNOWN";
937  }
938 }
939 
940 WINSCARDAPI const char* WINAPI SCardGetProtocolString(DWORD dwProtocols)
941 {
942  if (dwProtocols == SCARD_PROTOCOL_UNDEFINED)
943  return "SCARD_PROTOCOL_UNDEFINED";
944 
945  if (dwProtocols == SCARD_PROTOCOL_T0)
946  return "SCARD_PROTOCOL_T0";
947 
948  if (dwProtocols == SCARD_PROTOCOL_T1)
949  return "SCARD_PROTOCOL_T1";
950 
951  if (dwProtocols == SCARD_PROTOCOL_Tx)
952  return "SCARD_PROTOCOL_Tx";
953 
954  if (dwProtocols == SCARD_PROTOCOL_RAW)
955  return "SCARD_PROTOCOL_RAW";
956 
957  if (dwProtocols == SCARD_PROTOCOL_DEFAULT)
958  return "SCARD_PROTOCOL_DEFAULT";
959 
960  if (dwProtocols == (SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_RAW))
961  return "SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_RAW";
962 
963  if (dwProtocols == (SCARD_PROTOCOL_T1 | SCARD_PROTOCOL_RAW))
964  return "SCARD_PROTOCOL_T1 | SCARD_PROTOCOL_RAW";
965 
966  if (dwProtocols == (SCARD_PROTOCOL_Tx | SCARD_PROTOCOL_RAW))
967  return "SCARD_PROTOCOL_Tx | SCARD_PROTOCOL_RAW";
968 
969  return "SCARD_PROTOCOL_UNKNOWN";
970 }
971 
972 WINSCARDAPI const char* WINAPI SCardGetShareModeString(DWORD dwShareMode)
973 {
974  switch (dwShareMode)
975  {
976  case SCARD_SHARE_EXCLUSIVE:
977  return "SCARD_SHARE_EXCLUSIVE";
978 
979  case SCARD_SHARE_SHARED:
980  return "SCARD_SHARE_SHARED";
981 
982  case SCARD_SHARE_DIRECT:
983  return "SCARD_SHARE_DIRECT";
984 
985  default:
986  return "SCARD_SHARE_UNKNOWN";
987  }
988 }
989 
990 WINSCARDAPI const char* WINAPI SCardGetDispositionString(DWORD dwDisposition)
991 {
992  switch (dwDisposition)
993  {
994  case SCARD_LEAVE_CARD:
995  return "SCARD_LEAVE_CARD";
996 
997  case SCARD_RESET_CARD:
998  return "SCARD_RESET_CARD";
999 
1000  case SCARD_UNPOWER_CARD:
1001  return "SCARD_UNPOWER_CARD";
1002 
1003  default:
1004  return "SCARD_UNKNOWN_CARD";
1005  }
1006 }
1007 
1008 WINSCARDAPI const char* WINAPI SCardGetScopeString(DWORD dwScope)
1009 {
1010  switch (dwScope)
1011  {
1012  case SCARD_SCOPE_USER:
1013  return "SCARD_SCOPE_USER";
1014 
1015  case SCARD_SCOPE_TERMINAL:
1016  return "SCARD_SCOPE_TERMINAL";
1017 
1018  case SCARD_SCOPE_SYSTEM:
1019  return "SCARD_SCOPE_SYSTEM";
1020 
1021  default:
1022  return "SCARD_SCOPE_UNKNOWN";
1023  }
1024 }
1025 
1026 WINSCARDAPI const char* WINAPI SCardGetCardStateString(DWORD dwCardState)
1027 {
1028  switch (dwCardState)
1029  {
1030  case SCARD_UNKNOWN:
1031  return "SCARD_UNKNOWN";
1032 
1033  case SCARD_ABSENT:
1034  return "SCARD_ABSENT";
1035 
1036  case SCARD_PRESENT:
1037  return "SCARD_PRESENT";
1038 
1039  case SCARD_SWALLOWED:
1040  return "SCARD_SWALLOWED";
1041 
1042  case SCARD_POWERED:
1043  return "SCARD_POWERED";
1044 
1045  case SCARD_NEGOTIABLE:
1046  return "SCARD_NEGOTIABLE";
1047 
1048  case SCARD_SPECIFIC:
1049  return "SCARD_SPECIFIC";
1050 
1051  default:
1052  return "SCARD_UNKNOWN";
1053  }
1054 }
1055 
1056 WINSCARDAPI char* WINAPI SCardGetReaderStateString(DWORD dwReaderState)
1057 {
1058  const size_t size = 512;
1059  char* buffer = calloc(size, sizeof(char));
1060 
1061  if (!buffer)
1062  return NULL;
1063 
1064  if (dwReaderState & SCARD_STATE_IGNORE)
1065  winpr_str_append("SCARD_STATE_IGNORE", buffer, size, "|");
1066 
1067  if (dwReaderState & SCARD_STATE_CHANGED)
1068  winpr_str_append("SCARD_STATE_CHANGED", buffer, size, "|");
1069 
1070  if (dwReaderState & SCARD_STATE_UNKNOWN)
1071  winpr_str_append("SCARD_STATE_UNKNOWN", buffer, size, "|");
1072 
1073  if (dwReaderState & SCARD_STATE_UNAVAILABLE)
1074  winpr_str_append("SCARD_STATE_UNAVAILABLE", buffer, size, "|");
1075 
1076  if (dwReaderState & SCARD_STATE_EMPTY)
1077  winpr_str_append("SCARD_STATE_EMPTY", buffer, size, "|");
1078 
1079  if (dwReaderState & SCARD_STATE_PRESENT)
1080  winpr_str_append("SCARD_STATE_PRESENT", buffer, size, "|");
1081 
1082  if (dwReaderState & SCARD_STATE_ATRMATCH)
1083  winpr_str_append("SCARD_STATE_ATRMATCH", buffer, size, "|");
1084 
1085  if (dwReaderState & SCARD_STATE_EXCLUSIVE)
1086  winpr_str_append("SCARD_STATE_EXCLUSIVE", buffer, size, "|");
1087 
1088  if (dwReaderState & SCARD_STATE_INUSE)
1089  winpr_str_append("SCARD_STATE_INUSE", buffer, size, "|");
1090 
1091  if (dwReaderState & SCARD_STATE_MUTE)
1092  winpr_str_append("SCARD_STATE_MUTE", buffer, size, "|");
1093 
1094  if (dwReaderState & SCARD_STATE_UNPOWERED)
1095  winpr_str_append("SCARD_STATE_UNPOWERED", buffer, size, "|");
1096 
1097  if (!buffer[0])
1098  winpr_str_append("SCARD_STATE_UNAWARE", buffer, size, "|");
1099 
1100  return buffer;
1101 }
1102 
1103 #define WINSCARD_LOAD_PROC(_name) \
1104  do \
1105  { \
1106  WINPR_PRAGMA_DIAG_PUSH \
1107  WINPR_PRAGMA_DIAG_IGNORED_PEDANTIC \
1108  pWinSCardApiTable->pfn##_name = GetProcAddressAs(hWinSCardLibrary, #_name, fn##_name); \
1109  WINPR_PRAGMA_DIAG_POP \
1110  } while (0)
1111 
1112 BOOL WinSCard_LoadApiTableFunctions(PSCardApiFunctionTable pWinSCardApiTable,
1113  HMODULE hWinSCardLibrary)
1114 {
1115  WINPR_ASSERT(pWinSCardApiTable);
1116  WINPR_ASSERT(hWinSCardLibrary);
1117 
1118  WINSCARD_LOAD_PROC(SCardEstablishContext);
1119  WINSCARD_LOAD_PROC(SCardReleaseContext);
1120  WINSCARD_LOAD_PROC(SCardIsValidContext);
1121  WINSCARD_LOAD_PROC(SCardListReaderGroupsA);
1122  WINSCARD_LOAD_PROC(SCardListReaderGroupsW);
1123  WINSCARD_LOAD_PROC(SCardListReadersA);
1124  WINSCARD_LOAD_PROC(SCardListReadersW);
1125  WINSCARD_LOAD_PROC(SCardListCardsA);
1126  WINSCARD_LOAD_PROC(SCardListCardsW);
1127  WINSCARD_LOAD_PROC(SCardListInterfacesA);
1128  WINSCARD_LOAD_PROC(SCardListInterfacesW);
1129  WINSCARD_LOAD_PROC(SCardGetProviderIdA);
1130  WINSCARD_LOAD_PROC(SCardGetProviderIdW);
1131  WINSCARD_LOAD_PROC(SCardGetCardTypeProviderNameA);
1132  WINSCARD_LOAD_PROC(SCardGetCardTypeProviderNameW);
1133  WINSCARD_LOAD_PROC(SCardIntroduceReaderGroupA);
1134  WINSCARD_LOAD_PROC(SCardIntroduceReaderGroupW);
1135  WINSCARD_LOAD_PROC(SCardForgetReaderGroupA);
1136  WINSCARD_LOAD_PROC(SCardForgetReaderGroupW);
1137  WINSCARD_LOAD_PROC(SCardIntroduceReaderA);
1138  WINSCARD_LOAD_PROC(SCardIntroduceReaderW);
1139  WINSCARD_LOAD_PROC(SCardForgetReaderA);
1140  WINSCARD_LOAD_PROC(SCardForgetReaderW);
1141  WINSCARD_LOAD_PROC(SCardAddReaderToGroupA);
1142  WINSCARD_LOAD_PROC(SCardAddReaderToGroupW);
1143  WINSCARD_LOAD_PROC(SCardRemoveReaderFromGroupA);
1144  WINSCARD_LOAD_PROC(SCardRemoveReaderFromGroupW);
1145  WINSCARD_LOAD_PROC(SCardIntroduceCardTypeA);
1146  WINSCARD_LOAD_PROC(SCardIntroduceCardTypeW);
1147  WINSCARD_LOAD_PROC(SCardSetCardTypeProviderNameA);
1148  WINSCARD_LOAD_PROC(SCardSetCardTypeProviderNameW);
1149  WINSCARD_LOAD_PROC(SCardForgetCardTypeA);
1150  WINSCARD_LOAD_PROC(SCardForgetCardTypeW);
1151  WINSCARD_LOAD_PROC(SCardFreeMemory);
1152  WINSCARD_LOAD_PROC(SCardAccessStartedEvent);
1153  WINSCARD_LOAD_PROC(SCardReleaseStartedEvent);
1154  WINSCARD_LOAD_PROC(SCardLocateCardsA);
1155  WINSCARD_LOAD_PROC(SCardLocateCardsW);
1156  WINSCARD_LOAD_PROC(SCardLocateCardsByATRA);
1157  WINSCARD_LOAD_PROC(SCardLocateCardsByATRW);
1158  WINSCARD_LOAD_PROC(SCardGetStatusChangeA);
1159  WINSCARD_LOAD_PROC(SCardGetStatusChangeW);
1160  WINSCARD_LOAD_PROC(SCardCancel);
1161  WINSCARD_LOAD_PROC(SCardConnectA);
1162  WINSCARD_LOAD_PROC(SCardConnectW);
1163  WINSCARD_LOAD_PROC(SCardReconnect);
1164  WINSCARD_LOAD_PROC(SCardDisconnect);
1165  WINSCARD_LOAD_PROC(SCardBeginTransaction);
1166  WINSCARD_LOAD_PROC(SCardEndTransaction);
1167  WINSCARD_LOAD_PROC(SCardCancelTransaction);
1168  WINSCARD_LOAD_PROC(SCardState);
1169  WINSCARD_LOAD_PROC(SCardStatusA);
1170  WINSCARD_LOAD_PROC(SCardStatusW);
1171  WINSCARD_LOAD_PROC(SCardTransmit);
1172  WINSCARD_LOAD_PROC(SCardGetTransmitCount);
1173  WINSCARD_LOAD_PROC(SCardControl);
1174  WINSCARD_LOAD_PROC(SCardGetAttrib);
1175  WINSCARD_LOAD_PROC(SCardSetAttrib);
1176  WINSCARD_LOAD_PROC(SCardUIDlgSelectCardA);
1177  WINSCARD_LOAD_PROC(SCardUIDlgSelectCardW);
1178  WINSCARD_LOAD_PROC(GetOpenCardNameA);
1179  WINSCARD_LOAD_PROC(GetOpenCardNameW);
1180  WINSCARD_LOAD_PROC(SCardDlgExtendedError);
1181  WINSCARD_LOAD_PROC(SCardReadCacheA);
1182  WINSCARD_LOAD_PROC(SCardReadCacheW);
1183  WINSCARD_LOAD_PROC(SCardWriteCacheA);
1184  WINSCARD_LOAD_PROC(SCardWriteCacheW);
1185  WINSCARD_LOAD_PROC(SCardGetReaderIconA);
1186  WINSCARD_LOAD_PROC(SCardGetReaderIconW);
1187  WINSCARD_LOAD_PROC(SCardGetDeviceTypeIdA);
1188  WINSCARD_LOAD_PROC(SCardGetDeviceTypeIdW);
1189  WINSCARD_LOAD_PROC(SCardGetReaderDeviceInstanceIdA);
1190  WINSCARD_LOAD_PROC(SCardGetReaderDeviceInstanceIdW);
1191  WINSCARD_LOAD_PROC(SCardListReadersWithDeviceInstanceIdA);
1192  WINSCARD_LOAD_PROC(SCardListReadersWithDeviceInstanceIdW);
1193  WINSCARD_LOAD_PROC(SCardAudit);
1194 
1195  return TRUE;
1196 }
1197 
1198 static const SCardApiFunctionTable WinPR_SCardApiFunctionTable = {
1199  0, /* dwVersion */
1200  0, /* dwFlags */
1201 
1202  SCardEstablishContext, /* SCardEstablishContext */
1203  SCardReleaseContext, /* SCardReleaseContext */
1204  SCardIsValidContext, /* SCardIsValidContext */
1205  SCardListReaderGroupsA, /* SCardListReaderGroupsA */
1206  SCardListReaderGroupsW, /* SCardListReaderGroupsW */
1207  SCardListReadersA, /* SCardListReadersA */
1208  SCardListReadersW, /* SCardListReadersW */
1209  SCardListCardsA, /* SCardListCardsA */
1210  SCardListCardsW, /* SCardListCardsW */
1211  SCardListInterfacesA, /* SCardListInterfacesA */
1212  SCardListInterfacesW, /* SCardListInterfacesW */
1213  SCardGetProviderIdA, /* SCardGetProviderIdA */
1214  SCardGetProviderIdW, /* SCardGetProviderIdW */
1215  SCardGetCardTypeProviderNameA, /* SCardGetCardTypeProviderNameA */
1216  SCardGetCardTypeProviderNameW, /* SCardGetCardTypeProviderNameW */
1217  SCardIntroduceReaderGroupA, /* SCardIntroduceReaderGroupA */
1218  SCardIntroduceReaderGroupW, /* SCardIntroduceReaderGroupW */
1219  SCardForgetReaderGroupA, /* SCardForgetReaderGroupA */
1220  SCardForgetReaderGroupW, /* SCardForgetReaderGroupW */
1221  SCardIntroduceReaderA, /* SCardIntroduceReaderA */
1222  SCardIntroduceReaderW, /* SCardIntroduceReaderW */
1223  SCardForgetReaderA, /* SCardForgetReaderA */
1224  SCardForgetReaderW, /* SCardForgetReaderW */
1225  SCardAddReaderToGroupA, /* SCardAddReaderToGroupA */
1226  SCardAddReaderToGroupW, /* SCardAddReaderToGroupW */
1227  SCardRemoveReaderFromGroupA, /* SCardRemoveReaderFromGroupA */
1228  SCardRemoveReaderFromGroupW, /* SCardRemoveReaderFromGroupW */
1229  SCardIntroduceCardTypeA, /* SCardIntroduceCardTypeA */
1230  SCardIntroduceCardTypeW, /* SCardIntroduceCardTypeW */
1231  SCardSetCardTypeProviderNameA, /* SCardSetCardTypeProviderNameA */
1232  SCardSetCardTypeProviderNameW, /* SCardSetCardTypeProviderNameW */
1233  SCardForgetCardTypeA, /* SCardForgetCardTypeA */
1234  SCardForgetCardTypeW, /* SCardForgetCardTypeW */
1235  SCardFreeMemory, /* SCardFreeMemory */
1236  SCardAccessStartedEvent, /* SCardAccessStartedEvent */
1237  SCardReleaseStartedEvent, /* SCardReleaseStartedEvent */
1238  SCardLocateCardsA, /* SCardLocateCardsA */
1239  SCardLocateCardsW, /* SCardLocateCardsW */
1240  SCardLocateCardsByATRA, /* SCardLocateCardsByATRA */
1241  SCardLocateCardsByATRW, /* SCardLocateCardsByATRW */
1242  SCardGetStatusChangeA, /* SCardGetStatusChangeA */
1243  SCardGetStatusChangeW, /* SCardGetStatusChangeW */
1244  SCardCancel, /* SCardCancel */
1245  SCardConnectA, /* SCardConnectA */
1246  SCardConnectW, /* SCardConnectW */
1247  SCardReconnect, /* SCardReconnect */
1248  SCardDisconnect, /* SCardDisconnect */
1249  SCardBeginTransaction, /* SCardBeginTransaction */
1250  SCardEndTransaction, /* SCardEndTransaction */
1251  SCardCancelTransaction, /* SCardCancelTransaction */
1252  SCardState, /* SCardState */
1253  SCardStatusA, /* SCardStatusA */
1254  SCardStatusW, /* SCardStatusW */
1255  SCardTransmit, /* SCardTransmit */
1256  SCardGetTransmitCount, /* SCardGetTransmitCount */
1257  SCardControl, /* SCardControl */
1258  SCardGetAttrib, /* SCardGetAttrib */
1259  SCardSetAttrib, /* SCardSetAttrib */
1260  SCardUIDlgSelectCardA, /* SCardUIDlgSelectCardA */
1261  SCardUIDlgSelectCardW, /* SCardUIDlgSelectCardW */
1262  GetOpenCardNameA, /* GetOpenCardNameA */
1263  GetOpenCardNameW, /* GetOpenCardNameW */
1264  SCardDlgExtendedError, /* SCardDlgExtendedError */
1265  SCardReadCacheA, /* SCardReadCacheA */
1266  SCardReadCacheW, /* SCardReadCacheW */
1267  SCardWriteCacheA, /* SCardWriteCacheA */
1268  SCardWriteCacheW, /* SCardWriteCacheW */
1269  SCardGetReaderIconA, /* SCardGetReaderIconA */
1270  SCardGetReaderIconW, /* SCardGetReaderIconW */
1271  SCardGetDeviceTypeIdA, /* SCardGetDeviceTypeIdA */
1272  SCardGetDeviceTypeIdW, /* SCardGetDeviceTypeIdW */
1273  SCardGetReaderDeviceInstanceIdA, /* SCardGetReaderDeviceInstanceIdA */
1274  SCardGetReaderDeviceInstanceIdW, /* SCardGetReaderDeviceInstanceIdW */
1275  SCardListReadersWithDeviceInstanceIdA, /* SCardListReadersWithDeviceInstanceIdA */
1276  SCardListReadersWithDeviceInstanceIdW, /* SCardListReadersWithDeviceInstanceIdW */
1277  SCardAudit /* SCardAudit */
1278 };
1279 
1280 const SCardApiFunctionTable* WinPR_GetSCardApiFunctionTable(void)
1281 {
1282  return &WinPR_SCardApiFunctionTable;
1283 }