USB Descriptors

All USB devices have a hierarchy of descriptors which describe to the host information such as what the device is, who makes it, what version of USB it supports, how many ways it can be configured, the number of endpoints and their types etc.

The more common USB descriptors are

USB devices can only have one device descriptor. The device descriptor includes information such as what USB revision the device complies to, the Product and Vendor IDs used to load the appropriate drivers and the number of possible configurations the device can have. The number of configurations indicate how many configuration descriptors branches are to follow.

The configuration descriptor specifies values such as the amount of power this particular configuration uses, if the device is self or bus powered and the number of interfaces it has. When a device is enumerated, the host reads the device descriptors and can make a decision of which configuration to enable. It can only enable one configuration at a time.

For example, it is possible to have a high power bus powered configuration and a self powered configuration. If the device is plugged into a host with a mains power supply, the device driver may choose to enable the high power bus powered configuration enabling the device to be powered without a connection to the mains, yet if it is connected to a laptop or personal organiser it could enable the 2nd configuration (self powered) requiring the user to plug your device into the power point.

The configuration settings are not limited to power differences. Each configuration could be powered in the same way and draw the same current, yet have different interface or endpoint combinations. However it should be noted that changing the configuration requires all activity on each endpoint to stop. While USB offers this flexibility, very few devices have more than 1 configuration.

The interface descriptor could be seen as a header or grouping of the endpoints into a functional group performing a single feature of the device. For example you could have a multi-function fax/scanner/printer device. Interface descriptor one could describe the endpoints of the fax function, Interface descriptor two the scanner function and Interface descriptor three the printer function. Unlike the configuration descriptor, there is no limitation as to having only one interface enabled at a time. A device could have 1 or many interface descriptors enabled at once.

Interface descriptors have a bInterfaceNumber field specifying the Interface number and a bAlternateSetting which allows an interface to change settings on the fly. For example we could have a device with two interfaces, interface one and interface two. Interface one has bInterfaceNumber set to zero indicating it is the first interface descriptor and a bAlternativeSetting of zero.

Interface two would have a bInterfaceNumber set to one indicating it is the second interface and a bAlternativeSetting of zero (default). We could then throw in another descriptor, also with a bInterfaceNumber set to one indicating it is the second interface, but this time setting the bAlternativeSetting to one, indicating this interface descriptor can be an alternative setting to that of the other interface descriptor two.

When this configuration is enabled, the first two interface descriptors with bAlternativeSettings equal to zero is used. However during operation the host can send a SetInterface request directed to that of Interface one with a alternative setting of one to enable the other interface descriptor.

This gives an advantage over having two configurations, in that we can be transmitting data over interface zero while we change the endpoint settings associated with interface one without effecting interface zero.

Each endpoint descriptor is used to specify the type of transfer, direction, polling interval and maximum packet size for each endpoint. Endpoint zero, the default control endpoint is always assumed to be a control endpoint and as such never has a descriptor.

Composition of USB Descriptors

All descriptors are made up of a common format. The first byte specifies the length of the descriptor, while the second byte indicates the descriptor type. If the length of a descriptor is smaller than what the specification defines, then the host shall ignore it. However if the size is greater than expected the host will ignore the extra bytes and start looking for the next descriptor at the end of actual length returned.
OffsetFieldSizeValueDescription
0bLength1NumberSize of Descriptor in Bytes
1bDescriptionType1ConstantDescriptorType
2...nStart of parameters for descriptor

Device Descriptors

The device descriptor of a USB device represents the entire device. As a result a USB device can only have one device descriptor. It specifies some basic, yet important information about the device such as the supported USB version, maximum packet size, vendor and product IDs and the number of possible configurations the device can have. The format of the device descriptor is shown below.
OffsetFieldSizeValueDescription
0bLength1NumberSize of the Descriptor in Bytes (18 bytes)
1bDescriptorType1ConstantDevice Descriptor (0x01)
2bcdUSB2BCDUSB Specification Number which device complies too.
4bDeviceClass1ClassClass Code (Assigned by USB Org)

If equal to Zero, each interface specifies it’s own class code

If equal to 0xFF, the class code is vendor specified.

Otherwise field is valid Class Code.

5bDeviceSubClass1SubClassSubclass Code (Assigned by USB Org)
6bDeviceProtocol1ProtocolProtocol Code (Assigned by USB Org)
7bMaxPacketSize1NumberMaximum Packet Size for Zero Endpoint. Valid Sizes are 8, 16, 32, 64
8idVendor2IDVendor ID (Assigned by USB Org)
10idProduct2IDProduct ID (Assigned by Manufacturer)
12bcdDevice2BCDDevice Release Number
14iManufacturer1IndexIndex of Manufacturer String Descriptor
15iProduct1IndexIndex of Product String Descriptor
16iSerialNumber1IndexIndex of Serial Number String Descriptor
17bNumConfigurations1IntegerNumber of Possible Configurations

Configuration Descriptors

A USB device can have several different configurations although the majority of devices are simple and only have one. The configuration descriptor specifies how the device is powered, what the maximum power consumption is, the number of interfaces it has. Therefore it is possible to have two configurations, one for when the device is bus powered and another when it is mains powered. As this is a “header” to the Interface descriptors, its also feasible to have one configuration using a different transfer mode to that of another configuration.

Once all the configurations have been examined by the host, the host will send a SetConfiguration command with a non zero value which matches the bConfigurationValue of one of the configurations. This is used to select the desired configuration.

OffsetFieldSizeValueDescription
0bLength1NumberSize of Descriptor in Bytes
1bDescriptorType1ConstantConfiguration Descriptor (0x02)
2wTotalLength2NumberTotal length in bytes of data returned
4bNumInterfaces1NumberNumber of Interfaces
5bConfigurationValue1NumberValue to use as an argument to select this configuration
6iConfiguration1IndexIndex of String Descriptor describing this configuration
7bmAttributes1BitmapD7 Reserved, set to 1. (USB 1.0 Bus Powered)

D6 Self Powered

D5 Remote Wakeup

D4..0 Reserved, set to 0.

8bMaxPower1mAMaximum Power Consumption in 2 mA units

Interface Descriptors

The interface descriptor could be seen as a header or grouping of the endpoints into a functional group performing a single feature of the device. The interface descriptor conforms to the following format,
OffsetFieldSizeValueDescription
0bLength1NumberSize of Descriptor in Bytes (9 Bytes)
1bDescriptorType1ConstantInterface Descriptor (0x04)
2bInterfaceNumber1NumberNumber of Interface
3bAlternateSetting1NumberValue used to select alternative setting
4bNumEndpoints1NumberNumber of Endpoints used for this interface
5bInterfaceClass1ClassClass Code (Assigned by USB Org)
6bInterfaceSubClass1SubClassSubclass Code (Assigned by USB Org)
7bInterfaceProtocol1ProtocolProtocol Code (Assigned by USB Org)
8iInterface1IndexIndex of String Descriptor Describing this interface

Endpoint Descriptors

Endpoint descriptors are used to describe endpoints other than endpoint zero. Endpoint zero is always assumed to be a control endpoint and is configured before any descriptors are even requested. The host will use the information returned from these descriptors to determine the bandwidth requirements of the bus.
OffsetFieldSizeValueDescription
0bLength1NumberSize of Descriptor in Bytes (7 bytes)
1bDescriptorType1ConstantEndpoint Descriptor (0x05)
2bEndpointAddress1EndpointEndpoint Address
  • Bits 0..3 Endpoint Number.
  • Bits 4..6 Reserved. Set to Zero
  • Bits 7 Direction 0 = Out, 1 = In (Ignored for Control Endpoints)
3bmAttributes1BitmapBits 0..1 Transfer Type
  • 00 = Control
  • 01 = Isochronous
  • 10 = Bulk
  • 11 = Interrupt
Bits 2..7 are reserved. If Isochronous endpoint,
  • Bits 3..2 = Synchronisation Type (Iso Mode)
    • 00 = No Synchonisation
    • 01 = Asynchronous
    • 10 = Adaptive
    • 11 = Synchronous
  • Bits 5..4 = Usage Type (Iso Mode)
    • 00 = Data Endpoint
    • 01 = Feedback Endpoint
    • 10 = Explicit Feedback Data Endpoint
    • 11 = Reserved
4wMaxPacketSize2NumberMaximum Packet Size this endpoint is capable of sending or receiving
6bInterval1NumberInterval for polling endpoint data transfers. Value in frame counts. Ignored for Bulk and Control Endpoints. Isochronous must equal 1 and field may range from 1 to 255 for interrupt endpoints. For Low-Speed, minimum allowed value is 10.

String Descriptors

String descriptors provide human readable information and are optional. If they are not used, any string index fields of descriptors must be set to zero indicating there is no string descriptor available.

The strings are encoded in the Unicode format and products can be made to support multiple languages. String Index 0 should return a list of supported languages. A list of USB Language IDs can be found in Universal Serial Bus Language Identifiers (LANGIDs) version 1.0

OffsetFieldSizeValueDescription
0bLength1NumberSize of Descriptor in Bytes
1bDescriptorType1ConstantString Descriptor (0x03)
2wLANGID[0]2numberSupported Language Code Zero
(e.g. 0x0409 English - United States)
4wLANGID[1]2numberSupported Language Code One
(e.g. 0x0c09 English - Australian)
nwLANGID[x]2numberSupported Language Code x
(e.g. 0x0407 German - Standard)
The above String Descriptor shows the format of String Descriptor Zero. The host should read this descriptor to determine what languages are available. If a language is supported, it can then be referenced by sending the language ID in the wIndex field of a Get Descriptor(String) request.

All subsequent strings take on the format below,

OffsetFieldSizeValueDescription
0bLength1NumberSize of Descriptor in Bytes. Must be even
1bDescriptorType1ConstantString Descriptor (0x03)
2bStringnUnicodeUnicode (UTF-16) Encoded String
Strings are not null-terminated and should not contain non-printable characters. Furthermore, leading or trailing whitespace (tabs or spaces) should not be used. The string length, in encoding units (= characters for BMP), is determined by taking descriptor's bLength field.