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 1, 2024
1 parent 35c5e53 commit 011c394
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 @@ -1666,8 +1666,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) {
wchar_t *custom_string = NULL;

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

set_error(dev, res, custom_string);

return -1;
}

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

0 comments on commit 011c394

Please sign in to comment.