Hello Philip,
the USBD_STATUS says 0x00000000.
@Tim Roberts
I tried to summarize some (hopefully) relevant fragments from my code (some components are copied from Bruno van Dooren’s tutorial on WDF_USB driver):
//EvtDeviceD0Entry callback
status = WdfIoTargetStart(WdfUsbTargetPipeGetIoTarget(
devCtx->UsbBulkInPipe));
if(!NT_SUCCESS(status))
{
KdPrint((__DRIVER_NAME
“WdfIoTargetStart failed with status 0x%08x\n”, status));
return status;
}
// configurating a serialdispatch-IO-queue with a callback to receive read requests
WDF_IO_QUEUE_CONFIG_INIT(&ioQConfig,
WdfIoQueueDispatchSequential);
ioQConfig.EvtIoRead = EvtDeviceIoRead;
status = WdfIoQueueCreate(Device,
&ioQConfig,
WDF_NO_OBJECT_ATTRIBUTES,
&Context->IoReadQueue);
if(!NT_SUCCESS(status))
{
KdPrint((__DRIVER_NAME
“WdfIoQueueCreate failed with status 0x%08x\n”, status));
return status;
}
// finding the pipes to storage its type inside a DeviceContext struct:
pipe = WdfUsbInterfaceGetConfiguredPipe(DeviceContext->UsbInterface,
index,
&pipeConfig);
if(WdfUsbPipeTypeInterrupt == pipeConfig.PipeType)
{
DeviceContext->UsbInterruptPipe = pipe;
KdPrint((__DRIVER_NAME “WdfUsbPipeTypeInterrupt found.\n”));
}
else if(WdfUsbPipeTypeBulk == pipeConfig.PipeType)
{
KdPrint((__DRIVER_NAME “WdfUsbPipeTypeBulk found.\n”));
if(TRUE == WdfUsbTargetPipeIsInEndpoint(pipe))
{
DeviceContext->UsbBulkInPipe = pipe;
KdPrint((__DRIVER_NAME “WdfUsbPipeTypeBulk-> In Endpoint found.\n”));
// EvtDeviceIoRead callback
VOID
EvtDeviceIoRead(
IN WDFQUEUE Queue,
IN WDFREQUEST Request,
IN size_t Length
)
{
NTSTATUS status = STATUS_SUCCESS;
PDEVICE_CONTEXT devCtx = NULL;
WDFMEMORY requestMem;
BYTE *inChar;
size_t length_in = 0;
WDF_MEMORY_DESCRIPTOR memDescriptor;
WDF_USB_CONTROL_SETUP_PACKET controlPacket;
devCtx = GetDeviceContext(WdfIoQueueGetDevice(Queue));
KdPrint((__DRIVER_NAME “Received a read request of %d bytes\n”, Length));
KdPrint((__DRIVER_NAME “Generate ControlTransfer to trigger bulkIn\n”));
status = WdfMemoryCreatePreallocated(WDF_NO_OBJECT_ATTRIBUTES,
&devCtx->USERcommand,
sizeof(devCtx->USERcommand),
&devCtx->WdfUserCommandMemory);
if(!NT_SUCCESS(status))
{
KdPrint((__DRIVER_NAME
“WdfMemoryCreatePreallocated failed with status 0x%08x\n”, status));
}
inChar = WdfMemoryGetBuffer(devCtx->WdfUserCommandMemory, &length_in);
//set ControlByte
*inChar = 0x00;
WDF_MEMORY_DESCRIPTOR_INIT_HANDLE(&memDescriptor,devCtx->WdfUserCommandMemory, NULL);
//set ControlPaket
KdPrint((__DRIVER_NAME “Generate ControlPaket \n”));//
controlPacket.Generic.Bytes[0] = 0x00;
controlPacket.Generic.Bytes[1] = 0x42;
controlPacket.Generic.Bytes[2] = 0x00;
controlPacket.Generic.Bytes[3] = 0x00;
controlPacket.Generic.Bytes[4] = 0x00;
controlPacket.Generic.Bytes[5] = 0x00;
controlPacket.Generic.Bytes[6] = 0x01;
controlPacket.Generic.Bytes[7] = 0x00;
status = WdfRequestRetrieveOutputMemory(Request, &requestMem);
if(!NT_SUCCESS(status))
{
KdPrint((__DRIVER_NAME
“WdfRequestRetrieveOutputMemory failed with status 0x%08x\n”, status));
WdfRequestComplete(Request, status);
return;
}
status = WdfUsbTargetPipeFormatRequestForRead(
devCtx->UsbBulkInPipe,
Request,
requestMem,
NULL);
if(!NT_SUCCESS(status))
{
KdPrint((__DRIVER_NAME
“WdfUsbTargetPipeFormatRequestForRead failed with status 0x%08x\n”, status));
WdfRequestComplete(Request, status);
return;
} else KdPrint((__DRIVER_NAME “WdfUsbTargetPipeFormatRequestForRead succeeded\n”));
WdfRequestSetCompletionRoutine(Request,
EvtIoReadComplete,
devCtx->UsbBulkInPipe);
if(FALSE == WdfRequestSend(Request,
WdfUsbTargetPipeGetIoTarget(devCtx->UsbBulkInPipe),
NULL))
{
KdPrint((__DRIVER_NAME “WdfRequestSend failed with status 0x%08x\n”, status));
status = WdfRequestGetStatus(Request);
}
else {
KdPrint((__DRIVER_NAME “WdfRequestSend succeeded \n”));
KdPrint((__DRIVER_NAME “Send control code\n”));
status = WdfUsbTargetDeviceSendControlTransferSynchronously(
devCtx->UsbDevice,
NULL,
NULL,
&controlPacket,
&memDescriptor,
NULL);
if(!NT_SUCCESS(status))
{
KdPrint((__DRIVER_NAME
“WdfUsbTargetDeviceSendControlTransferSynchronouslyfailed with status 0x%08x\n”,
status));
}
return;
}
WdfRequestComplete(Request, status);
}
//completion routine
VOID
EvtIoReadComplete(
IN WDFREQUEST Request,
IN WDFIOTARGET Target,
IN PWDF_REQUEST_COMPLETION_PARAMS Params,
IN WDFCONTEXT Context)
{
UNREFERENCED_PARAMETER(Context);
UNREFERENCED_PARAMETER(Target);
PWDF_USB_REQUEST_COMPLETION_PARAMS usbCompletionParams;
KdPrint((__DRIVER_NAME “Entering Completion routine\n”));
usbCompletionParams = Params->Parameters.Usb.Completion;
KdPrint((__DRIVER_NAME “USBD_STATUS: 0x%08x\n”,
usbCompletionParams->UsbdStatus));
if(NT_SUCCESS(Params->IoStatus.Status))
{
KdPrint((__DRIVER_NAME “Completed the read request with %d bytes\n”,
usbCompletionParams->Parameters.PipeRead.Length));
}
else
{
KdPrint((__DRIVER_NAME “Failed the read request with status 0x%08x\n”,
Params->IoStatus.Status));
}
WdfRequestCompleteWithInformation(Request,
Params->IoStatus.Status,
usbCompletionParams->Parameters.PipeRead.Length);
}
I hope someone can find the problem.
Best Regards,
Matthias