From 241f6080cc72d3f4f19c0414338aa3c6943bcfbf Mon Sep 17 00:00:00 2001 From: cslashm Date: Thu, 7 Mar 2019 23:34:53 +0100 Subject: [PATCH] Add application version compatibility check. --- src/device/device_ledger.cpp | 12 +++++++++++- src/device/device_ledger.hpp | 12 ++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/device/device_ledger.cpp b/src/device/device_ledger.cpp index 8ead665a7..8f6cdd25f 100644 --- a/src/device/device_ledger.cpp +++ b/src/device/device_ledger.cpp @@ -303,7 +303,17 @@ namespace hw { offset += strlen(MONERO_VERSION); this->buffer_send[4] = offset-5; this->length_send = offset; - this->exchange(); + this->exchange(); + + ASSERT_X(this->length_recv>=3, "Communication error, less than three bytes received. Check your application version."); + + unsigned int device_version = 0; + device_version = VERSION(this->buffer_recv[0], this->buffer_recv[1], this->buffer_recv[2]); + + ASSERT_X (device_version >= MINIMAL_APP_VERSION, + "Unsupported device application version: " << VERSION_MAJOR(device_version)<<"."<>16)&0xFF) + #define VERSION_MINOR(v) (((v)>>8)&0xFF) + #define VERSION_MICRO(v) (((v)>>0)&0xFF) + + #define MINIMAL_APP_VERSION VERSION(MINIMAL_APP_VERSION_MAJOR, MINIMAL_APP_VERSION_MINOR, MINIMAL_APP_VERSION_MICRO) + void register_all(std::map> ®istry); #ifdef WITH_DEVICE_LEDGER