Skip to content

Commit d431e27

Browse files
committed
[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 svn path=/trunk/; revision=55942
1 parent 348d7d4 commit d431e27

File tree

2 files changed

+68
-37
lines changed

2 files changed

+68
-37
lines changed

reactos/drivers/usb/usbuhci/usb_request.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1111,7 +1111,7 @@ CUSBRequest::BuildControlTransferDescriptor(
11111111
//
11121112
// failed to allocate descriptor
11131113
//
1114-
DPRINT1("[UHCI] Failed to create setup descriptor\n");
1114+
DPRINT1("[UHCI] Failed to create status descriptor\n");
11151115
FreeDescriptor(SetupDescriptor);
11161116
m_DmaManager->Release(QueueHead, sizeof(UHCI_QUEUE_HEAD));
11171117
return Status;

reactos/lib/drivers/libusb/usb_device.cpp

Lines changed: 67 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class CUSBDevice : public IUSBDevice
6363
virtual NTSTATUS CreateDeviceDescriptor();
6464
virtual VOID DumpDeviceDescriptor(PUSB_DEVICE_DESCRIPTOR DeviceDescriptor);
6565
virtual VOID DumpConfigurationDescriptor(PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor);
66+
virtual NTSTATUS GetConfigurationDescriptor(UCHAR ConfigurationIndex, USHORT BufferSize, PVOID Buffer);
6667

6768
// constructor / destructor
6869
CUSBDevice(IUnknown *OuterUnknown){}
@@ -370,6 +371,7 @@ CUSBDevice::SetDeviceAddress(
370371
if (!NT_SUCCESS(Status))
371372
{
372373
DPRINT1("CUSBDevice::SetDeviceAddress> failed to retrieve configuration %lu\n", Index);
374+
ASSERT(FALSE);
373375
break;
374376
}
375377
}
@@ -651,32 +653,34 @@ CUSBDevice::CreateDeviceDescriptor()
651653

652654
//----------------------------------------------------------------------------------------
653655
NTSTATUS
654-
CUSBDevice::CreateConfigurationDescriptor(
655-
UCHAR Index)
656+
CUSBDevice::GetConfigurationDescriptor(
657+
IN UCHAR ConfigurationIndex,
658+
IN USHORT BufferSize,
659+
IN PVOID Buffer)
656660
{
657-
PVOID Buffer;
658661
USB_DEFAULT_PIPE_SETUP_PACKET CtrlSetup;
659662
NTSTATUS Status;
660663
PMDL Mdl;
661-
PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor;
662664

663-
//
664-
// sanity checks
665-
//
666-
PC_ASSERT(m_ConfigurationDescriptors);
667665

668666
//
669-
// first allocate a buffer which should be enough to store all different interfaces and endpoints
667+
// now build MDL describing the buffer
670668
//
671-
Buffer = ExAllocatePoolWithTag(NonPagedPool, PAGE_SIZE, TAG_USBLIB);
672-
if (!Buffer)
669+
Mdl = IoAllocateMdl(Buffer, BufferSize, FALSE, FALSE, 0);
670+
if (!Mdl)
673671
{
674672
//
675-
// failed to allocate buffer
673+
// failed to allocate mdl
676674
//
677675
return STATUS_INSUFFICIENT_RESOURCES;
678676
}
679677

678+
//
679+
// build mdl for non paged pool
680+
//
681+
MmBuildMdlForNonPagedPool(Mdl);
682+
683+
680684
//
681685
// build setup packet
682686
//
@@ -685,52 +689,79 @@ CUSBDevice::CreateConfigurationDescriptor(
685689
CtrlSetup.bmRequestType._BM.Reserved = 0;
686690
CtrlSetup.bmRequestType._BM.Dir = BMREQUEST_DEVICE_TO_HOST;
687691
CtrlSetup.bRequest = USB_REQUEST_GET_DESCRIPTOR;
688-
CtrlSetup.wValue.LowByte = Index;
692+
CtrlSetup.wValue.LowByte = ConfigurationIndex;
689693
CtrlSetup.wValue.HiByte = USB_CONFIGURATION_DESCRIPTOR_TYPE;
690694
CtrlSetup.wIndex.W = 0;
691-
CtrlSetup.wLength = PAGE_SIZE;
695+
CtrlSetup.wLength = BufferSize;
692696

693697
//
694-
// now build MDL describing the buffer
698+
// commit packet
695699
//
696-
Mdl = IoAllocateMdl(Buffer, PAGE_SIZE, FALSE, FALSE, 0);
697-
if (!Mdl)
700+
Status = CommitSetupPacket(&CtrlSetup, 0, BufferSize, Mdl);
701+
702+
//
703+
// free mdl
704+
//
705+
IoFreeMdl(Mdl);
706+
707+
//
708+
// done
709+
//
710+
return Status;
711+
}
712+
713+
//----------------------------------------------------------------------------------------
714+
NTSTATUS
715+
CUSBDevice::CreateConfigurationDescriptor(
716+
UCHAR Index)
717+
{
718+
NTSTATUS Status;
719+
PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor;
720+
721+
//
722+
// sanity checks
723+
//
724+
PC_ASSERT(m_ConfigurationDescriptors);
725+
726+
//
727+
// first allocate a buffer which should be enough to store all different interfaces and endpoints
728+
//
729+
ConfigurationDescriptor = (PUSB_CONFIGURATION_DESCRIPTOR)ExAllocatePoolWithTag(NonPagedPool, PAGE_SIZE, TAG_USBLIB);
730+
if (!ConfigurationDescriptor)
698731
{
699732
//
700-
// failed to allocate mdl
733+
// failed to allocate buffer
701734
//
702-
ExFreePoolWithTag(Buffer, TAG_USBLIB);
703735
return STATUS_INSUFFICIENT_RESOURCES;
704736
}
705737

706738
//
707-
// build mdl for non paged pool
739+
// get partial configuration descriptor
708740
//
709-
MmBuildMdlForNonPagedPool(Mdl);
710-
711-
//
712-
// commit packet
713-
//
714-
Status = CommitSetupPacket(&CtrlSetup, 0, PAGE_SIZE, Mdl);
741+
Status = GetConfigurationDescriptor(Index, sizeof(USB_CONFIGURATION_DESCRIPTOR), ConfigurationDescriptor);
715742
if (!NT_SUCCESS(Status))
716743
{
717744
//
718-
// failed to issue request, cleanup
745+
// failed to get partial configuration descriptor
719746
//
720-
IoFreeMdl(Mdl);
721-
ExFreePool(Buffer);
747+
DPRINT1("[USBLIB] Failed to get partial configuration descriptor Status %x Index %x\n", Status, Index);
748+
ExFreePoolWithTag(ConfigurationDescriptor, TAG_USBLIB);
722749
return Status;
723750
}
724751

725752
//
726-
// now free the mdl
753+
// now get full descriptor
727754
//
728-
IoFreeMdl(Mdl);
729-
730-
//
731-
// get configuration descriptor
732-
//
733-
ConfigurationDescriptor = (PUSB_CONFIGURATION_DESCRIPTOR)Buffer;
755+
Status = GetConfigurationDescriptor(Index, ConfigurationDescriptor->wTotalLength, ConfigurationDescriptor);
756+
if (!NT_SUCCESS(Status))
757+
{
758+
//
759+
// failed to get full configuration descriptor
760+
//
761+
DPRINT1("[USBLIB] Failed to get full configuration descriptor Status %x Index %x\n", Status, Index);
762+
ExFreePoolWithTag(ConfigurationDescriptor, TAG_USBLIB);
763+
return Status;
764+
}
734765

735766
//
736767
// informal debug print

0 commit comments

Comments
 (0)