From 0558c3abc528cb74c5b5bac296cb8b39b78e753b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Poussineau?= Date: Mon, 19 Sep 2005 10:04:07 +0000 Subject: [PATCH] Implement IRP_MN_QUERY_CAPABILITIES, IRP_MN_QUERY_RESOURCES, IRP_MN_QUERY_RESOURCE_REQUIREMENTS, IRP_MN_QUERY_DEVICE_TEXT for USB devices Fix DeviceID and HardwareIDs identifiers returned for root hub (Vendor and Product IDs are still not initialized by Cromwell code) Fix handling of removal IRPs for USB controller svn path=/trunk/; revision=17930 --- reactos/bootdata/hivesys.inf | 1 + reactos/drivers/usb/miniport/common/fdo.c | 22 ++-- reactos/drivers/usb/miniport/common/pdo.c | 33 ++++-- reactos/drivers/usb/usbhub/pdo.c | 131 ++++++++++++++++++++++ reactos/drivers/usb/usbport/usbport.def | 1 + reactos/media/inf/usbport.inf | 8 +- 6 files changed, 174 insertions(+), 22 deletions(-) diff --git a/reactos/bootdata/hivesys.inf b/reactos/bootdata/hivesys.inf index 497c490aec3..d6fa598772d 100644 --- a/reactos/bootdata/hivesys.inf +++ b/reactos/bootdata/hivesys.inf @@ -630,6 +630,7 @@ HKLM,"SYSTEM\CurrentControlSet\Services\usbhub","Tag",0x00010001,0x00000011 HKLM,"SYSTEM\CurrentControlSet\Services\usbhub","DisplayName",0x00000000,"ReactOS USB HUB cromwell-type driver" ;hard coded values HKLM,"SYSTEM\CurrentControlSet\Enum\USB\ROOT_HUB\0000","Service",0x0000000,"usbhub" +HKLM,"SYSTEM\CurrentControlSet\Enum\USB\ROOT_HUB20\0000","Service",0x0000000,"usbhub" ; ReactOS PCNet NIC driver ; To use the AMD supplied driver change the driver name to pcntn5m.sys diff --git a/reactos/drivers/usb/miniport/common/fdo.c b/reactos/drivers/usb/miniport/common/fdo.c index 14f68d06fe7..936bf385db5 100644 --- a/reactos/drivers/usb/miniport/common/fdo.c +++ b/reactos/drivers/usb/miniport/common/fdo.c @@ -190,7 +190,7 @@ UsbMpPnpFdo( switch (MinorFunction) { - case IRP_MN_START_DEVICE: + case IRP_MN_START_DEVICE: /* 0x00 */ { Status = ForwardIrpAndWait(DeviceObject, Irp); if (NT_SUCCESS(Status) && NT_SUCCESS(Irp->IoStatus.Status)) @@ -198,12 +198,15 @@ UsbMpPnpFdo( break; } - case IRP_MN_REMOVE_DEVICE: - case IRP_MN_QUERY_REMOVE_DEVICE: - case IRP_MN_CANCEL_REMOVE_DEVICE: - case IRP_MN_SURPRISE_REMOVAL: + case IRP_MN_QUERY_REMOVE_DEVICE: /* 0x01 */ + case IRP_MN_CANCEL_REMOVE_DEVICE: /* 0x03 */ + { + return ForwardIrpAndForget(DeviceObject, Irp); + } - case IRP_MN_STOP_DEVICE: + case IRP_MN_REMOVE_DEVICE: /* 0x02 */ + case IRP_MN_STOP_DEVICE: /* 0x04 */ + case IRP_MN_SURPRISE_REMOVAL: /* 0x17 */ { Status = ForwardIrpAndWait(DeviceObject, Irp); if (NT_SUCCESS(Status) && NT_SUCCESS(Irp->IoStatus.Status)) @@ -211,8 +214,9 @@ UsbMpPnpFdo( IoDeleteDevice(DeviceObject); // just delete device for now break; } - case IRP_MN_QUERY_STOP_DEVICE: - case IRP_MN_CANCEL_STOP_DEVICE: + + case IRP_MN_QUERY_STOP_DEVICE: /* 0x05 */ + case IRP_MN_CANCEL_STOP_DEVICE: /* 0x06 */ { Status = STATUS_SUCCESS; break; @@ -244,7 +248,7 @@ UsbMpPnpFdo( default: { - DPRINT1("USBMP: unknown minor function 0x%lx\n", MinorFunction); + DPRINT1("USBMP: IRP_MJ_PNP / unknown minor function 0x%lx\n", MinorFunction); return ForwardIrpAndForget(DeviceObject, Irp); } } diff --git a/reactos/drivers/usb/miniport/common/pdo.c b/reactos/drivers/usb/miniport/common/pdo.c index ca52d50def9..f4ee120346f 100644 --- a/reactos/drivers/usb/miniport/common/pdo.c +++ b/reactos/drivers/usb/miniport/common/pdo.c @@ -80,36 +80,49 @@ UsbMpPdoQueryId( ULONG IdType; UNICODE_STRING SourceString; UNICODE_STRING String; + struct usb_device *roothub; NTSTATUS Status = STATUS_SUCCESS; IdType = IoGetCurrentIrpStackLocation(Irp)->Parameters.QueryId.IdType; DeviceExtension = (PUSBMP_DEVICE_EXTENSION)DeviceObject->DeviceExtension; RtlInitUnicodeString(&String, NULL); + DeviceExtension = (PUSBMP_DEVICE_EXTENSION)DeviceExtension->FunctionalDeviceObject->DeviceExtension; + roothub = ((struct usb_hcd*)DeviceExtension->pdev->data)->self.root_hub; switch (IdType) { case BusQueryDeviceID: { DPRINT("USBMP: IRP_MJ_PNP / IRP_MN_QUERY_ID / BusQueryDeviceID\n"); - RtlInitUnicodeString(&SourceString, L"USB\\ROOT_HUB"); + if (roothub->speed == USB_SPEED_LOW || roothub->speed == USB_SPEED_FULL) + RtlInitUnicodeString(&SourceString, L"USB\\ROOT_HUB"); /* USB 1.1 */ + else + RtlInitUnicodeString(&SourceString, L"USB\\ROOT_HUB20"); /* USB 2.0 */ break; } case BusQueryHardwareIDs: { - //CHAR Buffer[2][40]; + CHAR Buffer[2][40]; + PCHAR RootHubName; + USHORT Vendor, Product, Revision; + DPRINT("USBMP: IRP_MJ_PNP / IRP_MN_QUERY_ID / BusQueryHardwareIDs\n"); - /*FIXME: sprintf(Buffer[0], "USB\\VID%04X&PID%04X&REV%04X", - VENDOR, - PRODUCT, - REV); + Vendor = DeviceExtension->pdev->vendor; + Product = DeviceExtension->pdev->device; + Revision = 0; /* FIXME */ + + sprintf(Buffer[0], "USB\\VID%04X&PID%04X&REV%04X", + Vendor, Product, Revision); sprintf(Buffer[1], "USB\\VID%04X&PID%04X", - VENDOR, - PRODUCT); + Vendor, Product); + if (roothub->speed == USB_SPEED_LOW || roothub->speed == USB_SPEED_FULL) + RootHubName = "USB\\ROOT_HUB"; /* USB 1.1 */ + else + RootHubName = "USB\\ROOT_HUB20"; /* USB 2.0 */ Status = UsbMpInitMultiSzString( &SourceString, - Buffer[0], Buffer[1], "USB\\ROOT_HUB", NULL);*/ - Status = UsbMpInitMultiSzString(&SourceString, "USB\\ROOT_HUB", NULL); + Buffer[0], Buffer[1], RootHubName, NULL); break; } case BusQueryCompatibleIDs: diff --git a/reactos/drivers/usb/usbhub/pdo.c b/reactos/drivers/usb/usbhub/pdo.c index 22edfd98859..fec7c3743b1 100644 --- a/reactos/drivers/usb/usbhub/pdo.c +++ b/reactos/drivers/usb/usbhub/pdo.c @@ -133,6 +133,61 @@ UsbhubPdoQueryId( return Status; } +static NTSTATUS +UsbhubPdoQueryDeviceText( + IN PDEVICE_OBJECT DeviceObject, + IN PIRP Irp, + OUT ULONG_PTR* Information) +{ + PHUB_DEVICE_EXTENSION DeviceExtension; + DEVICE_TEXT_TYPE DeviceTextType; + LCID LocaleId; + + DeviceTextType = IoGetCurrentIrpStackLocation(Irp)->Parameters.QueryDeviceText.DeviceTextType; + LocaleId = IoGetCurrentIrpStackLocation(Irp)->Parameters.QueryDeviceText.LocaleId; + DeviceExtension = (PHUB_DEVICE_EXTENSION)DeviceObject->DeviceExtension; + + switch (DeviceTextType) + { + /*case DeviceTextDescription: + { + DPRINT1("Usbhub: IRP_MJ_PNP / IRP_MN_QUERY_DEVICE_TEXT / DeviceTextDescription\n"); + return STATUS_NOT_IMPLEMENTED; + }*/ + case DeviceTextLocationInformation: + { + int size; + char *buf; + + DPRINT("Usbhub: IRP_MJ_PNP / IRP_MN_QUERY_DEVICE_TEXT / DeviceTextLocationInformation\n"); + if (!DeviceExtension->dev->descriptor.iProduct) + return STATUS_NOT_SUPPORTED; + + size = usb_get_string(DeviceExtension->dev, LocaleId, DeviceExtension->dev->descriptor.iProduct, NULL, 0); + if (size < 2) + { + DPRINT("Usbhub: usb_get_string() failed\n"); + return STATUS_IO_DEVICE_ERROR; + } + buf = ExAllocatePool(PagedPool, size); + if (buf == NULL) + return STATUS_INSUFFICIENT_RESOURCES; + size = usb_get_string(DeviceExtension->dev, LocaleId, DeviceExtension->dev->descriptor.iProduct, buf, size); + if (size < 0) + { + DPRINT("Usbhub: usb_get_string() failed\n"); + ExFreePool(buf); + return STATUS_IO_DEVICE_ERROR; + } + *Information = (ULONG_PTR)buf; + return STATUS_SUCCESS; + } + default: + DPRINT1("Usbhub: IRP_MJ_PNP / IRP_MN_QUERY_DEVICE_TEXT / unknown device text type 0x%lx\n", DeviceTextType); + return STATUS_NOT_SUPPORTED; + } +} + NTSTATUS STDCALL UsbhubPnpPdo( IN PDEVICE_OBJECT DeviceObject, @@ -154,6 +209,82 @@ UsbhubPnpPdo( Status = UsbhubPdoStartDevice(DeviceObject, Irp); break; } + case IRP_MN_QUERY_CAPABILITIES: /* 0x09 */ + { + PDEVICE_CAPABILITIES DeviceCapabilities; + ULONG i; + DPRINT("Usbhub: IRP_MJ_PNP / IRP_MN_QUERY_CAPABILITIES\n"); + + DeviceCapabilities = (PDEVICE_CAPABILITIES)Stack->Parameters.DeviceCapabilities.Capabilities; + /* FIXME: capabilities can change with connected device */ + DeviceCapabilities->LockSupported = TRUE; + DeviceCapabilities->EjectSupported = FALSE; + DeviceCapabilities->Removable = FALSE; + DeviceCapabilities->DockDevice = FALSE; + DeviceCapabilities->UniqueID = FALSE; + DeviceCapabilities->SilentInstall = TRUE; + DeviceCapabilities->RawDeviceOK = FALSE; + DeviceCapabilities->SurpriseRemovalOK = FALSE; + DeviceCapabilities->HardwareDisabled = FALSE; /* FIXME */ + //DeviceCapabilities->NoDisplayInUI = FALSE; /* FIXME */ + DeviceCapabilities->DeviceState[0] = PowerDeviceD0; /* FIXME */ + for (i = 0; i < PowerSystemMaximum; i++) + DeviceCapabilities->DeviceState[i] = PowerDeviceD3; /* FIXME */ + //DeviceCapabilities->DeviceWake = PowerDeviceUndefined; /* FIXME */ + DeviceCapabilities->D1Latency = 0; /* FIXME */ + DeviceCapabilities->D2Latency = 0; /* FIXME */ + DeviceCapabilities->D3Latency = 0; /* FIXME */ + Status = STATUS_SUCCESS; + break; + } + case IRP_MN_QUERY_RESOURCES: /* 0x0a */ + { + PCM_RESOURCE_LIST ResourceList; + + DPRINT("Usbhub: IRP_MJ_PNP / IRP_MN_QUERY_RESOURCES\n"); + ResourceList = ExAllocatePool(PagedPool, sizeof(CM_RESOURCE_LIST)); + if (!ResourceList) + { + DPRINT("Usbhub: ExAllocatePool() failed\n"); + Status = STATUS_INSUFFICIENT_RESOURCES; + } + else + { + ResourceList->Count = 0; + Information = (ULONG_PTR)ResourceList; + Status = STATUS_SUCCESS; + } + break; + } + case IRP_MN_QUERY_RESOURCE_REQUIREMENTS: /* 0x0b */ + { + PIO_RESOURCE_REQUIREMENTS_LIST ResourceList; + + DPRINT("Usbhub: IRP_MJ_PNP / IRP_MN_QUERY_RESOURCE_REQUIREMENTS\n"); + ResourceList = ExAllocatePool(PagedPool, sizeof(IO_RESOURCE_REQUIREMENTS_LIST)); + if (!ResourceList) + { + DPRINT("Usbhub: ExAllocatePool() failed\n"); + Status = STATUS_INSUFFICIENT_RESOURCES; + } + else + { + RtlZeroMemory(ResourceList, sizeof(IO_RESOURCE_REQUIREMENTS_LIST)); + ResourceList->ListSize = sizeof(IO_RESOURCE_REQUIREMENTS_LIST); + ResourceList->AlternativeLists = 1; + ResourceList->List->Version = 1; + ResourceList->List->Revision = 1; + ResourceList->List->Count = 0; + Information = (ULONG_PTR)ResourceList; + Status = STATUS_SUCCESS; + } + break; + } + case IRP_MN_QUERY_DEVICE_TEXT: /* 0x0c */ + { + Status = UsbhubPdoQueryDeviceText(DeviceObject, Irp, &Information); + break; + } case IRP_MN_QUERY_ID: /* 0x13 */ { Status = UsbhubPdoQueryId(DeviceObject, Irp, &Information); diff --git a/reactos/drivers/usb/usbport/usbport.def b/reactos/drivers/usb/usbport/usbport.def index 0c8e33ff900..c1ca326fef5 100644 --- a/reactos/drivers/usb/usbport/usbport.def +++ b/reactos/drivers/usb/usbport/usbport.def @@ -7,6 +7,7 @@ usb_exit@0 usb_init_urb@4 usb_alloc_urb@8 usb_free_urb@4 +usb_get_string usb_get_urb@4 usb_get_dev@4 usb_submit_urb@8 diff --git a/reactos/media/inf/usbport.inf b/reactos/media/inf/usbport.inf index 420b1d4907c..06604d3940f 100644 --- a/reactos/media/inf/usbport.inf +++ b/reactos/media/inf/usbport.inf @@ -31,6 +31,7 @@ HKR, , NoInstallClass, 0, 1 %PCI\CC_0C0310.DeviceDesc%=OHCI_Inst,PCI\CC_0C0310 %PCI\CC_0C0320.DeviceDesc%=EHCI_Inst,PCI\CC_0C0320 %USB\ROOT_HUB.DeviceDesc%=RootHub_Inst,USB\ROOT_HUB +%USB\ROOT_HUB.DeviceDesc%=RootHub_Inst,USB\ROOT_HUB20 [IntelMfg] %PCI\VEN_8086&DEV_7112&CC_0C0300.DeviceDesc%=UHCI_Inst,PCI\VEN_8086&DEV_7112&CC_0C0300 @@ -41,7 +42,7 @@ HKR, , NoInstallClass, 0, 1 CopyFiles = UHCI_CopyFiles [UHCI_CopyFiles.NT] -usbcore.sys +usbport.sys usbuhci.sys [UHCI_Inst.NT.Services] @@ -60,7 +61,7 @@ LoadOrderGroup = Base CopyFiles = OHCI_CopyFiles [OHCI_CopyFiles.NT] -usbcore.sys +usbport.sys usbohci.sys [OHCI_Inst.NT.Services] @@ -79,7 +80,7 @@ LoadOrderGroup = Base CopyFiles = EHCI_CopyFiles [EHCI_CopyFiles.NT] -usbcore.sys +usbport.sys usbehci.sys [EHCI_Inst.NT.Services] @@ -98,6 +99,7 @@ LoadOrderGroup = Base CopyFiles = RootHub_CopyFiles [RootHub_CopyFiles.NT] +usbport.sys usbhub.sys [RootHub_Inst.NT.Services]