ReactOS  0.4.15-dev-440-g5f37b68
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 127 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;
372  UNICODE_STRING DeviceName = RTL_CONSTANT_STRING(L"\\Device\\Beep");
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 */
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 }
DRIVER_DISPATCH BeepClose
Definition: beep.c:78
FORCEINLINE VOID IoInitializeDpcRequest(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIO_DPC_ROUTINE DpcRoutine)
Definition: iofuncs.h:2792
DRIVER_STARTIO BeepStartIo
Definition: beep.c:295
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
LONG NTSTATUS
Definition: precomp.h:26
WCHAR DeviceName[]
Definition: adapter.cpp:21
#define FILE_DEVICE_BEEP
Definition: winioctl.h:106
DRIVER_DISPATCH BeepDeviceControl
Definition: beep.c:206
NTSTATUS NTAPI DriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath)
Definition: beep.c:367
PVOID DeviceExtension
Definition: env_spec_w32.h:418
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
VOID NTAPI KeInitializeTimer(OUT PKTIMER Timer)
Definition: timerobj.c:233
DRIVER_DISPATCH BeepCreate
Definition: beep.c:52
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define DO_BUFFERED_IO
Definition: env_spec_w32.h:394
FORCEINLINE VOID ExInitializeFastMutex(_Out_ PFAST_MUTEX FastMutex)
Definition: exfuncs.h:274
PVOID NTAPI MmPageEntireDriver(IN PVOID AddressWithinSection)
Definition: sysldr.c:3370
IO_DPC_ROUTINE * PIO_DPC_ROUTINE
Definition: iotypes.h:2492
VOID NTAPI BeepDPC(IN PKDPC Dpc, IN PDEVICE_OBJECT DeviceObject, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
Definition: beep.c:34
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
static const WCHAR L[]
Definition: oid.c:1250
PDRIVER_UNLOAD DriverUnload
Definition: iotypes.h:2180
DRIVER_DISPATCH BeepCleanup
Definition: beep.c:145
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1569
FAST_MUTEX Mutex
Definition: beep.c:24
DRIVER_UNLOAD BeepUnload
Definition: beep.c:268
#define IRP_MJ_CLEANUP
PDRIVER_DISPATCH MajorFunction[IRP_MJ_MAXIMUM_FUNCTION+1]
Definition: iotypes.h:2181
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
_In_ PUNICODE_STRING RegistryPath
Definition: wmip.h:28
PDRIVER_STARTIO DriverStartIo
Definition: iotypes.h:2179
return STATUS_SUCCESS
Definition: btrfs.c:3014
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14

◆ 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  {
2524  return STATUS_NOT_IMPLEMENTED;
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:34
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
PUSB_DEVICE_HANDLE NTAPI USBH_SyncGetDeviceHandle(IN PDEVICE_OBJECT DeviceObject)
Definition: usbhub.c:832
_Outptr_ PUSB_DEVICE_HANDLE _In_ PUSB_DEVICE_HANDLE HubDeviceHandle
Definition: hubbusif.h:40
void DPRINT(...)
Definition: polytest.cpp:61
USB_BUSIFFN_CREATE_USB_DEVICE * PUSB_BUSIFFN_CREATE_USB_DEVICE
Definition: hubbusif.h:44

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;
2652  NTSTATUS Status;
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,
2682  DeviceHandle,
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
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_Inout_ PUSB_DEVICE_HANDLE DeviceHandle
Definition: hubbusif.h:121
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
LONG NTSTATUS
Definition: precomp.h:26
struct TraceInfo Info
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
struct _USB_DEVICE_INFORMATION_0 USB_DEVICE_INFORMATION_0
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
#define USB_HUB_TAG
Definition: usbhub.h:26
#define USBHUB_PDO_FLAG_HUB_DEVICE
Definition: usbhub.h:61
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:195
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
struct _DeviceInfo DeviceInfo
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
Status
Definition: gdiplustypes.h:24
ULONG_PTR SIZE_T
Definition: typedefs.h:79
unsigned char dummy
Definition: maze.c:118
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
USB_BUSIFFN_GET_DEVICE_INFORMATION * PUSB_BUSIFFN_GET_DEVICE_INFORMATION
Definition: hubbusif.h:183

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 {
2569  NTSTATUS Status;
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  {
2580  return STATUS_NOT_IMPLEMENTED;
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,
2592  DeviceHandle,
2597 }
_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 DeviceHandle
Definition: hubbusif.h:121
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
LONG NTSTATUS
Definition: precomp.h:26
USB_BUSIFFN_GET_USB_DESCRIPTORS * PUSB_BUSIFFN_GET_USB_DESCRIPTORS
Definition: hubbusif.h:154
_Inout_ PUSB_DEVICE_HANDLE _Out_writes_bytes_to_ DeviceDescriptorBufferLength PUCHAR DeviceDescriptorBuffer
Definition: hubbusif.h:148
void DPRINT(...)
Definition: polytest.cpp:61
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
_Inout_ PUSB_DEVICE_HANDLE _Out_writes_bytes_to_ DeviceDescriptorBufferLength PUCHAR _Inout_ PULONG DeviceDescriptorBufferLength
Definition: hubbusif.h:148
_Inout_ PUSB_DEVICE_HANDLE _Out_writes_bytes_to_ DeviceDescriptorBufferLength PUCHAR _Inout_ PULONG _Out_writes_bytes_to_ ConfigDescriptorBufferLength PUCHAR _Inout_ PULONG ConfigDescriptorBufferLength
Definition: hubbusif.h:151
USB_BUSIFFN_INITIALIZE_USB_DEVICE * PUSB_BUSIFFN_INITIALIZE_USB_DEVICE
Definition: hubbusif.h:122
Status
Definition: gdiplustypes.h:24

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  {
2996  return STATUS_NOT_IMPLEMENTED;
2997  }
2998 
2999  KeClearEvent(&HubExtension->RootHubNotificationEvent);
3000 
3001  return RootHubInitNotification(HubExtension->BusInterface.BusContext,
3002  HubExtension,
3004 }
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
VOID NTAPI USBHUB_RootHubCallBack(IN PVOID Context)
Definition: usbhub.c:2957
void DPRINT(...)
Definition: polytest.cpp:61
USB_BUSIFFN_ROOTHUB_INIT_NOTIFY * PUSB_BUSIFFN_ROOTHUB_INIT_NOTIFY
Definition: hubbusif.h:279
VOID NTAPI KeClearEvent(IN PKEVENT Event)
Definition: eventobj.c:22

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",
2545  DeviceHandle,
2546  Flags);
2547 
2548  RemoveUsbDevice = HubExtension->BusInterface.RemoveUsbDevice;
2549 
2550  if (!RemoveUsbDevice)
2551  {
2552  return STATUS_NOT_IMPLEMENTED;
2553  }
2554 
2555  return RemoveUsbDevice(HubExtension->BusInterface.BusContext,
2556  DeviceHandle,
2557  Flags);
2558 }
_Inout_ PUSB_DEVICE_HANDLE DeviceHandle
Definition: hubbusif.h:121
USB_BUSIFFN_REMOVE_USB_DEVICE * PUSB_BUSIFFN_REMOVE_USB_DEVICE
Definition: hubbusif.h:140
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
void DPRINT(...)
Definition: polytest.cpp:61

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;
2766  NTSTATUS Status;
2767 
2768  DPRINT("USBD_RestoreDeviceEx: HubExtension - %p, OldDeviceHandle - %p, NewDeviceHandle - %p\n",
2769  HubExtension,
2771  NewDeviceHandle);
2772 
2773  RestoreUsbDevice = HubExtension->BusInterface.RestoreUsbDevice;
2774 
2775  if (RestoreUsbDevice)
2776  {
2777  Status = RestoreUsbDevice(HubExtension->BusInterface.BusContext,
2779  NewDeviceHandle);
2780  }
2781  else
2782  {
2784  }
2785 
2786  return Status;
2787 }
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
LONG NTSTATUS
Definition: precomp.h:26
USB_BUSIFFN_RESTORE_DEVICE * PUSB_BUSIFFN_RESTORE_DEVICE
Definition: hubbusif.h:163
_Inout_ PUSB_DEVICE_HANDLE OldDeviceHandle
Definition: hubbusif.h:161
void DPRINT(...)
Definition: polytest.cpp:61
Status
Definition: gdiplustypes.h:24
_Outptr_ PUSB_DEVICE_HANDLE * NewDeviceHandle
Definition: hubbusif.h:40

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;
3011  NTSTATUS Status;
3012 
3013  DPRINT("USBD_UnRegisterRootHubCallBack ... \n");
3014 
3015  RootHubInitNotification = HubExtension->BusInterface.RootHubInitNotification;
3016 
3017  if (!RootHubInitNotification)
3018  {
3019  return STATUS_NOT_IMPLEMENTED;
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 STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24
USB_BUSIFFN_ROOTHUB_INIT_NOTIFY * PUSB_BUSIFFN_ROOTHUB_INIT_NOTIFY
Definition: hubbusif.h:279

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 {
4246  NTSTATUS Status;
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 
4297 Exit:
4299  return Status;
4300 }
#define TRUE
Definition: types.h:120
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
LONG NTSTATUS
Definition: precomp.h:26
uint16_t * PWCHAR
Definition: typedefs.h:55
void DPRINT(...)
Definition: polytest.cpp:61
#define USB_HUB_TAG
Definition: usbhub.h:26
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static void Exit(void)
Definition: sock.c:1331
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define MAXIMUM_USB_STRING_LENGTH
Definition: usb100.h:43
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
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
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1569
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:409
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
return STATUS_SUCCESS
Definition: btrfs.c:3014
_In_ PSTORAGE_PROPERTY_ID _Outptr_ PSTORAGE_DESCRIPTOR_HEADER * Descriptor
Definition: classpnp.h:966

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 
3822 return; //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 ||
3853  HubFlags & USBHUB_FDO_FLAG_ENUM_POST_RECOVER ||
3854  HubFlags & USBHUB_FDO_FLAG_DEVICE_FAILED ||
3855  HubFlags & USBHUB_FDO_FLAG_DEVICE_STOPPING ||
3856  HubFlags & USBHUB_FDO_FLAG_DEVICE_REMOVED ||
3857  HubFlags & USBHUB_FDO_FLAG_STATE_CHANGING ||
3858  HubFlags & USBHUB_FDO_FLAG_WAKEUP_START ||
3859  HubFlags & USBHUB_FDO_FLAG_ESD_RECOVERING)
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 
3940 Exit:
3941  KeAcquireSpinLock(&HubExtension->CheckIdleSpinLock, &Irql);
3942  HubExtension->HubFlags &= ~USBHUB_FDO_FLAG_CHECK_IDLE_LOCK;
3943  KeReleaseSpinLock(&HubExtension->CheckIdleSpinLock, Irql);
3944 }
CPPORT Port[4]
Definition: headless.c:34
#define TRUE
Definition: types.h:120
#define USBHUB_FDO_FLAG_DEFER_CHECK_IDLE
Definition: usbhub.h:48
NTSTATUS NTAPI USBH_FdoSubmitIdleRequestIrp(IN PUSBHUB_FDO_EXTENSION HubExtension)
Definition: usbhub.c:3722
PUSBHUB_FDO_EXTENSION NTAPI USBH_GetRootHubExtension(IN PUSBHUB_FDO_EXTENSION HubExtension)
Definition: usbhub.c:699
VOID NTAPI IoAcquireCancelSpinLock(OUT PKIRQL Irql)
Definition: util.c:56
#define USBHUB_FDO_FLAG_ENUM_POST_RECOVER
Definition: usbhub.h:51
#define LOW_REALTIME_PRIORITY
#define USBHUB_FDO_FLAG_NOT_ENUMERATED
Definition: usbhub.h:55
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
_Out_ PKIRQL Irql
Definition: csq.h:179
#define USBHUB_FDO_FLAG_DEVICE_STARTED
Definition: usbhub.h:33
PDEVICE_OBJECT DeviceObject
Definition: usbhub.h:119
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define USBHUB_FDO_FLAG_CHECK_IDLE_LOCK
Definition: usbhub.h:53
#define USBHUB_FDO_FLAG_STATE_CHANGING
Definition: usbhub.h:45
#define USBHUB_FDO_FLAG_DEVICE_FAILED
Definition: usbhub.h:35
PVOID DeviceExtension
Definition: env_spec_w32.h:418
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
#define USBHUB_FDO_FLAG_DO_ENUMERATION
Definition: usbhub.h:52
#define USBHUB_FDO_FLAG_WAKEUP_START
Definition: usbhub.h:49
#define USBHUB_FDO_FLAG_DEVICE_REMOVED
Definition: usbhub.h:46
#define USBHUB_FDO_FLAG_ESD_RECOVERING
Definition: usbhub.h:41
static void Exit(void)
Definition: sock.c:1331
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
#define USBHUB_FDO_FLAG_DEVICE_STOPPING
Definition: usbhub.h:34
#define InterlockedDecrement
Definition: armddk.h:52
VOID NTAPI IoReleaseCancelSpinLock(IN KIRQL Irql)
Definition: util.c:150
#define EVENT_INCREMENT
Definition: iotypes.h:565
#define InterlockedIncrement
Definition: armddk.h:53
LONG NTAPI KeReleaseSemaphore(IN PKSEMAPHORE Semaphore, IN KPRIORITY Increment, IN LONG Adjustment, IN BOOLEAN Wait)
Definition: semphobj.c:54
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
unsigned int ULONG
Definition: retypes.h:1
VOID NTAPI KeClearEvent(IN PKEVENT Event)
Definition: eventobj.c:22
#define USBHUB_FDO_FLAG_WAIT_IDLE_REQUEST
Definition: usbhub.h:44

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;
3229  BOOLEAN Result = FALSE;
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 
3280 Wait:
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 }
CPPORT Port[4]
Definition: headless.c:34
#define TRUE
Definition: types.h:120
#define LOW_REALTIME_PRIORITY
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
PDEVICE_OBJECT DeviceObject
Definition: usbhub.h:119
PVOID DeviceExtension
Definition: env_spec_w32.h:418
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
_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:426
void DPRINT(...)
Definition: polytest.cpp:61
#define InterlockedDecrement
Definition: armddk.h:52
#define InterlockedExchange
Definition: armddk.h:54
#define EVENT_INCREMENT
Definition: iotypes.h:565
#define InterlockedIncrement
Definition: armddk.h:53
LONG NTAPI KeReleaseSemaphore(IN PKSEMAPHORE Semaphore, IN KPRIORITY Increment, IN LONG Adjustment, IN BOOLEAN Wait)
Definition: semphobj.c:54
unsigned int ULONG
Definition: retypes.h:1
IN BOOLEAN Wait
Definition: fatprocs.h:1538

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;
3960  NTSTATUS Status;
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_QueueWorkItem(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PUSBHUB_IO_WORK_ITEM HubIoWorkItem)
Definition: usbhub.c:2917
LONG NTSTATUS
Definition: precomp.h:26
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
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
Status
Definition: gdiplustypes.h:24

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 
)

Definition at line 63 of file usbhub.c.

65 {
66  if (CompleteStatus != STATUS_SUCCESS)
67  {
68  DPRINT1("USBH_CompleteIrp: Irp - %p, CompleteStatus - %X\n",
69  Irp,
70  CompleteStatus);
71  }
72 
73  Irp->IoStatus.Status = CompleteStatus;
75 }
_In_ PIRP Irp
Definition: csq.h:116
#define IoCompleteRequest
Definition: irp.c:1240
#define DPRINT1
Definition: precomp.h:8
#define IO_NO_INCREMENT
Definition: iotypes.h:566
return STATUS_SUCCESS
Definition: btrfs.c:3014

Referenced by USBH_DeviceControl(), USBH_FdoDispatch(), USBH_FdoQueryBusRelations(), USBH_FdoStartDevice(), USBH_IoctlGetDescriptor(), USBH_IoctlGetHubCapabilities(), USBH_IoctlGetNodeConnectionAttributes(), USBH_IoctlGetNodeConnectionDriverKeyName(), USBH_IoctlGetNodeConnectionInformation(), USBH_IoctlGetNodeInformation(), USBH_IoctlGetNodeName(), USBH_PdoDispatch(), USBH_PdoInternalControl(), USBH_PdoIoctlGetPortStatus(), USBH_PdoIoctlResetPort(), USBH_PdoUrbFilter(), USBH_ResetPortWorker(), and USBH_StartHubFdoDevice().

◆ 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 }
_In_ PIRP Irp
Definition: csq.h:116
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
#define IoCompleteRequest
Definition: irp.c:1240
void DPRINT(...)
Definition: polytest.cpp:61
#define InterlockedDecrement
Definition: armddk.h:52
#define EVENT_INCREMENT
Definition: iotypes.h:565
VOID NTAPI PoStartNextPowerIrp(IN PIRP Irp)
Definition: power.c:737
#define IO_NO_INCREMENT
Definition: iotypes.h:566

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;
4394  NTSTATUS Status;
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,
4411  sizeof(USBHUB_PORT_PDO_EXTENSION),
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 
4438  PortExtension->Common.ExtensionType = USBH_EXTENSION_TYPE_PORT;
4439  PortExtension->Common.SelfDevice = DeviceObject;
4440 
4441  PortExtension->HubExtension = HubExtension;
4442  PortExtension->RootHubExtension = HubExtension;
4443 
4444  PortExtension->PortNumber = Port;
4445  PortExtension->CurrentPowerState.DeviceState = PowerDeviceD0;
4446  PortExtension->IgnoringHwSerial = FALSE;
4447 
4448  KeInitializeSpinLock(&PortExtension->PortTimeoutSpinLock);
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 */
4477  DestinationString.MaximumLength = 4 * sizeof(WCHAR);
4479 
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 
4547  USBH_GetSerialNumberString(PortExtension->Common.SelfDevice,
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 
4586 ErrorExit:
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 
4606 Exit:
4607 
4608  ASSERT(Port > 0);
4609  HubExtension->PortData[Port-1].DeviceObject = DeviceObject;
4610  return Status;
4611 }
#define DO_DEVICE_INITIALIZING
Definition: env_spec_w32.h:399
#define STATUS_OBJECT_NAME_COLLISION
Definition: udferr_usr.h:150
#define DO_POWER_PAGABLE
CPPORT Port[4]
Definition: headless.c:34
const uint16_t * PCWSTR
Definition: typedefs.h:56
PUSB_DEVICE_HANDLE DeviceHandle
Definition: usbhub.h:211
#define TRUE
Definition: types.h:120
_Inout_ PUSB_DEVICE_HANDLE DeviceHandle
Definition: hubbusif.h:121
NTSTATUS NTAPI USBD_RemoveDeviceEx(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PUSB_DEVICE_HANDLE DeviceHandle, IN ULONG Flags)
Definition: usbhub.c:2538
#define USBHUB_PDO_FLAG_PORT_LOW_SPEED
Definition: usbhub.h:64
unsigned char * PUCHAR
Definition: retypes.h:3
#define FILE_DEVICE_USB
Definition: usbiodef.h:71
PUSBHUB_FDO_EXTENSION HubExtension
Definition: usbhub.h:209
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI USBH_ValidateSerialNumberString(IN PUSHORT SerialNumberString)
Definition: usbhub.c:4219
USB_CONFIGURATION_DESCRIPTOR ConfigDescriptor
Definition: usbhub.h:218
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
WCHAR DeviceName[]
Definition: adapter.cpp:21
#define USBHUB_PDO_FLAG_INIT_PORT_FAILED
Definition: usbhub.h:63
#define SUBLANG_ENGLISH_US
Definition: nls.h:222
#define USBH_EXTENSION_TYPE_PORT
Definition: usbhub.h:29
POWER_STATE CurrentPowerState
Definition: usbhub.h:222
#define USBHUB_PDO_FLAG_PORT_HIGH_SPEED
Definition: usbhub.h:81
COMMON_DEVICE_EXTENSION Common
Definition: usbhub.h:204
FORCEINLINE VOID KeInitializeSpinLock(_Out_ PKSPIN_LOCK SpinLock)
Definition: kefuncs.h:238
PVOID DeviceExtension
Definition: env_spec_w32.h:418
NTSTATUS NTAPI USBH_ProcessDeviceInformation(IN PUSBHUB_PORT_PDO_EXTENSION PortExtension)
Definition: usbhub.c:4056
unsigned char BOOLEAN
_Out_ _Inout_ POEM_STRING DestinationString
Definition: rtlfuncs.h:1868
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
#define USB_HUB_TAG
Definition: usbhub.h:26
KSPIN_LOCK PortPowerListSpinLock
Definition: usbhub.h:234
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
NTSTATUS NTAPI USBH_Wait(IN ULONG Milliseconds)
Definition: usbhub.c:23
USB_DEVICE_DESCRIPTOR DeviceDescriptor
Definition: usbhub.h:216
NTSYSAPI NTSTATUS NTAPI RtlIntegerToUnicodeString(ULONG Value, ULONG Base, PUNICODE_STRING String)
#define InterlockedExchangePointer(Target, Value)
Definition: dshow.h:45
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
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
static void Exit(void)
Definition: sock.c:1331
DEVICE_POWER_STATE DeviceState
Definition: ntpoapi.h:58
#define LANG_ENGLISH
Definition: nls.h:52
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
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
static const WCHAR L[]
Definition: oid.c:1250
NTSTATUS NTAPI USBH_SyncResetPort(IN PUSBHUB_FDO_EXTENSION HubExtension, IN USHORT Port)
Definition: usbhub.c:471
Status
Definition: gdiplustypes.h:24
KSPIN_LOCK PortTimeoutSpinLock
Definition: usbhub.h:226
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1569
LIST_ENTRY PortPowerList
Definition: usbhub.h:233
static VOID ErrorExit(LPTSTR lpszMessage)
Definition: telnetd.c:647
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
VOID NTAPI USBH_PdoSetCapabilities(IN PUSBHUB_PORT_PDO_EXTENSION PortExtension)
Definition: usbhub.c:3981
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
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 MAKELANGID(p, s)
Definition: nls.h:15
PUSBHUB_FDO_EXTENSION RootHubExtension
Definition: usbhub.h:210
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
WCHAR * LPWSTR
Definition: xmlstorage.h:184
unsigned short MaximumLength
Definition: sprintf.c:452
NTSTATUS NTAPI USBH_GetSerialNumberString(IN PDEVICE_OBJECT DeviceObject, IN LPWSTR *OutSerialNumber, IN PUSHORT OutDescriptorLength, IN USHORT LanguageId, IN UCHAR Index)
Definition: usbhub.c:4304
unsigned short * PUSHORT
Definition: retypes.h:2

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 
1148  IoStack = IoGetCurrentIrpStackLocation(Irp);
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 }
#define IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION
Definition: usbioctl.h:175
#define IOCTL_KS_PROPERTY
Definition: ks.h:127
#define IOCTL_USB_GET_NODE_CONNECTION_INFORMATION
Definition: usbioctl.h:172
#define TRUE
Definition: types.h:120
_In_ PIRP Irp
Definition: csq.h:116
NTSTATUS NTAPI USBH_IoctlGetNodeConnectionInformation(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PIRP Irp, IN BOOLEAN IsExt)
Definition: ioctl.c:834
LONG NTSTATUS
Definition: precomp.h:26
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
#define IOCTL_USB_GET_NODE_CONNECTION_DRIVERKEY_NAME
Definition: usbioctl.h:187
void DbgBreakPoint()
Definition: mach.c:553
NTSTATUS NTAPI USBH_IoctlGetDescriptor(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PIRP Irp)
Definition: ioctl.c:1024
#define USBHUB_FDO_FLAG_DEVICE_STARTED
Definition: usbhub.h:33
NTSTATUS NTAPI USBH_IoctlGetNodeInformation(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PIRP Irp)
Definition: ioctl.c:684
NTSTATUS NTAPI USBH_IoctlGetNodeConnectionDriverKeyName(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PIRP Irp)
Definition: ioctl.c:947
unsigned char BOOLEAN
#define IOCTL_USB_GET_NODE_CONNECTION_NAME
Definition: usbioctl.h:178
void DPRINT(...)
Definition: polytest.cpp:61
_IRQL_requires_same_ typedef _In_ ULONG ControlCode
Definition: wmitypes.h:55
NTSTATUS NTAPI USBH_IoctlGetNodeName(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PIRP Irp)
Definition: ioctl.c:563
NTSTATUS NTAPI USBH_HubSetD0(IN PUSBHUB_FDO_EXTENSION HubExtension)
Definition: power.c:77
NTSTATUS NTAPI USBH_PassIrp(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: usbhub.c:79
VOID NTAPI USBH_CompleteIrp(IN PIRP Irp, IN NTSTATUS CompleteStatus)
Definition: usbhub.c:63
NTSTATUS NTAPI USBH_IoctlGetNodeConnectionAttributes(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PIRP Irp)
Definition: ioctl.c:779
VOID NTAPI USBH_CheckHubIdle(IN PUSBHUB_FDO_EXTENSION HubExtension)
Definition: usbhub.c:3808
Status
Definition: gdiplustypes.h:24
NTSTATUS NTAPI USBH_IoctlGetHubCapabilities(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PIRP Irp)
Definition: ioctl.c:731
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
#define STATUS_DEVICE_BUSY
Definition: udferr_usr.h:129
#define USBHUB_FDO_FLAG_DEVICE_STOPPED
Definition: usbhub.h:37
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
#define IOCTL_USB_GET_NODE_INFORMATION
Definition: usbioctl.h:169

Referenced by USBH_FdoDispatch().

◆ USBH_FdoPnP()

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

Definition at line 2355 of file pnp.c.

2358 {
2359  NTSTATUS Status;
2360  PIO_STACK_LOCATION IoStack;
2361  DEVICE_RELATION_TYPE RelationsType;
2362  BOOLEAN IsCheckIdle;
2363 
2364  DPRINT_PNP("USBH_FdoPnP: HubExtension - %p, Irp - %p, Minor - %X\n",
2365  HubExtension,
2366  Irp,
2367  Minor);
2368 
2369  if (HubExtension->HubFlags & USBHUB_FDO_FLAG_WAIT_IDLE_REQUEST &&
2371  {
2372  HubExtension->HubFlags |= USBHUB_FDO_FLAG_DEVICE_SUSPENDED;
2373  }
2374 
2375  KeWaitForSingleObject(&HubExtension->IdleSemaphore,
2376  Executive,
2377  KernelMode,
2378  FALSE,
2379  NULL);
2380 
2381  DPRINT_PNP("USBH_FdoPnP: HubFlags - %lX\n", HubExtension->HubFlags);
2382 
2383  if (HubExtension->HubFlags & USBHUB_FDO_FLAG_GOING_IDLE)
2384  {
2385  HubExtension->HubFlags |= USBHUB_FDO_FLAG_DEVICE_SUSPENDED;
2386  }
2387 
2388  IoStack = IoGetCurrentIrpStackLocation(Irp);
2389  RelationsType = IoStack->Parameters.QueryDeviceRelations.Type;
2390 
2391  if ((HubExtension->CurrentPowerState.DeviceState == PowerDeviceD0) ||
2392  !(HubExtension->HubFlags & (USBHUB_FDO_FLAG_DEVICE_STOPPED | USBHUB_FDO_FLAG_DEVICE_STARTED)) ||
2393  (Minor == IRP_MN_QUERY_DEVICE_RELATIONS && RelationsType == TargetDeviceRelation))
2394  {
2395  IsCheckIdle = FALSE;
2396  }
2397  else
2398  {
2399  DPRINT_PNP("USBH_FdoPnP: IsCheckIdle - TRUE\n");
2400  IsCheckIdle = TRUE;
2401  USBH_HubSetD0(HubExtension);
2402  }
2403 
2404  switch (Minor)
2405  {
2406  case IRP_MN_START_DEVICE:
2407  DPRINT_PNP("FDO IRP_MN_START_DEVICE\n");
2408  IsCheckIdle = FALSE;
2409  Irp->IoStatus.Status = STATUS_SUCCESS;
2410  Status = USBH_FdoStartDevice(HubExtension, Irp);
2411  break;
2412 
2414  DPRINT_PNP("FDO IRP_MN_QUERY_REMOVE_DEVICE\n");
2415  Irp->IoStatus.Status = STATUS_SUCCESS;
2416  Status = USBH_PassIrp(HubExtension->LowerDevice, Irp);
2417  break;
2418 
2419  case IRP_MN_REMOVE_DEVICE:
2420  DPRINT_PNP("FDO IRP_MN_REMOVE_DEVICE\n");
2421  IsCheckIdle = FALSE;
2422  HubExtension->HubFlags |= USBHUB_FDO_FLAG_DEVICE_REMOVED;
2423  Irp->IoStatus.Status = STATUS_SUCCESS;
2424  Status = USBH_FdoRemoveDevice(HubExtension, Irp);
2425  break;
2426 
2428  DPRINT_PNP("FDO IRP_MN_CANCEL_REMOVE_DEVICE\n");
2429  Irp->IoStatus.Status = STATUS_SUCCESS;
2430  Status = USBH_PassIrp(HubExtension->LowerDevice, Irp);
2431  break;
2432 
2433  case IRP_MN_STOP_DEVICE:
2434  DPRINT_PNP("FDO IRP_MN_STOP_DEVICE\n");
2435  IsCheckIdle = FALSE;
2436  Irp->IoStatus.Status = STATUS_SUCCESS;
2437  Status = USBH_FdoStopDevice(HubExtension, Irp);
2438  break;
2439 
2441  DPRINT_PNP("FDO IRP_MN_QUERY_STOP_DEVICE\n");
2442  Irp->IoStatus.Status = STATUS_SUCCESS;
2443  Status = USBH_PassIrp(HubExtension->LowerDevice, Irp);
2444  break;
2445 
2447  DPRINT_PNP("FDO IRP_MN_CANCEL_STOP_DEVICE\n");
2448  Irp->IoStatus.Status = STATUS_SUCCESS;
2449  Status = USBH_PassIrp(HubExtension->LowerDevice, Irp);
2450  break;
2451 
2453  DPRINT_PNP("FDO IRP_MN_QUERY_DEVICE_RELATIONS\n");
2454 
2455  if (RelationsType != BusRelations)
2456  {
2457  Status = USBH_PassIrp(HubExtension->LowerDevice, Irp);
2458  break;
2459  }
2460 
2461  HubExtension->HubFlags |= USBHUB_FDO_FLAG_HUB_BUSY;
2462 
2463  IsCheckIdle = TRUE;
2464  DPRINT_PNP("USBH_FdoPnP: IsCheckIdle - TRUE\n");
2465 
2466  Status = USBH_FdoQueryBusRelations(HubExtension, Irp);
2467 
2468  HubExtension->HubFlags &= ~USBHUB_FDO_FLAG_HUB_BUSY;
2469  break;
2470 
2472  DPRINT_PNP("FDO IRP_MN_QUERY_INTERFACE\n");
2473  Status = USBH_PassIrp(HubExtension->LowerDevice, Irp);
2474  break;
2475 
2477  DPRINT_PNP("FDO IRP_MN_QUERY_CAPABILITIES\n");
2479 
2482  HubExtension,
2483  TRUE,
2484  FALSE,
2485  FALSE);
2486 
2487  Status = IoCallDriver(HubExtension->LowerDevice, Irp);
2488  break;
2489 
2491  DPRINT_PNP("FDO IRP_MN_QUERY_RESOURCES\n");
2492  Status = USBH_PassIrp(HubExtension->LowerDevice, Irp);
2493  break;
2494 
2496  DPRINT_PNP("FDO IRP_MN_QUERY_RESOURCE_REQUIREMENTS\n");
2497  Status = USBH_PassIrp(HubExtension->LowerDevice, Irp);
2498  break;
2499 
2501  DPRINT_PNP("FDO IRP_MN_QUERY_DEVICE_TEXT\n");
2502  Status = USBH_PassIrp(HubExtension->LowerDevice, Irp);
2503  break;
2504 
2506  DPRINT_PNP("FDO IRP_MN_FILTER_RESOURCE_REQUIREMENTS\n");
2507  Status = USBH_PassIrp(HubExtension->LowerDevice, Irp);
2508  break;
2509 
2510  case IRP_MN_READ_CONFIG:
2511  DPRINT_PNP("FDO IRP_MN_READ_CONFIG\n");
2512  Status = USBH_PassIrp(HubExtension->LowerDevice, Irp);
2513  break;
2514 
2515  case IRP_MN_WRITE_CONFIG:
2516  DPRINT_PNP("FDO IRP_MN_WRITE_CONFIG\n");
2517  Status = USBH_PassIrp(HubExtension->LowerDevice, Irp);
2518  break;
2519 
2520  case IRP_MN_EJECT:
2521  DPRINT_PNP("FDO IRP_MN_EJECT\n");
2522  Status = USBH_PassIrp(HubExtension->LowerDevice, Irp);
2523  break;
2524 
2525  case IRP_MN_SET_LOCK:
2526  DPRINT_PNP("FDO IRP_MN_SET_LOCK\n");
2527  Status = USBH_PassIrp(HubExtension->LowerDevice, Irp);
2528  break;
2529 
2530  case IRP_MN_QUERY_ID:
2531  DPRINT_PNP("FDO IRP_MN_QUERY_ID\n");
2532  Status = USBH_PassIrp(HubExtension->LowerDevice, Irp);
2533  break;
2534 
2536  DPRINT_PNP("FDO IRP_MN_QUERY_PNP_DEVICE_STATE\n");
2537 
2538  if (HubExtension->HubFlags & USBHUB_FDO_FLAG_DEVICE_FAILED)
2539  {
2540  Irp->IoStatus.Information |= PNP_DEVICE_FAILED;
2541  }
2542 
2543  Status = USBH_PassIrp(HubExtension->LowerDevice, Irp);
2544  break;
2545 
2547  DPRINT_PNP("FDO IRP_MN_QUERY_BUS_INFORMATION\n");
2548  Status = USBH_PassIrp(HubExtension->LowerDevice, Irp);
2549  break;
2550 
2552  DPRINT_PNP("FDO IRP_MN_DEVICE_USAGE_NOTIFICATION\n");
2553  Irp->IoStatus.Status = STATUS_SUCCESS;
2554  Status = USBH_PassIrp(HubExtension->LowerDevice, Irp);
2555  break;
2556 
2558  DPRINT_PNP("FDO IRP_MN_SURPRISE_REMOVAL\n");
2559  USBH_FdoSurpriseRemoveDevice(HubExtension, Irp);
2560  Status = USBH_PassIrp(HubExtension->LowerDevice, Irp);
2561  break;
2562 
2563  default:
2564  DPRINT_PNP("FDO unknown IRP_MN_???\n");
2565  Status = USBH_PassIrp(HubExtension->LowerDevice, Irp);
2566  break;
2567  }
2568 
2569  KeReleaseSemaphore(&HubExtension->IdleSemaphore,
2571  1,
2572  FALSE);
2573 
2574  if (IsCheckIdle)
2575  {
2576  DPRINT_PNP("USBH_FdoPnP: call USBH_CheckIdleDeferred()\n");
2577  USBH_CheckIdleDeferred(HubExtension);
2578  }
2579 
2580  HubExtension->HubFlags &= ~USBHUB_FDO_FLAG_STATE_CHANGING;
2581 
2582  return Status;
2583 }
_Out_opt_ PULONG Minor
Definition: cmfuncs.h:44
#define IRP_MN_CANCEL_REMOVE_DEVICE
#define TRUE
Definition: types.h:120
#define IRP_MN_QUERY_RESOURCES
#define IRP_MN_REMOVE_DEVICE
#define IRP_MN_QUERY_ID
NTSTATUS NTAPI USBH_QueryCapsComplete(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context)
Definition: pnp.c:59
_In_ PIRP Irp
Definition: csq.h:116
#define IRP_MN_FILTER_RESOURCE_REQUIREMENTS
#define IRP_MN_QUERY_RESOURCE_REQUIREMENTS
#define IRP_MN_WRITE_CONFIG
LONG NTSTATUS
Definition: precomp.h:26
#define USBHUB_FDO_FLAG_GOING_IDLE
Definition: usbhub.h:57
#define LOW_REALTIME_PRIORITY
#define IRP_MN_EJECT
NTSTATUS NTAPI USBH_FdoStartDevice(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PIRP Irp)
Definition: pnp.c:988
VOID NTAPI USBH_CheckIdleDeferred(IN PUSBHUB_FDO_EXTENSION HubExtension)
Definition: usbhub.c:3957
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
#define IoSetCompletionRoutine(_Irp, _CompletionRoutine, _Context, _InvokeOnSuccess, _InvokeOnError, _InvokeOnCancel)
Definition: irp.cpp:498
#define USBHUB_FDO_FLAG_DEVICE_STARTED
Definition: usbhub.h:33
FORCEINLINE VOID IoCopyCurrentIrpStackLocationToNext(_Inout_ PIRP Irp)
Definition: iofuncs.h:2820
#define USBHUB_FDO_FLAG_STATE_CHANGING
Definition: usbhub.h:45
#define USBHUB_FDO_FLAG_DEVICE_FAILED
Definition: usbhub.h:35
#define IRP_MN_QUERY_REMOVE_DEVICE
NTSTATUS NTAPI USBH_FdoStopDevice(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PIRP Irp)
Definition: pnp.c:1446
NTSTATUS NTAPI USBH_FdoQueryBusRelations(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PIRP Irp)
Definition: pnp.c:1027
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
#define USBHUB_FDO_FLAG_DEVICE_SUSPENDED
Definition: usbhub.h:58
#define IRP_MN_READ_CONFIG
enum _DEVICE_RELATION_TYPE DEVICE_RELATION_TYPE
#define IRP_MN_QUERY_STOP_DEVICE
NTSTATUS NTAPI USBH_HubSetD0(IN PUSBHUB_FDO_EXTENSION HubExtension)
Definition: power.c:77
#define IRP_MN_SURPRISE_REMOVAL
Definition: ntifs_ex.h:408
#define IRP_MN_STOP_DEVICE
#define USBHUB_FDO_FLAG_DEVICE_REMOVED
Definition: usbhub.h:46
#define IRP_MN_START_DEVICE
#define IRP_MN_QUERY_DEVICE_TEXT
#define IRP_MN_QUERY_INTERFACE
NTSTATUS NTAPI USBH_PassIrp(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: usbhub.c:79
#define IRP_MN_QUERY_BUS_INFORMATION
#define PNP_DEVICE_FAILED
Definition: iotypes.h:966
Status
Definition: gdiplustypes.h:24
#define DPRINT_PNP(...)
Definition: dbg_uhub.h:109
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
LONG NTAPI KeReleaseSemaphore(IN PKSEMAPHORE Semaphore, IN KPRIORITY Increment, IN LONG Adjustment, IN BOOLEAN Wait)
Definition: semphobj.c:54
#define USBHUB_FDO_FLAG_HUB_BUSY
Definition: usbhub.h:38
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
#define IRP_MN_QUERY_DEVICE_RELATIONS
#define USBHUB_FDO_FLAG_DEVICE_STOPPED
Definition: usbhub.h:37
VOID NTAPI USBH_FdoSurpriseRemoveDevice(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PIRP Irp)
Definition: pnp.c:1517
#define IRP_MN_SET_LOCK
#define IRP_MN_CANCEL_STOP_DEVICE
#define IRP_MN_DEVICE_USAGE_NOTIFICATION
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
#define USBHUB_FDO_FLAG_WAIT_IDLE_REQUEST
Definition: usbhub.h:44
return STATUS_SUCCESS
Definition: btrfs.c:3014
#define IRP_MN_QUERY_PNP_DEVICE_STATE
NTSTATUS NTAPI USBH_FdoRemoveDevice(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PIRP Irp)
Definition: pnp.c:1456
#define IRP_MN_QUERY_CAPABILITIES

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",
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,
564  KernelMode,
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,
578  KernelMode,
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 
593  USBH_SubmitStatusChangeTransfer(HubExtension);
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");
637  DbgBreakPoint();
638  break;
639  }
640  }
641  else
642  {
644  {
647  }
648 
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 
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,
710  NULL) == STATUS_PENDING)
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 
727  {
728  USBH_CheckIdleDeferred(HubExtension);
729  }
730 
733 
734  return PoCallDriver(HubExtension->LowerDevice, Irp);
735  }
736 
737  break;
738 
739  case IRP_MN_QUERY_POWER:
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 }
_Out_opt_ PULONG Minor
Definition: cmfuncs.h:44
#define USBHUB_FDO_FLAG_SET_D0_STATE
Definition: usbhub.h:42
CPPORT Port[4]
Definition: headless.c:34
#define TRUE
Definition: types.h:120
_In_ UCHAR _In_ POWER_STATE PowerState
Definition: pofuncs.h:42
#define USBHUB_FDO_FLAG_HIBERNATE_STATE
Definition: usbhub.h:54
#define IRP_MN_POWER_SEQUENCE
#define IRP_MN_QUERY_POWER
_In_ PIRP Irp
Definition: csq.h:116
#define USBHUB_FDO_FLAG_DO_SUSPENSE
Definition: usbhub.h:56
PUSBHUB_FDO_EXTENSION NTAPI USBH_GetRootHubExtension(IN PUSBHUB_FDO_EXTENSION HubExtension)
Definition: usbhub.c:699
LONG NTSTATUS
Definition: precomp.h:26
#define USBHUB_FDO_FLAG_PENDING_WAKE_IRP
Definition: usbhub.h:39
#define LOW_REALTIME_PRIORITY
VOID NTAPI USBH_CheckIdleDeferred(IN PUSBHUB_FDO_EXTENSION HubExtension)
Definition: usbhub.c:3957
void DbgBreakPoint()
Definition: mach.c:553
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
#define IoSetCompletionRoutine(_Irp, _CompletionRoutine, _Context, _InvokeOnSuccess, _InvokeOnError, _InvokeOnCancel)
Definition: irp.cpp:498
#define USBHUB_FDO_FLAG_DEVICE_STARTED
Definition: usbhub.h:33
PDEVICE_OBJECT DeviceObject
Definition: usbhub.h:119
SYSTEM_POWER_STATE SystemState
Definition: ntpoapi.h:57
FORCEINLINE VOID IoCopyCurrentIrpStackLocationToNext(_Inout_ PIRP Irp)
Definition: iofuncs.h:2820
POWER_STATE CurrentPowerState
Definition: usbhub.h:222
PVOID DeviceExtension
Definition: env_spec_w32.h:418
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
#define IoCompleteRequest
Definition: irp.c:1240
#define STATUS_PENDING
Definition: ntstatus.h:82
POWER_STATE SystemPowerState
Definition: usbhub.h:161
static void Exit(void)
Definition: sock.c:1331
DEVICE_POWER_STATE DeviceState
Definition: ntpoapi.h:58
#define USBHUB_FDO_FLAG_NOT_D0_STATE
Definition: usbhub.h:43
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define USBHUB_FDO_FLAG_DEVICE_STOPPING
Definition: usbhub.h:34
#define IRP_MN_SET_POWER
#define DPRINT_PWR(...)
Definition: dbg_uhub.h:108
Status
Definition: gdiplustypes.h:24
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
VOID NTAPI PoStartNextPowerIrp(IN PIRP Irp)
Definition: power.c:737
LONG NTAPI KeReleaseSemaphore(IN PKSEMAPHORE Semaphore, IN KPRIORITY Increment, IN LONG Adjustment, IN BOOLEAN Wait)
Definition: semphobj.c:54
BOOLEAN NTAPI USBH_CheckIdleAbort(IN PUSBHUB_FDO_EXTENSION HubExtension, IN BOOLEAN IsWait, IN BOOLEAN IsExtCheck)
Definition: usbhub.c:3221
#define USBHUB_FDO_FLAG_DEVICE_STOPPED
Definition: usbhub.h:37
#define DPRINT1
Definition: precomp.h:8
BOOLEAN NTAPI IoCancelIrp(IN PIRP Irp)
Definition: irp.c:1101
NTSTATUS NTAPI USBH_FdoWWIrpIoCompletion(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context)
Definition: power.c:271
unsigned int ULONG
Definition: retypes.h:1
#define IO_NO_INCREMENT
Definition: iotypes.h:566
#define IRP_MN_WAIT_WAKE
NTSTATUS NTAPI PoRequestPowerIrp(IN PDEVICE_OBJECT DeviceObject, IN UCHAR MinorFunction, IN POWER_STATE PowerState, IN PREQUEST_POWER_COMPLETE CompletionFunction, IN PVOID Context, OUT PIRP *pIrp OPTIONAL)
Definition: power.c:639
NTSTATUS NTAPI USBH_SubmitStatusChangeTransfer(IN PUSBHUB_FDO_EXTENSION HubExtension)
Definition: usbhub.c:2442
NTSTATUS NTAPI USBH_PowerIrpCompletion(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context)
Definition: power.c:349
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
IoMarkIrpPending(Irp)
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

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 }
NTSTATUS NTAPI USBH_SyncSubmitUrb(IN PDEVICE_OBJECT DeviceObject, IN PURB Urb)
Definition: usbhub.c:250
void DPRINT(...)
Definition: polytest.cpp:61
PDEVICE_OBJECT LowerDevice
Definition: usbhub.h:150

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 {
2939  PIO_WORKITEM WorkItem;
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 
2952  IoFreeWorkItem(WorkItem);
2953 }
VOID NTAPI IoFreeWorkItem(IN PIO_WORKITEM IoWorkItem)
Definition: iowork.c:64
void DPRINT(...)
Definition: polytest.cpp:61
#define USB_HUB_TAG
Definition: usbhub.h:26
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099

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 {
977  PUSB_CONFIGURATION_DESCRIPTOR ConfigDescriptor;
978  ULONG ReturnedLen;
979  SIZE_T DescriptorLen;
981 
982  DPRINT("USBH_GetConfigurationDescriptor: ... \n");
983 
984  DescriptorLen = MAXUCHAR;
985 
986  while (TRUE)
987  {
988  ConfigDescriptor = ExAllocatePoolWithTag(NonPagedPool,
989  DescriptorLen,
990  USB_HUB_TAG);
991 
992  if (!ConfigDescriptor)
993  {
995  break;
996  }
997 
999  ConfigDescriptor,
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 
1022  ExFreePool(ConfigDescriptor);
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  {
1037  ExFreePool(ConfigDescriptor);
1038  }
1039 
1040  *OutDescriptor = NULL;
1041  }
1042 
1043  return Status;
1044 }
#define TRUE
Definition: types.h:120
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
NTSTATUS NTAPI USBH_SyncGetDeviceConfigurationDescriptor(IN PDEVICE_OBJECT DeviceObject, IN PUSB_CONFIGURATION_DESCRIPTOR ConfigDescriptor, IN ULONG NumberOfBytes, IN PULONG OutLength)
Definition: usbhub.c:913
LONG NTSTATUS
Definition: precomp.h:26
#define MAXUCHAR
Definition: umtypes.h:117
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
#define USB_HUB_TAG
Definition: usbhub.h:26
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1569
ULONG_PTR SIZE_T
Definition: typedefs.h:79
unsigned int ULONG
Definition: retypes.h:1
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
#define STATUS_DEVICE_DATA_ERROR
Definition: udferr_usr.h:159

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 {
880  struct _URB_CONTROL_DESCRIPTOR_REQUEST * Urb;
882 
883  DPRINT("USBH_GetDeviceDescriptor: ... \n");
884 
886  sizeof(struct _URB_CONTROL_DESCRIPTOR_REQUEST),
887  USB_HUB_TAG);
888 
889  if (!Urb)
890  {
891  DPRINT1("USBH_SyncGetDeviceHandle: Urb - NULL!\n");
893  }
894 
895  RtlZeroMemory(Urb, sizeof(struct _URB_CONTROL_DESCRIPTOR_REQUEST));
896 
898  Urb->Hdr.Length = sizeof(struct _URB_CONTROL_DESCRIPTOR_REQUEST);
899 
901  Urb->TransferBuffer = HubDeviceDescriptor;
903 
905 
907 
908  return Status;
909 }
struct _USB_DEVICE_DESCRIPTOR USB_DEVICE_DESCRIPTOR
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
LONG NTSTATUS
Definition: precomp.h:26
#define USB_DEVICE_DESCRIPTOR_TYPE
Definition: usb100.h:49
struct _URB_HEADER Hdr
Definition: usb.h:341
NTSTATUS NTAPI USBH_FdoSyncSubmitUrb(IN PDEVICE_OBJECT FdoDevice, IN PURB Urb)
Definition: usbhub.c:355
void DPRINT(...)
Definition: polytest.cpp:61
#define USB_HUB_TAG
Definition: usbhub.h:26
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define URB_FUNCTION_GET_DESCRIPTOR_FROM_DEVICE
Definition: usb.h:97
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1569
Definition: usb.h:529
#define DPRINT1
Definition: precomp.h:8
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099

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");
626  return STATUS_NOT_IMPLEMENTED;
627  }
628 
630 
631  while (TRUE)
632  {
635  USB_HUB_TAG);
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,
649  DeviceHandle,
650  DeviceInfo,
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 }
enum _USB_DEVICE_TYPE USB_DEVICE_TYPE
#define TRUE
Definition: types.h:120
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_Inout_ PUSB_DEVICE_HANDLE DeviceHandle
Definition: hubbusif.h:121
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
DeviceType
Definition: mmdrv.h:41
LONG NTSTATUS
Definition: precomp.h:26
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
struct _USB_DEVICE_INFORMATION_0 USB_DEVICE_INFORMATION_0
void DPRINT(...)
Definition: polytest.cpp:61
#define USB_HUB_TAG
Definition: usbhub.h:26
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:195
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
struct _DeviceInfo DeviceInfo
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
Status
Definition: gdiplustypes.h:24
ULONG_PTR SIZE_T
Definition: typedefs.h:79
unsigned char dummy
Definition: maze.c:118
_In_ PUSB_DEVICE_HANDLE _In_ ULONG DeviceInformationBufferLength
Definition: hubbusif.h:181
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
USB_BUSIFFN_GET_DEVICE_INFORMATION * PUSB_BUSIFFN_GET_DEVICE_INFORMATION
Definition: hubbusif.h:183

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 }
_In_ PIRP _In_ PDEVICE_OBJECT Device
Definition: fatprocs.h:2029
void DPRINT(...)
Definition: polytest.cpp:61

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 DPRINT(...)
Definition: polytest.cpp:61
#define InterlockedExchange
Definition: armddk.h:54
BOOLEAN NTAPI IoCancelIrp(IN PIRP Irp)
Definition: irp.c:1101
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 }
_In_ PIRP Irp
Definition: csq.h:116
#define IoCompleteRequest
Definition: irp.c:1240
void DPRINT(...)
Definition: polytest.cpp:61
#define STATUS_CANCELLED
Definition: udferr_usr.h:170
#define InterlockedExchange
Definition: armddk.h:54
VOID NTAPI PoStartNextPowerIrp(IN PIRP Irp)
Definition: power.c:737
BOOLEAN NTAPI IoCancelIrp(IN PIRP Irp)
Definition: irp.c:1101
#define IO_NO_INCREMENT
Definition: iotypes.h:566
signed int * PLONG
Definition: retypes.h:5

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
#define USBHUB_FDO_FLAG_DEVICE_STARTED
Definition: usbhub.h:33
void DPRINT(...)
Definition: polytest.cpp:61
VOID NTAPI USBH_HubCompleteQueuedPortWakeIrps(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PLIST_ENTRY ListIrps, IN NTSTATUS NtStatus)
Definition: power.c:202
Definition: typedefs.h:118

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 {
1592  BOOLEAN Result;
1593  USHORT UsbStatus;
1594  NTSTATUS Status;
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 }
LONG NTSTATUS
Definition: precomp.h:26
unsigned char BOOLEAN
_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:426
void DPRINT(...)
Definition: polytest.cpp:61
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define USB_CONFIG_BUS_POWERED
Definition: usb100.h:69
#define USB_GETSTATUS_SELF_POWERED
Definition: usb100.h:45
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1569
unsigned short USHORT
Definition: pedump.c:61
#define URB_FUNCTION_GET_STATUS_FROM_DEVICE
Definition: usb.h:105
#define USB_CONFIG_POWERED_MASK
Definition: usb100.h:68
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;
81  KEVENT Event;
83 
84  DPRINT("USBH_HubSetD0: HubExtension - %p\n", HubExtension);
85 
86  RootHubDevExt = USBH_GetRootHubExtension(HubExtension);
87 
88  if (RootHubDevExt->SystemPowerState.SystemState != PowerSystemWorking)
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,
99  Suspended,
100  KernelMode,
101  FALSE,
102  NULL);
103  }
104 
106 
108 
109  Status = PoRequestPowerIrp(HubExtension->LowerPDO,
111  PowerState,
113  &Event,
114  NULL);
115 
116  if (Status == STATUS_PENDING)
117  {
119  Suspended,
120  KernelMode,
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 }
_In_ UCHAR _In_ POWER_STATE PowerState
Definition: pofuncs.h:42
PUSBHUB_FDO_EXTENSION NTAPI USBH_GetRootHubExtension(IN PUSBHUB_FDO_EXTENSION HubExtension)
Definition: usbhub.c:699
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
#define STATUS_INVALID_DEVICE_STATE
Definition: udferr_usr.h:178
SYSTEM_POWER_STATE SystemState
Definition: ntpoapi.h:57
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:435
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
NTSTATUS NTAPI USBH_Wait(IN ULONG Milliseconds)
Definition: usbhub.c:23
#define USBHUB_FDO_FLAG_WAKEUP_START
Definition: usbhub.h:49
#define STATUS_PENDING
Definition: ntstatus.h:82
POWER_STATE SystemPowerState
Definition: usbhub.h:161
DEVICE_POWER_STATE DeviceState
Definition: ntpoapi.h:58
#define IRP_MN_SET_POWER
Status
Definition: gdiplustypes.h:24
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
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
NTSTATUS NTAPI PoRequestPowerIrp(IN PDEVICE_OBJECT DeviceObject, IN UCHAR MinorFunction, IN POWER_STATE PowerState, IN PREQUEST_POWER_COMPLETE CompletionFunction, IN PVOID Context, OUT PIRP *pIrp OPTIONAL)
Definition: power.c:639
#define USBHUB_FDO_FLAG_WAIT_IDLE_REQUEST
Definition: usbhub.h:44

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 }
_In_ PIRP Irp
Definition: csq.h:116
IO_STATUS_BLOCK IoStatus
#define USBHUB_FDO_FLAG_DEVICE_STARTED
Definition: usbhub.h:33
#define IoCompleteRequest
Definition: irp.c:1240
void DPRINT(...)
Definition: polytest.cpp:61
NTSTATUS NTAPI USBH_HubSetD0(IN PUSBHUB_FDO_EXTENSION HubExtension)
Definition: power.c:77
#define STATUS_CANCELLED
Definition: udferr_usr.h:170
struct tagContext Context
Definition: acpixf.h:1034
#define IO_NO_INCREMENT
Definition: iotypes.h:566

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 
87  return IoCallDriver(DeviceObject, Irp);
88 }
_In_ PIRP Irp
Definition: csq.h:116
#define DPRINT_PNP(...)
Definition: dbg_uhub.h:109
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1569
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
#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 
1307  IoStack = IoGetCurrentIrpStackLocation(Irp);
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 
1418 Exit:
1420  return Status;
1421 }
#define IOCTL_INTERNAL_USB_SUBMIT_URB
Definition: usbioctl.h:32
NTSTATUS NTAPI USBH_SyncGetHubCount(IN PDEVICE_OBJECT DeviceObject, IN OUT PULONG OutHubCount)
Definition: usbhub.c:781
#define IOCTL_GET_HCD_DRIVERKEY_NAME
Definition: usbioctl.h:165
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define IOCTL_INTERNAL_USB_GET_PARENT_HUB_INFO
Definition: usbioctl.h:68
#define IOCTL_INTERNAL_USB_ENABLE_PORT
Definition: usbioctl.h:47
NTSTATUS NTAPI USBH_PdoIoctlSubmitUrb(IN PUSBHUB_PORT_PDO_EXTENSION PortExtension, IN PIRP Irp)
Definition: ioctl.c:210
#define IOCTL_INTERNAL_USB_GET_HUB_NAME
Definition: usbioctl.h:56
LONG NTSTATUS
Definition: precomp.h:26
#define IOCTL_INTERNAL_USB_GET_BUS_INFO
Definition: usbioctl.h:59
void DbgBreakPoint()
Definition: mach.c:553
#define DPRINT_IOCTL(...)
Definition: dbg_uhub.h:107
#define USBHUB_PDO_FLAG_NOT_CONNECTED
Definition: usbhub.h:67
#define STATUS_DEVICE_POWERED_OFF
Definition: ntstatus.h:183
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
_IRQL_requires_same_ typedef _In_ ULONG ControlCode
Definition: wmitypes.h:55
#define USBHUB_PDO_FLAG_HUB_DEVICE
Definition: usbhub.h:61
#define IOCTL_INTERNAL_USB_CYCLE_PORT
Definition: usbioctl.h:53
#define STATUS_DEVICE_NOT_CONNECTED
Definition: udferr_usr.h:160
static void Exit(void)
Definition: sock.c:1331
PDEVICE_OBJECT LowerDevice
Definition: usbhub.h:150
#define IOCTL_INTERNAL_USB_GET_HUB_COUNT
Definition: usbioctl.h:50
NTSTATUS NTAPI USBH_PassIrp(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: usbhub.c:79
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define IOCTL_INTERNAL_USB_GET_ROOTHUB_PDO
Definition: usbioctl.h:38
VOID NTAPI USBH_CompleteIrp(IN PIRP Irp, IN NTSTATUS CompleteStatus)
Definition: usbhub.c:63
NTSTATUS NTAPI USBH_PdoIoctlGetPortStatus(IN PUSBHUB_PORT_PDO_EXTENSION PortExtension, IN PIRP Irp)
Definition: ioctl.c:239
NTSTATUS NTAPI USBH_PdoIoctlResetPort(IN PUSBHUB_PORT_PDO_EXTENSION PortExtension, IN PIRP Irp)
Definition: ioctl.c:379
Status
Definition: gdiplustypes.h:24
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
#define STATUS_DEVICE_BUSY
Definition: udferr_usr.h:129
unsigned int * PULONG
Definition: retypes.h:1
PDEVICE_OBJECT RootHubPdo
Definition: usbhub.h:151
#define IOCTL_INTERNAL_USB_RESET_PORT
Definition: usbioctl.h:35
#define IOCTL_INTERNAL_USB_GET_PORT_STATUS
Definition: usbioctl.h:44
#define DPRINT1
Definition: precomp.h:8
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:409
unsigned int ULONG
Definition: retypes.h:1
NTSTATUS NTAPI USBH_PortIdleNotificationRequest(IN PUSBHUB_PORT_PDO_EXTENSION PortExtension, IN PIRP Irp)
Definition: ioctl.c:487
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
return STATUS_SUCCESS
Definition: btrfs.c:3014

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 2587 of file pnp.c.

2591 {
2592  NTSTATUS Status;
2593  PIO_STACK_LOCATION IoStack;
2594  PPNP_BUS_INFORMATION BusInfo;
2596  USHORT Size;
2597  USHORT Version;
2598  PUSBHUB_FDO_EXTENSION HubExtension;
2599  PDEVICE_RELATIONS DeviceRelation;
2600 
2601  DPRINT_PNP("USBH_PdoPnP: PortExtension - %p, Irp - %p, Minor - %X\n",
2602  PortExtension,
2603  Irp,
2604  Minor);
2605 
2606  IoStack = IoGetCurrentIrpStackLocation(Irp);
2607 
2608  *IsCompleteIrp = TRUE;
2609 
2610  switch (Minor)
2611  {
2612  case IRP_MN_START_DEVICE:
2613  DPRINT_PNP("PDO IRP_MN_START_DEVICE\n");
2614  return USBH_PdoStartDevice(PortExtension, Irp);
2615 
2617  DPRINT_PNP("PDO IRP_MN_QUERY_REMOVE_DEVICE\n");
2618  return STATUS_SUCCESS;
2619 
2620  case IRP_MN_REMOVE_DEVICE:
2621  DPRINT_PNP("PDO IRP_MN_REMOVE_DEVICE\n");
2622  return USBH_PdoRemoveDevice(PortExtension, PortExtension->HubExtension);
2623 
2625  DPRINT_PNP("PDO IRP_MN_CANCEL_REMOVE_DEVICE\n");
2626  return STATUS_SUCCESS;
2627 
2628  case IRP_MN_STOP_DEVICE:
2629  DPRINT_PNP("PDO IRP_MN_STOP_DEVICE\n");
2630  return USBH_PdoStopDevice(PortExtension, Irp);
2631 
2633  DPRINT_PNP("PDO IRP_MN_QUERY_STOP_DEVICE\n");
2634  return STATUS_SUCCESS;
2635 
2637  DPRINT_PNP("PDO IRP_MN_CANCEL_STOP_DEVICE\n");
2638  return STATUS_SUCCESS;
2639 
2641  DPRINT_PNP("PDO IRP_MN_QUERY_DEVICE_RELATIONS\n");
2642 
2643  if (IoStack->Parameters.QueryDeviceRelations.Type != TargetDeviceRelation)
2644  {
2645  return Irp->IoStatus.Status;
2646  }
2647 
2648  DeviceRelation = ExAllocatePoolWithTag(PagedPool,
2649  sizeof(DEVICE_RELATIONS),
2650  USB_HUB_TAG);
2651 
2652  if (DeviceRelation)
2653  {
2654  RtlZeroMemory(DeviceRelation, sizeof(DEVICE_RELATIONS));
2655 
2656  DeviceRelation->Count = 1;
2657  DeviceRelation->Objects[0] = PortExtension->Common.SelfDevice;
2658 
2659  ObReferenceObject(DeviceRelation->Objects[0]);
2660 
2662  }
2663  else
2664  {
2666  }
2667 
2668  Irp->IoStatus.Information = (ULONG_PTR)DeviceRelation;
2669  break;
2670 
2672  DPRINT_PNP("PDO IRP_MN_QUERY_INTERFACE\n");
2673 
2674  *IsCompleteIrp = 0;
2675 
2676  if (IsEqualGUIDAligned(IoStack->Parameters.QueryInterface.InterfaceType,
2677  &USB_BUS_INTERFACE_USBDI_GUID))
2678  {
2679  IoStack->Parameters.QueryInterface.InterfaceSpecificData = PortExtension->DeviceHandle;
2680  }
2681 
2682  HubExtension = PortExtension->HubExtension;
2683 
2684  if (!HubExtension)
2685  {
2686  HubExtension = PortExtension->RootHubExtension;
2687  }
2688 
2689  Status = USBH_PassIrp(HubExtension->RootHubPdo, Irp);
2690  break;
2691 
2693  DPRINT_PNP("PDO IRP_MN_QUERY_CAPABILITIES\n");
2694 
2695  DeviceCapabilities = IoStack->Parameters.DeviceCapabilities.Capabilities;
2696 
2697  Size = DeviceCapabilities->Size;
2698  Version = DeviceCapabilities->Version;
2699 
2701  &PortExtension->Capabilities,
2702  sizeof(DEVICE_CAPABILITIES));
2703 
2704  DeviceCapabilities->Size = Size;
2705  DeviceCapabilities->Version = Version;
2706 
2707  /* All devices connected to a hub are removable */
2708  DeviceCapabilities->Removable = 1;
2709 
2711  break;
2712 
2714  DPRINT_PNP("PDO IRP_MN_QUERY_RESOURCES\n");
2715  Status = Irp->IoStatus.Status;
2716  break;
2717 
2719  DPRINT_PNP("PDO IRP_MN_QUERY_RESOURCE_REQUIREMENTS\n");
2720  PortExtension->PortPdoFlags |= USBHUB_PDO_FLAG_ENUMERATED;
2721 
2722  /* FIXME HKEY_LOCAL_MACHINE\SYSTEM\ControlSetXXX\Enum\USB\
2723  Vid_????&Pid_????\????????????\Device Parameters\
2724  if (ExtPropDescSemaphore)
2725  */
2726 
2728  break;
2729 
2731  DPRINT_PNP("PDO IRP_MN_QUERY_DEVICE_TEXT\n");
2732  return USBH_PdoQueryDeviceText(PortExtension, Irp);
2733 
2735  DPRINT_PNP("PDO IRP_MN_FILTER_RESOURCE_REQUIREMENTS\n");
2736  Status = Irp->IoStatus.Status;
2737  break;
2738 
2739  case IRP_MN_READ_CONFIG:
2740  DPRINT_PNP("PDO IRP_MN_READ_CONFIG\n");
2741  DbgBreakPoint();
2742  Status = Irp->IoStatus.Status;
2743  break;
2744 
2745  case IRP_MN_WRITE_CONFIG:
2746  DPRINT_PNP("PDO IRP_MN_WRITE_CONFIG\n");
2747  DbgBreakPoint();
2748  Status = Irp->IoStatus.Status;
2749  break;
2750 
2751  case IRP_MN_EJECT:
2752  DPRINT_PNP("PDO IRP_MN_EJECT\n");
2753  DbgBreakPoint();
2754  Status = Irp->IoStatus.Status;
2755  break;
2756 
2757  case IRP_MN_SET_LOCK:
2758  DPRINT_PNP("PDO IRP_MN_SET_LOCK\n");
2759  DbgBreakPoint();
2760  Status = Irp->IoStatus.Status;
2761  break;
2762 
2763  case IRP_MN_QUERY_ID:
2764  DPRINT_PNP("PDO IRP_MN_QUERY_ID\n");
2765  return USBH_PdoQueryId(PortExtension, Irp);
2766 
2768  DPRINT_PNP("PDO IRP_MN_QUERY_PNP_DEVICE_STATE\n");
2769  if (PortExtension->PortPdoFlags & (USBHUB_PDO_FLAG_INSUFFICIENT_PWR |
2773  {
2774  Irp->IoStatus.Information |= PNP_DEVICE_FAILED;
2775  }
2776 
2778  break;
2779 
2781  DPRINT_PNP("PDO IRP_MN_QUERY_BUS_INFORMATION\n");
2782 
2783  BusInfo = ExAllocatePoolWithTag(PagedPool,
2784  sizeof(PNP_BUS_INFORMATION),
2785  USB_HUB_TAG);
2786 
2787  if (!BusInfo)
2788  {
2790  }
2791 
2792  RtlZeroMemory(BusInfo, sizeof(PNP_BUS_INFORMATION));
2793 
2794  RtlCopyMemory(&BusInfo->BusTypeGuid,
2795  &GUID_BUS_TYPE_USB,
2796  sizeof(BusInfo->BusTypeGuid));
2797 
2798  BusInfo->LegacyBusType = PNPBus;
2799  BusInfo->BusNumber = 0;
2800 
2801  Irp->IoStatus.Information = (ULONG_PTR)BusInfo;
2803  break;
2804 
2806  DPRINT_PNP("PDO IRP_MN_DEVICE_USAGE_NOTIFICATION\n");
2807  DbgBreakPoint();
2808  Status = Irp->IoStatus.Status;
2809  break;
2810 
2812  DPRINT_PNP("PDO IRP_MN_SURPRISE_REMOVAL\n");
2813  if (PortExtension->PortPdoFlags & USBHUB_PDO_FLAG_REG_DEV_INTERFACE)
2814  {
2815  Status = USBH_SymbolicLink(PortExtension, NULL, FALSE);
2816 
2817  if (NT_SUCCESS(Status))
2818  {
2819  PortExtension->PortPdoFlags &= ~USBHUB_PDO_FLAG_REG_DEV_INTERFACE;
2820  }
2821  }
2822 
2824  break;
2825 
2826  default:
2827  DPRINT_PNP("PDO unknown IRP_MN_???\n");
2828  Status = Irp->IoStatus.Status;
2829  break;
2830  }
2831 
2832  return Status;
2833 }
_Out_opt_ PULONG Minor
Definition: cmfuncs.h:44
#define IRP_MN_CANCEL_REMOVE_DEVICE
#define USBHUB_PDO_FLAG_INSUFFICIENT_PWR
Definition: usbhub.h:77
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
IN PVOID IN PVOID IN USHORT Version
Definition: pci.h:361
#define IRP_MN_QUERY_RESOURCES
#define IRP_MN_REMOVE_DEVICE
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define IRP_MN_QUERY_ID
#define USBHUB_PDO_FLAG_REG_DEV_INTERFACE
Definition: usbhub.h:72
#define USBHUB_PDO_FLAG_ENUMERATED
Definition: usbhub.h:82
_In_ PIRP Irp
Definition: csq.h:116
#define IRP_MN_FILTER_RESOURCE_REQUIREMENTS
#define IRP_MN_QUERY_RESOURCE_REQUIREMENTS
NTSTATUS NTAPI USBH_PdoStartDevice(IN PUSBHUB_PORT_PDO_EXTENSION PortExtension, IN PIRP Irp)
Definition: pnp.c:2117
#define IRP_MN_WRITE_CONFIG
PDEVICE_OBJECT Objects[1]
Definition: iotypes.h:2055
LONG NTSTATUS
Definition: precomp.h:26
DEVICE_CAPABILITIES
Definition: iotypes.h:928
#define IRP_MN_EJECT
void DbgBreakPoint()
Definition: mach.c:553
#define USBHUB_PDO_FLAG_INIT_PORT_FAILED
Definition: usbhub.h:63
#define IsEqualGUIDAligned(guid1, guid2)
Definition: wdm.template.h:233
#define USBHUB_PDO_FLAG_OVERCURRENT_PORT
Definition: usbhub.h:75
#define IRP_MN_QUERY_REMOVE_DEVICE
smooth NULL
Definition: ftsmooth.c:416
NTSTATUS NTAPI USBH_SymbolicLink(IN PUSBHUB_PORT_PDO_EXTENSION PortExtension, IN const GUID *InterfaceClassGuid, IN BOOLEAN IsEnable)
Definition: pnp.c:2001
#define DeviceCapabilities
Definition: wingdi.h:4448
#define USB_HUB_TAG
Definition: usbhub.h:26
NTSTATUS NTAPI USBH_PdoRemoveDevice(IN PUSBHUB_PORT_PDO_EXTENSION PortExtension, IN PUSBHUB_FDO_EXTENSION HubExtension)
Definition: pnp.c:2173
NTSTATUS NTAPI USBH_PdoQueryId(IN PUSBHUB_PORT_PDO_EXTENSION PortExtension, IN PIRP Irp)
Definition: pnp.c:1554
#define IRP_MN_READ_CONFIG
#define IRP_MN_QUERY_STOP_DEVICE
#define IRP_MN_SURPRISE_REMOVAL
Definition: ntifs_ex.h:408
#define IRP_MN_STOP_DEVICE
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define IRP_MN_START_DEVICE
#define IRP_MN_QUERY_DEVICE_TEXT
#define IRP_MN_QUERY_INTERFACE
NTSTATUS NTAPI USBH_PassIrp(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: usbhub.c:79
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define IRP_MN_QUERY_BUS_INFORMATION
#define PNP_DEVICE_FAILED
Definition: iotypes.h:966
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
* PDEVICE_CAPABILITIES
Definition: iotypes.h:928
Status
Definition: gdiplustypes.h:24
#define DPRINT_PNP(...)
Definition: dbg_uhub.h:109
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
NTSTATUS NTAPI USBH_PdoQueryDeviceText(IN PUSBHUB_PORT_PDO_EXTENSION PortExtension, IN PIRP Irp)
Definition: pnp.c:1846
NTSTATUS NTAPI USBH_PdoStopDevice(IN PUSBHUB_PORT_PDO_EXTENSION PortExtension, IN PIRP Irp)
Definition: pnp.c:2345
unsigned short USHORT
Definition: pedump.c:61
#define USBHUB_PDO_FLAG_PORT_RESTORE_FAIL
Definition: usbhub.h:73
PDEVICE_OBJECT RootHubPdo
Definition: usbhub.h:151
#define IRP_MN_QUERY_DEVICE_RELATIONS
HRESULT QueryInterface([in] REFIID riid, [out, iid_is(riid)] void **ppvObject)
#define ObReferenceObject
Definition: obfuncs.h:204
#define IRP_MN_SET_LOCK
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define ULONG_PTR
Definition: config.h:101
#define IRP_MN_CANCEL_STOP_DEVICE
#define IRP_MN_DEVICE_USAGE_NOTIFICATION
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
return STATUS_SUCCESS
Definition: btrfs.c:3014
INTERFACE_TYPE LegacyBusType
Definition: cmtypes.h:365
#define IRP_MN_QUERY_PNP_DEVICE_STATE
#define IRP_MN_QUERY_CAPABILITIES

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");