ReactOS  0.4.15-dev-439-g292f67a
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 
5122 
5125 
5128 
5132 
5134 
5135  return STATUS_SUCCESS;
5136 }
NTSTATUS NTAPI USBH_HubDispatch(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: usbhub.c:5034
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
PDRIVER_EXTENSION DriverExtension
Definition: iotypes.h:2174
NTSTATUS NTAPI USBH_AddDevice(IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT LowerPDO)
Definition: usbhub.c:4947
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
void DPRINT(...)
Definition: polytest.cpp:61
NTSTATUS NTAPI USBH_RegQueryGenericUSBDeviceString(PVOID USBDeviceString)
Definition: usbhub.c:5090
#define IRP_MJ_INTERNAL_DEVICE_CONTROL
#define IRP_MJ_POWER
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
PDRIVER_UNLOAD DriverUnload
Definition: iotypes.h:2180
#define IRP_MJ_SYSTEM_CONTROL
VOID NTAPI USBH_DriverUnload(IN PDRIVER_OBJECT DriverObject)
Definition: usbhub.c:5021
PDRIVER_ADD_DEVICE AddDevice
Definition: iotypes.h:2112
PDRIVER_DISPATCH MajorFunction[IRP_MJ_MAXIMUM_FUNCTION+1]
Definition: iotypes.h:2181
_In_ PUNICODE_STRING RegistryPath
Definition: wmip.h:28
return STATUS_SUCCESS
Definition: btrfs.c:3014
PWSTR GenericUSBDeviceString
Definition: usbhub.c:19
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52

◆ 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
void DPRINT(...)
Definition: polytest.cpp:61

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  {
2524  return STATUS_NOT_IMPLEMENTED;
2525  }
2526 
2527  HubDeviceHandle = USBH_SyncGetDeviceHandle(HubExtension->LowerDevice);
2528 
2529  return CreateUsbDevice(HubExtension->BusInterface.BusContext,
2530  OutDeviceHandle,
2532  UsbPortStatus.AsUshort16,
2533  Port);
2534 }
CPPORT Port[4]
Definition: headless.c:34
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
PUSB_DEVICE_HANDLE NTAPI USBH_SyncGetDeviceHandle(IN PDEVICE_OBJECT DeviceObject)
Definition: usbhub.c:832
_Outptr_ PUSB_DEVICE_HANDLE _In_ PUSB_DEVICE_HANDLE HubDeviceHandle
Definition: hubbusif.h:40
void DPRINT(...)
Definition: polytest.cpp:61
USB_BUSIFFN_CREATE_USB_DEVICE * PUSB_BUSIFFN_CREATE_USB_DEVICE
Definition: hubbusif.h:44

Referenced by USBH_CreateDevice(), and USBH_ResetDevice().

◆ USBD_GetDeviceInformationEx()

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

Definition at line 2639 of file usbhub.c.

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

Referenced by USBH_IoctlGetNodeConnectionInformation().

◆ USBD_InitializeDeviceEx()

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

Definition at line 2562 of file usbhub.c.

2568 {
2569  NTSTATUS Status;
2570  PUSB_BUSIFFN_INITIALIZE_USB_DEVICE InitializeUsbDevice;
2571  PUSB_BUSIFFN_GET_USB_DESCRIPTORS GetUsbDescriptors;
2572 
2573  DPRINT("USBD_InitializeDeviceEx: ... \n");
2574 
2575  InitializeUsbDevice = HubExtension->BusInterface.InitializeUsbDevice;
2576  GetUsbDescriptors = HubExtension->BusInterface.GetUsbDescriptors;
2577 
2578  if (!InitializeUsbDevice || !GetUsbDescriptors)
2579  {
2580  return STATUS_NOT_IMPLEMENTED;
2581  }
2582 
2583  Status = InitializeUsbDevice(HubExtension->BusInterface.BusContext,
2584  DeviceHandle);
2585 
2586  if (!NT_SUCCESS(Status))
2587  {
2588  return Status;
2589  }
2590 
2591  return GetUsbDescriptors(HubExtension->BusInterface.BusContext,
2592  DeviceHandle,
2597 }
_Inout_ PUSB_DEVICE_HANDLE _Out_writes_bytes_to_ DeviceDescriptorBufferLength PUCHAR _Inout_ PULONG _Out_writes_bytes_to_ ConfigDescriptorBufferLength PUCHAR ConfigDescriptorBuffer
Definition: hubbusif.h:151
_Inout_ PUSB_DEVICE_HANDLE DeviceHandle
Definition: hubbusif.h:121
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
LONG NTSTATUS
Definition: precomp.h:26
USB_BUSIFFN_GET_USB_DESCRIPTORS * PUSB_BUSIFFN_GET_USB_DESCRIPTORS
Definition: hubbusif.h:154
_Inout_ PUSB_DEVICE_HANDLE _Out_writes_bytes_to_ DeviceDescriptorBufferLength PUCHAR DeviceDescriptorBuffer
Definition: hubbusif.h:148
void DPRINT(...)
Definition: polytest.cpp:61
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
_Inout_ PUSB_DEVICE_HANDLE _Out_writes_bytes_to_ DeviceDescriptorBufferLength PUCHAR _Inout_ PULONG DeviceDescriptorBufferLength
Definition: hubbusif.h:148
_Inout_ PUSB_DEVICE_HANDLE _Out_writes_bytes_to_ DeviceDescriptorBufferLength PUCHAR _Inout_ PULONG _Out_writes_bytes_to_ ConfigDescriptorBufferLength PUCHAR _Inout_ PULONG ConfigDescriptorBufferLength
Definition: hubbusif.h:151
USB_BUSIFFN_INITIALIZE_USB_DEVICE * PUSB_BUSIFFN_INITIALIZE_USB_DEVICE
Definition: hubbusif.h:122
Status
Definition: gdiplustypes.h:24

Referenced by USBH_CreateDevice(), and USBH_ResetDevice().

◆ USBD_RegisterRootHubCallBack()

NTSTATUS NTAPI USBD_RegisterRootHubCallBack ( IN PUSBHUB_FDO_EXTENSION  HubExtension)

Definition at line 2986 of file usbhub.c.

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

Referenced by USBH_StartHubFdoDevice().

◆ USBD_RemoveDeviceEx()

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

Definition at line 2538 of file usbhub.c.

2541 {
2542  PUSB_BUSIFFN_REMOVE_USB_DEVICE RemoveUsbDevice;
2543 
2544  DPRINT("USBD_RemoveDeviceEx: DeviceHandle - %p, Flags - %X\n",
2545  DeviceHandle,
2546  Flags);
2547 
2548  RemoveUsbDevice = HubExtension->BusInterface.RemoveUsbDevice;
2549 
2550  if (!RemoveUsbDevice)
2551  {
2552  return STATUS_NOT_IMPLEMENTED;
2553  }
2554 
2555  return RemoveUsbDevice(HubExtension->BusInterface.BusContext,
2556  DeviceHandle,
2557  Flags);
2558 }
_Inout_ PUSB_DEVICE_HANDLE DeviceHandle
Definition: hubbusif.h:121
USB_BUSIFFN_REMOVE_USB_DEVICE * PUSB_BUSIFFN_REMOVE_USB_DEVICE
Definition: hubbusif.h:140
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
void DPRINT(...)
Definition: polytest.cpp:61

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

◆ USBD_RestoreDeviceEx()

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

Definition at line 2761 of file usbhub.c.

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

Referenced by USBH_ResetDevice().

◆ USBD_UnRegisterRootHubCallBack()

NTSTATUS NTAPI USBD_UnRegisterRootHubCallBack ( IN PUSBHUB_FDO_EXTENSION  HubExtension)

Definition at line 3008 of file usbhub.c.

3009 {
3010  PUSB_BUSIFFN_ROOTHUB_INIT_NOTIFY RootHubInitNotification;
3011  NTSTATUS Status;
3012 
3013  DPRINT("USBD_UnRegisterRootHubCallBack ... \n");
3014 
3015  RootHubInitNotification = HubExtension->BusInterface.RootHubInitNotification;
3016 
3017  if (!RootHubInitNotification)
3018  {
3019  return STATUS_NOT_IMPLEMENTED;
3020  }
3021 
3022  Status = RootHubInitNotification(HubExtension->BusInterface.BusContext,
3023  NULL,
3024  NULL);
3025 
3026  if (!NT_SUCCESS(Status))
3027  {
3028  KeWaitForSingleObject(&HubExtension->RootHubNotificationEvent,
3029  Executive,
3030  KernelMode,
3031  FALSE,
3032  NULL);
3033  }
3034 
3035  return Status;
3036 }
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24
USB_BUSIFFN_ROOTHUB_INIT_NOTIFY * PUSB_BUSIFFN_ROOTHUB_INIT_NOTIFY
Definition: hubbusif.h:279

Referenced by USBH_FdoCleanup().

◆ USBH_AddDevice()

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

Definition at line 4947 of file usbhub.c.

4949 {
4951  NTSTATUS Status;
4952  PUSBHUB_FDO_EXTENSION HubExtension;
4953  PDEVICE_OBJECT LowerDevice;
4954 
4955  DPRINT("USBH_AddDevice: DriverObject - %p, LowerPDO - %p\n",
4956  DriverObject,
4957  LowerPDO);
4958 
4959  DeviceObject = NULL;
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 
4986  HubExtension->Common.ExtensionType = USBH_EXTENSION_TYPE_HUB;
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 
5013 
5014  DPRINT("USBH_AddDevice: call IoWMIRegistrationControl() UNIMPLEMENTED. FIXME\n");
5015 
5016  return Status;
5017 }
#define DO_DEVICE_INITIALIZING
Definition: env_spec_w32.h:399
#define DO_POWER_PAGABLE
LONG NTSTATUS
Definition: precomp.h:26
KSEMAPHORE IdleSemaphore
Definition: usbhub.h:177
PDEVICE_OBJECT NTAPI IoAttachDeviceToDeviceStack(IN PDEVICE_OBJECT SourceDevice, IN PDEVICE_OBJECT TargetDevice)
Definition: device.c:966
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
void DPRINT(...)
Definition: polytest.cpp:61
#define FILE_AUTOGENERATED_DEVICE_NAME
Definition: iotypes.h:138
VOID NTAPI KeInitializeSemaphore(IN PKSEMAPHORE Semaphore, IN LONG Count, IN LONG Limit)
Definition: semphobj.c:22
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
PDEVICE_OBJECT LowerDevice
Definition: usbhub.h:150
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define USBH_EXTENSION_TYPE_HUB
Definition: usbhub.h:28
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1569
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
PDEVICE_OBJECT LowerPDO
Definition: usbhub.h:149
COMMON_DEVICE_EXTENSION Common
Definition: usbhub.h:148
#define DPRINT1
Definition: precomp.h:8
NTSTATUS NTAPI IoCreateDevice(IN PDRIVER_OBJECT DriverObject, IN ULONG DeviceExtensionSize, IN PUNICODE_STRING DeviceName, IN DEVICE_TYPE DeviceType, IN ULONG DeviceCharacteristics, IN BOOLEAN Exclusive, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:1031
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261

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;
2799  PIO_WORKITEM WorkItem;
2800  PVOID WorkItemBuffer;
2801 
2802  DPRINT("USBH_AllocateWorkItem: ... \n");
2803 
2804  if (!(HubExtension->HubFlags & USBHUB_FDO_FLAG_WITEM_INIT))
2805  {
2806  return STATUS_INVALID_PARAMETER;
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 
2820  WorkItem = IoAllocateWorkItem(HubExtension->Common.SelfDevice);
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,
2833  BufferLength,
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 }
PUSBHUB_FDO_EXTENSION HubExtension
Definition: usbhub.h:137
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
WORK_QUEUE_TYPE HubWorkItemType
Definition: usbhub.h:136
Type
Definition: Type.h:6
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
_Must_inspect_result_ _In_ PFLT_CALLBACK_DATA _In_ PFLT_DEFERRED_IO_WORKITEM_ROUTINE WorkerRoutine
Definition: fltkernel.h:1977
PIO_WORKITEM NTAPI IoAllocateWorkItem(IN PDEVICE_OBJECT DeviceObject)
Definition: iowork.c:75
VOID NTAPI IoFreeWorkItem(IN PIO_WORKITEM IoWorkItem)
Definition: iowork.c:64
_In_ ULONG BufferLength
Definition: usbdlib.h:225
smooth NULL
Definition: ftsmooth.c:416
PVOID HubWorkItemBuffer
Definition: usbhub.h:139
void DPRINT(...)
Definition: polytest.cpp:61
#define USB_HUB_TAG
Definition: usbhub.h:26
PUSBHUB_WORKER_ROUTINE HubWorkerRoutine
Definition: usbhub.h:138
PIO_WORKITEM HubWorkItem
Definition: usbhub.h:135
#define USBHUB_FDO_FLAG_WITEM_INIT
Definition: usbhub.h:59
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
COMMON_DEVICE_EXTENSION Common
Definition: usbhub.h:148
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
return STATUS_SUCCESS
Definition: btrfs.c:3014

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;
2330  NTSTATUS Status;
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,
2379  BufferLength,
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 }
CPPORT Port[4]
Definition: headless.c:34
#define STATUS_DELETE_PENDING
Definition: ntstatus.h:308
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
struct _URB_CONTROL_VENDOR_OR_CLASS_REQUEST SCEWorkerUrb
Definition: usbhub.h:175
#define STATUS_MORE_PROCESSING_REQUIRED
Definition: shellext.h:68
PUSBHUB_FDO_EXTENSION HubExtension
Definition: usbhub.h:249
struct _USBHUB_STATUS_CHANGE_CONTEXT USBHUB_STATUS_CHANGE_CONTEXT
_In_ PIRP Irp
Definition: csq.h:116
BOOLEAN NTAPI IsBitSet(IN PUCHAR BitMapAddress, IN USHORT Bit)
Definition: usbhub.c:121
LONG NTSTATUS
Definition: precomp.h:26
PUSBHUB_IO_WORK_ITEM WorkItemToQueue
Definition: usbhub.h:197
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
#define DPRINT_SCE(...)
Definition: dbg_uhub.h:110
#define USBHUB_FDO_FLAG_DEVICE_FAILED
Definition: usbhub.h:35
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
_In_ ULONG BufferLength
Definition: usbdlib.h:225
#define USBHUB_MAX_REQUEST_ERRORS
Definition: usbhub.h:108
unsigned char BOOLEAN
KEVENT StatusChangeEvent
Definition: usbhub.h:176
UCHAR bNumberOfPorts
Definition: usb100.h:173
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define NT_ERROR(Status)
Definition: umtypes.h:106
#define USBHUB_FDO_FLAG_DEVICE_STOPPING
Definition: usbhub.h:34
LONG USBD_STATUS
Definition: usb.h:165
NTSTATUS NTAPI USBH_AllocateWorkItem(PUSBHUB_FDO_EXTENSION HubExtension, PUSBHUB_IO_WORK_ITEM *OutHubIoWorkItem, PUSBHUB_WORKER_ROUTINE WorkerRoutine, SIZE_T BufferLength, PVOID *OutHubWorkItemBuffer, WORK_QUEUE_TYPE Type)
Definition: usbhub.c:2791
Status
Definition: gdiplustypes.h:24
#define USBD_ERROR(Status)
Definition: usb.h:169
PUSB_HUB_DESCRIPTOR HubDescriptor
Definition: usbhub.h:166
#define EVENT_INCREMENT
Definition: iotypes.h:565
#define InterlockedIncrement
Definition: armddk.h:53
unsigned short USHORT
Definition: pedump.c:61
struct tagContext Context
Definition: acpixf.h:1034
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
VOID NTAPI KeClearEvent(IN PKEVENT Event)
Definition: eventobj.c:22
VOID NTAPI USBH_ChangeIndicationWorker(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PVOID Context)
Definition: usbhub.c:2146

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;
1664  BM_REQUEST_TYPE RequestType;
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;
1680  RequestType.Type = BMREQUEST_CLASS;
1681  RequestType.Dir = BMREQUEST_HOST_TO_DEVICE;
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;
1696  IoStack->Parameters.DeviceIoControl.IoControlCode = IOCTL_INTERNAL_USB_SUBMIT_URB;
1697 
1700  HubExtension,
1701  TRUE,
1702  TRUE,
1703  TRUE);
1704 
1705  return IoCallDriver(HubExtension->LowerDevice, Irp);
1706 }
CPPORT Port[4]
Definition: headless.c:34
#define TRUE
Definition: types.h:120
#define IOCTL_INTERNAL_USB_SUBMIT_URB
Definition: usbioctl.h:32
NTSTATUS NTAPI USBH_ChangeIndicationAckChangeComplete(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context)
Definition: usbhub.c:1618
_In_ PIRP Irp
Definition: csq.h:116
#define BMREQUEST_HOST_TO_DEVICE
Definition: usb100.h:31
VOID NTAPI IoInitializeIrp(IN PIRP Irp, IN USHORT PacketSize, IN CCHAR StackSize)
Definition: irp.c:1854
#define DPRINT_SCE(...)
Definition: dbg_uhub.h:110
#define IoSetCompletionRoutine(_Irp, _CompletionRoutine, _Context, _InvokeOnSuccess, _InvokeOnError, _InvokeOnCancel)
Definition: irp.cpp:498
smooth NULL
Definition: ftsmooth.c:416
#define BMREQUEST_TO_OTHER
Definition: usb100.h:41
#define USB_REQUEST_CLEAR_FEATURE
Definition: usb100.h:79
#define IRP_MJ_INTERNAL_DEVICE_CONTROL
#define BMREQUEST_CLASS
Definition: usb100.h:35
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2647
#define USBD_SHORT_TRANSFER_OK
Definition: usb.h:154
#define IoSizeOfIrp(_StackSize)
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
#define URB_FUNCTION_CLASS_OTHER
Definition: usb.h:117

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 }
CPPORT Port[4]
Definition: headless.c:34
#define STATUS_MORE_PROCESSING_REQUIRED
Definition: shellext.h:68
USB_PORT_STATUS_AND_CHANGE PortStatus
Definition: usbhub.h:118
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
#define DPRINT_SCE(...)
Definition: dbg_uhub.h:110
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:435
smooth NULL
Definition: ftsmooth.c:416
#define InterlockedExchangePointer(Target, Value)
Definition: dshow.h:45
USB_PORT_STATUS_AND_CHANGE PortStatus
Definition: usbhub.h:199
PRKEVENT pResetPortEvent
Definition: usbhub.h:183
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define InterlockedDecrement
Definition: armddk.h:52
#define EVENT_INCREMENT
Definition: iotypes.h:565
unsigned short USHORT
Definition: pedump.c:61
struct tagContext Context
Definition: acpixf.h:1034
NTSTATUS NTAPI USBH_SubmitStatusChangeTransfer(IN PUSBHUB_FDO_EXTENSION HubExtension)
Definition: usbhub.c:2442
PUSBHUB_PORT_DATA PortData
Definition: usbhub.h:167

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;
1715  PUSBHUB_IO_WORK_ITEM WorkItem;
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 }
#define USBHUB_FEATURE_C_PORT_ENABLE
Definition: usbhub.h:99
struct _URB_CONTROL_VENDOR_OR_CLASS_REQUEST SCEWorkerUrb
Definition: usbhub.h:175
#define STATUS_MORE_PROCESSING_REQUIRED
Definition: shellext.h:68
_In_ PIRP Irp
Definition: csq.h:116
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
VOID NTAPI USBH_QueueWorkItem(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PUSBHUB_IO_WORK_ITEM HubIoWorkItem)
Definition: usbhub.c:2917
PUSBHUB_IO_WORK_ITEM WorkItemToQueue
Definition: usbhub.h:197
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
#define DPRINT_SCE(...)
Definition: dbg_uhub.h:110
smooth NULL
Definition: ftsmooth.c:416
LONG PendingRequestCount
Definition: usbhub.h:180
USHORT PortEnableDisableChange
Definition: usb200.h:164
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
USB_PORT_STATUS_AND_CHANGE PortStatus
Definition: usbhub.h:199
USB_PORT_CHANGE PortChange
Definition: usb200.h:241
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
KEVENT PendingRequestEvent
Definition: usbhub.h:181
#define InterlockedDecrement
Definition: armddk.h:52
USB_20_PORT_CHANGE Usb20PortChange
Definition: usb200.h:231
#define EVENT_INCREMENT
Definition: iotypes.h:565
#define USBHUB_FEATURE_C_PORT_RESET
Definition: usbhub.h:102
unsigned short USHORT
Definition: pedump.c:61
VOID NTAPI USBH_FreeWorkItem(IN PUSBHUB_IO_WORK_ITEM HubIoWorkItem)
Definition: usbhub.c:2937
struct tagContext Context
Definition: acpixf.h:1034
#define USBD_SUCCESS(Status)
Definition: usb.h:167
USHORT ResetChange
Definition: usb200.h:167

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 {
1774  PUSBHUB_IO_WORK_ITEM WorkItem;
1775  NTSTATUS Status;
1776  PIO_STACK_LOCATION IoStack;
1777  BM_REQUEST_TYPE RequestType;
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 
1799  Urb->TransferFlags = USBD_SHORT_TRANSFER_OK | USBD_TRANSFER_DIRECTION_IN;
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;
1807  RequestType.Type = BMREQUEST_CLASS;
1808  RequestType.Dir = BMREQUEST_DEVICE_TO_HOST;
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;
1825  IoStack->Parameters.DeviceIoControl.IoControlCode = IOCTL_INTERNAL_USB_SUBMIT_URB;
1826 
1829  HubExtension,
1830  TRUE,
1831  TRUE,
1832  TRUE);
1833 
1834  Status = IoCallDriver(HubExtension->LowerDevice, Irp);
1835 
1836  return Status;
1837 }
CPPORT Port[4]
Definition: headless.c:34
#define TRUE
Definition: types.h:120
NTSTATUS NTAPI USBH_ChangeIndicationProcessChange(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context)
Definition: usbhub.c:1710
#define IOCTL_INTERNAL_USB_SUBMIT_URB
Definition: usbioctl.h:32
_In_ PIRP Irp
Definition: csq.h:116
VOID NTAPI USBH_QueueWorkItem(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PUSBHUB_IO_WORK_ITEM HubIoWorkItem)
Definition: usbhub.c:2917
LONG NTSTATUS
Definition: precomp.h:26
#define USBD_TRANSFER_DIRECTION_IN
Definition: usb.h:160
VOID NTAPI IoInitializeIrp(IN PIRP Irp, IN USHORT PacketSize, IN CCHAR StackSize)
Definition: irp.c:1854
#define DPRINT_SCE(...)
Definition: dbg_uhub.h:110
#define IoSetCompletionRoutine(_Irp, _CompletionRoutine, _Context, _InvokeOnSuccess, _InvokeOnError, _InvokeOnCancel)
Definition: irp.cpp:498
#define BMREQUEST_DEVICE_TO_HOST
Definition: usb100.h:32
smooth NULL
Definition: ftsmooth.c:416
#define BMREQUEST_TO_OTHER
Definition: usb100.h:41
#define IRP_MJ_INTERNAL_DEVICE_CONTROL
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define BMREQUEST_CLASS
Definition: usb100.h:35
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2647
Status
Definition: gdiplustypes.h:24
#define USBD_SHORT_TRANSFER_OK
Definition: usb.h:154
#define USB_REQUEST_GET_STATUS
Definition: usb100.h:78
#define InterlockedIncrement
Definition: armddk.h:53
#define IoSizeOfIrp(_StackSize)
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
return STATUS_SUCCESS
Definition: btrfs.c:3014
#define URB_FUNCTION_CLASS_OTHER
Definition: usb.h:117

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;
2154  NTSTATUS Status;
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,
2206  sizeof(USB_PORT_STATUS_AND_CHANGE));
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 
2230 Enum:
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 
2290 Exit:
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 }
CPPORT Port[4]
Definition: headless.c:34
#define USBHUB_FDO_FLAG_DEFER_CHECK_IDLE
Definition: usbhub.h:48
#define USBHUB_PDO_FLAG_POWER_D1_OR_D2
Definition: usbhub.h:74
BOOLEAN NTAPI IsBitSet(IN PUCHAR BitMapAddress, IN USHORT Bit)
Definition: usbhub.c:121
unsigned char * PUCHAR
Definition: retypes.h:3
PUSBHUB_FDO_EXTENSION HubExtension
Definition: usbhub.h:209
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI USBH_ResetHub(IN PUSBHUB_FDO_EXTENSION HubExtension)
Definition: usbhub.c:2117
#define LOW_REALTIME_PRIORITY
void DbgBreakPoint()
Definition: mach.c:553
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
#define DPRINT_SCE(...)
Definition: dbg_uhub.h:110
#define USBHUB_FDO_FLAG_DEVICE_FAILED
Definition: usbhub.h:35
#define USBHUB_MAX_REQUEST_ERRORS
Definition: usbhub.h:108
smooth NULL
Definition: ftsmooth.c:416
NTSTATUS NTAPI USBH_SyncGetHubStatus(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PUSB_HUB_STATUS_AND_CHANGE HubStatus, IN ULONG Length)
Definition: usbhub.c:1363
#define USBHUB_FDO_FLAG_DEVICE_REMOVED
Definition: usbhub.h:46
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define USBHUB_FDO_FLAG_ESD_RECOVERING
Definition: usbhub.h:41
static void Exit(void)
Definition: sock.c:1331
#define USBHUB_FDO_FLAG_DEVICE_STOPPING
Definition: usbhub.h:34
#define InterlockedDecrement
Definition: armddk.h:52
MIXER_STATUS Enum(IN PVOID EnumContext, IN ULONG DeviceIndex, OUT LPWSTR *DeviceName, OUT PHANDLE OutHandle, OUT PHANDLE OutKey)
Definition: mmixer.c:225
_Outptr_ PUSB_DEVICE_HANDLE _In_ PUSB_DEVICE_HANDLE _In_ USHORT PortStatus
Definition: hubbusif.h:40
VOID NTAPI USBH_CheckHubIdle(IN PUSBHUB_FDO_EXTENSION HubExtension)
Definition: usbhub.c:3808
Status
Definition: gdiplustypes.h:24
#define EVENT_INCREMENT
Definition: iotypes.h:565
LONG NTAPI KeReleaseSemaphore(IN PKSEMAPHORE Semaphore, IN KPRIORITY Increment, IN LONG Adjustment, IN BOOLEAN Wait)
Definition: semphobj.c:54
unsigned short USHORT
Definition: pedump.c:61
#define DPRINT1
Definition: precomp.h:8
struct tagContext Context
Definition: acpixf.h:1034
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_SubmitStatusChangeTransfer(IN PUSBHUB_FDO_EXTENSION HubExtension)
Definition: usbhub.c:2442
VOID NTAPI USBH_ProcessHubStateChange(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PUSB_HUB_STATUS_AND_CHANGE HubStatus)
Definition: usbhub.c:1841
signed int * PLONG
Definition: retypes.h:5
VOID NTAPI USBH_ProcessPortStateChange(IN PUSBHUB_FDO_EXTENSION HubExtension, IN USHORT Port, IN PUSB_PORT_STATUS_AND_CHANGE PortStatus)
Definition: usbhub.c:1870

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,
4202  SerialNumber,
4203  SN_DescriptorLength);
4204 
4205  if (NumberBytes == SN_DescriptorLength)
4206  {
4207  return FALSE;
4208  }
4209  }
4210  }
4211  }
4212  }
4213 
4214  return TRUE;
4215 }
CPPORT Port[4]
Definition: headless.c:34
#define TRUE
Definition: types.h:120
PVOID DeviceExtension
Definition: env_spec_w32.h:418
void DPRINT(...)
Definition: polytest.cpp:61
USB_DEVICE_DESCRIPTOR DeviceDescriptor
Definition: usbhub.h:216
ULONG SerialNumber
Definition: rxce.c:117
ULONG_PTR SIZE_T
Definition: typedefs.h:79
unsigned int ULONG
Definition: retypes.h:1
#define RtlCompareMemory(s1, s2, l)
Definition: env_spec_w32.h:465

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 {
4246  NTSTATUS Status;
4247  ULONG NumSymbols;
4248  ULONG ix;
4249  PWCHAR pSymbol;
4250  ULONG Length;
4251 
4252  DPRINT("USBH_CheckDeviceLanguage: LanguageId - 0x%04X\n", LanguageId);
4253 
4256  USB_HUB_TAG);
4257 
4258  if (!Descriptor)
4259  {
4261  }
4262 
4264 
4266  0,
4267  0,
4268  Descriptor,
4270  &Length,
4271  TRUE);
4272 
4273  if (!NT_SUCCESS(Status) ||
4274  Length < sizeof(USB_COMMON_DESCRIPTOR))
4275  {
4276  goto Exit;
4277  }
4278 
4279  NumSymbols = (Length -
4280  FIELD_OFFSET(USB_STRING_DESCRIPTOR, bString)) / sizeof(WCHAR);
4281 
4282  pSymbol = Descriptor->bString;
4283 
4284  for (ix = 1; ix < NumSymbols; ix++)
4285  {
4286  if (*pSymbol == (WCHAR)LanguageId)
4287  {
4289  goto Exit;
4290  }
4291 
4292  pSymbol++;
4293  }
4294 
4296 
4297 Exit:
4299  return Status;
4300 }
#define TRUE
Definition: types.h:120
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
LONG NTSTATUS
Definition: precomp.h:26
uint16_t * PWCHAR
Definition: typedefs.h:55
void DPRINT(...)
Definition: polytest.cpp:61
#define USB_HUB_TAG
Definition: usbhub.h:26
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static void Exit(void)
Definition: sock.c:1331
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define MAXIMUM_USB_STRING_LENGTH
Definition: usb100.h:43
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
NTSTATUS NTAPI USBH_SyncGetStringDescriptor(IN PDEVICE_OBJECT DeviceObject, IN UCHAR Index, IN USHORT LanguageId, IN PUSB_STRING_DESCRIPTOR Descriptor, IN ULONG NumberOfBytes, IN PULONG OutLength, IN BOOLEAN IsValidateLength)
Definition: usbhub.c:1248
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1569
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:409
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
return STATUS_SUCCESS
Definition: btrfs.c:3014
_In_ PSTORAGE_PROPERTY_ID _Outptr_ PSTORAGE_DESCRIPTOR_HEADER * Descriptor
Definition: classpnp.h:966

Referenced by USBH_GetSerialNumberString(), and USBH_PdoQueryDeviceText().

◆ USBH_CheckHubIdle()

VOID NTAPI USBH_CheckHubIdle ( IN PUSBHUB_FDO_EXTENSION  HubExtension)

Definition at line 3808 of file usbhub.c.

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

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

◆ USBH_CheckIdleAbort()

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

Definition at line 3221 of file usbhub.c.

3224 {
3225  PDEVICE_OBJECT PdoDevice;
3226  PUSBHUB_PORT_PDO_EXTENSION PortExtension;
3227  PUSBHUB_PORT_DATA PortData;
3228  ULONG Port;
3229  BOOLEAN Result = FALSE;
3230 
3231  DPRINT("USBH_CheckIdleAbort: ... \n");
3232 
3233  InterlockedIncrement(&HubExtension->PendingRequestCount);
3234 
3235  if (IsWait == TRUE)
3236  {
3237  KeWaitForSingleObject(&HubExtension->ResetDeviceSemaphore,
3238  Executive,
3239  KernelMode,
3240  FALSE,
3241  NULL);
3242  }
3243 
3244  PortData = HubExtension->PortData;
3245 
3246  for (Port = 0; Port < HubExtension->HubDescriptor->bNumberOfPorts; Port++)
3247  {
3248  PdoDevice = PortData[Port].DeviceObject;
3249 
3250  if (PdoDevice)
3251  {
3252  PortExtension = PdoDevice->DeviceExtension;
3253 
3254  if (PortExtension->PoRequestCounter)
3255  {
3256  Result = TRUE;
3257  goto Wait;
3258  }
3259  }
3260  }
3261 
3262  if (IsExtCheck == TRUE)
3263  {
3264  PortData = HubExtension->PortData;
3265 
3266  for (Port = 0;
3267  Port < HubExtension->HubDescriptor->bNumberOfPorts;
3268  Port++)
3269  {
3270  PdoDevice = PortData[Port].DeviceObject;
3271 
3272  if (PdoDevice)
3273  {
3274  PortExtension = PdoDevice->DeviceExtension;
3275  InterlockedExchange(&PortExtension->StateBehindD2, 0);
3276  }
3277  }
3278  }
3279 
3280 Wait:
3281 
3282  if (IsWait == TRUE)
3283  {
3284  KeReleaseSemaphore(&HubExtension->ResetDeviceSemaphore,
3286  1,
3287  FALSE);
3288  }
3289 
3290  if (!InterlockedDecrement(&HubExtension->PendingRequestCount))
3291  {
3292  KeSetEvent(&HubExtension->PendingRequestEvent,
3294  FALSE);
3295  }
3296 
3297  return Result;
3298 }
CPPORT Port[4]
Definition: headless.c:34
#define TRUE
Definition: types.h:120
#define LOW_REALTIME_PRIORITY
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
PDEVICE_OBJECT DeviceObject
Definition: usbhub.h:119
PVOID DeviceExtension
Definition: env_spec_w32.h:418
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
void DPRINT(...)
Definition: polytest.cpp:61
#define InterlockedDecrement
Definition: armddk.h:52
#define InterlockedExchange
Definition: armddk.h:54
#define EVENT_INCREMENT
Definition: iotypes.h:565
#define InterlockedIncrement
Definition: armddk.h:53
LONG NTAPI KeReleaseSemaphore(IN PKSEMAPHORE Semaphore, IN KPRIORITY Increment, IN LONG Adjustment, IN BOOLEAN Wait)
Definition: semphobj.c:54
unsigned int ULONG
Definition: retypes.h:1
IN BOOLEAN Wait
Definition: fatprocs.h:1538

Referenced by USBH_FdoIdleNotificationCallback(), and USBH_FdoPower().

◆ USBH_CheckIdleDeferred()

VOID NTAPI USBH_CheckIdleDeferred ( IN PUSBHUB_FDO_EXTENSION  HubExtension)

Definition at line 3957 of file usbhub.c.

3958 {
3959  PUSBHUB_IO_WORK_ITEM HubIoWorkItem;
3960  NTSTATUS Status;
3961 
3962  DPRINT("USBH_CheckIdleDeferred: HubExtension - %p\n", HubExtension);
3963 
3964  Status = USBH_AllocateWorkItem(HubExtension,
3965  &HubIoWorkItem,
3967  0,
3968  NULL,
3970 
3971  DPRINT("USBH_CheckIdleDeferred: HubIoWorkItem - %p\n", HubIoWorkItem);
3972 
3973  if (NT_SUCCESS(Status))
3974  {
3975  USBH_QueueWorkItem(HubExtension, HubIoWorkItem);
3976  }
3977 }
VOID NTAPI USBH_QueueWorkItem(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PUSBHUB_IO_WORK_ITEM HubIoWorkItem)
Definition: usbhub.c:2917
LONG NTSTATUS
Definition: precomp.h:26
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
VOID NTAPI USBH_CheckIdleWorker(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PVOID Context)
Definition: usbhub.c:3948
NTSTATUS NTAPI USBH_AllocateWorkItem(PUSBHUB_FDO_EXTENSION HubExtension, PUSBHUB_IO_WORK_ITEM *OutHubIoWorkItem, PUSBHUB_WORKER_ROUTINE WorkerRoutine, SIZE_T BufferLength, PVOID *OutHubWorkItemBuffer, WORK_QUEUE_TYPE Type)
Definition: usbhub.c:2791
Status
Definition: gdiplustypes.h:24

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

◆ USBH_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 }
void DPRINT(...)
Definition: polytest.cpp:61
VOID NTAPI USBH_CheckHubIdle(IN PUSBHUB_FDO_EXTENSION HubExtension)
Definition: usbhub.c:3808

Referenced by USBH_CheckIdleDeferred().

◆ USBH_CompleteIrp()

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

Definition at line 63 of file usbhub.c.

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

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

◆ USBH_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;
3581  NTSTATUS Status;
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 }
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
LONG NTSTATUS
Definition: precomp.h:26
unsigned char BOOLEAN
void DPRINT(...)
Definition: polytest.cpp:61
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24
VOID NTAPI USBH_HubCompleteQueuedPortIdleIrps(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PLIST_ENTRY IdleList, IN NTSTATUS NtStatus)
Definition: usbhub.c:3110
VOID NTAPI USBH_FlushPortPwrList(IN PUSBHUB_FDO_EXTENSION HubExtension)
Definition: usbhub.c:3125
#define DPRINT1
Definition: precomp.h:8
struct tagContext Context
Definition: acpixf.h:1034

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

Referenced by USBH_FdoQueryBusRelations().

◆ USBH_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 }
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
PWSTR GenericUSBDeviceString
Definition: usbhub.c:19
#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;
2035  NTSTATUS Status;
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 TRUE
Definition: types.h:120
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ PIRP Irp
Definition: csq.h:116
#define IOCTL_INTERNAL_USB_ENABLE_PORT
Definition: usbioctl.h:47
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:435
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
#define STATUS_PENDING
Definition: ntstatus.h:82
Status
Definition: gdiplustypes.h:24
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
PIRP NTAPI IoBuildDeviceIoControlRequest(IN ULONG IoControlCode, IN PDEVICE_OBJECT DeviceObject, IN PVOID InputBuffer, IN ULONG InputBufferLength, IN PVOID OutputBuffer, IN ULONG OutputBufferLength, IN BOOLEAN InternalDeviceIoControl, IN PKEVENT Event, IN PIO_STATUS_BLOCK IoStatusBlock)
Definition: irp.c:881

Referenced by 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;
4900  UCHAR MajorFunction;
4901  NTSTATUS Status;
4902 
4903  IoStack = IoGetCurrentIrpStackLocation(Irp);
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 
4920  case IRP_MJ_DEVICE_CONTROL:
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 
4932  case IRP_MJ_SYSTEM_CONTROL:
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 }
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
_In_ PIRP Irp
Definition: csq.h:116
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI USBH_FdoPnP(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PIRP Irp, IN UCHAR Minor)
Definition: pnp.c:2355
void DPRINT(...)
Definition: polytest.cpp:61
#define IRP_MJ_INTERNAL_DEVICE_CONTROL
NTSTATUS NTAPI USBH_PassIrp(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: usbhub.c:79
unsigned char UCHAR
Definition: xmlstorage.h:181
#define IRP_MJ_POWER
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
VOID NTAPI USBH_CompleteIrp(IN PIRP Irp, IN NTSTATUS CompleteStatus)
Definition: usbhub.c:63
#define IRP_MJ_SYSTEM_CONTROL
Status
Definition: gdiplustypes.h:24
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
NTSTATUS NTAPI USBH_DeviceControl(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PIRP Irp)
Definition: ioctl.c:1136
#define DPRINT1
Definition: precomp.h:8
return STATUS_SUCCESS
Definition: btrfs.c:3014
NTSTATUS NTAPI USBH_FdoPower(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PIRP Irp, IN UCHAR Minor)
Definition: power.c:460
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52

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;
3380  NTSTATUS Status;
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 
3415  InterlockedIncrement(&HubExtension->PendingRequestCount);
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 
3493 IdleHub:
3494 
3497  1,
3498  FALSE);
3499 
3500  if (!InterlockedDecrement(&HubExtension->PendingRequestCount))
3501  {
3502  KeSetEvent(&HubExtension->PendingRequestEvent,
3504  FALSE);
3505  }
3506 
3507  if (!IsReady ||
3508  (HubExtension->HubFlags & USBHUB_FDO_FLAG_DEVICE_SUSPENDED))
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",
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 }
CPPORT Port[4]
Definition: headless.c:34
#define TRUE
Definition: types.h:120
NTSTATUS NTAPI USBH_FdoSubmitWaitWakeIrp(IN PUSBHUB_FDO_EXTENSION HubExtension)
Definition: usbhub.c:3313
_In_ UCHAR _In_ POWER_STATE PowerState
Definition: pofuncs.h:42
DEVICE_POWER_STATE DeviceWake
Definition: usbhub.h:159
_In_ PIRP Irp
Definition: csq.h:116
#define USBHUB_FDO_FLAG_DO_SUSPENSE
Definition: usbhub.h:56
LONG NTSTATUS
Definition: precomp.h:26
VOID NTAPI IoAcquireCancelSpinLock(OUT PKIRQL Irql)
Definition: util.c:56
#define USBHUB_FDO_FLAG_PENDING_WAKE_IRP
Definition: usbhub.h:39
#define USBHUB_FDO_FLAG_ENUM_POST_RECOVER
Definition: usbhub.h:51
#define InterlockedCompareExchange
Definition: interlocked.h:104
#define USBHUB_FDO_FLAG_GOING_IDLE
Definition: usbhub.h:57
#define LOW_REALTIME_PRIORITY
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
void DbgBreakPoint()
Definition: mach.c:553
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
PDEVICE_OBJECT DeviceObject
Definition: usbhub.h:119
UCHAR KIRQL
Definition: env_spec_w32.h:591
POWER_STATE CurrentPowerState
Definition: usbhub.h:222
#define USBHUB_FDO_FLAG_STATE_CHANGING
Definition: usbhub.h:45
#define USBHUB_FDO_FLAG_DEVICE_FAILED
Definition: usbhub.h:35
KSEMAPHORE IdleSemaphore
Definition: usbhub.h:177
VOID NTAPI USBH_HubCompletePortIdleIrps(IN PUSBHUB_FDO_EXTENSION HubExtension, IN NTSTATUS NtStatus)
Definition: usbhub.c:3185
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:435
PVOID DeviceExtension
Definition: env_spec_w32.h:418
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
VOID NTAPI USBH_HubCancelIdleIrp(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PIRP IdleIrp)
Definition: usbhub.c:3206
#define USBHUB_FDO_FLAG_DEVICE_SUSPENDED
Definition: usbhub.h:58
void DPRINT(...)
Definition: polytest.cpp:61
LONG PendingRequestCount
Definition: usbhub.h:180
#define USBHUB_FDO_FLAG_WAKEUP_START
Definition: usbhub.h:49
UCHAR bNumberOfPorts
Definition: usb100.h:173
#define USBHUB_FDO_FLAG_DEVICE_REMOVED
Definition: usbhub.h:46
#define STATUS_PENDING
Definition: ntstatus.h:82
#define USBHUB_FDO_FLAG_ESD_RECOVERING
Definition: usbhub.h:41
#define STATUS_CANCELLED
Definition: udferr_usr.h:170
DEVICE_POWER_STATE DeviceState
Definition: ntpoapi.h:58
KEVENT PendingRequestEvent
Definition: usbhub.h:181
#define USBHUB_FDO_FLAG_DEVICE_STOPPING
Definition: usbhub.h:34
#define InterlockedDecrement
Definition: armddk.h:52
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:790
#define IRP_MN_SET_POWER
VOID NTAPI IoReleaseCancelSpinLock(IN KIRQL Irql)
Definition: util.c:150
Status
Definition: gdiplustypes.h:24
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
PUSB_HUB_DESCRIPTOR HubDescriptor
Definition: usbhub.h:166
#define EVENT_INCREMENT
Definition: iotypes.h:565
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define InterlockedIncrement
Definition: armddk.h:53
PDEVICE_OBJECT LowerPDO
Definition: usbhub.h:149
LONG NTAPI KeReleaseSemaphore(IN PKSEMAPHORE Semaphore, IN KPRIORITY Increment, IN LONG Adjustment, IN BOOLEAN Wait)
Definition: semphobj.c:54
BOOLEAN NTAPI USBH_CheckIdleAbort(IN PUSBHUB_FDO_EXTENSION HubExtension, IN BOOLEAN IsWait, IN BOOLEAN IsExtCheck)
Definition: usbhub.c:3221
KSEMAPHORE ResetDeviceSemaphore
Definition: usbhub.h:182
#define DPRINT1
Definition: precomp.h:8
struct tagContext Context
Definition: acpixf.h:1034
unsigned int ULONG
Definition: retypes.h:1
NTSTATUS NTAPI PoRequestPowerIrp(IN PDEVICE_OBJECT DeviceObject, IN UCHAR MinorFunction, IN POWER_STATE PowerState, IN PREQUEST_POWER_COMPLETE CompletionFunction, IN PVOID Context, OUT PIRP *pIrp OPTIONAL)
Definition: power.c:639
PUSBHUB_PORT_DATA PortData
Definition: usbhub.h:167
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772

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;
3637  NTSTATUS Status;
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,
3677  sizeof(USBHUB_IDLE_PORT_CONTEXT),
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,
3698  sizeof(USBHUB_IDLE_HUB_CONTEXT),
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 USBH_HubQueuePortIdleIrps(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PLIST_ENTRY IdleList)
Definition: usbhub.c:3052
#define STATUS_MORE_PROCESSING_REQUIRED
Definition: shellext.h:68
_In_ PIRP Irp
Definition: csq.h:116
VOID NTAPI USBH_QueueWorkItem(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PUSBHUB_IO_WORK_ITEM HubIoWorkItem)
Definition: usbhub.c:2917
LONG NTSTATUS
Definition: precomp.h:26
VOID NTAPI IoAcquireCancelSpinLock(OUT PKIRQL Irql)
Definition: util.c:56
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
_Out_ PKIRQL Irql
Definition: csq.h:179
UCHAR KIRQL
Definition: env_spec_w32.h:591
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
LONG PendingRequestCount
Definition: usbhub.h:180
#define InterlockedExchangePointer(Target, Value)
Definition: dshow.h:45
#define USBHUB_FDO_FLAG_DEVICE_REMOVED
Definition: usbhub.h:46
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
DEVICE_POWER_STATE DeviceState
Definition: ntpoapi.h:58
KEVENT PendingRequestEvent
Definition: usbhub.h:181
#define InterlockedDecrement
Definition: armddk.h:52
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
#define InterlockedExchange
Definition: armddk.h:54
VOID NTAPI IoReleaseCancelSpinLock(IN KIRQL Irql)
Definition: util.c:150
Status
Definition: gdiplustypes.h:24
POWER_STATE CurrentPowerState
Definition: usbhub.h:160
#define EVENT_INCREMENT
Definition: iotypes.h:565
#define STATUS_POWER_STATE_INVALID
Definition: ntstatus.h:817
#define USBHUB_FDO_FLAG_DEVICE_STOPPED
Definition: usbhub.h:37
VOID NTAPI IoFreeIrp(IN PIRP Irp)
Definition: irp.c:1666
VOID NTAPI USBH_CompletePortIdleIrpsWorker(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PVOID Context)
Definition: usbhub.c:3576
struct tagContext Context
Definition: acpixf.h:1034
VOID NTAPI USBH_IdleCompletePowerHubWorker(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PVOID Context)
Definition: usbhub.c:3607
#define USBHUB_FDO_FLAG_WAIT_IDLE_REQUEST
Definition: usbhub.h:44
signed int * PLONG
Definition: retypes.h:5

Referenced by USBH_FdoSubmitIdleRequestIrp().

◆ USBH_FdoSubmitIdleRequestIrp()

NTSTATUS NTAPI USBH_FdoSubmitIdleRequestIrp ( IN PUSBHUB_FDO_EXTENSION  HubExtension)

Definition at line 3722 of file usbhub.c.

3723 {
3724  NTSTATUS Status;
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 ||
3745  HubFlags & USBHUB_FDO_FLAG_DEVICE_REMOVED)
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: ntstatus.h:795
#define TRUE
Definition: types.h:120
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
VOID NTAPI IoAcquireCancelSpinLock(OUT PKIRQL Irql)
Definition: util.c:56
#define USBHUB_FDO_FLAG_GOING_IDLE
Definition: usbhub.h:57
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
_Out_ PKIRQL Irql
Definition: csq.h:179
#define IoSetCompletionRoutine(_Irp, _CompletionRoutine, _Context, _InvokeOnSuccess, _InvokeOnError, _InvokeOnCancel)
Definition: irp.cpp:498
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define USBHUB_FDO_FLAG_DEVICE_SUSPENDED
Definition: usbhub.h:58
VOID NTAPI USBH_FdoIdleNotificationCallback(IN PVOID Context)
Definition: usbhub.c:3365
void DPRINT(...)
Definition: polytest.cpp:61
#define USBHUB_FDO_FLAG_DEVICE_REMOVED
Definition: usbhub.h:46
#define STATUS_PENDING
Definition: ntstatus.h:82
#define IRP_MJ_INTERNAL_DEVICE_CONTROL
#define USBHUB_FDO_FLAG_DEVICE_STOPPING
Definition: usbhub.h:34
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2647
#define InterlockedExchange
Definition: armddk.h:54
VOID NTAPI IoReleaseCancelSpinLock(IN KIRQL Irql)
Definition: util.c:150
Status
Definition: gdiplustypes.h:24
#define EVENT_INCREMENT
Definition: iotypes.h:565
#define InterlockedIncrement
Definition: armddk.h:53
#define STATUS_DEVICE_BUSY
Definition: udferr_usr.h:129
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
unsigned int ULONG
Definition: retypes.h:1
PIRP NTAPI IoAllocateIrp(IN CCHAR StackSize, IN BOOLEAN ChargeQuota)
Definition: irp.c:615
NTSTATUS NTAPI USBH_FdoIdleNotificationRequestComplete(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context)
Definition: usbhub.c:3629
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
#define USBHUB_FDO_FLAG_WAIT_IDLE_REQUEST
Definition: usbhub.h:44

Referenced by USBH_CheckHubIdle().

◆ USBH_FdoSubmitWaitWakeIrp()

NTSTATUS NTAPI USBH_FdoSubmitWaitWakeIrp ( IN PUSBHUB_FDO_EXTENSION  HubExtension)

Definition at line 3313 of file usbhub.c.

3314 {
3316  NTSTATUS Status;
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 }
_In_ UCHAR _In_ POWER_STATE PowerState
Definition: pofuncs.h:42
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
VOID NTAPI IoAcquireCancelSpinLock(OUT PKIRQL Irql)
Definition: util.c:56
#define USBHUB_FDO_FLAG_PENDING_WAKE_IRP
Definition: usbhub.h:39
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
_Out_ PKIRQL Irql
Definition: csq.h:179
SYSTEM_POWER_STATE SystemState
Definition: ntpoapi.h:57
UCHAR KIRQL
Definition: env_spec_w32.h:591
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
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
#define STATUS_PENDING
Definition: ntstatus.h:82
#define InterlockedDecrement
Definition: armddk.h:52
#define InterlockedExchange
Definition: armddk.h:54
VOID NTAPI IoReleaseCancelSpinLock(IN KIRQL Irql)
Definition: util.c:150
Status
Definition: gdiplustypes.h:24
#define EVENT_INCREMENT
Definition: iotypes.h:565
#define InterlockedIncrement
Definition: armddk.h:53
#define IRP_MN_WAIT_WAKE
NTSTATUS NTAPI PoRequestPowerIrp(IN PDEVICE_OBJECT DeviceObject, IN UCHAR MinorFunction, IN POWER_STATE PowerState, IN PREQUEST_POWER_COMPLETE CompletionFunction, IN PVOID Context, OUT PIRP *pIrp OPTIONAL)
Definition: power.c:639

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
void DPRINT(...)
Definition: polytest.cpp:61
PDEVICE_OBJECT LowerDevice
Definition: usbhub.h:150

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

◆ USBH_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 }
void DPRINT(...)
Definition: polytest.cpp:61

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 }
CPPORT Port[4]
Definition: headless.c:34
#define TRUE
Definition: types.h:120
struct _Entry Entry
Definition: kefuncs.h:627
#define LOW_REALTIME_PRIORITY
void DbgBreakPoint()
Definition: mach.c:553
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
PLIST_ENTRY NTAPI ExInterlockedRemoveHeadList(IN OUT PLIST_ENTRY ListHead, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:166
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
KSPIN_LOCK PortPowerListSpinLock
Definition: usbhub.h:234
#define InterlockedDecrement
Definition: armddk.h:52
Definition: typedefs.h:118
#define InterlockedExchange
Definition: armddk.h:54
LIST_ENTRY PortPowerList
Definition: usbhub.h:233
#define EVENT_INCREMENT
Definition: iotypes.h:565
#define InterlockedIncrement
Definition: armddk.h:53
LONG NTAPI KeReleaseSemaphore(IN PKSEMAPHORE Semaphore, IN KPRIORITY Increment, IN LONG Adjustment, IN BOOLEAN Wait)
Definition: semphobj.c:54
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
signed int * PLONG
Definition: retypes.h:5
base of all file and directory entries
Definition: entries.h:82

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 {
2939  PIO_WORKITEM WorkItem;
2940 
2941  DPRINT("USBH_FreeWorkItem: ... \n");
2942 
2943  WorkItem = HubIoWorkItem->HubWorkItem;
2944 
2945  if (HubIoWorkItem->HubWorkItemBuffer)
2946  {
2947  ExFreePoolWithTag(HubIoWorkItem->HubWorkItemBuffer, USB_HUB_TAG);
2948  }
2949 
2950  ExFreePoolWithTag(HubIoWorkItem, USB_HUB_TAG);
2951 
2952  IoFreeWorkItem(WorkItem);
2953 }
VOID NTAPI IoFreeWorkItem(IN PIO_WORKITEM IoWorkItem)
Definition: iowork.c:64
void DPRINT(...)
Definition: polytest.cpp:61
#define USB_HUB_TAG
Definition: usbhub.h:26
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099

Referenced by USBH_ChangeIndicationProcessChange().

◆ USBH_GetConfigurationDescriptor()

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

Definition at line 974 of file usbhub.c.

976 {
977  PUSB_CONFIGURATION_DESCRIPTOR ConfigDescriptor;
978  ULONG ReturnedLen;
979  SIZE_T DescriptorLen;
981 
982  DPRINT("USBH_GetConfigurationDescriptor: ... \n");
983 
984  DescriptorLen = MAXUCHAR;
985 
986  while (TRUE)
987  {
988  ConfigDescriptor = ExAllocatePoolWithTag(NonPagedPool,
989  DescriptorLen,
990  USB_HUB_TAG);
991 
992  if (!ConfigDescriptor)
993  {
995  break;
996  }
997 
999  ConfigDescriptor,
1000  DescriptorLen,
1001  &ReturnedLen);
1002 
1003  if (ReturnedLen < sizeof(USB_CONFIGURATION_DESCRIPTOR))
1004  {
1006  }
1007 
1008  if (!NT_SUCCESS(Status))
1009  {
1010  break;
1011  }
1012 
1013  *OutDescriptor = ConfigDescriptor;
1014 
1015  if (ConfigDescriptor->wTotalLength <= DescriptorLen)
1016  {
1017  break;
1018  }
1019 
1020  DescriptorLen = ConfigDescriptor->wTotalLength;
1021 
1022  ExFreePool(ConfigDescriptor);
1023  *OutDescriptor = NULL;
1024  }
1025 
1026  if (NT_SUCCESS(Status))
1027  {
1028  if (ReturnedLen < ConfigDescriptor->wTotalLength)
1029  {
1031  }
1032  }
1033  else
1034  {
1035  if (ConfigDescriptor)
1036  {
1037  ExFreePool(ConfigDescriptor);
1038  }
1039 
1040  *OutDescriptor = NULL;
1041  }
1042 
1043  return Status;
1044 }
#define TRUE
Definition: types.h:120
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
NTSTATUS NTAPI USBH_SyncGetDeviceConfigurationDescriptor(IN PDEVICE_OBJECT DeviceObject, IN PUSB_CONFIGURATION_DESCRIPTOR ConfigDescriptor, IN ULONG NumberOfBytes, IN PULONG OutLength)
Definition: usbhub.c:913
LONG NTSTATUS
Definition: precomp.h:26
#define MAXUCHAR
Definition: umtypes.h:117
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
#define USB_HUB_TAG
Definition: usbhub.h:26
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1569
ULONG_PTR SIZE_T
Definition: typedefs.h:79
unsigned int ULONG
Definition: retypes.h:1
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
#define STATUS_DEVICE_DATA_ERROR
Definition: udferr_usr.h:159

Referenced by USBH_ProcessDeviceInformation(), and USBH_StartHubFdoDevice().

◆ USBH_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 }
#define REG_BINARY
Definition: nt_native.h:1496
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
unsigned char * PUCHAR
Definition: retypes.h:3
_In_ PCWSTR _In_z_ PCWSTR _In_ ULONG ValueType
Definition: rtlfuncs.h:4062
LONG NTSTATUS
Definition: precomp.h:26
_In_ PCWSTR _Inout_ _At_ QueryTable EntryContext
Definition: rtlfuncs.h:4050
void DPRINT(...)
Definition: polytest.cpp:61
_In_ GUID _In_ PVOID ValueData
Definition: hubbusif.h:311
Status
Definition: gdiplustypes.h:24
unsigned int * PULONG
Definition: retypes.h:1
return STATUS_SUCCESS
Definition: btrfs.c:3014
#define REG_DWORD
Definition: sdbapi.c:596

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

Referenced by USBH_StartHubFdoDevice().

◆ USBH_GetDeviceType()

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

Definition at line 608 of file usbhub.c.

611 {
616  ULONG dummy;
618 
619  DPRINT("USBH_GetDeviceType: ... \n");
620 
621  QueryDeviceInformation = HubExtension->BusInterface.QueryDeviceInformation;
622 
624  {
625  DPRINT1("USBH_GetDeviceType: no QueryDeviceInformation()\n");
626  return STATUS_NOT_IMPLEMENTED;
627  }
628 
630 
631  while (TRUE)
632  {
635  USB_HUB_TAG);
636 
637  if (!DeviceInfo)
638  {
639  DPRINT1("USBH_GetDeviceType: ExAllocatePoolWithTag() failed\n");
641  break;
642  }
643 
645 
646  DeviceInfo->InformationLevel = 0;
647 
648  Status = QueryDeviceInformation(HubExtension->BusInterface.BusContext,
649  DeviceHandle,
650  DeviceInfo,
652  &dummy);
653 
655  {
656  if (NT_SUCCESS(Status))
657  {
658  DeviceType = DeviceInfo->DeviceType;
659  }
660 
662  break;
663  }
664 
667  }
668 
669  if (OutDeviceType)
670  {
671  *OutDeviceType = DeviceType;
672  DPRINT("USBH_GetDeviceType: DeviceType - %x\n", DeviceType);
673  }
674 
675  return Status;
676 }
enum _USB_DEVICE_TYPE USB_DEVICE_TYPE
#define TRUE
Definition: types.h:120
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_Inout_ PUSB_DEVICE_HANDLE DeviceHandle
Definition: hubbusif.h:121
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
DeviceType
Definition: mmdrv.h:41
LONG NTSTATUS
Definition: precomp.h:26
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
struct _USB_DEVICE_INFORMATION_0 USB_DEVICE_INFORMATION_0
void DPRINT(...)
Definition: polytest.cpp:61
#define USB_HUB_TAG
Definition: usbhub.h:26
NTSTATUS QueryDeviceInformation(IN PUNICODE_STRING SymbolicName, OUT PUNICODE_STRING DeviceName OPTIONAL, OUT PMOUNTDEV_UNIQUE_ID *UniqueId OPTIONAL, OUT PBOOLEAN Removable OPTIONAL, OUT PBOOLEAN GptDriveLetter OPTIONAL, OUT PBOOLEAN HasGuid OPTIONAL, IN OUT LPGUID StableGuid OPTIONAL, OUT PBOOLEAN Valid OPTIONAL)
Definition: mountmgr.c:195
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
struct _DeviceInfo DeviceInfo
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
Status
Definition: gdiplustypes.h:24
ULONG_PTR SIZE_T
Definition: typedefs.h:79
unsigned char dummy
Definition: maze.c:118
_In_ PUSB_DEVICE_HANDLE _In_ ULONG DeviceInformationBufferLength
Definition: hubbusif.h:181
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
USB_BUSIFFN_GET_DEVICE_INFORMATION * PUSB_BUSIFFN_GET_DEVICE_INFORMATION
Definition: hubbusif.h:183

Referenced by USBH_StartHubFdoDevice().

◆ USBH_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;
1984  NTSTATUS Status;
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 TRUE
Definition: types.h:120
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS