Device Descriptors
Device Descriptors
Camera activated
Microphone activated
Camera and microphone activated
An Endpoint Descriptor contains information required by the host to determine the
bandwidth requirements of each endpoint. An endpoint represents a logical data
source or sink of a USB device. The endpoint zero is used for all control transfers
and there is never a descriptor for this endpoint. The USB specification uses the
terms pipe and endpoint interchangably.
Device Classes
The standard device and interface descriptors contain fields that are related to
classification: class, sub-class and protocol. These fields may be used by a host
system to associate a device or interface to a driver, depending on how they are
specified by the class specification. Valid values for the class fields of the
device and interface descriptors are defined by the USB Device Working Group.
That master/slave asymmetry was designed-in for a number of reasons, one being ease
of use. It is not physically possible to mistake upstream and downstream or it does
not matter with a type C plug (or they are built into the peripheral). Also, the
host software doesn’t need to deal with distributed auto-configuration since the
pre-designated master node manages all that.
Kernel developers added USB support to Linux early in the 2.2 kernel series and
have been developing it further since then. Besides support for each new generation
of USB, various host controllers gained support, new drivers for peripherals have
been added and advanced features for latency measurement and improved power
management introduced.
Linux can run inside USB devices as well as on the hosts that control the devices.
But USB device drivers running inside those peripherals don’t do the same things as
the ones running inside hosts, so they’ve been given a different name: gadget
drivers. This document does not cover gadget drivers.
USB supports four kinds of data transfers (control, bulk, interrupt, and
isochronous). Two of them (control and bulk) use bandwidth as it’s available, while
the other two (interrupt and isochronous) are scheduled to provide guaranteed
bandwidth.
The device description model includes one or more “configurations” per device, only
one of which is active at a time. Devices are supposed to be capable of operating
at lower than their top speeds and may provide a BOS descriptor showing the lowest
speed they remain fully operational at.
From USB 3.0 on configurations have one or more “functions”, which provide a common
functionality and are grouped together for purposes of power management.
Configurations or functions have one or more “interfaces”, each of which may have
“alternate settings”. Interfaces may be standardized by USB “Class” specifications,
or may be specific to a vendor or device.
USB device drivers actually bind to interfaces, not devices. Think of them as
“interface drivers”, though you may not see many devices where the distinction is
important. Most USB devices are simple, with only one function, one configuration,
one interface, and one alternate setting.
Interfaces have one or more “endpoints”, each of which supports one type and
direction of data transfer such as “bulk out” or “interrupt in”. The entire
configuration may have up to sixteen endpoints in each direction, allocated as
needed among all the interfaces.
Data transfer on USB is packetized; each endpoint has a maximum packet size.
Drivers must often be aware of conventions such as flagging the end of bulk
transfers using “short” (including zero length) packets.
The Linux USB API supports synchronous calls for control and bulk messages. It also
supports asynchronous calls for all kinds of data transfer, using request
structures called “URBs” (USB Request Blocks).
Accordingly, the USB Core API exposed to device drivers covers quite a lot of
territory. You’ll probably need to consult the USB 3.0 specification, available
online from www.usb.org at no cost, as well as class or device specifications.
The only host-side drivers that actually touch hardware (reading/writing registers,
handling IRQs, and so on) are the HCDs. In theory, all HCDs provide the same
functionality through the same API. In practice, that’s becoming more true, but
there are still differences that crop up especially with fault handling on the less
common controllers. Different controllers don’t necessarily report the same aspects
of failures, and recovery from faults (including software-induced ones like
unlinking an URB) isn’t yet fully consistent. Device driver authors should make a
point of doing disconnect testing (while the device is active) with each different
host controller driver, to make sure drivers don’t have bugs of their own as well
as to make sure they aren’t relying on some HCD-specific behavior.