From 901991afbe1e9c2cf5f3cb0cb7dfccaf84ebc7dc Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Wed, 25 Apr 2018 12:34:46 -0700 Subject: Do a better job of picking which transport to use If the user specified bluetooth, we really should pick bluetooth, not probe and possibly fall back to something else. We should also honor the users choice of BLE vs classic BT. Signed-off-by: Linus Torvalds --- core/libdivecomputer.c | 48 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 41 insertions(+), 7 deletions(-) (limited to 'core') diff --git a/core/libdivecomputer.c b/core/libdivecomputer.c index 990904878..577e8a7a3 100644 --- a/core/libdivecomputer.c +++ b/core/libdivecomputer.c @@ -1200,25 +1200,59 @@ void logfunc(dc_context_t *context, dc_loglevel_t loglevel, const char *file, un } } +/* + * Get the transports supported by us (as opposed to + * the list of transports supported by a particular + * dive computer). + * + * This could have various platform rules too.. + */ +static unsigned int get_supported_transports(device_data_t *data) +{ + unsigned int supported; + + /* + * We don't support BT or BLE unless bluetooth_mode was set, + * and if it was we won't try any of the other transports. + */ + supported = ~(DC_TRANSPORT_BLUETOOTH | DC_TRANSPORT_BLE); + if (data->bluetooth_mode) { + supported = ~supported; + if (!strncmp(data->devname, "LE:", 3)) + supported = DC_TRANSPORT_BLE; + } + + return supported; +} + + dc_status_t divecomputer_device_open(device_data_t *data) { dc_status_t rc; dc_descriptor_t *descriptor = data->descriptor; dc_context_t *context = data->context; - unsigned int transports; + unsigned int transports, supported; + transports = dc_descriptor_get_transports(descriptor); + supported = get_supported_transports(data); -#ifdef BLE_SUPPORT - if (data->bluetooth_mode && (transports & DC_TRANSPORT_BLE)) { - rc = ble_packet_open(&data->iostream, context, data->devname, data); + transports &= supported; + if (!transports) { + report_error("Dive computer transport not supported"); + return DC_STATUS_UNSUPPORTED; + } + +#ifdef BT_SUPPORT + if (transports & DC_TRANSPORT_BLUETOOTH) { + rc = rfcomm_stream_open(&data->iostream, context, data->devname); if (rc == DC_STATUS_SUCCESS) return rc; } #endif -#ifdef BT_SUPPORT - if (data->bluetooth_mode && (transports & DC_TRANSPORT_BLUETOOTH)) { - rc = rfcomm_stream_open(&data->iostream, context, data->devname); +#ifdef BLE_SUPPORT + if (transports & DC_TRANSPORT_BLE) { + rc = ble_packet_open(&data->iostream, context, data->devname, data); if (rc == DC_STATUS_SUCCESS) return rc; } -- cgit v1.2.3-70-g09d2