Anyball

Hi, I'm writing a KMDF driver for a USB device using the ¡°communication device¡± class. Between the driver and the device, I have the following USB pipes: "BULK_IN", "BULK_OUT", "INTERRUPT_IN", "INTERRUPT_OUT" and "IO_CONTROL". Logically I would like to have the same pipes between the application and the driver. So I have created 5 pipes in my application. I thought I could create one queue per pipe with WdfIoQueueCreate(), but this method only take a ¡°device¡± in parameter. So I defined only one default parallel queue for the whole device and the following callback functions "EvtIoControl", "EvtIoRead" and "EvtIoWrite". So when "Write" requests arrive for instance, from whatever pipes they have been sent thru by the application, they are all handled by the same ¡°EvtIoWrite¡± callback function. I can't therefore forward the request to the corresponding USB pipe: I can¡¯t know if I have to forward it to the ¡°BULK_OUT¡± or to the ¡°INTERRUPT OUT¡± pipe. I can see 3 solutions to solve that: 1. A method allows to link the application pipe with the USB pipes and WDF create the queues itself. 2. A method allows creating a queue for a pipe, in this case I create one queue per pipe myself. 3. I can retrieve the application pipe name in the request object so that I can forward it to the corresponding USB pipe. Unfortunately I can¡¯t find any of these methods. Please help. Thanks in advance. Hannibal



Re: Windows SDK WDF USB driver

sojins choi

Hi.

Have you seen WDF example source "osrfx2 final source" maybe solve your problems.

in function EvtDeviceAdd,

1. create your device with WdfDeviceCreate()

2. Default queue initialize and regist EvtIoDeviceControl

WDF_IO_QUEUE_CONFIG_INIT_DEFAULT_QUEUE(&ioQueueConfig, WdfIoQueueDispatchParallel);

ioQueueConfig.EvtIoDeviceControl = yourEvtIoDeviceControl;

status = WdfIoQueueCreate(device,
&ioQueueConfig,
WDF_NO_OBJECT_ATTRIBUTES,
&queue);// pointer to default queue

this is first and default event, so not necessary configure request dispatching

3. Reuse your ioQueueConfig struct for regist IRP_MJ_READ, IRP_MJ_WRITE,... and configure request dispatching

WDF_IO_QUEUE_CONFIG_INIT(&ioQueueConfig, WdfIoQueueDispatchSequential);

ioQueueConfig.EvtIoRead = YourEvtIoRead; //--> EvtIoWrite = YourEvtIoWrite;

ioQueueConfig.EvtIoStop = YourEvtIoStop;

status = WdfIoQueueCreate(
device,
&ioQueueConfig,
WDF_NO_OBJECT_ATTRIBUTES,
&queue // queue handle
);

...

status = WdfDeviceConfigureRequestDispatching(
device,
queue,
WdfRequestTypeRead); //-> WdfRequestTypeWrite

if(!NT_SUCCESS (status)){
ASSERT(NT_SUCCESS(status));
TraceEvents(TRACE_LEVEL_ERROR, DBG_PNP,
"WdfDeviceConfigureRequestDispatching failed 0x%x\n", status);
return status;
}

Good luck 2U




Re: Windows SDK WDF USB driver

Anyball

Dear Sojins Choi,

Thanks a lot for your reply and sorry for my late one. If I understood well, I¡¯m afraid your solution still doesn't allow redirecting the writings coming from 2 different APPLICATION pipes to 2 different USB pipes since both are handled by the same EvtIoWrite.

However I found the solution in the KMDF wdk (ver.6000), in the following sample: C:\WINDDK\6000\src\kmdf\usbsamp.

In this sample, they link the application pipe with the USB pipes when the pipe is open in the application (EvtDeviceFileCreate in the driver). To do that they use the pipe number defined in the pipe name and the index of the pipe seen for the selected interface: \\PIPE00 <-> 0, \\PIPE01 <-> 1, etc. The USB pipe index is stored in a FILE_CONTEXT structure.

The inconvenient is that the application has to know the device topology, it therefore doesn¡¯t suit for generic driver. Of course this is only when we need more than one pipe in the same direction in the same interface, it is not probably not a very frequent case.

Thanks again, regards

Hannibal