I am creating an interface using WdfDeviceCreateDeviceInterface() in my driver in the AddDevice() routine. The driver is not actual HW driver. Also i am setting the interface state explicitly using WdfDeviceSetDeviceInterfaceState(, , ,TRUE) after WdfDeviceCreateDeviceInterface() call. WDF_FILEOBJECT_CONFIG_INIT is properly configured before WdfDeviceCreateDeviceInterface call. Then another driver tries to open the interface using the same GUID but ZwCreateFile is failing.
But the same interface is visible after sometime and then i am able to open the interface. What is causing the failure in the first ZwCreateFile() ?
The interface is enabled after the device has completed the PNP start request request (WdfDevicePrepareHardware, WdfDeviceD0Entry, WdfDeviceSelfManagedIoInit, etc). You don’t have to explicitly manage the interface state, this is handled for you. The driver which wants to open a handle to this interface can register for a notification that the interface is enabled by calling IoRegisterPlugPlayNotification(EventCategoryDeviceInterfaceChange, PNPNOTIFY_DEVICE_INTERFACE_INCLUDE_EXISTING_INTERFACES**,** …)
Thanks for the input. My driver does not have any of these functions (WdfDevicePrepareHardware, WdfDeviceD0Entry, WdfDeviceSelfManagedIoInit) since it is not an actual HW driver. I understand registering for the interface arrival using IoRegisterPlugPlayNotification is better instead of assuming the interface already created and trying to open a handle.
But i have one doubt. Is there any delay OS imposes between WdfDeviceCreateDeviceInterface() call and publishing the interface for consumer?
You don’t need to register any of the callbacks I listed. I listed them so you understood the context of what a pnp start is in KMDF’s terms. As i said in my first reply, the OS will not enable the interface until after the pnp start has completed. This is the delay you are seeing. Why does it behave this way? If the OS allowed the interface to be enabled in AddDevice, or any time before the pnp start completes, the subsequent file object create would be sent to a device stack that has not yet been fully initialized. The completion of pnp start is the indication to the OS that the stack is in a fully initialized state and now prepared to accept incoming requests.
Any driver type, pnp or not, can enumerate device interfaces and be notified of new instances by calling IoRegisterPlugPlayNotification. You must only be a pnp driver to publish a new instance of a device interface
Thanks Doron. How could I force windows to publish my interface as soon as after it is created using wdfcreatedevinterfave? My need is like this CreateInterface then immediately make it available for other driver.. Is windows offering any api to do this?
You can’t force it. It will be enabled after the pnp start completes (which is very quickly after AddDevice returns and the stack is built). Why does it need to be immediately?
The other driver does initializes some important things based on the interface created by the first driver that initialization can’t be delayed. That is the reason I need the availability of the first driver created interface..