ReactOS  0.4.14-dev-1007-g90d795b
ioctl.c File Reference
#include "usbhub.h"
#include <debug.h>
#include "dbg_uhub.h"
Include dependency graph for ioctl.c:

Go to the source code of this file.

Macros

#define NDEBUG
 
#define NDEBUG_USBHUB_IOCTL
 

Functions

NTSTATUS NTAPI USBH_SelectConfigOrInterfaceComplete (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context)
 
NTSTATUS NTAPI USBH_PdoUrbFilter (IN PUSBHUB_PORT_PDO_EXTENSION PortExtension, IN PIRP Irp)
 
NTSTATUS NTAPI USBH_PdoIoctlSubmitUrb (IN PUSBHUB_PORT_PDO_EXTENSION PortExtension, IN PIRP Irp)
 
NTSTATUS NTAPI USBH_PdoIoctlGetPortStatus (IN PUSBHUB_PORT_PDO_EXTENSION PortExtension, IN PIRP Irp)
 
VOID NTAPI USBH_ResetPortWorker (IN PUSBHUB_FDO_EXTENSION HubExtension, IN PVOID Context)
 
NTSTATUS NTAPI USBH_PdoIoctlResetPort (IN PUSBHUB_PORT_PDO_EXTENSION PortExtension, IN PIRP Irp)
 
VOID NTAPI USBH_PortIdleNotificationCancelRoutine (IN PDEVICE_OBJECT Device, IN PIRP Irp)
 
NTSTATUS NTAPI USBH_PortIdleNotificationRequest (IN PUSBHUB_PORT_PDO_EXTENSION PortExtension, IN PIRP Irp)
 
NTSTATUS NTAPI USBH_IoctlGetNodeName (IN PUSBHUB_FDO_EXTENSION HubExtension, IN PIRP Irp)
 
NTSTATUS NTAPI USBH_IoctlGetNodeInformation (IN PUSBHUB_FDO_EXTENSION HubExtension, IN PIRP Irp)
 
NTSTATUS NTAPI USBH_IoctlGetHubCapabilities (IN PUSBHUB_FDO_EXTENSION HubExtension, IN PIRP Irp)
 
NTSTATUS NTAPI USBH_IoctlGetNodeConnectionAttributes (IN PUSBHUB_FDO_EXTENSION HubExtension, IN PIRP Irp)
 
NTSTATUS NTAPI USBH_IoctlGetNodeConnectionInformation (IN PUSBHUB_FDO_EXTENSION HubExtension, IN PIRP Irp, IN BOOLEAN IsExt)
 
NTSTATUS NTAPI USBH_IoctlGetNodeConnectionDriverKeyName (IN PUSBHUB_FDO_EXTENSION HubExtension, IN PIRP Irp)
 
NTSTATUS NTAPI USBH_IoctlGetDescriptor (IN PUSBHUB_FDO_EXTENSION HubExtension, IN PIRP Irp)
 
NTSTATUS NTAPI USBH_DeviceControl (IN PUSBHUB_FDO_EXTENSION HubExtension, IN PIRP Irp)
 
NTSTATUS NTAPI USBH_PdoInternalControl (IN PUSBHUB_PORT_PDO_EXTENSION PortExtension, IN PIRP Irp)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 10 of file ioctl.c.

◆ NDEBUG_USBHUB_IOCTL

#define NDEBUG_USBHUB_IOCTL

Definition at line 13 of file ioctl.c.

Function Documentation

◆ USBH_DeviceControl()

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

Definition at line 1136 of file ioctl.c.

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

Referenced by USBH_FdoDispatch().

◆ USBH_IoctlGetDescriptor()

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

Definition at line 1024 of file ioctl.c.

1026 {
1028  PUSBHUB_PORT_DATA PortData;
1029  PUSB_DESCRIPTOR_REQUEST UsbRequest;
1030  PDEVICE_OBJECT PortDevice;
1031  PUSBHUB_PORT_PDO_EXTENSION PortExtension;
1032  struct _URB_CONTROL_TRANSFER * Urb;
1033  NTSTATUS Status;
1034  ULONG RequestBufferLength;
1035  PIO_STACK_LOCATION IoStack;
1036  ULONG NumPorts;
1037 
1038  IoStack = IoGetCurrentIrpStackLocation(Irp);
1039  BufferLength = IoStack->Parameters.DeviceIoControl.OutputBufferLength;
1040 
1041  DPRINT("USBH_IoctlGetDescriptor: BufferLength - %x\n", BufferLength);
1042 
1043  if (BufferLength < sizeof(USB_DESCRIPTOR_REQUEST))
1044  {
1046  goto Exit;
1047  }
1048 
1049  UsbRequest = Irp->AssociatedIrp.SystemBuffer;
1050  RequestBufferLength = UsbRequest->SetupPacket.wLength;
1051 
1052  if (RequestBufferLength > BufferLength -
1054  {
1055  DPRINT("USBH_IoctlGetDescriptor: RequestBufferLength - %x\n",
1056  RequestBufferLength);
1057 
1059  goto Exit;
1060  }
1061 
1063 
1064  NumPorts = HubExtension->HubDescriptor->bNumberOfPorts;
1065 
1066  if (NumPorts == 0 ||
1067  UsbRequest->ConnectionIndex == 0 ||
1068  UsbRequest->ConnectionIndex > NumPorts)
1069  {
1070  goto Exit;
1071  }
1072 
1073  PortData = HubExtension->PortData + (UsbRequest->ConnectionIndex - 1);
1074  PortDevice = PortData->DeviceObject;
1075 
1076  if (!PortDevice)
1077  {
1078  goto Exit;
1079  }
1080 
1081  PortExtension = PortDevice->DeviceExtension;
1082 
1083  if (UsbRequest->SetupPacket.bmRequest == USB_CONFIGURATION_DESCRIPTOR_TYPE &&
1084  RequestBufferLength == sizeof(USB_CONFIGURATION_DESCRIPTOR))
1085  {
1087 
1088  RtlCopyMemory(&UsbRequest->Data[0],
1089  &PortExtension->ConfigDescriptor,
1091 
1092  Irp->IoStatus.Information = sizeof(USB_DESCRIPTOR_REQUEST) - sizeof(UCHAR) +
1094  goto Exit;
1095  }
1096 
1098  sizeof(struct _URB_CONTROL_DESCRIPTOR_REQUEST),
1099  USB_HUB_TAG);
1100 
1101  if (!Urb)
1102  {
1104  goto Exit;
1105  }
1106 
1107  RtlZeroMemory(Urb, sizeof(struct _URB_CONTROL_DESCRIPTOR_REQUEST));
1108 
1110  Urb->Hdr.Length = sizeof(struct _URB_CONTROL_DESCRIPTOR_REQUEST);
1111 
1112  Urb->TransferBuffer = &UsbRequest->Data[0];
1113  Urb->TransferBufferLength = RequestBufferLength;
1114  Urb->TransferBufferMDL = NULL;
1115  Urb->UrbLink = NULL;
1116 
1118  &UsbRequest->SetupPacket,
1120 
1121  Status = USBH_SyncSubmitUrb(PortExtension->Common.SelfDevice,
1122  (PURB)Urb);
1123 
1124  Irp->IoStatus.Information = (sizeof(USB_DESCRIPTOR_REQUEST) - sizeof(UCHAR)) +
1125  Urb->TransferBufferLength;
1126 
1128 
1129 Exit:
1131  return Status;
1132 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
USB_CONFIGURATION_DESCRIPTOR ConfigDescriptor
Definition: usbhub.h:218
struct _USB_DESCRIPTOR_REQUEST USB_DESCRIPTOR_REQUEST
struct _URB * UrbLink
Definition: usb.h:473
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
PDEVICE_OBJECT DeviceObject
Definition: usbhub.h:119
struct _URB_HEADER Hdr
Definition: usb.h:467
_In_ ULONG BufferLength
Definition: usbdlib.h:225
#define USB_CONFIGURATION_DESCRIPTOR_TYPE
Definition: usb100.h:50
COMMON_DEVICE_EXTENSION Common
Definition: usbhub.h:204
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
NTSTATUS NTAPI USBH_SyncSubmitUrb(IN PDEVICE_OBJECT DeviceObject, IN PURB Urb)
Definition: usbhub.c:250
void DPRINT(...)
Definition: polytest.cpp:61
#define USB_HUB_TAG
Definition: usbhub.h:26
PMDL TransferBufferMDL
Definition: usb.h:472
static void Exit(void)
Definition: sock.c:1331
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
unsigned char UCHAR
Definition: xmlstorage.h:181
VOID NTAPI USBH_CompleteIrp(IN PIRP Irp, IN NTSTATUS CompleteStatus)
Definition: usbhub.c:63
#define URB_FUNCTION_GET_DESCRIPTOR_FROM_DEVICE
Definition: usb.h:97
struct _USB_CONFIGURATION_DESCRIPTOR USB_CONFIGURATION_DESCRIPTOR
Status
Definition: gdiplustypes.h:24
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
UCHAR SetupPacket[8]
Definition: usb.h:475
Definition: usb.h:529
UCHAR Data[ANYSIZE_ARRAY]
Definition: usbioctl.h:337
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
struct _USB_DESCRIPTOR_REQUEST::@3155 SetupPacket
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
return STATUS_SUCCESS
Definition: btrfs.c:2938
PVOID TransferBuffer
Definition: usb.h:471
ULONG TransferBufferLength
Definition: usb.h:470

Referenced by USBH_DeviceControl().

◆ USBH_IoctlGetHubCapabilities()

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

Definition at line 731 of file ioctl.c.

733 {
734  PUSB_HUB_CAPABILITIES Capabilities;
735  PIO_STACK_LOCATION IoStack;
737  ULONG Length;
738  USB_HUB_CAPABILITIES HubCaps;
739 
740  DPRINT("USBH_IoctlGetHubCapabilities ... \n");
741 
742  Capabilities = Irp->AssociatedIrp.SystemBuffer;
743 
744  HubCaps.HubIs2xCapable = (HubExtension->HubFlags & USBHUB_FDO_FLAG_USB20_HUB) ==
746 
748 
749  BufferLength = IoStack->Parameters.DeviceIoControl.OutputBufferLength;
750 
751  if (BufferLength == 0)
752  {
753  Irp->IoStatus.Information = BufferLength;
756  }
757 
758  if (BufferLength <= sizeof(HubCaps))
759  {
760  Length = IoStack->Parameters.DeviceIoControl.OutputBufferLength;
761  }
762  else
763  {
764  Length = sizeof(HubCaps);
765  }
766 
768  RtlCopyMemory(Capabilities, &HubCaps, Length);
769 
770  Irp->IoStatus.Information = Length;
771 
773 
774  return STATUS_SUCCESS;
775 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
_Must_inspect_result_ typedef _Out_ PHIDP_CAPS Capabilities
Definition: hidclass.h:103
_In_ ULONG BufferLength
Definition: usbdlib.h:225
void DPRINT(...)
Definition: polytest.cpp:61
#define USBHUB_FDO_FLAG_USB20_HUB
Definition: usbhub.h:47
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
VOID NTAPI USBH_CompleteIrp(IN PIRP Irp, IN NTSTATUS CompleteStatus)
Definition: usbhub.c:63
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
return STATUS_SUCCESS
Definition: btrfs.c:2938

Referenced by USBH_DeviceControl().

◆ USBH_IoctlGetNodeConnectionAttributes()

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

Definition at line 779 of file ioctl.c.

781 {
782  PUSB_NODE_CONNECTION_ATTRIBUTES Attributes;
783  ULONG ConnectionIndex;
784  ULONG NumPorts;
786  PUSBHUB_PORT_DATA PortData;
787  PIO_STACK_LOCATION IoStack;
789 
790  DPRINT("USBH_IoctlGetNodeConnectionAttributes ... \n");
791 
793  BufferLength = IoStack->Parameters.DeviceIoControl.OutputBufferLength;
794 
795  if (BufferLength < sizeof(USB_NODE_CONNECTION_ATTRIBUTES))
796  {
798  goto Exit;
799  }
800 
801  Attributes = Irp->AssociatedIrp.SystemBuffer;
802 
803  ConnectionIndex = Attributes->ConnectionIndex;
805  Attributes->ConnectionIndex = ConnectionIndex;
806 
808 
809  NumPorts = HubExtension->HubDescriptor->bNumberOfPorts;
810 
811  if (NumPorts == 0 ||
812  ConnectionIndex == 0 ||
813  ConnectionIndex > NumPorts)
814  {
815  goto Exit;
816  }
817 
818  PortData = HubExtension->PortData + (ConnectionIndex - 1);
819 
820  Attributes->ConnectionStatus = PortData->ConnectionStatus;
821  Attributes->PortAttributes = PortData->PortAttributes;
822 
823  Irp->IoStatus.Information = sizeof(USB_NODE_CONNECTION_ATTRIBUTES);
825 
826 Exit:
827 
829  return Status;
830 }
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
USB_CONNECTION_STATUS ConnectionStatus
Definition: usbhub.h:120
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
_In_ ULONG BufferLength
Definition: usbdlib.h:225
void DPRINT(...)
Definition: polytest.cpp:61
static void Exit(void)
Definition: sock.c:1331
VOID NTAPI USBH_CompleteIrp(IN PIRP Irp, IN NTSTATUS CompleteStatus)
Definition: usbhub.c:63
Status
Definition: gdiplustypes.h:24
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
_Must_inspect_result_ _In_ USHORT _In_ PHIDP_PREPARSED_DATA _Out_writes_to_ LengthAttributes PHIDP_EXTENDED_ATTRIBUTES Attributes
Definition: hidpi.h:348
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
return STATUS_SUCCESS
Definition: btrfs.c:2938
ULONG PortAttributes
Definition: usbhub.h:121

Referenced by USBH_DeviceControl().

◆ USBH_IoctlGetNodeConnectionDriverKeyName()

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

Definition at line 947 of file ioctl.c.

949 {
950  PUSBHUB_PORT_DATA PortData;
951  PDEVICE_OBJECT PortDevice;
952  ULONG Length;
955  PIO_STACK_LOCATION IoStack;
958  PUSBHUB_PORT_PDO_EXTENSION PortExtension;
959 
960  DPRINT("USBH_IoctlGetNodeConnectionDriverKeyName ... \n");
961 
963  BufferLength = IoStack->Parameters.DeviceIoControl.OutputBufferLength;
964 
966  HubExtension->HubDescriptor->bNumberOfPorts == 0)
967  {
969  goto Exit;
970  }
971 
972  KeyName = Irp->AssociatedIrp.SystemBuffer;
974 
975  PortData = &HubExtension->PortData[KeyName->ConnectionIndex - 1];
976  PortDevice = PortData->DeviceObject;
977 
978  if (!PortDevice)
979  {
980  goto Exit;
981  }
982 
983  PortExtension = PortDevice->DeviceExtension;
984 
985  if (!(PortExtension->PortPdoFlags & USBHUB_PDO_FLAG_ENUMERATED))
986  {
988  goto Exit;
989  }
990 
992 
993  Status = IoGetDeviceProperty(PortDevice,
996  &KeyName->DriverKeyName,
997  &ResultLength);
998 
1000  {
1002  }
1003 
1005  KeyName->ActualLength = Length;
1006 
1007  if (BufferLength < Length)
1008  {
1009  KeyName->DriverKeyName[0] = 0;
1010  Irp->IoStatus.Information = sizeof(USB_NODE_CONNECTION_DRIVERKEY_NAME);
1011  }
1012  else
1013  {
1014  Irp->IoStatus.Information = Length;
1015  }
1016 
1017 Exit:
1019  return Status;
1020 }
IN CINT OUT PVOID IN ULONG OUT PULONG ResultLength
Definition: conport.c:47
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING KeyName
Definition: ndis.h:4711
#define USBHUB_PDO_FLAG_ENUMERATED
Definition: usbhub.h:82
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
struct _USB_NODE_CONNECTION_DRIVERKEY_NAME USB_NODE_CONNECTION_DRIVERKEY_NAME
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
#define STATUS_INVALID_DEVICE_STATE
Definition: udferr_usr.h:178
PDEVICE_OBJECT DeviceObject
Definition: usbhub.h:119
_In_ ULONG BufferLength
Definition: usbdlib.h:225
PVOID DeviceExtension
Definition: env_spec_w32.h:418
NTSTATUS NTAPI IoGetDeviceProperty(IN PDEVICE_OBJECT DeviceObject, IN DEVICE_REGISTRY_PROPERTY DeviceProperty, IN ULONG BufferLength, OUT PVOID PropertyBuffer, OUT PULONG ResultLength)
Definition: pnpmgr.c:4228
void DPRINT(...)
Definition: polytest.cpp:61
static void Exit(void)
Definition: sock.c:1331
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
VOID NTAPI USBH_CompleteIrp(IN PIRP Irp, IN NTSTATUS CompleteStatus)
Definition: usbhub.c:63
Status
Definition: gdiplustypes.h:24
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
unsigned int ULONG
Definition: retypes.h:1
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
return STATUS_SUCCESS
Definition: btrfs.c:2938

Referenced by USBH_DeviceControl().

◆ USBH_IoctlGetNodeConnectionInformation()

NTSTATUS NTAPI USBH_IoctlGetNodeConnectionInformation ( IN PUSBHUB_FDO_EXTENSION  HubExtension,
IN PIRP  Irp,
IN BOOLEAN  IsExt 
)

Definition at line 834 of file ioctl.c.

837 {
838  PUSBHUB_PORT_DATA PortData;
840  PUSB_NODE_CONNECTION_INFORMATION_EX Info;
841  ULONG ConnectionIndex;
842  ULONG NumPorts;
845  PUSBHUB_PORT_PDO_EXTENSION PortExtension;
846  PIO_STACK_LOCATION IoStack;
847 
848  DPRINT("USBH_IoctlGetNodeConnectionInformation ... \n");
849 
851  BufferLength = IoStack->Parameters.DeviceIoControl.OutputBufferLength;
852 
853  if (BufferLength < (ULONG)FIELD_OFFSET(USB_NODE_CONNECTION_INFORMATION_EX,
854  PipeList))
855  {
857  goto Exit;
858  }
859 
860  Info = Irp->AssociatedIrp.SystemBuffer;
861 
862  ConnectionIndex = Info->ConnectionIndex;
864  Info->ConnectionIndex = ConnectionIndex;
865 
867 
868  NumPorts = HubExtension->HubDescriptor->bNumberOfPorts;
869 
870  if (NumPorts == 0 ||
871  ConnectionIndex == 0 ||
872  ConnectionIndex > NumPorts)
873  {
874  goto Exit;
875  }
876 
877  PortData = HubExtension->PortData + (ConnectionIndex - 1);
878  DeviceObject = PortData->DeviceObject;
879 
880  if (!DeviceObject)
881  {
882  Info->ConnectionStatus = PortData->ConnectionStatus;
883 
884  Irp->IoStatus.Information = FIELD_OFFSET(USB_NODE_CONNECTION_INFORMATION_EX,
885  PipeList);
887  goto Exit;
888  }
889 
890  PortExtension = DeviceObject->DeviceExtension;
891 
892  Info->ConnectionStatus = PortData->ConnectionStatus;
893 
894  Info->DeviceIsHub = (PortExtension->PortPdoFlags &
897 
898  RtlCopyMemory(&Info->DeviceDescriptor,
899  &PortExtension->DeviceDescriptor,
900  sizeof(USB_DEVICE_DESCRIPTOR));
901 
902  if (PortExtension->DeviceHandle)
903  {
904  Status = USBD_GetDeviceInformationEx(PortExtension,
905  HubExtension,
906  Info,
907  BufferLength,
908  PortExtension->DeviceHandle);
909  }
910  else
911  {
913  }
914 
915  if (NT_SUCCESS(Status))
916  {
917  if (!IsExt)
918  {
919  /* IOCTL_USB_GET_NODE_CONNECTION_INFORMATION request reports
920  only low and full speed connections. Info->Speed member
921  is Info->LowSpeed in the non-EX version of the structure */
922 
923  Info->Speed = (Info->Speed == UsbLowSpeed);
924  }
925 
926  Irp->IoStatus.Information = sizeof(USB_NODE_CONNECTION_INFORMATION_EX) +
927  (Info->NumberOfOpenPipes - 1) * sizeof(USB_PIPE_INFO);
928  goto Exit;
929  }
930 
932  {
933  goto Exit;
934  }
935 
936  Irp->IoStatus.Information = FIELD_OFFSET(USB_NODE_CONNECTION_INFORMATION_EX,
937  PipeList);
939 
940 Exit:
942  return Status;
943 }
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: usbhub.c:2558
PUSB_DEVICE_HANDLE DeviceHandle
Definition: usbhub.h:211
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
USB_CONNECTION_STATUS ConnectionStatus
Definition: usbhub.h:120
struct TraceInfo Info
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
PDEVICE_OBJECT DeviceObject
Definition: usbhub.h:119
_In_ ULONG BufferLength
Definition: usbdlib.h:225
PVOID DeviceExtension
Definition: env_spec_w32.h:418
void DPRINT(...)
Definition: polytest.cpp:61
#define USBHUB_PDO_FLAG_HUB_DEVICE
Definition: usbhub.h:61
USB_DEVICE_DESCRIPTOR DeviceDescriptor
Definition: usbhub.h:216
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static void Exit(void)
Definition: sock.c:1331
struct _USB_PIPE_INFO USB_PIPE_INFO
VOID NTAPI USBH_CompleteIrp(IN PIRP Irp, IN NTSTATUS CompleteStatus)
Definition: usbhub.c:63
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
return STATUS_SUCCESS
Definition: btrfs.c:2938

Referenced by USBH_DeviceControl().

◆ USBH_IoctlGetNodeInformation()

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

Definition at line 684 of file ioctl.c.

686 {
687  PUSB_NODE_INFORMATION NodeInfo;
688  PIO_STACK_LOCATION IoStack;
691  BOOLEAN HubIsBusPowered;
692 
693  DPRINT("USBH_IoctlGetNodeInformation ... \n");
694 
696 
697  NodeInfo = Irp->AssociatedIrp.SystemBuffer;
698 
700  BufferLength = IoStack->Parameters.DeviceIoControl.OutputBufferLength;
701 
702  RtlZeroMemory(Irp->AssociatedIrp.SystemBuffer, BufferLength);
703 
704  if (BufferLength < sizeof(USB_NODE_INFORMATION))
705  {
708  return Status;
709  }
710 
711  NodeInfo->NodeType = UsbHub;
712 
714  HubExtension->HubDescriptor,
715  sizeof(USB_HUB_DESCRIPTOR));
716 
717  HubIsBusPowered = USBH_HubIsBusPowered(HubExtension->Common.SelfDevice,
718  HubExtension->HubConfigDescriptor);
719 
720  NodeInfo->u.HubInformation.HubIsBusPowered = HubIsBusPowered;
721 
722  Irp->IoStatus.Information = sizeof(USB_NODE_INFORMATION);
723 
725 
726  return Status;
727 }
union _USB_NODE_INFORMATION::@3154 u
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN HubIsBusPowered
Definition: usbioctl.h:225
USB_HUB_DESCRIPTOR HubDescriptor
Definition: usbioctl.h:224
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
BOOLEAN NTAPI USBH_HubIsBusPowered(IN PDEVICE_OBJECT DeviceObject, IN PUSB_CONFIGURATION_DESCRIPTOR HubConfigDescriptor)
Definition: usbhub.c:1538
_In_ ULONG BufferLength
Definition: usbdlib.h:225
unsigned char BOOLEAN
void DPRINT(...)
Definition: polytest.cpp:61
VOID NTAPI USBH_CompleteIrp(IN PIRP Irp, IN NTSTATUS CompleteStatus)
Definition: usbhub.c:63
Status
Definition: gdiplustypes.h:24
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
USB_HUB_INFORMATION HubInformation
Definition: usbioctl.h:235
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
struct _USB_NODE_INFORMATION USB_NODE_INFORMATION
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
return STATUS_SUCCESS
Definition: btrfs.c:2938
USB_HUB_NODE NodeType
Definition: usbioctl.h:233

Referenced by USBH_DeviceControl().

◆ USBH_IoctlGetNodeName()

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

Definition at line 563 of file ioctl.c.

565 {
566  PUSB_NODE_CONNECTION_NAME ConnectionName;
567  PDEVICE_OBJECT PortDevice;
568  PUSBHUB_PORT_PDO_EXTENSION PortExtension;
569  size_t LengthSkip;
570  PWCHAR Buffer;
574  size_t LengthName;
575  ULONG Length;
577  PIO_STACK_LOCATION IoStack;
579 
580  DPRINT("USBH_IoctlGetNodeName ... \n");
581 
583 
584  ConnectionName = Irp->AssociatedIrp.SystemBuffer;
585 
587  Length = IoStack->Parameters.DeviceIoControl.OutputBufferLength;
588 
589  if (Length < sizeof(USB_NODE_CONNECTION_NAME))
590  {
592  Information = Irp->IoStatus.Information;
593  goto Exit;
594  }
595 
596  if (ConnectionName->ConnectionIndex == 0 ||
597  ConnectionName->ConnectionIndex > HubExtension->HubDescriptor->bNumberOfPorts)
598  {
600  Information = Irp->IoStatus.Information;
601  goto Exit;
602  }
603 
604  PortDevice = HubExtension->PortData[ConnectionName->ConnectionIndex - 1].DeviceObject;
605 
606  if (!PortDevice)
607  {
608  ConnectionName->NodeName[0] = 0;
609  ConnectionName->ActualLength = sizeof(USB_NODE_CONNECTION_NAME);
610 
612  goto Exit;
613  }
614 
615  PortExtension = PortDevice->DeviceExtension;
616 
617  if (!(PortExtension->PortPdoFlags & USBHUB_PDO_FLAG_HUB_DEVICE) ||
618  !(PortExtension->PortPdoFlags & USBHUB_PDO_FLAG_DEVICE_STARTED) ||
620  {
621  ConnectionName->NodeName[0] = 0;
622  ConnectionName->ActualLength = sizeof(USB_NODE_CONNECTION_NAME);
623 
625  goto Exit;
626  }
627 
628  Buffer = PortExtension->SymbolicLinkName.Buffer;
629  BufferLength = PortExtension->SymbolicLinkName.Length;
630 
632 
633  LengthSkip = 0;
634 
635  if (*Buffer == L'\\')
636  {
637  BufferEnd = wcschr(Buffer + 1, L'\\');
638 
639  if (BufferEnd != NULL)
640  {
641  LengthSkip = (BufferEnd + 1 - Buffer) * sizeof(WCHAR);
642  }
643  else
644  {
645  LengthSkip = PortExtension->SymbolicLinkName.Length;
646  }
647  }
648 
649  LengthName = BufferLength - LengthSkip;
650 
651  ConnectionName->ActualLength = 0;
652 
653  RtlZeroMemory(ConnectionName->NodeName,
655 
656  LengthReturned = sizeof(USB_NODE_CONNECTION_NAME) + LengthName;
657 
658  if (Length < LengthReturned)
659  {
660  ConnectionName->NodeName[0] = 0;
661  ConnectionName->ActualLength = LengthReturned;
662 
664  goto Exit;
665  }
666 
667  RtlCopyMemory(&ConnectionName->NodeName[0],
668  &Buffer[LengthSkip / sizeof(WCHAR)],
669  LengthName);
670 
671  ConnectionName->ActualLength = LengthReturned;
672 
675 
676 Exit:
677  Irp->IoStatus.Information = Information;
679  return Status;
680 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define USBHUB_PDO_FLAG_REG_DEV_INTERFACE
Definition: usbhub.h:72
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
UNICODE_STRING SymbolicLinkName
Definition: usbhub.h:207
uint16_t * PWCHAR
Definition: typedefs.h:55
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
uint32_t ULONG_PTR
Definition: typedefs.h:64
#define UNICODE_NULL
_In_ ULONG BufferLength
Definition: usbdlib.h:225
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG _In_ FILE_INFORMATION_CLASS _Out_opt_ PULONG LengthReturned
Definition: fltkernel.h:1306
void DPRINT(...)
Definition: polytest.cpp:61
Definition: bufpool.h:45
struct _USB_NODE_CONNECTION_NAME USB_NODE_CONNECTION_NAME
#define USBHUB_PDO_FLAG_HUB_DEVICE
Definition: usbhub.h:61
WCHAR NodeName[ANYSIZE_ARRAY]
Definition: usbioctl.h:310
_CONST_RETURN wchar_t *__cdecl wcschr(_In_z_ const wchar_t *_Str, wchar_t _Ch)
__wchar_t WCHAR
Definition: xmlstorage.h:180
static void Exit(void)
Definition: sock.c:1331
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define USBHUB_PDO_FLAG_DEVICE_STARTED
Definition: usbhub.h:70
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
static const char * NodeName(const NOTIFICATIONLIST *item)
Definition: changenotify.c:145
static const WCHAR L[]
Definition: oid.c:1250
VOID NTAPI USBH_CompleteIrp(IN PIRP Irp, IN NTSTATUS CompleteStatus)
Definition: usbhub.c:63
_In_ PUCHAR BufferEnd
Definition: usbdlib.h:176
Status
Definition: gdiplustypes.h:24
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
return STATUS_SUCCESS
Definition: btrfs.c:2938
Iosb Information
Definition: create.c:4377

Referenced by USBH_DeviceControl().

◆ USBH_PdoInternalControl()

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

Definition at line 1280 of file ioctl.c.

1282 {
1283  PUSBHUB_FDO_EXTENSION HubExtension;
1286  PIO_STACK_LOCATION IoStack;
1287  PULONG HubCount;
1288 
1289  DPRINT_IOCTL("USBH_PdoInternalControl: PortExtension - %p, Irp - %p\n",
1290  PortExtension,
1291  Irp);
1292 
1293  HubExtension = PortExtension->HubExtension;
1294 
1295  if (PortExtension->PortPdoFlags & USBHUB_PDO_FLAG_NOT_CONNECTED)
1296  {
1298  goto Exit;
1299  }
1300 
1301  if (PortExtension->CurrentPowerState.DeviceState != PowerDeviceD0)
1302  {
1304  goto Exit;
1305  }
1306 
1307  IoStack = IoGetCurrentIrpStackLocation(Irp);
1308  ControlCode = IoStack->Parameters.DeviceIoControl.IoControlCode;
1309 
1311  {
1312  HubExtension = PortExtension->RootHubExtension;
1313  DPRINT("USBH_PdoInternalControl: HubExtension - %p\n", HubExtension);
1314  }
1315 
1316  if (!HubExtension)
1317  {
1319  goto Exit;
1320  }
1321 
1322  switch (ControlCode)
1323  {
1325  return USBH_PdoIoctlSubmitUrb(PortExtension, Irp);
1326 
1327  case IOCTL_INTERNAL_USB_SUBMIT_IDLE_NOTIFICATION:
1328  DPRINT1("USBH_PdoInternalControl: IOCTL_INTERNAL_USB_SUBMIT_IDLE_NOTIFICATION\n");
1329  return USBH_PortIdleNotificationRequest(PortExtension, Irp);
1330 
1332  DPRINT("USBH_PdoInternalControl: IOCTL_INTERNAL_USB_GET_PORT_STATUS\n");
1333  return USBH_PdoIoctlGetPortStatus(PortExtension, Irp);
1334 
1336  DPRINT1("USBH_PdoInternalControl: IOCTL_INTERNAL_USB_RESET_PORT\n");
1337  return USBH_PdoIoctlResetPort(PortExtension, Irp);
1338 
1340  DPRINT1("USBH_PdoInternalControl: IOCTL_INTERNAL_USB_ENABLE_PORT\n");
1341  DbgBreakPoint();
1342  break;
1343 
1345  DPRINT1("USBH_PdoInternalControl: IOCTL_INTERNAL_USB_CYCLE_PORT\n");
1346  DbgBreakPoint();
1347  break;
1348 
1349  case IOCTL_INTERNAL_USB_GET_DEVICE_HANDLE:
1350  DPRINT("USBH_PdoInternalControl: IOCTL_INTERNAL_USB_GET_DEVICE_HANDLE\n");
1351  *(PVOID *)IoStack->Parameters.Others.Argument1 = PortExtension->DeviceHandle;
1353  break;
1354 
1356  DPRINT("USBH_PdoInternalControl: IOCTL_INTERNAL_USB_GET_HUB_COUNT. PortPdoFlags - %lX\n",
1357  PortExtension->PortPdoFlags);
1358 
1359  if (!(PortExtension->PortPdoFlags & USBHUB_PDO_FLAG_HUB_DEVICE))
1360  {
1362  break;
1363  }
1364 
1365  HubCount = IoStack->Parameters.Others.Argument1;
1366 
1367  ++*HubCount;
1368 
1369  Status = USBH_SyncGetHubCount(HubExtension->LowerDevice,
1370  HubCount);
1371 
1372  DPRINT("USBH_PdoInternalControl: *HubCount - %x\n", *HubCount);
1373  break;
1374 
1376  DPRINT("USBH_PdoInternalControl: IOCTL_INTERNAL_USB_GET_ROOTHUB_PDO. PortPdoFlags - %lX\n",
1377  PortExtension->PortPdoFlags);
1378 
1379  if (!(PortExtension->PortPdoFlags & USBHUB_PDO_FLAG_HUB_DEVICE))
1380  {
1381  DbgBreakPoint();
1383 
1384  *(PVOID *)IoStack->Parameters.Others.Argument1 = NULL;
1385 
1387  break;
1388  }
1389 
1390  ASSERT(HubExtension->RootHubPdo);
1391  return USBH_PassIrp(HubExtension->RootHubPdo, Irp);
1392 
1394  DPRINT1("USBH_PdoInternalControl: IOCTL_INTERNAL_USB_GET_HUB_NAME\n");
1395  DbgBreakPoint();
1396  break;
1397 
1399  DPRINT1("USBH_PdoInternalControl: IOCTL_GET_HCD_DRIVERKEY_NAME\n");
1400  DbgBreakPoint();
1401  break;
1402 
1404  DPRINT1("USBH_PdoInternalControl: IOCTL_INTERNAL_USB_GET_BUS_INFO\n");
1405  DbgBreakPoint();
1406  break;
1407 
1409  DPRINT1("USBH_PdoInternalControl: IOCTL_INTERNAL_USB_GET_PARENT_HUB_INFO\n");
1410  DbgBreakPoint();
1411  break;
1412 
1413  default:
1414  DPRINT1("USBH_PdoInternalControl: unhandled IOCTL_ - %lX\n", ControlCode);
1415  break;
1416  }
1417 
1418 Exit:
1420  return Status;
1421 }
#define IOCTL_INTERNAL_USB_SUBMIT_URB
Definition: usbioctl.h:32
NTSTATUS NTAPI USBH_SyncGetHubCount(IN PDEVICE_OBJECT DeviceObject, IN OUT PULONG OutHubCount)
Definition: usbhub.c:781
#define IOCTL_GET_HCD_DRIVERKEY_NAME
Definition: usbioctl.h:165
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define IOCTL_INTERNAL_USB_GET_PARENT_HUB_INFO
Definition: usbioctl.h:68
#define IOCTL_INTERNAL_USB_ENABLE_PORT
Definition: usbioctl.h:47
NTSTATUS NTAPI USBH_PdoIoctlSubmitUrb(IN PUSBHUB_PORT_PDO_EXTENSION PortExtension, IN PIRP Irp)
Definition: ioctl.c:210
#define IOCTL_INTERNAL_USB_GET_HUB_NAME
Definition: usbioctl.h:56
LONG NTSTATUS
Definition: precomp.h:26
#define IOCTL_INTERNAL_USB_GET_BUS_INFO
Definition: usbioctl.h:59
void DbgBreakPoint()
Definition: mach.c:553
#define DPRINT_IOCTL(...)
Definition: dbg_uhub.h:107
#define USBHUB_PDO_FLAG_NOT_CONNECTED
Definition: usbhub.h:67
#define STATUS_DEVICE_POWERED_OFF
Definition: ntstatus.h:183
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
_IRQL_requires_same_ typedef _In_ ULONG ControlCode
Definition: wmitypes.h:55
#define USBHUB_PDO_FLAG_HUB_DEVICE
Definition: usbhub.h:61
#define IOCTL_INTERNAL_USB_CYCLE_PORT
Definition: usbioctl.h:53
#define STATUS_DEVICE_NOT_CONNECTED
Definition: udferr_usr.h:160
static void Exit(void)
Definition: sock.c:1331
PDEVICE_OBJECT LowerDevice
Definition: usbhub.h:150
#define IOCTL_INTERNAL_USB_GET_HUB_COUNT
Definition: usbioctl.h:50
NTSTATUS NTAPI USBH_PassIrp(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: usbhub.c:79
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define IOCTL_INTERNAL_USB_GET_ROOTHUB_PDO
Definition: usbioctl.h:38
VOID NTAPI USBH_CompleteIrp(IN PIRP Irp, IN NTSTATUS CompleteStatus)
Definition: usbhub.c:63
NTSTATUS NTAPI USBH_PdoIoctlGetPortStatus(IN PUSBHUB_PORT_PDO_EXTENSION PortExtension, IN PIRP Irp)
Definition: ioctl.c:239
NTSTATUS NTAPI USBH_PdoIoctlResetPort(IN PUSBHUB_PORT_PDO_EXTENSION PortExtension, IN PIRP Irp)
Definition: ioctl.c:379
Status
Definition: gdiplustypes.h:24
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
#define STATUS_DEVICE_BUSY
Definition: udferr_usr.h:129
unsigned int * PULONG
Definition: retypes.h:1
PDEVICE_OBJECT RootHubPdo
Definition: usbhub.h:151
#define IOCTL_INTERNAL_USB_RESET_PORT
Definition: usbioctl.h:35
#define IOCTL_INTERNAL_USB_GET_PORT_STATUS
Definition: usbioctl.h:44
#define DPRINT1
Definition: precomp.h:8
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:409
unsigned int ULONG
Definition: retypes.h:1
NTSTATUS NTAPI USBH_PortIdleNotificationRequest(IN PUSBHUB_PORT_PDO_EXTENSION PortExtension, IN PIRP Irp)
Definition: ioctl.c:487
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
return STATUS_SUCCESS
Definition: btrfs.c:2938

Referenced by USBH_PdoDispatch().

◆ USBH_PdoIoctlGetPortStatus()

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

Definition at line 239 of file ioctl.c.

241 {
242  PUSBHUB_FDO_EXTENSION HubExtension;
243  PUSBHUB_PORT_DATA PortData;
244  PIO_STACK_LOCATION IoStack;
247 
248  DPRINT("USBH_PdoIoctlGetPortStatus ... \n");
249 
250  HubExtension = PortExtension->HubExtension;
251 
253 
254  KeWaitForSingleObject(&HubExtension->HubSemaphore,
255  Executive,
256  KernelMode,
257  FALSE,
258  NULL);
259 
260  ASSERT(PortExtension->PortNumber > 0);
261  PortData = &HubExtension->PortData[PortExtension->PortNumber - 1];
262 
263  Status = USBH_SyncGetPortStatus(HubExtension,
264  PortExtension->PortNumber,
265  &PortData->PortStatus,
267 
269  PortStatus = IoStack->Parameters.Others.Argument1;
270 
271  *PortStatus = 0;
272 
273  if (PortExtension->Common.SelfDevice == PortData->DeviceObject)
274  {
276  {
278  }
279 
281  {
283  }
284  }
285 
286  KeReleaseSemaphore(&HubExtension->HubSemaphore,
288  1,
289  FALSE);
290 
291  if (!InterlockedDecrement(&HubExtension->PendingRequestCount))
292  {
293  KeSetEvent(&HubExtension->PendingRequestEvent,
295  FALSE);
296  }
297 
299 
300  return Status;
301 }
USB_20_PORT_STATUS Usb20PortStatus
Definition: usb200.h:223
_In_ PIRP Irp
Definition: csq.h:116
#define USBD_PORT_ENABLED
Definition: usbioctl.h:41
USB_PORT_STATUS_AND_CHANGE PortStatus
Definition: usbhub.h:118
LONG NTSTATUS
Definition: precomp.h:26
USHORT CurrentConnectStatus
Definition: usb200.h:133
#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
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
LONG PendingRequestCount
Definition: usbhub.h:180
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
KEVENT PendingRequestEvent
Definition: usbhub.h:181
#define InterlockedDecrement
Definition: armddk.h:52
VOID NTAPI USBH_CompleteIrp(IN PIRP Irp, IN NTSTATUS CompleteStatus)
Definition: usbhub.c:63
_Outptr_ PUSB_DEVICE_HANDLE _In_ PUSB_DEVICE_HANDLE _In_ USHORT PortStatus
Definition: hubbusif.h:40
Status
Definition: gdiplustypes.h:24
#define USBD_PORT_CONNECTED
Definition: usbioctl.h:42
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
#define EVENT_INCREMENT
Definition: iotypes.h:565
#define InterlockedIncrement
Definition: armddk.h:53
LONG NTAPI KeReleaseSemaphore(IN PKSEMAPHORE Semaphore, IN KPRIORITY Increment, IN LONG Adjustment, IN BOOLEAN Wait)
Definition: semphobj.c:54
KSEMAPHORE HubSemaphore
Definition: usbhub.h:196
USHORT PortEnabledDisabled
Definition: usb200.h:134
unsigned int * PULONG
Definition: retypes.h:1
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
PUSBHUB_PORT_DATA PortData
Definition: usbhub.h:167
USB_PORT_STATUS PortStatus
Definition: usb200.h:240
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772

Referenced by USBH_PdoInternalControl().

◆ USBH_PdoIoctlResetPort()

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

Definition at line 379 of file ioctl.c.

381 {
382  PUSBHUB_FDO_EXTENSION HubExtension;
383  PUSBHUB_RESET_PORT_CONTEXT HubWorkItemBuffer;
384  PUSBHUB_IO_WORK_ITEM HubIoWorkItem;
386 
387  HubExtension = PortExtension->HubExtension;
388 
389  DPRINT("USBH_PdoIoctlResetPort ... \n");
390 
391  if (PortExtension->PortPdoFlags & USBHUB_PDO_FLAG_PORT_RESSETING)
392  {
395  return Status;
396  }
397 
398  Status = USBH_AllocateWorkItem(HubExtension,
399  &HubIoWorkItem,
402  (PVOID *)&HubWorkItemBuffer,
404 
405  if (!NT_SUCCESS(Status))
406  {
409  return Status;
410  }
411 
412  PortExtension->PortPdoFlags |= USBHUB_PDO_FLAG_PORT_RESSETING;
414 
415  HubWorkItemBuffer->PortExtension = PortExtension;
416  HubWorkItemBuffer->Irp = Irp;
417 
419 
420  USBH_QueueWorkItem(PortExtension->HubExtension, HubIoWorkItem);
421 
422  return Status;
423 }
VOID NTAPI USBH_ResetPortWorker(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PVOID Context)
Definition: ioctl.c:305
_In_ PIRP Irp
Definition: csq.h:116
VOID NTAPI USBH_QueueWorkItem(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PUSBHUB_IO_WORK_ITEM HubIoWorkItem)
Definition: usbhub.c:2836
LONG NTSTATUS
Definition: precomp.h:26
#define USBHUB_PDO_FLAG_PORT_RESSETING
Definition: usbhub.h:79
void DPRINT(...)
Definition: polytest.cpp:61
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
VOID NTAPI USBH_CompleteIrp(IN PIRP Irp, IN NTSTATUS CompleteStatus)
Definition: usbhub.c:63
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
Status
Definition: gdiplustypes.h:24
PUSBHUB_PORT_PDO_EXTENSION PortExtension
Definition: usbhub.h:270
IoMarkIrpPending(Irp)

Referenced by USBH_PdoInternalControl().

◆ USBH_PdoIoctlSubmitUrb()

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

Definition at line 210 of file ioctl.c.

212 {
213  PUSBHUB_FDO_EXTENSION HubExtension;
214  PURB Urb;
216 
217  DPRINT_IOCTL("USBH_PdoIoctlSubmitUrb ... \n");
218 
219  HubExtension = PortExtension->HubExtension;
220 
221  Urb = URB_FROM_IRP(Irp);
222 
223  if (PortExtension->DeviceHandle == NULL)
224  {
225  Urb->UrbHeader.UsbdDeviceHandle = NULL;
226  Status = USBH_PassIrp(HubExtension->RootHubPdo2, Irp);
227  }
228  else
229  {
230  Urb->UrbHeader.UsbdDeviceHandle = PortExtension->DeviceHandle;
231  Status = USBH_PdoUrbFilter(PortExtension, Irp);
232  }
233 
234  return Status;
235 }
#define URB_FROM_IRP(Irp)
Definition: usb.h:85
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT_IOCTL(...)
Definition: dbg_uhub.h:107
PDEVICE_OBJECT RootHubPdo2
Definition: usbhub.h:152
smooth NULL
Definition: ftsmooth.c:416
struct _URB_HEADER UrbHeader
Definition: usb.h:531
NTSTATUS NTAPI USBH_PdoUrbFilter(IN PUSBHUB_PORT_PDO_EXTENSION PortExtension, IN PIRP Irp)
Definition: ioctl.c:87
NTSTATUS NTAPI USBH_PassIrp(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: usbhub.c:79
Status
Definition: gdiplustypes.h:24
Definition: usb.h:529

Referenced by USBH_PdoInternalControl().

◆ USBH_PdoUrbFilter()

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

Definition at line 87 of file ioctl.c.

89 {
90  PUSB_CONFIGURATION_DESCRIPTOR ConfigDescriptor;
91  PUSBHUB_FDO_EXTENSION HubExtension;
93  PURB Urb;
95  ULONG MaxPower;
96  USBD_STATUS UrbStatus;
97  BOOLEAN IsValidConfig;
98 
99  HubExtension = PortExtension->HubExtension;
100  DeviceObject = PortExtension->Common.SelfDevice;
101 
102  Urb = URB_FROM_IRP(Irp);
103 
104  DPRINT_IOCTL("USBH_PdoUrbFilter: Device - %p, Irp - %p, Urb - %p\n",
105  DeviceObject,
106  Irp,
107  Urb);
108 
109  if (PortExtension->PortPdoFlags & (USBHUB_PDO_FLAG_PORT_RESTORE_FAIL |
111  {
115  }
116 
117  Function = Urb->UrbHeader.Function;
118 
119  switch (Function)
120  {
122  {
123  ConfigDescriptor = Urb->UrbSelectConfiguration.ConfigurationDescriptor;
124 
125  if (ConfigDescriptor)
126  {
127  IsValidConfig = TRUE;
128 
129  if (ConfigDescriptor->bDescriptorType != USB_CONFIGURATION_DESCRIPTOR_TYPE)
130  {
131  DPRINT1("USBH_PdoUrbFilter: Not valid Cfg. bDescriptorType\n");
132  IsValidConfig = FALSE;
134  }
135 
136  if (ConfigDescriptor->bLength < sizeof(USB_CONFIGURATION_DESCRIPTOR))
137  {
138  DPRINT1("USBH_PdoUrbFilter: Size Cfg. descriptor is too small\n");
139  IsValidConfig = FALSE;
141  }
142 
143  if (!IsValidConfig)
144  {
145  Urb->UrbHeader.Status = UrbStatus;
148  }
149 
150  MaxPower = 2 * ConfigDescriptor->MaxPower;
151  PortExtension->MaxPower = MaxPower;
152 
153  if (HubExtension->MaxPowerPerPort < MaxPower)
154  {
155  PortExtension->PortPdoFlags |= USBHUB_PDO_FLAG_INSUFFICIENT_PWR;
156 
157  DPRINT1("USBH_PdoUrbFilter: USBH_InvalidatePortDeviceState() UNIMPLEMENTED. FIXME\n");
158  DbgBreakPoint();
159 
162  }
163  }
164  }
165 
166  /* fall through */
167 
169  {
171 
174  PortExtension,
175  TRUE,
176  TRUE,
177  TRUE);
178 
179  return IoCallDriver(HubExtension->RootHubPdo2, Irp);
180  }
181 
185  {
186  if (PortExtension->PortPdoFlags & USBHUB_PDO_FLAG_DELETE_PENDING)
187  {
190  return STATUS_DELETE_PENDING;
191  }
192 
193  break;
194  }
195 
196  case URB_FUNCTION_GET_MS_FEATURE_DESCRIPTOR:
197  DPRINT1("USBH_PdoUrbFilter: URB_FUNCTION_GET_MS_FEATURE_DESCRIPTOR UNIMPLEMENTED. FIXME\n");
199  return STATUS_NOT_IMPLEMENTED;
200 
201  default:
202  break;
203  }
204 
205  return USBH_PassIrp(HubExtension->RootHubPdo2, Irp);
206 }
#define STATUS_DELETE_PENDING
Definition: ntstatus.h:308
#define USBHUB_PDO_FLAG_INSUFFICIENT_PWR
Definition: usbhub.h:77
#define TRUE
Definition: types.h:120
#define URB_FROM_IRP(Irp)
Definition: usb.h:85
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define USBHUB_PDO_FLAG_PORT_RESSETING
Definition: usbhub.h:79
void DbgBreakPoint()
Definition: mach.c:553
#define IoSetCompletionRoutine(_Irp, _CompletionRoutine, _Context, _InvokeOnSuccess, _InvokeOnError, _InvokeOnCancel)
Definition: irp.cpp:498
FORCEINLINE VOID IoCopyCurrentIrpStackLocationToNext(_Inout_ PIRP Irp)
Definition: iofuncs.h:2820
#define DPRINT_IOCTL(...)
Definition: dbg_uhub.h:107
static LPOVERLAPPED_COMPLETION_ROUTINE Function
Definition: sync.c:684
PDEVICE_OBJECT RootHubPdo2
Definition: usbhub.h:152
#define USB_CONFIGURATION_DESCRIPTOR_TYPE
Definition: usb100.h:50
unsigned char BOOLEAN
struct _URB_HEADER UrbHeader
Definition: usb.h:531
#define USBD_STATUS_INVALID_PARAMETER
Definition: usb.h:192
NTSTATUS NTAPI USBH_PassIrp(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: usbhub.c:79
#define URB_FUNCTION_SELECT_CONFIGURATION
Definition: usb.h:86
LONG USBD_STATUS
Definition: usb.h:165
VOID NTAPI USBH_CompleteIrp(IN PIRP Irp, IN NTSTATUS CompleteStatus)
Definition: usbhub.c:63
#define URB_FUNCTION_SELECT_INTERFACE
Definition: usb.h:87
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
#define USBD_STATUS_INVALID_CONFIGURATION_DESCRIPTOR
Definition: usb.h:203
struct _URB_SELECT_CONFIGURATION UrbSelectConfiguration
Definition: usb.h:533
NTSTATUS NTAPI USBH_SelectConfigOrInterfaceComplete(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context)
Definition: ioctl.c:18
Definition: usb.h:529
#define URB_FUNCTION_ISOCH_TRANSFER
Definition: usb.h:96
unsigned short USHORT
Definition: pedump.c:61
#define USBHUB_PDO_FLAG_PORT_RESTORE_FAIL
Definition: usbhub.h:73
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
#define DPRINT1
Definition: precomp.h:8
#define URB_FUNCTION_CONTROL_TRANSFER
Definition: usb.h:94
unsigned int ULONG
Definition: retypes.h:1
#define USBHUB_PDO_FLAG_DELETE_PENDING
Definition: usbhub.h:68
#define URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER
Definition: usb.h:95

Referenced by USBH_PdoIoctlSubmitUrb().

◆ USBH_PortIdleNotificationCancelRoutine()

VOID NTAPI USBH_PortIdleNotificationCancelRoutine ( IN PDEVICE_OBJECT  Device,
IN PIRP  Irp 
)

Definition at line 427 of file ioctl.c.

429 {
430  PUSBHUB_PORT_PDO_EXTENSION PortExtension;
431  PUSBHUB_FDO_EXTENSION HubExtension;
432  PIRP PendingIdleIrp = NULL;
433  PUSBHUB_IO_WORK_ITEM HubIoWorkItem;
434  PUSBHUB_IDLE_PORT_CANCEL_CONTEXT HubWorkItemBuffer;
436 
437  DPRINT("USBH_PortIdleNotificationCancelRoutine ... \n");
438 
439  PortExtension = Device->DeviceExtension;
441 
442  HubExtension = PortExtension->HubExtension;
443  ASSERT(HubExtension);
444 
445  PortExtension->IdleNotificationIrp = NULL;
446 
447  if (HubExtension->HubFlags & USBHUB_FDO_FLAG_WAIT_IDLE_REQUEST)
448  {
449  PendingIdleIrp = HubExtension->PendingIdleIrp;
450  HubExtension->PendingIdleIrp = NULL;
451  }
452 
453  IoReleaseCancelSpinLock(Irp->CancelIrql);
454 
455  if (PendingIdleIrp)
456  {
457  USBH_HubCancelIdleIrp(HubExtension, PendingIdleIrp);
458  }
459 
460  if (HubExtension->CurrentPowerState.DeviceState == PowerDeviceD0)
461  {
462  goto ErrorExit;
463  }
464 
465  Status = USBH_AllocateWorkItem(HubExtension,
466  &HubIoWorkItem,
469  (PVOID *)&HubWorkItemBuffer,
471 
472  if (NT_SUCCESS(Status))
473  {
474  HubWorkItemBuffer->Irp = Irp;
475  USBH_QueueWorkItem(HubExtension, HubIoWorkItem);
476  return;
477  }
478 
479 ErrorExit:
480 
481  Irp->IoStatus.Status = STATUS_CANCELLED;
483 }
_In_ PIRP _In_ PDEVICE_OBJECT Device
Definition: fatprocs.h:2020
_In_ PIRP Irp
Definition: csq.h:116
VOID NTAPI USBH_QueueWorkItem(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PUSBHUB_IO_WORK_ITEM HubIoWorkItem)
Definition: usbhub.c:2836
PUSBHUB_FDO_EXTENSION HubExtension
Definition: usbhub.h:209
LONG NTSTATUS
Definition: precomp.h:26
VOID NTAPI USBH_IdleCancelPowerHubWorker(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PVOID Context)
Definition: power.c:135
smooth NULL
Definition: ftsmooth.c:416
VOID NTAPI USBH_HubCancelIdleIrp(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PIRP IdleIrp)
Definition: usbhub.c:3125
#define IoCompleteRequest
Definition: irp.c:1240
void DPRINT(...)
Definition: polytest.cpp:61
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_CANCELLED
Definition: udferr_usr.h:170
DEVICE_POWER_STATE DeviceState
Definition: ntpoapi.h:58
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
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 IoReleaseCancelSpinLock(IN KIRQL Irql)
Definition: util.c:150
Status
Definition: gdiplustypes.h:24
POWER_STATE CurrentPowerState
Definition: usbhub.h:160
static VOID ErrorExit(LPTSTR lpszMessage)
Definition: telnetd.c:647
#define USBHUB_PDO_FLAG_IDLE_NOTIFICATION
Definition: usbhub.h:80
#define IO_NO_INCREMENT
Definition: iotypes.h:566
#define USBHUB_FDO_FLAG_WAIT_IDLE_REQUEST
Definition: usbhub.h:44

Referenced by USBH_PortIdleNotificationRequest().

◆ USBH_PortIdleNotificationRequest()

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

Definition at line 487 of file ioctl.c.

489 {
490  PUSBHUB_FDO_EXTENSION HubExtension;
491  PIO_STACK_LOCATION IoStack;
492  PUSB_IDLE_CALLBACK_INFO IdleCallbackInfo;
494  KIRQL Irql;
495 
496  DPRINT("USBH_PortIdleNotificationRequest ... \n");
497 
498  HubExtension = PortExtension->HubExtension;
499 
501 
502  if (PortExtension->IdleNotificationIrp)
503  {
505  Irp->IoStatus.Status = STATUS_DEVICE_BUSY;
507  return STATUS_DEVICE_BUSY;
508  }
509 
511  IdleCallbackInfo = IoStack->Parameters.DeviceIoControl.Type3InputBuffer;
512 
513  if (!IdleCallbackInfo || !IdleCallbackInfo->IdleCallback)
514  {
516 
518  Irp->IoStatus.Status = Status;
520 
521  return Status;
522  }
523 
525 
526  if (Irp->Cancel)
527  {
529  {
532  Irp->IoStatus.Status = STATUS_CANCELLED;
534  }
535  else
536  {
540  }
541  }
542  else
543  {
544  PortExtension->PortPdoFlags |= USBHUB_PDO_FLAG_IDLE_NOTIFICATION;
545 
546  PortExtension->IdleNotificationIrp = Irp;
548 
551 
552  DPRINT("USBH_PortIdleNotificationRequest: IdleNotificationIrp - %p\n",
553  PortExtension->IdleNotificationIrp);
554 
555  USBH_CheckIdleDeferred(HubExtension);
556  }
557 
558  return Status;
559 }
VOID NTAPI USBH_PortIdleNotificationCancelRoutine(IN PDEVICE_OBJECT Device, IN PIRP Irp)
Definition: ioctl.c:427
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
VOID NTAPI IoAcquireCancelSpinLock(OUT PKIRQL Irql)
Definition: util.c:56
VOID NTAPI USBH_CheckIdleDeferred(IN PUSBHUB_FDO_EXTENSION HubExtension)
Definition: usbhub.c:3876
IoSetCancelRoutine(Irp, CancelRoutine)
_Out_ PKIRQL Irql
Definition: csq.h:179
UCHAR KIRQL
Definition: env_spec_w32.h:591
smooth NULL
Definition: ftsmooth.c:416
#define IoCompleteRequest
Definition: irp.c:1240
void DPRINT(...)
Definition: polytest.cpp:61
#define STATUS_PENDING
Definition: ntstatus.h:82
#define STATUS_CANCELLED
Definition: udferr_usr.h:170
VOID NTAPI IoReleaseCancelSpinLock(IN KIRQL Irql)
Definition: util.c:150
Status
Definition: gdiplustypes.h:24
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
#define STATUS_NO_CALLBACK_ACTIVE
Definition: ntstatus.h:712
#define STATUS_DEVICE_BUSY
Definition: udferr_usr.h:129
#define USBHUB_PDO_FLAG_IDLE_NOTIFICATION
Definition: usbhub.h:80
#define IO_NO_INCREMENT
Definition: iotypes.h:566
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
IoMarkIrpPending(Irp)

Referenced by USBH_PdoInternalControl().

◆ USBH_ResetPortWorker()

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

Definition at line 305 of file ioctl.c.

307 {
308  PUSBHUB_RESET_PORT_CONTEXT WorkItemReset;
309  PUSBHUB_PORT_PDO_EXTENSION PortExtension;
312  USHORT Port;
313 
314  DPRINT("USBH_ResetPortWorker ... \n");
315 
316  WorkItemReset = Context;
317 
318  PortExtension = WorkItemReset->PortExtension;
319 
320  if (!HubExtension)
321  {
323  goto Exit;
324  }
325 
326  InterlockedIncrement(&HubExtension->PendingRequestCount);
327 
328  KeWaitForSingleObject(&HubExtension->HubSemaphore,
329  Executive,
330  KernelMode,
331  FALSE,
332  NULL);
333 
334  Port = PortExtension->PortNumber;
335  DeviceHandle = PortExtension->DeviceHandle;
336 
337  ASSERT(Port > 0);
338 
339  if (PortExtension->Common.SelfDevice == HubExtension->PortData[Port-1].DeviceObject &&
340  DeviceHandle != NULL)
341  {
342  USBD_RemoveDeviceEx(HubExtension,
343  DeviceHandle,
345 
346  Status = USBH_ResetDevice(HubExtension,
347  Port,
348  TRUE,
349  FALSE);
350  }
351  else
352  {
354  }
355 
356  KeReleaseSemaphore(&HubExtension->HubSemaphore,
358  1,
359  FALSE);
360 
361  if (!InterlockedDecrement(&HubExtension->PendingRequestCount))
362  {
363  KeSetEvent(&HubExtension->PendingRequestEvent,
365  FALSE);
366  }
367 
368 Exit:
369 
370  PortExtension->PortPdoFlags &= ~USBHUB_PDO_FLAG_PORT_RESSETING;
371 
372  USBH_CompleteIrp(WorkItemReset->Irp, Status);
373 
375 }
CPPORT Port[4]
Definition: headless.c:34
PUSB_DEVICE_HANDLE DeviceHandle
Definition: usbhub.h:211
#define TRUE
Definition: types.h:120
_Inout_ PUSB_DEVICE_HANDLE DeviceHandle
Definition: hubbusif.h:121
NTSTATUS NTAPI USBD_RemoveDeviceEx(IN PUSBHUB_FDO_EXTENSION HubExtension, IN PUSB_DEVICE_HANDLE DeviceHandle, IN ULONG Flags)
Definition: usbhub.c:2457
#define USBD_MARK_DEVICE_BUSY
Definition: hubbusif.h:30
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
#define LOW_REALTIME_PRIORITY
#define USBHUB_PDO_FLAG_PORT_RESSETING
Definition: usbhub.h:79
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: kstypes.h:153
COMMON_DEVICE_EXTENSION Common
Definition: usbhub.h:204
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
NTSTATUS NTAPI USBH_ResetDevice(IN PUSBHUB_FDO_EXTENSION HubExtension, IN USHORT Port, IN BOOLEAN IsKeepDeviceData, IN BOOLEAN IsWait)
Definition: usbhub.c:4534
static void Exit(void)
Definition: sock.c:1331
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define InterlockedDecrement
Definition: armddk.h:52
VOID NTAPI USBH_CompleteIrp(IN PIRP Irp, IN NTSTATUS CompleteStatus)
Definition: usbhub.c:63
Status
Definition: gdiplustypes.h:24
#define EVENT_INCREMENT
Definition: iotypes.h:565
#define InterlockedIncrement
Definition: armddk.h:53
LONG NTAPI KeReleaseSemaphore(IN PKSEMAPHORE Semaphore, IN KPRIORITY Increment, IN LONG Adjustment, IN BOOLEAN Wait)
Definition: semphobj.c:54
unsigned short USHORT
Definition: pedump.c:61
#define USBHUB_PDO_FLAG_PORT_RESTORE_FAIL
Definition: usbhub.h:73
struct tagContext Context
Definition: acpixf.h:1034
PUSBHUB_PORT_PDO_EXTENSION PortExtension
Definition: usbhub.h:270

Referenced by USBH_PdoIoctlResetPort().

◆ USBH_SelectConfigOrInterfaceComplete()

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

Definition at line 18 of file ioctl.c.

21 {
22  PUSBHUB_PORT_PDO_EXTENSION PortExtension;
23  PUSBHUB_FDO_EXTENSION HubExtension;
24  PVOID TimeoutContext; // PUSBHUB_BANDWIDTH_TIMEOUT_CONTEXT
25  PUSBHUB_PORT_DATA PortData = NULL;
27  KIRQL OldIrql;
28  PURB Urb;
29 
30  DPRINT("USBH_SelectConfigOrInterfaceComplete ... \n");
31 
32  if (Irp->PendingReturned)
33  {
35  }
36 
37  PortExtension = Context;
38  HubExtension = PortExtension->HubExtension;
39 
40  ASSERT(PortExtension->PortNumber > 0);
41 
42  if (HubExtension)
43  {
44  PortData = &HubExtension->PortData[PortExtension->PortNumber - 1];
45  }
46 
47  Status = Irp->IoStatus.Status;
48 
49  if (NT_SUCCESS(Irp->IoStatus.Status))
50  {
52 
53  TimeoutContext = PortExtension->BndwTimeoutContext;
54 
55  if (TimeoutContext)
56  {
57  DPRINT1("USBH_SelectConfigOrInterfaceComplete: TimeoutContext != NULL. FIXME\n");
58  DbgBreakPoint();
59  }
60 
62 
65 
66  if (PortData && PortData->ConnectionStatus != DeviceHubNestedTooDeeply)
67  {
69  }
70  }
71  else
72  {
73  Urb = URB_FROM_IRP(Irp);
74  DPRINT1("USBH_SelectConfigOrInterfaceComplete: Status = 0x%lx, UsbdStatus = 0x%lx\n", Status, Urb->UrbHeader.Status);
75  if (Urb->UrbHeader.Status == USBD_STATUS_NO_BANDWIDTH)
76  {
77  DPRINT1("USBH_SelectConfigOrInterfaceComplete: USBD_STATUS_NO_BANDWIDTH. FIXME\n");
78  DbgBreakPoint();
79  }
80  }
81 
82  return Status;
83 }
#define URB_FROM_IRP(Irp)
Definition: usb.h:85
_In_ PIRP Irp
Definition: csq.h:116
PUSBHUB_FDO_EXTENSION HubExtension
Definition: usbhub.h:209
LONG NTSTATUS
Definition: precomp.h:26
USB_CONNECTION_STATUS ConnectionStatus
Definition: usbhub.h:120
void DbgBreakPoint()
Definition: mach.c:553
UCHAR KIRQL
Definition: env_spec_w32.h:591
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
struct _URB_HEADER UrbHeader
Definition: usb.h:531
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:790
Status
Definition: gdiplustypes.h:24
KSPIN_LOCK PortTimeoutSpinLock
Definition: usbhub.h:226
Definition: usb.h:529
#define USBHUB_PDO_FLAG_PORT_RESTORE_FAIL
Definition: usbhub.h:73
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define DPRINT1
Definition: precomp.h:8
struct tagContext Context
Definition: acpixf.h:1034
PUSBHUB_PORT_DATA PortData
Definition: usbhub.h:167
IoMarkIrpPending(Irp)
#define USBHUB_PDO_FLAG_ALLOC_BNDW_FAILED
Definition: usbhub.h:78
#define USBD_STATUS_NO_BANDWIDTH
Definition: usb.h:195

Referenced by USBH_PdoUrbFilter().