About cancelling the read request

Hi All,

I’m working on a function driver for one of our HID device. The device has one button.
Without the driver, pressing the button can launch default browser like IE. The function driver now can interrupt the button report by turning on/off from an IOCTL. It works fine if I turn off the button report. I press the button several times after that. However, after turning on the button report again, there’re multiple IE browsers show up. The driver actually stores those read request into a manual queue and complete them with status code STATUS_CANCELLED after turning on the report. Is it possible to make only one browser window shows up instead of multiple ones? The following is the code to interrupt the Read reports and complete them with STATUS_CANCELLED.

if (lEnableHid == FALSE)
{
if (WdfRequestGetRequestorMode(Request) == UserMode)
{
WdfRequestForwardToIoQueue(Request, pDeviceContext->hReadQueue);
bComplete = FALSE;
}
}
else
{
while (WdfIoQueueRetrieveNextRequest(pDeviceContext->hReadQueue, &hRequest) == STATUS_SUCCESS)
{
WdfRequestCompleteWithInformation(hRequest, STATUS_CANCELLED, 0);
}
}

Return a real failure code , not canceled. If you want one to go through successfully, complete one with success

Sent from Outlook Mailhttp: for Windows 10

From: xxxxx@hotmail.com
Sent: Tuesday, July 7, 2015 7:11 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] About cancelling the read request

Hi All,

I’m working on a function driver for one of our HID device. The device has one button.
Without the driver, pressing the button can launch default browser like IE. The function driver now can interrupt the button report by turning on/off from an IOCTL. It works fine if I turn off the button report. I press the button several times after that. However, after turning on the button report again, there’re multiple IE browsers show up. The driver actually stores those read request into a manual queue and complete them with status code STATUS_CANCELLED after turning on the report. Is it possible to make only one browser window shows up instead of multiple ones? The following is the code to interrupt the Read reports and complete them with STATUS_CANCELLED.

if (lEnableHid == FALSE)
{
if (WdfRequestGetRequestorMode(Request) == UserMode)
{
WdfRequestForwardToIoQueue(Request, pDeviceContext->hReadQueue);
bComplete = FALSE;
}
}
else
{
while (WdfIoQueueRetrieveNextRequest(pDeviceContext->hReadQueue, &hRequest) == STATUS_SUCCESS)
{
WdfRequestCompleteWithInformation(hRequest, STATUS_CANCELLED, 0);
}
}


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</http:>

Hi Doron,

I tried the error code STATUS_UNSUCCESSFUL but not work. Should I try other real error code than STATUS_CANCELLED and STATUS_UNSUCCESSFUL.

BR,
Marshall

How specifically didn?t it work?

Sent from Outlook Mailhttp: for Windows 10

From: xxxxx@hotmail.com
Sent: Wednesday, July 8, 2015 12:26 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] About cancelling the read request

Hi Doron,

I tried the error code STATUS_UNSUCCESSFUL but not work. Should I try other real error code than STATUS_CANCELLED and STATUS_UNSUCCESSFUL.

BR,
Marshall


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</http:>

Hi Doron,

The following is the code that causes the problem. When I turn off the HID report, the read request is cached into a manual queue. Turning it on again, the EvtIoRead completes the cached Read request with STATUS_UNSUCCESSFUL. During turning off and on, I pressed the button several times. After turning on the HID, multiple browser window show up. The number of the window is as same as the times that I pressed the button. Any idea to fix this issue? Or any problems are existing in the code?

VOID
Bthxbus_EvtIoRead(
IN WDFQUEUE Queue,
IN WDFREQUEST Request,
IN size_t Length
)
{
WDFDEVICE hDevice = NULL;
WDFIOTARGET hIoTarget = NULL;
WDFREQUEST hRequest = NULL;
PBTHXBUS_DEVICE_CONTEXT pDeviceContext = NULL;
LONG lEnableHid = FALSE;
BOOLEAN bForward = TRUE;

UNREFERENCED_PARAMETER(Length);

BthxTraceFuncEntry();

hDevice = WdfIoQueueGetDevice(Queue);
hIoTarget = WdfDeviceGetIoTarget(hDevice);

pDeviceContext = Bthxbus_GetDeviceContext(hDevice);

InterlockedExchange(&lEnableHid, pDeviceContext->lEnableHid);

if (lEnableHid == FALSE)
{
if (WdfRequestGetRequestorMode(Request) == UserMode)
{
WdfRequestForwardToIoQueue(Request, pDeviceContext->hReadQueue);
bForward = FALSE;
}
}
else
{
while (WdfIoQueueRetrieveNextRequest(pDeviceContext->hReadQueue, &hRequest) == STATUS_SUCCESS)
{
WdfRequestComplete(hRequest, STATUS_UNSUCCESSFUL);
}
}

if (bForward == TRUE)
{
WdfRequestFormatRequestUsingCurrentType(Request);
WdfRequestSetCompletionRoutine(Request, Bthxbus_EvtIoReadComplete, hDevice);
if (WdfRequestSend(Request, hIoTarget, NULL) == FALSE)
{
WdfRequestSetCompletionRoutine(Request, NULL, NULL);
WdfRequestComplete(Request, WdfRequestGetStatus(Request));
}
}

BthxTraceFuncExit();
}

Why are you queueing them at all when you remove the button press? Just fail them at the time you receive them. Or complete them with the hid data saying the button is up/clear, don?t complete the report that says the button went down

Sent from Outlook Mailhttp: for Windows 10

From: xxxxx@hotmail.com
Sent: Wednesday, July 8, 2015 6:44 PM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] About cancelling the read request

Hi Doron,

The following is the code that causes the problem. When I turn off the HID report, the read request is cached into a manual queue. Turning it on again, the EvtIoRead completes the cached Read request with STATUS_UNSUCCESSFUL. During turning off and on, I pressed the button several times. After turning on the HID, multiple browser window show up. The number of the window is as same as the times that I pressed the button. Any idea to fix this issue? Or any problems are existing in the code?

VOID
Bthxbus_EvtIoRead(
IN WDFQUEUE Queue,
IN WDFREQUEST Request,
IN size_t Length
)
{
WDFDEVICE hDevice = NULL;
WDFIOTARGET hIoTarget = NULL;
WDFREQUEST hRequest = NULL;
PBTHXBUS_DEVICE_CONTEXT pDeviceContext = NULL;
LONG lEnableHid = FALSE;
BOOLEAN bForward = TRUE;

UNREFERENCED_PARAMETER(Length);

BthxTraceFuncEntry();

hDevice = WdfIoQueueGetDevice(Queue);
hIoTarget = WdfDeviceGetIoTarget(hDevice);

pDeviceContext = Bthxbus_GetDeviceContext(hDevice);

InterlockedExchange(&lEnableHid, pDeviceContext->lEnableHid);

if (lEnableHid == FALSE)
{
if (WdfRequestGetRequestorMode(Request) == UserMode)
{
WdfRequestForwardToIoQueue(Request, pDeviceContext->hReadQueue);
bForward = FALSE;
}
}
else
{
while (WdfIoQueueRetrieveNextRequest(pDeviceContext->hReadQueue, &hRequest) == STATUS_SUCCESS)
{
WdfRequestComplete(hRequest, STATUS_UNSUCCESSFUL);
}
}

if (bForward == TRUE)
{
WdfRequestFormatRequestUsingCurrentType(Request);
WdfRequestSetCompletionRoutine(Request, Bthxbus_EvtIoReadComplete, hDevice);
if (WdfRequestSend(Request, hIoTarget, NULL) == FALSE)
{
WdfRequestSetCompletionRoutine(Request, NULL, NULL);
WdfRequestComplete(Request, WdfRequestGetStatus(Request));
}
}

BthxTraceFuncExit();
}


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</http:>