Source code of Windows XP (NT5)
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.

334 lines
12 KiB

  1. /*******************************************************************************
  2. * Copyright (c) 1997-1998 Gemplus developpement
  3. *
  4. * Name : GIOCTL09.H (Gemplus IOCTL Smart card Reader module 09)
  5. *
  6. * Description : Holds the common definitions for the IOCTL functions for a
  7. * GemCore smart card reader
  8. *
  9. * Release : 1.00.002
  10. *
  11. * Last Modif : 22/12/97: V1.00.002 (TFB)
  12. * - Modify the maximum IFSD and clock freqency parameters.
  13. * 08/07/97: V1.00.001 (GPZ)
  14. * - Start of development.
  15. *
  16. ********************************************************************************
  17. *
  18. * Warning :
  19. *
  20. * Remark :
  21. *
  22. *******************************************************************************/
  23. #ifndef _GIOSR09_
  24. #define _GIOSR09_
  25. /*------------------------------------------------------------------------------
  26. Constant section:
  27. - SC_VENDOR_NAME defines the name of the Smart Card reader vendor.
  28. - SC_IFD_NAME defines the type of the Smart Card reader.
  29. - SC_IFD_SAM_NAME defines the type of the Smart Card reader for a SAM
  30. (Security Access Module).
  31. ------------------------------------------------------------------------------*/
  32. #define SC_VENDOR_NAME "Gemplus"
  33. #define SC_IFD_TYPE "GemCore Based Readers"
  34. #define SC_IFD_SAM_TYPE "GemCore Based Readers - SAM"
  35. /*------------------------------------------------------------------------------
  36. Constant section:
  37. - IFD_FIRMWARE_VERSION defines the version of the firmware supported
  38. by the driver.
  39. - IFD_VERSION_MAJOR defines the major version of the firmware supported
  40. by the driver.
  41. - MAX_IFD_BY_READER defines the maximal number of IFD which can be
  42. availables in a reader.
  43. ------------------------------------------------------------------------------*/
  44. #define IFD_FIRMWARE_VERSION "GemCore-R1."
  45. #define IFD_VERSION_MAJOR 1
  46. #define MAX_IFD_BY_READER 9
  47. /*------------------------------------------------------------------------------
  48. - REG_KEY_MAXIMAL_BAUD_RATE defines the key name in the registry which
  49. contains the value of the maximal baud rate for the reader.
  50. - IFD_STANDARD_BAUD_RATE defines the standard baud rate for the reader (9600)
  51. ------------------------------------------------------------------------------*/
  52. #define REG_KEY_MAXIMAL_BAUD_RATE "MaximalBaudRate"
  53. #define IFD_STANDARD_BAUD_RATE 9600
  54. #define REG_KEY_MAXIMAL_IFD "MaximalIFD"
  55. #define REG_KEY_IFD_OPTION "IFDOption"
  56. /*------------------------------------------------------------------------------
  57. - ICC_DEFAULT_POWER_TIMOUT defines the default power timout in ms (1000).
  58. ------------------------------------------------------------------------------*/
  59. #define ICC_DEFAULT_POWER_TIMOUT 1000
  60. /*------------------------------------------------------------------------------
  61. - SCARD_CLASS is a macro to know the class of a Tag.
  62. - SCARD_ATTR_SPEC_MIN, SCARD_ATTR_SPEC_MAXI defines the limits of the tags
  63. for the vendor.
  64. - SCARD_ATTR_SPEC_BAUD_RATE is the Tag for the speed in use between the
  65. system and the reader.
  66. ------------------------------------------------------------------------------*/
  67. #define SCARD_CLASS(Value) (ULONG) (((ULONG)(Value)) >> 16)
  68. #define SCARD_ATTR_SPEC_MINI SCARD_ATTR_VALUE(SCARD_CLASS_VENDOR_DEFINED,0x0180)
  69. #define SCARD_ATTR_SPEC_MAXI SCARD_ATTR_VALUE(SCARD_CLASS_VENDOR_DEFINED,0x01F0)
  70. /*------------------------------------------------------------------------------
  71. - IOCTL_SMARTCARD_IFD_EXCHANGE defines a specific IOCTL for the Gemplus
  72. Reader to exchange data with the reader without control of the driver.
  73. ------------------------------------------------------------------------------*/
  74. #define IOCTL_SMARTCARD_IFD_EXCHANGE SCARD_CTL_CODE(0x20000000)
  75. /*------------------------------------------------------------------------------
  76. - SCARD_ATTR_SPEC_IFD_NUMBER is the Tag for the numero of the sub IFD (or
  77. SAM) in the reader.
  78. - SCARD_ATTR_SPEC_CMD_TIMEOUT is the Tag for the value of the Cmd Timeout.
  79. - SCARD_ATTR_SPEC_POWER_TIMEOUT is the Tag for the value of the Power
  80. Timeout.
  81. ------------------------------------------------------------------------------*/
  82. #define SCARD_ATTR_SPEC_BAUD_RATE SCARD_ATTR_VALUE(SCARD_CLASS_VENDOR_DEFINED,0x0180)
  83. #define SCARD_ATTR_SPEC_IFD_NUMBER SCARD_ATTR_VALUE(SCARD_CLASS_VENDOR_DEFINED,0x0181)
  84. #define SCARD_ATTR_SPEC_CMD_TIMEOUT SCARD_ATTR_VALUE(SCARD_CLASS_VENDOR_DEFINED,0x0182)
  85. #define SCARD_ATTR_SPEC_POWER_TIMEOUT SCARD_ATTR_VALUE(SCARD_CLASS_VENDOR_DEFINED,0x0183)
  86. #define SCARD_ATTR_SPEC_ICC_TYPE SCARD_ATTR_VALUE(SCARD_CLASS_VENDOR_DEFINED,0x0184)
  87. #define SCARD_ATTR_SPEC_IFD_OPTION SCARD_ATTR_VALUE(SCARD_CLASS_VENDOR_DEFINED,0x0185)
  88. #define SCARD_ATTR_SPEC_MAXIMAL_IFD SCARD_ATTR_VALUE(SCARD_CLASS_VENDOR_DEFINED,0x0186)
  89. #define SCARD_ATTR_SPEC_APDU_TIMEOUT SCARD_ATTR_VALUE(SCARD_CLASS_VENDOR_DEFINED,0x0187)
  90. /*------------------------------------------------------------------------------
  91. - SC_IFD_GEMCORE_DEFAULT_CLK_FREQUENCY defines the default frequency for
  92. a GEMCORE reader.
  93. - SC_IFD_GEMCORE_MAXIMUM_CLK_FREQUENCY defines the maximum frequency for
  94. a GEMCORE reader.
  95. - SC_IFD_GEMCORE_DEFAULT_DATA_RATE defines the default baud rate for
  96. a GEMCORE reader.
  97. - SC_IFD_GEMCORE_MAXIMUM_DATA_RATE defines the maximum baud rate for
  98. a GEMCORE reader.
  99. - SC_IFD_GEMCORE_MAXIMUM_IFSD defines the maximum IFSD supported by
  100. a GEMCORE reader.
  101. - SC_IFD_GEMCORE_T0_MAXIMUM_LEX defines the maximum LEX in T=0 supported by
  102. a GEMCORE reader.
  103. - SC_IFD_GEMCORE_T0_MAXIMUM_LC defines the maximum LC in T=0 supported by
  104. a GEMCORE reader.
  105. - SC_IFD_GEMCORE_T1_MAXIMUM_LEX defines the maximum LEX in T=1 supported by
  106. a GEMCORE reader.
  107. - SC_IFD_GEMCORE_T1_MAXIMUM_LC defines the maximum LC in T=1 supported by
  108. a GEMCORE reader.
  109. ------------------------------------------------------------------------------*/
  110. #define SC_IFD_GEMCORE_DEFAULT_CLK_FREQUENCY 3686
  111. #define SC_IFD_GEMCORE_MAXIMUM_CLK_FREQUENCY 3686
  112. #define SC_IFD_GEMCORE_DEFAULT_DATA_RATE 9909
  113. #define SC_IFD_GEMCORE_MAXIMUM_DATA_RATE 158554
  114. #define SC_IFD_GEMCORE_MAXIMUM_IFSD 254
  115. #define SC_IFD_GEMCORE_T0_MAXIMUM_LEX 256
  116. #define SC_IFD_GEMCORE_T0_MAXIMUM_LC 255
  117. #define SC_IFD_GEMCORE_T1_MAXIMUM_LEX 256
  118. #define SC_IFD_GEMCORE_T1_MAXIMUM_LC 255
  119. /*------------------------------------------------------------------------------
  120. Reader options:
  121. - No IFD option (SC_IFD_OPTION_UNDEFINED),
  122. - IFD with a keyboard (SC_IFD_OPTION_KEYBOARD),
  123. - IFD with a display (SC_IFD_OPTION_DISPLAY),
  124. - IFD with a buzzer (SC_IFD_OPTION_BUZZER),
  125. - IFD with bank of memory (SC_IFD_OPTION_MEMORY),
  126. - IFD with a real time clock (SC_IFD_OPTION_RTC).
  127. - IFD with one or more security module SC_IFD_OPTION_SAM).
  128. ------------------------------------------------------------------------------*/
  129. #define SC_IFD_OPTION_UNDEFINED 0x0000 // There is no IFD option.
  130. #define SC_IFD_OPTION_KEYBOARD 0x0001 // IFD with a keyboard.
  131. #define SC_IFD_OPTION_DISPLAY 0x0002 // IFD with a display.
  132. #define SC_IFD_OPTION_BUZZER 0x0004 // IFD with a buzzer.
  133. #define SC_IFD_OPTION_MEMORY 0x0008 // IFD with bank of memory.
  134. #define SC_IFD_OPTION_RTC 0x0010 // IFD with a real time clock.
  135. #define SC_IFD_OPTION_SAM 0x0020 // IFD with one or more security module.
  136. #define UNICODE_SIZE(x) ((x) * sizeof(WCHAR))
  137. /*------------------------------------------------------------------------------
  138. - CARD_STATUS_MODE define an enumeration of mode for function update card.
  139. ------------------------------------------------------------------------------*/
  140. typedef enum _CARD_STATUS_MODE {
  141. RUN_REQUEST,
  142. RUN_IN_PROCESS,
  143. STOP_REQUEST,
  144. STOP_IN_PROCESS
  145. } CARD_STATUS_MODE;
  146. /*------------------------------------------------------------------------------
  147. Struct section:
  148. - _SERIAL_READER_CONFIG define a struct for the serial configuration:
  149. ------------------------------------------------------------------------------*/
  150. typedef struct _SERIAL_READER_CONFIG {
  151. // flow control
  152. SERIAL_HANDFLOW HandFlow;
  153. // special characters
  154. SERIAL_CHARS SerialChars;
  155. // read/write timeouts
  156. SERIAL_TIMEOUTS Timeouts;
  157. // Baudrate for reader
  158. SERIAL_BAUD_RATE BaudRate;
  159. // Stop bits, parity configuration
  160. SERIAL_LINE_CONTROL LineControl;
  161. // Event serial reader uses to signal insert/removal
  162. ULONG WaitMask;
  163. } SERIAL_READER_CONFIG, *PSERIAL_READER_CONFIG;
  164. /*------------------------------------------------------------------------------
  165. - _READER_EXTENSION define a struct for the reader specific portion of
  166. the smart card extension.
  167. * Handle holds the serial communication handle;
  168. * IFD number in the reader (0 is the main reader, else is the SAM).
  169. * ICCType holds the ICC type.
  170. * ICCVpp holds the selected VPP value (G_Oros2IccDefineType).
  171. * ICCPresence holds the selected presence byte (G_Oros2IccDefineType).
  172. * CmdTimeOut holds the timeout for any command expect an APDU command.
  173. * APDUTimeOut holds the timeout for an APDU command.
  174. * IFDBaudRate holds the baudrate used between IFD and Host.
  175. * PowerTimeOut holds the time for the reader to really power off an ICC
  176. after the PowerOff command has been sent.
  177. * MaximalIFD holds the maximal number of security modules for the reader.
  178. * IFDOption holds the options for the reader.
  179. ------------------------------------------------------------------------------*/
  180. typedef struct _READER_EXTENSION {
  181. INT16 Handle;
  182. WORD32 IFDNumber;
  183. INT16 ICCType;
  184. WORD16 ICCVpp;
  185. WORD16 ICCPresence;
  186. WORD32 CmdTimeOut;
  187. WORD32 APDUTimeOut;
  188. WORD32 IFDBaudRate;
  189. WORD32 PowerTimeOut;
  190. WORD32 MaximalIFD;
  191. WORD32 IFDOption;
  192. BYTE ICCVcc;
  193. BYTE PTSMode;
  194. BYTE PTS0;
  195. BYTE PTS1;
  196. BYTE PTS2;
  197. BYTE PTS3;
  198. KMUTEX LongAPDUMutex;
  199. KMUTEX ExchangeMutex;
  200. ULONG SerialIoControlCode;
  201. SERIAL_READER_CONFIG
  202. SerialConfigData;
  203. ULONG EventMask;
  204. // DeviceObject pointer to serial port
  205. PDEVICE_OBJECT
  206. ConnectedSerialPort;
  207. // The dos device name of our smart card reader
  208. UNICODE_STRING
  209. DosDeviceName;
  210. KSPIN_LOCK SpinLock;
  211. // This FileObject is needed to close the connection to the serial port.
  212. PFILE_OBJECT
  213. SerialFileObject;
  214. struct _CARD_STATUS {
  215. PIRP Irp;
  216. CARD_STATUS_MODE Mode;
  217. HANDLE ThreadHandle;
  218. IO_STATUS_BLOCK IoStatus;
  219. KDPC Dpc;
  220. } CardStatus;
  221. } READER_EXTENSION, *PREADER_EXTENSION;
  222. /*------------------------------------------------------------------------------
  223. Prototype section
  224. ------------------------------------------------------------------------------*/
  225. NTSTATUS GDDK_09ReaderPower
  226. (
  227. PSMARTCARD_EXTENSION SmartcardExtension
  228. );
  229. NTSTATUS GDDK_09SetProtocol
  230. (
  231. PSMARTCARD_EXTENSION SmartcardExtension
  232. );
  233. NTSTATUS GDDK_09Transmit
  234. (
  235. PSMARTCARD_EXTENSION SmartcardExtension
  236. );
  237. NTSTATUS GDDK_09CardTracking
  238. (
  239. PSMARTCARD_EXTENSION SmartcardExtension
  240. );
  241. NTSTATUS GDDK_09SpecificIOCTL
  242. (
  243. PSMARTCARD_EXTENSION SmartcardExtension,
  244. DWORD IoControlCode,
  245. DWORD BufferInLen,
  246. BYTE *BufferIn,
  247. DWORD BufferOutLen,
  248. BYTE *BufferOut,
  249. DWORD *LengthOut
  250. );
  251. NTSTATUS GDDK_09SpecificTag
  252. (
  253. PSMARTCARD_EXTENSION SmartcardExtension,
  254. DWORD IoControlCode,
  255. DWORD BufferInLen,
  256. BYTE *BufferIn,
  257. DWORD BufferOutLen,
  258. BYTE *BufferOut,
  259. DWORD *LengthOut
  260. );
  261. void GDDK_09UpdateCardStatus
  262. (
  263. PSMARTCARD_EXTENSION SmartcardExtension
  264. );
  265. void GDDK_09LockExchange
  266. (
  267. PSMARTCARD_EXTENSION SmartcardExtension
  268. );
  269. void GDDK_09UnlockExchange
  270. (
  271. PSMARTCARD_EXTENSION SmartcardExtension
  272. );
  273. NTSTATUS GDDK_09OpenChannel
  274. (
  275. PSMARTCARD_EXTENSION SmartcardExtension,
  276. CONST WORD32 DeviceNumber,
  277. CONST WORD32 PortSerialNumber,
  278. CONST WORD32 IFDNumber,
  279. CONST WORD32 MaximalBaudRate
  280. );
  281. NTSTATUS GDDK_09CloseChannel
  282. (
  283. PSMARTCARD_EXTENSION SmartcardExtension
  284. );
  285. NTSTATUS GDDK_09OpenSession
  286. (
  287. PSMARTCARD_EXTENSION SmartcardExtension
  288. );
  289. NTSTATUS GDDK_09SwitchSession
  290. (
  291. PSMARTCARD_EXTENSION SmartcardExtension
  292. );
  293. NTSTATUS GDDK_09CloseSession
  294. (
  295. PSMARTCARD_EXTENSION SmartcardExtension
  296. );
  297. #endif