Author: janderwald
Date: Thu Mar 1 14:16:33 2012
New Revision: 55942
URL:
http://svn.reactos.org/svn/reactos?rev=55942&view=rev
Log:
[USBLIB]
- Split retrieving the full configuration descriptor into 2 steps
- Fixes errors while initializing usb devices on UHCI controller
- Tested in VmWare / VBox and real hardware
Modified:
trunk/reactos/drivers/usb/usbuhci/usb_request.cpp
trunk/reactos/lib/drivers/libusb/usb_device.cpp
Modified: trunk/reactos/drivers/usb/usbuhci/usb_request.cpp
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/usb/usbuhci/usb_re…
==============================================================================
--- trunk/reactos/drivers/usb/usbuhci/usb_request.cpp [iso-8859-1] (original)
+++ trunk/reactos/drivers/usb/usbuhci/usb_request.cpp [iso-8859-1] Thu Mar 1 14:16:33
2012
@@ -1111,7 +1111,7 @@
//
// failed to allocate descriptor
//
- DPRINT1("[UHCI] Failed to create setup descriptor\n");
+ DPRINT1("[UHCI] Failed to create status descriptor\n");
FreeDescriptor(SetupDescriptor);
m_DmaManager->Release(QueueHead, sizeof(UHCI_QUEUE_HEAD));
return Status;
Modified: trunk/reactos/lib/drivers/libusb/usb_device.cpp
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/drivers/libusb/usb_dev…
==============================================================================
--- trunk/reactos/lib/drivers/libusb/usb_device.cpp [iso-8859-1] (original)
+++ trunk/reactos/lib/drivers/libusb/usb_device.cpp [iso-8859-1] Thu Mar 1 14:16:33 2012
@@ -63,6 +63,7 @@
virtual NTSTATUS CreateDeviceDescriptor();
virtual VOID DumpDeviceDescriptor(PUSB_DEVICE_DESCRIPTOR DeviceDescriptor);
virtual VOID DumpConfigurationDescriptor(PUSB_CONFIGURATION_DESCRIPTOR
ConfigurationDescriptor);
+ virtual NTSTATUS GetConfigurationDescriptor(UCHAR ConfigurationIndex, USHORT
BufferSize, PVOID Buffer);
// constructor / destructor
CUSBDevice(IUnknown *OuterUnknown){}
@@ -370,6 +371,7 @@
if (!NT_SUCCESS(Status))
{
DPRINT1("CUSBDevice::SetDeviceAddress> failed to retrieve
configuration %lu\n", Index);
+ ASSERT(FALSE);
break;
}
}
@@ -651,31 +653,33 @@
//----------------------------------------------------------------------------------------
NTSTATUS
-CUSBDevice::CreateConfigurationDescriptor(
- UCHAR Index)
-{
- PVOID Buffer;
+CUSBDevice::GetConfigurationDescriptor(
+ IN UCHAR ConfigurationIndex,
+ IN USHORT BufferSize,
+ IN PVOID Buffer)
+{
USB_DEFAULT_PIPE_SETUP_PACKET CtrlSetup;
NTSTATUS Status;
PMDL Mdl;
- PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor;
-
- //
- // sanity checks
- //
- PC_ASSERT(m_ConfigurationDescriptors);
-
- //
- // first allocate a buffer which should be enough to store all different interfaces
and endpoints
- //
- Buffer = ExAllocatePoolWithTag(NonPagedPool, PAGE_SIZE, TAG_USBLIB);
- if (!Buffer)
- {
- //
- // failed to allocate buffer
+
+
+ //
+ // now build MDL describing the buffer
+ //
+ Mdl = IoAllocateMdl(Buffer, BufferSize, FALSE, FALSE, 0);
+ if (!Mdl)
+ {
+ //
+ // failed to allocate mdl
//
return STATUS_INSUFFICIENT_RESOURCES;
}
+
+ //
+ // build mdl for non paged pool
+ //
+ MmBuildMdlForNonPagedPool(Mdl);
+
//
// build setup packet
@@ -685,52 +689,79 @@
CtrlSetup.bmRequestType._BM.Reserved = 0;
CtrlSetup.bmRequestType._BM.Dir = BMREQUEST_DEVICE_TO_HOST;
CtrlSetup.bRequest = USB_REQUEST_GET_DESCRIPTOR;
- CtrlSetup.wValue.LowByte = Index;
+ CtrlSetup.wValue.LowByte = ConfigurationIndex;
CtrlSetup.wValue.HiByte = USB_CONFIGURATION_DESCRIPTOR_TYPE;
CtrlSetup.wIndex.W = 0;
- CtrlSetup.wLength = PAGE_SIZE;
-
- //
- // now build MDL describing the buffer
- //
- Mdl = IoAllocateMdl(Buffer, PAGE_SIZE, FALSE, FALSE, 0);
- if (!Mdl)
- {
- //
- // failed to allocate mdl
- //
- ExFreePoolWithTag(Buffer, TAG_USBLIB);
+ CtrlSetup.wLength = BufferSize;
+
+ //
+ // commit packet
+ //
+ Status = CommitSetupPacket(&CtrlSetup, 0, BufferSize, Mdl);
+
+ //
+ // free mdl
+ //
+ IoFreeMdl(Mdl);
+
+ //
+ // done
+ //
+ return Status;
+}
+
+//----------------------------------------------------------------------------------------
+NTSTATUS
+CUSBDevice::CreateConfigurationDescriptor(
+ UCHAR Index)
+{
+ NTSTATUS Status;
+ PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor;
+
+ //
+ // sanity checks
+ //
+ PC_ASSERT(m_ConfigurationDescriptors);
+
+ //
+ // first allocate a buffer which should be enough to store all different interfaces
and endpoints
+ //
+ ConfigurationDescriptor =
(PUSB_CONFIGURATION_DESCRIPTOR)ExAllocatePoolWithTag(NonPagedPool, PAGE_SIZE,
TAG_USBLIB);
+ if (!ConfigurationDescriptor)
+ {
+ //
+ // failed to allocate buffer
+ //
return STATUS_INSUFFICIENT_RESOURCES;
}
//
- // build mdl for non paged pool
- //
- MmBuildMdlForNonPagedPool(Mdl);
-
- //
- // commit packet
- //
- Status = CommitSetupPacket(&CtrlSetup, 0, PAGE_SIZE, Mdl);
+ // get partial configuration descriptor
+ //
+ Status = GetConfigurationDescriptor(Index, sizeof(USB_CONFIGURATION_DESCRIPTOR),
ConfigurationDescriptor);
if (!NT_SUCCESS(Status))
{
//
- // failed to issue request, cleanup
- //
- IoFreeMdl(Mdl);
- ExFreePool(Buffer);
- return Status;
- }
-
- //
- // now free the mdl
- //
- IoFreeMdl(Mdl);
-
- //
- // get configuration descriptor
- //
- ConfigurationDescriptor = (PUSB_CONFIGURATION_DESCRIPTOR)Buffer;
+ // failed to get partial configuration descriptor
+ //
+ DPRINT1("[USBLIB] Failed to get partial configuration descriptor Status %x
Index %x\n", Status, Index);
+ ExFreePoolWithTag(ConfigurationDescriptor, TAG_USBLIB);
+ return Status;
+ }
+
+ //
+ // now get full descriptor
+ //
+ Status = GetConfigurationDescriptor(Index, ConfigurationDescriptor->wTotalLength,
ConfigurationDescriptor);
+ if (!NT_SUCCESS(Status))
+ {
+ //
+ // failed to get full configuration descriptor
+ //
+ DPRINT1("[USBLIB] Failed to get full configuration descriptor Status %x
Index %x\n", Status, Index);
+ ExFreePoolWithTag(ConfigurationDescriptor, TAG_USBLIB);
+ return Status;
+ }
//
// informal debug print