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.

298 lines
13 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. hidusb.h
  5. Abstract:
  6. Author:
  7. Daniel Dean.
  8. Environment:
  9. Kernel & user mode
  10. Revision History:
  11. --*/
  12. #ifndef __HIDUSB_H__
  13. #define __HIDUSB_H__
  14. #include <PSHPACK1.H>
  15. typedef struct _USB_HID_DESCRIPTOR
  16. {
  17. UCHAR bLength;
  18. UCHAR bDescriptorType;
  19. USHORT bcdHID;
  20. UCHAR bCountry;
  21. UCHAR bNumDescriptors;
  22. UCHAR bReportType;
  23. USHORT wReportLength;
  24. } USB_HID_DESCRIPTOR, * PUSB_HID_DESCRIPTOR;
  25. #include <POPPACK.H>
  26. //
  27. // Device Class Constants for HID
  28. //
  29. #define HID_GET_REPORT 0x01
  30. #define HID_GET_IDLE 0x02
  31. #define HID_GET_PROTOCOL 0x03
  32. #define HID_SET_REPORT 0x09
  33. #define HID_SET_IDLE 0x0A
  34. #define HID_SET_PROTOCOL 0x0B
  35. //
  36. // USB Constants that should be defined in a USB header...
  37. //
  38. #define USB_INTERFACE_CLASS_HID 0x03
  39. #define USB_DESCRIPTOR_TYPE_HID 0x21
  40. typedef struct _DEVICE_EXTENSION
  41. {
  42. ULONG DeviceState;
  43. PUSB_DEVICE_DESCRIPTOR DeviceDescriptor;
  44. PUSBD_INTERFACE_INFORMATION Interface;
  45. USBD_CONFIGURATION_HANDLE ConfigurationHandle;
  46. LONG NumPendingRequests;
  47. KEVENT AllRequestsCompleteEvent;
  48. ULONG DeviceFlags;
  49. PIO_WORKITEM ResetWorkItem;
  50. USB_HID_DESCRIPTOR HidDescriptor;
  51. PDEVICE_OBJECT functionalDeviceObject;
  52. } DEVICE_EXTENSION, *PDEVICE_EXTENSION;
  53. /*
  54. * This structure is used to pass information to the
  55. * resetWorkItem callback.
  56. */
  57. typedef struct tag_resetWorkItemContext {
  58. #define RESET_WORK_ITEM_CONTEXT_SIG 'tesR'
  59. ULONG sig;
  60. PIO_WORKITEM ioWorkItem;
  61. PDEVICE_OBJECT deviceObject;
  62. PIRP irpToComplete;
  63. struct tag_resetWorkItemContext *next;
  64. } resetWorkItemContext;
  65. #define DEVICE_STATE_NONE 0
  66. #define DEVICE_STATE_STARTING 1
  67. #define DEVICE_STATE_RUNNING 2
  68. #define DEVICE_STATE_STOPPING 3
  69. #define DEVICE_STATE_STOPPED 4
  70. #define DEVICE_STATE_REMOVING 5
  71. #define DEVICE_STATE_START_FAILED 6
  72. #define DEVICE_FLAGS_HID_1_0_D3_COMPAT_DEVICE 0x00000001
  73. //
  74. // Interface slection options
  75. //
  76. #define HUM_SELECT_DEFAULT_INTERFACE 0
  77. #define HUM_SELECT_SPECIFIED_INTERFACE 1
  78. //
  79. // Device Extension Macros
  80. //
  81. #define GET_MINIDRIVER_DEVICE_EXTENSION(DO) ((PDEVICE_EXTENSION) (((PHID_DEVICE_EXTENSION)(DO)->DeviceExtension)->MiniDeviceExtension))
  82. #define GET_HIDCLASS_DEVICE_EXTENSION(DO) ((PHID_DEVICE_EXTENSION)(DO)->DeviceExtension)
  83. #define GET_NEXT_DEVICE_OBJECT(DO) (((PHID_DEVICE_EXTENSION)(DO)->DeviceExtension)->NextDeviceObject)
  84. #if DBG
  85. extern ULONG HIDUSB_DebugLevel;
  86. extern BOOLEAN dbgTrapOnWarn;
  87. #define DBGBREAK \
  88. { \
  89. DbgPrint("'HIDUSB> Code coverage trap: file %s, line %d \n", __FILE__, __LINE__ ); \
  90. DbgBreakPoint(); \
  91. }
  92. #define DBGWARN(args_in_parens) \
  93. { \
  94. DbgPrint("'HIDUSB> *** WARNING *** (file %s, line %d)\n", __FILE__, __LINE__ ); \
  95. DbgPrint("' > "); \
  96. DbgPrint args_in_parens; \
  97. DbgPrint("\n"); \
  98. if (dbgTrapOnWarn){ \
  99. DbgBreakPoint(); \
  100. } \
  101. }
  102. #define DBGERR(args_in_parens) \
  103. { \
  104. DbgPrint("'HIDUSB> *** ERROR *** (file %s, line %d)\n", __FILE__, __LINE__ ); \
  105. DbgPrint("' > "); \
  106. DbgPrint args_in_parens; \
  107. DbgPrint("\n"); \
  108. DbgBreakPoint(); \
  109. }
  110. #define DBGOUT(args_in_parens) \
  111. { \
  112. DbgPrint("'HIDUSB> "); \
  113. DbgPrint args_in_parens; \
  114. DbgPrint("\n"); \
  115. }
  116. #define DBGPRINT(lvl, args_in_parens) \
  117. if (lvl <= HIDUSB_DebugLevel){ \
  118. DBGOUT(args_in_parens); \
  119. }
  120. #else // DBG
  121. #define DBGPRINT(lvl, arg)
  122. #define DBGBREAK
  123. #define DBGWARN(args_in_parens)
  124. #define DBGERR(args_in_parens)
  125. #define DBGOUT(args_in_parens)
  126. #endif // DBG
  127. #define HumBuildGetDescriptorRequest(urb, \
  128. function, \
  129. length, \
  130. descriptorType, \
  131. index, \
  132. languageId, \
  133. transferBuffer, \
  134. transferBufferMDL, \
  135. transferBufferLength, \
  136. link) { \
  137. (urb)->UrbHeader.Function = (function); \
  138. (urb)->UrbHeader.Length = (length); \
  139. (urb)->UrbControlDescriptorRequest.TransferBufferLength = (transferBufferLength); \
  140. (urb)->UrbControlDescriptorRequest.TransferBufferMDL = (transferBufferMDL); \
  141. (urb)->UrbControlDescriptorRequest.TransferBuffer = (transferBuffer); \
  142. (urb)->UrbControlDescriptorRequest.DescriptorType = (descriptorType); \
  143. (urb)->UrbControlDescriptorRequest.Index = (index); \
  144. (urb)->UrbControlDescriptorRequest.LanguageId = (languageId); \
  145. (urb)->UrbControlDescriptorRequest.UrbLink = (link); }
  146. #define HumBuildClassRequest(urb, \
  147. function, \
  148. transferFlags, \
  149. transferBuffer, \
  150. transferBufferLength, \
  151. requestType, \
  152. request, \
  153. value, \
  154. index, \
  155. reqLength){ \
  156. (urb)->UrbHeader.Length = (USHORT) sizeof( struct _URB_CONTROL_VENDOR_OR_CLASS_REQUEST); \
  157. (urb)->UrbHeader.Function = function; \
  158. (urb)->UrbControlVendorClassRequest.Index = (index); \
  159. (urb)->UrbControlVendorClassRequest.RequestTypeReservedBits = (requestType); \
  160. (urb)->UrbControlVendorClassRequest.Request = (request); \
  161. (urb)->UrbControlVendorClassRequest.Value = (value); \
  162. (urb)->UrbControlVendorClassRequest.TransferFlags = (transferFlags); \
  163. (urb)->UrbControlVendorClassRequest.TransferBuffer = (transferBuffer); \
  164. (urb)->UrbControlVendorClassRequest.TransferBufferLength = (transferBufferLength); }
  165. #define HumBuildSelectConfigurationRequest(urb, \
  166. length, \
  167. configurationDescriptor) { \
  168. (urb)->UrbHeader.Function = URB_FUNCTION_SELECT_CONFIGURATION; \
  169. (urb)->UrbHeader.Length = (length); \
  170. (urb)->UrbSelectConfiguration.ConfigurationDescriptor = (configurationDescriptor); }
  171. #define HumBuildOsFeatureDescriptorRequest(urb, \
  172. length, \
  173. interface, \
  174. index, \
  175. transferBuffer, \
  176. transferBufferMDL, \
  177. transferBufferLength, \
  178. link) { \
  179. (urb)->UrbHeader.Function = URB_FUNCTION_GET_MS_FEATURE_DESCRIPTOR; \
  180. (urb)->UrbHeader.Length = (length); \
  181. (urb)->UrbOSFeatureDescriptorRequest.Recipient = 1; \
  182. (urb)->UrbOSFeatureDescriptorRequest.TransferBufferLength = (transferBufferLength); \
  183. (urb)->UrbOSFeatureDescriptorRequest.TransferBufferMDL = (transferBufferMDL); \
  184. (urb)->UrbOSFeatureDescriptorRequest.TransferBuffer = (transferBuffer); \
  185. (urb)->UrbOSFeatureDescriptorRequest.InterfaceNumber = (interface); \
  186. (urb)->UrbOSFeatureDescriptorRequest.MS_FeatureDescriptorIndex = (index); \
  187. (urb)->UrbOSFeatureDescriptorRequest.UrbLink = (link); }
  188. #define BAD_POINTER ((PVOID)0xFFFFFFFE)
  189. /*
  190. * HIDUSB signature tag for memory allocations
  191. */
  192. #define HIDUSB_TAG (ULONG)'UdiH'
  193. //
  194. // Function prototypes
  195. //
  196. NTSTATUS DriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING registryPath);
  197. NTSTATUS HumAbortPendingRequests(IN PDEVICE_OBJECT DeviceObject);
  198. NTSTATUS HumCreateClose(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp);
  199. NTSTATUS HumInternalIoctl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp);
  200. NTSTATUS HumPnP(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp);
  201. NTSTATUS HumPower(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp);
  202. NTSTATUS HumCreateDevice(IN PDRIVER_OBJECT DriverObject, IN OUT PDEVICE_OBJECT *DeviceObject);
  203. NTSTATUS HumAddDevice(IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT FunctionalDeviceObject);
  204. NTSTATUS HumStartDevice(IN PDEVICE_OBJECT DeviceObject);
  205. NTSTATUS HumPnpCompletion(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context);
  206. NTSTATUS HumInitDevice(IN PDEVICE_OBJECT DeviceObject);
  207. NTSTATUS HumStopDevice(IN PDEVICE_OBJECT DeviceObject);
  208. NTSTATUS HumRemoveDevice(IN PDEVICE_OBJECT DeviceObject, PIRP Irp);
  209. NTSTATUS HumCallUSB(IN PDEVICE_OBJECT DeviceObject, IN PURB Urb);
  210. VOID HumUnload(IN PDRIVER_OBJECT DriverObject);
  211. NTSTATUS HumGetHidDescriptor(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp);
  212. NTSTATUS HumGetReportDescriptor(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, BOOLEAN *NeedsCompletion);
  213. NTSTATUS HumReadReport(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, OUT BOOLEAN *NeedsCompletion);
  214. NTSTATUS HumReadCompletion(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context);
  215. NTSTATUS HumWriteReport(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, OUT BOOLEAN *NeedsCompletion);
  216. NTSTATUS HumGetSetReport(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, OUT BOOLEAN *NeedsCompletion);
  217. NTSTATUS HumWriteCompletion(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context);
  218. NTSTATUS HumGetString(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, OUT BOOLEAN *NeedsCompletion);
  219. NTSTATUS HumGetDeviceAttributes(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp);
  220. NTSTATUS HumGetDescriptorRequest(IN PDEVICE_OBJECT DeviceObject, IN USHORT Function, IN ULONG DescriptorType, IN OUT PVOID *Descriptor, IN OUT ULONG *DescSize, IN ULONG TypeSize, IN ULONG Index, IN ULONG LangID);
  221. NTSTATUS HumSetIdle(IN PDEVICE_OBJECT DeviceObject);
  222. NTSTATUS HumSelectConfiguration(IN PDEVICE_OBJECT DeviceObject, IN PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor);
  223. NTSTATUS HumParseHidInterface(IN PDEVICE_EXTENSION DeviceExtension, IN PUSB_INTERFACE_DESCRIPTOR InterfaceDesc, IN ULONG InterfaceLength, OUT PUSB_HID_DESCRIPTOR *HidDescriptor);
  224. NTSTATUS HumGetDeviceDescriptor(IN PDEVICE_OBJECT, IN PDEVICE_EXTENSION);
  225. NTSTATUS HumGetConfigDescriptor(IN PDEVICE_OBJECT DeviceObject, OUT PUSB_CONFIGURATION_DESCRIPTOR *ConfigurationDesc, OUT PULONG ConfigurationDescLength);
  226. NTSTATUS HumGetHidInfo(IN PDEVICE_OBJECT DeviceObject, IN PUSB_CONFIGURATION_DESCRIPTOR ConfigDesc, IN ULONG DescriptorLength);
  227. NTSTATUS DumpConfigDescriptor(IN PUSB_CONFIGURATION_DESCRIPTOR ConfigDesc, IN ULONG DescriptorLength);
  228. VOID HumDecrementPendingRequestCount(IN PDEVICE_EXTENSION DeviceExtension);
  229. NTSTATUS HumIncrementPendingRequestCount(IN PDEVICE_EXTENSION DeviceExtension);
  230. NTSTATUS HumResetWorkItem(IN PDEVICE_OBJECT deviceObject, IN PVOID Context);
  231. NTSTATUS HumResetParentPort(IN PDEVICE_OBJECT DeviceObject);
  232. NTSTATUS HumGetPortStatus(IN PDEVICE_OBJECT DeviceObject, IN PULONG PortStatus);
  233. NTSTATUS HumResetInterruptPipe(IN PDEVICE_OBJECT DeviceObject);
  234. NTSTATUS HumSystemControl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp);
  235. NTSTATUS HumGetStringDescriptor(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp);
  236. NTSTATUS HumGetPhysicalDescriptor(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, BOOLEAN *NeedsCompletion);
  237. NTSTATUS HumGetMsGenreDescriptor(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp);
  238. NTSTATUS HumSendIdleNotificationRequest(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, BOOLEAN *NeedsCompletion);
  239. NTSTATUS HumQueueResetWorkItem(PDEVICE_OBJECT DeviceObject, PIRP Irp);
  240. extern KSPIN_LOCK resetWorkItemsListSpinLock;
  241. #endif