USB protocol analysis, usb protocol

Source: Internet
Author: User

USB protocol analysis, usb protocol

1. Description structure of USB devices

1. Logical Organizational Structure

The logical organization of a USB device consists of four layers: device, configuration, interface, and endpoint. A device usually has one or more configurations. The configuration usually has one or more interfaces with zero or multiple endpoints.

Each USB device can contain one or more configurations. Different Configurations make the device display different combinations of functions. The configuration consists of multiple interfaces. In the USB protocol, interfaces represent a basic function. A complicated USB device can have multiple interfaces, and interfaces are the collection of endpoints.

A usb player provides audio, video, and knob and buttons.
Configuration 1: audio (Interface) + knob (Interface)
Configuration 2: Video (Interface) + knob (Interface)
Configuration 3: audio (Interface) + video (Interface) + button (Interface)
A driver is required for audio, video, button, and knob interfaces.

The only addressable part of a USB device is the device endpoint, which acts like a register. Each endpoint has a unique endpoint number inside the device, which is specified during device design. The communication between the host and the device finally acts on each endpoint on the device. Each endpoint supports one-way operations, either read-only or write-only.

2.Descriptor

Each USB device contains data in a fixed format. With the data, the USB host can obtain information such as the type and manufacturer of the USB device. These fixed-format data are called USB descriptors. The standard USB device has five types of USB descriptors: device descriptor, configuration descriptor, interface descriptor, endpoint descriptor, and string descriptor.

2.1Device descriptor

BLength: the descriptor length, fixed to 0x12.
BDescriptorType: device descriptor type, fixed to 0x01.
BcdUSB: USB specification release number. Indicates the Protocol that the device can apply to, for example, 2.0 = 0200.
BDeviceClass: type code.
BDeviceSubClass: subtype code.
BDeviceProtocol: protocol code.
BMaxPacketSize0: Maximum group size of endpoint 0.
IdVendor: Supplier ID.
IdProduct: The product ID (allocated by the manufacturer ).
BcdDevice: The device production code, which is set by the manufacturer.
IManufacturer: vendor descriptor string index. Index to the corresponding string descriptor.
IProduct: Product descriptor string index.
ISerialNumber: Device serial number string index.
BNumConfigurations: number of possible configurations.

2.2Configuration Descriptor

BLength: the descriptor length, fixed to 0x09.
BDescriptorType: Specifies the descriptor type, which is 0x02.
WTotalLength: the length of the returned data. It refers to the configuration descriptor, interface descriptor, and the full size of the endpoint descriptor returned by this configuration.
BNumInterfaces: number of interfaces supported by the configuration, which indicates the number of interfaces configured in the configuration and the number of interface descriptors under the configuration.
BConfigurationValue: select the Configuration value as a parameter of Set Configuration.
IConfiguration: used to describe the index of the configuration string descriptor.
BmAttributes: select the power supply mode. Bit4-0 retained, D7: Bus powered, D6: self powered, D5: Remote Wake-Up.
MaxPower: maximum current consumption of a USB device powered by a bus, in 2mA.

2.3Interface Descriptor

BLength: the descriptor length, fixed to 0x09.
BDescriptorType: specifies the type of the interface descriptor, Which is 0x04.
BInterfaceNumber: ID of the API.
BAlternateSetting: used to select an alternative setting for the previous field.
BNumEndpoint: Number of endpoints used, except for endpoint 0.
BInterfaceClass: Type Code (allocated by USB organization ).
BInterfaceSunClass: Child type code (allocated by USB organization ).
BInterfaceProtocol: protocol code (allocated by USB organization ).
IInterface: Index of the string descriptor.

2.4Endpoint Descriptor

BLength: the descriptor size, fixed to 0x07.
BDescriptorType: specifies the type of the interface descriptor, Which is 0x05.
BEndpointType: the endpoint address of the USB device. Bit7, direction, can be ignored for the control endpoint, 1/0: IN/OUT. Bit6-4, retained. BIt3-0: endpoint number.
BmAttributes: endpoint property, Bit7-2, retained. BIt1-0: 00 control, 01 synchronization, 02 batch, 03 interrupt.
WMaxPacketSize: maximum information package size received or sent by the current endpoint.
BInterval: the time interval of the training data transmission endpoint. ignore the Batch Transfer and Control Transfer endpoints. the synchronous transmission endpoint must be 1. For the interrupted transmission endpoint, the range is 1-255.

 

Ii. USB Data Communication

1. Communication Model

2. Transmission

 

USB data communication is first based on transmission (Transfer). The transmission types include:Interrupted transmission (such as USB or keyboard), batch transmission (large-capacity transmission, such as USB flash drives), synchronous transmission, and control transmission.

3. Transactions

 

A single transmission is composed of one or more transactions. transactions can be divided:In transaction, Out transaction, Setup transaction

4. Package

 

A transaction consists of one or more packages. packages can be divided:Token package (setup), data packet (data), handshake packet (ACK), and special packet

5. Domain

 

A package consists of multiple domains, which can be divided:Synchronization domain (SYNC), Id domain (PID), address domain (ADDR), End Point domain (ENDP), frame number domain (FRAM), data domain(DATA), verification domain (CRC)

Iii. USB data Enumeration

 

Before the USB device works properly, the first thing to do is enumeration.Enumeration allows the host to recognize the USB device, prepare resources for the device, and establish a data transfer channel between the host and the device.

 

1. Get the device descriptor
2. Reset
3. Set the address
4. Get the device descriptor again
5. Get the configuration Descriptor
6. Obtain the interface and Endpoint Descriptor
7. Get the string Descriptor
8. Select Device Configuration

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.