summaryrefslogtreecommitdiffstats
path: root/src/bluetooth/qlowenergycontroller_bluez.cpp
diff options
context:
space:
mode:
authorAlex Blasche <alexander.blasche@qt.io>2017-05-19 16:44:06 +0200
committerAlex Blasche <alexander.blasche@qt.io>2017-06-16 07:52:29 +0000
commitcba4c454543ab83797b44946b132323687a198dc (patch)
tree8cb2ab0bfe0aa52702eb7516e70cc65e94ad1dab /src/bluetooth/qlowenergycontroller_bluez.cpp
parent1d1b133fa86c0874e8fe3bc9320dd2c3b02de9c3 (diff)
Obtain random bt address flag via Bluetooth Mgmt API
DBus does not expose this information. The Bluetooth Management API advertises the information but requires CAP_NET_ADMIN. The Management class monitors DEVICE FOUND events and records the random bit flag of each new device. QBluetoothDeviceDiscoveryAgent can subsequently add this information to the internal data set. Ultimately this makes QLowEnergyController::setRemoteAddressType obsolete. This function was only ever required on Linux. Task-number: QTBUG-46776 Change-Id: If10df86d332dfc7cc98b7c783eb28487c3fa9045 Reviewed-by: Kai Koehne <kai.koehne@qt.io>
Diffstat (limited to 'src/bluetooth/qlowenergycontroller_bluez.cpp')
-rw-r--r--src/bluetooth/qlowenergycontroller_bluez.cpp19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/bluetooth/qlowenergycontroller_bluez.cpp b/src/bluetooth/qlowenergycontroller_bluez.cpp
index 9dadab91..583c0e27 100644
--- a/src/bluetooth/qlowenergycontroller_bluez.cpp
+++ b/src/bluetooth/qlowenergycontroller_bluez.cpp
@@ -46,6 +46,7 @@
#include "bluez/hcimanager_p.h"
#include "bluez/remotedevicemanager_p.h"
#include "bluez/bluez5_helper_p.h"
+#include "bluez/bluetoothmanagement_p.h"
#include <QtCore/QFileInfo>
#include <QtCore/QLoggingCategory>
@@ -598,10 +599,20 @@ void QLowEnergyControllerPrivate::establishL2cpClientSocket()
this, SLOT(l2cpErrorChanged(QBluetoothSocket::SocketError)));
connect(l2cpSocket, SIGNAL(readyRead()), this, SLOT(l2cpReadyRead()));
- if (addressType == QLowEnergyController::PublicAddress)
- l2cpSocket->d_ptr->lowEnergySocketType = BDADDR_LE_PUBLIC;
- else if (addressType == QLowEnergyController::RandomAddress)
- l2cpSocket->d_ptr->lowEnergySocketType = BDADDR_LE_RANDOM;
+ quint32 addressTypeToUse = (addressType == QLowEnergyController::PublicAddress)
+ ? BDADDR_LE_PUBLIC : BDADDR_LE_RANDOM;
+ if (BluetoothManagement::instance()->isMonitoringEnabled()) {
+ // if monitoring is possible and it's private then we force it to the relevant option
+ if (BluetoothManagement::instance()->isAddressRandom(remoteDevice)) {
+ addressTypeToUse = BDADDR_LE_RANDOM;
+ }
+ }
+
+ qCDebug(QT_BT_BLUEZ) << "addresstypeToUse:"
+ << (addressTypeToUse == BDADDR_LE_RANDOM
+ ? QStringLiteral("Random") : QStringLiteral("Public"));
+
+ l2cpSocket->d_ptr->lowEnergySocketType = addressTypeToUse;
int sockfd = l2cpSocket->socketDescriptor();
if (sockfd < 0) {