usbhid: How to wait for response after submitting report
Hi all,
I'm working on a USB HID driver, but my driver seems to be receiving bad data.
I think it's because usbhid_submit_report is non-blocking and I'm not
correctly waiting for a response. I'm not sure though, because none of the existing usbhid drivers seem to work in this way.
Could someone please let me know if I'm going about this the right way?
odin_psu->report->field[0]->value[0] = msg; odin_psu->report->field[0]->value[1] = 0x01; usbhid_submit_report(odin_psu->hdev, odin_psu->report, USB_DIR_OUT); usbhid_wait_io(odin_psu->hdev); usbhid_submit_report(odin_psu->hdev, odin_psu->report_in, USB_DIR_IN); usbhid_wait_io(odin_psu->hdev);
Many thanks,
Adam.
(Please CC)
Quoted 7 lines · Adam Nielsen
I'm working on a USB HID driver, but my driver seems to be receiving bad data.
I think it's becauseusbhid_submit_reportis non-blocking and I'm not
correctly waiting for a response. I'm not sure though, because none of the existing usbhid drivers seem to work in this way.Could someone please let me know if I'm going about this the right way?
Quoted 8 lines
odin_psu->report->field[0]->value[0] = msg; odin_psu->report->field[0]->value[1] = 0x01; usbhid_submit_report(odin_psu->hdev, odin_psu->report, USB_DIR_OUT); usbhid_wait_io(odin_psu->hdev); usbhid_submit_report(odin_psu->hdev, odin_psu->report_in, USB_DIR_IN); usbhid_wait_io(odin_psu->hdev);
Hi Adam,
I am afraid you'll have to explain in more detail what exactly you are tying to achieve, and why the way the current HID code does it (i.e. URB gets submitted, completion handler is called when completed) doesn't work for you.
Thanks,
Signature · 2 lines
Jiri Kosina SUSE Labs, Novell Inc.
Quoted 11 lines
Quoted 6 lines
I'm working on a USB HID driver, but my driver seems to be receiving bad data.
I think it's becauseusbhid_submit_reportis non-blocking and I'm not
correctly waiting for a response. I'm not sure though, because none of the existing usbhid drivers seem to work in this way.Could someone please let me know if I'm going about this the right way?
I am afraid you'll have to explain in more detail what exactly you are tying to achieve, and why the way the current HID code does it (i.e. URB gets submitted, completion handler is called when completed) doesn't work for you.
Thanks Jiri, it's probably because I still don't know what I'm doing :-) Can you point me at any HID examples that show how to use a completion handler? I'm afraid after hours of staring at HID code I'm still none the wiser as to how this part of the system works.
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.
Many thanks,
Adam.
Quoted 11 lines · Adam Nielsen
Thanks Jiri, it's probably because I still don't know what I'm doing :-) Can you point me at any HID examples that show how to use a completion handler? I'm afraid after hours of staring at HID code I'm still none the wiser as to how this part of the system works.
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.
Quoted 3 lines
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.
Basically you prepare URB, along with specifying which routine should be called by USB core as completion handler, and then submit the URB.
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().
Signature · 2 lines
Jiri Kosina SUSE Labs, Novell Inc.
Quoted 6 lines
Quoted 6 lines
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.
Quoted 6 lines
Quoted 3 lines
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.
Quoted 2 lines
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.
Quoted 4 lines
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) inhid_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.