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.

326 lines
13 KiB

  1. #ifndef __CHAP9_H__
  2. #define __CHAP9_H__
  3. //
  4. // CHAP9_GETDEVHANDLE requires that the lpInBuffer parameter of the
  5. // DeviceIOControl function points to a REQ_DEVICE_HANDLES structure.
  6. //
  7. // CHAP9_USB_CONTROL requires that the lpInBuffer parameter of the
  8. // DeviceIOControl function points to a REQ structure. The 'function'
  9. // field of REQ_HEADER determines which union structure is actually
  10. // passed.
  11. // Structure for getting device handles. DeviceHandle should be set to
  12. // either NULL or a valid handle. If it is set to NULL, then the driver
  13. // should return the first USB device handle. On return, the driver will
  14. // set NextDeviceHandle to a valid handle for the next USB device. If no
  15. // more devices exist then the field is set to NULL. The returned
  16. // DeviceString should be some way that users can identify the device.
  17. // Identification should include the Vendor ID and Product ID and some
  18. // instance info.
  19. //
  20. struct _REQ_DEVICE_HANDLES {
  21. PVOID DeviceHandle;
  22. PVOID NextDeviceHandle;
  23. UCHAR DeviceString[128];
  24. };
  25. //
  26. // These functions are put in the function field of REQ_HEADER
  27. //
  28. #define REQ_FUNCTION_GET_DESCRIPTOR 0x0001
  29. #define REQ_FUNCTION_SET_DESCRIPTOR 0x0002
  30. #define REQ_FUNCTION_SET_FEATURE 0x0003
  31. #define REQ_FUNCTION_CLEAR_FEATURE 0x0004
  32. #define REQ_FUNCTION_GET_STATUS 0x0005
  33. // Functions below this line may not be implementable because the
  34. // stacks dont support them. Do we want to allow a special interface
  35. // to let these happen??
  36. #define REQ_FUNCTION_SET_ADDRESS 0x0006
  37. #define REQ_FUNCTION_GET_CONFIGURATION 0x0007
  38. #define REQ_FUNCTION_SET_CONFIGURATION 0x0008
  39. #define REQ_FUNCTION_GET_INTERFACE 0x0009
  40. #define REQ_FUNCTION_SET_INTERFACE 0x000A
  41. #define REQ_FUNCTION_GET_CHAP9VERSION 0x000B
  42. // raw packet can be used for sending a USB setup
  43. // packet down to the device from the app.
  44. #define REQ_FUNCTION_RAW_PACKET 0x00F0
  45. // Function codes to read and write from a device's endpoints
  46. #define REQ_FUNCTION_READ_FROM_PIPE 0x01F1
  47. #define REQ_FUNCTION_WRITE_TO_PIPE 0x01F2
  48. // Cancel transfers on a device
  49. // Only the REQ_HEADER is needed for this FUNCTION
  50. #define REQ_FUNCTION_CANCEL_TRANSFERS 0x01F3
  51. #define REQ_FUNCTION_CANCEL_WAIT_WAKE 0x01F4
  52. // power ioctl's
  53. #define REQ_FUNCTION_SET_DEVICE_POWER_STATE 0x02F0
  54. #define REQ_FUNCTION_GET_DEVICE_POWER_STATE 0x02F1
  55. #define REQ_FUNCTION_ISSUE_WAIT_WAKE 0x02F2
  56. #define REQ_FUNCTION_WAIT_FOR_WAKEUP 0x02F3
  57. // Chapter 11 IOCTL's
  58. #define REQ_FUNCTION_CHAP11_CREATE_USBD_DEVICE 0x000F
  59. #define REQ_FUNCTION_CHAP11_INIT_USBD_DEVICE 0x0010
  60. #define REQ_FUNCTION_CHAP11_DESTROY_USBD_DEVICE 0x0011
  61. #define REQ_FUNCTION_CHAP11_SEND_PACKET_DOWNSTREAM 0x0012
  62. #define REQ_FUNCTION_CHAP11_GET_DOWNSTREAM_DESCRIPTOR 0x0013
  63. #define REQ_FUNCTION_DISABLE_ENABLING_REMOTE_WAKEUP 0x0030
  64. #define REQ_FUNCTION_ENABLE_ENABLING_REMOTE_WAKEUP 0x0031
  65. #define REQ_FUNCTION_RESET_PARENT_PORT 0x001F
  66. #define REQ_FUNCTION_GET_DEVICE_STATE 0x0020
  67. //
  68. // Chap9drv status codes. Returned in status field of REQ_HEADER.
  69. // Also returned if a GetLastError() is done.
  70. //
  71. #define CH9_STATUS_SUCCESS 0x00000000
  72. #define CH9_STATUS_PENDING 0x00000001
  73. #define CH9_STATUS_NO_MEMORY 0x00000002
  74. #define CH9_STATUS_BAD_COMMAND 0x00000003
  75. #define CH9_STATUS_BUSY 0x00000004
  76. #define CH9_STATUS_INVALID_PARAMETER 0x00000005
  77. #define CH9_STATUS_ENDPOINT_STALLED 0x00000006
  78. #define CH9_STATUS_ABORTED 0x00000007
  79. #define CH9_STATUS_INVALID_DESCRIPTOR_INDEX 0x00000008
  80. #define CH9_STATUS_DEVICE_NOT_RESPONDING 0x00000009
  81. #define CH9_STATUS_DEVICE_ERROR 0x0000000A
  82. #define CH9_STATUS_CRC_ERROR 0x0000000B
  83. #define CH9_STATUS_BITSTUFF_ERROR 0x0000000C
  84. #define CH9_STATUS_DATA_TOGGLE_ERROR 0x0000000D
  85. #define CH9_STATUS_ERROR_VALUE 0x000000ff
  86. //########---------------------------------------
  87. // ---- Macro to get the "PDO" which is where the UsbdDeviceHandle used to
  88. // live in the structure below.
  89. //
  90. // Eventually change the app so that we can rename this element and
  91. // call it a PDO, which is what it really is.
  92. //
  93. #define GET_DEVICE_OBJECT_FROM_HANDLE(hU) (((PDEVICE_EXTENSION)(((PDEVICE_OBJECT)(hU))->DeviceExtension))->PhysicalDeviceObject)
  94. struct _REQ_HEADER {
  95. //
  96. // Fields filled in by client driver
  97. //
  98. USHORT Length; // Total length of structure
  99. USHORT Function; // Determines function to perform and
  100. // structure type in union
  101. ULONG Status; // Return codes defined above
  102. PVOID UsbdDeviceHandle; // device handle for device of interest
  103. };
  104. struct _REQ_GETCHAP9_VERSION {
  105. struct _REQ_HEADER Hdr;
  106. USHORT Version; // version includes major version in HIBYTE and minir version# in LOBYTE
  107. };
  108. struct _REQ_GETSET_DESCRIPTOR {
  109. struct _REQ_HEADER Hdr; // function code indicates get or set.
  110. ULONG TransferBufferLength;
  111. PVOID TransferBuffer; // This contains the descriptor data
  112. USHORT Index; // Zero-based index
  113. USHORT DescriptorType; // Ch 9-defined constants (Tbl 9-4)
  114. USHORT LanguageId; // String descriptors only
  115. };
  116. struct _REQ_GET_STATUS {
  117. struct _REQ_HEADER Hdr;
  118. IN USHORT Recipient; //Recipient of status request
  119. //Use constants defined above.
  120. //DEVICE_STATUS
  121. //INTERFACE_STATUS
  122. //ENDPOINT_STATUS
  123. IN USHORT Index;
  124. // zero for device
  125. // else specifies interface/endpoint number
  126. USHORT Status;
  127. };
  128. struct _REQ_FEATURE {
  129. struct _REQ_HEADER Hdr;
  130. USHORT FeatureSelector;
  131. USHORT Recipient; // zero, interface or endpoint
  132. USHORT Index;
  133. };
  134. struct _REQ_SET_ADDRESS {
  135. struct _REQ_HEADER Hdr;
  136. USHORT DevAddr;
  137. };
  138. struct _REQ_GETSET_CONFIGURATION {
  139. struct _REQ_HEADER Hdr;
  140. USHORT ConfigValue;
  141. };
  142. struct _REQ_GETSET_INTERFACE {
  143. struct _REQ_HEADER Hdr;
  144. USHORT Index;
  145. USHORT AltSetting;
  146. };
  147. struct _REQ_GET_SET_DEVICE_POWER_STATE {
  148. struct _REQ_HEADER Hdr;
  149. ULONG DevicePowerState;
  150. };
  151. // The following structure is a later addition to allow an
  152. // application to send a USB raw packet directly down to
  153. // the stack.
  154. //
  155. //BUGBUG make these fields all ULONGs since some (like wLength) are
  156. // overloaded and used for other reasons in the driver.
  157. //
  158. struct _REQ_SEND_RAWPACKET {
  159. struct _REQ_HEADER Hdr;
  160. USHORT bmRequestType;
  161. USHORT bRequest;
  162. USHORT wValue;
  163. USHORT wIndex;
  164. PVOID pvBuffer;
  165. USHORT wLength;
  166. };
  167. //Follwing are lifted from usbdi.h just for consistency
  168. #define USB_ENDPOINT_TYPE_CONTROL 0x00
  169. #define USB_ENDPOINT_TYPE_ISOCHRONOUS 0x01
  170. #define USB_ENDPOINT_TYPE_BULK 0x02
  171. #define USB_ENDPOINT_TYPE_INTERRUPT 0x03
  172. struct _PIPE_CONTXT {
  173. ULONG PipeNum;
  174. ULONG PipeType; //use #defines above (note they are the same as USBDI.H)
  175. };
  176. /*
  177. // This IOCTL REQ block is sent by the app to configure the device in
  178. // a given configuration. The app should determine the configuration
  179. // value by reading the configuration descriptor using the appropriate
  180. // REQ block for that above.
  181. //
  182. // This REQ block is sent with the IOCTL code IOCTL_USBDIAG_CONFIGURE_DEVICE.
  183. */
  184. struct _REQ_SET_DEVICE_CONFIG {
  185. struct _REQ_HEADER Hdr;
  186. ULONG iConfigurationDescIndex;//It's the DESCRIPTOR Index, not the bConfigurationValue!
  187. //and don't get cute and send me the Descriptor Type in here; Make that a ZERO!
  188. //So, for the first config descriptor, send a ZERO here. For the second
  189. //config descriptor, send a ONE here, etc.
  190. ULONG nNumContexts; //Number of __elements__ in the Contxt array below
  191. struct _PIPE_CONTXT Contxt[0];//First pipe context in array which will be filled in
  192. //by the driver upon successful return
  193. };
  194. /*
  195. // This IOCTL REQ block is sent by the app to read or write from the device in
  196. // a given configuration. This REQ block corresponds to the READ/WRITE Function
  197. // that an app would send down to the USBDIAG driver (using IOCTL_USBDIAG_CHAP9_CONTROL).
  198. // The app must have set device config using IOCTL_USBDIAG_CONFIGURE_DEVICE.
  199. */
  200. struct _REQ_READ_WRITE_PIPE {
  201. IN struct _REQ_HEADER Hdr; //Set according to whether it's a read or write
  202. //(see the #define-s above to use constants here)
  203. IN struct _PIPE_CONTXT Contxt; //Read or Write from one pipe at a time
  204. IN PVOID pvBuffer; //Buffer to take data from or read data into
  205. IN OUT ULONG ulLength; //Length of pvBuffer (IN: bytes provided)
  206. // (OUT: actual bytes txferred)
  207. };
  208. typedef struct _REQ {
  209. union {
  210. struct _REQ_HEADER REQHeader;
  211. struct _REQ_GETSET_DESCRIPTOR REQGetSetDescriptor;
  212. struct _REQ_GET_STATUS REQGetStatus;
  213. struct _REQ_FEATURE REQFeature;
  214. struct _REQ_SET_ADDRESS REQSetAddress;
  215. struct _REQ_GETSET_CONFIGURATION REQGetSetConfiguration;
  216. struct _REQ_GETSET_INTERFACE REQGetSetInterface;
  217. struct _REQ_SEND_RAWPACKET REQRawPacket;
  218. struct _REQ_SET_DEVICE_CONFIG REQSetDeviceConfig;
  219. struct _REQ_READ_WRITE_PIPE REQReadWritePipe;
  220. struct _REQ_DEVICE_HANDLES REQhDev;
  221. struct _REQ_GETCHAP9_VERSION REQGetCh9;
  222. struct _REQ_GET_SET_DEVICE_POWER_STATE REQGetSetDevicePowerState;
  223. };
  224. } REQ, *PREQ;
  225. #define RECIPIENT_DEVICE ((UCHAR)0x00)
  226. #define RECIPIENT_INTERFACE ((UCHAR)0x01)
  227. #define RECIPIENT_ENDPOINT ((UCHAR)0x02)
  228. #define bmReqH2D ((UCHAR)0x00)
  229. #define bmReqD2H ((UCHAR)0x80)
  230. #define bmReqSTANDARD ((UCHAR)0x00)
  231. #define bmReqCLASS ((UCHAR)0x20)
  232. #define bmReqVENDOR ((UCHAR)0x40)
  233. #define bmReqRESERVED ((UCHAR)0x60)
  234. #define bmReqDEVICE ((UCHAR)0x00)
  235. #define bmReqINTERFACE ((UCHAR)0x01)
  236. #define bmReqENDPOINT ((UCHAR)0x02)
  237. #define GET_STATUS_DATA_LEN 2
  238. #define SETUP_PACKET_LEN 8
  239. typedef struct _REQ_ENUMERATE_DOWNSTREAM_DEVICE {
  240. struct _REQ_HEADER Hdr;
  241. BOOLEAN bLowSpeed;
  242. UCHAR ucPortNumber;
  243. } REQ_ENUMERATE_DOWNSTREAM_DEVICE, * PREQ_ENUMERATE_DOWNSTREAM_DEVICE;
  244. typedef struct _CHAP11_SETUP_PACKET {
  245. USHORT wRequest;
  246. USHORT wValue;
  247. USHORT wIndex;
  248. USHORT wLength;
  249. } CHAP11_SETUP_PACKET, * PCHAP11_SETUP_PACKET;
  250. typedef struct _REQ_SEND_PACKET_DOWNSTREAM {
  251. struct _REQ_HEADER Hdr;
  252. USHORT bLowSpeed;
  253. USHORT usPortNumber;
  254. struct _CHAP11_SETUP_PACKET SetupPacket;
  255. PUCHAR pucBuffer;
  256. ULONG ulUrbStatus;
  257. ULONG dwBytes;
  258. } REQ_SEND_PACKET_DOWNSTREAM, * PREQ_SEND_PACKET_DOWNSTREAM;
  259. typedef struct _REQ_GET_DOWNSTREAM_DESCRIPTOR {
  260. struct _REQ_HEADER Hdr;
  261. USHORT usPortNumber;
  262. USHORT Index; // Zero-based index
  263. USHORT DescriptorType; // Ch 9-defined constants (Tbl 9-4)
  264. USHORT LanguageId; // String descriptors only
  265. PVOID TransferBuffer; // This contains the descriptor data
  266. ULONG TransferBufferLength;
  267. } REQ_GET_DOWNSTREAM_DESCRIPTOR, * PREQ_GET_DOWNSTREAM_DESCRIPTOR;
  268. #endif /* __UCHAP9_H__ */