USB descriptor details

Source: Internet
Author: User

I. Basic Concepts

1. the USB protocol itself is complex, but it provides a unified interface to simplify the work of drivers when using devices to perform similar operations on serial interfaces.

2. USB devices can be seen as devices that provide multiple serial ports. According to USB specifications, each serial port is called an endpoint to communicate with this endpoint, we need to open the connection to this endpoint, which is the pipeline ).

3. After the endpoint is enabled, You can transmit data like a serial port. There are four different USB transmission modes: control transmission, bulk transmission, interrupt transmission, and isochtransfer ).

4. Because a device may have to adapt to multiple situations, multiple endpoints are configured for use. The endpoint settings are called interfaces ). The interfaces shown by the USB device are the interfaces we can find. We can select the interfaces we want to use to find the endpoint, and then open the endpoint to transmit data. Therefore, when the driver starts, you need to record these interfaces.

5. For example, the ov511 + endpoint 0 is the control endpoint, which is used to set parameters and start and stop devices, and the real-time transmission endpoint 1 is used to transmit videos. There are 8 sets of different settings for endpoint 1. The main difference is the size of the data frame transmitted at a time. Therefore, you need to record these settings in the driver during USB deviceattach before selecting them.

II. Introduction to Descriptors
The standard USB device has five types of USB descriptors: device descriptor, configuration descriptor, string descriptor, interface descriptor, and Endpoint descriptor. The following details:

1. device descriptor: A device has only one device descriptor.

Typedef struct _ usb_device_descriptor _
{
Byte blength,
Byte bdescriptortype,
Word bcdusb,
Byte bdeviceclass,
Btye bdevicesubclass,
Byte bdeviceprotol,
Byte bmaxpacketsize0,
Word idvenderi,
Word idproduct,
Word bcddevice,
Byte imanufacturer,
Byte iproduct,
Byte iserialnumber,
Byte inumconfiguations
} Usb_device_descriptor;

Blength: descriptor size. Fixed to 0x12.
Bdescriptortype: device descriptor type. Fixed to 0x01.
Bcdusb: USB specification release number. indicates the Protocol applicable to this device, such as 2.0 = 0200, 1.1 = 0110.

Bdeviceclass: Type Code (specified by USB ). When its value is 0, it indicates that all interfaces are in the configuration Descriptor and all interfaces are independent. When its value is 1 to Feh, it indicates that different interfaces are associated. When its value is FFH, it is defined by the vendor. bdevicesubclass: Child-type code (allocated by USB ). if the bdeviceclass value is 0, you must set it to 0. the other case is the Code defined by the USB-IF organization. bdeviceprotocol: protocol code (allocated by USB ). if you use a protocol defined by the USB-IF organization, you need to set the value here, otherwise it is directly set to 0. If the vendor defines it, it can be set to FFH. bmaxpacketsize0: The maximum group size of endpoint 0 (only 8, 16, 32, 64 valid ).

Idvendor: Supplier ID (allocated by USB ).

Idproduct: Product ID (allocated by manufacturer). Different drivers can be loaded by the operating system by supplier ID and product ID.

Bcddevice: The device production code, which is set by the manufacturer.

Imanufacturer: vendor descriptor string index. Index to the corresponding string descriptor. 0 indicates no. iproduct: Product descriptor string index. Same as above.
Iserialnumber: Device serial number string index. Same as. bnumconfigurations: possible number of configurations. It indicates the number of configuration strings. 2. Configuration Descriptor: The configuration descriptor defines the configuration information of the device. A device can have multiple configuration descriptors: typedef struct _ usb_configuration_descriptor _
{
Byte blength,
Byte bdescriptortype,
Word wtotallength,
Byte bnuminterfaces,
Byte bconfigurationvalue,
Byte iconfiguration,
Byte bmattributes,
Byte maxpower
} Usb_configuration_descriptor;

Blength: descriptor size. Fixed to 0x09.
Bdescriptortype: configures the descriptor type. The value is fixed to 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. This parameter indicates the number of interfaces configured for 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: Power Supply Mode Selection. Bit4-0 retention, D7: Bus Power Supply, D6: Self-powered, D5: Remote Wake-Up.
Maxpower: the maximum current consumption of a USB device powered by the bus. The unit is 2mA.3. Interface Descriptor: The interface descriptor describes the configuration provided by the interface. The number of interfaces owned by a configuration determines the typedef struct _ usb_interface_descriptor _ through the bnuminterfaces of the configuration descriptor _
{
Byte blength,
Byte bdescriptortype,
Byte binterfacenumber,
Byte balternatesetting,
Byte bnumendpoint,
Byte binterfaceclass,
Byte binterfacesubclass,
Byte binterfaceprotocol,
Byte iinterface
} Usb_interface_descriptor;

Blength: descriptor size. Fixed to 0x09.
Bdescriptortype: Type of the interface descriptor. The value is fixed to 0x04.
Binterfacenumber: ID of the interface.
Balternatesetting: used to select a position for replacement for the previous field, that is, the backup interface descriptor number.
Bnumendpoint: Number of endpoints used, except for endpoint 0.
Binterfaceclass: Type Code (allocated by USB ).
Binterfacesunclass: Child type code (allocated by USB ).
Binterfaceprotocol: protocol code (allocated by USB ).
Iinterface: String descriptor Index4. endpoint Descriptor: Each endpoint in the USB device has its own endpoint descriptor, which is determined by the bnumendpoint in the interface descriptor. The number of typedef struct _ usb_endpoint_descriptor _
{
Byte blength,
Byte bdescriptortype,
Byte bendpointaddress,
Byte bmattributes,
Word wmaxpacketsize,
Byte binterval
} Usb_endpoint_descriptor;

Blength: descriptor size. Fixed to 0x07.
Bdescriptortype: Type of the interface descriptor. The value is fixed to 0x05.
Bendpointtype: USB device endpoint address. bit7, direction, can be ignored for control endpoint, 1/0: in/out. Bit6-4, keep. BIt3-0: endpoint number.
Bmattributes: endpoint properties. 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.5. String Descriptor: The string descriptor is optional. If the string descriptor is not supported, the device, configuration, and index of all string descriptors in the interface descriptor must be 0 typedef struct _ usb_string_description _
{
Byte blength,
Byte bdescriptiontype,
Byte bstring [1];
} Usb_string_description;

Blength: the descriptor size, which is determined by the length of the entire string plus the length of blength and bdescriptortype.
Bdescriptortype: Type of the interface descriptor. The value is fixed to 0x03.
Bstring [1]: unicode encoded string.

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.