Stop/unload Pnp driver

Hi,
I have a pnp driver with a device control object created in DriverEntry function. The current issue is that I can’t unload/stop the driver manually even my driver is not attached to any device. I want this behavior to stop/ unload the driver from an user mode application, it is possible?

Thank you.

Do you delete the control device when the DriverUnload is invoked when your driver is being unloaded ?

Do you use KMDF or WDM ?

Hi Miles N.
I’m using WDM, the problem is that my DriverUnload is never called… maybe because it is pnp driver and I have reference to my control device object.

Thank you.

A pnp driver can’t create devices in driverentry. You need to create the control device in AddDevice and delete it in the context of the last pnp device being deleted when they pnp device processes pnp remove.

The app needs to call setup APIs to disable the pnp device, same code that you would see in the devcon disable implementation

d

Bent from my phone


From: xxxxx@yahoo.commailto:xxxxx
Sent: ?8/?21/?2014 6:31 AM
To: Windows System Software Devs Interest Listmailto:xxxxx
Subject: [ntdev] Stop/unload Pnp driver

Hi,
I have a pnp driver with a device control object created in DriverEntry function. The current issue is that I can’t unload/stop the driver manually even my driver is not attached to any device. I want this behavior to stop/ unload the driver from an user mode application, it is possible?

Thank you.


NTDEV is sponsored by OSR

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

OSR is HIRING!! See http://www.osr.com/careers

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer</mailto:xxxxx></mailto:xxxxx>

Hi Doron,
Thank you for reply. But what if I want to send IOCTL to my driver before any device has added, what is the approach in this case?

That window is very small since the only way your driver can load as a pnp driver is when the pnp device shows up. That means driverentry will be immediately followed by AddDevice, I doubt your app can even hit that window in between. And how will it know when the symlink is available?

d

Bent from my phone


From: xxxxx@yahoo.commailto:xxxxx
Sent: ?8/?21/?2014 7:03 AM
To: Windows System Software Devs Interest Listmailto:xxxxx
Subject: RE:[ntdev] Stop/unload Pnp driver

Hi Doron,
Thank you for reply. But what if I want to send IOCTL to my driver before any device has added, what is the approach in this case?


NTDEV is sponsored by OSR

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

OSR is HIRING!! See http://www.osr.com/careers

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer</mailto:xxxxx></mailto:xxxxx>

Hi again Doron,

But I don’t understand how a pnp driver can notify an user application for a device change? How you said the app doesn’t know when the symlink is available.

Thank you.

I’m thinking to use IoReportTargetDeviceChangeAsynchronous for device notifications. It’s a good solution?

Notifications for device arrival and departure are handled through device interfaces. If you want to notify about changes other than that after the device has been started, IoReportTargetDeviceChangeAsynchronous works

d

Bent from my phone


From: xxxxx@yahoo.commailto:xxxxx
Sent: ?8/?22/?2014 6:47 AM
To: Windows System Software Devs Interest Listmailto:xxxxx
Subject: RE:[ntdev] Stop/unload Pnp driver

I’m thinking to use IoReportTargetDeviceChangeAsynchronous for device notifications. It’s a good solution?


NTDEV is sponsored by OSR

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

OSR is HIRING!! See http://www.osr.com/careers

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer</mailto:xxxxx></mailto:xxxxx>

Thank you very much Doron.

Hi Doron,
I used IoReportTargetDeviceChangeAsynchronous in my driver but when I try to call RegisterDeviceNotification from user mode I got a BSOD. (SYSTEM_SERVICE_EXCEPTION)
My code from msdn sample:

DEV_BROADCAST_HANDLE NotificationFilter;
DWORD Err = 0;

ZeroMemory(&NotificationFilter, sizeof(DEV_BROADCAST_HANDLE));
NotificationFilter.dbch_size = sizeof(DEV_BROADCAST_HANDLE);
NotificationFilter.dbch_handle = m_DeviceDriver; //device driver handle obtained with //CreateFile…
NotificationFilter.dbch_eventguid = DeviceEventGuid; //device event guid also used in
//TARGET_DEVICE_CUSTOM_NOTIFICATION structure.

What I’m doing wrong or I’m missing. I also consulted KM-UMGuide document.

Thank you.

If I remember correctly, all you have to do is register for file handle notifications on the handle you opened. Subsequent custom notifications will just show up when created by the driver. A user mode API cannot cause the system to blue screen, the issue is in the driver.

d

Bent from my phone


From: xxxxx@yahoo.commailto:xxxxx
Sent: ?8/?24/?2014 5:02 AM
To: Windows System Software Devs Interest Listmailto:xxxxx
Subject: RE:[ntdev] Stop/unload Pnp driver

Hi Doron,
I used IoReportTargetDeviceChangeAsynchronous in my driver but when I try to call RegisterDeviceNotification from user mode I got a BSOD. (SYSTEM_SERVICE_EXCEPTION)
My code from msdn sample:

DEV_BROADCAST_HANDLE NotificationFilter;
DWORD Err = 0;

ZeroMemory(&NotificationFilter, sizeof(DEV_BROADCAST_HANDLE));
NotificationFilter.dbch_size = sizeof(DEV_BROADCAST_HANDLE);
NotificationFilter.dbch_handle = m_DeviceDriver; //device driver handle obtained with //CreateFile…
NotificationFilter.dbch_eventguid = DeviceEventGuid; //device event guid also used in
//TARGET_DEVICE_CUSTOM_NOTIFICATION structure.

What I’m doing wrong or I’m missing. I also consulted KM-UMGuide document.

Thank you.


NTDEV is sponsored by OSR

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

OSR is HIRING!! See http://www.osr.com/careers

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer</mailto:xxxxx></mailto:xxxxx>

You was right Doron, the BSOD was caused by my driver, I fixed it but I still have the problem receiving the custom event in user mode. IoReportTargetDeviceChangeAsynchronous return STATUS_PENDING(when processing following irps: IRP_MN_START_DEVICE and IRP_MN_REMOVE_DEVICE) but I think it’s ok since it’s an async call. In user mode WM_DEVICECHANGE message is called but not with my custom event, and what I noticed that this message is received even the IoReportTargetDeviceChangeAsynchronous routine was not called . I can’t figure out what is the problem, or if this method of communication really works.

Thank you.

You can’t useIoReportTargetDeviceChangeAsynchronous to report events for start or remove. Why? Because at both points in time your application can’t have an open handle to register for notifications on. For start, the app isn’t even notified that your device is present until after the start irp completes back to the kernel. For remove, all handles must be closed for the remove to be sent in the first place

d

Bent from my phone


From: xxxxx@yahoo.commailto:xxxxx
Sent: ?8/?25/?2014 5:34 AM
To: Windows System Software Devs Interest Listmailto:xxxxx
Subject: RE:[ntdev] Stop/unload Pnp driver

You was right Doron, the BSOD was caused by my driver, I fixed it but I still have the problem receiving the custom event in user mode. IoReportTargetDeviceChangeAsynchronous return STATUS_PENDING(when processing following irps: IRP_MN_START_DEVICE and IRP_MN_REMOVE_DEVICE) but I think it’s ok since it’s an async call. In user mode WM_DEVICECHANGE message is called but not with my custom event, and what I noticed that this message is received even the IoReportTargetDeviceChangeAsynchronous routine was not called . I can’t figure out what is the problem, or if this method of communication really works.

Thank you.


NTDEV is sponsored by OSR

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

OSR is HIRING!! See http://www.osr.com/careers

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer</mailto:xxxxx></mailto:xxxxx>

Thank you again for your clarification.
Thread closed.