ReactOS 0.4.16-dev-297-gc569aee
usbhub.c File Reference
#include "usbhub.h"
#include <debug.h>
#include "dbg_uhub.h"
#include <ntddstor.h>
Include dependency graph for usbhub.c:

Go to the source code of this file.

Macros

#define NDEBUG
 
#define NDEBUG_USBHUB_SCE
 
#define NDEBUG_USBHUB_PNP
 

Functions

NTSTATUS NTAPI USBH_Wait (IN ULONG Milliseconds)
 
NTSTATUS NTAPI USBH_GetConfigValue (IN PWSTR ValueName, IN ULONG ValueType, IN PVOID ValueData, IN ULONG ValueLength, IN PVOID Context, IN PVOID EntryContext)
 
VOID NTAPI USBH_CompleteIrp (IN PIRP Irp, IN NTSTATUS CompleteStatus)
 
NTSTATUS NTAPI USBH_PassIrp (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS NTAPI USBH_SyncIrpComplete (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context)
 
BOOLEAN NTAPI IsBitSet (IN PUCHAR BitMapAddress, IN USHORT Bit)
 
PUSBHUB_PORT_PDO_EXTENSION NTAPI PdoExt (IN PDEVICE_OBJECT DeviceObject)
 
NTSTATUS NTAPI USBH_WriteFailReasonID (IN PDEVICE_OBJECT DeviceObject, IN ULONG FailReason)
 
VOID NTAPI USBH_UrbTimeoutDPC (IN PKDPC Dpc, IN PVOID DeferredContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
 
NTSTATUS NTAPI USBH_SetPdoRegistryParameter (IN PDEVICE_OBJECT DeviceObject, IN PCWSTR ValueName, 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_Transact (IN PUSBHUB_FDO_EXTENSION HubExtension, IN PVOID TransferBuffer, IN ULONG BufferLen, IN BOOLEAN IsDeviceToHost, IN USHORT Function, IN BM_REQUEST_TYPE RequestType, IN UCHAR Request, IN USHORT RequestValue, IN USHORT RequestIndex)
 
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)
 
NTSTATUS NTAPI USBHUB_GetExtendedHubInfo (IN PUSBHUB_FDO_EXTENSION HubExtension, IN PUSB_EXTHUB_INFORMATION_0 HubInfoBuffer)
 
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_SyncGetDeviceConfigurationDescriptor (IN PDEVICE_OBJECT DeviceObject, IN PUSB_CONFIGURATION_DESCRIPTOR ConfigDescriptor, IN ULONG NumberOfBytes, IN PULONG OutLength)
 
NTSTATUS NTAPI USBH_GetConfigurationDescriptor (IN PDEVICE_OBJECT DeviceObject, IN PUSB_CONFIGURATION_DESCRIPTOR *OutDescriptor)
 
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_SyncGetStatus (IN PDEVICE_OBJECT DeviceObject, IN PUSHORT OutStatus, IN USHORT Function, IN USHORT RequestIndex)
 
NTSTATUS NTAPI USBH_SyncGetHubStatus (IN PUSBHUB_FDO_EXTENSION HubExtension, IN PUSB_HUB_STATUS_AND_CHANGE HubStatus, IN ULONG Length)
 
NTSTATUS NTAPI USBH_SyncClearHubStatus (IN PUSBHUB_FDO_EXTENSION HubExtension, IN USHORT RequestValue)
 
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_SyncPowerOnPort (IN PUSBHUB_FDO_EXTENSION HubExtension, IN USHORT Port, IN BOOLEAN IsWait)
 
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_ChangeIndicationAckChangeComplete (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context)
 
NTSTATUS NTAPI USBH_ChangeIndicationAckChange (IN PUSBHUB_FDO_EXTENSION HubExtension, IN PIRP Irp, IN struct _URB_CONTROL_VENDOR_OR_CLASS_REQUEST *Urb, IN USHORT Port, IN USHORT RequestValue)
 
NTSTATUS NTAPI USBH_ChangeIndicationProcessChange (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context)
 
NTSTATUS NTAPI USBH_ChangeIndicationQueryChange (IN PUSBHUB_FDO_EXTENSION HubExtension, IN PIRP Irp, IN struct _URB_CONTROL_VENDOR_OR_CLASS_REQUEST *Urb, IN USHORT Port)
 
VOID NTAPI USBH_ProcessHubStateChange (IN PUSBHUB_FDO_EXTENSION HubExtension, IN PUSB_HUB_STATUS_AND_CHANGE HubStatus)
 
VOID NTAPI USBH_ProcessPortStateChange (IN PUSBHUB_FDO_EXTENSION HubExtension, IN USHORT Port, IN PUSB_PORT_STATUS_AND_CHANGE PortStatus)
 
NTSTATUS NTAPI USBH_GetPortStatus (IN PUSBHUB_FDO_EXTENSION HubExtension, IN PULONG PortStatus)
 
NTSTATUS NTAPI USBH_EnableParentPort (IN PUSBHUB_FDO_EXTENSION HubExtension)
 
NTSTATUS NTAPI USBH_ResetInterruptPipe (IN PUSBHUB_FDO_EXTENSION HubExtension)
 
NTSTATUS NTAPI USBH_ResetHub (IN PUSBHUB_FDO_EXTENSION HubExtension)
 
VOID NTAPI USBH_ChangeIndicationWorker (IN PUSBHUB_FDO_EXTENSION HubExtension, IN PVOID Context)
 
NTSTATUS NTAPI USBH_ChangeIndication (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context)
 
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 (PUSBHUB_FDO_EXTENSION HubExtension, PUSBHUB_IO_WORK_ITEM *OutHubIoWorkItem, PUSBHUB_WORKER_ROUTINE WorkerRoutine, SIZE_T BufferLength, PVOID *OutHubWorkItemBuffer, WORK_QUEUE_TYPE Type)
 
VOID NTAPI USBH_Worker (IN PDEVICE_OBJECT DeviceObject, IN PVOID Context)
 
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)
 
VOID NTAPI USBHUB_RootHubCallBack (IN PVOID Context)
 
NTSTATUS NTAPI USBD_RegisterRootHubCallBack (IN PUSBHUB_FDO_EXTENSION HubExtension)
 
NTSTATUS NTAPI USBD_UnRegisterRootHubCallBack (IN PUSBHUB_FDO_EXTENSION HubExtension)
 
VOID NTAPI USBH_HubSetDWakeCompletion (IN PDEVICE_OBJECT DeviceObject, IN UCHAR MinorFunction, IN POWER_STATE PowerState, IN PVOID Context, IN PIO_STATUS_BLOCK IoStatus)
 
VOID NTAPI USBH_HubQueuePortIdleIrps (IN PUSBHUB_FDO_EXTENSION HubExtension, IN PLIST_ENTRY IdleList)
 
VOID NTAPI USBH_HubCompleteQueuedPortIdleIrps (IN PUSBHUB_FDO_EXTENSION HubExtension, IN PLIST_ENTRY IdleList, IN NTSTATUS NtStatus)
 
VOID NTAPI USBH_FlushPortPwrList (IN PUSBHUB_FDO_EXTENSION HubExtension)
 
VOID NTAPI USBH_HubCompletePortIdleIrps (IN PUSBHUB_FDO_EXTENSION HubExtension, IN NTSTATUS NtStatus)
 
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_FdoWaitWakeIrpCompletion (IN PDEVICE_OBJECT DeviceObject, IN UCHAR MinorFunction, IN POWER_STATE PowerState, IN PVOID Context, IN PIO_STATUS_BLOCK IoStatus)
 
NTSTATUS NTAPI USBH_FdoSubmitWaitWakeIrp (IN PUSBHUB_FDO_EXTENSION HubExtension)
 
VOID NTAPI USBH_FdoIdleNotificationCallback (IN PVOID Context)
 
VOID NTAPI USBH_CompletePortIdleIrpsWorker (IN PUSBHUB_FDO_EXTENSION HubExtension, IN PVOID Context)
 
VOID NTAPI USBH_IdleCompletePowerHubWorker (IN PUSBHUB_FDO_EXTENSION HubExtension, IN PVOID Context)
 
NTSTATUS NTAPI USBH_FdoIdleNotificationRequestComplete (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context)
 
NTSTATUS NTAPI USBH_FdoSubmitIdleRequestIrp (IN PUSBHUB_FDO_EXTENSION HubExtension)
 
VOID NTAPI USBH_CheckHubIdle (IN PUSBHUB_FDO_EXTENSION HubExtension)
 
VOID NTAPI USBH_CheckIdleWorker (IN PUSBHUB_FDO_EXTENSION HubExtension, IN PVOID Context)
 
VOID NTAPI USBH_CheckIdleDeferred (IN PUSBHUB_FDO_EXTENSION HubExtension)
 
VOID NTAPI USBH_PdoSetCapabilities (IN PUSBHUB_PORT_PDO_EXTENSION PortExtension)
 
NTSTATUS NTAPI USBH_ProcessDeviceInformation (IN PUSBHUB_PORT_PDO_EXTENSION PortExtension)
 
BOOLEAN NTAPI USBH_CheckDeviceIDUnique (IN PUSBHUB_FDO_EXTENSION HubExtension, IN USHORT idVendor, IN USHORT idProduct, IN PVOID SerialNumber, IN USHORT SN_DescriptorLength)
 
BOOLEAN NTAPI USBH_ValidateSerialNumberString (IN PUSHORT SerialNumberString)
 
NTSTATUS NTAPI USBH_CheckDeviceLanguage (IN PDEVICE_OBJECT DeviceObject, IN USHORT LanguageId)
 
NTSTATUS NTAPI USBH_GetSerialNumberString (IN PDEVICE_OBJECT DeviceObject, IN LPWSTR *OutSerialNumber, IN PUSHORT OutDescriptorLength, IN USHORT LanguageId, IN UCHAR Index)
 
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 USBH_PdoDispatch (IN PUSBHUB_PORT_PDO_EXTENSION PortExtension, IN PIRP Irp)
 
NTSTATUS NTAPI USBH_FdoDispatch (IN PUSBHUB_FDO_EXTENSION HubExtension, IN PIRP Irp)
 
NTSTATUS NTAPI USBH_AddDevice (IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT LowerPDO)
 
VOID NTAPI USBH_DriverUnload (IN PDRIVER_OBJECT DriverObject)
 
NTSTATUS NTAPI USBH_HubDispatch (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS NTAPI USBH_RegQueryGenericUSBDeviceString (PVOID USBDeviceString)
 
NTSTATUS NTAPI DriverEntry (IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath)
 

Variables

PWSTR GenericUSBDeviceString = NULL
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 10 of file usbhub.c.

◆ NDEBUG_USBHUB_PNP

#define NDEBUG_USBHUB_PNP

Definition at line 14 of file usbhub.c.

◆ NDEBUG_USBHUB_SCE

#define NDEBUG_USBHUB_SCE

Definition at line 13 of file usbhub.c.

Function Documentation

◆ DriverEntry()

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

Definition at line 5115 of file usbhub.c.

5117{
5118 DPRINT("USBHUB: DriverEntry - %wZ\n", RegistryPath);
5119
5120 DriverObject->DriverExtension->AddDevice = USBH_AddDevice;
5121 DriverObject->DriverUnload = USBH_DriverUnload;
5122
5124 DriverObject->MajorFunction[IRP_MJ_CLOSE] = USBH_HubDispatch;
5125
5128
5129 DriverObject->MajorFunction[IRP_MJ_PNP] = USBH_HubDispatch;
5130 DriverObject->MajorFunction[IRP_MJ_POWER] = USBH_HubDispatch;
5132
5134
5135 return STATUS_SUCCESS;
5136}
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:73
NTSTATUS NTAPI USBH_AddDevice(IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT LowerPDO)
Definition: usbhub.c:4947
NTSTATUS NTAPI USBH_HubDispatch(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: usbhub.c:5034
PWSTR GenericUSBDeviceString
Definition: usbhub.c:19
NTSTATUS NTAPI USBH_RegQueryGenericUSBDeviceString(PVOID USBDeviceString)
Definition: usbhub.c:5090
VOID NTAPI USBH_DriverUnload(IN PDRIVER_OBJECT DriverObject)
Definition: usbhub.c:5021
_Must_inspect_result_ _In_ PDRIVER_OBJECT _In_ PCUNICODE_STRING RegistryPath
Definition: wdfdriver.h:215
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
#define IRP_MJ_SYSTEM_CONTROL
#define IRP_MJ_INTERNAL_DEVICE_CONTROL
#define IRP_MJ_POWER

◆ IsBitSet()

BOOLEAN NTAPI IsBitSet ( IN PUCHAR  BitMapAddress,
IN USHORT  Bit 
)

Definition at line 121 of file usbhub.c.

123{
124 BOOLEAN IsSet;
125
126 IsSet = (BitMapAddress[Bit / 8] & (1 << (Bit & 7))) != 0;
127 DPRINT("IsBitSet: Bit - %lX, IsSet - %x\n", Bit, IsSet);
128 return IsSet;
129}
unsigned char BOOLEAN

Referenced by USBH_ChangeIndication(), and USBH_ChangeIndicationWorker().

◆ PdoExt()

◆ USBD_CreateDeviceEx()

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

Definition at line 2508 of file usbhub.c.

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

Referenced by USBH_CreateDevice(), and USBH_ResetDevice().

◆ USBD_GetDeviceInformationEx()

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

Definition at line 2639 of file usbhub.c.

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

Referenced by USBH_IoctlGetNodeConnectionInformation().

◆ USBD_InitializeDeviceEx()

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

Definition at line 2562 of file usbhub.c.

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

Referenced by USBH_CreateDevice(), and USBH_ResetDevice().

◆ USBD_RegisterRootHubCallBack()

NTSTATUS NTAPI USBD_RegisterRootHubCallBack ( IN PUSBHUB_FDO_EXTENSION  HubExtension)

Definition at line 2986 of file usbhub.c.

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

Referenced by USBH_StartHubFdoDevice().

◆ USBD_RemoveDeviceEx()

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

Definition at line 2538 of file usbhub.c.

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

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

◆ USBD_RestoreDeviceEx()

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

Definition at line 2761 of file usbhub.c.

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

Referenced by USBH_ResetDevice().

◆ USBD_UnRegisterRootHubCallBack()

NTSTATUS NTAPI USBD_UnRegisterRootHubCallBack ( IN PUSBHUB_FDO_EXTENSION  HubExtension)

Definition at line 3008 of file usbhub.c.

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

Referenced by USBH_FdoCleanup().

◆ USBH_AddDevice()

NTSTATUS NTAPI USBH_AddDevice ( IN PDRIVER_OBJECT  DriverObject,
IN PDEVICE_OBJECT  LowerPDO 
)

Definition at line 4947 of file usbhub.c.

4949{
4952 PUSBHUB_FDO_EXTENSION HubExtension;
4953 PDEVICE_OBJECT LowerDevice;
4954
4955 DPRINT("USBH_AddDevice: DriverObject - %p, LowerPDO - %p\n",
4957 LowerPDO);
4958
4960
4962 sizeof(USBHUB_FDO_EXTENSION),
4963 NULL,
4964 0x8600,
4966 FALSE,
4967 &DeviceObject);
4968
4969 if (!NT_SUCCESS(Status))
4970 {
4971 DPRINT1("USBH_AddDevice: IoCreateDevice() fail\n");
4972
4973 if (DeviceObject)
4974 {
4976 }
4977
4978 return Status;
4979 }
4980
4981 DPRINT("USBH_AddDevice: DeviceObject - %p\n", DeviceObject);
4982
4983 HubExtension = DeviceObject->DeviceExtension;
4984 RtlZeroMemory(HubExtension, sizeof(USBHUB_FDO_EXTENSION));
4985
4987
4988 LowerDevice = IoAttachDeviceToDeviceStack(DeviceObject, LowerPDO);
4989
4990 if (!LowerDevice)
4991 {
4992 DPRINT1("USBH_AddDevice: IoAttachDeviceToDeviceStack() fail\n");
4993
4994 if (DeviceObject)
4995 {
4997 }
4998
4999 return STATUS_UNSUCCESSFUL;
5000 }
5001
5002 DPRINT("USBH_AddDevice: LowerDevice - %p\n", LowerDevice);
5003
5004 HubExtension->Common.SelfDevice = DeviceObject;
5005
5006 HubExtension->LowerPDO = LowerPDO;
5007 HubExtension->LowerDevice = LowerDevice;
5008
5009 KeInitializeSemaphore(&HubExtension->IdleSemaphore, 1, 1);
5010
5012 DeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
5013
5014 DPRINT("USBH_AddDevice: call IoWMIRegistrationControl() UNIMPLEMENTED. FIXME\n");
5015
5016 return Status;
5017}
#define DPRINT1
Definition: precomp.h:8
#define FILE_AUTOGENERATED_DEVICE_NAME
Definition: iotypes.h:138
PDEVICE_OBJECT NTAPI IoAttachDeviceToDeviceStack(IN PDEVICE_OBJECT SourceDevice, IN PDEVICE_OBJECT TargetDevice)
Definition: device.c:966
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
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
VOID NTAPI KeInitializeSemaphore(IN PKSEMAPHORE Semaphore, IN LONG Count, IN LONG Limit)
Definition: semphobj.c:22
PDEVICE_OBJECT SelfDevice
Definition: usbhub.h:144
PDEVICE_OBJECT LowerPDO
Definition: usbhub.h:149
KSEMAPHORE IdleSemaphore
Definition: usbhub.h:177
COMMON_DEVICE_EXTENSION Common
Definition: usbhub.h:148
PDEVICE_OBJECT LowerDevice
Definition: usbhub.h:150
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define USBH_EXTENSION_TYPE_HUB
Definition: usbhub.h:28
#define DO_POWER_PAGABLE

Referenced by DriverEntry().

◆ USBH_AllocateWorkItem()

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 at line 2791 of file usbhub.c.

2797{
2798 PUSBHUB_IO_WORK_ITEM HubIoWorkItem;
2800 PVOID WorkItemBuffer;
2801
2802 DPRINT("USBH_AllocateWorkItem: ... \n");
2803
2804 if (!(HubExtension->HubFlags & USBHUB_FDO_FLAG_WITEM_INIT))
2805 {
2807 }
2808
2809 HubIoWorkItem = ExAllocatePoolWithTag(NonPagedPool,
2810 sizeof(USBHUB_IO_WORK_ITEM),
2811 USB_HUB_TAG);
2812
2813 if (!HubIoWorkItem)
2814 {
2816 }
2817
2818 RtlZeroMemory(HubIoWorkItem, sizeof(USBHUB_IO_WORK_ITEM));
2819
2821
2822 HubIoWorkItem->HubWorkItem = WorkItem;
2823
2824 if (!WorkItem)
2825 {
2826 ExFreePoolWithTag(HubIoWorkItem, USB_HUB_TAG);
2828 }
2829
2830 if (BufferLength && OutHubWorkItemBuffer)
2831 {
2832 WorkItemBuffer = ExAllocatePoolWithTag(NonPagedPool,
2834 USB_HUB_TAG);
2835
2836 HubIoWorkItem->HubWorkItemBuffer = WorkItemBuffer;
2837
2838 if (!WorkItemBuffer)
2839 {
2840 IoFreeWorkItem(HubIoWorkItem->HubWorkItem);
2841 ExFreePoolWithTag(HubIoWorkItem, USB_HUB_TAG);
2842
2844 }
2845
2846 RtlZeroMemory(WorkItemBuffer, BufferLength);
2847 }
2848 else
2849 {
2850 HubIoWorkItem->HubWorkItemBuffer = NULL;
2851 }
2852
2853 HubIoWorkItem->HubWorkItemType = Type;
2854 HubIoWorkItem->HubExtension = HubExtension;
2855 HubIoWorkItem->HubWorkerRoutine = WorkerRoutine;
2856
2857 if (OutHubIoWorkItem)
2858 {
2859 *OutHubIoWorkItem = HubIoWorkItem;
2860 }
2861
2862 if (OutHubWorkItemBuffer)
2863 {
2864 *OutHubWorkItemBuffer = HubIoWorkItem->HubWorkItemBuffer;
2865 }
2866
2867 return STATUS_SUCCESS;
2868}
Type
Definition: Type.h:7
#define NonPagedPool
Definition: env_spec_w32.h:307
_Must_inspect_result_ _In_ PFLT_CALLBACK_DATA _In_ PFLT_DEFERRED_IO_WORKITEM_ROUTINE WorkerRoutine
Definition: fltkernel.h:1977
VOID NTAPI IoFreeWorkItem(IN PIO_WORKITEM IoWorkItem)
Definition: iowork.c:64
PIO_WORKITEM NTAPI IoAllocateWorkItem(IN PDEVICE_OBJECT DeviceObject)
Definition: iowork.c:75
PUSBHUB_WORKER_ROUTINE HubWorkerRoutine
Definition: usbhub.h:138
PUSBHUB_FDO_EXTENSION HubExtension
Definition: usbhub.h:137
WORK_QUEUE_TYPE HubWorkItemType
Definition: usbhub.h:136
PVOID HubWorkItemBuffer
Definition: usbhub.h:139
PIO_WORKITEM HubWorkItem
Definition: usbhub.h:135
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define USBHUB_FDO_FLAG_WITEM_INIT
Definition: usbhub.h:59
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG BufferLength
Definition: wdfdevice.h:3771
_Must_inspect_result_ _In_ PWDF_WORKITEM_CONFIG _In_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFWORKITEM * WorkItem
Definition: wdfworkitem.h:115

Referenced by USBH_ChangeIndication(), USBH_CheckIdleDeferred(), USBH_FdoIdleNotificationRequestComplete(), USBH_PdoIoctlResetPort(), and USBH_PortIdleNotificationCancelRoutine().

◆ USBH_ChangeIndication()

NTSTATUS NTAPI USBH_ChangeIndication ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp,
IN PVOID  Context 
)

Definition at line 2319 of file usbhub.c.

2322{
2323 PUSBHUB_FDO_EXTENSION HubExtension;
2324 USBD_STATUS UrbStatus;
2325 BOOLEAN IsErrors = FALSE;
2326 PUSBHUB_IO_WORK_ITEM HubWorkItem;
2327 PUSBHUB_STATUS_CHANGE_CONTEXT HubWorkItemBuffer;
2328 USHORT NumPorts;
2329 USHORT Port;
2331 PVOID Bitmap;
2333
2334 HubExtension = Context;
2335 UrbStatus = HubExtension->SCEWorkerUrb.Hdr.Status;
2336
2337 DPRINT_SCE("USBH_ChangeIndication: IrpStatus - %x, UrbStatus - %x, HubFlags - %lX\n",
2338 Irp->IoStatus.Status,
2339 UrbStatus,
2340 HubExtension->HubFlags);
2341
2342 if (NT_ERROR(Irp->IoStatus.Status) || USBD_ERROR(UrbStatus) ||
2343 (HubExtension->HubFlags & USBHUB_FDO_FLAG_DEVICE_FAILED) ||
2344 (HubExtension->HubFlags & USBHUB_FDO_FLAG_DEVICE_STOPPING))
2345 {
2346 HubExtension->RequestErrors++;
2347
2348 IsErrors = TRUE;
2349
2350 KeSetEvent(&HubExtension->StatusChangeEvent,
2352 FALSE);
2353
2354 if (HubExtension->HubFlags & USBHUB_FDO_FLAG_DEVICE_STOPPING ||
2355 HubExtension->HubFlags & USBHUB_FDO_FLAG_DEVICE_FAILED ||
2356 HubExtension->RequestErrors > USBHUB_MAX_REQUEST_ERRORS ||
2357 Irp->IoStatus.Status == STATUS_DELETE_PENDING)
2358 {
2359 DPRINT_SCE("USBH_ChangeIndication: HubExtension->RequestErrors - %x\n",
2360 HubExtension->RequestErrors);
2361
2363 }
2364
2365 DPRINT_SCE("USBH_ChangeIndication: HubExtension->RequestErrors - %x\n",
2366 HubExtension->RequestErrors);
2367 }
2368 else
2369 {
2370 HubExtension->RequestErrors = 0;
2371 }
2372
2374 HubExtension->SCEBitmapLength;
2375
2376 Status = USBH_AllocateWorkItem(HubExtension,
2377 &HubWorkItem,
2380 (PVOID *)&HubWorkItemBuffer,
2382
2383 if (!NT_SUCCESS(Status))
2384 {
2386 }
2387
2388 RtlZeroMemory(HubWorkItemBuffer, BufferLength);
2389
2390 HubWorkItemBuffer->IsRequestErrors = FALSE;
2391
2392 if (IsErrors)
2393 {
2394 HubWorkItemBuffer->IsRequestErrors = TRUE;
2395 }
2396
2397 if (InterlockedIncrement(&HubExtension->ResetRequestCount) == 1)
2398 {
2399 KeClearEvent(&HubExtension->ResetEvent);
2400 }
2401
2402 HubWorkItemBuffer->HubExtension = HubExtension;
2403
2404 HubExtension->WorkItemToQueue = HubWorkItem;
2405
2406 Bitmap = HubWorkItemBuffer + 1;
2407
2409 HubExtension->SCEBitmap,
2410 HubExtension->SCEBitmapLength);
2411
2412 NumPorts = HubExtension->HubDescriptor->bNumberOfPorts;
2413
2414 for (Port = 0; Port <= NumPorts; ++Port)
2415 {
2416 if (IsBitSet(Bitmap, Port))
2417 {
2418 break;
2419 }
2420 }
2421
2422 if (Port > NumPorts)
2423 {
2424 Port = 0;
2425 }
2426
2428 HubExtension->ResetPortIrp,
2429 &HubExtension->SCEWorkerUrb,
2430 Port);
2431
2432 if (NT_ERROR(Status))
2433 {
2434 HubExtension->HubFlags |= USBHUB_FDO_FLAG_DEVICE_FAILED;
2435 }
2436
2438}
#define InterlockedIncrement
Definition: armddk.h:53
_In_ PIRP Irp
Definition: csq.h:116
#define DPRINT_SCE(...)
Definition: dbg_uhub.h:110
#define KeSetEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:476
#define STATUS_DELETE_PENDING
Definition: ntstatus.h:322
unsigned short USHORT
Definition: pedump.c:61
#define STATUS_MORE_PROCESSING_REQUIRED
Definition: shellext.h:68
PUSBHUB_IO_WORK_ITEM WorkItemToQueue
Definition: usbhub.h:197
PUSB_HUB_DESCRIPTOR HubDescriptor
Definition: usbhub.h:166
struct _URB_CONTROL_VENDOR_OR_CLASS_REQUEST SCEWorkerUrb
Definition: usbhub.h:175
KEVENT StatusChangeEvent
Definition: usbhub.h:176
PUSBHUB_FDO_EXTENSION HubExtension
Definition: usbhub.h:249
UCHAR bNumberOfPorts
Definition: usb100.h:173
#define NT_ERROR(Status)
Definition: umtypes.h:106
#define USBD_ERROR(Status)
Definition: usb.h:169
LONG USBD_STATUS
Definition: usb.h:165
VOID NTAPI USBH_ChangeIndicationWorker(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PVOID Context)
Definition: usbhub.c:2146
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
NTSTATUS NTAPI USBH_ChangeIndicationQueryChange(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PIRP Irp, IN struct _URB_CONTROL_VENDOR_OR_CLASS_REQUEST *Urb, IN USHORT Port)
Definition: usbhub.c:1769
BOOLEAN NTAPI IsBitSet(IN PUCHAR BitMapAddress, IN USHORT Bit)
Definition: usbhub.c:121
#define USBHUB_FDO_FLAG_DEVICE_STOPPING
Definition: usbhub.h:34
#define USBHUB_MAX_REQUEST_ERRORS
Definition: usbhub.h:108
struct _USBHUB_STATUS_CHANGE_CONTEXT USBHUB_STATUS_CHANGE_CONTEXT
#define USBHUB_FDO_FLAG_DEVICE_FAILED
Definition: usbhub.h:35
@ DelayedWorkQueue
Definition: extypes.h:190
#define EVENT_INCREMENT
Definition: iotypes.h:597

Referenced by USBH_SubmitStatusChangeTransfer().

◆ USBH_ChangeIndicationAckChange()

NTSTATUS NTAPI USBH_ChangeIndicationAckChange ( IN PUSBHUB_FDO_EXTENSION  HubExtension,
IN PIRP  Irp,
IN struct _URB_CONTROL_VENDOR_OR_CLASS_REQUEST Urb,
IN USHORT  Port,
IN USHORT  RequestValue 
)

Definition at line 1657 of file usbhub.c.

1662{
1663 PIO_STACK_LOCATION IoStack;
1665
1666 DPRINT_SCE("USBH_ChangeIndicationAckChange: ... \n");
1667
1668 Urb->Hdr.Length = sizeof(struct _URB_CONTROL_VENDOR_OR_CLASS_REQUEST);
1669 Urb->Hdr.Function = URB_FUNCTION_CLASS_OTHER;
1670 Urb->Hdr.UsbdDeviceHandle = NULL;
1671
1672 Urb->TransferFlags = USBD_SHORT_TRANSFER_OK;
1673 Urb->TransferBufferLength = 0;
1674 Urb->TransferBuffer = NULL;
1675 Urb->TransferBufferMDL = NULL;
1676 Urb->UrbLink = NULL;
1677
1678 RequestType.B = 0;
1679 RequestType.Recipient = BMREQUEST_TO_OTHER;
1682
1683 Urb->RequestTypeReservedBits = RequestType.B;
1684 Urb->Request = USB_REQUEST_CLEAR_FEATURE;
1685 Urb->Index = Port;
1686 Urb->Value = RequestValue;
1687
1689 IoSizeOfIrp(HubExtension->LowerDevice->StackSize),
1690 HubExtension->LowerDevice->StackSize);
1691
1692 IoStack = IoGetNextIrpStackLocation(Irp);
1693
1695 IoStack->Parameters.Others.Argument1 = Urb;
1697
1700 HubExtension,
1701 TRUE,
1702 TRUE,
1703 TRUE);
1704
1705 return IoCallDriver(HubExtension->LowerDevice, Irp);
1706}
#define IoSetCompletionRoutine(_Irp, _CompletionRoutine, _Context, _InvokeOnSuccess, _InvokeOnError, _InvokeOnCancel)
Definition: irp.cpp:490
VOID NTAPI IoInitializeIrp(IN PIRP Irp, IN USHORT PacketSize, IN CCHAR StackSize)
Definition: irp.c:1854
#define IoCallDriver
Definition: irp.c:1225
struct _IO_STACK_LOCATION::@1579::@1580 DeviceIoControl
struct _IO_STACK_LOCATION::@3978::@4017 Others
union _IO_STACK_LOCATION::@1579 Parameters
#define BMREQUEST_CLASS
Definition: usb100.h:35
#define BMREQUEST_TO_OTHER
Definition: usb100.h:41
#define BMREQUEST_HOST_TO_DEVICE
Definition: usb100.h:31
#define USB_REQUEST_CLEAR_FEATURE
Definition: usb100.h:79
#define USBD_SHORT_TRANSFER_OK
Definition: usb.h:154
#define URB_FUNCTION_CLASS_OTHER
Definition: usb.h:117
NTSTATUS NTAPI USBH_ChangeIndicationAckChangeComplete(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context)
Definition: usbhub.c:1618
#define IOCTL_INTERNAL_USB_SUBMIT_URB
Definition: usbioctl.h:32
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFQUEUE _In_ _Strict_type_match_ WDF_REQUEST_TYPE RequestType
Definition: wdfdevice.h:4233
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2695
#define IoSizeOfIrp(_StackSize)

Referenced by USBH_ChangeIndicationProcessChange().

◆ USBH_ChangeIndicationAckChangeComplete()

NTSTATUS NTAPI USBH_ChangeIndicationAckChangeComplete ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp,
IN PVOID  Context 
)

Definition at line 1618 of file usbhub.c.

1621{
1622 PUSBHUB_FDO_EXTENSION HubExtension;
1623 PVOID Event;
1624 USHORT Port;
1625
1626 HubExtension = Context;
1627
1628 DPRINT_SCE("USBH_ChangeIndicationAckChangeComplete: ... \n");
1629
1630 ASSERT(HubExtension->Port > 0);
1631 Port = HubExtension->Port - 1;
1632
1633 HubExtension->PortData[Port].PortStatus = HubExtension->PortStatus;
1634
1636 NULL);
1637
1638 if (Event)
1639 {
1641 }
1642
1643 USBH_SubmitStatusChangeTransfer(HubExtension);
1644
1645 if (!InterlockedDecrement(&HubExtension->ResetRequestCount))
1646 {
1647 KeSetEvent(&HubExtension->ResetEvent,
1649 FALSE);
1650 }
1651
1653}
#define InterlockedDecrement
Definition: armddk.h:52
#define InterlockedExchangePointer(Target, Value)
Definition: dshow.h:45
#define ASSERT(a)
Definition: mode.c:44
PUSBHUB_PORT_DATA PortData
Definition: usbhub.h:167
USB_PORT_STATUS_AND_CHANGE PortStatus
Definition: usbhub.h:199
PRKEVENT pResetPortEvent
Definition: usbhub.h:183
USB_PORT_STATUS_AND_CHANGE PortStatus
Definition: usbhub.h:118
NTSTATUS NTAPI USBH_SubmitStatusChangeTransfer(IN PUSBHUB_FDO_EXTENSION HubExtension)
Definition: usbhub.c:2442

Referenced by USBH_ChangeIndicationAckChange().

◆ USBH_ChangeIndicationProcessChange()

NTSTATUS NTAPI USBH_ChangeIndicationProcessChange ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp,
IN PVOID  Context 
)

Definition at line 1710 of file usbhub.c.

1713{
1714 PUSBHUB_FDO_EXTENSION HubExtension;
1716 USHORT RequestValue;
1717
1718 HubExtension = Context;
1719
1720 DPRINT_SCE("USBH_ChangeIndicationProcessChange: PortStatus - %lX\n",
1721 HubExtension->PortStatus.AsUlong32);
1722
1723 if ((NT_SUCCESS(Irp->IoStatus.Status) ||
1724 USBD_SUCCESS(HubExtension->SCEWorkerUrb.Hdr.Status)) &&
1727 {
1728 if (!InterlockedDecrement(&HubExtension->PendingRequestCount))
1729 {
1730 KeSetEvent(&HubExtension->PendingRequestEvent,
1732 FALSE);
1733 }
1734
1735 USBH_FreeWorkItem(HubExtension->WorkItemToQueue);
1736
1737 HubExtension->WorkItemToQueue = NULL;
1738
1740 {
1741 RequestValue = USBHUB_FEATURE_C_PORT_RESET;
1742 }
1743 else
1744 {
1745 RequestValue = USBHUB_FEATURE_C_PORT_ENABLE;
1746 }
1747
1748 USBH_ChangeIndicationAckChange(HubExtension,
1749 HubExtension->ResetPortIrp,
1750 &HubExtension->SCEWorkerUrb,
1751 HubExtension->Port,
1752 RequestValue);
1753 }
1754 else
1755 {
1756 ASSERT(HubExtension->WorkItemToQueue != NULL);
1757
1758 WorkItem = HubExtension->WorkItemToQueue;
1759 HubExtension->WorkItemToQueue = NULL;
1760
1761 USBH_QueueWorkItem(HubExtension, WorkItem);
1762 }
1763
1765}
LONG PendingRequestCount
Definition: usbhub.h:180
KEVENT PendingRequestEvent
Definition: usbhub.h:181
USHORT PortEnableDisableChange
Definition: usb200.h:164
USHORT ResetChange
Definition: usb200.h:167
USB_20_PORT_CHANGE Usb20PortChange
Definition: usb200.h:231
USB_PORT_CHANGE PortChange
Definition: usb200.h:241
#define USBD_SUCCESS(Status)
Definition: usb.h:167
VOID NTAPI USBH_FreeWorkItem(IN PUSBHUB_IO_WORK_ITEM HubIoWorkItem)
Definition: usbhub.c:2937
VOID NTAPI USBH_QueueWorkItem(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PUSBHUB_IO_WORK_ITEM HubIoWorkItem)
Definition: usbhub.c:2917
NTSTATUS NTAPI USBH_ChangeIndicationAckChange(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PIRP Irp, IN struct _URB_CONTROL_VENDOR_OR_CLASS_REQUEST *Urb, IN USHORT Port, IN USHORT RequestValue)
Definition: usbhub.c:1657
#define USBHUB_FEATURE_C_PORT_ENABLE
Definition: usbhub.h:99
#define USBHUB_FEATURE_C_PORT_RESET
Definition: usbhub.h:102

Referenced by USBH_ChangeIndicationQueryChange().

◆ USBH_ChangeIndicationQueryChange()

NTSTATUS NTAPI USBH_ChangeIndicationQueryChange ( IN PUSBHUB_FDO_EXTENSION  HubExtension,
IN PIRP  Irp,
IN struct _URB_CONTROL_VENDOR_OR_CLASS_REQUEST Urb,
IN USHORT  Port 
)

Definition at line 1769 of file usbhub.c.

1773{
1776 PIO_STACK_LOCATION IoStack;
1778
1779 DPRINT_SCE("USBH_ChangeIndicationQueryChange: Port - %x\n", Port);
1780
1781 InterlockedIncrement(&HubExtension->PendingRequestCount);
1782
1783 if (!Port)
1784 {
1785 ASSERT(HubExtension->WorkItemToQueue != NULL);
1786
1787 WorkItem = HubExtension->WorkItemToQueue;
1788 HubExtension->WorkItemToQueue = NULL;
1789
1790 USBH_QueueWorkItem(HubExtension, WorkItem);
1791
1792 return STATUS_SUCCESS;
1793 }
1794
1795 Urb->Hdr.Length = sizeof(struct _URB_CONTROL_VENDOR_OR_CLASS_REQUEST);
1796 Urb->Hdr.UsbdDeviceHandle = NULL;
1797 Urb->Hdr.Function = URB_FUNCTION_CLASS_OTHER;
1798
1800 Urb->TransferBuffer = &HubExtension->PortStatus;
1801 Urb->TransferBufferLength = sizeof(HubExtension->PortStatus);
1802 Urb->TransferBufferMDL = NULL;
1803 Urb->UrbLink = NULL;
1804
1805 RequestType.B = 0;
1806 RequestType.Recipient = BMREQUEST_TO_OTHER;
1809
1810 Urb->RequestTypeReservedBits = RequestType.B;
1811 Urb->Request = USB_REQUEST_GET_STATUS;
1812 Urb->Value = 0;
1813 Urb->Index = Port;
1814
1815 HubExtension->Port = Port;
1816
1818 IoSizeOfIrp(HubExtension->LowerDevice->StackSize),
1819 HubExtension->LowerDevice->StackSize);
1820
1821 IoStack = IoGetNextIrpStackLocation(Irp);
1822
1824 IoStack->Parameters.Others.Argument1 = Urb;
1826
1829 HubExtension,
1830 TRUE,
1831 TRUE,
1832 TRUE);
1833
1834 Status = IoCallDriver(HubExtension->LowerDevice, Irp);
1835
1836 return Status;
1837}
#define USB_REQUEST_GET_STATUS
Definition: usb100.h:78
#define BMREQUEST_DEVICE_TO_HOST
Definition: usb100.h:32
#define USBD_TRANSFER_DIRECTION_IN
Definition: usb.h:160
NTSTATUS NTAPI USBH_ChangeIndicationProcessChange(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context)
Definition: usbhub.c:1710

Referenced by USBH_ChangeIndication().

◆ USBH_ChangeIndicationWorker()

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

Definition at line 2146 of file usbhub.c.

2148{
2149 PUSBHUB_FDO_EXTENSION LowerHubExtension;
2150 PUSBHUB_PORT_PDO_EXTENSION LowerPortExtension;
2153 USB_HUB_STATUS_AND_CHANGE HubStatus;
2155 USHORT Port = 0;
2156
2157 DPRINT_SCE("USBH_ChangeIndicationWorker ... \n");
2158
2159 WorkItem = Context;
2160
2161 KeWaitForSingleObject(&HubExtension->HubSemaphore,
2162 Executive,
2163 KernelMode,
2164 FALSE,
2165 NULL);
2166
2167 if (HubExtension->HubFlags & USBHUB_FDO_FLAG_DEVICE_STOPPING)
2168 {
2169 KeSetEvent(&HubExtension->StatusChangeEvent,
2171 FALSE);
2172
2173 goto Exit;
2174 }
2175
2176 if (!HubExtension->RequestErrors)
2177 {
2178 goto Enum;
2179 }
2180
2181 DPRINT_SCE("USBH_ChangeIndicationWorker: RequestErrors - %x\n",
2182 HubExtension->RequestErrors);
2183
2184 if (HubExtension->LowerPDO == HubExtension->RootHubPdo)
2185 {
2186 goto Enum;
2187 }
2188
2189 LowerPortExtension = HubExtension->LowerPDO->DeviceExtension;
2190
2191 if (LowerPortExtension->PortPdoFlags & USBHUB_PDO_FLAG_POWER_D1_OR_D2)
2192 {
2193 goto Enum;
2194 }
2195
2196 LowerHubExtension = LowerPortExtension->HubExtension;
2197
2198 if (!LowerHubExtension)
2199 {
2200 goto Enum;
2201 }
2202
2203 Status = USBH_SyncGetPortStatus(LowerHubExtension,
2204 LowerPortExtension->PortNumber,
2205 &PortStatus,
2207
2208 if (!NT_SUCCESS(Status) ||
2209 !PortStatus.PortStatus.Usb20PortStatus.CurrentConnectStatus)
2210 {
2211 HubExtension->HubFlags |= USBHUB_FDO_FLAG_DEVICE_REMOVED;
2212
2213 KeSetEvent(&HubExtension->StatusChangeEvent,
2215 FALSE);
2216
2217 goto Exit;
2218 }
2219
2220 if (!(HubExtension->HubFlags & USBHUB_FDO_FLAG_ESD_RECOVERING))
2221 {
2222 HubExtension->HubFlags |= USBHUB_FDO_FLAG_ESD_RECOVERING;
2223
2224 DPRINT1("USBH_ChangeIndicationWorker: USBHUB_FDO_FLAG_ESD_RECOVERING FIXME\n");
2225 DbgBreakPoint();
2226
2227 goto Exit;
2228 }
2229
2230Enum:
2231
2232 if (WorkItem->IsRequestErrors)
2233 {
2234 USBH_ResetHub(HubExtension);
2235 }
2236 else
2237 {
2238 for (Port = 0;
2239 Port < HubExtension->HubDescriptor->bNumberOfPorts;
2240 Port++)
2241 {
2242 if (IsBitSet((PUCHAR)(WorkItem + 1), Port))
2243 {
2244 break;
2245 }
2246 }
2247
2248 if (Port)
2249 {
2250 Status = USBH_SyncGetPortStatus(HubExtension,
2251 Port,
2252 &PortStatus,
2253 sizeof(PortStatus));
2254 }
2255 else
2256 {
2257 Status = USBH_SyncGetHubStatus(HubExtension,
2258 &HubStatus,
2259 sizeof(HubStatus));
2260 }
2261
2262 if (NT_SUCCESS(Status))
2263 {
2264 if (Port)
2265 {
2266 USBH_ProcessPortStateChange(HubExtension,
2267 Port,
2268 &PortStatus);
2269 }
2270 else
2271 {
2272 USBH_ProcessHubStateChange(HubExtension,
2273 &HubStatus);
2274 }
2275 }
2276 else
2277 {
2278 HubExtension->RequestErrors++;
2279
2280 if (HubExtension->RequestErrors > USBHUB_MAX_REQUEST_ERRORS)
2281 {
2282 HubExtension->HubFlags |= USBHUB_FDO_FLAG_DEVICE_FAILED;
2283 goto Exit;
2284 }
2285 }
2286 }
2287
2288 USBH_SubmitStatusChangeTransfer(HubExtension);
2289
2290Exit:
2291
2292 KeReleaseSemaphore(&HubExtension->HubSemaphore,
2294 1,
2295 FALSE);
2296
2297 if (!InterlockedDecrement(&HubExtension->PendingRequestCount))
2298 {
2299 KeSetEvent(&HubExtension->PendingRequestEvent,
2301 FALSE);
2302 }
2303
2304 if (!InterlockedDecrement((PLONG)&HubExtension->ResetRequestCount))
2305 {
2306 KeSetEvent(&HubExtension->ResetEvent,
2308 FALSE);
2309
2310 if (HubExtension->HubFlags & USBHUB_FDO_FLAG_DEFER_CHECK_IDLE)
2311 {
2312 USBH_CheckHubIdle(HubExtension);
2313 }
2314 }
2315}
MIXER_STATUS Enum(IN PVOID EnumContext, IN ULONG DeviceIndex, OUT LPWSTR *DeviceName, OUT PHANDLE OutHandle, OUT PHANDLE OutKey)
Definition: mmixer.c:220
_Outptr_ PUSB_DEVICE_HANDLE _In_ PUSB_DEVICE_HANDLE _In_ USHORT PortStatus
Definition: hubbusif.h:42
NTSYSAPI void WINAPI DbgBreakPoint(void)
#define LOW_REALTIME_PRIORITY
LONG NTAPI KeReleaseSemaphore(IN PKSEMAPHORE Semaphore, IN KPRIORITY Increment, IN LONG Adjustment, IN BOOLEAN Wait)
Definition: semphobj.c:54
static void Exit(void)
Definition: sock.c:1330
PUSBHUB_FDO_EXTENSION HubExtension
Definition: usbhub.h:209
int32_t * PLONG
Definition: typedefs.h:58
unsigned char * PUCHAR
Definition: typedefs.h:53
VOID NTAPI USBH_CheckHubIdle(IN PUSBHUB_FDO_EXTENSION HubExtension)
Definition: usbhub.c:3808
NTSTATUS NTAPI USBH_SyncGetPortStatus(IN PUSBHUB_FDO_EXTENSION HubExtension, IN USHORT Port, IN PUSB_PORT_STATUS_AND_CHANGE PortStatus, IN ULONG Length)
Definition: usbhub.c:1414
NTSTATUS NTAPI USBH_SyncGetHubStatus(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PUSB_HUB_STATUS_AND_CHANGE HubStatus, IN ULONG Length)
Definition: usbhub.c:1363
VOID NTAPI USBH_ProcessHubStateChange(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PUSB_HUB_STATUS_AND_CHANGE HubStatus)
Definition: usbhub.c:1841
VOID NTAPI USBH_ProcessPortStateChange(IN PUSBHUB_FDO_EXTENSION HubExtension, IN USHORT Port, IN PUSB_PORT_STATUS_AND_CHANGE PortStatus)
Definition: usbhub.c:1870
NTSTATUS NTAPI USBH_ResetHub(IN PUSBHUB_FDO_EXTENSION HubExtension)
Definition: usbhub.c:2117
#define USBHUB_FDO_FLAG_ESD_RECOVERING
Definition: usbhub.h:41
#define USBHUB_PDO_FLAG_POWER_D1_OR_D2
Definition: usbhub.h:74
#define USBHUB_FDO_FLAG_DEVICE_REMOVED
Definition: usbhub.h:46
#define USBHUB_FDO_FLAG_DEFER_CHECK_IDLE
Definition: usbhub.h:48

Referenced by USBH_ChangeIndication().

◆ USBH_CheckDeviceIDUnique()

BOOLEAN NTAPI USBH_CheckDeviceIDUnique ( IN PUSBHUB_FDO_EXTENSION  HubExtension,
IN USHORT  idVendor,
IN USHORT  idProduct,
IN PVOID  SerialNumber,
IN USHORT  SN_DescriptorLength 
)

Definition at line 4167 of file usbhub.c.

4172{
4173 PDEVICE_OBJECT PortDevice;
4174 PUSBHUB_PORT_PDO_EXTENSION PortExtension;
4175 ULONG Port;
4176 SIZE_T NumberBytes;
4177
4178 DPRINT("USBH_CheckDeviceIDUnique: idVendor - 0x%04X, idProduct - 0x%04X\n",
4179 idVendor,
4180 idProduct);
4181
4182 if (!HubExtension->HubDescriptor->bNumberOfPorts)
4183 {
4184 return TRUE;
4185 }
4186
4187 for (Port = 0; Port < HubExtension->HubDescriptor->bNumberOfPorts; Port++)
4188 {
4189 PortDevice = HubExtension->PortData[Port].DeviceObject;
4190
4191 if (PortDevice)
4192 {
4193 PortExtension = PortDevice->DeviceExtension;
4194
4195 if (PortExtension->DeviceDescriptor.idVendor == idVendor &&
4196 PortExtension->DeviceDescriptor.idProduct == idProduct &&
4197 PortExtension->SN_DescriptorLength == SN_DescriptorLength)
4198 {
4199 if (PortExtension->SerialNumber)
4200 {
4201 NumberBytes = RtlCompareMemory(PortExtension->SerialNumber,
4203 SN_DescriptorLength);
4204
4205 if (NumberBytes == SN_DescriptorLength)
4206 {
4207 return FALSE;
4208 }
4209 }
4210 }
4211 }
4212 }
4213
4214 return TRUE;
4215}
#define RtlCompareMemory(s1, s2, l)
Definition: env_spec_w32.h:465
ULONG SerialNumber
Definition: rxce.c:117
PVOID DeviceExtension
Definition: env_spec_w32.h:418
USB_DEVICE_DESCRIPTOR DeviceDescriptor
Definition: usbhub.h:216

Referenced by USBH_CreateDevice().

◆ USBH_CheckDeviceLanguage()

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

Definition at line 4242 of file usbhub.c.

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

Referenced by USBH_GetSerialNumberString(), and USBH_PdoQueryDeviceText().

◆ USBH_CheckHubIdle()

VOID NTAPI USBH_CheckHubIdle ( IN PUSBHUB_FDO_EXTENSION  HubExtension)

Definition at line 3808 of file usbhub.c.

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

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

◆ USBH_CheckIdleAbort()

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

Definition at line 3221 of file usbhub.c.

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

Referenced by USBH_FdoIdleNotificationCallback(), and USBH_FdoPower().

◆ USBH_CheckIdleDeferred()

VOID NTAPI USBH_CheckIdleDeferred ( IN PUSBHUB_FDO_EXTENSION  HubExtension)

Definition at line 3957 of file usbhub.c.

3958{
3959 PUSBHUB_IO_WORK_ITEM HubIoWorkItem;
3961
3962 DPRINT("USBH_CheckIdleDeferred: HubExtension - %p\n", HubExtension);
3963
3964 Status = USBH_AllocateWorkItem(HubExtension,
3965 &HubIoWorkItem,
3967 0,
3968 NULL,
3970
3971 DPRINT("USBH_CheckIdleDeferred: HubIoWorkItem - %p\n", HubIoWorkItem);
3972
3973 if (NT_SUCCESS(Status))
3974 {
3975 USBH_QueueWorkItem(HubExtension, HubIoWorkItem);
3976 }
3977}
VOID NTAPI USBH_CheckIdleWorker(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PVOID Context)
Definition: usbhub.c:3948

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

◆ USBH_CheckIdleWorker()

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

Definition at line 3948 of file usbhub.c.

3950{
3951 DPRINT("USBH_CheckIdleWorker: ... \n");
3952 USBH_CheckHubIdle(HubExtension);
3953}

Referenced by USBH_CheckIdleDeferred().

◆ USBH_CompleteIrp()

◆ USBH_CompletePortIdleIrpsWorker()

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

Definition at line 3576 of file usbhub.c.

3578{
3579 PUSBHUB_IDLE_PORT_CONTEXT IdlePortContext;
3580 NTSTATUS NtStatus;
3582 BOOLEAN IsFlush = FALSE;
3583
3584 DPRINT("USBH_CompletePortIdleIrpsWorker ... \n");
3585
3586 IdlePortContext = Context;
3587 NtStatus = IdlePortContext->Status;
3588
3590 &IdlePortContext->PwrList,
3591 NtStatus);
3592
3593 DPRINT1("USBH_CompletePortIdleIrpsWorker: USBH_RegQueryFlushPortPowerIrpsFlag() UNIMPLEMENTED. FIXME\n");
3594 Status = STATUS_NOT_IMPLEMENTED;// USBH_RegQueryFlushPortPowerIrpsFlag(&IsFlush);
3595
3596 if (NT_SUCCESS(Status))
3597 {
3598 if (IsFlush)
3599 {
3600 USBH_FlushPortPwrList(HubExtension);
3601 }
3602 }
3603}
VOID NTAPI USBH_FlushPortPwrList(IN PUSBHUB_FDO_EXTENSION HubExtension)
Definition: usbhub.c:3125
VOID NTAPI USBH_HubCompleteQueuedPortIdleIrps(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PLIST_ENTRY IdleList, IN NTSTATUS NtStatus)
Definition: usbhub.c:3110

Referenced by USBH_FdoIdleNotificationRequestComplete().

◆ USBH_CreateDevice()

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

Definition at line 4379 of file usbhub.c.

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

Referenced by USBH_FdoQueryBusRelations().

◆ USBH_DriverUnload()

VOID NTAPI USBH_DriverUnload ( IN PDRIVER_OBJECT  DriverObject)

Definition at line 5021 of file usbhub.c.

5022{
5023 DPRINT("USBH_DriverUnload: UNIMPLEMENTED\n");
5024
5026 {
5029 }
5030}
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

Referenced by DriverEntry().

◆ USBH_EnableParentPort()

NTSTATUS NTAPI USBH_EnableParentPort ( IN PUSBHUB_FDO_EXTENSION  HubExtension)

Definition at line 2032 of file usbhub.c.

2033{
2034 PIRP Irp;
2036 KEVENT Event;
2038
2039 DPRINT("USBH_EnableParentPort ... \n");
2040
2042
2044 HubExtension->LowerDevice,
2045 NULL,
2046 0,
2047 NULL,
2048 0,
2049 TRUE,
2050 &Event,
2051 &IoStatusBlock);
2052
2053 if (!Irp)
2054 {
2056 }
2057
2058 Status = IoCallDriver(HubExtension->LowerDevice, Irp);
2059
2060 if (Status == STATUS_PENDING)
2061 {
2063 Suspended,
2064 KernelMode,
2065 FALSE,
2066 NULL);
2067 }
2068 else
2069 {
2071 }
2072
2073 return IoStatusBlock.Status;
2074}
#define STATUS_PENDING
Definition: d3dkmdt.h:43
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
@ NotificationEvent
PIRP NTAPI IoBuildDeviceIoControlRequest(IN ULONG IoControlCode, IN PDEVICE_OBJECT DeviceObject, IN PVOID InputBuffer, IN ULONG InputBufferLength, IN PVOID OutputBuffer, IN ULONG OutputBufferLength, IN BOOLEAN InternalDeviceIoControl, IN PKEVENT Event, IN PIO_STATUS_BLOCK IoStatusBlock)
Definition: irp.c:881
#define IOCTL_INTERNAL_USB_ENABLE_PORT
Definition: usbioctl.h:47
@ Suspended
Definition: ketypes.h:420

Referenced by USBH_ResetHub().

◆ USBH_FdoDispatch()

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

Definition at line 4896 of file usbhub.c.

4898{
4899 PIO_STACK_LOCATION IoStack;
4902
4904
4905 DPRINT("USBH_FdoDispatch: HubExtension - %p, Irp - %p, MajorFunction - %X\n",
4906 HubExtension,
4907 Irp,
4908 IoStack->MajorFunction);
4909
4910 MajorFunction = IoStack->MajorFunction;
4911
4912 switch (MajorFunction)
4913 {
4914 case IRP_MJ_CREATE:
4915 case IRP_MJ_CLOSE:
4918 break;
4919
4921 Status = USBH_DeviceControl(HubExtension, Irp);
4922 break;
4923
4924 case IRP_MJ_PNP:
4925 Status = USBH_FdoPnP(HubExtension, Irp, IoStack->MinorFunction);
4926 break;
4927
4928 case IRP_MJ_POWER:
4929 Status = USBH_FdoPower(HubExtension, Irp, IoStack->MinorFunction);
4930 break;
4931
4933 DPRINT1("USBH_FdoDispatch: USBH_SystemControl() UNIMPLEMENTED. FIXME\n");
4934 /* fall through */
4935
4937 default:
4938 Status = USBH_PassIrp(HubExtension->LowerDevice, Irp);
4939 break;
4940 }
4941
4942 return Status;
4943}
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
NTSTATUS NTAPI USBH_DeviceControl(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PIRP Irp)
Definition: ioctl.c:1136
NTSTATUS NTAPI USBH_FdoPnP(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PIRP Irp, IN UCHAR Minor)
Definition: pnp.c:2362
NTSTATUS NTAPI USBH_FdoPower(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PIRP Irp, IN UCHAR Minor)
Definition: power.c:460
VOID NTAPI USBH_CompleteIrp(IN PIRP Irp, IN NTSTATUS CompleteStatus)
Definition: usbhub.c:63
NTSTATUS NTAPI USBH_PassIrp(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: usbhub.c:79
_In_ UCHAR MajorFunction
Definition: wdfdevice.h:1697
unsigned char UCHAR
Definition: xmlstorage.h:181

Referenced by USBH_HubDispatch().

◆ USBH_FdoIdleNotificationCallback()

VOID NTAPI USBH_FdoIdleNotificationCallback ( IN PVOID  Context)

Definition at line 3365 of file usbhub.c.

3366{
3367 PUSBHUB_FDO_EXTENSION HubExtension;
3368 PUSBHUB_PORT_DATA PortData;
3369 PDEVICE_OBJECT PortDevice;
3370 PUSBHUB_PORT_PDO_EXTENSION PortExtension;
3371 PIRP Irp = NULL;
3372 PIRP IdleIrp;
3374 KEVENT Event;
3375 ULONG Port;
3376 PIO_STACK_LOCATION IoStack;
3377 PUSB_IDLE_CALLBACK_INFO CallbackInfo;
3378 BOOLEAN IsReady;
3379 KIRQL OldIrql;
3381
3382 HubExtension = Context;
3383
3384 DPRINT("USBH_FdoIdleNotificationCallback: HubExtension - %p, HubFlags - %lX\n",
3385 HubExtension,
3386 HubExtension->HubFlags);
3387
3388 if (HubExtension->HubFlags & (USBHUB_FDO_FLAG_ENUM_POST_RECOVER |
3395 {
3396 DbgBreakPoint();
3397 return;
3398 }
3399
3400 HubExtension->HubFlags |= USBHUB_FDO_FLAG_GOING_IDLE;
3401
3402 if (!(HubExtension->HubFlags & USBHUB_FDO_FLAG_PENDING_WAKE_IRP))
3403 {
3404 Status = USBH_FdoSubmitWaitWakeIrp(HubExtension);
3405
3406 if (Status != STATUS_PENDING)
3407 {
3408 DPRINT("Status != STATUS_PENDING. DbgBreakPoint()\n");
3409 DbgBreakPoint();
3410 HubExtension->HubFlags &= ~USBHUB_FDO_FLAG_GOING_IDLE;
3411 return;
3412 }
3413 }
3414
3416
3418 Executive,
3419 KernelMode,
3420 FALSE,
3421 NULL);
3422
3423 PortData = HubExtension->PortData;
3424 IsReady = TRUE;
3425
3426 for (Port = 0;
3427 Port < HubExtension->HubDescriptor->bNumberOfPorts;
3428 Port++)
3429 {
3430 PortDevice = PortData[Port].DeviceObject;
3431
3432 if (PortDevice)
3433 {
3434 PortExtension = PortDevice->DeviceExtension;
3435
3436 IdleIrp = PortExtension->IdleNotificationIrp;
3437
3438 if (!IdleIrp)
3439 {
3440 IsReady = FALSE;
3441 goto IdleHub;
3442 }
3443
3444 IoStack = IoGetCurrentIrpStackLocation(IdleIrp);
3445
3446 CallbackInfo = IoStack->Parameters.DeviceIoControl.Type3InputBuffer;
3447
3448 if (!CallbackInfo)
3449 {
3450 IsReady = FALSE;
3451 goto IdleHub;
3452 }
3453
3454 if (!CallbackInfo->IdleCallback)
3455 {
3456 IsReady = FALSE;
3457 goto IdleHub;
3458 }
3459
3460 if (PortExtension->PendingSystemPoRequest)
3461 {
3462 IsReady = FALSE;
3463 goto IdleHub;
3464 }
3465
3466 if (InterlockedCompareExchange(&PortExtension->StateBehindD2,
3467 1,
3468 0))
3469 {
3470 IsReady = FALSE;
3471 goto IdleHub;
3472 }
3473
3474 DPRINT("USBH_FdoIdleNotificationCallback: IdleContext - %p\n",
3475 CallbackInfo->IdleContext);
3476
3477 CallbackInfo->IdleCallback(CallbackInfo->IdleContext);
3478
3479 if (PortExtension->CurrentPowerState.DeviceState == PowerDeviceD0)
3480 {
3481 IsReady = FALSE;
3482 goto IdleHub;
3483 }
3484 }
3485 }
3486
3487 if (!(HubExtension->HubFlags & USBHUB_FDO_FLAG_DEVICE_STOPPING) &&
3488 (USBH_CheckIdleAbort(HubExtension, FALSE, FALSE) == TRUE))
3489 {
3490 IsReady = FALSE;
3491 }
3492
3493IdleHub:
3494
3497 1,
3498 FALSE);
3499
3500 if (!InterlockedDecrement(&HubExtension->PendingRequestCount))
3501 {
3502 KeSetEvent(&HubExtension->PendingRequestEvent,
3504 FALSE);
3505 }
3506
3507 if (!IsReady ||
3509 {
3510 DPRINT1("USBH_FdoIdleNotificationCallback: HubFlags - %lX\n",
3511 HubExtension->HubFlags);
3512
3513 HubExtension->HubFlags &= ~(USBHUB_FDO_FLAG_DEVICE_SUSPENDED |
3515
3516 /* Aborting Idle for Hub */
3518
3519 if (HubExtension->PendingIdleIrp)
3520 {
3521 Irp = HubExtension->PendingIdleIrp;
3522 HubExtension->PendingIdleIrp = NULL;
3523 }
3524
3526
3527 if (Irp)
3528 {
3529 USBH_HubCancelIdleIrp(HubExtension, Irp);
3530 }
3531
3532 DbgBreakPoint();
3534 }
3535 else
3536 {
3537 PowerState.DeviceState = HubExtension->DeviceWake;
3538
3539 KeWaitForSingleObject(&HubExtension->IdleSemaphore,
3540 Executive,
3541 KernelMode,
3542 FALSE,
3543 NULL);
3544
3545 HubExtension->HubFlags &= ~USBHUB_FDO_FLAG_GOING_IDLE;
3546 HubExtension->HubFlags |= USBHUB_FDO_FLAG_DO_SUSPENSE;
3547
3549
3550 DPRINT("USBH_FdoIdleNotificationCallback: LowerPdo - %p\n",
3551 HubExtension->LowerPDO);
3552
3553 DPRINT("USBH_FdoIdleNotificationCallback: PowerState.DeviceState - %x\n",
3554 PowerState.DeviceState);
3555
3556 Status = PoRequestPowerIrp(HubExtension->LowerPDO,
3558 PowerState,
3560 &Event,
3561 NULL);
3562
3563 if (Status == STATUS_PENDING)
3564 {
3566 Executive,
3567 KernelMode,
3568 FALSE,
3569 NULL);
3570 }
3571 }
3572}
#define InterlockedCompareExchange
Definition: interlocked.h:104
NTSTATUS NTAPI PoRequestPowerIrp(_In_ PDEVICE_OBJECT DeviceObject, _In_ UCHAR MinorFunction, _In_ POWER_STATE PowerState, _In_opt_ PREQUEST_POWER_COMPLETE CompletionFunction, _In_opt_ __drv_aliasesMem PVOID Context, _Outptr_opt_ PIRP *pIrp)
Definition: power.c:659
KSEMAPHORE ResetDeviceSemaphore
Definition: usbhub.h:182
DEVICE_POWER_STATE DeviceWake
Definition: usbhub.h:159
#define STATUS_CANCELLED
Definition: udferr_usr.h:170
VOID NTAPI USBH_HubCompletePortIdleIrps(IN PUSBHUB_FDO_EXTENSION HubExtension, IN NTSTATUS NtStatus)
Definition: usbhub.c:3185
VOID NTAPI USBH_HubCancelIdleIrp(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PIRP IdleIrp)
Definition: usbhub.c:3206
VOID NTAPI USBH_HubSetDWakeCompletion(IN PDEVICE_OBJECT DeviceObject, IN UCHAR MinorFunction, IN POWER_STATE PowerState, IN PVOID Context, IN PIO_STATUS_BLOCK IoStatus)
Definition: usbhub.c:3040
NTSTATUS NTAPI USBH_FdoSubmitWaitWakeIrp(IN PUSBHUB_FDO_EXTENSION HubExtension)
Definition: usbhub.c:3313
BOOLEAN NTAPI USBH_CheckIdleAbort(IN PUSBHUB_FDO_EXTENSION HubExtension, IN BOOLEAN IsWait, IN BOOLEAN IsExtCheck)
Definition: usbhub.c:3221
#define USBHUB_FDO_FLAG_DEVICE_SUSPENDED
Definition: usbhub.h:58
#define USBHUB_FDO_FLAG_DO_SUSPENSE
Definition: usbhub.h:56
#define USBHUB_FDO_FLAG_GOING_IDLE
Definition: usbhub.h:57
#define USBHUB_FDO_FLAG_PENDING_WAKE_IRP
Definition: usbhub.h:39
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_ WDF_DEVICE_POWER_STATE PowerState
Definition: wdfdevice.h:3034
#define IRP_MN_SET_POWER
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:778

Referenced by USBH_FdoSubmitIdleRequestIrp().

◆ USBH_FdoIdleNotificationRequestComplete()

NTSTATUS NTAPI USBH_FdoIdleNotificationRequestComplete ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp,
IN PVOID  Context 
)

Definition at line 3629 of file usbhub.c.

3632{
3633 PUSBHUB_FDO_EXTENSION HubExtension;
3634 NTSTATUS NtStatus;
3635 PVOID IdleIrp;
3636 KIRQL Irql;
3638 PUSBHUB_IO_WORK_ITEM HubIoWorkItem;
3639
3641
3642 HubExtension = Context;
3643 HubExtension->HubFlags &= ~USBHUB_FDO_FLAG_WAIT_IDLE_REQUEST;
3644
3645 IdleIrp = InterlockedExchangePointer((PVOID)&HubExtension->PendingIdleIrp,
3646 NULL);
3647
3648 DPRINT("USBH_FdoIdleNotificationRequestComplete: IdleIrp - %p\n", IdleIrp);
3649
3650 if (!InterlockedDecrement(&HubExtension->PendingRequestCount))
3651 {
3653 }
3654
3656
3657 NtStatus = Irp->IoStatus.Status;
3658
3659 DPRINT("USBH_FdoIdleNotificationRequestComplete: NtStatus - %lX\n",
3660 NtStatus);
3661
3662 if (!NT_SUCCESS(NtStatus) &&
3663 NtStatus != STATUS_POWER_STATE_INVALID &&
3664 !(HubExtension->HubFlags & USBHUB_FDO_FLAG_DEVICE_REMOVED) &&
3665 !(HubExtension->HubFlags & USBHUB_FDO_FLAG_DEVICE_STOPPED))
3666 {
3667 DPRINT("USBH_FdoIdleNotificationRequestComplete: DeviceState - %x\n",
3668 HubExtension->CurrentPowerState.DeviceState);
3669
3670 if (HubExtension->CurrentPowerState.DeviceState == PowerDeviceD0)
3671 {
3672 PUSBHUB_IDLE_PORT_CONTEXT HubWorkItemBuffer;
3673
3674 Status = USBH_AllocateWorkItem(HubExtension,
3675 &HubIoWorkItem,
3678 (PVOID *)&HubWorkItemBuffer,
3680
3681 if (NT_SUCCESS(Status))
3682 {
3683 HubWorkItemBuffer->Status = NtStatus;
3684
3685 USBH_HubQueuePortIdleIrps(HubExtension,
3686 &HubWorkItemBuffer->PwrList);
3687
3688 USBH_QueueWorkItem(HubExtension, HubIoWorkItem);
3689 }
3690 }
3691 else
3692 {
3693 PUSBHUB_IDLE_HUB_CONTEXT HubWorkItemBuffer;
3694
3695 Status = USBH_AllocateWorkItem(HubExtension,
3696 &HubIoWorkItem,
3699 (PVOID *)&HubWorkItemBuffer,
3701
3702 if (NT_SUCCESS(Status))
3703 {
3704 HubWorkItemBuffer->Status = NtStatus;
3705 USBH_QueueWorkItem(HubExtension, HubIoWorkItem);
3706 }
3707 }
3708 }
3709
3710 if (IdleIrp ||
3711 InterlockedExchange((PLONG)&HubExtension->IdleRequestLock, 1))
3712 {
3713 DPRINT("USBH_FdoIdleNotificationRequestComplete: Irp - %p\n", Irp);
3714 IoFreeIrp(Irp);
3715 }
3716
3718}
VOID NTAPI IoFreeIrp(IN PIRP Irp)
Definition: irp.c:1666
#define STATUS_POWER_STATE_INVALID
Definition: ntstatus.h:831
POWER_STATE CurrentPowerState
Definition: usbhub.h:160
VOID NTAPI USBH_IdleCompletePowerHubWorker(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PVOID Context)
Definition: usbhub.c:3607
VOID NTAPI USBH_CompletePortIdleIrpsWorker(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PVOID Context)
Definition: usbhub.c:3576
VOID NTAPI USBH_HubQueuePortIdleIrps(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PLIST_ENTRY IdleList)
Definition: usbhub.c:3052
#define USBHUB_FDO_FLAG_DEVICE_STOPPED
Definition: usbhub.h:37

Referenced by USBH_FdoSubmitIdleRequestIrp().

◆ USBH_FdoSubmitIdleRequestIrp()

NTSTATUS NTAPI USBH_FdoSubmitIdleRequestIrp ( IN PUSBHUB_FDO_EXTENSION  HubExtension)

Definition at line 3722 of file usbhub.c.

3723{
3725 ULONG HubFlags;
3726 PDEVICE_OBJECT LowerPDO;
3727 PIRP Irp;
3728 PIO_STACK_LOCATION IoStack;
3729 KIRQL Irql;
3730
3731 DPRINT("USBH_FdoSubmitIdleRequestIrp: HubExtension - %p, PendingIdleIrp - %p\n",
3732 HubExtension,
3733 HubExtension->PendingIdleIrp);
3734
3735 if (HubExtension->PendingIdleIrp)
3736 {
3738 KeSetEvent(&HubExtension->IdleEvent, EVENT_INCREMENT, FALSE);
3739 return Status;
3740 }
3741
3742 HubFlags = HubExtension->HubFlags;
3743
3744 if (HubFlags & USBHUB_FDO_FLAG_DEVICE_STOPPING ||
3746 {
3747 HubExtension->HubFlags = HubFlags & ~USBHUB_FDO_FLAG_WAIT_IDLE_REQUEST;
3748 KeSetEvent(&HubExtension->IdleEvent, EVENT_INCREMENT, FALSE);
3749 return STATUS_DEVICE_REMOVED;
3750 }
3751
3752 LowerPDO = HubExtension->LowerPDO;
3753
3754 HubExtension->IdleCallbackInfo.IdleCallback = USBH_FdoIdleNotificationCallback;
3755 HubExtension->IdleCallbackInfo.IdleContext = HubExtension;
3756
3757 Irp = IoAllocateIrp(LowerPDO->StackSize, FALSE);
3758
3759 if (!Irp)
3760 {
3761 HubExtension->HubFlags &= ~USBHUB_FDO_FLAG_WAIT_IDLE_REQUEST;
3763
3764 KeSetEvent(&HubExtension->IdleEvent, EVENT_INCREMENT, FALSE);
3765 return Status;
3766 }
3767
3768 IoStack = IoGetNextIrpStackLocation(Irp);
3769
3771
3772 IoStack->Parameters.DeviceIoControl.InputBufferLength = sizeof(USB_IDLE_CALLBACK_INFO);
3773 IoStack->Parameters.DeviceIoControl.IoControlCode = IOCTL_INTERNAL_USB_SUBMIT_IDLE_NOTIFICATION;
3774 IoStack->Parameters.DeviceIoControl.Type3InputBuffer = &HubExtension->IdleCallbackInfo;
3775
3778 HubExtension,
3779 TRUE,
3780 TRUE,
3781 TRUE);
3782
3783 InterlockedIncrement(&HubExtension->PendingRequestCount);
3784 InterlockedExchange(&HubExtension->IdleRequestLock, 0);
3785
3786 HubExtension->HubFlags &= ~(USBHUB_FDO_FLAG_DEVICE_SUSPENDED |
3788
3789 Status = IoCallDriver(HubExtension->LowerPDO, Irp);
3790
3792
3793 if (Status == STATUS_PENDING &&
3794 HubExtension->HubFlags & USBHUB_FDO_FLAG_WAIT_IDLE_REQUEST)
3795 {
3796 HubExtension->PendingIdleIrp = Irp;
3797 }
3798
3800
3801 KeSetEvent(&HubExtension->IdleEvent, EVENT_INCREMENT, FALSE);
3802
3803 return Status;
3804}
#define STATUS_DEVICE_REMOVED
Definition: d3dkmdt.h:39
PIRP NTAPI IoAllocateIrp(IN CCHAR StackSize, IN BOOLEAN ChargeQuota)
Definition: irp.c:615
#define STATUS_DEVICE_BUSY
Definition: udferr_usr.h:129
NTSTATUS NTAPI USBH_FdoIdleNotificationRequestComplete(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context)
Definition: usbhub.c:3629
VOID NTAPI USBH_FdoIdleNotificationCallback(IN PVOID Context)
Definition: usbhub.c:3365

Referenced by USBH_CheckHubIdle().

◆ USBH_FdoSubmitWaitWakeIrp()

NTSTATUS NTAPI USBH_FdoSubmitWaitWakeIrp ( IN PUSBHUB_FDO_EXTENSION  HubExtension)

Definition at line 3313 of file usbhub.c.

3314{
3317 PIRP Irp = NULL;
3318 KIRQL Irql;
3319
3320 DPRINT("USBH_FdoSubmitWaitWakeIrp: ... \n");
3321
3322 PowerState.SystemState = HubExtension->SystemWake;
3323 HubExtension->HubFlags |= USBHUB_FDO_FLAG_PENDING_WAKE_IRP;
3324
3325 InterlockedIncrement(&HubExtension->PendingRequestCount);
3326 InterlockedExchange(&HubExtension->FdoWaitWakeLock, 0);
3327
3328 Status = PoRequestPowerIrp(HubExtension->LowerPDO,
3330 PowerState,
3332 HubExtension,
3333 &Irp);
3334
3336
3337 if (Status == STATUS_PENDING)
3338 {
3339 if (HubExtension->HubFlags & USBHUB_FDO_FLAG_PENDING_WAKE_IRP)
3340 {
3341 HubExtension->PendingWakeIrp = Irp;
3342 DPRINT("USBH_FdoSubmitWaitWakeIrp: PendingWakeIrp - %p\n",
3343 HubExtension->PendingWakeIrp);
3344 }
3345 }
3346 else
3347 {
3348 HubExtension->HubFlags &= ~USBHUB_FDO_FLAG_PENDING_WAKE_IRP;
3349
3350 if (!InterlockedDecrement(&HubExtension->PendingRequestCount))
3351 {
3352 KeSetEvent(&HubExtension->PendingRequestEvent,
3354 FALSE);
3355 }
3356 }
3357
3359
3360 return Status;
3361}
VOID NTAPI USBH_FdoWaitWakeIrpCompletion(IN PDEVICE_OBJECT DeviceObject, IN UCHAR MinorFunction, IN POWER_STATE PowerState, IN PVOID Context, IN PIO_STATUS_BLOCK IoStatus)
Definition: usbhub.c:3302
#define IRP_MN_WAIT_WAKE

Referenced by USBH_FdoIdleNotificationCallback().

◆ 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

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

◆ USBH_FdoWaitWakeIrpCompletion()

VOID NTAPI USBH_FdoWaitWakeIrpCompletion ( IN PDEVICE_OBJECT  DeviceObject,
IN UCHAR  MinorFunction,
IN POWER_STATE  PowerState,
IN PVOID  Context,
IN PIO_STATUS_BLOCK  IoStatus 
)

Definition at line 3302 of file usbhub.c.

3307{
3308 DPRINT("USBH_FdoWaitWakeIrpCompletion ... \n");
3309}

Referenced by USBH_FdoSubmitWaitWakeIrp().

◆ USBH_FlushPortPwrList()

VOID NTAPI USBH_FlushPortPwrList ( IN PUSBHUB_FDO_EXTENSION  HubExtension)

Definition at line 3125 of file usbhub.c.

3126{
3127 PDEVICE_OBJECT PortDevice;
3128 PUSBHUB_PORT_PDO_EXTENSION PortExtension;
3130 ULONG Port;
3131
3132 DPRINT("USBH_FlushPortPwrList ... \n");
3133
3134 InterlockedIncrement((PLONG)&HubExtension->PendingRequestCount);
3135
3136 KeWaitForSingleObject(&HubExtension->ResetDeviceSemaphore,
3137 Executive,
3138 KernelMode,
3139 FALSE,
3140 NULL);
3141
3142 for (Port = 0; Port < HubExtension->HubDescriptor->bNumberOfPorts; ++Port)
3143 {
3144 PortDevice = HubExtension->PortData[Port].DeviceObject;
3145
3146 if (!PortDevice)
3147 {
3148 continue;
3149 }
3150
3151 PortExtension = PortDevice->DeviceExtension;
3152
3153 InterlockedExchange((PLONG)&PortExtension->StateBehindD2, 0);
3154
3155 while (TRUE)
3156 {
3158 &PortExtension->PortPowerListSpinLock);
3159
3160 if (!Entry)
3161 {
3162 break;
3163 }
3164
3165 DPRINT1("USBH_FlushPortPwrList: PortPowerList FIXME\n");
3166 DbgBreakPoint();
3167 }
3168 }
3169
3170 KeReleaseSemaphore(&HubExtension->ResetDeviceSemaphore,
3172 1,
3173 FALSE);
3174
3175 if (!InterlockedDecrement((PLONG)&HubExtension->PendingRequestCount))
3176 {
3177 KeSetEvent(&HubExtension->PendingRequestEvent,
3179 FALSE);
3180 }
3181}
PLIST_ENTRY NTAPI ExInterlockedRemoveHeadList(IN OUT PLIST_ENTRY ListHead, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:166
base of all file and directory entries
Definition: entries.h:83
Definition: typedefs.h:120

Referenced by USBH_CompletePortIdleIrpsWorker(), and USBH_HubCompletePortIdleIrps().

◆ USBH_FreeWorkItem()

VOID NTAPI USBH_FreeWorkItem ( IN PUSBHUB_IO_WORK_ITEM  HubIoWorkItem)

Definition at line 2937 of file usbhub.c.

2938{
2940
2941 DPRINT("USBH_FreeWorkItem: ... \n");
2942
2943 WorkItem = HubIoWorkItem->HubWorkItem;
2944
2945 if (HubIoWorkItem->HubWorkItemBuffer)
2946 {
2947 ExFreePoolWithTag(HubIoWorkItem->HubWorkItemBuffer, USB_HUB_TAG);
2948 }
2949
2950 ExFreePoolWithTag(HubIoWorkItem, USB_HUB_TAG);
2951
2953}

Referenced by USBH_ChangeIndicationProcessChange().

◆ USBH_GetConfigurationDescriptor()

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

Definition at line 974 of file usbhub.c.

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

Referenced by USBH_ProcessDeviceInformation(), and USBH_StartHubFdoDevice().

◆ USBH_GetConfigValue()

NTSTATUS NTAPI USBH_GetConfigValue ( IN PWSTR  ValueName,
IN ULONG  ValueType,
IN PVOID  ValueData,
IN ULONG  ValueLength,
IN PVOID  Context,
IN PVOID  EntryContext 
)

Definition at line 34 of file usbhub.c.

40{
42
43 DPRINT("USBHUB_GetConfigValue: ... \n");
44
45 if (ValueType == REG_BINARY)
46 {
48 }
49 else if (ValueType == REG_DWORD)
50 {
52 }
53 else
54 {
56 }
57
58 return Status;
59}
_In_ GUID _In_ PVOID ValueData
Definition: hubbusif.h:312
_In_ PCWSTR _Inout_ _At_ QueryTable EntryContext
Definition: rtlfuncs.h:4219
#define REG_BINARY
Definition: nt_native.h:1496
#define REG_DWORD
Definition: sdbapi.c:596
uint32_t * PULONG
Definition: typedefs.h:59
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _In_ ULONG _Out_opt_ PULONG _Out_opt_ PULONG ValueType
Definition: wdfregistry.h:282

Referenced by USBH_RegQueryGenericUSBDeviceString().

◆ USBH_GetDeviceDescriptor()

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

Definition at line 877 of file usbhub.c.

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

Referenced by USBH_StartHubFdoDevice().

◆ USBH_GetDeviceType()

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

Definition at line 608 of file usbhub.c.

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

Referenced by USBH_StartHubFdoDevice().

◆ USBH_GetPortStatus()

NTSTATUS NTAPI USBH_GetPortStatus ( IN PUSBHUB_FDO_EXTENSION  HubExtension,
IN PULONG  PortStatus 
)

Definition at line 1979 of file usbhub.c.

1981{
1982 PIRP Irp;
1983 PIO_STACK_LOCATION IoStack;
1985 KEVENT Event;
1987
1988 DPRINT("USBH_GetPortStatus ... \n");
1989
1990 *PortStatus = 0;
1991
1993
1995 HubExtension->LowerDevice,
1996 NULL,
1997 0,
1998 NULL,
1999 0,
2000 TRUE,
2001 &Event,
2002 &IoStatusBlock);
2003
2004 if (!Irp)
2005 {
2007 }
2008
2009 IoStack = IoGetNextIrpStackLocation(Irp);
2010 IoStack->Parameters.Others.Argument1 = PortStatus;
2011
2012 Status = IoCallDriver(HubExtension->LowerDevice, Irp);
2013
2014 if (Status == STATUS_PENDING)
2015 {
2017 Suspended,
2018 KernelMode,
2019 FALSE,
2020 NULL);
2021 }
2022 else
2023 {
2025 }
2026
2027 return IoStatusBlock.Status;
2028}
#define IOCTL_INTERNAL_USB_GET_PORT_STATUS
Definition: usbioctl.h:44

Referenced by USBH_ResetHub().

◆ USBH_GetRootHubExtension()

PUSBHUB_FDO_EXTENSION NTAPI USBH_GetRootHubExtension ( IN PUSBHUB_FDO_EXTENSION  HubExtension)

Definition at line 699 of file usbhub.c.

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

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

◆ USBH_GetSerialNumberString()

NTSTATUS NTAPI USBH_GetSerialNumberString ( IN PDEVICE_OBJECT  DeviceObject,
IN LPWSTR OutSerialNumber,
IN PUSHORT  OutDescriptorLength,
IN USHORT  LanguageId,
IN UCHAR  Index 
)

Definition at line 4304 of file usbhub.c.

4309{
4312 LPWSTR SerialNumberBuffer = NULL;
4313 UCHAR StringLength;
4314 UCHAR Length;
4315
4316 DPRINT("USBH_GetSerialNumberString: ... \n");
4317
4318 *OutSerialNumber = NULL;
4319 *OutDescriptorLength = 0;
4320
4323 USB_HUB_TAG);
4324
4325 if (!Descriptor)
4326 {
4328 }
4329
4331
4333
4334 if (!NT_SUCCESS(Status))
4335 {
4336 goto Exit;
4337 }
4338
4340 Index,
4341 LanguageId,
4342 Descriptor,
4344 NULL,
4345 TRUE);
4346
4347 if (!NT_SUCCESS(Status) ||
4348 Descriptor->bLength <= sizeof(USB_COMMON_DESCRIPTOR))
4349 {
4351 goto Exit;
4352 }
4353
4354 StringLength = Descriptor->bLength -
4356
4357 Length = StringLength + sizeof(UNICODE_NULL);
4358
4359 SerialNumberBuffer = ExAllocatePoolWithTag(PagedPool, Length, USB_HUB_TAG);
4360
4361 if (!SerialNumberBuffer)
4362 {
4363 goto Exit;
4364 }
4365
4366 RtlZeroMemory(SerialNumberBuffer, Length);
4367 RtlCopyMemory(SerialNumberBuffer, Descriptor->bString, StringLength);
4368
4369 *OutSerialNumber = SerialNumberBuffer;
4370 *OutDescriptorLength = Length;
4371
4372Exit:
4374 return Status;
4375}
#define UNICODE_NULL
NTSTATUS NTAPI USBH_CheckDeviceLanguage(IN PDEVICE_OBJECT DeviceObject, IN USHORT LanguageId)
Definition: usbhub.c:4242
_In_ WDFCOLLECTION _In_ ULONG Index

Referenced by USBH_CreateDevice().

◆ 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}
BOOLEAN NTAPI IoCancelIrp(IN PIRP Irp)
Definition: irp.c:1101

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

◆ USBH_HubCompletePortIdleIrps()

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

Definition at line 3185 of file usbhub.c.

3187{
3188 LIST_ENTRY IdleList;
3189
3190 DPRINT("USBH_HubCompletePortIdleIrps ... \n");
3191
3192 if (HubExtension->HubFlags & USBHUB_FDO_FLAG_DEVICE_STARTED)
3193 {
3194 USBH_HubQueuePortIdleIrps(HubExtension, &IdleList);
3195
3197 &IdleList,
3198 NtStatus);
3199
3200 USBH_FlushPortPwrList(HubExtension);
3201 }
3202}

Referenced by USBH_FdoIdleNotificationCallback(), and USBH_IdleCompletePowerHubWorker().

◆ USBH_HubCompleteQueuedPortIdleIrps()

VOID NTAPI USBH_HubCompleteQueuedPortIdleIrps ( IN PUSBHUB_FDO_EXTENSION  HubExtension,
IN PLIST_ENTRY  IdleList,
IN NTSTATUS  NtStatus 
)

Definition at line 3110 of file usbhub.c.

3113{
3114 DPRINT("USBH_HubCompleteQueuedPortIdleIrps ... \n");
3115
3116 while (!IsListEmpty(IdleList))
3117 {
3118 DPRINT1("USBH_HubCompleteQueuedPortIdleIrps: IdleList not Empty. FIXME\n");
3119 DbgBreakPoint();
3120 }
3121}
#define IsListEmpty(ListHead)
Definition: env_spec_w32.h:954

Referenced by USBH_CompletePortIdleIrpsWorker(), and USBH_HubCompletePortIdleIrps().

◆ USBH_HubDispatch()

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

Definition at line 5034 of file usbhub.c.

5036{
5037 PCOMMON_DEVICE_EXTENSION DeviceExtension;
5038 ULONG ExtensionType;
5040
5041
5042 DeviceExtension = DeviceObject->DeviceExtension;
5043 ExtensionType = DeviceExtension->ExtensionType;
5044
5045 if (ExtensionType == USBH_EXTENSION_TYPE_HUB)
5046 {
5047 DPRINT("USBH_HubDispatch: DeviceObject - %p, Irp - %p\n",
5049 Irp);
5050
5051 Status = USBH_FdoDispatch((PUSBHUB_FDO_EXTENSION)DeviceExtension, Irp);
5052 }
5053 else if (ExtensionType == USBH_EXTENSION_TYPE_PORT)
5054 {
5057 BOOLEAN IsDprint = TRUE;
5058
5060 {
5061 ULONG ControlCode = IoStack->Parameters.DeviceIoControl.IoControlCode;
5062
5064 {
5065 IsDprint = FALSE;
5066 }
5067 }
5068
5069 if (IsDprint)
5070 {
5071 DPRINT("USBH_HubDispatch: DeviceObject - %p, Irp - %p\n",
5073 Irp);
5074 }
5075
5077 }
5078 else
5079 {
5080 DPRINT1("USBH_HubDispatch: Unknown ExtensionType - %x\n", ExtensionType);
5081 DbgBreakPoint();
5083 }
5084
5085 return Status;
5086}
#define STATUS_ASSERTION_FAILURE
Definition: ntstatus.h:960
NTSTATUS NTAPI USBH_FdoDispatch(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PIRP Irp)
Definition: usbhub.c:4896
NTSTATUS NTAPI USBH_PdoDispatch(IN PUSBHUB_PORT_PDO_EXTENSION PortExtension, IN PIRP Irp)
Definition: usbhub.c:4809
_IRQL_requires_same_ typedef _In_ ULONG ControlCode
Definition: wmitypes.h:55

Referenced by DriverEntry().

◆ USBH_HubIsBusPowered()

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

Definition at line 1589 of file usbhub.c.

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

Referenced by USBH_IoctlGetNodeInformation(), and USBH_StartHubFdoDevice().

◆ USBH_HubQueuePortIdleIrps()

VOID NTAPI USBH_HubQueuePortIdleIrps ( IN PUSBHUB_FDO_EXTENSION  HubExtension,
IN PLIST_ENTRY  IdleList 
)

Definition at line 3052 of file usbhub.c.

3054{
3055 PDEVICE_OBJECT PortDevice;
3056 PUSBHUB_PORT_PDO_EXTENSION PortExtension;
3057 PIRP IdleIrp;
3058 PIRP HubIdleIrp;
3059 ULONG NumPorts;
3060 ULONG Port;
3061 KIRQL Irql;
3062
3063 DPRINT("USBH_HubQueuePortIdleIrps ... \n");
3064
3065 InitializeListHead(IdleList);
3066
3068
3069 NumPorts = HubExtension->HubDescriptor->bNumberOfPorts;
3070
3071 for (Port = 0; Port < NumPorts; ++Port)
3072 {
3073 PortDevice = HubExtension->PortData[Port].DeviceObject;
3074
3075 if (PortDevice)
3076 {
3077 PortExtension = PortDevice->DeviceExtension;
3078
3079 IdleIrp = PortExtension->IdleNotificationIrp;
3080 PortExtension->IdleNotificationIrp = NULL;
3081
3082 if (IdleIrp && IoSetCancelRoutine(IdleIrp, NULL))
3083 {
3084 DPRINT1("USBH_HubQueuePortIdleIrps: IdleIrp != NULL. FIXME\n");
3085 DbgBreakPoint();
3086 }
3087 }
3088 }
3089
3090 if (HubExtension->HubFlags & USBHUB_FDO_FLAG_WAIT_IDLE_REQUEST)
3091 {
3092 HubIdleIrp = HubExtension->PendingIdleIrp;
3093 HubExtension->PendingIdleIrp = NULL;
3094 }
3095 else
3096 {
3097 HubIdleIrp = NULL;
3098 }
3099
3101
3102 if (HubIdleIrp)
3103 {
3104 USBH_HubCancelIdleIrp(HubExtension, HubIdleIrp);
3105 }
3106}
IoSetCancelRoutine(Irp, CancelRoutine)

Referenced by USBH_FdoIdleNotificationRequestComplete(), and USBH_HubCompletePortIdleIrps().

◆ USBH_HubSetDWakeCompletion()

VOID NTAPI USBH_HubSetDWakeCompletion ( IN PDEVICE_OBJECT  DeviceObject,
IN UCHAR  MinorFunction,
IN POWER_STATE  PowerState,
IN PVOID  Context,
IN PIO_STATUS_BLOCK  IoStatus 
)

Definition at line 3040 of file usbhub.c.

3045{
3046 DPRINT("USBH_HubSetDWakeCompletion: ... \n");
3048}

Referenced by USBH_FdoIdleNotificationCallback().

◆ USBH_IdleCompletePowerHubWorker()

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

Definition at line 3607 of file usbhub.c.

3609{
3610 PUSBHUB_IDLE_HUB_CONTEXT HubWorkItemBuffer;
3611
3612 DPRINT("USBH_IdleCompletePowerHubWorker ... \n");
3613
3614 if (HubExtension &&
3615 HubExtension->CurrentPowerState.DeviceState != PowerDeviceD0 &&
3616 HubExtension->HubFlags & USBHUB_FDO_FLAG_DEVICE_STARTED)
3617 {
3618 USBH_HubSetD0(HubExtension);
3619 }
3620
3621 HubWorkItemBuffer = Context;
3622
3623 USBH_HubCompletePortIdleIrps(HubExtension, HubWorkItemBuffer->Status);
3624
3625}
NTSTATUS NTAPI USBH_HubSetD0(IN PUSBHUB_FDO_EXTENSION HubExtension)
Definition: power.c:77

Referenced by USBH_FdoIdleNotificationRequestComplete().

◆ USBH_PassIrp()

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

Definition at line 79 of file usbhub.c.

81{
82 DPRINT_PNP("USBH_PassIrp: DeviceObject - %p, Irp - %p\n",
84 Irp);
85
88}
#define DPRINT_PNP(...)
Definition: dbg_uhub.h:109
#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_PdoDispatch()

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

Definition at line 4809 of file usbhub.c.

4811{
4812 PIO_STACK_LOCATION IoStack;
4814 BOOLEAN ShouldCompleteIrp;
4817
4819 MajorFunction = IoStack->MajorFunction;
4820
4821 switch (MajorFunction)
4822 {
4823 case IRP_MJ_CREATE:
4824 case IRP_MJ_CLOSE:
4825 DPRINT("USBH_PdoDispatch: IRP_MJ_CREATE / IRP_MJ_CLOSE (%d)\n",
4829 break;
4830
4832 ControlCode = IoStack->Parameters.DeviceIoControl.IoControlCode;
4833 DPRINT("USBH_PdoDispatch: IRP_MJ_DEVICE_CONTROL ControlCode - %x\n",
4834 ControlCode);
4835
4837 {
4840 break;
4841 }
4842
4844 {
4845 DPRINT1("USBH_PdoDispatch: IOCTL_KS_PROPERTY FIXME\n");
4846 DbgBreakPoint();
4849 break;
4850 }
4851
4852 Status = Irp->IoStatus.Status;
4854 break;
4855
4857 Status = USBH_PdoInternalControl(PortExtension, Irp);
4858 break;
4859
4860 case IRP_MJ_PNP:
4861 Status = USBH_PdoPnP(PortExtension,
4862 Irp,
4863 IoStack->MinorFunction,
4864 &ShouldCompleteIrp);
4865
4866 if (ShouldCompleteIrp)
4867 {
4869 }
4870
4871 break;
4872
4873 case IRP_MJ_POWER:
4874 Status = USBH_PdoPower(PortExtension, Irp, IoStack->MinorFunction);
4875 break;
4876
4878 DPRINT1("USBH_PdoDispatch: USBH_SystemControl() UNIMPLEMENTED. FIXME\n");
4879 //USBH_PortSystemControl(PortExtension, Irp);
4880 Status = Irp->IoStatus.Status;
4882 break;
4883
4884 default:
4885 DPRINT("USBH_PdoDispatch: Unhandled MajorFunction - %d\n", MajorFunction);
4886 Status = Irp->IoStatus.Status;
4888 break;
4889 }
4890
4891 return Status;
4892}
NTSTATUS NTAPI USBH_PdoInternalControl(IN PUSBHUB_PORT_PDO_EXTENSION PortExtension, IN PIRP Irp)
Definition: ioctl.c:1280
NTSTATUS NTAPI USBH_PdoPnP(IN PUSBHUB_PORT_PDO_EXTENSION PortExtension, IN PIRP Irp, IN UCHAR Minor, OUT BOOLEAN *IsCompleteIrp)
Definition: pnp.c:2594
NTSTATUS NTAPI USBH_PdoPower(IN PUSBHUB_PORT_PDO_EXTENSION PortExtension, IN PIRP Irp, IN UCHAR Minor)
Definition: power.c:757
#define IOCTL_KS_PROPERTY
Definition: ks.h:127
#define IOCTL_STORAGE_GET_MEDIA_SERIAL_NUMBER
Definition: ntddstor.h:151

Referenced by USBH_HubDispatch().

◆ USBH_PdoSetCapabilities()

VOID NTAPI USBH_PdoSetCapabilities ( IN PUSBHUB_PORT_PDO_EXTENSION  PortExtension)

Definition at line 3981 of file usbhub.c.

3982{
3983 PUSBHUB_FDO_EXTENSION HubExtension;
3984 ULONG State;
3986 PDEVICE_POWER_STATE pDeviceState;
3987
3988 DPRINT("USBH_PdoSetCapabilities ... \n");
3989
3990 HubExtension = PortExtension->HubExtension;
3991
3992 PortExtension->Capabilities.Size = 64;
3993 PortExtension->Capabilities.Version = 1;
3994
3995 PortExtension->Capabilities.Removable = 1;
3996 PortExtension->Capabilities.Address = PortExtension->PortNumber;
3997
3998 if (PortExtension->SerialNumber)
3999 {
4000 PortExtension->Capabilities.UniqueID = 1;
4001 }
4002 else
4003 {
4004 PortExtension->Capabilities.UniqueID = 0;
4005 }
4006
4007 PortExtension->Capabilities.RawDeviceOK = 0;
4008
4009 RtlCopyMemory(PortExtension->Capabilities.DeviceState,
4010 HubExtension->DeviceState,
4011 (PowerSystemMaximum + 2) * sizeof(POWER_STATE));
4012
4013 PortExtension->Capabilities.DeviceState[1] = PowerDeviceD0;
4014
4015 if (PortExtension->PortPdoFlags & USBHUB_PDO_FLAG_REMOTE_WAKEUP)
4016 {
4017 PortExtension->Capabilities.DeviceWake = PowerDeviceD2;
4018
4019 PortExtension->Capabilities.DeviceD1 = 1;
4020 PortExtension->Capabilities.DeviceD2 = 1;
4021
4022 PortExtension->Capabilities.WakeFromD0 = 1;
4023 PortExtension->Capabilities.WakeFromD1 = 1;
4024 PortExtension->Capabilities.WakeFromD2 = 1;
4025
4026 pDeviceState = &PortExtension->Capabilities.DeviceState[2];
4027
4028 for (State = 2; State <= 5; State++)
4029 {
4031
4032 if (PortExtension->Capabilities.SystemWake < SystemPowerState)
4033 {
4034 *pDeviceState = PowerDeviceD3;
4035 }
4036 else
4037 {
4038 *pDeviceState = PowerDeviceD2;
4039 }
4040
4041 ++pDeviceState;
4042 }
4043 }
4044 else
4045 {
4046 PortExtension->Capabilities.DeviceWake = PowerDeviceD0;
4047 PortExtension->Capabilities.DeviceState[2] = PowerDeviceD3;
4048 PortExtension->Capabilities.DeviceState[3] = PowerDeviceD3;
4049 PortExtension->Capabilities.DeviceState[4] = PowerDeviceD3;
4050 PortExtension->Capabilities.DeviceState[5] = PowerDeviceD3;
4051 }
4052}
@ PowerSystemMaximum
Definition: ntpoapi.h:42
enum _DEVICE_POWER_STATE * PDEVICE_POWER_STATE
@ PowerDeviceD2
Definition: ntpoapi.h:51
@ PowerDeviceD3
Definition: ntpoapi.h:52
enum _SYSTEM_POWER_STATE SYSTEM_POWER_STATE
DEVICE_POWER_STATE DeviceState[POWER_SYSTEM_MAXIMUM]
Definition: usbhub.h:157
#define USBHUB_PDO_FLAG_REMOTE_WAKEUP
Definition: usbhub.h:65

Referenced by USBH_CreateDevice().

◆ USBH_ProcessDeviceInformation()

NTSTATUS NTAPI USBH_ProcessDeviceInformation ( IN PUSBHUB_PORT_PDO_EXTENSION  PortExtension)

Definition at line 4056 of file usbhub.c.

4057{
4061
4062 DPRINT("USBH_ProcessDeviceInformation ... \n");
4063
4065
4066 RtlZeroMemory(&PortExtension->InterfaceDescriptor,
4067 sizeof(PortExtension->InterfaceDescriptor));
4068
4069 PortExtension->PortPdoFlags &= ~USBHUB_PDO_FLAG_HUB_DEVICE;
4070
4071 Status = USBH_GetConfigurationDescriptor(PortExtension->Common.SelfDevice,
4073
4074 if (!NT_SUCCESS(Status))
4075 {
4076 if (ConfigDescriptor)
4077 {
4079 }
4080
4081 return Status;
4082 }
4083
4084 PortExtension->PortPdoFlags &= ~USBHUB_PDO_FLAG_REMOTE_WAKEUP;
4085
4086 if (ConfigDescriptor->bmAttributes & 0x20)
4087 {
4088 /* device configuration supports remote wakeup */
4089 PortExtension->PortPdoFlags |= USBHUB_PDO_FLAG_REMOTE_WAKEUP;
4090 }
4091
4092 USBHUB_DumpingDeviceDescriptor(&PortExtension->DeviceDescriptor);
4094
4095 DPRINT_PNP("USBH_ProcessDeviceInformation: Class - %x, SubClass - %x, Protocol - %x\n",
4096 PortExtension->DeviceDescriptor.bDeviceClass,
4097 PortExtension->DeviceDescriptor.bDeviceSubClass,
4098 PortExtension->DeviceDescriptor.bDeviceProtocol);
4099
4100 DPRINT_PNP("USBH_ProcessDeviceInformation: bNumConfigurations - %x, bNumInterfaces - %x\n",
4101 PortExtension->DeviceDescriptor.bNumConfigurations,
4102 ConfigDescriptor->bNumInterfaces);
4103
4104
4105 /* Enumeration of USB Composite Devices (msdn):
4106 1) The device class field of the device descriptor (bDeviceClass) must contain a value of zero,
4107 or the class (bDeviceClass), subclass (bDeviceSubClass), and protocol (bDeviceProtocol)
4108 fields of the device descriptor must have the values 0xEF, 0x02 and 0x01 respectively,
4109 as explained in USB Interface Association Descriptor.
4110 2) The device must have multiple interfaces
4111 3) The device must have a single configuration.
4112 */
4113
4114 if (((PortExtension->DeviceDescriptor.bDeviceClass == USB_DEVICE_CLASS_RESERVED) ||
4115 (PortExtension->DeviceDescriptor.bDeviceClass == USB_DEVICE_CLASS_MISCELLANEOUS &&
4116 PortExtension->DeviceDescriptor.bDeviceSubClass == 0x02 &&
4117 PortExtension->DeviceDescriptor.bDeviceProtocol == 0x01)) &&
4118 (ConfigDescriptor->bNumInterfaces > 1) &&
4119 (PortExtension->DeviceDescriptor.bNumConfigurations < 2))
4120 {
4121 DPRINT("USBH_ProcessDeviceInformation: Multi-Interface configuration\n");
4122
4123 PortExtension->PortPdoFlags |= USBHUB_PDO_FLAG_MULTI_INTERFACE;
4124
4125 if (ConfigDescriptor)
4126 {
4128 }
4129
4130 return Status;
4131 }
4132
4135 -1,
4136 -1,
4137 -1,
4138 -1,
4139 -1);
4140 if (Pid)
4141 {
4142 RtlCopyMemory(&PortExtension->InterfaceDescriptor,
4143 Pid,
4144 sizeof(PortExtension->InterfaceDescriptor));
4145
4147 {
4148 PortExtension->PortPdoFlags |= (USBHUB_PDO_FLAG_HUB_DEVICE |
4150 }
4151 }
4152 else
4153 {
4155 }
4156
4157 if (ConfigDescriptor)
4158 {
4160 }
4161
4162 return Status;
4163}
VOID NTAPI USBHUB_DumpingConfiguration(IN PUSB_CONFIGURATION_DESCRIPTOR ConfigDescriptor)
Definition: debug.c:41
VOID NTAPI USBHUB_DumpingDeviceDescriptor(IN PUSB_DEVICE_DESCRIPTOR DeviceDescriptor)
Definition: debug.c:15
#define USB_DEVICE_CLASS_HUB
Definition: usb100.h:99
#define USB_DEVICE_CLASS_RESERVED
Definition: usb100.h:90
#define USB_DEVICE_CLASS_MISCELLANEOUS
Definition: usb200.h:310
PUSB_INTERFACE_DESCRIPTOR NTAPI USBD_ParseConfigurationDescriptorEx(PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor, PVOID StartPosition, LONG InterfaceNumber, LONG AlternateSetting, LONG InterfaceClass, LONG InterfaceSubClass, LONG InterfaceProtocol)
Definition: usbd.c:496
NTSTATUS NTAPI USBH_GetConfigurationDescriptor(IN PDEVICE_OBJECT DeviceObject, IN PUSB_CONFIGURATION_DESCRIPTOR *OutDescriptor)
Definition: usbhub.c:974
#define USBHUB_PDO_FLAG_MULTI_INTERFACE
Definition: usbhub.h:62

Referenced by USBH_CreateDevice().

◆ USBH_ProcessHubStateChange()

VOID NTAPI USBH_ProcessHubStateChange ( IN PUSBHUB_FDO_EXTENSION  HubExtension,
IN PUSB_HUB_STATUS_AND_CHANGE  HubStatus 
)

Definition at line 1841 of file usbhub.c.

1843{
1844 USB_HUB_CHANGE HubStatusChange;
1845
1846 DPRINT_SCE("USBH_ProcessHubStateChange: HubStatus - %lx\n", HubStatus->AsUlong32);
1847
1848 HubStatusChange = HubStatus->HubChange;
1849
1850 if (HubStatusChange.LocalPowerChange)
1851 {
1852 DPRINT1("USBH_ProcessHubStateChange: LocalPowerChange\n");
1853 USBH_SyncClearHubStatus(HubExtension,
1855 }
1856 else if (HubStatusChange.OverCurrentChange)
1857 {
1858 USBH_SyncClearHubStatus(HubExtension,
1860 if (HubStatus->HubStatus.OverCurrent)
1861 {
1862 DPRINT1("USBH_ProcessHubStateChange: OverCurrent UNIMPLEMENTED. FIXME\n");
1863 DbgBreakPoint();
1864 }
1865 }
1866}
USHORT OverCurrentChange
Definition: usb200.h:262
USHORT LocalPowerChange
Definition: usb200.h:261
NTSTATUS NTAPI USBH_SyncClearHubStatus(IN PUSBHUB_FDO_EXTENSION HubExtension, IN USHORT RequestValue)
Definition: usbhub.c:1389
#define USBHUB_FEATURE_C_HUB_LOCAL_POWER
Definition: usbhub.h:88
#define USBHUB_FEATURE_C_HUB_OVER_CURRENT
Definition: usbhub.h:89

Referenced by USBH_ChangeIndicationWorker().

◆ USBH_ProcessPortStateChange()

VOID NTAPI USBH_ProcessPortStateChange ( IN PUSBHUB_FDO_EXTENSION  HubExtension,
IN USHORT  Port,
IN PUSB_PORT_STATUS_AND_CHANGE  PortStatus 
)

Definition at line 1870 of file usbhub.c.

1873{
1874 PUSBHUB_PORT_DATA PortData;
1875 USB_20_PORT_CHANGE PortStatusChange;
1876 PDEVICE_OBJECT PortDevice;
1877 PUSBHUB_PORT_PDO_EXTENSION PortExtension;
1880 USHORT RequestValue;
1881 KIRQL Irql;
1882
1883 DPRINT_SCE("USBH_ProcessPortStateChange ... \n");
1884
1885 ASSERT(Port > 0);
1886 PortData = &HubExtension->PortData[Port - 1];
1887
1888 PortStatusChange = PortStatus->PortChange.Usb20PortChange;
1889
1890 if (PortStatusChange.ConnectStatusChange)
1891 {
1892 PortData->PortStatus = *PortStatus;
1893
1894 USBH_SyncClearPortStatus(HubExtension,
1895 Port,
1897
1898 PortData = &HubExtension->PortData[Port - 1];
1899
1900 PortDevice = PortData->DeviceObject;
1901
1902 if (!PortDevice)
1903 {
1904 IoInvalidateDeviceRelations(HubExtension->LowerPDO, BusRelations);
1905 return;
1906 }
1907
1908 PortExtension = PortDevice->DeviceExtension;
1909
1911 {
1912 return;
1913 }
1914
1915 KeAcquireSpinLock(&HubExtension->RelationsWorkerSpinLock, &Irql);
1916
1917 if (PortExtension->PortPdoFlags & USBHUB_PDO_FLAG_POWER_D3)
1918 {
1919 KeReleaseSpinLock(&HubExtension->RelationsWorkerSpinLock, Irql);
1920 IoInvalidateDeviceRelations(HubExtension->LowerPDO, BusRelations);
1921 return;
1922 }
1923
1924 PortData->DeviceObject = NULL;
1926
1927 HubExtension->HubFlags |= USBHUB_FDO_FLAG_STATE_CHANGING;
1928
1929 InsertTailList(&HubExtension->PdoList, &PortExtension->PortLink);
1930
1931 KeReleaseSpinLock(&HubExtension->RelationsWorkerSpinLock, Irql);
1932
1934 NULL);
1935
1936 if (SerialNumber)
1937 {
1939 }
1940
1942 NULL);
1943
1944 if (DeviceHandle)
1945 {
1946 USBD_RemoveDeviceEx(HubExtension, DeviceHandle, 0);
1947 USBH_SyncDisablePort(HubExtension, Port);
1948 }
1949
1950 IoInvalidateDeviceRelations(HubExtension->LowerPDO, BusRelations);
1951 }
1952 else if (PortStatusChange.PortEnableDisableChange)
1953 {
1954 RequestValue = USBHUB_FEATURE_C_PORT_ENABLE;
1955 PortData->PortStatus = *PortStatus;
1956 USBH_SyncClearPortStatus(HubExtension, Port, RequestValue);
1957 return;
1958 }
1959 else if (PortStatusChange.SuspendChange)
1960 {
1961 DPRINT1("USBH_ProcessPortStateChange: SuspendChange UNIMPLEMENTED. FIXME\n");
1962 DbgBreakPoint();
1963 }
1964 else if (PortStatusChange.OverCurrentIndicatorChange)
1965 {
1966 DPRINT1("USBH_ProcessPortStateChange: OverCurrentIndicatorChange UNIMPLEMENTED. FIXME\n");
1967 DbgBreakPoint();
1968 }
1969 else if (PortStatusChange.ResetChange)
1970 {
1971 RequestValue = USBHUB_FEATURE_C_PORT_RESET;
1972 PortData->PortStatus = *PortStatus;
1973 USBH_SyncClearPortStatus(HubExtension, Port, RequestValue);
1974 }
1975}
#define InsertTailList(ListHead, Entry)
VOID NTAPI IoInvalidateDeviceRelations(IN PDEVICE_OBJECT DeviceObject, IN DEVICE_RELATION_TYPE Type)
Definition: pnpmgr.c:1772
USB_CONNECTION_STATUS ConnectionStatus
Definition: usbhub.h:120
USHORT SuspendChange
Definition: usb200.h:165
USHORT OverCurrentIndicatorChange
Definition: usb200.h:166
USHORT ConnectStatusChange
Definition: usb200.h:163
NTSTATUS NTAPI USBH_SyncDisablePort(IN PUSBHUB_FDO_EXTENSION HubExtension, IN USHORT Port)
Definition: usbhub.c:1553
NTSTATUS NTAPI USBH_SyncClearPortStatus(IN PUSBHUB_FDO_EXTENSION HubExtension, IN USHORT Port, IN USHORT RequestValue)
Definition: usbhub.c:1442
#define USBHUB_PDO_FLAG_OVERCURRENT_PORT
Definition: usbhub.h:75
#define USBHUB_FEATURE_C_PORT_CONNECTION
Definition: usbhub.h:98
#define USBHUB_PDO_FLAG_POWER_D3
Definition: usbhub.h:69
@ NoDeviceConnected
Definition: usbioctl.h:278
@ BusRelations
Definition: iotypes.h:2152

Referenced by USBH_ChangeIndicationWorker().

◆ USBH_QueueWorkItem()

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

Definition at line 2917 of file usbhub.c.

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

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

◆ USBH_RegQueryGenericUSBDeviceString()

NTSTATUS NTAPI USBH_RegQueryGenericUSBDeviceString ( PVOID  USBDeviceString)

Definition at line 5090 of file usbhub.c.

5091{
5093
5094 DPRINT("USBH_RegQueryGenericUSBDeviceString ... \n");
5095
5097
5100 QueryTable[0].Name = L"GenericUSBDeviceString";
5101 QueryTable[0].EntryContext = USBDeviceString;
5103 QueryTable[0].DefaultData = 0;
5105
5107 L"usbflags",
5108 QueryTable,
5109 NULL,
5110 NULL);
5111}
NTSYSAPI NTSTATUS WINAPI RtlQueryRegistryValues(ULONG, PCWSTR, PRTL_QUERY_REGISTRY_TABLE, PVOID, PVOID)
_In_ PCWSTR _Inout_ _At_ QueryTable _Pre_unknown_ PRTL_QUERY_REGISTRY_TABLE QueryTable
Definition: rtlfuncs.h:4220
#define RTL_REGISTRY_CONTROL
Definition: nt_native.h:163
#define RTL_QUERY_REGISTRY_REQUIRED
Definition: nt_native.h:132
#define REG_NONE
Definition: nt_native.h:1492
PRTL_QUERY_REGISTRY_ROUTINE QueryRoutine
Definition: nt_native.h:109
NTSTATUS NTAPI USBH_GetConfigValue(IN PWSTR ValueName, IN ULONG ValueType, IN PVOID ValueData, IN ULONG ValueLength, IN PVOID Context, IN PVOID EntryContext)
Definition: usbhub.c:34

Referenced by DriverEntry().

◆ USBH_ResetDevice()

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

Definition at line 4615 of file usbhub.c.

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

Referenced by USBH_ResetPortWorker(), and USBH_RestoreDevice().

◆ USBH_ResetHub()

NTSTATUS NTAPI USBH_ResetHub ( IN PUSBHUB_FDO_EXTENSION  HubExtension)

Definition at line 2117 of file usbhub.c.

2118{
2120 ULONG PortStatusFlags = 0;
2121
2122 DPRINT("USBH_ResetHub: ... \n");
2123
2124 Status = USBH_GetPortStatus(HubExtension, &PortStatusFlags);
2125
2126 if (!NT_SUCCESS(Status))
2127 {
2128 return Status;
2129 }
2130
2131 if (!(PortStatusFlags & USBD_PORT_ENABLED))
2132 {
2133 if (PortStatusFlags & USBD_PORT_CONNECTED)
2134 {
2135 USBH_EnableParentPort(HubExtension);
2136 }
2137 }
2138
2139 Status = USBH_ResetInterruptPipe(HubExtension);
2140
2141 return Status;
2142}
NTSTATUS NTAPI USBH_GetPortStatus(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PULONG PortStatus)
Definition: usbhub.c:1979
NTSTATUS NTAPI USBH_EnableParentPort(IN PUSBHUB_FDO_EXTENSION HubExtension)
Definition: usbhub.c:2032
NTSTATUS NTAPI USBH_ResetInterruptPipe(IN PUSBHUB_FDO_EXTENSION HubExtension)
Definition: usbhub.c:2078
#define USBD_PORT_ENABLED
Definition: usbioctl.h:41
#define USBD_PORT_CONNECTED
Definition: usbioctl.h:42

Referenced by USBH_ChangeIndicationWorker().

◆ USBH_ResetInterruptPipe()

NTSTATUS NTAPI USBH_ResetInterruptPipe ( IN PUSBHUB_FDO_EXTENSION  HubExtension)

Definition at line 2078 of file usbhub.c.

2079{
2080 struct _URB_PIPE_REQUEST * Urb;
2082
2083 DPRINT("USBH_ResetInterruptPipe ... \n");
2084
2086 sizeof(struct _URB_PIPE_REQUEST),
2087 USB_HUB_TAG);
2088
2089 if (Urb)
2090 {
2091 RtlZeroMemory(Urb, sizeof(struct _URB_PIPE_REQUEST));
2092
2093 Urb->Hdr.Length = sizeof(struct _URB_PIPE_REQUEST);
2095 Urb->PipeHandle = HubExtension->PipeInfo.PipeHandle;
2096
2097 Status = USBH_FdoSyncSubmitUrb(HubExtension->Common.SelfDevice,
2098 (PURB)Urb);
2099
2101 }
2102 else
2103 {
2105 }
2106
2107 if (NT_SUCCESS(Status))
2108 {
2109 HubExtension->RequestErrors = 0;
2110 }
2111
2112 return Status;
2113}
struct _URB_HEADER Hdr
Definition: usb.h:315
USBD_PIPE_HANDLE PipeHandle
Definition: usb.h:316
#define URB_FUNCTION_SYNC_RESET_PIPE_AND_CLEAR_STALL
Definition: usb.h:116

Referenced by USBH_ResetHub().

◆ USBH_SetPdoRegistryParameter()

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

Definition at line 213 of file usbhub.c.

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

Referenced by USBH_SymbolicLink().

◆ USBH_SubmitStatusChangeTransfer()

NTSTATUS NTAPI USBH_SubmitStatusChangeTransfer ( IN PUSBHUB_FDO_EXTENSION  HubExtension)

Definition at line 2442 of file usbhub.c.

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

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

◆ USBH_SyncClearHubStatus()

NTSTATUS NTAPI USBH_SyncClearHubStatus ( IN PUSBHUB_FDO_EXTENSION  HubExtension,
IN USHORT  RequestValue 
)

Definition at line 1389 of file usbhub.c.

1391{
1393
1394 DPRINT("USBH_SyncClearHubStatus: RequestValue - %x\n", RequestValue);
1395
1396 RequestType.B = 0;
1397 RequestType.Recipient = BMREQUEST_TO_DEVICE;
1400
1401 return USBH_Transact(HubExtension,
1402 NULL,
1403 0,
1408 RequestValue,
1409 0);
1410}
#define BMREQUEST_TO_DEVICE
Definition: usb100.h:38
#define URB_FUNCTION_CLASS_DEVICE
Definition: usb.h:112
NTSTATUS NTAPI USBH_Transact(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PVOID TransferBuffer, IN ULONG BufferLen, IN BOOLEAN IsDeviceToHost, IN USHORT Function, IN BM_REQUEST_TYPE RequestType, IN UCHAR Request, IN USHORT RequestValue, IN USHORT RequestIndex)
Definition: usbhub.c:370

Referenced by USBH_ProcessHubStateChange().

◆ USBH_SyncClearPortStatus()

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

Definition at line 1442 of file usbhub.c.

1445{
1447
1448 DPRINT("USBH_SyncClearPortStatus: Port - %x, RequestValue - %x\n",
1449 Port,
1450 RequestValue);
1451
1452 RequestType.B = 0;
1453 RequestType.Recipient = BMREQUEST_TO_OTHER;
1456
1457 return USBH_Transact(HubExtension,
1458 NULL,
1459 0,
1464 RequestValue,
1465 Port);
1466}

Referenced by USBH_ProcessPortStateChange(), and USBH_StartHubFdoDevice().

◆ USBH_SyncDisablePort()

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

Definition at line 1553 of file usbhub.c.

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

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

◆ USBH_SyncGetDeviceConfigurationDescriptor()

NTSTATUS NTAPI USBH_SyncGetDeviceConfigurationDescriptor ( IN PDEVICE_OBJECT  DeviceObject,
IN PUSB_CONFIGURATION_DESCRIPTOR  ConfigDescriptor,
IN ULONG  NumberOfBytes,
IN PULONG  OutLength 
)

Definition at line 913 of file usbhub.c.

917{
918 PCOMMON_DEVICE_EXTENSION DeviceExtension;
921
922 DPRINT("USBH_SyncGetDeviceConfigurationDescriptor: ... \n");
923
924 DeviceExtension = DeviceObject->DeviceExtension;
925
926 if (OutLength)
927 {
928 *OutLength = 0;
929 }
930
932 sizeof(struct _URB_CONTROL_DESCRIPTOR_REQUEST),
934
935 if (!Urb)
936 {
938 }
939
941
943 Urb->Hdr.Length = sizeof(struct _URB_CONTROL_DESCRIPTOR_REQUEST);
944
948
949 if (DeviceExtension->ExtensionType == USBH_EXTENSION_TYPE_HUB ||
950 DeviceExtension->ExtensionType == USBH_EXTENSION_TYPE_PARENT)
951 {
953 }
954 else
955 {
957 }
958
959 if (OutLength)
960 {
961 *OutLength = Urb->TransferBufferLength;
962 }
963
964 if (Urb)
965 {
967 }
968
969 return Status;
970}
#define USB_CONFIGURATION_DESCRIPTOR_TYPE
Definition: usb100.h:50
#define USBH_EXTENSION_TYPE_PARENT
Definition: usbhub.h:30
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS _Inout_ PLARGE_INTEGER NumberOfBytes
Definition: iotypes.h:1036

Referenced by USBH_GetConfigurationDescriptor().

◆ USBH_SyncGetDeviceHandle()

PUSB_DEVICE_HANDLE NTAPI USBH_SyncGetDeviceHandle ( IN PDEVICE_OBJECT  DeviceObject)

Definition at line 832 of file usbhub.c.

833{
834 PIRP Irp;
838 PIO_STACK_LOCATION IoStack;
839
840 DPRINT("USBH_SyncGetDeviceHandle: ... \n");
841
843
844 Irp = IoBuildDeviceIoControlRequest(IOCTL_INTERNAL_USB_GET_DEVICE_HANDLE,
846 NULL,
847 0,
848 NULL,
849 0,
850 TRUE,
851 &Event,
853
854 if (!Irp)
855 {
856 DPRINT1("USBH_SyncGetDeviceHandle: Irp - NULL!\n");
857 return NULL;
858 }
859
861 IoStack->Parameters.Others.Argument1 = &DeviceHandle;
862
864 {
866 Suspended,
868 FALSE,
869 NULL);
870 }
871
872 return DeviceHandle;
873}

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

◆ USBH_SyncGetHubCount()

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

Definition at line 781 of file usbhub.c.

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

Referenced by USBH_PdoInternalControl(), and USBH_StartHubFdoDevice().

◆ USBH_SyncGetHubDescriptor()

NTSTATUS NTAPI USBH_SyncGetHubDescriptor ( IN PUSBHUB_FDO_EXTENSION  HubExtension)

Definition at line 1048 of file usbhub.c.

1049{
1050 PUSB_EXTHUB_INFORMATION_0 ExtendedHubInfo;
1051 ULONG NumberPorts;
1052 PUSBHUB_PORT_DATA PortData;
1053 USHORT RequestValue;
1056 PUSB_HUB_DESCRIPTOR HubDescriptor = NULL;
1057 ULONG ix;
1058 ULONG Retry;
1059
1060 DPRINT("USBH_SyncGetHubDescriptor: ... \n");
1061
1062 ExtendedHubInfo = ExAllocatePoolWithTag(NonPagedPool,
1064 USB_HUB_TAG);
1065
1066 if (!ExtendedHubInfo)
1067 {
1069 goto ErrorExit;
1070 }
1071
1072 RtlZeroMemory(ExtendedHubInfo, sizeof(USB_EXTHUB_INFORMATION_0));
1073
1074 Status = USBHUB_GetExtendedHubInfo(HubExtension, ExtendedHubInfo);
1075
1076 if (!NT_SUCCESS(Status))
1077 {
1078 ExFreePoolWithTag(ExtendedHubInfo, USB_HUB_TAG);
1079 ExtendedHubInfo = NULL;
1080 }
1081
1083
1084 HubDescriptor = ExAllocatePoolWithTag(NonPagedPool,
1086 USB_HUB_TAG);
1087
1088 if (!HubDescriptor)
1089 {
1091 goto ErrorExit;
1092 }
1093
1094 RtlZeroMemory(HubDescriptor, NumberOfBytes);
1095
1096 RequestValue = 0;
1097 Retry = 0;
1098
1099 while (TRUE)
1100 {
1101 while (Retry <= 5)
1102 {
1104
1105 RequestType.B = 0;
1106 RequestType.Recipient = BMREQUEST_TO_DEVICE;
1109
1110 Status = USBH_Transact(HubExtension,
1111 HubDescriptor,
1117 RequestValue,
1118 0);
1119
1120 if (NT_SUCCESS(Status))
1121 {
1122 break;
1123 }
1124
1125 RequestValue = 0x2900; // Hub DescriptorType - 0x29
1126
1127 Retry++;
1128 }
1129
1130 if (HubDescriptor->bDescriptorLength <= NumberOfBytes)
1131 {
1132 break;
1133 }
1134
1135 NumberOfBytes = HubDescriptor->bDescriptorLength;
1136 ExFreePoolWithTag(HubDescriptor, USB_HUB_TAG);
1137
1138 if (Retry >= 5)
1139 {
1141 HubDescriptor = NULL;
1142 goto ErrorExit;
1143 }
1144
1145 HubDescriptor = ExAllocatePoolWithTag(NonPagedPool,
1147 USB_HUB_TAG);
1148
1149 if (!HubDescriptor)
1150 {
1152 goto ErrorExit;
1153 }
1154
1155 RtlZeroMemory(HubDescriptor, NumberOfBytes);
1156 }
1157
1158 NumberPorts = HubDescriptor->bNumberOfPorts;
1159
1160 if (HubExtension->PortData)
1161 {
1162 PortData = HubExtension->PortData;
1163
1164 for (ix = 0; ix < NumberPorts; ix++)
1165 {
1166 PortData[ix].PortStatus.AsUlong32 = 0;
1167
1168 if (ExtendedHubInfo)
1169 {
1170 PortData[ix].PortAttributes = ExtendedHubInfo->Port[ix].PortAttributes;
1171 }
1172 else
1173 {
1174 PortData[ix].PortAttributes = 0;
1175 }
1176
1177 PortData[ix].ConnectionStatus = NoDeviceConnected;
1178
1179 if (PortData[ix].DeviceObject != NULL)
1180 {
1181 PortData[ix].ConnectionStatus = DeviceConnected;
1182 }
1183 }
1184 }
1185 else
1186 {
1187 PortData = NULL;
1188
1189 if (HubDescriptor->bNumberOfPorts)
1190 {
1192 NumberPorts * sizeof(USBHUB_PORT_DATA),
1193 USB_HUB_TAG);
1194 }
1195
1196 if (!PortData)
1197 {
1199 goto ErrorExit;
1200 }
1201
1202 RtlZeroMemory(PortData, NumberPorts * sizeof(USBHUB_PORT_DATA));
1203
1204 for (ix = 0; ix < NumberPorts; ix++)
1205 {
1206 PortData[ix].ConnectionStatus = NoDeviceConnected;
1207
1208 if (ExtendedHubInfo)
1209 {
1210 PortData[ix].PortAttributes = ExtendedHubInfo->Port[ix].PortAttributes;
1211 }
1212 }
1213 }
1214
1215 if (!NT_SUCCESS(Status))
1216 {
1217 goto ErrorExit;
1218 }
1219
1220 HubExtension->HubDescriptor = HubDescriptor;
1221
1222 HubExtension->PortData = PortData;
1223
1224 if (ExtendedHubInfo)
1225 {
1226 ExFreePoolWithTag(ExtendedHubInfo, USB_HUB_TAG);
1227 }
1228
1229 return Status;
1230
1231ErrorExit:
1232
1233 if (HubDescriptor)
1234 {
1235 ExFreePoolWithTag(HubDescriptor, USB_HUB_TAG);
1236 }
1237
1238 if (ExtendedHubInfo)
1239 {
1240 ExFreePoolWithTag(ExtendedHubInfo, USB_HUB_TAG);
1241 }
1242
1243 return Status;
1244}
_In_ PSCSI_REQUEST_BLOCK _Out_ NTSTATUS _Inout_ BOOLEAN * Retry
Definition: classpnp.h:312
ULONG PortAttributes
Definition: usbhub.h:121
USB_EXTPORT_INFORMATION_0 Port[255]
Definition: hubbusif.h:732
UCHAR bDescriptorLength
Definition: usb100.h:171
#define USB_REQUEST_GET_DESCRIPTOR
Definition: usb100.h:82
struct _USB_HUB_DESCRIPTOR USB_HUB_DESCRIPTOR
#define BMREQUEST_STANDARD
Definition: usb100.h:34
NTSTATUS NTAPI USBHUB_GetExtendedHubInfo(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PUSB_EXTHUB_INFORMATION_0 HubInfoBuffer)
Definition: usbhub.c:680
@ DeviceConnected
Definition: usbioctl.h:279

Referenced by USBH_StartHubFdoDevice().

◆ USBH_SyncGetHubStatus()

NTSTATUS NTAPI USBH_SyncGetHubStatus ( IN PUSBHUB_FDO_EXTENSION  HubExtension,
IN PUSB_HUB_STATUS_AND_CHANGE  HubStatus,
IN ULONG  Length 
)

Definition at line 1363 of file usbhub.c.

1366{
1368
1369 DPRINT("USBH_SyncGetHubStatus\n");
1370
1371 RequestType.B = 0;
1372 RequestType.Recipient = BMREQUEST_TO_DEVICE;
1375
1376 return USBH_Transact(HubExtension,
1377 HubStatus,
1378 Length,
1383 0,
1384 0);
1385}

Referenced by USBH_ChangeIndicationWorker().

◆ USBH_SyncGetPortStatus()

NTSTATUS NTAPI USBH_SyncGetPortStatus ( IN PUSBHUB_FDO_EXTENSION  HubExtension,
IN USHORT  Port,
IN PUSB_PORT_STATUS_AND_CHANGE  PortStatus,
IN ULONG  Length 
)

Definition at line 1414 of file usbhub.c.

1418{
1420
1421 DPRINT("USBH_SyncGetPortStatus: Port - %x\n", Port);
1422
1423 RequestType.B = 0;
1424 RequestType.Recipient = BMREQUEST_TO_OTHER;
1427
1428 return USBH_Transact(HubExtension,
1429 PortStatus,
1430 Length,
1435 0,
1436 Port);
1437}

Referenced by USBH_ChangeIndicationWorker(), USBH_FdoQueryBusRelations(), USBH_PdoIoctlGetPortStatus(), USBH_ResetDevice(), USBH_RestoreDevice(), and USBH_SyncResetPort().

◆ USBH_SyncGetRootHubPdo()

NTSTATUS NTAPI USBH_SyncGetRootHubPdo ( IN PDEVICE_OBJECT  DeviceObject,
IN OUT PDEVICE_OBJECT OutPdo1,
IN OUT PDEVICE_OBJECT OutPdo2 
)

Definition at line 728 of file usbhub.c.

731{
734 PIRP Irp;
735 PIO_STACK_LOCATION IoStack;
737
738 DPRINT("USBH_SyncGetRootHubPdo: ... \n");
739
741
744 NULL,
745 0,
746 NULL,
747 0,
748 TRUE,
749 &Event,
751
752 if (!Irp)
753 {
755 }
756
758 IoStack->Parameters.Others.Argument1 = OutPdo1;
759 IoStack->Parameters.Others.Argument2 = OutPdo2;
760
762
763 if (Status == STATUS_PENDING)
764 {
766 Suspended,
768 FALSE,
769 NULL);
770 }
771 else
772 {
774 }
775
776 return IoStatusBlock.Status;
777}
#define IOCTL_INTERNAL_USB_GET_ROOTHUB_PDO
Definition: usbioctl.h:38

Referenced by USBH_FdoStartDevice(), and USBH_StartHubFdoDevice().

◆ USBH_SyncGetStatus()

NTSTATUS NTAPI USBH_SyncGetStatus ( IN PDEVICE_OBJECT  DeviceObject,
IN PUSHORT  OutStatus,
IN USHORT  Function,
IN USHORT  RequestIndex 
)

Definition at line 1323 of file usbhub.c.

1327{
1329 NTSTATUS NtStatus;
1330 USHORT UsbStatus;
1331
1332 DPRINT("USBH_SyncGetStatus: ... \n");
1333
1335 sizeof(struct _URB_CONTROL_GET_STATUS_REQUEST),
1336 USB_HUB_TAG);
1337
1338 if (!Urb)
1339 {
1341 }
1342
1344
1345 Urb->Hdr.Length = sizeof(struct _URB_CONTROL_GET_STATUS_REQUEST);
1346 Urb->Hdr.Function = Function;
1347
1348 Urb->TransferBuffer = &UsbStatus;
1349 Urb->TransferBufferLength = sizeof(UsbStatus);
1350 Urb->Index = RequestIndex;
1351
1352 NtStatus = USBH_FdoSyncSubmitUrb(DeviceObject, (PURB)Urb);
1353
1354 *OutStatus = UsbStatus;
1355
1357
1358 return NtStatus;
1359}
_In_ CDROM_SCAN_FOR_SPECIAL_INFO _In_ PCDROM_SCAN_FOR_SPECIAL_HANDLER Function
Definition: cdrom.h:1156
struct _URB_HEADER Hdr
Definition: usb.h:357

Referenced by USBH_HubIsBusPowered().

◆ USBH_SyncGetStringDescriptor()

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 at line 1248 of file usbhub.c.

1255{
1257 ULONG TransferedLength;
1259
1260 DPRINT("USBH_SyncGetStringDescriptor: Index - %x, LanguageId - %x\n",
1261 Index,
1262 LanguageId);
1263
1265 sizeof(struct _URB_CONTROL_DESCRIPTOR_REQUEST),
1266 USB_HUB_TAG);
1267
1268 if (!Urb)
1269 {
1271 }
1272
1274
1276 Urb->Hdr.Length = sizeof(struct _URB_CONTROL_DESCRIPTOR_REQUEST);
1277
1280
1281 Urb->Index = Index;
1283 Urb->LanguageId = LanguageId;
1284
1286
1287 if (!NT_SUCCESS(Status))
1288 {
1290 return Status;
1291 }
1292
1293 TransferedLength = Urb->TransferBufferLength;
1294
1295 if (TransferedLength > NumberOfBytes)
1296 {
1298 }
1299
1300 if (!NT_SUCCESS(Status))
1301 {
1303 return Status;
1304 }
1305
1306 if (OutLength)
1307 {
1308 *OutLength = TransferedLength;
1309 }
1310
1311 if (IsValidateLength && TransferedLength != Descriptor->bLength)
1312 {
1314 }
1315
1317
1318 return Status;
1319}
#define USB_STRING_DESCRIPTOR_TYPE
Definition: usb100.h:51

Referenced by USBH_CheckDeviceLanguage(), USBH_GetSerialNumberString(), and USBH_PdoQueryDeviceText().

◆ USBH_SyncIrpComplete()

NTSTATUS NTAPI USBH_SyncIrpComplete ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp,
IN PVOID  Context 
)

Definition at line 92 of file usbhub.c.

95{
96 PUSBHUB_URB_TIMEOUT_CONTEXT HubTimeoutContext;
99
100 DPRINT("USBH_SyncIrpComplete: ... \n");
101
102 HubTimeoutContext = Context;
103
104 KeAcquireSpinLock(&HubTimeoutContext->UrbTimeoutSpinLock, &OldIrql);
105 HubTimeoutContext->IsNormalCompleted = TRUE;
106 TimerCancelled = KeCancelTimer(&HubTimeoutContext->UrbTimeoutTimer);
107 KeReleaseSpinLock(&HubTimeoutContext->UrbTimeoutSpinLock, OldIrql);
108
109 if (TimerCancelled)
110 {
111 KeSetEvent(&HubTimeoutContext->UrbTimeoutEvent,
113 FALSE);
114 }
115
116 return STATUS_SUCCESS;
117}
_Out_ _At_ TimerCancelled PBOOLEAN TimerCancelled
Definition: ndis.h:2820
KSPIN_LOCK UrbTimeoutSpinLock
Definition: usbhub.h:242
BOOLEAN NTAPI KeCancelTimer(IN OUT PKTIMER Timer)
Definition: timerobj.c:206

Referenced by USBH_SyncSubmitUrb().

◆ USBH_SyncPowerOnPort()

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

Definition at line 1470 of file usbhub.c.

1473{
1474 PUSBHUB_PORT_DATA PortData;
1475 PUSB_HUB_DESCRIPTOR HubDescriptor;
1479
1480 DPRINT("USBH_SyncPowerOnPort: Port - %x, IsWait - %x\n", Port, IsWait);
1481
1482 ASSERT(Port > 0);
1483 PortData = &HubExtension->PortData[Port - 1];
1484 PortStatus = &PortData->PortStatus;
1485
1486 if (PortStatus->PortStatus.Usb20PortStatus.CurrentConnectStatus == 1)
1487 {
1488 return Status;
1489 }
1490
1491 RequestType.B = 0;
1492 RequestType.Recipient = BMREQUEST_TO_DEVICE;
1495
1496 Status = USBH_Transact(HubExtension,
1497 NULL,
1498 0,
1504 Port);
1505
1506 if (NT_SUCCESS(Status))
1507 {
1508 if (IsWait)
1509 {
1510 HubDescriptor = HubExtension->HubDescriptor;
1511 USBH_Wait(2 * HubDescriptor->bPowerOnToPowerGood);
1512 }
1513
1514 PortStatus->PortStatus.Usb20PortStatus.CurrentConnectStatus = 1;
1515 }
1516
1517 return Status;
1518}
UCHAR bPowerOnToPowerGood
Definition: usb100.h:175
#define USB_REQUEST_SET_FEATURE
Definition: usb100.h:80
#define USBHUB_FEATURE_PORT_POWER
Definition: usbhub.h:96

Referenced by USBH_SyncPowerOnPorts().

◆ USBH_SyncPowerOnPorts()

NTSTATUS NTAPI USBH_SyncPowerOnPorts ( IN PUSBHUB_FDO_EXTENSION  HubExtension)

Definition at line 1522 of file usbhub.c.

1523{
1524 PUSB_HUB_DESCRIPTOR HubDescriptor;
1526 USHORT Port;
1528
1529 DPRINT("USBH_SyncPowerOnPorts: ... \n");
1530
1531 HubDescriptor = HubExtension->HubDescriptor;
1532 NumberOfPorts = HubDescriptor->bNumberOfPorts;
1533
1534 for (Port = 1; Port <= NumberOfPorts; ++Port)
1535 {
1536 Status = USBH_SyncPowerOnPort(HubExtension, Port, 0);
1537
1538 if (!NT_SUCCESS(Status))
1539 {
1540 DPRINT1("USBH_SyncPowerOnPorts: USBH_SyncPowerOnPort() failed - %lX\n",
1541 Status);
1542 break;
1543 }
1544 }
1545
1546 USBH_Wait(2 * HubDescriptor->bPowerOnToPowerGood);
1547
1548 return Status;
1549}
#define NumberOfPorts()
Definition: portcls.h:444
NTSTATUS NTAPI USBH_SyncPowerOnPort(IN PUSBHUB_FDO_EXTENSION HubExtension, IN USHORT Port, IN BOOLEAN IsWait)
Definition: usbhub.c:1470

Referenced by USBH_StartHubFdoDevice().

◆ USBH_SyncResetPort()

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

Definition at line 471 of file usbhub.c.

473{
477 ULONG ResetRetry = 0;
479
480 DPRINT("USBH_SyncResetPort: Port - %x\n", Port);
481
482 InterlockedIncrement(&HubExtension->PendingRequestCount);
483
484 KeWaitForSingleObject(&HubExtension->HubPortSemaphore,
485 Executive,
487 FALSE,
488 NULL);
489
490 Status = USBH_SyncGetPortStatus(HubExtension,
491 Port,
492 &PortStatus,
494
495 if (NT_SUCCESS(Status) &&
496 (PortStatus.PortStatus.Usb20PortStatus.CurrentConnectStatus == 0))
497 {
499 goto Exit;
500 }
501
502 HubExtension->HubFlags |= USBHUB_FDO_FLAG_RESET_PORT_LOCK;
503
504 while (TRUE)
505 {
507
509
510 InterlockedExchangePointer((PVOID)&HubExtension->pResetPortEvent,
511 &Event);
512
513 RequestType.B = 0;
517
518 Status = USBH_Transact(HubExtension,
519 NULL,
520 0,
526 Port);
527
528 Timeout.QuadPart = -5000 * 10000;
529
530 if (!NT_SUCCESS(Status))
531 {
532 InterlockedExchangePointer((PVOID)&HubExtension->pResetPortEvent,
533 NULL);
534
535 USBH_Wait(10);
536 HubExtension->HubFlags &= ~USBHUB_FDO_FLAG_RESET_PORT_LOCK;
537
538 goto Exit;
539 }
540
542 Suspended,
544 FALSE,
545 &Timeout);
546
547 if (Status != STATUS_TIMEOUT)
548 {
549 break;
550 }
551
552 Status = USBH_SyncGetPortStatus(HubExtension,
553 Port,
554 &PortStatus,
556
557 if (!NT_SUCCESS(Status) ||
558 (PortStatus.PortStatus.Usb20PortStatus.CurrentConnectStatus == 0) ||
559 ResetRetry >= USBHUB_RESET_PORT_MAX_RETRY)
560 {
561 InterlockedExchangePointer((PVOID)&HubExtension->pResetPortEvent,
562 NULL);
563
564 USBH_Wait(10);
565 HubExtension->HubFlags &= ~USBHUB_FDO_FLAG_RESET_PORT_LOCK;
566
568 goto Exit;
569 }
570
571 ResetRetry++;
572 }
573
574 Status = USBH_SyncGetPortStatus(HubExtension,
575 Port,
576 &PortStatus,
578
579 if ((PortStatus.PortStatus.Usb20PortStatus.CurrentConnectStatus == 0) &&
581 HubExtension->HubFlags & USBHUB_FDO_FLAG_USB20_HUB)
582 {
584 }
585
586 USBH_Wait(10);
587 HubExtension->HubFlags &= ~USBHUB_FDO_FLAG_RESET_PORT_LOCK;
588
589Exit:
590
591 KeReleaseSemaphore(&HubExtension->HubPortSemaphore,
593 1,
594 FALSE);
595
596 if (!InterlockedDecrement(&HubExtension->PendingRequestCount))
597 {
598 KeSetEvent(&HubExtension->PendingRequestEvent,
600 FALSE);
601 }
602
603 return Status;
604}
#define STATUS_TIMEOUT
Definition: d3dkmdt.h:49
static ULONG Timeout
Definition: ping.c:61
#define USBHUB_FDO_FLAG_USB20_HUB
Definition: usbhub.h:47
#define USBHUB_RESET_PORT_MAX_RETRY
Definition: usbhub.h:107
#define USBHUB_FEATURE_PORT_RESET
Definition: usbhub.h:95
#define USBHUB_FDO_FLAG_RESET_PORT_LOCK
Definition: usbhub.h:40

Referenced by USBH_CreateDevice(), USBH_FdoQueryBusRelations(), and USBH_ResetDevice().

◆ USBH_SyncSubmitUrb()

NTSTATUS NTAPI USBH_SyncSubmitUrb ( IN PDEVICE_OBJECT  DeviceObject,
IN PURB  Urb 
)

Definition at line 250 of file usbhub.c.

252{
255 PIRP Irp;
256 PIO_STACK_LOCATION IoStack;
257 PUSBHUB_URB_TIMEOUT_CONTEXT HubTimeoutContext;
258 BOOLEAN IsWaitTimeout = FALSE;
261
262 DPRINT("USBH_SyncSubmitUrb: ... \n");
263
264 Urb->UrbHeader.UsbdDeviceHandle = NULL;
265
267
270 NULL,
271 0,
272 NULL,
273 0,
274 TRUE,
275 &Event,
277
278 if (!Irp)
279 {
281 }
282
284 IoStack->Parameters.Others.Argument1 = Urb;
285
286 HubTimeoutContext = ExAllocatePoolWithTag(NonPagedPool,
289
290 if (HubTimeoutContext)
291 {
292 RtlZeroMemory(HubTimeoutContext, sizeof(USBHUB_URB_TIMEOUT_CONTEXT));
293
294 HubTimeoutContext->Irp = Irp;
295 HubTimeoutContext->IsNormalCompleted = FALSE;
296
297 KeInitializeEvent(&HubTimeoutContext->UrbTimeoutEvent,
299 FALSE);
300
301 KeInitializeSpinLock(&HubTimeoutContext->UrbTimeoutSpinLock);
302 KeInitializeTimer(&HubTimeoutContext->UrbTimeoutTimer);
303
304 KeInitializeDpc(&HubTimeoutContext->UrbTimeoutDPC,
306 HubTimeoutContext);
307
308 DueTime.QuadPart = -5000 * 10000; // Timeout 5 sec.
309
310 KeSetTimer(&HubTimeoutContext->UrbTimeoutTimer,
311 DueTime,
312 &HubTimeoutContext->UrbTimeoutDPC);
313
316 HubTimeoutContext,
317 TRUE,
318 TRUE,
319 TRUE);
320
321 IsWaitTimeout = TRUE;
322 }
323
325
326 if (Status == STATUS_PENDING)
327 {
329 Suspended,
331 FALSE,
332 NULL);
333 }
334 else
335 {
337 }
338
339 if (IsWaitTimeout)
340 {
341 KeWaitForSingleObject(&HubTimeoutContext->UrbTimeoutEvent,
342 Suspended,
344 FALSE,
345 NULL);
346
347 ExFreePoolWithTag(HubTimeoutContext, USB_HUB_TAG);
348 }
349
350 return IoStatusBlock.Status;
351}
VOID NTAPI KeInitializeDpc(IN PKDPC Dpc, IN PKDEFERRED_ROUTINE DeferredRoutine, IN PVOID DeferredContext)
Definition: dpc.c:712
BOOLEAN NTAPI KeSetTimer(IN OUT PKTIMER Timer, IN LARGE_INTEGER DueTime, IN PKDPC Dpc OPTIONAL)
Definition: timerobj.c:281
VOID NTAPI KeInitializeTimer(OUT PKTIMER Timer)
Definition: timerobj.c:233
NTSTATUS NTAPI USBH_SyncIrpComplete(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context)
Definition: usbhub.c:92
VOID NTAPI USBH_UrbTimeoutDPC(IN PKDPC Dpc, IN PVOID DeferredContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
Definition: usbhub.c:184
_In_ WDFTIMER _In_ LONGLONG DueTime
Definition: wdftimer.h:190

Referenced by USBH_FdoSyncSubmitUrb(), USBH_IoctlGetDescriptor(), USBH_SyncGetDeviceConfigurationDescriptor(), and USBH_SyncGetStringDescriptor().

◆ USBH_Transact()

NTSTATUS NTAPI USBH_Transact ( IN PUSBHUB_FDO_EXTENSION  HubExtension,
IN PVOID  TransferBuffer,
IN ULONG  BufferLen,
IN BOOLEAN  IsDeviceToHost,
IN USHORT  Function,
IN BM_REQUEST_TYPE  RequestType,
IN UCHAR  Request,
IN USHORT  RequestValue,
IN USHORT  RequestIndex 
)

Definition at line 370 of file usbhub.c.

379{
382 PVOID Buffer = NULL;
385
386 DPRINT("USBH_Transact: ... \n");
387
388 if (BufferLen)
389 {
390 Length = ALIGN_DOWN_BY(BufferLen + sizeof(ULONG), sizeof(ULONG));
391
393
394 if (!Buffer)
395 {
397 }
398
400 }
401
405
406 if (!Urb)
407 {
408 if (Buffer)
409 {
411 }
412
414 }
415
417
418 if (IsDeviceToHost)
419 {
420 if (BufferLen)
421 {
422 RtlZeroMemory(TransferBuffer, BufferLen);
423 }
424
426 }
427 else
428 {
429 if (BufferLen)
430 {
432 }
433
435 }
436
437 Urb->Hdr.Length = sizeof(struct _URB_CONTROL_VENDOR_OR_CLASS_REQUEST);
438 Urb->Hdr.Function = Function;
439 Urb->Hdr.UsbdDeviceHandle = NULL;
440
442 Urb->TransferBuffer = BufferLen != 0 ? Buffer : NULL;
443 Urb->TransferBufferLength = BufferLen;
444 Urb->TransferBufferMDL = NULL;
445 Urb->UrbLink = NULL;
446
448 Urb->Request = Request;
449 Urb->Value = RequestValue;
450 Urb->Index = RequestIndex;
451
452 Status = USBH_FdoSyncSubmitUrb(HubExtension->Common.SelfDevice, (PURB)Urb);
453
454 if (IsDeviceToHost && BufferLen)
455 {
457 }
458
459 if (Buffer)
460 {
462 }
463
465
466 return Status;
467}
#define ALIGN_DOWN_BY(size, align)
Definition: bufpool.h:45
struct _URB_HEADER Hdr
Definition: usb.h:386
#define USBD_TRANSFER_DIRECTION_OUT
Definition: usb.h:159
_In_ WDFREQUEST Request
Definition: wdfdevice.h:547

Referenced by USBH_SyncClearHubStatus(), USBH_SyncClearPortStatus(), USBH_SyncDisablePort(), USBH_SyncGetHubDescriptor(), USBH_SyncGetHubStatus(), USBH_SyncGetPortStatus(), USBH_SyncPowerOnPort(), and USBH_SyncResetPort().

◆ USBH_UrbTimeoutDPC()

VOID NTAPI USBH_UrbTimeoutDPC ( IN PKDPC  Dpc,
IN PVOID  DeferredContext,
IN PVOID  SystemArgument1,
IN PVOID  SystemArgument2 
)

Definition at line 184 of file usbhub.c.

188{
189 PUSBHUB_URB_TIMEOUT_CONTEXT HubTimeoutContext;
191 BOOL IsCompleted;
192
193 DPRINT("USBH_TimeoutDPC ... \n");
194
195 HubTimeoutContext = DeferredContext;
196
197 KeAcquireSpinLock(&HubTimeoutContext->UrbTimeoutSpinLock, &OldIrql);
198 IsCompleted = HubTimeoutContext->IsNormalCompleted;
199 KeReleaseSpinLock(&HubTimeoutContext->UrbTimeoutSpinLock, OldIrql);
200
201 if (!IsCompleted)
202 {
203 IoCancelIrp(HubTimeoutContext->Irp);
204 }
205
206 KeSetEvent(&HubTimeoutContext->UrbTimeoutEvent,
208 FALSE);
209}
unsigned int BOOL
Definition: ntddk_ex.h:94
_In_opt_ PVOID DeferredContext
Definition: ketypes.h:687

Referenced by USBH_SyncSubmitUrb().

◆ USBH_ValidateSerialNumberString()

BOOLEAN NTAPI USBH_ValidateSerialNumberString ( IN PUSHORT  SerialNumberString)

Definition at line 4219 of file usbhub.c.

4220{
4221 USHORT ix;
4222 USHORT Symbol;
4223
4224 DPRINT("USBH_ValidateSerialNumberString: ... \n");
4225
4226 for (ix = 0; SerialNumberString[ix] != UNICODE_NULL; ix++)
4227 {
4228 Symbol = SerialNumberString[ix];
4229
4230 if (Symbol < 0x20 || Symbol > 0x7F || Symbol == 0x2C) // ','
4231 {
4232 return FALSE;
4233 }
4234 }
4235
4236 return TRUE;
4237}
Definition: Symbol.h:9

Referenced by USBH_CreateDevice().

◆ USBH_Wait()

NTSTATUS NTAPI USBH_Wait ( IN ULONG  Milliseconds)

Definition at line 23 of file usbhub.c.

24{
26
27 DPRINT("USBH_Wait: Milliseconds - %x\n", Milliseconds);
28 Interval.QuadPart = -10000LL * Milliseconds - ((ULONGLONG)KeQueryTimeIncrement() - 1);
30}
#define KeDelayExecutionThread(mode, foo, t)
Definition: env_spec_w32.h:484
DWORD Interval
Definition: netstat.c:30
ULONG NTAPI KeQueryTimeIncrement(VOID)
Definition: clock.c:153
uint64_t ULONGLONG
Definition: typedefs.h:67

Referenced by USBH_CreateDevice(), USBH_FdoQueryBusRelations(), USBH_HubSetD0(), USBH_ResetDevice(), USBH_RestoreDevice(), USBH_SyncPowerOnPort(), USBH_SyncPowerOnPorts(), and USBH_SyncResetPort().

◆ USBH_Worker()

VOID NTAPI USBH_Worker ( IN PDEVICE_OBJECT  DeviceObject,
IN PVOID  Context 
)

Definition at line 2872 of file usbhub.c.

2874{
2875 PUSBHUB_IO_WORK_ITEM HubIoWorkItem;
2876 PUSBHUB_FDO_EXTENSION HubExtension;
2877 KIRQL OldIrql;
2879
2880 DPRINT("USBH_Worker: HubIoWorkItem - %p\n", Context);
2881
2882 HubIoWorkItem = Context;
2883
2884 InterlockedDecrement(&HubIoWorkItem->HubWorkerQueued);
2885
2886 HubExtension = HubIoWorkItem->HubExtension;
2887 WorkItem = HubIoWorkItem->HubWorkItem;
2888
2889 HubIoWorkItem->HubWorkerRoutine(HubIoWorkItem->HubExtension,
2890 HubIoWorkItem->HubWorkItemBuffer);
2891
2892 KeAcquireSpinLock(&HubExtension->WorkItemSpinLock, &OldIrql);
2893 RemoveEntryList(&HubIoWorkItem->HubWorkItemLink);
2895
2896 if (HubIoWorkItem->HubWorkItemBuffer)
2897 {
2899 }
2900
2901 ExFreePoolWithTag(HubIoWorkItem, USB_HUB_TAG);
2902
2903 if (!InterlockedDecrement(&HubExtension->PendingRequestCount))
2904 {
2905 KeSetEvent(&HubExtension->PendingRequestEvent,
2907 FALSE);
2908 }
2909
2911
2912 DPRINT("USBH_Worker: HubIoWorkItem %p complete\n", Context);
2913}
#define RemoveEntryList(Entry)
Definition: env_spec_w32.h:986
KSPIN_LOCK WorkItemSpinLock
Definition: usbhub.h:191
LIST_ENTRY HubWorkItemLink
Definition: usbhub.h:133

Referenced by USBH_QueueWorkItem().

◆ USBH_WriteFailReasonID()

NTSTATUS NTAPI USBH_WriteFailReasonID ( IN PDEVICE_OBJECT  DeviceObject,
IN ULONG  FailReason 
)

Definition at line 153 of file usbhub.c.

155{
159
160 DPRINT("USBH_WriteFailReason: ID - %x\n", FailReason);
161
165 &KeyHandle);
166
167 if (NT_SUCCESS(Status))
168 {
169 ZwSetValueKey(KeyHandle,
170 &ValueName,
171 0,
172 REG_DWORD,
173 &FailReason,
174 sizeof(FailReason));
175
177 }
178
179 return Status;
180}
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
#define PLUGPLAY_REGKEY_DEVICE
Definition: iofuncs.h:2786

Referenced by USBH_StartHubFdoDevice().

◆ USBHUB_FlushAllTransfers()

VOID NTAPI USBHUB_FlushAllTransfers ( IN PUSBHUB_FDO_EXTENSION  HubExtension)

Definition at line 2623 of file usbhub.c.

2624{
2625 PUSB_BUSIFFN_FLUSH_TRANSFERS FlushTransfers;
2626
2627 DPRINT("USBHUB_FlushAllTransfers ... \n");
2628
2629 FlushTransfers = HubExtension->BusInterface.FlushTransfers;
2630
2631 if (FlushTransfers)
2632 {
2633 FlushTransfers(HubExtension->BusInterface.BusContext, NULL);
2634 }
2635}
USB_BUSIFFN_FLUSH_TRANSFERS * PUSB_BUSIFFN_FLUSH_TRANSFERS
Definition: hubbusif.h:287

Referenced by USBH_PdoRemoveDevice().

◆ USBHUB_GetExtendedHubInfo()

NTSTATUS NTAPI USBHUB_GetExtendedHubInfo ( IN PUSBHUB_FDO_EXTENSION  HubExtension,
IN PUSB_EXTHUB_INFORMATION_0  HubInfoBuffer 
)

Definition at line 680 of file usbhub.c.

682{
683 PUSB_BUSIFFN_GET_EXTENDED_HUB_INFO GetExtendedHubInformation;
684 ULONG dummy = 0;
685
686 DPRINT("USBHUB_GetExtendedHubInfo: ... \n");
687
688 GetExtendedHubInformation = HubExtension->BusInterface.GetExtendedHubInformation;
689
690 return GetExtendedHubInformation(HubExtension->BusInterface.BusContext,
691 HubExtension->LowerPDO,
692 HubInfoBuffer,
694 &dummy);
695}
USB_BUSIFFN_GET_EXTENDED_HUB_INFO * PUSB_BUSIFFN_GET_EXTENDED_HUB_INFO
Definition: hubbusif.h:214

Referenced by USBH_SyncGetHubDescriptor().

◆ USBHUB_RootHubCallBack()

VOID NTAPI USBHUB_RootHubCallBack ( IN PVOID  Context)

Definition at line 2957 of file usbhub.c.

2958{
2959 PUSBHUB_FDO_EXTENSION HubExtension;
2960
2961 DPRINT("USBHUB_RootHubCallBack: ... \n");
2962
2963 HubExtension = Context;
2964
2965 if (HubExtension->SCEIrp)
2966 {
2967 HubExtension->HubFlags |= (USBHUB_FDO_FLAG_DO_ENUMERATION |
2969
2970 USBH_SubmitStatusChangeTransfer(HubExtension);
2971
2973 }
2974 else
2975 {
2977 }
2978
2979 KeSetEvent(&HubExtension->RootHubNotificationEvent,
2981 FALSE);
2982}
KEVENT RootHubNotificationEvent
Definition: usbhub.h:174

Referenced by USBD_RegisterRootHubCallBack().

◆ USBHUB_SetDeviceHandleData()

VOID NTAPI USBHUB_SetDeviceHandleData ( IN PUSBHUB_FDO_EXTENSION  HubExtension,
IN PDEVICE_OBJECT  UsbDevicePdo,
IN PVOID  DeviceHandle 
)

Definition at line 2601 of file usbhub.c.

2604{
2605 PUSB_BUSIFFN_SET_DEVHANDLE_DATA SetDeviceHandleData;
2606
2607 DPRINT("USBHUB_SetDeviceHandleData ... \n");
2608
2609 SetDeviceHandleData = HubExtension->BusInterface.SetDeviceHandleData;
2610
2611 if (!SetDeviceHandleData)
2612 {
2613 return;
2614 }
2615
2616 SetDeviceHandleData(HubExtension->BusInterface.BusContext,
2618 UsbDevicePdo);
2619}
_In_ PVOID _In_ PDEVICE_OBJECT UsbDevicePdo
Definition: hubbusif.h:322
USB_BUSIFFN_SET_DEVHANDLE_DATA * PUSB_BUSIFFN_SET_DEVHANDLE_DATA
Definition: hubbusif.h:323

Referenced by USBH_PdoStartDevice().

Variable Documentation

◆ GenericUSBDeviceString

PWSTR GenericUSBDeviceString = NULL

Definition at line 19 of file usbhub.c.

Referenced by DriverEntry(), USBH_DriverUnload(), and USBH_PdoQueryDeviceText().