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.

646 lines
16 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. USBUSER.H
  5. Abstract:
  6. This file contains USER Mode IOCTLS supported by
  7. the USB PORT or (HC - Host Controller) driver.
  8. Environment:
  9. user mode
  10. Revision History:
  11. --*/
  12. #ifndef __USBUSER_H__
  13. #define __USBUSER_H__
  14. #include "usbiodef.h"
  15. #include <PSHPACK1.H>
  16. #define USBUSER_VERSION 0x00000004
  17. #define IOCTL_USB_USER_REQUEST USB_CTL(HCD_USER_REQUEST)
  18. /*
  19. The following were used by test applications and are no
  20. longer supported (they have been replaced with USBUSER Opcodes):
  21. #define IOCTL_USB_HCD_GET_STATS_1 USB_CTL(HCD_GET_STATS_1)
  22. #define IOCTL_USB_HCD_GET_STATS_2 USB_CTL(HCD_GET_STATS_2)
  23. #define IOCTL_USB_HCD_DISABLE_PORT USB_CTL(HCD_DISABLE_PORT)
  24. #define IOCTL_USB_HCD_ENABLE_PORT USB_CTL(HCD_ENABLE_PORT)
  25. */
  26. /*
  27. The following are used by the 'USBDIAG' driver
  28. */
  29. #ifndef IOCTL_USB_DIAGNOSTIC_MODE_ON
  30. #define IOCTL_USB_DIAGNOSTIC_MODE_ON USB_CTL(HCD_DIAGNOSTIC_MODE_ON)
  31. #endif
  32. #ifndef IOCTL_USB_DIAGNOSTIC_MODE_OFF
  33. #define IOCTL_USB_DIAGNOSTIC_MODE_OFF USB_CTL(HCD_DIAGNOSTIC_MODE_OFF)
  34. #endif
  35. #ifndef IOCTL_USB_GET_ROOT_HUB_NAME
  36. #define IOCTL_USB_GET_ROOT_HUB_NAME USB_CTL(HCD_GET_ROOT_HUB_NAME)
  37. #endif
  38. #ifndef IOCTL_GET_HCD_DRIVERKEY_NAME
  39. #define IOCTL_GET_HCD_DRIVERKEY_NAME USB_CTL(HCD_GET_DRIVERKEY_NAME)
  40. #endif
  41. /*
  42. define error codes
  43. */
  44. typedef enum _USB_USER_ERROR_CODE {
  45. UsbUserSuccess = 0,
  46. UsbUserNotSupported,
  47. UsbUserInvalidRequestCode,
  48. UsbUserFeatureDisabled,
  49. UsbUserInvalidHeaderParameter,
  50. UsbUserInvalidParameter,
  51. UsbUserMiniportError,
  52. UsbUserBufferTooSmall,
  53. UsbUserErrorNotMapped,
  54. UsbUserDeviceNotStarted,
  55. UsbUserNoDeviceConnected
  56. } USB_USER_ERROR_CODE;
  57. /*
  58. define USB USER request Codes
  59. */
  60. /*
  61. The following APIS are enabled always
  62. */
  63. #define USBUSER_GET_CONTROLLER_INFO_0 0x00000001
  64. #define USBUSER_GET_CONTROLLER_DRIVER_KEY 0x00000002
  65. #define USBUSER_PASS_THRU 0x00000003
  66. #define USBUSER_GET_POWER_STATE_MAP 0x00000004
  67. #define USBUSER_GET_BANDWIDTH_INFORMATION 0x00000005
  68. #define USBUSER_GET_BUS_STATISTICS_0 0x00000006
  69. #define USBUSER_GET_ROOTHUB_SYMBOLIC_NAME 0x00000007
  70. #define USBUSER_GET_USB_DRIVER_VERSION 0x00000008
  71. #define USBUSER_GET_USB2_HW_VERSION 0x00000009
  72. /*
  73. The following APIs are only enabled when the
  74. devlopr key is set in the registry.
  75. */
  76. #define USBUSER_OP_SEND_ONE_PACKET 0x10000001
  77. /*
  78. The following APIs are only enabled when the
  79. root hub is disabled.
  80. */
  81. #define USBUSER_OP_RAW_RESET_PORT 0x20000001
  82. #define USBUSER_OP_OPEN_RAW_DEVICE 0x20000002
  83. #define USBUSER_OP_CLOSE_RAW_DEVICE 0x20000003
  84. #define USBUSER_OP_SEND_RAW_COMMAND 0x20000004
  85. #define USBUSER_SET_ROOTPORT_FEATURE 0x20000005
  86. #define USBUSER_CLEAR_ROOTPORT_FEATURE 0x20000006
  87. #define USBUSER_GET_ROOTPORT_STATUS 0x20000007
  88. #define USBUSER_INVALID_REQUEST 0xFFFFFFF0
  89. #define USBUSER_OP_MASK_DEVONLY_API 0x10000000
  90. #define USBUSER_OP_MASK_HCTEST_API 0x20000000
  91. /*
  92. Common Header used by all USBUSER APIS
  93. */
  94. typedef struct _USBUSER_REQUEST_HEADER {
  95. /*
  96. API Requested
  97. */
  98. ULONG UsbUserRequest;
  99. /*
  100. status code returned by port driver
  101. */
  102. USB_USER_ERROR_CODE UsbUserStatusCode;
  103. /*
  104. size of client input/output buffer
  105. we always use the same buffer for input
  106. and output
  107. */
  108. ULONG RequestBufferLength;
  109. /*
  110. size of buffer required to get all of the data
  111. */
  112. ULONG ActualBufferLength;
  113. } USBUSER_REQUEST_HEADER, *PUSBUSER_REQUEST_HEADER;
  114. /*****************************************************
  115. API - Send a single usb packet on the bus
  116. USBUSER_OP_SEND_ONE_PACKET
  117. This API is used to implement the 'single step'
  118. USB transaction development tool.
  119. *******************************************************/
  120. /*
  121. transaction speed
  122. */
  123. #define USB_PACKETFLAG_LOW_SPEED 0x00000001
  124. #define USB_PACKETFLAG_FULL_SPEED 0x00000002
  125. #define USB_PACKETFLAG_HIGH_SPEED 0x00000004
  126. /*
  127. transaction type async(bulk, control, interrupt) or iso
  128. */
  129. #define USB_PACKETFLAG_ASYNC_IN 0x00000008
  130. #define USB_PACKETFLAG_ASYNC_OUT 0x00000010
  131. #define USB_PACKETFLAG_ISO_IN 0x00000020
  132. #define USB_PACKETFLAG_ISO_OUT 0x00000040
  133. #define USB_PACKETFLAG_SETUP 0x00000080
  134. /*
  135. transaction data toggle
  136. */
  137. #define USB_PACKETFLAG_TOGGLE0 0x00000100
  138. #define USB_PACKETFLAG_TOGGLE1 0x00000200
  139. typedef struct _PACKET_PARAMETERS {
  140. UCHAR DeviceAddress;
  141. UCHAR EndpointAddress;
  142. USHORT MaximumPacketSize;
  143. /* timeout in ms, zero means default */
  144. /* default timeout is 10 ms */
  145. ULONG Timeout;
  146. ULONG Flags;
  147. ULONG DataLength;
  148. /* for 2.0 hubs */
  149. USHORT HubDeviceAddress;
  150. USHORT PortTTNumber;
  151. UCHAR ErrorCount;
  152. UCHAR Pad[3];
  153. USBD_STATUS UsbdStatusCode;
  154. UCHAR Data[4];
  155. } PACKET_PARAMETERS, *PPACKET_PARAMETERS;
  156. typedef struct _USBUSER_SEND_ONE_PACKET {
  157. USBUSER_REQUEST_HEADER Header;
  158. PACKET_PARAMETERS PacketParameters;
  159. } USBUSER_SEND_ONE_PACKET, *PUSBUSER_SEND_ONE_PACKET;
  160. /*****************************************************
  161. API - Test Reset Root Port
  162. USBUSER_OP_RAW_RESET_PORT
  163. ******************************************************/
  164. typedef struct _RAW_RESET_PORT_PARAMETERS {
  165. USHORT PortNumber;
  166. USHORT PortStatus;
  167. } RAW_RESET_PORT_PARAMETERS, *PRAW_RESET_PORT_PARAMETERS;
  168. typedef struct _USBUSER_RAW_RESET_ROOT_PORT {
  169. USBUSER_REQUEST_HEADER Header;
  170. RAW_RESET_PORT_PARAMETERS Parameters;
  171. } USBUSER_RAW_RESET_ROOT_PORT, *PUSBUSER_RAW_RESET_ROOT_PORT;
  172. /*****************************************************
  173. API - Test Set/Clear Root Port Feature
  174. USBUSER_SET_ROOTPORT_FEATURE
  175. USBUSER_CLEAR_ROOTPORT_FEATURE
  176. ******************************************************/
  177. typedef struct _RAW_ROOTPORT_FEATURE {
  178. USHORT PortNumber;
  179. USHORT PortFeature;
  180. USHORT PortStatus;
  181. } RAW_ROOTPORT_FEATURE, *PRAW_ROOTPORT_FEATURE;
  182. typedef struct _USBUSER_ROOTPORT_FEATURE_REQUEST {
  183. USBUSER_REQUEST_HEADER Header;
  184. RAW_ROOTPORT_FEATURE Parameters;
  185. } USBUSER_ROOTPORT_FEATURE_REQUEST, *PUSBUSER_ROOTPORT_FEATURE_REQUEST;
  186. /*****************************************************
  187. API - Get RootPort Status
  188. USBUSER_GET_ROOTPORT_STATUS
  189. ******************************************************/
  190. typedef struct _RAW_ROOTPORT_PARAMETERS {
  191. USHORT PortNumber;
  192. USHORT PortStatus;
  193. } RAW_ROOTPORT_PARAMETERS, *PRAW_ROOTPORT_PARAMETERS;
  194. typedef struct _USBUSER_ROOTPORT_PARAMETERS {
  195. USBUSER_REQUEST_HEADER Header;
  196. RAW_ROOTPORT_PARAMETERS Parameters;
  197. } USBUSER_ROOTPORT_PARAMETERS, *PUSBUSER_ROOTPORT_PARAMETERS;
  198. /****************************************************
  199. API - Get Controller Information
  200. Return some information about the controller
  201. USBUSER_GET_CONTROLLER_INFO_0
  202. ****************************************************/
  203. /* these flags indicate features of the HC */
  204. #define USB_HC_FEATURE_FLAG_PORT_POWER_SWITCHING 0x00000001
  205. #define USB_HC_FEATURE_FLAG_SEL_SUSPEND 0x00000002
  206. #define USB_HC_FEATURE_LEGACY_BIOS 0x00000004
  207. typedef struct _USB_CONTROLLER_INFO_0 {
  208. ULONG PciVendorId;
  209. ULONG PciDeviceId;
  210. ULONG PciRevision;
  211. ULONG NumberOfRootPorts;
  212. USB_CONTROLLER_FLAVOR ControllerFlavor;
  213. ULONG HcFeatureFlags;
  214. } USB_CONTROLLER_INFO_0 , *PUSB_CONTROLLER_INFO_0;
  215. typedef struct _USBUSER_CONTROLLER_INFO_0 {
  216. USBUSER_REQUEST_HEADER Header;
  217. USB_CONTROLLER_INFO_0 Info0;
  218. } USBUSER_CONTROLLER_INFO_0, *PUSBUSER_CONTROLLER_INFO_0;
  219. /****************************************************
  220. API - Get Controller Driver Key
  221. Returns the driver key in the registry associated
  222. with this controller.
  223. The key is returned NULL terminated, KeyLength
  224. is the length of the key in bytes including the
  225. UNICODE_NULL
  226. USBUSER_GET_CONTROLLER_DRIVER_KEY
  227. API - Get Root Hub Name
  228. The following structure is used to return unicode
  229. names from the port driver
  230. ****************************************************/
  231. typedef struct _USB_UNICODE_NAME {
  232. ULONG Length;
  233. WCHAR String[1];
  234. } USB_UNICODE_NAME, *PUSB_UNICODE_NAME;
  235. typedef struct _USBUSER_CONTROLLER_UNICODE_NAME {
  236. USBUSER_REQUEST_HEADER Header;
  237. USB_UNICODE_NAME UnicodeName;
  238. } USBUSER_CONTROLLER_UNICODE_NAME, *PUSBUSER_CONTROLLER_UNICODE_NAME;
  239. /****************************************************
  240. API - PassThru
  241. allows for vendor specific APIs to be passed to
  242. Host Controller Miniport Driver
  243. The vendors must pass a guid that is recognized
  244. by the miniport , this enures that the parameters
  245. are not miss-interpreted
  246. USBUSER_PASS_THRU
  247. ****************************************************/
  248. typedef struct _USB_PASS_THRU_PARAMETERS {
  249. GUID FunctionGUID;
  250. ULONG ParameterLength;
  251. UCHAR Parameters[4];
  252. } USB_PASS_THRU_PARAMETERS, *PUSB_PASS_THRU_PARAMETERS;
  253. typedef struct _USBUSER_PASS_THRU_REQUEST {
  254. USBUSER_REQUEST_HEADER Header;
  255. USB_PASS_THRU_PARAMETERS PassThru;
  256. } USBUSER_PASS_THRU_REQUEST, *PUSBUSER_PASS_THRU_REQUEST;
  257. /****************************************************
  258. API - GetPowerStateMap
  259. Returns specific information about a controller
  260. and root hubs power state given a specific
  261. system state.
  262. USBUSER_GET_POWER_STATE_MAP
  263. ****************************************************/
  264. typedef enum _WDMUSB_POWER_STATE {
  265. WdmUsbPowerNotMapped = 0,
  266. WdmUsbPowerSystemUnspecified = 100,
  267. WdmUsbPowerSystemWorking,
  268. WdmUsbPowerSystemSleeping1,
  269. WdmUsbPowerSystemSleeping2,
  270. WdmUsbPowerSystemSleeping3,
  271. WdmUsbPowerSystemHibernate,
  272. WdmUsbPowerSystemShutdown,
  273. WdmUsbPowerDeviceUnspecified = 200,
  274. WdmUsbPowerDeviceD0,
  275. WdmUsbPowerDeviceD1,
  276. WdmUsbPowerDeviceD2,
  277. WdmUsbPowerDeviceD3
  278. } WDMUSB_POWER_STATE;
  279. typedef struct _USB_POWER_INFO {
  280. /* input */
  281. WDMUSB_POWER_STATE SystemState;
  282. /* output */
  283. WDMUSB_POWER_STATE HcDevicePowerState;
  284. WDMUSB_POWER_STATE HcDeviceWake;
  285. WDMUSB_POWER_STATE HcSystemWake;
  286. WDMUSB_POWER_STATE RhDevicePowerState;
  287. WDMUSB_POWER_STATE RhDeviceWake;
  288. WDMUSB_POWER_STATE RhSystemWake;
  289. WDMUSB_POWER_STATE LastSystemSleepState;
  290. BOOLEAN CanWakeup;
  291. BOOLEAN IsPowered;
  292. } USB_POWER_INFO, *PUSB_POWER_INFO;
  293. typedef struct _USBUSER_POWER_INFO_REQUEST {
  294. USBUSER_REQUEST_HEADER Header;
  295. USB_POWER_INFO PowerInformation;
  296. } USBUSER_POWER_INFO_REQUEST, *PUSBUSER_POWER_INFO_REQUEST;
  297. /****************************************************
  298. API - Open Raw Device access on the bus
  299. USBUSER_OP_OPEN_RAW_DEVICE
  300. ****************************************************/
  301. typedef struct _USB_OPEN_RAW_DEVICE_PARAMETERS {
  302. USHORT PortStatus;
  303. USHORT MaxPacketEp0;
  304. } USB_OPEN_RAW_DEVICE_PARAMETERS , *PUSB_OPEN_RAW_DEVICE_PARAMETERS;
  305. typedef struct _USBUSER_OPEN_RAW_DEVICE {
  306. USBUSER_REQUEST_HEADER Header;
  307. USB_OPEN_RAW_DEVICE_PARAMETERS Parameters;
  308. } USBUSER_OPEN_RAW_DEVICE, *PUSBUSER_OPEN_RAW_DEVICE;
  309. /****************************************************
  310. API - Close Raw Device access on the bus
  311. USBUSER_OP_CLOSE_RAW_DEVICE
  312. ****************************************************/
  313. typedef struct _USB_CLOSE_RAW_DEVICE_PARAMETERS {
  314. ULONG xxx;
  315. } USB_CLOSE_RAW_DEVICE_PARAMETERS , *PUSB_CLOSE_RAW_DEVICE_PARAMETERS;
  316. typedef struct _USBUSER_CLOSE_RAW_DEVICE {
  317. USBUSER_REQUEST_HEADER Header;
  318. USB_CLOSE_RAW_DEVICE_PARAMETERS Parameters;
  319. } USBUSER_CLOSE_RAW_DEVICE, *PUSBUSER_CLOSE_RAW_DEVICE;
  320. /****************************************************
  321. API - Send control command via raw device handle
  322. USBUSER_OP_SEND_RAW_COMMAND
  323. ****************************************************/
  324. typedef struct _USB_SEND_RAW_COMMAND_PARAMETERS {
  325. /* setup packet */
  326. UCHAR Usb_bmRequest;
  327. UCHAR Usb_bRequest;
  328. USHORT Usb_wVlaue;
  329. USHORT Usb_wIndex;
  330. USHORT Usb_wLength;
  331. /* other parameters */
  332. USHORT DeviceAddress;
  333. USHORT MaximumPacketSize;
  334. ULONG Timeout;
  335. ULONG DataLength;
  336. USBD_STATUS UsbdStatusCode;
  337. UCHAR Data[4];
  338. } USB_SEND_RAW_COMMAND_PARAMETERS, *PUSB_SEND_RAW_COMMAND_PARAMETERS;
  339. typedef struct _USBUSER_SEND_RAW_COMMAND {
  340. USBUSER_REQUEST_HEADER Header;
  341. USB_SEND_RAW_COMMAND_PARAMETERS Parameters;
  342. } USBUSER_SEND_RAW_COMMAND, *PUSBUSER_SEND_RAW_COMMAND;
  343. /****************************************************
  344. API - return information about allocated
  345. bandwidth
  346. USBUSER_GET_BANDWIDTH_INFORMATION
  347. ****************************************************/
  348. typedef struct _USB_BANDWIDTH_INFO {
  349. ULONG DeviceCount;
  350. // total bandith in bits/sec
  351. ULONG TotalBusBandwidth;
  352. // allocated bandwidth based on a 32 sec
  353. // slice of bus time ie bits/32 sec
  354. ULONG Total32secBandwidth;
  355. ULONG AllocedBulkAndControl;
  356. ULONG AllocedIso;
  357. ULONG AllocedInterrupt_1ms;
  358. ULONG AllocedInterrupt_2ms;
  359. ULONG AllocedInterrupt_4ms;
  360. ULONG AllocedInterrupt_8ms;
  361. ULONG AllocedInterrupt_16ms;
  362. ULONG AllocedInterrupt_32ms;
  363. } USB_BANDWIDTH_INFO, *PUSB_BANDWIDTH_INFO;
  364. typedef struct _USBUSER_BANDWIDTH_INFO_REQUEST {
  365. USBUSER_REQUEST_HEADER Header;
  366. USB_BANDWIDTH_INFO BandwidthInformation;
  367. } USBUSER_BANDWIDTH_INFO_REQUEST, *PUSBUSER_BANDWIDTH_INFO_REQUEST;
  368. /****************************************************
  369. API - return information data transferred on the
  370. bus
  371. USBUSER_BUS_STATISTICS_0
  372. ****************************************************/
  373. typedef struct _USB_BUS_STATISTICS_0 {
  374. ULONG DeviceCount;
  375. LARGE_INTEGER CurrentSystemTime;
  376. ULONG CurrentUsbFrame;
  377. ULONG BulkBytes;
  378. ULONG IsoBytes;
  379. ULONG InterruptBytes;
  380. ULONG ControlDataBytes;
  381. ULONG PciInterruptCount;
  382. ULONG HardResetCount;
  383. ULONG WorkerSignalCount;
  384. ULONG CommonBufferBytes;
  385. ULONG WorkerIdleTimeMs;
  386. BOOLEAN RootHubEnabled;
  387. // 0=D0, 1=D1, 2=D2, 3=D3
  388. UCHAR RootHubDevicePowerState;
  389. // 1 = active 0 = idle
  390. UCHAR Unused;
  391. // used to generate legacy name HCDn
  392. UCHAR NameIndex;
  393. } USB_BUS_STATISTICS_0, *PUSB_BUS_STATISTICS_0;
  394. typedef struct _USBUSER_BUS_STATISTICS_0_REQUEST {
  395. USBUSER_REQUEST_HEADER Header;
  396. USB_BUS_STATISTICS_0 BusStatistics0;
  397. } USBUSER_BUS_STATISTICS_0_REQUEST, *PUSBUSER_BUS_STATISTICS_0_REQUEST;
  398. /****************************************************
  399. API - Get USB DRIVER Version
  400. USBUSER_GET_USB_DRIVER_VERSION
  401. ****************************************************/
  402. typedef struct _USB_DRIVER_VERSION_PARAMETERS {
  403. /* goat code for this rev of the stack */
  404. ULONG DriverTrackingCode;
  405. /* USBDI Api set supported */
  406. ULONG USBDI_Version;
  407. /* USB USER Api Set supported */
  408. ULONG USBUSER_Version;
  409. /* set to true if checked vesrion(s) on
  410. the stack are loaded
  411. */
  412. BOOLEAN CheckedPortDriver;
  413. BOOLEAN CheckedMiniportDriver;
  414. /* BCD usb version 0x0110 (1.1) 0x0200 (2.0) */
  415. USHORT USB_Version;
  416. } USB_DRIVER_VERSION_PARAMETERS , *PUSB_DRIVER_VERSION_PARAMETERS;
  417. typedef struct _USBUSER_GET_DRIVER_VERSION {
  418. USBUSER_REQUEST_HEADER Header;
  419. USB_DRIVER_VERSION_PARAMETERS Parameters;
  420. } USBUSER_GET_DRIVER_VERSION, *PUSBUSER_GET_DRIVER_VERSION;
  421. /****************************************************
  422. API - Get USB 2 Hardware Revision
  423. USBUSER_GET_USB2HW_VERSION
  424. *****************************************************/
  425. //#define USB2HW_UNKNOWN 0x00
  426. //#define USB2HW_A0 0xA0
  427. //#define USB2HW_A1 0xA1
  428. //#define USB2HW_B0 0xB0
  429. typedef struct _USB_USB2HW_VERSION_PARAMETERS {
  430. UCHAR Usb2HwRevision;
  431. } USB_USB2HW_VERSION_PARAMETERS, *PUSB_USB2HW_VERSION_PARAMETERS;
  432. typedef struct _USBUSER_GET_USB2HW_VERSION {
  433. USBUSER_REQUEST_HEADER Header;
  434. USB_USB2HW_VERSION_PARAMETERS Parameters;
  435. } USBUSER_GET_USB2HW_VERSION, *PUSBUSER_GET_USB2HW_VERSION;
  436. #include <POPPACK.H>
  437. #endif //__USBUSER_H__