ReactOS  0.4.13-dev-242-g611e6d7
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_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_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 5034 of file usbhub.c.

5036 {
5037  DPRINT("USBHUB: DriverEntry - %wZ\n", RegistryPath);
5038 
5041 
5044 
5047 
5051 
5053 
5054  return STATUS_SUCCESS;
5055 }
PWSTR GenericUSBDeviceString
Definition: usbhub.c:19
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
NTSTATUS NTAPI USBH_RegQueryGenericUSBDeviceString(PVOID USBDeviceString)
Definition: usbhub.c:5009
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
PDRIVER_EXTENSION DriverExtension
Definition: iotypes.h:2173
VOID NTAPI USBH_DriverUnload(IN PDRIVER_OBJECT DriverObject)
Definition: usbhub.c:4940
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
void DPRINT(...)
Definition: polytest.cpp:61
NTSTATUS NTAPI USBH_HubDispatch(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: usbhub.c:4953
#define IRP_MJ_INTERNAL_DEVICE_CONTROL
#define IRP_MJ_POWER
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
PDRIVER_UNLOAD DriverUnload
Definition: iotypes.h:2179
NTSTATUS NTAPI USBH_AddDevice(IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT LowerPDO)
Definition: usbhub.c:4866
#define IRP_MJ_SYSTEM_CONTROL
PDRIVER_ADD_DEVICE AddDevice
Definition: iotypes.h:2111
PDRIVER_DISPATCH MajorFunction[IRP_MJ_MAXIMUM_FUNCTION+1]
Definition: iotypes.h:2180
_In_ PUNICODE_STRING RegistryPath
Definition: wmip.h:27
return STATUS_SUCCESS
Definition: btrfs.c:2745
#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()

Definition at line 133 of file usbhub.c.

134 {
136 
137  DPRINT("PdoExt: DeviceObject - %p\n", DeviceObject);
138 
139  if (DeviceObject)
140  {
142  }
143  else
144  {
145  PdoExtension = NULL;
146  }
147 
149 }
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560

Referenced by PcmciaPdoPlugPlay(), PcmciaPdoSetPowerState(), USBH_FdoQueryBusRelations(), USBH_FdoSurpriseRemoveDevice(), and USBH_PdoRemoveDevice().

◆ 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 2427 of file usbhub.c.

2431 {
2433  PUSB_BUSIFFN_CREATE_USB_DEVICE CreateUsbDevice;
2434 
2435  DPRINT("USBD_CreateDeviceEx: Port - %x, UsbPortStatus - 0x%04X\n",
2436  Port,
2437  UsbPortStatus.AsUshort16);
2438 
2439  CreateUsbDevice = HubExtension->BusInterface.CreateUsbDevice;
2440 
2441  if (!CreateUsbDevice)
2442  {
2443  return STATUS_NOT_IMPLEMENTED;
2444  }
2445 
2446  HubDeviceHandle = USBH_SyncGetDeviceHandle(HubExtension->LowerDevice);
2447 
2448  return CreateUsbDevice(HubExtension->BusInterface.BusContext,
2449  OutDeviceHandle,
2451  UsbPortStatus.AsUshort16,
2452  Port);
2453 }
CPPORT Port[4]
Definition: headless.c:34
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
_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
PUSB_DEVICE_HANDLE NTAPI USBH_SyncGetDeviceHandle(IN PDEVICE_OBJECT DeviceObject)
Definition: usbhub.c:832

Referenced by USBH_CreateDevice(), and USBH_ResetDevice().

◆ USBD_GetDeviceInformationEx()

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

Definition at line 2558 of file usbhub.c.

2563 {
2566  SIZE_T DeviceInfoLength;
2567  PUSB_NODE_CONNECTION_INFORMATION_EX NodeInfo;
2568  SIZE_T NodeInfoLength;
2569  ULONG PipeNumber;
2570  ULONG dummy;
2571  NTSTATUS Status;
2572 
2573  DPRINT("USBD_GetDeviceInformationEx ... \n");
2574 
2575  QueryDeviceInformation = HubExtension->BusInterface.QueryDeviceInformation;
2576 
2578  {
2580  return Status;
2581  }
2582 
2583  DeviceInfoLength = sizeof(USB_DEVICE_INFORMATION_0);
2584 
2585  while (TRUE)
2586  {
2588  DeviceInfoLength,
2589  USB_HUB_TAG);
2590 
2591  if (!DeviceInfo)
2592  {
2594  }
2595 
2596  RtlZeroMemory(DeviceInfo, DeviceInfoLength);
2597 
2598  DeviceInfo->InformationLevel = 0;
2599 
2600  Status = QueryDeviceInformation(HubExtension->BusInterface.BusContext,
2601  DeviceHandle,
2602  DeviceInfo,
2603  DeviceInfoLength,
2604  &dummy);
2605 
2607  {
2608  break;
2609  }
2610 
2611  DeviceInfoLength = DeviceInfo->ActualLength;
2612 
2614  }
2615 
2616  NodeInfo = NULL;
2617  NodeInfoLength = 0;
2618 
2619  if (NT_SUCCESS(Status))
2620  {
2621  NodeInfoLength = (sizeof(USB_NODE_CONNECTION_INFORMATION_EX) - sizeof(USB_PIPE_INFO)) +
2622  DeviceInfo->NumberOfOpenPipes * sizeof(USB_PIPE_INFO);
2623 
2624  NodeInfo = ExAllocatePoolWithTag(PagedPool, NodeInfoLength, USB_HUB_TAG);
2625 
2626  if (!NodeInfo)
2627  {
2630  }
2631 
2632  RtlZeroMemory(NodeInfo, NodeInfoLength);
2633 
2634  NodeInfo->ConnectionIndex = Info->ConnectionIndex;
2635 
2636  RtlCopyMemory(&NodeInfo->DeviceDescriptor,
2637  &DeviceInfo->DeviceDescriptor,
2638  sizeof(USB_DEVICE_DESCRIPTOR));
2639 
2640  NodeInfo->CurrentConfigurationValue = DeviceInfo->CurrentConfigurationValue;
2641  NodeInfo->Speed = DeviceInfo->DeviceSpeed;
2642  NodeInfo->DeviceIsHub = PortExtension->PortPdoFlags & USBHUB_PDO_FLAG_HUB_DEVICE;
2643  NodeInfo->DeviceAddress = DeviceInfo->DeviceAddress;
2644  NodeInfo->NumberOfOpenPipes = DeviceInfo->NumberOfOpenPipes;
2645  NodeInfo->ConnectionStatus = Info->ConnectionStatus;
2646 
2647  for (PipeNumber = 0;
2648  PipeNumber < DeviceInfo->NumberOfOpenPipes;
2649  PipeNumber++)
2650  {
2651  RtlCopyMemory(&NodeInfo->PipeList[PipeNumber],
2652  &DeviceInfo->PipeList[PipeNumber],
2653  sizeof(USB_PIPE_INFO));
2654  }
2655  }
2656 
2658 
2659  if (NodeInfo)
2660  {
2661  if (NodeInfoLength <= Length)
2662  {
2663  Length = NodeInfoLength;
2664  }
2665  else
2666  {
2668  }
2669 
2670  RtlCopyMemory(Info, NodeInfo, Length);
2671 
2672  ExFreePoolWithTag(NodeInfo, USB_HUB_TAG);
2673  }
2674 
2675  return Status;
2676 }
#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:64
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:9
#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:204
#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:78
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 2481 of file usbhub.c.

2487 {
2488  NTSTATUS Status;
2489  PUSB_BUSIFFN_INITIALIZE_USB_DEVICE InitializeUsbDevice;
2490  PUSB_BUSIFFN_GET_USB_DESCRIPTORS GetUsbDescriptors;
2491 
2492  DPRINT("USBD_InitializeDeviceEx: ... \n");
2493 
2494  InitializeUsbDevice = HubExtension->BusInterface.InitializeUsbDevice;
2495  GetUsbDescriptors = HubExtension->BusInterface.GetUsbDescriptors;
2496 
2497  if (!InitializeUsbDevice || !GetUsbDescriptors)
2498  {
2499  return STATUS_NOT_IMPLEMENTED;
2500  }
2501 
2502  Status = InitializeUsbDevice(HubExtension->BusInterface.BusContext,
2503  DeviceHandle);
2504 
2505  if (!NT_SUCCESS(Status))
2506  {
2507  return Status;
2508  }
2509 
2510  return GetUsbDescriptors(HubExtension->BusInterface.BusContext,
2511  DeviceHandle,
2516 }
_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 2905 of file usbhub.c.

2906 {
2907  PUSB_BUSIFFN_ROOTHUB_INIT_NOTIFY RootHubInitNotification;
2908 
2909  DPRINT("USBD_RegisterRootHubCallBack: ... \n");
2910 
2911  RootHubInitNotification = HubExtension->BusInterface.RootHubInitNotification;
2912 
2913  if (!RootHubInitNotification)
2914  {
2915  return STATUS_NOT_IMPLEMENTED;
2916  }
2917 
2918  KeClearEvent(&HubExtension->RootHubNotificationEvent);
2919 
2920  return RootHubInitNotification(HubExtension->BusInterface.BusContext,
2921  HubExtension,
2923 }
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
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
VOID NTAPI USBHUB_RootHubCallBack(IN PVOID Context)
Definition: usbhub.c:2876

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 2457 of file usbhub.c.

2460 {
2461  PUSB_BUSIFFN_REMOVE_USB_DEVICE RemoveUsbDevice;
2462 
2463  DPRINT("USBD_RemoveDeviceEx: DeviceHandle - %p, Flags - %X\n",
2464  DeviceHandle,
2465  Flags);
2466 
2467  RemoveUsbDevice = HubExtension->BusInterface.RemoveUsbDevice;
2468 
2469  if (!RemoveUsbDevice)
2470  {
2471  return STATUS_NOT_IMPLEMENTED;
2472  }
2473 
2474  return RemoveUsbDevice(HubExtension->BusInterface.BusContext,
2475  DeviceHandle,
2476  Flags);
2477 }
_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 2680 of file usbhub.c.

2683 {
2684  PUSB_BUSIFFN_RESTORE_DEVICE RestoreUsbDevice;
2685  NTSTATUS Status;
2686 
2687  DPRINT("USBD_RestoreDeviceEx: HubExtension - %p, OldDeviceHandle - %p, NewDeviceHandle - %p\n",
2688  HubExtension,
2690  NewDeviceHandle);
2691 
2692  RestoreUsbDevice = HubExtension->BusInterface.RestoreUsbDevice;
2693 
2694  if (RestoreUsbDevice)
2695  {
2696  Status = RestoreUsbDevice(HubExtension->BusInterface.BusContext,
2698  NewDeviceHandle);
2699  }
2700  else
2701  {
2703  }
2704 
2705  return Status;
2706 }
#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 2927 of file usbhub.c.

2928 {
2929  PUSB_BUSIFFN_ROOTHUB_INIT_NOTIFY RootHubInitNotification;
2930  NTSTATUS Status;
2931 
2932  DPRINT("USBD_UnRegisterRootHubCallBack ... \n");
2933 
2934  RootHubInitNotification = HubExtension->BusInterface.RootHubInitNotification;
2935 
2936  if (!RootHubInitNotification)
2937  {
2938  return STATUS_NOT_IMPLEMENTED;
2939  }
2940 
2941  Status = RootHubInitNotification(HubExtension->BusInterface.BusContext,
2942  NULL,
2943  NULL);
2944 
2945  if (!NT_SUCCESS(Status))
2946  {
2947  KeWaitForSingleObject(&HubExtension->RootHubNotificationEvent,
2948  Executive,
2949  KernelMode,
2950  FALSE,
2951  NULL);
2952  }
2953 
2954  return Status;
2955 }
#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 4866 of file usbhub.c.

4868 {
4870  NTSTATUS Status;
4871  PUSBHUB_FDO_EXTENSION HubExtension;
4872  PDEVICE_OBJECT LowerDevice;
4873 
4874  DPRINT("USBH_AddDevice: DriverObject - %p, LowerPDO - %p\n",
4875  DriverObject,
4876  LowerPDO);
4877 
4878  DeviceObject = NULL;
4879 
4881  sizeof(USBHUB_FDO_EXTENSION),
4882  NULL,
4883  0x8600,
4885  FALSE,
4886  &DeviceObject);
4887 
4888  if (!NT_SUCCESS(Status))
4889  {
4890  DPRINT1("USBH_AddDevice: IoCreateDevice() fail\n");
4891 
4892  if (DeviceObject)
4893  {
4895  }
4896 
4897  return Status;
4898  }
4899 
4900  DPRINT("USBH_AddDevice: DeviceObject - %p\n", DeviceObject);
4901 
4902  HubExtension = DeviceObject->DeviceExtension;
4903  RtlZeroMemory(HubExtension, sizeof(USBHUB_FDO_EXTENSION));
4904 
4905  HubExtension->Common.ExtensionType = USBH_EXTENSION_TYPE_HUB;
4906 
4907  LowerDevice = IoAttachDeviceToDeviceStack(DeviceObject, LowerPDO);
4908 
4909  if (!LowerDevice)
4910  {
4911  DPRINT1("USBH_AddDevice: IoAttachDeviceToDeviceStack() fail\n");
4912 
4913  if (DeviceObject)
4914  {
4916  }
4917 
4918  return STATUS_UNSUCCESSFUL;
4919  }
4920 
4921  DPRINT("USBH_AddDevice: LowerDevice - %p\n", LowerDevice);
4922 
4923  HubExtension->Common.SelfDevice = DeviceObject;
4924 
4925  HubExtension->LowerPDO = LowerPDO;
4926  HubExtension->LowerDevice = LowerDevice;
4927 
4928  KeInitializeSemaphore(&HubExtension->IdleSemaphore, 1, 1);
4929 
4932 
4933  DPRINT("USBH_AddDevice: call IoWMIRegistrationControl() UNIMPLEMENTED. FIXME\n");
4934 
4935  return Status;
4936 }
#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
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1250
PDEVICE_OBJECT LowerPDO
Definition: usbhub.h:149
COMMON_DEVICE_EXTENSION Common
Definition: usbhub.h:148
#define DPRINT1
Definition: precomp.h:8
#define USBH_EXTENSION_TYPE_HUB
Definition: usbhub.h:28
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 2710 of file usbhub.c.

2716 {
2717  PUSBHUB_IO_WORK_ITEM HubIoWorkItem;
2718  PIO_WORKITEM WorkItem;
2719  PVOID WorkItemBuffer;
2720 
2721  DPRINT("USBH_AllocateWorkItem: ... \n");
2722 
2723  if (!(HubExtension->HubFlags & USBHUB_FDO_FLAG_WITEM_INIT))
2724  {
2725  return STATUS_INVALID_PARAMETER;
2726  }
2727 
2728  HubIoWorkItem = ExAllocatePoolWithTag(NonPagedPool,
2729  sizeof(USBHUB_IO_WORK_ITEM),
2730  USB_HUB_TAG);
2731 
2732  if (!HubIoWorkItem)
2733  {
2735  }
2736 
2737  RtlZeroMemory(HubIoWorkItem, sizeof(USBHUB_IO_WORK_ITEM));
2738 
2739  WorkItem = IoAllocateWorkItem(HubExtension->Common.SelfDevice);
2740 
2741  HubIoWorkItem->HubWorkItem = WorkItem;
2742 
2743  if (!WorkItem)
2744  {
2745  ExFreePoolWithTag(HubIoWorkItem, USB_HUB_TAG);
2747  }
2748 
2749  if (BufferLength && OutHubWorkItemBuffer)
2750  {
2751  WorkItemBuffer = ExAllocatePoolWithTag(NonPagedPool,
2752  BufferLength,
2753  USB_HUB_TAG);
2754 
2755  HubIoWorkItem->HubWorkItemBuffer = WorkItemBuffer;
2756 
2757  if (!WorkItemBuffer)
2758  {
2759  IoFreeWorkItem(HubIoWorkItem->HubWorkItem);
2760  ExFreePoolWithTag(HubIoWorkItem, USB_HUB_TAG);
2761 
2763  }
2764 
2765  RtlZeroMemory(WorkItemBuffer, BufferLength);
2766  }
2767  else
2768  {
2769  HubIoWorkItem->HubWorkItemBuffer = NULL;
2770  }
2771 
2772  HubIoWorkItem->HubWorkItemType = Type;
2773  HubIoWorkItem->HubExtension = HubExtension;
2774  HubIoWorkItem->HubWorkerRoutine = WorkerRoutine;
2775 
2776  if (OutHubIoWorkItem)
2777  {
2778  *OutHubIoWorkItem = HubIoWorkItem;
2779  }
2780 
2781  if (OutHubWorkItemBuffer)
2782  {
2783  *OutHubWorkItemBuffer = HubIoWorkItem->HubWorkItemBuffer;
2784  }
2785 
2786  return STATUS_SUCCESS;
2787 }
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:9
PUSBHUB_WORKER_ROUTINE HubWorkerRoutine
Definition: usbhub.h:138
PIO_WORKITEM HubWorkItem
Definition: usbhub.h:135
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define USBHUB_FDO_FLAG_WITEM_INIT
Definition: usbhub.h:59
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:2745

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 2238 of file usbhub.c.

2241 {
2242  PUSBHUB_FDO_EXTENSION HubExtension;
2243  USBD_STATUS UrbStatus;
2244  BOOLEAN IsErrors = FALSE;
2245  PUSBHUB_IO_WORK_ITEM HubWorkItem;
2246  PUSBHUB_STATUS_CHANGE_CONTEXT HubWorkItemBuffer;
2247  USHORT NumPorts;
2248  USHORT Port;
2249  NTSTATUS Status;
2250  PVOID Bitmap;
2252 
2253  HubExtension = Context;
2254  UrbStatus = HubExtension->SCEWorkerUrb.Hdr.Status;
2255 
2256  DPRINT_SCE("USBH_ChangeIndication: IrpStatus - %x, UrbStatus - %x, HubFlags - %lX\n",
2257  Irp->IoStatus.Status,
2258  UrbStatus,
2259  HubExtension->HubFlags);
2260 
2261  if (NT_ERROR(Irp->IoStatus.Status) || USBD_ERROR(UrbStatus) ||
2262  (HubExtension->HubFlags & USBHUB_FDO_FLAG_DEVICE_FAILED) ||
2263  (HubExtension->HubFlags & USBHUB_FDO_FLAG_DEVICE_STOPPING))
2264  {
2265  HubExtension->RequestErrors++;
2266 
2267  IsErrors = TRUE;
2268 
2269  KeSetEvent(&HubExtension->StatusChangeEvent,
2271  FALSE);
2272 
2273  if (HubExtension->HubFlags & USBHUB_FDO_FLAG_DEVICE_STOPPING ||
2274  HubExtension->HubFlags & USBHUB_FDO_FLAG_DEVICE_FAILED ||
2275  HubExtension->RequestErrors > USBHUB_MAX_REQUEST_ERRORS ||
2276  Irp->IoStatus.Status == STATUS_DELETE_PENDING)
2277  {
2278  DPRINT_SCE("USBH_ChangeIndication: HubExtension->RequestErrors - %x\n",
2279  HubExtension->RequestErrors);
2280 
2282  }
2283 
2284  DPRINT_SCE("USBH_ChangeIndication: HubExtension->RequestErrors - %x\n",
2285  HubExtension->RequestErrors);
2286  }
2287  else
2288  {
2289  HubExtension->RequestErrors = 0;
2290  }
2291 
2293  HubExtension->SCEBitmapLength;
2294 
2295  Status = USBH_AllocateWorkItem(HubExtension,
2296  &HubWorkItem,
2298  BufferLength,
2299  (PVOID *)&HubWorkItemBuffer,
2301 
2302  if (!NT_SUCCESS(Status))
2303  {
2305  }
2306 
2307  RtlZeroMemory(HubWorkItemBuffer, BufferLength);
2308 
2309  HubWorkItemBuffer->IsRequestErrors = FALSE;
2310 
2311  if (IsErrors)
2312  {
2313  HubWorkItemBuffer->IsRequestErrors = TRUE;
2314  }
2315 
2316  if (InterlockedIncrement(&HubExtension->ResetRequestCount) == 1)
2317  {
2318  KeClearEvent(&HubExtension->ResetEvent);
2319  }
2320 
2321  HubWorkItemBuffer->HubExtension = HubExtension;
2322 
2323  HubExtension->WorkItemToQueue = HubWorkItem;
2324 
2325  Bitmap = HubWorkItemBuffer + 1;
2326 
2328  HubExtension->SCEBitmap,
2329  HubExtension->SCEBitmapLength);
2330 
2331  NumPorts = HubExtension->HubDescriptor->bNumberOfPorts;
2332 
2333  for (Port = 0; Port <= NumPorts; ++Port)
2334  {
2335  if (IsBitSet(Bitmap, Port))
2336  {
2337  break;
2338  }
2339  }
2340 
2341  if (Port > NumPorts)
2342  {
2343  Port = 0;
2344  }
2345 
2347  HubExtension->ResetPortIrp,
2348  &HubExtension->SCEWorkerUrb,
2349  Port);
2350 
2351  if (NT_ERROR(Status))
2352  {
2353  HubExtension->HubFlags |= USBHUB_FDO_FLAG_DEVICE_FAILED;
2354  }
2355 
2357 }
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:63
PUSBHUB_FDO_EXTENSION HubExtension
Definition: usbhub.h:249
_In_ PIRP Irp
Definition: csq.h:116
#define USBHUB_MAX_REQUEST_ERRORS
Definition: usbhub.h:108
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
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:1718
_In_ ULONG BufferLength
Definition: usbdlib.h:225
unsigned char BOOLEAN
KEVENT StatusChangeEvent
Definition: usbhub.h:176
struct _USBHUB_STATUS_CHANGE_CONTEXT USBHUB_STATUS_CHANGE_CONTEXT
VOID NTAPI USBH_ChangeIndicationWorker(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PVOID Context)
Definition: usbhub.c:2066
UCHAR bNumberOfPorts
Definition: usb100.h:173
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define NT_ERROR(Status)
Definition: umtypes.h:106
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:2710
LONG USBD_STATUS
Definition: usb.h:165
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:564
#define InterlockedIncrement
Definition: armddk.h:53
#define USBHUB_FDO_FLAG_DEVICE_STOPPING
Definition: usbhub.h:34
unsigned short USHORT
Definition: pedump.c:61
BOOLEAN NTAPI IsBitSet(IN PUCHAR BitMapAddress, IN USHORT Bit)
Definition: usbhub.c:121
struct tagContext Context
Definition: acpixf.h:1012
#define USBHUB_FDO_FLAG_DEVICE_FAILED
Definition: usbhub.h:35
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

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 1606 of file usbhub.c.

1611 {
1612  PIO_STACK_LOCATION IoStack;
1613  BM_REQUEST_TYPE RequestType;
1614 
1615  DPRINT_SCE("USBH_ChangeIndicationAckChange: ... \n");
1616 
1617  Urb->Hdr.Length = sizeof(struct _URB_CONTROL_VENDOR_OR_CLASS_REQUEST);
1618  Urb->Hdr.Function = URB_FUNCTION_CLASS_OTHER;
1619  Urb->Hdr.UsbdDeviceHandle = NULL;
1620 
1621  Urb->TransferFlags = USBD_SHORT_TRANSFER_OK;
1622  Urb->TransferBufferLength = 0;
1623  Urb->TransferBuffer = NULL;
1624  Urb->TransferBufferMDL = NULL;
1625  Urb->UrbLink = NULL;
1626 
1627  RequestType.B = 0;
1628  RequestType.Recipient = BMREQUEST_TO_OTHER;
1629  RequestType.Type = BMREQUEST_CLASS;
1630  RequestType.Dir = BMREQUEST_HOST_TO_DEVICE;
1631 
1632  Urb->RequestTypeReservedBits = RequestType.B;
1633  Urb->Request = USB_REQUEST_CLEAR_FEATURE;
1634  Urb->Index = Port;
1635  Urb->Value = RequestValue;
1636 
1638  IoSizeOfIrp(HubExtension->LowerDevice->StackSize),
1639  HubExtension->LowerDevice->StackSize);
1640 
1641  IoStack = IoGetNextIrpStackLocation(Irp);
1642 
1644  IoStack->Parameters.Others.Argument1 = Urb;
1645  IoStack->Parameters.DeviceIoControl.IoControlCode = IOCTL_INTERNAL_USB_SUBMIT_URB;
1646 
1649  HubExtension,
1650  TRUE,
1651  TRUE,
1652  TRUE);
1653 
1654  return IoCallDriver(HubExtension->LowerDevice, Irp);
1655 }
CPPORT Port[4]
Definition: headless.c:34
#define TRUE
Definition: types.h:120
#define IOCTL_INTERNAL_USB_SUBMIT_URB
Definition: usbioctl.h:32
_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:515
NTSTATUS NTAPI USBH_ChangeIndicationAckChangeComplete(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context)
Definition: usbhub.c:1567
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:2771
#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 1567 of file usbhub.c.

1570 {
1571  PUSBHUB_FDO_EXTENSION HubExtension;
1572  PVOID Event;
1573  USHORT Port;
1574 
1575  HubExtension = Context;
1576 
1577  DPRINT_SCE("USBH_ChangeIndicationAckChangeComplete: ... \n");
1578 
1579  ASSERT(HubExtension->Port > 0);
1580  Port = HubExtension->Port - 1;
1581 
1582  HubExtension->PortData[Port].PortStatus = HubExtension->PortStatus;
1583 
1585  NULL);
1586 
1587  if (Event)
1588  {
1590  }
1591 
1592  USBH_SubmitStatusChangeTransfer(HubExtension);
1593 
1594  if (!InterlockedDecrement(&HubExtension->ResetRequestCount))
1595  {
1596  KeSetEvent(&HubExtension->ResetEvent,
1598  FALSE);
1599  }
1600 
1602 }
CPPORT Port[4]
Definition: headless.c:34
#define STATUS_MORE_PROCESSING_REQUIRED
Definition: shellext.h:63
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:434
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:564
unsigned short USHORT
Definition: pedump.c:61
NTSTATUS NTAPI USBH_SubmitStatusChangeTransfer(IN PUSBHUB_FDO_EXTENSION HubExtension)
Definition: usbhub.c:2361
struct tagContext Context
Definition: acpixf.h:1012
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 1659 of file usbhub.c.

1662 {
1663  PUSBHUB_FDO_EXTENSION HubExtension;
1664  PUSBHUB_IO_WORK_ITEM WorkItem;
1665  USHORT RequestValue;
1666 
1667  HubExtension = Context;
1668 
1669  DPRINT_SCE("USBH_ChangeIndicationProcessChange: PortStatus - %lX\n",
1670  HubExtension->PortStatus.AsUlong32);
1671 
1672  if ((NT_SUCCESS(Irp->IoStatus.Status) ||
1673  USBD_SUCCESS(HubExtension->SCEWorkerUrb.Hdr.Status)) &&
1676  {
1677  if (!InterlockedDecrement(&HubExtension->PendingRequestCount))
1678  {
1679  KeSetEvent(&HubExtension->PendingRequestEvent,
1681  FALSE);
1682  }
1683 
1684  USBH_FreeWorkItem(HubExtension->WorkItemToQueue);
1685 
1686  HubExtension->WorkItemToQueue = NULL;
1687 
1689  {
1690  RequestValue = USBHUB_FEATURE_C_PORT_RESET;
1691  }
1692  else
1693  {
1694  RequestValue = USBHUB_FEATURE_C_PORT_ENABLE;
1695  }
1696 
1697  USBH_ChangeIndicationAckChange(HubExtension,
1698  HubExtension->ResetPortIrp,
1699  &HubExtension->SCEWorkerUrb,
1700  HubExtension->Port,
1701  RequestValue);
1702  }
1703  else
1704  {
1705  ASSERT(HubExtension->WorkItemToQueue != NULL);
1706 
1707  WorkItem = HubExtension->WorkItemToQueue;
1708  HubExtension->WorkItemToQueue = NULL;
1709 
1710  USBH_QueueWorkItem(HubExtension, WorkItem);
1711  }
1712 
1714 }
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:1606
struct _URB_CONTROL_VENDOR_OR_CLASS_REQUEST SCEWorkerUrb
Definition: usbhub.h:175
#define STATUS_MORE_PROCESSING_REQUIRED
Definition: shellext.h:63
_In_ PIRP Irp
Definition: csq.h:116
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
VOID NTAPI USBH_FreeWorkItem(IN PUSBHUB_IO_WORK_ITEM HubIoWorkItem)
Definition: usbhub.c:2856
#define USBHUB_FEATURE_C_PORT_RESET
Definition: usbhub.h:102
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
VOID NTAPI USBH_QueueWorkItem(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PUSBHUB_IO_WORK_ITEM HubIoWorkItem)
Definition: usbhub.c:2836
#define InterlockedDecrement
Definition: armddk.h:52
USB_20_PORT_CHANGE Usb20PortChange
Definition: usb200.h:231
#define USBHUB_FEATURE_C_PORT_ENABLE
Definition: usbhub.h:99
#define EVENT_INCREMENT
Definition: iotypes.h:564
unsigned short USHORT
Definition: pedump.c:61
struct tagContext Context
Definition: acpixf.h:1012
#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 1718 of file usbhub.c.

1722 {
1723  PUSBHUB_IO_WORK_ITEM WorkItem;
1724  NTSTATUS Status;
1725  PIO_STACK_LOCATION IoStack;
1726  BM_REQUEST_TYPE RequestType;
1727 
1728  DPRINT_SCE("USBH_ChangeIndicationQueryChange: Port - %x\n", Port);
1729 
1730  InterlockedIncrement(&HubExtension->PendingRequestCount);
1731 
1732  if (!Port)
1733  {
1734  ASSERT(HubExtension->WorkItemToQueue != NULL);
1735 
1736  WorkItem = HubExtension->WorkItemToQueue;
1737  HubExtension->WorkItemToQueue = NULL;
1738 
1739  USBH_QueueWorkItem(HubExtension, WorkItem);
1740 
1741  return STATUS_SUCCESS;
1742  }
1743 
1744  Urb->Hdr.Length = sizeof(struct _URB_CONTROL_VENDOR_OR_CLASS_REQUEST);
1745  Urb->Hdr.UsbdDeviceHandle = NULL;
1746  Urb->Hdr.Function = URB_FUNCTION_CLASS_OTHER;
1747 
1748  Urb->TransferFlags = USBD_SHORT_TRANSFER_OK | USBD_TRANSFER_DIRECTION_IN;
1749  Urb->TransferBuffer = &HubExtension->PortStatus;
1750  Urb->TransferBufferLength = sizeof(HubExtension->PortStatus);
1751  Urb->TransferBufferMDL = NULL;
1752  Urb->UrbLink = NULL;
1753 
1754  RequestType.B = 0;
1755  RequestType.Recipient = BMREQUEST_TO_OTHER;
1756  RequestType.Type = BMREQUEST_CLASS;
1757  RequestType.Dir = BMREQUEST_DEVICE_TO_HOST;
1758 
1759  Urb->RequestTypeReservedBits = RequestType.B;
1760  Urb->Request = USB_REQUEST_GET_STATUS;
1761  Urb->Value = 0;
1762  Urb->Index = Port;
1763 
1764  HubExtension->Port = Port;
1765 
1767  IoSizeOfIrp(HubExtension->LowerDevice->StackSize),
1768  HubExtension->LowerDevice->StackSize);
1769 
1770  IoStack = IoGetNextIrpStackLocation(Irp);
1771 
1773  IoStack->Parameters.Others.Argument1 = Urb;
1774  IoStack->Parameters.DeviceIoControl.IoControlCode = IOCTL_INTERNAL_USB_SUBMIT_URB;
1775 
1778  HubExtension,
1779  TRUE,
1780  TRUE,
1781  TRUE);
1782 
1783  Status = IoCallDriver(HubExtension->LowerDevice, Irp);
1784 
1785  return Status;
1786 }
CPPORT Port[4]
Definition: headless.c:34
#define TRUE
Definition: types.h:120
#define IOCTL_INTERNAL_USB_SUBMIT_URB
Definition: usbioctl.h:32
_In_ PIRP Irp
Definition: csq.h:116
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:515
#define BMREQUEST_DEVICE_TO_HOST
Definition: usb100.h:32
smooth NULL
Definition: ftsmooth.c:416
#define BMREQUEST_TO_OTHER
Definition: usb100.h:41
NTSTATUS NTAPI USBH_ChangeIndicationProcessChange(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context)
Definition: usbhub.c:1659
#define IRP_MJ_INTERNAL_DEVICE_CONTROL
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define BMREQUEST_CLASS
Definition: usb100.h:35
VOID NTAPI USBH_QueueWorkItem(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PUSBHUB_IO_WORK_ITEM HubIoWorkItem)
Definition: usbhub.c:2836
__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:2771
return STATUS_SUCCESS
Definition: btrfs.c:2745
#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 2066 of file usbhub.c.

2068 {
2069  PUSBHUB_FDO_EXTENSION LowerHubExtension;
2070  PUSBHUB_PORT_PDO_EXTENSION LowerPortExtension;
2073  NTSTATUS Status;
2074  USHORT Port = 0;
2075 
2076  DPRINT_SCE("USBH_ChangeIndicationWorker ... \n");
2077 
2078  WorkItem = Context;
2079 
2080  KeWaitForSingleObject(&HubExtension->HubSemaphore,
2081  Executive,
2082  KernelMode,
2083  FALSE,
2084  NULL);
2085 
2086  if (HubExtension->HubFlags & USBHUB_FDO_FLAG_DEVICE_STOPPING)
2087  {
2088  KeSetEvent(&HubExtension->StatusChangeEvent,
2090  FALSE);
2091 
2092  goto Exit;
2093  }
2094 
2095  if (!HubExtension->RequestErrors)
2096  {
2097  goto Enum;
2098  }
2099 
2100  DPRINT_SCE("USBH_ChangeIndicationWorker: RequestErrors - %x\n",
2101  HubExtension->RequestErrors);
2102 
2103  if (HubExtension->LowerPDO == HubExtension->RootHubPdo)
2104  {
2105  goto Enum;
2106  }
2107 
2108  LowerPortExtension = HubExtension->LowerPDO->DeviceExtension;
2109 
2110  if (LowerPortExtension->PortPdoFlags & USBHUB_PDO_FLAG_POWER_D1_OR_D2)
2111  {
2112  goto Enum;
2113  }
2114 
2115  LowerHubExtension = LowerPortExtension->HubExtension;
2116 
2117  if (!LowerHubExtension)
2118  {
2119  goto Enum;
2120  }
2121 
2122  Status = USBH_SyncGetPortStatus(LowerHubExtension,
2123  LowerPortExtension->PortNumber,
2124  &PortStatus,
2125  sizeof(USB_PORT_STATUS_AND_CHANGE));
2126 
2127  if (!NT_SUCCESS(Status) ||
2128  !PortStatus.PortStatus.Usb20PortStatus.CurrentConnectStatus)
2129  {
2130  HubExtension->HubFlags |= USBHUB_FDO_FLAG_DEVICE_REMOVED;
2131 
2132  KeSetEvent(&HubExtension->StatusChangeEvent,
2134  FALSE);
2135 
2136  goto Exit;
2137  }
2138 
2139  if (!(HubExtension->HubFlags & USBHUB_FDO_FLAG_ESD_RECOVERING))
2140  {
2141  HubExtension->HubFlags |= USBHUB_FDO_FLAG_ESD_RECOVERING;
2142 
2143  DPRINT1("USBH_ChangeIndicationWorker: USBHUB_FDO_FLAG_ESD_RECOVERING FIXME\n");
2144  DbgBreakPoint();
2145 
2146  goto Exit;
2147  }
2148 
2149 Enum:
2150 
2151  if (WorkItem->IsRequestErrors)
2152  {
2153  USBH_ResetHub(HubExtension);
2154  }
2155  else
2156  {
2157  for (Port = 0;
2158  Port < HubExtension->HubDescriptor->bNumberOfPorts;
2159  Port++)
2160  {
2161  if (IsBitSet((PUCHAR)(WorkItem + 1), Port))
2162  {
2163  break;
2164  }
2165  }
2166 
2167  if (Port)
2168  {
2169  Status = USBH_SyncGetPortStatus(HubExtension,
2170  Port,
2171  &PortStatus,
2172  sizeof(USB_PORT_STATUS_AND_CHANGE));
2173  }
2174  else
2175  {
2176  DPRINT1("USBH_ChangeIndicationWorker: USBH_SyncGetHubStatus() UNIMPLEMENTED. FIXME\n");
2177  DbgBreakPoint();
2179  }
2180 
2181  if (NT_SUCCESS(Status))
2182  {
2183  if (Port)
2184  {
2185  USBH_ProcessPortStateChange(HubExtension,
2186  Port,
2187  &PortStatus);
2188  }
2189  else
2190  {
2191  DPRINT1("USBH_ChangeIndicationWorker: USBH_ProcessHubStateChange() UNIMPLEMENTED. FIXME\n");
2192  DbgBreakPoint();
2193  }
2194  }
2195  else
2196  {
2197  HubExtension->RequestErrors++;
2198 
2199  if (HubExtension->RequestErrors > USBHUB_MAX_REQUEST_ERRORS)
2200  {
2201  HubExtension->HubFlags |= USBHUB_FDO_FLAG_DEVICE_FAILED;
2202  goto Exit;
2203  }
2204  }
2205  }
2206 
2207  USBH_SubmitStatusChangeTransfer(HubExtension);
2208 
2209 Exit:
2210 
2211  KeReleaseSemaphore(&HubExtension->HubSemaphore,
2213  1,
2214  FALSE);
2215 
2216  if (!InterlockedDecrement(&HubExtension->PendingRequestCount))
2217  {
2218  KeSetEvent(&HubExtension->PendingRequestEvent,
2220  FALSE);
2221  }
2222 
2223  if (!InterlockedDecrement((PLONG)&HubExtension->ResetRequestCount))
2224  {
2225  KeSetEvent(&HubExtension->ResetEvent,
2227  FALSE);
2228 
2229  if (HubExtension->HubFlags & USBHUB_FDO_FLAG_DEFER_CHECK_IDLE)
2230  {
2231  USBH_CheckHubIdle(HubExtension);
2232  }
2233  }
2234 }
CPPORT Port[4]
Definition: headless.c:34
#define USBHUB_PDO_FLAG_POWER_D1_OR_D2
Definition: usbhub.h:74
unsigned char * PUCHAR
Definition: retypes.h:3
#define USBHUB_MAX_REQUEST_ERRORS
Definition: usbhub.h:108
PUSBHUB_FDO_EXTENSION HubExtension
Definition: usbhub.h:209
LONG NTSTATUS
Definition: precomp.h:26
#define LOW_REALTIME_PRIORITY
#define USBHUB_FDO_FLAG_DEVICE_REMOVED
Definition: usbhub.h:46
void DbgBreakPoint()
Definition: mach.c:558
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
smooth NULL
Definition: ftsmooth.c:416
#define STATUS_ASSERTION_FAILURE
Definition: ntstatus.h:946
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static void Exit(void)
Definition: sock.c:1331
#define USBHUB_FDO_FLAG_ESD_RECOVERING
Definition: usbhub.h:41
#define InterlockedDecrement
Definition: armddk.h:52
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:1363
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
Status
Definition: gdiplustypes.h:24
#define USBHUB_FDO_FLAG_DEFER_CHECK_IDLE
Definition: usbhub.h:48
#define EVENT_INCREMENT
Definition: iotypes.h:564
#define USBHUB_FDO_FLAG_DEVICE_STOPPING
Definition: usbhub.h:34
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
VOID NTAPI USBH_ProcessPortStateChange(IN PUSBHUB_FDO_EXTENSION HubExtension, IN USHORT Port, IN PUSB_PORT_STATUS_AND_CHANGE PortStatus)
Definition: usbhub.c:1790
BOOLEAN NTAPI IsBitSet(IN PUCHAR BitMapAddress, IN USHORT Bit)
Definition: usbhub.c:121
NTSTATUS NTAPI USBH_SubmitStatusChangeTransfer(IN PUSBHUB_FDO_EXTENSION HubExtension)
Definition: usbhub.c:2361
#define DPRINT1
Definition: precomp.h:8
struct tagContext Context
Definition: acpixf.h:1012
#define USBHUB_FDO_FLAG_DEVICE_FAILED
Definition: usbhub.h:35
VOID NTAPI USBH_CheckHubIdle(IN PUSBHUB_FDO_EXTENSION HubExtension)
Definition: usbhub.c:3727
signed int * PLONG
Definition: retypes.h:5
NTSTATUS NTAPI USBH_ResetHub(IN PUSBHUB_FDO_EXTENSION HubExtension)
Definition: usbhub.c:2037

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 4086 of file usbhub.c.

4091 {
4092  PDEVICE_OBJECT PortDevice;
4093  PUSBHUB_PORT_PDO_EXTENSION PortExtension;
4094  ULONG Port;
4095  SIZE_T NumberBytes;
4096 
4097  DPRINT("USBH_CheckDeviceIDUnique: idVendor - 0x%04X, idProduct - 0x%04X\n",
4098  idVendor,
4099  idProduct);
4100 
4101  if (!HubExtension->HubDescriptor->bNumberOfPorts)
4102  {
4103  return TRUE;
4104  }
4105 
4106  for (Port = 0; Port < HubExtension->HubDescriptor->bNumberOfPorts; Port++)
4107  {
4108  PortDevice = HubExtension->PortData[Port].DeviceObject;
4109 
4110  if (PortDevice)
4111  {
4112  PortExtension = PortDevice->DeviceExtension;
4113 
4114  if (PortExtension->DeviceDescriptor.idVendor == idVendor &&
4115  PortExtension->DeviceDescriptor.idProduct == idProduct &&
4116  PortExtension->SN_DescriptorLength == SN_DescriptorLength)
4117  {
4118  if (PortExtension->SerialNumber)
4119  {
4120  NumberBytes = RtlCompareMemory(PortExtension->SerialNumber,
4121  SerialNumber,
4122  SN_DescriptorLength);
4123 
4124  if (NumberBytes == SN_DescriptorLength)
4125  {
4126  return FALSE;
4127  }
4128  }
4129  }
4130  }
4131  }
4132 
4133  return TRUE;
4134 }
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:78
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 4161 of file usbhub.c.

4163 {
4165  NTSTATUS Status;
4166  ULONG NumSymbols;
4167  ULONG ix;
4168  PWCHAR pSymbol;
4169  ULONG Length;
4170 
4171  DPRINT("USBH_CheckDeviceLanguage: LanguageId - 0x%04X\n", LanguageId);
4172 
4175  USB_HUB_TAG);
4176 
4177  if (!Descriptor)
4178  {
4180  }
4181 
4183 
4185  0,
4186  0,
4187  Descriptor,
4189  &Length,
4190  TRUE);
4191 
4192  if (!NT_SUCCESS(Status) ||
4193  Length < sizeof(USB_COMMON_DESCRIPTOR))
4194  {
4195  goto Exit;
4196  }
4197 
4198  NumSymbols = (Length -
4199  FIELD_OFFSET(USB_STRING_DESCRIPTOR, bString)) / sizeof(WCHAR);
4200 
4201  pSymbol = Descriptor->bString;
4202 
4203  for (ix = 1; ix < NumSymbols; ix++)
4204  {
4205  if (*pSymbol == (WCHAR)LanguageId)
4206  {
4208  goto Exit;
4209  }
4210 
4211  pSymbol++;
4212  }
4213 
4215 
4216 Exit:
4218  return Status;
4219 }
#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:54
void DPRINT(...)
Definition: polytest.cpp:61
#define USB_HUB_TAG
Definition: usbhub.h:9
__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
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
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
#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:2745
_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 3727 of file usbhub.c.

3728 {
3729  PDEVICE_OBJECT PdoDevice;
3730  PUSBHUB_PORT_PDO_EXTENSION PortExtension;
3731  PUSBHUB_PORT_DATA PortData;
3732  ULONG HubFlags;
3733  ULONG Port;
3734  KIRQL Irql;
3735  BOOLEAN IsHubIdle = FALSE;
3736  BOOLEAN IsAllPortsIdle;
3737  BOOLEAN IsHubCheck = TRUE;
3738 
3739  DPRINT("USBH_CheckHubIdle: FIXME !!! HubExtension - %p\n", HubExtension);
3740 
3741 return; //HACK: delete it line after fixing Power Manager!!!
3742 
3743  KeAcquireSpinLock(&HubExtension->CheckIdleSpinLock, &Irql);
3744 
3745  if (HubExtension->HubFlags & USBHUB_FDO_FLAG_CHECK_IDLE_LOCK)
3746  {
3747  KeReleaseSpinLock(&HubExtension->CheckIdleSpinLock, Irql);
3748  return;
3749  }
3750 
3751  HubExtension->HubFlags |= USBHUB_FDO_FLAG_CHECK_IDLE_LOCK;
3752  KeReleaseSpinLock(&HubExtension->CheckIdleSpinLock, Irql);
3753 
3754  if (USBH_GetRootHubExtension(HubExtension)->SystemPowerState.SystemState != PowerSystemWorking)
3755  {
3756  KeAcquireSpinLock(&HubExtension->CheckIdleSpinLock, &Irql);
3757  HubExtension->HubFlags &= ~USBHUB_FDO_FLAG_CHECK_IDLE_LOCK;
3758  KeReleaseSpinLock(&HubExtension->CheckIdleSpinLock, Irql);
3759  return;
3760  }
3761 
3762  HubFlags = HubExtension->HubFlags;
3763  DPRINT("USBH_CheckHubIdle: HubFlags - %lX\n", HubFlags);
3764 
3765  if (!(HubFlags & USBHUB_FDO_FLAG_DEVICE_STARTED) ||
3766  !(HubFlags & USBHUB_FDO_FLAG_DO_ENUMERATION))
3767  {
3768  goto Exit;
3769  }
3770 
3771  if (HubFlags & USBHUB_FDO_FLAG_NOT_ENUMERATED ||
3772  HubFlags & USBHUB_FDO_FLAG_ENUM_POST_RECOVER ||
3773  HubFlags & USBHUB_FDO_FLAG_DEVICE_FAILED ||
3774  HubFlags & USBHUB_FDO_FLAG_DEVICE_STOPPING ||
3775  HubFlags & USBHUB_FDO_FLAG_DEVICE_REMOVED ||
3776  HubFlags & USBHUB_FDO_FLAG_STATE_CHANGING ||
3777  HubFlags & USBHUB_FDO_FLAG_WAKEUP_START ||
3778  HubFlags & USBHUB_FDO_FLAG_ESD_RECOVERING)
3779  {
3780  goto Exit;
3781  }
3782 
3783  if (HubExtension->ResetRequestCount)
3784  {
3785  HubExtension->HubFlags |= USBHUB_FDO_FLAG_DEFER_CHECK_IDLE;
3786  goto Exit;
3787  }
3788 
3789  HubExtension->HubFlags &= ~USBHUB_FDO_FLAG_DEFER_CHECK_IDLE;
3790 
3791  InterlockedIncrement(&HubExtension->PendingRequestCount);
3792 
3793  KeWaitForSingleObject(&HubExtension->ResetDeviceSemaphore,
3794  Executive,
3795  KernelMode,
3796  FALSE,
3797  NULL);
3798 
3800 
3801  IsAllPortsIdle = TRUE;
3802 
3803  PortData = HubExtension->PortData;
3804 
3805  for (Port = 0;
3806  Port < HubExtension->HubDescriptor->bNumberOfPorts;
3807  Port++)
3808  {
3809  PdoDevice = PortData[Port].DeviceObject;
3810 
3811  if (PdoDevice)
3812  {
3813  PortExtension = PdoDevice->DeviceExtension;
3814 
3815  if (!PortExtension->IdleNotificationIrp)
3816  {
3817  DPRINT("USBH_CheckHubIdle: PortExtension - %p\n",
3818  PortExtension);
3819 
3820  IsAllPortsIdle = FALSE;
3821  IsHubCheck = FALSE;
3822 
3823  break;
3824  }
3825  }
3826  }
3827 
3828  if (IsHubCheck &&
3829  !(HubExtension->HubFlags & USBHUB_FDO_FLAG_WAIT_IDLE_REQUEST))
3830  {
3831  KeClearEvent(&HubExtension->IdleEvent);
3832  HubExtension->HubFlags |= USBHUB_FDO_FLAG_WAIT_IDLE_REQUEST;
3833  IsHubIdle = TRUE;
3834  }
3835 
3837 
3838  KeReleaseSemaphore(&HubExtension->ResetDeviceSemaphore,
3840  1,
3841  FALSE);
3842 
3843  if (!InterlockedDecrement(&HubExtension->PendingRequestCount))
3844  {
3845  KeSetEvent(&HubExtension->PendingRequestEvent,
3847  FALSE);
3848  }
3849 
3850  DPRINT("USBH_CheckHubIdle: IsAllPortsIdle - %x, IsHubIdle - %x\n",
3851  IsAllPortsIdle,
3852  IsHubIdle);
3853 
3854  if (IsAllPortsIdle && IsHubIdle)
3855  {
3856  USBH_FdoSubmitIdleRequestIrp(HubExtension);
3857  }
3858 
3859 Exit:
3860  KeAcquireSpinLock(&HubExtension->CheckIdleSpinLock, &Irql);
3861  HubExtension->HubFlags &= ~USBHUB_FDO_FLAG_CHECK_IDLE_LOCK;
3862  KeReleaseSpinLock(&HubExtension->CheckIdleSpinLock, Irql);
3863 }
CPPORT Port[4]
Definition: headless.c:34
#define TRUE
Definition: types.h:120
#define USBHUB_FDO_FLAG_WAKEUP_START
Definition: usbhub.h:49
VOID NTAPI IoAcquireCancelSpinLock(OUT PKIRQL Irql)
Definition: util.c:56
#define USBHUB_FDO_FLAG_CHECK_IDLE_LOCK
Definition: usbhub.h:53
#define LOW_REALTIME_PRIORITY
#define USBHUB_FDO_FLAG_DEVICE_REMOVED
Definition: usbhub.h:46
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_WAIT_IDLE_REQUEST
Definition: usbhub.h:44
PDEVICE_OBJECT DeviceObject
Definition: usbhub.h:119
UCHAR KIRQL
Definition: env_spec_w32.h:591
PVOID DeviceExtension
Definition: env_spec_w32.h:418
unsigned char BOOLEAN
PUSBHUB_FDO_EXTENSION NTAPI USBH_GetRootHubExtension(IN PUSBHUB_FDO_EXTENSION HubExtension)
Definition: usbhub.c:699
smooth NULL
Definition: ftsmooth.c:416
#define USBHUB_FDO_FLAG_STATE_CHANGING
Definition: usbhub.h:45
void DPRINT(...)
Definition: polytest.cpp:61
#define USBHUB_FDO_FLAG_DO_ENUMERATION
Definition: usbhub.h:52
#define USBHUB_FDO_FLAG_NOT_ENUMERATED
Definition: usbhub.h:55
static void Exit(void)
Definition: sock.c:1331
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
#define USBHUB_FDO_FLAG_ESD_RECOVERING
Definition: usbhub.h:41
#define USBHUB_FDO_FLAG_DEVICE_STARTED
Definition: usbhub.h:33
#define InterlockedDecrement
Definition: armddk.h:52
VOID NTAPI IoReleaseCancelSpinLock(IN KIRQL Irql)
Definition: util.c:150
#define USBHUB_FDO_FLAG_ENUM_POST_RECOVER
Definition: usbhub.h:51
#define USBHUB_FDO_FLAG_DEFER_CHECK_IDLE
Definition: usbhub.h:48
#define EVENT_INCREMENT
Definition: iotypes.h:564
#define InterlockedIncrement
Definition: armddk.h:53
#define USBHUB_FDO_FLAG_DEVICE_STOPPING
Definition: usbhub.h:34
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
#define USBHUB_FDO_FLAG_DEVICE_FAILED
Definition: usbhub.h:35
unsigned int ULONG
Definition: retypes.h:1
VOID NTAPI KeClearEvent(IN PKEVENT Event)
Definition: eventobj.c:22
NTSTATUS NTAPI USBH_FdoSubmitIdleRequestIrp(IN PUSBHUB_FDO_EXTENSION HubExtension)
Definition: usbhub.c:3641

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 3140 of file usbhub.c.

3143 {
3144  PDEVICE_OBJECT PdoDevice;
3145  PUSBHUB_PORT_PDO_EXTENSION PortExtension;
3146  PUSBHUB_PORT_DATA PortData;
3147  ULONG Port;
3148  BOOLEAN Result = FALSE;
3149 
3150  DPRINT("USBH_CheckIdleAbort: ... \n");
3151 
3152  InterlockedIncrement(&HubExtension->PendingRequestCount);
3153 
3154  if (IsWait == TRUE)
3155  {
3156  KeWaitForSingleObject(&HubExtension->ResetDeviceSemaphore,
3157  Executive,
3158  KernelMode,
3159  FALSE,
3160  NULL);
3161  }
3162 
3163  PortData = HubExtension->PortData;
3164 
3165  for (Port = 0; Port < HubExtension->HubDescriptor->bNumberOfPorts; Port++)
3166  {
3167  PdoDevice = PortData[Port].DeviceObject;
3168 
3169  if (PdoDevice)
3170  {
3171  PortExtension = PdoDevice->DeviceExtension;
3172 
3173  if (PortExtension->PoRequestCounter)
3174  {
3175  Result = TRUE;
3176  goto Wait;
3177  }
3178  }
3179  }
3180 
3181  if (IsExtCheck == TRUE)
3182  {
3183  PortData = HubExtension->PortData;
3184 
3185  for (Port = 0;
3186  Port < HubExtension->HubDescriptor->bNumberOfPorts;
3187  Port++)
3188  {
3189  PdoDevice = PortData[Port].DeviceObject;
3190 
3191  if (PdoDevice)
3192  {
3193  PortExtension = PdoDevice->DeviceExtension;
3194  InterlockedExchange(&PortExtension->StateBehindD2, 0);
3195  }
3196  }
3197  }
3198 
3199 Wait:
3200 
3201  if (IsWait == TRUE)
3202  {
3203  KeReleaseSemaphore(&HubExtension->ResetDeviceSemaphore,
3205  1,
3206  FALSE);
3207  }
3208 
3209  if (!InterlockedDecrement(&HubExtension->PendingRequestCount))
3210  {
3211  KeSetEvent(&HubExtension->PendingRequestEvent,
3213  FALSE);
3214  }
3215 
3216  return Result;
3217 }
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:564
#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:1529

Referenced by USBH_FdoIdleNotificationCallback(), and USBH_FdoPower().

◆ USBH_CheckIdleDeferred()

VOID NTAPI USBH_CheckIdleDeferred ( IN PUSBHUB_FDO_EXTENSION  HubExtension)

Definition at line 3876 of file usbhub.c.

3877 {
3878  PUSBHUB_IO_WORK_ITEM HubIoWorkItem;
3879  NTSTATUS Status;
3880 
3881  DPRINT("USBH_CheckIdleDeferred: HubExtension - %p\n", HubExtension);
3882 
3883  Status = USBH_AllocateWorkItem(HubExtension,
3884  &HubIoWorkItem,
3886  0,
3887  NULL,
3889 
3890  DPRINT("USBH_CheckIdleDeferred: HubIoWorkItem - %p\n", HubIoWorkItem);
3891 
3892  if (NT_SUCCESS(Status))
3893  {
3894  USBH_QueueWorkItem(HubExtension, HubIoWorkItem);
3895  }
3896 }
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
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:2710
VOID NTAPI USBH_QueueWorkItem(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PUSBHUB_IO_WORK_ITEM HubIoWorkItem)
Definition: usbhub.c:2836
VOID NTAPI USBH_CheckIdleWorker(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PVOID Context)
Definition: usbhub.c:3867
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 3867 of file usbhub.c.

3869 {
3870  DPRINT("USBH_CheckIdleWorker: ... \n");
3871  USBH_CheckHubIdle(HubExtension);
3872 }
void DPRINT(...)
Definition: polytest.cpp:61
VOID NTAPI USBH_CheckHubIdle(IN PUSBHUB_FDO_EXTENSION HubExtension)
Definition: usbhub.c:3727

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:565
return STATUS_SUCCESS
Definition: btrfs.c:2745

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 3495 of file usbhub.c.

3497 {
3498  PUSBHUB_IDLE_PORT_CONTEXT IdlePortContext;
3499  NTSTATUS NtStatus;
3500  NTSTATUS Status;
3501  BOOLEAN IsFlush = FALSE;
3502 
3503  DPRINT("USBH_CompletePortIdleIrpsWorker ... \n");
3504 
3505  IdlePortContext = Context;
3506  NtStatus = IdlePortContext->Status;
3507 
3509  &IdlePortContext->PwrList,
3510  NtStatus);
3511 
3512  DPRINT1("USBH_CompletePortIdleIrpsWorker: USBH_RegQueryFlushPortPowerIrpsFlag() UNIMPLEMENTED. FIXME\n");
3513  Status = STATUS_NOT_IMPLEMENTED;// USBH_RegQueryFlushPortPowerIrpsFlag(&IsFlush);
3514 
3515  if (NT_SUCCESS(Status))
3516  {
3517  if (IsFlush)
3518  {
3519  USBH_FlushPortPwrList(HubExtension);
3520  }
3521  }
3522 }
VOID NTAPI USBH_HubCompleteQueuedPortIdleIrps(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PLIST_ENTRY IdleList, IN NTSTATUS NtStatus)
Definition: usbhub.c:3029
#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
#define DPRINT1
Definition: precomp.h:8
struct tagContext Context
Definition: acpixf.h:1012
VOID NTAPI USBH_FlushPortPwrList(IN PUSBHUB_FDO_EXTENSION HubExtension)
Definition: usbhub.c:3044

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 4298 of file usbhub.c.

4302 {
4303  ULONG PdoNumber = 0;
4304  WCHAR CharDeviceName[64];
4307  PUSBHUB_PORT_PDO_EXTENSION PortExtension;
4309  LPWSTR SerialNumberBuffer;
4310  BOOLEAN IsHsDevice;
4311  BOOLEAN IsLsDevice;
4312  BOOLEAN IgnoringHwSerial = FALSE;
4313  NTSTATUS Status;
4315 
4316  DPRINT("USBH_CreateDevice: Port - %x, UsbPortStatus - %lX\n",
4317  Port,
4318  UsbPortStatus.AsUshort16);
4319 
4320  do
4321  {
4322  RtlStringCbPrintfW(CharDeviceName,
4323  sizeof(CharDeviceName),
4324  L"\\Device\\USBPDO-%d",
4325  PdoNumber);
4326 
4327  RtlInitUnicodeString(&DeviceName, CharDeviceName);
4328 
4329  Status = IoCreateDevice(HubExtension->Common.SelfDevice->DriverObject,
4330  sizeof(USBHUB_PORT_PDO_EXTENSION),
4331  &DeviceName,
4333  0,
4334  FALSE,
4335  &DeviceObject);
4336 
4337  ++PdoNumber;
4338  }
4340 
4341  if (!NT_SUCCESS(Status))
4342  {
4343  ASSERT(Port > 0);
4344  HubExtension->PortData[Port-1].DeviceObject = DeviceObject;
4345  return Status;
4346  }
4347 
4348  DeviceObject->StackSize = HubExtension->RootHubPdo2->StackSize;
4349 
4350  PortExtension = DeviceObject->DeviceExtension;
4351 
4352  DPRINT("USBH_CreateDevice: PortDevice - %p, <%wZ>\n", DeviceObject, &DeviceName);
4353  DPRINT("USBH_CreateDevice: PortExtension - %p\n", PortExtension);
4354 
4355  RtlZeroMemory(PortExtension, sizeof(USBHUB_PORT_PDO_EXTENSION));
4356 
4357  PortExtension->Common.ExtensionType = USBH_EXTENSION_TYPE_PORT;
4358  PortExtension->Common.SelfDevice = DeviceObject;
4359 
4360  PortExtension->HubExtension = HubExtension;
4361  PortExtension->RootHubExtension = HubExtension;
4362 
4363  PortExtension->PortNumber = Port;
4364  PortExtension->CurrentPowerState.DeviceState = PowerDeviceD0;
4365  PortExtension->IgnoringHwSerial = FALSE;
4366 
4367  KeInitializeSpinLock(&PortExtension->PortTimeoutSpinLock);
4368 
4369  InitializeListHead(&PortExtension->PortPowerList);
4371 
4372  PortExtension->PoRequestCounter = 0;
4373  PortExtension->PendingSystemPoRequest = 0;
4374  PortExtension->PendingDevicePoRequest = 0;
4375  PortExtension->StateBehindD2 = 0;
4376 
4377  SerialNumberBuffer = NULL;
4378 
4379  IsHsDevice = UsbPortStatus.Usb20PortStatus.HighSpeedDeviceAttached;
4380  IsLsDevice = UsbPortStatus.Usb20PortStatus.LowSpeedDeviceAttached;
4381 
4382  if (IsLsDevice == 0)
4383  {
4384  if (IsHsDevice)
4385  {
4387  }
4388  }
4389  else
4390  {
4392  }
4393 
4394  /* Initialize PortExtension->InstanceID */
4396  DestinationString.MaximumLength = 4 * sizeof(WCHAR);
4398 
4401 
4402  if (!NT_SUCCESS(Status))
4403  {
4404  DPRINT1("USBH_CreateDevice: IoCreateDevice() failed - %lX\n", Status);
4405  goto ErrorExit;
4406  }
4407 
4408  Status = USBD_CreateDeviceEx(HubExtension,
4409  &PortExtension->DeviceHandle,
4410  UsbPortStatus,
4411  Port);
4412 
4413  if (!NT_SUCCESS(Status))
4414  {
4415  DPRINT1("USBH_CreateDevice: USBD_CreateDeviceEx() failed - %lX\n", Status);
4416  goto ErrorExit;
4417  }
4418 
4419  Status = USBH_SyncResetPort(HubExtension, Port);
4420 
4421  if (!NT_SUCCESS(Status))
4422  {
4423  DPRINT1("USBH_CreateDevice: USBH_SyncResetPort() failed - %lX\n", Status);
4424  goto ErrorExit;
4425  }
4426 
4427  if (IsWait)
4428  {
4429  USBH_Wait(50);
4430  }
4431 
4432  Status = USBD_InitializeDeviceEx(HubExtension,
4433  PortExtension->DeviceHandle,
4434  (PUCHAR)&PortExtension->DeviceDescriptor,
4435  sizeof(USB_DEVICE_DESCRIPTOR),
4436  (PUCHAR)&PortExtension->ConfigDescriptor,
4438 
4439  if (!NT_SUCCESS(Status))
4440  {
4441  DPRINT1("USBH_CreateDevice: USBD_InitializeDeviceEx() failed - %lX\n", Status);
4442  PortExtension->DeviceHandle = NULL;
4443  goto ErrorExit;
4444  }
4445 
4446  DPRINT1("USBH_RegQueryDeviceIgnoreHWSerNumFlag UNIMPLEMENTED. FIXME\n");
4447  //Status = USBH_RegQueryDeviceIgnoreHWSerNumFlag(PortExtension->DeviceDescriptor.idVendor,
4448  // PortExtension->DeviceDescriptor.idProduct,
4449  // &IgnoringHwSerial);
4450 
4451  if (TRUE)//Status == STATUS_OBJECT_NAME_NOT_FOUND)
4452  {
4453  IgnoringHwSerial = FALSE;
4454  }
4455 
4456  if (IgnoringHwSerial)
4457  {
4458  PortExtension->IgnoringHwSerial = TRUE;
4459  }
4460 
4461  if (PortExtension->DeviceDescriptor.iSerialNumber &&
4462  !PortExtension->IgnoringHwSerial)
4463  {
4465 
4466  USBH_GetSerialNumberString(PortExtension->Common.SelfDevice,
4467  &SerialNumberBuffer,
4468  &PortExtension->SN_DescriptorLength,
4470  PortExtension->DeviceDescriptor.iSerialNumber);
4471 
4472  if (SerialNumberBuffer)
4473  {
4474  if (!USBH_ValidateSerialNumberString((PUSHORT)SerialNumberBuffer))
4475  {
4476  ExFreePoolWithTag(SerialNumberBuffer, USB_HUB_TAG);
4477  SerialNumberBuffer = NULL;
4478  }
4479 
4480  if (SerialNumberBuffer &&
4481  !USBH_CheckDeviceIDUnique(HubExtension,
4482  PortExtension->DeviceDescriptor.idVendor,
4483  PortExtension->DeviceDescriptor.idProduct,
4484  SerialNumberBuffer,
4485  PortExtension->SN_DescriptorLength))
4486  {
4487  ExFreePoolWithTag(SerialNumberBuffer, USB_HUB_TAG);
4488  SerialNumberBuffer = NULL;
4489  }
4490  }
4491 
4493  SerialNumberBuffer);
4494  }
4495 
4496  Status = USBH_ProcessDeviceInformation(PortExtension);
4497 
4498  USBH_PdoSetCapabilities(PortExtension);
4499 
4500  if (NT_SUCCESS(Status))
4501  {
4502  goto Exit;
4503  }
4504 
4505 ErrorExit:
4506 
4508 
4510  NULL);
4511 
4512  if (DeviceHandle)
4513  {
4514  USBD_RemoveDeviceEx(HubExtension, DeviceHandle, 0);
4515  }
4516 
4517  SerialNumberBuffer = InterlockedExchangePointer((PVOID)&PortExtension->SerialNumber,
4518  NULL);
4519 
4520  if (SerialNumberBuffer)
4521  {
4522  ExFreePoolWithTag(SerialNumberBuffer, USB_HUB_TAG);
4523  }
4524 
4525 Exit:
4526 
4527  ASSERT(Port > 0);
4528  HubExtension->PortData[Port-1].DeviceObject = DeviceObject;
4529  return Status;
4530 }
#define DO_DEVICE_INITIALIZING
Definition: env_spec_w32.h:399
#define STATUS_OBJECT_NAME_COLLISION
Definition: udferr_usr.h:150
#define DO_POWER_PAGABLE
#define USBH_EXTENSION_TYPE_PORT
Definition: usbhub.h:29
CPPORT Port[4]
Definition: headless.c:34
const uint16_t * PCWSTR
Definition: typedefs.h:55
PUSB_DEVICE_HANDLE DeviceHandle
Definition: usbhub.h:211
#define USBHUB_PDO_FLAG_INIT_PORT_FAILED
Definition: usbhub.h:63
#define TRUE
Definition: types.h:120
_Inout_ PUSB_DEVICE_HANDLE DeviceHandle
Definition: hubbusif.h:121
NTSTATUS NTAPI USBH_GetSerialNumberString(IN PDEVICE_OBJECT DeviceObject, IN LPWSTR *OutSerialNumber, IN PUSHORT OutDescriptorLength, IN USHORT LanguageId, IN UCHAR Index)
Definition: usbhub.c:4223
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
NTSTATUS NTAPI USBH_Wait(IN ULONG Milliseconds)
Definition: usbhub.c:23
USB_CONFIGURATION_DESCRIPTOR ConfigDescriptor
Definition: usbhub.h:218
WCHAR DeviceName[]
Definition: adapter.cpp:21
#define SUBLANG_ENGLISH_US
Definition: nls.h:222
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:251
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:2481
PVOID DeviceExtension
Definition: env_spec_w32.h:418
unsigned char BOOLEAN
_Out_ _Inout_ POEM_STRING DestinationString
Definition: rtlfuncs.h:1869
smooth NULL
Definition: ftsmooth.c:416
NTSTATUS NTAPI USBH_SyncResetPort(IN PUSBHUB_FDO_EXTENSION HubExtension, IN USHORT Port)
Definition: usbhub.c:471
void DPRINT(...)
Definition: polytest.cpp:61
#define USB_HUB_TAG
Definition: usbhub.h:9
KSPIN_LOCK PortPowerListSpinLock
Definition: usbhub.h:234
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
static void Exit(void)
Definition: sock.c:1331
DEVICE_POWER_STATE DeviceState
Definition: ntpoapi.h:58
NTSTATUS NTAPI USBD_RemoveDeviceEx(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PUSB_DEVICE_HANDLE DeviceHandle, IN ULONG Flags)
Definition: usbhub.c:2457
#define LANG_ENGLISH
Definition: nls.h:52
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
static const WCHAR L[]
Definition: oid.c:1250
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:4086
static __inline NTSTATUS 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:1120
Status
Definition: gdiplustypes.h:24
KSPIN_LOCK PortTimeoutSpinLock
Definition: usbhub.h:226
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
LIST_ENTRY PortPowerList
Definition: usbhub.h:233
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:2427
static VOID ErrorExit(LPTSTR lpszMessage)
Definition: telnetd.c:647
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define USBHUB_PDO_FLAG_PORT_LOW_SPEED
Definition: usbhub.h:64
#define DPRINT1
Definition: precomp.h:8
BOOLEAN NTAPI USBH_ValidateSerialNumberString(IN PUSHORT SerialNumberString)
Definition: usbhub.c:4138
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
VOID NTAPI USBH_PdoSetCapabilities(IN PUSBHUB_PORT_PDO_EXTENSION PortExtension)
Definition: usbhub.c:3900
unsigned short * PUSHORT
Definition: retypes.h:2
NTSTATUS NTAPI USBH_ProcessDeviceInformation(IN PUSBHUB_PORT_PDO_EXTENSION PortExtension)
Definition: usbhub.c:3975

Referenced by USBH_FdoQueryBusRelations().

◆ USBH_DriverUnload()

VOID NTAPI USBH_DriverUnload ( IN PDRIVER_OBJECT  DriverObject)

Definition at line 4940 of file usbhub.c.

4941 {
4942  DPRINT("USBH_DriverUnload: UNIMPLEMENTED\n");
4943 
4945  {
4948  }
4949 }
PWSTR GenericUSBDeviceString
Definition: usbhub.c:19
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
#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 1952 of file usbhub.c.

1953 {
1954  PIRP Irp;
1955  NTSTATUS Status;
1956  KEVENT Event;
1958 
1959  DPRINT("USBH_EnableParentPort ... \n");
1960 
1962 
1964  HubExtension->LowerDevice,
1965  NULL,
1966  0,
1967  NULL,
1968  0,
1969  TRUE,
1970  &Event,
1971  &IoStatusBlock);
1972 
1973  if (!Irp)
1974  {
1976  }
1977 
1978  Status = IoCallDriver(HubExtension->LowerDevice, Irp);
1979 
1980  if (Status == STATUS_PENDING)
1981  {
1983  Suspended,
1984  KernelMode,
1985  FALSE,
1986  NULL);
1987  }
1988  else
1989  {
1991  }
1992 
1993  return IoStatusBlock.Status;
1994 }
#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:434
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 4815 of file usbhub.c.

4817 {
4818  PIO_STACK_LOCATION IoStack;
4819  UCHAR MajorFunction;
4820  NTSTATUS Status;
4821 
4822  IoStack = IoGetCurrentIrpStackLocation(Irp);
4823 
4824  DPRINT("USBH_FdoDispatch: HubExtension - %p, Irp - %p, MajorFunction - %X\n",
4825  HubExtension,
4826  Irp,
4827  IoStack->MajorFunction);
4828 
4829  MajorFunction = IoStack->MajorFunction;
4830 
4831  switch (MajorFunction)
4832  {
4833  case IRP_MJ_CREATE:
4834  case IRP_MJ_CLOSE:
4837  break;
4838 
4839  case IRP_MJ_DEVICE_CONTROL:
4840  Status = USBH_DeviceControl(HubExtension, Irp);
4841  break;
4842 
4843  case IRP_MJ_PNP:
4844  Status = USBH_FdoPnP(HubExtension, Irp, IoStack->MinorFunction);
4845  break;
4846 
4847  case IRP_MJ_POWER:
4848  Status = USBH_FdoPower(HubExtension, Irp, IoStack->MinorFunction);
4849  break;
4850 
4851  case IRP_MJ_SYSTEM_CONTROL:
4852  DPRINT1("USBH_FdoDispatch: USBH_SystemControl() UNIMPLEMENTED. FIXME\n");
4853  /* fall through */
4854 
4856  default:
4857  Status = USBH_PassIrp(HubExtension->LowerDevice, Irp);
4858  break;
4859  }
4860 
4861  return Status;
4862 }
NTSTATUS NTAPI USBH_PassIrp(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: usbhub.c:79
#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_DeviceControl(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PIRP Irp)
Definition: ioctl.c:1130
VOID NTAPI USBH_CompleteIrp(IN PIRP Irp, IN NTSTATUS CompleteStatus)
Definition: usbhub.c:63
void DPRINT(...)
Definition: polytest.cpp:61
#define IRP_MJ_INTERNAL_DEVICE_CONTROL
NTSTATUS NTAPI USBH_FdoPower(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PIRP Irp, IN UCHAR Minor)
Definition: power.c:460
unsigned char UCHAR
Definition: xmlstorage.h:181
#define IRP_MJ_POWER
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
#define IRP_MJ_SYSTEM_CONTROL
Status
Definition: gdiplustypes.h:24
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
#define DPRINT1
Definition: precomp.h:8
return STATUS_SUCCESS
Definition: btrfs.c:2745
NTSTATUS NTAPI USBH_FdoPnP(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PIRP Irp, IN UCHAR Minor)
Definition: pnp.c:2355
#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 3284 of file usbhub.c.

3285 {
3286  PUSBHUB_FDO_EXTENSION HubExtension;
3287  PUSBHUB_PORT_DATA PortData;
3288  PDEVICE_OBJECT PortDevice;
3289  PUSBHUB_PORT_PDO_EXTENSION PortExtension;
3290  PIRP Irp = NULL;
3291  PIRP IdleIrp;
3293  KEVENT Event;
3294  ULONG Port;
3295  PIO_STACK_LOCATION IoStack;
3296  PUSB_IDLE_CALLBACK_INFO CallbackInfo;
3297  BOOLEAN IsReady;
3298  KIRQL OldIrql;
3299  NTSTATUS Status;
3300 
3301  HubExtension = Context;
3302 
3303  DPRINT("USBH_FdoIdleNotificationCallback: HubExtension - %p, HubFlags - %lX\n",
3304  HubExtension,
3305  HubExtension->HubFlags);
3306 
3307  if (HubExtension->HubFlags & (USBHUB_FDO_FLAG_ENUM_POST_RECOVER |
3314  {
3315  DbgBreakPoint();
3316  return;
3317  }
3318 
3319  HubExtension->HubFlags |= USBHUB_FDO_FLAG_GOING_IDLE;
3320 
3321  if (!(HubExtension->HubFlags & USBHUB_FDO_FLAG_PENDING_WAKE_IRP))
3322  {
3323  Status = USBH_FdoSubmitWaitWakeIrp(HubExtension);
3324 
3325  if (Status != STATUS_PENDING)
3326  {
3327  DPRINT("Status != STATUS_PENDING. DbgBreakPoint()\n");
3328  DbgBreakPoint();
3329  HubExtension->HubFlags &= ~USBHUB_FDO_FLAG_GOING_IDLE;
3330  return;
3331  }
3332  }
3333 
3334  InterlockedIncrement(&HubExtension->PendingRequestCount);
3335 
3337  Executive,
3338  KernelMode,
3339  FALSE,
3340  NULL);
3341 
3342  PortData = HubExtension->PortData;
3343  IsReady = TRUE;
3344 
3345  for (Port = 0;
3346  Port < HubExtension->HubDescriptor->bNumberOfPorts;
3347  Port++)
3348  {
3349  PortDevice = PortData[Port].DeviceObject;
3350 
3351  if (PortDevice)
3352  {
3353  PortExtension = PortDevice->DeviceExtension;
3354 
3355  IdleIrp = PortExtension->IdleNotificationIrp;
3356 
3357  if (!IdleIrp)
3358  {
3359  IsReady = FALSE;
3360  goto IdleHub;
3361  }
3362 
3363  IoStack = IoGetCurrentIrpStackLocation(IdleIrp);
3364 
3365  CallbackInfo = IoStack->Parameters.DeviceIoControl.Type3InputBuffer;
3366 
3367  if (!CallbackInfo)
3368  {
3369  IsReady = FALSE;
3370  goto IdleHub;
3371  }
3372 
3373  if (!CallbackInfo->IdleCallback)
3374  {
3375  IsReady = FALSE;
3376  goto IdleHub;
3377  }
3378 
3379  if (PortExtension->PendingSystemPoRequest)
3380  {
3381  IsReady = FALSE;
3382  goto IdleHub;
3383  }
3384 
3385  if (InterlockedCompareExchange(&PortExtension->StateBehindD2,
3386  1,
3387  0))
3388  {
3389  IsReady = FALSE;
3390  goto IdleHub;
3391  }
3392 
3393  DPRINT("USBH_FdoIdleNotificationCallback: IdleContext - %p\n",
3394  CallbackInfo->IdleContext);
3395 
3396  CallbackInfo->IdleCallback(CallbackInfo->IdleContext);
3397 
3398  if (PortExtension->CurrentPowerState.DeviceState == PowerDeviceD0)
3399  {
3400  IsReady = FALSE;
3401  goto IdleHub;
3402  }
3403  }
3404  }
3405 
3406  if (!(HubExtension->HubFlags & USBHUB_FDO_FLAG_DEVICE_STOPPING) &&
3407  (USBH_CheckIdleAbort(HubExtension, FALSE, FALSE) == TRUE))
3408  {
3409  IsReady = FALSE;
3410  }
3411 
3412 IdleHub:
3413 
3416  1,
3417  FALSE);
3418 
3419  if (!InterlockedDecrement(&HubExtension->PendingRequestCount))
3420  {
3421  KeSetEvent(&HubExtension->PendingRequestEvent,
3423  FALSE);
3424  }
3425 
3426  if (!IsReady ||
3427  (HubExtension->HubFlags & USBHUB_FDO_FLAG_DEVICE_SUSPENDED))
3428  {
3429  DPRINT1("USBH_FdoIdleNotificationCallback: HubFlags - %lX\n",
3430  HubExtension->HubFlags);
3431 
3432  HubExtension->HubFlags &= ~(USBHUB_FDO_FLAG_DEVICE_SUSPENDED |
3434 
3435  /* Aborting Idle for Hub */
3437 
3438  if (HubExtension->PendingIdleIrp)
3439  {
3440  Irp = HubExtension->PendingIdleIrp;
3441  HubExtension->PendingIdleIrp = NULL;
3442  }
3443 
3445 
3446  if (Irp)
3447  {
3448  USBH_HubCancelIdleIrp(HubExtension, Irp);
3449  }
3450 
3451  DbgBreakPoint();
3453  }
3454  else
3455  {
3456  PowerState.DeviceState = HubExtension->DeviceWake;
3457 
3458  KeWaitForSingleObject(&HubExtension->IdleSemaphore,
3459  Executive,
3460  KernelMode,
3461  FALSE,
3462  NULL);
3463 
3464  HubExtension->HubFlags &= ~USBHUB_FDO_FLAG_GOING_IDLE;
3465  HubExtension->HubFlags |= USBHUB_FDO_FLAG_DO_SUSPENSE;
3466 
3468 
3469  DPRINT("USBH_FdoIdleNotificationCallback: LowerPdo - %p\n",
3470  HubExtension->LowerPDO);
3471 
3472  DPRINT("USBH_FdoIdleNotificationCallback: PowerState.DeviceState - %x\n",
3474 
3475  Status = PoRequestPowerIrp(HubExtension->LowerPDO,
3477  PowerState,
3479  &Event,
3480  NULL);
3481 
3482  if (Status == STATUS_PENDING)
3483  {
3485  Executive,
3486  KernelMode,
3487  FALSE,
3488  NULL);
3489  }
3490  }
3491 }
#define USBHUB_FDO_FLAG_DO_SUSPENSE
Definition: usbhub.h:56
VOID NTAPI USBH_HubCompletePortIdleIrps(IN PUSBHUB_FDO_EXTENSION HubExtension, IN NTSTATUS NtStatus)
Definition: usbhub.c:3104
CPPORT Port[4]
Definition: headless.c:34
#define TRUE
Definition: types.h:120
_In_ UCHAR _In_ POWER_STATE PowerState
Definition: pofuncs.h:42
NTSTATUS NTAPI USBH_FdoSubmitWaitWakeIrp(IN PUSBHUB_FDO_EXTENSION HubExtension)
Definition: usbhub.c:3232
DEVICE_POWER_STATE DeviceWake
Definition: usbhub.h:159
#define USBHUB_FDO_FLAG_PENDING_WAKE_IRP
Definition: usbhub.h:39
#define USBHUB_FDO_FLAG_WAKEUP_START
Definition: usbhub.h:49
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
VOID NTAPI IoAcquireCancelSpinLock(OUT PKIRQL Irql)
Definition: util.c:56
#define InterlockedCompareExchange
Definition: interlocked.h:104
#define LOW_REALTIME_PRIORITY
#define USBHUB_FDO_FLAG_DEVICE_REMOVED
Definition: usbhub.h:46
void DbgBreakPoint()
Definition: mach.c:558
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
KSEMAPHORE IdleSemaphore
Definition: usbhub.h:177
#define USBHUB_FDO_FLAG_GOING_IDLE
Definition: usbhub.h:57
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:434
VOID NTAPI USBH_HubCancelIdleIrp(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PIRP IdleIrp)
Definition: usbhub.c:3125
PVOID DeviceExtension
Definition: env_spec_w32.h:418
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
#define USBHUB_FDO_FLAG_STATE_CHANGING
Definition: usbhub.h:45
void DPRINT(...)
Definition: polytest.cpp:61
LONG PendingRequestCount
Definition: usbhub.h:180
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:2959
UCHAR bNumberOfPorts
Definition: usb100.h:173
#define STATUS_PENDING
Definition: ntstatus.h:82
#define USBHUB_FDO_FLAG_DEVICE_SUSPENDED
Definition: usbhub.h:58
#define STATUS_CANCELLED
Definition: udferr_usr.h:170
DEVICE_POWER_STATE DeviceState
Definition: ntpoapi.h:58
#define USBHUB_FDO_FLAG_ESD_RECOVERING
Definition: usbhub.h:41
KEVENT PendingRequestEvent
Definition: usbhub.h:181
#define InterlockedDecrement
Definition: armddk.h:52
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
#define IRP_MN_SET_POWER
VOID NTAPI IoReleaseCancelSpinLock(IN KIRQL Irql)
Definition: util.c:150
Status
Definition: gdiplustypes.h:24
#define USBHUB_FDO_FLAG_ENUM_POST_RECOVER
Definition: usbhub.h:51
__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:564
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define InterlockedIncrement
Definition: armddk.h:53
#define USBHUB_FDO_FLAG_DEVICE_STOPPING
Definition: usbhub.h:34
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
KSEMAPHORE ResetDeviceSemaphore
Definition: usbhub.h:182
#define DPRINT1
Definition: precomp.h:8
BOOLEAN NTAPI USBH_CheckIdleAbort(IN PUSBHUB_FDO_EXTENSION HubExtension, IN BOOLEAN IsWait, IN BOOLEAN IsExtCheck)
Definition: usbhub.c:3140
struct tagContext Context
Definition: acpixf.h:1012
#define USBHUB_FDO_FLAG_DEVICE_FAILED
Definition: usbhub.h:35
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:528
PUSBHUB_PORT_DATA PortData
Definition: usbhub.h:167
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2771

Referenced by USBH_FdoSubmitIdleRequestIrp().

◆ USBH_FdoIdleNotificationRequestComplete()

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

Definition at line 3548 of file usbhub.c.

3551 {
3552  PUSBHUB_FDO_EXTENSION HubExtension;
3553  NTSTATUS NtStatus;
3554  PVOID IdleIrp;
3555  KIRQL Irql;
3556  NTSTATUS Status;
3557  PUSBHUB_IO_WORK_ITEM HubIoWorkItem;
3558 
3560 
3561  HubExtension = Context;
3562  HubExtension->HubFlags &= ~USBHUB_FDO_FLAG_WAIT_IDLE_REQUEST;
3563 
3564  IdleIrp = InterlockedExchangePointer((PVOID)&HubExtension->PendingIdleIrp,
3565  NULL);
3566 
3567  DPRINT("USBH_FdoIdleNotificationRequestComplete: IdleIrp - %p\n", IdleIrp);
3568 
3569  if (!InterlockedDecrement(&HubExtension->PendingRequestCount))
3570  {
3572  }
3573 
3575 
3576  NtStatus = Irp->IoStatus.Status;
3577 
3578  DPRINT("USBH_FdoIdleNotificationRequestComplete: NtStatus - %lX\n",
3579  NtStatus);
3580 
3581  if (!NT_SUCCESS(NtStatus) &&
3582  NtStatus != STATUS_POWER_STATE_INVALID &&
3583  !(HubExtension->HubFlags & USBHUB_FDO_FLAG_DEVICE_REMOVED) &&
3584  !(HubExtension->HubFlags & USBHUB_FDO_FLAG_DEVICE_STOPPED))
3585  {
3586  DPRINT("USBH_FdoIdleNotificationRequestComplete: DeviceState - %x\n",
3587  HubExtension->CurrentPowerState.DeviceState);
3588 
3589  if (HubExtension->CurrentPowerState.DeviceState == PowerDeviceD0)
3590  {
3591  PUSBHUB_IDLE_PORT_CONTEXT HubWorkItemBuffer;
3592 
3593  Status = USBH_AllocateWorkItem(HubExtension,
3594  &HubIoWorkItem,
3596  sizeof(USBHUB_IDLE_PORT_CONTEXT),
3597  (PVOID *)&HubWorkItemBuffer,
3599 
3600  if (NT_SUCCESS(Status))
3601  {
3602  HubWorkItemBuffer->Status = NtStatus;
3603 
3604  USBH_HubQueuePortIdleIrps(HubExtension,
3605  &HubWorkItemBuffer->PwrList);
3606 
3607  USBH_QueueWorkItem(HubExtension, HubIoWorkItem);
3608  }
3609  }
3610  else
3611  {
3612  PUSBHUB_IDLE_HUB_CONTEXT HubWorkItemBuffer;
3613 
3614  Status = USBH_AllocateWorkItem(HubExtension,
3615  &HubIoWorkItem,
3617  sizeof(USBHUB_IDLE_HUB_CONTEXT),
3618  (PVOID *)&HubWorkItemBuffer,
3620 
3621  if (NT_SUCCESS(Status))
3622  {
3623  HubWorkItemBuffer->Status = NtStatus;
3624  USBH_QueueWorkItem(HubExtension, HubIoWorkItem);
3625  }
3626  }
3627  }
3628 
3629  if (IdleIrp ||
3630  InterlockedExchange((PLONG)&HubExtension->IdleRequestLock, 1))
3631  {
3632  DPRINT("USBH_FdoIdleNotificationRequestComplete: Irp - %p\n", Irp);
3633  IoFreeIrp(Irp);
3634  }
3635 
3637 }
#define STATUS_MORE_PROCESSING_REQUIRED
Definition: shellext.h:63
VOID NTAPI USBH_HubQueuePortIdleIrps(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PLIST_ENTRY IdleList)
Definition: usbhub.c:2971
#define USBHUB_FDO_FLAG_DEVICE_STOPPED
Definition: usbhub.h:37
_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_DEVICE_REMOVED
Definition: usbhub.h:46
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
_Out_ PKIRQL Irql
Definition: csq.h:179
#define USBHUB_FDO_FLAG_WAIT_IDLE_REQUEST
Definition: usbhub.h:44
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
VOID NTAPI USBH_CompletePortIdleIrpsWorker(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PVOID Context)
Definition: usbhub.c:3495
VOID NTAPI USBH_IdleCompletePowerHubWorker(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PVOID Context)
Definition: usbhub.c:3526
#define InterlockedExchangePointer(Target, Value)
Definition: dshow.h:45
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
DEVICE_POWER_STATE DeviceState
Definition: ntpoapi.h:58
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:2710
KEVENT PendingRequestEvent
Definition: usbhub.h:181
VOID NTAPI USBH_QueueWorkItem(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PUSBHUB_IO_WORK_ITEM HubIoWorkItem)
Definition: usbhub.c:2836
#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
POWER_STATE CurrentPowerState
Definition: usbhub.h:160
#define EVENT_INCREMENT
Definition: iotypes.h:564
#define STATUS_POWER_STATE_INVALID
Definition: ntstatus.h:817
VOID NTAPI IoFreeIrp(IN PIRP Irp)
Definition: irp.c:1666
struct tagContext Context
Definition: acpixf.h:1012
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 3641 of file usbhub.c.

3642 {
3643  NTSTATUS Status;
3644  ULONG HubFlags;
3645  PDEVICE_OBJECT LowerPDO;
3646  PIRP Irp;
3647  PIO_STACK_LOCATION IoStack;
3648  KIRQL Irql;
3649 
3650  DPRINT("USBH_FdoSubmitIdleRequestIrp: HubExtension - %p, PendingIdleIrp - %p\n",
3651  HubExtension,
3652  HubExtension->PendingIdleIrp);
3653 
3654  if (HubExtension->PendingIdleIrp)
3655  {
3657  KeSetEvent(&HubExtension->IdleEvent, EVENT_INCREMENT, FALSE);
3658  return Status;
3659  }
3660 
3661  HubFlags = HubExtension->HubFlags;
3662 
3663  if (HubFlags & USBHUB_FDO_FLAG_DEVICE_STOPPING ||
3664  HubFlags & USBHUB_FDO_FLAG_DEVICE_REMOVED)
3665  {
3666  HubExtension->HubFlags = HubFlags & ~USBHUB_FDO_FLAG_WAIT_IDLE_REQUEST;
3667  KeSetEvent(&HubExtension->IdleEvent, EVENT_INCREMENT, FALSE);
3668  return STATUS_DEVICE_REMOVED;
3669  }
3670 
3671  LowerPDO = HubExtension->LowerPDO;
3672 
3673  HubExtension->IdleCallbackInfo.IdleCallback = USBH_FdoIdleNotificationCallback;
3674  HubExtension->IdleCallbackInfo.IdleContext = HubExtension;
3675 
3676  Irp = IoAllocateIrp(LowerPDO->StackSize, FALSE);
3677 
3678  if (!Irp)
3679  {
3680  HubExtension->HubFlags &= ~USBHUB_FDO_FLAG_WAIT_IDLE_REQUEST;
3682 
3683  KeSetEvent(&HubExtension->IdleEvent, EVENT_INCREMENT, FALSE);
3684  return Status;
3685  }
3686 
3687  IoStack = IoGetNextIrpStackLocation(Irp);
3688 
3690 
3691  IoStack->Parameters.DeviceIoControl.InputBufferLength = sizeof(USB_IDLE_CALLBACK_INFO);
3692  IoStack->Parameters.DeviceIoControl.IoControlCode = IOCTL_INTERNAL_USB_SUBMIT_IDLE_NOTIFICATION;
3693  IoStack->Parameters.DeviceIoControl.Type3InputBuffer = &HubExtension->IdleCallbackInfo;
3694 
3697  HubExtension,
3698  TRUE,
3699  TRUE,
3700  TRUE);
3701 
3702  InterlockedIncrement(&HubExtension->PendingRequestCount);
3703  InterlockedExchange(&HubExtension->IdleRequestLock, 0);
3704 
3705  HubExtension->HubFlags &= ~(USBHUB_FDO_FLAG_DEVICE_SUSPENDED |
3707 
3708  Status = IoCallDriver(HubExtension->LowerPDO, Irp);
3709 
3711 
3712  if (Status == STATUS_PENDING &&
3713  HubExtension->HubFlags & USBHUB_FDO_FLAG_WAIT_IDLE_REQUEST)
3714  {
3715  HubExtension->PendingIdleIrp = Irp;
3716  }
3717 
3719 
3720  KeSetEvent(&HubExtension->IdleEvent, EVENT_INCREMENT, FALSE);
3721 
3722  return Status;
3723 }
#define STATUS_DEVICE_REMOVED
Definition: ntstatus.h:795
#define TRUE
Definition: types.h:120
NTSTATUS NTAPI USBH_FdoIdleNotificationRequestComplete(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context)
Definition: usbhub.c:3548
#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_DEVICE_REMOVED
Definition: usbhub.h:46
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
_Out_ PKIRQL Irql
Definition: csq.h:179
#define USBHUB_FDO_FLAG_WAIT_IDLE_REQUEST
Definition: usbhub.h:44
#define IoSetCompletionRoutine(_Irp, _CompletionRoutine, _Context, _InvokeOnSuccess, _InvokeOnError, _InvokeOnCancel)
Definition: irp.cpp:515
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define USBHUB_FDO_FLAG_GOING_IDLE
Definition: usbhub.h:57
void DPRINT(...)
Definition: polytest.cpp:61
#define STATUS_PENDING
Definition: ntstatus.h:82
#define USBHUB_FDO_FLAG_DEVICE_SUSPENDED
Definition: usbhub.h:58
#define IRP_MJ_INTERNAL_DEVICE_CONTROL
__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:564
#define InterlockedIncrement
Definition: armddk.h:53
#define USBHUB_FDO_FLAG_DEVICE_STOPPING
Definition: usbhub.h:34
#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
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2771
VOID NTAPI USBH_FdoIdleNotificationCallback(IN PVOID Context)
Definition: usbhub.c:3284

Referenced by USBH_CheckHubIdle().

◆ USBH_FdoSubmitWaitWakeIrp()

NTSTATUS NTAPI USBH_FdoSubmitWaitWakeIrp ( IN PUSBHUB_FDO_EXTENSION  HubExtension)

Definition at line 3232 of file usbhub.c.

3233 {
3235  NTSTATUS Status;
3236  PIRP Irp = NULL;
3237  KIRQL Irql;
3238 
3239  DPRINT("USBH_FdoSubmitWaitWakeIrp: ... \n");
3240 
3241  PowerState.SystemState = HubExtension->SystemWake;
3242  HubExtension->HubFlags |= USBHUB_FDO_FLAG_PENDING_WAKE_IRP;
3243 
3244  InterlockedIncrement(&HubExtension->PendingRequestCount);
3245  InterlockedExchange(&HubExtension->FdoWaitWakeLock, 0);
3246 
3247  Status = PoRequestPowerIrp(HubExtension->LowerPDO,
3249  PowerState,
3251  HubExtension,
3252  &Irp);
3253 
3255 
3256  if (Status == STATUS_PENDING)
3257  {
3258  if (HubExtension->HubFlags & USBHUB_FDO_FLAG_PENDING_WAKE_IRP)
3259  {
3260  HubExtension->PendingWakeIrp = Irp;
3261  DPRINT("USBH_FdoSubmitWaitWakeIrp: PendingWakeIrp - %p\n",
3262  HubExtension->PendingWakeIrp);
3263  }
3264  }
3265  else
3266  {
3267  HubExtension->HubFlags &= ~USBHUB_FDO_FLAG_PENDING_WAKE_IRP;
3268 
3269  if (!InterlockedDecrement(&HubExtension->PendingRequestCount))
3270  {
3271  KeSetEvent(&HubExtension->PendingRequestEvent,
3273  FALSE);
3274  }
3275  }
3276 
3278 
3279  return Status;
3280 }
_In_ UCHAR _In_ POWER_STATE PowerState
Definition: pofuncs.h:42
#define USBHUB_FDO_FLAG_PENDING_WAKE_IRP
Definition: usbhub.h:39
_In_ PIRP Irp
Definition: csq.h:116
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
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:3221
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:564
#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:528

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

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

◆ USBH_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 3221 of file usbhub.c.

3226 {
3227  DPRINT("USBH_FdoWaitWakeIrpCompletion ... \n");
3228 }
void DPRINT(...)
Definition: polytest.cpp:61

Referenced by USBH_FdoSubmitWaitWakeIrp().

◆ USBH_FlushPortPwrList()

VOID NTAPI USBH_FlushPortPwrList ( IN PUSBHUB_FDO_EXTENSION  HubExtension)

Definition at line 3044 of file usbhub.c.

3045 {
3046  PDEVICE_OBJECT PortDevice;
3047  PUSBHUB_PORT_PDO_EXTENSION PortExtension;
3049  ULONG Port;
3050 
3051  DPRINT("USBH_FlushPortPwrList ... \n");
3052 
3053  InterlockedIncrement((PLONG)&HubExtension->PendingRequestCount);
3054 
3055  KeWaitForSingleObject(&HubExtension->ResetDeviceSemaphore,
3056  Executive,
3057  KernelMode,
3058  FALSE,
3059  NULL);
3060 
3061  for (Port = 0; Port < HubExtension->HubDescriptor->bNumberOfPorts; ++Port)
3062  {
3063  PortDevice = HubExtension->PortData[Port].DeviceObject;
3064 
3065  if (!PortDevice)
3066  {
3067  continue;
3068  }
3069 
3070  PortExtension = PortDevice->DeviceExtension;
3071 
3072  InterlockedExchange((PLONG)&PortExtension->StateBehindD2, 0);
3073 
3074  while (TRUE)
3075  {
3077  &PortExtension->PortPowerListSpinLock);
3078 
3079  if (!Entry)
3080  {
3081  break;
3082  }
3083 
3084  DPRINT1("USBH_FlushPortPwrList: PortPowerList FIXME\n");
3085  DbgBreakPoint();
3086  }
3087  }
3088 
3089  KeReleaseSemaphore(&HubExtension->ResetDeviceSemaphore,
3091  1,
3092  FALSE);
3093 
3094  if (!InterlockedDecrement((PLONG)&HubExtension->PendingRequestCount))
3095  {
3096  KeSetEvent(&HubExtension->PendingRequestEvent,
3098  FALSE);
3099  }
3100 }
CPPORT Port[4]
Definition: headless.c:34
#define TRUE
Definition: types.h:120
struct _Entry Entry
Definition: kefuncs.h:640
#define LOW_REALTIME_PRIORITY
void DbgBreakPoint()
Definition: mach.c:558
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:117
#define InterlockedExchange
Definition: armddk.h:54
LIST_ENTRY PortPowerList
Definition: usbhub.h:233
#define EVENT_INCREMENT
Definition: iotypes.h:564
#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 2856 of file usbhub.c.

2857 {
2858  PIO_WORKITEM WorkItem;
2859 
2860  DPRINT("USBH_FreeWorkItem: ... \n");
2861 
2862  WorkItem = HubIoWorkItem->HubWorkItem;
2863 
2864  if (HubIoWorkItem->HubWorkItemBuffer)
2865  {
2866  ExFreePoolWithTag(HubIoWorkItem->HubWorkItemBuffer, USB_HUB_TAG);
2867  }
2868 
2869  ExFreePoolWithTag(HubIoWorkItem, USB_HUB_TAG);
2870 
2871  IoFreeWorkItem(WorkItem);
2872 }
VOID NTAPI IoFreeWorkItem(IN PIO_WORKITEM IoWorkItem)
Definition: iowork.c:64
void DPRINT(...)
Definition: polytest.cpp:61
#define USB_HUB_TAG
Definition: usbhub.h:9
#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
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:9
#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:1560
ULONG_PTR SIZE_T
Definition: typedefs.h:78
NTSTATUS NTAPI USBH_SyncGetDeviceConfigurationDescriptor(IN PDEVICE_OBJECT DeviceObject, IN PUSB_CONFIGURATION_DESCRIPTOR ConfigDescriptor, IN ULONG NumberOfBytes, IN PULONG OutLength)
Definition: usbhub.c:913
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:4000
LONG NTSTATUS
Definition: precomp.h:26
_In_ PCWSTR _Inout_ _At_ QueryTable EntryContext
Definition: rtlfuncs.h:3988
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:2745
#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
void DPRINT(...)
Definition: polytest.cpp:61
#define USB_HUB_TAG
Definition: usbhub.h:9
NTSTATUS NTAPI USBH_FdoSyncSubmitUrb(IN PDEVICE_OBJECT FdoDevice, IN PURB Urb)
Definition: usbhub.c:355
#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:1560
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:64
struct _USB_DEVICE_INFORMATION_0 USB_DEVICE_INFORMATION_0
void DPRINT(...)
Definition: polytest.cpp:61
#define USB_HUB_TAG
Definition: usbhub.h:9
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:204
#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:78
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 1899 of file usbhub.c.

1901 {
1902  PIRP Irp;
1903  PIO_STACK_LOCATION IoStack;
1904  NTSTATUS Status;
1905  KEVENT Event;
1907 
1908  DPRINT("USBH_GetPortStatus ... \n");
1909 
1910  *PortStatus = 0;
1911 
1913 
1915  HubExtension->LowerDevice,
1916  NULL,
1917  0,
1918  NULL,
1919  0,
1920  TRUE,
1921  &Event,
1922  &IoStatusBlock);
1923 
1924  if (!Irp)
1925  {
1927  }
1928 
1929  IoStack = IoGetNextIrpStackLocation(Irp);
1930  IoStack->Parameters.Others.Argument1 = PortStatus;
1931 
1932  Status = IoCallDriver(HubExtension->LowerDevice, Irp);
1933 
1934  if (Status == STATUS_PENDING)
1935  {
1937  Suspended,
1938  KernelMode,
1939  FALSE,
1940  NULL);
1941  }
1942  else
1943  {
1945  }
1946 
1947  return IoStatusBlock.Status;
1948 }
#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