From d40cdb4755ee478530a09f297836f310d7423678 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Sun, 24 Apr 2016 19:14:52 +0200 Subject: [PATCH] Add the devinfo event. The devinfo event with the device serial number is required for the fingerprint feature. Without this event, applications won't be able to load (or save) the correct fingerprint. All necessary information is already available in the initial handshake packet. --- src/array.c | 14 ++++++++++++++ src/array.h | 3 +++ src/suunto_eonsteel.c | 11 ++++++++++- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/array.c b/src/array.c index 26a6c1b..13a73e5 100644 --- a/src/array.c +++ b/src/array.c @@ -146,6 +146,20 @@ array_convert_hex2bin (const unsigned char input[], unsigned int isize, unsigned return 0; } +unsigned int +array_convert_str2num (const unsigned char data[], unsigned int size) +{ + unsigned int value = 0; + for (unsigned int i = 0; i < size; ++i) { + if (data[i] < '0' || data[i] > '9') + break; + value *= 10; + value += data[i] - '0'; + } + + return value; +} + unsigned int array_uint_be (const unsigned char data[], unsigned int n) { diff --git a/src/array.h b/src/array.h index 49e8ab1..cd0a3a1 100644 --- a/src/array.h +++ b/src/array.h @@ -49,6 +49,9 @@ array_convert_bin2hex (const unsigned char input[], unsigned int isize, unsigned int array_convert_hex2bin (const unsigned char input[], unsigned int isize, unsigned char output[], unsigned int osize); +unsigned int +array_convert_str2num (const unsigned char data[], unsigned int size); + unsigned int array_uint_be (const unsigned char data[], unsigned int n); diff --git a/src/suunto_eonsteel.c b/src/suunto_eonsteel.c index 9debc6a..079c353 100644 --- a/src/suunto_eonsteel.c +++ b/src/suunto_eonsteel.c @@ -52,6 +52,7 @@ typedef struct suunto_eonsteel_device_t { libusb_device_handle *handle; unsigned int magic; unsigned short seq; + unsigned char version[0x30]; unsigned char fingerprint[4]; } suunto_eonsteel_device_t; @@ -544,7 +545,7 @@ static int initialize_eonsteel(suunto_eonsteel_device_t *eon) ERROR(eon->base.context, "Failed to send initialization command"); return -1; } - if (receive_header(eon, &hdr, buf, sizeof(buf)) < 0) { + if (receive_header(eon, &hdr, eon->version, sizeof(eon->version)) < 0) { ERROR(eon->base.context, "Failed to receive initial reply"); return -1; } @@ -572,6 +573,7 @@ suunto_eonsteel_device_open(dc_device_t **out, dc_context_t *context, const char // Set up the magic handshake fields eon->magic = INIT_MAGIC; eon->seq = INIT_SEQ; + memset (eon->version, 0, sizeof (eon->version)); memset (eon->fingerprint, 0, sizeof (eon->fingerprint)); if (libusb_init(&eon->ctx)) { @@ -652,6 +654,13 @@ suunto_eonsteel_device_foreach(dc_device_t *abstract, dc_dive_callback_t callbac if (get_file_list(eon, &de) < 0) return DC_STATUS_IO; + // Emit a device info event. + dc_event_devinfo_t devinfo; + devinfo.model = 0; + devinfo.firmware = array_uint32_be (eon->version + 0x20); + devinfo.serial = array_convert_str2num(eon->version + 0x10, 16); + device_event_emit (abstract, DC_EVENT_DEVINFO, &devinfo); + file = dc_buffer_new(0); progress.maximum = count_dir_entries(de); progress.current = 0;