i am trying to write hid driver for my usb joystick. i am use hidusbfx as example. Everything works except completing hid read report request.
for example i use simple hid descriptor
CONST UCHAR G_DefaultReportDescriptor = {
// Consumer control collection
0x05,0x01, // USAGE_PAGE (GENERAL DESKTOP)
0x09,0x04, // USAGE (Joystick)
0xa1, 0x01, // COLLECTION (Application)
0xa1, 0x00, // COLLECTION (Physical)
0x05, 0x09, // USAGE_PAGE (Button)
0x19, 0x01, // USAGE_MINIMUM (Button 1)
0x29, 0x08, // USAGE_MAXIMUM (Button 8)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x25, 0x01, // LOGICAL_MAXIMUM (1)
0x95, 0x08, // REPORT_COUNT (8)
0x75, 0x01, // REPORT_SIZE (1)
0x81, 0x02, // INPUT (Data,Var,Abs)
0xc0, // END_COLLECTION
0xc0
};
when i receive IOCTL_HID_READ_REPORT i forward request to manual queue
case IOCTL_HID_READ_REPORT:
{
TraceEvents(TRACE_LEVEL_ERROR, TRACE_QUEUE, “read report”);
status = WdfRequestForwardToIoQueue(Request, context->interruptMsgQueue);
if (!NT_SUCCESS(status)) {
TraceEvents(TRACE_LEVEL_ERROR, TRACE_DRIVER,
“WdfRequestForwardToIoQueue failed with status: 0x%x\n”, status);
WdfRequestComplete(Request, status);
}
return;
}
and later, when i get data from interrupt pipe i complete request
VOID
InterruptPipeReadComplete(
WDFUSBPIPE Pipe,
WDFMEMORY Buffer,
size_t NumBytesTransferred,
WDFCONTEXT Context
)
{
TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_DRIVER, “%!FUNC! entry”);
UNREFERENCED_PARAMETER(Pipe);
UNREFERENCED_PARAMETER(Context);
PUCHAR buf = WdfMemoryGetBuffer(Buffer, NULL);
TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_DRIVER, “data: %x %x %x %x %x %x %x”, buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], (unsigned)NumBytesTransferred);
WDFREQUEST request;
NTSTATUS status;
PDEVICE_CONTEXT context = Context;
status = WdfIoQueueRetrieveNextRequest(
context->interruptMsgQueue,
&request);
if (NT_SUCCESS(status)) {
TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_DRIVER, “complete”);
PUCHAR reqbuf;
size_t bytesReturned;
status = WdfRequestRetrieveOutputBuffer(request,
1,
&reqbuf,
&bytesReturned);// BufferLength
*reqbuf = buf[4];
TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_DRIVER, “returned : %x”,(unsigned)bytesReturned);
WdfRequestCompleteWithInformation(request, status, bytesReturned);
}
TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_DRIVER, “%!FUNC! exit”);
}
and when WdfRequestCompleteWithInformation is called windows stop responding
i was trying different descriptors and reports, but it doesn’t help
full code in github repo:
https://github.com/TheHoudini/KMDFDriver/tree/master/Jdriver
pls help, i have no idea how to fix it =(
p.s. sry for my english