Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1071 lines
38 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. WinSCard
  5. Abstract:
  6. This header file provides the definitions and symbols necessary for an
  7. Application or Smart Card Service Provider to access the Smartcard
  8. Subsystem.
  9. Environment:
  10. Win32
  11. Notes:
  12. --*/
  13. #ifndef _WINSCARD_H_
  14. #define _WINSCARD_H_
  15. #if defined (_MSC_VER) && (_MSC_VER >= 1020)
  16. #pragma once
  17. #endif
  18. #include <wtypes.h>
  19. #include <winioctl.h>
  20. #include "winsmcrd.h"
  21. #ifndef SCARD_S_SUCCESS
  22. #include "SCardErr.h"
  23. #endif
  24. #ifdef __cplusplus
  25. extern "C" {
  26. #endif
  27. #ifndef _LPCBYTE_DEFINED
  28. #define _LPCBYTE_DEFINED
  29. typedef const BYTE *LPCBYTE;
  30. #endif
  31. #ifndef _LPCVOID_DEFINED
  32. #define _LPCVOID_DEFINED
  33. typedef const VOID *LPCVOID;
  34. #endif
  35. #ifndef WINSCARDAPI
  36. #define WINSCARDAPI
  37. #endif
  38. #ifndef WINSCARDDATA
  39. #define WINSCARDDATA __declspec(dllimport)
  40. #endif
  41. WINSCARDDATA extern const SCARD_IO_REQUEST
  42. g_rgSCardT0Pci,
  43. g_rgSCardT1Pci,
  44. g_rgSCardRawPci;
  45. #define SCARD_PCI_T0 (&g_rgSCardT0Pci)
  46. #define SCARD_PCI_T1 (&g_rgSCardT1Pci)
  47. #define SCARD_PCI_RAW (&g_rgSCardRawPci)
  48. //
  49. ////////////////////////////////////////////////////////////////////////////////
  50. //
  51. // Service Manager Access Services
  52. //
  53. // The following services are used to manage user and terminal contexts for
  54. // Smart Cards.
  55. //
  56. typedef ULONG_PTR SCARDCONTEXT;
  57. typedef SCARDCONTEXT *PSCARDCONTEXT, *LPSCARDCONTEXT;
  58. typedef ULONG_PTR SCARDHANDLE;
  59. typedef SCARDHANDLE *PSCARDHANDLE, *LPSCARDHANDLE;
  60. #define SCARD_AUTOALLOCATE (DWORD)(-1)
  61. #define SCARD_SCOPE_USER 0 // The context is a user context, and any
  62. // database operations are performed within the
  63. // domain of the user.
  64. #define SCARD_SCOPE_TERMINAL 1 // The context is that of the current terminal,
  65. // and any database operations are performed
  66. // within the domain of that terminal. (The
  67. // calling application must have appropriate
  68. // access permissions for any database actions.)
  69. #define SCARD_SCOPE_SYSTEM 2 // The context is the system context, and any
  70. // database operations are performed within the
  71. // domain of the system. (The calling
  72. // application must have appropriate access
  73. // permissions for any database actions.)
  74. extern WINSCARDAPI LONG WINAPI
  75. SCardEstablishContext(
  76. IN DWORD dwScope,
  77. IN LPCVOID pvReserved1,
  78. IN LPCVOID pvReserved2,
  79. OUT LPSCARDCONTEXT phContext);
  80. extern WINSCARDAPI LONG WINAPI
  81. SCardReleaseContext(
  82. IN SCARDCONTEXT hContext);
  83. extern WINSCARDAPI LONG WINAPI
  84. SCardIsValidContext(
  85. IN SCARDCONTEXT hContext);
  86. //
  87. ////////////////////////////////////////////////////////////////////////////////
  88. //
  89. // Smart Card Database Management Services
  90. //
  91. // The following services provide for managing the Smart Card Database.
  92. //
  93. #define SCARD_ALL_READERS TEXT("SCard$AllReaders\000")
  94. #define SCARD_DEFAULT_READERS TEXT("SCard$DefaultReaders\000")
  95. #define SCARD_LOCAL_READERS TEXT("SCard$LocalReaders\000")
  96. #define SCARD_SYSTEM_READERS TEXT("SCard$SystemReaders\000")
  97. #define SCARD_PROVIDER_PRIMARY 1 // Primary Provider Id
  98. #define SCARD_PROVIDER_CSP 2 // Crypto Service Provider Id
  99. //
  100. // Database Reader routines
  101. //
  102. extern WINSCARDAPI LONG WINAPI
  103. SCardListReaderGroupsA(
  104. IN SCARDCONTEXT hContext,
  105. OUT LPSTR mszGroups,
  106. IN OUT LPDWORD pcchGroups);
  107. extern WINSCARDAPI LONG WINAPI
  108. SCardListReaderGroupsW(
  109. IN SCARDCONTEXT hContext,
  110. OUT LPWSTR mszGroups,
  111. IN OUT LPDWORD pcchGroups);
  112. #ifdef UNICODE
  113. #define SCardListReaderGroups SCardListReaderGroupsW
  114. #else
  115. #define SCardListReaderGroups SCardListReaderGroupsA
  116. #endif // !UNICODE
  117. extern WINSCARDAPI LONG WINAPI
  118. SCardListReadersA(
  119. IN SCARDCONTEXT hContext,
  120. IN LPCSTR mszGroups,
  121. OUT LPSTR mszReaders,
  122. IN OUT LPDWORD pcchReaders);
  123. extern WINSCARDAPI LONG WINAPI
  124. SCardListReadersW(
  125. IN SCARDCONTEXT hContext,
  126. IN LPCWSTR mszGroups,
  127. OUT LPWSTR mszReaders,
  128. IN OUT LPDWORD pcchReaders);
  129. #ifdef UNICODE
  130. #define SCardListReaders SCardListReadersW
  131. #else
  132. #define SCardListReaders SCardListReadersA
  133. #endif // !UNICODE
  134. extern WINSCARDAPI LONG WINAPI
  135. SCardListCardsA(
  136. IN SCARDCONTEXT hContext,
  137. IN LPCBYTE pbAtr,
  138. IN LPCGUID rgquidInterfaces,
  139. IN DWORD cguidInterfaceCount,
  140. OUT LPSTR mszCards,
  141. IN OUT LPDWORD pcchCards);
  142. extern WINSCARDAPI LONG WINAPI
  143. SCardListCardsW(
  144. IN SCARDCONTEXT hContext,
  145. IN LPCBYTE pbAtr,
  146. IN LPCGUID rgquidInterfaces,
  147. IN DWORD cguidInterfaceCount,
  148. OUT LPWSTR mszCards,
  149. IN OUT LPDWORD pcchCards);
  150. #ifdef UNICODE
  151. #define SCardListCards SCardListCardsW
  152. #else
  153. #define SCardListCards SCardListCardsA
  154. #endif // !UNICODE
  155. //
  156. // NOTE: The routine SCardListCards name differs from the PC/SC definition.
  157. // It should be:
  158. //
  159. // extern WINSCARDAPI LONG WINAPI
  160. // SCardListCardTypes(
  161. // IN SCARDCONTEXT hContext,
  162. // IN LPCBYTE pbAtr,
  163. // IN LPCGUID rgquidInterfaces,
  164. // IN DWORD cguidInterfaceCount,
  165. // OUT LPTSTR mszCards,
  166. // IN OUT LPDWORD pcchCards);
  167. //
  168. // Here's a work-around MACRO:
  169. #define SCardListCardTypes SCardListCards
  170. extern WINSCARDAPI LONG WINAPI
  171. SCardListInterfacesA(
  172. IN SCARDCONTEXT hContext,
  173. IN LPCSTR szCard,
  174. OUT LPGUID pguidInterfaces,
  175. IN OUT LPDWORD pcguidInterfaces);
  176. extern WINSCARDAPI LONG WINAPI
  177. SCardListInterfacesW(
  178. IN SCARDCONTEXT hContext,
  179. IN LPCWSTR szCard,
  180. OUT LPGUID pguidInterfaces,
  181. IN OUT LPDWORD pcguidInterfaces);
  182. #ifdef UNICODE
  183. #define SCardListInterfaces SCardListInterfacesW
  184. #else
  185. #define SCardListInterfaces SCardListInterfacesA
  186. #endif // !UNICODE
  187. extern WINSCARDAPI LONG WINAPI
  188. SCardGetProviderIdA(
  189. IN SCARDCONTEXT hContext,
  190. IN LPCSTR szCard,
  191. OUT LPGUID pguidProviderId);
  192. extern WINSCARDAPI LONG WINAPI
  193. SCardGetProviderIdW(
  194. IN SCARDCONTEXT hContext,
  195. IN LPCWSTR szCard,
  196. OUT LPGUID pguidProviderId);
  197. #ifdef UNICODE
  198. #define SCardGetProviderId SCardGetProviderIdW
  199. #else
  200. #define SCardGetProviderId SCardGetProviderIdA
  201. #endif // !UNICODE
  202. //
  203. // NOTE: The routine SCardGetProviderId in this implementation uses GUIDs.
  204. // The PC/SC definition uses BYTEs.
  205. //
  206. extern WINSCARDAPI LONG WINAPI
  207. SCardGetCardTypeProviderNameA(
  208. IN SCARDCONTEXT hContext,
  209. IN LPCSTR szCardName,
  210. IN DWORD dwProviderId,
  211. OUT LPSTR szProvider,
  212. IN OUT LPDWORD pcchProvider);
  213. extern WINSCARDAPI LONG WINAPI
  214. SCardGetCardTypeProviderNameW(
  215. IN SCARDCONTEXT hContext,
  216. IN LPCWSTR szCardName,
  217. IN DWORD dwProviderId,
  218. OUT LPWSTR szProvider,
  219. IN OUT LPDWORD pcchProvider);
  220. #ifdef UNICODE
  221. #define SCardGetCardTypeProviderName SCardGetCardTypeProviderNameW
  222. #else
  223. #define SCardGetCardTypeProviderName SCardGetCardTypeProviderNameA
  224. #endif // !UNICODE
  225. //
  226. // NOTE: This routine is an extension to the PC/SC definitions.
  227. //
  228. //
  229. // Database Writer routines
  230. //
  231. extern WINSCARDAPI LONG WINAPI
  232. SCardIntroduceReaderGroupA(
  233. IN SCARDCONTEXT hContext,
  234. IN LPCSTR szGroupName);
  235. extern WINSCARDAPI LONG WINAPI
  236. SCardIntroduceReaderGroupW(
  237. IN SCARDCONTEXT hContext,
  238. IN LPCWSTR szGroupName);
  239. #ifdef UNICODE
  240. #define SCardIntroduceReaderGroup SCardIntroduceReaderGroupW
  241. #else
  242. #define SCardIntroduceReaderGroup SCardIntroduceReaderGroupA
  243. #endif // !UNICODE
  244. extern WINSCARDAPI LONG WINAPI
  245. SCardForgetReaderGroupA(
  246. IN SCARDCONTEXT hContext,
  247. IN LPCSTR szGroupName);
  248. extern WINSCARDAPI LONG WINAPI
  249. SCardForgetReaderGroupW(
  250. IN SCARDCONTEXT hContext,
  251. IN LPCWSTR szGroupName);
  252. #ifdef UNICODE
  253. #define SCardForgetReaderGroup SCardForgetReaderGroupW
  254. #else
  255. #define SCardForgetReaderGroup SCardForgetReaderGroupA
  256. #endif // !UNICODE
  257. extern WINSCARDAPI LONG WINAPI
  258. SCardIntroduceReaderA(
  259. IN SCARDCONTEXT hContext,
  260. IN LPCSTR szReaderName,
  261. IN LPCSTR szDeviceName);
  262. extern WINSCARDAPI LONG WINAPI
  263. SCardIntroduceReaderW(
  264. IN SCARDCONTEXT hContext,
  265. IN LPCWSTR szReaderName,
  266. IN LPCWSTR szDeviceName);
  267. #ifdef UNICODE
  268. #define SCardIntroduceReader SCardIntroduceReaderW
  269. #else
  270. #define SCardIntroduceReader SCardIntroduceReaderA
  271. #endif // !UNICODE
  272. extern WINSCARDAPI LONG WINAPI
  273. SCardForgetReaderA(
  274. IN SCARDCONTEXT hContext,
  275. IN LPCSTR szReaderName);
  276. extern WINSCARDAPI LONG WINAPI
  277. SCardForgetReaderW(
  278. IN SCARDCONTEXT hContext,
  279. IN LPCWSTR szReaderName);
  280. #ifdef UNICODE
  281. #define SCardForgetReader SCardForgetReaderW
  282. #else
  283. #define SCardForgetReader SCardForgetReaderA
  284. #endif // !UNICODE
  285. extern WINSCARDAPI LONG WINAPI
  286. SCardAddReaderToGroupA(
  287. IN SCARDCONTEXT hContext,
  288. IN LPCSTR szReaderName,
  289. IN LPCSTR szGroupName);
  290. extern WINSCARDAPI LONG WINAPI
  291. SCardAddReaderToGroupW(
  292. IN SCARDCONTEXT hContext,
  293. IN LPCWSTR szReaderName,
  294. IN LPCWSTR szGroupName);
  295. #ifdef UNICODE
  296. #define SCardAddReaderToGroup SCardAddReaderToGroupW
  297. #else
  298. #define SCardAddReaderToGroup SCardAddReaderToGroupA
  299. #endif // !UNICODE
  300. extern WINSCARDAPI LONG WINAPI
  301. SCardRemoveReaderFromGroupA(
  302. IN SCARDCONTEXT hContext,
  303. IN LPCSTR szReaderName,
  304. IN LPCSTR szGroupName);
  305. extern WINSCARDAPI LONG WINAPI
  306. SCardRemoveReaderFromGroupW(
  307. IN SCARDCONTEXT hContext,
  308. IN LPCWSTR szReaderName,
  309. IN LPCWSTR szGroupName);
  310. #ifdef UNICODE
  311. #define SCardRemoveReaderFromGroup SCardRemoveReaderFromGroupW
  312. #else
  313. #define SCardRemoveReaderFromGroup SCardRemoveReaderFromGroupA
  314. #endif // !UNICODE
  315. extern WINSCARDAPI LONG WINAPI
  316. SCardIntroduceCardTypeA(
  317. IN SCARDCONTEXT hContext,
  318. IN LPCSTR szCardName,
  319. IN LPCGUID pguidPrimaryProvider,
  320. IN LPCGUID rgguidInterfaces,
  321. IN DWORD dwInterfaceCount,
  322. IN LPCBYTE pbAtr,
  323. IN LPCBYTE pbAtrMask,
  324. IN DWORD cbAtrLen);
  325. extern WINSCARDAPI LONG WINAPI
  326. SCardIntroduceCardTypeW(
  327. IN SCARDCONTEXT hContext,
  328. IN LPCWSTR szCardName,
  329. IN LPCGUID pguidPrimaryProvider,
  330. IN LPCGUID rgguidInterfaces,
  331. IN DWORD dwInterfaceCount,
  332. IN LPCBYTE pbAtr,
  333. IN LPCBYTE pbAtrMask,
  334. IN DWORD cbAtrLen);
  335. #ifdef UNICODE
  336. #define SCardIntroduceCardType SCardIntroduceCardTypeW
  337. #else
  338. #define SCardIntroduceCardType SCardIntroduceCardTypeA
  339. #endif // !UNICODE
  340. //
  341. // NOTE: The routine SCardIntroduceCardType's parameters' order differs from
  342. // the PC/SC definition. It should be:
  343. //
  344. // extern WINSCARDAPI LONG WINAPI
  345. // SCardIntroduceCardType(
  346. // IN SCARDCONTEXT hContext,
  347. // IN LPCTSTR szCardName,
  348. // IN LPCBYTE pbAtr,
  349. // IN LPCBYTE pbAtrMask,
  350. // IN DWORD cbAtrLen,
  351. // IN LPCGUID pguidPrimaryProvider,
  352. // IN LPCGUID rgguidInterfaces,
  353. // IN DWORD dwInterfaceCount);
  354. //
  355. // Here's a work-around MACRO:
  356. #define PCSCardIntroduceCardType(hContext, szCardName, pbAtr, pbAtrMask, cbAtrLen, pguidPrimaryProvider, rgguidInterfaces, dwInterfaceCount) \
  357. SCardIntroduceCardType(hContext, szCardName, pguidPrimaryProvider, rgguidInterfaces, dwInterfaceCount, pbAtr, pbAtrMask, cbAtrLen)
  358. extern WINSCARDAPI LONG WINAPI
  359. SCardSetCardTypeProviderNameA(
  360. IN SCARDCONTEXT hContext,
  361. IN LPCSTR szCardName,
  362. IN DWORD dwProviderId,
  363. IN LPCSTR szProvider);
  364. extern WINSCARDAPI LONG WINAPI
  365. SCardSetCardTypeProviderNameW(
  366. IN SCARDCONTEXT hContext,
  367. IN LPCWSTR szCardName,
  368. IN DWORD dwProviderId,
  369. IN LPCWSTR szProvider);
  370. #ifdef UNICODE
  371. #define SCardSetCardTypeProviderName SCardSetCardTypeProviderNameW
  372. #else
  373. #define SCardSetCardTypeProviderName SCardSetCardTypeProviderNameA
  374. #endif // !UNICODE
  375. //
  376. // NOTE: This routine is an extention to the PC/SC specifications.
  377. //
  378. extern WINSCARDAPI LONG WINAPI
  379. SCardForgetCardTypeA(
  380. IN SCARDCONTEXT hContext,
  381. IN LPCSTR szCardName);
  382. extern WINSCARDAPI LONG WINAPI
  383. SCardForgetCardTypeW(
  384. IN SCARDCONTEXT hContext,
  385. IN LPCWSTR szCardName);
  386. #ifdef UNICODE
  387. #define SCardForgetCardType SCardForgetCardTypeW
  388. #else
  389. #define SCardForgetCardType SCardForgetCardTypeA
  390. #endif // !UNICODE
  391. //
  392. ////////////////////////////////////////////////////////////////////////////////
  393. //
  394. // Service Manager Support Routines
  395. //
  396. // The following services are supplied to simplify the use of the Service
  397. // Manager API.
  398. //
  399. extern WINSCARDAPI LONG WINAPI
  400. SCardFreeMemory(
  401. IN SCARDCONTEXT hContext,
  402. IN LPCVOID pvMem);
  403. extern WINSCARDAPI HANDLE WINAPI
  404. SCardAccessStartedEvent(void);
  405. extern WINSCARDAPI void WINAPI
  406. SCardReleaseStartedEvent(void);
  407. //
  408. ////////////////////////////////////////////////////////////////////////////////
  409. //
  410. // Reader Services
  411. //
  412. // The following services supply means for tracking cards within readers.
  413. //
  414. typedef struct {
  415. LPCSTR szReader; // reader name
  416. LPVOID pvUserData; // user defined data
  417. DWORD dwCurrentState; // current state of reader at time of call
  418. DWORD dwEventState; // state of reader after state change
  419. DWORD cbAtr; // Number of bytes in the returned ATR.
  420. BYTE rgbAtr[36]; // Atr of inserted card, (extra alignment bytes)
  421. } SCARD_READERSTATEA, *PSCARD_READERSTATEA, *LPSCARD_READERSTATEA;
  422. typedef struct {
  423. LPCWSTR szReader; // reader name
  424. LPVOID pvUserData; // user defined data
  425. DWORD dwCurrentState; // current state of reader at time of call
  426. DWORD dwEventState; // state of reader after state change
  427. DWORD cbAtr; // Number of bytes in the returned ATR.
  428. BYTE rgbAtr[36]; // Atr of inserted card, (extra alignment bytes)
  429. } SCARD_READERSTATEW, *PSCARD_READERSTATEW, *LPSCARD_READERSTATEW;
  430. #ifdef UNICODE
  431. typedef SCARD_READERSTATEW SCARD_READERSTATE;
  432. typedef PSCARD_READERSTATEW PSCARD_READERSTATE;
  433. typedef LPSCARD_READERSTATEW LPSCARD_READERSTATE;
  434. #else
  435. typedef SCARD_READERSTATEA SCARD_READERSTATE;
  436. typedef PSCARD_READERSTATEA PSCARD_READERSTATE;
  437. typedef LPSCARD_READERSTATEA LPSCARD_READERSTATE;
  438. #endif // UNICODE
  439. // Backwards compatibility macros
  440. #define SCARD_READERSTATE_A SCARD_READERSTATEA
  441. #define SCARD_READERSTATE_W SCARD_READERSTATEW
  442. #define PSCARD_READERSTATE_A PSCARD_READERSTATEA
  443. #define PSCARD_READERSTATE_W PSCARD_READERSTATEW
  444. #define LPSCARD_READERSTATE_A LPSCARD_READERSTATEA
  445. #define LPSCARD_READERSTATE_W LPSCARD_READERSTATEW
  446. #define SCARD_STATE_UNAWARE 0x00000000 // The application is unaware of the
  447. // current state, and would like to
  448. // know. The use of this value
  449. // results in an immediate return
  450. // from state transition monitoring
  451. // services. This is represented by
  452. // all bits set to zero.
  453. #define SCARD_STATE_IGNORE 0x00000001 // The application requested that
  454. // this reader be ignored. No other
  455. // bits will be set.
  456. #define SCARD_STATE_CHANGED 0x00000002 // This implies that there is a
  457. // difference between the state
  458. // believed by the application, and
  459. // the state known by the Service
  460. // Manager. When this bit is set,
  461. // the application may assume a
  462. // significant state change has
  463. // occurred on this reader.
  464. #define SCARD_STATE_UNKNOWN 0x00000004 // This implies that the given
  465. // reader name is not recognized by
  466. // the Service Manager. If this bit
  467. // is set, then SCARD_STATE_CHANGED
  468. // and SCARD_STATE_IGNORE will also
  469. // be set.
  470. #define SCARD_STATE_UNAVAILABLE 0x00000008 // This implies that the actual
  471. // state of this reader is not
  472. // available. If this bit is set,
  473. // then all the following bits are
  474. // clear.
  475. #define SCARD_STATE_EMPTY 0x00000010 // This implies that there is not
  476. // card in the reader. If this bit
  477. // is set, all the following bits
  478. // will be clear.
  479. #define SCARD_STATE_PRESENT 0x00000020 // This implies that there is a card
  480. // in the reader.
  481. #define SCARD_STATE_ATRMATCH 0x00000040 // This implies that there is a card
  482. // in the reader with an ATR
  483. // matching one of the target cards.
  484. // If this bit is set,
  485. // SCARD_STATE_PRESENT will also be
  486. // set. This bit is only returned
  487. // on the SCardLocateCard() service.
  488. #define SCARD_STATE_EXCLUSIVE 0x00000080 // This implies that the card in the
  489. // reader is allocated for exclusive
  490. // use by another application. If
  491. // this bit is set,
  492. // SCARD_STATE_PRESENT will also be
  493. // set.
  494. #define SCARD_STATE_INUSE 0x00000100 // This implies that the card in the
  495. // reader is in use by one or more
  496. // other applications, but may be
  497. // connected to in shared mode. If
  498. // this bit is set,
  499. // SCARD_STATE_PRESENT will also be
  500. // set.
  501. #define SCARD_STATE_MUTE 0x00000200 // This implies that the card in the
  502. // reader is unresponsive or not
  503. // supported by the reader or
  504. // software.
  505. #define SCARD_STATE_UNPOWERED 0x00000400 // This implies that the card in the
  506. // reader has not been powered up.
  507. extern WINSCARDAPI LONG WINAPI
  508. SCardLocateCardsA(
  509. IN SCARDCONTEXT hContext,
  510. IN LPCSTR mszCards,
  511. IN OUT LPSCARD_READERSTATEA rgReaderStates,
  512. IN DWORD cReaders);
  513. extern WINSCARDAPI LONG WINAPI
  514. SCardLocateCardsW(
  515. IN SCARDCONTEXT hContext,
  516. IN LPCWSTR mszCards,
  517. IN OUT LPSCARD_READERSTATEW rgReaderStates,
  518. IN DWORD cReaders);
  519. #ifdef UNICODE
  520. #define SCardLocateCards SCardLocateCardsW
  521. #else
  522. #define SCardLocateCards SCardLocateCardsA
  523. #endif // !UNICODE
  524. typedef struct _SCARD_ATRMASK {
  525. DWORD cbAtr; // Number of bytes in the ATR and the mask.
  526. BYTE rgbAtr[36]; // Atr of card (extra alignment bytes)
  527. BYTE rgbMask[36]; // Mask for the Atr (extra alignment bytes)
  528. } SCARD_ATRMASK, *PSCARD_ATRMASK, *LPSCARD_ATRMASK;
  529. extern WINSCARDAPI LONG WINAPI
  530. SCardLocateCardsByATRA(
  531. IN SCARDCONTEXT hContext,
  532. IN LPSCARD_ATRMASK rgAtrMasks,
  533. IN DWORD cAtrs,
  534. IN OUT LPSCARD_READERSTATEA rgReaderStates,
  535. IN DWORD cReaders);
  536. extern WINSCARDAPI LONG WINAPI
  537. SCardLocateCardsByATRW(
  538. IN SCARDCONTEXT hContext,
  539. IN LPSCARD_ATRMASK rgAtrMasks,
  540. IN DWORD cAtrs,
  541. IN OUT LPSCARD_READERSTATEW rgReaderStates,
  542. IN DWORD cReaders);
  543. #ifdef UNICODE
  544. #define SCardLocateCardsByATR SCardLocateCardsByATRW
  545. #else
  546. #define SCardLocateCardsByATR SCardLocateCardsByATRA
  547. #endif // !UNICODE
  548. extern WINSCARDAPI LONG WINAPI
  549. SCardGetStatusChangeA(
  550. IN SCARDCONTEXT hContext,
  551. IN DWORD dwTimeout,
  552. IN OUT LPSCARD_READERSTATEA rgReaderStates,
  553. IN DWORD cReaders);
  554. extern WINSCARDAPI LONG WINAPI
  555. SCardGetStatusChangeW(
  556. IN SCARDCONTEXT hContext,
  557. IN DWORD dwTimeout,
  558. IN OUT LPSCARD_READERSTATEW rgReaderStates,
  559. IN DWORD cReaders);
  560. #ifdef UNICODE
  561. #define SCardGetStatusChange SCardGetStatusChangeW
  562. #else
  563. #define SCardGetStatusChange SCardGetStatusChangeA
  564. #endif // !UNICODE
  565. extern WINSCARDAPI LONG WINAPI
  566. SCardCancel(
  567. IN SCARDCONTEXT hContext);
  568. //
  569. ////////////////////////////////////////////////////////////////////////////////
  570. //
  571. // Card/Reader Communication Services
  572. //
  573. // The following services provide means for communication with the card.
  574. //
  575. #define SCARD_SHARE_EXCLUSIVE 1 // This application is not willing to share this
  576. // card with other applications.
  577. #define SCARD_SHARE_SHARED 2 // This application is willing to share this
  578. // card with other applications.
  579. #define SCARD_SHARE_DIRECT 3 // This application demands direct control of
  580. // the reader, so it is not available to other
  581. // applications.
  582. #define SCARD_LEAVE_CARD 0 // Don't do anything special on close
  583. #define SCARD_RESET_CARD 1 // Reset the card on close
  584. #define SCARD_UNPOWER_CARD 2 // Power down the card on close
  585. #define SCARD_EJECT_CARD 3 // Eject the card on close
  586. extern WINSCARDAPI LONG WINAPI
  587. SCardConnectA(
  588. IN SCARDCONTEXT hContext,
  589. IN LPCSTR szReader,
  590. IN DWORD dwShareMode,
  591. IN DWORD dwPreferredProtocols,
  592. OUT LPSCARDHANDLE phCard,
  593. OUT LPDWORD pdwActiveProtocol);
  594. extern WINSCARDAPI LONG WINAPI
  595. SCardConnectW(
  596. IN SCARDCONTEXT hContext,
  597. IN LPCWSTR szReader,
  598. IN DWORD dwShareMode,
  599. IN DWORD dwPreferredProtocols,
  600. OUT LPSCARDHANDLE phCard,
  601. OUT LPDWORD pdwActiveProtocol);
  602. #ifdef UNICODE
  603. #define SCardConnect SCardConnectW
  604. #else
  605. #define SCardConnect SCardConnectA
  606. #endif // !UNICODE
  607. extern WINSCARDAPI LONG WINAPI
  608. SCardReconnect(
  609. IN SCARDHANDLE hCard,
  610. IN DWORD dwShareMode,
  611. IN DWORD dwPreferredProtocols,
  612. IN DWORD dwInitialization,
  613. OUT LPDWORD pdwActiveProtocol);
  614. extern WINSCARDAPI LONG WINAPI
  615. SCardDisconnect(
  616. IN SCARDHANDLE hCard,
  617. IN DWORD dwDisposition);
  618. extern WINSCARDAPI LONG WINAPI
  619. SCardBeginTransaction(
  620. IN SCARDHANDLE hCard);
  621. extern WINSCARDAPI LONG WINAPI
  622. SCardEndTransaction(
  623. IN SCARDHANDLE hCard,
  624. IN DWORD dwDisposition);
  625. extern WINSCARDAPI LONG WINAPI
  626. SCardCancelTransaction(
  627. IN SCARDHANDLE hCard);
  628. //
  629. // NOTE: This call corresponds to the PC/SC SCARDCOMM::Cancel routine,
  630. // terminating a blocked SCardBeginTransaction service.
  631. //
  632. extern WINSCARDAPI LONG WINAPI
  633. SCardState(
  634. IN SCARDHANDLE hCard,
  635. OUT LPDWORD pdwState,
  636. OUT LPDWORD pdwProtocol,
  637. OUT LPBYTE pbAtr,
  638. IN OUT LPDWORD pcbAtrLen);
  639. //
  640. // NOTE: SCardState is an obsolete routine. PC/SC has replaced it with
  641. // SCardStatus.
  642. //
  643. extern WINSCARDAPI LONG WINAPI
  644. SCardStatusA(
  645. IN SCARDHANDLE hCard,
  646. OUT LPSTR szReaderName,
  647. IN OUT LPDWORD pcchReaderLen,
  648. OUT LPDWORD pdwState,
  649. OUT LPDWORD pdwProtocol,
  650. OUT LPBYTE pbAtr,
  651. IN OUT LPDWORD pcbAtrLen);
  652. extern WINSCARDAPI LONG WINAPI
  653. SCardStatusW(
  654. IN SCARDHANDLE hCard,
  655. OUT LPWSTR szReaderName,
  656. IN OUT LPDWORD pcchReaderLen,
  657. OUT LPDWORD pdwState,
  658. OUT LPDWORD pdwProtocol,
  659. OUT LPBYTE pbAtr,
  660. IN OUT LPDWORD pcbAtrLen);
  661. #ifdef UNICODE
  662. #define SCardStatus SCardStatusW
  663. #else
  664. #define SCardStatus SCardStatusA
  665. #endif // !UNICODE
  666. extern WINSCARDAPI LONG WINAPI
  667. SCardTransmit(
  668. IN SCARDHANDLE hCard,
  669. IN LPCSCARD_IO_REQUEST pioSendPci,
  670. IN LPCBYTE pbSendBuffer,
  671. IN DWORD cbSendLength,
  672. IN OUT LPSCARD_IO_REQUEST pioRecvPci,
  673. OUT LPBYTE pbRecvBuffer,
  674. IN OUT LPDWORD pcbRecvLength);
  675. //
  676. ////////////////////////////////////////////////////////////////////////////////
  677. //
  678. // Reader Control Routines
  679. //
  680. // The following services provide for direct, low-level manipulation of the
  681. // reader by the calling application allowing it control over the
  682. // attributes of the communications with the card.
  683. //
  684. extern WINSCARDAPI LONG WINAPI
  685. SCardControl(
  686. IN SCARDHANDLE hCard,
  687. IN DWORD dwControlCode,
  688. IN LPCVOID lpInBuffer,
  689. IN DWORD nInBufferSize,
  690. OUT LPVOID lpOutBuffer,
  691. IN DWORD nOutBufferSize,
  692. OUT LPDWORD lpBytesReturned);
  693. extern WINSCARDAPI LONG WINAPI
  694. SCardGetAttrib(
  695. IN SCARDHANDLE hCard,
  696. IN DWORD dwAttrId,
  697. OUT LPBYTE pbAttr,
  698. IN OUT LPDWORD pcbAttrLen);
  699. //
  700. // NOTE: The routine SCardGetAttrib's name differs from the PC/SC definition.
  701. // It should be:
  702. //
  703. // extern WINSCARDAPI LONG WINAPI
  704. // SCardGetReaderCapabilities(
  705. // IN SCARDHANDLE hCard,
  706. // IN DWORD dwTag,
  707. // OUT LPBYTE pbAttr,
  708. // IN OUT LPDWORD pcbAttrLen);
  709. //
  710. // Here's a work-around MACRO:
  711. #define SCardGetReaderCapabilities SCardGetAttrib
  712. extern WINSCARDAPI LONG WINAPI
  713. SCardSetAttrib(
  714. IN SCARDHANDLE hCard,
  715. IN DWORD dwAttrId,
  716. IN LPCBYTE pbAttr,
  717. IN DWORD cbAttrLen);
  718. //
  719. // NOTE: The routine SCardSetAttrib's name differs from the PC/SC definition.
  720. // It should be:
  721. //
  722. // extern WINSCARDAPI LONG WINAPI
  723. // SCardSetReaderCapabilities(
  724. // IN SCARDHANDLE hCard,
  725. // IN DWORD dwTag,
  726. // OUT LPBYTE pbAttr,
  727. // IN OUT LPDWORD pcbAttrLen);
  728. //
  729. // Here's a work-around MACRO:
  730. #define SCardSetReaderCapabilities SCardSetAttrib
  731. //
  732. ////////////////////////////////////////////////////////////////////////////////
  733. //
  734. // Smart Card Dialog definitions
  735. //
  736. // The following section contains structures and exported function
  737. // declarations for the Smart Card Common Dialog dialog.
  738. //
  739. // Defined constants
  740. // Flags
  741. #define SC_DLG_MINIMAL_UI 0x01
  742. #define SC_DLG_NO_UI 0x02
  743. #define SC_DLG_FORCE_UI 0x04
  744. #define SCERR_NOCARDNAME 0x4000
  745. #define SCERR_NOGUIDS 0x8000
  746. typedef SCARDHANDLE (WINAPI *LPOCNCONNPROCA) (IN SCARDCONTEXT, IN LPSTR, IN LPSTR, IN PVOID);
  747. typedef SCARDHANDLE (WINAPI *LPOCNCONNPROCW) (IN SCARDCONTEXT, IN LPWSTR, IN LPWSTR, IN PVOID);
  748. #ifdef UNICODE
  749. #define LPOCNCONNPROC LPOCNCONNPROCW
  750. #else
  751. #define LPOCNCONNPROC LPOCNCONNPROCA
  752. #endif // !UNICODE
  753. typedef BOOL (WINAPI *LPOCNCHKPROC) (IN SCARDCONTEXT, IN SCARDHANDLE, IN PVOID);
  754. typedef void (WINAPI *LPOCNDSCPROC) (IN SCARDCONTEXT, IN SCARDHANDLE, IN PVOID);
  755. //
  756. // OPENCARD_SEARCH_CRITERIA: In order to specify a user-extended search,
  757. // lpfnCheck must not be NULL. Moreover, the connection to be made to the
  758. // card before performing the callback must be indicated by either providing
  759. // lpfnConnect and lpfnDisconnect OR by setting dwShareMode.
  760. // If both the connection callbacks and dwShareMode are non-NULL, the callbacks
  761. // will be used.
  762. //
  763. typedef struct {
  764. DWORD dwStructSize;
  765. LPSTR lpstrGroupNames; // OPTIONAL reader groups to include in
  766. DWORD nMaxGroupNames; // search. NULL defaults to
  767. // SCard$DefaultReaders
  768. LPCGUID rgguidInterfaces; // OPTIONAL requested interfaces
  769. DWORD cguidInterfaces; // supported by card's SSP
  770. LPSTR lpstrCardNames; // OPTIONAL requested card names; all cards w/
  771. DWORD nMaxCardNames; // matching ATRs will be accepted
  772. LPOCNCHKPROC lpfnCheck; // OPTIONAL if NULL no user check will be performed.
  773. LPOCNCONNPROCA lpfnConnect; // OPTIONAL if lpfnConnect is provided,
  774. LPOCNDSCPROC lpfnDisconnect; // lpfnDisconnect must also be set.
  775. LPVOID pvUserData; // OPTIONAL parameter to callbacks
  776. DWORD dwShareMode; // OPTIONAL must be set if lpfnCheck is not null
  777. DWORD dwPreferredProtocols; // OPTIONAL
  778. } OPENCARD_SEARCH_CRITERIAA, *POPENCARD_SEARCH_CRITERIAA, *LPOPENCARD_SEARCH_CRITERIAA;
  779. typedef struct {
  780. DWORD dwStructSize;
  781. LPWSTR lpstrGroupNames; // OPTIONAL reader groups to include in
  782. DWORD nMaxGroupNames; // search. NULL defaults to
  783. // SCard$DefaultReaders
  784. LPCGUID rgguidInterfaces; // OPTIONAL requested interfaces
  785. DWORD cguidInterfaces; // supported by card's SSP
  786. LPWSTR lpstrCardNames; // OPTIONAL requested card names; all cards w/
  787. DWORD nMaxCardNames; // matching ATRs will be accepted
  788. LPOCNCHKPROC lpfnCheck; // OPTIONAL if NULL no user check will be performed.
  789. LPOCNCONNPROCW lpfnConnect; // OPTIONAL if lpfnConnect is provided,
  790. LPOCNDSCPROC lpfnDisconnect; // lpfnDisconnect must also be set.
  791. LPVOID pvUserData; // OPTIONAL parameter to callbacks
  792. DWORD dwShareMode; // OPTIONAL must be set if lpfnCheck is not null
  793. DWORD dwPreferredProtocols; // OPTIONAL
  794. } OPENCARD_SEARCH_CRITERIAW, *POPENCARD_SEARCH_CRITERIAW, *LPOPENCARD_SEARCH_CRITERIAW;
  795. #ifdef UNICODE
  796. typedef OPENCARD_SEARCH_CRITERIAW OPENCARD_SEARCH_CRITERIA;
  797. typedef POPENCARD_SEARCH_CRITERIAW POPENCARD_SEARCH_CRITERIA;
  798. typedef LPOPENCARD_SEARCH_CRITERIAW LPOPENCARD_SEARCH_CRITERIA;
  799. #else
  800. typedef OPENCARD_SEARCH_CRITERIAA OPENCARD_SEARCH_CRITERIA;
  801. typedef POPENCARD_SEARCH_CRITERIAA POPENCARD_SEARCH_CRITERIA;
  802. typedef LPOPENCARD_SEARCH_CRITERIAA LPOPENCARD_SEARCH_CRITERIA;
  803. #endif // UNICODE
  804. //
  805. // OPENCARDNAME_EX: used by SCardUIDlgSelectCard; replaces obsolete OPENCARDNAME
  806. //
  807. typedef struct {
  808. DWORD dwStructSize; // REQUIRED
  809. SCARDCONTEXT hSCardContext; // REQUIRED
  810. HWND hwndOwner; // OPTIONAL
  811. DWORD dwFlags; // OPTIONAL -- default is SC_DLG_MINIMAL_UI
  812. LPCSTR lpstrTitle; // OPTIONAL
  813. LPCSTR lpstrSearchDesc; // OPTIONAL (eg. "Please insert your <brandname> smart card.")
  814. HICON hIcon; // OPTIONAL 32x32 icon for your brand insignia
  815. POPENCARD_SEARCH_CRITERIAA pOpenCardSearchCriteria; // OPTIONAL
  816. LPOCNCONNPROCA lpfnConnect; // OPTIONAL - performed on successful selection
  817. LPVOID pvUserData; // OPTIONAL parameter to lpfnConnect
  818. DWORD dwShareMode; // OPTIONAL - if lpfnConnect is NULL, dwShareMode and
  819. DWORD dwPreferredProtocols; // OPTIONAL dwPreferredProtocols will be used to
  820. // connect to the selected card
  821. LPSTR lpstrRdr; // REQUIRED [IN|OUT] Name of selected reader
  822. DWORD nMaxRdr; // REQUIRED [IN|OUT]
  823. LPSTR lpstrCard; // REQUIRED [IN|OUT] Name of selected card
  824. DWORD nMaxCard; // REQUIRED [IN|OUT]
  825. DWORD dwActiveProtocol; // [OUT] set only if dwShareMode not NULL
  826. SCARDHANDLE hCardHandle; // [OUT] set if a card connection was indicated
  827. } OPENCARDNAME_EXA, *POPENCARDNAME_EXA, *LPOPENCARDNAME_EXA;
  828. typedef struct {
  829. DWORD dwStructSize; // REQUIRED
  830. SCARDCONTEXT hSCardContext; // REQUIRED
  831. HWND hwndOwner; // OPTIONAL
  832. DWORD dwFlags; // OPTIONAL -- default is SC_DLG_MINIMAL_UI
  833. LPCWSTR lpstrTitle; // OPTIONAL
  834. LPCWSTR lpstrSearchDesc; // OPTIONAL (eg. "Please insert your <brandname> smart card.")
  835. HICON hIcon; // OPTIONAL 32x32 icon for your brand insignia
  836. POPENCARD_SEARCH_CRITERIAW pOpenCardSearchCriteria; // OPTIONAL
  837. LPOCNCONNPROCW lpfnConnect; // OPTIONAL - performed on successful selection
  838. LPVOID pvUserData; // OPTIONAL parameter to lpfnConnect
  839. DWORD dwShareMode; // OPTIONAL - if lpfnConnect is NULL, dwShareMode and
  840. DWORD dwPreferredProtocols; // OPTIONAL dwPreferredProtocols will be used to
  841. // connect to the selected card
  842. LPWSTR lpstrRdr; // REQUIRED [IN|OUT] Name of selected reader
  843. DWORD nMaxRdr; // REQUIRED [IN|OUT]
  844. LPWSTR lpstrCard; // REQUIRED [IN|OUT] Name of selected card
  845. DWORD nMaxCard; // REQUIRED [IN|OUT]
  846. DWORD dwActiveProtocol; // [OUT] set only if dwShareMode not NULL
  847. SCARDHANDLE hCardHandle; // [OUT] set if a card connection was indicated
  848. } OPENCARDNAME_EXW, *POPENCARDNAME_EXW, *LPOPENCARDNAME_EXW;
  849. #ifdef UNICODE
  850. typedef OPENCARDNAME_EXW OPENCARDNAME_EX;
  851. typedef POPENCARDNAME_EXW POPENCARDNAME_EX;
  852. typedef LPOPENCARDNAME_EXW LPOPENCARDNAME_EX;
  853. #else
  854. typedef OPENCARDNAME_EXA OPENCARDNAME_EX;
  855. typedef POPENCARDNAME_EXA POPENCARDNAME_EX;
  856. typedef LPOPENCARDNAME_EXA LPOPENCARDNAME_EX;
  857. #endif // UNICODE
  858. #define OPENCARDNAMEA_EX OPENCARDNAME_EXA
  859. #define OPENCARDNAMEW_EX OPENCARDNAME_EXW
  860. #define POPENCARDNAMEA_EX POPENCARDNAME_EXA
  861. #define POPENCARDNAMEW_EX POPENCARDNAME_EXW
  862. #define LPOPENCARDNAMEA_EX LPOPENCARDNAME_EXA
  863. #define LPOPENCARDNAMEW_EX LPOPENCARDNAME_EXW
  864. //
  865. // SCardUIDlgSelectCard replaces GetOpenCardName
  866. //
  867. extern WINSCARDAPI LONG WINAPI
  868. SCardUIDlgSelectCardA(
  869. LPOPENCARDNAMEA_EX);
  870. extern WINSCARDAPI LONG WINAPI
  871. SCardUIDlgSelectCardW(
  872. LPOPENCARDNAMEW_EX);
  873. #ifdef UNICODE
  874. #define SCardUIDlgSelectCard SCardUIDlgSelectCardW
  875. #else
  876. #define SCardUIDlgSelectCard SCardUIDlgSelectCardA
  877. #endif // !UNICODE
  878. //
  879. // "Smart Card Common Dialog" definitions for backwards compatibility
  880. // with the Smart Card Base Services SDK version 1.0
  881. //
  882. typedef struct {
  883. DWORD dwStructSize;
  884. HWND hwndOwner;
  885. SCARDCONTEXT hSCardContext;
  886. LPSTR lpstrGroupNames;
  887. DWORD nMaxGroupNames;
  888. LPSTR lpstrCardNames;
  889. DWORD nMaxCardNames;
  890. LPCGUID rgguidInterfaces;
  891. DWORD cguidInterfaces;
  892. LPSTR lpstrRdr;
  893. DWORD nMaxRdr;
  894. LPSTR lpstrCard;
  895. DWORD nMaxCard;
  896. LPCSTR lpstrTitle;
  897. DWORD dwFlags;
  898. LPVOID pvUserData;
  899. DWORD dwShareMode;
  900. DWORD dwPreferredProtocols;
  901. DWORD dwActiveProtocol;
  902. LPOCNCONNPROCA lpfnConnect;
  903. LPOCNCHKPROC lpfnCheck;
  904. LPOCNDSCPROC lpfnDisconnect;
  905. SCARDHANDLE hCardHandle;
  906. } OPENCARDNAMEA, *POPENCARDNAMEA, *LPOPENCARDNAMEA;
  907. typedef struct {
  908. DWORD dwStructSize;
  909. HWND hwndOwner;
  910. SCARDCONTEXT hSCardContext;
  911. LPWSTR lpstrGroupNames;
  912. DWORD nMaxGroupNames;
  913. LPWSTR lpstrCardNames;
  914. DWORD nMaxCardNames;
  915. LPCGUID rgguidInterfaces;
  916. DWORD cguidInterfaces;
  917. LPWSTR lpstrRdr;
  918. DWORD nMaxRdr;
  919. LPWSTR lpstrCard;
  920. DWORD nMaxCard;
  921. LPCWSTR lpstrTitle;
  922. DWORD dwFlags;
  923. LPVOID pvUserData;
  924. DWORD dwShareMode;
  925. DWORD dwPreferredProtocols;
  926. DWORD dwActiveProtocol;
  927. LPOCNCONNPROCW lpfnConnect;
  928. LPOCNCHKPROC lpfnCheck;
  929. LPOCNDSCPROC lpfnDisconnect;
  930. SCARDHANDLE hCardHandle;
  931. } OPENCARDNAMEW, *POPENCARDNAMEW, *LPOPENCARDNAMEW;
  932. #ifdef UNICODE
  933. typedef OPENCARDNAMEW OPENCARDNAME;
  934. typedef POPENCARDNAMEW POPENCARDNAME;
  935. typedef LPOPENCARDNAMEW LPOPENCARDNAME;
  936. #else
  937. typedef OPENCARDNAMEA OPENCARDNAME;
  938. typedef POPENCARDNAMEA POPENCARDNAME;
  939. typedef LPOPENCARDNAMEA LPOPENCARDNAME;
  940. #endif // UNICODE
  941. // Backwards compatibility macros
  942. #define OPENCARDNAME_A OPENCARDNAMEA
  943. #define OPENCARDNAME_W OPENCARDNAMEW
  944. #define POPENCARDNAME_A POPENCARDNAMEA
  945. #define POPENCARDNAME_W POPENCARDNAMEW
  946. #define LPOPENCARDNAME_A LPOPENCARDNAMEA
  947. #define LPOPENCARDNAME_W LPOPENCARDNAMEW
  948. extern WINSCARDAPI LONG WINAPI
  949. GetOpenCardNameA(
  950. LPOPENCARDNAMEA);
  951. extern WINSCARDAPI LONG WINAPI
  952. GetOpenCardNameW(
  953. LPOPENCARDNAMEW);
  954. #ifdef UNICODE
  955. #define GetOpenCardName GetOpenCardNameW
  956. #else
  957. #define GetOpenCardName GetOpenCardNameA
  958. #endif // !UNICODE
  959. extern WINSCARDAPI LONG WINAPI
  960. SCardDlgExtendedError (void);
  961. #ifdef __cplusplus
  962. }
  963. #endif
  964. #endif // _WINSCARD_H_