UsbBuildGetDescriptorRequest parameters

Hi all,

Which is the right Index parameter value when trying to get a usb device descriptor or a usb configuration descriptor? Is this ok?

URB TheURB;

UsbBuildGetDescriptorRequest(&TheURB, sizeof(_URB_CONTROL_DESCRIPTOR_REQUEST), USB_CONFIGURATION_DESCRIPTOR_TYPE, 1, 0, pDescriptor, NULL, nDeviceDescriptorSize, NULL);

Or it should be:

URB TheURB;

UsbBuildGetDescriptorRequest(&TheURB, sizeof(_URB_CONTROL_DESCRIPTOR_REQUEST), USB_CONFIGURATION_DESCRIPTOR_TYPE, 0, 0, pDescriptor, NULL, nDeviceDescriptorSize, NULL);

Thanks in advance.

Eugenio Barahona

xxxxx@gmail.com wrote:

Which is the right Index parameter value when trying to get a usb device descriptor or a usb configuration descriptor?

This is all described in the USB spec. If you are going to do USB
device development, you need to have that. Chapter 9 is of particular
interest to driver writers. It covers descriptors and the standard
control endpoint requests.

The “index” value (which, confusingly, goes in the wValue field, not the
wIndex field) starts numbering from 0. There is only one device
descriptor, so you always pass 0. Most devices also have only one
configuration descriptor, so again you specify 0. If you have a
multi-configuration device, then you need to know which one you are after.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

Hi Tim,

First of all I want to thank you for your response.

But I am a little confused. In page 517 of Walter Oney book “Programming the Microsoft Windows Driver Model” he wrote the following code:

ULONG iconfig = 1;
URB urb;
USB_CONFIGURATION_DESCRIPTOR tcd;
UsbBuildGetDescriptorRequest(&urb,
sizeof(_URB_CONTROL_DESCRIPTOR_REQUEST),
USB_CONFIGURATION_DESCRIPTOR_TYPE,
iconfig, 0, &tcd, NULL, sizeof(tcd), NULL);
SendAwaitUrb(fdo, &urb);
ULONG size = tcd.wTotalLength;
PUSB_CONFIGURATION_DESCRIPTOR pcd =
(PUSB_CONFIGURATION_DESCRIPTOR) ExAllocatePool(
NonPagedPool, size);
UsbBuildGetDescriptorRequest(&urb,
sizeof(_URB_CONTROL_DESCRIPTOR_REQUEST),
USB_CONFIGURATION_DESCRIPTOR_TYPE,
iconfig, 0, pcd, NULL, size, NULL);
SendAwaitUrb(fdo, &urb);

ExFreePool(pcd);

And then he said:

“In this fragment, we issue one URB to read a configuration descriptor?I specified configuration number 1, which is the first one?into a temporary descriptor area named tcd. This descriptor contains the length (wTotalLength) of the combined structure that includes configuration, interface, and endpoint descriptors.”

So which is the first configuration descriptor? The one with index 0 or the one with index 1?

Eugenio Barahona

On Mar 7, 2016, at 10:14 PM, xxxxx@gmail.com wrote:

First of all I want to thank you for your response.

But I am a little confused. In page 517 of Walter Oney book “Programming the Microsoft Windows Driver Model” he wrote the following code:

And then he said:

“In this fragment, we issue one URB to read a configuration descriptor?I specified configuration number 1, which is the first one?into a temporary descriptor area named tcd. This descriptor contains the length (wTotalLength) of the combined structure that includes configuration, interface, and endpoint descriptors.”

So which is the first configuration descriptor? The one with index 0 or the one with index 1?

The answer is 0. Walter Oney is a powerful wizard indeed, but he is not infallible. His code has a misunderstanding that is easy to make.

The key here is the difference between the configuration INDEX and the configuration VALUE. Every USB configuration has a VALUE, which is an arbitrary number that is not required to be consecutive. When you go to select a configuration, you use the configuration VALUE (which you have to read from the descriptor).

But when you go to fetch a configuration descriptor, you fetch it by index, which starts at 0 and increments in order.

So, the 1st configuration is index 0, and usually has iValue of 1.

Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.