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.

347 lines
9.6 KiB

  1. /*++
  2. Copyright (c) 1999 SCM Microsystems, Inc.
  3. Module Name:
  4. common.h
  5. Abstract:
  6. Constants, structures, macro etc.. for STC USB WDM
  7. Revision History:
  8. PP 01/20/1999 Initial Version
  9. --*/
  10. #if !defined( __COMMON_H__ )
  11. #define __COMMON_H__
  12. #include <ntstatus.h>
  13. #include <wdm.h>
  14. #include <usbdi.h>
  15. #include <usbdlib.h>
  16. #include <usb100.h>
  17. #include <DEVIOCTL.H>
  18. #define DRIVER_NAME "STCUSB"
  19. #include "SMCLIB.h"
  20. #include "WINSMCRD.h"
  21. //
  22. // Constants -----------------------------------------------------------------
  23. //
  24. #define SMARTCARD_POOL_TAG '4SCS'
  25. #define STCUSB_VENDOR_NAME "SCM Microsystems"
  26. #define STCUSB_PRODUCT_NAME "STCUSB"
  27. #define MAX_READ_REGISTER_BUFFER_SIZE 18
  28. #define STCUSB_MAX_DEVICE 16
  29. #define USB_WRITE_RETRIES 2
  30. #define IOCTL_WRITE_STC_REGISTER SCARD_CTL_CODE(0x800)
  31. #define IOCTL_READ_STC_REGISTER SCARD_CTL_CODE(0x801)
  32. #define IOCTL_WRITE_STC_DATA SCARD_CTL_CODE(0x802)
  33. #define IOCTL_READ_STC_DATA SCARD_CTL_CODE(0x803)
  34. #define POLLING_PERIOD 500
  35. #define CLA_IDX 0
  36. #define INS_IDX 1
  37. #define P1_IDX 2
  38. #define P2_IDX 3
  39. #define P3_IDX 4
  40. #define ISO_OUT TRUE
  41. #define ISO_IN !ISO_OUT
  42. #define NAD_IDX 0x00
  43. #define PCB_IDX 0x01
  44. #define LEN_IDX 0x02
  45. #define DATA_IDX 0x03
  46. #define PROLOGUE_LEN 0x03
  47. #define EPILOGUE_LEN 0x01
  48. #define OSC 16000
  49. #define FREQ 3580
  50. #define CYC_TO_MS( cyc ) ((ULONG)( cyc / FREQ ))
  51. // register addresses
  52. #define ADR_ETULENGTH15 0x00
  53. #define ADR_ETULENGTH7 0x01
  54. #define ADR_CGT8 0x02
  55. #define ADR_CGT7 0x03
  56. #define ADR_CWT31 0x04
  57. #define ADR_CWT23 0x05
  58. #define ADR_CWT15 0x06
  59. #define ADR_CWT7 0x07
  60. #define ADR_BGT8 0x08
  61. #define ADR_BGT7 0x09
  62. #define ADR_BWT31 0x0A
  63. #define ADR_BWT23 0x0B
  64. #define ADR_BWT15 0x0C
  65. #define ADR_BWT7 0x0D
  66. #define ADR_TCON 0x0E
  67. #define ADR_UART_CONTROL 0x0F
  68. #define ADR_FIFO_CONFIG 0x10
  69. #define ADR_INT_CONTROL 0x11
  70. #define ADR_INT_STATUS 0x12
  71. #define ADR_DATA 0x13
  72. #define ADR_IO_CONFIG 0x14
  73. #define ADR_SC_CONTROL 0x15
  74. #define ADR_CLOCK_CONTROL 0x16
  75. // clock control register
  76. #define M_CKE 0x01
  77. #define M_OEN 0x02
  78. // ETU length register
  79. #define M_ETU_RST 0x80
  80. #define M_DIV 0x30
  81. #define M_DIV1 0x20
  82. #define M_DIV0 0x10
  83. #define M_ETUH 0x0F
  84. #define M_ETUL 0xFF
  85. // CGT length register
  86. #define M_CGTH 0x01
  87. #define M_CGTL 0XFF
  88. // BGT length register
  89. #define M_BGTH 0x01
  90. #define M_BGTL 0xFF
  91. // CWT register
  92. #define M_CWT4 0xFF
  93. #define M_CWT3 0xFF
  94. #define M_CWT2 0xFF
  95. #define M_CWT1 0xFF
  96. // TCON register
  97. #define M_MGT 0x80
  98. #define M_MWT 0x40
  99. #define M_WTR 0x04
  100. #define M_GT 0x02
  101. #define M_WT 0x01
  102. // UART control register
  103. #define M_UEN 0x40
  104. #define M_UART_RST 0x20
  105. #define M_CONV 0x10
  106. #define M_TS 0x08
  107. #define M_PE 0x04
  108. #define M_R 0x03
  109. // FIFO config register
  110. #define M_RFP 0x80
  111. #define M_LD 0x0F
  112. // INT control register
  113. #define M_SSL 0x20
  114. #define M_DRM 0x10
  115. #define M_DSM 0x08
  116. #define M_WTE 0x04
  117. #define M_SIM 0x02
  118. #define M_MEM 0x01
  119. #define M_DRM_MEM 0x11
  120. // INT status register
  121. #define M_FNE 0x80
  122. #define M_FE 0x40
  123. #define M_OE 0x20
  124. #define M_DR 0x10
  125. #define M_TRE 0x08
  126. #define M_WTOVF 0x04
  127. #define M_SENSE 0x02
  128. #define M_MOV 0x01
  129. // SMART card interface
  130. #define M_ALT1 0x20
  131. #define M_ALT2 0x10
  132. #define M_ALT0 0x08
  133. #define M_SDE 0x04
  134. #define M_SL 0x02
  135. #define M_SD 0x01
  136. // SMART card control register
  137. #define M_IO 0x80
  138. #define M_VCE 0x40
  139. #define M_SC_RST 0x20
  140. #define M_SCE 0x10
  141. #define M_SCK 0x08
  142. #define M_C8 0x04
  143. #define M_C4 0x02
  144. #define M_VPE 0x01
  145. // Nad
  146. #define HOST_TO_STC1 0x12
  147. #define HOST_TO_STC2 0x52
  148. #define HOST_TO_ICC1 0x02
  149. #define HOST_TO_ICC2 0x42
  150. #define STC1_TO_HOST 0x21
  151. #define STC2_TO_HOST 0x25
  152. #define ICC1_TO_HOST 0x20
  153. #define ICC2_TO_HOST 0x24
  154. // PCB
  155. #define PCB 0x00
  156. #define CLA_READ_REGISTER 0x00
  157. #define INS_READ_REGISTER 0xB0
  158. #define CLA_WRITE_REGISTER 0x00
  159. #define INS_WRITE_REGISTER 0xD0
  160. #define CLA_READ_FIRMWARE_REVISION 0x00
  161. #define INS_READ_FIRMWARE_REVISION 0xB1
  162. #define PCB_DEFAULT 0x00
  163. #define TLV_BUFFER_SIZE 0x20
  164. #define ATR_SIZE 0x40 // TS + 32 + SW + PROLOGUE + EPILOGUE...
  165. #define MAX_T1_BLOCK_SIZE 270
  166. // ATR interface byte coding in TS
  167. #define TAx 0x01
  168. #define TBx 0x02
  169. #define TCx 0x04
  170. #define TDx 0x08
  171. #define FREQ_DIV 1 // 3,58 MHz XTAL -> SC Clock = 3.58MHz
  172. //#define FREQ_DIV 0x08 /* 30MHz XTAL -> SC Clock = 3.75MHz */
  173. #define PROTOCOL_TO 0
  174. #define PROTOCOL_T1 1
  175. #define PROTOCOL_T14 14
  176. #define PROTOCOL_T15 15
  177. #define STC_READ_TIMEOUT 1000
  178. // max. of communication errors while polling the device
  179. #define ERROR_COUNTER_TRESHOLD 5
  180. //
  181. // Macros --------------------------------------------------------------------
  182. //
  183. #define SysCompareMemory( p1, p2, Len ) ( RtlCompareMemory( p1,p2, Len ) != Len )
  184. #define SysCopyMemory( pDest, pSrc, Len ) RtlCopyMemory( pDest, pSrc, Len )
  185. #define SysFillMemory( pDest, Value, Len ) RtlFillMemory( pDest, Len, Value )
  186. //
  187. // Structures ----------------------------------------------------------------
  188. //
  189. typedef struct _DEVICE_EXTENSION
  190. {
  191. // The PDO that we are attached to
  192. PDEVICE_OBJECT AttachedPDO;
  193. // Our PnP device name
  194. UNICODE_STRING DeviceName;
  195. // Current number of io-requests
  196. LONG IoCount;
  197. // Used to access IoCount;
  198. KSPIN_LOCK SpinLock;
  199. // Used to signal that the device has been removed
  200. //KEVENT ReaderRemoved;
  201. // Used to signal that the reader is able to process reqeusts
  202. KEVENT ReaderStarted;
  203. // Used to signal the the reader has been closed
  204. LONG ReaderOpen;
  205. // Used to synchonize the polling thread
  206. KMUTEX hMutex;
  207. // Used to keep track of the current power state the reader is in
  208. LONG PowerState;
  209. // configuration handle for the configuration the device is currently in use
  210. USBD_CONFIGURATION_HANDLE ConfigurationHandle;
  211. // ptr to the USB device descriptor for this device
  212. PUSB_DEVICE_DESCRIPTOR DeviceDescriptor;
  213. // we support up to one interface
  214. PUSBD_INTERFACE_INFORMATION Interface;
  215. // poll thread relevant data
  216. KEVENT FinishPollThread;
  217. KEVENT PollThreadStopped;
  218. PIO_WORKITEM PollWorkItem;
  219. SMARTCARD_EXTENSION SmartcardExtension;
  220. } DEVICE_EXTENSION, *PDEVICE_EXTENSION;
  221. typedef enum _READER_POWER_STATE {
  222. PowerReaderUnspecified = 0,
  223. PowerReaderWorking,
  224. PowerReaderOff
  225. } READER_POWER_STATE, *PREADER_POWER_STATE;
  226. typedef struct _READER_EXTENSION {
  227. UCHAR Device;
  228. // Software revision ID of the firmware.
  229. UCHAR FirmwareMajor, FirmwareMinor;
  230. BOOLEAN CardPresent;
  231. // Current reader power state.
  232. READER_POWER_STATE ReaderPowerState;
  233. // read timeout in ms
  234. ULONG ReadTimeout;
  235. PDEVICE_OBJECT DeviceObject;
  236. UCHAR ucReadBuffer[MIN_BUFFER_SIZE];
  237. ULONG ulReadBufferLen;
  238. // counter for communication errors while polling the reader
  239. ULONG ErrorCounter;
  240. } READER_EXTENSION, *PREADER_EXTENSION;
  241. #define SIZEOF_READER_EXTENSION ( sizeof( READER_EXTENSION ))
  242. typedef struct _STC_REGISTER
  243. {
  244. UCHAR Register;
  245. UCHAR Size;
  246. ULONG Value;
  247. } STC_REGISTER, *PSTC_REGISTER;
  248. //
  249. // wrapper ------------------------------------------------------------------
  250. //
  251. #define IFReadSTCRegister UsbReadSTCRegister
  252. #define IFReadSTCData UsbReadSTCData
  253. #define IFWriteSTCRegister UsbWriteSTCRegister
  254. #define IFWriteSTCData UsbWriteSTCData
  255. #endif // __COMMON_H__
  256. // ------------------------------- END OF FILE -------------------------------