aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Linus Torvalds <torvalds@linux-foundation.org>2018-04-25 12:34:46 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2018-04-27 11:52:13 -0700
commit901991afbe1e9c2cf5f3cb0cb7dfccaf84ebc7dc (patch)
treee6bd6b537364869efee70521657efafffe69ff9f
parentfd359f5a88c9cab94713908cc0b79780f22729c3 (diff)
downloadsubsurface-901991afbe1e9c2cf5f3cb0cb7dfccaf84ebc7dc.tar.gz
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 <torvalds@linux-foundation.org>
-rw-r--r--core/libdivecomputer.c48
1 files changed, 41 insertions, 7 deletions
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;
}