Windows System Software -- Consulting, Training, Development -- Unique Expertise, Guaranteed Results

Before Posting...
Please check out the Community Guidelines in the Announcements and Administration Category.

More Info on Driver Writing and Debugging

The free OSR Learning Library has more than 50 articles on a wide variety of topics about writing and debugging device drivers and Minifilters. From introductory level to advanced. All the articles have been recently reviewed and updated, and are written using the clear and definitive style you've come to expect from OSR over the years.

Check out The OSR Learning Library at:

PNP driver type recommendation

AvalonAvalon Member Posts: 26
edited October 2019 in NTDEV

Hello. So we have a PCI device that supports PNP, so the user will insert/eject the device many times during the running session of the OS.

So I've been testing with root bus toaster, what's recommended for the driver associated with this HWID, to be a functional driver right, or one of the filter drivers in the samples? Due to 3rd party nature of the service which will need to be associated with the INF. Another part of the requirement, will be to completely stop/cleanup the service on device removal. Such that when the device is re-plugged in, the service can start as a fresh, so to do this, I assume the driver also needs to be fully unloaded as well right, for the INF to start the service again on device insertion?

I might be doing something silly, but using the MS driver toaster sample "featured2" functional driver, I never see the IRP_MN_SURPRISE_REMOVAL or the IRP_MN_REMOVE_DEVICE, is it supposed to? Once I use the enum.exe -u commands, the output looks like below. The setup is loading the "dynambus" as the rootbus, then using "featured2" as the device that will be associated with the real HWID.

// enum.exe -p 1234 ...
IRP_MN_??? Unknown
*** IopQueryLegacyBusInformation - Driver TestBusDrv returned STATUS_SUCCESS
[!] BusEnum: PDO IRP_MN_START_DEVICE IRP: 0xFFFF9382CB978530
//enum.exe -u 1234
[!] BusEnum: Create 
[!] BusEnum: UnPlug called
[!] BusEnum: Plugging out 1234
// No PNP IRP from the functional driver for removal, but the bus driver sees the event


  • Tim_RobertsTim_Roberts Member - All Emails Posts: 13,403

    Does your device have its own subdevices that come and go, or does your device plug and unplug from PCIe? PCIe hotplug not only requires support from the device, but support from the BIOS, and very, very few PCIExpress BIOSes support PCIe hotplug.

    Tim Roberts, [email protected]
    Providenza & Boekelheide, Inc.

  • AvalonAvalon Member Posts: 26
    edited October 2019

    @Tim_Roberts said:
    Does your device have its own subdevices that come and go, or does your device plug and unplug from PCIe? PCIe hotplug not only requires support from the device, but support from the BIOS, and very, very few PCIExpress BIOSes support PCIe hotplug.

    No the actual device doesn't have subdevices (though the MS toaster sample come under there own class tree). It plugs/unplugs as you mentioned. And yes we do have support from BIOS. At the moment, the devices appears in device manager under system devices and we have control to influence the hwid/class etc if need be.

    So to receive the IRP_MN_SURPRISE_REMOVAL, using the MS toaster. I've tried both the KMDF (modern driver samples) and WDM (DDK 7) toasters, and neither are showing the removal when using the provided enum.exe -e nnn.
    "\Program Files (x86)\Windows Kits\10\tools\x64\devcon.exe" install busenum.inf root\busenum"
    pnputil /add-driver featured2.inf /install
    enum.exe -p 123
    enum.exe -u 123
    //no surprise removal irp received in featured2 functional driver, should I try using the filter drivers instead?

  • AvalonAvalon Member Posts: 26

    Okay I resolved the missing PNP IRP, from looking at random code online. Uhhh MS driver samples are missing the key IoSkipCurrentIrpStackLocation and IoCallDriver(nextDriver), in the IRP_MN_START_DEVICE, so I presume not correctly completing in that doesn't then register you to receive the IRP removal related events.

    So back the original question then.

    I now have a driver that can capture the removal. And the INF that is associated with it, contains a service along with the driver. So when the real device is unplugged, the service needs to be restarted (do I need to fully unload the driver as well, or will just the AddDevice() be called again (but not DriverEntry), based on the image below). Such that the INF when loaded again, it starts both the service and driver. Or will it handle only loading one, if the other is present?

  • Peter_Viscarola_(OSR)Peter_Viscarola_(OSR) Administrator Posts: 7,807

    Advice for today: Don’t use WDM. I’ve written a metric shit-ton of WDM drivers, and PnP code... and I wouldn’t write your driver using WDM. Why would you?

    I suggest you put the restart logic in the service itself. It can register for device interface change notification and restart itself... or whatever.


    Peter Viscarola

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Upcoming OSR Seminars
OSR has suspended in-person seminars due to the Covid-19 outbreak. But, don't miss your training! Attend via the internet instead!
Kernel Debugging 30 Mar 2020 OSR Seminar Space
Developing Minifilters 15 Jun 2020 LIVE ONLINE
Writing WDF Drivers 22 June 2020 LIVE ONLINE
Internals & Software Drivers 28 Sept 2020 Dulles, VA