Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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