[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.

svn path=/trunk/; revision=46735
This commit is contained in:
Michael Martin 2010-04-05 12:23:30 +00:00
parent 817ca6d3d7
commit 222e4f03b9
6 changed files with 258 additions and 118 deletions

View file

@ -83,11 +83,11 @@ EhciDefferedRoutine(PKDPC Dpc, PVOID DeferredContext, PVOID SystemArgument1, PVO
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 @@ StartDevice(PDEVICE_OBJECT DeviceObject, PCM_PARTIAL_RESOURCE_LIST raw, PCM_PART
StartEhci(DeviceObject);
FdoDeviceExtension->DeviceState = DEVICESTARTED;
return STATUS_SUCCESS;
}
@ -814,7 +815,6 @@ AddDevice(PDRIVER_OBJECT DriverObject, PDEVICE_OBJECT Pdo)
IoDetachDevice(FdoDeviceExtension->LowerDevice);
IoDeleteSymbolicLink(&SymLinkName);
IoDeleteDevice(Fdo);
return STATUS_UNSUCCESSFUL;
}
@ -840,11 +840,14 @@ AddDevice(PDRIVER_OBJECT DriverObject, PDEVICE_OBJECT Pdo)
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;

View file

@ -101,7 +101,7 @@ CompletePendingURBRequest(PPDO_DEVICE_EXTENSION DeviceExtension)
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 @@ CompletePendingURBRequest(PPDO_DEVICE_EXTENSION DeviceExtension)
DPRINT1("Uknown identifier\n");
Urb->UrbHeader.Status = USBD_STATUS_INVALID_URB_FUNCTION;
Status = STATUS_UNSUCCESSFUL;
ASSERT(FALSE);
}
break;
}
@ -164,19 +165,39 @@ CompletePendingURBRequest(PPDO_DEVICE_EXTENSION DeviceExtension)
}
case USB_CONFIGURATION_DESCRIPTOR_TYPE:
{
DPRINT1("USB CONFIG DESC\n");
ULONG FullDescriptorLength = sizeof(USB_CONFIGURATION_DESCRIPTOR) +
sizeof(USB_INTERFACE_DESCRIPTOR) +
sizeof(USB_ENDPOINT_DESCRIPTOR);
PUCHAR BufPtr;
LONG i, j;
if (Urb->UrbControlDescriptorRequest.TransferBufferLength >= FullDescriptorLength)
DPRINT1("USB CONFIG DESC\n");
if (Urb->UrbControlDescriptorRequest.TransferBufferLength >= UsbDevice->ActiveConfig->ConfigurationDescriptor.wTotalLength)
{
Urb->UrbControlDescriptorRequest.TransferBufferLength = FullDescriptorLength;
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);
}
}
RtlCopyMemory(Urb->UrbControlDescriptorRequest.TransferBuffer,
&UsbDevice->ConfigurationDescriptor,
Urb->UrbControlDescriptorRequest.TransferBufferLength);
break;
}
case USB_STRING_DESCRIPTOR_TYPE:
@ -213,7 +234,7 @@ CompletePendingURBRequest(PPDO_DEVICE_EXTENSION DeviceExtension)
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 @@ CompletePendingURBRequest(PPDO_DEVICE_EXTENSION DeviceExtension)
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 @@ CompletePendingURBRequest(PPDO_DEVICE_EXTENSION DeviceExtension)
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 @@ CompletePendingURBRequest(PPDO_DEVICE_EXTENSION DeviceExtension)
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 @@ CompletePendingURBRequest(PPDO_DEVICE_EXTENSION DeviceExtension)
/* 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 @@ CompletePendingURBRequest(PPDO_DEVICE_EXTENSION DeviceExtension)
case USB_REQUEST_SET_ADDRESS:
{
DPRINT1("USB_REQUEST_SET_ADDRESS\n");
ASSERT(FALSE);
break;
}
case USB_REQUEST_GET_DESCRIPTOR:

View file

@ -11,8 +11,10 @@
#define NDEBUG
#include "usbehci.h"
#include <wdmguid.h>
#include <hubbusif.h>
#include <usbbusif.h>
#include "usbiffn.h"
#include <wdmguid.h>
#include <stdio.h>
#include <debug.h>
@ -51,8 +53,11 @@ const UCHAR ROOTHUB2_CONFIGURATION_DESCRIPTOR [] =
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 @@ const UCHAR ROOTHUB2_CONFIGURATION_DESCRIPTOR [] =
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 @@ UrbWorkerThread(PVOID Context)
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 @@ PVOID InternalCreateUsbDevice(UCHAR DeviceNumber, ULONG Port, PUSB_DEVICE Parent
return NULL;
}
RtlZeroMemory(UsbDevicePointer, sizeof(USB_DEVICE));
if ((Hub) && (!Parent))
{
DPRINT1("This is the root hub\n");
@ -176,21 +185,27 @@ PdoDispatchInternalDeviceControl(PDEVICE_OBJECT DeviceObject, PIRP Irp)
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;
}
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 @@ PdoDispatchInternalDeviceControl(PDEVICE_OBJECT DeviceObject, PIRP Irp)
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 @@ PdoQueryId(PDEVICE_OBJECT DeviceObject, PIRP Irp, ULONG_PTR* Information)
SourceString.Length = SourceString.MaximumLength = Index * sizeof(WCHAR);
SourceString.Buffer = Buffer;
break;
}
case BusQueryCompatibleIDs:
{
@ -375,10 +391,44 @@ PdoDispatchPnp(
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;
/* Create a thread to handle the URB's */
@ -397,14 +447,15 @@ PdoDispatchPnp(
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 @@ PdoDispatchPnp(
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return Status;
}

View file

@ -5,10 +5,12 @@
#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
#define DEVICEBUSY 0x04
@ -196,21 +198,46 @@ typedef struct _EHCI_SETUP_FORMAT
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
{
UCHAR Address;
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 @@ typedef struct _PDO_DEVICE_EXTENSION
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;

View file

@ -7,12 +7,33 @@
* 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
InterfaceReference(PVOID BusContext)
@ -44,8 +65,21 @@ NTSTATUS
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 @@ QueryDeviceInformation(PVOID BusContext,
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 @@ GetControllerInformation(PVOID BusContext,
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 @@ USB_BUSIFFN
ControllerSelectiveSuspend(PVOID BusContext, BOOLEAN Enable)
{
DPRINT1("ControllerSelectiveSuspend called\n");
return STATUS_SUCCESS;
return STATUS_NOT_SUPPORTED;
}
NTSTATUS
@ -162,6 +263,12 @@ GetRootHubSymbolicName(PVOID BusContext,
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 @@ SetDeviceHandleData(PVOID BusContext, PVOID DeviceHandle, PDEVICE_OBJECT UsbDevi
/* 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

View file

@ -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 @@ VOID
USB_BUSIFFN
SetDeviceHandleData(PVOID BusContext, PVOID DeviceHandle, PDEVICE_OBJECT UsbDevicePdo);
NTSTATUS
VOID
USB_BUSIFFN
GetUSBDIVersion(PVOID BusContext, PUSBD_VERSION_INFORMATION VersionInformation, PULONG HcdCapabilites);