I am USB in Linux. I am a USB flash drive (10). Who am I?

Source: Internet
Author: User

Probe, disconnect, id_table, the first of the three elements to appear is id_table. What is it?

We have said that a device can only bind one driver, but the driver does not support only one device. The principle is very simple. For example, if I have two USB flash drives, I can insert them together, but I only need to load one module, USB-storage. I have never heard of it. inserting two USB flash drives requires loading the drivers twice, unless the two USB flash drives have to use different drivers. It is precisely because a module can be shared by multiple devices that the "module count" clause is generated.

Since a driver supports multiple devices, how can I know which one is its driver when I find a device? This is the use of id_table. Let every struct usb_driver prepare a table, which indicates which devices the driver supports. If this device belongs to this table, bind it. If it does not belong to this table, sorry. Please proceed.

Id_table is from struct usb_driver:

Const struct usb_device_id * id_table;

It is actually a pointer, A structusb_device_id struct pointer, of course, after the value is assigned, it represents an array name, just as we have defined the value assigned in struct usb_driver usb_storage_driver ,. id_table = storage_usb_ids. Well, let's take a look at the structure of usb_device_id.

Struct usb_device_id from include/Linux/mod_devicetable.h:

98 struct usb_device_id {

99/* whichfields to match against? */

100 _ match_flags;

101

102/* used for product specificmatches; range is random */

103 _ 16idvendor;

104 _ 16idproduct;

105 _ 2010bcddevice_lo;

106 _ 16bcddevice_hi;

107

108/* used for device class matches */

109 _ u8 bdeviceclass;

110 _ u8 bdevicesubclass;

111 _ u8 bdeviceprotocol;

112

113/* used for interface classmatches */

114 _ u8 binterfaceclass;

115 _ u8 binterfacesubclass;

116 _ u8 binterfaceprotocol;

117

118/* not matched against */

119 kernel_ulong_t driver_info;

120 };

In fact, this structure is equivalent to its ID card for every USB device, recording some of its basic information. Generally, our ID card records our name, gender, date of birth, account address, and so on. USB devices also have the information they need to record to distinguish it from other USB devices. For example, the vendor-manufacturer, product-product, and other products such as product numbers, product categories, and protocols will all find corresponding members in the USB specifications.

So we know that a USB _ driver will compare its ID table with the actual situation of each USB device. If the actual situation of this device is the same as that of a specific ID in this table, to be accurate, only when many of these features are consistent can a USB device be bound to the USB driver, and these features are even less difficult.

When was the actual situation of the USB device established? Before introducing the. Probe pointer, it is necessary to talk about another data structure, which is struct usb_device.

Related Article

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.