Skip to content

Commit 011c394

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 35c5e53 commit 011c394

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
@@ -1666,8 +1666,31 @@ int HID_API_EXPORT hid_send_feature_report(hid_device *dev, const unsigned char
16661666
(unsigned char *)data, length,
16671667
1000/*timeout millis*/);
16681668

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

16721695
/* Account for the report ID */
16731696
if (skipped_report_id)

0 commit comments

Comments
 (0)