Speaking of USB devices, we have to mention a variety of descriptors (descriptors), in general, descriptors are as follows:
1: Device Descriptor (Device descriptors)
2: Configuration descriptor (Configuration descriptors)
2: Interface Descriptor (Interface descriptors)
3: Endpoint descriptor (Endpoint descriptors)
A USB device has only one device descriptor, the device descriptor defines how many configurations the device has, each configuration descriptor corresponds to the configuration descriptor, and the configuration descriptor defines how many interfaces are in the configuration, each interface has a corresponding interface descriptor. The interface descriptor also defines how many endpoints the interface has, each endpoint corresponds to an endpoint descriptor, and the endpoint descriptor defines the endpoint size, type, and so on. From this we can see that the relationship between the USB descriptor is one layer, the last layer is the device descriptor, the following is the configuration descriptor, the following is the interface descriptor, and the following is the endpoint descriptor. When the descriptor is obtained, the device descriptor is obtained, and then the configuration descriptor is obtained, and the configuration descriptor, interface descriptor, and endpoint descriptor are read back one at a time, depending on the configuration set length in the configuration descriptor. It may also have access to device serial numbers, vendor strings, product strings, and so on.
The detailed relationship is shown in the following illustration:
Below we look at the detailed definition of these descriptors from the software perspective (the following definition is taken from the window system, the Linux naming is slightly different, the member content is consistent)
The device descriptor structure is as follows:
typedef struct _USB_DEVICE_DESCRIPTOR {
uchar blength; The descriptor structure Body size (18 bytes)
uchar bDescriptorType; The descriptor type (fixed in the structure is 0x01)
USHORT Bcdusb; USB version number
Uchar bdeviceclass; Device class code (by USB official distribution)
Uchar bdevicesubclass; The subclass code (officially allocated by USB)
Uchar bdeviceprotocol; Device protocol code (distributed by USB official)
Uchar bMaxPacketSize0; The maximum packet size of endpoint 0 (valid size is 8,16,32,64)
USHORT Idvendor; Manufacturer number (by USB official distribution)
USHORT idproduct; Product number (manufacturer allocation)
USHORT Bcddevice; Equipment Factory number
Uchar imanufacturer; Device manufacturer String Index
uchar iproduct; Product Description String index
uchar iserialnumber; Device serial number string index
uchar bnumconfigurations; The number of configurations that can be supported at current speeds
} usb_device_descriptor, *pusb_device_descriptor;
The configuration descriptor structure is as follows:
typedef struct _USB_CONFIGURATION_DESCRIPTOR {
uchar blength; The descriptor structure body size
uchar bdescriptortype; The descriptor type (fixed in the structure is 0x02)
USHORT wtotallength; All data sizes returned by this configuration
uchar bnuminterfaces; The number of interfaces for this configuration
uchar bconfigurationvalue; The parameter value required by the set_configuration command
uchar iconfiguration; The index value of the string describing the configuration
uchar bmattributes; The choice of power supply mode
Uchar maxpower; Equipment from the bus to extract the maximum current
} usb_configuration_descriptor, *pusb_configuration_descriptor;
The interface descriptor structure is as follows:
typedef struct _USB_INTERFACE_DESCRIPTOR {
uchar blength; The descriptor structure size
Uchar bDescriptorType; The type number of the interface descriptor (0x04)
Uchar Binterfacenumber; The number of the interface is
Uchar balternatesetting; The alternate interface descriptor number
Uchar bnumendpoints; The number of end points used by the interface, excluding endpoints 0
Uchar Binterfaceclass; Interface type
Uchar Binterfacesubclass; Connection type
Uchar Binterfaceprotocol; Interfaces follow the protocol
Uchar IInterface; Describes the string index value of the interface
} usb_interface_descriptor, *pusb_interface_descriptor;
The endpoint descriptor structure is as follows:
typedef struct _USB_ENDPOINT_DESCRIPTOR {
uchar blength; Endpoint descriptor byte number size (7 bytes)
uchar bDescriptorType; Endpoint Descriptor type number (0x05)
uchar bendpointaddress; Endpoint address and input and output attributes
Uchar bmattributes; The transport type attribute of the endpoint
USHORT wmaxpacketsize; The maximum packet size of end registration and hair
uchar binterval; Host query endpoint time interval
} usb_endpoint_descriptor, *pusb_endpoint_descriptor;
In addition to the above four descriptors, there is a string descriptor that, for a USB device, is not necessarily implemented (when not implemented, the descriptor should be set to 0 to indicate that the feature is not implemented).
typedef struct _USB_STRING_DESCRIPTOR {
Uchar Blength; Number of String Descriptor bytes
Uchar bDescriptorType; String descriptor type Number (0X03)
WCHAR Bstring[1]; Unicode string
} usb_string_descriptor, *pusb_string_descriptor;
Reprint: http://blog.csdn.net/saloon_yuan/article/details/7837492
Resources:
1, Libusb open Source Library related
2. USB Device Development----Non-flooding design based on LIBUSB