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.

568 lines
11 KiB

  1. /*++
  2. Module Name:
  3. L220SCR.h
  4. Abstract:
  5. smartcard 220 serial miniport defines and structures
  6. Revision History:
  7. --*/
  8. #ifndef _L220SCR_
  9. #define _L220SCR_
  10. #define DRIVER_NAME "LIT220P"
  11. #ifndef _WDMDDK_
  12. #include <ntddk.h>
  13. #endif
  14. #include <ntddser.h>
  15. // Pool tag for Litronic xlCS where x is a number we choose
  16. #define SMARTCARD_POOL_TAG '0lCS'
  17. #include "smclib.h"
  18. #include "L220log.h"
  19. #define IOCTL_SMARTCARD_220_READ SCARD_CTL_CODE( 8)
  20. #define IOCTL_SMARTCARD_220_WRITE SCARD_CTL_CODE( 9)
  21. #define MAX_IFSD 254
  22. //
  23. // 220 smart card reader command constants
  24. //
  25. #define LIT220_READER_ATTENTION 0xF4
  26. #define KBD_ACK 0xFA
  27. #define LIT220_GET_READER_TYPE 0xB0
  28. #define LIT220_SET_MODE 0xB1
  29. #define LIT220_CARD_POWER_ON 0xB2
  30. #define LIT220_CARD_POWER_OFF 0xB3
  31. #define LIT220_RESET 0xB4
  32. #define LIT220_GET_READER_STATUS 0xB5
  33. #define LIT220_SEND_BYTE 0xB6
  34. #define LIT220_SEND_BLOCK 0xB7
  35. #define LIT220_RESEND_BLOCK 0xB8
  36. #define LIT220_GET_READER_CAPS 0xB9
  37. #define LIT220_DEACTIVATE_READER 0xBA
  38. //
  39. // 220 smart card respons bytes
  40. // every received packet starts with one of these bytes
  41. //
  42. #define LIT220_READER_TYPE 0x60
  43. #define LIT220_READER_STATUS 0x61
  44. #define LIT220_ACK 0x62
  45. #define LIT220_RECEIVE_BYTE 0x63
  46. #define LIT220_RECEIVE_BLOCK 0x64
  47. #define LIT220_CARD_IN 0x65
  48. #define LIT220_CARD_OUT 0x66
  49. #define LIT220_NACK 0x67
  50. //
  51. // Length of constant size reply packets
  52. //
  53. #define LIT220_READER_TYPE_LEN 16
  54. #define LIT220_READER_STATUS_LEN 4
  55. //
  56. // Length of constant command packets
  57. //
  58. #define LIT220_READER_SET_MODE_LEN 8
  59. //
  60. // Reader status flags
  61. //
  62. #define LIT220_STATUS_CARD_INSERTED 0x08
  63. #define LIT220_VENDOR_NAME "Litronic"
  64. #define LIT220_PRODUCT_NAME "220 Smartcard Reader"
  65. //
  66. // WaitMask values
  67. //
  68. #define WAIT_DATA 0x0001
  69. #define WAIT_ACK 0x0002
  70. #define WAIT_INSERTION 0x0004
  71. #define WAIT_REMOVAL 0x0008
  72. //
  73. // 220 smart card reader dependent flags
  74. //
  75. #define LIT220_READER_PROTOCOL_T1 0x10
  76. #define LIT220_READER_CONVENTION_INVERSE 0x02
  77. #define LIT220_READER_CHECK_CRC 0x01
  78. #define LIT220_READER_BWT_EXTENSION 0x04
  79. // Set mode flags
  80. #define SETMODE_PROTOCOL 0x01
  81. #define SETMODE_GT 0x02
  82. #define SETMODE_WI 0x04
  83. #define SETMODE_BWI 0x08
  84. #define SETMODE_WTX 0x10
  85. #define SETMODE_FI_DI 0x20
  86. #define UNICODE_SIZE(x) ((x) * sizeof(WCHAR))
  87. typedef enum _READER_POWER_STATE {
  88. PowerReaderUnspecified = 0,
  89. PowerReaderWorking,
  90. PowerReaderOff
  91. } READER_POWER_STATE, *PREADER_POWER_STATE;
  92. typedef struct _SERIAL_READER_CONFIG {
  93. //
  94. // flow control
  95. //
  96. SERIAL_HANDFLOW HandFlow;
  97. //
  98. // special characters
  99. //
  100. SERIAL_CHARS SerialChars;
  101. //
  102. // read/write timeouts
  103. //
  104. SERIAL_TIMEOUTS Timeouts;
  105. //
  106. // Baudrate for reader
  107. //
  108. SERIAL_BAUD_RATE BaudRate;
  109. //
  110. // Stop bits, parity configuration
  111. //
  112. SERIAL_LINE_CONTROL LineControl;
  113. //
  114. // Event serial reader uses to signal insert/removal
  115. //
  116. ULONG WaitMask;
  117. } SERIAL_READER_CONFIG, *PSERIAL_READER_CONFIG;
  118. //
  119. // Define the reader specific portion of the smart card extension
  120. //
  121. typedef struct _READER_EXTENSION {
  122. //
  123. // DeviceObject pointer to serial port
  124. //
  125. PDEVICE_OBJECT ConnectedSerialPort;
  126. //
  127. // This struct is used for CardTracking
  128. //
  129. struct {
  130. PIRP Irp;
  131. KEVENT Event;
  132. IO_STATUS_BLOCK IoStatus;
  133. KDPC Dpc;
  134. } CardStatus;
  135. //
  136. // This struct is used to get the number of characters in the input queue
  137. //
  138. SERIAL_STATUS SerialStatus;
  139. //
  140. // IOCTL to send to the serial driver
  141. //
  142. ULONG SerialIoControlCode;
  143. //
  144. // This holds state bits for the COM port such as DSR
  145. //
  146. ULONG ModemStatus;
  147. //
  148. // This holds the serial parameters used to configure the serial port
  149. //
  150. SERIAL_READER_CONFIG SerialConfigData;
  151. //
  152. // This is the data byte no in reply packet
  153. //
  154. ULONG DataByteNo;
  155. //
  156. // Number of bytes expected in the reply packer as indicated by byte 2
  157. // and 3 of the receive packet
  158. //
  159. LENGTH DataLength;
  160. //
  161. // Flags that indicate if we have received the length-bytes in the receive packet
  162. //
  163. BOOLEAN GotLengthB0;
  164. BOOLEAN GotLengthB1;
  165. //
  166. // Nack received from reader
  167. //
  168. BOOLEAN GotNack;
  169. //
  170. // The total number of bytes currently in the receive packet
  171. //
  172. ULONG ReceivedByteNo;
  173. //
  174. // This flag inidictes that the input filter treats the next packet as and ATR
  175. //
  176. BOOLEAN WaitForATR;
  177. //
  178. // Mask that indicates the input filter what events we are expecting
  179. //
  180. ULONG WaitMask;
  181. //
  182. // Smartcard notification DPC queue
  183. //
  184. KDPC NotificationIsrDpc;
  185. //
  186. // Event used to indicate that an ack was received by the input filter.
  187. // This will signal the Lit220Command that it can continue.
  188. //
  189. KEVENT AckEvnt;
  190. //
  191. // Event used to indicate that a data packet was received by the input filter.
  192. // This will signal the Lit220Command that it can continue.
  193. //
  194. KEVENT DataEvnt;
  195. //
  196. // Holds the Device Object of the top of our stack
  197. //
  198. PDEVICE_OBJECT BusDeviceObject;
  199. //
  200. // Holds the Device Object of our parent (1394 bus driver)
  201. //
  202. PDEVICE_OBJECT PhysicalDeviceObject;
  203. //
  204. // State the Lit220SerialEventCallback is in.
  205. //
  206. DWORD SerialEventState;
  207. //
  208. // Temporary transfer buffer used to get data from the serial port
  209. // before we send it to the input filter
  210. //
  211. BYTE TempXferBuf[270];
  212. // Flag that indicates that the caller requests a power-down or a reset
  213. BOOLEAN PowerRequest;
  214. // Saved card state for hibernation/sleeping modes.
  215. BOOLEAN CardPresent;
  216. // Current reader power state.
  217. READER_POWER_STATE ReaderPowerState;
  218. // Used to indicate that the device has been removed even before we can release
  219. // the remove lock throw SmartcardReleaseRemoveLockAndWait. This way when we
  220. // close the connection to the serial port we won't send any more IRPs to the
  221. // device
  222. BOOLEAN DeviceRemoved;
  223. // Flag indicating whether the card is inserted or not
  224. DWORD CardIn;
  225. } READER_EXTENSION, *PREADER_EXTENSION;
  226. typedef struct _DEVICE_EXTENSION {
  227. SMARTCARD_EXTENSION SmartcardExtension;
  228. // The current number of io-requests
  229. LONG IoCount;
  230. // Used to signal that the reader is able to process reqeusts
  231. KEVENT ReaderStarted;
  232. // The pnp device name of our smart card reader
  233. UNICODE_STRING PnPDeviceName;
  234. // Used to signal the the reader has been closed
  235. LONG ReaderOpen;
  236. // Used to signal that the connection to the serial driver has been closed
  237. KEVENT SerialCloseDone;
  238. // Used to keep track of the current power state the reader is in
  239. LONG PowerState;
  240. KSPIN_LOCK SpinLock;
  241. // A worker thread that closes the serial driver &
  242. // handling IO timeouts
  243. PIO_WORKITEM WorkItem;
  244. // Keeps track of how many times the timeout
  245. // function has been called
  246. BYTE EntryCount;
  247. } DEVICE_EXTENSION, *PDEVICE_EXTENSION;
  248. //
  249. // Prototypes
  250. //
  251. NTSTATUS
  252. DriverEntry(
  253. IN PDRIVER_OBJECT DriverObject,
  254. IN PUNICODE_STRING RegistryPath
  255. );
  256. VOID
  257. Lit220Unload(
  258. IN PDRIVER_OBJECT DriverObject
  259. );
  260. NTSTATUS
  261. Lit220CreateClose(
  262. IN PDEVICE_OBJECT DeviceObject,
  263. IN PIRP Irp
  264. );
  265. NTSTATUS
  266. Lit220SystemControl(
  267. IN PDEVICE_OBJECT DeviceObject,
  268. IN PIRP Irp
  269. );
  270. NTSTATUS
  271. Lit220DeviceControl(
  272. PDEVICE_OBJECT DeviceObject,
  273. PIRP Irp
  274. );
  275. NTSTATUS
  276. Lit220Initialize(
  277. IN PSMARTCARD_EXTENSION SmartcardExtension
  278. );
  279. NTSTATUS
  280. Lit220ConfigureSerialPort(
  281. PSMARTCARD_EXTENSION SmartcardExtension
  282. );
  283. NTSTATUS
  284. Lit220SerialIo(
  285. IN PSMARTCARD_EXTENSION SmartcardExtension
  286. );
  287. VOID
  288. Lit220StopDevice(
  289. IN PSMARTCARD_EXTENSION SmartcardExtension
  290. );
  291. VOID
  292. Lit220RemoveDevice(
  293. IN PDEVICE_OBJECT DeviceObject
  294. );
  295. NTSTATUS
  296. Lit220StartDevice(
  297. IN PSMARTCARD_EXTENSION SmartcardExtension
  298. );
  299. NTSTATUS
  300. Lit220InitializeInputFilter(
  301. PSMARTCARD_EXTENSION SmartcardExtension
  302. );
  303. NTSTATUS
  304. Lit220Cleanup(
  305. IN PDEVICE_OBJECT DeviceObject,
  306. IN PIRP Irp
  307. );
  308. NTSTATUS
  309. Lit220Cancel(
  310. IN PDEVICE_OBJECT DeviceObject,
  311. IN PIRP Irp
  312. );
  313. BOOLEAN
  314. Lit220InputFilter(
  315. IN BYTE SmartcardByte,
  316. IN PSMARTCARD_EXTENSION smartcardExtension
  317. );
  318. NTSTATUS
  319. Lit220CardTracking(
  320. PSMARTCARD_EXTENSION SmartcardExtension
  321. );
  322. NTSTATUS
  323. Lit220SetProtocol(
  324. PSMARTCARD_EXTENSION SmartcardExtension
  325. );
  326. NTSTATUS
  327. Lit220Power(
  328. PSMARTCARD_EXTENSION SmartcardExtension
  329. );
  330. NTSTATUS
  331. Lit220IoRequest(
  332. PSMARTCARD_EXTENSION SmartcardExtension
  333. );
  334. NTSTATUS
  335. Lit220GetReaderError(
  336. PSMARTCARD_EXTENSION SmartcardExtension
  337. );
  338. NTSTATUS
  339. Lit220IoReply(
  340. PSMARTCARD_EXTENSION SmartcardExtension
  341. );
  342. BOOLEAN
  343. Lit220IsCardPresent(
  344. IN PSMARTCARD_EXTENSION SmartcardExtension
  345. );
  346. NTSTATUS
  347. Lit220Command(
  348. IN PSMARTCARD_EXTENSION SmartcardExtension
  349. );
  350. NTSTATUS
  351. Lit220AddDevice(
  352. IN PDRIVER_OBJECT DriverObject,
  353. IN PDEVICE_OBJECT PhysicalDeviceObject
  354. );
  355. NTSTATUS
  356. Lit220PnP(
  357. IN PDEVICE_OBJECT DeviceObject,
  358. IN PIRP Irp
  359. );
  360. NTSTATUS
  361. Lit220SynchCompletionRoutine(
  362. IN PDEVICE_OBJECT DeviceObject,
  363. IN PIRP Irp,
  364. IN PKEVENT Event
  365. );
  366. VOID
  367. Lit220CloseSerialPort(
  368. IN PDEVICE_OBJECT DeviceObject,
  369. IN PVOID Context
  370. );
  371. NTSTATUS
  372. Lit220CallSerialDriver(
  373. IN PDEVICE_OBJECT DeviceObject,
  374. IN PIRP Irp);
  375. NTSTATUS
  376. Lit220SerialEventCallback(
  377. IN PDEVICE_OBJECT DeviceObject,
  378. IN PIRP Irp,
  379. IN PSMARTCARD_EXTENSION SmartcardExtension
  380. );
  381. NTSTATUS
  382. Lit220DispatchPower (
  383. IN PDEVICE_OBJECT DeviceObject,
  384. IN PIRP Irp
  385. );
  386. VOID
  387. Lit220NotifyCardChange(
  388. IN PSMARTCARD_EXTENSION smartcardExtension,
  389. IN DWORD CardInserted
  390. );
  391. NTSTATUS
  392. Lit220DevicePowerCompletion (
  393. IN PDEVICE_OBJECT DeviceObject,
  394. IN PIRP Irp,
  395. IN PSMARTCARD_EXTENSION SmartcardExtension
  396. );
  397. VOID
  398. Lit220CompleteCardTracking(
  399. IN PSMARTCARD_EXTENSION SmartcardExtension
  400. );
  401. VOID
  402. Lit220ReceiveBlockTimeout(
  403. IN PDEVICE_OBJECT DeviceObject,
  404. IN PVOID Context
  405. );
  406. VOID
  407. Lit220ProcessNack(
  408. PSMARTCARD_EXTENSION SmartcardExtension
  409. );
  410. VOID
  411. Lit220StartTimer(
  412. IN PDEVICE_OBJECT DeviceObject,
  413. IN PIO_WORKITEM WorkItem
  414. );
  415. VOID
  416. Lit220StopTimer(
  417. IN PDEVICE_OBJECT DeviceObject,
  418. IN PIO_WORKITEM WorkItem
  419. );
  420. VOID
  421. Lit220ScheduleTimer(
  422. IN PSMARTCARD_EXTENSION SmartcardExtension,
  423. IN PIO_WORKITEM_ROUTINE Routine
  424. );
  425. #endif