summaryrefslogtreecommitdiffstats
path: root/src/bluetooth
diff options
context:
space:
mode:
authorAlex Blasche <alexander.blasche@qt.io>2018-04-12 11:17:00 +0200
committerAlex Blasche <alexander.blasche@qt.io>2018-04-17 10:29:10 +0000
commit184307884f560653421286cc9e5e6f0e86a4cef4 (patch)
tree45dbcd58758cf8cce08cd37d907c659785813caa /src/bluetooth
parent8b334771babd64b1c7f47babcb5c4c449b9067a1 (diff)
BlueZ: Ensure that QLEController::remoteName() has a value
This fixes the problem for the custom GATT stack on Bluez4 and older Bluez5 versions (below 5.42). Task-number: QTBUG-67651 Change-Id: Ia3c64c06777c8d357f615d681838bcdc83b92236 Reviewed-by: Oliver Wolff <oliver.wolff@qt.io> Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Diffstat (limited to 'src/bluetooth')
-rw-r--r--src/bluetooth/qlowenergycontroller_bluez.cpp79
1 files changed, 77 insertions, 2 deletions
diff --git a/src/bluetooth/qlowenergycontroller_bluez.cpp b/src/bluetooth/qlowenergycontroller_bluez.cpp
index 40519b51..d58e0ee8 100644
--- a/src/bluetooth/qlowenergycontroller_bluez.cpp
+++ b/src/bluetooth/qlowenergycontroller_bluez.cpp
@@ -44,10 +44,16 @@
#include "qleadvertiser_p.h"
#include "bluez/bluez_data_p.h"
#include "bluez/hcimanager_p.h"
+#include "bluez/objectmanager_p.h"
#include "bluez/remotedevicemanager_p.h"
#include "bluez/bluez5_helper_p.h"
#include "bluez/bluetoothmanagement_p.h"
+// Bluez 4
+#include "bluez/adapter_p.h"
+#include "bluez/device_p.h"
+#include "bluez/manager_p.h"
+
#include <QtCore/QFileInfo>
#include <QtCore/QLoggingCategory>
#include <QtCore/QSettings>
@@ -746,8 +752,11 @@ void QLowEnergyControllerPrivateBluez::l2cpDisconnected()
{
Q_Q(QLowEnergyController);
- if (role == QLowEnergyController::PeripheralRole)
+ if (role == QLowEnergyController::PeripheralRole) {
storeClientConfigurations();
+ remoteDevice.clear();
+ remoteName.clear();
+ }
invalidateServices();
resetController();
setState(QLowEnergyController::UnconnectedState);
@@ -3012,6 +3021,69 @@ void QLowEnergyControllerPrivateBluez::sendNextIndication()
sendIndication(scheduledIndications.takeFirst());
}
+static QString nameOfRemoteCentral(const QBluetoothAddress &peerAddress, const QBluetoothAddress &localAdapter)
+{
+ const QString peerAddressString = peerAddress.toString();
+ if (isBluez5()) {
+ OrgFreedesktopDBusObjectManagerInterface manager(QStringLiteral("org.bluez"),
+ QStringLiteral("/"),
+ QDBusConnection::systemBus());
+ QDBusPendingReply<ManagedObjectList> reply = manager.GetManagedObjects();
+ reply.waitForFinished();
+ if (reply.isError())
+ return QString();
+
+ ManagedObjectList managedObjectList = reply.value();
+ for (ManagedObjectList::const_iterator it = managedObjectList.constBegin(); it != managedObjectList.constEnd(); ++it) {
+ const InterfaceList &ifaceList = it.value();
+
+ for (InterfaceList::const_iterator jt = ifaceList.constBegin(); jt != ifaceList.constEnd(); ++jt) {
+ const QString &iface = jt.key();
+ const QVariantMap &ifaceValues = jt.value();
+
+ if (iface == QStringLiteral("org.bluez.Device1")) {
+ if (ifaceValues.value(QStringLiteral("Address")).toString() == peerAddressString)
+ return ifaceValues.value(QStringLiteral("Alias")).toString();
+ }
+ }
+ }
+ return QString();
+ } else {
+ OrgBluezManagerInterface manager(QStringLiteral("org.bluez"), QStringLiteral("/"),
+ QDBusConnection::systemBus());
+
+ QDBusPendingReply<QDBusObjectPath> reply = manager.FindAdapter(localAdapter.toString());
+ reply.waitForFinished();
+ if (reply.isError())
+ return QString();
+
+ OrgBluezAdapterInterface adapter(QStringLiteral("org.bluez"), reply.value().path(),
+ QDBusConnection::systemBus());
+
+ QDBusPendingReply<QDBusObjectPath> deviceObjectPath = adapter.FindDevice(peerAddressString);
+ deviceObjectPath.waitForFinished();
+ if (deviceObjectPath.isError()) {
+ if (deviceObjectPath.error().name() != QStringLiteral("org.bluez.Error.DoesNotExist"))
+ return QString();
+
+ deviceObjectPath = adapter.CreateDevice(peerAddressString);
+ deviceObjectPath.waitForFinished();
+ if (deviceObjectPath.isError())
+ return QString();
+ }
+
+ OrgBluezDeviceInterface device(QStringLiteral("org.bluez"), deviceObjectPath.value().path(),
+ QDBusConnection::systemBus());
+
+ QDBusPendingReply<QVariantMap> properties = device.GetProperties();
+ properties.waitForFinished();
+ if (properties.isError())
+ return QString();
+
+ return properties.value().value(QStringLiteral("Alias")).toString();
+ }
+}
+
void QLowEnergyControllerPrivateBluez::handleConnectionRequest()
{
if (state != QLowEnergyController::AdvertisingState) {
@@ -3030,8 +3102,11 @@ void QLowEnergyControllerPrivateBluez::handleConnectionRequest()
serverSocketNotifier->setEnabled(true);
return;
}
+
remoteDevice = QBluetoothAddress(convertAddress(clientAddr.l2_bdaddr.b));
- qCDebug(QT_BT_BLUEZ) << "GATT connection from device" << remoteDevice;
+ remoteName = nameOfRemoteCentral(remoteDevice, localAdapter);
+ qCDebug(QT_BT_BLUEZ) << "GATT connection from device" << remoteDevice << remoteName;
+
if (connectionHandle == 0)
qCWarning(QT_BT_BLUEZ) << "Received client connection, but no connection complete event";