Garmin devices - like Shearwater - want random BLE addressing

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 <xplwowi@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Linus Torvalds 2018-09-06 17:32:24 -07:00 committed by Dirk Hohndel
parent c03c2b5fd7
commit 56a77f0fa3

View file

@ -25,6 +25,7 @@ static int debugCounter;
#define IS_HW(_d) same_string((_d)->vendor, "Heinrichs Weikamp") #define IS_HW(_d) same_string((_d)->vendor, "Heinrichs Weikamp")
#define IS_SHEARWATER(_d) same_string((_d)->vendor, "Shearwater") #define IS_SHEARWATER(_d) same_string((_d)->vendor, "Shearwater")
#define IS_GARMIN(_d) same_string((_d)->vendor, "Garmin")
#define MAXIMAL_HW_CREDIT 255 #define MAXIMAL_HW_CREDIT 255
#define MINIMAL_HW_CREDIT 32 #define MINIMAL_HW_CREDIT 32
@ -271,6 +272,14 @@ dc_status_t BLEObject::setupHwTerminalIo(QList<QLowEnergyCharacteristic> allC)
return setHwCredit(MAXIMAL_HW_CREDIT); 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) dc_status_t qt_ble_open(void **io, dc_context_t *, const char *devaddr, dc_user_device_t *user_device)
{ {
debugCounter = 0; debugCounter = 0;
@ -302,7 +311,7 @@ dc_status_t qt_ble_open(void **io, dc_context_t *, const char *devaddr, dc_user_
#endif #endif
qDebug() << "qt_ble_open(" << devaddr << ")"; qDebug() << "qt_ble_open(" << devaddr << ")";
if (IS_SHEARWATER(user_device)) if (use_random_address(user_device))
controller->setRemoteAddressType(QLowEnergyController::RandomAddress); controller->setRemoteAddressType(QLowEnergyController::RandomAddress);
// Try to connect to the device // Try to connect to the device