Author: mjmartin
Date: Sun Sep 5 19:00:37 2010
New Revision: 48705
URL:
http://svn.reactos.org/svn/reactos?rev=48705&view=rev
Log:
[usb/usbhub]
- Start rewrite of usbhub driver using the old and dead usbhub driver in trunk.
- Implement QueryRootHub for sending USB request to miniport driver.
- Implement new IRP_MN_START_DEVICE.
Get the roothubs PDO and FDO and forward the start device down to start the PDO.
Get USBDI and HUB interfaces. Set all ports as returned by DCI GetExtendedHubInformation
to powered and reset.
- Temporary add some usb specific defines until header is fixed.
- Fix Formatting.
Modified:
trunk/reactos/drivers/usb/usbhub/fdo.c
trunk/reactos/drivers/usb/usbhub/misc.c
trunk/reactos/drivers/usb/usbhub/pdo.c
trunk/reactos/drivers/usb/usbhub/usbhub.c
trunk/reactos/drivers/usb/usbhub/usbhub.h
trunk/reactos/drivers/usb/usbhub/usbhub.rbuild
Modified: trunk/reactos/drivers/usb/usbhub/fdo.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/usb/usbhub/fdo.c?r…
==============================================================================
--- trunk/reactos/drivers/usb/usbhub/fdo.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/usb/usbhub/fdo.c [iso-8859-1] Sun Sep 5 19:00:37 2010
@@ -4,499 +4,574 @@
* FILE: drivers/usb/cromwell/hub/fdo.c
* PURPOSE: IRP_MJ_PNP operations for FDOs
*
- * PROGRAMMERS: Hervé Poussineau (hpoussin(a)reactos.com)
+ * PROGRAMMERS: Herv� Poussineau (hpoussin(a)reactos.com)
+ * Michael Martin (michael.martin(a)reactos.org)
*/
#define INITGUID
+#include <stdio.h>
#define NDEBUG
#include "usbhub.h"
+#include "usbdlib.h"
#define IO_METHOD_FROM_CTL_CODE(ctlCode) (ctlCode&0x00000003)
+NTSTATUS
+QueryRootHub(IN PDEVICE_OBJECT Pdo, IN ULONG IoControlCode, OUT PVOID OutParameter1, OUT
PVOID OutParameter2)
+{
+ KEVENT Event;
+ PIRP Irp;
+ IO_STATUS_BLOCK IoStatus;
+ NTSTATUS Status;
+ PIO_STACK_LOCATION Stack = NULL;
+
+ KeInitializeEvent(&Event, NotificationEvent, FALSE);
+
+ Irp = IoBuildDeviceIoControlRequest(IoControlCode,
+ Pdo,
+ NULL, 0,
+ NULL, 0,
+ TRUE,
+ &Event,
+ &IoStatus);
+
+ if (Irp == NULL)
+ {
+ DPRINT("Usbhub: IoBuildDeviceIoControlRequest() failed\n");
+ return STATUS_INSUFFICIENT_RESOURCES;
+ }
+
+ /* Initialize the status block before sending the IRP */
+
+ IoStatus.Status = STATUS_NOT_SUPPORTED;
+ IoStatus.Information = 0;
+
+ Stack = IoGetNextIrpStackLocation(Irp);
+
+ Stack->Parameters.Others.Argument1 = OutParameter1;
+ Stack->Parameters.Others.Argument2 = OutParameter2;
+
+ Status = IoCallDriver(Pdo, Irp);
+
+ if (Status == STATUS_PENDING)
+ {
+ DPRINT("Usbhub: Operation pending\n");
+ KeWaitForSingleObject(&Event, Suspended, KernelMode, FALSE, NULL);
+ Status = IoStatus.Status;
+ }
+
+ return Status;
+}
+
+NTSTATUS QueryInterface(IN PDEVICE_OBJECT Pdo, IN CONST GUID InterfaceType, IN LONG Size,
IN LONG Version, OUT PVOID Interface)
+{
+ KEVENT Event;
+ PIRP Irp;
+ IO_STATUS_BLOCK IoStatus;
+ NTSTATUS Status;
+ PIO_STACK_LOCATION Stack = NULL;
+
+ KeInitializeEvent(&Event, NotificationEvent, FALSE);
+
+ Irp = IoBuildSynchronousFsdRequest(IRP_MJ_PNP,
+ Pdo,
+ NULL,
+ 0,
+ NULL,
+ &Event,
+ &IoStatus);
+
+ Stack = IoGetNextIrpStackLocation(Irp);
+ Stack->MinorFunction = IRP_MN_QUERY_INTERFACE;
+ Stack->Parameters.QueryInterface.InterfaceType=
&InterfaceType;//USB_BUS_INTERFACE_HUB_GUID;
+ Stack->Parameters.QueryInterface.Size = Size;
+ Stack->Parameters.QueryInterface.Version = Version;
+ Stack->Parameters.QueryInterface.Interface = Interface;
+ Stack->Parameters.QueryInterface.InterfaceSpecificData = NULL;
+
+ Status = IoCallDriver(Pdo, Irp);
+
+ if (Status == STATUS_PENDING)
+ {
+ DPRINT("Usbhub: Operation pending\n");
+ KeWaitForSingleObject(&Event, Suspended, KernelMode, FALSE, NULL);
+ Status = IoStatus.Status;
+ }
+
+ return Status;
+}
+
static VOID
-UsbhubGetUserBuffers(
- IN PIRP Irp,
- IN ULONG IoControlCode,
- OUT PVOID* BufferIn,
- OUT PVOID* BufferOut)
-{
- ASSERT(Irp);
- ASSERT(BufferIn);
- ASSERT(BufferOut);
-
- switch (IO_METHOD_FROM_CTL_CODE(IoControlCode))
- {
- case METHOD_BUFFERED:
- *BufferIn = *BufferOut = Irp->AssociatedIrp.SystemBuffer;
- break;
- case METHOD_IN_DIRECT:
- case METHOD_OUT_DIRECT:
- *BufferIn = Irp->AssociatedIrp.SystemBuffer;
- *BufferOut = MmGetSystemAddressForMdl(Irp->MdlAddress);
- break;
- case METHOD_NEITHER:
- *BufferIn =
IoGetCurrentIrpStackLocation(Irp)->Parameters.DeviceIoControl.Type3InputBuffer;
- *BufferOut = Irp->UserBuffer;
- break;
- default:
- /* Should never happen */
- *BufferIn = NULL;
- *BufferOut = NULL;
- break;
- }
-}
-
-static NTSTATUS
-UsbhubFdoQueryBusRelations(
- IN PDEVICE_OBJECT DeviceObject,
- OUT PDEVICE_RELATIONS* pDeviceRelations)
-{
- PHUB_DEVICE_EXTENSION DeviceExtension;
- PDEVICE_RELATIONS DeviceRelations;
- PDEVICE_OBJECT Pdo;
- PHUB_DEVICE_EXTENSION PdoExtension;
- struct usb_device* dev;
- ULONG i;
- ULONG Children = 0;
- ULONG NeededSize;
- NTSTATUS Status;
- CHAR Buffer[3][40];
-
- DeviceExtension = (PHUB_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
- dev = DeviceExtension->dev;
-
- /* Create PDOs that are missing */
- for (i = 0; i < dev->maxchild; i++)
- {
- if (dev->children[i] == NULL)
- {
- /* No child device at this place */
- continue;
- }
- Children++;
- if (DeviceExtension->Children[i] != NULL)
- {
- /* PDO already exists */
- continue;
- }
- /* Need to create the PDO */
- Status = IoCreateDevice(
- DeviceObject->DriverObject,
- sizeof(HUB_DEVICE_EXTENSION),
- NULL, /* Device name */
- FILE_DEVICE_CONTROLLER,
- FILE_AUTOGENERATED_DEVICE_NAME,
- FALSE,
- &DeviceExtension->Children[i]);
- if (!NT_SUCCESS(Status))
- {
- DPRINT("Usbhub: IoCreateDevice() failed with status 0x%08lx\n", Status);
- return Status;
- }
-
- Pdo = DeviceExtension->Children[i];
- Pdo->Flags |= DO_BUS_ENUMERATED_DEVICE;
-
- PdoExtension = Pdo->DeviceExtension;
- RtlZeroMemory(PdoExtension, sizeof(HUB_DEVICE_EXTENSION));
-
- PdoExtension->IsFDO = FALSE;
- PdoExtension->dev = dev->children[i];
-
- sprintf(Buffer[0], "%lu", i);
- Status = UsbhubInitMultiSzString(
- &PdoExtension->InstanceId,
- Buffer[0], NULL);
- if (!NT_SUCCESS(Status))
- goto ByeBye;
-
- DPRINT1("child #%lu: USB\\Vid_%04x&Pid_%04x&Rev_%04x\n",
- i,
- PdoExtension->dev->descriptor.idVendor,
- PdoExtension->dev->descriptor.idProduct,
- PdoExtension->dev->descriptor.bcdDevice);
- sprintf(Buffer[0], "USB\\Vid_%04x&Pid_%04x&Rev_%04x",
- PdoExtension->dev->descriptor.idVendor,
- PdoExtension->dev->descriptor.idProduct,
- PdoExtension->dev->descriptor.bcdDevice);
- sprintf(Buffer[1], "USB\\Vid_%04x&Pid_%04x",
- PdoExtension->dev->descriptor.idVendor,
- PdoExtension->dev->descriptor.idProduct);
- Status = UsbhubInitMultiSzString(
- &PdoExtension->HardwareIds,
- Buffer[0], Buffer[1], NULL);
- if (!NT_SUCCESS(Status))
- goto ByeBye;
-
- Status = UsbhubInitMultiSzString(
- &PdoExtension->DeviceId,
- Buffer[1], NULL);
- if (!NT_SUCCESS(Status))
- goto ByeBye;
-
- if (PdoExtension->dev->actconfig->desc.bNumInterfaces == 1)
- {
- /* Single-interface USB device */
- if (PdoExtension->dev->descriptor.bDeviceClass != 0)
- {
- /* Use these values for device class/sub class/protocol */
- sprintf(Buffer[0], "USB\\Class_%02x&SubClass_%02x&Prot_%02x",
- PdoExtension->dev->descriptor.bDeviceClass,
- PdoExtension->dev->descriptor.bDeviceSubClass,
- PdoExtension->dev->descriptor.bDeviceProtocol);
- sprintf(Buffer[1], "USB\\Class_%02x&SubClass_%02x",
- PdoExtension->dev->descriptor.bDeviceClass,
- PdoExtension->dev->descriptor.bDeviceSubClass);
- sprintf(Buffer[2], "USB\\Class_%02x",
- PdoExtension->dev->descriptor.bDeviceClass);
- }
- else
- {
- /* Use values specified in the interface descriptor */
- struct usb_host_interface *itf =
PdoExtension->dev->actconfig->interface->altsetting;
- sprintf(Buffer[0], "USB\\Class_%02x&SubClass_%02x&Prot_%02x",
- itf->desc.bInterfaceClass,
- itf->desc.bInterfaceSubClass,
- itf->desc.bInterfaceProtocol);
- sprintf(Buffer[1], "USB\\Class_%02x&SubClass_%02x",
- itf->desc.bInterfaceClass,
- itf->desc.bInterfaceSubClass);
- sprintf(Buffer[2], "USB\\Class_%02x",
- itf->desc.bInterfaceClass);
- }
- Status = UsbhubInitMultiSzString(
- &PdoExtension->CompatibleIds,
- Buffer[0], Buffer[1], Buffer[2], NULL);
- }
- else
- {
- /* Multiple-interface USB device */
- sprintf(Buffer[0], "USB\\DevClass_%02x&SubClass_%02x&Prot_%02x",
- PdoExtension->dev->descriptor.bDeviceClass,
- PdoExtension->dev->descriptor.bDeviceSubClass,
- PdoExtension->dev->descriptor.bDeviceProtocol);
- sprintf(Buffer[1], "USB\\DevClass_%02x&SubClass_%02x",
- PdoExtension->dev->descriptor.bDeviceClass,
- PdoExtension->dev->descriptor.bDeviceSubClass);
- sprintf(Buffer[2], "USB\\DevClass_%02x",
- PdoExtension->dev->descriptor.bDeviceClass);
- Status = UsbhubInitMultiSzString(
- &PdoExtension->CompatibleIds,
- Buffer[0], Buffer[1], Buffer[2], "USB\\COMPOSITE", NULL);
- }
-
- if (!NT_SUCCESS(Status))
- goto ByeBye;
-
- Pdo->Flags &= ~DO_DEVICE_INITIALIZING;
- }
-
- /* Fill returned structure */
- NeededSize = sizeof(DEVICE_RELATIONS);
- if (Children > 1)
- NeededSize += (Children - 1) * sizeof(PDEVICE_OBJECT);
- DeviceRelations = (PDEVICE_RELATIONS)ExAllocatePool(
- PagedPool,
- NeededSize);
- if (!DeviceRelations)
- return STATUS_INSUFFICIENT_RESOURCES;
- DeviceRelations->Count = Children;
- Children = 0;
- for (i = 0; i < USB_MAXCHILDREN; i++)
- {
- if (DeviceExtension->Children[i])
- {
- ObReferenceObject(DeviceExtension->Children[i]);
- DeviceRelations->Objects[Children++] = DeviceExtension->Children[i];
- }
- }
- ASSERT(Children == DeviceRelations->Count);
-
- *pDeviceRelations = DeviceRelations;
- return STATUS_SUCCESS;
-
-ByeBye:
- RtlFreeUnicodeString(&PdoExtension->DeviceId);
- RtlFreeUnicodeString(&PdoExtension->InstanceId);
- RtlFreeUnicodeString(&PdoExtension->HardwareIds);
- RtlFreeUnicodeString(&PdoExtension->CompatibleIds);
- IoDeleteDevice(Pdo);
- return Status;
+UsbhubGetUserBuffers(IN PIRP Irp, IN ULONG IoControlCode, OUT PVOID* BufferIn, OUT PVOID*
BufferOut)
+{
+ ASSERT(Irp);
+ ASSERT(BufferIn);
+ ASSERT(BufferOut);
+
+ switch (IO_METHOD_FROM_CTL_CODE(IoControlCode))
+ {
+ case METHOD_BUFFERED:
+ *BufferIn = *BufferOut = Irp->AssociatedIrp.SystemBuffer;
+ break;
+ case METHOD_IN_DIRECT:
+ case METHOD_OUT_DIRECT:
+ *BufferIn = Irp->AssociatedIrp.SystemBuffer;
+ *BufferOut = MmGetSystemAddressForMdl(Irp->MdlAddress);
+ break;
+ case METHOD_NEITHER:
+ *BufferIn =
IoGetCurrentIrpStackLocation(Irp)->Parameters.DeviceIoControl.Type3InputBuffer;
+ *BufferOut = Irp->UserBuffer;
+ break;
+ default:
+ /* Should never happen */
+ *BufferIn = NULL;
+ *BufferOut = NULL;
+ break;
+ }
+}
+
+NTSTATUS
+UsbhubFdoQueryBusRelations(IN PDEVICE_OBJECT DeviceObject, OUT PDEVICE_RELATIONS*
pDeviceRelations)
+{
+ PHUB_DEVICE_EXTENSION DeviceExtension;
+ PDEVICE_RELATIONS DeviceRelations;
+ PDEVICE_OBJECT Pdo;
+ PHUB_DEVICE_EXTENSION PdoExtension;
+ ULONG i;
+ ULONG Children = 0;
+ ULONG NeededSize;
+
+ DeviceExtension = (PHUB_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
+ DPRINT1("USBHUB: Query Bus Relations\n");
+ /* Create PDOs that are missing */
+ for (i = 0; i < USB_MAXCHILDREN; i++)
+ {
+
+ if (DeviceExtension->Children[i] == NULL)
+ {
+ continue;
+ }
+ Children++;
+ Pdo = DeviceExtension->Children[i];
+ Pdo->Flags |= DO_BUS_ENUMERATED_DEVICE;
+
+ PdoExtension = Pdo->DeviceExtension;
+
+ RtlZeroMemory(PdoExtension, sizeof(HUB_DEVICE_EXTENSION));
+
+ PdoExtension->IsFDO = FALSE;
+
+ Pdo->Flags &= ~DO_DEVICE_INITIALIZING;
+ }
+
+ /* Fill returned structure */
+ NeededSize = sizeof(DEVICE_RELATIONS);
+ if (Children > 1)
+ NeededSize += (Children - 1) * sizeof(PDEVICE_OBJECT);
+
+ DeviceRelations = (PDEVICE_RELATIONS)ExAllocatePool(PagedPool,
+ NeededSize);
+
+ if (!DeviceRelations)
+ return STATUS_INSUFFICIENT_RESOURCES;
+ DeviceRelations->Count = Children;
+ Children = 0;
+
+ for (i = 0; i < USB_MAXCHILDREN; i++)
+ {
+ if (DeviceExtension->Children[i])
+ {
+ ObReferenceObject(DeviceExtension->Children[i]);
+ DeviceRelations->Objects[Children++] = DeviceExtension->Children[i];
+ }
+ }
+ ASSERT(Children == DeviceRelations->Count);
+
+ *pDeviceRelations = DeviceRelations;
+ return STATUS_SUCCESS;
}
NTSTATUS NTAPI
-UsbhubPnpFdo(
- IN PDEVICE_OBJECT DeviceObject,
- IN PIRP Irp)
-{
- PIO_STACK_LOCATION IrpSp;
- NTSTATUS Status;
- ULONG MinorFunction;
- ULONG_PTR Information = 0;
-
- IrpSp = IoGetCurrentIrpStackLocation(Irp);
- MinorFunction = IrpSp->MinorFunction;
-
- switch (MinorFunction)
- {
- case IRP_MN_START_DEVICE: /* 0x0 */
- {
- DPRINT("Usbhub: IRP_MJ_PNP / IRP_MN_START_DEVICE\n");
- Status = ForwardIrpAndWait(DeviceObject, Irp);
- break;
- }
-
- case IRP_MN_QUERY_DEVICE_RELATIONS: /* (optional) 0x7 */
- {
- switch (IrpSp->Parameters.QueryDeviceRelations.Type)
- {
- case BusRelations:
- {
- PDEVICE_RELATIONS DeviceRelations = NULL;
- DPRINT("Usbhub: IRP_MJ_PNP / IRP_MN_QUERY_DEVICE_RELATIONS /
BusRelations\n");
- Status = UsbhubFdoQueryBusRelations(DeviceObject, &DeviceRelations);
- Information = (ULONG_PTR)DeviceRelations;
- break;
- }
- case RemovalRelations:
- {
- DPRINT1("Usbhub: IRP_MJ_PNP / IRP_MN_QUERY_DEVICE_RELATIONS /
RemovalRelations\n");
- return ForwardIrpAndForget(DeviceObject, Irp);
- }
- default:
- DPRINT1("Usbhub: IRP_MJ_PNP / IRP_MN_QUERY_DEVICE_RELATIONS / Unknown type
0x%lx\n",
- IrpSp->Parameters.QueryDeviceRelations.Type);
- return ForwardIrpAndForget(DeviceObject, Irp);
- }
- break;
- }
-
- default:
- {
- DPRINT1("Usbhub: IRP_MJ_PNP / unknown minor function 0x%lx\n",
MinorFunction);
- return ForwardIrpAndForget(DeviceObject, Irp);
- }
- }
- Irp->IoStatus.Information = Information;
- Irp->IoStatus.Status = Status;
- IoCompleteRequest(Irp, IO_NO_INCREMENT);
- return Status;
+UsbhubPnpFdo(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
+{
+ PIO_STACK_LOCATION IrpSp;
+ NTSTATUS Status;
+ ULONG MinorFunction;
+ ULONG_PTR Information = 0;
+ PHUB_DEVICE_EXTENSION DeviceExtension;
+
+ IrpSp = IoGetCurrentIrpStackLocation(Irp);
+ MinorFunction = IrpSp->MinorFunction;
+
+ DeviceExtension = (PHUB_DEVICE_EXTENSION) DeviceObject->DeviceExtension;
+
+ switch (MinorFunction)
+ {
+ case IRP_MN_START_DEVICE: /* 0x0 */
+ {
+ URB Urb;
+ ULONG Result = 0;
+ USB_DEVICE_INFORMATION_0 DeviceInformation;
+
+ /* We differ from windows on hubpdo because we dont have usbport.sys which
manages all usb device objects */
+ DPRINT("Usbhub: IRP_MJ_PNP / IRP_MN_START_DEVICE\n");
+
+ /* Get the hubs PDO */
+ QueryRootHub(DeviceObject, IOCTL_INTERNAL_USB_GET_ROOTHUB_PDO,
&DeviceExtension->RootHubPdo, &DeviceExtension->RootHubFdo);
+ ASSERT(DeviceExtension->RootHubPdo);
+ ASSERT(DeviceExtension->RootHubFdo);
+
+ /* Send the START_DEVICE irp down to the PDO of RootHub */
+ Status = ForwardIrpAndWait(DeviceExtension->RootHubPdo, Irp);
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT1("Failed to start the RootHub PDO\n");
+ ASSERT(FALSE);
+ }
+
+ /* Get the current number of hubs */
+ QueryRootHub(DeviceObject,IOCTL_INTERNAL_USB_GET_HUB_COUNT,
&DeviceExtension->HubCount, NULL);
+
+ /* Get the Direct Call Interfaces */
+ Status = QueryInterface(DeviceObject, USB_BUS_INTERFACE_HUB_GUID,
sizeof(USB_BUS_INTERFACE_HUB_V5), 5, (PVOID)&DeviceExtension->HubInterface);
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT1("UsbhubM Failed to get HUB_GUID interface with status
0x%08lx\n", Status);
+ return STATUS_UNSUCCESSFUL;
+ }
+
+ Status = QueryInterface(DeviceObject, USB_BUS_INTERFACE_USBDI_GUID,
sizeof(USB_BUS_INTERFACE_USBDI_V2), 2, (PVOID)&DeviceExtension->UsbDInterface);
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT1("UsbhubM Failed to get USBDI_GUID interface with status
0x%08lx\n", Status);
+ return STATUS_UNSUCCESSFUL;
+ }
+
+ /* Get roothub device handle */
+ Status = QueryRootHub(DeviceObject, IOCTL_INTERNAL_USB_GET_DEVICE_HANDLE,
&DeviceExtension->RootHubUsbDevice, NULL);
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT1("Usbhub: GetRootHubDeviceHandle failed with status
0x%08lx\n", Status);
+ return Status;
+ }
+
+ RtlZeroMemory(&DeviceInformation, sizeof(USB_DEVICE_INFORMATION_0));
+
+ Status =
DeviceExtension->HubInterface.QueryDeviceInformation(DeviceExtension->RootHubPdo,
+
DeviceExtension->RootHubUsbDevice,
+ &DeviceInformation,
+
sizeof(USB_DEVICE_INFORMATION_0),
+ &Result);
+
+ DPRINT1("Status %x, Result %x\n", Status, Result);
+ DPRINT1("InformationLevel %x\n",
DeviceInformation.InformationLevel);
+ DPRINT1("ActualLength %x\n", DeviceInformation.ActualLength);
+ DPRINT1("PortNumber %x\n", DeviceInformation.PortNumber);
+ DPRINT1("DeviceDescriptor %x\n",
DeviceInformation.DeviceDescriptor);
+ DPRINT1("HubAddress %x\n", DeviceInformation.HubAddress);
+ DPRINT1("NumberofPipes %x\n",
DeviceInformation.NumberOfOpenPipes);
+
+
+
+ UsbBuildGetDescriptorRequest(&Urb,
+ sizeof(Urb.UrbControlDescriptorRequest),
+ USB_DEVICE_DESCRIPTOR_TYPE,
+ 0,
+ 0,
+ &DeviceExtension->HubDeviceDescriptor,
+ NULL,
+ sizeof(USB_DEVICE_DESCRIPTOR),
+ NULL);
+
+ Urb.UrbHeader.UsbdDeviceHandle = DeviceExtension->RootHubUsbDevice;
+
+ Status = QueryRootHub(DeviceObject, IOCTL_INTERNAL_USB_SUBMIT_URB, &Urb,
NULL);
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT1("Usbhub: Failed to get HubDeviceDescriptor!\n");
+ }
+
+ UsbBuildGetDescriptorRequest(&Urb,
+ sizeof(Urb.UrbControlDescriptorRequest),
+ USB_CONFIGURATION_DESCRIPTOR_TYPE,
+ 0,
+ 0,
+ &DeviceExtension->HubConfig,
+ NULL,
+ sizeof(USB_CONFIGURATION_DESCRIPTOR),
+ NULL);
+ Urb.UrbHeader.UsbdDeviceHandle = DeviceExtension->RootHubUsbDevice;
+
+ Status = QueryRootHub(DeviceObject, IOCTL_INTERNAL_USB_SUBMIT_URB, &Urb,
NULL);
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT1("Usbhub: Failed to get HubConfig!\n");
+ }
+
+ Status =
DeviceExtension->HubInterface.GetExtendedHubInformation(DeviceExtension->RootHubPdo,
+
DeviceExtension->RootHubPdo,
+
&DeviceExtension->UsbExtHubInfo,
+
sizeof(USB_EXTHUB_INFORMATION_0),
+ &Result);
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT1("Usbhub: Failed to extended hub information. Unable to
determine the number of ports!\n");
+ ASSERT(FALSE);
+ }
+
+ DPRINT1("DeviceExtension->UsbExtHubInfo.NumberOfPorts %x\n",
DeviceExtension->UsbExtHubInfo.NumberOfPorts);
+
+ /* FIXME: HubDescriptor is empty and shouldnt be but Status is success */
+ UsbBuildVendorRequest(&Urb,
+ URB_FUNCTION_CLASS_DEVICE,
+ sizeof(Urb.UrbControlVendorClassRequest),
+ USBD_TRANSFER_DIRECTION_IN,
+ 0,
+ USB_DEVICE_CLASS_RESERVED,
+ 0,
+ 0,
+ &DeviceExtension->HubDescriptor,
+ NULL,
+ sizeof(USB_HUB_DESCRIPTOR),
+ NULL);
+
+ Urb.UrbHeader.UsbdDeviceHandle = DeviceExtension->RootHubUsbDevice;
+
+ Status = QueryRootHub(DeviceObject, IOCTL_INTERNAL_USB_SUBMIT_URB, &Urb,
NULL);
+
+ DPRINT1("bDescriptorType %x\n",
DeviceExtension->HubDescriptor.bDescriptorType);
+
+ Status =
DeviceExtension->HubInterface.Initialize20Hub(DeviceExtension->RootHubPdo,
DeviceExtension->RootHubUsbDevice, 1);
+
+ break;
+ }
+
+ case IRP_MN_QUERY_DEVICE_RELATIONS: /* (optional) 0x7 */
+ {
+ switch (IrpSp->Parameters.QueryDeviceRelations.Type)
+ {
+ case BusRelations:
+ {
+ PDEVICE_RELATIONS DeviceRelations = NULL;
+ DPRINT1("Usbhub: IRP_MJ_PNP / IRP_MN_QUERY_DEVICE_RELATIONS /
BusRelations\n");
+
+ Status = UsbhubFdoQueryBusRelations(DeviceObject,
&DeviceRelations);
+
+ Information = (ULONG_PTR)DeviceRelations;
+ break;
+ }
+ case RemovalRelations:
+ {
+ DPRINT1("Usbhub: IRP_MJ_PNP / IRP_MN_QUERY_DEVICE_RELATIONS /
RemovalRelations\n");
+ return ForwardIrpAndForget(DeviceObject, Irp);
+ }
+ default:
+ DPRINT1("Usbhub: IRP_MJ_PNP / IRP_MN_QUERY_DEVICE_RELATIONS /
Unknown type 0x%lx\n",
+ IrpSp->Parameters.QueryDeviceRelations.Type);
+ return ForwardIrpAndForget(DeviceObject, Irp);
+ }
+ break;
+ }
+case IRP_MN_QUERY_BUS_INFORMATION:
+{
+DPRINT1("IRP_MN_QUERY_BUS_INFORMATION\n");
+break;
+}
+
+case IRP_MN_QUERY_ID:
+{
+DPRINT1("IRP_MN_QUERY_ID\n");
+break;
+}
+
+
+case IRP_MN_QUERY_CAPABILITIES:
+{
+DPRINT1("IRP_MN_QUERY_CAPABILITIES\n");
+break;
+}
+
+
+
+ default:
+ {
+ DPRINT1("Usbhub: IRP_MJ_PNP / unknown minor function 0x%lx\n",
MinorFunction);
+ return ForwardIrpAndForget(DeviceObject, Irp);
+ }
+ }
+ Irp->IoStatus.Information = Information;
+ Irp->IoStatus.Status = Status;
+ IoCompleteRequest(Irp, IO_NO_INCREMENT);
+ return Status;
}
NTSTATUS
-UsbhubDeviceControlFdo(
- IN PDEVICE_OBJECT DeviceObject,
- IN PIRP Irp)
-{
- PIO_STACK_LOCATION Stack;
- ULONG IoControlCode;
- PHUB_DEVICE_EXTENSION DeviceExtension;
- ULONG LengthIn, LengthOut;
- ULONG_PTR Information = 0;
- PVOID BufferIn, BufferOut;
- NTSTATUS Status;
-
- Stack = IoGetCurrentIrpStackLocation(Irp);
- LengthIn = Stack->Parameters.DeviceIoControl.InputBufferLength;
- LengthOut = Stack->Parameters.DeviceIoControl.OutputBufferLength;
- DeviceExtension = (PHUB_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
- IoControlCode = Stack->Parameters.DeviceIoControl.IoControlCode;
- UsbhubGetUserBuffers(Irp, IoControlCode, &BufferIn, &BufferOut);
-
- switch (IoControlCode)
- {
- case IOCTL_USB_GET_NODE_INFORMATION:
- {
- PUSB_NODE_INFORMATION NodeInformation;
- struct usb_device* dev;
- DPRINT("Usbhub: IOCTL_USB_GET_NODE_INFORMATION\n");
- if (LengthOut < sizeof(USB_NODE_INFORMATION))
- Status = STATUS_BUFFER_TOO_SMALL;
- else if (BufferOut == NULL)
- Status = STATUS_INVALID_PARAMETER;
- else
- {
- NodeInformation = (PUSB_NODE_INFORMATION)BufferOut;
- dev = ((PHUB_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->dev;
- NodeInformation->NodeType = UsbHub;
- RtlCopyMemory(
- &NodeInformation->u.HubInformation.HubDescriptor,
- ((struct usb_hub
*)usb_get_intfdata(to_usb_interface(&dev->actconfig->interface[0].dev)))->descriptor,
- sizeof(USB_HUB_DESCRIPTOR));
- NodeInformation->u.HubInformation.HubIsBusPowered =
dev->actconfig->desc.bmAttributes & 0x80;
- Information = sizeof(USB_NODE_INFORMATION);
- Status = STATUS_SUCCESS;
- }
- break;
- }
- case IOCTL_USB_GET_NODE_CONNECTION_NAME:
- {
- PHUB_DEVICE_EXTENSION DeviceExtension;
- PUSB_NODE_CONNECTION_NAME ConnectionName;
- DeviceExtension = (PHUB_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
- ConnectionName = (PUSB_NODE_CONNECTION_NAME)BufferOut;
-
- DPRINT("Usbhub: IOCTL_USB_GET_NODE_CONNECTION_NAME\n");
- if (LengthOut < sizeof(USB_NODE_CONNECTION_NAME))
- Status = STATUS_BUFFER_TOO_SMALL;
- else if (BufferOut == NULL)
- Status = STATUS_INVALID_PARAMETER;
- else if (ConnectionName->ConnectionIndex < 1
- || ConnectionName->ConnectionIndex > USB_MAXCHILDREN)
- Status = STATUS_INVALID_PARAMETER;
- else if (DeviceExtension->Children[ConnectionName->ConnectionIndex - 1] ==
NULL)
- Status = STATUS_INVALID_PARAMETER;
- else
- {
- ULONG NeededStructureSize;
- DeviceExtension =
(PHUB_DEVICE_EXTENSION)DeviceExtension->Children[ConnectionName->ConnectionIndex -
1]->DeviceExtension;
- NeededStructureSize = DeviceExtension->SymbolicLinkName.Length +
sizeof(UNICODE_NULL) + FIELD_OFFSET(USB_NODE_CONNECTION_NAME, NodeName);
- if (ConnectionName->ActualLength < NeededStructureSize / sizeof(WCHAR)
- || LengthOut < NeededStructureSize)
- {
- /* Buffer too small */
- ConnectionName->ActualLength = NeededStructureSize / sizeof(WCHAR);
- Information = sizeof(USB_NODE_CONNECTION_NAME);
- Status = STATUS_BUFFER_TOO_SMALL;
- }
- else
- {
- RtlCopyMemory(
- ConnectionName->NodeName,
- DeviceExtension->SymbolicLinkName.Buffer,
- DeviceExtension->SymbolicLinkName.Length);
- ConnectionName->NodeName[DeviceExtension->SymbolicLinkName.Length /
sizeof(WCHAR)] = UNICODE_NULL;
- DPRINT("Usbhub: IOCTL_USB_GET_NODE_CONNECTION_NAME returns
'%S'\n", ConnectionName->NodeName);
- ConnectionName->ActualLength = NeededStructureSize / sizeof(WCHAR);
- Information = NeededStructureSize;
- Status = STATUS_SUCCESS;
- }
- Information = LengthOut;
- }
- break;
- }
- case IOCTL_USB_GET_NODE_CONNECTION_INFORMATION:
- {
- PUSB_NODE_CONNECTION_INFORMATION ConnectionInformation;
- ULONG i, j, k;
- struct usb_device* dev;
- ULONG NumberOfOpenPipes = 0;
- ULONG SizeOfOpenPipesArray;
- ConnectionInformation = (PUSB_NODE_CONNECTION_INFORMATION)BufferOut;
-
- DPRINT("Usbhub: IOCTL_USB_GET_NODE_CONNECTION_INFORMATION\n");
- if (LengthOut < sizeof(USB_NODE_CONNECTION_INFORMATION))
- Status = STATUS_BUFFER_TOO_SMALL;
- else if (BufferOut == NULL)
- Status = STATUS_INVALID_PARAMETER;
- else if (ConnectionInformation->ConnectionIndex < 1
- || ConnectionInformation->ConnectionIndex > USB_MAXCHILDREN)
- Status = STATUS_INVALID_PARAMETER;
- else
- {
- dev = ((PHUB_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->dev;
- dev = dev->children[ConnectionInformation->ConnectionIndex - 1];
- if (dev == NULL)
- {
- /* No device connected to this port */
- RtlZeroMemory(
- &ConnectionInformation->DeviceDescriptor,
- sizeof(USB_NODE_CONNECTION_INFORMATION) -
FIELD_OFFSET(USB_NODE_CONNECTION_INFORMATION, DeviceDescriptor));
- ConnectionInformation->ConnectionStatus = NoDeviceConnected;
- Information = sizeof(USB_NODE_CONNECTION_INFORMATION);
- Status = STATUS_SUCCESS;
- break;
- }
- SizeOfOpenPipesArray = (LengthOut - FIELD_OFFSET(USB_NODE_CONNECTION_INFORMATION,
PipeList)) / sizeof(USB_PIPE_INFO);
- RtlCopyMemory(
- &ConnectionInformation->DeviceDescriptor,
- &dev->descriptor,
- sizeof(USB_DEVICE_DESCRIPTOR));
- ConnectionInformation->CurrentConfigurationValue =
dev->actconfig->desc.bConfigurationValue;
- ConnectionInformation->LowSpeed = dev->speed == USB_SPEED_LOW || dev->speed
== USB_SPEED_FULL;
- ConnectionInformation->DeviceIsHub = dev->descriptor.bDeviceClass ==
USB_CLASS_HUB;
- ConnectionInformation->DeviceAddress = dev->devnum;
- ConnectionInformation->ConnectionStatus = DeviceConnected;
-
- for (i = 0; i < dev->actconfig->desc.bNumInterfaces; i++)
- for (j = 0; j < dev->actconfig->interface[i].num_altsetting; j++)
- for (k = 0; k <
dev->actconfig->interface[i].altsetting[j].desc.bNumEndpoints; k++)
- {
- if (NumberOfOpenPipes < SizeOfOpenPipesArray)
- {
- PUSB_PIPE_INFO Pipe =
&ConnectionInformation->PipeList[NumberOfOpenPipes];
- struct usb_host_endpoint* endpoint =
&dev->actconfig->interface[i].altsetting[j].endpoint[k];
- RtlCopyMemory(
- &Pipe->EndpointDescriptor,
- &endpoint->desc,
- endpoint->desc.bLength);
- Pipe->ScheduleOffset = 0; /* FIXME */
- }
- NumberOfOpenPipes++;
- }
- ConnectionInformation->NumberOfOpenPipes = NumberOfOpenPipes;
-
- Information = sizeof(USB_NODE_CONNECTION_INFORMATION);
- if (NumberOfOpenPipes <= SizeOfOpenPipesArray)
- Status = STATUS_SUCCESS;
- else
- Status = STATUS_BUFFER_OVERFLOW;
- }
- break;
- }
- case IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION:
- {
- //PUSB_DESCRIPTOR_REQUEST Descriptor;
- DPRINT("Usbhub: IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION\n");
- DPRINT1("Usbhub: IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION
unimplemented\n");
- Information = 0;
- Status = STATUS_NOT_IMPLEMENTED;
- break;
- }
- case IOCTL_USB_GET_NODE_CONNECTION_DRIVERKEY_NAME:
- {
- PHUB_DEVICE_EXTENSION DeviceExtension;
- PUSB_NODE_CONNECTION_DRIVERKEY_NAME StringDescriptor;
- DPRINT("Usbhub: IOCTL_USB_GET_NODE_CONNECTION_DRIVERKEY_NAME\n");
- DeviceExtension = (PHUB_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
- StringDescriptor = (PUSB_NODE_CONNECTION_DRIVERKEY_NAME)BufferOut;
- if (LengthOut < sizeof(USB_NODE_CONNECTION_DRIVERKEY_NAME))
- Status = STATUS_BUFFER_TOO_SMALL;
- else if (StringDescriptor == NULL)
- Status = STATUS_INVALID_PARAMETER;
- else if (StringDescriptor->ConnectionIndex < 1
- || StringDescriptor->ConnectionIndex > USB_MAXCHILDREN)
- Status = STATUS_INVALID_PARAMETER;
- else if (DeviceExtension->Children[StringDescriptor->ConnectionIndex - 1] ==
NULL)
- Status = STATUS_INVALID_PARAMETER;
- else
- {
- ULONG StringSize;
- Status = IoGetDeviceProperty(
- DeviceExtension->Children[StringDescriptor->ConnectionIndex - 1],
- DevicePropertyDriverKeyName,
- LengthOut - FIELD_OFFSET(USB_NODE_CONNECTION_DRIVERKEY_NAME, DriverKeyName),
- StringDescriptor->DriverKeyName,
- &StringSize);
- if (NT_SUCCESS(Status) || Status == STATUS_BUFFER_TOO_SMALL)
- {
- StringDescriptor->ActualLength = StringSize +
FIELD_OFFSET(USB_NODE_CONNECTION_DRIVERKEY_NAME, DriverKeyName);
- Information = LengthOut;
- Status = STATUS_SUCCESS;
- }
- }
- break;
- }
- default:
- {
- /* Pass Irp to lower driver */
- DPRINT1("Usbhub: Unknown IOCTL code 0x%lx\n",
Stack->Parameters.DeviceIoControl.IoControlCode);
- return ForwardIrpAndForget(DeviceObject, Irp);
- }
- }
-
- Irp->IoStatus.Information = Information;
- Irp->IoStatus.Status = Status;
- IoCompleteRequest(Irp, IO_NO_INCREMENT);
- return Status;
-}
+UsbhubDeviceControlFdo(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
+{
+ PIO_STACK_LOCATION Stack;
+ ULONG IoControlCode;
+ PHUB_DEVICE_EXTENSION DeviceExtension;
+ ULONG LengthIn, LengthOut;
+ ULONG_PTR Information = 0;
+ PVOID BufferIn, BufferOut;
+ NTSTATUS Status = STATUS_UNSUCCESSFUL;
+
+ Stack = IoGetCurrentIrpStackLocation(Irp);
+ LengthIn = Stack->Parameters.DeviceIoControl.InputBufferLength;
+ LengthOut = Stack->Parameters.DeviceIoControl.OutputBufferLength;
+ DeviceExtension = (PHUB_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
+ IoControlCode = Stack->Parameters.DeviceIoControl.IoControlCode;
+ UsbhubGetUserBuffers(Irp, IoControlCode, &BufferIn, &BufferOut);
+
+ switch (IoControlCode)
+ {
+ case IOCTL_USB_GET_NODE_INFORMATION:
+ {
+ //PUSB_NODE_INFORMATION NodeInformation;
+
+ DPRINT1("Usbhub: IOCTL_USB_GET_NODE_INFORMATION\n");
+ if (LengthOut < sizeof(USB_NODE_INFORMATION))
+ Status = STATUS_BUFFER_TOO_SMALL;
+ else if (BufferOut == NULL)
+ Status = STATUS_INVALID_PARAMETER;
+ else
+ {
+ /*NodeInformation = (PUSB_NODE_INFORMATION)BufferOut;
+ dev = ((PHUB_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->dev;
+ NodeInformation->NodeType = UsbHub;
+ RtlCopyMemory(
+ &NodeInformation->u.HubInformation.HubDescriptor,
+ ((struct usb_hub
*)usb_get_intfdata(to_usb_interface(&dev->actconfig->interface[0].dev)))->descriptor,
+ sizeof(USB_HUB_DESCRIPTOR));
+ NodeInformation->u.HubInformation.HubIsBusPowered =
dev->actconfig->desc.bmAttributes & 0x80;
+ Information = sizeof(USB_NODE_INFORMATION);*/
+ Status = STATUS_SUCCESS;
+ }
+ break;
+ }
+ case IOCTL_USB_GET_NODE_CONNECTION_NAME:
+ {
+ PHUB_DEVICE_EXTENSION DeviceExtension;
+ PUSB_NODE_CONNECTION_NAME ConnectionName;
+ DeviceExtension = (PHUB_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
+ ConnectionName = (PUSB_NODE_CONNECTION_NAME)BufferOut;
+
+ DPRINT1("Usbhub: IOCTL_USB_GET_NODE_CONNECTION_NAME\n");
+ if (LengthOut < sizeof(USB_NODE_CONNECTION_NAME))
+ Status = STATUS_BUFFER_TOO_SMALL;
+ else if (BufferOut == NULL)
+ Status = STATUS_INVALID_PARAMETER;
+ else if (ConnectionName->ConnectionIndex < 1
+ || ConnectionName->ConnectionIndex > USB_MAXCHILDREN)
+ Status = STATUS_INVALID_PARAMETER;
+ else if (DeviceExtension->Children[ConnectionName->ConnectionIndex - 1]
== NULL)
+ Status = STATUS_INVALID_PARAMETER;
+ else
+ {
+ ULONG NeededStructureSize;
+ DeviceExtension =
(PHUB_DEVICE_EXTENSION)DeviceExtension->Children[ConnectionName->ConnectionIndex -
1]->DeviceExtension;
+ NeededStructureSize = DeviceExtension->SymbolicLinkName.Length +
sizeof(UNICODE_NULL) + FIELD_OFFSET(USB_NODE_CONNECTION_NAME, NodeName);
+ if (ConnectionName->ActualLength < NeededStructureSize /
sizeof(WCHAR)
+ || LengthOut < NeededStructureSize)
+ {
+ /* Buffer too small */
+ ConnectionName->ActualLength = NeededStructureSize /
sizeof(WCHAR);
+ Information = sizeof(USB_NODE_CONNECTION_NAME);
+ Status = STATUS_BUFFER_TOO_SMALL;
+ }
+ else
+ {
+ RtlCopyMemory(
+ ConnectionName->NodeName,
+ DeviceExtension->SymbolicLinkName.Buffer,
+ DeviceExtension->SymbolicLinkName.Length);
+
ConnectionName->NodeName[DeviceExtension->SymbolicLinkName.Length / sizeof(WCHAR)] =
UNICODE_NULL;
+ DPRINT1("Usbhub: IOCTL_USB_GET_NODE_CONNECTION_NAME returns
'%S'\n", ConnectionName->NodeName);
+ ConnectionName->ActualLength = NeededStructureSize /
sizeof(WCHAR);
+ Information = NeededStructureSize;
+ Status = STATUS_SUCCESS;
+ }
+ Information = LengthOut;
+ }
+ break;
+ }
+ case IOCTL_USB_GET_NODE_CONNECTION_INFORMATION:
+ {
+ PUSB_NODE_CONNECTION_INFORMATION ConnectionInformation;
+/*
+ ULONG i, j, k;
+ struct usb_device* dev;
+ ULONG NumberOfOpenPipes = 0;
+ ULONG SizeOfOpenPipesArray;
+*/
+ ConnectionInformation = (PUSB_NODE_CONNECTION_INFORMATION)BufferOut;
+
+ DPRINT1("Usbhub: IOCTL_USB_GET_NODE_CONNECTION_INFORMATION\n");
+ if (LengthOut < sizeof(USB_NODE_CONNECTION_INFORMATION))
+ Status = STATUS_BUFFER_TOO_SMALL;
+ else if (BufferOut == NULL)
+ Status = STATUS_INVALID_PARAMETER;
+ else if (ConnectionInformation->ConnectionIndex < 1
+ || ConnectionInformation->ConnectionIndex > USB_MAXCHILDREN)
+ Status = STATUS_INVALID_PARAMETER;
+ else
+ {
+ DPRINT1("Usbhub: We should succeed\n");
+ }
+ break;
+ }
+ case IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION:
+ {
+ //PUSB_DESCRIPTOR_REQUEST Descriptor;
+ DPRINT1("Usbhub:
IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION\n");
+ Information = 0;
+ Status = STATUS_NOT_IMPLEMENTED;
+ break;
+ }
+ case IOCTL_USB_GET_NODE_CONNECTION_DRIVERKEY_NAME:
+ {
+ PHUB_DEVICE_EXTENSION DeviceExtension;
+ PUSB_NODE_CONNECTION_DRIVERKEY_NAME StringDescriptor;
+ DPRINT1("Usbhub: IOCTL_USB_GET_NODE_CONNECTION_DRIVERKEY_NAME\n");
+ DeviceExtension = (PHUB_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
+ StringDescriptor = (PUSB_NODE_CONNECTION_DRIVERKEY_NAME)BufferOut;
+ if (LengthOut < sizeof(USB_NODE_CONNECTION_DRIVERKEY_NAME))
+ Status = STATUS_BUFFER_TOO_SMALL;
+ else if (StringDescriptor == NULL)
+ Status = STATUS_INVALID_PARAMETER;
+ else if (StringDescriptor->ConnectionIndex < 1
+ || StringDescriptor->ConnectionIndex > USB_MAXCHILDREN)
+ Status = STATUS_INVALID_PARAMETER;
+ else if (DeviceExtension->Children[StringDescriptor->ConnectionIndex -
1] == NULL)
+ Status = STATUS_INVALID_PARAMETER;
+ else
+ {
+ ULONG StringSize;
+ Status = IoGetDeviceProperty(
+ DeviceExtension->Children[StringDescriptor->ConnectionIndex -
1],
+ DevicePropertyDriverKeyName,
+ LengthOut - FIELD_OFFSET(USB_NODE_CONNECTION_DRIVERKEY_NAME,
DriverKeyName),
+ StringDescriptor->DriverKeyName,
+ &StringSize);
+ if (NT_SUCCESS(Status) || Status == STATUS_BUFFER_TOO_SMALL)
+ {
+ StringDescriptor->ActualLength = StringSize +
FIELD_OFFSET(USB_NODE_CONNECTION_DRIVERKEY_NAME, DriverKeyName);
+ Information = LengthOut;
+ Status = STATUS_SUCCESS;
+ }
+ }
+ break;
+ }
+ default:
+ {
+ /* Pass Irp to lower driver */
+ DPRINT1("Usbhub: Unknown IOCTL code 0x%lx\n",
Stack->Parameters.DeviceIoControl.IoControlCode);
+ return ForwardIrpAndForget(DeviceObject, Irp);
+ }
+ }
+
+ Irp->IoStatus.Information = Information;
+ Irp->IoStatus.Status = Status;
+ IoCompleteRequest(Irp, IO_NO_INCREMENT);
+ return Status;
+}
Modified: trunk/reactos/drivers/usb/usbhub/misc.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/usb/usbhub/misc.c?…
==============================================================================
--- trunk/reactos/drivers/usb/usbhub/misc.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/usb/usbhub/misc.c [iso-8859-1] Sun Sep 5 19:00:37 2010
@@ -4,7 +4,7 @@
* FILE: drivers/usb/cromwell/hub/misc.c
* PURPOSE: Misceallenous operations
*
- * PROGRAMMERS: Hervé Poussineau (hpoussin(a)reactos.com),
+ * PROGRAMMERS: Herv� Poussineau (hpoussin(a)reactos.com),
*/
#define NDEBUG
@@ -13,54 +13,50 @@
NTSTATUS NTAPI
ForwardIrpAndWaitCompletion(
- IN PDEVICE_OBJECT DeviceObject,
- IN PIRP Irp,
- IN PVOID Context)
+ IN PDEVICE_OBJECT DeviceObject,
+ IN PIRP Irp,
+ IN PVOID Context)
{
- if (Irp->PendingReturned)
- KeSetEvent((PKEVENT)Context, IO_NO_INCREMENT, FALSE);
- return STATUS_MORE_PROCESSING_REQUIRED;
+ if (Irp->PendingReturned)
+ KeSetEvent((PKEVENT)Context, IO_NO_INCREMENT, FALSE);
+ return STATUS_MORE_PROCESSING_REQUIRED;
}
NTSTATUS
ForwardIrpAndWait(
- IN PDEVICE_OBJECT DeviceObject,
- IN PIRP Irp)
+ IN PDEVICE_OBJECT DeviceObject,
+ IN PIRP Irp)
{
- PDEVICE_OBJECT LowerDevice =
((PHUB_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->LowerDevice;
- KEVENT Event;
- NTSTATUS Status;
+ KEVENT Event;
+ NTSTATUS Status;
- ASSERT(LowerDevice);
+ KeInitializeEvent(&Event, NotificationEvent, FALSE);
+ IoCopyCurrentIrpStackLocationToNext(Irp);
- KeInitializeEvent(&Event, NotificationEvent, FALSE);
- IoCopyCurrentIrpStackLocationToNext(Irp);
+ IoSetCompletionRoutine(Irp, ForwardIrpAndWaitCompletion, &Event, TRUE, TRUE,
TRUE);
- DPRINT("UHCI: Calling lower device %p [%wZ]\n", LowerDevice,
&LowerDevice->DriverObject->DriverName);
- IoSetCompletionRoutine(Irp, ForwardIrpAndWaitCompletion, &Event, TRUE, TRUE, TRUE);
+ Status = IoCallDriver(DeviceObject, Irp);
+ if (Status == STATUS_PENDING)
+ {
+ Status = KeWaitForSingleObject(&Event, Suspended, KernelMode, FALSE, NULL);
+ if (NT_SUCCESS(Status))
+ Status = Irp->IoStatus.Status;
+ }
- Status = IoCallDriver(LowerDevice, Irp);
- if (Status == STATUS_PENDING)
- {
- Status = KeWaitForSingleObject(&Event, Suspended, KernelMode, FALSE, NULL);
- if (NT_SUCCESS(Status))
- Status = Irp->IoStatus.Status;
- }
-
- return Status;
+ return Status;
}
NTSTATUS NTAPI
ForwardIrpAndForget(
- IN PDEVICE_OBJECT DeviceObject,
- IN PIRP Irp)
+ IN PDEVICE_OBJECT DeviceObject,
+ IN PIRP Irp)
{
- PDEVICE_OBJECT LowerDevice =
((PHUB_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->LowerDevice;
+ PDEVICE_OBJECT LowerDevice =
((PHUB_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->LowerDevice;
- ASSERT(LowerDevice);
+ ASSERT(LowerDevice);
- IoSkipCurrentIrpStackLocation(Irp);
- return IoCallDriver(LowerDevice, Irp);
+ IoSkipCurrentIrpStackLocation(Irp);
+ return IoCallDriver(LowerDevice, Irp);
}
/* I really want PCSZ strings as last arguments because
@@ -68,99 +64,99 @@
* identification */
NTSTATUS
UsbhubInitMultiSzString(
- OUT PUNICODE_STRING Destination,
- ... /* list of PCSZ */)
+ OUT PUNICODE_STRING Destination,
+ ... /* list of PCSZ */)
{
- va_list args;
- PCSZ Source;
- ANSI_STRING AnsiString;
- UNICODE_STRING UnicodeString;
- ULONG DestinationSize = 0;
- NTSTATUS Status = STATUS_SUCCESS;
+ va_list args;
+ PCSZ Source;
+ ANSI_STRING AnsiString;
+ UNICODE_STRING UnicodeString;
+ ULONG DestinationSize = 0;
+ NTSTATUS Status = STATUS_SUCCESS;
- ASSERT(Destination);
+ ASSERT(Destination);
- /* Calculate length needed for destination unicode string */
- va_start(args, Destination);
- Source = va_arg(args, PCSZ);
- while (Source != NULL)
- {
- RtlInitAnsiString(&AnsiString, Source);
- DestinationSize += RtlAnsiStringToUnicodeSize(&AnsiString)
- + sizeof(WCHAR) /* final NULL */;
- Source = va_arg(args, PCSZ);
- }
- va_end(args);
- if (DestinationSize == 0)
- {
- RtlInitUnicodeString(Destination, NULL);
- return STATUS_SUCCESS;
- }
+ /* Calculate length needed for destination unicode string */
+ va_start(args, Destination);
+ Source = va_arg(args, PCSZ);
+ while (Source != NULL)
+ {
+ RtlInitAnsiString(&AnsiString, Source);
+ DestinationSize += RtlAnsiStringToUnicodeSize(&AnsiString)
+ + sizeof(WCHAR) /* final NULL */;
+ Source = va_arg(args, PCSZ);
+ }
+ va_end(args);
+ if (DestinationSize == 0)
+ {
+ RtlInitUnicodeString(Destination, NULL);
+ return STATUS_SUCCESS;
+ }
- /* Initialize destination string */
- DestinationSize += sizeof(WCHAR); // final NULL
- Destination->Buffer = (PWSTR)ExAllocatePoolWithTag(PagedPool, DestinationSize,
USB_HUB_TAG);
- if (!Destination->Buffer)
- return STATUS_INSUFFICIENT_RESOURCES;
- Destination->Length = 0;
- Destination->MaximumLength = (USHORT)DestinationSize;
+ /* Initialize destination string */
+ DestinationSize += sizeof(WCHAR); // final NULL
+ Destination->Buffer = (PWSTR)ExAllocatePoolWithTag(PagedPool, DestinationSize,
USB_HUB_TAG);
+ if (!Destination->Buffer)
+ return STATUS_INSUFFICIENT_RESOURCES;
+ Destination->Length = 0;
+ Destination->MaximumLength = (USHORT)DestinationSize;
- /* Copy arguments to destination string */
- /* Use a temporary unicode string, which buffer is shared with
- * destination string, to copy arguments */
- UnicodeString.Length = Destination->Length;
- UnicodeString.MaximumLength = Destination->MaximumLength;
- UnicodeString.Buffer = Destination->Buffer;
- va_start(args, Destination);
- Source = va_arg(args, PCSZ);
- while (Source != NULL)
- {
- RtlInitAnsiString(&AnsiString, Source);
- Status = RtlAnsiStringToUnicodeString(&UnicodeString, &AnsiString, FALSE);
- if (!NT_SUCCESS(Status))
- {
- ExFreePoolWithTag(Destination->Buffer, USB_HUB_TAG);
- break;
- }
- Destination->Length += UnicodeString.Length + sizeof(WCHAR);
- UnicodeString.MaximumLength -= UnicodeString.Length + sizeof(WCHAR);
- UnicodeString.Buffer += UnicodeString.Length / sizeof(WCHAR) + 1;
- UnicodeString.Length = 0;
- Source = va_arg(args, PCSZ);
- }
- va_end(args);
- if (NT_SUCCESS(Status))
- {
- /* Finish multi-sz string */
- Destination->Buffer[Destination->Length / sizeof(WCHAR)] = L'\0';
- Destination->Length += sizeof(WCHAR);
- }
- return Status;
+ /* Copy arguments to destination string */
+ /* Use a temporary unicode string, which buffer is shared with
+ * destination string, to copy arguments */
+ UnicodeString.Length = Destination->Length;
+ UnicodeString.MaximumLength = Destination->MaximumLength;
+ UnicodeString.Buffer = Destination->Buffer;
+ va_start(args, Destination);
+ Source = va_arg(args, PCSZ);
+ while (Source != NULL)
+ {
+ RtlInitAnsiString(&AnsiString, Source);
+ Status = RtlAnsiStringToUnicodeString(&UnicodeString, &AnsiString,
FALSE);
+ if (!NT_SUCCESS(Status))
+ {
+ ExFreePoolWithTag(Destination->Buffer, USB_HUB_TAG);
+ break;
+ }
+ Destination->Length += UnicodeString.Length + sizeof(WCHAR);
+ UnicodeString.MaximumLength -= UnicodeString.Length + sizeof(WCHAR);
+ UnicodeString.Buffer += UnicodeString.Length / sizeof(WCHAR) + 1;
+ UnicodeString.Length = 0;
+ Source = va_arg(args, PCSZ);
+ }
+ va_end(args);
+ if (NT_SUCCESS(Status))
+ {
+ /* Finish multi-sz string */
+ Destination->Buffer[Destination->Length / sizeof(WCHAR)] = L'\0';
+ Destination->Length += sizeof(WCHAR);
+ }
+ return Status;
}
NTSTATUS
UsbhubDuplicateUnicodeString(
- OUT PUNICODE_STRING Destination,
- IN PUNICODE_STRING Source,
- IN POOL_TYPE PoolType)
+ OUT PUNICODE_STRING Destination,
+ IN PUNICODE_STRING Source,
+ IN POOL_TYPE PoolType)
{
- ASSERT(Destination);
+ ASSERT(Destination);
- if (Source == NULL)
- {
- RtlInitUnicodeString(Destination, NULL);
- return STATUS_SUCCESS;
- }
+ if (Source == NULL)
+ {
+ RtlInitUnicodeString(Destination, NULL);
+ return STATUS_SUCCESS;
+ }
- Destination->Buffer = ExAllocatePool(PoolType, Source->MaximumLength);
- if (Destination->Buffer == NULL)
- {
- return STATUS_INSUFFICIENT_RESOURCES;
- }
+ Destination->Buffer = ExAllocatePool(PoolType, Source->MaximumLength);
+ if (Destination->Buffer == NULL)
+ {
+ return STATUS_INSUFFICIENT_RESOURCES;
+ }
- Destination->MaximumLength = Source->MaximumLength;
- Destination->Length = Source->Length;
- RtlCopyMemory(Destination->Buffer, Source->Buffer, Source->MaximumLength);
+ Destination->MaximumLength = Source->MaximumLength;
+ Destination->Length = Source->Length;
+ RtlCopyMemory(Destination->Buffer, Source->Buffer, Source->MaximumLength);
- return STATUS_SUCCESS;
+ return STATUS_SUCCESS;
}
Modified: trunk/reactos/drivers/usb/usbhub/pdo.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/usb/usbhub/pdo.c?r…
==============================================================================
--- trunk/reactos/drivers/usb/usbhub/pdo.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/usb/usbhub/pdo.c [iso-8859-1] Sun Sep 5 19:00:37 2010
@@ -5,6 +5,7 @@
* PURPOSE: IRP_MJ_PNP operations for PDOs
*
* PROGRAMMERS: Copyright 2005-2006 Hervé Poussineau (hpoussin(a)reactos.org)
+ * 2010 Michael Martin (michael.martin(a)reactos.org)
*/
#define NDEBUG
@@ -22,7 +23,7 @@
ULONG_PTR Information = 0;
NTSTATUS Status;
- DPRINT("Usbhub: UsbhubInternalDeviceControlPdo() called\n");
+ DPRINT1("Usbhub: UsbhubInternalDeviceControlPdo() called\n");
Stack = IoGetCurrentIrpStackLocation(Irp);
Status = Irp->IoStatus.Status;
@@ -33,7 +34,7 @@
{
PHUB_DEVICE_EXTENSION DeviceExtension;
- DPRINT("Usbhub: IOCTL_INTERNAL_USB_GET_PARENT_HUB_INFO\n");
+ DPRINT1("Usbhub: IOCTL_INTERNAL_USB_GET_PARENT_HUB_INFO\n");
if (Irp->AssociatedIrp.SystemBuffer == NULL
|| Stack->Parameters.DeviceIoControl.OutputBufferLength != sizeof(PVOID))
{
@@ -71,28 +72,30 @@
IN PIRP Irp)
{
PHUB_DEVICE_EXTENSION DeviceExtension;
- NTSTATUS Status;
+ NTSTATUS Status = STATUS_UNSUCCESSFUL;
DeviceExtension = (PHUB_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
/* Register and activate device interface */
+/*
Status = IoRegisterDeviceInterface(
DeviceObject,
DeviceExtension->dev->descriptor.bDeviceClass == USB_CLASS_HUB ?
&GUID_DEVINTERFACE_USB_HUB :
&GUID_DEVINTERFACE_USB_DEVICE,
- NULL, /* Reference string */
+ NULL,
&DeviceExtension->SymbolicLinkName);
+*/
if (!NT_SUCCESS(Status))
{
- DPRINT("Usbhub: IoRegisterDeviceInterface() failed with status 0x%08lx\n",
Status);
+ DPRINT1("Usbhub: IoRegisterDeviceInterface() failed with status 0x%08lx\n",
Status);
return Status;
}
- Status = IoSetDeviceInterfaceState(&DeviceExtension->SymbolicLinkName, TRUE);
+ //Status = IoSetDeviceInterfaceState(&DeviceExtension->SymbolicLinkName, TRUE);
if (!NT_SUCCESS(Status))
{
- DPRINT("Usbhub: IoSetDeviceInterfaceState() failed with status 0x%08lx\n",
Status);
+ DPRINT1("Usbhub: IoSetDeviceInterfaceState() failed with status 0x%08lx\n",
Status);
return Status;
}
@@ -119,25 +122,25 @@
{
case BusQueryDeviceID:
{
- DPRINT("Usbhub: IRP_MJ_PNP / IRP_MN_QUERY_ID / BusQueryDeviceID\n");
+ DPRINT1("Usbhub: IRP_MJ_PNP / IRP_MN_QUERY_ID / BusQueryDeviceID\n");
SourceString = &DeviceExtension->DeviceId;
break;
}
case BusQueryHardwareIDs:
{
- DPRINT("Usbhub: IRP_MJ_PNP / IRP_MN_QUERY_ID / BusQueryHardwareIDs\n");
+ DPRINT1("Usbhub: IRP_MJ_PNP / IRP_MN_QUERY_ID / BusQueryHardwareIDs\n");
SourceString = &DeviceExtension->HardwareIds;
break;
}
case BusQueryCompatibleIDs:
{
- DPRINT("Usbhub: IRP_MJ_PNP / IRP_MN_QUERY_ID / BusQueryCompatibleIDs\n");
+ DPRINT1("Usbhub: IRP_MJ_PNP / IRP_MN_QUERY_ID / BusQueryCompatibleIDs\n");
SourceString = &DeviceExtension->CompatibleIds;
break;
}
case BusQueryInstanceID:
{
- DPRINT("Usbhub: IRP_MJ_PNP / IRP_MN_QUERY_ID / BusQueryInstanceID\n");
+ DPRINT1("Usbhub: IRP_MJ_PNP / IRP_MN_QUERY_ID / BusQueryInstanceID\n");
SourceString = &DeviceExtension->InstanceId;
break;
}
@@ -167,57 +170,20 @@
DeviceTextType =
IoGetCurrentIrpStackLocation(Irp)->Parameters.QueryDeviceText.DeviceTextType;
LocaleId = IoGetCurrentIrpStackLocation(Irp)->Parameters.QueryDeviceText.LocaleId;
DeviceExtension = (PHUB_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
-
+DPRINT1("Usbhub: UsbhubPdoQueryDeviceText\n");
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");
+ DPRINT1("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);
+ DPRINT1("Usbhub: IRP_MJ_PNP / IRP_MN_QUERY_DEVICE_TEXT /
DeviceTextLocationInformation\n");
+
+/* if (!DeviceExtension->dev->descriptor.iProduct)
+ return STATUS_NOT_SUPPORTED;*/
+
return STATUS_SUCCESS;
}
default:
@@ -243,7 +209,7 @@
{
case IRP_MN_START_DEVICE: /* 0x0 */
{
- DPRINT("Usbhub: IRP_MJ_PNP / IRP_MN_START_DEVICE\n");
+ DPRINT1("Usbhub: IRP_MJ_PNP / IRP_MN_START_DEVICE\n");
Status = UsbhubPdoStartDevice(DeviceObject, Irp);
break;
}
@@ -251,7 +217,7 @@
{
PDEVICE_CAPABILITIES DeviceCapabilities;
ULONG i;
- DPRINT("Usbhub: IRP_MJ_PNP / IRP_MN_QUERY_CAPABILITIES\n");
+ DPRINT1("Usbhub: IRP_MJ_PNP / IRP_MN_QUERY_CAPABILITIES\n");
DeviceCapabilities =
(PDEVICE_CAPABILITIES)Stack->Parameters.DeviceCapabilities.Capabilities;
/* FIXME: capabilities can change with connected device */
@@ -279,11 +245,11 @@
{
PCM_RESOURCE_LIST ResourceList;
- DPRINT("Usbhub: IRP_MJ_PNP / IRP_MN_QUERY_RESOURCES\n");
+ DPRINT1("Usbhub: IRP_MJ_PNP / IRP_MN_QUERY_RESOURCES\n");
ResourceList = ExAllocatePool(PagedPool, sizeof(CM_RESOURCE_LIST));
if (!ResourceList)
{
- DPRINT("Usbhub: ExAllocatePool() failed\n");
+ DPRINT1("Usbhub: ExAllocatePool() failed\n");
Status = STATUS_INSUFFICIENT_RESOURCES;
}
else
@@ -298,11 +264,11 @@
{
PIO_RESOURCE_REQUIREMENTS_LIST ResourceList;
- DPRINT("Usbhub: IRP_MJ_PNP / IRP_MN_QUERY_RESOURCE_REQUIREMENTS\n");
+ DPRINT1("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");
+ DPRINT1("Usbhub: ExAllocatePool() failed\n");
Status = STATUS_INSUFFICIENT_RESOURCES;
}
else
Modified: trunk/reactos/drivers/usb/usbhub/usbhub.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/usb/usbhub/usbhub.…
==============================================================================
--- trunk/reactos/drivers/usb/usbhub/usbhub.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/usb/usbhub/usbhub.c [iso-8859-1] Sun Sep 5 19:00:37 2010
@@ -2,7 +2,8 @@
* ReactOS USB hub driver
* Copyright (C) 2004 Aleksey Bragin
* (C) 2005 Mark Tempel
- * (C) 2005 Hervé Poussineau
+ * (C) 2005 Herv� Poussineau
+ * (C) 2010 Michael Martin
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -26,159 +27,107 @@
/* PUBLIC AND PRIVATE FUNCTIONS ***********************************************/
-static NTSTATUS
-GetRootHubPointer(
- IN PDEVICE_OBJECT Pdo,
- OUT PVOID* RootHubPointer)
-{
- KEVENT Event;
- PIRP Irp;
- IO_STATUS_BLOCK IoStatus;
- NTSTATUS Status;
-
- KeInitializeEvent (&Event, NotificationEvent, FALSE);
-
- Irp = IoBuildDeviceIoControlRequest(IOCTL_INTERNAL_USB_GET_PARENT_HUB_INFO,
- Pdo,
- NULL, sizeof(NULL),
- RootHubPointer, sizeof(*RootHubPointer),
- FALSE,
- &Event,
- &IoStatus);
- if (Irp == NULL)
- {
- DPRINT("Usbhub: IoBuildDeviceIoControlRequest() failed\n");
- return STATUS_INSUFFICIENT_RESOURCES;
- }
-
- /* Initialize the status block before sending the IRP */
- IoGetNextIrpStackLocation(Irp)->MajorFunction = IRP_MJ_INTERNAL_DEVICE_CONTROL;
- IoStatus.Status = STATUS_NOT_SUPPORTED;
- IoStatus.Information = 0;
-
- Status = IoCallDriver(Pdo, Irp);
-
- if (Status == STATUS_PENDING)
- {
- DPRINT("Usbhub: Operation pending\n");
- KeWaitForSingleObject(&Event, Suspended, KernelMode, FALSE, NULL);
- Status = IoStatus.Status;
- }
-
- return Status;
-}
-
NTSTATUS NTAPI
UsbhubAddDevice(
- IN PDRIVER_OBJECT DriverObject,
- IN PDEVICE_OBJECT Pdo)
+ IN PDRIVER_OBJECT DriverObject,
+ IN PDEVICE_OBJECT Pdo)
{
- PDEVICE_OBJECT Fdo;
- PHUB_DEVICE_EXTENSION DeviceExtension;
- NTSTATUS Status;
+ PDEVICE_OBJECT Fdo;
+ PHUB_DEVICE_EXTENSION DeviceExtension;
+ NTSTATUS Status;
- Status = IoCreateDevice(DriverObject,
- sizeof(HUB_DEVICE_EXTENSION),
- NULL, /* DeviceName */
- FILE_DEVICE_BUS_EXTENDER,
- 0,
- FALSE,
- &Fdo);
- if (!NT_SUCCESS(Status))
- {
- DPRINT1("Usbhub: IoCreateDevice() failed with status 0x%08lx\n", Status);
- return Status;
- }
+ Status = IoCreateDevice(DriverObject,
+ sizeof(HUB_DEVICE_EXTENSION),
+ NULL, /* DeviceName */
+ FILE_DEVICE_BUS_EXTENDER,
+ FILE_AUTOGENERATED_DEVICE_NAME,
+ FALSE,
+ &Fdo);
- // zerofill device extension
- DeviceExtension = (PHUB_DEVICE_EXTENSION)Fdo->DeviceExtension;
- RtlZeroMemory(DeviceExtension, sizeof(HUB_DEVICE_EXTENSION));
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT1("Usbhub: IoCreateDevice() failed with status 0x%08lx\n",
Status);
+ return Status;
+ }
- /* Get a pointer to the linux structure created by the USB controller,
- * by sending IOCTL_INTERNAL_USB_GET_PARENT_HUB_INFO to lower device.
- */
- Status = GetRootHubPointer(Pdo, (PVOID*)&DeviceExtension->dev);
- if (!NT_SUCCESS(Status))
- {
- DPRINT("Usbhub: GetRootHubPointer() failed with status 0x%08lx\n", Status);
- IoDeleteDevice(Fdo);
- return Status;
- }
- DeviceExtension->dev->dev.dev_ext = Pdo;
+ // zerofill device extension
+ DeviceExtension = (PHUB_DEVICE_EXTENSION)Fdo->DeviceExtension;
+ RtlZeroMemory(DeviceExtension, sizeof(HUB_DEVICE_EXTENSION));
- DeviceExtension->IsFDO = TRUE;
- Fdo->Flags |= DO_POWER_PAGABLE;
- Status = IoAttachDeviceToDeviceStackSafe(Fdo, Pdo,
&DeviceExtension->LowerDevice);
- if (!NT_SUCCESS(Status))
- {
- DPRINT("Usbhub: IoAttachDeviceToDeviceStackSafe() failed with status
0x%08lx\n", Status);
- IoDeleteDevice(Fdo);
- return Status;
- }
- Fdo->Flags |= DO_BUFFERED_IO;
- Fdo->Flags &= ~DO_DEVICE_INITIALIZING;
+ DeviceExtension->IsFDO = TRUE;
+ Fdo->Flags |= DO_POWER_PAGABLE;
+ Status = IoAttachDeviceToDeviceStackSafe(Fdo, Pdo,
&DeviceExtension->LowerDevice);
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT("Usbhub: IoAttachDeviceToDeviceStackSafe() failed with status
0x%08lx\n", Status);
+ IoDeleteDevice(Fdo);
+ return Status;
+ }
+ Fdo->Flags |= DO_BUFFERED_IO;
- return STATUS_SUCCESS;
+ Fdo->Flags &= ~DO_DEVICE_INITIALIZING;
+
+ return STATUS_SUCCESS;
}
static NTSTATUS NTAPI
IrpStub(
- IN PDEVICE_OBJECT DeviceObject,
- IN PIRP Irp)
+ IN PDEVICE_OBJECT DeviceObject,
+ IN PIRP Irp)
{
- NTSTATUS Status;
+ NTSTATUS Status;
- if (((PHUB_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->IsFDO)
- {
- DPRINT1("Usbhub: FDO stub for major function 0x%lx\n",
- IoGetCurrentIrpStackLocation(Irp)->MajorFunction);
+ if (((PHUB_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->IsFDO)
+ {
+ DPRINT1("Usbhub: FDO stub for major function 0x%lx\n",
+ IoGetCurrentIrpStackLocation(Irp)->MajorFunction);
+ return ForwardIrpAndForget(DeviceObject, Irp);
+ }
+ else
+ {
+ /* We can't forward request to the lower driver, because
+ * we are a Pdo, so we don't have lower driver...
+ */
+ DPRINT1("Usbhub: PDO stub for major function 0x%lx\n",
+ IoGetCurrentIrpStackLocation(Irp)->MajorFunction);
#ifndef NDEBUG
- DbgBreakPoint();
+ DbgBreakPoint();
#endif
- return ForwardIrpAndForget(DeviceObject, Irp);
- }
- else
- {
- /* We can't forward request to the lower driver, because
- * we are a Pdo, so we don't have lower driver...
- */
- DPRINT1("Usbhub: PDO stub for major function 0x%lx\n",
- IoGetCurrentIrpStackLocation(Irp)->MajorFunction);
-#ifndef NDEBUG
- DbgBreakPoint();
-#endif
- }
+ }
- Status = Irp->IoStatus.Status;
- IoCompleteRequest(Irp, IO_NO_INCREMENT);
- return Status;
+ Status = Irp->IoStatus.Status;
+ IoCompleteRequest(Irp, IO_NO_INCREMENT);
+ return Status;
}
static NTSTATUS NTAPI
DispatchDeviceControl(PDEVICE_OBJECT DeviceObject, PIRP Irp)
{
- if (((PHUB_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->IsFDO)
- return UsbhubDeviceControlFdo(DeviceObject, Irp);
- else
- return IrpStub(DeviceObject, Irp);
+ DPRINT1("Usbhub: DispatchDeviceControl\n");
+ if (((PHUB_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->IsFDO)
+ return UsbhubDeviceControlFdo(DeviceObject, Irp);
+ else
+ return IrpStub(DeviceObject, Irp);
}
static NTSTATUS NTAPI
DispatchInternalDeviceControl(PDEVICE_OBJECT DeviceObject, PIRP Irp)
{
- if (((PHUB_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->IsFDO)
- return IrpStub(DeviceObject, Irp);
- else
- return UsbhubInternalDeviceControlPdo(DeviceObject, Irp);
+ DPRINT1("Usbhub: DispatchInternalDeviceControl\n");
+ if (((PHUB_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->IsFDO)
+ return IrpStub(DeviceObject, Irp);
+ else
+ return UsbhubInternalDeviceControlPdo(DeviceObject, Irp);
}
static NTSTATUS NTAPI
DispatchPnp(PDEVICE_OBJECT DeviceObject, PIRP Irp)
{
- if (((PHUB_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->IsFDO)
- return UsbhubPnpFdo(DeviceObject, Irp);
- else
- return UsbhubPnpPdo(DeviceObject, Irp);
+ DPRINT1("Usbhub: DispatchPnp\n");
+ if (((PHUB_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->IsFDO)
+ return UsbhubPnpFdo(DeviceObject, Irp);
+ else
+ return UsbhubPnpPdo(DeviceObject, Irp);
}
/*
@@ -186,23 +135,24 @@
*/
NTSTATUS NTAPI
DriverEntry(
- IN PDRIVER_OBJECT DriverObject,
- IN PUNICODE_STRING RegistryPath)
+ IN PDRIVER_OBJECT DriverObject,
+ IN PUNICODE_STRING RegistryPath)
{
- ULONG i;
+ ULONG i;
- DriverObject->DriverExtension->AddDevice = UsbhubAddDevice;
+ DriverObject->DriverExtension->AddDevice = UsbhubAddDevice;
+ DPRINT1("Usbhub: DriverEntry\n");
- for (i = 0; i <= IRP_MJ_MAXIMUM_FUNCTION; i++)
- DriverObject->MajorFunction[i] = IrpStub;
+ for (i = 0; i <= IRP_MJ_MAXIMUM_FUNCTION; i++)
+ DriverObject->MajorFunction[i] = IrpStub;
- DriverObject->MajorFunction[IRP_MJ_CREATE] = UsbhubCreate;
- DriverObject->MajorFunction[IRP_MJ_CLOSE] = UsbhubClose;
- DriverObject->MajorFunction[IRP_MJ_CLEANUP] = UsbhubCleanup;
- DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = DispatchDeviceControl;
- DriverObject->MajorFunction[IRP_MJ_INTERNAL_DEVICE_CONTROL] =
DispatchInternalDeviceControl;
- DriverObject->MajorFunction[IRP_MJ_PNP] = DispatchPnp;
+ DriverObject->MajorFunction[IRP_MJ_CREATE] = UsbhubCreate;
+ DriverObject->MajorFunction[IRP_MJ_CLOSE] = UsbhubClose;
+ DriverObject->MajorFunction[IRP_MJ_CLEANUP] = UsbhubCleanup;
+ DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = DispatchDeviceControl;
+ DriverObject->MajorFunction[IRP_MJ_INTERNAL_DEVICE_CONTROL] =
DispatchInternalDeviceControl;
+ DriverObject->MajorFunction[IRP_MJ_PNP] = DispatchPnp;
- return STATUS_SUCCESS;
+ return STATUS_SUCCESS;
}
Modified: trunk/reactos/drivers/usb/usbhub/usbhub.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/usb/usbhub/usbhub.…
==============================================================================
--- trunk/reactos/drivers/usb/usbhub/usbhub.h [iso-8859-1] (original)
+++ trunk/reactos/drivers/usb/usbhub/usbhub.h [iso-8859-1] Sun Sep 5 19:00:37 2010
@@ -1,27 +1,98 @@
+#include <ntddk.h>
+#include <hubbusif.h>
+#include <usbbusif.h>
+#include <usbioctl.h>
+#include <usb.h>
#include <debug.h>
-
-#include <ntddk.h>
-#include <usbioctl.h>
-
-#include "../miniport/usb_wrapper.h"
-#include "../usbport/hub.h"
+//BROKEN: #include <usbprotocoldefs.h>
#define USB_HUB_TAG 'hbsu'
+#define USB_MAXCHILDREN 127
+
+/* Lifted from broken header above */
+#define C_HUB_LOCAL_POWER 0
+#define C_HUB_OVER_CURRENT 1
+#define PORT_CONNECTION 0
+#define PORT_ENABLE 1
+#define PORT_SUSPEND 2
+#define PORT_OVER_CURRENT 3
+#define PORT_RESET 4
+#define PORT_POWER 8
+#define PORT_LOW_SPEED 9
+#define C_PORT_CONNECTION 16
+#define C_PORT_ENABLE 17
+#define C_PORT_SUSPEND 18
+#define C_PORT_OVER_CURRENT 19
+#define C_PORT_RESET 20
+#define PORT_TEST 21
+#define PORT_INDICATOR 22
+
+typedef struct _USB_ENDPOINT
+{
+ ULONG Flags;
+ LIST_ENTRY UrbList;
+ struct _USB_INTERFACE *Interface;
+ USB_ENDPOINT_DESCRIPTOR EndPointDescriptor;
+} USB_ENDPOINT, *PUSB_ENDPOINT;
+
+typedef struct _USB_INTERFACE
+{
+ struct _USB_CONFIGURATION *Config;
+ USB_INTERFACE_DESCRIPTOR InterfaceDescriptor;
+ USB_ENDPOINT *EndPoints[];
+} USB_INTERFACE, *PUSB_INTERFACE;
+
+typedef struct _USB_CONFIGURATION
+{
+ struct _USB_DEVICE *Device;
+ USB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor;
+ USB_INTERFACE *Interfaces[];
+} USB_CONFIGURATION, *PUSB_CONFIGURATION;
+
+typedef struct _USB_DEVICE
+{
+ UCHAR Address;
+ ULONG Port;
+ PVOID ParentDevice;
+ BOOLEAN IsHub;
+ USB_DEVICE_SPEED DeviceSpeed;
+ USB_DEVICE_TYPE DeviceType;
+ USB_DEVICE_DESCRIPTOR DeviceDescriptor;
+ USB_CONFIGURATION *ActiveConfig;
+ USB_INTERFACE *ActiveInterface;
+ USB_CONFIGURATION **Configs;
+
+} USB_DEVICE, *PUSB_DEVICE;
typedef struct _HUB_DEVICE_EXTENSION
{
BOOLEAN IsFDO;
- struct usb_device* dev;
+ USB_DEVICE* dev;
PDEVICE_OBJECT LowerDevice;
-
+ ULONG ChildCount;
PDEVICE_OBJECT Children[USB_MAXCHILDREN];
- /* Fields valid only when IsFDO == FALSE */
- UNICODE_STRING DeviceId; // REG_SZ
- UNICODE_STRING InstanceId; // REG_SZ
- UNICODE_STRING HardwareIds; // REG_MULTI_SZ
- UNICODE_STRING CompatibleIds; // REG_MULTI_SZ
- UNICODE_STRING SymbolicLinkName;
+ PUSB_DEVICE RootHubUsbDevice;
+
+ PDEVICE_OBJECT RootHubPdo;
+ PDEVICE_OBJECT RootHubFdo;
+
+ ULONG HubCount;
+
+ USB_BUS_INTERFACE_HUB_V5 HubInterface;
+ USB_BUS_INTERFACE_USBDI_V2 UsbDInterface;
+
+ USB_HUB_DESCRIPTOR HubDescriptor;
+ USB_DEVICE_DESCRIPTOR HubDeviceDescriptor;
+ USB_CONFIGURATION_DESCRIPTOR HubConfig;
+ USB_EXTHUB_INFORMATION_0 UsbExtHubInfo;
+
+ /* Fields valid only when IsFDO == FALSE */
+ UNICODE_STRING DeviceId; // REG_SZ
+ UNICODE_STRING InstanceId; // REG_SZ
+ UNICODE_STRING HardwareIds; // REG_MULTI_SZ
+ UNICODE_STRING CompatibleIds; // REG_MULTI_SZ
+ UNICODE_STRING SymbolicLinkName;
} HUB_DEVICE_EXTENSION, *PHUB_DEVICE_EXTENSION;
/* createclose.c */
Modified: trunk/reactos/drivers/usb/usbhub/usbhub.rbuild
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/usb/usbhub/usbhub.…
==============================================================================
--- trunk/reactos/drivers/usb/usbhub/usbhub.rbuild [iso-8859-1] (original)
+++ trunk/reactos/drivers/usb/usbhub/usbhub.rbuild [iso-8859-1] Sun Sep 5 19:00:37 2010
@@ -1,11 +1,8 @@
<?xml version="1.0"?>
<!DOCTYPE module SYSTEM "../../../tools/rbuild/project.dtd">
<module name="usbhub" type="kernelmodedriver"
installbase="system32/drivers" installname="usbhub.sys">
- <include>../miniport/linux</include>
- <library>sys_base</library>
<library>ntoskrnl</library>
<library>hal</library>
- <library>usbport</library>
<file>createclose.c</file>
<file>fdo.c</file>
<file>misc.c</file>