All USB devices have a hierarchy of descriptors that describe various features of the device: the manufacturer ID, the version of the device, the version of USB it supports, what the device is, its power requirements, the number and type of endpoints, and so forth.
The most common USB descriptors are:
• Device descriptors
• Configuration descriptors
• Interface descriptors
• HID descriptors
• Endpoint descriptors
The descriptors are in a hierarchical structure as shown in Figure 8.7. At the top of the hierarchy we have the device descriptor, then the configuration descriptors, followed by the interface descriptors, and finally the endpoint descriptors. The HID descriptor always follows the interface descriptor when the interface belongs to the HID class.
Figure 8.7: USB descriptor hierarchy
All descriptors have a common format. The first byte ( bLength ) specifies the length of the descriptor, while the second byte ( bDescriptorType ) indicates the descriptor type.
The device descriptor is the top-level set of information read from a device and the first item the host attempts to retrieve.
A USB device has only one device descriptor, since the device descriptor represents the entire device. It provides general information such as manufacturer, serial number, product number, the class of the device, and the number of configurations. Table 8.5 shows the format for a device descriptor with the meaning of each field.
bLength is the length of the device descriptor.
bDescriptorType is the descriptor type.
bcdUSB reports the highest version of USB the device supports in BCD format. The number is represented as 0xJJMN, where JJ is the major version number, M is the minor version number, and N is the subminor version number. For example, USB 1.1 is reported as 0x0110.
bDeviceClass , bDeviceSubClass , and bDeviceProtocol are assigned by the USB organization and are used by the system to find a class driver for the device.
bMaxPacketSize0 is the maximum input and output packet size for endpoint 0.
idVendor is assigned by the USB organization and is the vendor’s ID.
idProduct is assigned by the manufacturer and is the product ID.
bcdDevice is the device release number and has the same format as the bcdUSB .
iManufacturer , iProduct , and iSerialNumber are details about the manufacturer and the product. These fields have no requirement and can be set to zero.
bNumConfigurations is the number of configurations the device supports.
Table 8.5: Device descriptor
Offset |
Field |
Size |
Description |
0 |
bLength |
1 |
Descriptor size in bytes |
1 |
bDescriptorType |
1 |
Device descriptor (0x01) |
2 |
bcdUSB |
2 |
Highest version of USB supported |
4 |
bDeviceClass |
1 |
Class code |
5 |
bDeviceSubClass |
1 |
Subclass code |
6 |
bDeviceProtocol |
1 |
Protocol code |
7 |
bMaxPacketSize0 |
1 |
Maximum packet size |
8 |
idVendor |
2 |
Vendor ID |
10 |
idProduct |
2 |
Product ID |
12 |
bcdDevice |
2 |
Device release number |
14 |
iManufacturer |
1 |
Manufacturer string descriptor |
15 |
iProduct |
1 |
Index of product string descriptor |
16 |
iSerialNumber |
1 |
Index of serial number descriptor |
17 |
bNumConfigurations |
1 |
Number of possible configurations |
Table 8.6 shows an example device descriptor for a mouse device. The length of the descriptor is 18 bytes ( bLength =18), and the descriptor type is 0x01 ( bDescriptorType =0x01). The device supports USB 1.1 ( bcdUSB =0x0110). bDeviceClass , bDeviceSubClass , and bDeviceProtocol are set to zero to show that the class information is in the interface descriptor. bMaxPacketSize0 is set to 8 to show that the maximum input and output packet size for endpoint 0 is 8 bytes. The next three bytes identify the device by the vendor ID, product ID, and device version number. The next three items define indexes to strings about the manufacturer, product, and the serial number. Finally, we notice that the mouse device has just one configuration ( bNumConfigurations =1).
Table 8.6: Example device descriptor
Offset |
Field |
Value |
Description |
0 |
bLength |
18 |
Size is 18 |
1 |
bDescriptorType |
0x01 |
Descriptor type |
2 |
bcdUSB |
0x0110 |
Highest USB supported = USB 1.1 |
4 |
bDeviceClass |
0x00 |
Class information in interface descriptor |
5 |
bDeviceSubClass |
0x00 |
Class information in interface descriptor |
6 |
bDeviceProtocol |
0x00 |
Class information in interface descriptor |
7 |
bMaxPacketSize0 |
8 |
Maximum packet size |
8 |
idVendor |
0x02A |
XYZ Co Ltd. |
10 |
idProduct |
0x1001 |
Mouse |
12 |
bcdDevice |
0x0011 |
Device release number |
14 |
iManufacturer |
0x20 |
Index to manufacturer string |
15 |
iProduct |
0x21 |
Index of product string |
16 |
iSerialNumber |
0x22 |
Index of serial number string |
17 |
bNumConfigurations |
1 |
Number of possible configurations |
8.4.2 Configuration Descriptors
The configuration descriptor provides information about the power requirements of the device and how many different interfaces it supports. There may be more than one configuration for a device.
Table 8.7 shows the format of the configuration descriptor with the meaning of each field.
bLength is the length of the device descriptor.
bDescriptorType is the descriptor type.
wTotalLength is the total combined size of this set of descriptors (i.e., total of configuration descriptor + interface descriptor + HID descriptor + endpoint descriptor). When the configuration descriptor is read by the host, it returns the entire configuration information, which includes all interface and endpoint descriptors.
bNumInterfaces is the number of interfaces present for this configuration.
bConfigurationValue is used by the host (in command SetConfiguration ) to select the configuration.
iConfiguration is an index to a string descriptor describing the configuration in readable format.
bmAttributes describes the power requirements of the device. If the device is USB bus-powered, then bit D7 is set. If it is self-powered, it sets bit D6. Bit D5 specifies the remote wakeup of the device. Bits D7 and D0–D4 are reserved.
bMaxPower defines the maximum power the device will draw from the bus in 2mA units.
Table 8.7: Configuration descriptor
Читать дальше