What are USB descriptors and what information do they contain? Describe the descriptor hierarchy.
USB descriptors are structured data blocks that a device provides to the host during enumeration. They form a tree-like hierarchy that describes every aspect of the device's capabilities and requirements. The host uses this information to load the correct driver and allocate bus bandwidth.
Device Descriptor (18 bytes, one per device): Contains the USB specification version (bcdUSB), device class/subclass/protocol codes, VID (Vendor ID) and PID (Product ID), maximum packet size for endpoint 0, number of configurations, and manufacturer/product/serial number string indices. The VID/PID pair is what the OS uses to match the device to a driver. The device class field can be 0x00 (class defined at interface level — most common for composite devices), or a specific class code (0x02 for CDC, 0xEF for miscellaneous composite).
Configuration Descriptor (9 bytes, one or more per device): Describes a specific configuration the device can operate in. Most devices have exactly one configuration. Contains the total length of all subordinate descriptors (wTotalLength — critical for the host to know how many bytes to read), number of interfaces, power requirements (bMaxPower in 2 mA units), and self-powered/remote-wakeup attributes. When the host sends GET_DESCRIPTOR for a configuration, the device returns the configuration descriptor followed by all its interface and endpoint descriptors concatenated into a single response of wTotalLength bytes.
Interface Descriptor (9 bytes): Describes a functional group of endpoints — one "function" of the device. A composite device (e.g., a USB keyboard with a built-in hub) has multiple interfaces, each potentially using a different device class. Contains the interface number, alternate setting number, class/subclass/protocol, and number of endpoints. Endpoint Descriptor (7 bytes): Describes a single endpoint — its address (number + direction), transfer type (control, bulk, interrupt, isochronous), maximum packet size, and polling interval (for interrupt and isochronous endpoints). Endpoint 0 is always a bidirectional control endpoint and has no explicit descriptor — its properties are defined in the device descriptor.
The hierarchy is: Device contains Configurations, each Configuration contains Interfaces, each Interface contains Endpoints. String descriptors provide human-readable names referenced by index from other descriptors. Class-specific descriptors (e.g., HID report descriptors, CDC functional descriptors) are inserted between interface and endpoint descriptors.
Source: USB Q&A
