From 8c0ab03706d2f30f3f750502b6f17c9347c46075 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Thu, 15 Jun 2017 06:36:57 +0900 Subject: [PATCH] Scubapro G2: add back the initial handshake code When doing the G2 downloader, I dropped the initial handshake as I tried to keep the code minimal, and the handshake didn't seem to make any difference what-so-ever to me. And it probably doesn't matter for anybody else either. But the code isn't working for some people, and maybe it does actually matter. More importantly, Scubapro's own LogTRAK application does send those two initial commands, and it's probably a good idea to minimize the differences between the different downloaders anyway, so add the handshake sequence back in. Signed-off-by: Linus Torvalds --- src/uwatec_g2.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/src/uwatec_g2.c b/src/uwatec_g2.c index 864ec32..7fb8e0d 100644 --- a/src/uwatec_g2.c +++ b/src/uwatec_g2.c @@ -125,6 +125,43 @@ uwatec_g2_transfer (uwatec_g2_device_t *device, const unsigned char command[], u } +static dc_status_t +uwatec_g2_handshake (uwatec_g2_device_t *device) +{ + dc_device_t *abstract = (dc_device_t *) device; + + // Command template. + unsigned char answer[1] = {0}; + unsigned char command[5] = {0x00, 0x10, 0x27, 0, 0}; + + // Handshake (stage 1). + command[0] = 0x1B; + dc_status_t rc = uwatec_g2_transfer (device, command, 1, answer, 1); + if (rc != DC_STATUS_SUCCESS) + return rc; + + // Verify the answer. + if (answer[0] != 0x01) { + ERROR (abstract->context, "Unexpected answer byte(s)."); + return DC_STATUS_PROTOCOL; + } + + // Handshake (stage 2). + command[0] = 0x1C; + rc = uwatec_g2_transfer (device, command, 5, answer, 1); + if (rc != DC_STATUS_SUCCESS) + return rc; + + // Verify the answer. + if (answer[0] != 0x01) { + ERROR (abstract->context, "Unexpected answer byte(s)."); + return DC_STATUS_PROTOCOL; + } + + return DC_STATUS_SUCCESS; +} + + dc_status_t uwatec_g2_device_open (dc_device_t **out, dc_context_t *context) { @@ -154,10 +191,19 @@ uwatec_g2_device_open (dc_device_t **out, dc_context_t *context) goto error_free; } + // Perform the handshaking. + status = uwatec_g2_handshake (device); + if (status != DC_STATUS_SUCCESS) { + ERROR (context, "Failed to handshake with the device."); + goto error_close; + } + *out = (dc_device_t*) device; return DC_STATUS_SUCCESS; +error_close: + dc_usbhid_close (device->usbhid); error_free: dc_device_deallocate ((dc_device_t *) device); return status;