[USBEHCI_NEW]

- Add interface function GetHubControllerSymbolicLink
- Implement IOCTL_USB_GET_ROOT_HUB_NAME for usbview

svn path=/branches/usb-bringup/; revision=51387
This commit is contained in:
Johannes Anderwald 2011-04-17 22:38:32 +00:00
parent bbad937d99
commit a2b99febfa
3 changed files with 141 additions and 48 deletions

View file

@ -230,87 +230,123 @@ CHCDController::HandleDeviceControl(
//
DeviceExtension = (PCOMMON_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
//
// sanity check
//
PC_ASSERT(DeviceExtension->IsFDO);
DPRINT1("HandleDeviceControl>Type: FDO %u IoCtl %x InputBufferLength %lu OutputBufferLength %lu\n",
DeviceExtension->IsFDO,
DPRINT1("HandleDeviceControl>Type: IoCtl %x InputBufferLength %lu OutputBufferLength %lu\n",
IoStack->Parameters.DeviceIoControl.IoControlCode,
IoStack->Parameters.DeviceIoControl.InputBufferLength,
IoStack->Parameters.DeviceIoControl.OutputBufferLength);
//
// get device type
// perform ioctl for FDO
//
if (DeviceExtension->IsFDO)
if (IoStack->Parameters.DeviceIoControl.IoControlCode == IOCTL_GET_HCD_DRIVERKEY_NAME)
{
//
// perform ioctl for FDO
// check if sizee is at least >= USB_HCD_DRIVERKEY_NAME
//
if (IoStack->Parameters.DeviceIoControl.IoControlCode == IOCTL_GET_HCD_DRIVERKEY_NAME)
if(IoStack->Parameters.DeviceIoControl.OutputBufferLength >= sizeof(USB_HCD_DRIVERKEY_NAME))
{
//
// check if sizee is at least >= USB_HCD_DRIVERKEY_NAME
// get device property size
//
if(IoStack->Parameters.DeviceIoControl.OutputBufferLength >= sizeof(USB_HCD_DRIVERKEY_NAME))
Status = IoGetDeviceProperty(m_PhysicalDeviceObject, DevicePropertyDriverKeyName, 0, NULL, &ResultLength);
//
// get input buffer
//
DriverKey = (PUSB_HCD_DRIVERKEY_NAME)Irp->AssociatedIrp.SystemBuffer;
//
// check result
//
if (Status == STATUS_BUFFER_TOO_SMALL)
{
//
// get device property size
// does the caller provide enough buffer space
//
Status = IoGetDeviceProperty(m_PhysicalDeviceObject, DevicePropertyDriverKeyName, 0, NULL, &ResultLength);
DriverKey = (PUSB_HCD_DRIVERKEY_NAME)Irp->AssociatedIrp.SystemBuffer;
//
// check result
//
if (Status == STATUS_BUFFER_TOO_SMALL)
if (IoStack->Parameters.DeviceIoControl.OutputBufferLength >= ResultLength)
{
//
// does the caller provide enough buffer space
// it does
//
if (IoStack->Parameters.DeviceIoControl.OutputBufferLength >= ResultLength)
Status = IoGetDeviceProperty(m_PhysicalDeviceObject, DevicePropertyDriverKeyName, IoStack->Parameters.DeviceIoControl.OutputBufferLength - sizeof(ULONG), DriverKey->DriverKeyName, &ResultLength);
if (NT_SUCCESS(Status))
{
//
// it does
// informal debug print
//
Status = IoGetDeviceProperty(m_PhysicalDeviceObject, DevicePropertyDriverKeyName, IoStack->Parameters.DeviceIoControl.OutputBufferLength - sizeof(ULONG), DriverKey->DriverKeyName, &ResultLength);
if (NT_SUCCESS(Status))
{
//
// informal debug print
//
DPRINT1("Result %S\n", DriverKey->DriverKeyName);
}
DPRINT1("Result %S\n", DriverKey->DriverKeyName);
}
//
// store result
//
DriverKey->ActualLength = ResultLength + FIELD_OFFSET(USB_HCD_DRIVERKEY_NAME, DriverKeyName) + sizeof(WCHAR);
Irp->IoStatus.Information = IoStack->Parameters.DeviceIoControl.OutputBufferLength;
Status = STATUS_SUCCESS;
}
}
else
{
//
// buffer is certainly too small
// store result
//
Status = STATUS_BUFFER_OVERFLOW;
Irp->IoStatus.Information = sizeof(USB_HCD_DRIVERKEY_NAME);
DriverKey->ActualLength = ResultLength + FIELD_OFFSET(USB_HCD_DRIVERKEY_NAME, DriverKeyName) + sizeof(WCHAR);
Irp->IoStatus.Information = IoStack->Parameters.DeviceIoControl.OutputBufferLength;
Status = STATUS_SUCCESS;
}
}
else if (IoStack->Parameters.DeviceIoControl.IoControlCode == IOCTL_USB_GET_ROOT_HUB_NAME)
else
{
DPRINT1("IOCTL_USB_GET_ROOT_HUB_NAME is not implemented yet\n");
//
// buffer is certainly too small
//
Status = STATUS_BUFFER_OVERFLOW;
Irp->IoStatus.Information = sizeof(USB_HCD_DRIVERKEY_NAME);
}
}
else
else if (IoStack->Parameters.DeviceIoControl.IoControlCode == IOCTL_USB_GET_ROOT_HUB_NAME)
{
//
// the PDO does not support any device IOCTLs
// check if sizee is at least >= USB_HCD_DRIVERKEY_NAME
//
Status = STATUS_SUCCESS;
if(IoStack->Parameters.DeviceIoControl.OutputBufferLength >= sizeof(USB_HCD_DRIVERKEY_NAME))
{
//
// sanity check
//
PC_ASSERT(m_HubController);
//
// get input buffer
//
DriverKey = (PUSB_HCD_DRIVERKEY_NAME)Irp->AssociatedIrp.SystemBuffer;
//
// get symbolic link
//
Status = m_HubController->GetHubControllerSymbolicLink(IoStack->Parameters.DeviceIoControl.OutputBufferLength - sizeof(ULONG), DriverKey->DriverKeyName, &ResultLength);
if (NT_SUCCESS(Status))
{
//
// informal debug print
//
DPRINT1("Result %S\n", DriverKey->DriverKeyName);
}
//
// store result
//
DriverKey->ActualLength = ResultLength + FIELD_OFFSET(USB_HCD_DRIVERKEY_NAME, DriverKeyName) + sizeof(WCHAR);
Irp->IoStatus.Information = IoStack->Parameters.DeviceIoControl.OutputBufferLength;
Status = STATUS_SUCCESS;
}
else
{
//
// buffer is certainly too small
//
Status = STATUS_BUFFER_OVERFLOW;
Irp->IoStatus.Information = sizeof(USB_HCD_DRIVERKEY_NAME);
}
}
//

View file

@ -36,6 +36,8 @@ public:
// IHubController interface functions
virtual NTSTATUS Initialize(IN PDRIVER_OBJECT DriverObject, IN PHCDCONTROLLER Controller, IN PUSBHARDWAREDEVICE Device, IN BOOLEAN IsRootHubDevice, IN ULONG DeviceAddress);
virtual NTSTATUS GetHubControllerDeviceObject(PDEVICE_OBJECT * HubDeviceObject);
virtual NTSTATUS GetHubControllerSymbolicLink(ULONG BufferLength, PVOID Buffer, PULONG RequiredLength);
// IDispatchIrp interface functions
virtual NTSTATUS HandlePnp(IN PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp);
@ -46,7 +48,6 @@ public:
NTSTATUS HandleQueryInterface(PIO_STACK_LOCATION IoStack);
NTSTATUS SetDeviceInterface(BOOLEAN bEnable);
NTSTATUS CreatePDO(PDRIVER_OBJECT DriverObject, PDEVICE_OBJECT * OutDeviceObject);
NTSTATUS GetHubControllerDeviceObject(PDEVICE_OBJECT * HubDeviceObject);
PUSBHARDWAREDEVICE GetUsbHardware();
ULONG AcquireDeviceAddress();
VOID ReleaseDeviceAddress(ULONG DeviceAddress);
@ -71,8 +72,10 @@ protected:
PUSBHARDWAREDEVICE m_Hardware;
BOOLEAN m_IsRootHubDevice;
ULONG m_DeviceAddress;
BOOLEAN m_InterfaceEnabled;
UNICODE_STRING m_HubDeviceInterfaceString;
PDEVICE_OBJECT m_HubControllerDeviceObject;
PDRIVER_OBJECT m_DriverObject;
@ -267,6 +270,51 @@ CHubController::GetHubControllerDeviceObject(PDEVICE_OBJECT * HubDeviceObject)
return STATUS_SUCCESS;
}
//-----------------------------------------------------------------------------------------
NTSTATUS
CHubController::GetHubControllerSymbolicLink(
ULONG BufferLength,
PVOID Buffer,
PULONG RequiredLength)
{
if (!m_InterfaceEnabled)
{
//
// device interface not yet enabled
//
return STATUS_UNSUCCESSFUL;
}
if (BufferLength < m_HubDeviceInterfaceString.Length - 8)
{
//
// buffer too small
// length is without '\??\'
//
*RequiredLength = m_HubDeviceInterfaceString.Length- 8;
//
// done
//
return STATUS_BUFFER_OVERFLOW;
}
//
// copy symbolic link
//
RtlCopyMemory(Buffer, &m_HubDeviceInterfaceString.Buffer[4], m_HubDeviceInterfaceString.Length - 8);
//
// store length, length is without '\??\'
//
*RequiredLength = m_HubDeviceInterfaceString.Length - 8;
//
// done
//
return STATUS_SUCCESS;
}
//-----------------------------------------------------------------------------------------
NTSTATUS
CHubController::HandlePnp(

View file

@ -444,6 +444,15 @@ DECLARE_INTERFACE_(IHubController, IUnknown)
virtual NTSTATUS GetHubControllerDeviceObject(PDEVICE_OBJECT * HubDeviceObject) = 0;
//----------------------------------------------------------------------------------------
//
// GetHubControllerSymbolicLink
//
// Description: Returns the symbolic link of the root hub
virtual NTSTATUS GetHubControllerSymbolicLink(ULONG BufferLength, PVOID Buffer, PULONG RequiredLength) = 0;
};
typedef IHubController *PHUBCONTROLLER;