The Wdm1DeviceControl dispatch routine handles the four IOCTLs defined for Wdm1 devices: Zero the buffer, Remove the Buffer, Get the buffer size, and Get the buffer. All these IOCTLs use Buffered I/O, so any input and output data is found at Irp->Associ-atedIrp.SystemBuffer. As usual, the routine acquires the shared buffer spin lock for the duration of the call. The actual implementation of each IOCTL is straightforward. The Get buffer size and Get buffer handlers check that the output buffer is large enough; if not, they return STATUS INVALID_PARAMETER. Defining IOCTLs An IOCTL code is a 32-bit value formed using the CTL_CODE macro shown in Table 7.4. The Wdm1 example defines its IOCTL codes in Ioctl.h, as shown in this example. Table 7.4 CTL_CODE macro parameters Ioctl.h is also included in the Wdm1Test project. It includes the standard winioctl.h header file first to get the definition of CTL_CODE.IOCTL
//define IOCTL_WDM1_ZERO_BUFFER CTL_CODE( \
FILE_DEVICE_UNKNOWN, \
0x801, \
METHOD_BUFFERED, \
FILE_ANY_ACCESS)
Parameter
Description
DeviceType
FILE_DEVICE_XXX value given to IoCreateDevice.
Control Code
IOCTL Function Code
0x000–0x7FF
Reserved for Microsoft 0x800-0xFFF
Private codes
TransferType
METHOD_BUFFERED
METHOD_IN_DIRECT
METHOD_OUT_DIRECT
METHOD_NEITHER
RequiredAccess
FILE_ANY_ACCESS
FILE READ_DATA
FILE_WRITE_DATA
FILE READ_DATA|FILE_WRITE_DATA