USB device driver guide (7)

Source: Internet
Author: User
Let's see Program In line 2, here is a judgment Statement, which is used to determine whether the inserted device is of the usbmsc_interface_class type. This constant is in usbmsc. the H file defines that if the device is not a USB storage device, the function is terminated, that is, the driver can only process USB storage devices.

When the device meets the requirements of this driver, it will be resolved through the parseusbdescriptors () function, which will be implemented in the following program, let's take a look at the function body of this function. Obviously, it is configuring various configurations for the device, so we will not talk about it much.

Next, allocate the memory, set the flag, and read the information from the registry. Note: The registry information read here is the value under the Registry Key combined by drivers // USB // clientdrivers // mass_storage_class and binterfacesubclass. For details, refer to the source program, what is placed under this registry key is
[HKEY_LOCAL_MACHINE/Drivers/USB/clientdrivers/mass_storage_class/6]
"DLL" = "usbdisk6.dll"
"Prefix" = "DSK"
"Folder" = "USB disk"
"IOCTL" = DWORD: 4
"Iclass" = "{A4E7EDDA-E575-4252-9D6B-4195D48BB865 }"
From this we can see that, through the registry here, the driver can know which form and DLL the device will provide interfaces to the operating system. At the same time, we have prepared for subsequent operations.

The most important part is in the next loaddriver () clause. Load the DLL file of another driver, which is the usbdisk6.dll file in the above registry. Add one to the counter, obtain the address of the usbdiskattach function and the usbdiskdetach function in the file, register the Event Notification processing function, and then call the usbdiskattach function in the DLL file.

It can be seen that the USB device driver has two layers of functions, one is to identify and configure the specified device, and the other is to call a higher-level driver as required to provide interfaces to the operating system. After usbdisk6.dll is called, the operating system processes the program in the file as a disk or as a folder, you can control the read and write operations. We can also take a look at this function of the HID device. It also allows the operating system to recognize the USB device as a mouse device.

As mentioned above, there is also a callback function for notification messages, which we have found in the program body just now:
Usbfuncs-> lpregisternotificationroutine (hdevice, usbdeviceno133, pusbdevice );
The statement has been set for this function. Let's look down at the function body of this function. This function is very simple. You only need to process the message of usb_close_device. Since you want to disable the USB device, it is necessary to call the detach function in usbdisk6.dll to release the driver on the upper layer, then, reduce the reference count by one. If no device references this driver, freelibrary () is the only one.

The rest of the functions can be carefully studied. I will not describe them in detail here. Next we need to understand how the Operating System reads and writes specific devices through an abstract disk?

 

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.