USB Device Logical Structure
In the logical organization of USB devices, there are 4 levels of devices, configurations, interfaces, and endpoints. A device typically has one or more configurations, and the configuration usually has one or more interfaces, and the interface typically has 0 or more endpoints.
USB Device Descriptor
When we plug a USB device (such as a USB mouse) into our PC, the host can automatically identify our USB device type. Within each USB device, contains the fixed-format data, through which the USB host can obtain the type of USB device, manufacturer and other information. These fixed-format data, which we call USB descriptors. Standard devices have 5 USB descriptors: Device descriptors, configuration descriptors, interface descriptors, endpoint descriptors, string descriptors. These descriptors are in registers inside the USB device for the host to view.
A USB device has only one device descriptor, and the device descriptor is 18 bytes long.
1. Important device descriptors are:
Bdeviceclass: Type Code
Bdevicesubclass: Sub-type Code
Idvendor: Vendor ID
IDPRODUCT: Product ID
You can determine the type of USB device by type code and subtype code.
2. Important configuration descriptors are:
Bnuminterfaces: The number of interfaces supported by the configuration, which is the number of interfaces configured by the configuration device, and also the number of interface descriptors under that configuration.
USB Data Communication
A transfer (transport) consists of one or more transaction (transactions), a transaction (transaction) consisting of one or more packet (packets), and a packet (packet) consisting of one or more sync (domains).
1. Transmission Data communication
The data communication of USB is based on transmission (transfer) First, the type of transmission is: interrupt transmission, batch transmission, synchronous transmission, control transmission.
2. Transactional data communication
A single transport consists of one or more transactions (transaction), which can be divided into: in transaction, out transaction, setup transaction.
3. Packet data communication
A transaction consists of one or more packages (packet), which can be divided into: Token package (Setup), packet (data), Handshake Packet (ACK), special package.
4. Domain Data communication
A package consists of multiple domains, domain can be divided into: synchronization domain (sync), identity domain (PID), address domain (addr), endpoint domain (ENDP), Frame Number field (FRAM), data domain (database), check domain (CRC).
USB Device Enumeration
USB device before it works, the first thing to do is enumerate. Enumeration is to let the host recognize this USB device, and prepare resources for the device, to establish a good host and the data transfer channel between the device.
1. Get the device descriptor
2. Reset
3. Setting the Address
4. Get the device descriptor again
5. Get the configuration descriptor
6. Get interface, endpoint descriptor
7. Get the string descriptor
8. Select Device Configuration
[Country EMBED strategy] [162] [USB Protocol Analysis]