summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlex Blasche <alexander.blasche@qt.io>2017-06-20 16:49:03 +0200
committerAlex Blasche <alexander.blasche@qt.io>2017-06-21 06:27:38 +0000
commit3222f7b7a6115891515e6340aec62b2d045d1bba (patch)
tree9c80db8c5fc5dd3c518a986a821b8271edc9f96a /src
parent240be1579d3c9ab8c7eeec9402b5a7ed0fae7abd (diff)
Improve detection of lowenergy devices
Bluez DBus API does not expose a flag indicating whether a given device is BTLE or not. For BTLE only cases the device class is still a fairly good indicator. However more and more devices are hybrids. This patch takes a closer look at the advertised service uuids and matches them against the known 0x1800 BTLE service uuids. Change-Id: Iaad747ff8a7b17be5ee17e51e2f4e329604a708c Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp32
1 files changed, 24 insertions, 8 deletions
diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp
index 5288eaf8..cda1bd17 100644
--- a/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp
+++ b/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp
@@ -400,18 +400,34 @@ void QBluetoothDeviceDiscoveryAgentPrivate::deviceFoundBluez5(const QString& dev
// read information
QBluetoothDeviceInfo deviceInfo(btAddress, btName, btClass);
-
- if (!btClass)
- deviceInfo.setCoreConfigurations(QBluetoothDeviceInfo::LowEnergyCoreConfiguration);
- else
- deviceInfo.setCoreConfigurations(QBluetoothDeviceInfo::BaseRateCoreConfiguration);
-
deviceInfo.setRssi(device.rSSI());
+
QList<QBluetoothUuid> uuids;
- foreach (const QString &u, device.uUIDs())
- uuids.append(QBluetoothUuid(u));
+ bool foundLikelyLowEnergyUuid = false;
+ for (const auto &u: device.uUIDs()) {
+ const QBluetoothUuid id(u);
+ if (id.isNull())
+ continue;
+
+ if (!foundLikelyLowEnergyUuid) {
+ //once we found one BTLE service we are done
+ bool ok = false;
+ quint16 shortId = id.toUInt16(&ok);
+ if (ok && ((shortId & QBluetoothUuid::GenericAccess) == QBluetoothUuid::GenericAccess))
+ foundLikelyLowEnergyUuid = true;
+ }
+ uuids.append(id);
+ }
deviceInfo.setServiceUuids(uuids, QBluetoothDeviceInfo::DataIncomplete);
+ if (!btClass) {
+ deviceInfo.setCoreConfigurations(QBluetoothDeviceInfo::LowEnergyCoreConfiguration);
+ } else {
+ deviceInfo.setCoreConfigurations(QBluetoothDeviceInfo::BaseRateCoreConfiguration);
+ if (foundLikelyLowEnergyUuid)
+ deviceInfo.setCoreConfigurations(QBluetoothDeviceInfo::BaseRateAndLowEnergyCoreConfiguration);
+ }
+
for (int i = 0; i < discoveredDevices.size(); i++) {
if (discoveredDevices[i].address() == deviceInfo.address()) {
if (discoveredDevices[i] == deviceInfo) {