two. Development of USB interface driver
1. Hierarchy of equipment and drivers
The WDM model uses the hierarchy as shown. On the right side of the figure is a device object stack. The device object is a data structure created by the system to help software management hardware. A physical hardware can have multiple such data structures.
The Function Device Object (FDO) and Physical Device Objects (PDOs) are introduced in WDM to describe hardware. A PDO corresponds to a real hardware, one hardware only allows a PDO, but there can be multiple FDOs. Directly in the driver is not a hardware device, but the corresponding PDO and FDO. PDO and FDO are in the lowest level of the stack. There are also some filter device objects (Filter Device Object) on the FDO. The filter device object on the FDO is called the upper filter, which is located below the FDO (but still on the PDO), called the lower filter. In terms of user-state and kernel communication, the system is packaged for each user request to form an IRP structure, which transmits it to the driver, and distinguishes it to which device is sent to the IRP.
2. Basic steps to write drivers
(1) First write a DriveREntry routine. In this routine, you must have a series of callback routines to process IRP. DriveREntry is the name commonly used by the kernel mode driver master entry point. The main job of this routine is to fill various function pointers into the driver object. These pointers indicate the location of each subroutine in the driver container for the operating system.
(2) Write an AddDevice routine, which the basic function is to create a device object and connect it to the bottom of the stack for the PDO device stack. The relevant steps are as follows: Call IOCREATEDEVICE to create a device object, and create a private device extension object; host one or more device interfaces so that the application can know the existence of the device, and give the device name and create a symbolic connection; initialization Device extension and device objects of the device object; call the iOattachDeventEvicEVicesTack function to put the new device object on the stack.
(3) Compile the connection driver.
(4) Test the driver.