- Implement URB_FUNCTION_VENDOR_DEVICE
- Sensibly handle unknown requests in HandleClassDevice
- DPRINT fixes

svn path=/trunk/; revision=56660
This commit is contained in:
Thomas Faber 2012-05-26 17:19:41 +00:00
parent 571a6d3ce6
commit 8ea9a9d758
3 changed files with 158 additions and 40 deletions

View file

@ -279,6 +279,9 @@ USBHUB_PdoHandleInternalDeviceControl(
case URB_FUNCTION_CLASS_INTERFACE:
DPRINT1("URB_FUNCTION_CLASS_INTERFACE\n");
break;
case URB_FUNCTION_VENDOR_DEVICE:
DPRINT1("URB_FUNCTION_VENDOR_DEVICE\n");
break;
default:
DPRINT1("IOCTL_INTERNAL_USB_SUBMIT_URB Function %x NOT IMPLEMENTED\n", Urb->UrbHeader.Function);
break;

View file

@ -69,6 +69,7 @@ public:
NTSTATUS HandleClassOther(IN OUT PIRP Irp, PURB Urb);
NTSTATUS HandleClassInterface(IN OUT PIRP Irp, PURB Urb);
NTSTATUS HandleClassEndpoint(IN OUT PIRP Irp, PURB Urb);
NTSTATUS HandleVendorDevice(IN OUT PIRP Irp, PURB Urb);
NTSTATUS HandleBulkOrInterruptTransfer(IN OUT PIRP Irp, PURB Urb);
NTSTATUS HandleIsochronousTransfer(IN OUT PIRP Irp, PURB Urb);
NTSTATUS HandleClearStall(IN OUT PIRP Irp, PURB Urb);
@ -1381,7 +1382,52 @@ CHubController::HandleClassDevice(
break;
}
default:
DPRINT1("[USBLIB] HandleClassDevice Type %x not implemented\n", Urb->UrbControlVendorClassRequest.Request);
{
//
// check if this is a valid usb device handle
//
if (!ValidateUsbDevice(PUSBDEVICE(Urb->UrbHeader.UsbdDeviceHandle)))
{
DPRINT1("HandleClassDevice invalid device handle %p\n", Urb->UrbHeader.UsbdDeviceHandle);
//
// invalid device handle
//
return STATUS_DEVICE_NOT_CONNECTED;
}
//
// get device
//
UsbDevice = PUSBDEVICE(Urb->UrbHeader.UsbdDeviceHandle);
//
// generate setup packet
//
CtrlSetup.bmRequestType.B = 0;
CtrlSetup.bmRequestType._BM.Recipient = BMREQUEST_TO_DEVICE;
CtrlSetup.bmRequestType._BM.Type = BMREQUEST_CLASS;
CtrlSetup.bRequest = Urb->UrbControlVendorClassRequest.Request;
CtrlSetup.wValue.W = Urb->UrbControlVendorClassRequest.Value;
CtrlSetup.wIndex.W = Urb->UrbControlVendorClassRequest.Index;
CtrlSetup.wLength = Urb->UrbControlVendorClassRequest.TransferBufferLength;
if (Urb->UrbControlVendorClassRequest.TransferFlags & USBD_TRANSFER_DIRECTION_IN)
{
//
// data direction is device to host
//
CtrlSetup.bmRequestType._BM.Dir = BMREQUEST_DEVICE_TO_HOST;
}
//
// submit setup packet
//
Status = UsbDevice->SubmitSetupPacket(&CtrlSetup, Urb->UrbControlDescriptorRequest.TransferBufferLength, Urb->UrbControlDescriptorRequest.TransferBuffer);
ASSERT(Status == STATUS_SUCCESS);
break;
}
}
return Status;
@ -1740,6 +1786,70 @@ CHubController::HandleClassEndpoint(
return Status;
}
//-----------------------------------------------------------------------------------------
NTSTATUS
CHubController::HandleVendorDevice(
IN OUT PIRP Irp,
IN OUT PURB Urb)
{
NTSTATUS Status = STATUS_NOT_IMPLEMENTED;
PUSBDEVICE UsbDevice;
USB_DEFAULT_PIPE_SETUP_PACKET CtrlSetup;
DPRINT("CHubController::HandleVendorDevice Request %x\n", Urb->UrbControlVendorClassRequest.Request);
//
// sanity check
//
PC_ASSERT(Urb->UrbHeader.UsbdDeviceHandle);
//
// check if this is a valid usb device handle
//
if (!ValidateUsbDevice(PUSBDEVICE(Urb->UrbHeader.UsbdDeviceHandle)))
{
DPRINT1("[USBLIB] HandleVendorDevice invalid device handle %p\n", Urb->UrbHeader.UsbdDeviceHandle);
//
// invalid device handle
//
return STATUS_DEVICE_NOT_CONNECTED;
}
//
// get device
//
UsbDevice = PUSBDEVICE(Urb->UrbHeader.UsbdDeviceHandle);
//
// initialize setup packet
//
CtrlSetup.bmRequestType.B = 0;
CtrlSetup.bmRequestType._BM.Recipient = BMREQUEST_TO_DEVICE;
CtrlSetup.bmRequestType._BM.Type = BMREQUEST_VENDOR;
CtrlSetup.bRequest = Urb->UrbControlVendorClassRequest.Request;
CtrlSetup.wValue.W = Urb->UrbControlVendorClassRequest.Value;
CtrlSetup.wIndex.W = Urb->UrbControlVendorClassRequest.Index;
CtrlSetup.wLength = Urb->UrbControlVendorClassRequest.TransferBufferLength;
if (Urb->UrbControlVendorClassRequest.TransferFlags & USBD_TRANSFER_DIRECTION_IN)
{
//
// data direction is device to host
//
CtrlSetup.bmRequestType._BM.Dir = BMREQUEST_DEVICE_TO_HOST;
}
//
// issue request
//
Status = UsbDevice->SubmitSetupPacket(&CtrlSetup, Urb->UrbControlVendorClassRequest.TransferBufferLength, Urb->UrbControlVendorClassRequest.TransferBuffer);
PC_ASSERT(NT_SUCCESS(Status));
return Status;
}
//-----------------------------------------------------------------------------------------
NTSTATUS
CHubController::HandleSyncResetAndClearStall(
IN OUT PIRP Irp,
@ -1812,6 +1922,7 @@ CHubController::HandleSyncResetAndClearStall(
return Status;
}
//-----------------------------------------------------------------------------------------
NTSTATUS
CHubController::HandleAbortPipe(
IN OUT PIRP Irp,
@ -2098,6 +2209,9 @@ CHubController::HandleDeviceControl(
case URB_FUNCTION_CLASS_ENDPOINT:
Status = HandleClassEndpoint(Irp, Urb);
break;
case URB_FUNCTION_VENDOR_DEVICE:
Status = HandleVendorDevice(Irp, Urb);
break;
default:
DPRINT1("[USBLIB] IOCTL_INTERNAL_USB_SUBMIT_URB Function %x NOT IMPLEMENTED\n", Urb->UrbHeader.Function);
break;

View file

@ -309,7 +309,7 @@ CUSBDevice::SetDeviceAddress(
UCHAR OldAddress;
UCHAR Index;
DPRINT1("CUSBDevice::SetDeviceAddress Address %d\n", DeviceAddress);
DPRINT1("CUSBDevice::SetDeviceAddress> Address %x\n", DeviceAddress);
CtrlSetup = (PUSB_DEFAULT_PIPE_SETUP_PACKET)ExAllocatePoolWithTag(NonPagedPool, sizeof(USB_DEFAULT_PIPE_SETUP_PACKET), TAG_USBLIB);
if (!CtrlSetup)
@ -332,7 +332,7 @@ CUSBDevice::SetDeviceAddress(
if (!NT_SUCCESS(Status))
{
// failed to set device address
DPRINT1("CUSBDevice::SetDeviceAddress> failed to set device address with %x Address %x\n", Status, DeviceAddress);
DPRINT1("CUSBDevice::SetDeviceAddress> failed to set device address with %lx Address %x\n", Status, DeviceAddress);
return Status;
}
@ -349,7 +349,7 @@ CUSBDevice::SetDeviceAddress(
Status = CreateDeviceDescriptor();
if (!NT_SUCCESS(Status))
{
DPRINT1("CUSBbDevice::SetDeviceAddress> failed to retrieve device descriptor with device address set Error %x\n", Status);
DPRINT1("CUSBDevice::SetDeviceAddress> failed to retrieve device descriptor with device address set Error %lx\n", Status);
// return error status
return Status;
}
@ -360,7 +360,7 @@ CUSBDevice::SetDeviceAddress(
m_DeviceDescriptor.bNumConfigurations == 0)
{
// failed to retrieve device descriptor
DPRINT1("CUSBbDevice::SetDeviceAddress> device returned bogus device descriptor\n");
DPRINT1("CUSBDevice::SetDeviceAddress> device returned bogus device descriptor\n");
DumpDeviceDescriptor(&m_DeviceDescriptor);
// return error status
@ -430,7 +430,7 @@ CUSBDevice::CommitIrp(
//
// no queue, wtf?
//
DPRINT1("CUSBDevice::CommitUrb> no queue / dma !!!\n");
DPRINT1("CUSBDevice::CommitIrp> no queue / dma !!!\n");
return STATUS_UNSUCCESSFUL;
}
@ -443,7 +443,7 @@ CUSBDevice::CommitIrp(
//
// failed to build request
//
DPRINT1("CUSBDevice::CommitSetupPacket> CreateUSBRequest failed with %x\n", Status);
DPRINT1("CUSBDevice::CommitIrp> CreateUSBRequest failed with %lx\n", Status);
return Status;
}
@ -466,7 +466,7 @@ CUSBDevice::CommitIrp(
//
// failed to add request
//
DPRINT1("CUSBDevice::CommitSetupPacket> failed add request to queue with %x\n", Status);
DPRINT1("CUSBDevice::CommitIrp> failed add request to queue with %lx\n", Status);
Request->Release();
return Status;
}
@ -502,6 +502,7 @@ CUSBDevice::SubmitIrp(
return Status;
}
//----------------------------------------------------------------------------------------
NTSTATUS
CUSBDevice::CommitSetupPacket(
@ -965,7 +966,7 @@ CUSBDevice::BuildInterfaceDescriptor(
if (EndpointDescriptor->bLength == 0 || EndpointDescriptor->bDescriptorType == USB_INTERFACE_DESCRIPTOR_TYPE)
{
// bogus configuration descriptor
DPRINT1("[USBEHCI] Bogus descriptor found in InterfaceNumber %x Alternate %x EndpointIndex %x bLength %x bDescriptorType %x\n", InterfaceDescriptor->bInterfaceNumber, InterfaceDescriptor->bAlternateSetting, PipeIndex,
DPRINT1("[USBLIB] Bogus descriptor found in InterfaceNumber %x Alternate %x EndpointIndex %x bLength %x bDescriptorType %x\n", InterfaceDescriptor->bInterfaceNumber, InterfaceDescriptor->bAlternateSetting, PipeIndex,
EndpointDescriptor->bLength, EndpointDescriptor->bDescriptorType);
// failed
@ -1037,7 +1038,7 @@ CUSBDevice::SelectConfiguration(
if (!Found)
{
DPRINT1("[USBUHCI] invalid configuration value %lu\n", ConfigurationDescriptor->bConfigurationValue);
DPRINT1("[USBLIB] invalid configuration value %lu\n", ConfigurationDescriptor->bConfigurationValue);
return STATUS_INVALID_PARAMETER;
}
@ -1059,13 +1060,13 @@ CUSBDevice::SelectConfiguration(
if (!ConfigurationDescriptor)
{
// unconfigure request
DPRINT1("CUsbDevice::SelectConfiguration Unconfigure Request Status %x\n", Status);
DPRINT1("CUSBDevice::SelectConfiguration Unconfigure Request Status %x\n", Status);
m_ConfigurationIndex = 0;
return Status;
}
// informal debug print
DPRINT1("CUsbDevice::SelectConfiguration New Configuration %x Old Configuration %x Result %x\n", ConfigurationIndex, m_ConfigurationIndex, Status);
DPRINT1("CUSBDevice::SelectConfiguration New Configuration %x Old Configuration %x Result %x\n", ConfigurationIndex, m_ConfigurationIndex, Status);
if (!NT_SUCCESS(Status))
{
//
@ -1161,7 +1162,7 @@ CUSBDevice::SelectInterface(
if (!Found)
{
// invalid handle passed
DPRINT1("[USBEHCI] Invalid configuration handle passed %p\n", ConfigurationHandle);
DPRINT1("[USBLIB] Invalid configuration handle passed %p\n", ConfigurationHandle);
return STATUS_INVALID_PARAMETER;
}