@@ -63,6 +63,7 @@ class CUSBDevice : public IUSBDevice
63
63
virtual NTSTATUS CreateDeviceDescriptor ();
64
64
virtual VOID DumpDeviceDescriptor (PUSB_DEVICE_DESCRIPTOR DeviceDescriptor);
65
65
virtual VOID DumpConfigurationDescriptor (PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor);
66
+ virtual NTSTATUS GetConfigurationDescriptor (UCHAR ConfigurationIndex, USHORT BufferSize, PVOID Buffer);
66
67
67
68
// constructor / destructor
68
69
CUSBDevice (IUnknown *OuterUnknown){}
@@ -370,6 +371,7 @@ CUSBDevice::SetDeviceAddress(
370
371
if (!NT_SUCCESS (Status))
371
372
{
372
373
DPRINT1 (" CUSBDevice::SetDeviceAddress> failed to retrieve configuration %lu\n " , Index);
374
+ ASSERT (FALSE );
373
375
break ;
374
376
}
375
377
}
@@ -651,32 +653,34 @@ CUSBDevice::CreateDeviceDescriptor()
651
653
652
654
// ----------------------------------------------------------------------------------------
653
655
NTSTATUS
654
- CUSBDevice::CreateConfigurationDescriptor (
655
- UCHAR Index)
656
+ CUSBDevice::GetConfigurationDescriptor (
657
+ IN UCHAR ConfigurationIndex,
658
+ IN USHORT BufferSize,
659
+ IN PVOID Buffer)
656
660
{
657
- PVOID Buffer;
658
661
USB_DEFAULT_PIPE_SETUP_PACKET CtrlSetup;
659
662
NTSTATUS Status;
660
663
PMDL Mdl;
661
- PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor;
662
664
663
- //
664
- // sanity checks
665
- //
666
- PC_ASSERT (m_ConfigurationDescriptors);
667
665
668
666
//
669
- // first allocate a buffer which should be enough to store all different interfaces and endpoints
667
+ // now build MDL describing the buffer
670
668
//
671
- Buffer = ExAllocatePoolWithTag (NonPagedPool, PAGE_SIZE, TAG_USBLIB );
672
- if (!Buffer )
669
+ Mdl = IoAllocateMdl (Buffer, BufferSize, FALSE , FALSE , 0 );
670
+ if (!Mdl )
673
671
{
674
672
//
675
- // failed to allocate buffer
673
+ // failed to allocate mdl
676
674
//
677
675
return STATUS_INSUFFICIENT_RESOURCES;
678
676
}
679
677
678
+ //
679
+ // build mdl for non paged pool
680
+ //
681
+ MmBuildMdlForNonPagedPool (Mdl);
682
+
683
+
680
684
//
681
685
// build setup packet
682
686
//
@@ -685,52 +689,79 @@ CUSBDevice::CreateConfigurationDescriptor(
685
689
CtrlSetup.bmRequestType ._BM .Reserved = 0 ;
686
690
CtrlSetup.bmRequestType ._BM .Dir = BMREQUEST_DEVICE_TO_HOST;
687
691
CtrlSetup.bRequest = USB_REQUEST_GET_DESCRIPTOR;
688
- CtrlSetup.wValue .LowByte = Index ;
692
+ CtrlSetup.wValue .LowByte = ConfigurationIndex ;
689
693
CtrlSetup.wValue .HiByte = USB_CONFIGURATION_DESCRIPTOR_TYPE;
690
694
CtrlSetup.wIndex .W = 0 ;
691
- CtrlSetup.wLength = PAGE_SIZE ;
695
+ CtrlSetup.wLength = BufferSize ;
692
696
693
697
//
694
- // now build MDL describing the buffer
698
+ // commit packet
695
699
//
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)
698
731
{
699
732
//
700
- // failed to allocate mdl
733
+ // failed to allocate buffer
701
734
//
702
- ExFreePoolWithTag (Buffer, TAG_USBLIB);
703
735
return STATUS_INSUFFICIENT_RESOURCES;
704
736
}
705
737
706
738
//
707
- // build mdl for non paged pool
739
+ // get partial configuration descriptor
708
740
//
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);
715
742
if (!NT_SUCCESS (Status))
716
743
{
717
744
//
718
- // failed to issue request, cleanup
745
+ // failed to get partial configuration descriptor
719
746
//
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 );
722
749
return Status;
723
750
}
724
751
725
752
//
726
- // now free the mdl
753
+ // now get full descriptor
727
754
//
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
+ }
734
765
735
766
//
736
767
// informal debug print
0 commit comments