Publishing a Device Driver Interface (DDI) from a control driver

Hi All,

I am working on implementing a control driver tied with a user-space application. The control driver publishes a driver-defined interface (DDI) is using WdfDeviceAddQueryInterface(), which gets used by other KMDF driver to service the IOCTL requests received from the user-space app.

Sample code:

RtlZeroMemory(&sampleInterface, sizeof(sampleInterface));

sampleInterface.InterfaceHeader.Size = sizeof(sampleInterface);
sampleInterface.InterfaceHeader.Version = SAMPLE_INTERFACE_VERSION;
sampleInterface.InterfaceHeader.InterfaceReference = WdfDeviceInterfaceReferenceNoOp;
sampleInterface.InterfaceHeader.InterfaceDereference = WdfDeviceInterfaceDereferenceNoOp;
sampleInterface.SampleCallback = SampleCallback;

WDF_QUERY_INTERFACE_CONFIG_INIT(
    &wdfQueryInterfaceConfig,
    (PINTERFACE)&sampleInterface,
    &GUID_SAMPLE_INTERFACE_GUID,
    NULL);

status = WdfDeviceAddQueryInterface(
    device,
    &wdfQueryInterfaceConfig);

When the control-driver publishes the DDI using WdfDeviceAddQueryInterface() this is resulting in a Bug Check 0xA: IRQL_NOT_LESS_OR_EQUAL

nt!DbgBreakPoint
nt!KiBugCheckDebugBreak+0x1c 
nt!KeBugCheck2+0x870
nt!KeBugCheckEx+0x18
nt!KiAbortException+0x1863f0
nt!KiSynchronousException+0x70
nt!KzSynchronousException+0x24
nt!KiArm64ExceptionVectors+0x5c
nt!KiInitializeWaitBlock+0x24
nt!KeWaitForSingleObject+0x11c
Wdf01000.sys ->   Wdf01000.sys
Wdf01000!MxEvent::WaitFor+0x20
Wdf01000!FxWaitLockInternal::AcquireLock+0x60
Wdf01000!FxPkgPnp::AddQueryInterface+0x14
Wdf01000!imp_WdfDeviceAddQueryInterface+0x2a0
xxxxx!WdfDeviceAddQueryInterface+0x24
xxxxx!OnCreateDevice+0x57c
xxxxx!OnDeviceAdd+0x5c
xxxxx!DriverEntry+0x2a0
xxxxx!FxDriverEntryWorker+0xc4
xxxxx!FxDriverEntry+0x24
nt!PnpCallDriverEntry+0x44

kd> !irql
Debugger saved IRQL for processor 0x6 -- 2 (DISPATCH_LEVEL) [Dispatcher interrupt level]

I see similar implementations for publishing a DDI, from the MSDN and other KMDF drivers usage.

Have a couple of queries related to the above:

  • Can a control driver (or non-PnP) publish a DDI or are there any limitations around it?
  • If the above is true, anything additional needs to be taken care of before publishing a DDI from the control driver?

Thanks!

Can a control driver (or non-PnP) publish a DDI or are there any limitations around it?

No. The QueryInterface thing is a PnP concept. If you’re not PnP, you can’t use an interface. With KMDF, it’s pretty easy to make your driver a bus driver and create a raw PnP child device.

Or, you can use ExRegisterCallback.

Thanks, Tim.