Scubapro G2: add zero report type to USBHID packet write

Jef reports that this is required for HIDAPI, and while I would really
like to just make the report type part of the custom packet_io interface
instead of making it visible here, this is the minimal fix for now.

See commit d251b373becc ("Add a zero report ID to the commands"), which
does the same thing, except for the fact that we now need to treat BLE
and USB HID differently.

I may still end up teaching the USB HID custom-IO layer to add the
report ID byte, and just specify it at dc_usbhid_custom_io() time
instead.  That would make the G2 code not have to care about the
transfer protocol again.

(But the other user of USB HID - the Suunto EON Steel - has much bigger
protocol differences between USB HID and BLE, so the whole "try to be
protocol-agnostic" hope may be just a pipe dream anyway, and it's just
the Scubapro G2 that _could_ work that way).

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
Linus Torvalds 2017-08-20 19:16:21 -07:00
parent aed80fe7fd
commit d7503b05e2

View File

@ -112,16 +112,25 @@ scubapro_g2_transfer(scubapro_g2_device_t *g2, const unsigned char command[], un
dc_status_t status = DC_STATUS_SUCCESS; dc_status_t status = DC_STATUS_SUCCESS;
size_t transferred = 0; size_t transferred = 0;
if (csize >= PACKET_SIZE) { if (csize > PACKET_SIZE-2) {
ERROR(g2->base.context, "command too big (%d)", csize); ERROR(g2->base.context, "command too big (%d)", csize);
return DC_STATUS_INVALIDARGS; return DC_STATUS_INVALIDARGS;
} }
HEXDUMP (g2->base.context, DC_LOGLEVEL_DEBUG, "cmd", command, csize); HEXDUMP (g2->base.context, DC_LOGLEVEL_DEBUG, "cmd", command, csize);
buf[0] = csize; buf[0] = 0; // USBHID report type
memcpy(buf+1, command, csize); buf[1] = csize; // command size
status = io->packet_write(io, buf, csize+1, &transferred); memcpy(buf+2, command, csize); // command bytes
// BLE GATT protocol?
if (io->packet_size < 64) {
// No report type byte
status = io->packet_write(io, buf+1, csize+1, &transferred);
} else {
status = io->packet_write(io, buf, csize+2, &transferred);
}
if (status != DC_STATUS_SUCCESS) { if (status != DC_STATUS_SUCCESS) {
ERROR(g2->base.context, "Failed to send the command."); ERROR(g2->base.context, "Failed to send the command.");
return status; return status;