WDF: Notifying client from driver

Working with OSRBUFX2 sample driver, I decided to add event which is set when switch state is changed, allowing to user-mode client to wait for this event. I added member PKEVENT SwitchInterruptEvent;
to DEVICE_CONTEXT structure. I added new IOCTL_OSRUSBFX2_REGISTER_EVENT code. Client program calls CreateEvent and passes event handle to the driver using DeviceIOControl with IOCTL_OSRUSBFX2_REGISTER_EVENT. Driver in OsrFxEvtIoDeviceControl function converts HANDLE to PKEVENT using ObReferenceObjectByHandle function. Finally, OsrFxEvtUsbInterruptPipeReadComplete sets this event using KeSetEvent.
All this stuff basically works. However, there are some problems. I don’t know exactly where to release SwitchInterruptEvent. Another problem is that this works only for one client. If there are two clients, only one gets event notification. Is there better and 100% correct way to make notification from driver?


Relax. Yahoo! Mail virus scanning helps detect nasty viruses!

> All this stuff basically works. However, there are some problems. I don’t
know

exactly where to release SwitchInterruptEvent. Another problem is that this
works
only for one client. If there are two clients, only one gets event
notification. Is
there better and 100% correct way to make notification from driver?

Yes. Pending IRPs which are completed when the event occurs.

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

Thank you, currently I am trying to implement this. I think about following changes:
Add member WDFREQUEST SwitchChangedRequest; to DEVICE_CONTEXT structure.
In function OsrFxEvtIoDeviceControl I don’t call WdfRequestCompleteWithInformation,
instead of this I keep this request in DEVICE_CONTEXT:
case IOCTL_OSRUSBFX2_GET_SWITCH_CHANGE:
pDevContext->SwitchChangedRequest = Request;
return;
In OsrFxEvtUsbInterruptPipeReadComplete function (interrupt callback) I complete
this request:
if ( pDeviceContext->SwitchChangedRequest != NULL )
{
WdfRequestCompleteWithInformation(
pDeviceContext->SwitchChangedRequest,
STATUS_SUCCESS,
0);
pDeviceContext->SwitchChangedRequest = NULL;
}

Is this right or I must do something else?
Thank you.


Yahoo! Mail
Use Photomail to share photos without annoying attachments.

This still does not help with multiple clients. Instead, create a manual WDFQUEUE and put all switch changed requests in the queue. When an interrupt occurs, drain the manual queue and complete all the drained requests.

d


From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Alex Farber
Sent: Tuesday, February 21, 2006 2:43 AM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] WDF: Notifying client from driver

Thank you, currently I am trying to implement this. I think about following changes:
Add member WDFREQUEST SwitchChangedRequest; to DEVICE_CONTEXT structure.
In function OsrFxEvtIoDeviceControl I don’t call WdfRequestCompleteWithInformation,
instead of this I keep this request in DEVICE_CONTEXT:
case IOCTL_OSRUSBFX2_GET_SWITCH_CHANGE:
??? pDevContext->SwitchChangedRequest = Request;
??? return;
In OsrFxEvtUsbInterruptPipeReadComplete function (interrupt callback) I complete
this request:
if ( pDeviceContext->SwitchChangedRequest != NULL )
{
??? WdfRequestCompleteWithInformation(
??? pDeviceContext->SwitchChangedRequest,
??? STATUS_SUCCESS,
??? 0);
??? pDeviceContext->SwitchChangedRequest = NULL;
}
?
Is this right or I must do something else?
??? Thank you.

?


Yahoo! Mail
Use Photomail to share photos without annoying attachments. — Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256 You are currently subscribed to ntdev as: xxxxx@microsoft.com To unsubscribe send a blank email to xxxxx@lists.osr.com

Thank you. Actually, this approach doesn’t work even for single client. If I don’t complete request, client hangs. From Walter Oney’s book I see that if request is not completed immediately, it is marked as pending using IoMarkIrpPending function. How can I do this for WDFREQUEST in KMDF ?

Doron Holan wrote: This still does not help with multiple clients. Instead, create a manual WDFQUEUE and put all switch changed requests in the queue. When an interrupt occurs, drain the manual queue and complete all the drained requests.

d


From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Alex Farber
Sent: Tuesday, February 21, 2006 2:43 AM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] WDF: Notifying client from driver

Thank you, currently I am trying to implement this. I think about following changes:
Add member WDFREQUEST SwitchChangedRequest; to DEVICE_CONTEXT structure.
In function OsrFxEvtIoDeviceControl I don’t call WdfRequestCompleteWithInformation,
instead of this I keep this request in DEVICE_CONTEXT:
case IOCTL_OSRUSBFX2_GET_SWITCH_CHANGE:
pDevContext->SwitchChangedRequest = Request;
return;
In OsrFxEvtUsbInterruptPipeReadComplete function (interrupt callback) I complete
this request:
if ( pDeviceContext->SwitchChangedRequest != NULL )
{
WdfRequestCompleteWithInformation(
pDeviceContext->SwitchChangedRequest,
STATUS_SUCCESS,
0);
pDeviceContext->SwitchChangedRequest = NULL;
}

Is this right or I must do something else?
Thank you.


Yahoo! Mail
Use Photomail to share photos without annoying attachments. — Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256 You are currently subscribed to ntdev as: xxxxx@microsoft.com To unsubscribe send a blank email to xxxxx@lists.osr.com


Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com

---------------------------------
Yahoo! Mail
Use Photomail to share photos without annoying attachments.

By the time the PIRP becomes a WDFREQUEST and is presented to you in a WDFQUEUEU callback, it has already been marked pending. Is your app opening up the handle as OVERLAPPED? If not, that is the only way you can do asynchronous I/O.

d

– I can spell, I just can’t type.


From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Alex Farber
Sent: Tuesday, February 21, 2006 10:20 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] WDF: Notifying client from driver

Thank you. Actually, this approach doesn’t work even for single client. If I don’t complete request, client hangs. From Walter Oney’s book I see that if request is not completed immediately, it is marked as pending using IoMarkIrpPending function. How can I do this for WDFREQUEST in KMDF ?

Doron Holan wrote:
This still does not help with multiple clients. Instead, create a manual WDFQUEUE and put all switch changed requests in the queue. When an interrupt occurs, drain the manual queue and complete all the drained requests.

d


From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Alex Farber
Sent: Tuesday, February 21, 2006 2:43 AM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] WDF: Notifying client from driver

Thank you, currently I am trying to implement this. I think about following changes:
Add member WDFREQUEST SwitchChangedRequest; to DEVICE_CONTEXT structure.
In function OsrFxEvtIoDeviceControl I don’t call WdfRequestCompleteWithInformation,
instead of this I keep this request in DEVICE_CONTEXT:
case IOCTL_OSRUSBFX2_GET_SWITCH_CHANGE:
??? pDevContext->SwitchChangedRequest = Request;
??? return;
In OsrFxEvtUsbInterruptPipeReadComplete function (interrupt callback) I complete
this request:
if ( pDeviceContext->SwitchChangedRequest != NULL )
{
??? WdfRequestCompleteWithInformation(
??? pDeviceContext->SwitchChangedRequest,
??? STATUS_SUCCESS,
??? 0);
??? pDeviceContext->SwitchChangedRequest = NULL;
}
?
Is this right or I must do something else?
??? Thank you.

?

Yahoo! Mail
Use Photomail to share photos without annoying attachments. — Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256 You are currently subscribed to ntdev as: xxxxx@microsoft.com To unsubscribe send a blank email to xxxxx@lists.osr.com


Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com

________________________________________
Yahoo! Mail
Use Photomail to share photos without annoying attachments. — Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256 You are currently subscribed to ntdev as: xxxxx@microsoft.com To unsubscribe send a blank email to xxxxx@lists.osr.com

Yes, I am working with overlapped I/O in the client application. I will try to play with this and provide additional information.
Thank you.

Doron Holan wrote:
By the time the PIRP becomes a WDFREQUEST and is presented to you in a WDFQUEUEU callback, it has already been marked pending. Is your app opening up the handle as OVERLAPPED? If not, that is the only way you can do asynchronous I/O.

d

– I can spell, I just can’t type.

From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Alex Farber
Sent: Tuesday, February 21, 2006 10:20 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] WDF: Notifying client from driver

Thank you. Actually, this approach doesn’t work even for single client. If I don’t complete request, client hangs. From Walter Oney’s book I see that if request is not completed immediately, it is marked as pending using IoMarkIrpPending function. How can I do this for WDFREQUEST in KMDF ?

Doron Holan wrote:
This still does not help with multiple clients. Instead, create a manual WDFQUEUE and put all switch changed requests in the queue. When an interrupt occurs, drain the manual queue and complete all the drained requests.

d


From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Alex Farber
Sent: Tuesday, February 21, 2006 2:43 AM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] WDF: Notifying client from driver

Thank you, currently I am trying to implement this. I think about following changes:
Add member WDFREQUEST SwitchChangedRequest; to DEVICE_CONTEXT structure.
In function OsrFxEvtIoDeviceControl I don’t call WdfRequestCompleteWithInformation,
instead of this I keep this request in DEVICE_CONTEXT:
case IOCTL_OSRUSBFX2_GET_SWITCH_CHANGE:
pDevContext->SwitchChangedRequest = Request;
return;
In OsrFxEvtUsbInterruptPipeReadComplete function (interrupt callback) I complete
this request:
if ( pDeviceContext->SwitchChangedRequest != NULL )
{
WdfRequestCompleteWithInformation(
pDeviceContext->SwitchChangedRequest,
STATUS_SUCCESS,
0);
pDeviceContext->SwitchChangedRequest = NULL;
}

Is this right or I must do something else?
Thank you.


Yahoo! Mail
Use Photomail to share photos without annoying attachments. — Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256 You are currently subscribed to ntdev as: xxxxx@microsoft.com To unsubscribe send a blank email to xxxxx@lists.osr.com


Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com


Yahoo! Mail
Use Photomail to share photos without annoying attachments. — Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256 You are currently subscribed to ntdev as: xxxxx@microsoft.com To unsubscribe send a blank email to xxxxx@lists.osr.com


Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com

---------------------------------
Relax. Yahoo! Mail virus scanning helps detect nasty viruses!