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.

385 lines
8.9 KiB

  1. /*++
  2. Copyright (c) 1998 Gemplus Development
  3. Name:
  4. gprnt.h
  5. Description:
  6. This module holds the prototypes of the functions
  7. from gprnt.C + MACRO and structures declarations
  8. Environment:
  9. Kernel Mode
  10. Revision History:
  11. 22/11/98: V1.00.004 (Y. Nadeau)
  12. - Add KEvent ReaderRemoved
  13. 06/05/98: V1.00.003 (P. Plouidy)
  14. - Power management for NT5
  15. 10/02/98: V1.00.002 (P. Plouidy)
  16. - Plug and Play for NT5
  17. 03/07/97: V1.00.001 (P. Plouidy)
  18. - Start of development.
  19. --*/
  20. #define SMARTCARD_POOL_TAG 'bGCS'
  21. //
  22. // Include
  23. //
  24. // - smclib.h: smart card library definitions.
  25. //
  26. #include <ntddk.h>
  27. #include <smclib.h>
  28. #ifndef _GPRNT_
  29. #define _GPRNT_
  30. //
  31. // Constant section
  32. //
  33. #define SC_VENDOR_NAME "Gemplus"
  34. #define SC_DRIVER_NAME "GPR400"
  35. #define SC_IFD_TYPE "GPR400"
  36. #define GPR_DEFAULT_FREQUENCY 3686
  37. #define GPR_MAX_FREQUENCY 3686
  38. #define GPR_MAX_IFSD 253
  39. #define GPR_DEFAULT_DATARATE 9909
  40. #define GPR_MAX_DATARATE 9909
  41. #define GPR_MAX_DEVICE 4
  42. #define GPR_DEFAULT_TIME 120l // Exchange Cmd
  43. #define GPR_CMD_TIME 5 // Gpr Cmd only
  44. #define GPR_DEFAULT_POWER_TIME 0
  45. #define GPR_BUFFER_SIZE 262
  46. // DRIVER FLAVOR
  47. // 0 : Gemplus GPR400
  48. // 1 : IBM IBM400
  49. // 2 : COMPAQ PC_CARD_SMARTCARD_READER
  50. // ...
  51. #define DF_GPR400 0
  52. #define DF_IBM400 1
  53. #define DF_CPQ400 2
  54. #define SZ_VENDOR_NAME "GEMPLUS"
  55. #define SZ_VENDOR_NAME_IBM "IBM"
  56. #define SZ_VENDOR_NAME_COMPAQ "COMPAQ"
  57. #define SZ_READER_NAME "GPR400"
  58. #define SZ_READER_NAME_IBM "IBM400"
  59. #define SZ_READER_NAME_COMPAQ "PC_CARD_SMARTCARD_READER"
  60. #define GPR400_ID "\\??\\PCMCIA#GEMPLUS-GPR400"
  61. #define COMPAQ_ID "\\??\\PCMCIA#COMPAQ-PC_Card_SmartCard_Reader-446E"
  62. #define CHECK_ID_LEN 25 // Check first 25 bytes!
  63. //
  64. // MACRO declarations.
  65. //
  66. #ifndef SMARTCARD_NT_LOG
  67. #define SMARTCARD_NT_LOG(pObj, lErrCode, pwszStr, ulDump) \
  68. do { \
  69. if (lErrCode != 0) { \
  70. SmartcardLogError(pObj, \
  71. lErrCode, \
  72. pwszStr, \
  73. ulDump); } \
  74. } while (0)
  75. #endif
  76. #ifndef NT_FAIL
  77. #define NT_FAIL(status) (((NTSTATUS) (status)) < 0)
  78. #endif
  79. #ifndef IS_POINTER_INVALID
  80. #define IS_POINTER_INVALID(p) (!IS_POINTER_VALID(p))
  81. #endif
  82. #ifndef IS_POINTER_VALID
  83. #define IS_POINTER_VALID(p) \
  84. ((BOOLEAN) ((p != NULL) ? TRUE : FALSE))
  85. #endif
  86. #ifndef IS_HANDLE_VALID
  87. #define IS_HANDLE_VALID(h) \
  88. ((BOOLEAN) ((h == NULL) ? FALSE : TRUE))
  89. #endif
  90. #ifndef IS_HANDLE_INVALID
  91. #define IS_HANDLE_INVALID(h) (!IS_HANDLE_VALID(h))
  92. #endif
  93. #ifndef INIT_STRING
  94. #define INIT_STRING(s) \
  95. s.Length = 0; \
  96. s.MaximumLength = 0; \
  97. s.Buffer = NULL
  98. #endif
  99. //
  100. // Data structures.
  101. //
  102. // PCMCIA_READER_CONFIG:Configuration data structure for PC Card readers.
  103. typedef struct _PCMCIA_READER_CONFIG {
  104. KIRQL Level;
  105. KAFFINITY Affinity;
  106. ULONG Vector;
  107. USHORT BufferSize;
  108. USHORT Reserved;
  109. } PCMCIA_READER_CONFIG, *PPCMCIA_READER_CONFIG, *LPPCMCIA_READER_CONFIG;
  110. typedef enum _READER_POWER_STATE {
  111. PowerReaderUnspecified = 0,
  112. PowerReaderWorking,
  113. PowerReaderOff
  114. } READER_POWER_STATE, *PREADER_POWER_STATE;
  115. typedef enum _ACTION {
  116. Undefined = 0,
  117. SkipRequest,
  118. WaitForCompletion,
  119. CompleteRequest,
  120. MarkPending
  121. } ACTION;
  122. // GPR400_REGISTERS: GPR400 I/O registers
  123. typedef struct _GPR400_REGISTERS {
  124. UCHAR ucHandshake;
  125. UCHAR ucProgram;
  126. UCHAR ucT;
  127. UCHAR ucL;
  128. UCHAR ucV;
  129. UCHAR Dummy[3];
  130. } GPR400_REGISTERS, *PGPR400_REGISTERS, *LPGPR400_REGISTERS;
  131. // READER_EXTENSION:
  132. typedef struct _READER_EXTENSION {
  133. ULONG CmdTimeOut;
  134. ULONG PowerTimeOut;
  135. PGPR400_REGISTERS BaseIoAddress;
  136. PCMCIA_READER_CONFIG ConfigData;
  137. KEVENT GPRAckEvent;
  138. KEVENT GPRIccPresEvent;
  139. KDPC CardDpcObject;
  140. KTIMER CardDetectionTimer;
  141. UCHAR OsVersion;
  142. USHORT Lo;
  143. UCHAR To;
  144. PUCHAR Vo;
  145. READER_POWER_STATE ReaderPowerState;
  146. BOOLEAN PowerRequest;
  147. PDEVICE_OBJECT AttachedDeviceObject;
  148. BOOLEAN CardPresent;
  149. // Used to signal that the device has been removed
  150. KEVENT ReaderRemoved;
  151. BOOLEAN NewDevice;
  152. KEVENT IdleState;
  153. BOOLEAN RestartCardDetection;
  154. } READER_EXTENSION, *PREADER_EXTENSION, *LPREADER_EXTENSION;
  155. // DEVICE_EXTENSION:
  156. typedef struct _DEVICE_EXTENSION {
  157. PDEVICE_OBJECT DeviceObject;
  158. PDEVICE_OBJECT PhysicalDeviceObject;
  159. PKINTERRUPT InterruptObject;
  160. PKSERVICE_ROUTINE InterruptServiceRoutine;
  161. KDPC DpcObject;
  162. PVOID IsrContext;
  163. SMARTCARD_EXTENSION SmartcardExtension;
  164. UNICODE_STRING PnPDeviceName;
  165. LONG IoCount;
  166. KSPIN_LOCK SpinLock;
  167. BOOLEAN OpenFlag;
  168. LONG PowerState;
  169. KEVENT ReaderStarted;
  170. KEVENT ReaderClosed;
  171. // A worker thread to startup GPR gently
  172. PIO_WORKITEM GprWorkStartup;
  173. LONG DriverFlavor; // GPR400(default), IBM400 or CPQ400?
  174. PIRP PowerIrp;
  175. } DEVICE_EXTENSION, *PDEVICE_EXTENSION, *LPDEVICE_EXTENSION;
  176. //
  177. // Prototype section:
  178. //
  179. NTSTATUS DriverEntry
  180. (
  181. PDRIVER_OBJECT DriverObject,
  182. PUNICODE_STRING RegistryPath
  183. );
  184. NTSTATUS GprAddDevice
  185. (
  186. IN PDRIVER_OBJECT DriverObject,
  187. IN PDEVICE_OBJECT PhysicalDeviceObject
  188. );
  189. NTSTATUS GprSystemControl
  190. (
  191. IN PDEVICE_OBJECT DeviceObject,
  192. IN PIRP Irp
  193. );
  194. NTSTATUS GprDeviceControl
  195. (
  196. PDEVICE_OBJECT DeviceObject,
  197. PIRP Irp
  198. );
  199. NTSTATUS GprCleanup
  200. (
  201. IN PDEVICE_OBJECT DeviceObject,
  202. IN PIRP Irp
  203. );
  204. BOOLEAN GprIsr
  205. (
  206. IN PKINTERRUPT pkInterrupt,
  207. IN PVOID pvContext
  208. );
  209. NTSTATUS
  210. GprCancelEventWait
  211. (
  212. IN PDEVICE_OBJECT DeviceObject,
  213. IN PIRP Irp
  214. );
  215. VOID GprCardEventDpc
  216. (
  217. PKDPC Dpc,
  218. PDEVICE_OBJECT DeviceObject,
  219. PDEVICE_EXTENSION pDevExt,
  220. PSMARTCARD_EXTENSION SmartcardExtension
  221. );
  222. VOID GprCardPresenceDpc
  223. (
  224. IN PKDPC pDpc,
  225. IN PVOID pvContext,
  226. IN PVOID pArg1,
  227. IN PVOID pArg2
  228. );
  229. NTSTATUS GprDispatchPnp
  230. (
  231. IN PDEVICE_OBJECT DeviceObject,
  232. IN PIRP Irp
  233. );
  234. NTSTATUS GprCallPcmciaDriver
  235. (
  236. IN PDEVICE_OBJECT DeviceObject,
  237. IN PIRP Irp
  238. );
  239. NTSTATUS GprStartDevice
  240. (
  241. PDEVICE_OBJECT DeviceObject,
  242. PCM_FULL_RESOURCE_DESCRIPTOR FullResourceDescriptor
  243. );
  244. VOID GprStopDevice
  245. (
  246. PDEVICE_OBJECT DeviceObject
  247. );
  248. VOID GprUnloadDriver
  249. (
  250. PDRIVER_OBJECT DriverObject
  251. );
  252. VOID GprUnloadDevice
  253. (
  254. PDEVICE_OBJECT DeviceObject
  255. );
  256. NTSTATUS GprCreateClose
  257. (
  258. PDEVICE_OBJECT DeviceObject,
  259. PIRP Irp
  260. );
  261. NTSTATUS GprComplete
  262. (
  263. IN PDEVICE_OBJECT DeviceObject,
  264. IN PIRP Irp,
  265. IN PKEVENT Event
  266. );
  267. NTSTATUS GprCreateDevice
  268. (
  269. IN PDRIVER_OBJECT DriverObject,
  270. IN PDEVICE_OBJECT PhysicalDeviceObject,
  271. OUT PDEVICE_OBJECT *DeviceObject
  272. );
  273. VOID GprFinishPendingRequest
  274. (
  275. PDEVICE_OBJECT DeviceObject,
  276. NTSTATUS NTStatus
  277. );
  278. VOID GprWorkStartup
  279. (
  280. IN PDEVICE_OBJECT DeviceObject,
  281. IN PVOID Context
  282. );
  283. VOID setBusy(PREADER_EXTENSION Device);
  284. VOID setIdle(PREADER_EXTENSION Device);
  285. NTSTATUS waitForIdle(PREADER_EXTENSION Device);
  286. NTSTATUS waitForIdleAndBlock(PREADER_EXTENSION Device);
  287. NTSTATUS testForIdleAndBlock(PREADER_EXTENSION Device);
  288. NTSTATUS GprPower
  289. (
  290. IN PDEVICE_OBJECT DeviceObject,
  291. IN PIRP Irp
  292. );
  293. NTSTATUS power_HandleQueryPower(PDEVICE_OBJECT DeviceObject, IN PIRP Irp);
  294. NTSTATUS power_HandleSetPower(PDEVICE_OBJECT DeviceObject, IN PIRP Irp);
  295. NTSTATUS onDevicePowerUpComplete(
  296. IN PDEVICE_OBJECT NullDeviceObject,
  297. IN PIRP Irp,
  298. IN PVOID DeviceObject
  299. );
  300. NTSTATUS onPowerRequestCompletion(
  301. IN PDEVICE_OBJECT DeviceObject,
  302. IN UCHAR MinorFunction,
  303. IN POWER_STATE PowerState,
  304. IN PVOID Context,
  305. IN PIO_STATUS_BLOCK IoStatus
  306. );
  307. #define ATTACHED_DEVICE_OBJECT deviceExtension->SmartcardExtension.ReaderExtension->AttachedDeviceObject
  308. #endif