Allow more than one USB controller (was a XBOX hack no more needed)
[reactos.git] / reactos / drivers / usb / usbhub / pdo.c
index 22edfd9..1339412 100644 (file)
@@ -133,6 +133,78 @@ 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:
+               case DeviceTextLocationInformation:
+               {
+                       unsigned short size;
+                       int ret;
+                       PWCHAR buf;
+                       PWCHAR bufret;
+
+                       if (DeviceTextType == DeviceTextDescription)
+                               DPRINT("Usbhub: IRP_MJ_PNP / IRP_MN_QUERY_DEVICE_TEXT / DeviceTextDescription\n");
+                       else
+                               DPRINT("Usbhub: IRP_MJ_PNP / IRP_MN_QUERY_DEVICE_TEXT / DeviceTextLocationInformation\n");
+                       
+                       if (!DeviceExtension->dev->descriptor.iProduct)
+                               return STATUS_NOT_SUPPORTED;
+
+                       ret = usb_get_string(DeviceExtension->dev, LocaleId, DeviceExtension->dev->descriptor.iProduct, &size, sizeof(size));
+                       if (ret < 2)
+                       {
+                               DPRINT("Usbhub: usb_get_string() failed with error %d\n", ret);
+                               return STATUS_IO_DEVICE_ERROR;
+                       }
+                       size &= 0xff;
+                       buf = ExAllocatePool(PagedPool, size);
+                       if (buf == NULL)
+                       {
+                               DPRINT("Usbhub: ExAllocatePool() failed\n");
+                               return STATUS_INSUFFICIENT_RESOURCES;
+                       }
+                       ret = usb_get_string(DeviceExtension->dev, LocaleId, DeviceExtension->dev->descriptor.iProduct, buf, size);
+                       if (ret < 0)
+                       {
+                               DPRINT("Usbhub: usb_get_string() failed with error %d\n", ret);
+                               ExFreePool(buf);
+                               return STATUS_IO_DEVICE_ERROR;
+                       }
+                       bufret = ExAllocatePool(PagedPool, size - 2 /* size of length identifier */ + 2 /* final NULL */);
+                       if (bufret == NULL)
+                       {
+                               DPRINT("Usbhub: ExAllocatePool() failed\n");
+                               ExFreePool(buf);
+                               return STATUS_INSUFFICIENT_RESOURCES;
+                       }
+
+                       RtlCopyMemory(bufret, &buf[1], size - 2);
+                       bufret[(size - 1) / sizeof(WCHAR)] = 0;
+                       *Information = (ULONG_PTR)bufret;
+                       ExFreePool(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 +226,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);