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.

2484 lines
59 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. usbhub.h
  5. Abstract:
  6. This header define structures and macros for USB Hub driver.
  7. Author:
  8. JohnLee
  9. Environment:
  10. Kernel mode
  11. Revision History:
  12. 2-2-96 : created
  13. 11-18-96 : jdunn -- added composite device support
  14. --*/
  15. #include <wdmwarn4.h>
  16. #include <usb.h> // usbdi.h has been replaced by usb.h
  17. #include <usbdlib.h>
  18. #include <msosdesc.h> // contains internal definitions for MS OS Desc.
  19. #ifdef USB2
  20. #include "hubbusif.h" // hub service bus interface
  21. #include "usbbusif.h" // usb client service bus interface
  22. #else
  23. #include <hcdi.h>
  24. #include <usbdlibi.h>
  25. #endif
  26. #include <usbioctl.h>
  27. #include <wmidata.h>
  28. #include <enumlog.h>
  29. //enable pageable code
  30. #ifndef PAGE_CODE
  31. #define PAGE_CODE
  32. #endif
  33. #define MULTI_FUNCTION_SUPPORT
  34. #define EARLY_RESOURCE_RELEASE
  35. #define RESUME_PERF
  36. #define USBH_MAX_FUNCTION_INTERFACES 4
  37. #define BcdNibbleToAscii( byte ) (byte)+ '0'
  38. //
  39. // fail reason codes
  40. //
  41. // "Device Failed Enumeration"
  42. // indicates the device failed some part of the enumeration process
  43. // when this happens we cannot tell enough about the device to load
  44. // the appropriate driver.
  45. #define USBH_FAILREASON_ENUM_FAILED 1
  46. // "Device General Failure"
  47. // this is our 'if it does not fit any other catagory' error
  48. #define USBH_FAILREASON_GEN_DEVICE_FAILURE 2
  49. // "Device Caused Overcurrent"
  50. // if a hub supports per port power switching and the device
  51. // causes an overcurrent condition (over-current is like blowing
  52. // a fuse) the we report this error.
  53. #define USBH_FAILREASON_PORT_OVERCURRENT 3
  54. // "Not Enough Power"
  55. // indicates that the device requested a configuration that requires
  56. // more power than the hub can provide.
  57. #define USBH_FAILREASON_NOT_ENOUGH_POWER 4
  58. // "Hub General failure"
  59. // if the hub starts failing transfer requests the driver will
  60. // disable it and report this error.
  61. #define USBH_FAILREASON_HUB_GENERAL_FAILURE 5
  62. // "Cannot connect more than five hubs"
  63. #define USBH_FAILREASON_MAXHUBS_CONNECTED 6
  64. // "An overcurrent condition has disabled the hub"
  65. // if a device generates overcurrent and the hub implements
  66. // gang power switching the entire hub will be disabled and
  67. // this error reported.
  68. #define USBH_FAILREASON_HUB_OVERCURRENT 7
  69. //
  70. // Struc definitions
  71. //
  72. //
  73. // Work item
  74. //
  75. #define USBH_WKFLAG_REQUEST_RESET 0x00000001
  76. typedef struct _USBH_WORK_ITEM {
  77. WORK_QUEUE_ITEM WorkQueueItem;
  78. ULONG Flags;
  79. PVOID Context;
  80. struct _DEVICE_EXTENSION_HUB *DeviceExtensionHub;
  81. KDPC Dpc;
  82. KTIMER Timer;
  83. UCHAR Data[0];
  84. } USBH_WORK_ITEM, *PUSBH_WORK_ITEM;
  85. typedef struct _USBH_RESET_WORK_ITEM {
  86. WORK_QUEUE_ITEM WorkQueueItem;
  87. struct _DEVICE_EXTENSION_PORT *DeviceExtensionPort;
  88. PIRP Irp;
  89. } USBH_RESET_WORK_ITEM, *PUSBH_RESET_WORK_ITEM;
  90. typedef struct _USBH_COMP_RESET_WORK_ITEM {
  91. WORK_QUEUE_ITEM WorkQueueItem;
  92. struct _DEVICE_EXTENSION_PARENT *DeviceExtensionParent;
  93. } USBH_COMP_RESET_WORK_ITEM, *PUSBH_COMP_RESET_WORK_ITEM;
  94. typedef struct _USBH_BANDWIDTH_TIMEOUT_WORK_ITEM {
  95. WORK_QUEUE_ITEM WorkQueueItem;
  96. struct _DEVICE_EXTENSION_PORT *DeviceExtensionPort;
  97. } USBH_BANDWIDTH_TIMEOUT_WORK_ITEM, *PUSBH_BANDWIDTH_TIMEOUT_WORK_ITEM;
  98. typedef struct _USBH_COMP_RESET_TIMEOUT_WORK_ITEM {
  99. WORK_QUEUE_ITEM WorkQueueItem;
  100. struct _DEVICE_EXTENSION_PARENT *DeviceExtensionParent;
  101. } USBH_COMP_RESET_TIMEOUT_WORK_ITEM, *PUSBH_COMP_RESET_TIMEOUT_WORK_ITEM;
  102. typedef struct _USBH_SET_POWER_D0_WORK_ITEM {
  103. WORK_QUEUE_ITEM WorkQueueItem;
  104. struct _DEVICE_EXTENSION_HUB *DeviceExtensionHub;
  105. PIRP Irp;
  106. } USBH_SET_POWER_D0_WORK_ITEM, *PUSBH_SET_POWER_D0_WORK_ITEM;
  107. typedef struct _USBH_HUB_ESD_RECOVERY_WORK_ITEM {
  108. WORK_QUEUE_ITEM WorkQueueItem;
  109. struct _DEVICE_EXTENSION_HUB *DeviceExtensionHub;
  110. } USBH_HUB_ESD_RECOVERY_WORK_ITEM, *PUSBH_HUB_ESD_RECOVERY_WORK_ITEM;
  111. typedef struct _USBH_HUB_IDLE_POWER_WORK_ITEM {
  112. WORK_QUEUE_ITEM WorkQueueItem;
  113. struct _DEVICE_EXTENSION_HUB *DeviceExtensionHub;
  114. NTSTATUS ntStatus;
  115. } USBH_HUB_IDLE_POWER_WORK_ITEM, *PUSBH_HUB_IDLE_POWER_WORK_ITEM;
  116. typedef struct _USBH_PORT_IDLE_POWER_WORK_ITEM {
  117. WORK_QUEUE_ITEM WorkQueueItem;
  118. struct _DEVICE_EXTENSION_HUB *DeviceExtensionHub;
  119. PIRP Irp;
  120. } USBH_PORT_IDLE_POWER_WORK_ITEM, *PUSBH_PORT_IDLE_POWER_WORK_ITEM;
  121. typedef struct _USBH_COMPLETE_PORT_IRPS_WORK_ITEM {
  122. WORK_QUEUE_ITEM WorkQueueItem;
  123. struct _DEVICE_EXTENSION_HUB *DeviceExtensionHub;
  124. LIST_ENTRY IrpsToComplete;
  125. NTSTATUS ntStatus;
  126. } USBH_COMPLETE_PORT_IRPS_WORK_ITEM, *PUSBH_COMPLETE_PORT_IRPS_WORK_ITEM;
  127. typedef struct _USBH_HUB_ASYNC_POWER_WORK_ITEM {
  128. WORK_QUEUE_ITEM WorkQueueItem;
  129. struct _DEVICE_EXTENSION_PORT *DeviceExtensionPort;
  130. PIRP Irp;
  131. UCHAR MinorFunction;
  132. } USBH_HUB_ASYNC_POWER_WORK_ITEM, *PUSBH_HUB_ASYNC_POWER_WORK_ITEM;
  133. typedef struct _HUB_TIMEOUT_CONTEXT {
  134. PIRP Irp;
  135. KEVENT Event;
  136. KDPC TimeoutDpc;
  137. KTIMER TimeoutTimer;
  138. KSPIN_LOCK TimeoutSpin;
  139. BOOLEAN Complete;
  140. } HUB_TIMEOUT_CONTEXT, *PHUB_TIMEOUT_CONTEXT;
  141. typedef struct _PORT_TIMEOUT_CONTEXT {
  142. KDPC TimeoutDpc;
  143. KTIMER TimeoutTimer;
  144. struct _DEVICE_EXTENSION_PORT *DeviceExtensionPort;
  145. BOOLEAN CancelFlag;
  146. } PORT_TIMEOUT_CONTEXT, *PPORT_TIMEOUT_CONTEXT;
  147. typedef struct _COMP_RESET_TIMEOUT_CONTEXT {
  148. KDPC TimeoutDpc;
  149. KTIMER TimeoutTimer;
  150. struct _DEVICE_EXTENSION_PARENT *DeviceExtensionParent;
  151. BOOLEAN CancelFlag;
  152. } COMP_RESET_TIMEOUT_CONTEXT, *PCOMP_RESET_TIMEOUT_CONTEXT;
  153. typedef struct _HUB_ESD_RECOVERY_CONTEXT {
  154. KDPC TimeoutDpc;
  155. KTIMER TimeoutTimer;
  156. struct _DEVICE_EXTENSION_HUB *DeviceExtensionHub;
  157. } HUB_ESD_RECOVERY_CONTEXT, *PHUB_ESD_RECOVERY_CONTEXT;
  158. typedef struct _USB_DEVICE_UI_FIRMWARE_REVISION
  159. {
  160. USHORT Length;
  161. WCHAR FirmwareRevisionString[1];
  162. } USB_DEVICE_UI_FIRMWARE_REVISION, *PUSB_DEVICE_UI_FIRMWARE_REVISION;
  163. typedef struct _HUB_STATE {
  164. USHORT HubStatus;
  165. USHORT HubChange;
  166. } HUB_STATE, *PHUB_STATE;
  167. typedef struct _PORT_STATE {
  168. USHORT PortStatus;
  169. USHORT PortChange;
  170. } PORT_STATE, *PPORT_STATE;
  171. //
  172. // Hub and Port status defined below also apply to StatusChnage bits
  173. //
  174. #define HUB_STATUS_LOCAL_POWER 0x01
  175. #define HUB_STATUS_OVER_CURRENT 0x02
  176. #define PORT_STATUS_CONNECT 0x001
  177. #define PORT_STATUS_ENABLE 0x002
  178. #define PORT_STATUS_SUSPEND 0x004
  179. #define PORT_STATUS_OVER_CURRENT 0x008
  180. #define PORT_STATUS_RESET 0x010
  181. #define PORT_STATUS_POWER 0x100
  182. #define PORT_STATUS_LOW_SPEED 0x200
  183. #define PORT_STATUS_HIGH_SPEED 0x400
  184. //
  185. // Port data to describe relevant info about a port
  186. //
  187. // values for PortFlags
  188. // #define PORTFLAG_ 0x00000001
  189. typedef struct _PORT_DATA {
  190. PORT_STATE PortState; // the status & change bit mask of the port
  191. PDEVICE_OBJECT DeviceObject; // the PDO
  192. USB_CONNECTION_STATUS ConnectionStatus;
  193. // extended port attributes as defined in USB.H
  194. ULONG PortAttributes;
  195. // revised port data structure
  196. ULONG PortFlags;
  197. } PORT_DATA, *PPORT_DATA;
  198. //
  199. // Define the various device type values. Note that values used by Microsoft
  200. // Corporation are in the range 0-32767, and 32768-65535 are reserved for use
  201. // by customers.
  202. //
  203. #define FILE_DEVICE_USB_HUB 0x00008600
  204. #define USBH_MAX_ENUMERATION_ATTEMPTS 3
  205. //
  206. // Common fields for Pdo and Fdo extensions
  207. //
  208. #define EXTENSION_TYPE_PORT 0x54524f50 // "PORT"
  209. #define EXTENSION_TYPE_HUB 0x20425548 // "HUB "
  210. #define EXTENSION_TYPE_PARENT 0x50525400 // "PRT "
  211. #define EXTENSION_TYPE_FUNCTION 0xfefefeff // ""
  212. typedef struct _USBH_POWER_WORKER {
  213. PIRP Irp;
  214. WORK_QUEUE_ITEM WorkQueueItem;
  215. } USBH_POWER_WORKER, *PUSBH_POWER_WORKER;
  216. typedef struct _DEVICE_EXTENSION_HEADER {
  217. ULONG ExtensionType;
  218. } DEVICE_EXTENSION_HEADER, *PDEVICE_EXTENSION_HEADER;
  219. typedef struct _DEVICE_EXTENSION_COMMON {
  220. PDEVICE_OBJECT FunctionalDeviceObject; // points back to owner device object
  221. PDEVICE_OBJECT PhysicalDeviceObject; // the PDO for this device
  222. PDEVICE_OBJECT TopOfStackDeviceObject; // to of stack passed to adddevice
  223. } DEVICE_EXTENSION_COMMON, *PDEVICE_EXTENSION_COMMON;
  224. // common to FDO for hub and generic parent
  225. typedef struct _DEVICE_EXTENSION_FDO {
  226. DEVICE_EXTENSION_HEADER;
  227. DEVICE_EXTENSION_COMMON;
  228. KEVENT PnpStartEvent;
  229. PIRP PowerIrp;
  230. #ifdef WMI_SUPPORT
  231. WMILIB_CONTEXT WmiLibInfo;
  232. #endif /* WMI_SUPPORT */
  233. } DEVICE_EXTENSION_FDO, *PDEVICE_EXTENSION_FDO;
  234. //
  235. // Device_Extension for HUB
  236. //
  237. typedef struct _DEVICE_EXTENSION_HUB {
  238. //
  239. // *** NOTE the first four fields must match
  240. // DEVICE_EXTENSION_FDO
  241. //
  242. DEVICE_EXTENSION_HEADER;
  243. DEVICE_EXTENSION_COMMON;
  244. KEVENT PnpStartEvent;
  245. PIRP PowerIrp;
  246. #ifdef WMI_SUPPORT
  247. WMILIB_CONTEXT WmiLibInfo;
  248. #endif /* WMI_SUPPORT */
  249. //
  250. // Pdo created by HCD for the root hub
  251. //
  252. PDEVICE_OBJECT RootHubPdo;
  253. //
  254. // top of the host controller stack
  255. // typically this is the FDO for the HCD
  256. //
  257. PDEVICE_OBJECT TopOfHcdStackDeviceObject;
  258. ULONG HubFlags;
  259. //
  260. // we use the hub mutex to serialize access to the
  261. // hub ports between ioctls and pnp events
  262. //
  263. ULONG PendingRequestCount;
  264. ULONG ErrorCount;
  265. HUB_STATE HubState;
  266. PIRP Irp;
  267. PIRP PendingWakeIrp;
  268. LONG NumberPortWakeIrps;
  269. PUCHAR TransferBuffer;
  270. ULONG TransferBufferLength;
  271. PKEVENT Event;
  272. PUSB_HUB_DESCRIPTOR HubDescriptor;
  273. PPORT_DATA PortData;
  274. USBD_CONFIGURATION_HANDLE Configuration;
  275. PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor;
  276. DEVICE_POWER_STATE DeviceState[PowerSystemMaximum];
  277. SYSTEM_POWER_STATE SystemWake;
  278. DEVICE_POWER_STATE DeviceWake;
  279. DEVICE_POWER_STATE CurrentPowerState;
  280. LONG MaximumPowerPerPort;
  281. PORT_STATE PortStateBuffer;
  282. LONG ResetPortNumber;
  283. PUSBH_WORK_ITEM WorkItemToQueue;
  284. KEVENT AbortEvent;
  285. KEVENT PendingRequestEvent;
  286. //
  287. // we use the hub mutex to serialize access to the
  288. // hub ports between ioctls and pnp events
  289. //
  290. KSEMAPHORE HubMutex;
  291. KSEMAPHORE HubPortResetMutex;
  292. KSEMAPHORE ResetDeviceMutex;
  293. USB_DEVICE_DESCRIPTOR DeviceDescriptor;
  294. USBD_PIPE_INFORMATION PipeInformation;
  295. URB Urb;
  296. LONG InESDRecovery;
  297. #ifdef USB2
  298. USB_BUS_INTERFACE_HUB_V5 BusIf;
  299. USB_BUS_INTERFACE_USBDI_V2 UsbdiBusIf;
  300. #endif
  301. PIRP PendingIdleIrp;
  302. USB_IDLE_CALLBACK_INFO IdleCallbackInfo;
  303. KEVENT SubmitIdleEvent;
  304. LONG ChangeIndicationWorkitemPending;
  305. LONG WaitWakeIrpCancelFlag;
  306. LONG IdleIrpCancelFlag;
  307. KEVENT CWKEvent;
  308. // Only used for the Root Hub!
  309. SYSTEM_POWER_STATE CurrentSystemPowerState;
  310. KSPIN_LOCK CheckIdleSpinLock;
  311. // revised extension
  312. // deleted Pdo list, we use this list to handle
  313. // async deletion of PDOs. Basically these are
  314. // PDO we have not reported gone to PnP yet.
  315. LIST_ENTRY DeletePdoList;
  316. } DEVICE_EXTENSION_HUB, *PDEVICE_EXTENSION_HUB;
  317. #define HUBFLAG_NEED_CLEANUP 0x00000001
  318. #define HUBFLAG_ENABLED_FOR_WAKEUP 0x00000002
  319. #define HUBFLAG_DEVICE_STOPPING 0x00000004
  320. #define HUBFLAG_HUB_FAILURE 0x00000008
  321. #define HUBFLAG_SUPPORT_WAKEUP 0x00000010
  322. #define HUBFLAG_HUB_STOPPED 0x00000020
  323. #define HUBFLAG_HUB_BUSY 0x00000040
  324. #define HUBFLAG_PENDING_WAKE_IRP 0x00000080
  325. #define HUBFLAG_PENDING_PORT_RESET 0x00000100
  326. #define HUBFLAG_HUB_HAS_LOST_BRAINS 0x00000200
  327. #define HUBFLAG_SET_D0_PENDING 0x00000400
  328. #define HUBFLAG_DEVICE_LOW_POWER 0x00000800
  329. #define HUBFLAG_PENDING_IDLE_IRP 0x00001000
  330. #define HUBFLAG_CHILD_DELETES_PENDING 0x00002000
  331. #define HUBFLAG_HUB_GONE 0x00004000
  332. #define HUBFLAG_USB20_HUB 0x00008000
  333. #define HUBFLAG_NEED_IDLE_CHECK 0x00010000
  334. #define HUBFLAG_WW_SET_D0_PENDING 0x00020000
  335. #define HUBFLAG_USB20_MULTI_TT 0x00040000
  336. #define HUBFLAG_POST_ESD_ENUM_PENDING 0x00080000
  337. #define HUBFLAG_OK_TO_ENUMERATE 0x00100000
  338. #define HUBFLAG_IN_IDLE_CHECK 0x00200000
  339. #define HUBFLAG_HIBER 0x00400000
  340. typedef struct _DEVICE_EXTENSION_PARENT {
  341. DEVICE_EXTENSION_HEADER;
  342. DEVICE_EXTENSION_COMMON;
  343. KEVENT PnpStartEvent;
  344. PIRP PowerIrp;
  345. #ifdef WMI_SUPPORT
  346. WMILIB_CONTEXT WmiLibInfo;
  347. #endif /* WMI_SUPPORT */
  348. PIRP PendingWakeIrp;
  349. LONG NumberFunctionWakeIrps;
  350. ULONG FunctionCount;
  351. PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor;
  352. SINGLE_LIST_ENTRY FunctionList;
  353. DEVICE_POWER_STATE DeviceState[PowerSystemMaximum];
  354. SYSTEM_POWER_STATE SystemWake;
  355. DEVICE_POWER_STATE DeviceWake;
  356. DEVICE_POWER_STATE CurrentPowerState;
  357. ULONG ParentFlags;
  358. BOOLEAN NeedCleanup;
  359. UCHAR CurrentConfig;
  360. UCHAR Reserved[2];
  361. USB_DEVICE_DESCRIPTOR DeviceDescriptor;
  362. PCOMP_RESET_TIMEOUT_CONTEXT CompResetTimeoutContext;
  363. KSEMAPHORE ParentMutex;
  364. KSPIN_LOCK ParentSpinLock;
  365. } DEVICE_EXTENSION_PARENT, *PDEVICE_EXTENSION_PARENT;
  366. typedef struct _FUNCTION_INTERFACE {
  367. PUSBD_INTERFACE_INFORMATION InterfaceInformation;
  368. PUSB_INTERFACE_DESCRIPTOR InterfaceDescriptor;
  369. ULONG InterfaceDescriptorLength;
  370. } FUNCTION_INTERFACE, *PFUNCTION_INTERFACE;
  371. typedef struct _DEVICE_EXTENSION_FUNCTION {
  372. DEVICE_EXTENSION_HEADER;
  373. PDEVICE_EXTENSION_PARENT DeviceExtensionParent;
  374. PDEVICE_OBJECT FunctionPhysicalDeviceObject;
  375. PIRP WaitWakeIrp;
  376. PIRP ResetIrp;
  377. ULONG InterfaceCount;
  378. ULONG FunctionPdoFlags;
  379. SINGLE_LIST_ENTRY ListEntry;
  380. USBD_CONFIGURATION_HANDLE ConfigurationHandle;
  381. WCHAR UniqueIdString[4]; // room for three unicode digits plus
  382. // NULL
  383. FUNCTION_INTERFACE FunctionInterfaceList[USBH_MAX_FUNCTION_INTERFACES];
  384. } DEVICE_EXTENSION_FUNCTION, *PDEVICE_EXTENSION_FUNCTION;
  385. //
  386. // Device Extension for Port
  387. //
  388. typedef struct _DEVICE_EXTENSION_PORT {
  389. DEVICE_EXTENSION_HEADER;
  390. PDEVICE_OBJECT PortPhysicalDeviceObject;
  391. PDEVICE_EXTENSION_HUB DeviceExtensionHub;
  392. USHORT PortNumber;
  393. // port you are on on your parent hub.
  394. USHORT SerialNumberBufferLength;
  395. PVOID DeviceData;
  396. DEVICE_POWER_STATE DeviceState;
  397. PIRP WaitWakeIrp;
  398. // these flags describe the state of the PDO and
  399. // the capabilities of the device connected
  400. ULONG PortPdoFlags;
  401. ULONG DeviceHackFlags;
  402. PWCHAR SerialNumberBuffer;
  403. WCHAR UniqueIdString[4];
  404. // room for three unicode digits plus NULL
  405. UNICODE_STRING SymbolicLinkName;
  406. USB_DEVICE_DESCRIPTOR DeviceDescriptor;
  407. USB_DEVICE_DESCRIPTOR OldDeviceDescriptor;
  408. USB_CONFIGURATION_DESCRIPTOR ConfigDescriptor;
  409. USB_INTERFACE_DESCRIPTOR InterfaceDescriptor;
  410. // information returned through WMI
  411. //
  412. ULONG FailReasonId;
  413. ULONG PowerRequested;
  414. ULONG RequestedBandwidth;
  415. ULONG EnumerationFailReason;
  416. PPORT_TIMEOUT_CONTEXT PortTimeoutContext;
  417. UCHAR FeatureDescVendorCode;
  418. PIRP IdleNotificationIrp;
  419. KSPIN_LOCK PortSpinLock;
  420. DEVICE_CAPABILITIES DevCaps;
  421. PDEVICE_EXTENSION_HUB HubExtSave;
  422. #ifdef WMI_SUPPORT
  423. WMILIB_CONTEXT WmiLibInfo;
  424. #endif /* WMI_SUPPORT */
  425. // revised extension
  426. // Storage for MS Extended Config Descriptor Compatible IDs
  427. UCHAR CompatibleID[8];
  428. UCHAR SubCompatibleID[8];
  429. ULONG PnPFlags;
  430. LIST_ENTRY DeletePdoLink;
  431. } DEVICE_EXTENSION_PORT, *PDEVICE_EXTENSION_PORT;
  432. // values for PNP flags
  433. // #define PDO_PNPFLAG_
  434. #define PDO_PNPFLAG_DEVICE_PRESENT 0x00000001
  435. typedef struct _SERIAL_NUMBER_ENTRY {
  436. ULONG Vid;
  437. ULONG Pid;
  438. PVOID Pdo;
  439. } SERIAL_NUMBER_ENTRY, *PSERIAL_NUMBER_ENTRY;
  440. typedef struct _SERIAL_NUMBER_TABLE {
  441. ULONG NumEntries;
  442. ULONG MaxEntries;
  443. PSERIAL_NUMBER_ENTRY Entries;
  444. FAST_MUTEX Mutex;
  445. } SERIAL_NUMBER_TABLE, * PSERIAL_NUMBER_TABLE;
  446. //
  447. // values for PortPdoFlags
  448. //
  449. #define PORTPDO_DEVICE_IS_HUB 0x00000001
  450. #define PORTPDO_DEVICE_IS_PARENT 0x00000002
  451. #define PORTPDO_DEVICE_ENUM_ERROR 0x00000004
  452. #define PORTPDO_LOW_SPEED_DEVICE 0x00000008
  453. #define PORTPDO_REMOTE_WAKEUP_SUPPORTED 0x00000010
  454. #define PORTPDO_REMOTE_WAKEUP_ENABLED 0x00000020
  455. #define PORTPDO_DELETED_PDO 0x00000040
  456. // revised
  457. // set when the device for a PDO is removed from bus
  458. // (physically detached from hub)
  459. // PnP may or may not know the device is gone.
  460. #define PORTPDO_DELETE_PENDING 0x00000080
  461. #define PORTPDO_NEED_RESET 0x00000100
  462. #define PORTPDO_STARTED 0x00000200
  463. #define PORTPDO_USB20_DEVICE_IN_LEGACY_HUB 0x00000400
  464. #define PORTPDO_SYM_LINK 0x00000800
  465. #define PORTPDO_DEVICE_FAILED 0x00001000
  466. #define PORTPDO_USB_SUSPEND 0x00002000
  467. #define PORTPDO_OVERCURRENT 0x00004000
  468. #define PORTPDO_DD_REMOVED 0x00008000
  469. #define PORTPDO_NOT_ENOUGH_POWER 0x00010000
  470. // revised not used
  471. //#define PORTPDO_PDO_RETURNED 0x00020000
  472. #define PORTPDO_NO_BANDWIDTH 0x00040000
  473. #define PORTPDO_RESET_PENDING 0x00080000
  474. #define PORTPDO_OS_STRING_DESC_REQUESTED 0x00100000
  475. #define PORTPDO_MS_VENDOR_CODE_VALID 0x00200000
  476. #define PORTPDO_IDLE_NOTIFIED 0x00400000
  477. #define PORTPDO_HIGH_SPEED_DEVICE 0x00800000
  478. #define PORTPDO_NEED_CLEAR_REMOTE_WAKEUP 0x01000000
  479. #define PORTPDO_WMI_REGISTERED 0x02000000
  480. #define PORTPDO_VALID_FOR_PNP_FUNCTION 0x04000000
  481. #define PORTPDO_CYCLED 0x08000000
  482. //
  483. // NOTE: this macro will alway inavlidate the device state but
  484. // never change the current "fail reason"
  485. #define HUB_FAILURE(de) \
  486. { \
  487. de->HubFlags |= HUBFLAG_HUB_FAILURE; \
  488. USBH_KdPrint((1, "'hub failure, VID %x PID %x line %d file %s\n", \
  489. de->DeviceDescriptor.idVendor, \
  490. de->DeviceDescriptor.idProduct, __LINE__, __FILE__)); \
  491. LOGENTRY(LOG_PNP, "HUB!", de, __LINE__, de->HubFlags); \
  492. }
  493. //#define DEVICE_FAILURE(dep) \
  494. // { \
  495. // dep->PortPdoFlags |= PORTPDO_DEVICE_FAILED; \
  496. // USBH_KdPrint((1, "'device failure, VID %x PID %x line %d file %s\n", \
  497. // dep->DeviceDescriptor.idVendor, \
  498. // dep->DeviceDescriptor.idProduct,\
  499. // __LINE__, __FILE__)); \
  500. // LOGENTRY(LOG_PNP, "DEV!", dep, 0, 0); \
  501. // }
  502. #define IS_ROOT_HUB(de) (de->PhysicalDeviceObject == de->RootHubPdo)
  503. #define USBH_IoInvalidateDeviceRelations(devobj, b) \
  504. { \
  505. LOGENTRY(LOG_PNP, "HUBr", devobj, 0, 0); \
  506. USBH_KdPrint((1, "'IoInvalidateDeviceRelations %x\n", devobj));\
  507. IoInvalidateDeviceRelations(devobj, b); \
  508. }
  509. //
  510. // Length of buffer for Hub and port status are both 4
  511. //
  512. #define STATUS_HUB_OR_PORT_LENGTH 4
  513. //
  514. // Hub Characterics
  515. //
  516. //
  517. // Powere switch mode
  518. //
  519. #define HUB_CHARS_POWER_SWITCH_MODE_MASK 0x0003
  520. #define HUB_CHARS_POWER_SWITCH_GANGED 0x0000 //00
  521. #define HUB_CHARS_POWER_SWITCH_INDIVIDUAL 0x0001 //01
  522. #define HUB_CHARS_POWER_SWITCH_NONE 0x0002 //1X
  523. #define HUB_IS_GANG_POWER_SWITCHED(hc) \
  524. (((hc) & HUB_CHARS_POWER_SWITCH_MODE_MASK) == HUB_CHARS_POWER_SWITCH_GANGED)
  525. #define HUB_IS_NOT_POWER_SWITCHED(hc) \
  526. (((hc) & HUB_CHARS_POWER_SWITCH_NONE) == HUB_CHARS_POWER_SWITCH_NONE)
  527. #define HUB_IS_PORT_POWER_SWITCHED(hc) \
  528. (((hc) & HUB_CHARS_POWER_SWITCH_MODE_MASK) == HUB_CHARS_POWER_SWITCH_INDIVIDUAL)
  529. BOOLEAN
  530. IsBitSet(
  531. PVOID Bitmap,
  532. ULONG PortNumber
  533. );
  534. #define PORT_ALWAYS_POWER_SWITCHED(hd, p) \
  535. IsBitSet(&(hd)->bRemoveAndPowerMask[((hd)->bNumberOfPorts)/8 + 1], \
  536. (p))
  537. #define PORT_DEVICE_NOT_REMOVABLE(hd, p) \
  538. IsBitSet(&(hd)->bRemoveAndPowerMask[0], \
  539. (p))
  540. //
  541. // Compound Device
  542. //
  543. #define HUB_CHARS_COMPOUND_DEVICE 0x4
  544. //
  545. // Over Current Protection Mode
  546. //
  547. #define HUB_CHARS_OVERCURRENT_PROTECTION_MODE_MASK 0x18
  548. #define HUB_CHARS_OVERCURRENT_PROTECTION_MODE_GLOBAL 0x0
  549. #define HUB_CHARS_OVERCURRENT_PROTECTION_MODE_INDIVIDUAL 0x8
  550. #define HUB_CHARS_OVERCURRENT_PROTECTION_MODE_NONE 0x10
  551. //
  552. // Request codes, defined in Ch11
  553. //
  554. #define REQUEST_GET_STATUS 0
  555. #define REQUEST_CLEAR_FEATURE 1
  556. #define REQUEST_GET_STATE 2
  557. #define REQUEST_SET_FEATURE 3
  558. #define REQUEST_SET_ADDRESS 5
  559. #define REQUEST_GET_DESCRIPTOR 6
  560. #define REQUEST_SET_DESCRIPTOR 7
  561. #define REQUEST_GET_CONFIGURATION 8
  562. #define REQUEST_SET_CONFIGURATION 9
  563. #define REQUEST_GET_INTERFACE 10
  564. #define REQUEST_SET_INTERFACE 11
  565. #define REQUEST_SYNCH_FRAME 12
  566. //
  567. // These request types can be composed.
  568. // But it is just easy to define them.
  569. //
  570. #define REQUEST_TYPE_CLEAR_HUB_FEATURE 0x20
  571. #define REQUEST_TYPE_CLEAR_PORT_FEATURE 0x23
  572. #define REQUEST_TYPE_GET_BUS_STATE 0xa3
  573. #define REQUEST_TYPE_GET_HUB_DESCRIPTOR 0xa0
  574. #define REQUEST_TYPE_GET_HUB_STATUS 0xa0
  575. #define REQUEST_TYPE_GET_PORT_STATUS 0xa3
  576. #define REQUEST_TYPE_SET_HUB_DESCRIPTOR 0x20
  577. #define REQUEST_TYPE_SET_HUB_FEATURE 0x20
  578. #define REQUEST_TYPE_SET_PORT_FEATURE 0x23
  579. //
  580. // Feature selector, defined in Ch11
  581. //
  582. #define FEATURE_C_HUB_LOCAL_POWER 0
  583. #define FEATURE_C_HUB_OVER_CURRENT 1
  584. #define FEATURE_PORT_CONNECT 0
  585. #define FEATURE_PORT_ENABLE 1
  586. #define FEATURE_PORT_SUSPEND 2
  587. #define FEATURE_PORT_OVER_CURRENT 3
  588. #define FEATURE_PORT_RESET 4
  589. #define FEATURE_PORT_POWER 8
  590. #define FEATURE_PORT_LOW_SPEED 9
  591. #define FEATURE_C_PORT_CONNECT 16
  592. #define FEATURE_C_PORT_ENABLE 17
  593. #define FEATURE_C_PORT_SUSPEND 18
  594. #define FEATURE_C_PORT_OVER_CURRENT 19
  595. #define FEATURE_C_PORT_RESET 20
  596. //----------------------------------------------------------------------------------
  597. // Utility Macros
  598. #define UsbhBuildGetDescriptorUrb(\
  599. pUrb, \
  600. pDeviceData, \
  601. bDescriptorType, \
  602. bDescriptorIndex, \
  603. wLanguageId, \
  604. ulTransferLength, \
  605. pTransferBuffer) \
  606. {\
  607. (pUrb)->UrbHeader.UsbdDeviceHandle = pDeviceData;\
  608. (pUrb)->UrbHeader.Length = (USHORT) sizeof (struct _URB_CONTROL_DESCRIPTOR_REQUEST);\
  609. (pUrb)->UrbHeader.Function = URB_FUNCTION_GET_DESCRIPTOR_FROM_DEVICE;\
  610. (pUrb)->UrbControlDescriptorRequest.DescriptorType = bDescriptorType;\
  611. (pUrb)->UrbControlDescriptorRequest.Index = bDescriptorIndex;\
  612. (pUrb)->UrbControlDescriptorRequest.LanguageId = wLanguageId;\
  613. (pUrb)->UrbControlDescriptorRequest.TransferBufferLength = ulTransferLength;\
  614. (pUrb)->UrbControlDescriptorRequest.TransferBuffer = pTransferBuffer;\
  615. (pUrb)->UrbControlDescriptorRequest.TransferBufferMDL = NULL;\
  616. (pUrb)->UrbControlVendorClassRequest.UrbLink = NULL;\
  617. }
  618. #define UsbhBuildVendorClassUrb(\
  619. pUrb,\
  620. pDeviceData,\
  621. wFunction,\
  622. ulTransferFlags,\
  623. bRequestType,\
  624. bRequest,\
  625. wFeatureSelector,\
  626. wPort,\
  627. ulTransferBufferLength,\
  628. pTransferBuffer)\
  629. {\
  630. (pUrb)->UrbHeader.Length = (USHORT) sizeof( struct _URB_CONTROL_VENDOR_OR_CLASS_REQUEST);\
  631. (pUrb)->UrbHeader.Function = wFunction;\
  632. (pUrb)->UrbHeader.UsbdDeviceHandle = pDeviceData;\
  633. (pUrb)->UrbControlVendorClassRequest.TransferFlags = ulTransferFlags;\
  634. (pUrb)->UrbControlVendorClassRequest.TransferBufferLength = ulTransferBufferLength;\
  635. (pUrb)->UrbControlVendorClassRequest.TransferBuffer = pTransferBuffer;\
  636. (pUrb)->UrbControlVendorClassRequest.TransferBufferMDL = NULL;\
  637. (pUrb)->UrbControlVendorClassRequest.RequestTypeReservedBits = bRequestType;\
  638. (pUrb)->UrbControlVendorClassRequest.Request = bRequest;\
  639. (pUrb)->UrbControlVendorClassRequest.Value = wFeatureSelector;\
  640. (pUrb)->UrbControlVendorClassRequest.Index = wPort;\
  641. (pUrb)->UrbControlVendorClassRequest.UrbLink = NULL;\
  642. }
  643. //----------------------------------------------------------------------------------
  644. //
  645. // string macros. these work with char and wide char strings
  646. //
  647. // Counting the byte count of an ascii string or wide char string
  648. //
  649. #define STRLEN( Length, p )\
  650. {\
  651. int i;\
  652. for ( i=0; (p)[i]; i++ );\
  653. Length = i*sizeof(*p);\
  654. }
  655. //
  656. // copy wide char string
  657. //
  658. #define STRCPY( pDst, pSrc )\
  659. {\
  660. int nLength, i;\
  661. STRLEN( nLength, pSrc );\
  662. nLength /= sizeof( *pSrc );\
  663. for ( i=0; i < nLength; i++ ) pDst[i] = pSrc[i];\
  664. pDst[i] = 0;\
  665. }
  666. //
  667. // concat (wide) char strings
  668. //
  669. #define STRCAT( pFirst, pSecond )\
  670. {\
  671. int j, k;\
  672. int nLength;\
  673. STRLEN( j, pFirst );\
  674. STRLEN( nLength, pSecond );\
  675. j /= sizeof( *pFirst );\
  676. nLength /= sizeof( *pSecond);\
  677. for ( k=0; k < nLength; k++, j++ ) pFirst[j] = pSecond[k];\
  678. pFirst[j] = 0;\
  679. }
  680. //
  681. // append a (wide) char,
  682. //
  683. #define APPEND( pString, ch )\
  684. {\
  685. int nLength;\
  686. STRLEN( nLength, pString );\
  687. nLength /= sizeof( *pString );\
  688. pString[nLength] = ch;\
  689. pString[nLength+1] = 0;\
  690. }
  691. //----------------------------------------------------------------------------------
  692. //
  693. // Debug Macros
  694. //
  695. #ifdef NTKERN
  696. // Win95 only
  697. #define DBGBREAK() _asm {int 3}
  698. #else
  699. #define DBGBREAK() DbgBreakPoint()
  700. #endif
  701. #define USBHUB_HEAP_TAG 0x42554855 //"UHUB"
  702. #define USBHUB_FREE_TAG 0x62756875 //"uhub"
  703. #if DBG
  704. PVOID
  705. UsbhGetHeap(
  706. IN POOL_TYPE PoolType,
  707. IN ULONG NumberOfBytes,
  708. IN ULONG Signature,
  709. IN PLONG TotalAllocatedHeapSpace
  710. );
  711. VOID
  712. UsbhRetHeap(
  713. IN PVOID P,
  714. IN ULONG Signature,
  715. IN PLONG TotalAllocatedHeapSpace
  716. );
  717. // TEST_TRAP() is a code coverage trap these should be removed
  718. // if you are able to 'g' past the OK
  719. //
  720. // KdTrap() breaks in the debugger on the debug build
  721. // these indicate bugs in client drivers, kernel apis or fatal error
  722. // conditions that should be debugged. also used to mark
  723. // code for features not implemented yet.
  724. //
  725. // KdBreak() breaks in the debugger when in MAX_DEBUG mode
  726. // ie debug trace info is turned on, these are intended to help
  727. // debug drivers devices and special conditions on the
  728. // bus.
  729. ULONG
  730. _cdecl
  731. USBH_KdPrintX(
  732. ULONG l,
  733. PCH Format,
  734. ...
  735. );
  736. #define UsbhExAllocatePool(pt, l) UsbhGetHeap(pt, l, USBHUB_HEAP_TAG, \
  737. &UsbhHeapCount)
  738. #define UsbhExFreePool(p) UsbhRetHeap(p, USBHUB_HEAP_TAG, &UsbhHeapCount)
  739. #define DBG_ONLY(s) s
  740. #define USBH_KdPrint(_s_) USBH_KdPrintX _s_
  741. //#define USBH_KdPrintAlways(s) { DbgPrint( "USBH: "); \
  742. // DbgPrint s; \
  743. // }
  744. #ifdef MAX_DEBUG
  745. #define USBH_KdBreak(s) if (USBH_Debug_Trace_Level) { \
  746. DbgPrint( "USBH: "); \
  747. DbgPrint s; \
  748. } \
  749. DBGBREAK();
  750. #else
  751. #define USBH_KdBreak(s)
  752. #endif /* MAX_DEBUG */
  753. #define USBH_KdTrap(s) { DbgPrint( "USBH: ");\
  754. DbgPrint s; \
  755. DBGBREAK(); }
  756. #define TEST_TRAP() { DbgPrint( "USBH: Code coverage trap %s line: %d\n", __FILE__, __LINE__);\
  757. DBGBREAK();}
  758. #else // not debug
  759. #define UsbhExAllocatePool(pt, l) ExAllocatePoolWithTag(pt, l, USBHUB_HEAP_TAG)
  760. #define UsbhExFreePool(p) ExFreePool(p)
  761. #define DBG_ONLY(s)
  762. #define USBH_KdPrint(_s_)
  763. #define USBH_KdBreak(s)
  764. #define USBH_KdTrap(s)
  765. //#define USBH_KdPrintAlways(s)
  766. #define TEST_TRAP();
  767. #endif
  768. #ifdef HOST_GLOBALS
  769. #define DECLARE(type, var, init_value ) type var = init_value;
  770. #define DECLARE_NO_INIT(type, var) type var;
  771. #else
  772. #define DECLARE(type, var, init_value ) extern type var;
  773. #define DECLARE_NO_INIT(type, var ) extern type var;
  774. #endif
  775. //----------------------------------------------------------------------------------
  776. //
  777. // Global Variables
  778. //
  779. //
  780. // Remember our driver object
  781. //
  782. DECLARE( PDRIVER_OBJECT, UsbhDriverObject, NULL)
  783. extern PWCHAR GenericUSBDeviceString;
  784. #if DBG
  785. //
  786. // keep track of heap allocations
  787. //
  788. DECLARE( ULONG, UsbhHeapCount, 0)
  789. #define PNP_TEST_FAIL_ENUM 0x00000001
  790. #define PNP_TEST_FAIL_DEV_POWER 0x00000002
  791. #define PNP_TEST_FAIL_HUB_COUNT 0x00000004
  792. #define PNP_TEST_FAIL_HUB 0x00000008
  793. #define PNP_TEST_FAIL_PORT_RESET 0x00000010
  794. #define PNP_TEST_FAIL_WAKE_REQUEST 0x00000020
  795. #define PNP_TEST_FAIL_RESTORE 0x00000040
  796. DECLARE( ULONG, UsbhPnpTest, 0)
  797. #endif
  798. //
  799. // The following strings are used to build HardwareId etc.
  800. //
  801. // USB string
  802. //
  803. DECLARE( PWCHAR, pwchUsbSlash, L"USB\\");
  804. // Vendor ID string
  805. //
  806. DECLARE( PWCHAR, pwchVid, L"Vid_");
  807. //
  808. // Product Id string
  809. //
  810. DECLARE( PWCHAR, pwchPid, L"Pid_");
  811. //
  812. // Revision string
  813. //
  814. DECLARE( PWCHAR, pwchRev, L"Rev_");
  815. //
  816. // Device Class string
  817. //
  818. DECLARE( PWCHAR, pwchDevClass, L"DevClass_");
  819. //
  820. // Class string
  821. //
  822. DECLARE( PWCHAR, pwchClass, L"Class_");
  823. //
  824. // Composite
  825. //
  826. DECLARE( PWCHAR, pwchComposite, L"USB\\COMPOSITE");
  827. //
  828. // SubClass string
  829. //
  830. DECLARE( PWCHAR, pwchSubClass, L"SubClass_");
  831. //
  832. // MultiInterface string
  833. //
  834. DECLARE( PWCHAR, pwchMultiInterface, L"USB\\MI");
  835. //
  836. // Device Protocol string
  837. //
  838. DECLARE( PWCHAR, pwchProt, L"Prot_");
  839. DECLARE_NO_INIT( UNICODE_STRING, UsbhRegistryPath);
  840. //
  841. // To set the verbose level of the debug print
  842. //
  843. #ifdef MAX_DEBUG
  844. #define DEBUG3
  845. #endif /* MAX_DEBUG */
  846. #ifdef DEBUG3
  847. DBG_ONLY( DECLARE( ULONG, USBH_Debug_Trace_Level, 3))
  848. #else
  849. #ifdef DEBUG2
  850. DBG_ONLY( DECLARE( ULONG, USBH_Debug_Trace_Level, 2))
  851. #else
  852. #ifdef DEBUG1
  853. DBG_ONLY( DECLARE( ULONG, USBH_Debug_Trace_Level, 1))
  854. #else
  855. DBG_ONLY( DECLARE( ULONG, USBH_Debug_Trace_Level, 0))
  856. #endif // DEBUG1
  857. #endif // DEBUG2
  858. #endif // DEBUG3
  859. #define USBH_DEBUGFLAG_BREAK_PDO_START 0x00000001
  860. DBG_ONLY( DECLARE( ULONG, USBH_Debug_Flags, 0))
  861. #if DBG
  862. VOID
  863. UsbhWarning(
  864. PDEVICE_EXTENSION_PORT DeviceExtensionPort,
  865. PUCHAR Message,
  866. BOOLEAN DebugBreak
  867. );
  868. #define ASSERT_HUB(de) USBH_ASSERT(EXTENSION_TYPE_HUB == ((PDEVICE_EXTENSION_HUB) de)->ExtensionType)
  869. #define ASSERT_PORT(de) USBH_ASSERT(EXTENSION_TYPE_PORT == ((PDEVICE_EXTENSION_PORT) de)->ExtensionType)
  870. #define ASSERT_FUNCTION(de) USBH_ASSERT(EXTENSION_TYPE_FUNCTION == ((PDEVICE_EXTENSION_FUNCTION) de)->ExtensionType)
  871. #else
  872. #define UsbhWarning(x, y, z)
  873. #define ASSERT_HUB(de)
  874. #define ASSERT_PORT(de)
  875. #define ASSERT_FUNCTION(de)
  876. #endif
  877. #define TO_USB_DEVICE 0
  878. #define TO_USB_INTERFACE 1
  879. #define TO_USB_ENDPOINT 2
  880. //
  881. // maximum number of times we will attempt to reset
  882. // the hub before giving up
  883. //
  884. #define USBH_MAX_ERRORS 3
  885. //----------------------------------------------------------------------------------
  886. //
  887. // Function Prototypes
  888. //
  889. #ifdef USB2
  890. VOID
  891. USBH_InitializeUSB2Hub(
  892. PDEVICE_EXTENSION_HUB DeviceExtensionHub
  893. );
  894. // use version 5
  895. #define PUSB_HUB_BUS_INTERFACE PUSB_BUS_INTERFACE_HUB_V5
  896. #define HUB_BUSIF_VERSION USB_BUSIF_HUB_VERSION_5
  897. NTSTATUS
  898. USBHUB_GetBusInterface(
  899. IN PDEVICE_OBJECT RootHubPdo,
  900. IN PUSB_HUB_BUS_INTERFACE BusInterface
  901. );
  902. NTSTATUS
  903. USBD_CreateDeviceEx(
  904. IN PDEVICE_EXTENSION_HUB DeviceExtensionHub,
  905. IN OUT PUSB_DEVICE_HANDLE *DeviceData,
  906. IN PDEVICE_OBJECT RootHubPdo,
  907. IN ULONG MaxPacketSize_Endpoint0,
  908. IN OUT PULONG DeviceHackFlags,
  909. IN USHORT PortStatus,
  910. IN USHORT PortNumber
  911. );
  912. VOID
  913. USBHUB_FlushAllTransfers(
  914. PDEVICE_EXTENSION_HUB DeviceExtensionHub
  915. );
  916. NTSTATUS
  917. USBD_InitializeDeviceEx(
  918. IN PDEVICE_EXTENSION_HUB DeviceExtensionHub,
  919. IN PUSB_DEVICE_HANDLE DeviceData,
  920. IN PDEVICE_OBJECT RootHubPdo,
  921. IN OUT PUSB_DEVICE_DESCRIPTOR DeviceDescriptor,
  922. IN ULONG DeviceDescriptorLength,
  923. IN OUT PUSB_CONFIGURATION_DESCRIPTOR ConfigDescriptor,
  924. IN ULONG ConfigDescriptorLength
  925. );
  926. NTSTATUS
  927. USBD_RemoveDeviceEx(
  928. IN PDEVICE_EXTENSION_HUB DeviceExtensionHub,
  929. IN PUSB_DEVICE_HANDLE DeviceData,
  930. IN PDEVICE_OBJECT RootHubPdo,
  931. IN ULONG Flags
  932. );
  933. NTSTATUS
  934. USBD_GetDeviceInformationEx(
  935. IN PDEVICE_EXTENSION_PORT DeviceExtensionPort,
  936. IN PDEVICE_EXTENSION_HUB DeviceExtensionHub,
  937. IN PUSB_NODE_CONNECTION_INFORMATION_EX DeviceInformation,
  938. IN ULONG DeviceInformationLength,
  939. IN PUSB_DEVICE_HANDLE DeviceData
  940. );
  941. NTSTATUS
  942. USBD_MakePdoNameEx(
  943. IN PDEVICE_EXTENSION_HUB DeviceExtensionHub,
  944. IN OUT PUNICODE_STRING PdoNameUnicodeString,
  945. IN ULONG Index
  946. );
  947. ULONG
  948. USBD_CalculateUsbBandwidthEx(
  949. IN ULONG MaxPacketSize,
  950. IN UCHAR EndpointType,
  951. IN BOOLEAN LowSpeed
  952. );
  953. NTSTATUS
  954. USBD_RestoreDeviceEx(
  955. IN PDEVICE_EXTENSION_HUB DeviceExtensionHub,
  956. IN OUT PUSB_DEVICE_HANDLE OldDeviceData,
  957. IN OUT PUSB_DEVICE_HANDLE NewDeviceData,
  958. IN PDEVICE_OBJECT RootHubPdo
  959. );
  960. NTSTATUS
  961. USBD_QuerySelectiveSuspendEnabled(
  962. IN PDEVICE_EXTENSION_HUB DeviceExtensionHub,
  963. IN OUT PBOOLEAN SelectiveSuspendEnabled
  964. );
  965. NTSTATUS
  966. USBD_SetSelectiveSuspendEnabled(
  967. IN PDEVICE_EXTENSION_HUB DeviceExtensionHub,
  968. IN BOOLEAN SelectiveSuspendEnabled
  969. );
  970. NTSTATUS
  971. USBHUB_GetRootHubName(
  972. IN PDEVICE_EXTENSION_HUB DeviceExtensionHub,
  973. IN PVOID Buffer,
  974. IN PULONG BufferLength
  975. );
  976. //ULONG
  977. //USBD_GetHackFlags(
  978. // IN PDEVICE_EXTENSION_HUB DeviceExtensionHub
  979. // );
  980. #endif
  981. NTSTATUS
  982. USBH_SyncResetPort(
  983. IN OUT PDEVICE_EXTENSION_HUB DeviceExtensionHub,
  984. IN USHORT PortNumber);
  985. NTSTATUS
  986. USBH_SyncResetDevice (
  987. IN PDEVICE_OBJECT DeviceObject
  988. );
  989. NTSTATUS
  990. USBH_SyncResumePort(
  991. IN OUT PDEVICE_EXTENSION_HUB DeviceExtensionHub,
  992. IN USHORT PortNumber);
  993. NTSTATUS
  994. USBH_SyncSuspendPort(
  995. IN OUT PDEVICE_EXTENSION_HUB DeviceExtensionHub,
  996. IN USHORT PortNumber);
  997. VOID
  998. USBH_ProcessHubStateChange(
  999. IN PHUB_STATE CurrentHubState,
  1000. IN PDEVICE_EXTENSION_HUB DeviceExtensionHub);
  1001. VOID
  1002. USBH_ProcessPortStateChange(
  1003. IN PPORT_STATE CurrentPortState,
  1004. IN USHORT PortNumber,
  1005. IN PDEVICE_EXTENSION_HUB DeviceExtensionHub);
  1006. NTSTATUS
  1007. USBH_SyncGetPortStatus(
  1008. IN PDEVICE_EXTENSION_HUB DeviceExtensionHub,
  1009. IN USHORT PortNumber,
  1010. OUT PUCHAR DataBuffer,
  1011. IN ULONG DataBufferLength);
  1012. NTSTATUS
  1013. USBH_SyncClearPortStatus(
  1014. IN PDEVICE_EXTENSION_HUB DeviceExtensionHub,
  1015. IN USHORT PortNumber,
  1016. IN USHORT Feature);
  1017. NTSTATUS
  1018. USBH_SyncClearHubStatus(
  1019. IN PDEVICE_EXTENSION_HUB DeviceExtensionHub,
  1020. IN USHORT Feature);
  1021. NTSTATUS
  1022. USBH_SyncEnablePort(
  1023. IN OUT PDEVICE_EXTENSION_HUB DeviceExtensionHub,
  1024. IN USHORT PortNumber);
  1025. NTSTATUS
  1026. USBH_SyncPowerOnPort(
  1027. IN OUT PDEVICE_EXTENSION_HUB DeviceExtensionHub,
  1028. IN USHORT PortNumber,
  1029. IN BOOLEAN WaitForPowerGood);
  1030. NTSTATUS
  1031. USBH_SyncPowerOffPort(
  1032. IN OUT PDEVICE_EXTENSION_HUB DeviceExtensionHub,
  1033. IN USHORT PortNumber);
  1034. NTSTATUS
  1035. USBH_SyncPowerOnPorts(
  1036. IN OUT PDEVICE_EXTENSION_HUB DeviceExtensionHub);
  1037. NTSTATUS
  1038. DriverEntry(
  1039. IN PDRIVER_OBJECT DriverObject,
  1040. IN PUNICODE_STRING UniRegistryPath);
  1041. NTSTATUS
  1042. USBH_HubDispatch(
  1043. IN PDEVICE_OBJECT DeviceObject,
  1044. IN PIRP Irp);
  1045. VOID
  1046. USBH_DriverUnload(
  1047. IN PDRIVER_OBJECT DriverObject);
  1048. VOID
  1049. UsbhWait(
  1050. ULONG MiliSeconds);
  1051. NTSTATUS
  1052. USBH_PdoDispatch(
  1053. PDEVICE_EXTENSION_PORT pDeviceExtensionPort,
  1054. PIRP pIrp);
  1055. NTSTATUS
  1056. USBH_SyncGetHubDescriptor(
  1057. IN PDEVICE_EXTENSION_HUB DeviceExtensionHub);
  1058. NTSTATUS
  1059. USBH_SyncGetDeviceConfigurationDescriptor(
  1060. PDEVICE_OBJECT DeviceObject,
  1061. PUCHAR DataBuffer,
  1062. ULONG DataBufferLength,
  1063. OUT PULONG BytesReturned);
  1064. BOOLEAN
  1065. USBH_ValidateSerialNumberString(
  1066. PWCHAR DeviceId
  1067. );
  1068. NTSTATUS
  1069. USBH_CreateDevice(
  1070. PDEVICE_EXTENSION_HUB DeviceExtensionHub,
  1071. USHORT PortNumber,
  1072. USHORT PortStatus,
  1073. ULONG RetryIteration
  1074. );
  1075. NTSTATUS
  1076. USBH_FdoSyncSubmitUrb(
  1077. PDEVICE_OBJECT HubDeviceObject,
  1078. IN PURB Urb);
  1079. NTSTATUS
  1080. USBH_SyncGetRootHubPdo(
  1081. IN PDEVICE_OBJECT DeviceObject,
  1082. IN OUT PDEVICE_OBJECT *RootHubPdo,
  1083. IN OUT PDEVICE_OBJECT *HcdDeviceObject,
  1084. IN OUT PULONG Count
  1085. );
  1086. NTSTATUS
  1087. USBH_AddDevice(
  1088. IN PDRIVER_OBJECT DriverObject,
  1089. IN PDEVICE_OBJECT PhysicalDeviceObject);
  1090. NTSTATUS
  1091. USBH_FdoPnP(
  1092. PDEVICE_EXTENSION_HUB DeviceExtensionHub,
  1093. PIRP Irp,
  1094. UCHAR MinorFunction);
  1095. NTSTATUS
  1096. USBH_FdoPower(
  1097. PDEVICE_EXTENSION_HUB DeviceExtensionHub,
  1098. PIRP Irp,
  1099. UCHAR MinorFunction);
  1100. NTSTATUS
  1101. USBH_ChangeIndication(
  1102. IN PDEVICE_OBJECT PNull,
  1103. IN PIRP Irp,
  1104. IN PVOID Context);
  1105. VOID
  1106. USBH_ChangeIndicationWorker(
  1107. PVOID Context);
  1108. NTSTATUS
  1109. USBH_PassIrp(
  1110. PIRP Irp,
  1111. PDEVICE_OBJECT NextDeviceObject);
  1112. VOID
  1113. USBH_CompleteIrp(
  1114. IN PIRP Irp,
  1115. IN NTSTATUS NtStatus);
  1116. NTSTATUS
  1117. USBH_SyncDisablePort(
  1118. IN OUT PDEVICE_EXTENSION_HUB DeviceExtensionHub,
  1119. IN USHORT PortNumber);
  1120. NTSTATUS
  1121. USBH_SyncGetHubStatus(
  1122. IN PDEVICE_EXTENSION_HUB DeviceExtensionHub,
  1123. OUT PUCHAR DataBuffer,
  1124. IN ULONG DataBufferLength);
  1125. NTSTATUS
  1126. USBH_FdoHubStartDevice(
  1127. IN OUT PDEVICE_EXTENSION_HUB DeviceExtensionHub,
  1128. IN PIRP Irp);
  1129. NTSTATUS
  1130. USBH_ParentFdoStartDevice(
  1131. IN OUT PDEVICE_EXTENSION_PARENT DeviceExtensionParent,
  1132. IN PIRP Irp,
  1133. IN BOOLEAN NewList
  1134. );
  1135. NTSTATUS
  1136. USBH_ParentDispatch(
  1137. IN PDEVICE_EXTENSION_PARENT DeviceExtensionParent,
  1138. IN PIRP Irp
  1139. );
  1140. NTSTATUS
  1141. USBH_GetConfigurationDescriptor(
  1142. IN PDEVICE_OBJECT DeviceObject,
  1143. IN OUT PUSB_CONFIGURATION_DESCRIPTOR *DataBuffer
  1144. );
  1145. PWCHAR
  1146. USBH_BuildDeviceID(
  1147. IN USHORT IdVendor,
  1148. IN USHORT IdProduct,
  1149. IN LONG MiId,
  1150. IN BOOLEAN IsHubClass
  1151. );
  1152. PWCHAR
  1153. USBH_BuildHardwareIDs(
  1154. IN USHORT IdVendor,
  1155. IN USHORT IdProduct,
  1156. IN USHORT BcdDevice,
  1157. IN LONG MiId,
  1158. IN BOOLEAN IsHubClass
  1159. );
  1160. PWCHAR
  1161. USBH_BuildCompatibleIDs(
  1162. IN PUCHAR CompatibleID,
  1163. IN PUCHAR SubCompatibleID,
  1164. IN UCHAR Class,
  1165. IN UCHAR SubClass,
  1166. IN UCHAR Protocol,
  1167. IN BOOLEAN DeviceClass,
  1168. IN BOOLEAN DeviceIsHighSpeed
  1169. );
  1170. PWCHAR
  1171. USBH_BuildInstanceID(
  1172. IN PWCHAR UniqueIdString,
  1173. IN ULONG Length
  1174. );
  1175. NTSTATUS
  1176. USBH_GetDeviceDescriptor(
  1177. IN PDEVICE_OBJECT HubFDO,
  1178. OUT PUSB_DEVICE_DESCRIPTOR DeviceDescriptor
  1179. );
  1180. NTSTATUS
  1181. USBH_GetDeviceQualifierDescriptor(
  1182. IN PDEVICE_OBJECT DevicePDO,
  1183. OUT PUSB_DEVICE_QUALIFIER_DESCRIPTOR DeviceQualifierDescriptor
  1184. );
  1185. NTSTATUS
  1186. USBH_FunctionPdoDispatch(
  1187. IN PDEVICE_EXTENSION_FUNCTION DeviceExtensionFunction,
  1188. IN PIRP Irp
  1189. );
  1190. NTSTATUS
  1191. USBH_CloseConfiguration(
  1192. IN PDEVICE_EXTENSION_FDO DeviceExtensionFdo
  1193. );
  1194. NTSTATUS
  1195. USBH_IoctlGetNodeInformation(
  1196. IN PDEVICE_EXTENSION_HUB DeviceExtensionHub,
  1197. IN PIRP Irp
  1198. );
  1199. NTSTATUS
  1200. USBH_IoctlGetHubCapabilities(
  1201. IN PDEVICE_EXTENSION_HUB DeviceExtensionHub,
  1202. IN PIRP Irp
  1203. );
  1204. NTSTATUS
  1205. USBH_IoctlGetNodeConnectionInformation(
  1206. IN PDEVICE_EXTENSION_HUB DeviceExtensionHub,
  1207. IN PIRP Irp,
  1208. IN BOOLEAN ExApi
  1209. );
  1210. NTSTATUS
  1211. USBH_IoctlGetDescriptorForPDO(
  1212. IN PDEVICE_EXTENSION_HUB DeviceExtensionHub,
  1213. IN PIRP Irp
  1214. );
  1215. NTSTATUS
  1216. USBH_SyncSubmitUrb(
  1217. IN PDEVICE_OBJECT DeviceObject,
  1218. IN PURB Urb
  1219. );
  1220. NTSTATUS
  1221. USBH_Transact(
  1222. IN PDEVICE_EXTENSION_HUB DeviceExtensionHub,
  1223. IN PUCHAR DataBuffer,
  1224. IN ULONG DataBufferLength,
  1225. IN BOOLEAN DataOutput,
  1226. IN USHORT Function,
  1227. IN UCHAR RequestType,
  1228. IN UCHAR Request,
  1229. IN USHORT Feature,
  1230. IN USHORT Port,
  1231. OUT PULONG BytesTransferred
  1232. );
  1233. NTSTATUS
  1234. USBH_GetNameFromPdo(
  1235. IN PDEVICE_OBJECT PdoDeviceObject,
  1236. IN OUT PUNICODE_STRING DeviceNameUnicodeString
  1237. );
  1238. NTSTATUS
  1239. USBH_MakeName(
  1240. PDEVICE_OBJECT PdoDeviceObject,
  1241. ULONG NameLength,
  1242. PWCHAR Name,
  1243. PUNICODE_STRING UnicodeString
  1244. );
  1245. NTSTATUS
  1246. USBH_FdoStartDevice(
  1247. IN OUT PDEVICE_EXTENSION_HUB DeviceExtensionHub,
  1248. IN PIRP Irp
  1249. );
  1250. VOID
  1251. USBH_QueryCapabilities(
  1252. IN PDEVICE_OBJECT PdoDeviceObject,
  1253. IN PDEVICE_CAPABILITIES DeviceCapabilities
  1254. );
  1255. NTSTATUS
  1256. USBH_FdoStopDevice(
  1257. IN PDEVICE_EXTENSION_HUB DeviceExtensionHub,
  1258. IN PIRP Irp
  1259. );
  1260. NTSTATUS
  1261. USBH_FdoRemoveDevice(
  1262. IN PDEVICE_EXTENSION_HUB DeviceExtensionHub,
  1263. IN PIRP Irp
  1264. );
  1265. NTSTATUS
  1266. USBH_FdoQueryBusRelations(
  1267. IN PDEVICE_EXTENSION_HUB DeviceExtensionHub,
  1268. IN PIRP Irp
  1269. );
  1270. VOID
  1271. UsbhFdoCleanup(
  1272. IN PDEVICE_EXTENSION_HUB DeviceExtensionHub
  1273. );
  1274. NTSTATUS
  1275. USBH_ProcessDeviceInformation(
  1276. IN OUT PDEVICE_EXTENSION_PORT DeviceExtensionPort
  1277. );
  1278. NTSTATUS
  1279. USBH_PdoQueryId(
  1280. IN PDEVICE_EXTENSION_PORT DeviceExtensionPort,
  1281. IN PIRP Irp
  1282. );
  1283. NTSTATUS
  1284. USBH_PdoPnP(
  1285. IN PDEVICE_EXTENSION_PORT DeviceExtensionPort,
  1286. IN PIRP Irp,
  1287. IN UCHAR MinorFunction,
  1288. IN PBOOLEAN CompleteIrp
  1289. );
  1290. NTSTATUS
  1291. USBH_PdoRemoveDevice(
  1292. IN PDEVICE_EXTENSION_PORT DeviceExtensionPort,
  1293. IN PDEVICE_EXTENSION_HUB DeviceExtensionHub,
  1294. IN PIRP Irp
  1295. );
  1296. NTSTATUS
  1297. USBH_PdoQueryCapabilities(
  1298. IN PDEVICE_EXTENSION_PORT DeviceExtensionPort,
  1299. IN PIRP Irp
  1300. );
  1301. NTSTATUS
  1302. USBH_PdoSetPower(
  1303. IN PDEVICE_EXTENSION_PORT DeviceExtensionPort,
  1304. IN PIRP Irp
  1305. );
  1306. NTSTATUS
  1307. USBH_ParentFdoStopDevice(
  1308. IN PDEVICE_EXTENSION_PARENT DeviceExtensionParent,
  1309. IN PIRP Irp
  1310. );
  1311. NTSTATUS
  1312. USBH_ParentFdoRemoveDevice(
  1313. IN PDEVICE_EXTENSION_PARENT DeviceExtensionParent,
  1314. IN PIRP Irp
  1315. );
  1316. VOID
  1317. UsbhParentFdoCleanup(
  1318. IN PDEVICE_EXTENSION_PARENT DeviceExtensionParent
  1319. );
  1320. NTSTATUS
  1321. USBH_ParentQueryBusRelations(
  1322. IN PDEVICE_EXTENSION_PARENT DeviceExtensionParent,
  1323. IN PIRP Irp
  1324. );
  1325. NTSTATUS
  1326. USBH_FunctionPdoQueryId(
  1327. IN PDEVICE_EXTENSION_FUNCTION DeviceExtensionFunction,
  1328. IN PIRP Irp
  1329. );
  1330. NTSTATUS
  1331. USBH_FunctionPdoQueryDeviceText(
  1332. IN PDEVICE_EXTENSION_FUNCTION DeviceExtensionFunction,
  1333. IN PIRP Irp
  1334. );
  1335. NTSTATUS
  1336. USBH_FunctionPdoPnP(
  1337. IN PDEVICE_EXTENSION_FUNCTION DeviceExtensionFunction,
  1338. IN PIRP Irp,
  1339. IN UCHAR MinorFunction,
  1340. IN OUT PBOOLEAN IrpNeedsCompletion
  1341. );
  1342. NTSTATUS
  1343. USBH_IoctlGetNodeName(
  1344. IN PDEVICE_EXTENSION_HUB DeviceExtensionHub,
  1345. IN PIRP Irp
  1346. );
  1347. BOOLEAN
  1348. USBH_HubIsBusPowered(
  1349. IN PDEVICE_OBJECT DeviceObject,
  1350. IN PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor
  1351. );
  1352. NTSTATUS
  1353. USBH_SyncGetStatus(
  1354. IN PDEVICE_OBJECT HubFDO,
  1355. IN OUT PUSHORT StatusBits,
  1356. IN USHORT function,
  1357. IN USHORT Index
  1358. );
  1359. NTSTATUS
  1360. USBH_GetSerialNumberString(
  1361. IN PDEVICE_OBJECT DevicePDO,
  1362. IN OUT PWCHAR *SerialNumberBuffer,
  1363. IN OUT PUSHORT SerialNumberBufferLength,
  1364. IN LANGID LanguageId,
  1365. IN UCHAR StringIndex
  1366. );
  1367. NTSTATUS
  1368. USBH_SyncGetStringDescriptor(
  1369. IN PDEVICE_OBJECT DevicePDO,
  1370. IN UCHAR Index,
  1371. IN USHORT LangId,
  1372. IN OUT PUSB_STRING_DESCRIPTOR Buffer,
  1373. IN ULONG BufferLength,
  1374. IN PULONG BytesReturned,
  1375. IN BOOLEAN ExpectHeader
  1376. );
  1377. NTSTATUS
  1378. USBH_SyncFeatureRequest(
  1379. IN PDEVICE_OBJECT DeviceObject,
  1380. IN USHORT FeatureSelector,
  1381. IN USHORT Index,
  1382. IN USHORT Target,
  1383. IN BOOLEAN ClearFeature
  1384. );
  1385. NTSTATUS
  1386. USBH_PdoIoctlGetPortStatus(
  1387. IN PDEVICE_EXTENSION_PORT DeviceExtensionPort,
  1388. IN PIRP Irp
  1389. );
  1390. NTSTATUS
  1391. USBH_PdoIoctlEnablePort(
  1392. IN PDEVICE_EXTENSION_PORT DeviceExtensionPort,
  1393. IN PIRP Irp
  1394. );
  1395. NTSTATUS
  1396. USBH_FdoDeferPoRequestCompletion(
  1397. IN PDEVICE_OBJECT DeviceObject,
  1398. IN UCHAR MinorFunction,
  1399. IN POWER_STATE PowerState,
  1400. IN PVOID Context,
  1401. IN PIO_STATUS_BLOCK IoStatus
  1402. );
  1403. NTSTATUS
  1404. USBH_DeferIrpCompletion(
  1405. IN PDEVICE_OBJECT DeviceObject,
  1406. IN PIRP Irp,
  1407. IN PVOID Context
  1408. );
  1409. NTSTATUS
  1410. USBH_BuildFunctionConfigurationDescriptor(
  1411. IN PDEVICE_EXTENSION_FUNCTION DeviceExtensionFunction,
  1412. IN OUT PUCHAR Buffer,
  1413. IN ULONG BufferLength,
  1414. OUT PULONG BytesReturned
  1415. );
  1416. NTSTATUS
  1417. USBH_ResetHub(
  1418. IN PDEVICE_EXTENSION_HUB DeviceExtensionHub
  1419. );
  1420. NTSTATUS
  1421. USBH_ResetDevice(
  1422. IN OUT PDEVICE_EXTENSION_HUB DeviceExtensionHub,
  1423. IN USHORT PortNumber,
  1424. IN BOOLEAN KeepConfiguration,
  1425. IN ULONG RetryIteration
  1426. );
  1427. NTSTATUS
  1428. USBH_PdoIoctlResetPort(
  1429. IN PDEVICE_EXTENSION_PORT DeviceExtensionPort,
  1430. IN PIRP Irp
  1431. );
  1432. NTSTATUS
  1433. USBH_SetPowerD1orD2(
  1434. IN PIRP Irp,
  1435. IN PDEVICE_EXTENSION_PORT DeviceExtensionPort
  1436. );
  1437. NTSTATUS
  1438. USBH_SetPowerD0(
  1439. IN PIRP Irp,
  1440. IN PDEVICE_EXTENSION_PORT DeviceExtensionPort
  1441. );
  1442. NTSTATUS
  1443. USBH_SetPowerD3(
  1444. IN PIRP Irp,
  1445. IN PDEVICE_EXTENSION_PORT DeviceExtensionPort
  1446. );
  1447. NTSTATUS
  1448. USBH_PdoQueryDeviceText(
  1449. IN PDEVICE_EXTENSION_PORT DeviceExtensionPort,
  1450. IN PIRP Irp
  1451. );
  1452. NTSTATUS
  1453. USBH_CheckDeviceLanguage(
  1454. IN PDEVICE_OBJECT DevicePDO,
  1455. IN LANGID LanguageId
  1456. );
  1457. NTSTATUS
  1458. USBH_PdoPower(
  1459. IN PDEVICE_EXTENSION_PORT DeviceExtensionPort,
  1460. IN PIRP Irp,
  1461. IN UCHAR MinorFunction
  1462. );
  1463. NTSTATUS
  1464. USBH_SubmitInterruptTransfer(
  1465. IN PDEVICE_EXTENSION_HUB DeviceExtensionHub
  1466. );
  1467. NTSTATUS
  1468. USBH_SymbolicLink(
  1469. BOOLEAN CreateFlag,
  1470. PDEVICE_EXTENSION_PORT DeviceExtensionPort,
  1471. LPGUID lpGuid
  1472. );
  1473. NTSTATUS
  1474. USBH_SyncPowerOffPorts(
  1475. IN OUT PDEVICE_EXTENSION_HUB DeviceExtensionHub
  1476. );
  1477. NTSTATUS
  1478. USBH_RestoreDevice(
  1479. IN OUT PDEVICE_EXTENSION_PORT DeviceExtensionPort,
  1480. IN BOOLEAN KeepConfiguration
  1481. );
  1482. NTSTATUS
  1483. USBH_PnPIrp_Complete(
  1484. IN PDEVICE_OBJECT DeviceObject,
  1485. IN PIRP Irp,
  1486. IN PVOID Context
  1487. );
  1488. NTSTATUS
  1489. USBH_ParentCreateFunctionList(
  1490. IN PDEVICE_EXTENSION_PARENT DeviceExtensionParent,
  1491. IN PUSBD_INTERFACE_LIST_ENTRY InterfaceList,
  1492. IN PURB Urb
  1493. );
  1494. NTSTATUS
  1495. USBH_PdoStopDevice(
  1496. IN PDEVICE_EXTENSION_PORT DeviceExtensionPort,
  1497. IN PIRP Irp
  1498. );
  1499. NTSTATUS
  1500. USBH_ChangeIndicationProcessChange(
  1501. IN PDEVICE_OBJECT PNull,
  1502. IN PIRP Irp,
  1503. IN PVOID Context
  1504. );
  1505. NTSTATUS
  1506. USBH_ChangeIndicationAckChangeComplete(
  1507. IN PDEVICE_OBJECT PNull,
  1508. IN PIRP Irp,
  1509. IN PVOID Context
  1510. );
  1511. NTSTATUS
  1512. USBH_ChangeIndicationAckChange(
  1513. IN PDEVICE_EXTENSION_HUB DeviceExtensionHub,
  1514. IN PIRP Irp,
  1515. IN PURB Urb,
  1516. IN USHORT Port,
  1517. IN USHORT FeatureSelector
  1518. );
  1519. NTSTATUS
  1520. USBH_IoctlGetNodeConnectionDriverKeyName(
  1521. IN PDEVICE_EXTENSION_HUB DeviceExtensionHub,
  1522. IN PIRP Irp
  1523. );
  1524. NTSTATUS
  1525. USBH_FdoSubmitWaitWakeIrp(
  1526. IN PDEVICE_EXTENSION_HUB DeviceExtensionHub
  1527. );
  1528. NTSTATUS
  1529. USBH_ChangeIndicationQueryChange(
  1530. IN PDEVICE_EXTENSION_HUB DeviceExtensionHub,
  1531. IN PIRP Irp,
  1532. IN PURB Urb,
  1533. IN USHORT Port
  1534. );
  1535. NTSTATUS
  1536. USBH_InvalidatePortDeviceState(
  1537. IN PDEVICE_EXTENSION_HUB DeviceExtensionHub,
  1538. IN USB_CONNECTION_STATUS ConnectStatus,
  1539. IN USHORT PortNumber
  1540. );
  1541. NTSTATUS
  1542. USBH_PdoEvent(
  1543. IN PDEVICE_EXTENSION_HUB DeviceExtensionHub,
  1544. IN USHORT PortNumber
  1545. );
  1546. USB_CONNECTION_STATUS
  1547. UsbhGetConnectionStatus(
  1548. IN PDEVICE_EXTENSION_PORT DeviceExtensionPort
  1549. );
  1550. NTSTATUS
  1551. USBH_ParentSubmitWaitWakeIrp(
  1552. IN PDEVICE_EXTENSION_PARENT DeviceExtensionParent
  1553. );
  1554. NTSTATUS
  1555. USBH_WriteFailReason(
  1556. IN PDEVICE_OBJECT PhysicalDeviceObject,
  1557. IN ULONG FailReason
  1558. );
  1559. NTSTATUS
  1560. USBH_WriteRegistryKeyValue (
  1561. IN HANDLE Handle,
  1562. IN PWCHAR KeyNameString,
  1563. IN ULONG KeyNameStringLength,
  1564. IN ULONG Data
  1565. );
  1566. NTSTATUS
  1567. USBH_SystemControl (
  1568. IN PDEVICE_EXTENSION_FDO DeviceExtensionFdo,
  1569. IN PIRP Irp
  1570. );
  1571. NTSTATUS
  1572. USBH_PortSystemControl (
  1573. IN PDEVICE_EXTENSION_PORT DeviceExtensionPort,
  1574. IN PIRP Irp
  1575. );
  1576. NTSTATUS
  1577. USBH_ExecuteWmiMethod(
  1578. IN PDEVICE_OBJECT DeviceObject,
  1579. IN PIRP Irp,
  1580. IN ULONG GuidIndex,
  1581. IN ULONG InstanceIndex,
  1582. IN ULONG MethodId,
  1583. IN ULONG InBufferSize,
  1584. IN ULONG OutBufferSize,
  1585. IN OUT PUCHAR Buffer
  1586. );
  1587. NTSTATUS
  1588. USBH_QueryWmiRegInfo(
  1589. IN PDEVICE_OBJECT DeviceObject,
  1590. OUT PULONG RegFlags,
  1591. OUT PUNICODE_STRING InstanceName,
  1592. OUT PUNICODE_STRING *RegistryPath,
  1593. OUT PUNICODE_STRING MofResourceName,
  1594. OUT PDEVICE_OBJECT *Pdo
  1595. );
  1596. NTSTATUS
  1597. USBH_PortQueryWmiRegInfo(
  1598. IN PDEVICE_OBJECT DeviceObject,
  1599. OUT PULONG RegFlags,
  1600. OUT PUNICODE_STRING InstanceName,
  1601. OUT PUNICODE_STRING *RegistryPath,
  1602. OUT PUNICODE_STRING MofResourceName,
  1603. OUT PDEVICE_OBJECT *Pdo
  1604. );
  1605. NTSTATUS
  1606. USBH_FlushPortChange(
  1607. IN OUT PDEVICE_EXTENSION_HUB DeviceExtensionHub,
  1608. IN OUT PDEVICE_EXTENSION_PORT DeviceExtensionPort
  1609. );
  1610. NTSTATUS
  1611. USBH_PdoIoctlCyclePort(
  1612. IN PDEVICE_EXTENSION_PORT DeviceExtensionPort,
  1613. IN PIRP Irp
  1614. );
  1615. NTSTATUS
  1616. USBH_ResetPortOvercurrent(
  1617. IN PDEVICE_EXTENSION_HUB DeviceExtensionHub,
  1618. IN USHORT PortNumber,
  1619. IN PDEVICE_EXTENSION_PORT DeviceExtensionPort
  1620. );
  1621. NTSTATUS
  1622. USBH_SyncGetControllerInfo(
  1623. IN PDEVICE_OBJECT DeviceObject,
  1624. IN PVOID Buffer,
  1625. IN ULONG BufferLength,
  1626. IN ULONG Ioctl
  1627. );
  1628. NTSTATUS
  1629. USBH_SyncGetHubName(
  1630. IN PDEVICE_OBJECT DeviceObject,
  1631. IN PVOID Buffer,
  1632. IN ULONG BufferLength
  1633. );
  1634. NTSTATUS
  1635. USBH_IoctlHubSymbolicName(
  1636. IN PDEVICE_EXTENSION_PORT DeviceExtensionPort,
  1637. IN PIRP Irp
  1638. );
  1639. NTSTATUS
  1640. USBH_SetWmiDataBlock(
  1641. IN PDEVICE_OBJECT DeviceObject,
  1642. IN PIRP Irp,
  1643. IN ULONG GuidIndex,
  1644. IN ULONG InstanceIndex,
  1645. IN ULONG BufferSize,
  1646. IN PUCHAR Buffer
  1647. );
  1648. NTSTATUS
  1649. USBH_QueryWmiDataBlock(
  1650. IN PDEVICE_OBJECT DeviceObject,
  1651. IN PIRP Irp,
  1652. IN ULONG GuidIndex,
  1653. IN ULONG InstanceIndex,
  1654. IN ULONG InstanceCount,
  1655. IN OUT PULONG InstanceLengthArray,
  1656. IN ULONG OutBufferSize,
  1657. OUT PUCHAR Buffer
  1658. );
  1659. NTSTATUS
  1660. USBH_PortQueryWmiDataBlock(
  1661. IN PDEVICE_OBJECT DeviceObject,
  1662. IN PIRP Irp,
  1663. IN ULONG GuidIndex,
  1664. IN ULONG InstanceIndex,
  1665. IN ULONG InstanceCount,
  1666. IN OUT PULONG InstanceLengthArray,
  1667. IN ULONG OutBufferSize,
  1668. OUT PUCHAR Buffer
  1669. );
  1670. NTSTATUS
  1671. USBH_SetRegistryKeyValue (
  1672. IN HANDLE Handle,
  1673. IN PUNICODE_STRING KeyNameUnicodeString,
  1674. IN PVOID Data,
  1675. IN ULONG DataLength,
  1676. IN ULONG KeyType
  1677. );
  1678. NTSTATUS
  1679. USBH_SetPdoRegistryParameter (
  1680. IN PDEVICE_OBJECT PhysicalDeviceObject,
  1681. IN PWCHAR KeyName,
  1682. IN ULONG KeyNameLength,
  1683. IN PVOID Data,
  1684. IN ULONG DataLength,
  1685. IN ULONG KeyType,
  1686. IN ULONG DevInstKeyType
  1687. );
  1688. NTSTATUS
  1689. USBH_GetPdoRegistryParameter(
  1690. IN PDEVICE_OBJECT PhysicalDeviceObject,
  1691. IN PWCHAR ValueName,
  1692. OUT PVOID Data,
  1693. IN ULONG DataLength,
  1694. OUT PULONG Type,
  1695. OUT PULONG ActualDataLength
  1696. );
  1697. NTSTATUS
  1698. USBH_OsVendorCodeQueryRoutine(
  1699. IN PWSTR ValueName,
  1700. IN ULONG ValueType,
  1701. IN PVOID ValueData,
  1702. IN ULONG ValueLength,
  1703. IN PVOID Context,
  1704. IN PVOID EntryContext
  1705. );
  1706. VOID
  1707. USBH_GetMsOsVendorCode(
  1708. IN PDEVICE_OBJECT DeviceObject
  1709. );
  1710. NTSTATUS
  1711. USBH_GetMsOsFeatureDescriptor(
  1712. IN PDEVICE_OBJECT DeviceObject,
  1713. IN UCHAR Recipient,
  1714. IN UCHAR Interface,
  1715. IN USHORT Index,
  1716. IN OUT PVOID DataBuffer,
  1717. IN ULONG DataBufferLength,
  1718. OUT PULONG BytesReturned
  1719. );
  1720. VOID
  1721. USBH_InstallExtPropDesc (
  1722. IN PDEVICE_OBJECT DeviceObject
  1723. );
  1724. VOID
  1725. USBH_InstallExtPropDescSections (
  1726. PDEVICE_OBJECT DeviceObject,
  1727. PMS_EXT_PROP_DESC pMsExtPropDesc
  1728. );
  1729. PMS_EXT_CONFIG_DESC
  1730. USBH_GetExtConfigDesc (
  1731. IN PDEVICE_OBJECT DeviceObject
  1732. );
  1733. BOOLEAN
  1734. USBH_ValidateExtConfigDesc (
  1735. IN PMS_EXT_CONFIG_DESC MsExtConfigDesc,
  1736. IN PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor
  1737. );
  1738. NTSTATUS
  1739. USBH_CalculateInterfaceBandwidth(
  1740. IN PDEVICE_EXTENSION_PORT DeviceExtensionPort,
  1741. IN PUSBD_INTERFACE_INFORMATION Interface,
  1742. IN OUT PULONG Bandwidth // in kenr units?
  1743. );
  1744. NTSTATUS
  1745. USBH_RegQueryDeviceIgnoreHWSerNumFlag(
  1746. IN USHORT idVendor,
  1747. IN USHORT idProduct,
  1748. IN OUT PBOOLEAN IgnoreHWSerNumFlag
  1749. );
  1750. NTSTATUS
  1751. USBH_RegQueryGenericUSBDeviceString(
  1752. IN OUT PWCHAR *GenericUSBDeviceString
  1753. );
  1754. VOID
  1755. USBH_ParentCompleteFunctionWakeIrps(
  1756. IN PDEVICE_EXTENSION_PARENT DeviceExtensionParent,
  1757. IN NTSTATUS NtStatus
  1758. );
  1759. BOOLEAN
  1760. USBH_ValidateConfigurationDescriptor(
  1761. PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor,
  1762. USBD_STATUS *UsbdSatus
  1763. );
  1764. VOID
  1765. USBH_HubCompletePortWakeIrps(
  1766. IN PDEVICE_EXTENSION_HUB DeviceExtensionHub,
  1767. IN NTSTATUS NtStatus
  1768. );
  1769. VOID
  1770. USBH_HubCompletePortIdleIrps(
  1771. IN PDEVICE_EXTENSION_HUB DeviceExtensionHub,
  1772. IN NTSTATUS NtStatus
  1773. );
  1774. PUSB_DEVICE_HANDLE
  1775. USBH_SyncGetDeviceHandle(
  1776. IN PDEVICE_OBJECT DeviceObject
  1777. );
  1778. VOID
  1779. USBH_CompletePowerIrp(
  1780. IN PDEVICE_EXTENSION_HUB DeviceExtensionHub,
  1781. IN PIRP Irp,
  1782. IN NTSTATUS NtStatus
  1783. );
  1784. VOID
  1785. USBH_HubESDRecoveryWorker(
  1786. IN PVOID Context);
  1787. NTSTATUS
  1788. USBH_ScheduleESDRecovery(
  1789. IN PDEVICE_EXTENSION_HUB DeviceExtensionHub
  1790. );
  1791. // these are for the USB2 'backport'
  1792. PWCHAR
  1793. USBH_BuildHubHardwareIDs(
  1794. IN USHORT IdVendor,
  1795. IN USHORT IdProduct,
  1796. IN USHORT BcdDevice,
  1797. IN LONG MiId
  1798. );
  1799. PWCHAR
  1800. USBH_BuildHubCompatibleIDs(
  1801. IN UCHAR Class,
  1802. IN UCHAR SubClass,
  1803. IN UCHAR Protocol,
  1804. IN BOOLEAN DeviceClass,
  1805. IN BOOLEAN DeviceIsHighSpeed
  1806. );
  1807. NTSTATUS
  1808. USBH_IoctlCycleHubPort(
  1809. IN PDEVICE_EXTENSION_HUB DeviceExtensionHub,
  1810. IN PIRP Irp
  1811. );
  1812. VOID
  1813. USBH_InternalCyclePort(
  1814. IN PDEVICE_EXTENSION_HUB DeviceExtensionHub,
  1815. IN USHORT PortNumber,
  1816. IN PDEVICE_EXTENSION_PORT DeviceExtensionPort
  1817. );
  1818. PWCHAR
  1819. USBH_BuildHubDeviceID(
  1820. IN USHORT IdVendor,
  1821. IN USHORT IdProduct,
  1822. IN LONG MiId
  1823. );
  1824. NTSTATUS
  1825. USBHUB_GetBusInfo(
  1826. IN PDEVICE_EXTENSION_HUB DeviceExtensionHub,
  1827. IN PUSB_BUS_NOTIFICATION BusInfo,
  1828. IN PVOID BusContext
  1829. );
  1830. NTSTATUS
  1831. USBHUB_GetBusInfoDevice(
  1832. IN PDEVICE_EXTENSION_HUB DeviceExtensionHub,
  1833. IN PDEVICE_EXTENSION_PORT DeviceExtensionPort,
  1834. IN PUSB_BUS_NOTIFICATION BusInfo
  1835. );
  1836. NTSTATUS
  1837. USBHUB_GetBusInterfaceUSBDI(
  1838. IN PDEVICE_OBJECT HubPdo,
  1839. IN PUSB_BUS_INTERFACE_USBDI_V2 BusInterface
  1840. );
  1841. USB_DEVICE_TYPE
  1842. USBH_GetDeviceType(
  1843. IN PDEVICE_EXTENSION_HUB DeviceExtensionHub,
  1844. IN PUSB_DEVICE_HANDLE DeviceData
  1845. );
  1846. VOID
  1847. USBH_CompletePortIdleNotification(
  1848. IN PDEVICE_EXTENSION_PORT DeviceExtensionPort
  1849. );
  1850. VOID
  1851. USBH_PortIdleNotificationCancelRoutine(
  1852. IN PDEVICE_OBJECT DeviceObject,
  1853. IN PIRP Irp
  1854. );
  1855. NTSTATUS
  1856. USBH_FdoSubmitIdleRequestIrp(
  1857. IN PDEVICE_EXTENSION_HUB DeviceExtensionHub
  1858. );
  1859. NTSTATUS
  1860. USBH_HubSetD0(
  1861. IN PDEVICE_EXTENSION_HUB DeviceExtensionHub
  1862. );
  1863. NTSTATUS
  1864. USBHUB_GetControllerName(
  1865. IN PDEVICE_EXTENSION_HUB DeviceExtensionHub,
  1866. IN PUSB_HUB_NAME Buffer,
  1867. IN ULONG BufferLength
  1868. );
  1869. NTSTATUS
  1870. USBHUB_GetExtendedHubInfo(
  1871. IN PDEVICE_EXTENSION_HUB DeviceExtensionHub,
  1872. IN PUSB_EXTHUB_INFORMATION_0 ExtendedHubInfo
  1873. );
  1874. BOOLEAN
  1875. USBH_DoesHubNeedWaitWake(
  1876. IN PDEVICE_EXTENSION_HUB DeviceExtensionHub
  1877. );
  1878. VOID
  1879. USBH_CheckHubIdle(
  1880. IN PDEVICE_EXTENSION_HUB DeviceExtensionHub
  1881. );
  1882. NTSTATUS
  1883. USBH_PdoSetContentId(
  1884. IN PIRP irp,
  1885. IN PVOID pKsProperty,
  1886. IN PVOID pvData
  1887. );
  1888. BOOLEAN
  1889. USBH_CheckDeviceIDUnique(
  1890. IN PDEVICE_EXTENSION_HUB DeviceExtensionHub,
  1891. IN USHORT IDVendor,
  1892. IN USHORT IDProduct,
  1893. IN PWCHAR SerialNumberBuffer,
  1894. IN USHORT SerialNumberBufferLength
  1895. );
  1896. VOID
  1897. USBH_IdleCompletePowerHubWorker(
  1898. IN PVOID Context
  1899. );
  1900. BOOLEAN
  1901. USBH_DeviceIs2xDualMode(
  1902. IN PDEVICE_EXTENSION_PORT DeviceExtensionPort
  1903. );
  1904. PDEVICE_EXTENSION_HUB
  1905. USBH_GetRootHubDevExt(
  1906. IN PDEVICE_EXTENSION_HUB DeviceExtensionHub
  1907. );
  1908. VOID
  1909. USBH_CheckLeafHubsIdle(
  1910. IN PDEVICE_EXTENSION_HUB DeviceExtensionHub
  1911. );
  1912. VOID
  1913. USBH_HubCancelWakeIrp(
  1914. IN PDEVICE_EXTENSION_HUB DeviceExtensionHub,
  1915. IN PIRP Irp
  1916. );
  1917. VOID
  1918. USBH_HubCancelIdleIrp(
  1919. IN PDEVICE_EXTENSION_HUB DeviceExtensionHub,
  1920. IN PIRP Irp
  1921. );
  1922. NTSTATUS
  1923. USBH_IoctlGetNodeConnectionAttributes(
  1924. IN PDEVICE_EXTENSION_HUB DeviceExtensionHub,
  1925. IN PIRP Irp
  1926. );
  1927. VOID
  1928. USBH_CompletePortIdleIrpsWorker(
  1929. IN PVOID Context);
  1930. VOID
  1931. USBH_CompletePortWakeIrpsWorker(
  1932. IN PVOID Context);
  1933. VOID
  1934. USBH_HubAsyncPowerWorker(
  1935. IN PVOID Context);
  1936. VOID
  1937. USBH_IdleCancelPowerHubWorker(
  1938. IN PVOID Context);
  1939. NTSTATUS
  1940. USBD_InitUsb2Hub(
  1941. IN PDEVICE_EXTENSION_HUB DeviceExtensionHub
  1942. );
  1943. VOID
  1944. USBH_PdoSetCapabilities(
  1945. IN PDEVICE_EXTENSION_PORT DeviceExtensionPort
  1946. );
  1947. NTSTATUS
  1948. USBH_HubPnPIrp_Complete(
  1949. IN PDEVICE_OBJECT DeviceObject,
  1950. IN PIRP Irp,
  1951. IN PVOID Context
  1952. );
  1953. NTSTATUS
  1954. USBH_RegQueryUSBGlobalSelectiveSuspend(
  1955. IN OUT PBOOLEAN DisableSelectiveSuspend
  1956. );
  1957. VOID
  1958. USBH_SyncRefreshPortAttributes(
  1959. IN PDEVICE_EXTENSION_HUB DeviceExtensionHub
  1960. );
  1961. NTSTATUS
  1962. USBD_RegisterRhHubCallBack(
  1963. IN PDEVICE_EXTENSION_HUB DeviceExtensionHub
  1964. );
  1965. NTSTATUS
  1966. USBD_UnRegisterRhHubCallBack(
  1967. IN PDEVICE_EXTENSION_HUB DeviceExtensionHub
  1968. );
  1969. NTSTATUS
  1970. USBH_PdoStartDevice(
  1971. IN PDEVICE_EXTENSION_PORT DeviceExtensionPort,
  1972. IN PIRP Irp
  1973. );
  1974. VOID
  1975. USBHUB_SetDeviceHandleData(
  1976. PDEVICE_EXTENSION_HUB DeviceExtensionHub,
  1977. PDEVICE_OBJECT PdoDeviceObject,
  1978. PVOID DeviceData
  1979. );
  1980. #define PDO_EXT(p) PdoExt((p))
  1981. PDEVICE_EXTENSION_PORT
  1982. PdoExt(
  1983. PDEVICE_OBJECT DeviceObject
  1984. );
  1985. #ifdef TEST_MS_DESC
  1986. #pragma message ("Warning! Compiling in non-retail test code!")
  1987. NTSTATUS
  1988. USBH_SyncGetMsOsDescriptor(
  1989. IN PDEVICE_OBJECT DeviceObject,
  1990. IN USHORT Index,
  1991. IN OUT PUCHAR DataBuffer,
  1992. IN ULONG DataBufferLength,
  1993. OUT PULONG BytesReturned);
  1994. NTSTATUS
  1995. USBH_TestGetMsOsDescriptor(
  1996. IN PDEVICE_OBJECT DeviceObject,
  1997. IN USHORT Index
  1998. );
  1999. #endif
  2000. #define LOG_PNP 0x00000001
  2001. #if DBG
  2002. NTSTATUS
  2003. USBH_GetClassGlobalDebugRegistryParameters(
  2004. );
  2005. VOID
  2006. UsbhInfo(
  2007. PDEVICE_EXTENSION_HUB DeviceExtensionHub
  2008. );
  2009. VOID
  2010. USBH_ShowPortState(
  2011. IN USHORT PortNumber,
  2012. IN PPORT_STATE PortState
  2013. );
  2014. #define DEBUG_LOG
  2015. #define USBH_ASSERT(exp) \
  2016. if (!(exp)) { \
  2017. USBH_Assert( #exp, __FILE__, __LINE__, NULL );\
  2018. }
  2019. VOID
  2020. USBH_Assert(
  2021. IN PVOID FailedAssertion,
  2022. IN PVOID FileName,
  2023. IN ULONG LineNumber,
  2024. IN PCHAR Message
  2025. );
  2026. #else
  2027. #define USBH_ASSERT(exp)
  2028. #define UsbhInfo(de)
  2029. #endif
  2030. #ifdef DEBUG_LOG
  2031. VOID
  2032. USBH_LogInit(
  2033. );
  2034. VOID
  2035. USBH_LogFree(
  2036. );
  2037. #define LOGENTRY(mask, sig, info1, info2, info3) \
  2038. USBH_Debug_LogEntry(mask, sig, \
  2039. (ULONG_PTR)info1, \
  2040. (ULONG_PTR)info2, \
  2041. (ULONG_PTR)info3)
  2042. VOID
  2043. USBH_Debug_LogEntry(
  2044. IN ULONG Mask,
  2045. IN CHAR *Name,
  2046. IN ULONG_PTR Info1,
  2047. IN ULONG_PTR Info2,
  2048. IN ULONG_PTR Info3
  2049. );
  2050. #else
  2051. #define LOGENTRY(mask, sig, info1, info2, info3)
  2052. #define USBH_LogInit()
  2053. #define USBH_LogFree()
  2054. #endif
  2055. // last workitem will let the shutdown code continue
  2056. // !! do not reference the devicExtension beyond this point
  2057. // if event is signaled
  2058. #define USBH_DEC_PENDING_IO_COUNT(de) \
  2059. LOGENTRY(LOG_PNP, "PEN-", de, &de->PendingRequestEvent, de->PendingRequestCount); \
  2060. if (InterlockedDecrement(&de->PendingRequestCount) == 0) {\
  2061. USBH_ASSERT(de->HubFlags & HUBFLAG_DEVICE_STOPPING); \
  2062. LOGENTRY(LOG_PNP, "hWAK", de, &de->PendingRequestEvent, de->PendingRequestCount); \
  2063. KeSetEvent(&de->PendingRequestEvent, 1, FALSE); \
  2064. }
  2065. #define USBH_INC_PENDING_IO_COUNT(de) \
  2066. {\
  2067. LOGENTRY(LOG_PNP, "PEN+", de, &de->PendingRequestEvent, de->PendingRequestCount); \
  2068. InterlockedIncrement(&de->PendingRequestCount);\
  2069. }