2. Development of USB interface drivers
1. Hierarchy of devices and drivers
The WDM model uses a layered structure. The right side of the figure is a device object stack. A device object is a data structure created by the system to help software manage hardware. A physical hardware can have multiple such data structures.
Fdo and PdO are introduced in WDM to describe hardware. A pdo corresponds to a real hardware. A hardware can have only one PDO, but can have multiple fdo. In the driver, the corresponding PDO and fdo are not the hardware devices. Both PDO and fdo are at the lowest layer of the stack. There are some filter device objects in the above and below of fdo ). The filter device object on the fdo is called the upper-layer filter, and the filter device object on the fdo (but still on the PDO) is called the lower-layer filter. In terms of user-state and kernel-State communication, the system packs an IRP structure for each user request and sends it to the driver, identify the PDO in the IRP to identify the device to which the message is sent.
2. Basic Steps for writing a driver
(1) first write a DriverEntry routine. In this routine, you must set a series of callback routines to process IRP. DriverEntry is a common name for the main entry point of the kernel-mode driver. The main task of this routine is to fill in various function pointers with driver objects. These pointers indicate the locations of various subroutines in the driver container for the operating system.
(2) write an adddevice routine. Its basic function is to create a device object and connect it to the device stack whose bottom is PDO. The related steps are as follows: Call iocreatedevice to create a device object and create a private device extension object. Store one or more device interfaces so that the application can know the existence of the device. In addition, you can also give a device name and create a symbolic connection. initialize the flag Member of the device extension and the device object. Call ioattachdevicetodevicestack to put the new device object on the stack.
(3) Compile the connection driver.
(4) Test the driver.