Skip to content

Commit

Permalink
hid: set error data in send_feature_report
Browse files Browse the repository at this point in the history
Set error data when send_feature_report fails, including custom messages
for the situations especially outlined in the libusb documentation for
the libusb_control_transfer function.
  • Loading branch information
matheusmoreira committed Sep 7, 2024
1 parent 9cc5ac0 commit ec4d74a
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion libusb/hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -1669,8 +1669,31 @@ int HID_API_EXPORT hid_send_feature_report(hid_device *dev, const unsigned char
(unsigned char *)data, length,
1000/*timeout millis*/);

if (res < 0)
if (res < 0) {
const char *context = NULL;

switch (res) {
case LIBUSB_ERROR_TIMEOUT:
context = "Transfer timed out";
break;
case LIBUSB_ERROR_PIPE:
context = "Control request not supported by device";
break;
case LIBUSB_ERROR_NO_DEVICE:
context = "Device has disconnected";
break;
case LIBUSB_ERROR_BUSY:
context = "Called from event handling context";
break;
case LIBUSB_ERROR_INVALID_PARAM:
context = "Transfer size larger than supported";
break;
}

set_error(dev, res, context);

return -1;
}

/* Account for the report ID */
if (skipped_report_id)
Expand Down

0 comments on commit ec4d74a

Please sign in to comment.