Device Structure and Enumeration
Before the host application can communicate with a device, the host needs to understand the capabilities of the device. This process takes place during device enumeration. After enumeration, the host can assign and load a specific driver to allow communication between the application and the device.
During enumeration, the host assigns an address to the device, reads descriptors from the device, and selects a configuration that specifies power and interface requirements. In order for the host to learn about the device’s capabilities, the device must provide information about itself in the form of descriptors.
This section describes the device’s logical organization from the USB host’s point of view.
USB Device Structure
From the host’s point of view, USB devices are internally organized as a collection of configurations, interfaces and endpoints.
Configuration
A USB configuration specifies the capabilities of a device. A configuration consists of a collection of USB interfaces that implement one or more USB functions. Typically only one configuration is required for a given device. However, the USB specification allows up to 255 different configurations. During enumeration, the host selects a configuration. Only one configuration can be active at a time. The device uses a configuration descriptor to inform the host about a specific configuration’s capabilities.
Interface
A USB interface or a group of interfaces provides information about a function or class implemented by the device. An interface can contain multiple mutually exclusive settings called alternate settings. The device uses an interface descriptor to inform the host about a specific interface’s capabilities. Each interface descriptor contains a class, subclass, and protocol codes defined by the USB-IF, and the number of endpoints required for a particular class implementation.
Alternate Settings
Alternate settings are used by the device to specify mutually exclusive settings for each interface. The default alternate settings contain the default settings of the device. The device also uses an interface descriptor to inform the host about an interface’s alternate settings.
Endpoint
An interface requires a set of endpoints to communicate with the host. Each interface has different requirements in terms of the number of endpoints, transfer type, direction, maximum packet size, and maximum polling interval. The device sends an endpoint descriptor to notify the host about endpoint capabilities.
Figure - USB Device Structure shows the hierarchical organization of a USB device. Configurations are grouped based on the device’s speed. A high-speed device might have a particular configuration in both high-speed and low/full speed.
Device States
The USB 2.0 specification defines six different states and are listed in Table - USB Device States.
Device States | Description |
---|---|
Attached | The device is in the Attached state when it is connected to the host or a hub port. The hub must be connected to the host or to another hub. |
Powered | A device is considered in the Powered state when it starts consuming power from the bus. Only bus-powered devices use power from the host. Self-powered devices are in the Powered state after port attachment. |
Default | After the device has been powered, it should not respond to any request or transactions until it receives a reset signal from the host. The device enters in the Default state when it receives a reset signal from the host. In the Default state, the device responds to standard requests at the default address 0. |
Address | During enumeration, the host assigns a unique address to the device. When this occurs, the device moves from the Default state to the Address state. |
Configured | After the host assigns an address to the device, the host must select a configuration. After the host selects a configuration, the device enters the Configured state. In this state, the device is ready to communicate with the host applications. |
Suspended | The device enters into Suspended state when no traffic has been seen over the bus for a specific period of time. The device retains the address assigned by the host in the Suspended state. The device returns to the previous state after traffic is present in the bus. |
Enumeration
Enumeration is the process where the host configures the device and learns about the device’s capabilities. The host starts enumeration after the device is attached to one of the root or external hub ports. The host learns about the device’s manufacturer, vendor/product IDs and release versions by sending a Get Descriptor request to obtain the device descriptor and the maximum packet size of the default pipe (control endpoint 0). Once that is done, the host assigns a unique address to the device which will tell the device to only answer requests at this unique address. Next, the host gets the capabilities of the device by a series of Get Descriptor requests. The host iterates through all the available configurations to retrieve information about number of interfaces in each configuration, interfaces classes, and endpoint parameters for each interface and will lastly finish the enumeration process by selecting the most suitable configuration.