Help Using the driver INTERFACE

Hi Everyone,

I have a WDF bus driver that is attached directly to a PCI hw device. The bus driver creates 4 different devices. Which I then attach various other drivers to.

The bus driver creates a custom INTERFACE type, and then registers that interface using WdfDeviceAddQueryInterface. That interface contains a couple of function pointer callbacks.

All of my child device drivers that I create are WDF drivers except for one. From the WDF drivers I can query the interface created by the bus driver without any issues. My problem child (pun intended) is an old serial driver that is written in WDM. We’re trying to convert it over to use our new bus driver.

From the WDM serial driver, I am unable to query the bus driver interface. From my reading it looks like I need to generate an IRP and pass that along to the bus driver, but when I do I always receive STATUS_NOT_SUPPORTED back from the IoCallDriver function.

I feel like i’m trying to talk to a device which doesn’t support my INTERFACE, and i’m likely using the wrong device object to build my IRP, but I can’t figure out how to retrieve the device object of my bus driver. I’ve tried the following functions to retrieve the device object with the same outcome (IoCallDriver returns STATUS_NOT_SUPPORTED)

  • IoGetAttachedDeviceReference
  • IoGetDeviceAttachmentBaseRef
  • IoGetLowerDeviceObject

Anyways, any suggestions or directions to go would be much appreciated!

IRP generation code is pasted below

NTSTATUS get_bus_interface(IN PDEVICE_OBJECT PDevObj)
{
PIRP irp = NULL;
KEVENT event;
NTSTATUS status = STATUS_SUCCESS;
PDEVICE_OBJECT pvmf_device = NULL;
IO_STATUS_BLOCK ioStatus = { 0 };
PIO_STACK_LOCATION irpStack = NULL;
PVMF_BUS_INTERFACE bus_interface;

pvmf_device = IoGetAttachedDeviceReference(PDevObj);

irp = IoBuildSynchronousFsdRequest(
IRP_MJ_PNP,
pvmf_device,
NULL,
0,
0,
&event,
&ioStatus);
if (irp == NULL)
{
goto cleanup;
}

irp->IoStatus.Status = STATUS_NOT_SUPPORTED;
irp->IoStatus.Information = 0;

irpStack = IoGetNextIrpStackLocation(irp);
irpStack->MinorFunction = IRP_MN_QUERY_INTERFACE;
irpStack->Parameters.QueryInterface.InterfaceType = (LPGUID)&GUID_SEL_PVMF_BUS_INTERFACE;
irpStack->Parameters.QueryInterface.Size = sizeof(PVMF_BUS_INTERFACE);
irpStack->Parameters.QueryInterface.Version = SEL_PVMF_BUS_INTERFACE_VERSION;
irpStack->Parameters.QueryInterface.Interface = (PINTERFACE)&bus_interface;
irpStack->Parameters.QueryInterface.InterfaceSpecificData = NULL;

status = IoCallDriver(pvmf_device, irp);

if (status == STATUS_PENDING)
{
KeWaitForSingleObject(&event, Executive, KernelMode, FALSE, NULL);
status = ioStatus.Status;
}

if (!NT_SUCCESS(status))
{
goto cleanup;
}

cleanup:
ObDereferenceObject(pvmf_device);

return status;
}

Thanks!
Ryan

This Wdm driver is a pnp driver, right? If so, you already have the device object you want to send the query interface to. It will be the device object returned by IoAttachDeviceToDeviceStack that you store in your device extension. You can confirm that this is the right device by breaking into the debugger and running

!devstack

And you should see your pdo listed at the bottom of the stack along with the instance id path.

d

Bent from my phone

________________________________
From: 30321470000n behalf of
Sent: Monday, August 13, 2018 4:43 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Help Using the driver INTERFACE

Hi Everyone,

I have a WDF bus driver that is attached directly to a PCI hw device. The bus driver creates 4 different devices. Which I then attach various other drivers to.

The bus driver creates a custom INTERFACE type, and then registers that interface using WdfDeviceAddQueryInterface. That interface contains a couple of function pointer callbacks.

All of my child device drivers that I create are WDF drivers except for one. From the WDF drivers I can query the interface created by the bus driver without any issues. My problem child (pun intended) is an old serial driver that is written in WDM. We’re trying to convert it over to use our new bus driver.

From the WDM serial driver, I am unable to query the bus driver interface. From my reading it looks like I need to generate an IRP and pass that along to the bus driver, but when I do I always receive STATUS_NOT_SUPPORTED back from the IoCallDriver function.

I feel like i’m trying to talk to a device which doesn’t support my INTERFACE, and i’m likely using the wrong device object to build my IRP, but I can’t figure out how to retrieve the device object of my bus driver. I’ve tried the following functions to retrieve the device object with the same outcome (IoCallDriver returns STATUS_NOT_SUPPORTED)

- IoGetAttachedDeviceReference
- IoGetDeviceAttachmentBaseRef
- IoGetLowerDeviceObject

Anyways, any suggestions or directions to go would be much appreciated!

IRP generation code is pasted below

NTSTATUS get_bus_interface(IN PDEVICE_OBJECT PDevObj)
{
PIRP irp = NULL;
KEVENT event;
NTSTATUS status = STATUS_SUCCESS;
PDEVICE_OBJECT pvmf_device = NULL;
IO_STATUS_BLOCK ioStatus = { 0 };
PIO_STACK_LOCATION irpStack = NULL;
PVMF_BUS_INTERFACE bus_interface;

pvmf_device = IoGetAttachedDeviceReference(PDevObj);

irp = IoBuildSynchronousFsdRequest(
IRP_MJ_PNP,
pvmf_device,
NULL,
0,
0,
&event,
&ioStatus);
if (irp == NULL)
{
goto cleanup;
}

irp->IoStatus.Status = STATUS_NOT_SUPPORTED;
irp->IoStatus.Information = 0;

irpStack = IoGetNextIrpStackLocation(irp);
irpStack->MinorFunction = IRP_MN_QUERY_INTERFACE;
irpStack->Parameters.QueryInterface.InterfaceType = (LPGUID)&GUID_SEL_PVMF_BUS_INTERFACE;
irpStack->Parameters.QueryInterface.Size = sizeof(PVMF_BUS_INTERFACE);
irpStack->Parameters.QueryInterface.Version = SEL_PVMF_BUS_INTERFACE_VERSION;
irpStack->Parameters.QueryInterface.Interface = (PINTERFACE)&bus_interface;
irpStack->Parameters.QueryInterface.InterfaceSpecificData = NULL;

status = IoCallDriver(pvmf_device, irp);

if (status == STATUS_PENDING)
{
KeWaitForSingleObject(&event, Executive, KernelMode, FALSE, NULL);
status = ioStatus.Status;
}

if (!NT_SUCCESS(status))
{
goto cleanup;
}

cleanup:
ObDereferenceObject(pvmf_device);

return status;
}

Thanks!
Ryan


NTDEV is sponsored by OSR

Visit the list online at: https:

MONTHLY seminars on crash dump analysis, WDF, Windows internals and software drivers!
Details at https:

To unsubscribe, visit the List Server section of OSR Online at https:</https:></https:></https:>

Thanks Doron,

The WDM driver is definitely a PnP driver. Using the output from the IoAttachDeviceToDeviceStack call makes complete sense. I have updated the function to use the attached device for my generate the IRP, but I am still receiving a STATUS_NOT_SUPPORTED from the IoCallDriver call.

I hooked the debugger up and ran !devstack as you suggested, I received the following output:

6: kd> !devstack 0xffff8000`eb8e8690
!DevObj !DrvObj !DevExt ObjectName
ffff8000ec080bd0 \Driver\Serenum ffff8000ec080d20
ffff8000eb993070 \Driver\SEL_Serial_Instffff8000eb9931c0 SELSerial0
> ffff8000eb8e8690 \Driver\PnpManager 00000000 00000052
!DevNode ffff8000eaf525b0 :
DeviceInst is “ROOT\PORTS\0000”
ServiceName is “SEL_Serial_Inst”

I was expecting to see the bus driver that I had written as the next device below my SEL_Serial_Inst driver, but instead I see the PnpManager device. It’s possible i’m misunderstanding how the driver stack works here.

I guess I see two paths ways of going forward here… If its weird that I’m not seeing my bus driver underneath the WDM serial driver on the stack then, I can chase the reasoning for that. Otherwise, if it’s normal to see the PnpManager there, then it’s seems likely that my interface is not set up correctly and I should pursue that.

How did you install the driver? Looks like devcon install. This will create a root enumerated device not connected to your bus. You need to use devcon update or use device manager and update driver on the bus enumerated child device.

Bent from my phone

Yep, that was it. Looks like the Visual Studio deployment system bit me there.

My bus driver now shows up in the stack when I use !devstack and I can retrieve the interface.

Thanks so much for your help!

I never use the VS deployment system. I prefer knowing what just happened.

Mark Roddy

On Tue, Aug 14, 2018 at 5:05 PM xxxxx@selinc.com <
xxxxx@lists.osr.com> wrote:

Yep, that was it. Looks like the Visual Studio deployment system bit me
there.

My bus driver now shows up in the stack when I use !devstack and I can
retrieve the interface.

Thanks so much for your help!


NTDEV is sponsored by OSR

Visit the list online at: <
http://www.osronline.com/showlists.cfm?list=ntdev\>

MONTHLY seminars on crash dump analysis, WDF, Windows internals and
software drivers!
Details at http:
>
> To unsubscribe, visit the List Server section of OSR Online at <
> http://www.osronline.com/page.cfm?name=ListServer&gt;
></http:>