ReactOS 0.4.15-dev-7918-g2a2556c
usbhub.h File Reference
#include <ntddk.h>
#include <windef.h>
#include <stdio.h>
#include <wmistr.h>
#include <wmilib.h>
#include <wdmguid.h>
#include <ntstrsafe.h>
#include <usb.h>
#include <usbioctl.h>
#include <hubbusif.h>
#include <usbbusif.h>
#include <usbdlib.h>
#include <ks.h>
#include <drivers/usbport/usbmport.h>
Include dependency graph for usbhub.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _USBHUB_PORT_DATA
 
struct  _USBHUB_IO_WORK_ITEM
 
struct  _COMMON_DEVICE_EXTENSION
 
struct  _USBHUB_FDO_EXTENSION
 
struct  _USBHUB_PORT_PDO_EXTENSION
 
struct  _USBHUB_URB_TIMEOUT_CONTEXT
 
struct  _USBHUB_STATUS_CHANGE_CONTEXT
 
struct  _USBHUB_IDLE_HUB_CONTEXT
 
struct  _USBHUB_IDLE_PORT_CONTEXT
 
struct  _USBHUB_IDLE_PORT_CANCEL_CONTEXT
 
struct  _USBHUB_RESET_PORT_CONTEXT
 

Macros

#define USB_HUB_TAG   'BUHU'
 
#define USBH_EXTENSION_TYPE_HUB   0x01
 
#define USBH_EXTENSION_TYPE_PORT   0x02
 
#define USBH_EXTENSION_TYPE_PARENT   0x04
 
#define USBH_EXTENSION_TYPE_FUNCTION   0x08
 
#define USBHUB_FDO_FLAG_DEVICE_STARTED   (1 << 0)
 
#define USBHUB_FDO_FLAG_DEVICE_STOPPING   (1 << 2)
 
#define USBHUB_FDO_FLAG_DEVICE_FAILED   (1 << 3)
 
#define USBHUB_FDO_FLAG_REMOTE_WAKEUP   (1 << 4)
 
#define USBHUB_FDO_FLAG_DEVICE_STOPPED   (1 << 5)
 
#define USBHUB_FDO_FLAG_HUB_BUSY   (1 << 6)
 
#define USBHUB_FDO_FLAG_PENDING_WAKE_IRP   (1 << 7)
 
#define USBHUB_FDO_FLAG_RESET_PORT_LOCK   (1 << 8)
 
#define USBHUB_FDO_FLAG_ESD_RECOVERING   (1 << 9)
 
#define USBHUB_FDO_FLAG_SET_D0_STATE   (1 << 10)
 
#define USBHUB_FDO_FLAG_NOT_D0_STATE   (1 << 11)
 
#define USBHUB_FDO_FLAG_WAIT_IDLE_REQUEST   (1 << 12)
 
#define USBHUB_FDO_FLAG_STATE_CHANGING   (1 << 13)
 
#define USBHUB_FDO_FLAG_DEVICE_REMOVED   (1 << 14)
 
#define USBHUB_FDO_FLAG_USB20_HUB   (1 << 15)
 
#define USBHUB_FDO_FLAG_DEFER_CHECK_IDLE   (1 << 16)
 
#define USBHUB_FDO_FLAG_WAKEUP_START   (1 << 17)
 
#define USBHUB_FDO_FLAG_MULTIPLE_TTS   (1 << 18)
 
#define USBHUB_FDO_FLAG_ENUM_POST_RECOVER   (1 << 19)
 
#define USBHUB_FDO_FLAG_DO_ENUMERATION   (1 << 20)
 
#define USBHUB_FDO_FLAG_CHECK_IDLE_LOCK   (1 << 21)
 
#define USBHUB_FDO_FLAG_HIBERNATE_STATE   (1 << 22)
 
#define USBHUB_FDO_FLAG_NOT_ENUMERATED   (1 << 23)
 
#define USBHUB_FDO_FLAG_DO_SUSPENSE   (1 << 24)
 
#define USBHUB_FDO_FLAG_GOING_IDLE   (1 << 25)
 
#define USBHUB_FDO_FLAG_DEVICE_SUSPENDED   (1 << 26)
 
#define USBHUB_FDO_FLAG_WITEM_INIT   (1 << 27)
 
#define USBHUB_PDO_FLAG_HUB_DEVICE   (1 << 0)
 
#define USBHUB_PDO_FLAG_MULTI_INTERFACE   (1 << 1)
 
#define USBHUB_PDO_FLAG_INIT_PORT_FAILED   (1 << 2)
 
#define USBHUB_PDO_FLAG_PORT_LOW_SPEED   (1 << 3)
 
#define USBHUB_PDO_FLAG_REMOTE_WAKEUP   (1 << 4)
 
#define USBHUB_PDO_FLAG_WAIT_WAKE   (1 << 5)
 
#define USBHUB_PDO_FLAG_NOT_CONNECTED   (1 << 6)
 
#define USBHUB_PDO_FLAG_DELETE_PENDING   (1 << 7)
 
#define USBHUB_PDO_FLAG_POWER_D3   (1 << 8)
 
#define USBHUB_PDO_FLAG_DEVICE_STARTED   (1 << 9)
 
#define USBHUB_PDO_FLAG_HS_USB1_DUALMODE   (1 << 10)
 
#define USBHUB_PDO_FLAG_REG_DEV_INTERFACE   (1 << 11)
 
#define USBHUB_PDO_FLAG_PORT_RESTORE_FAIL   (1 << 12)
 
#define USBHUB_PDO_FLAG_POWER_D1_OR_D2   (1 << 13)
 
#define USBHUB_PDO_FLAG_OVERCURRENT_PORT   (1 << 14)
 
#define USBHUB_PDO_FLAG_REMOVING_PORT_PDO   (1 << 15)
 
#define USBHUB_PDO_FLAG_INSUFFICIENT_PWR   (1 << 16)
 
#define USBHUB_PDO_FLAG_ALLOC_BNDW_FAILED   (1 << 18)
 
#define USBHUB_PDO_FLAG_PORT_RESSETING   (1 << 19)
 
#define USBHUB_PDO_FLAG_IDLE_NOTIFICATION   (1 << 22)
 
#define USBHUB_PDO_FLAG_PORT_HIGH_SPEED   (1 << 23)
 
#define USBHUB_PDO_FLAG_ENUMERATED   (1 << 26)
 
#define USBHUB_ENUM_FLAG_DEVICE_PRESENT   0x01
 
#define USBHUB_ENUM_FLAG_GHOST_DEVICE   0x02
 
#define USBHUB_FEATURE_C_HUB_LOCAL_POWER   0
 
#define USBHUB_FEATURE_C_HUB_OVER_CURRENT   1
 
#define USBHUB_FEATURE_PORT_CONNECTION   0
 
#define USBHUB_FEATURE_PORT_ENABLE   1
 
#define USBHUB_FEATURE_PORT_SUSPEND   2
 
#define USBHUB_FEATURE_PORT_OVER_CURRENT   3
 
#define USBHUB_FEATURE_PORT_RESET   4
 
#define USBHUB_FEATURE_PORT_POWER   8
 
#define USBHUB_FEATURE_PORT_LOW_SPEED   9
 
#define USBHUB_FEATURE_C_PORT_CONNECTION   16
 
#define USBHUB_FEATURE_C_PORT_ENABLE   17
 
#define USBHUB_FEATURE_C_PORT_SUSPEND   18
 
#define USBHUB_FEATURE_C_PORT_OVER_CURRENT   19
 
#define USBHUB_FEATURE_C_PORT_RESET   20
 
#define USBHUB_FEATURE_PORT_TEST   21
 
#define USBHUB_FEATURE_PORT_INDICATOR   22
 
#define USBHUB_MAX_CASCADE_LEVELS   6
 
#define USBHUB_RESET_PORT_MAX_RETRY   3
 
#define USBHUB_MAX_REQUEST_ERRORS   3
 
#define USBHUB_FAIL_NO_FAIL   5
 
#define USBHUB_FAIL_NESTED_TOO_DEEPLY   6
 
#define USBHUB_FAIL_OVERCURRENT   7
 

Typedefs

typedef struct _USBHUB_PORT_DATA USBHUB_PORT_DATA
 
typedef struct _USBHUB_PORT_DATAPUSBHUB_PORT_DATA
 
typedef struct _USBHUB_FDO_EXTENSIONPUSBHUB_FDO_EXTENSION
 
typedef VOID(NTAPIPUSBHUB_WORKER_ROUTINE) (IN PUSBHUB_FDO_EXTENSION HubExtension, IN PVOID Context)
 
typedef struct _USBHUB_IO_WORK_ITEM USBHUB_IO_WORK_ITEM
 
typedef struct _USBHUB_IO_WORK_ITEMPUSBHUB_IO_WORK_ITEM
 
typedef struct _COMMON_DEVICE_EXTENSION COMMON_DEVICE_EXTENSION
 
typedef struct _COMMON_DEVICE_EXTENSIONPCOMMON_DEVICE_EXTENSION
 
typedef struct _USBHUB_FDO_EXTENSION USBHUB_FDO_EXTENSION
 
typedef struct _USBHUB_PORT_PDO_EXTENSION USBHUB_PORT_PDO_EXTENSION
 
typedef struct _USBHUB_PORT_PDO_EXTENSIONPUSBHUB_PORT_PDO_EXTENSION
 
typedef struct _USBHUB_URB_TIMEOUT_CONTEXT USBHUB_URB_TIMEOUT_CONTEXT
 
typedef struct _USBHUB_URB_TIMEOUT_CONTEXTPUSBHUB_URB_TIMEOUT_CONTEXT
 
typedef struct _USBHUB_STATUS_CHANGE_CONTEXT USBHUB_STATUS_CHANGE_CONTEXT
 
typedef struct _USBHUB_STATUS_CHANGE_CONTEXTPUSBHUB_STATUS_CHANGE_CONTEXT
 
typedef struct _USBHUB_IDLE_HUB_CONTEXT USBHUB_IDLE_HUB_CONTEXT
 
typedef struct _USBHUB_IDLE_HUB_CONTEXTPUSBHUB_IDLE_HUB_CONTEXT
 
typedef struct _USBHUB_IDLE_PORT_CONTEXT USBHUB_IDLE_PORT_CONTEXT
 
typedef struct _USBHUB_IDLE_PORT_CONTEXTPUSBHUB_IDLE_PORT_CONTEXT
 
typedef struct _USBHUB_IDLE_PORT_CANCEL_CONTEXT USBHUB_IDLE_PORT_CANCEL_CONTEXT
 
typedef struct _USBHUB_IDLE_PORT_CANCEL_CONTEXTPUSBHUB_IDLE_PORT_CANCEL_CONTEXT
 
typedef struct _USBHUB_RESET_PORT_CONTEXT USBHUB_RESET_PORT_CONTEXT
 
typedef struct _USBHUB_RESET_PORT_CONTEXTPUSBHUB_RESET_PORT_CONTEXT
 

Functions

VOID NTAPI USBHUB_DumpingDeviceDescriptor (IN PUSB_DEVICE_DESCRIPTOR DeviceDescriptor)
 
VOID NTAPI USBHUB_DumpingConfiguration (IN PUSB_CONFIGURATION_DESCRIPTOR ConfigDescriptor)
 
VOID NTAPI USBHUB_DumpingIDs (IN PVOID Id)
 
NTSTATUS NTAPI USBH_DeviceControl (IN PUSBHUB_FDO_EXTENSION HubExtension, IN PIRP Irp)
 
NTSTATUS NTAPI USBH_PdoInternalControl (IN PUSBHUB_PORT_PDO_EXTENSION PortExtension, IN PIRP Irp)
 
NTSTATUS NTAPI USBH_PdoRemoveDevice (IN PUSBHUB_PORT_PDO_EXTENSION PortExtension, IN PUSBHUB_FDO_EXTENSION HubExtension)
 
NTSTATUS NTAPI USBH_FdoPnP (IN PUSBHUB_FDO_EXTENSION HubExtension, IN PIRP Irp, IN UCHAR Minor)
 
NTSTATUS NTAPI USBH_PdoPnP (IN PUSBHUB_PORT_PDO_EXTENSION PortExtension, IN PIRP Irp, IN UCHAR Minor, OUT BOOLEAN *IsCompleteIrp)
 
VOID NTAPI USBH_CompletePowerIrp (IN PUSBHUB_FDO_EXTENSION HubExtension, IN PIRP Irp, IN NTSTATUS NtStatus)
 
NTSTATUS NTAPI USBH_HubSetD0 (IN PUSBHUB_FDO_EXTENSION HubExtension)
 
NTSTATUS NTAPI USBH_FdoPower (IN PUSBHUB_FDO_EXTENSION HubExtension, IN PIRP Irp, IN UCHAR Minor)
 
NTSTATUS NTAPI USBH_PdoPower (IN PUSBHUB_PORT_PDO_EXTENSION PortExtension, IN PIRP Irp, IN UCHAR Minor)
 
VOID NTAPI USBH_HubCompletePortWakeIrps (IN PUSBHUB_FDO_EXTENSION HubExtension, IN NTSTATUS NtStatus)
 
VOID NTAPI USBH_HubCancelWakeIrp (IN PUSBHUB_FDO_EXTENSION HubExtension, IN PIRP Irp)
 
VOID NTAPI USBH_IdleCancelPowerHubWorker (IN PUSBHUB_FDO_EXTENSION HubExtension, IN PVOID Context)
 
NTSTATUS NTAPI USBH_Wait (IN ULONG Milliseconds)
 
VOID NTAPI USBH_CompleteIrp (IN PIRP Irp, IN NTSTATUS CompleteStatus)
 
NTSTATUS NTAPI USBH_PassIrp (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
PUSBHUB_PORT_PDO_EXTENSION NTAPI PdoExt (IN PDEVICE_OBJECT DeviceObject)
 
NTSTATUS NTAPI USBH_WriteFailReasonID (IN PDEVICE_OBJECT DeviceObject, IN ULONG Data)
 
NTSTATUS NTAPI USBH_SetPdoRegistryParameter (IN PDEVICE_OBJECT DeviceObject, IN PCWSTR SourceString, IN PVOID Data, IN ULONG DataSize, IN ULONG Type, IN ULONG DevInstKeyType)
 
NTSTATUS NTAPI USBH_SyncSubmitUrb (IN PDEVICE_OBJECT DeviceObject, IN PURB Urb)
 
NTSTATUS NTAPI USBH_FdoSyncSubmitUrb (IN PDEVICE_OBJECT FdoDevice, IN PURB Urb)
 
NTSTATUS NTAPI USBH_SyncResetPort (IN PUSBHUB_FDO_EXTENSION HubExtension, IN USHORT Port)
 
NTSTATUS NTAPI USBH_GetDeviceType (IN PUSBHUB_FDO_EXTENSION HubExtension, IN PUSB_DEVICE_HANDLE DeviceHandle, OUT USB_DEVICE_TYPE *OutDeviceType)
 
PUSBHUB_FDO_EXTENSION NTAPI USBH_GetRootHubExtension (IN PUSBHUB_FDO_EXTENSION HubExtension)
 
NTSTATUS NTAPI USBH_SyncGetRootHubPdo (IN PDEVICE_OBJECT DeviceObject, IN OUT PDEVICE_OBJECT *OutPdo1, IN OUT PDEVICE_OBJECT *OutPdo2)
 
NTSTATUS NTAPI USBH_SyncGetHubCount (IN PDEVICE_OBJECT DeviceObject, IN OUT PULONG OutHubCount)
 
PUSB_DEVICE_HANDLE NTAPI USBH_SyncGetDeviceHandle (IN PDEVICE_OBJECT DeviceObject)
 
NTSTATUS NTAPI USBH_GetDeviceDescriptor (IN PDEVICE_OBJECT DeviceObject, IN PUSB_DEVICE_DESCRIPTOR HubDeviceDescriptor)
 
NTSTATUS NTAPI USBH_GetConfigurationDescriptor (IN PDEVICE_OBJECT DeviceObject, IN PUSB_CONFIGURATION_DESCRIPTOR *pConfigurationDescriptor)
 
NTSTATUS NTAPI USBH_SyncGetHubDescriptor (IN PUSBHUB_FDO_EXTENSION HubExtension)
 
NTSTATUS NTAPI USBH_SyncGetStringDescriptor (IN PDEVICE_OBJECT DeviceObject, IN UCHAR Index, IN USHORT LanguageId, IN PUSB_STRING_DESCRIPTOR Descriptor, IN ULONG NumberOfBytes, IN PULONG OutLength, IN BOOLEAN IsValidateLength)
 
NTSTATUS NTAPI USBH_SyncGetPortStatus (IN PUSBHUB_FDO_EXTENSION HubExtension, IN USHORT Port, IN PUSB_PORT_STATUS_AND_CHANGE PortStatus, IN ULONG Length)
 
NTSTATUS NTAPI USBH_SyncClearPortStatus (IN PUSBHUB_FDO_EXTENSION HubExtension, IN USHORT Port, IN USHORT RequestValue)
 
NTSTATUS NTAPI USBH_SyncPowerOnPorts (IN PUSBHUB_FDO_EXTENSION HubExtension)
 
NTSTATUS NTAPI USBH_SyncDisablePort (IN PUSBHUB_FDO_EXTENSION HubExtension, IN USHORT Port)
 
BOOLEAN NTAPI USBH_HubIsBusPowered (IN PDEVICE_OBJECT DeviceObject, IN PUSB_CONFIGURATION_DESCRIPTOR HubConfigDescriptor)
 
NTSTATUS NTAPI USBH_SubmitStatusChangeTransfer (IN PUSBHUB_FDO_EXTENSION HubExtension)
 
NTSTATUS NTAPI USBD_CreateDeviceEx (IN PUSBHUB_FDO_EXTENSION HubExtension, IN PUSB_DEVICE_HANDLE *OutDeviceHandle, IN USB_PORT_STATUS UsbPortStatus, IN USHORT Port)
 
NTSTATUS NTAPI USBD_RemoveDeviceEx (IN PUSBHUB_FDO_EXTENSION HubExtension, IN PUSB_DEVICE_HANDLE DeviceHandle, IN ULONG Flags)
 
NTSTATUS NTAPI USBD_InitializeDeviceEx (IN PUSBHUB_FDO_EXTENSION HubExtension, IN PUSB_DEVICE_HANDLE DeviceHandle, IN PUCHAR DeviceDescriptorBuffer, IN ULONG DeviceDescriptorBufferLength, IN PUCHAR ConfigDescriptorBuffer, IN ULONG ConfigDescriptorBufferLength)
 
VOID NTAPI USBHUB_SetDeviceHandleData (IN PUSBHUB_FDO_EXTENSION HubExtension, IN PDEVICE_OBJECT UsbDevicePdo, IN PVOID DeviceHandle)
 
VOID NTAPI USBHUB_FlushAllTransfers (IN PUSBHUB_FDO_EXTENSION HubExtension)
 
NTSTATUS NTAPI USBD_GetDeviceInformationEx (IN PUSBHUB_PORT_PDO_EXTENSION PortExtension, IN PUSBHUB_FDO_EXTENSION HubExtension, IN PUSB_NODE_CONNECTION_INFORMATION_EX Info, IN ULONG Length, IN PUSB_DEVICE_HANDLE DeviceHandle)
 
NTSTATUS NTAPI USBD_RestoreDeviceEx (IN PUSBHUB_FDO_EXTENSION HubExtension, IN OUT PUSB_DEVICE_HANDLE OldDeviceHandle, IN OUT PUSB_DEVICE_HANDLE NewDeviceHandle)
 
NTSTATUS NTAPI USBH_AllocateWorkItem (IN PUSBHUB_FDO_EXTENSION HubExtension, OUT PUSBHUB_IO_WORK_ITEM *OutHubIoWorkItem, IN PUSBHUB_WORKER_ROUTINE WorkerRoutine, IN SIZE_T BufferLength, OUT PVOID *OutHubWorkItemBuffer, IN WORK_QUEUE_TYPE Type)
 
VOID NTAPI USBH_QueueWorkItem (IN PUSBHUB_FDO_EXTENSION HubExtension, IN PUSBHUB_IO_WORK_ITEM HubIoWorkItem)
 
VOID NTAPI USBH_FreeWorkItem (IN PUSBHUB_IO_WORK_ITEM HubIoWorkItem)
 
NTSTATUS NTAPI USBD_RegisterRootHubCallBack (IN PUSBHUB_FDO_EXTENSION HubExtension)
 
NTSTATUS NTAPI USBD_UnRegisterRootHubCallBack (IN PUSBHUB_FDO_EXTENSION HubExtension)
 
VOID NTAPI USBH_HubCancelIdleIrp (IN PUSBHUB_FDO_EXTENSION HubExtension, IN PIRP IdleIrp)
 
BOOLEAN NTAPI USBH_CheckIdleAbort (IN PUSBHUB_FDO_EXTENSION HubExtension, IN BOOLEAN IsWait, IN BOOLEAN IsExtCheck)
 
VOID NTAPI USBH_CheckHubIdle (IN PUSBHUB_FDO_EXTENSION HubExtension)
 
VOID NTAPI USBH_CheckIdleDeferred (IN PUSBHUB_FDO_EXTENSION HubExtension)
 
NTSTATUS NTAPI USBH_CheckDeviceLanguage (IN PDEVICE_OBJECT DeviceObject, IN USHORT LanguageId)
 
NTSTATUS NTAPI USBH_CreateDevice (IN PUSBHUB_FDO_EXTENSION HubExtension, IN USHORT Port, IN USB_PORT_STATUS UsbPortStatus, IN ULONG IsWait)
 
NTSTATUS NTAPI USBH_ResetDevice (IN PUSBHUB_FDO_EXTENSION HubExtension, IN USHORT Port, IN BOOLEAN IsKeepDeviceData, IN BOOLEAN IsWait)
 
NTSTATUS NTAPI DriverEntry (IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath)
 

Variables

PWSTR GenericUSBDeviceString
 

Macro Definition Documentation

◆ USB_HUB_TAG

#define USB_HUB_TAG   'BUHU'

Definition at line 26 of file usbhub.h.

◆ USBH_EXTENSION_TYPE_FUNCTION

#define USBH_EXTENSION_TYPE_FUNCTION   0x08

Definition at line 31 of file usbhub.h.

◆ USBH_EXTENSION_TYPE_HUB

#define USBH_EXTENSION_TYPE_HUB   0x01

Definition at line 28 of file usbhub.h.

◆ USBH_EXTENSION_TYPE_PARENT

#define USBH_EXTENSION_TYPE_PARENT   0x04

Definition at line 30 of file usbhub.h.

◆ USBH_EXTENSION_TYPE_PORT

#define USBH_EXTENSION_TYPE_PORT   0x02

Definition at line 29 of file usbhub.h.

◆ USBHUB_ENUM_FLAG_DEVICE_PRESENT

#define USBHUB_ENUM_FLAG_DEVICE_PRESENT   0x01

Definition at line 84 of file usbhub.h.

◆ USBHUB_ENUM_FLAG_GHOST_DEVICE

#define USBHUB_ENUM_FLAG_GHOST_DEVICE   0x02

Definition at line 85 of file usbhub.h.

◆ USBHUB_FAIL_NESTED_TOO_DEEPLY

#define USBHUB_FAIL_NESTED_TOO_DEEPLY   6

Definition at line 112 of file usbhub.h.

◆ USBHUB_FAIL_NO_FAIL

#define USBHUB_FAIL_NO_FAIL   5

Definition at line 111 of file usbhub.h.

◆ USBHUB_FAIL_OVERCURRENT

#define USBHUB_FAIL_OVERCURRENT   7

Definition at line 113 of file usbhub.h.

◆ USBHUB_FDO_FLAG_CHECK_IDLE_LOCK

#define USBHUB_FDO_FLAG_CHECK_IDLE_LOCK   (1 << 21)

Definition at line 53 of file usbhub.h.

◆ USBHUB_FDO_FLAG_DEFER_CHECK_IDLE

#define USBHUB_FDO_FLAG_DEFER_CHECK_IDLE   (1 << 16)

Definition at line 48 of file usbhub.h.

◆ USBHUB_FDO_FLAG_DEVICE_FAILED

#define USBHUB_FDO_FLAG_DEVICE_FAILED   (1 << 3)

Definition at line 35 of file usbhub.h.

◆ USBHUB_FDO_FLAG_DEVICE_REMOVED

#define USBHUB_FDO_FLAG_DEVICE_REMOVED   (1 << 14)

Definition at line 46 of file usbhub.h.

◆ USBHUB_FDO_FLAG_DEVICE_STARTED

#define USBHUB_FDO_FLAG_DEVICE_STARTED   (1 << 0)

Definition at line 33 of file usbhub.h.

◆ USBHUB_FDO_FLAG_DEVICE_STOPPED

#define USBHUB_FDO_FLAG_DEVICE_STOPPED   (1 << 5)

Definition at line 37 of file usbhub.h.

◆ USBHUB_FDO_FLAG_DEVICE_STOPPING

#define USBHUB_FDO_FLAG_DEVICE_STOPPING   (1 << 2)

Definition at line 34 of file usbhub.h.

◆ USBHUB_FDO_FLAG_DEVICE_SUSPENDED

#define USBHUB_FDO_FLAG_DEVICE_SUSPENDED   (1 << 26)

Definition at line 58 of file usbhub.h.

◆ USBHUB_FDO_FLAG_DO_ENUMERATION

#define USBHUB_FDO_FLAG_DO_ENUMERATION   (1 << 20)

Definition at line 52 of file usbhub.h.

◆ USBHUB_FDO_FLAG_DO_SUSPENSE

#define USBHUB_FDO_FLAG_DO_SUSPENSE   (1 << 24)

Definition at line 56 of file usbhub.h.

◆ USBHUB_FDO_FLAG_ENUM_POST_RECOVER

#define USBHUB_FDO_FLAG_ENUM_POST_RECOVER   (1 << 19)

Definition at line 51 of file usbhub.h.

◆ USBHUB_FDO_FLAG_ESD_RECOVERING

#define USBHUB_FDO_FLAG_ESD_RECOVERING   (1 << 9)

Definition at line 41 of file usbhub.h.

◆ USBHUB_FDO_FLAG_GOING_IDLE

#define USBHUB_FDO_FLAG_GOING_IDLE   (1 << 25)

Definition at line 57 of file usbhub.h.

◆ USBHUB_FDO_FLAG_HIBERNATE_STATE

#define USBHUB_FDO_FLAG_HIBERNATE_STATE   (1 << 22)

Definition at line 54 of file usbhub.h.

◆ USBHUB_FDO_FLAG_HUB_BUSY

#define USBHUB_FDO_FLAG_HUB_BUSY   (1 << 6)

Definition at line 38 of file usbhub.h.

◆ USBHUB_FDO_FLAG_MULTIPLE_TTS

#define USBHUB_FDO_FLAG_MULTIPLE_TTS   (1 << 18)

Definition at line 50 of file usbhub.h.

◆ USBHUB_FDO_FLAG_NOT_D0_STATE

#define USBHUB_FDO_FLAG_NOT_D0_STATE   (1 << 11)

Definition at line 43 of file usbhub.h.

◆ USBHUB_FDO_FLAG_NOT_ENUMERATED

#define USBHUB_FDO_FLAG_NOT_ENUMERATED   (1 << 23)

Definition at line 55 of file usbhub.h.

◆ USBHUB_FDO_FLAG_PENDING_WAKE_IRP

#define USBHUB_FDO_FLAG_PENDING_WAKE_IRP   (1 << 7)

Definition at line 39 of file usbhub.h.

◆ USBHUB_FDO_FLAG_REMOTE_WAKEUP

#define USBHUB_FDO_FLAG_REMOTE_WAKEUP   (1 << 4)

Definition at line 36 of file usbhub.h.

◆ USBHUB_FDO_FLAG_RESET_PORT_LOCK

#define USBHUB_FDO_FLAG_RESET_PORT_LOCK   (1 << 8)

Definition at line 40 of file usbhub.h.

◆ USBHUB_FDO_FLAG_SET_D0_STATE

#define USBHUB_FDO_FLAG_SET_D0_STATE   (1 << 10)

Definition at line 42 of file usbhub.h.

◆ USBHUB_FDO_FLAG_STATE_CHANGING

#define USBHUB_FDO_FLAG_STATE_CHANGING   (1 << 13)

Definition at line 45 of file usbhub.h.

◆ USBHUB_FDO_FLAG_USB20_HUB

#define USBHUB_FDO_FLAG_USB20_HUB   (1 << 15)

Definition at line 47 of file usbhub.h.

◆ USBHUB_FDO_FLAG_WAIT_IDLE_REQUEST

#define USBHUB_FDO_FLAG_WAIT_IDLE_REQUEST   (1 << 12)

Definition at line 44 of file usbhub.h.

◆ USBHUB_FDO_FLAG_WAKEUP_START

#define USBHUB_FDO_FLAG_WAKEUP_START   (1 << 17)

Definition at line 49 of file usbhub.h.

◆ USBHUB_FDO_FLAG_WITEM_INIT

#define USBHUB_FDO_FLAG_WITEM_INIT   (1 << 27)

Definition at line 59 of file usbhub.h.

◆ USBHUB_FEATURE_C_HUB_LOCAL_POWER

#define USBHUB_FEATURE_C_HUB_LOCAL_POWER   0

Definition at line 88 of file usbhub.h.

◆ USBHUB_FEATURE_C_HUB_OVER_CURRENT

#define USBHUB_FEATURE_C_HUB_OVER_CURRENT   1

Definition at line 89 of file usbhub.h.

◆ USBHUB_FEATURE_C_PORT_CONNECTION

#define USBHUB_FEATURE_C_PORT_CONNECTION   16

Definition at line 98 of file usbhub.h.

◆ USBHUB_FEATURE_C_PORT_ENABLE

#define USBHUB_FEATURE_C_PORT_ENABLE   17

Definition at line 99 of file usbhub.h.

◆ USBHUB_FEATURE_C_PORT_OVER_CURRENT

#define USBHUB_FEATURE_C_PORT_OVER_CURRENT   19

Definition at line 101 of file usbhub.h.

◆ USBHUB_FEATURE_C_PORT_RESET

#define USBHUB_FEATURE_C_PORT_RESET   20

Definition at line 102 of file usbhub.h.

◆ USBHUB_FEATURE_C_PORT_SUSPEND

#define USBHUB_FEATURE_C_PORT_SUSPEND   18

Definition at line 100 of file usbhub.h.

◆ USBHUB_FEATURE_PORT_CONNECTION

#define USBHUB_FEATURE_PORT_CONNECTION   0

Definition at line 91 of file usbhub.h.

◆ USBHUB_FEATURE_PORT_ENABLE

#define USBHUB_FEATURE_PORT_ENABLE   1

Definition at line 92 of file usbhub.h.

◆ USBHUB_FEATURE_PORT_INDICATOR

#define USBHUB_FEATURE_PORT_INDICATOR   22

Definition at line 104 of file usbhub.h.

◆ USBHUB_FEATURE_PORT_LOW_SPEED

#define USBHUB_FEATURE_PORT_LOW_SPEED   9

Definition at line 97 of file usbhub.h.

◆ USBHUB_FEATURE_PORT_OVER_CURRENT

#define USBHUB_FEATURE_PORT_OVER_CURRENT   3

Definition at line 94 of file usbhub.h.

◆ USBHUB_FEATURE_PORT_POWER

#define USBHUB_FEATURE_PORT_POWER   8

Definition at line 96 of file usbhub.h.

◆ USBHUB_FEATURE_PORT_RESET

#define USBHUB_FEATURE_PORT_RESET   4

Definition at line 95 of file usbhub.h.

◆ USBHUB_FEATURE_PORT_SUSPEND

#define USBHUB_FEATURE_PORT_SUSPEND   2

Definition at line 93 of file usbhub.h.

◆ USBHUB_FEATURE_PORT_TEST

#define USBHUB_FEATURE_PORT_TEST   21

Definition at line 103 of file usbhub.h.

◆ USBHUB_MAX_CASCADE_LEVELS

#define USBHUB_MAX_CASCADE_LEVELS   6

Definition at line 106 of file usbhub.h.

◆ USBHUB_MAX_REQUEST_ERRORS

#define USBHUB_MAX_REQUEST_ERRORS   3

Definition at line 108 of file usbhub.h.

◆ USBHUB_PDO_FLAG_ALLOC_BNDW_FAILED

#define USBHUB_PDO_FLAG_ALLOC_BNDW_FAILED   (1 << 18)

Definition at line 78 of file usbhub.h.

◆ USBHUB_PDO_FLAG_DELETE_PENDING

#define USBHUB_PDO_FLAG_DELETE_PENDING   (1 << 7)

Definition at line 68 of file usbhub.h.

◆ USBHUB_PDO_FLAG_DEVICE_STARTED

#define USBHUB_PDO_FLAG_DEVICE_STARTED   (1 << 9)

Definition at line 70 of file usbhub.h.

◆ USBHUB_PDO_FLAG_ENUMERATED

#define USBHUB_PDO_FLAG_ENUMERATED   (1 << 26)

Definition at line 82 of file usbhub.h.

◆ USBHUB_PDO_FLAG_HS_USB1_DUALMODE

#define USBHUB_PDO_FLAG_HS_USB1_DUALMODE   (1 << 10)

Definition at line 71 of file usbhub.h.

◆ USBHUB_PDO_FLAG_HUB_DEVICE

#define USBHUB_PDO_FLAG_HUB_DEVICE   (1 << 0)

Definition at line 61 of file usbhub.h.

◆ USBHUB_PDO_FLAG_IDLE_NOTIFICATION

#define USBHUB_PDO_FLAG_IDLE_NOTIFICATION   (1 << 22)

Definition at line 80 of file usbhub.h.

◆ USBHUB_PDO_FLAG_INIT_PORT_FAILED

#define USBHUB_PDO_FLAG_INIT_PORT_FAILED   (1 << 2)

Definition at line 63 of file usbhub.h.

◆ USBHUB_PDO_FLAG_INSUFFICIENT_PWR

#define USBHUB_PDO_FLAG_INSUFFICIENT_PWR   (1 << 16)

Definition at line 77 of file usbhub.h.

◆ USBHUB_PDO_FLAG_MULTI_INTERFACE

#define USBHUB_PDO_FLAG_MULTI_INTERFACE   (1 << 1)

Definition at line 62 of file usbhub.h.

◆ USBHUB_PDO_FLAG_NOT_CONNECTED

#define USBHUB_PDO_FLAG_NOT_CONNECTED   (1 << 6)

Definition at line 67 of file usbhub.h.

◆ USBHUB_PDO_FLAG_OVERCURRENT_PORT

#define USBHUB_PDO_FLAG_OVERCURRENT_PORT   (1 << 14)

Definition at line 75 of file usbhub.h.

◆ USBHUB_PDO_FLAG_PORT_HIGH_SPEED

#define USBHUB_PDO_FLAG_PORT_HIGH_SPEED   (1 << 23)

Definition at line 81 of file usbhub.h.

◆ USBHUB_PDO_FLAG_PORT_LOW_SPEED

#define USBHUB_PDO_FLAG_PORT_LOW_SPEED   (1 << 3)

Definition at line 64 of file usbhub.h.

◆ USBHUB_PDO_FLAG_PORT_RESSETING

#define USBHUB_PDO_FLAG_PORT_RESSETING   (1 << 19)

Definition at line 79 of file usbhub.h.

◆ USBHUB_PDO_FLAG_PORT_RESTORE_FAIL

#define USBHUB_PDO_FLAG_PORT_RESTORE_FAIL   (1 << 12)

Definition at line 73 of file usbhub.h.

◆ USBHUB_PDO_FLAG_POWER_D1_OR_D2

#define USBHUB_PDO_FLAG_POWER_D1_OR_D2   (1 << 13)

Definition at line 74 of file usbhub.h.

◆ USBHUB_PDO_FLAG_POWER_D3

#define USBHUB_PDO_FLAG_POWER_D3   (1 << 8)

Definition at line 69 of file usbhub.h.

◆ USBHUB_PDO_FLAG_REG_DEV_INTERFACE

#define USBHUB_PDO_FLAG_REG_DEV_INTERFACE   (1 << 11)

Definition at line 72 of file usbhub.h.

◆ USBHUB_PDO_FLAG_REMOTE_WAKEUP

#define USBHUB_PDO_FLAG_REMOTE_WAKEUP   (1 << 4)

Definition at line 65 of file usbhub.h.

◆ USBHUB_PDO_FLAG_REMOVING_PORT_PDO

#define USBHUB_PDO_FLAG_REMOVING_PORT_PDO   (1 << 15)

Definition at line 76 of file usbhub.h.

◆ USBHUB_PDO_FLAG_WAIT_WAKE

#define USBHUB_PDO_FLAG_WAIT_WAKE   (1 << 5)

Definition at line 66 of file usbhub.h.

◆ USBHUB_RESET_PORT_MAX_RETRY

#define USBHUB_RESET_PORT_MAX_RETRY   3

Definition at line 107 of file usbhub.h.

Typedef Documentation

◆ COMMON_DEVICE_EXTENSION

◆ PCOMMON_DEVICE_EXTENSION

◆ PUSBHUB_FDO_EXTENSION

Definition at line 124 of file usbhub.h.

◆ PUSBHUB_IDLE_HUB_CONTEXT

◆ PUSBHUB_IDLE_PORT_CANCEL_CONTEXT

◆ PUSBHUB_IDLE_PORT_CONTEXT

◆ PUSBHUB_IO_WORK_ITEM

◆ PUSBHUB_PORT_DATA

◆ PUSBHUB_PORT_PDO_EXTENSION

◆ PUSBHUB_RESET_PORT_CONTEXT

◆ PUSBHUB_STATUS_CHANGE_CONTEXT

◆ PUSBHUB_URB_TIMEOUT_CONTEXT

◆ PUSBHUB_WORKER_ROUTINE

typedef VOID(NTAPI * PUSBHUB_WORKER_ROUTINE) (IN PUSBHUB_FDO_EXTENSION HubExtension, IN PVOID Context)

Definition at line 126 of file usbhub.h.

◆ USBHUB_FDO_EXTENSION

◆ USBHUB_IDLE_HUB_CONTEXT

◆ USBHUB_IDLE_PORT_CANCEL_CONTEXT

◆ USBHUB_IDLE_PORT_CONTEXT

◆ USBHUB_IO_WORK_ITEM

◆ USBHUB_PORT_DATA

◆ USBHUB_PORT_PDO_EXTENSION

◆ USBHUB_RESET_PORT_CONTEXT

◆ USBHUB_STATUS_CHANGE_CONTEXT

◆ USBHUB_URB_TIMEOUT_CONTEXT

Function Documentation

◆ DriverEntry()

NTSTATUS NTAPI DriverEntry ( IN PDRIVER_OBJECT  DriverObject,
IN PUNICODE_STRING  RegistryPath 
)

Definition at line 367 of file beep.c.

369{
370 PDEVICE_EXTENSION DeviceExtension;
374
376
377 /* Create the device */
379 sizeof(DEVICE_EXTENSION),
380 &DeviceName,
382 0,
383 FALSE,
384 &DeviceObject);
385 if (!NT_SUCCESS(Status)) return Status;
386
387 /* Make it use buffered I/O */
389
390 /* Setup the Driver Object */
391 DriverObject->MajorFunction[IRP_MJ_CREATE] = BeepCreate;
392 DriverObject->MajorFunction[IRP_MJ_CLOSE] = BeepClose;
393 DriverObject->MajorFunction[IRP_MJ_CLEANUP] = BeepCleanup;
395 DriverObject->DriverUnload = BeepUnload;
396 DriverObject->DriverStartIo = BeepStartIo;
397
398 /* Set up device extension */
399 DeviceExtension = DeviceObject->DeviceExtension;
400 DeviceExtension->ReferenceCount = 0;
401 DeviceExtension->TimerActive = FALSE;
403 KeInitializeTimer(&DeviceExtension->Timer);
404 ExInitializeFastMutex(&DeviceExtension->Mutex);
405
406 /* Page the entire driver */
408 return STATUS_SUCCESS;
409}
LONG NTSTATUS
Definition: precomp.h:26
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
DRIVER_STARTIO BeepStartIo
Definition: beep.c:295
VOID NTAPI BeepDPC(IN PKDPC Dpc, IN PDEVICE_OBJECT DeviceObject, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
Definition: beep.c:34
DRIVER_DISPATCH BeepClose
Definition: beep.c:78
DRIVER_DISPATCH BeepCleanup
Definition: beep.c:145
DRIVER_UNLOAD BeepUnload
Definition: beep.c:268
DRIVER_DISPATCH BeepCreate
Definition: beep.c:52
DRIVER_DISPATCH BeepDeviceControl
Definition: beep.c:206
DRIVER_INITIALIZE DriverEntry
Definition: condrv.c:21
#define DO_BUFFERED_IO
Definition: env_spec_w32.h:394
Status
Definition: gdiplustypes.h:25
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
NTSTATUS NTAPI IoCreateDevice(IN PDRIVER_OBJECT DriverObject, IN ULONG DeviceExtensionSize, IN PUNICODE_STRING DeviceName, IN DEVICE_TYPE DeviceType, IN ULONG DeviceCharacteristics, IN BOOLEAN Exclusive, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:1031
#define L(x)
Definition: ntvdm.h:50
#define FILE_DEVICE_BEEP
Definition: winioctl.h:107
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
#define STATUS_SUCCESS
Definition: shellext.h:65
FAST_MUTEX Mutex
Definition: beep.c:24
PVOID NTAPI MmPageEntireDriver(IN PVOID AddressWithinSection)
Definition: sysldr.c:3557
VOID NTAPI KeInitializeTimer(OUT PKTIMER Timer)
Definition: timerobj.c:233
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_opt_ PCUNICODE_STRING DeviceName
Definition: wdfdevice.h:3275
_Must_inspect_result_ _In_ PDRIVER_OBJECT _In_ PCUNICODE_STRING RegistryPath
Definition: wdfdriver.h:215
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
FORCEINLINE VOID ExInitializeFastMutex(_Out_ PFAST_MUTEX FastMutex)
Definition: exfuncs.h:274
FORCEINLINE VOID IoInitializeDpcRequest(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIO_DPC_ROUTINE DpcRoutine)
Definition: iofuncs.h:2840
IO_DPC_ROUTINE * PIO_DPC_ROUTINE
Definition: iotypes.h:2847
#define IRP_MJ_CLEANUP

◆ PdoExt()

◆ USBD_CreateDeviceEx()

NTSTATUS NTAPI USBD_CreateDeviceEx ( IN PUSBHUB_FDO_EXTENSION  HubExtension,
IN PUSB_DEVICE_HANDLE OutDeviceHandle,
IN USB_PORT_STATUS  UsbPortStatus,
IN USHORT  Port 
)

Definition at line 2508 of file usbhub.c.

2512{
2514 PUSB_BUSIFFN_CREATE_USB_DEVICE CreateUsbDevice;
2515
2516 DPRINT("USBD_CreateDeviceEx: Port - %x, UsbPortStatus - 0x%04X\n",
2517 Port,
2518 UsbPortStatus.AsUshort16);
2519
2520 CreateUsbDevice = HubExtension->BusInterface.CreateUsbDevice;
2521
2522 if (!CreateUsbDevice)
2523 {
2525 }
2526
2527 HubDeviceHandle = USBH_SyncGetDeviceHandle(HubExtension->LowerDevice);
2528
2529 return CreateUsbDevice(HubExtension->BusInterface.BusContext,
2530 OutDeviceHandle,
2532 UsbPortStatus.AsUshort16,
2533 Port);
2534}
CPPORT Port[4]
Definition: headless.c:35
_Outptr_ PUSB_DEVICE_HANDLE _In_ PUSB_DEVICE_HANDLE HubDeviceHandle
Definition: hubbusif.h:41
USB_BUSIFFN_CREATE_USB_DEVICE * PUSB_BUSIFFN_CREATE_USB_DEVICE
Definition: hubbusif.h:44
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:239
PUSB_DEVICE_HANDLE NTAPI USBH_SyncGetDeviceHandle(IN PDEVICE_OBJECT DeviceObject)
Definition: usbhub.c:832

Referenced by USBH_CreateDevice(), and USBH_ResetDevice().

◆ USBD_GetDeviceInformationEx()

NTSTATUS NTAPI USBD_GetDeviceInformationEx ( IN PUSBHUB_PORT_PDO_EXTENSION  PortExtension,
IN PUSBHUB_FDO_EXTENSION  HubExtension,
IN PUSB_NODE_CONNECTION_INFORMATION_EX  Info,
IN ULONG  Length,
IN PUSB_DEVICE_HANDLE  DeviceHandle 
)

Definition at line 2639 of file usbhub.c.

2644{
2647 SIZE_T DeviceInfoLength;
2648 PUSB_NODE_CONNECTION_INFORMATION_EX NodeInfo;
2649 SIZE_T NodeInfoLength;
2650 ULONG PipeNumber;
2651 ULONG dummy;
2653
2654 DPRINT("USBD_GetDeviceInformationEx ... \n");
2655
2656 QueryDeviceInformation = HubExtension->BusInterface.QueryDeviceInformation;
2657
2659 {
2661 return Status;
2662 }
2663
2664 DeviceInfoLength = sizeof(USB_DEVICE_INFORMATION_0);
2665
2666 while (TRUE)
2667 {
2669 DeviceInfoLength,
2670 USB_HUB_TAG);
2671
2672 if (!DeviceInfo)
2673 {
2675 }
2676
2677 RtlZeroMemory(DeviceInfo, DeviceInfoLength);
2678
2679 DeviceInfo->InformationLevel = 0;
2680
2681 Status = QueryDeviceInformation(HubExtension->BusInterface.BusContext,
2683 DeviceInfo,
2684 DeviceInfoLength,
2685 &dummy);
2686
2688 {
2689 break;
2690 }
2691
2692 DeviceInfoLength = DeviceInfo->ActualLength;
2693
2695 }
2696
2697 NodeInfo = NULL;
2698 NodeInfoLength = 0;
2699
2700 if (NT_SUCCESS(Status))
2701 {
2702 NodeInfoLength = (sizeof(USB_NODE_CONNECTION_INFORMATION_EX) - sizeof(USB_PIPE_INFO)) +
2703 DeviceInfo->NumberOfOpenPipes * sizeof(USB_PIPE_INFO);
2704
2705 NodeInfo = ExAllocatePoolWithTag(PagedPool, NodeInfoLength, USB_HUB_TAG);
2706
2707 if (!NodeInfo)
2708 {
2711 }
2712
2713 RtlZeroMemory(NodeInfo, NodeInfoLength);
2714
2715 NodeInfo->ConnectionIndex = Info->ConnectionIndex;
2716
2717 RtlCopyMemory(&NodeInfo->DeviceDescriptor,
2718 &DeviceInfo->DeviceDescriptor,
2719 sizeof(USB_DEVICE_DESCRIPTOR));
2720
2721 NodeInfo->CurrentConfigurationValue = DeviceInfo->CurrentConfigurationValue;
2722 NodeInfo->Speed = DeviceInfo->DeviceSpeed;
2723 NodeInfo->DeviceIsHub = PortExtension->PortPdoFlags & USBHUB_PDO_FLAG_HUB_DEVICE;
2724 NodeInfo->DeviceAddress = DeviceInfo->DeviceAddress;
2725 NodeInfo->NumberOfOpenPipes = DeviceInfo->NumberOfOpenPipes;
2726 NodeInfo->ConnectionStatus = Info->ConnectionStatus;
2727
2728 for (PipeNumber = 0;
2729 PipeNumber < DeviceInfo->NumberOfOpenPipes;
2730 PipeNumber++)
2731 {
2732 RtlCopyMemory(&NodeInfo->PipeList[PipeNumber],
2733 &DeviceInfo->PipeList[PipeNumber],
2734 sizeof(USB_PIPE_INFO));
2735 }
2736 }
2737
2739
2740 if (NodeInfo)
2741 {
2742 if (NodeInfoLength <= Length)
2743 {
2744 Length = NodeInfoLength;
2745 }
2746 else
2747 {
2749 }
2750
2751 RtlCopyMemory(Info, NodeInfo, Length);
2752
2753 ExFreePoolWithTag(NodeInfo, USB_HUB_TAG);
2754 }
2755
2756 return Status;
2757}
#define TRUE
Definition: types.h:120
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define PagedPool
Definition: env_spec_w32.h:308
_Inout_ PUSB_DEVICE_HANDLE DeviceHandle
Definition: hubbusif.h:121
struct _USB_DEVICE_INFORMATION_0 USB_DEVICE_INFORMATION_0
USB_BUSIFFN_GET_DEVICE_INFORMATION * PUSB_BUSIFFN_GET_DEVICE_INFORMATION
Definition: hubbusif.h:183
NTSTATUS QueryDeviceInformation(IN PUNICODE_STRING SymbolicName, OUT PUNICODE_STRING DeviceName OPTIONAL, OUT PMOUNTDEV_UNIQUE_ID *UniqueId OPTIONAL, OUT PBOOLEAN Removable OPTIONAL, OUT PBOOLEAN GptDriveLetter OPTIONAL, OUT PBOOLEAN HasGuid OPTIONAL, IN OUT LPGUID StableGuid OPTIONAL, OUT PBOOLEAN Valid OPTIONAL)
Definition: mountmgr.c:190
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define USB_HUB_TAG
Definition: usbhub.h:26
#define USBHUB_PDO_FLAG_HUB_DEVICE
Definition: usbhub.h:61
_Must_inspect_result_ _In_ WDFCHILDLIST _In_ PWDF_CHILD_LIST_ITERATOR _Out_ WDFDEVICE _Inout_opt_ PWDF_CHILD_RETRIEVE_INFO Info
Definition: wdfchildlist.h:690

Referenced by USBH_IoctlGetNodeConnectionInformation().

◆ USBD_InitializeDeviceEx()

NTSTATUS NTAPI USBD_InitializeDeviceEx ( IN PUSBHUB_FDO_EXTENSION  HubExtension,
IN PUSB_DEVICE_HANDLE  DeviceHandle,
IN PUCHAR  DeviceDescriptorBuffer,
IN ULONG  DeviceDescriptorBufferLength,
IN PUCHAR  ConfigDescriptorBuffer,
IN ULONG  ConfigDescriptorBufferLength 
)

Definition at line 2562 of file usbhub.c.

2568{
2570 PUSB_BUSIFFN_INITIALIZE_USB_DEVICE InitializeUsbDevice;
2571 PUSB_BUSIFFN_GET_USB_DESCRIPTORS GetUsbDescriptors;
2572
2573 DPRINT("USBD_InitializeDeviceEx: ... \n");
2574
2575 InitializeUsbDevice = HubExtension->BusInterface.InitializeUsbDevice;
2576 GetUsbDescriptors = HubExtension->BusInterface.GetUsbDescriptors;
2577
2578 if (!InitializeUsbDevice || !GetUsbDescriptors)
2579 {
2581 }
2582
2583 Status = InitializeUsbDevice(HubExtension->BusInterface.BusContext,
2584 DeviceHandle);
2585
2586 if (!NT_SUCCESS(Status))
2587 {
2588 return Status;
2589 }
2590
2591 return GetUsbDescriptors(HubExtension->BusInterface.BusContext,
2597}
USB_BUSIFFN_INITIALIZE_USB_DEVICE * PUSB_BUSIFFN_INITIALIZE_USB_DEVICE
Definition: hubbusif.h:122
USB_BUSIFFN_GET_USB_DESCRIPTORS * PUSB_BUSIFFN_GET_USB_DESCRIPTORS
Definition: hubbusif.h:154
_Inout_ PUSB_DEVICE_HANDLE _Out_writes_bytes_to_ DeviceDescriptorBufferLength PUCHAR _Inout_ PULONG _Out_writes_bytes_to_ ConfigDescriptorBufferLength PUCHAR _Inout_ PULONG ConfigDescriptorBufferLength
Definition: hubbusif.h:153
_Inout_ PUSB_DEVICE_HANDLE _Out_writes_bytes_to_ DeviceDescriptorBufferLength PUCHAR DeviceDescriptorBuffer
Definition: hubbusif.h:148
_Inout_ PUSB_DEVICE_HANDLE _Out_writes_bytes_to_ DeviceDescriptorBufferLength PUCHAR _Inout_ PULONG _Out_writes_bytes_to_ ConfigDescriptorBufferLength PUCHAR ConfigDescriptorBuffer
Definition: hubbusif.h:151
_Inout_ PUSB_DEVICE_HANDLE _Out_writes_bytes_to_ DeviceDescriptorBufferLength PUCHAR _Inout_ PULONG DeviceDescriptorBufferLength
Definition: hubbusif.h:150

Referenced by USBH_CreateDevice(), and USBH_ResetDevice().

◆ USBD_RegisterRootHubCallBack()

NTSTATUS NTAPI USBD_RegisterRootHubCallBack ( IN PUSBHUB_FDO_EXTENSION  HubExtension)

Definition at line 2986 of file usbhub.c.

2987{
2988 PUSB_BUSIFFN_ROOTHUB_INIT_NOTIFY RootHubInitNotification;
2989
2990 DPRINT("USBD_RegisterRootHubCallBack: ... \n");
2991
2992 RootHubInitNotification = HubExtension->BusInterface.RootHubInitNotification;
2993
2994 if (!RootHubInitNotification)
2995 {
2997 }
2998
2999 KeClearEvent(&HubExtension->RootHubNotificationEvent);
3000
3001 return RootHubInitNotification(HubExtension->BusInterface.BusContext,
3002 HubExtension,
3004}
VOID NTAPI KeClearEvent(IN PKEVENT Event)
Definition: eventobj.c:22
USB_BUSIFFN_ROOTHUB_INIT_NOTIFY * PUSB_BUSIFFN_ROOTHUB_INIT_NOTIFY
Definition: hubbusif.h:279
VOID NTAPI USBHUB_RootHubCallBack(IN PVOID Context)
Definition: usbhub.c:2957

Referenced by USBH_StartHubFdoDevice().

◆ USBD_RemoveDeviceEx()

NTSTATUS NTAPI USBD_RemoveDeviceEx ( IN PUSBHUB_FDO_EXTENSION  HubExtension,
IN PUSB_DEVICE_HANDLE  DeviceHandle,
IN ULONG  Flags 
)

Definition at line 2538 of file usbhub.c.

2541{
2542 PUSB_BUSIFFN_REMOVE_USB_DEVICE RemoveUsbDevice;
2543
2544 DPRINT("USBD_RemoveDeviceEx: DeviceHandle - %p, Flags - %X\n",
2546 Flags);
2547
2548 RemoveUsbDevice = HubExtension->BusInterface.RemoveUsbDevice;
2549
2550 if (!RemoveUsbDevice)
2551 {
2553 }
2554
2555 return RemoveUsbDevice(HubExtension->BusInterface.BusContext,
2557 Flags);
2558}
USB_BUSIFFN_REMOVE_USB_DEVICE * PUSB_BUSIFFN_REMOVE_USB_DEVICE
Definition: hubbusif.h:140
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170

Referenced by USBH_CreateDevice(), USBH_FdoCleanup(), USBH_FdoQueryBusRelations(), USBH_PdoRemoveDevice(), USBH_ProcessPortStateChange(), USBH_ResetDevice(), and USBH_ResetPortWorker().

◆ USBD_RestoreDeviceEx()

NTSTATUS NTAPI USBD_RestoreDeviceEx ( IN PUSBHUB_FDO_EXTENSION  HubExtension,
IN OUT PUSB_DEVICE_HANDLE  OldDeviceHandle,
IN OUT PUSB_DEVICE_HANDLE  NewDeviceHandle 
)

Definition at line 2761 of file usbhub.c.

2764{
2765 PUSB_BUSIFFN_RESTORE_DEVICE RestoreUsbDevice;
2767
2768 DPRINT("USBD_RestoreDeviceEx: HubExtension - %p, OldDeviceHandle - %p, NewDeviceHandle - %p\n",
2769 HubExtension,
2772
2773 RestoreUsbDevice = HubExtension->BusInterface.RestoreUsbDevice;
2774
2775 if (RestoreUsbDevice)
2776 {
2777 Status = RestoreUsbDevice(HubExtension->BusInterface.BusContext,
2780 }
2781 else
2782 {
2784 }
2785
2786 return Status;
2787}
_Outptr_ PUSB_DEVICE_HANDLE * NewDeviceHandle
Definition: hubbusif.h:40
_Inout_ PUSB_DEVICE_HANDLE OldDeviceHandle
Definition: hubbusif.h:161
USB_BUSIFFN_RESTORE_DEVICE * PUSB_BUSIFFN_RESTORE_DEVICE
Definition: hubbusif.h:163

Referenced by USBH_ResetDevice().

◆ USBD_UnRegisterRootHubCallBack()

NTSTATUS NTAPI USBD_UnRegisterRootHubCallBack ( IN PUSBHUB_FDO_EXTENSION  HubExtension)

Definition at line 3008 of file usbhub.c.

3009{
3010 PUSB_BUSIFFN_ROOTHUB_INIT_NOTIFY RootHubInitNotification;
3012
3013 DPRINT("USBD_UnRegisterRootHubCallBack ... \n");
3014
3015 RootHubInitNotification = HubExtension->BusInterface.RootHubInitNotification;
3016
3017 if (!RootHubInitNotification)
3018 {
3020 }
3021
3022 Status = RootHubInitNotification(HubExtension->BusInterface.BusContext,
3023 NULL,
3024 NULL);
3025
3026 if (!NT_SUCCESS(Status))
3027 {
3028 KeWaitForSingleObject(&HubExtension->RootHubNotificationEvent,
3029 Executive,
3030 KernelMode,
3031 FALSE,
3032 NULL);
3033 }
3034
3035 return Status;
3036}
#define KeWaitForSingleObject(pEvt, foo, a, b, c)
Definition: env_spec_w32.h:478
#define KernelMode
Definition: asm.h:34
@ Executive
Definition: ketypes.h:415

Referenced by USBH_FdoCleanup().

◆ USBH_AllocateWorkItem()

NTSTATUS NTAPI USBH_AllocateWorkItem ( IN PUSBHUB_FDO_EXTENSION  HubExtension,
OUT PUSBHUB_IO_WORK_ITEM OutHubIoWorkItem,
IN PUSBHUB_WORKER_ROUTINE  WorkerRoutine,
IN SIZE_T  BufferLength,
OUT PVOID OutHubWorkItemBuffer,
IN WORK_QUEUE_TYPE  Type 
)

◆ USBH_CheckDeviceLanguage()

NTSTATUS NTAPI USBH_CheckDeviceLanguage ( IN PDEVICE_OBJECT  DeviceObject,
IN USHORT  LanguageId 
)

Definition at line 4242 of file usbhub.c.

4244{
4247 ULONG NumSymbols;
4248 ULONG ix;
4249 PWCHAR pSymbol;
4250 ULONG Length;
4251
4252 DPRINT("USBH_CheckDeviceLanguage: LanguageId - 0x%04X\n", LanguageId);
4253
4256 USB_HUB_TAG);
4257
4258 if (!Descriptor)
4259 {
4261 }
4262
4264
4266 0,
4267 0,
4268 Descriptor,
4270 &Length,
4271 TRUE);
4272
4273 if (!NT_SUCCESS(Status) ||
4274 Length < sizeof(USB_COMMON_DESCRIPTOR))
4275 {
4276 goto Exit;
4277 }
4278
4279 NumSymbols = (Length -
4280 FIELD_OFFSET(USB_STRING_DESCRIPTOR, bString)) / sizeof(WCHAR);
4281
4282 pSymbol = Descriptor->bString;
4283
4284 for (ix = 1; ix < NumSymbols; ix++)
4285 {
4286 if (*pSymbol == (WCHAR)LanguageId)
4287 {
4289 goto Exit;
4290 }
4291
4292 pSymbol++;
4293 }
4294
4296
4297Exit:
4299 return Status;
4300}
#define NonPagedPool
Definition: env_spec_w32.h:307
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:423
static void Exit(void)
Definition: sock.c:1330
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
uint16_t * PWCHAR
Definition: typedefs.h:56
#define MAXIMUM_USB_STRING_LENGTH
Definition: usb100.h:43
NTSTATUS NTAPI USBH_SyncGetStringDescriptor(IN PDEVICE_OBJECT DeviceObject, IN UCHAR Index, IN USHORT LanguageId, IN PUSB_STRING_DESCRIPTOR Descriptor, IN ULONG NumberOfBytes, IN PULONG OutLength, IN BOOLEAN IsValidateLength)
Definition: usbhub.c:1248
_Must_inspect_result_ _In_ WDFIORESLIST _In_ PIO_RESOURCE_DESCRIPTOR Descriptor
Definition: wdfresource.h:342
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by USBH_GetSerialNumberString(), and USBH_PdoQueryDeviceText().

◆ USBH_CheckHubIdle()

VOID NTAPI USBH_CheckHubIdle ( IN PUSBHUB_FDO_EXTENSION  HubExtension)

Definition at line 3808 of file usbhub.c.

3809{
3810 PDEVICE_OBJECT PdoDevice;
3811 PUSBHUB_PORT_PDO_EXTENSION PortExtension;
3812 PUSBHUB_PORT_DATA PortData;
3813 ULONG HubFlags;
3814 ULONG Port;
3815 KIRQL Irql;
3816 BOOLEAN IsHubIdle = FALSE;
3817 BOOLEAN IsAllPortsIdle;
3818 BOOLEAN IsHubCheck = TRUE;
3819
3820 DPRINT("USBH_CheckHubIdle: FIXME !!! HubExtension - %p\n", HubExtension);
3821
3822return; //HACK: delete it line after fixing Power Manager!!!
3823
3824 KeAcquireSpinLock(&HubExtension->CheckIdleSpinLock, &Irql);
3825
3826 if (HubExtension->HubFlags & USBHUB_FDO_FLAG_CHECK_IDLE_LOCK)
3827 {
3828 KeReleaseSpinLock(&HubExtension->CheckIdleSpinLock, Irql);
3829 return;
3830 }
3831
3832 HubExtension->HubFlags |= USBHUB_FDO_FLAG_CHECK_IDLE_LOCK;
3833 KeReleaseSpinLock(&HubExtension->CheckIdleSpinLock, Irql);
3834
3835 if (USBH_GetRootHubExtension(HubExtension)->SystemPowerState.SystemState != PowerSystemWorking)
3836 {
3837 KeAcquireSpinLock(&HubExtension->CheckIdleSpinLock, &Irql);
3838 HubExtension->HubFlags &= ~USBHUB_FDO_FLAG_CHECK_IDLE_LOCK;
3839 KeReleaseSpinLock(&HubExtension->CheckIdleSpinLock, Irql);
3840 return;
3841 }
3842
3843 HubFlags = HubExtension->HubFlags;
3844 DPRINT("USBH_CheckHubIdle: HubFlags - %lX\n", HubFlags);
3845
3846 if (!(HubFlags & USBHUB_FDO_FLAG_DEVICE_STARTED) ||
3847 !(HubFlags & USBHUB_FDO_FLAG_DO_ENUMERATION))
3848 {
3849 goto Exit;
3850 }
3851
3852 if (HubFlags & USBHUB_FDO_FLAG_NOT_ENUMERATED ||
3854 HubFlags & USBHUB_FDO_FLAG_DEVICE_FAILED ||
3856 HubFlags & USBHUB_FDO_FLAG_DEVICE_REMOVED ||
3857 HubFlags & USBHUB_FDO_FLAG_STATE_CHANGING ||
3858 HubFlags & USBHUB_FDO_FLAG_WAKEUP_START ||
3860 {
3861 goto Exit;
3862 }
3863
3864 if (HubExtension->ResetRequestCount)
3865 {
3866 HubExtension->HubFlags |= USBHUB_FDO_FLAG_DEFER_CHECK_IDLE;
3867 goto Exit;
3868 }
3869
3870 HubExtension->HubFlags &= ~USBHUB_FDO_FLAG_DEFER_CHECK_IDLE;
3871
3872 InterlockedIncrement(&HubExtension->PendingRequestCount);
3873
3874 KeWaitForSingleObject(&HubExtension->ResetDeviceSemaphore,
3875 Executive,
3876 KernelMode,
3877 FALSE,
3878 NULL);
3879
3881
3882 IsAllPortsIdle = TRUE;
3883
3884 PortData = HubExtension->PortData;
3885
3886 for (Port = 0;
3887 Port < HubExtension->HubDescriptor->bNumberOfPorts;
3888 Port++)
3889 {
3890 PdoDevice = PortData[Port].DeviceObject;
3891
3892 if (PdoDevice)
3893 {
3894 PortExtension = PdoDevice->DeviceExtension;
3895
3896 if (!PortExtension->IdleNotificationIrp)
3897 {
3898 DPRINT("USBH_CheckHubIdle: PortExtension - %p\n",
3899 PortExtension);
3900
3901 IsAllPortsIdle = FALSE;
3902 IsHubCheck = FALSE;
3903
3904 break;
3905 }
3906 }
3907 }
3908
3909 if (IsHubCheck &&
3910 !(HubExtension->HubFlags & USBHUB_FDO_FLAG_WAIT_IDLE_REQUEST))
3911 {
3912 KeClearEvent(&HubExtension->IdleEvent);
3913 HubExtension->HubFlags |= USBHUB_FDO_FLAG_WAIT_IDLE_REQUEST;
3914 IsHubIdle = TRUE;
3915 }
3916
3918
3919 KeReleaseSemaphore(&HubExtension->ResetDeviceSemaphore,
3921 1,
3922 FALSE);
3923
3924 if (!InterlockedDecrement(&HubExtension->PendingRequestCount))
3925 {
3926 KeSetEvent(&HubExtension->PendingRequestEvent,
3928 FALSE);
3929 }
3930
3931 DPRINT("USBH_CheckHubIdle: IsAllPortsIdle - %x, IsHubIdle - %x\n",
3932 IsAllPortsIdle,
3933 IsHubIdle);
3934
3935 if (IsAllPortsIdle && IsHubIdle)
3936 {
3937 USBH_FdoSubmitIdleRequestIrp(HubExtension);
3938 }
3939
3940Exit:
3941 KeAcquireSpinLock(&HubExtension->CheckIdleSpinLock, &Irql);
3942 HubExtension->HubFlags &= ~USBHUB_FDO_FLAG_CHECK_IDLE_LOCK;
3943 KeReleaseSpinLock(&HubExtension->CheckIdleSpinLock, Irql);
3944}
unsigned char BOOLEAN
#define InterlockedIncrement
Definition: armddk.h:53
#define InterlockedDecrement
Definition: armddk.h:52
_Out_ PKIRQL Irql
Definition: csq.h:179
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define KeSetEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:476
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
#define LOW_REALTIME_PRIORITY
VOID NTAPI IoReleaseCancelSpinLock(IN KIRQL Irql)
Definition: util.c:150
VOID NTAPI IoAcquireCancelSpinLock(OUT PKIRQL Irql)
Definition: util.c:56
@ PowerSystemWorking
Definition: ntpoapi.h:36
LONG NTAPI KeReleaseSemaphore(IN PKSEMAPHORE Semaphore, IN KPRIORITY Increment, IN LONG Adjustment, IN BOOLEAN Wait)
Definition: semphobj.c:54
PVOID DeviceExtension
Definition: env_spec_w32.h:418
PDEVICE_OBJECT DeviceObject
Definition: usbhub.h:119
PUSBHUB_FDO_EXTENSION NTAPI USBH_GetRootHubExtension(IN PUSBHUB_FDO_EXTENSION HubExtension)
Definition: usbhub.c:699
NTSTATUS NTAPI USBH_FdoSubmitIdleRequestIrp(IN PUSBHUB_FDO_EXTENSION HubExtension)
Definition: usbhub.c:3722
#define USBHUB_FDO_FLAG_DEVICE_STARTED
Definition: usbhub.h:33
#define USBHUB_FDO_FLAG_DEVICE_STOPPING
Definition: usbhub.h:34
#define USBHUB_FDO_FLAG_STATE_CHANGING
Definition: usbhub.h:45
#define USBHUB_FDO_FLAG_CHECK_IDLE_LOCK
Definition: usbhub.h:53
#define USBHUB_FDO_FLAG_ESD_RECOVERING
Definition: usbhub.h:41
#define USBHUB_FDO_FLAG_ENUM_POST_RECOVER
Definition: usbhub.h:51
#define USBHUB_FDO_FLAG_DEVICE_REMOVED
Definition: usbhub.h:46
#define USBHUB_FDO_FLAG_DO_ENUMERATION
Definition: usbhub.h:52
#define USBHUB_FDO_FLAG_DEVICE_FAILED
Definition: usbhub.h:35
#define USBHUB_FDO_FLAG_WAKEUP_START
Definition: usbhub.h:49
#define USBHUB_FDO_FLAG_WAIT_IDLE_REQUEST
Definition: usbhub.h:44
#define USBHUB_FDO_FLAG_DEFER_CHECK_IDLE
Definition: usbhub.h:48
#define USBHUB_FDO_FLAG_NOT_ENUMERATED
Definition: usbhub.h:55
#define EVENT_INCREMENT
Definition: iotypes.h:597
_In_ SYSTEM_POWER_STATE SystemPowerState
Definition: iotypes.h:7519

Referenced by USBH_ChangeIndicationWorker(), USBH_CheckIdleWorker(), and USBH_DeviceControl().

◆ USBH_CheckIdleAbort()

BOOLEAN NTAPI USBH_CheckIdleAbort ( IN PUSBHUB_FDO_EXTENSION  HubExtension,
IN BOOLEAN  IsWait,
IN BOOLEAN  IsExtCheck 
)

Definition at line 3221 of file usbhub.c.

3224{
3225 PDEVICE_OBJECT PdoDevice;
3226 PUSBHUB_PORT_PDO_EXTENSION PortExtension;
3227 PUSBHUB_PORT_DATA PortData;
3228 ULONG Port;
3230
3231 DPRINT("USBH_CheckIdleAbort: ... \n");
3232
3233 InterlockedIncrement(&HubExtension->PendingRequestCount);
3234
3235 if (IsWait == TRUE)
3236 {
3237 KeWaitForSingleObject(&HubExtension->ResetDeviceSemaphore,
3238 Executive,
3239 KernelMode,
3240 FALSE,
3241 NULL);
3242 }
3243
3244 PortData = HubExtension->PortData;
3245
3246 for (Port = 0; Port < HubExtension->HubDescriptor->bNumberOfPorts; Port++)
3247 {
3248 PdoDevice = PortData[Port].DeviceObject;
3249
3250 if (PdoDevice)
3251 {
3252 PortExtension = PdoDevice->DeviceExtension;
3253
3254 if (PortExtension->PoRequestCounter)
3255 {
3256 Result = TRUE;
3257 goto Wait;
3258 }
3259 }
3260 }
3261
3262 if (IsExtCheck == TRUE)
3263 {
3264 PortData = HubExtension->PortData;
3265
3266 for (Port = 0;
3267 Port < HubExtension->HubDescriptor->bNumberOfPorts;
3268 Port++)
3269 {
3270 PdoDevice = PortData[Port].DeviceObject;
3271
3272 if (PdoDevice)
3273 {
3274 PortExtension = PdoDevice->DeviceExtension;
3275 InterlockedExchange(&PortExtension->StateBehindD2, 0);
3276 }
3277 }
3278 }
3279
3280Wait:
3281
3282 if (IsWait == TRUE)
3283 {
3284 KeReleaseSemaphore(&HubExtension->ResetDeviceSemaphore,
3286 1,
3287 FALSE);
3288 }
3289
3290 if (!InterlockedDecrement(&HubExtension->PendingRequestCount))
3291 {
3292 KeSetEvent(&HubExtension->PendingRequestEvent,
3294 FALSE);
3295 }
3296
3297 return Result;
3298}
#define InterlockedExchange
Definition: armddk.h:54
_In_ WDFDPC _In_ BOOLEAN Wait
Definition: wdfdpc.h:170
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:409

Referenced by USBH_FdoIdleNotificationCallback(), and USBH_FdoPower().

◆ USBH_CheckIdleDeferred()

VOID NTAPI USBH_CheckIdleDeferred ( IN PUSBHUB_FDO_EXTENSION  HubExtension)

Definition at line 3957 of file usbhub.c.

3958{
3959 PUSBHUB_IO_WORK_ITEM HubIoWorkItem;
3961
3962 DPRINT("USBH_CheckIdleDeferred: HubExtension - %p\n", HubExtension);
3963
3964 Status = USBH_AllocateWorkItem(HubExtension,
3965 &HubIoWorkItem,
3967 0,
3968 NULL,
3970
3971 DPRINT("USBH_CheckIdleDeferred: HubIoWorkItem - %p\n", HubIoWorkItem);
3972
3973 if (NT_SUCCESS(Status))
3974 {
3975 USBH_QueueWorkItem(HubExtension, HubIoWorkItem);
3976 }
3977}
VOID NTAPI USBH_CheckIdleWorker(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PVOID Context)
Definition: usbhub.c:3948
NTSTATUS NTAPI USBH_AllocateWorkItem(PUSBHUB_FDO_EXTENSION HubExtension, PUSBHUB_IO_WORK_ITEM *OutHubIoWorkItem, PUSBHUB_WORKER_ROUTINE WorkerRoutine, SIZE_T BufferLength, PVOID *OutHubWorkItemBuffer, WORK_QUEUE_TYPE Type)
Definition: usbhub.c:2791
VOID NTAPI USBH_QueueWorkItem(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PUSBHUB_IO_WORK_ITEM HubIoWorkItem)
Definition: usbhub.c:2917
@ DelayedWorkQueue
Definition: extypes.h:190

Referenced by USBH_FdoDeferPoRequestCompletion(), USBH_FdoPnP(), USBH_FdoPower(), USBH_PdoRemoveDevice(), and USBH_PortIdleNotificationRequest().

◆ USBH_CompleteIrp()

VOID NTAPI USBH_CompleteIrp ( IN PIRP  Irp,
IN NTSTATUS  CompleteStatus 
)

◆ USBH_CompletePowerIrp()

VOID NTAPI USBH_CompletePowerIrp ( IN PUSBHUB_FDO_EXTENSION  HubExtension,
IN PIRP  Irp,
IN NTSTATUS  NtStatus 
)

Definition at line 18 of file power.c.

21{
22 DPRINT("USBH_CompletePowerIrp: HubExtension - %p, Irp - %p, NtStatus - %lX\n",
23 HubExtension,
24 Irp,
25 NtStatus);
26
27 Irp->IoStatus.Status = NtStatus;
28
30
31 if (!InterlockedDecrement(&HubExtension->PendingRequestCount))
32 {
33 KeSetEvent(&HubExtension->PendingRequestEvent,
35 FALSE);
36 }
37
39}
VOID NTAPI PoStartNextPowerIrp(IN PIRP Irp)
Definition: power.c:758

Referenced by USBH_FdoCleanup(), and USBH_PdoRemoveDevice().

◆ USBH_CreateDevice()

NTSTATUS NTAPI USBH_CreateDevice ( IN PUSBHUB_FDO_EXTENSION  HubExtension,
IN USHORT  Port,
IN USB_PORT_STATUS  UsbPortStatus,
IN ULONG  IsWait 
)

Definition at line 4379 of file usbhub.c.

4383{
4384 ULONG PdoNumber = 0;
4385 WCHAR CharDeviceName[64];
4388 PUSBHUB_PORT_PDO_EXTENSION PortExtension;
4390 LPWSTR SerialNumberBuffer;
4391 BOOLEAN IsHsDevice;
4392 BOOLEAN IsLsDevice;
4393 BOOLEAN IgnoringHwSerial = FALSE;
4396
4397 DPRINT("USBH_CreateDevice: Port - %x, UsbPortStatus - %lX\n",
4398 Port,
4399 UsbPortStatus.AsUshort16);
4400
4401 do
4402 {
4403 RtlStringCbPrintfW(CharDeviceName,
4404 sizeof(CharDeviceName),
4405 L"\\Device\\USBPDO-%d",
4406 PdoNumber);
4407
4408 RtlInitUnicodeString(&DeviceName, CharDeviceName);
4409
4410 Status = IoCreateDevice(HubExtension->Common.SelfDevice->DriverObject,
4412 &DeviceName,
4414 0,
4415 FALSE,
4416 &DeviceObject);
4417
4418 ++PdoNumber;
4419 }
4421
4422 if (!NT_SUCCESS(Status))
4423 {
4424 ASSERT(Port > 0);
4425 HubExtension->PortData[Port-1].DeviceObject = DeviceObject;
4426 return Status;
4427 }
4428
4429 DeviceObject->StackSize = HubExtension->RootHubPdo2->StackSize;
4430
4431 PortExtension = DeviceObject->DeviceExtension;
4432
4433 DPRINT("USBH_CreateDevice: PortDevice - %p, <%wZ>\n", DeviceObject, &DeviceName);
4434 DPRINT("USBH_CreateDevice: PortExtension - %p\n", PortExtension);
4435
4436 RtlZeroMemory(PortExtension, sizeof(USBHUB_PORT_PDO_EXTENSION));
4437
4439 PortExtension->Common.SelfDevice = DeviceObject;
4440
4441 PortExtension->HubExtension = HubExtension;
4442 PortExtension->RootHubExtension = HubExtension;
4443
4444 PortExtension->PortNumber = Port;
4446 PortExtension->IgnoringHwSerial = FALSE;
4447
4449
4450 InitializeListHead(&PortExtension->PortPowerList);
4452
4453 PortExtension->PoRequestCounter = 0;
4454 PortExtension->PendingSystemPoRequest = 0;
4455 PortExtension->PendingDevicePoRequest = 0;
4456 PortExtension->StateBehindD2 = 0;
4457
4458 SerialNumberBuffer = NULL;
4459
4460 IsHsDevice = UsbPortStatus.Usb20PortStatus.HighSpeedDeviceAttached;
4461 IsLsDevice = UsbPortStatus.Usb20PortStatus.LowSpeedDeviceAttached;
4462
4463 if (IsLsDevice == 0)
4464 {
4465 if (IsHsDevice)
4466 {
4468 }
4469 }
4470 else
4471 {
4473 }
4474
4475 /* Initialize PortExtension->InstanceID */
4479
4481 DeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
4482
4483 if (!NT_SUCCESS(Status))
4484 {
4485 DPRINT1("USBH_CreateDevice: IoCreateDevice() failed - %lX\n", Status);
4486 goto ErrorExit;
4487 }
4488
4489 Status = USBD_CreateDeviceEx(HubExtension,
4490 &PortExtension->DeviceHandle,
4491 UsbPortStatus,
4492 Port);
4493
4494 if (!NT_SUCCESS(Status))
4495 {
4496 DPRINT1("USBH_CreateDevice: USBD_CreateDeviceEx() failed - %lX\n", Status);
4497 goto ErrorExit;
4498 }
4499
4500 Status = USBH_SyncResetPort(HubExtension, Port);
4501
4502 if (!NT_SUCCESS(Status))
4503 {
4504 DPRINT1("USBH_CreateDevice: USBH_SyncResetPort() failed - %lX\n", Status);
4505 goto ErrorExit;
4506 }
4507
4508 if (IsWait)
4509 {
4510 USBH_Wait(50);
4511 }
4512
4513 Status = USBD_InitializeDeviceEx(HubExtension,
4514 PortExtension->DeviceHandle,
4515 (PUCHAR)&PortExtension->DeviceDescriptor,
4516 sizeof(USB_DEVICE_DESCRIPTOR),
4517 (PUCHAR)&PortExtension->ConfigDescriptor,
4519
4520 if (!NT_SUCCESS(Status))
4521 {
4522 DPRINT1("USBH_CreateDevice: USBD_InitializeDeviceEx() failed - %lX\n", Status);
4523 PortExtension->DeviceHandle = NULL;
4524 goto ErrorExit;
4525 }
4526
4527 DPRINT1("USBH_RegQueryDeviceIgnoreHWSerNumFlag UNIMPLEMENTED. FIXME\n");
4528 //Status = USBH_RegQueryDeviceIgnoreHWSerNumFlag(PortExtension->DeviceDescriptor.idVendor,
4529 // PortExtension->DeviceDescriptor.idProduct,
4530 // &IgnoringHwSerial);
4531
4532 if (TRUE)//Status == STATUS_OBJECT_NAME_NOT_FOUND)
4533 {
4534 IgnoringHwSerial = FALSE;
4535 }
4536
4537 if (IgnoringHwSerial)
4538 {
4539 PortExtension->IgnoringHwSerial = TRUE;
4540 }
4541
4542 if (PortExtension->DeviceDescriptor.iSerialNumber &&
4543 !PortExtension->IgnoringHwSerial)
4544 {
4546
4548 &SerialNumberBuffer,
4549 &PortExtension->SN_DescriptorLength,
4551 PortExtension->DeviceDescriptor.iSerialNumber);
4552
4553 if (SerialNumberBuffer)
4554 {
4555 if (!USBH_ValidateSerialNumberString((PUSHORT)SerialNumberBuffer))
4556 {
4557 ExFreePoolWithTag(SerialNumberBuffer, USB_HUB_TAG);
4558 SerialNumberBuffer = NULL;
4559 }
4560
4561 if (SerialNumberBuffer &&
4562 !USBH_CheckDeviceIDUnique(HubExtension,
4563 PortExtension->DeviceDescriptor.idVendor,
4564 PortExtension->DeviceDescriptor.idProduct,
4565 SerialNumberBuffer,
4566 PortExtension->SN_DescriptorLength))
4567 {
4568 ExFreePoolWithTag(SerialNumberBuffer, USB_HUB_TAG);
4569 SerialNumberBuffer = NULL;
4570 }
4571 }
4572
4574 SerialNumberBuffer);
4575 }
4576
4577 Status = USBH_ProcessDeviceInformation(PortExtension);
4578
4579 USBH_PdoSetCapabilities(PortExtension);
4580
4581 if (NT_SUCCESS(Status))
4582 {
4583 goto Exit;
4584 }
4585
4586ErrorExit:
4587
4589
4591 NULL);
4592
4593 if (DeviceHandle)
4594 {
4595 USBD_RemoveDeviceEx(HubExtension, DeviceHandle, 0);
4596 }
4597
4598 SerialNumberBuffer = InterlockedExchangePointer((PVOID)&PortExtension->SerialNumber,
4599 NULL);
4600
4601 if (SerialNumberBuffer)
4602 {
4603 ExFreePoolWithTag(SerialNumberBuffer, USB_HUB_TAG);
4604 }
4605
4606Exit:
4607
4608 ASSERT(Port > 0);
4609 HubExtension->PortData[Port-1].DeviceObject = DeviceObject;
4610 return Status;
4611}
#define InterlockedExchangePointer(Target, Value)
Definition: dshow.h:45
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define KeInitializeSpinLock(sl)
Definition: env_spec_w32.h:604
#define ASSERT(a)
Definition: mode.c:44
_Out_ _Inout_ POEM_STRING DestinationString
Definition: rtlfuncs.h:1909
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
NTSYSAPI NTSTATUS NTAPI RtlIntegerToUnicodeString(ULONG Value, ULONG Base, PUNICODE_STRING String)
@ PowerDeviceD0
Definition: ntpoapi.h:49
NTSTRSAFEVAPI RtlStringCbPrintfW(_Out_writes_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PWSTR pszDest, _In_ size_t cbDest, _In_ _Printf_format_string_ NTSTRSAFE_PCWSTR pszFormat,...)
Definition: ntstrsafe.h:1173
#define MAKELANGID(p, s)
Definition: nls.h:15
#define LANG_ENGLISH
Definition: nls.h:52
#define SUBLANG_ENGLISH_US
Definition: nls.h:222
PDEVICE_OBJECT SelfDevice
Definition: usbhub.h:144
unsigned short MaximumLength
Definition: sprintf.c:452
LIST_ENTRY PortPowerList
Definition: usbhub.h:233
KSPIN_LOCK PortPowerListSpinLock
Definition: usbhub.h:234
USB_DEVICE_DESCRIPTOR DeviceDescriptor
Definition: usbhub.h:216
PUSB_DEVICE_HANDLE DeviceHandle
Definition: usbhub.h:211
PUSBHUB_FDO_EXTENSION HubExtension
Definition: usbhub.h:209
COMMON_DEVICE_EXTENSION Common
Definition: usbhub.h:204
PUSBHUB_FDO_EXTENSION RootHubExtension
Definition: usbhub.h:210
USB_CONFIGURATION_DESCRIPTOR ConfigDescriptor
Definition: usbhub.h:218
KSPIN_LOCK PortTimeoutSpinLock
Definition: usbhub.h:226
POWER_STATE CurrentPowerState
Definition: usbhub.h:222
static VOID ErrorExit(LPTSTR lpszMessage)
Definition: telnetd.c:647
const uint16_t * PCWSTR
Definition: typedefs.h:57
uint16_t * PUSHORT
Definition: typedefs.h:56
unsigned char * PUCHAR
Definition: typedefs.h:53
#define STATUS_OBJECT_NAME_COLLISION
Definition: udferr_usr.h:150
DEVICE_POWER_STATE DeviceState
Definition: ntpoapi.h:58
VOID NTAPI USBH_PdoSetCapabilities(IN PUSBHUB_PORT_PDO_EXTENSION PortExtension)
Definition: usbhub.c:3981
NTSTATUS NTAPI USBD_RemoveDeviceEx(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PUSB_DEVICE_HANDLE DeviceHandle, IN ULONG Flags)
Definition: usbhub.c:2538
NTSTATUS NTAPI USBH_ProcessDeviceInformation(IN PUSBHUB_PORT_PDO_EXTENSION PortExtension)
Definition: usbhub.c:4056
NTSTATUS NTAPI USBH_Wait(IN ULONG Milliseconds)
Definition: usbhub.c:23
NTSTATUS NTAPI USBD_InitializeDeviceEx(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PUSB_DEVICE_HANDLE DeviceHandle, IN PUCHAR DeviceDescriptorBuffer, IN ULONG DeviceDescriptorBufferLength, IN PUCHAR ConfigDescriptorBuffer, IN ULONG ConfigDescriptorBufferLength)
Definition: usbhub.c:2562
BOOLEAN NTAPI USBH_ValidateSerialNumberString(IN PUSHORT SerialNumberString)
Definition: usbhub.c:4219
NTSTATUS NTAPI USBD_CreateDeviceEx(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PUSB_DEVICE_HANDLE *OutDeviceHandle, IN USB_PORT_STATUS UsbPortStatus, IN USHORT Port)
Definition: usbhub.c:2508
NTSTATUS NTAPI USBH_SyncResetPort(IN PUSBHUB_FDO_EXTENSION HubExtension, IN USHORT Port)
Definition: usbhub.c:471
BOOLEAN NTAPI USBH_CheckDeviceIDUnique(IN PUSBHUB_FDO_EXTENSION HubExtension, IN USHORT idVendor, IN USHORT idProduct, IN PVOID SerialNumber, IN USHORT SN_DescriptorLength)
Definition: usbhub.c:4167
NTSTATUS NTAPI USBH_GetSerialNumberString(IN PDEVICE_OBJECT DeviceObject, IN LPWSTR *OutSerialNumber, IN PUSHORT OutDescriptorLength, IN USHORT LanguageId, IN UCHAR Index)
Definition: usbhub.c:4304
#define USBHUB_PDO_FLAG_PORT_HIGH_SPEED
Definition: usbhub.h:81
#define USBHUB_PDO_FLAG_PORT_LOW_SPEED
Definition: usbhub.h:64
#define USBH_EXTENSION_TYPE_PORT
Definition: usbhub.h:29
#define USBHUB_PDO_FLAG_INIT_PORT_FAILED
Definition: usbhub.h:63
#define FILE_DEVICE_USB
Definition: usbiodef.h:71
#define DO_POWER_PAGABLE
WCHAR * LPWSTR
Definition: xmlstorage.h:184

Referenced by USBH_FdoQueryBusRelations().

◆ USBH_DeviceControl()

NTSTATUS NTAPI USBH_DeviceControl ( IN PUSBHUB_FDO_EXTENSION  HubExtension,
IN PIRP  Irp 
)

Definition at line 1136 of file ioctl.c.

1138{
1140 PIO_STACK_LOCATION IoStack;
1142 BOOLEAN IsCheckHubIdle = FALSE;
1143
1144 DPRINT("USBH_DeviceControl: HubExtension - %p, Irp - %p\n",
1145 HubExtension,
1146 Irp);
1147
1149 ControlCode = IoStack->Parameters.DeviceIoControl.IoControlCode;
1150 DPRINT("USBH_DeviceControl: ControlCode - %lX\n", ControlCode);
1151
1152 if ((HubExtension->CurrentPowerState.DeviceState != PowerDeviceD0) &&
1153 (HubExtension->HubFlags & USBHUB_FDO_FLAG_DEVICE_STARTED))
1154 {
1155 IsCheckHubIdle = TRUE;
1156 USBH_HubSetD0(HubExtension);
1157 }
1158
1159 switch (ControlCode)
1160 {
1161 case IOCTL_USB_GET_HUB_CAPABILITIES:
1162 DPRINT("USBH_DeviceControl: IOCTL_USB_GET_HUB_CAPABILITIES\n");
1163 if (!(HubExtension->HubFlags & USBHUB_FDO_FLAG_DEVICE_STOPPED))
1164 {
1165 Status = USBH_IoctlGetHubCapabilities(HubExtension, Irp);
1166 break;
1167 }
1168
1170 break;
1171
1172 case IOCTL_USB_HUB_CYCLE_PORT:
1173 DPRINT1("USBH_DeviceControl: IOCTL_USB_HUB_CYCLE_PORT UNIMPLEMENTED. FIXME\n");
1174 DbgBreakPoint();
1175 break;
1176
1178 DPRINT("USBH_DeviceControl: IOCTL_USB_GET_NODE_INFORMATION\n");
1179 if (!(HubExtension->HubFlags & USBHUB_FDO_FLAG_DEVICE_STOPPED))
1180 {
1181 Status = USBH_IoctlGetNodeInformation(HubExtension, Irp);
1182 break;
1183 }
1184
1186 break;
1187
1189 DPRINT("USBH_DeviceControl: IOCTL_USB_GET_NODE_CONNECTION_INFORMATION\n");
1190 if (!(HubExtension->HubFlags & USBHUB_FDO_FLAG_DEVICE_STOPPED))
1191 {
1193 Irp,
1194 FALSE);
1195 break;
1196 }
1197
1199 break;
1200
1201 case IOCTL_USB_GET_NODE_CONNECTION_INFORMATION_EX:
1202 DPRINT("USBH_DeviceControl: IOCTL_USB_GET_NODE_CONNECTION_INFORMATION_EX\n");
1203 if (!(HubExtension->HubFlags & USBHUB_FDO_FLAG_DEVICE_STOPPED))
1204 {
1206 Irp,
1207 TRUE);
1208 break;
1209 }
1210
1212 break;
1213
1214 case IOCTL_USB_GET_NODE_CONNECTION_ATTRIBUTES:
1215 DPRINT("USBH_DeviceControl: IOCTL_USB_GET_NODE_CONNECTION_ATTRIBUTES\n");
1216 if (!(HubExtension->HubFlags & USBHUB_FDO_FLAG_DEVICE_STOPPED))
1217 {
1219 break;
1220 }
1221
1223 break;
1224
1226 DPRINT("USBH_DeviceControl: IOCTL_USB_GET_NODE_CONNECTION_NAME\n");
1227 if (!(HubExtension->HubFlags & USBHUB_FDO_FLAG_DEVICE_STOPPED))
1228 {
1229 Status = USBH_IoctlGetNodeName(HubExtension, Irp);
1230 break;
1231 }
1232
1234 break;
1235
1237 DPRINT("USBH_DeviceControl: IOCTL_USB_GET_NODE_CONNECTION_DRIVERKEY_NAME\n");
1238 if (!(HubExtension->HubFlags & USBHUB_FDO_FLAG_DEVICE_STOPPED))
1239 {
1241 break;
1242 }
1243
1245 break;
1246
1248 DPRINT("USBH_DeviceControl: IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION\n");
1249 if (!(HubExtension->HubFlags & USBHUB_FDO_FLAG_DEVICE_STOPPED))
1250 {
1251 Status = USBH_IoctlGetDescriptor(HubExtension, Irp);
1252 break;
1253 }
1254
1256 break;
1257
1258 case IOCTL_KS_PROPERTY:
1259 DPRINT("USBH_DeviceControl: IOCTL_KS_PROPERTY\n");
1262 break;
1263
1264 default:
1265 DPRINT1("USBH_DeviceControl: Unhandled IOCTL_ - %lX\n", ControlCode);
1266 Status = USBH_PassIrp(HubExtension->RootHubPdo, Irp);
1267 break;
1268 }
1269
1270 if (IsCheckHubIdle)
1271 {
1272 USBH_CheckHubIdle(HubExtension);
1273 }
1274
1275 return Status;
1276}
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
NTSTATUS NTAPI USBH_IoctlGetNodeName(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PIRP Irp)
Definition: ioctl.c:563
NTSTATUS NTAPI USBH_IoctlGetNodeConnectionInformation(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PIRP Irp, IN BOOLEAN IsExt)
Definition: ioctl.c:834
NTSTATUS NTAPI USBH_IoctlGetNodeConnectionAttributes(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PIRP Irp)
Definition: ioctl.c:779
NTSTATUS NTAPI USBH_IoctlGetHubCapabilities(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PIRP Irp)
Definition: ioctl.c:731
NTSTATUS NTAPI USBH_IoctlGetDescriptor(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PIRP Irp)
Definition: ioctl.c:1024
NTSTATUS NTAPI USBH_IoctlGetNodeConnectionDriverKeyName(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PIRP Irp)
Definition: ioctl.c:947
NTSTATUS NTAPI USBH_IoctlGetNodeInformation(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PIRP Irp)
Definition: ioctl.c:684
NTSTATUS NTAPI USBH_HubSetD0(IN PUSBHUB_FDO_EXTENSION HubExtension)
Definition: power.c:77
NTSYSAPI void WINAPI DbgBreakPoint(void)
#define IOCTL_KS_PROPERTY
Definition: ks.h:127
struct _IO_STACK_LOCATION::@1564::@1565 DeviceIoControl
union _IO_STACK_LOCATION::@1564 Parameters
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
#define STATUS_DEVICE_BUSY
Definition: udferr_usr.h:129
VOID NTAPI USBH_CheckHubIdle(IN PUSBHUB_FDO_EXTENSION HubExtension)
Definition: usbhub.c:3808
VOID NTAPI USBH_CompleteIrp(IN PIRP Irp, IN NTSTATUS CompleteStatus)
Definition: usbhub.c:63
NTSTATUS NTAPI USBH_PassIrp(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: usbhub.c:79
#define USBHUB_FDO_FLAG_DEVICE_STOPPED
Definition: usbhub.h:37
#define IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION
Definition: usbioctl.h:175
#define IOCTL_USB_GET_NODE_CONNECTION_DRIVERKEY_NAME
Definition: usbioctl.h:187
#define IOCTL_USB_GET_NODE_CONNECTION_INFORMATION
Definition: usbioctl.h:172
#define IOCTL_USB_GET_NODE_INFORMATION
Definition: usbioctl.h:169
#define IOCTL_USB_GET_NODE_CONNECTION_NAME
Definition: usbioctl.h:178
_IRQL_requires_same_ typedef _In_ ULONG ControlCode
Definition: wmitypes.h:55

Referenced by USBH_FdoDispatch().

◆ USBH_FdoPnP()

NTSTATUS NTAPI USBH_FdoPnP ( IN PUSBHUB_FDO_EXTENSION  HubExtension,
IN PIRP  Irp,
IN UCHAR  Minor 
)

Definition at line 2362 of file pnp.c.

2365{
2367 PIO_STACK_LOCATION IoStack;
2368 DEVICE_RELATION_TYPE RelationsType;
2369 BOOLEAN IsCheckIdle;
2370
2371 DPRINT_PNP("USBH_FdoPnP: HubExtension - %p, Irp - %p, Minor - %X\n",
2372 HubExtension,
2373 Irp,
2374 Minor);
2375
2376 if (HubExtension->HubFlags & USBHUB_FDO_FLAG_WAIT_IDLE_REQUEST &&
2378 {
2379 HubExtension->HubFlags |= USBHUB_FDO_FLAG_DEVICE_SUSPENDED;
2380 }
2381
2382 KeWaitForSingleObject(&HubExtension->IdleSemaphore,
2383 Executive,
2384 KernelMode,
2385 FALSE,
2386 NULL);
2387
2388 DPRINT_PNP("USBH_FdoPnP: HubFlags - %lX\n", HubExtension->HubFlags);
2389
2390 if (HubExtension->HubFlags & USBHUB_FDO_FLAG_GOING_IDLE)
2391 {
2392 HubExtension->HubFlags |= USBHUB_FDO_FLAG_DEVICE_SUSPENDED;
2393 }
2394
2396 RelationsType = IoStack->Parameters.QueryDeviceRelations.Type;
2397
2398 if ((HubExtension->CurrentPowerState.DeviceState == PowerDeviceD0) ||
2399 !(HubExtension->HubFlags & (USBHUB_FDO_FLAG_DEVICE_STOPPED | USBHUB_FDO_FLAG_DEVICE_STARTED)) ||
2401 {
2402 IsCheckIdle = FALSE;
2403 }
2404 else
2405 {
2406 DPRINT_PNP("USBH_FdoPnP: IsCheckIdle - TRUE\n");
2407 IsCheckIdle = TRUE;
2408 USBH_HubSetD0(HubExtension);
2409 }
2410
2411 switch (Minor)
2412 {
2414 DPRINT_PNP("FDO IRP_MN_START_DEVICE\n");
2415 IsCheckIdle = FALSE;
2416 Irp->IoStatus.Status = STATUS_SUCCESS;
2417 Status = USBH_FdoStartDevice(HubExtension, Irp);
2418 break;
2419
2421 DPRINT_PNP("FDO IRP_MN_QUERY_REMOVE_DEVICE\n");
2422 Irp->IoStatus.Status = STATUS_SUCCESS;
2423 Status = USBH_PassIrp(HubExtension->LowerDevice, Irp);
2424 break;
2425
2427 DPRINT_PNP("FDO IRP_MN_REMOVE_DEVICE\n");
2428 IsCheckIdle = FALSE;
2429 HubExtension->HubFlags |= USBHUB_FDO_FLAG_DEVICE_REMOVED;
2430 Irp->IoStatus.Status = STATUS_SUCCESS;
2431 Status = USBH_FdoRemoveDevice(HubExtension, Irp);
2432 break;
2433
2435 DPRINT_PNP("FDO IRP_MN_CANCEL_REMOVE_DEVICE\n");
2436 Irp->IoStatus.Status = STATUS_SUCCESS;
2437 Status = USBH_PassIrp(HubExtension->LowerDevice, Irp);
2438 break;
2439
2440 case IRP_MN_STOP_DEVICE:
2441 DPRINT_PNP("FDO IRP_MN_STOP_DEVICE\n");
2442 IsCheckIdle = FALSE;
2443 Irp->IoStatus.Status = STATUS_SUCCESS;
2444 Status = USBH_FdoStopDevice(HubExtension, Irp);
2445 break;
2446
2448 DPRINT_PNP("FDO IRP_MN_QUERY_STOP_DEVICE\n");
2449 Irp->IoStatus.Status = STATUS_SUCCESS;
2450 Status = USBH_PassIrp(HubExtension->LowerDevice, Irp);
2451 break;
2452
2454 DPRINT_PNP("FDO IRP_MN_CANCEL_STOP_DEVICE\n");
2455 Irp->IoStatus.Status = STATUS_SUCCESS;
2456 Status = USBH_PassIrp(HubExtension->LowerDevice, Irp);
2457 break;
2458
2460 DPRINT_PNP("FDO IRP_MN_QUERY_DEVICE_RELATIONS\n");
2461
2462 if (RelationsType != BusRelations)
2463 {
2464 Status = USBH_PassIrp(HubExtension->LowerDevice, Irp);
2465 break;
2466 }
2467
2468 HubExtension->HubFlags |= USBHUB_FDO_FLAG_HUB_BUSY;
2469
2470 IsCheckIdle = TRUE;
2471 DPRINT_PNP("USBH_FdoPnP: IsCheckIdle - TRUE\n");
2472
2473 Status = USBH_FdoQueryBusRelations(HubExtension, Irp);
2474
2475 HubExtension->HubFlags &= ~USBHUB_FDO_FLAG_HUB_BUSY;
2476 break;
2477
2479 DPRINT_PNP("FDO IRP_MN_QUERY_INTERFACE\n");
2480 Status = USBH_PassIrp(HubExtension->LowerDevice, Irp);
2481 break;
2482
2484 DPRINT_PNP("FDO IRP_MN_QUERY_CAPABILITIES\n");
2486
2489 HubExtension,
2490 TRUE,
2491 FALSE,
2492 FALSE);
2493
2494 Status = IoCallDriver(HubExtension->LowerDevice, Irp);
2495 break;
2496
2498 DPRINT_PNP("FDO IRP_MN_QUERY_RESOURCES\n");
2499 Status = USBH_PassIrp(HubExtension->LowerDevice, Irp);
2500 break;
2501
2503 DPRINT_PNP("FDO IRP_MN_QUERY_RESOURCE_REQUIREMENTS\n");
2504 Status = USBH_PassIrp(HubExtension->LowerDevice, Irp);
2505 break;
2506
2508 DPRINT_PNP("FDO IRP_MN_QUERY_DEVICE_TEXT\n");
2509 Status = USBH_PassIrp(HubExtension->LowerDevice, Irp);
2510 break;
2511
2513 DPRINT_PNP("FDO IRP_MN_FILTER_RESOURCE_REQUIREMENTS\n");
2514 Status = USBH_PassIrp(HubExtension->LowerDevice, Irp);
2515 break;
2516
2517 case IRP_MN_READ_CONFIG:
2518 DPRINT_PNP("FDO IRP_MN_READ_CONFIG\n");
2519 Status = USBH_PassIrp(HubExtension->LowerDevice, Irp);
2520 break;
2521
2523 DPRINT_PNP("FDO IRP_MN_WRITE_CONFIG\n");
2524 Status = USBH_PassIrp(HubExtension->LowerDevice, Irp);
2525 break;
2526
2527 case IRP_MN_EJECT:
2528 DPRINT_PNP("FDO IRP_MN_EJECT\n");
2529 Status = USBH_PassIrp(HubExtension->LowerDevice, Irp);
2530 break;
2531
2532 case IRP_MN_SET_LOCK:
2533 DPRINT_PNP("FDO IRP_MN_SET_LOCK\n");
2534 Status = USBH_PassIrp(HubExtension->LowerDevice, Irp);
2535 break;
2536
2537 case IRP_MN_QUERY_ID:
2538 DPRINT_PNP("FDO IRP_MN_QUERY_ID\n");
2539 Status = USBH_PassIrp(HubExtension->LowerDevice, Irp);
2540 break;
2541
2543 DPRINT_PNP("FDO IRP_MN_QUERY_PNP_DEVICE_STATE\n");
2544
2545 if (HubExtension->HubFlags & USBHUB_FDO_FLAG_DEVICE_FAILED)
2546 {
2547 Irp->IoStatus.Information |= PNP_DEVICE_FAILED;
2548 }
2549
2550 Status = USBH_PassIrp(HubExtension->LowerDevice, Irp);
2551 break;
2552
2554 DPRINT_PNP("FDO IRP_MN_QUERY_BUS_INFORMATION\n");
2555 Status = USBH_PassIrp(HubExtension->LowerDevice, Irp);
2556 break;
2557
2559 DPRINT_PNP("FDO IRP_MN_DEVICE_USAGE_NOTIFICATION\n");
2560 Irp->IoStatus.Status = STATUS_SUCCESS;
2561 Status = USBH_PassIrp(HubExtension->LowerDevice, Irp);
2562 break;
2563
2565 DPRINT_PNP("FDO IRP_MN_SURPRISE_REMOVAL\n");
2566 USBH_FdoSurpriseRemoveDevice(HubExtension, Irp);
2567 Status = USBH_PassIrp(HubExtension->LowerDevice, Irp);
2568 break;
2569
2570 default:
2571 DPRINT_PNP("FDO unknown IRP_MN_???\n");
2572 Status = USBH_PassIrp(HubExtension->LowerDevice, Irp);
2573 break;
2574 }
2575
2576 KeReleaseSemaphore(&HubExtension->IdleSemaphore,
2578 1,
2579 FALSE);
2580
2581 if (IsCheckIdle)
2582 {
2583 DPRINT_PNP("USBH_FdoPnP: call USBH_CheckIdleDeferred()\n");
2584 USBH_CheckIdleDeferred(HubExtension);
2585 }
2586
2587 HubExtension->HubFlags &= ~USBHUB_FDO_FLAG_STATE_CHANGING;
2588
2589 return Status;
2590}
#define DPRINT_PNP(...)
Definition: dbg_uhub.h:109
NTSTATUS NTAPI USBH_QueryCapsComplete(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context)
Definition: pnp.c:59
NTSTATUS NTAPI USBH_FdoStartDevice(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PIRP Irp)
Definition: pnp.c:988
NTSTATUS NTAPI USBH_FdoRemoveDevice(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PIRP Irp)
Definition: pnp.c:1463
NTSTATUS NTAPI USBH_FdoQueryBusRelations(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PIRP Irp)
Definition: pnp.c:1027
NTSTATUS NTAPI USBH_FdoStopDevice(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PIRP Irp)
Definition: pnp.c:1453
VOID NTAPI USBH_FdoSurpriseRemoveDevice(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PIRP Irp)
Definition: pnp.c:1524
#define IoSetCompletionRoutine(_Irp, _CompletionRoutine, _Context, _InvokeOnSuccess, _InvokeOnError, _InvokeOnCancel)
Definition: irp.cpp:490
#define IRP_MN_SURPRISE_REMOVAL
Definition: ntifs_ex.h:408
#define IoCopyCurrentIrpStackLocationToNext(Irp)
Definition: ntifs_ex.h:413
#define IoCallDriver
Definition: irp.c:1225
struct _IO_STACK_LOCATION::@3978::@4003 QueryDeviceRelations
VOID NTAPI USBH_CheckIdleDeferred(IN PUSBHUB_FDO_EXTENSION HubExtension)
Definition: usbhub.c:3957
#define USBHUB_FDO_FLAG_DEVICE_SUSPENDED
Definition: usbhub.h:58
#define USBHUB_FDO_FLAG_GOING_IDLE
Definition: usbhub.h:57
#define USBHUB_FDO_FLAG_HUB_BUSY
Definition: usbhub.h:38
_Out_opt_ PULONG Minor
Definition: cmfuncs.h:44
#define IRP_MN_CANCEL_STOP_DEVICE
@ BusRelations
Definition: iotypes.h:2152
@ TargetDeviceRelation
Definition: iotypes.h:2156
#define IRP_MN_QUERY_PNP_DEVICE_STATE
#define IRP_MN_EJECT
#define IRP_MN_QUERY_INTERFACE
#define IRP_MN_START_DEVICE
#define PNP_DEVICE_FAILED
Definition: iotypes.h:1003
#define IRP_MN_DEVICE_USAGE_NOTIFICATION
#define IRP_MN_READ_CONFIG
#define IRP_MN_WRITE_CONFIG
#define IRP_MN_QUERY_RESOURCE_REQUIREMENTS
#define IRP_MN_QUERY_ID
#define IRP_MN_REMOVE_DEVICE
#define IRP_MN_FILTER_RESOURCE_REQUIREMENTS
#define IRP_MN_QUERY_DEVICE_RELATIONS
#define IRP_MN_QUERY_STOP_DEVICE
#define IRP_MN_QUERY_DEVICE_TEXT
#define IRP_MN_QUERY_CAPABILITIES
#define IRP_MN_QUERY_RESOURCES
#define IRP_MN_CANCEL_REMOVE_DEVICE
#define IRP_MN_STOP_DEVICE
#define IRP_MN_SET_LOCK
enum _DEVICE_RELATION_TYPE DEVICE_RELATION_TYPE
#define IRP_MN_QUERY_BUS_INFORMATION
#define IRP_MN_QUERY_REMOVE_DEVICE

Referenced by USBH_FdoDispatch().

◆ USBH_FdoPower()

NTSTATUS NTAPI USBH_FdoPower ( IN PUSBHUB_FDO_EXTENSION  HubExtension,
IN PIRP  Irp,
IN UCHAR  Minor 
)

Definition at line 460 of file power.c.

463{
465 PIO_STACK_LOCATION IoStack;
467 POWER_STATE DevicePwrState;
468 BOOLEAN IsAllPortsD3;
469 PUSBHUB_PORT_DATA PortData;
470 PDEVICE_OBJECT PdoDevice;
471 PUSBHUB_PORT_PDO_EXTENSION PortExtension;
472 ULONG Port;
473
474 DPRINT_PWR("USBH_FdoPower: HubExtension - %p, Irp - %p, Minor - %X\n",
475 HubExtension,
476 Irp,
477 Minor);
478
479 switch (Minor)
480 {
481 case IRP_MN_WAIT_WAKE:
482 DPRINT_PWR("USBH_FdoPower: IRP_MN_WAIT_WAKE\n");
483
485
488 HubExtension,
489 TRUE,
490 TRUE,
491 TRUE);
492
495 PoCallDriver(HubExtension->LowerDevice, Irp);
496
497 return STATUS_PENDING;
498
500 DPRINT_PWR("USBH_FdoPower: IRP_MN_POWER_SEQUENCE\n");
501 break;
502
503 case IRP_MN_SET_POWER:
504 DPRINT_PWR("USBH_FdoPower: IRP_MN_SET_POWER\n");
505
507 DPRINT_PWR("USBH_FdoPower: IRP_MN_SET_POWER/DevicePowerState\n");
508 PowerState = IoStack->Parameters.Power.State;
509
510 if (IoStack->Parameters.Power.Type == DevicePowerState)
511 {
512 DPRINT_PWR("USBH_FdoPower: PowerState - %x\n",
513 PowerState.DeviceState);
514
515 if (HubExtension->CurrentPowerState.DeviceState == PowerState.DeviceState)
516 {
518
521 PoCallDriver(HubExtension->LowerDevice, Irp);
522
523 return STATUS_PENDING;
524 }
525
526 switch (PowerState.DeviceState)
527 {
528 case PowerDeviceD0:
529 if (!(HubExtension->HubFlags & USBHUB_FDO_FLAG_SET_D0_STATE))
530 {
531 HubExtension->HubFlags &= ~(USBHUB_FDO_FLAG_NOT_D0_STATE |
533
534 HubExtension->HubFlags |= USBHUB_FDO_FLAG_SET_D0_STATE;
535
537
540 HubExtension,
541 TRUE,
542 TRUE,
543 TRUE);
544 }
545 else
546 {
549 }
550
552 PoCallDriver(HubExtension->LowerDevice, Irp);
553 return STATUS_PENDING;
554
555 case PowerDeviceD1:
556 case PowerDeviceD2:
557 case PowerDeviceD3:
558 if (HubExtension->ResetRequestCount)
559 {
560 IoCancelIrp(HubExtension->ResetPortIrp);
561
562 KeWaitForSingleObject(&HubExtension->ResetEvent,
563 Executive,
565 FALSE,
566 NULL);
567 }
568
569 if (!(HubExtension->HubFlags & USBHUB_FDO_FLAG_DEVICE_STOPPED))
570 {
571 HubExtension->HubFlags |= (USBHUB_FDO_FLAG_NOT_D0_STATE |
573
574 IoCancelIrp(HubExtension->SCEIrp);
575
576 KeWaitForSingleObject(&HubExtension->StatusChangeEvent,
577 Executive,
579 FALSE,
580 NULL);
581 }
582
583 HubExtension->CurrentPowerState.DeviceState = PowerState.DeviceState;
584
585 if (HubExtension->HubFlags & USBHUB_FDO_FLAG_DO_SUSPENSE &&
586 USBH_CheckIdleAbort(HubExtension, TRUE, TRUE) == TRUE)
587 {
588 HubExtension->HubFlags &= ~(USBHUB_FDO_FLAG_NOT_D0_STATE |
590
591 HubExtension->CurrentPowerState.DeviceState = PowerDeviceD0;
592
594
596
597 Irp->IoStatus.Status = STATUS_UNSUCCESSFUL;
599
600 HubExtension->HubFlags &= ~USBHUB_FDO_FLAG_DO_SUSPENSE;
601
602 KeReleaseSemaphore(&HubExtension->IdleSemaphore,
604 1,
605 FALSE);
606
607 return STATUS_UNSUCCESSFUL;
608 }
609
611
614 HubExtension,
615 TRUE,
616 TRUE,
617 TRUE);
618
621 PoCallDriver(HubExtension->LowerDevice, Irp);
622
623 if (HubExtension->HubFlags & USBHUB_FDO_FLAG_DO_SUSPENSE)
624 {
625 HubExtension->HubFlags &= ~USBHUB_FDO_FLAG_DO_SUSPENSE;
626
627 KeReleaseSemaphore(&HubExtension->IdleSemaphore,
629 1,
630 FALSE);
631 }
632
633 return STATUS_PENDING;
634
635 default:
636 DPRINT1("USBH_FdoPower: Unsupported PowerState.DeviceState\n");
638 break;
639 }
640 }
641 else
642 {
643 if (PowerState.SystemState != PowerSystemWorking)
644 {
646 PowerState.SystemState;
647 }
648
649 if (PowerState.SystemState == PowerSystemHibernate)
650 {
651 HubExtension->HubFlags |= USBHUB_FDO_FLAG_HIBERNATE_STATE;
652 }
653
654 PortData = HubExtension->PortData;
655
656 IsAllPortsD3 = TRUE;
657
658 if (PortData && HubExtension->HubDescriptor)
659 {
660 for (Port = 0;
661 Port < HubExtension->HubDescriptor->bNumberOfPorts;
662 Port++)
663 {
664 PdoDevice = PortData[Port].DeviceObject;
665
666 if (PdoDevice)
667 {
668 PortExtension = PdoDevice->DeviceExtension;
669
670 if (PortExtension->CurrentPowerState.DeviceState != PowerDeviceD3)
671 {
672 IsAllPortsD3 = FALSE;
673 break;
674 }
675 }
676 }
677 }
678
679 if (PowerState.SystemState == PowerSystemWorking)
680 {
681 DevicePwrState.DeviceState = PowerDeviceD0;
682 }
683 else if (HubExtension->HubFlags & USBHUB_FDO_FLAG_PENDING_WAKE_IRP ||
684 !IsAllPortsD3)
685 {
686 DevicePwrState.DeviceState = HubExtension->DeviceState[PowerState.SystemState];
687
688 if (DevicePwrState.DeviceState == PowerDeviceUnspecified)
689 {
690 goto Exit;
691 }
692 }
693 else
694 {
695 DevicePwrState.DeviceState = PowerDeviceD3;
696 }
697
698 if (DevicePwrState.DeviceState != HubExtension->CurrentPowerState.DeviceState &&
699 HubExtension->HubFlags & USBHUB_FDO_FLAG_DEVICE_STARTED)
700 {
701 HubExtension->PowerIrp = Irp;
702
704
705 if (PoRequestPowerIrp(HubExtension->LowerPDO,
707 DevicePwrState,
709 (PVOID)HubExtension,
711 {
712 return STATUS_PENDING;
713 }
714
717 PoCallDriver(HubExtension->LowerDevice, Irp);
718
719 return STATUS_PENDING;
720 }
721
722 Exit:
723
724 HubExtension->SystemPowerState.SystemState = PowerState.SystemState;
725
726 if (PowerState.SystemState == PowerSystemWorking)
727 {
728 USBH_CheckIdleDeferred(HubExtension);
729 }
730
733
734 return PoCallDriver(HubExtension->LowerDevice, Irp);
735 }
736
737 break;
738
740 DPRINT_PWR("USBH_FdoPower: IRP_MN_QUERY_POWER\n");
741 break;
742
743 default:
744 DPRINT1("USBH_FdoPower: unknown IRP_MN_POWER!\n");
745 break;
746 }
747
750 Status = PoCallDriver(HubExtension->LowerDevice, Irp);
751
752 return Status;
753}
#define DPRINT_PWR(...)
Definition: dbg_uhub.h:108
NTSTATUS NTAPI USBH_PowerIrpCompletion(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context)
Definition: power.c:349
VOID NTAPI USBH_FdoDeferPoRequestCompletion(IN PDEVICE_OBJECT DeviceObject, IN UCHAR MinorFunction, IN POWER_STATE PowerState, IN PVOID Context, IN PIO_STATUS_BLOCK IoStatus)
Definition: power.c:422
NTSTATUS NTAPI USBH_FdoWWIrpIoCompletion(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context)
Definition: power.c:271
IoMarkIrpPending(Irp)
BOOLEAN NTAPI IoCancelIrp(IN PIRP Irp)
Definition: irp.c:1101
NTSTATUS NTAPI PoRequestPowerIrp(_In_ PDEVICE_OBJECT DeviceObject, _In_ UCHAR MinorFunction, _In_ POWER_STATE PowerState, _In_opt_ PREQUEST_POWER_COMPLETE CompletionFunction, _In_opt_ __drv_aliasesMem PVOID Context, _Outptr_opt_ PIRP *pIrp)
Definition: power.c:659
@ PowerSystemHibernate
Definition: ntpoapi.h:40
@ DevicePowerState
Definition: ntpoapi.h:63
@ PowerDeviceD1
Definition: ntpoapi.h:50
@ PowerDeviceUnspecified
Definition: ntpoapi.h:48
@ PowerDeviceD2
Definition: ntpoapi.h:51
@ PowerDeviceD3
Definition: ntpoapi.h:52
#define STATUS_PENDING
Definition: ntstatus.h:82
struct _IO_STACK_LOCATION::@3978::@4014 Power
POWER_STATE SystemPowerState
Definition: usbhub.h:161
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
SYSTEM_POWER_STATE SystemState
Definition: ntpoapi.h:57
NTSTATUS NTAPI USBH_SubmitStatusChangeTransfer(IN PUSBHUB_FDO_EXTENSION HubExtension)
Definition: usbhub.c:2442
BOOLEAN NTAPI USBH_CheckIdleAbort(IN PUSBHUB_FDO_EXTENSION HubExtension, IN BOOLEAN IsWait, IN BOOLEAN IsExtCheck)
Definition: usbhub.c:3221
#define USBHUB_FDO_FLAG_DO_SUSPENSE
Definition: usbhub.h:56
#define USBHUB_FDO_FLAG_HIBERNATE_STATE
Definition: usbhub.h:54
#define USBHUB_FDO_FLAG_NOT_D0_STATE
Definition: usbhub.h:43
#define USBHUB_FDO_FLAG_PENDING_WAKE_IRP
Definition: usbhub.h:39
#define USBHUB_FDO_FLAG_SET_D0_STATE
Definition: usbhub.h:42
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_ WDF_DEVICE_POWER_STATE PowerState
Definition: wdfdevice.h:3034
#define IRP_MN_WAIT_WAKE
#define IRP_MN_POWER_SEQUENCE
#define IRP_MN_SET_POWER
#define IRP_MN_QUERY_POWER

Referenced by USBH_FdoDispatch().

◆ USBH_FdoSyncSubmitUrb()

NTSTATUS NTAPI USBH_FdoSyncSubmitUrb ( IN PDEVICE_OBJECT  FdoDevice,
IN PURB  Urb 
)

Definition at line 355 of file usbhub.c.

357{
358 PUSBHUB_FDO_EXTENSION HubExtension;
359
360 DPRINT("USBH_FdoSyncSubmitUrb: FdoDevice - %p, Urb - %p\n",
361 FdoDevice,
362 Urb);
363
364 HubExtension = FdoDevice->DeviceExtension;
365 return USBH_SyncSubmitUrb(HubExtension->LowerDevice, Urb);
366}
PDEVICE_OBJECT LowerDevice
Definition: usbhub.h:150
NTSTATUS NTAPI USBH_SyncSubmitUrb(IN PDEVICE_OBJECT DeviceObject, IN PURB Urb)
Definition: usbhub.c:250

Referenced by USBH_AbortInterruptPipe(), USBH_GetDeviceDescriptor(), USBH_OpenConfiguration(), USBH_ResetInterruptPipe(), USBH_SyncGetDeviceConfigurationDescriptor(), USBH_SyncGetStatus(), and USBH_Transact().

◆ USBH_FreeWorkItem()

VOID NTAPI USBH_FreeWorkItem ( IN PUSBHUB_IO_WORK_ITEM  HubIoWorkItem)

Definition at line 2937 of file usbhub.c.

2938{
2940
2941 DPRINT("USBH_FreeWorkItem: ... \n");
2942
2943 WorkItem = HubIoWorkItem->HubWorkItem;
2944
2945 if (HubIoWorkItem->HubWorkItemBuffer)
2946 {
2947 ExFreePoolWithTag(HubIoWorkItem->HubWorkItemBuffer, USB_HUB_TAG);
2948 }
2949
2950 ExFreePoolWithTag(HubIoWorkItem, USB_HUB_TAG);
2951
2953}
VOID NTAPI IoFreeWorkItem(IN PIO_WORKITEM IoWorkItem)
Definition: iowork.c:64
_Must_inspect_result_ _In_ PWDF_WORKITEM_CONFIG _In_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFWORKITEM * WorkItem
Definition: wdfworkitem.h:115

Referenced by USBH_ChangeIndicationProcessChange().

◆ USBH_GetConfigurationDescriptor()

NTSTATUS NTAPI USBH_GetConfigurationDescriptor ( IN PDEVICE_OBJECT  DeviceObject,
IN PUSB_CONFIGURATION_DESCRIPTOR pConfigurationDescriptor 
)

Definition at line 974 of file usbhub.c.

976{
978 ULONG ReturnedLen;
979 SIZE_T DescriptorLen;
981
982 DPRINT("USBH_GetConfigurationDescriptor: ... \n");
983
984 DescriptorLen = MAXUCHAR;
985
986 while (TRUE)
987 {
989 DescriptorLen,
991
992 if (!ConfigDescriptor)
993 {
995 break;
996 }
997
1000 DescriptorLen,
1001 &ReturnedLen);
1002
1003 if (ReturnedLen < sizeof(USB_CONFIGURATION_DESCRIPTOR))
1004 {
1006 }
1007
1008 if (!NT_SUCCESS(Status))
1009 {
1010 break;
1011 }
1012
1013 *OutDescriptor = ConfigDescriptor;
1014
1015 if (ConfigDescriptor->wTotalLength <= DescriptorLen)
1016 {
1017 break;
1018 }
1019
1020 DescriptorLen = ConfigDescriptor->wTotalLength;
1021
1023 *OutDescriptor = NULL;
1024 }
1025
1026 if (NT_SUCCESS(Status))
1027 {
1028 if (ReturnedLen < ConfigDescriptor->wTotalLength)
1029 {
1031 }
1032 }
1033 else
1034 {
1035 if (ConfigDescriptor)
1036 {
1038 }
1039
1040 *OutDescriptor = NULL;
1041 }
1042
1043 return Status;
1044}
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
#define STATUS_DEVICE_DATA_ERROR
Definition: udferr_usr.h:159
#define MAXUCHAR
Definition: umtypes.h:117
NTSTATUS NTAPI USBH_SyncGetDeviceConfigurationDescriptor(IN PDEVICE_OBJECT DeviceObject, IN PUSB_CONFIGURATION_DESCRIPTOR ConfigDescriptor, IN ULONG NumberOfBytes, IN PULONG OutLength)
Definition: usbhub.c:913
_Must_inspect_result_ _In_ WDFUSBDEVICE _Out_writes_bytes_to_opt_ ConfigDescriptorLength PVOID ConfigDescriptor
Definition: wdfusb.h:1036

Referenced by USBH_ProcessDeviceInformation(), and USBH_StartHubFdoDevice().

◆ USBH_GetDeviceDescriptor()

NTSTATUS NTAPI USBH_GetDeviceDescriptor ( IN PDEVICE_OBJECT  DeviceObject,
IN PUSB_DEVICE_DESCRIPTOR  HubDeviceDescriptor 
)

Definition at line 877 of file usbhub.c.

879{
882
883 DPRINT("USBH_GetDeviceDescriptor: ... \n");
884
886 sizeof(struct _URB_CONTROL_DESCRIPTOR_REQUEST),
888
889 if (!Urb)
890 {
891 DPRINT1("USBH_SyncGetDeviceHandle: Urb - NULL!\n");
893 }
894
896
898 Urb->Hdr.Length = sizeof(struct _URB_CONTROL_DESCRIPTOR_REQUEST);
899
901 Urb->TransferBuffer = HubDeviceDescriptor;
903
905
907
908 return Status;
909}
struct _URB_HEADER Hdr
Definition: usb.h:341
Definition: usb.h:529
#define USB_DEVICE_DESCRIPTOR_TYPE
Definition: usb100.h:49
struct _USB_DEVICE_DESCRIPTOR USB_DEVICE_DESCRIPTOR
#define URB_FUNCTION_GET_DESCRIPTOR_FROM_DEVICE
Definition: usb.h:97
NTSTATUS NTAPI USBH_FdoSyncSubmitUrb(IN PDEVICE_OBJECT FdoDevice, IN PURB Urb)
Definition: usbhub.c:355

Referenced by USBH_StartHubFdoDevice().

◆ USBH_GetDeviceType()

NTSTATUS NTAPI USBH_GetDeviceType ( IN PUSBHUB_FDO_EXTENSION  HubExtension,
IN PUSB_DEVICE_HANDLE  DeviceHandle,
OUT USB_DEVICE_TYPE OutDeviceType 
)

Definition at line 608 of file usbhub.c.

611{
616 ULONG dummy;
618
619 DPRINT("USBH_GetDeviceType: ... \n");
620
621 QueryDeviceInformation = HubExtension->BusInterface.QueryDeviceInformation;
622
624 {
625 DPRINT1("USBH_GetDeviceType: no QueryDeviceInformation()\n");
627 }
628
630
631 while (TRUE)
632 {
636
637 if (!DeviceInfo)
638 {
639 DPRINT1("USBH_GetDeviceType: ExAllocatePoolWithTag() failed\n");
641 break;
642 }
643
645
646 DeviceInfo->InformationLevel = 0;
647
648 Status = QueryDeviceInformation(HubExtension->BusInterface.BusContext,
652 &dummy);
653
655 {
656 if (NT_SUCCESS(Status))
657 {
658 DeviceType = DeviceInfo->DeviceType;
659 }
660
662 break;
663 }
664
667 }
668
669 if (OutDeviceType)
670 {
671 *OutDeviceType = DeviceType;
672 DPRINT("USBH_GetDeviceType: DeviceType - %x\n", DeviceType);
673 }
674
675 return Status;
676}
_In_ PUSB_DEVICE_HANDLE _In_ ULONG DeviceInformationBufferLength
Definition: hubbusif.h:181
DeviceType
Definition: mmdrv.h:42
@ Usb11Device
Definition: usb200.h:37
enum _USB_DEVICE_TYPE USB_DEVICE_TYPE

Referenced by USBH_StartHubFdoDevice().

◆ USBH_GetRootHubExtension()

PUSBHUB_FDO_EXTENSION NTAPI USBH_GetRootHubExtension ( IN PUSBHUB_FDO_EXTENSION  HubExtension)

Definition at line 699 of file usbhub.c.

700{
702 PUSBHUB_FDO_EXTENSION RootHubExtension;
703
704 DPRINT("USBH_GetRootHubExtension: HubExtension - %p\n", HubExtension);
705
706 RootHubExtension = HubExtension;
707
708 if (HubExtension->LowerPDO != HubExtension->RootHubPdo)
709 {
710 Device = HubExtension->RootHubPdo;
711
712 do
713 {
714 Device = Device->AttachedDevice;
715 }
716 while (Device->DriverObject != HubExtension->Common.SelfDevice->DriverObject);
717
718 RootHubExtension = Device->DeviceExtension;
719 }
720
721 DPRINT("USBH_GetRootHubExtension: RootHubExtension - %p\n", RootHubExtension);
722
723 return RootHubExtension;
724}
PDEVICE_OBJECT RootHubPdo
Definition: usbhub.h:151
_Must_inspect_result_ _In_ WDFDEVICE Device
Definition: wdfchildlist.h:474

Referenced by USBH_CheckHubIdle(), USBH_FdoPower(), and USBH_HubSetD0().

◆ USBH_HubCancelIdleIrp()

VOID NTAPI USBH_HubCancelIdleIrp ( IN PUSBHUB_FDO_EXTENSION  HubExtension,
IN PIRP  IdleIrp 
)

Definition at line 3206 of file usbhub.c.

3208{
3209 DPRINT("USBH_HubCancelIdleIrp ... \n");
3210
3211 IoCancelIrp(IdleIrp);
3212
3213 if (InterlockedExchange(&HubExtension->IdleRequestLock, 1))
3214 {
3215 IoFreeIrp(IdleIrp);
3216 }
3217}
VOID NTAPI IoFreeIrp(IN PIRP Irp)
Definition: irp.c:1666

Referenced by USBH_FdoCleanup(), USBH_FdoIdleNotificationCallback(), USBH_HubQueuePortIdleIrps(), and USBH_PortIdleNotificationCancelRoutine().

◆ USBH_HubCancelWakeIrp()

VOID NTAPI USBH_HubCancelWakeIrp ( IN PUSBHUB_FDO_EXTENSION  HubExtension,
IN PIRP  Irp 
)

Definition at line 43 of file power.c.

45{
46 DPRINT("USBH_HubCancelWakeIrp: HubExtension - %p, Irp - %p\n",
47 HubExtension,
48 Irp);
49
51
52 if (InterlockedExchange((PLONG)&HubExtension->FdoWaitWakeLock, 1))
53 {
55 Irp->IoStatus.Status = STATUS_CANCELLED;
57 }
58}
int32_t * PLONG
Definition: typedefs.h:58
#define STATUS_CANCELLED
Definition: udferr_usr.h:170

Referenced by USBH_FdoCleanup().

◆ USBH_HubCompletePortWakeIrps()

VOID NTAPI USBH_HubCompletePortWakeIrps ( IN PUSBHUB_FDO_EXTENSION  HubExtension,
IN NTSTATUS  NtStatus 
)

Definition at line 217 of file power.c.

219{
220 LIST_ENTRY ListIrps;
221
222 DPRINT("USBH_HubCompletePortWakeIrps: NtStatus - %x\n", NtStatus);
223
224 if (HubExtension->HubFlags & USBHUB_FDO_FLAG_DEVICE_STARTED)
225 {
226 USBH_HubQueuePortWakeIrps(HubExtension, &ListIrps);
227
229 &ListIrps,
230 NtStatus);
231 }
232}
VOID NTAPI USBH_HubQueuePortWakeIrps(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PLIST_ENTRY ListIrps)
Definition: power.c:160
VOID NTAPI USBH_HubCompleteQueuedPortWakeIrps(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PLIST_ENTRY ListIrps, IN NTSTATUS NtStatus)
Definition: power.c:202
Definition: typedefs.h:120

Referenced by USBH_FdoCleanup(), and USBH_FdoPoRequestD0Completion().

◆ USBH_HubIsBusPowered()

BOOLEAN NTAPI USBH_HubIsBusPowered ( IN PDEVICE_OBJECT  DeviceObject,
IN PUSB_CONFIGURATION_DESCRIPTOR  HubConfigDescriptor 
)

Definition at line 1589 of file usbhub.c.

1591{
1593 USHORT UsbStatus;
1595
1596 DPRINT("USBH_HubIsBusPowered: ... \n");
1597
1599 &UsbStatus,
1601 0);
1602
1603 if (!NT_SUCCESS(Status))
1604 {
1605 Result = (HubConfigDescriptor->bmAttributes & USB_CONFIG_POWERED_MASK)
1607 }
1608 else
1609 {
1610 Result = (UsbStatus & USB_GETSTATUS_SELF_POWERED) == 0;
1611 }
1612
1613 return Result;
1614}
unsigned short USHORT
Definition: pedump.c:61
#define USB_GETSTATUS_SELF_POWERED
Definition: usb100.h:45
#define USB_CONFIG_BUS_POWERED
Definition: usb100.h:69
#define USB_CONFIG_POWERED_MASK
Definition: usb100.h:68
#define URB_FUNCTION_GET_STATUS_FROM_DEVICE
Definition: usb.h:105
NTSTATUS NTAPI USBH_SyncGetStatus(IN PDEVICE_OBJECT DeviceObject, IN PUSHORT OutStatus, IN USHORT Function, IN USHORT RequestIndex)
Definition: usbhub.c:1323

Referenced by USBH_IoctlGetNodeInformation(), and USBH_StartHubFdoDevice().

◆ USBH_HubSetD0()

NTSTATUS NTAPI USBH_HubSetD0 ( IN PUSBHUB_FDO_EXTENSION  HubExtension)

Definition at line 77 of file power.c.

78{
79 PUSBHUB_FDO_EXTENSION RootHubDevExt;
83
84 DPRINT("USBH_HubSetD0: HubExtension - %p\n", HubExtension);
85
86 RootHubDevExt = USBH_GetRootHubExtension(HubExtension);
87
89 {
91 return Status;
92 }
93
94 if (HubExtension->HubFlags & USBHUB_FDO_FLAG_WAIT_IDLE_REQUEST)
95 {
96 DPRINT("USBH_HubSetD0: HubFlags - %lX\n", HubExtension->HubFlags);
97
98 KeWaitForSingleObject(&HubExtension->IdleEvent,
101 FALSE,
102 NULL);
103 }
104
106
107 PowerState.DeviceState = PowerDeviceD0;
108
109 Status = PoRequestPowerIrp(HubExtension->LowerPDO,
113 &Event,
114 NULL);
115
116 if (Status == STATUS_PENDING)
117 {
119 Suspended,
121 FALSE,
122 NULL);
123 }
124
125 while (HubExtension->HubFlags & USBHUB_FDO_FLAG_WAKEUP_START)
126 {
127 USBH_Wait(10);
128 }
129
130 return Status;
131}
VOID NTAPI USBH_HubESDRecoverySetD3Completion(IN PDEVICE_OBJECT DeviceObject, IN UCHAR MinorFunction, IN POWER_STATE PowerState, IN PVOID Context, IN PIO_STATUS_BLOCK IoStatus)
Definition: power.c:62
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
@ NotificationEvent
#define STATUS_INVALID_DEVICE_STATE
Definition: udferr_usr.h:178
@ Suspended
Definition: ketypes.h:420

Referenced by USBH_DeviceControl(), USBH_FdoPnP(), USBH_IdleCancelPowerHubWorker(), USBH_IdleCompletePowerHubWorker(), and USBH_PdoRemoveDevice().

◆ USBH_IdleCancelPowerHubWorker()

VOID NTAPI USBH_IdleCancelPowerHubWorker ( IN PUSBHUB_FDO_EXTENSION  HubExtension,
IN PVOID  Context 
)

Definition at line 135 of file power.c.

137{
138 PUSBHUB_IDLE_PORT_CANCEL_CONTEXT WorkItemIdlePower;
139 PIRP Irp;
140
141 DPRINT("USBH_IdleCancelPowerHubWorker: ... \n");
142
143 WorkItemIdlePower = Context;
144
145 if (HubExtension &&
146 HubExtension->CurrentPowerState.DeviceState != PowerDeviceD0 &&
147 HubExtension->HubFlags & USBHUB_FDO_FLAG_DEVICE_STARTED)
148 {
149 USBH_HubSetD0(HubExtension);
150 }
151
152 Irp = WorkItemIdlePower->Irp;
154
156}
IO_STATUS_BLOCK IoStatus

Referenced by USBH_PortIdleNotificationCancelRoutine().

◆ USBH_PassIrp()

NTSTATUS NTAPI USBH_PassIrp ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 79 of file usbhub.c.

81{
82 DPRINT_PNP("USBH_PassIrp: DeviceObject - %p, Irp - %p\n",
84 Irp);
85
88}
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421

Referenced by USBH_DeviceControl(), USBH_FdoDispatch(), USBH_FdoPnP(), USBH_FdoQueryBusRelations(), USBH_FdoRemoveDevice(), USBH_PdoInternalControl(), USBH_PdoIoctlSubmitUrb(), USBH_PdoPnP(), and USBH_PdoUrbFilter().

◆ USBH_PdoInternalControl()

NTSTATUS NTAPI USBH_PdoInternalControl ( IN PUSBHUB_PORT_PDO_EXTENSION  PortExtension,
IN PIRP  Irp 
)

Definition at line 1280 of file ioctl.c.

1282{
1283 PUSBHUB_FDO_EXTENSION HubExtension;
1286 PIO_STACK_LOCATION IoStack;
1287 PULONG HubCount;
1288
1289 DPRINT_IOCTL("USBH_PdoInternalControl: PortExtension - %p, Irp - %p\n",
1290 PortExtension,
1291 Irp);
1292
1293 HubExtension = PortExtension->HubExtension;
1294
1295 if (PortExtension->PortPdoFlags & USBHUB_PDO_FLAG_NOT_CONNECTED)
1296 {
1298 goto Exit;
1299 }
1300
1301 if (PortExtension->CurrentPowerState.DeviceState != PowerDeviceD0)
1302 {
1304 goto Exit;
1305 }
1306
1308 ControlCode = IoStack->Parameters.DeviceIoControl.IoControlCode;
1309
1311 {
1312 HubExtension = PortExtension->RootHubExtension;
1313 DPRINT("USBH_PdoInternalControl: HubExtension - %p\n", HubExtension);
1314 }
1315
1316 if (!HubExtension)
1317 {
1319 goto Exit;
1320 }
1321
1322 switch (ControlCode)
1323 {
1325 return USBH_PdoIoctlSubmitUrb(PortExtension, Irp);
1326
1327 case IOCTL_INTERNAL_USB_SUBMIT_IDLE_NOTIFICATION:
1328 DPRINT1("USBH_PdoInternalControl: IOCTL_INTERNAL_USB_SUBMIT_IDLE_NOTIFICATION\n");
1329 return USBH_PortIdleNotificationRequest(PortExtension, Irp);
1330
1332 DPRINT("USBH_PdoInternalControl: IOCTL_INTERNAL_USB_GET_PORT_STATUS\n");
1333 return USBH_PdoIoctlGetPortStatus(PortExtension, Irp);
1334
1336 DPRINT1("USBH_PdoInternalControl: IOCTL_INTERNAL_USB_RESET_PORT\n");
1337 return USBH_PdoIoctlResetPort(PortExtension, Irp);
1338
1340 DPRINT1("USBH_PdoInternalControl: IOCTL_INTERNAL_USB_ENABLE_PORT\n");
1341 DbgBreakPoint();
1342 break;
1343
1345 DPRINT1("USBH_PdoInternalControl: IOCTL_INTERNAL_USB_CYCLE_PORT\n");
1346 DbgBreakPoint();
1347 break;
1348
1349 case IOCTL_INTERNAL_USB_GET_DEVICE_HANDLE:
1350 DPRINT("USBH_PdoInternalControl: IOCTL_INTERNAL_USB_GET_DEVICE_HANDLE\n");
1351 *(PVOID *)IoStack->Parameters.Others.Argument1 = PortExtension->DeviceHandle;
1353 break;
1354
1356 DPRINT("USBH_PdoInternalControl: IOCTL_INTERNAL_USB_GET_HUB_COUNT. PortPdoFlags - %lX\n",
1357 PortExtension->PortPdoFlags);
1358
1359 if (!(PortExtension->PortPdoFlags & USBHUB_PDO_FLAG_HUB_DEVICE))
1360 {
1362 break;
1363 }
1364
1365 HubCount = IoStack->Parameters.Others.Argument1;
1366
1367 ++*HubCount;
1368
1369 Status = USBH_SyncGetHubCount(HubExtension->LowerDevice,
1370 HubCount);
1371
1372 DPRINT("USBH_PdoInternalControl: *HubCount - %x\n", *HubCount);
1373 break;
1374
1376 DPRINT("USBH_PdoInternalControl: IOCTL_INTERNAL_USB_GET_ROOTHUB_PDO. PortPdoFlags - %lX\n",
1377 PortExtension->PortPdoFlags);
1378
1379 if (!(PortExtension->PortPdoFlags & USBHUB_PDO_FLAG_HUB_DEVICE))
1380 {
1381 DbgBreakPoint();
1383
1384 *(PVOID *)IoStack->Parameters.Others.Argument1 = NULL;
1385
1387 break;
1388 }
1389
1390 ASSERT(HubExtension->RootHubPdo);
1391 return USBH_PassIrp(HubExtension->RootHubPdo, Irp);
1392
1394 DPRINT1("USBH_PdoInternalControl: IOCTL_INTERNAL_USB_GET_HUB_NAME\n");
1395 DbgBreakPoint();
1396 break;
1397
1399 DPRINT1("USBH_PdoInternalControl: IOCTL_GET_HCD_DRIVERKEY_NAME\n");
1400 DbgBreakPoint();
1401 break;
1402
1404 DPRINT1("USBH_PdoInternalControl: IOCTL_INTERNAL_USB_GET_BUS_INFO\n");
1405 DbgBreakPoint();
1406 break;
1407
1409 DPRINT1("USBH_PdoInternalControl: IOCTL_INTERNAL_USB_GET_PARENT_HUB_INFO\n");
1410 DbgBreakPoint();
1411 break;
1412
1413 default:
1414 DPRINT1("USBH_PdoInternalControl: unhandled IOCTL_ - %lX\n", ControlCode);
1415 break;
1416 }
1417
1418Exit:
1420 return Status;
1421}
#define DPRINT_IOCTL(...)
Definition: dbg_uhub.h:107
NTSTATUS NTAPI USBH_PdoIoctlGetPortStatus(IN PUSBHUB_PORT_PDO_EXTENSION PortExtension, IN PIRP Irp)
Definition: ioctl.c:239
NTSTATUS NTAPI USBH_PortIdleNotificationRequest(IN PUSBHUB_PORT_PDO_EXTENSION PortExtension, IN PIRP Irp)
Definition: ioctl.c:487
NTSTATUS NTAPI USBH_PdoIoctlSubmitUrb(IN PUSBHUB_PORT_PDO_EXTENSION PortExtension, IN PIRP Irp)
Definition: ioctl.c:210
NTSTATUS NTAPI USBH_PdoIoctlResetPort(IN PUSBHUB_PORT_PDO_EXTENSION PortExtension, IN PIRP Irp)
Definition: ioctl.c:379
#define STATUS_DEVICE_POWERED_OFF
Definition: ntstatus.h:195
struct _IO_STACK_LOCATION::@3978::@4017 Others
uint32_t * PULONG
Definition: typedefs.h:59
#define STATUS_DEVICE_NOT_CONNECTED
Definition: udferr_usr.h:160
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
NTSTATUS NTAPI USBH_SyncGetHubCount(IN PDEVICE_OBJECT DeviceObject, IN OUT PULONG OutHubCount)
Definition: usbhub.c:781
#define USBHUB_PDO_FLAG_NOT_CONNECTED
Definition: usbhub.h:67
#define IOCTL_INTERNAL_USB_SUBMIT_URB
Definition: usbioctl.h:32
#define IOCTL_INTERNAL_USB_GET_PARENT_HUB_INFO
Definition: usbioctl.h:68
#define IOCTL_INTERNAL_USB_RESET_PORT
Definition: usbioctl.h:35
#define IOCTL_GET_HCD_DRIVERKEY_NAME
Definition: usbioctl.h:165
#define IOCTL_INTERNAL_USB_CYCLE_PORT
Definition: usbioctl.h:53
#define IOCTL_INTERNAL_USB_GET_HUB_COUNT
Definition: usbioctl.h:50
#define IOCTL_INTERNAL_USB_ENABLE_PORT
Definition: usbioctl.h:47
#define IOCTL_INTERNAL_USB_GET_BUS_INFO
Definition: usbioctl.h:59
#define IOCTL_INTERNAL_USB_GET_ROOTHUB_PDO
Definition: usbioctl.h:38
#define IOCTL_INTERNAL_USB_GET_HUB_NAME
Definition: usbioctl.h:56
#define IOCTL_INTERNAL_USB_GET_PORT_STATUS
Definition: usbioctl.h:44

Referenced by USBH_PdoDispatch().

◆ USBH_PdoPnP()

NTSTATUS NTAPI USBH_PdoPnP ( IN PUSBHUB_PORT_PDO_EXTENSION  PortExtension,
IN PIRP  Irp,
IN UCHAR  Minor,
OUT BOOLEAN IsCompleteIrp 
)

Definition at line 2594 of file pnp.c.

2598{
2600 PIO_STACK_LOCATION IoStack;
2601 PPNP_BUS_INFORMATION BusInfo;
2603 USHORT Size;
2605 PUSBHUB_FDO_EXTENSION HubExtension;
2606 PDEVICE_RELATIONS DeviceRelation;
2607
2608 DPRINT_PNP("USBH_PdoPnP: PortExtension - %p, Irp - %p, Minor - %X\n",
2609 PortExtension,
2610 Irp,
2611 Minor);
2612
2614
2615 *IsCompleteIrp = TRUE;
2616
2617 switch (Minor)
2618 {
2620 DPRINT_PNP("PDO IRP_MN_START_DEVICE\n");
2621 return USBH_PdoStartDevice(PortExtension, Irp);
2622
2624 DPRINT_PNP("PDO IRP_MN_QUERY_REMOVE_DEVICE\n");
2625 return STATUS_SUCCESS;
2626
2628 DPRINT_PNP("PDO IRP_MN_REMOVE_DEVICE\n");
2629 return USBH_PdoRemoveDevice(PortExtension, PortExtension->HubExtension);
2630
2632 DPRINT_PNP("PDO IRP_MN_CANCEL_REMOVE_DEVICE\n");
2633 return STATUS_SUCCESS;
2634
2635 case IRP_MN_STOP_DEVICE:
2636 DPRINT_PNP("PDO IRP_MN_STOP_DEVICE\n");
2637 return USBH_PdoStopDevice(PortExtension, Irp);
2638
2640 DPRINT_PNP("PDO IRP_MN_QUERY_STOP_DEVICE\n");
2641 return STATUS_SUCCESS;
2642
2644 DPRINT_PNP("PDO IRP_MN_CANCEL_STOP_DEVICE\n");
2645 return STATUS_SUCCESS;
2646
2648 DPRINT_PNP("PDO IRP_MN_QUERY_DEVICE_RELATIONS\n");
2649
2651 {
2652 return Irp->IoStatus.Status;
2653 }
2654
2655 DeviceRelation = ExAllocatePoolWithTag(PagedPool,
2656 sizeof(DEVICE_RELATIONS),
2657 USB_HUB_TAG);
2658
2659 if (DeviceRelation)
2660 {
2661 RtlZeroMemory(DeviceRelation, sizeof(DEVICE_RELATIONS));
2662
2663 DeviceRelation->Count = 1;
2664 DeviceRelation->Objects[0] = PortExtension->Common.SelfDevice;
2665
2666 ObReferenceObject(DeviceRelation->Objects[0]);
2667
2669 }
2670 else
2671 {
2673 }
2674
2675 Irp->IoStatus.Information = (ULONG_PTR)DeviceRelation;
2676 break;
2677
2679 DPRINT_PNP("PDO IRP_MN_QUERY_INTERFACE\n");
2680
2681 *IsCompleteIrp = 0;
2682
2683 if (IsEqualGUIDAligned(IoStack->Parameters.QueryInterface.InterfaceType,
2684 &USB_BUS_INTERFACE_USBDI_GUID))
2685 {
2686 IoStack->Parameters.QueryInterface.InterfaceSpecificData = PortExtension->DeviceHandle;
2687 }
2688
2689 HubExtension = PortExtension->HubExtension;
2690
2691 if (!HubExtension)
2692 {
2693 HubExtension = PortExtension->RootHubExtension;
2694 }
2695
2696 Status = USBH_PassIrp(HubExtension->RootHubPdo, Irp);
2697 break;
2698
2700 DPRINT_PNP("PDO IRP_MN_QUERY_CAPABILITIES\n");
2701
2702 DeviceCapabilities = IoStack->Parameters.DeviceCapabilities.Capabilities;
2703
2704 Size = DeviceCapabilities->Size;
2705 Version = DeviceCapabilities->Version;
2706
2708 &PortExtension->Capabilities,
2709 sizeof(DEVICE_CAPABILITIES));
2710
2711 DeviceCapabilities->Size = Size;
2712 DeviceCapabilities->Version = Version;
2713
2714 /* All devices connected to a hub are removable */
2715 DeviceCapabilities->Removable = 1;
2716
2718 break;
2719
2721 DPRINT_PNP("PDO IRP_MN_QUERY_RESOURCES\n");
2722 Status = Irp->IoStatus.Status;
2723 break;
2724
2726 DPRINT_PNP("PDO IRP_MN_QUERY_RESOURCE_REQUIREMENTS\n");
2727 PortExtension->PortPdoFlags |= USBHUB_PDO_FLAG_ENUMERATED;
2728
2729 /* FIXME HKEY_LOCAL_MACHINE\SYSTEM\ControlSetXXX\Enum\USB\
2730 Vid_????&Pid_????\????????????\Device Parameters\
2731 if (ExtPropDescSemaphore)
2732 */
2733
2735 break;
2736
2738 DPRINT_PNP("PDO IRP_MN_QUERY_DEVICE_TEXT\n");
2739 return USBH_PdoQueryDeviceText(PortExtension, Irp);
2740
2742 DPRINT_PNP("PDO IRP_MN_FILTER_RESOURCE_REQUIREMENTS\n");
2743 Status = Irp->IoStatus.Status;
2744 break;
2745
2746 case IRP_MN_READ_CONFIG:
2747 DPRINT_PNP("PDO IRP_MN_READ_CONFIG\n");
2748 DbgBreakPoint();
2749 Status = Irp->IoStatus.Status;
2750 break;
2751
2753 DPRINT_PNP("PDO IRP_MN_WRITE_CONFIG\n");
2754 DbgBreakPoint();
2755 Status = Irp->IoStatus.Status;
2756 break;
2757
2758 case IRP_MN_EJECT:
2759 DPRINT_PNP("PDO IRP_MN_EJECT\n");
2760 DbgBreakPoint();
2761 Status = Irp->IoStatus.Status;
2762 break;
2763
2764 case IRP_MN_SET_LOCK:
2765 DPRINT_PNP("PDO IRP_MN_SET_LOCK\n");
2766 DbgBreakPoint();
2767 Status = Irp->IoStatus.Status;
2768 break;
2769
2770 case IRP_MN_QUERY_ID:
2771 DPRINT_PNP("PDO IRP_MN_QUERY_ID\n");
2772 return USBH_PdoQueryId(PortExtension, Irp);
2773
2775 DPRINT_PNP("PDO IRP_MN_QUERY_PNP_DEVICE_STATE\n");
2776 if (PortExtension->PortPdoFlags & (USBHUB_PDO_FLAG_INSUFFICIENT_PWR |
2780 {
2781 Irp->IoStatus.Information |= PNP_DEVICE_FAILED;
2782 }
2783
2785 break;
2786
2788 DPRINT_PNP("PDO IRP_MN_QUERY_BUS_INFORMATION\n");
2789
2791 sizeof(PNP_BUS_INFORMATION),
2792 USB_HUB_TAG);
2793
2794 if (!BusInfo)
2795 {
2797 }
2798
2799 RtlZeroMemory(BusInfo, sizeof(PNP_BUS_INFORMATION));
2800
2801 RtlCopyMemory(&BusInfo->BusTypeGuid,
2802 &GUID_BUS_TYPE_USB,
2803 sizeof(BusInfo->BusTypeGuid));
2804
2805 BusInfo->LegacyBusType = PNPBus;
2806 BusInfo->BusNumber = 0;
2807
2808 Irp->IoStatus.Information = (ULONG_PTR)BusInfo;
2810 break;
2811
2813 DPRINT_PNP("PDO IRP_MN_DEVICE_USAGE_NOTIFICATION\n");
2814 DbgBreakPoint();
2815 Status = Irp->IoStatus.Status;
2816 break;
2817
2819 DPRINT_PNP("PDO IRP_MN_SURPRISE_REMOVAL\n");
2820 if (PortExtension->PortPdoFlags & USBHUB_PDO_FLAG_REG_DEV_INTERFACE)
2821 {
2822 Status = USBH_SymbolicLink(PortExtension, NULL, FALSE);
2823
2824 if (NT_SUCCESS(Status))
2825 {
2826 PortExtension->PortPdoFlags &= ~USBHUB_PDO_FLAG_REG_DEV_INTERFACE;
2827 }
2828 }
2829
2831 break;
2832
2833 default:
2834 DPRINT_PNP("PDO unknown IRP_MN_???\n");
2835 Status = Irp->IoStatus.Status;
2836 break;
2837 }
2838
2839 return Status;
2840}
#define ULONG_PTR
Definition: config.h:101
NTSTATUS NTAPI USBH_PdoStopDevice(IN PUSBHUB_PORT_PDO_EXTENSION PortExtension, IN PIRP Irp)
Definition: pnp.c:2352
NTSTATUS NTAPI USBH_PdoRemoveDevice(IN PUSBHUB_PORT_PDO_EXTENSION PortExtension, IN PUSBHUB_FDO_EXTENSION HubExtension)
Definition: pnp.c:2180
NTSTATUS NTAPI USBH_PdoStartDevice(IN PUSBHUB_PORT_PDO_EXTENSION PortExtension, IN PIRP Irp)
Definition: pnp.c:2124
NTSTATUS NTAPI USBH_PdoQueryDeviceText(IN PUSBHUB_PORT_PDO_EXTENSION PortExtension, IN PIRP Irp)
Definition: pnp.c:1853
NTSTATUS NTAPI USBH_SymbolicLink(IN PUSBHUB_PORT_PDO_EXTENSION PortExtension, IN const GUID *InterfaceClassGuid, IN BOOLEAN IsEnable)
Definition: pnp.c:2008
NTSTATUS NTAPI USBH_PdoQueryId(IN PUSBHUB_PORT_PDO_EXTENSION PortExtension, IN PIRP Irp)
Definition: pnp.c:1561
@ PNPBus
Definition: hwresource.cpp:152
PDEVICE_OBJECT Objects[1]
Definition: iotypes.h:2163
struct _IO_STACK_LOCATION::@3978::@4004 QueryInterface
struct _IO_STACK_LOCATION::@3978::@4005 DeviceCapabilities
INTERFACE_TYPE LegacyBusType
Definition: cmtypes.h:365
#define USBHUB_PDO_FLAG_OVERCURRENT_PORT
Definition: usbhub.h:75
#define USBHUB_PDO_FLAG_INSUFFICIENT_PWR
Definition: usbhub.h:77
#define USBHUB_PDO_FLAG_PORT_RESTORE_FAIL
Definition: usbhub.h:73
#define USBHUB_PDO_FLAG_ENUMERATED
Definition: usbhub.h:82
#define USBHUB_PDO_FLAG_REG_DEV_INTERFACE
Definition: usbhub.h:72
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
_Must_inspect_result_ _In_ WDFDEVICE _In_ LPCGUID _Out_ PINTERFACE _In_ USHORT _In_ USHORT Version
Definition: wdffdo.h:469
#define IsEqualGUIDAligned(guid1, guid2)
Definition: wdm.template.h:235
#define DeviceCapabilities
Definition: wingdi.h:4449
DEVICE_CAPABILITIES
Definition: iotypes.h:965
* PDEVICE_CAPABILITIES
Definition: iotypes.h:965
#define ObReferenceObject
Definition: obfuncs.h:204

Referenced by USBH_PdoDispatch().

◆ USBH_PdoPower()

NTSTATUS NTAPI USBH_PdoPower ( IN PUSBHUB_PORT_PDO_EXTENSION  PortExtension,
IN PIRP  Irp,
IN UCHAR  Minor 
)

Definition at line 757 of file power.c.

760{
761 NTSTATUS Status = Irp->IoStatus.Status;
762
763 DPRINT_PWR("USBH_FdoPower: PortExtension - %p, Irp - %p, Minor - %X\n",
764 PortExtension,
765 Irp,
766 Minor);
767
768 switch (Minor)
769 {
770 case IRP_MN_WAIT_WAKE:
771 DPRINT_PWR("USBHUB_PdoPower: IRP_MN_WAIT_WAKE\n");
773 break;
774
776 DPRINT_PWR("USBHUB_PdoPower: IRP_MN_POWER_SEQUENCE\n");
778 break;
779
780 case IRP_MN_SET_POWER:
781 DPRINT_PWR("USBHUB_PdoPower: IRP_MN_SET_POWER\n");
783 break;
784
786 DPRINT_PWR("USBHUB_PdoPower: IRP_MN_QUERY_POWER\n");
788 break;
789
790 default:
791 DPRINT1("USBHUB_PdoPower: unknown IRP_MN_POWER!\n");
793 break;
794 }
795
796 Irp->IoStatus.Status = Status;
797 Irp->IoStatus.Information = 0;
799
800 return Status;
801}

Referenced by USBH_PdoDispatch().

◆ USBH_PdoRemoveDevice()

NTSTATUS NTAPI USBH_PdoRemoveDevice ( IN PUSBHUB_PORT_PDO_EXTENSION  PortExtension,
IN PUSBHUB_FDO_EXTENSION  HubExtension 
)

Definition at line 2180 of file pnp.c.

2182{
2184 PDEVICE_OBJECT PortDevice;
2186 PUSBHUB_PORT_DATA PortData;
2187 PIRP IdleNotificationIrp;
2188 PIRP WakeIrp;
2192 USHORT Port;
2193 KIRQL Irql;
2194
2195 DPRINT("USBH_PdoRemoveDevice ... \n");
2196
2197 PortDevice = PortExtension->Common.SelfDevice;
2198 PortExtension->HubExtension = NULL;
2199
2200 Port = PortExtension->PortNumber;
2201 ASSERT(Port > 0);
2202
2203 if (HubExtension &&
2204 HubExtension->CurrentPowerState.DeviceState != PowerDeviceD0 &&
2205 (HubExtension->HubFlags & USBHUB_FDO_FLAG_DEVICE_STARTED) != 0)
2206 {
2207 USBH_HubSetD0(HubExtension);
2208 }
2209
2211 IdleNotificationIrp = PortExtension->IdleNotificationIrp;
2212
2213 if (IdleNotificationIrp)
2214 {
2215 PortExtension->IdleNotificationIrp = NULL;
2216 PortExtension->PortPdoFlags &= ~USBHUB_PDO_FLAG_IDLE_NOTIFICATION;
2217
2218 if (IdleNotificationIrp->Cancel)
2219 {
2220 IdleNotificationIrp = NULL;
2221 }
2222
2223 if (IdleNotificationIrp)
2224 {
2225 IoSetCancelRoutine(IdleNotificationIrp, NULL);
2226 }
2227 }
2228
2229 WakeIrp = PortExtension->PdoWaitWakeIrp;
2230
2231 if (WakeIrp)
2232 {
2233 PortExtension->PdoWaitWakeIrp = NULL;
2234 PortExtension->PortPdoFlags &= ~USBHUB_PDO_FLAG_WAIT_WAKE;
2235
2236 if (WakeIrp->Cancel || !IoSetCancelRoutine(WakeIrp, NULL))
2237 {
2238 WakeIrp = NULL;
2239
2240 ASSERT(HubExtension);
2241 if (!InterlockedDecrement(&HubExtension->PendingRequestCount))
2242 {
2243 KeSetEvent(&HubExtension->PendingRequestEvent,
2245 FALSE);
2246 }
2247 }
2248 }
2249
2251
2252 if (IdleNotificationIrp)
2253 {
2254 IdleNotificationIrp->IoStatus.Status = STATUS_CANCELLED;
2255 IoCompleteRequest(IdleNotificationIrp, IO_NO_INCREMENT);
2256 }
2257
2258 if (WakeIrp)
2259 {
2260 ASSERT(HubExtension);
2261 USBH_CompletePowerIrp(HubExtension, WakeIrp, STATUS_CANCELLED);
2262 }
2263
2264 PortExtension->PortPdoFlags |= USBHUB_PDO_FLAG_POWER_D3;
2265
2266 if (PortExtension->PortPdoFlags & USBHUB_PDO_FLAG_REG_DEV_INTERFACE)
2267 {
2268 Status = USBH_SymbolicLink(PortExtension, NULL, FALSE);
2269
2270 if (NT_SUCCESS(Status))
2271 {
2272 PortExtension->PortPdoFlags &= ~USBHUB_PDO_FLAG_REG_DEV_INTERFACE;
2273 }
2274 }
2275
2276 DeviceHandle = InterlockedExchangePointer(&PortExtension->DeviceHandle,
2277 NULL);
2278
2279 if (DeviceHandle)
2280 {
2281 ASSERT(HubExtension);
2282 Status = USBD_RemoveDeviceEx(HubExtension, DeviceHandle, 0);
2283
2284 if (HubExtension->PortData &&
2285 HubExtension->PortData[Port - 1].DeviceObject == PortDevice)
2286 {
2287 USBH_SyncDisablePort(HubExtension, Port);
2288 }
2289 }
2290
2291 if (NT_SUCCESS(Status))
2292 {
2293 PortExtension->PortPdoFlags &= ~USBHUB_PDO_FLAG_DEVICE_STARTED;
2294
2295 if (HubExtension && HubExtension->PortData)
2296 {
2297 PortData = &HubExtension->PortData[Port - 1];
2298
2299 if (PortExtension->PortPdoFlags & USBHUB_PDO_FLAG_DELETE_PENDING)
2300 {
2301 Pdo = PortData->DeviceObject;
2302
2303 if (Pdo)
2304 {
2305 PortData->DeviceObject = NULL;
2307
2308 if (PdoExt(Pdo)->EnumFlags & USBHUB_ENUM_FLAG_DEVICE_PRESENT)
2309 {
2310 PortExt = PdoExt(Pdo);
2311
2312 InsertTailList(&HubExtension->PdoList,
2313 &PortExt->PortLink);
2314 }
2315 }
2316 }
2317 }
2318
2319 if (!(PortExtension->EnumFlags & USBHUB_ENUM_FLAG_DEVICE_PRESENT) &&
2320 !(PortExtension->PortPdoFlags & USBHUB_PDO_FLAG_NOT_CONNECTED))
2321 {
2322 PortExtension->PortPdoFlags |= USBHUB_PDO_FLAG_NOT_CONNECTED;
2323
2324 SerialNumber = InterlockedExchangePointer((PVOID)&PortExtension->SerialNumber,
2325 NULL);
2326
2327 if (SerialNumber)
2328 {
2330 }
2331
2332 DPRINT1("USBH_PdoRemoveDevice: call IoWMIRegistrationControl UNIMPLEMENTED. FIXME\n");
2333
2334 if (HubExtension)
2335 USBHUB_FlushAllTransfers(HubExtension);
2336
2337 IoDeleteDevice(PortDevice);
2338 }
2339 }
2340
2341 if (HubExtension)
2342 {
2343 DPRINT("USBH_PdoRemoveDevice: call USBH_CheckIdleDeferred()\n");
2344 USBH_CheckIdleDeferred(HubExtension);
2345 }
2346
2347 return Status;
2348}
VOID NTAPI USBH_CompletePowerIrp(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PIRP Irp, IN NTSTATUS NtStatus)
Definition: power.c:18
#define InsertTailList(ListHead, Entry)
IoSetCancelRoutine(Irp, CancelRoutine)
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
ULONG SerialNumber
Definition: rxce.c:117
USB_CONNECTION_STATUS ConnectionStatus
Definition: usbhub.h:120
PUSBHUB_PORT_PDO_EXTENSION NTAPI PdoExt(IN PDEVICE_OBJECT DeviceObject)
Definition: usbhub.c:133
VOID NTAPI USBHUB_FlushAllTransfers(IN PUSBHUB_FDO_EXTENSION HubExtension)
Definition: usbhub.c:2623
NTSTATUS NTAPI USBH_SyncDisablePort(IN PUSBHUB_FDO_EXTENSION HubExtension, IN USHORT Port)
Definition: usbhub.c:1553
#define USBHUB_ENUM_FLAG_DEVICE_PRESENT
Definition: usbhub.h:84
#define USBHUB_PDO_FLAG_POWER_D3
Definition: usbhub.h:69
#define USBHUB_PDO_FLAG_DELETE_PENDING
Definition: usbhub.h:68
@ NoDeviceConnected
Definition: usbioctl.h:278
WDF_EXTERN_C_START typedef _Must_inspect_result_ _In_ WDFDRIVER _In_opt_ PWDF_OBJECT_ATTRIBUTES _In_ PDEVICE_OBJECT _In_opt_ PDEVICE_OBJECT _In_opt_ PDEVICE_OBJECT Pdo
Definition: wdfminiport.h:72

Referenced by USBH_FdoRemoveDevice(), and USBH_PdoPnP().

◆ USBH_QueueWorkItem()

VOID NTAPI USBH_QueueWorkItem ( IN PUSBHUB_FDO_EXTENSION  HubExtension,
IN PUSBHUB_IO_WORK_ITEM  HubIoWorkItem 
)

Definition at line 2917 of file usbhub.c.

2919{
2920 DPRINT("USBH_QueueWorkItem: ... \n");
2921
2922 InterlockedIncrement(&HubExtension->PendingRequestCount);
2923 InterlockedIncrement(&HubIoWorkItem->HubWorkerQueued);
2924
2925 ExInterlockedInsertTailList(&HubExtension->WorkItemList,
2926 &HubIoWorkItem->HubWorkItemLink,
2927 &HubExtension->WorkItemSpinLock);
2928
2929 IoQueueWorkItem(HubIoWorkItem->HubWorkItem,
2931 HubIoWorkItem->HubWorkItemType,
2932 HubIoWorkItem);
2933}
PLIST_ENTRY NTAPI ExInterlockedInsertTailList(IN OUT PLIST_ENTRY ListHead, IN OUT PLIST_ENTRY ListEntry, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:140
VOID NTAPI IoQueueWorkItem(IN PIO_WORKITEM IoWorkItem, IN PIO_WORKITEM_ROUTINE WorkerRoutine, IN WORK_QUEUE_TYPE QueueType, IN PVOID Context)
Definition: iowork.c:40
VOID NTAPI USBH_Worker(IN PDEVICE_OBJECT DeviceObject, IN PVOID Context)
Definition: usbhub.c:2872

Referenced by USBH_ChangeIndicationProcessChange(), USBH_ChangeIndicationQueryChange(), USBH_CheckIdleDeferred(), USBH_FdoIdleNotificationRequestComplete(), USBH_PdoIoctlResetPort(), and USBH_PortIdleNotificationCancelRoutine().

◆ USBH_ResetDevice()

NTSTATUS NTAPI USBH_ResetDevice ( IN PUSBHUB_FDO_EXTENSION  HubExtension,
IN USHORT  Port,
IN BOOLEAN  IsKeepDeviceData,
IN BOOLEAN  IsWait 
)

Definition at line 4615 of file usbhub.c.

4619{
4621 PUSBHUB_PORT_DATA PortData;
4622 PDEVICE_OBJECT PortDevice;
4623 PUSBHUB_PORT_PDO_EXTENSION PortExtension;
4625 PVOID Handle;
4629
4630 DPRINT("USBH_ResetDevice: HubExtension - %p, Port - %x, IsKeepDeviceData - %x, IsWait - %x\n",
4631 HubExtension,
4632 Port,
4633 IsKeepDeviceData,
4634 IsWait);
4635
4636 Status = USBH_SyncGetPortStatus(HubExtension,
4637 Port,
4638 &PortStatus,
4640
4641 if (!NT_SUCCESS(Status) ||
4642 !(PortStatus.PortStatus.Usb20PortStatus.CurrentConnectStatus))
4643 {
4644 return STATUS_UNSUCCESSFUL;
4645 }
4646
4647 InterlockedIncrement(&HubExtension->PendingRequestCount);
4648
4649 KeWaitForSingleObject(&HubExtension->ResetDeviceSemaphore,
4650 Executive,
4651 KernelMode,
4652 FALSE,
4653 NULL);
4654
4655 ASSERT(Port > 0);
4656 PortData = &HubExtension->PortData[Port-1];
4657
4658 PortDevice = PortData->DeviceObject;
4659
4660 if (!PortDevice)
4661 {
4663
4664 KeReleaseSemaphore(&HubExtension->ResetDeviceSemaphore,
4666 1,
4667 FALSE);
4668
4669 if (!InterlockedDecrement(&HubExtension->PendingRequestCount))
4670 {
4671 KeSetEvent(&HubExtension->PendingRequestEvent,
4673 FALSE);
4674 }
4675
4676 return Status;
4677 }
4678
4679 PortExtension = PortDevice->DeviceExtension;
4680 DeviceHandle = &PortExtension->DeviceHandle;
4681
4683 NULL);
4684
4685 if (OldDeviceHandle)
4686 {
4687 if (!(PortExtension->PortPdoFlags & USBHUB_PDO_FLAG_REMOVING_PORT_PDO))
4688 {
4689 Status = USBD_RemoveDeviceEx(HubExtension,
4691 IsKeepDeviceData);
4692
4694 }
4695 }
4696 else
4697 {
4699 }
4700
4701 if (!NT_SUCCESS(Status))
4702 {
4703 goto ErrorExit;
4704 }
4705
4706 Status = USBH_SyncResetPort(HubExtension, Port);
4707
4708 if (!NT_SUCCESS(Status))
4709 {
4710 goto ErrorExit;
4711 }
4712
4713 Status = USBH_SyncGetPortStatus(HubExtension,
4714 Port,
4715 &PortStatus,
4717
4718 if (!NT_SUCCESS(Status))
4719 {
4720 goto ErrorExit;
4721 }
4722
4723 Status = USBD_CreateDeviceEx(HubExtension,
4725 PortStatus.PortStatus,
4726 Port);
4727
4728 if (!NT_SUCCESS(Status))
4729 {
4730 goto ErrorExit;
4731 }
4732
4733 Status = USBH_SyncResetPort(HubExtension, Port);
4734
4735 if (IsWait)
4736 {
4737 USBH_Wait(50);
4738 }
4739
4740 if (!NT_SUCCESS(Status))
4741 {
4742 goto ErrorExit;
4743 }
4744
4745 Status = USBD_InitializeDeviceEx(HubExtension,
4746 *DeviceHandle,
4747 &PortExtension->DeviceDescriptor.bLength,
4748 sizeof(PortExtension->DeviceDescriptor),
4749 &PortExtension->ConfigDescriptor.bLength,
4750 sizeof(PortExtension->ConfigDescriptor));
4751
4752 if (NT_SUCCESS(Status))
4753 {
4754 if (IsKeepDeviceData)
4755 {
4756 Status = USBD_RestoreDeviceEx(HubExtension,
4758 *DeviceHandle);
4759
4760 if (!NT_SUCCESS(Status))
4761 {
4763
4764 USBD_RemoveDeviceEx(HubExtension, Handle, 0);
4765 USBH_SyncDisablePort(HubExtension, Port);
4766
4768 }
4769 }
4770 else
4771 {
4772 PortExtension->PortPdoFlags &= ~USBHUB_PDO_FLAG_REMOVING_PORT_PDO;
4773 }
4774
4775 goto Exit;
4776 }
4777
4778 *DeviceHandle = NULL;
4779
4780ErrorExit:
4781
4784
4785 if (NewDeviceHandle)
4786 {
4787 Status = USBD_RemoveDeviceEx(HubExtension, NewDeviceHandle, 0);
4788 }
4789
4790Exit:
4791
4792 KeReleaseSemaphore(&HubExtension->ResetDeviceSemaphore,
4794 1,
4795 FALSE);
4796
4797 if (!InterlockedDecrement(&HubExtension->PendingRequestCount))
4798 {
4799 KeSetEvent(&HubExtension->PendingRequestEvent,
4801 FALSE);
4802 }
4803
4804 return Status;
4805}
ULONG Handle
Definition: gdb_input.c:15
_Outptr_ PUSB_DEVICE_HANDLE _In_ PUSB_DEVICE_HANDLE _In_ USHORT PortStatus
Definition: hubbusif.h:42
#define STATUS_NO_SUCH_DEVICE
Definition: udferr_usr.h:136
NTSTATUS NTAPI USBH_SyncGetPortStatus(IN PUSBHUB_FDO_EXTENSION HubExtension, IN USHORT Port, IN PUSB_PORT_STATUS_AND_CHANGE PortStatus, IN ULONG Length)
Definition: usbhub.c:1414
NTSTATUS NTAPI USBD_RestoreDeviceEx(IN PUSBHUB_FDO_EXTENSION HubExtension, IN OUT PUSB_DEVICE_HANDLE OldDeviceHandle, IN OUT PUSB_DEVICE_HANDLE NewDeviceHandle)
Definition: usbhub.c:2761
#define USBHUB_PDO_FLAG_REMOVING_PORT_PDO
Definition: usbhub.h:76

Referenced by USBH_ResetPortWorker(), and USBH_RestoreDevice().

◆ USBH_SetPdoRegistryParameter()

NTSTATUS NTAPI USBH_SetPdoRegistryParameter ( IN PDEVICE_OBJECT  DeviceObject,
IN PCWSTR  SourceString,
IN PVOID  Data,
IN ULONG  DataSize,
IN ULONG  Type,
IN ULONG  DevInstKeyType 
)

Definition at line 213 of file usbhub.c.

219{
221 UNICODE_STRING ValueNameString;
223
224 DPRINT("USBH_SetPdoRegistryParameter ... \n");
225
226 RtlInitUnicodeString(&ValueNameString, ValueName);
227
231 &KeyHandle);
232
233 if (NT_SUCCESS(Status))
234 {
235 ZwSetValueKey(KeyHandle,
236 &ValueNameString,
237 0,
238 Type,
239 Data,
240 DataSize);
241
243 }
244
245 return Status;
246}
Type
Definition: Type.h:7
_In_ NDIS_STATUS _In_ ULONG _In_ USHORT _In_opt_ PVOID _In_ ULONG DataSize
Definition: ndis.h:4755
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4715
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
#define STANDARD_RIGHTS_ALL
Definition: nt_native.h:69
NTSTATUS NTAPI IoOpenDeviceRegistryKey(IN PDEVICE_OBJECT DeviceObject, IN ULONG DevInstKeyType, IN ACCESS_MASK DesiredAccess, OUT PHANDLE DevInstRegKey)
Definition: pnpmgr.c:1621
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING ValueName
Definition: wdfregistry.h:243
_In_ ULONG DevInstKeyType
Definition: iofuncs.h:1125

Referenced by USBH_SymbolicLink().

◆ USBH_SubmitStatusChangeTransfer()

NTSTATUS NTAPI USBH_SubmitStatusChangeTransfer ( IN PUSBHUB_FDO_EXTENSION  HubExtension)

Definition at line 2442 of file usbhub.c.

2443{
2444 PIRP Irp;
2447 PIO_STACK_LOCATION IoStack;
2448
2449 DPRINT_SCE("USBH_SubmitStatusChangeTransfer: HubExtension - %p, SCEIrp - %p\n",
2450 HubExtension,
2451 HubExtension->SCEIrp);
2452
2453 if (HubExtension->HubFlags & USBHUB_FDO_FLAG_NOT_D0_STATE)
2454 {
2455 DPRINT_SCE("USBH_SubmitStatusChangeTransfer: USBHUB_FDO_FLAG_NOT_D0_STATE\n");
2456 DPRINT_SCE("USBH_SubmitStatusChangeTransfer: HubFlags - %lX\n",
2457 HubExtension->HubFlags);
2458
2460 }
2461
2462 Irp = HubExtension->SCEIrp;
2463
2464 if (!Irp)
2465 {
2467 }
2468
2469 Urb = (struct _URB_BULK_OR_INTERRUPT_TRANSFER *)&HubExtension->SCEWorkerUrb;
2470
2471 Urb->Hdr.Length = sizeof(struct _URB_BULK_OR_INTERRUPT_TRANSFER);
2473 Urb->Hdr.UsbdDeviceHandle = NULL;
2474
2475 Urb->PipeHandle = HubExtension->PipeInfo.PipeHandle;
2477 Urb->TransferBuffer = HubExtension->SCEBitmap;
2478 Urb->TransferBufferLength = HubExtension->SCEBitmapLength;
2479 Urb->TransferBufferMDL = NULL;
2480 Urb->UrbLink = NULL;
2481
2483 IoSizeOfIrp(HubExtension->LowerDevice->StackSize),
2484 HubExtension->LowerDevice->StackSize);
2485
2486 IoStack = IoGetNextIrpStackLocation(Irp);
2487
2489 IoStack->Parameters.Others.Argument1 = &HubExtension->SCEWorkerUrb;
2491
2494 HubExtension,
2495 TRUE,
2496 TRUE,
2497 TRUE);
2498
2499 KeClearEvent(&HubExtension->StatusChangeEvent);
2500
2501 Status = IoCallDriver(HubExtension->LowerDevice, Irp);
2502
2503 return Status;
2504}
#define DPRINT_SCE(...)
Definition: dbg_uhub.h:110
VOID NTAPI IoInitializeIrp(IN PIRP Irp, IN USHORT PacketSize, IN CCHAR StackSize)
Definition: irp.c:1854
USBD_PIPE_HANDLE PipeHandle
Definition: usb.h:499
struct _URB_HEADER Hdr
Definition: usb.h:498
struct _URB * UrbLink
Definition: usb.h:504
#define USBD_SHORT_TRANSFER_OK
Definition: usb.h:154
#define URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER
Definition: usb.h:95
NTSTATUS NTAPI USBH_ChangeIndication(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context)
Definition: usbhub.c:2319
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2695
#define IoSizeOfIrp(_StackSize)
#define IRP_MJ_INTERNAL_DEVICE_CONTROL

Referenced by USBH_ChangeIndicationAckChangeComplete(), USBH_ChangeIndicationWorker(), USBH_FdoPower(), USBH_PowerIrpCompletion(), USBH_StartHubFdoDevice(), and USBHUB_RootHubCallBack().

◆ USBH_SyncClearPortStatus()

NTSTATUS NTAPI USBH_SyncClearPortStatus ( IN PUSBHUB_FDO_EXTENSION  HubExtension,
IN USHORT  Port,
IN USHORT  RequestValue 
)

Definition at line 1442 of file usbhub.c.

1445{
1447
1448 DPRINT("USBH_SyncClearPortStatus: Port - %x, RequestValue - %x\n",
1449 Port,
1450 RequestValue);
1451
1452 RequestType.B = 0;
1453 RequestType.Recipient = BMREQUEST_TO_OTHER;
1456
1457 return USBH_Transact(HubExtension,
1458 NULL,
1459 0,
1464 RequestValue,
1465 Port);
1466}
#define BMREQUEST_CLASS
Definition: usb100.h:35
#define BMREQUEST_TO_OTHER
Definition: usb100.h:41
#define BMREQUEST_HOST_TO_DEVICE
Definition: usb100.h:31
#define USB_REQUEST_CLEAR_FEATURE
Definition: usb100.h:79
#define URB_FUNCTION_CLASS_OTHER
Definition: usb.h:117
NTSTATUS NTAPI USBH_Transact(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PVOID TransferBuffer, IN ULONG BufferLen, IN BOOLEAN IsDeviceToHost, IN USHORT Function, IN BM_REQUEST_TYPE RequestType, IN UCHAR Request, IN USHORT RequestValue, IN USHORT RequestIndex)
Definition: usbhub.c:370
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFQUEUE _In_ _Strict_type_match_ WDF_REQUEST_TYPE RequestType
Definition: wdfdevice.h:4233

Referenced by USBH_ProcessPortStateChange(), and USBH_StartHubFdoDevice().

◆ USBH_SyncDisablePort()

NTSTATUS NTAPI USBH_SyncDisablePort ( IN PUSBHUB_FDO_EXTENSION  HubExtension,
IN USHORT  Port 
)

Definition at line 1553 of file usbhub.c.

1555{
1556 PUSBHUB_PORT_DATA PortData;
1559
1560 DPRINT("USBH_SyncDisablePort ... \n");
1561
1562 PortData = &HubExtension->PortData[Port - 1];
1563
1564 RequestType.B = 0;
1565 RequestType.Recipient = BMREQUEST_TO_DEVICE;
1568
1569 Status = USBH_Transact(HubExtension,
1570 NULL,
1571 0,
1577 Port);
1578
1579 if (NT_SUCCESS(Status))
1580 {
1582 }
1583
1584 return Status;
1585}
USB_PORT_STATUS_AND_CHANGE PortStatus
Definition: usbhub.h:118
USHORT PortEnabledDisabled
Definition: usb200.h:134
USB_PORT_STATUS PortStatus
Definition: usb200.h:240
USB_20_PORT_STATUS Usb20PortStatus
Definition: usb200.h:223
#define BMREQUEST_TO_DEVICE
Definition: usb100.h:38
#define USBHUB_FEATURE_PORT_ENABLE
Definition: usbhub.h:92

Referenced by USBH_FdoCleanup(), USBH_FdoQueryBusRelations(), USBH_PdoRemoveDevice(), USBH_ProcessPortStateChange(), and USBH_ResetDevice().

◆ USBH_SyncGetDeviceHandle()

PUSB_DEVICE_HANDLE NTAPI USBH_SyncGetDeviceHandle ( IN PDEVICE_OBJECT  DeviceObject)

Definition at line 832 of file usbhub.c.

833{
834 PIRP Irp;
838 PIO_STACK_LOCATION IoStack;
839
840 DPRINT("USBH_SyncGetDeviceHandle: ... \n");
841
843
844 Irp = IoBuildDeviceIoControlRequest(IOCTL_INTERNAL_USB_GET_DEVICE_HANDLE,
846 NULL,
847 0,
848 NULL,
849 0,
850 TRUE,
851 &Event,
853
854 if (!Irp)
855 {
856 DPRINT1("USBH_SyncGetDeviceHandle: Irp - NULL!\n");
857 return NULL;
858 }
859
861 IoStack->Parameters.Others.Argument1 = &DeviceHandle;
862
864 {
866 Suspended,
868 FALSE,
869 NULL);
870 }
871
872 return DeviceHandle;
873}
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
PIRP NTAPI IoBuildDeviceIoControlRequest(IN ULONG IoControlCode, IN PDEVICE_OBJECT DeviceObject, IN PVOID InputBuffer, IN ULONG InputBufferLength, IN PVOID OutputBuffer, IN ULONG OutputBufferLength, IN BOOLEAN InternalDeviceIoControl, IN PKEVENT Event, IN PIO_STATUS_BLOCK IoStatusBlock)
Definition: irp.c:881

Referenced by USBD_CreateDeviceEx(), USBD_Initialize20Hub(), and USBH_StartHubFdoDevice().

◆ USBH_SyncGetHubCount()

NTSTATUS NTAPI USBH_SyncGetHubCount ( IN PDEVICE_OBJECT  DeviceObject,
IN OUT PULONG  OutHubCount 
)

Definition at line 781 of file usbhub.c.

783{
786 PIRP Irp;
787 PIO_STACK_LOCATION IoStack;
789
790 DPRINT("USBH_SyncGetHubCount: *OutHubCount - %x\n", *OutHubCount);
791
793
796 NULL,
797 0,
798 NULL,
799 0,
800 TRUE,
801 &Event,
803
804 if (!Irp)
805 {
807 }
808
810 IoStack->Parameters.Others.Argument1 = OutHubCount;
811
813
814 if (Status == STATUS_PENDING)
815 {
817 Suspended,
819 FALSE,
820 NULL);
821 }
822 else
823 {
825 }
826
827 return IoStatusBlock.Status;
828}

Referenced by USBH_PdoInternalControl(), and USBH_StartHubFdoDevice().

◆ USBH_SyncGetHubDescriptor()

NTSTATUS NTAPI USBH_SyncGetHubDescriptor ( IN PUSBHUB_FDO_EXTENSION  HubExtension)

Definition at line 1048 of file usbhub.c.

1049{
1050 PUSB_EXTHUB_INFORMATION_0 ExtendedHubInfo;
1051 ULONG NumberPorts;
1052 PUSBHUB_PORT_DATA PortData;
1053 USHORT RequestValue;
1056 PUSB_HUB_DESCRIPTOR HubDescriptor = NULL;
1057 ULONG ix;
1058 ULONG Retry;
1059
1060 DPRINT("USBH_SyncGetHubDescriptor: ... \n");
1061
1062 ExtendedHubInfo = ExAllocatePoolWithTag(NonPagedPool,
1064 USB_HUB_TAG);
1065
1066 if (!ExtendedHubInfo)
1067 {
1069 goto ErrorExit;
1070 }
1071
1072 RtlZeroMemory(ExtendedHubInfo, sizeof(USB_EXTHUB_INFORMATION_0));
1073
1074 Status = USBHUB_GetExtendedHubInfo(HubExtension, ExtendedHubInfo);
1075
1076 if (!NT_SUCCESS(Status))
1077 {
1078 ExFreePoolWithTag(ExtendedHubInfo, USB_HUB_TAG);
1079 ExtendedHubInfo = NULL;
1080 }
1081
1083
1084 HubDescriptor = ExAllocatePoolWithTag(NonPagedPool,
1086 USB_HUB_TAG);
1087
1088 if (!HubDescriptor)
1089 {
1091 goto ErrorExit;
1092 }
1093
1094 RtlZeroMemory(HubDescriptor, NumberOfBytes);
1095
1096 RequestValue = 0;
1097 Retry = 0;
1098
1099 while (TRUE)
1100 {
1101 while (Retry <= 5)
1102 {
1104
1105 RequestType.B = 0;
1106 RequestType.Recipient = BMREQUEST_TO_DEVICE;
1109
1110 Status = USBH_Transact(HubExtension,
1111 HubDescriptor,
1117 RequestValue,
1118 0);
1119
1120 if (NT_SUCCESS(Status))
1121 {
1122 break;
1123 }
1124
1125 RequestValue = 0x2900; // Hub DescriptorType - 0x29
1126
1127 Retry++;
1128 }
1129
1130 if (HubDescriptor->bDescriptorLength <= NumberOfBytes)
1131 {
1132 break;
1133 }
1134
1135 NumberOfBytes = HubDescriptor->bDescriptorLength;
1136 ExFreePoolWithTag(HubDescriptor, USB_HUB_TAG);
1137
1138 if (Retry >= 5)
1139 {
1141 HubDescriptor = NULL;
1142 goto ErrorExit;
1143 }
1144
1145 HubDescriptor = ExAllocatePoolWithTag(NonPagedPool,
1147 USB_HUB_TAG);
1148
1149 if (!HubDescriptor)
1150 {
1152 goto ErrorExit;
1153 }
1154
1155 RtlZeroMemory(HubDescriptor, NumberOfBytes);
1156 }
1157
1158 NumberPorts = HubDescriptor->bNumberOfPorts;
1159
1160 if (HubExtension->PortData)
1161 {
1162 PortData = HubExtension->PortData;
1163
1164 for (ix = 0; ix < NumberPorts; ix++)
1165 {
1166 PortData[ix].PortStatus.AsUlong32 = 0;
1167
1168 if (ExtendedHubInfo)
1169 {
1170 PortData[ix].PortAttributes = ExtendedHubInfo->Port[ix].PortAttributes;
1171 }
1172 else
1173 {
1174 PortData[ix].PortAttributes = 0;
1175 }
1176
1177 PortData[ix].ConnectionStatus = NoDeviceConnected;
1178
1179 if (PortData[ix].DeviceObject != NULL)
1180 {
1181 PortData[ix].ConnectionStatus = DeviceConnected;
1182 }
1183 }
1184 }
1185 else
1186 {
1187 PortData = NULL;
1188
1189 if (HubDescriptor->