Skip to content

Commit ec4d74a

Browse files
hid: set error data in send_feature_report
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.
1 parent 9cc5ac0 commit ec4d74a

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

libusb/hid.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1669,8 +1669,31 @@ int HID_API_EXPORT hid_send_feature_report(hid_device *dev, const unsigned char
16691669
(unsigned char *)data, length,
16701670
1000/*timeout millis*/);
16711671

1672-
if (res < 0)
1672+
if (res < 0) {
1673+
const char *context = NULL;
1674+
1675+
switch (res) {
1676+
case LIBUSB_ERROR_TIMEOUT:
1677+
context = "Transfer timed out";
1678+
break;
1679+
case LIBUSB_ERROR_PIPE:
1680+
context = "Control request not supported by device";
1681+
break;
1682+
case LIBUSB_ERROR_NO_DEVICE:
1683+
context = "Device has disconnected";
1684+
break;
1685+
case LIBUSB_ERROR_BUSY:
1686+
context = "Called from event handling context";
1687+
break;
1688+
case LIBUSB_ERROR_INVALID_PARAM:
1689+
context = "Transfer size larger than supported";
1690+
break;
1691+
}
1692+
1693+
set_error(dev, res, context);
1694+
16731695
return -1;
1696+
}
16741697

16751698
/* Account for the report ID */
16761699
if (skipped_report_id)

0 commit comments

Comments
 (0)