summaryrefslogtreecommitdiffstats
path: root/src/bluetooth
diff options
context:
space:
mode:
Diffstat (limited to 'src/bluetooth')
-rw-r--r--src/bluetooth/android/lowenergynotificationhub.cpp5
-rw-r--r--src/bluetooth/bluetooth.pro4
-rw-r--r--src/bluetooth/bluez/adapter1_bluez5.cpp4
-rw-r--r--src/bluetooth/bluez/adapter1_bluez5_p.h23
-rw-r--r--src/bluetooth/bluez/bluez5_helper.cpp1
-rw-r--r--src/bluetooth/bluez/bluez5_helper_p.h2
-rw-r--r--src/bluetooth/bluez/device1_bluez5.cpp3
-rw-r--r--src/bluetooth/bluez/device1_bluez5_p.h38
-rwxr-xr-xsrc/bluetooth/bluez/generate14
-rw-r--r--src/bluetooth/bluez/objectmanager_p.h4
-rw-r--r--src/bluetooth/bluez/org.bluez.Adapter1.xml4
-rw-r--r--src/bluetooth/bluez/org.bluez.Device1.xml10
-rw-r--r--src/bluetooth/osx/osxbtcentralmanager.mm2
-rw-r--r--src/bluetooth/qbluetoothdevicediscoveryagent.cpp8
-rw-r--r--src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp2
-rw-r--r--src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp66
-rw-r--r--src/bluetooth/qbluetoothdevicediscoveryagent_p.h2
-rw-r--r--src/bluetooth/qbluetoothdeviceinfo.h1
-rw-r--r--src/bluetooth/qbluetoothlocaldevice_bluez.cpp8
-rw-r--r--src/bluetooth/qbluetoothsocket.cpp8
-rw-r--r--src/bluetooth/qbluetoothsocket.h1
-rw-r--r--src/bluetooth/qbluetoothsocket_bluez.cpp4
-rw-r--r--src/bluetooth/qbluetoothsocket_osx.mm6
-rw-r--r--src/bluetooth/qbluetoothsocket_winrt.cpp5
-rw-r--r--src/bluetooth/qlowenergycharacteristic.h2
-rw-r--r--src/bluetooth/qlowenergycontroller.cpp5
-rw-r--r--src/bluetooth/qlowenergycontroller.h1
-rw-r--r--src/bluetooth/qlowenergycontroller_bluez.cpp10
-rw-r--r--src/bluetooth/qlowenergycontroller_p.h5
-rw-r--r--src/bluetooth/qlowenergycontroller_winrt.cpp5
-rw-r--r--src/bluetooth/qlowenergydescriptor.h2
-rw-r--r--src/bluetooth/qlowenergyservice.cpp2
32 files changed, 189 insertions, 68 deletions
diff --git a/src/bluetooth/android/lowenergynotificationhub.cpp b/src/bluetooth/android/lowenergynotificationhub.cpp
index 53f2d6cc..9f90e3de 100644
--- a/src/bluetooth/android/lowenergynotificationhub.cpp
+++ b/src/bluetooth/android/lowenergynotificationhub.cpp
@@ -41,7 +41,7 @@
#include <QtCore/QHash>
#include <QtCore/QLoggingCategory>
-#include <QtCore/QTime>
+#include <QtCore/QRandomGenerator>
#include <QtAndroidExtras/QAndroidJniEnvironment>
QT_BEGIN_NAMESPACE
@@ -81,11 +81,10 @@ LowEnergyNotificationHub::LowEnergyNotificationHub(const QBluetoothAddress &remo
}
// register C++ class pointer in Java
- qsrand(QTime::currentTime().msec());
lock.lockForWrite();
while (true) {
- javaToCtoken = qrand();
+ javaToCtoken = QRandomGenerator::get32();
if (!hubMap()->contains(javaToCtoken))
break;
}
diff --git a/src/bluetooth/bluetooth.pro b/src/bluetooth/bluetooth.pro
index 40b14a84..233cdb3b 100644
--- a/src/bluetooth/bluetooth.pro
+++ b/src/bluetooth/bluetooth.pro
@@ -183,11 +183,9 @@ qtConfig(bluez) {
qbluetoothserviceinfo_p.cpp \
qbluetoothservicediscoveryagent_p.cpp \
qbluetoothsocket_p.cpp \
- qbluetoothserver_p.cpp \
- qlowenergycontroller_p.cpp
+ qbluetoothserver_p.cpp
SOURCES -= qbluetoothdevicediscoveryagent.cpp
- SOURCES -= qlowenergycontroller_p.cpp
SOURCES -= qlowenergyservice.cpp
SOURCES -= qlowenergycontroller.cpp
} else:winrt {
diff --git a/src/bluetooth/bluez/adapter1_bluez5.cpp b/src/bluetooth/bluez/adapter1_bluez5.cpp
index 0f1e0acd..b1aefc8d 100644
--- a/src/bluetooth/bluez/adapter1_bluez5.cpp
+++ b/src/bluetooth/bluez/adapter1_bluez5.cpp
@@ -1,8 +1,8 @@
/*
* This file was generated by qdbusxml2cpp version 0.8
- * Command line was: qdbusxml2cpp -p adapter1 -v org.bluez.Adapter1.xml
+ * Command line was: qdbusxml2cpp -p adapter1_bluez5_p.h:adapter1_bluez5.cpp org.bluez.Adapter1.xml
*
- * qdbusxml2cpp is Copyright (C) 2015 The Qt Company Ltd.
+ * qdbusxml2cpp is Copyright (C) 2017 The Qt Company Ltd.
*
* This is an auto-generated file.
* This file may have been hand-edited. Look for HAND-EDIT comments
diff --git a/src/bluetooth/bluez/adapter1_bluez5_p.h b/src/bluetooth/bluez/adapter1_bluez5_p.h
index 5568da4c..ce108ad0 100644
--- a/src/bluetooth/bluez/adapter1_bluez5_p.h
+++ b/src/bluetooth/bluez/adapter1_bluez5_p.h
@@ -1,15 +1,15 @@
/*
* This file was generated by qdbusxml2cpp version 0.8
- * Command line was: qdbusxml2cpp -p adapter1 -v org.bluez.Adapter1.xml
+ * Command line was: qdbusxml2cpp -p adapter1_bluez5_p.h:adapter1_bluez5.cpp org.bluez.Adapter1.xml
*
- * qdbusxml2cpp is Copyright (C) 2015 The Qt Company Ltd.
+ * qdbusxml2cpp is Copyright (C) 2017 The Qt Company Ltd.
*
* This is an auto-generated file.
* Do not edit! All changes made to it will be lost.
*/
-#ifndef ADAPTER1_H_1396951555
-#define ADAPTER1_H_1396951555
+#ifndef ADAPTER1_BLUEZ5_P_H
+#define ADAPTER1_BLUEZ5_P_H
#include <QtCore/QObject>
#include <QtCore/QByteArray>
@@ -31,7 +31,7 @@ public:
{ return "org.bluez.Adapter1"; }
public:
- OrgBluezAdapter1Interface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = 0);
+ OrgBluezAdapter1Interface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = nullptr);
~OrgBluezAdapter1Interface();
@@ -100,19 +100,26 @@ public Q_SLOTS: // METHODS
{
QList<QVariant> argumentList;
argumentList << QVariant::fromValue(device);
- return asyncCallWithArgumentList(QLatin1String("RemoveDevice"), argumentList);
+ return asyncCallWithArgumentList(QStringLiteral("RemoveDevice"), argumentList);
+ }
+
+ inline QDBusPendingReply<> SetDiscoveryFilter(const QVariantMap &properties)
+ {
+ QList<QVariant> argumentList;
+ argumentList << QVariant::fromValue(properties);
+ return asyncCallWithArgumentList(QStringLiteral("SetDiscoveryFilter"), argumentList);
}
inline QDBusPendingReply<> StartDiscovery()
{
QList<QVariant> argumentList;
- return asyncCallWithArgumentList(QLatin1String("StartDiscovery"), argumentList);
+ return asyncCallWithArgumentList(QStringLiteral("StartDiscovery"), argumentList);
}
inline QDBusPendingReply<> StopDiscovery()
{
QList<QVariant> argumentList;
- return asyncCallWithArgumentList(QLatin1String("StopDiscovery"), argumentList);
+ return asyncCallWithArgumentList(QStringLiteral("StopDiscovery"), argumentList);
}
Q_SIGNALS: // SIGNALS
diff --git a/src/bluetooth/bluez/bluez5_helper.cpp b/src/bluetooth/bluez/bluez5_helper.cpp
index 8871a872..de41003f 100644
--- a/src/bluetooth/bluez/bluez5_helper.cpp
+++ b/src/bluetooth/bluez/bluez5_helper.cpp
@@ -69,6 +69,7 @@ bool isBluez5()
qDBusRegisterMetaType<InterfaceList>();
qDBusRegisterMetaType<ManagedObjectList>();
+ qDBusRegisterMetaType<ManufacturerDataList>();
QDBusPendingReply<ManagedObjectList> reply = manager.GetManagedObjects();
reply.waitForFinished();
diff --git a/src/bluetooth/bluez/bluez5_helper_p.h b/src/bluetooth/bluez/bluez5_helper_p.h
index a46810fc..2d72caf1 100644
--- a/src/bluetooth/bluez/bluez5_helper_p.h
+++ b/src/bluetooth/bluez/bluez5_helper_p.h
@@ -57,8 +57,10 @@
typedef QMap<QString, QVariantMap> InterfaceList;
typedef QMap<QDBusObjectPath, InterfaceList> ManagedObjectList;
+typedef QMap<quint16, QDBusVariant> ManufacturerDataList;
Q_DECLARE_METATYPE(InterfaceList)
+Q_DECLARE_METATYPE(ManufacturerDataList)
Q_DECLARE_METATYPE(ManagedObjectList)
QT_BEGIN_NAMESPACE
diff --git a/src/bluetooth/bluez/device1_bluez5.cpp b/src/bluetooth/bluez/device1_bluez5.cpp
index a4c01d3f..491a365d 100644
--- a/src/bluetooth/bluez/device1_bluez5.cpp
+++ b/src/bluetooth/bluez/device1_bluez5.cpp
@@ -1,8 +1,7 @@
/*
* This file was generated by qdbusxml2cpp version 0.8
- * Command line was: qdbusxml2cpp -p device1_bluez5 -v org.bluez.Device1.xml
*
- * qdbusxml2cpp is Copyright (C) 2015 The Qt Company Ltd.
+ * qdbusxml2cpp is Copyright (C) 2017 The Qt Company Ltd.
*
* This is an auto-generated file.
* This file may have been hand-edited. Look for HAND-EDIT comments
diff --git a/src/bluetooth/bluez/device1_bluez5_p.h b/src/bluetooth/bluez/device1_bluez5_p.h
index d6181b34..4feb5318 100644
--- a/src/bluetooth/bluez/device1_bluez5_p.h
+++ b/src/bluetooth/bluez/device1_bluez5_p.h
@@ -1,15 +1,14 @@
/*
* This file was generated by qdbusxml2cpp version 0.8
- * Command line was: qdbusxml2cpp -p device1_bluez5 -v org.bluez.Device1.xml
*
- * qdbusxml2cpp is Copyright (C) 2015 The Qt Company Ltd.
+ * qdbusxml2cpp is Copyright (C) 2017 The Qt Company Ltd.
*
* This is an auto-generated file.
* Do not edit! All changes made to it will be lost.
*/
-#ifndef DEVICE1_BLUEZ5_H_1396951960
-#define DEVICE1_BLUEZ5_H_1396951960
+#ifndef DEVICE1_BLUEZ5_P_H
+#define DEVICE1_BLUEZ5_P_H
#include <QtCore/QObject>
#include <QtCore/QByteArray>
@@ -19,6 +18,7 @@
#include <QtCore/QStringList>
#include <QtCore/QVariant>
#include <QtDBus/QtDBus>
+#include "bluez5_helper_p.h"
/*
* Proxy class for interface org.bluez.Device1
@@ -31,7 +31,7 @@ public:
{ return "org.bluez.Device1"; }
public:
- OrgBluezDevice1Interface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = 0);
+ OrgBluezDevice1Interface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent = nullptr);
~OrgBluezDevice1Interface();
@@ -75,6 +75,10 @@ public:
inline bool legacyPairing() const
{ return qvariant_cast< bool >(property("LegacyPairing")); }
+ Q_PROPERTY(ManufacturerDataList ManufacturerData READ manufacturerData)
+ inline ManufacturerDataList manufacturerData() const
+ { return qvariant_cast< ManufacturerDataList >(property("ManufacturerData")); }
+
Q_PROPERTY(QString Modalias READ modalias)
inline QString modalias() const
{ return qvariant_cast< QString >(property("Modalias")); }
@@ -91,12 +95,24 @@ public:
inline short rSSI() const
{ return qvariant_cast< short >(property("RSSI")); }
+ Q_PROPERTY(QVariantMap ServiceData READ serviceData)
+ inline QVariantMap serviceData() const
+ { return qvariant_cast< QVariantMap >(property("ServiceData")); }
+
+ Q_PROPERTY(bool ServicesResolved READ servicesResolved)
+ inline bool servicesResolved() const
+ { return qvariant_cast< bool >(property("ServicesResolved")); }
+
Q_PROPERTY(bool Trusted READ trusted WRITE setTrusted)
inline bool trusted() const
{ return qvariant_cast< bool >(property("Trusted")); }
inline void setTrusted(bool value)
{ setProperty("Trusted", QVariant::fromValue(value)); }
+ Q_PROPERTY(short TxPower READ txPower)
+ inline short txPower() const
+ { return qvariant_cast< short >(property("TxPower")); }
+
Q_PROPERTY(QStringList UUIDs READ uUIDs)
inline QStringList uUIDs() const
{ return qvariant_cast< QStringList >(property("UUIDs")); }
@@ -105,39 +121,39 @@ public Q_SLOTS: // METHODS
inline QDBusPendingReply<> CancelPairing()
{
QList<QVariant> argumentList;
- return asyncCallWithArgumentList(QLatin1String("CancelPairing"), argumentList);
+ return asyncCallWithArgumentList(QStringLiteral("CancelPairing"), argumentList);
}
inline QDBusPendingReply<> Connect()
{
QList<QVariant> argumentList;
- return asyncCallWithArgumentList(QLatin1String("Connect"), argumentList);
+ return asyncCallWithArgumentList(QStringLiteral("Connect"), argumentList);
}
inline QDBusPendingReply<> ConnectProfile(const QString &UUID)
{
QList<QVariant> argumentList;
argumentList << QVariant::fromValue(UUID);
- return asyncCallWithArgumentList(QLatin1String("ConnectProfile"), argumentList);
+ return asyncCallWithArgumentList(QStringLiteral("ConnectProfile"), argumentList);
}
inline QDBusPendingReply<> Disconnect()
{
QList<QVariant> argumentList;
- return asyncCallWithArgumentList(QLatin1String("Disconnect"), argumentList);
+ return asyncCallWithArgumentList(QStringLiteral("Disconnect"), argumentList);
}
inline QDBusPendingReply<> DisconnectProfile(const QString &UUID)
{
QList<QVariant> argumentList;
argumentList << QVariant::fromValue(UUID);
- return asyncCallWithArgumentList(QLatin1String("DisconnectProfile"), argumentList);
+ return asyncCallWithArgumentList(QStringLiteral("DisconnectProfile"), argumentList);
}
inline QDBusPendingReply<> Pair()
{
QList<QVariant> argumentList;
- return asyncCallWithArgumentList(QLatin1String("Pair"), argumentList);
+ return asyncCallWithArgumentList(QStringLiteral("Pair"), argumentList);
}
Q_SIGNALS: // SIGNALS
diff --git a/src/bluetooth/bluez/generate b/src/bluetooth/bluez/generate
index 14bcaea8..cdba18c4 100755
--- a/src/bluetooth/bluez/generate
+++ b/src/bluetooth/bluez/generate
@@ -1,5 +1,6 @@
#!/bin/sh
+#Bluez 4
qdbusxml2cpp -p manager_p.h:manager.cpp org.bluez.Manager.xml org.bluez.Manager
qdbusxml2cpp -p adapter_p.h:adapter.cpp org.bluez.all.xml org.bluez.Adapter
qdbusxml2cpp -i servicemap_p.h -p device_p.h:device.cpp org.bluez.Device.xml org.bluez.Device
@@ -9,8 +10,13 @@ qdbusxml2cpp -p obex_manager_p.h:obex_manager.cpp org.openobex.all.xml org.openo
qdbusxml2cpp -p obex_client_p.h:obex_client.cpp org.openobex.client.xml org.openobex.Client
qdbusxml2cpp -p obex_transfer_p.h:obex_transfer.cpp org.openobex.transfer.xml org.openobex.Transfer
qdbusxml2cpp -a obex_agent_p.h:obex_agent.cpp org.openobex.agent.xml org.openobex.Agent
-#qdbusxml2cpp -p serialproxymanager_p.h:serialproxymanager.cpp org.bluez.all.xml org.bluez.SerialProxyManager
-#qdbusxml2cpp -p networkpeer_p.h:networkpeer.cpp org.bluez.all.xml org.bluez.NetworkPeer
-#qdbusxml2cpp -p networkhub_p.h:networkhub.cpp org.bluez.all.xml org.bluez.NetworkHub
-#qdbusxml2cpp -p networkrouter_p.h:networkrouter.cpp org.bluez.all.xml org.bluez.NetworkRouter
+#Bluez 5
+qdbusxml2cpp -p adapter1_bluez5_p.h:adapter1_bluez5.cpp org.bluez.Adapter1.xml
+qdbusxml2cpp -p device1_bluez5_p.h:device1_bluez5.cpp org.bluez.Device1.xml
+qdbusxml2cpp -p profile1_p.h:profile1.cpp org.bluez.ProfileManager1.xml
+qdbusxml2cpp -p objectmanager_p.h:objectmanager.cpp org.freedesktop.dbus.objectmanager.xml
+qdbusxml2cpp -p properties_p.h:properties.cpp org.freedesktop.dbus.properties.xml
+qdbusxml2cpp -p obex_client1_bluez5_p.h:obex_client1_bluez5_p.h org.bluez.Client1.xml
+qdbusxml2cpp -p obex_objectpush1_bluez5_p.h:obex_objectpush1_bluez5.cpp org.bluez.obex.ObjectPush1.xml
+qdbusxml2cpp -p obex_transfer1_bluez5_p.h:obex_transfer1_bluez5_p.h org.bluez.obex.Transfer1.xml
diff --git a/src/bluetooth/bluez/objectmanager_p.h b/src/bluetooth/bluez/objectmanager_p.h
index 823badeb..74f5ab43 100644
--- a/src/bluetooth/bluez/objectmanager_p.h
+++ b/src/bluetooth/bluez/objectmanager_p.h
@@ -20,10 +20,6 @@
#include <QtCore/QVariant>
#include <QtDBus/QtDBus>
-/* Temporary hack to merge branches until Bluez headers are removed
- * from bluez5_helpers_p.h.
- */
-#define NO_BLUEZ_INCLUDES
#include "bluez5_helper_p.h"
/*
diff --git a/src/bluetooth/bluez/org.bluez.Adapter1.xml b/src/bluetooth/bluez/org.bluez.Adapter1.xml
index a1e6babe..121c277e 100644
--- a/src/bluetooth/bluez/org.bluez.Adapter1.xml
+++ b/src/bluetooth/bluez/org.bluez.Adapter1.xml
@@ -7,6 +7,10 @@
<method name="RemoveDevice">
<arg name="device" type="o" direction="in"/>
</method>
+ <method name="SetDiscoveryFilter">
+ <arg name="properties" type="a{sv}" direction="in"/>
+ <annotation name="org.qtproject.QtDBus.QtTypeName.In0" value="QVariantMap"/>
+ </method>
<property name="Address" type="s" access="read"></property>
<property name="Name" type="s" access="read"></property>
<property name="Alias" type="s" access="readwrite"></property>
diff --git a/src/bluetooth/bluez/org.bluez.Device1.xml b/src/bluetooth/bluez/org.bluez.Device1.xml
index 1f8fd2c1..554d0b53 100644
--- a/src/bluetooth/bluez/org.bluez.Device1.xml
+++ b/src/bluetooth/bluez/org.bluez.Device1.xml
@@ -27,5 +27,15 @@
<property name="UUIDs" type="as" access="read"></property>
<property name="Modalias" type="s" access="read"></property>
<property name="Adapter" type="o" access="read"></property>
+ <!-- ManufacturerData & ServiceData introduced by Bluez 5.31 -->
+ <property name="ManufacturerData" type="a{qv}" access="read">
+ <annotation name="org.qtproject.QtDBus.QtTypeName" value="ManufacturerDataList"/>
+ </property>
+ <property name="ServiceData" type="a{sv}" access="read">
+ <annotation name="org.qtproject.QtDBus.QtTypeName" value="QVariantMap"/>
+ </property>
+ <!-- TxPower and ServicesResolved introduced by Bluez 5.42 -->
+ <property name="TxPower" type="n" access="read"></property>
+ <property name="ServicesResolved" type="b" access="read"></property>
</interface>
</node>
diff --git a/src/bluetooth/osx/osxbtcentralmanager.mm b/src/bluetooth/osx/osxbtcentralmanager.mm
index 9e5128c4..15354f80 100644
--- a/src/bluetooth/osx/osxbtcentralmanager.mm
+++ b/src/bluetooth/osx/osxbtcentralmanager.mm
@@ -48,8 +48,6 @@
#include <algorithm>
#include <limits>
-Q_DECLARE_METATYPE(QLowEnergyCharacteristic)
-Q_DECLARE_METATYPE(QLowEnergyDescriptor)
Q_DECLARE_METATYPE(QLowEnergyHandle)
QT_BEGIN_NAMESPACE
diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent.cpp
index 02ea30d1..5f142f1a 100644
--- a/src/bluetooth/qbluetoothdevicediscoveryagent.cpp
+++ b/src/bluetooth/qbluetoothdevicediscoveryagent.cpp
@@ -333,13 +333,19 @@ void QBluetoothDeviceDiscoveryAgent::start()
}
/*!
- Start Bluetooth device discovery, if it is not already started and the provided
+ Starts Bluetooth device discovery, if it is not already started and the provided
\a methods are supported.
The discovery \a methods limit the scope of the device search.
For example, if the target service or device is a Bluetooth Low Energy device,
this function could be used to limit the search to Bluetooth Low Energy devices and
thereby reduces the discovery time significantly.
+ \note \a methods only determines the type of discovery and does not imply
+ the filtering of the results. For example, the search may still contain classic bluetooth devices
+ despite \a methods being set to \l {QBluetoothDeviceDiscoveryAgent::LowEnergyMethod}
+ {LowEnergyMethod} only. This may happen due to previously cached search results
+ which may be incorporated into the search results.
+
\since 5.8
*/
void QBluetoothDeviceDiscoveryAgent::start(DiscoveryMethods methods)
diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp
index 7e8e4236..303dd67f 100644
--- a/src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp
+++ b/src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp
@@ -165,7 +165,7 @@ void QBluetoothDeviceDiscoveryAgentPrivate::start(QBluetoothDeviceDiscoveryAgent
{
qCWarning(QT_BT_ANDROID) << "Search not possible due to missing permission (ACCESS_COARSE_LOCATION)";
lastError = QBluetoothDeviceDiscoveryAgent::UnknownError;
- errorString = QBluetoothDeviceDiscoveryAgent::tr("Missing Location permission. Search is not possible");
+ errorString = QBluetoothDeviceDiscoveryAgent::tr("Missing Location permission. Search is not possible.");
emit q->error(lastError);
return;
}
diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp
index 5c70f1c1..3cc3354a 100644
--- a/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp
+++ b/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp
@@ -125,7 +125,7 @@ QBluetoothDeviceDiscoveryAgent::DiscoveryMethods QBluetoothDeviceDiscoveryAgent:
return (ClassicMethod | LowEnergyMethod);
}
-void QBluetoothDeviceDiscoveryAgentPrivate::start(QBluetoothDeviceDiscoveryAgent::DiscoveryMethods /*methods*/)
+void QBluetoothDeviceDiscoveryAgentPrivate::start(QBluetoothDeviceDiscoveryAgent::DiscoveryMethods methods)
{
// Currently both BlueZ backends do not distinguish discovery methods.
// The DBus API's always return both device types. Therefore we ignore
@@ -139,7 +139,7 @@ void QBluetoothDeviceDiscoveryAgentPrivate::start(QBluetoothDeviceDiscoveryAgent
discoveredDevices.clear();
if (managerBluez5) {
- startBluez5();
+ startBluez5(methods);
return;
}
@@ -228,11 +228,10 @@ void QBluetoothDeviceDiscoveryAgentPrivate::start(QBluetoothDeviceDiscoveryAgent
}
}
-void QBluetoothDeviceDiscoveryAgentPrivate::startBluez5()
+void QBluetoothDeviceDiscoveryAgentPrivate::startBluez5(QBluetoothDeviceDiscoveryAgent::DiscoveryMethods methods)
{
Q_Q(QBluetoothDeviceDiscoveryAgent);
-
bool ok = false;
const QString adapterPath = findAdapterForAddress(m_adapterAddress, &ok);
if (!ok || adapterPath.isEmpty()) {
@@ -257,6 +256,33 @@ void QBluetoothDeviceDiscoveryAgentPrivate::startBluez5()
return;
}
+ QVariantMap map;
+ if (methods == (QBluetoothDeviceDiscoveryAgent::LowEnergyMethod|QBluetoothDeviceDiscoveryAgent::ClassicMethod))
+ map.insert(QStringLiteral("Transport"), QStringLiteral("auto"));
+ else if (methods & QBluetoothDeviceDiscoveryAgent::LowEnergyMethod)
+ map.insert(QStringLiteral("Transport"), QStringLiteral("le"));
+ else
+ map.insert(QStringLiteral("Transport"), QStringLiteral("bredr"));
+
+ // older BlueZ 5.x versions don't have this function
+ // filterReply returns UnknownMethod which we ignore
+ QDBusPendingReply<> filterReply = adapterBluez5->SetDiscoveryFilter(map);
+ filterReply.waitForFinished();
+ if (filterReply.isError()) {
+ if (filterReply.error().type() == QDBusError::Other
+ && filterReply.error().name() == QStringLiteral("org.bluez.Error.Failed")) {
+ qCDebug(QT_BT_BLUEZ) << "Discovery method" << methods << "not supported";
+ lastError = QBluetoothDeviceDiscoveryAgent::UnsupportedDiscoveryMethod;
+ errorString = QBluetoothDeviceDiscoveryAgent::tr("One or more device discovery methods "
+ "are not supported on this platform");
+ delete adapterBluez5;
+ adapterBluez5 = 0;
+ emit q->error(lastError);
+ return;
+ } else if (filterReply.error().type() != QDBusError::UnknownMethod) {
+ qCDebug(QT_BT_BLUEZ) << "SetDiscoveryFilter failed:" << filterReply.error();
+ }
+ }
QtBluezDiscoveryManager::instance()->registerDiscoveryInterest(adapterBluez5->path());
QObject::connect(QtBluezDiscoveryManager::instance(), SIGNAL(discoveryInterrupted(QString)),
@@ -403,18 +429,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 && lowEnergySearchTimeout > 0) {
diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_p.h b/src/bluetooth/qbluetoothdevicediscoveryagent_p.h
index 44834024..243d7fd2 100644
--- a/src/bluetooth/qbluetoothdevicediscoveryagent_p.h
+++ b/src/bluetooth/qbluetoothdevicediscoveryagent_p.h
@@ -153,7 +153,7 @@ private:
QList<OrgFreedesktopDBusPropertiesInterface *> propertyMonitors;
void deviceFoundBluez5(const QString& devicePath);
- void startBluez5();
+ void startBluez5(QBluetoothDeviceDiscoveryAgent::DiscoveryMethods methods);
bool useExtendedDiscovery;
QTimer extendedDiscoveryTimer;
diff --git a/src/bluetooth/qbluetoothdeviceinfo.h b/src/bluetooth/qbluetoothdeviceinfo.h
index 751c8384..5ff17e1c 100644
--- a/src/bluetooth/qbluetoothdeviceinfo.h
+++ b/src/bluetooth/qbluetoothdeviceinfo.h
@@ -189,6 +189,7 @@ public:
};
Q_DECLARE_FLAGS(ServiceClasses, ServiceClass)
+ //TODO Qt6 Remove DataCompleteness -> it serves no purpose
enum DataCompleteness {
DataComplete,
DataIncomplete,
diff --git a/src/bluetooth/qbluetoothlocaldevice_bluez.cpp b/src/bluetooth/qbluetoothlocaldevice_bluez.cpp
index c8c5ffbf..0982573e 100644
--- a/src/bluetooth/qbluetoothlocaldevice_bluez.cpp
+++ b/src/bluetooth/qbluetoothlocaldevice_bluez.cpp
@@ -38,6 +38,7 @@
****************************************************************************/
#include <QtCore/QLoggingCategory>
+#include <QtCore/QRandomGenerator>
#include <QtDBus/QDBusContext>
#include "qbluetoothlocaldevice.h"
@@ -798,9 +799,8 @@ void QBluetoothLocalDevicePrivate::initializeAdapter()
connect(adapter, SIGNAL(PropertyChanged(QString, QDBusVariant)),
SLOT(PropertyChanged(QString, QDBusVariant)));
- qsrand(QTime::currentTime().msec());
agent_path = agentPath;
- agent_path.append(QString::fromLatin1("/%1").arg(qrand()));
+ agent_path.append(QString::fromLatin1("/%1").arg(QRandomGenerator::get32()));
}
}
@@ -1164,7 +1164,7 @@ QString QBluetoothLocalDevicePrivate::RequestPinCode(const QDBusObjectPath &in0)
Q_Q(QBluetoothLocalDevice);
qCDebug(QT_BT_BLUEZ) << Q_FUNC_INFO << in0.path();
// seeded in constructor, 6 digit pin
- QString pin = QString::fromLatin1("%1").arg(qrand() % 1000000);
+ QString pin = QString::fromLatin1("%1").arg(QRandomGenerator::bounded(1000000));
pin = QString::fromLatin1("%1").arg(pin, 6, QLatin1Char('0'));
emit q->pairingDisplayPinCode(address, pin);
@@ -1276,7 +1276,7 @@ uint QBluetoothLocalDevicePrivate::RequestPasskey(const QDBusObjectPath &in0)
{
Q_UNUSED(in0);
qCDebug(QT_BT_BLUEZ) << Q_FUNC_INFO;
- return (qrand() % 1000000);
+ return (QRandomGenerator::bounded(1000000));
}
// Bluez 4
diff --git a/src/bluetooth/qbluetoothsocket.cpp b/src/bluetooth/qbluetoothsocket.cpp
index 2f38ed04..a35863b4 100644
--- a/src/bluetooth/qbluetoothsocket.cpp
+++ b/src/bluetooth/qbluetoothsocket.cpp
@@ -112,6 +112,8 @@ Q_DECLARE_LOGGING_CATEGORY(QT_BT)
supported on this platform.
\value OperationError An operation was attempted while the socket was in a state
that did not permit it.
+ \value RemoteHostClosedError The remote host closed the connection. This value was
+ introduced by Qt 5.10.
*/
/*!
@@ -854,12 +856,18 @@ QDebug operator<<(QDebug debug, QBluetoothSocket::SocketError error)
case QBluetoothSocket::HostNotFoundError:
debug << "QBluetoothSocket::HostNotFoundError";
break;
+ case QBluetoothSocket::RemoteHostClosedError:
+ debug << "QBluetoothSocket::RemoteHostClosedError";
+ break;
case QBluetoothSocket::ServiceNotFoundError:
debug << "QBluetoothSocket::ServiceNotFoundError";
break;
case QBluetoothSocket::NetworkError:
debug << "QBluetoothSocket::NetworkError";
break;
+ case QBluetoothSocket::UnsupportedProtocolError:
+ debug << "QBluetoothSocket::UnsupportedProtocolError";
+ break;
default:
debug << "QBluetoothSocket::SocketError(" << (int)error << ")";
}
diff --git a/src/bluetooth/qbluetoothsocket.h b/src/bluetooth/qbluetoothsocket.h
index 97b6685b..2b1bd3cf 100644
--- a/src/bluetooth/qbluetoothsocket.h
+++ b/src/bluetooth/qbluetoothsocket.h
@@ -79,6 +79,7 @@ public:
enum SocketError {
NoSocketError = -2,
UnknownSocketError = QAbstractSocket::UnknownSocketError, //-1
+ RemoteHostClosedError = QAbstractSocket::RemoteHostClosedError, //1
HostNotFoundError = QAbstractSocket::HostNotFoundError, //2
ServiceNotFoundError = QAbstractSocket::SocketAddressNotAvailableError, //9
NetworkError = QAbstractSocket::NetworkError, //7
diff --git a/src/bluetooth/qbluetoothsocket_bluez.cpp b/src/bluetooth/qbluetoothsocket_bluez.cpp
index 6aef811a..17b8e738 100644
--- a/src/bluetooth/qbluetoothsocket_bluez.cpp
+++ b/src/bluetooth/qbluetoothsocket_bluez.cpp
@@ -290,7 +290,9 @@ void QBluetoothSocketPrivate::_q_readNotify()
qCWarning(QT_BT_BLUEZ) << Q_FUNC_INFO << socket << "error:" << readFromDevice << errorString;
if (errsv == EHOSTDOWN)
q->setSocketError(QBluetoothSocket::HostNotFoundError);
- else if (errsv != ECONNRESET) // The other side closing the connection is not an error.
+ else if (errsv == ECONNRESET)
+ q->setSocketError(QBluetoothSocket::RemoteHostClosedError);
+ else
q->setSocketError(QBluetoothSocket::UnknownSocketError);
q->disconnectFromService();
diff --git a/src/bluetooth/qbluetoothsocket_osx.mm b/src/bluetooth/qbluetoothsocket_osx.mm
index 75712868..71e249fe 100644
--- a/src/bluetooth/qbluetoothsocket_osx.mm
+++ b/src/bluetooth/qbluetoothsocket_osx.mm
@@ -761,12 +761,18 @@ QDebug operator<<(QDebug debug, QBluetoothSocket::SocketError error)
case QBluetoothSocket::HostNotFoundError:
debug << "QBluetoothSocket::HostNotFoundError";
break;
+ case QBluetoothSocket::RemoteHostClosedError:
+ debug << "QBluetoothSocket::RemoteHostClosedError";
+ break;
case QBluetoothSocket::ServiceNotFoundError:
debug << "QBluetoothSocket::ServiceNotFoundError";
break;
case QBluetoothSocket::NetworkError:
debug << "QBluetoothSocket::NetworkError";
break;
+ case QBluetoothSocket::UnsupportedProtocolError:
+ debug << "QBluetoothSocket::UnsupportedProtocolError";
+ break;
default:
debug << "QBluetoothSocket::SocketError(" << (int)error << ")";
}
diff --git a/src/bluetooth/qbluetoothsocket_winrt.cpp b/src/bluetooth/qbluetoothsocket_winrt.cpp
index 501ffd74..365fe046 100644
--- a/src/bluetooth/qbluetoothsocket_winrt.cpp
+++ b/src/bluetooth/qbluetoothsocket_winrt.cpp
@@ -223,7 +223,7 @@ public:
// the closing of the socket won't be communicated to the caller. So only the error is set. The
// actual socket close happens inside of read.
if (!bufferLength) {
- emit socketErrorOccured(QBluetoothSocket::NetworkError);
+ emit socketErrorOccured(QBluetoothSocket::RemoteHostClosedError);
return S_OK;
}
@@ -609,6 +609,9 @@ void QBluetoothSocketPrivate::handleError(QBluetoothSocket::SocketError error)
case QBluetoothSocket::NetworkError:
errorString = QBluetoothSocket::tr("Network error");
break;
+ case QBluetoothSocket::RemoteHostClosedError:
+ errorString = QBluetoothSocket::tr("Remote host closed connection");
+ break;
default:
errorString = QBluetoothSocket::tr("Unknown socket error");
}
diff --git a/src/bluetooth/qlowenergycharacteristic.h b/src/bluetooth/qlowenergycharacteristic.h
index b991e9a2..154c9936 100644
--- a/src/bluetooth/qlowenergycharacteristic.h
+++ b/src/bluetooth/qlowenergycharacteristic.h
@@ -107,4 +107,6 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(QLowEnergyCharacteristic::PropertyTypes)
QT_END_NAMESPACE
+Q_DECLARE_METATYPE(QLowEnergyCharacteristic)
+
#endif // QLOWENERGYCHARACTERISTIC_H
diff --git a/src/bluetooth/qlowenergycontroller.cpp b/src/bluetooth/qlowenergycontroller.cpp
index 053ca980..004ee3be 100644
--- a/src/bluetooth/qlowenergycontroller.cpp
+++ b/src/bluetooth/qlowenergycontroller.cpp
@@ -138,6 +138,8 @@ Q_DECLARE_LOGGING_CATEGORY(QT_BT)
This value was introduced by Qt 5.5.
\value AdvertisingError The attempt to start advertising failed.
This value was introduced by Qt 5.7.
+ \value RemoteHostClosedError The remote device closed the connection.
+ This value was introduced by Qt 5.10.
*/
/*!
@@ -299,6 +301,9 @@ void QLowEnergyControllerPrivate::setError(
case QLowEnergyController::AdvertisingError:
errorString = QLowEnergyController::tr("Error occurred trying to start advertising");
break;
+ case QLowEnergyController::RemoteHostClosedError:
+ errorString = QLowEnergyController::tr("Remote device closed the connection");
+ break;
case QLowEnergyController::NoError:
return;
default:
diff --git a/src/bluetooth/qlowenergycontroller.h b/src/bluetooth/qlowenergycontroller.h
index 1c4fa83f..1a84b05b 100644
--- a/src/bluetooth/qlowenergycontroller.h
+++ b/src/bluetooth/qlowenergycontroller.h
@@ -66,6 +66,7 @@ public:
InvalidBluetoothAdapterError,
ConnectionError,
AdvertisingError,
+ RemoteHostClosedError
};
Q_ENUM(Error)
diff --git a/src/bluetooth/qlowenergycontroller_bluez.cpp b/src/bluetooth/qlowenergycontroller_bluez.cpp
index 0744bcc4..ca3f7760 100644
--- a/src/bluetooth/qlowenergycontroller_bluez.cpp
+++ b/src/bluetooth/qlowenergycontroller_bluez.cpp
@@ -648,9 +648,9 @@ void QLowEnergyControllerPrivate::establishL2cpClientSocket()
void QLowEnergyControllerPrivate::createServicesForCentralIfRequired()
{
- //only enable when requested
- //for now we use env variable to activate the feature
- if (Q_LIKELY(!qEnvironmentVariableIsSet("QT_DEFAULT_CENTRAL_SERVICES")))
+ bool ok = false;
+ int value = qEnvironmentVariableIntValue("QT_DEFAULT_CENTRAL_SERVICES", &ok);
+ if (Q_UNLIKELY(ok && value == 0))
return; //nothing to do
//do not add the services each time we start a connection
@@ -753,6 +753,10 @@ void QLowEnergyControllerPrivate::l2cpErrorChanged(QBluetoothSocket::SocketError
setError(QLowEnergyController::NetworkError);
qCDebug(QT_BT_BLUEZ) << "Network IO error while talking to LE device";
break;
+ case QBluetoothSocket::RemoteHostClosedError:
+ setError(QLowEnergyController::RemoteHostClosedError);
+ qCDebug(QT_BT_BLUEZ) << "Remote host closed the connection";
+ break;
case QBluetoothSocket::UnknownSocketError:
case QBluetoothSocket::UnsupportedProtocolError:
case QBluetoothSocket::OperationError:
diff --git a/src/bluetooth/qlowenergycontroller_p.h b/src/bluetooth/qlowenergycontroller_p.h
index b92716e9..6e866144 100644
--- a/src/bluetooth/qlowenergycontroller_p.h
+++ b/src/bluetooth/qlowenergycontroller_p.h
@@ -497,11 +497,6 @@ Q_DECLARE_TYPEINFO(QLowEnergyControllerPrivate::Attribute, Q_MOVABLE_TYPE);
QT_END_NAMESPACE
-#ifdef QT_WINRT_BLUETOOTH
-Q_DECLARE_METATYPE(QLowEnergyCharacteristic)
-Q_DECLARE_METATYPE(QLowEnergyDescriptor)
-#endif // QT_WINRT_BLUETOOTH
-
#endif // QT_OSX_BLUETOOTH || QT_IOS_BLUETOOTH
#endif // QLOWENERGYCONTROLLERPRIVATE_P_H
diff --git a/src/bluetooth/qlowenergycontroller_winrt.cpp b/src/bluetooth/qlowenergycontroller_winrt.cpp
index d6fc4952..8d3d85d8 100644
--- a/src/bluetooth/qlowenergycontroller_winrt.cpp
+++ b/src/bluetooth/qlowenergycontroller_winrt.cpp
@@ -338,6 +338,7 @@ void QLowEnergyControllerPrivate::connectToDevice()
emit q->connected();
} else if (state == QLowEnergyController::ConnectedState
&& status == BluetoothConnectionStatus::BluetoothConnectionStatus_Disconnected) {
+ setError(QLowEnergyController::RemoteHostClosedError);
setState(QLowEnergyController::UnconnectedState);
emit q->disconnected();
}
@@ -419,6 +420,10 @@ void QLowEnergyControllerPrivate::disconnectFromDevice()
Q_Q(QLowEnergyController);
setState(QLowEnergyController::UnconnectedState);
emit q->disconnected();
+ if (mDevice && mStatusChangedToken.value) {
+ mDevice->remove_ConnectionStatusChanged(mStatusChangedToken);
+ mStatusChangedToken.value = 0;
+ }
}
ComPtr<IGattDeviceService> QLowEnergyControllerPrivate::getNativeService(const QBluetoothUuid &serviceUuid)
diff --git a/src/bluetooth/qlowenergydescriptor.h b/src/bluetooth/qlowenergydescriptor.h
index 1dfe1c35..9e71fc56 100644
--- a/src/bluetooth/qlowenergydescriptor.h
+++ b/src/bluetooth/qlowenergydescriptor.h
@@ -89,4 +89,6 @@ protected:
QT_END_NAMESPACE
+Q_DECLARE_METATYPE(QLowEnergyDescriptor)
+
#endif // QLOWENERGYDESCRIPTOR_H
diff --git a/src/bluetooth/qlowenergyservice.cpp b/src/bluetooth/qlowenergyservice.cpp
index 6e33c565..9d3129fd 100644
--- a/src/bluetooth/qlowenergyservice.cpp
+++ b/src/bluetooth/qlowenergyservice.cpp
@@ -380,6 +380,8 @@ QLowEnergyService::QLowEnergyService(QSharedPointer<QLowEnergyServicePrivate> p,
qRegisterMetaType<QLowEnergyService::ServiceError>();
qRegisterMetaType<QLowEnergyService::ServiceType>();
qRegisterMetaType<QLowEnergyService::WriteMode>();
+ qRegisterMetaType<QLowEnergyCharacteristic>();
+ qRegisterMetaType<QLowEnergyDescriptor>();
connect(p.data(), SIGNAL(error(QLowEnergyService::ServiceError)),
this, SIGNAL(error(QLowEnergyService::ServiceError)));