USB Protocol Stack
Bus Architectures & Interconnects · Hardware Foundations track
10 min read
In this module
The Universal Serial Bus
USB is the most universal peripheral interface in computing. Keyboards, storage drives, smartphones, medical devices — billions of them connect to billions of hosts every day. Where PCIe is mostly an internal bus, USB was designed from day one as an external, hot-pluggable interface that non-technical users can plug in without thinking.
Underneath the friendly exterior is a serious protocol stack: a layered descriptor model, several transfer types tuned to different workloads, and a host-controlled polling architecture that's evolved dramatically across generations.
USB Architecture: Host-Centric
USB runs a host-controlled, tiered-star topology. Exactly one host (the PC, usually), and the host kicks off every conversation. Devices never speak to each other. The host polls each device and runs the show.
Hubs extend the bus by adding more downstream ports. The USB spec allows up to 127 devices on a single host controller and up to 7 tiers of hubs. Practical limits in real systems are lower.
The Descriptor Hierarchy
Every USB device introduces itself through a hierarchy of descriptors — structured data blocks the host reads during enumeration. That's how the OS figures out what a device is and how to talk to it.
A USB device is described by a tree of descriptors: the device descriptor (one per device, identifies the vendor and product), one or more configuration descriptors (each describing a set of interfaces the device can present), interface descriptors (each representing a logical function like "mass storage" or "audio"), and endpoint descriptors (the actual data pipes). The host reads these descriptors during enumeration to load the correct driver.
Device Descriptor
The top-level descriptor carries vendor ID, product ID, device class, and the number of configurations on offer. Every USB device has exactly one of these.
Device Descriptor (selected fields): bLength: 18 bDescriptorType: 1 (Device) bcdUSB: 0x0200 (USB 2.0) bDeviceClass: 0x00 (defined at interface level) idVendor: 0x046D (Logitech) idProduct: 0xC52B bNumConfigurations: 1Configuration Descriptor
A device can advertise multiple configurations, though almost everything ships with one. Each configuration names a set of interfaces and lists the power requirements.
Interface Descriptor
Each interface is a logical function. A single device can present several at once. A USB headset, for example, exposes an audio interface plus a volume-control HID (Human Interface Device) interface for the inline buttons.
The bInterfaceClass field tells the host what driver to load:
| Class Code | Description |
|---|---|
| 0x01 | Audio |
| 0x02 | Communications (CDC) |
| 0x03 | HID (keyboard, mouse) |
| 0x08 | Mass Storage |
| 0x09 | Hub |
| 0x0E | Video |
| 0xFF | Vendor-Specific |
Endpoint Descriptor
Endpoints are the actual data channels. Each one has a direction (IN or OUT, from the host's point of view), a transfer type, and a maximum packet size. Endpoint 0 is special — every device must have it, and it carries the control transfers used for setup and configuration.
Transfer Types
USB defines four transfer types, each tuned to a different shape of traffic:
Control Transfers
For device configuration and command/status work. Every USB session opens with control transfers on endpoint 0, reading descriptors and configuring the device. Delivery is guaranteed — the host retries on error — and the transfers are reserved for small, infrequent messages.
Bulk Transfers
For large, time-insensitive data — file copies, print jobs. Bulk transfers grab whatever bandwidth other transfer types haven't claimed and guarantee delivery via error detection and retry. No timing guarantees, though. If higher-priority traffic shows up, bulk waits.
Switch the visualiser below to USB to see both in packet terms. The first three steps are one control transfer on endpoint 0: a SETUP stage with the 8-byte request, a DATA stage returning the descriptor, and a STATUS stage closing the handshake. The last step is a bulk transfer to endpoint 2. Notice that the host starts every exchange, including the ones where data flows from the device.
Bus Transaction Flow
The GPU issues a Memory Read request TLP with a 64-bit address, requester ID, tag, and byte count. The TLP traverses the PCIe switch hierarchy toward the root complex.
Interrupt Transfers
For small, time-sensitive payloads where latency matters. Despite the name, these aren't real hardware interrupts. The host polls the device at a guaranteed interval — no tighter than every 10 ms for low-speed devices and 1 ms for full-speed, and as often as every 125 microseconds for high-speed USB 2.0 and USB 3.x. Keyboards and mice ride interrupt transfers.
Isochronous Transfers
For real-time streams: audio, video. Isochronous transfers reserve a guaranteed slice of bus bandwidth and deliver at a constant rate. They do not retry on error — a lost audio sample is better dropped than smeared late. Each isochronous endpoint declares its bandwidth needs up front, and the host controller pre-allocates capacity during configuration.
Isochronous transfers sacrifice reliability for timing. Every USB frame delivers exactly the promised amount of data, but corrupted packets are discarded rather than retransmitted. Bulk transfers sacrifice timing for reliability: every byte is delivered correctly, but the host can delay transfers when bandwidth is scarce. Choosing the right transfer type is a fundamental USB design decision.
USB Generations
USB has stair-stepped through multiple speed tiers, each one keeping backwards compatibility with everything before it:
| Generation | Speed | Year | Notes |
|---|---|---|---|
| USB 1.0 | 1.5 Mbps (Low Speed) | 1996 | Keyboards, mice |
| USB 1.1 | 12 Mbps (Full Speed) | 1998 | Audio, basic peripherals |
| USB 2.0 | 480 Mbps (High Speed) | 2000 | Storage, cameras, most devices |
| USB 3.0 | 5 Gbps (SuperSpeed) | 2008 | Separate Tx/Rx pairs, full-duplex |
| USB 3.1 | 10 Gbps (SuperSpeed+) | 2013 | 128b/132b encoding |
| USB 3.2 | 20 Gbps (SuperSpeed+ x2) | 2017 | Dual-lane operation |
| USB4 | 40 Gbps (Gen 3 x2) | 2019 | Tunnelled protocols, based on Thunderbolt 3 |
| USB4 v2 | 80 Gbps (Gen 4) | 2022 | Asymmetric up to 120 Gbps |
USB 3.x: A Parallel Protocol Stack
USB 3.0 wasn't just a faster USB 2.0. It bolted on a whole new set of differential pairs (SuperSpeed Tx and Rx) right alongside the original USB 2.0 wires. A USB 3.0 connection actually runs two independent protocols at once: the legacy USB 2.0 on the original wires, the new SuperSpeed on the extra pairs.
USB 3.0 Type-A Connector Pins: [USB 2.0 pins: VBUS, D-, D+, GND] -- legacy half-duplex [USB 3.0 pins: StdA_SSRX-, StdA_SSRX+, GND, StdA_SSTX-, StdA_SSTX+] -- SuperSpeed full-duplexUSB 3.0 also overhauled the transaction model. Instead of the host polling every device on a schedule, SuperSpeed devices can fire asynchronous notifications when they have data ready. Less wasteful polling, less power burn.
USB4 and Thunderbolt Convergence
USB4 is a real architectural shift. It's built on the Thunderbolt 3 protocol that Intel handed to the USB Implementers Forum. USB4 uses a tunnelling architecture — multiple protocols (USB 3.x data, DisplayPort video, PCIe) share one physical link via time-division multiplexing.
One USB4/Thunderbolt cable can simultaneously carry USB data to an external drive, DisplayPort video to a monitor, and PCIe traffic to an external GPU or NVMe enclosure. The host's USB4 controller divvies up bandwidth across the tunnels on the fly based on demand.
Every USB4 host has to support the USB Type-C connector and USB Power Delivery — up to 240W under the Extended Power Range specification.
USB Security: BadUSB and Beyond
The USB trust model has a load-bearing flaw: the host trusts the device's self-description. During enumeration, the host reads the device's descriptors and loads the matching driver. There is no mechanism — none — for the host to verify a self-declared keyboard is actually a keyboard.
The BadUSB Attack
BadUSB (Karsten Nohl and Jakob Lell, Black Hat 2014) weaponises that trust. The attacker reflashes the controller firmware of an ordinary USB device so it enumerates as a different class than the user expects. Purpose-built injectors like the Rubber Ducky get the same result without any reflashing: they're keyboards from the start, in a flash-drive case. Typical scenarios:
- A USB flash drive reprogrammed to also enumerate as a keyboard, then "typing" malicious commands at high speed
- A device presenting as a network adapter to redirect DNS traffic or inject proxy settings
- A device claiming to be a mass storage device with an autorun payload
The same idea now fits inside a cable. Implants such as the O.MG Cable hide a HID injector and a Wi-Fi radio in the connector of what looks like an ordinary charging lead. USB-C widens the surface further: Power Delivery negotiation and alternate modes (DisplayPort, Thunderbolt) run their own firmware-driven protocols over the same connector, and each has been a target for fuzzing and downgrade research.
Normal USB drive enumeration: Device Descriptor: idVendor=0x0781 (SanDisk) Interface Class: 0x08 (Mass Storage)
BadUSB-modified enumeration: Device Descriptor: idVendor=0x0781 (SanDisk) -- looks legitimate Interface 0 Class: 0x08 (Mass Storage) -- expected Interface 1 Class: 0x03 (HID / Keyboard) -- hidden attack interfaceHere's that drive's configuration descriptor as raw bytes, walked the way a host does it: each descriptor starts with its own length and type, so you hop from one to the next. A USBGuard rule such as allow id 0781:5567 with-interface equals { 08:06:50 } would refuse this stick, because its interface list doesn't match.
Defences
Operating systems have started fighting back:
- USBGuard (Linux): policy-based USB device authorisation. Devices must match a whitelist before the kernel loads a driver.
- Accessory approval (macOS 13 and later on Apple silicon laptops): prompts the user before allowing a new USB accessory to connect.
- USB device class filtering: blocking unexpected interface classes (e.g., a storage device should not also be a keyboard).
- Hardware security keys: devices like YubiKeys use signed firmware updates to prevent reprogramming.
USB's descriptor-based enumeration trusts the device to honestly describe itself. The host has no cryptographic mechanism to verify a device's identity or class. This design made USB simple and universal but created a fundamental security gap that BadUSB and similar attacks exploit. USB Authentication (defined in the USB specification) adds optional cryptographic device authentication, but adoption remains limited.
USB in Practice
# Linux: list all USB devices with their descriptorslsusb -v
# Show the USB device tree (hubs and ports)lsusb -t
# macOS: list USB devicessystem_profiler SPUSBDataTypeWhy It Matters
USB is simultaneously the most convenient and one of the most dangerous peripheral interfaces. Its ubiquity and hot-plug nature make it part of every system. The same properties make it an attractive attack surface. Understanding the descriptor hierarchy, transfer types, and trust model pays off whether you're writing drivers, building embedded systems, or auditing the USB stack of a target device.