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.

330 lines
13 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. winsmcrd.h
  5. Abstract:
  6. Smart Card class/port IOCTL codes. This file is required for all code
  7. user mode and kernel mode, using Smart Card IOCTL's, defines,
  8. data structures
  9. Revision History:
  10. --*/
  11. #ifndef _NTDDSCRD_H2_
  12. #define _NTDDSCRD_H2_
  13. #if defined (_MSC_VER) && (_MSC_VER >= 1020)
  14. #pragma once
  15. #endif
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. #ifdef _WINSCARD_H_
  20. typedef DWORD ULONG;
  21. typedef WORD UWORD;
  22. typedef BYTE UCHAR;
  23. #else
  24. typedef ULONG DWORD;
  25. // typedef UWORD WORD;
  26. typedef UCHAR BYTE;
  27. #endif
  28. #ifndef DEVICE_TYPE_SMARTCARD
  29. #define FILE_DEVICE_SMARTCARD 0x00000031
  30. #else
  31. #if 0x00000031 != FILE_DEVICE_SMARTCARD
  32. #error "Incorrect Smart Card Device Definition"
  33. #endif
  34. #endif
  35. //
  36. // Various constants
  37. //
  38. #define SCARD_ATR_LENGTH 33 // ISO 7816-3 spec.
  39. //
  40. ///////////////////////////////////////////////////////////////////////////////
  41. //
  42. // Protocol Flag definitions
  43. //
  44. #define SCARD_PROTOCOL_UNDEFINED 0x00000000 // There is no active protocol.
  45. #define SCARD_PROTOCOL_T0 0x00000001 // T=0 is the active protocol.
  46. #define SCARD_PROTOCOL_T1 0x00000002 // T=1 is the active protocol.
  47. #define SCARD_PROTOCOL_RAW 0x00010000 // Raw is the active protocol.
  48. //
  49. // This is the mask of ISO defined transmission protocols
  50. //
  51. #define SCARD_PROTOCOL_Tx (SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1)
  52. //
  53. // Use the default transmission parameters / card clock freq.
  54. //
  55. #define SCARD_PROTOCOL_DEFAULT 0x80000000
  56. //
  57. // Use optimal transmission parameters / card clock freq.
  58. // Since using the optimal parameters is the default case no bit is defined to be 1
  59. //
  60. #define SCARD_PROTOCOL_OPTIMAL 0x00000000
  61. //
  62. // Ioctl parameters 1 for IOCTL_SMARTCARD_POWER
  63. //
  64. #define SCARD_POWER_DOWN 0 // Power down the card.
  65. #define SCARD_COLD_RESET 1 // Cycle power and reset the card.
  66. #define SCARD_WARM_RESET 2 // Force a reset on the card.
  67. //
  68. ///////////////////////////////////////////////////////////////////////////////
  69. //
  70. // Reader Action IOCTLs
  71. //
  72. #define SCARD_CTL_CODE(code) CTL_CODE(FILE_DEVICE_SMARTCARD, \
  73. (code), \
  74. METHOD_BUFFERED, \
  75. FILE_ANY_ACCESS)
  76. #define IOCTL_SMARTCARD_POWER SCARD_CTL_CODE( 1)
  77. #define IOCTL_SMARTCARD_GET_ATTRIBUTE SCARD_CTL_CODE( 2)
  78. #define IOCTL_SMARTCARD_SET_ATTRIBUTE SCARD_CTL_CODE( 3)
  79. #define IOCTL_SMARTCARD_CONFISCATE SCARD_CTL_CODE( 4)
  80. #define IOCTL_SMARTCARD_TRANSMIT SCARD_CTL_CODE( 5)
  81. #define IOCTL_SMARTCARD_EJECT SCARD_CTL_CODE( 6)
  82. #define IOCTL_SMARTCARD_SWALLOW SCARD_CTL_CODE( 7)
  83. // #define IOCTL_SMARTCARD_READ SCARD_CTL_CODE( 8) obsolete
  84. // #define IOCTL_SMARTCARD_WRITE SCARD_CTL_CODE( 9) obsolete
  85. #define IOCTL_SMARTCARD_IS_PRESENT SCARD_CTL_CODE(10)
  86. #define IOCTL_SMARTCARD_IS_ABSENT SCARD_CTL_CODE(11)
  87. #define IOCTL_SMARTCARD_SET_PROTOCOL SCARD_CTL_CODE(12)
  88. #define IOCTL_SMARTCARD_GET_STATE SCARD_CTL_CODE(14)
  89. #define IOCTL_SMARTCARD_GET_LAST_ERROR SCARD_CTL_CODE(15)
  90. #define IOCTL_SMARTCARD_GET_PERF_CNTR SCARD_CTL_CODE(16)
  91. //
  92. ///////////////////////////////////////////////////////////////////////////////
  93. //
  94. // Tags for requesting card and reader attributes
  95. //
  96. #define MAXIMUM_ATTR_STRING_LENGTH 32 // Nothing bigger than this from getAttr
  97. #define MAXIMUM_SMARTCARD_READERS 10 // Limit the readers on the system
  98. #define SCARD_ATTR_VALUE(Class, Tag) ((((ULONG)(Class)) << 16) | ((ULONG)(Tag)))
  99. #define SCARD_CLASS_VENDOR_INFO 1 // Vendor information definitions
  100. #define SCARD_CLASS_COMMUNICATIONS 2 // Communication definitions
  101. #define SCARD_CLASS_PROTOCOL 3 // Protocol definitions
  102. #define SCARD_CLASS_POWER_MGMT 4 // Power Management definitions
  103. #define SCARD_CLASS_SECURITY 5 // Security Assurance definitions
  104. #define SCARD_CLASS_MECHANICAL 6 // Mechanical characteristic definitions
  105. #define SCARD_CLASS_VENDOR_DEFINED 7 // Vendor specific definitions
  106. #define SCARD_CLASS_IFD_PROTOCOL 8 // Interface Device Protocol options
  107. #define SCARD_CLASS_ICC_STATE 9 // ICC State specific definitions
  108. #define SCARD_CLASS_PERF 0x7ffe // performace counters
  109. #define SCARD_CLASS_SYSTEM 0x7fff // System-specific definitions
  110. #define SCARD_ATTR_VENDOR_NAME SCARD_ATTR_VALUE(SCARD_CLASS_VENDOR_INFO, 0x0100)
  111. #define SCARD_ATTR_VENDOR_IFD_TYPE SCARD_ATTR_VALUE(SCARD_CLASS_VENDOR_INFO, 0x0101)
  112. #define SCARD_ATTR_VENDOR_IFD_VERSION SCARD_ATTR_VALUE(SCARD_CLASS_VENDOR_INFO, 0x0102)
  113. #define SCARD_ATTR_VENDOR_IFD_SERIAL_NO SCARD_ATTR_VALUE(SCARD_CLASS_VENDOR_INFO, 0x0103)
  114. #define SCARD_ATTR_CHANNEL_ID SCARD_ATTR_VALUE(SCARD_CLASS_COMMUNICATIONS, 0x0110)
  115. #define SCARD_ATTR_PROTOCOL_TYPES SCARD_ATTR_VALUE(SCARD_CLASS_PROTOCOL, 0x0120)
  116. // #define SCARD_ATTR_ASYNC_PROTOCOL_TYPES SCARD_ATTR_VALUE(SCARD_CLASS_PROTOCOL, 0x0120)
  117. #define SCARD_ATTR_DEFAULT_CLK SCARD_ATTR_VALUE(SCARD_CLASS_PROTOCOL, 0x0121)
  118. #define SCARD_ATTR_MAX_CLK SCARD_ATTR_VALUE(SCARD_CLASS_PROTOCOL, 0x0122)
  119. #define SCARD_ATTR_DEFAULT_DATA_RATE SCARD_ATTR_VALUE(SCARD_CLASS_PROTOCOL, 0x0123)
  120. #define SCARD_ATTR_MAX_DATA_RATE SCARD_ATTR_VALUE(SCARD_CLASS_PROTOCOL, 0x0124)
  121. #define SCARD_ATTR_MAX_IFSD SCARD_ATTR_VALUE(SCARD_CLASS_PROTOCOL, 0x0125)
  122. // #define SCARD_ATTR_SYNC_PROTOCOL_TYPES SCARD_ATTR_VALUE(SCARD_CLASS_PROTOCOL, 0x0126)
  123. #define SCARD_ATTR_POWER_MGMT_SUPPORT SCARD_ATTR_VALUE(SCARD_CLASS_POWER_MGMT, 0x0131)
  124. #define SCARD_ATTR_USER_TO_CARD_AUTH_DEVICE SCARD_ATTR_VALUE(SCARD_CLASS_SECURITY, 0x0140)
  125. #define SCARD_ATTR_USER_AUTH_INPUT_DEVICE SCARD_ATTR_VALUE(SCARD_CLASS_SECURITY, 0x0142)
  126. #define SCARD_ATTR_CHARACTERISTICS SCARD_ATTR_VALUE(SCARD_CLASS_MECHANICAL, 0x0150)
  127. #define SCARD_ATTR_CURRENT_PROTOCOL_TYPE SCARD_ATTR_VALUE(SCARD_CLASS_IFD_PROTOCOL, 0x0201)
  128. #define SCARD_ATTR_CURRENT_CLK SCARD_ATTR_VALUE(SCARD_CLASS_IFD_PROTOCOL, 0x0202)
  129. #define SCARD_ATTR_CURRENT_F SCARD_ATTR_VALUE(SCARD_CLASS_IFD_PROTOCOL, 0x0203)
  130. #define SCARD_ATTR_CURRENT_D SCARD_ATTR_VALUE(SCARD_CLASS_IFD_PROTOCOL, 0x0204)
  131. #define SCARD_ATTR_CURRENT_N SCARD_ATTR_VALUE(SCARD_CLASS_IFD_PROTOCOL, 0x0205)
  132. #define SCARD_ATTR_CURRENT_W SCARD_ATTR_VALUE(SCARD_CLASS_IFD_PROTOCOL, 0x0206)
  133. #define SCARD_ATTR_CURRENT_IFSC SCARD_ATTR_VALUE(SCARD_CLASS_IFD_PROTOCOL, 0x0207)
  134. #define SCARD_ATTR_CURRENT_IFSD SCARD_ATTR_VALUE(SCARD_CLASS_IFD_PROTOCOL, 0x0208)
  135. #define SCARD_ATTR_CURRENT_BWT SCARD_ATTR_VALUE(SCARD_CLASS_IFD_PROTOCOL, 0x0209)
  136. #define SCARD_ATTR_CURRENT_CWT SCARD_ATTR_VALUE(SCARD_CLASS_IFD_PROTOCOL, 0x020a)
  137. #define SCARD_ATTR_CURRENT_EBC_ENCODING SCARD_ATTR_VALUE(SCARD_CLASS_IFD_PROTOCOL, 0x020b)
  138. #define SCARD_ATTR_EXTENDED_BWT SCARD_ATTR_VALUE(SCARD_CLASS_IFD_PROTOCOL, 0x020c)
  139. #define SCARD_ATTR_ICC_PRESENCE SCARD_ATTR_VALUE(SCARD_CLASS_ICC_STATE, 0x0300)
  140. #define SCARD_ATTR_ICC_INTERFACE_STATUS SCARD_ATTR_VALUE(SCARD_CLASS_ICC_STATE, 0x0301)
  141. #define SCARD_ATTR_CURRENT_IO_STATE SCARD_ATTR_VALUE(SCARD_CLASS_ICC_STATE, 0x0302)
  142. #define SCARD_ATTR_ATR_STRING SCARD_ATTR_VALUE(SCARD_CLASS_ICC_STATE, 0x0303)
  143. #define SCARD_ATTR_ICC_TYPE_PER_ATR SCARD_ATTR_VALUE(SCARD_CLASS_ICC_STATE, 0x0304)
  144. #define SCARD_ATTR_ESC_RESET SCARD_ATTR_VALUE(SCARD_CLASS_VENDOR_DEFINED, 0xA000)
  145. #define SCARD_ATTR_ESC_CANCEL SCARD_ATTR_VALUE(SCARD_CLASS_VENDOR_DEFINED, 0xA003)
  146. #define SCARD_ATTR_ESC_AUTHREQUEST SCARD_ATTR_VALUE(SCARD_CLASS_VENDOR_DEFINED, 0xA005)
  147. #define SCARD_ATTR_MAXINPUT SCARD_ATTR_VALUE(SCARD_CLASS_VENDOR_DEFINED, 0xA007)
  148. #define SCARD_ATTR_DEVICE_UNIT SCARD_ATTR_VALUE(SCARD_CLASS_SYSTEM, 0x0001)
  149. #define SCARD_ATTR_DEVICE_IN_USE SCARD_ATTR_VALUE(SCARD_CLASS_SYSTEM, 0x0002)
  150. #define SCARD_ATTR_DEVICE_FRIENDLY_NAME_A SCARD_ATTR_VALUE(SCARD_CLASS_SYSTEM, 0x0003)
  151. #define SCARD_ATTR_DEVICE_SYSTEM_NAME_A SCARD_ATTR_VALUE(SCARD_CLASS_SYSTEM, 0x0004)
  152. #define SCARD_ATTR_DEVICE_FRIENDLY_NAME_W SCARD_ATTR_VALUE(SCARD_CLASS_SYSTEM, 0x0005)
  153. #define SCARD_ATTR_DEVICE_SYSTEM_NAME_W SCARD_ATTR_VALUE(SCARD_CLASS_SYSTEM, 0x0006)
  154. #define SCARD_ATTR_SUPRESS_T1_IFS_REQUEST SCARD_ATTR_VALUE(SCARD_CLASS_SYSTEM, 0x0007)
  155. #define SCARD_PERF_NUM_TRANSMISSIONS SCARD_ATTR_VALUE(SCARD_CLASS_PERF, 0x0001)
  156. #define SCARD_PERF_BYTES_TRANSMITTED SCARD_ATTR_VALUE(SCARD_CLASS_PERF, 0x0002)
  157. #define SCARD_PERF_TRANSMISSION_TIME SCARD_ATTR_VALUE(SCARD_CLASS_PERF, 0x0003)
  158. #ifdef UNICODE
  159. #define SCARD_ATTR_DEVICE_FRIENDLY_NAME SCARD_ATTR_DEVICE_FRIENDLY_NAME_W
  160. #define SCARD_ATTR_DEVICE_SYSTEM_NAME SCARD_ATTR_DEVICE_SYSTEM_NAME_W
  161. #else
  162. #define SCARD_ATTR_DEVICE_FRIENDLY_NAME SCARD_ATTR_DEVICE_FRIENDLY_NAME_A
  163. #define SCARD_ATTR_DEVICE_SYSTEM_NAME SCARD_ATTR_DEVICE_SYSTEM_NAME_A
  164. #endif
  165. //
  166. // T=0 Protocol Defines
  167. //
  168. #define SCARD_T0_HEADER_LENGTH 7
  169. #define SCARD_T0_CMD_LENGTH 5
  170. //
  171. // T=1 Protocol Defines
  172. //
  173. #define SCARD_T1_PROLOGUE_LENGTH 3
  174. #define SCARD_T1_EPILOGUE_LENGTH 2
  175. #define SCARD_T1_MAX_IFS 254
  176. //
  177. ///////////////////////////////////////////////////////////////////////////////
  178. //
  179. // Reader states
  180. //
  181. #define SCARD_UNKNOWN 0 // This value implies the driver is unaware
  182. // of the current state of the reader.
  183. #define SCARD_ABSENT 1 // This value implies there is no card in
  184. // the reader.
  185. #define SCARD_PRESENT 2 // This value implies there is a card is
  186. // present in the reader, but that it has
  187. // not been moved into position for use.
  188. #define SCARD_SWALLOWED 3 // This value implies there is a card in the
  189. // reader in position for use. The card is
  190. // not powered.
  191. #define SCARD_POWERED 4 // This value implies there is power is
  192. // being provided to the card, but the
  193. // Reader Driver is unaware of the mode of
  194. // the card.
  195. #define SCARD_NEGOTIABLE 5 // This value implies the card has been
  196. // reset and is awaiting PTS negotiation.
  197. #define SCARD_SPECIFIC 6 // This value implies the card has been
  198. // reset and specific communication
  199. // protocols have been established.
  200. ////////////////////////////////////////////////////////////////////////////////
  201. //
  202. // I/O Services
  203. //
  204. // The following services provide access to the I/O capabilities of the
  205. // reader drivers. Services of the Smart Card are requested by placing the
  206. // following structure into the protocol buffer:
  207. //
  208. typedef struct _SCARD_IO_REQUEST{
  209. DWORD dwProtocol; // Protocol identifier
  210. DWORD cbPciLength; // Protocol Control Information Length
  211. } SCARD_IO_REQUEST, *PSCARD_IO_REQUEST, *LPSCARD_IO_REQUEST;
  212. typedef const SCARD_IO_REQUEST *LPCSCARD_IO_REQUEST;
  213. //
  214. // T=0 protocol services.
  215. //
  216. typedef struct {
  217. BYTE
  218. bCla, // The instruction class
  219. bIns, // The instruction code within the instruction class
  220. bP1,
  221. bP2, // Parameters to the instruction
  222. bP3; // Size of I/O Transfer
  223. } SCARD_T0_COMMAND, *LPSCARD_T0_COMMAND;
  224. typedef struct {
  225. SCARD_IO_REQUEST ioRequest;
  226. BYTE
  227. bSw1,
  228. bSw2; // Return codes from the instruction
  229. union
  230. {
  231. SCARD_T0_COMMAND CmdBytes;
  232. BYTE rgbHeader[5];
  233. };
  234. } SCARD_T0_REQUEST;
  235. typedef SCARD_T0_REQUEST *PSCARD_T0_REQUEST, *LPSCARD_T0_REQUEST;
  236. //
  237. // T=1 Protocol Services
  238. //
  239. typedef struct {
  240. SCARD_IO_REQUEST ioRequest;
  241. } SCARD_T1_REQUEST;
  242. typedef SCARD_T1_REQUEST *PSCARD_T1_REQUEST, *LPSCARD_T1_REQUEST;
  243. //
  244. ////////////////////////////////////////////////////////////////////////////////
  245. //
  246. // Driver attribute flags
  247. //
  248. #define SCARD_READER_SWALLOWS 0x00000001 // Reader has a card swallowing
  249. // mechanism.
  250. #define SCARD_READER_EJECTS 0x00000002 // Reader has a card ejection
  251. // mechanism.
  252. #define SCARD_READER_CONFISCATES 0x00000004 // Reader has a card capture
  253. // mechanism.
  254. //
  255. ///////////////////////////////////////////////////////////////////////////////
  256. //
  257. // Type of reader
  258. //
  259. #define SCARD_READER_TYPE_SERIAL 0x01
  260. #define SCARD_READER_TYPE_PARALELL 0x02
  261. #define SCARD_READER_TYPE_KEYBOARD 0x04
  262. #define SCARD_READER_TYPE_SCSI 0x08
  263. #define SCARD_READER_TYPE_IDE 0x10
  264. #define SCARD_READER_TYPE_USB 0x20
  265. #define SCARD_READER_TYPE_PCMCIA 0x40
  266. #define SCARD_READER_TYPE_VENDOR 0xF0
  267. #ifdef __cplusplus
  268. }
  269. #endif
  270. #endif