Fix compatibility issue with hidapi

The hidapi library requires that the first byte contains the report ID.
For devices which support only a single report, the report ID byte
should be zero. The remaining bytes contain the actual report data.

Now, when hidapi uses libusb internally, it strips the zero report ID
byte again before passing the data to libusb. Thus in order to remain
compatible with the hidapi based implementation, our libusb based
implementation should do the same.
This commit is contained in:
Jef Driesen 2017-07-11 00:15:39 +02:00
parent 854ad13f16
commit 05c858bf96

View File

@ -391,14 +391,32 @@ dc_usbhid_write (dc_usbhid_t *usbhid, const void *data, size_t size, size_t *act
goto out_invalidargs;
}
if (size == 0) {
goto out;
}
#if defined(HAVE_LIBUSB) && !defined(__APPLE__)
int rc = libusb_interrupt_transfer (usbhid->handle, usbhid->endpoint_out, (void *) data, size, &nbytes, 0);
const unsigned char *buffer = (const unsigned char *) data;
size_t length = size;
// Skip a report id of zero.
unsigned char report = buffer[0];
if (report == 0) {
buffer++;
length--;
}
int rc = libusb_interrupt_transfer (usbhid->handle, usbhid->endpoint_out, (void *) buffer, length, &nbytes, 0);
if (rc != LIBUSB_SUCCESS) {
ERROR (usbhid->context, "Usb write interrupt transfer failed (%s).",
libusb_error_name (rc));
status = syserror (rc);
goto out;
}
if (report == 0) {
nbytes++;
}
#elif defined(HAVE_HIDAPI)
nbytes = hid_write(usbhid->handle, data, size);
if (nbytes < 0) {