[ros-diffs] [mjmartin] 46735: [usb/usbehci] - Modify UsbDevice structure to hold all the device's configurations vice only the active one. - Change code to handle new UsbDevice structure and data. - Add missing Status assignment for IOCTLs get device handle and get hub count. - When checking port status in deffered routine continue looping through the ports if the device is not high speed. - Implement direct call functions InitializeUsbDevice, QueryDeviceInformation and GetControllerInformation. - Fix incorrect return type for direct call function GetUSBDIVersion. - Remove no longer needed structures from usbiffn.h as they are now in usbbusif.h and hubbusif.h. - Code based on XEN PV Drivers by James Harper.

mjmartin at svn.reactos.org mjmartin at svn.reactos.org
Mon Apr 5 14:23:30 CEST 2010


Author: mjmartin
Date: Mon Apr  5 14:23:30 2010
New Revision: 46735

URL: http://svn.reactos.org/svn/reactos?rev=46735&view=rev
Log:
[usb/usbehci]
- Modify UsbDevice structure to hold all the device's configurations vice only the active one.
- Change code to handle new UsbDevice structure and data.
- Add missing Status assignment for IOCTLs get device handle and get hub count.
- When checking port status in deffered routine continue looping through the ports if the device is not high speed.
- Implement direct call functions InitializeUsbDevice, QueryDeviceInformation and GetControllerInformation.
- Fix incorrect return type for direct call function GetUSBDIVersion.
- Remove no longer needed structures from usbiffn.h as they are now in usbbusif.h and hubbusif.h.
- Code based on XEN PV Drivers by James Harper.

Modified:
    trunk/reactos/drivers/usb/usbehci/fdo.c
    trunk/reactos/drivers/usb/usbehci/irp.c
    trunk/reactos/drivers/usb/usbehci/pdo.c
    trunk/reactos/drivers/usb/usbehci/usbehci.h
    trunk/reactos/drivers/usb/usbehci/usbiffn.c
    trunk/reactos/drivers/usb/usbehci/usbiffn.h

Modified: trunk/reactos/drivers/usb/usbehci/fdo.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/usb/usbehci/fdo.c?rev=46735&r1=46734&r2=46735&view=diff
==============================================================================
--- trunk/reactos/drivers/usb/usbehci/fdo.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/usb/usbehci/fdo.c [iso-8859-1] Mon Apr  5 14:23:30 2010
@@ -83,11 +83,11 @@
                             DPRINT1("Releasing ownership to companion host controller!\n");
                             /* Release ownership to companion host controller */
                             WRITE_REGISTER_ULONG((PULONG) ((Base + EHCI_PORTSC) + (4 * i)), 0x4000);
+                            continue;
                         }
                     }
 
                     KeStallExecutionProcessor(30);
-                    DPRINT("port tmp %x\n", tmp);
 
                     /* As per USB 2.0 Specs, 9.1.2. Reset the port and clear the status change */
                     tmp |= 0x100 | 0x02;
@@ -545,6 +545,7 @@
 
     StartEhci(DeviceObject);
     FdoDeviceExtension->DeviceState = DEVICESTARTED;
+
     return STATUS_SUCCESS;
 }
 
@@ -814,7 +815,6 @@
         IoDetachDevice(FdoDeviceExtension->LowerDevice);
         IoDeleteSymbolicLink(&SymLinkName);
         IoDeleteDevice(Fdo);
-
         return STATUS_UNSUCCESSFUL;
     }
 
@@ -840,11 +840,14 @@
     if (!NT_SUCCESS(Status))
     {
         DPRINT1("Unable to register device interface!\n");
+        ASSERT(FALSE);
     }
     else
     {
         Status = IoSetDeviceInterfaceState(&InterfaceSymLinkName, TRUE);
         DPRINT1("SetInterfaceState %x\n", Status);
+        if (!NT_SUCCESS(Status))
+            ASSERT(FALSE);
     }
     Fdo->Flags &= ~DO_DEVICE_INITIALIZING;
 

Modified: trunk/reactos/drivers/usb/usbehci/irp.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/usb/usbehci/irp.c?rev=46735&r1=46734&r2=46735&view=diff
==============================================================================
--- trunk/reactos/drivers/usb/usbehci/irp.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/usb/usbehci/irp.c [iso-8859-1] Mon Apr  5 14:23:30 2010
@@ -101,7 +101,7 @@
                 DPRINT1("--->TransferBufferLength %x\n",Urb->UrbBulkOrInterruptTransfer.TransferBufferLength);
                 DPRINT1("--->TransferBuffer %x\n",Urb->UrbBulkOrInterruptTransfer.TransferBuffer);
                 DPRINT1("--->PipeHandle %x\n",Urb->UrbBulkOrInterruptTransfer.PipeHandle);
-                DPRINT1("---->(PVOID)&UsbDevice->EndPointDescriptor %x\n", (PVOID)&UsbDevice->EndPointDescriptor);
+                DPRINT1("---->(PVOID)&UsbDevice->EndPointDescriptor %x\n", (PVOID)&UsbDevice->ActiveInterface->EndPoints[0]->EndPointDescriptor);
                 DPRINT1("--->TransferFlags %x\n", Urb->UrbBulkOrInterruptTransfer.TransferFlags);
 
                 RtlZeroMemory(Urb->UrbBulkOrInterruptTransfer.TransferBuffer, Urb->UrbBulkOrInterruptTransfer.TransferBufferLength);
@@ -142,6 +142,7 @@
                     DPRINT1("Uknown identifier\n");
                     Urb->UrbHeader.Status = USBD_STATUS_INVALID_URB_FUNCTION;
                     Status = STATUS_UNSUCCESSFUL;
+                    ASSERT(FALSE);
                 }
                 break;
             }
@@ -164,19 +165,39 @@
                     }
                     case USB_CONFIGURATION_DESCRIPTOR_TYPE:
                     {
+                        PUCHAR BufPtr;
+                        LONG i, j;
+
                         DPRINT1("USB CONFIG DESC\n");
-                        ULONG FullDescriptorLength = sizeof(USB_CONFIGURATION_DESCRIPTOR) +
-                                                     sizeof(USB_INTERFACE_DESCRIPTOR) +
-                                                     sizeof(USB_ENDPOINT_DESCRIPTOR);
-
-                        if (Urb->UrbControlDescriptorRequest.TransferBufferLength >= FullDescriptorLength)
-                        {
-                            Urb->UrbControlDescriptorRequest.TransferBufferLength = FullDescriptorLength;
-                        }
-
-                        RtlCopyMemory(Urb->UrbControlDescriptorRequest.TransferBuffer,
-                                      &UsbDevice->ConfigurationDescriptor,
-                                      Urb->UrbControlDescriptorRequest.TransferBufferLength);
+
+                        if (Urb->UrbControlDescriptorRequest.TransferBufferLength >= UsbDevice->ActiveConfig->ConfigurationDescriptor.wTotalLength)
+                        {
+                            Urb->UrbControlDescriptorRequest.TransferBufferLength = UsbDevice->ActiveConfig->ConfigurationDescriptor.wTotalLength;
+                        }
+                        else
+                        {
+                            DPRINT1("Buffer to small!!!\n");
+                            ASSERT(FALSE);
+                        }
+
+                        BufPtr = (PUCHAR)Urb->UrbControlDescriptorRequest.TransferBuffer;
+
+                        /* Copy the Configuration Descriptor */
+                        RtlCopyMemory(BufPtr, &UsbDevice->ActiveConfig->ConfigurationDescriptor, sizeof(USB_CONFIGURATION_DESCRIPTOR));
+                        BufPtr += sizeof(USB_CONFIGURATION_DESCRIPTOR);
+                        for (i = 0; i < UsbDevice->ActiveConfig->ConfigurationDescriptor.bNumInterfaces; i++)
+                        {
+                            /* Copy the Interface Descriptor */
+                            RtlCopyMemory(BufPtr, &UsbDevice->ActiveConfig->Interfaces[i]->InterfaceDescriptor, sizeof(USB_INTERFACE_DESCRIPTOR));
+                            BufPtr += sizeof(USB_INTERFACE_DESCRIPTOR);
+                            for (j = 0; j < UsbDevice->ActiveConfig->Interfaces[i]->InterfaceDescriptor.bNumEndpoints; j++)
+                            {
+                                /* Copy the EndPoint Descriptor */
+                                RtlCopyMemory(BufPtr, &UsbDevice->ActiveConfig->Interfaces[i]->EndPoints[j]->EndPointDescriptor, sizeof(USB_ENDPOINT_DESCRIPTOR));
+                                BufPtr += sizeof(USB_ENDPOINT_DESCRIPTOR);
+                            }
+                        }
+
                         break;
                     }
                     case USB_STRING_DESCRIPTOR_TYPE:
@@ -213,7 +234,7 @@
                     DPRINT(" MaxPower = %d\n", Urb->UrbSelectConfiguration.ConfigurationDescriptor->MaxPower);
 
 
-                    Urb->UrbSelectConfiguration.ConfigurationHandle = (PVOID)&DeviceExtension->UsbDevices[0]->ConfigurationDescriptor;
+                    Urb->UrbSelectConfiguration.ConfigurationHandle = (PVOID)&DeviceExtension->UsbDevices[0]->ActiveConfig->ConfigurationDescriptor;
                     DPRINT("ConfigHandle %x\n", Urb->UrbSelectConfiguration.ConfigurationHandle);
                     InterfaceInfo = &Urb->UrbSelectConfiguration.Interface;
 
@@ -229,10 +250,10 @@
                         DPRINT(" Reserved = %02x\n", (ULONG)InterfaceInfo->Reserved);
                         DPRINT(" InterfaceHandle = %p\n", InterfaceInfo->InterfaceHandle);
                         DPRINT(" NumberOfPipes = %d\n", InterfaceInfo->NumberOfPipes);
-                        InterfaceInfo->InterfaceHandle = (PVOID)&UsbDevice->InterfaceDescriptor;
-                        InterfaceInfo->Class = UsbDevice->InterfaceDescriptor.bInterfaceClass;
-                        InterfaceInfo->SubClass = UsbDevice->InterfaceDescriptor.bInterfaceSubClass;
-                        InterfaceInfo->Protocol = UsbDevice->InterfaceDescriptor.bInterfaceProtocol;
+                        InterfaceInfo->InterfaceHandle = (PVOID)&UsbDevice->ActiveInterface->InterfaceDescriptor;
+                        InterfaceInfo->Class = UsbDevice->ActiveInterface->InterfaceDescriptor.bInterfaceClass;
+                        InterfaceInfo->SubClass = UsbDevice->ActiveInterface->InterfaceDescriptor.bInterfaceSubClass;
+                        InterfaceInfo->Protocol = UsbDevice->ActiveInterface->InterfaceDescriptor.bInterfaceProtocol;
                         InterfaceInfo->Reserved = 0;
 
                         for (pCount = 0; pCount < InterfaceInfo->NumberOfPipes; pCount++)
@@ -245,11 +266,11 @@
                           DPRINT(" PipeHandle = %x\n", InterfaceInfo->Pipes[pCount].PipeHandle);
                           DPRINT(" MaximumTransferSize = %d\n", InterfaceInfo->Pipes[pCount].MaximumTransferSize);
                           DPRINT(" PipeFlags = %08x\n", InterfaceInfo->Pipes[pCount].PipeFlags);
-                          InterfaceInfo->Pipes[pCount].MaximumPacketSize = UsbDevice->EndPointDescriptor.wMaxPacketSize;
-                          InterfaceInfo->Pipes[pCount].EndpointAddress = UsbDevice->EndPointDescriptor.bEndpointAddress;
-                          InterfaceInfo->Pipes[pCount].Interval = UsbDevice->EndPointDescriptor.bInterval;
+                          InterfaceInfo->Pipes[pCount].MaximumPacketSize = UsbDevice->ActiveInterface->EndPoints[pCount]->EndPointDescriptor.wMaxPacketSize;
+                          InterfaceInfo->Pipes[pCount].EndpointAddress = UsbDevice->ActiveInterface->EndPoints[pCount]->EndPointDescriptor.bEndpointAddress;
+                          InterfaceInfo->Pipes[pCount].Interval = UsbDevice->ActiveInterface->EndPoints[pCount]->EndPointDescriptor.bInterval;
                           InterfaceInfo->Pipes[pCount].PipeType = UsbdPipeTypeInterrupt;
-                          InterfaceInfo->Pipes[pCount].PipeHandle = (PVOID)&UsbDevice->EndPointDescriptor;
+                          InterfaceInfo->Pipes[pCount].PipeHandle = (PVOID)&UsbDevice->ActiveInterface->EndPoints[pCount]->EndPointDescriptor;
                           if (InterfaceInfo->Pipes[pCount].MaximumTransferSize == 0)
                               InterfaceInfo->Pipes[pCount].MaximumTransferSize = 4096;
                           /* InterfaceInfo->Pipes[j].PipeFlags = 0; */
@@ -315,6 +336,7 @@
                                break;
                             }
                             case USB_DEVICE_CLASS_RESERVED:
+                                DPRINT1("Reserved!!!\n");
                             case USB_DEVICE_CLASS_HUB:
                             {
                                 PUSB_HUB_DESCRIPTOR UsbHubDescr = Urb->UrbControlVendorClassRequest.TransferBuffer;
@@ -328,7 +350,7 @@
                                     /* FIXME: Handle this correctly */
                                     UsbHubDescr->bDescriptorLength = sizeof(USB_HUB_DESCRIPTOR);
                                     UsbHubDescr->bDescriptorType = 0x29;
-                                    return;
+                                    break;
                                 }
                                 DPRINT1("USB_DEVICE_CLASS_HUB request\n");
                                 UsbHubDescr->bDescriptorLength = sizeof(USB_HUB_DESCRIPTOR);
@@ -425,7 +447,6 @@
                     case USB_REQUEST_SET_ADDRESS:
                     {
                         DPRINT1("USB_REQUEST_SET_ADDRESS\n");
-                        ASSERT(FALSE);
                         break;
                     }
                     case USB_REQUEST_GET_DESCRIPTOR:

Modified: trunk/reactos/drivers/usb/usbehci/pdo.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/usb/usbehci/pdo.c?rev=46735&r1=46734&r2=46735&view=diff
==============================================================================
--- trunk/reactos/drivers/usb/usbehci/pdo.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/usb/usbehci/pdo.c [iso-8859-1] Mon Apr  5 14:23:30 2010
@@ -11,8 +11,10 @@
 #define NDEBUG
 
 #include "usbehci.h"
+#include <hubbusif.h>
+#include <usbbusif.h>
+#include "usbiffn.h"
 #include <wdmguid.h>
-#include "usbiffn.h"
 #include <stdio.h>
 #include <debug.h>
 
@@ -51,8 +53,11 @@
         6: Self-powered,
         5: Remote wakeup,
         4..0: reserved */
-    0x00,       /* MaxPower; */
-
+    0x00       /* MaxPower; */
+};
+
+const UCHAR ROOTHUB2_INTERFACE_DESCRIPTOR [] = 
+{
     /* one interface */
     0x09,       /* bLength: Interface; */
     0x04,       /* bDescriptorType; Interface */
@@ -62,8 +67,11 @@
     0x09,       /* bInterfaceClass; HUB_CLASSCODE */
     0x01,       /* bInterfaceSubClass; */
     0x00,       /* bInterfaceProtocol: */
-    0x00,       /* iInterface; */
-
+    0x00       /* iInterface; */
+};
+
+const UCHAR ROOTHUB2_ENDPOINT_DESCRIPTOR [] =
+{
     /* one endpoint (status change endpoint) */
     0x07,       /* bLength; */
     0x05,       /* bDescriptorType; Endpoint */
@@ -87,7 +95,6 @@
     DPRINT1("Thread terminated\n");
 }
 
-/* FIXME: Do something better */
 PVOID InternalCreateUsbDevice(UCHAR DeviceNumber, ULONG Port, PUSB_DEVICE Parent, BOOLEAN Hub)
 {
     PUSB_DEVICE UsbDevicePointer = NULL;
@@ -98,6 +105,8 @@
         return NULL;
     }
 
+    RtlZeroMemory(UsbDevicePointer, sizeof(USB_DEVICE));
+
     if ((Hub) && (!Parent))
     {
         DPRINT1("This is the root hub\n");
@@ -176,21 +185,27 @@
             if (Stack->Parameters.Others.Argument1)
             {
                 /* Return the root hubs devicehandle */
+                DPRINT1("Returning RootHub Handle %x\n", PdoDeviceExtension->UsbDevices[0]);
                 *(PVOID *)Stack->Parameters.Others.Argument1 = (PVOID)PdoDeviceExtension->UsbDevices[0];
+                Status = STATUS_SUCCESS;
             }
             else
                 Status = STATUS_INVALID_DEVICE_REQUEST;
-            break;
+
+            break;
+
         }
         case IOCTL_INTERNAL_USB_GET_HUB_COUNT:
         {
             DPRINT1("IOCTL_INTERNAL_USB_GET_HUB_COUNT %x\n", IOCTL_INTERNAL_USB_GET_HUB_COUNT);
+            ASSERT(Stack->Parameters.Others.Argument1 != NULL);
             if (Stack->Parameters.Others.Argument1)
             {
                 /* FIXME: Determine the number of hubs between the usb device and root hub */
-                /* For now return 1, the root hub */
-                *(PVOID *)Stack->Parameters.Others.Argument1 = (PVOID)1;
-            }
+                DPRINT1("RootHubCount %x\n", *(PULONG)Stack->Parameters.Others.Argument1);
+                *(PULONG)Stack->Parameters.Others.Argument1 = 0;
+            }
+            Status = STATUS_SUCCESS;
             break;
         }
         case IOCTL_INTERNAL_USB_GET_HUB_NAME:
@@ -220,7 +235,7 @@
             if (Stack->Parameters.Others.Argument1)
                 *(PVOID *)Stack->Parameters.Others.Argument1 = FdoDeviceExtension->Pdo;
             if (Stack->Parameters.Others.Argument2)
-                *(PVOID *)Stack->Parameters.Others.Argument2 = IoGetAttachedDevice(FdoDeviceExtension->DeviceObject);
+                *(PVOID *)Stack->Parameters.Others.Argument2 = IoGetAttachedDeviceReference(FdoDeviceExtension->DeviceObject);
 
             Information = 0;
             Status = STATUS_SUCCESS;
@@ -275,6 +290,7 @@
             SourceString.Length = SourceString.MaximumLength = Index * sizeof(WCHAR);
             SourceString.Buffer = Buffer;
             break;
+
         }
         case BusQueryCompatibleIDs:
         {
@@ -375,9 +391,43 @@
             RootHubDevice->DeviceDescriptor.idVendor = FdoDeviceExtension->VendorId;
             RootHubDevice->DeviceDescriptor.idProduct = FdoDeviceExtension->DeviceId;
 
-            RtlCopyMemory(&RootHubDevice->ConfigurationDescriptor,
+            RootHubDevice->Configs = ExAllocatePoolWithTag(NonPagedPool,
+                                                            sizeof(PVOID) * RootHubDevice->DeviceDescriptor.bNumConfigurations,
+                                                            USB_POOL_TAG);
+
+            RootHubDevice->Configs[0] = ExAllocatePoolWithTag(NonPagedPool,
+                                                            sizeof(USB_CONFIGURATION) + sizeof(PVOID) * ROOTHUB2_CONFIGURATION_DESCRIPTOR[5],
+                                                            USB_POOL_TAG);
+
+            RootHubDevice->Configs[0]->Interfaces[0] = ExAllocatePoolWithTag(NonPagedPool,
+                                                            sizeof(USB_INTERFACE) + sizeof(PVOID) * ROOTHUB2_INTERFACE_DESCRIPTOR[3],
+                                                            USB_POOL_TAG);
+
+            RootHubDevice->Configs[0]->Interfaces[0]->EndPoints[0] = ExAllocatePoolWithTag(NonPagedPool,
+                                                            sizeof(USB_ENDPOINT),
+                                                            USB_POOL_TAG);
+
+            DPRINT1("before: ActiveConfig %x\n", RootHubDevice->ActiveConfig);
+            RootHubDevice->ActiveConfig = RootHubDevice->Configs[0];
+            DPRINT1("after: ActiveConfig %x\n", RootHubDevice->ActiveConfig);
+
+            DPRINT1("before: ActiveConfig->Interfaces[0] %x\n", RootHubDevice->ActiveConfig->Interfaces[0]);
+            RootHubDevice->ActiveInterface = RootHubDevice->ActiveConfig->Interfaces[0];
+
+
+            RtlCopyMemory(&RootHubDevice->ActiveConfig->ConfigurationDescriptor,
                           ROOTHUB2_CONFIGURATION_DESCRIPTOR,
                           sizeof(ROOTHUB2_CONFIGURATION_DESCRIPTOR));
+
+            RtlCopyMemory(&RootHubDevice->ActiveConfig->Interfaces[0]->InterfaceDescriptor,
+                         ROOTHUB2_INTERFACE_DESCRIPTOR,
+                         sizeof(ROOTHUB2_INTERFACE_DESCRIPTOR));
+
+            RtlCopyMemory(&RootHubDevice->ActiveConfig->Interfaces[0]->EndPoints[0]->EndPointDescriptor,
+                         ROOTHUB2_ENDPOINT_DESCRIPTOR,
+                         sizeof(ROOTHUB2_ENDPOINT_DESCRIPTOR));
+            RootHubDevice->DeviceSpeed = UsbHighSpeed;
+            RootHubDevice->DeviceType = Usb20Device;
 
             PdoDeviceExtension->UsbDevices[0] = RootHubDevice;
 
@@ -397,13 +447,14 @@
             if (!NT_SUCCESS(Status))
             {
                 DPRINT1("Failed to register interface\n");
+                ASSERT(FALSE);
             }
             else
             {
                 Status = IoSetDeviceInterfaceState(&InterfaceSymLinkName, TRUE);
                 DPRINT1("Set interface state %x\n", Status);
-            }
-
+                if (!NT_SUCCESS(Status)) ASSERT(FALSE);
+            }
 
             Status = STATUS_SUCCESS;
             break;
@@ -593,4 +644,3 @@
     IoCompleteRequest(Irp, IO_NO_INCREMENT);
     return Status;
 }
-

Modified: trunk/reactos/drivers/usb/usbehci/usbehci.h
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/usb/usbehci/usbehci.h?rev=46735&r1=46734&r2=46735&view=diff
==============================================================================
--- trunk/reactos/drivers/usb/usbehci/usbehci.h [iso-8859-1] (original)
+++ trunk/reactos/drivers/usb/usbehci/usbehci.h [iso-8859-1] Mon Apr  5 14:23:30 2010
@@ -5,9 +5,11 @@
 #include <stdio.h>
 #define	NDEBUG
 #include <debug.h>
-#include "usbiffn.h"
+#include <hubbusif.h>
 #include <usbioctl.h>
 #include <usb.h>
+
+#define USB_POOL_TAG (ULONG)'UsbR'
 
 #define	DEVICEINTIALIZED		0x01
 #define	DEVICESTARTED			0x02
@@ -196,10 +198,32 @@
 
 typedef struct _STRING_DESCRIPTOR
 {
-  UCHAR bLength;		/* Size of this descriptor in bytes */
+  UCHAR bLength;            /* Size of this descriptor in bytes */
   UCHAR bDescriptorType;	/* STRING Descriptor Type */
-  UCHAR bString[0];		/* UNICODE encoded string */
+  UCHAR bString[0];         /* UNICODE encoded string */
 } STRING_DESCRIPTOR, *PSTRING_DESCRIPTOR;
+
+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
 {
@@ -207,10 +231,13 @@
     ULONG Port;
     PVOID ParentDevice;
     BOOLEAN IsHub;
+    USB_DEVICE_SPEED DeviceSpeed;
+    USB_DEVICE_TYPE DeviceType;
     USB_DEVICE_DESCRIPTOR DeviceDescriptor;
-    USB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor;
-    USB_INTERFACE_DESCRIPTOR InterfaceDescriptor;
-    USB_ENDPOINT_DESCRIPTOR EndPointDescriptor;
+    USB_CONFIGURATION *ActiveConfig;
+    USB_INTERFACE *ActiveInterface;
+    USB_CONFIGURATION **Configs;
+
 } USB_DEVICE, *PUSB_DEVICE;
 
 /* USBCMD register 32 bits */
@@ -382,7 +409,7 @@
     ULONG ChildDeviceCount;
     BOOLEAN HaltUrbHandling;
     PVOID CallbackContext;
-    PRH_INIT_CALLBACK CallbackRoutine;
+    RH_INIT_CALLBACK *CallbackRoutine;
     ULONG NumberOfPorts;
     EHCIPORTS Ports[32];
 } PDO_DEVICE_EXTENSION, *PPDO_DEVICE_EXTENSION;

Modified: trunk/reactos/drivers/usb/usbehci/usbiffn.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/usb/usbehci/usbiffn.c?rev=46735&r1=46734&r2=46735&view=diff
==============================================================================
--- trunk/reactos/drivers/usb/usbehci/usbiffn.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/usb/usbehci/usbiffn.c [iso-8859-1] Mon Apr  5 14:23:30 2010
@@ -7,11 +7,32 @@
  *              Michael Martin
  */
 
-/* usbbusif.h and hubbusif.h need to be imported */
 #include "usbehci.h"
-#include "usbiffn.h"
-#define	NDEBUG
+#include <hubbusif.h>
+#include <usbbusif.h>
+#define NDEBUG
 #include <debug.h>
+
+BOOLEAN
+IsHandleValid(PVOID BusContext,
+              PUSB_DEVICE_HANDLE DeviceHandle)
+{
+    PPDO_DEVICE_EXTENSION PdoDeviceExtension;
+    LONG i;
+
+    PdoDeviceExtension = (PPDO_DEVICE_EXTENSION) BusContext;
+
+    if (!DeviceHandle)
+        return FALSE;
+
+    for (i = 0; i < 128; i++)
+    {
+        if (PdoDeviceExtension->UsbDevices[i] == DeviceHandle)
+            return TRUE;
+    }
+
+    return FALSE;
+}
 
 VOID
 USB_BUSIFFN
@@ -44,8 +65,21 @@
 USB_BUSIFFN
 InitializeUsbDevice(PVOID BusContext, PUSB_DEVICE_HANDLE DeviceHandle)
 {
+    PPDO_DEVICE_EXTENSION PdoDeviceExtension;
+    LONG i;
     DPRINT1("InitializeUsbDevice called\n");
-    return STATUS_SUCCESS;
+
+    PdoDeviceExtension = (PPDO_DEVICE_EXTENSION)((PDEVICE_OBJECT)BusContext)->DeviceExtension;
+    /* Find the device handle */
+    for (i = 0; i < PdoDeviceExtension->ChildDeviceCount; i++)
+    {
+        if (DeviceHandle == PdoDeviceExtension->UsbDevices[i])
+        {
+            DPRINT1("Device Handle Found!\n");
+            return STATUS_SUCCESS;
+        }
+    }
+    return STATUS_DEVICE_DATA_ERROR;
 }
 
 NTSTATUS
@@ -93,7 +127,52 @@
                        ULONG DeviceInformationBufferLength,
                        PULONG LengthReturned)
 {
-    DPRINT1("QueryDeviceInformation called\n");
+    PUSB_DEVICE_INFORMATION_0 DeviceInfo = DeviceInformationBuffer;
+    PUSB_DEVICE UsbDevice = (PUSB_DEVICE) DeviceHandle;
+    ULONG SizeNeeded;
+    LONG i;
+
+    DPRINT1("QueryDeviceInformation (%x, %x, %x, %d, %x\n", BusContext, DeviceHandle, DeviceInformationBuffer, DeviceInformationBufferLength, LengthReturned);
+
+    /* Search for a valid usb device in this BusContext */
+    if (!IsHandleValid(BusContext, DeviceHandle))
+    {
+        DPRINT1("Not a valid DeviceHandle\n");
+        return STATUS_INVALID_PARAMETER;
+    }
+
+    SizeNeeded = FIELD_OFFSET(USB_DEVICE_INFORMATION_0, PipeList[UsbDevice->ActiveInterface->InterfaceDescriptor.bNumEndpoints]);
+    *LengthReturned = SizeNeeded;
+
+    DeviceInfo->ActualLength = SizeNeeded;
+
+    if (DeviceInformationBufferLength < SizeNeeded)
+    {
+        DPRINT1("Buffer to small\n");
+        return STATUS_BUFFER_TOO_SMALL;
+    }
+
+    if (DeviceInfo->InformationLevel != 0)
+    {
+        DPRINT1("Invalid Param\n");
+        return STATUS_INVALID_PARAMETER;
+    }
+
+    DeviceInfo->PortNumber = UsbDevice->Port;
+    DeviceInfo->HubAddress = 1;
+    DeviceInfo->DeviceAddress = UsbDevice->Address;
+    DeviceInfo->DeviceSpeed = UsbDevice->DeviceSpeed;
+    DeviceInfo->DeviceType = UsbDevice->DeviceType;
+    DeviceInfo->CurrentConfigurationValue = UsbDevice->ActiveConfig->ConfigurationDescriptor.bConfigurationValue;
+    DeviceInfo->NumberOfOpenPipes = UsbDevice->ActiveInterface->InterfaceDescriptor.bNumEndpoints;
+
+    RtlCopyMemory(&DeviceInfo->DeviceDescriptor, &UsbDevice->DeviceDescriptor, sizeof(USB_DEVICE_DESCRIPTOR));
+
+    for (i = 0; i < UsbDevice->ActiveInterface->InterfaceDescriptor.bNumEndpoints; i++)
+    {
+        RtlCopyMemory(&DeviceInfo->PipeList[i].EndpointDescriptor, &UsbDevice->ActiveInterface->EndPoints[i]->EndPointDescriptor, sizeof(USB_ENDPOINT_DESCRIPTOR));
+    }
+
     return STATUS_SUCCESS;
 }
 
@@ -104,7 +183,29 @@
                          ULONG ControllerInformationBufferLength,
                          PULONG LengthReturned)
 {
+    PUSB_CONTROLLER_INFORMATION_0 ControllerInfo;
+
     DPRINT1("GetControllerInformation called\n");
+    ControllerInfo = ControllerInformationBuffer;
+
+    if (ControllerInformationBufferLength < sizeof(USB_CONTROLLER_INFORMATION_0))
+    {
+        DPRINT1("Buffer to small\n");
+        return STATUS_BUFFER_TOO_SMALL;
+    }
+
+    if (ControllerInfo->InformationLevel != 0)
+    {
+        DPRINT1("InformationLevel other than 0 not supported\n");
+        return STATUS_NOT_SUPPORTED;
+    }
+
+    ControllerInfo->ActualLength = sizeof(USB_CONTROLLER_INFORMATION_0);
+    ControllerInfo->SelectiveSuspendEnabled = FALSE;
+    ControllerInfo->IsHighSpeedController = TRUE;
+
+    *LengthReturned = ControllerInfo->ActualLength;
+
     return STATUS_SUCCESS;
 }
 
@@ -113,7 +214,7 @@
 ControllerSelectiveSuspend(PVOID BusContext, BOOLEAN Enable)
 {
     DPRINT1("ControllerSelectiveSuspend called\n");
-    return STATUS_SUCCESS;
+    return STATUS_NOT_SUPPORTED;
 }
 
 NTSTATUS
@@ -162,6 +263,12 @@
                        PULONG HubSymNameActualLength)
 {
     DPRINT1("GetRootHubSymbolicName called\n");
+
+    if (HubSymNameBufferLength < 20)
+        return STATUS_UNSUCCESSFUL;
+    //RtlStringCbCopy(HubSymNameBuffer, HubSymNameBufferLength, L"ROOT_HUB20");
+    *HubSymNameActualLength = 20;
+
     return STATUS_SUCCESS;
 }
 
@@ -211,12 +318,12 @@
 
 /* USB_BUS_INTERFACE_USBDI_V2 Functions */
 
-NTSTATUS
+VOID
 USB_BUSIFFN
 GetUSBDIVersion(PVOID BusContext, PUSBD_VERSION_INFORMATION VersionInformation, PULONG HcdCapabilites)
 {
     DPRINT1("GetUSBDIVersion called\n");
-    return STATUS_SUCCESS;
+    return;
 }
 
 NTSTATUS

Modified: trunk/reactos/drivers/usb/usbehci/usbiffn.h
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/usb/usbehci/usbiffn.h?rev=46735&r1=46734&r2=46735&view=diff
==============================================================================
--- trunk/reactos/drivers/usb/usbehci/usbiffn.h [iso-8859-1] (original)
+++ trunk/reactos/drivers/usb/usbehci/usbiffn.h [iso-8859-1] Mon Apr  5 14:23:30 2010
@@ -1,77 +1,9 @@
 #pragma once
 
-#define USB_BUSIFFN __stdcall
 #include <ntifs.h>
 #include <ntddk.h>
 #include <usb.h>
-
-/* usbbusif.h and hubbusif.h need to be imported */
-typedef PVOID PUSB_DEVICE_HANDLE;
-
-typedef
-VOID
-USB_BUSIFFN
-RH_INIT_CALLBACK (PVOID CallBackContext);
-
-typedef RH_INIT_CALLBACK *PRH_INIT_CALLBACK;
-
-typedef struct _USB_EXTPORT_INFORMATION_0
-{
-    ULONG PhysicalPortNumber;
-    ULONG PortLabelNumber;
-    USHORT VidOverride;
-    USHORT PidOverride;
-    ULONG PortAttributes;
-} USB_EXTPORT_INFORMATION_0, *PUSB_EXTPORT_INFORMATION;
-
-typedef struct _USB_EXTHUB_INFORMATION_0
-{
-    ULONG InformationLevel;
-    ULONG NumberOfPorts;
-    USB_EXTPORT_INFORMATION_0 Port[255];
-} USB_EXTHUB_INFORMATION_0, *PUSB_EXTHUB_INFORMATION_0;
-
-typedef struct _USB_BUS_INTERFACE_USBDI_V2
-{
-    USHORT Size;
-    USHORT Version;
-    PVOID BusContext;
-    PINTERFACE_REFERENCE InterfaceReference;
-    PINTERFACE_DEREFERENCE InterfaceDereference;
-
-    PVOID GetUSBDIVersion;
-    PVOID QueryBusTime;
-    PVOID SubmitIsoOutUrb;
-    PVOID QueryBusInformation;
-    PVOID IsDeviceHighSpeed;
-    PVOID EnumLogEntry;
-} USB_BUS_INTERFACE_USBDI_V2, *PUSB_BUS_INTERFACE_USBDI_V2;
-
-typedef struct _USB_BUS_INTERFACE_HUB_V5
-{
-    USHORT Size;
-    USHORT Version;
-    PVOID BusContext;
-    PINTERFACE_REFERENCE InterfaceReference;
-    PINTERFACE_DEREFERENCE InterfaceDereference;
-
-    PVOID CreateUsbDevice;
-    PVOID InitializeUsbDevice;
-    PVOID GetUsbDescriptors;
-    PVOID RemoveUsbDevice;
-    PVOID RestoreUsbDevice;
-    PVOID GetPortHackFlags;
-    PVOID QueryDeviceInformation;
-    PVOID GetControllerInformation;
-    PVOID ControllerSelectiveSuspend;
-    PVOID GetExtendedHubInformation;
-    PVOID GetRootHubSymbolicName;
-    PVOID GetDeviceBusContext;
-    PVOID Initialize20Hub;
-    PVOID RootHubInitNotification;
-    PVOID FlushTransfers;
-    PVOID SetDeviceHandleData;
-} USB_BUS_INTERFACE_HUB_V5, *PUSB_BUS_INTERFACE_HUB_V5;
+#include <usbbusif.h>
 
 VOID
 USB_BUSIFFN
@@ -167,7 +99,7 @@
 USB_BUSIFFN
 SetDeviceHandleData(PVOID BusContext, PVOID DeviceHandle, PDEVICE_OBJECT UsbDevicePdo);
 
-NTSTATUS
+VOID
 USB_BUSIFFN
 GetUSBDIVersion(PVOID BusContext, PUSBD_VERSION_INFORMATION VersionInformation, PULONG HcdCapabilites);
 




More information about the Ros-diffs mailing list