Windows driver development and windows driver development
In the previous article "Windows driver development-4", we have completed hardware preparation. However, we do not have specific data operations, such as receiving read/write operations.
Before performing such operations in WDF, you must perform device I/O control to ensure data integrity.
We know that WDF development follows the "Footsteps" of IRPs ".
I/O Request Delivery Mechanic |
I/O request type |
UMDF delivery Mechanic |
KMDF delivery Mechanic |
Read |
Queue |
Queue |
Write |
Queue |
Queue |
Device I/O control |
Queue |
Queue |
Internal device I/O control |
Queue |
Queue |
Create |
Queue |
Queue or callback |
Close |
Callback |
Callback |
Cleanup |
Callback |
Callback |
From the table, we can see that WDF uses the Queue mechanism during device I/O control.
Therefore, we need to provide queue support when adding devices.
WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&ioQueueConfig, WdfIoQueueDispatchParallel); ioQueueConfig.EvtIoDeviceControl = EvtIoDeviceControl; status = WdfIoQueueCreate(device, &ioQueueConfig, WDF_NO_OBJECT_ATTRIBUTES, WDF_NO_HANDLE);
(1) initialize queue Configuration
WDF_IO_QUEUE_CONFIG_INIT_DEFAULT_QUEUE
VOID WDF_IO_QUEUE_CONFIG_INIT_DEFAULT_QUEUE( _Out_ PWDF_IO_QUEUE_CONFIG Config, _In_ WDF_IO_QUEUE_DISPATCH_TYPE DispatchType);
(2) Set callback events
Set the member variable value in the WDF_IO_QUEUE_CONFIG structure.
typedef struct _WDF_IO_QUEUE_CONFIG { ULONG Size; WDF_IO_QUEUE_DISPATCH_TYPE DispatchType; WDF_TRI_STATE PowerManaged; BOOLEAN AllowZeroLengthRequests; BOOLEAN DefaultQueue; PFN_WDF_IO_QUEUE_IO_DEFAULT EvtIoDefault; PFN_WDF_IO_QUEUE_IO_READ EvtIoRead; PFN_WDF_IO_QUEUE_IO_WRITE EvtIoWrite; PFN_WDF_IO_QUEUE_IO_DEVICE_CONTROL EvtIoDeviceControl; PFN_WDF_IO_QUEUE_IO_INTERNAL_DEVICE_CONTROL EvtIoInternalDeviceControl; PFN_WDF_IO_QUEUE_IO_STOP EvtIoStop; PFN_WDF_IO_QUEUE_IO_RESUME EvtIoResume; PFN_WDF_IO_QUEUE_IO_CANCELED_ON_QUEUE EvtIoCanceledOnQueue; union { struct { ULONG NumberOfPresentedRequests; } Parallel; } Settings; WDFDRIVER Driver;} WDF_IO_QUEUE_CONFIG, *PWDF_IO_QUEUE_CONFIG;
(3) create a queue
WdfIoQueueCreate
NTSTATUS WdfIoQueueCreate( [in] WDFDEVICE Device, [in] PWDF_IO_QUEUE_CONFIG Config, [in, optional] PWDF_OBJECT_ATTRIBUTES QueueAttributes, [out, optional] WDFQUEUE *Queue);