Re: usbhid: How to wait for response after submitting report

From: Adam Nielsen
Date: Tue Mar 30 2010 - 08:22:05 EST


>> Basically I have a USB HID device, and it works by submitting a HID report,
>> then waiting until it replies with (I assume) another HID report. The
>> messages are all proprietary. I can send the reports fine, but half the time
>> I get garbage coming back, which I assume is because I'm not getting the
>> message quickly enough and processing whatever was in the buffer instead.
>>
>> If you're able to point me in the direction of an example showing how to set
>> up and use a completion handler, hopefully I can change my code to work like
>> that instead.
>
> Well this is rather more USB-related question than HID related question,
> I'd say.

Well originally I was going to write a USB driver, but as it's a HID device
and there's a HID class in the kernel, I thought it would be better to use the
functions provided by the USB HID device class.

> Basically you prepare URB, along with specifying which routine should be
> called by USB core as completion handler, and then submit the URB.

Can I do this without conflicting with the HID "layer"? I assumed that
drivers appearing in the HID class should only use HID functions, and those
functions would take care of the USB side of things. I don't really want to
reimplement all the standard HID communication code when it has already been
implemented in the USB HID driver/class.

> USB HID implementation is working like this (and zillions of other USB
> drivers which are in kernel do as well) -- just look at initialization of
> control URB in usbhid_start(), and the completion handler (for control
> URBs) in hid_ctrl().

At the moment I am calling functions like hid_hw_start and
usbhid_submit_report, which (I think) take care of all this for me. There's
not a lot of documentation about how the HID class works, and only a handful
of drivers unfortunately, since it's a standard USB device class - you only
need to write a driver for nonstandard hardware, which means all the existing
HID drivers are all very different!

Because usbhid_submit_report takes the raw data to be packaged up inside a USB
HID message, I don't have an opportunity to set any sort of completion
handler. I imagine the HID class takes care of it, but I don't know how to
figure out whether the completion handler has been called and there's data to
read.

Thanks,
Adam.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/