Skip to content

Commit

Permalink
libuuu: hidreport: fix write size for Windows
Browse files Browse the repository at this point in the history
Commit 96aae2eaaca9 ("libuuu: hidreport: fix write size") introduced an
regression for Windows hosts. The Windows HIDAPI is very strict when it
comes to packet lengths: The API always expect the length specified by
the device and rejects the transfer otherwise.

This commit is based on [1]. Also a note was added for future developers.

[1] boundarydevices/imx_usb_loader@561f037

Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
  • Loading branch information
Marco Felsch authored and nxpfrankli committed Oct 17, 2023
1 parent 7cac399 commit 3f512a6
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion libuuu/hidreport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,14 @@ int HIDReport::write(const void *p, size_t sz, uint8_t report_id)
m_out_buff[0] = report_id;

size_t s = sz - off;
if (s > m_size_out)

/*
* The Windows HIDAPI is ver strict. It always require to send
* buffers of the size reported by the HID Report Descriptor.
* Therefore we must to send m_size_out buffers for HID ID 2
* albeit it may not required for the last buffer.
*/
if (s > m_size_out || report_id == 2)
s = m_size_out;

memcpy(m_out_buff.data() + m_size_payload, buff + off, s);
Expand Down

0 comments on commit 3f512a6

Please sign in to comment.