From 56a77f0fa3ed952f945b34f13b065124909654ea Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Thu, 6 Sep 2018 17:32:24 -0700 Subject: Garmin devices - like Shearwater - want random BLE addressing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We had a special-case for the Shearwater case, let's just make it slightly more generic and add Garmin to the list of vendors that want a random BLE address rather than a static one. The Bluez model of having to state this explicitly - but not giving the information to the user - is completely broken and this is all very annoying, credit goes to Wojciech Więckowski for pointing this out. Of course, right now we don't actually know how to parse the BLE stream from the Garmin Descent, but with this (and some libdivecomputer hackery) I actually get connected and start receiving data. That we then can't parse, but that's hopefully just a libdivecomputer update away. Pointed-out-by: Wojciech Więckowski Signed-off-by: Linus Torvalds Signed-off-by: Dirk Hohndel --- core/qt-ble.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/core/qt-ble.cpp b/core/qt-ble.cpp index 2d1de1408..b4678aa5c 100644 --- a/core/qt-ble.cpp +++ b/core/qt-ble.cpp @@ -25,6 +25,7 @@ static int debugCounter; #define IS_HW(_d) same_string((_d)->vendor, "Heinrichs Weikamp") #define IS_SHEARWATER(_d) same_string((_d)->vendor, "Shearwater") +#define IS_GARMIN(_d) same_string((_d)->vendor, "Garmin") #define MAXIMAL_HW_CREDIT 255 #define MINIMAL_HW_CREDIT 32 @@ -271,6 +272,14 @@ dc_status_t BLEObject::setupHwTerminalIo(QList allC) return setHwCredit(MAXIMAL_HW_CREDIT); } +// Bluez is broken, and doesn't have a sane way to query +// whether to use a random address or not. So we have to +// fake it. +static int use_random_address(dc_user_device_t *user_device) +{ + return IS_SHEARWATER(user_device) || IS_GARMIN(user_device); +} + dc_status_t qt_ble_open(void **io, dc_context_t *, const char *devaddr, dc_user_device_t *user_device) { debugCounter = 0; @@ -302,7 +311,7 @@ dc_status_t qt_ble_open(void **io, dc_context_t *, const char *devaddr, dc_user_ #endif qDebug() << "qt_ble_open(" << devaddr << ")"; - if (IS_SHEARWATER(user_device)) + if (use_random_address(user_device)) controller->setRemoteAddressType(QLowEnergyController::RandomAddress); // Try to connect to the device -- cgit v1.2.3-70-g09d2