Blocking HID input report data from going back to the OS

Hello to all. I’ve started a thread with this same topic before, but a new problem arose from the offered solution in that thread. Here’s the link to the thread by the way: http://www.osronline.com/showthread.cfm?link=264351

To summarize, I’m trying to look for a way so that an HID input report does not go back to the OS; instead, I want my filter to be the last driver that the report bubbles back up to before it goes back down again. Doron Holan’s suggestion was to call ForwardRequestCompletionRoutine again from the CompletionRoutine, and that works well, except for when my filter driver is being unloaded, since it causes an infinite loop. Here’s the relevant code snippet right now:

VOID
ReadForwardRequestWithCompletionRoutine(
IN WDFREQUEST Request,
IN WDFIOTARGET Target
)

{

//
// The following funciton essentially copies the content of
// current stack location of the underlying IRP to the next one.
//
WdfRequestFormatRequestUsingCurrentType(Request);

// MJP: register ReadRequestCompletionRoutine as the read request
// completion routine
WdfRequestSetCompletionRoutine(Request,
ReadRequestCompletionRoutine,
WDF_NO_CONTEXT);

ret = WdfRequestSend(Request,
Target,
WDF_NO_SEND_OPTIONS);

if (ret == FALSE) {
status = WdfRequestGetStatus(Request);
KdPrint((“EcoPenTouchDriver: WdfRequestSend failed: 0x%x\n”, status));
WdfRequestComplete(Request, status);
}

return;
}

VOID
ReadRequestCompletionRoutine(
IN WDFREQUEST Request,
IN WDFIOTARGET Target,
PWDF_REQUEST_COMPLETION_PARAMS CompletionParams,
IN WDFCONTEXT Context
)
{
… after printing X, Y coordinates and other data …

// MJP: don’t complete OS’ request in order to not cancel touch when pen is close to screen
// MJP: send request back down insead (per Doron Holan’s advice)
// MJP: comment this out to NOT complete report back to OS
ReadForwardRequestWithCompletionRoutine(Request, WdfDeviceGetIoTarget(device));

ExitAndFree:

// MJP: uncomment this to complete report back to OS
//WdfRequestComplete(Request, CompletionParams->IoStatus.Status);

return;
}

Any ideas on how to fix this code to avoid the infinite loop upon driver unload?

Thanks!

Obviously you can’t send the request down the stack when you are unloading. The target will be destroyed when the device stack is torn down, you need to complete the request when that happens and stop resending it down the stack. When the target is destroyed it will cancel the request, you should look at the request status before reformatting and resending to see what happened

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@gmail.com
Sent: Monday, March 30, 2015 11:25 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] Blocking HID input report data from going back to the OS

Hello to all. I’ve started a thread with this same topic before, but a new problem arose from the offered solution in that thread. Here’s the link to the thread by the way: http://www.osronline.com/showthread.cfm?link=264351

To summarize, I’m trying to look for a way so that an HID input report does not go back to the OS; instead, I want my filter to be the last driver that the report bubbles back up to before it goes back down again. Doron Holan’s suggestion was to call ForwardRequestCompletionRoutine again from the CompletionRoutine, and that works well, except for when my filter driver is being unloaded, since it causes an infinite loop. Here’s the relevant code snippet right now:

VOID
ReadForwardRequestWithCompletionRoutine(
IN WDFREQUEST Request,
IN WDFIOTARGET Target
)

{

//
// The following funciton essentially copies the content of
// current stack location of the underlying IRP to the next one.
//
WdfRequestFormatRequestUsingCurrentType(Request);

// MJP: register ReadRequestCompletionRoutine as the read request
// completion routine
WdfRequestSetCompletionRoutine(Request,
ReadRequestCompletionRoutine,
WDF_NO_CONTEXT);

ret = WdfRequestSend(Request,
Target,
WDF_NO_SEND_OPTIONS);

if (ret == FALSE) {
status = WdfRequestGetStatus(Request);
KdPrint((“EcoPenTouchDriver: WdfRequestSend failed: 0x%x\n”, status));
WdfRequestComplete(Request, status);
}

return;
}

VOID
ReadRequestCompletionRoutine(
IN WDFREQUEST Request,
IN WDFIOTARGET Target,
PWDF_REQUEST_COMPLETION_PARAMS CompletionParams,
IN WDFCONTEXT Context
)
{
… after printing X, Y coordinates and other data …

// MJP: don’t complete OS’ request in order to not cancel touch when pen is close to screen
// MJP: send request back down insead (per Doron Holan’s advice)
// MJP: comment this out to NOT complete report back to OS
ReadForwardRequestWithCompletionRoutine(Request, WdfDeviceGetIoTarget(device));

ExitAndFree:

// MJP: uncomment this to complete report back to OS
//WdfRequestComplete(Request, CompletionParams->IoStatus.Status);

return;
}

Any ideas on how to fix this code to avoid the infinite loop upon driver unload?

Thanks!


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

xxxxx@gmail.com wrote:

To summarize, I’m trying to look for a way so that an HID input report does not go back to the OS; instead, I want my filter to be the last driver that the report bubbles back up to before it goes back down again. Doron Holan’s suggestion was to call ForwardRequestCompletionRoutine again from the CompletionRoutine, and that works well, except for when my filter driver is being unloaded, since it causes an infinite loop.

Why does it cause an infinite loop?

I think you can imagine what the solution has to be. You need to have a
couple of flags here: one that says “we are shutting down” that causes
your completion routine to complete the request instead of forwarding
it, and another that tracks whether you have any outstanding requests.
Only when the last request completes can you allow yourself to be unloaded.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

Thank you all, could anyone help me find the API calls to do this? Doron mentioned checking the request status, does that mean inspecting WDFREQUEST before forwarding the requests?

Thank you very much!

You get the status of the completed request in the parameters to the completion routine

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@gmail.com
Sent: Thursday, April 2, 2015 10:51 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] Blocking HID input report data from going back to the OS

Thank you all, could anyone help me find the API calls to do this? Doron mentioned checking the request status, does that mean inspecting WDFREQUEST before forwarding the requests?

Thank you very much!


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

Thank you very much to you both! The problem is solved now.