Author Topic: HidD_GetInputReport question...  (Read 10384 times)

usbnewbie

  • Member
  • ***
  • Posts: 2
HidD_GetInputReport question...
« on: April 15, 2015, 01:44:55 pm »
I'm seeing some unexplained behavior with this system API. My device's descriptor defines the input report with ID == 3 to be 32 bytes long. It does not initiate input reports -- I always have to ask for them (perhaps that's a redundant statment?) I am only using HidD_GetInputReport -- I'm not calling ReadFile on this device at all.

Occasionally the device misbehaves and will send a shorter input report (which of course does not match the length declared in the descriptor). I can see this in Wireshark captures...the data packet length will be a smaller number. When this happens, HidD_GetInputReport() returns true but only part of the buffer is filled -- if I preload the buffer with some pattern, it shows that only the actual number of bytes that were in the USB transfer are in the buffer.

Does this behavior make sense? I read somewhere that HidD_GetInputReport() was only supposed to return reports that matched the size declared in the descriptor, but that's not what I think I see here. Am I doing something wrong here or is there some way to find out how many bytes were in the data packet?

One acceptable answer would be that Windows does not support this abberant behavior by the device and the device needs to be fixed...but either way, I'd at least like to understand what I'm seeing.

Thanks!

Barry Twycross

  • Frequent Contributor
  • ****
  • Posts: 263
Re: HidD_GetInputReport question...
« Reply #1 on: April 15, 2015, 05:07:27 pm »
Makes perfect sense to me, depending on the maxpacket size.

In general if you ask for a certain number of bytes, and the device sends less, and not a full packet, the read will end and the buffer will be partly filled. Just as you describe.

I don't know the specifics of HidD_GetInputReport, but if its supposed to behave as you suggest, that looks like a bug. But a bug which is quite understandable, and is due to not coping with a misbehaving device properly.

usbnewbie

  • Member
  • ***
  • Posts: 2
Re: HidD_GetInputReport question...
« Reply #2 on: April 17, 2015, 02:56:09 am »
Thanks.

Although I've not been able to find it in print, I assume that an HID device is not supposed to be sending input reports that don't match the size/count declared in the descriptor...?

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: HidD_GetInputReport question...
« Reply #3 on: April 17, 2015, 04:13:21 am »
Yes, all data must be in defined reports.