VBOXUSBTOOL_DECL(NTSTATUS) VBoxUsbToolGetDeviceSpeed(PDEVICE_OBJECT pDevObj, BOOLEAN *pbIsHigh) { Assert(pbIsHigh); *pbIsHigh = FALSE; PIRP pIrp = IoAllocateIrp(pDevObj->StackSize, FALSE); Assert(pIrp); if (!pIrp) { return STATUS_INSUFFICIENT_RESOURCES; } USB_BUS_INTERFACE_USBDI_V1 BusIf; PIO_STACK_LOCATION pSl = IoGetNextIrpStackLocation(pIrp); pSl->MajorFunction = IRP_MJ_PNP; pSl->MinorFunction = IRP_MN_QUERY_INTERFACE; pSl->Parameters.QueryInterface.InterfaceType = &USB_BUS_INTERFACE_USBDI_GUID; pSl->Parameters.QueryInterface.Size = sizeof (BusIf); pSl->Parameters.QueryInterface.Version = USB_BUSIF_USBDI_VERSION_1; pSl->Parameters.QueryInterface.Interface = (PINTERFACE)&BusIf; pSl->Parameters.QueryInterface.InterfaceSpecificData = NULL; pIrp->IoStatus.Status = STATUS_NOT_SUPPORTED; NTSTATUS Status = VBoxDrvToolIoPostSync(pDevObj, pIrp); Assert(NT_SUCCESS(Status) || Status == STATUS_NOT_SUPPORTED); if (NT_SUCCESS(Status)) { *pbIsHigh = BusIf.IsDeviceHighSpeed(BusIf.BusContext); BusIf.InterfaceDereference(BusIf.BusContext); } IoFreeIrp(pIrp); return Status; }
USB_DK_DEVICE_SPEED UsbDkWdmUsbDeviceGetSpeed(PDEVICE_OBJECT DevObj, PDRIVER_OBJECT DriverObj) { #if !TARGET_OS_WIN_XP CWdmUSBD USBD(DriverObj, DevObj); if (!USBD.Create()) { return NoSpeed; } if (USBD.IsSuperSpeed()) { return SuperSpeed; } if (USBD.IsHighSpeed()) { return HighSpeed; } return FullSpeed; #else //TARGET_OS_WIN_XP // Using IsDeviceHighSpeed() method of USB_BUS_INTERFACE_USBDI_V1 // Note: placing the interface on stack because we release it before return UNREFERENCED_PARAMETER(DriverObj); auto res = NoSpeed; USB_BUS_INTERFACE_USBDI_V1 iusbb; CWdmDeviceAccess wda(DevObj); NTSTATUS status = wda.QueryForInterface( USB_BUS_INTERFACE_USBDI_GUID, reinterpret_cast<INTERFACE &>(iusbb), sizeof(USB_BUS_INTERFACE_USBDI_V1), USB_BUSIF_USBDI_VERSION_1 ); if (NT_SUCCESS(status)) { ASSERT(iusbb.IsDeviceHighSpeed && iusbb.InterfaceDereference); res = iusbb.IsDeviceHighSpeed(iusbb.BusContext) ? HighSpeed : FullSpeed; iusbb.InterfaceDereference(iusbb.BusContext); } return res; #endif //TARGET_OS_WIN_XP }