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.

343 lines
8.7 KiB

  1. #if !defined( __USBSC_H__ )
  2. #define __USBSC_H__
  3. #define DRIVER_NAME "USBSC"
  4. #include <NTDDK.H>
  5. #include "smclib.h"
  6. #include <windef.h>
  7. #include <usb.h>
  8. #include "usbutil.h"
  9. #include "scutil.h"
  10. #define ESCAPE_COMMAND_ENABLE L"EscapeCommandEnable"
  11. #define SMARTCARD_POOL_TAG 'DICC'
  12. #define CCID_CLASS_DESCRIPTOR_TYPE 0x21
  13. #define PC_to_RDR_IccPowerOn 0x62
  14. #define PC_to_RDR_IccPowerOff 0x63
  15. #define PC_to_RDR_GetSlotStatus 0x65
  16. #define PC_to_RDR_XfrBlock 0x6F
  17. #define PC_to_RDR_GetParameters 0x6C
  18. #define PC_to_RDR_ResetParameters 0x6D
  19. #define PC_to_RDR_SetParameters 0x61
  20. #define PC_to_RDR_Escape 0x6B
  21. #define PC_to_RDR_IccClock 0x6E
  22. #define PC_to_RDR_T0APDU 0x6A
  23. #define PC_to_RDR_Secure 0x69
  24. #define PC_to_RDR_Mechanical 0x71
  25. #define PC_to_RDR_Abort 0x72
  26. #define PC_to_RDR_SetDataRateAndClockFrequency 0x73
  27. #define RDR_to_PC_DataBlock 0x80
  28. #define RDR_to_PC_SlotStatus 0x81
  29. #define RDR_to_PC_Parameters 0x82
  30. #define RDR_to_PC_Escape 0x83
  31. #define RDR_to_PC_DataRateAndClockFrequency 0x84
  32. #define RDR_to_PC_NotifySlotChange 0x50
  33. #define RDR_to_PC_HardwareError 0x51
  34. #define ABORT 0x01
  35. #define GET_CLOCK_FREQUENCIES 0x02
  36. #define GET_DATA_RATES 0x03
  37. #define CMD_ABORTED 0xFF
  38. #define ICC_MUTE 0xFE
  39. #define XFR_PARITY_ERROR 0xFD
  40. #define XFR_OVERRUN 0xFC
  41. #define HW_ERROR 0xFB
  42. #define BAD_ATR_TS 0xF8
  43. #define BAD_ATR_TCK 0xF7
  44. #define ICC_PROTOCOL_NOT_SUPPORTED 0xF6
  45. #define ICC_CLASS_NOT_SUPPORTED 0xF5
  46. #define PROCEDURE_BYTE_CONFLICT 0xF4
  47. #define DEACTIVATED_PROTOCOL 0xF3
  48. #define BUSY_WITH_AUTO_SEQUENCE 0xF2
  49. #define PIN_TIMEOUT 0xF0
  50. #define PIN_CANCELLED 0xEF
  51. #define CMD_SLOT_BUSY 0xE0
  52. #define COMMAND_STATUS_MASK 0xC0
  53. #define COMMAND_STATUS_FAILED 0x40
  54. #define COMMAND_STATUS_TIME_EXT 0x80
  55. #define COMMAND_STATUS_SUCCESS 0x00
  56. #define ICC_STATUS_MASK 0x03
  57. #define CHARACTER_LEVEL 0x00
  58. #define TPDU_LEVEL 0x01
  59. #define SHORT_APDU_LEVEL 0x02
  60. #define EXTENDED_APDU_LEVEL 0x04
  61. #define ATR_SIZE 64
  62. #define AUTO_PARAMETER_CONFIG 0x02
  63. #define AUTO_ICC_ACTIVATION 0x04
  64. #define AUTO_VOLTAGE_SELECTION 0x08
  65. #define AUTO_CLOCK_FREQ 0x10
  66. #define AUTO_BAUD_RATE 0x20
  67. #define AUTO_PARAMETER_NEGOTIATION 0x40
  68. #define AUTO_PPS 0x80
  69. #define AUTO_CLOCK_STOP 0x100
  70. #define NOZERO_NAD_ACCEPT 0x200
  71. #define AUTO_IFSD_EXCHANGE 0x400
  72. #define TPDU_EXCHANGE_LEVEL 0x10000
  73. #define SHORT_APDU_EXCHANGE 0x20000
  74. #define EXT_APDU_EXCHANGE 0x40000
  75. #define SLOT0_MASK 0x3
  76. #define SLOT1_MASK 0xc
  77. #define SLOT2_MASK 0x30
  78. #define SLOT3_MASK 0xc0
  79. #define IOCTL_CCID_ESCAPE SCARD_CTL_CODE(3500)
  80. #include <pshpack1.h>
  81. typedef struct _CCID_CLASS_DESCRIPTOR
  82. {
  83. BYTE bLength;
  84. BYTE bDescriptorType;
  85. WORD bcdCCID;
  86. BYTE bMaxSlotIndex;
  87. BYTE bVoltageSupport;
  88. DWORD dwProtocols;
  89. DWORD dwDefaultClock;
  90. DWORD dwMaximumClock;
  91. BYTE bNumClockSupported;
  92. DWORD dwDataRate;
  93. DWORD dwMaxDataRate;
  94. BYTE bNumDataRatesSupported;
  95. DWORD dwMaxIFSD;
  96. DWORD dwSynchProtocols;
  97. DWORD dwMechanical;
  98. DWORD dwFeatures;
  99. DWORD dwMaxCCIDMessageLength;
  100. BYTE bClassGetResponse;
  101. BYTE bClassEnvelope;
  102. WORD wLcdLayout;
  103. BYTE bPINSupport;
  104. BYTE bMaxCCIDBusySlots;
  105. } CCID_CLASS_DESCRIPTOR, *PCCID_CLASS_DESCRIPTOR;
  106. #include <poppack.h>
  107. typedef struct _DEVICE_EXTENSION
  108. {
  109. SCUTIL_HANDLE ScUtilHandle; // Utility library handle
  110. USB_WRAPPER_HANDLE WrapperHandle; // Points to the storage used by the Usb Wrapper
  111. SMARTCARD_EXTENSION SmartcardExtension;
  112. PDEVICE_OBJECT LowerDeviceObject;
  113. PDEVICE_OBJECT PhysicalDeviceObject;
  114. IO_REMOVE_LOCK RemoveLock;
  115. ULONG DeviceInstance;
  116. DEVICE_POWER_STATE PowerState; // Used to keep track of the current power state the reader is in
  117. USBD_INTERFACE_INFORMATION* Interface;
  118. PUSB_DEVICE_DESCRIPTOR DeviceDescriptor;
  119. DEVICE_CAPABILITIES DeviceCapabilities;
  120. } DEVICE_EXTENSION, *PDEVICE_EXTENSION;
  121. typedef struct _READER_EXTENSION {
  122. BOOLEAN CardPresent;
  123. USBD_PIPE_HANDLE BulkOutHandle;
  124. UINT BulkOutIndex;
  125. USBD_PIPE_HANDLE BulkInHandle;
  126. UINT BulkInIndex;
  127. USBD_PIPE_HANDLE InterruptHandle;
  128. UINT InterruptIndex;
  129. // Current reader power state.
  130. // READER_POWER_STATE ReaderPowerState;
  131. // read timeout in ms
  132. ULONG ReadTimeout;
  133. PDEVICE_OBJECT DeviceObject;
  134. DWORD SequenceNumber;
  135. PDEVICE_EXTENSION DeviceExtension;
  136. DWORD MaxMessageLength;
  137. WORD ExchangeLevel;
  138. CCID_CLASS_DESCRIPTOR
  139. ClassDescriptor;
  140. BYTE CurrentVoltage;
  141. BOOLEAN EscapeCommandEnabled;
  142. } READER_EXTENSION, *PREADER_EXTENSION;
  143. #include <pshpack1.h>
  144. typedef struct _USBSC_OUT_MESSAGE_HEADER
  145. {
  146. BYTE bMessageType;
  147. DWORD dwLength;
  148. BYTE bSlot;
  149. BYTE bSeq;
  150. union {
  151. BYTE bPowerSelect;
  152. struct {
  153. BYTE bBWI;
  154. WORD wLevelParameter;
  155. };
  156. BYTE bProtocolNum;
  157. BYTE bClockCommand;
  158. struct {
  159. BYTE bmChanges;
  160. BYTE bClassGetResponse;
  161. BYTE bClassEnvelope;
  162. };
  163. BYTE bFunction;
  164. };
  165. } USBSC_OUT_MESSAGE_HEADER, *PUSBSC_OUT_MESSAGE_HEADER;
  166. typedef struct _USBSC_IN_MESSAGE_HEADER
  167. {
  168. BYTE bMessageType;
  169. DWORD dwLength;
  170. BYTE bSlot;
  171. BYTE bSeq;
  172. BYTE bStatus;
  173. BYTE bError;
  174. union {
  175. BYTE bChainParameter;
  176. BYTE bClockStatus;
  177. BYTE bProtocolNum;
  178. };
  179. } USBSC_IN_MESSAGE_HEADER, *PUSBSC_IN_MESSAGE_HEADER;
  180. typedef struct _USBSC_SLOT_CHANGE_HEADER
  181. {
  182. BYTE bMessageType;
  183. BYTE bmSlotICCState;
  184. } USBSC_SLOT_CHANGE_HEADER, *PUSBSC_SLOT_CHANGE_HEADER;
  185. typedef struct _USBSC_HWERROR_HEADER
  186. {
  187. BYTE bMessageType;
  188. BYTE bSlot;
  189. BYTE bSeq;
  190. BYTE bHardwareErrorCode;
  191. } USBSC_HWERROR_HEADER, *PUSBSC_HWERROR_HEADER;
  192. typedef struct _PROTOCOL_DATA_T0
  193. {
  194. BYTE bmFindexDindex;
  195. BYTE bmTCCKST0;
  196. BYTE bGuardTimeT0;
  197. BYTE bWaitingIntegerT0;
  198. BYTE bClockStop;
  199. } PROTOCOL_DATA_T0, *PPROTOCOL_DATA_T0;
  200. typedef struct _PROTOCOL_DATA_T1
  201. {
  202. BYTE bmFindexDindex;
  203. BYTE bmTCCKST1;
  204. BYTE bGuardTimeT1;
  205. BYTE bmWaitingIntegersT1;
  206. BYTE bClockStop;
  207. BYTE bIFSC;
  208. BYTE bNadValue;
  209. } PROTOCOL_DATA_T1, *PPROTOCOL_DATA_T1;
  210. typedef struct _CLOCK_AND_DATA_RATE
  211. {
  212. DWORD dwClockFrequency;
  213. DWORD dwDataRate;
  214. } CLOCK_AND_DATA_RATE, *PCLOCK_AND_DATA_RATE;
  215. typedef struct _PIN_VERIFICATION_DATA
  216. {
  217. BYTE bTimeOut;
  218. BYTE bmFormatString;
  219. BYTE bmPINBlockString;
  220. BYTE bmPINLengthFormat;
  221. WORD wPINMaxExtraDigit;
  222. BYTE bEntryValidationCondition;
  223. BYTE bNumberMessage;
  224. WORD wLangId;
  225. BYTE bMsgIndex;
  226. BYTE bTeoPrologue;
  227. WORD wRFU;
  228. } PIN_VERIFICATION_DATA, *PPIN_VERIFICATION_DATA;
  229. typedef struct _PIN_MODIFICATION_DATA
  230. {
  231. BYTE bTimeOut;
  232. BYTE bmFormatString;
  233. BYTE bmPINBlockString;
  234. BYTE bmPinLengthFormat;
  235. BYTE bInsertionOffsetOld;
  236. BYTE bInsertionOffsetNew;
  237. WORD wPINMaxExtraDigit;
  238. BYTE bConfirmPIN;
  239. BYTE bEntryValidationCondition;
  240. BYTE bNumberMessage;
  241. WORD wLangId;
  242. BYTE bMsgIndex1;
  243. BYTE bMsgIndex2;
  244. BYTE bMsgIndex3;
  245. BYTE bTeoPrologue;
  246. WORD wRFU;
  247. } PIN_MODIFICATION_DATA, *PPIN_MODIFICATION_DATA;
  248. typedef struct _PPS_REQUEST
  249. {
  250. BYTE bPPSS;
  251. BYTE bPPS0;
  252. BYTE bPPS1;
  253. BYTE bPCK;
  254. } PPS_REQUEST, *PPPS_REQUEST;
  255. #include <poppack.h>
  256. NTSTATUS
  257. DriverEntry(
  258. PDRIVER_OBJECT DriverObject,
  259. PUNICODE_STRING RegistryPath
  260. );
  261. #endif // !__USBSC_H__