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.

275 lines
8.6 KiB

  1. /*++
  2. Copyright (c) 1998 Gemplus Development
  3. Name:
  4. GNTSCR.H (Gemplus NT Smart Card Reader definition)
  5. Description :
  6. Holds the common definitions for a smart card reader
  7. This file is a dedicated to a GemCore Pnp reader
  8. Revision History :
  9. dd/mm/yy
  10. 13/03/98: V1.00.001 (GPZ)
  11. - Start of development.
  12. --*/
  13. #ifndef _GNTSCR_
  14. #define _GNTSCR_
  15. #define SMARTCARD_POOL_TAG 'bGCS'
  16. #include <ntddk.h>
  17. #include <ntddser.h>
  18. #include <smclib.h>
  19. #include "gemlog.h"
  20. #include "gemcore.h"
  21. #include "gioctl0A.h"
  22. //
  23. // Constant section:
  24. // - SC_DRIVER_NAME defines the name of the Smart Card reader driver.
  25. // - SC_VENDOR_NAME defines the name of the Smart Card reader vendor.
  26. // - SC_IFD_TYPE defines the type of the Smart Card reader.
  27. //
  28. #define SC_DRIVER_NAME "GCR410P"
  29. #define SC_VENDOR_NAME "GEMPLUS"
  30. #define SC_IFD_TYPE "GCR410P"
  31. //
  32. // - IFD_FIRMWARE_VERSION defines the version of the firmware supported
  33. // by the driver.
  34. // - IFD_VERSION_MAJOR and IFD_VERSION_MINOR defines the major and minor
  35. // version of the firmware supported by the driver.
  36. //
  37. #define IFD_FIRMWARE_VERSION "GemCore-R"
  38. #define IFD_VERSION_MAJOR 1
  39. #define IFD_VERSION_MINOR 113
  40. //
  41. // - REG_KEY_MAXIMAL_BAUD_RATE defines the key name in the registry which
  42. // contains the value of the maximal baud rate for the reader.
  43. // - IFD_STANDARD_BAUD_RATE defines the standard baud rate for the reader (38400)
  44. //
  45. #define REG_KEY_MAXIMAL_BAUD_RATE "MaximalBaudRate"
  46. #define IFD_STANDARD_BAUD_RATE 38400
  47. //
  48. // - ICC_DEFAULT_POWER_TIMOUT defines the default power timout in ms (0).
  49. //
  50. #define ICC_DEFAULT_POWER_TIMOUT 0
  51. //
  52. // - SCARD_CLASS is a macro to know the class of a Tag.
  53. //
  54. #define SCARD_CLASS(Value) (ULONG) (((ULONG)(Value)) >> 16)
  55. //
  56. // - IOCTL_SMARTCARD_VENDOR_IFD_EXCHANGE defines a specific IOCTL for the Gemplus
  57. // Reader to exchange data with the reader without control of the driver.
  58. // - IOCTL_SMARTCARD_VENDOR_GET_ATTRIBUTE defines a specific IOCTL for the Gemplus
  59. // Reader to gets vendor attributes.
  60. // - IOCTL_SMARTCARD_VENDOR_SET_ATTRIBUTE defines a specific IOCTL for the Gemplus
  61. // Reader to sets vendor attributes.
  62. //
  63. #define IOCTL_SMARTCARD_VENDOR_IFD_EXCHANGE CTL_CODE(FILE_DEVICE_SMARTCARD,2048,0,0)
  64. #define IOCTL_SMARTCARD_VENDOR_GET_ATTRIBUTE CTL_CODE(FILE_DEVICE_SMARTCARD,2049,0,0)
  65. #define IOCTL_SMARTCARD_VENDOR_SET_ATTRIBUTE CTL_CODE(FILE_DEVICE_SMARTCARD,2050,0,0)
  66. //
  67. // - SCARD_ATTR_SPEC_BAUD_RATE is the Tag to acces at the value of the baud rate (PC/IFD).
  68. // - SCARD_ATTR_SPEC_CMD_TIMEOUT is the Tag to access at the value of the Cmd Timeout.
  69. // - SCARD_ATTR_SPEC_POWER_TIMEOUT is the Tag to access at the value of the Power
  70. // Timeout.
  71. // - SCARD_ATTR_SPEC_APDU_TIMEOUT is the Tag to access at the value of the APDU
  72. // Timeout.
  73. //
  74. #define SCARD_ATTR_SPEC_BAUD_RATE SCARD_ATTR_VALUE(SCARD_CLASS_VENDOR_DEFINED,0x0180)
  75. #define SCARD_ATTR_SPEC_CMD_TIMEOUT SCARD_ATTR_VALUE(SCARD_CLASS_VENDOR_DEFINED,0x0181)
  76. #define SCARD_ATTR_SPEC_POWER_TIMEOUT SCARD_ATTR_VALUE(SCARD_CLASS_VENDOR_DEFINED,0x0182)
  77. #define SCARD_ATTR_SPEC_APDU_TIMEOUT SCARD_ATTR_VALUE(SCARD_CLASS_VENDOR_DEFINED,0x0183)
  78. //
  79. // - SC_IFD_DEFAULT_CLK_FREQUENCY defines the default frequency for the reader.
  80. // - SC_IFD_MAXIMUM_CLK_FREQUENCY defines the maximum frequency for the reader.
  81. // - SC_IFD_DEFAULT_DATA_RATE defines the default baud rate for the reader.
  82. // - SC_IFD_MAXIMUM_DATA_RATE defines the maximum baud rate for the reader.
  83. // - SC_IFD_MAXIMUM_IFSD defines the maximum IFSD supported by the reader.
  84. // - SC_IFD_T0_MAXIMUM_LEX defines the maximum LEX in T=0 supported by the reader.
  85. // - SC_IFD_T0_MAXIMUM_LC defines the maximum LC in T=0 supported by the reader.
  86. //
  87. #define SC_IFD_DEFAULT_CLK_FREQUENCY 3686
  88. #define SC_IFD_MAXIMUM_CLK_FREQUENCY 3686
  89. #define SC_IFD_DEFAULT_DATA_RATE 9909
  90. #define SC_IFD_MAXIMUM_DATA_RATE 158554
  91. #define SC_IFD_MAXIMUM_IFSD 254
  92. #define SC_IFD_T0_MAXIMUM_LEX 256
  93. #define SC_IFD_T0_MAXIMUM_LC 255
  94. typedef enum _READER_POWER_STATE {
  95. PowerReaderUnspecified = 0,
  96. PowerReaderWorking,
  97. PowerReaderOff
  98. } READER_POWER_STATE, *PREADER_POWER_STATE;
  99. typedef enum _ACTION {
  100. Undefined = 0,
  101. SkipRequest,
  102. WaitForCompletion,
  103. CompleteRequest,
  104. MarkPending
  105. } ACTION;
  106. //
  107. // Struct section:
  108. // - _DEVICE_EXTENSION define a struct for the device extension:
  109. //
  110. typedef struct _DEVICE_EXTENSION {
  111. // Our smart card extension
  112. SMARTCARD_EXTENSION SmartcardExtension;
  113. // The current number of io-requests
  114. LONG IoCount;
  115. // Used to signal that the reader is able to process requests
  116. KEVENT ReaderStarted;
  117. // Used to signal the the reader has been closed
  118. LONG ReaderOpen;
  119. // Used to signal that the connection to the serial driver has been closed
  120. KEVENT SerialCloseDone;
  121. // Used to signal that the card status thread is scheduled
  122. KEVENT CardStatusNotInUse;
  123. // The pnp device name of our smart card reader
  124. UNICODE_STRING PnPDeviceName;
  125. // Used to keep track of the current power state the reader is in
  126. LONG PowerState;
  127. KSPIN_LOCK SpinLock;
  128. // A worker thread that closes the serial driver
  129. PIO_WORKITEM CloseSerial;
  130. // A worker thread that closes the serial driver
  131. PIO_WORKITEM CardStateChange;
  132. } DEVICE_EXTENSION, *PDEVICE_EXTENSION;
  133. //
  134. // - _SERIAL_READER_CONFIG define a struct for the serial configuration:
  135. //
  136. typedef struct _SERIAL_READER_CONFIG {
  137. // flow control
  138. SERIAL_HANDFLOW HandFlow;
  139. // special characters
  140. SERIAL_CHARS SerialChars;
  141. // read/write timeouts
  142. SERIAL_TIMEOUTS Timeouts;
  143. // Baudrate for reader
  144. SERIAL_BAUD_RATE BaudRate;
  145. // Stop bits, parity configuration
  146. SERIAL_LINE_CONTROL LineControl;
  147. // Event serial reader uses to signal insert/removal
  148. ULONG SerialWaitMask;
  149. } SERIAL_READER_CONFIG, *PSERIAL_READER_CONFIG;
  150. //
  151. // - _READER_EXTENSION define a struct for the reader specific portion of
  152. // the smart card extension.
  153. // * Handle holds the serial communication handle;
  154. // * ICCType holds the ICC type.
  155. // * ICCVpp holds the selected VPP value (G_Oros2IccDefineType).
  156. // * ICCPresence holds the selected presence byte (G_Oros2IccDefineType).
  157. // * CmdTimeOut holds the timeout for any command expect an APDU command.
  158. // * APDUTimeOut holds the timeout for an APDU command.
  159. // * IFDBaudRate holds the baudrate used between IFD and Host.
  160. // * PowerTimeOut holds the time for the reader to really power off an ICC
  161. // after the PowerOff command has been sent.
  162. // * MaximalBaudRate defines the maximal baud rate for the reader.
  163. //
  164. typedef struct _READER_EXTENSION {
  165. short Handle;
  166. ULONG CmdTimeOut;
  167. ULONG APDUTimeOut;
  168. ULONG IFDBaudRate;
  169. ULONG PowerTimeOut;
  170. ULONG MaximalBaudRate;
  171. struct _ICC_CONFIG {
  172. short ICCType;
  173. USHORT ICCVpp;
  174. USHORT ICCPresence;
  175. BYTE ICCVcc;
  176. BYTE PTSMode;
  177. BYTE PTS0;
  178. BYTE PTS1;
  179. BYTE PTS2;
  180. BYTE PTS3;
  181. } IccConfig;
  182. struct _TRANSPARENT_CONFIG {
  183. BYTE CFG;
  184. BYTE ETU;
  185. BYTE EGT;
  186. BYTE CWT;
  187. BYTE BWI;
  188. BYTE Fi;
  189. BYTE Di;
  190. } TransparentConfig;
  191. KMUTEX LongAPDUMutex;
  192. KMUTEX ExchangeMutex;
  193. ULONG SerialIoControlCode;
  194. SERIAL_READER_CONFIG SerialConfigData;
  195. PIRP SerialStatusIrp;
  196. // DeviceObject pointer to serial port
  197. PDEVICE_OBJECT AttachedDeviceObject;
  198. // Flag that indicates that the caller requests a power-down or a reset
  199. BOOLEAN PowerRequest;
  200. // Current reader power state.
  201. READER_POWER_STATE ReaderPowerState;
  202. // Saved card state for hibernation/sleeping modes.
  203. BOOLEAN CardPresent;
  204. // Flag that indicates we're getting the ModemStatus (used in a DPC)
  205. BOOLEAN GetModemStatus;
  206. // Variable used to receive the modem status
  207. ULONG ModemStatus;
  208. } READER_EXTENSION, *PREADER_EXTENSION;
  209. #define READER_EXTENSION(member) (SmartcardExtension->ReaderExtension->member)
  210. #define ATTACHED_DEVICE_OBJECT deviceExtension->SmartcardExtension.ReaderExtension->AttachedDeviceObject
  211. //ISV
  212. /*
  213. #undef SmartcardDebug
  214. #define SmartcardDebug(LEVEL, STRING) {DbgPrint STRING;}
  215. */
  216. #endif