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

Sept/Oct 2019 Issue of The NT Insider available


Download PDF here: http://insider.osr.com/2019/ntinsider_2019_01.pdf

It’s a particularly BIG issue, too: 40 pages of technical goodness, ranging from WDF to Minifilters. Check it out.
Before Posting...
Please check out the Community Guidelines in the Announcements and Administration Category.

PNP driver type recommendation

AvalonAvalon Member Posts: 20
edited October 21 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
    for IRP_MN_QUERY_LEGACY_BUS_INFORMATION, and a NULL POINTER.
IRP_MN_QUERY_RESOURCE_REQUIREMENTS
IRP_MN_FILTER_RESOURCE_REQUIREMENTS
IRP_MN_START_DEVICE
[!] BusEnum: PDO IRP_MN_START_DEVICE IRP: 0xFFFF9382CB978530
IRP_MN_QUERY_CAPABILITIES
//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

Comments

  • Tim_RobertsTim_Roberts Member - All Emails Posts: 13,131

    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: 20
    edited October 22

    @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: 20

    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,467

    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

    Peter Viscarola
    OSR
    @OSRDrivers

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
Writing WDF Drivers 21 Oct 2019 OSR Seminar Space & ONLINE
Internals & Software Drivers 18 Nov 2019 Dulles, VA
Kernel Debugging 30 Mar 2020 OSR Seminar Space
Developing Minifilters 27 Apr 2020 OSR Seminar Space & ONLINE