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

Home NTDEV

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: https://www.osr.com/osr-learning-library/


KMDF: how to get PnP notification on change state of interface created by other driver/device

PiotrGPiotrG Member Posts: 4
edited August 2023 in NTDEV

The problem:
There are two KMDF drivers: driverA and driverB. These drivers do not belong to the same driver stack.
The driverA creates device, this device creates interface (using WdfDeviceCreateDeviceInterface()), using specific GUID.
The driverB needs to be notified on each change of the state of this interface, even if it was created before driverB was loaded.
The driverB knows the interface GUID only.


How to do it in WDF/KMDF way?


I found a solution for WDM drivers in this article: Buddy Drivers - Methods for Driver to Driver Communication and it uses IoRegisterPlugPlayNotification() function call for registering notification handler:

status = IoRegisterPlugPlayNotification(
    EventCategoryDeviceInterfaceChange,
    PNPNOTIFY_DEVICE_INTERFACE_INCLUDE_EXISTING_INTERFACES,
    (LPGUID)&GUID_DRIVERA_INTERFACE,
    DeviceObject->DriverObject,
    PlugPlayCallback, DeviceObject,
    &devExt->NotificationEntry);



Is there any WDF equivalent for: IoRegisterPlugPlayNotification(EventCategoryDeviceInterfaceChange, ...) ?

Comments

  • Peter_Viscarola_(OSR)Peter_Viscarola_(OSR) Administrator Posts: 9,160

    Why not just use the WDM call (in your WDF driver)?

    Peter

    Peter Viscarola
    OSR
    @OSRDrivers

  • PiotrGPiotrG Member Posts: 4

    Good question :)
    Mainly because I see WDF as a tool that facilitates working on drivers, and I intuitively expect that everything will be easier :)
    But more seriously, the main difficulty associated with using the IoRegisterPlugPlayNotification() function is that the callback cannot directly open a device - it is necessary to use the WorkItem mechanism. This is not a big problem, but I was hoping that WDF provides an equivalent function without such a limitation.

  • Scott_Noone_(OSR)Scott_Noone_(OSR) Administrator Posts: 3,679

    @PiotrG said:
    Good question :)
    Mainly because I see WDF as a tool that facilitates working on drivers, and I intuitively expect that everything will be easier :)
    But more seriously, the main difficulty associated with using the IoRegisterPlugPlayNotification() function is that the callback cannot directly open a device - it is necessary to use the WorkItem mechanism.

    It's safe to open from within the callback routine as long as the target driver doesn't trigger synchronous PnP operations from within its IRP_MJ_CREATE/EvtDeviceFileCreate callback. There used to be a case where an inbox driver stack did this (HID maybe?) and the documentation turned that into a generic statement of "don't do it" (which we also perpetuated for a while)

    -scott
    OSR

  • PiotrGPiotrG Member Posts: 4
    edited September 2023

    @Scott_Noone_(OSR) - thank you for the info, it will be useful for me probably :)

  • Doron_HolanDoron_Holan Member - All Emails Posts: 10,829
    SWENUM was the driver that caused the doc warning as it enumerated virtual audio/media devices on create. I would have never designed that behavior into HIDClass :).
    d
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. Sign in or register to get started.

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 13-17 May 2024 Live, Online
Developing Minifilters 1-5 Apr 2024 Live, Online
Internals & Software Drivers 11-15 Mar 2024 Live, Online
Writing WDF Drivers 20-24 May 2024 Live, Online