diff options
author | Alex Blasche <alexander.blasche@theqtcompany.com> | 2016-04-27 10:44:18 +0200 |
---|---|---|
committer | Timur Pocheptsov <timur.pocheptsov@theqtcompany.com> | 2016-04-29 20:21:27 +0000 |
commit | 3e7befcd5801645fa4f7f84d5f1805ae615f28c3 (patch) | |
tree | 720135269844060b2eff9542e2f3ea53786eebf6 | |
parent | 4a6c2b9fd607dfabace868feb0433ef3d99edcf4 (diff) | |
download | qtconnectivity-3e7befcd5801645fa4f7f84d5f1805ae615f28c3.tar.gz |
Bluez5: Fix serial service discovery inside QBluetoothSocket
QBluetoothSocket::connectToService() performs its own service discovery
if the remote RFCOMM channel is not known. This may happen if the passed
in BluetothServiceInfo object was obtained via a minimal service
discovery (which does not perform a channel discovery) or if the
connectToService(const QBluetoothAddress &address, const QBluetoothUuid
&uuid, OpenMode openMode = ReadWrite);
overload was called.
This was not an issue with Bluez4 as every type of discovery
provided the RFCOMM channel id.
The internal discovery required at least the service's ServiceId to be
known. However a lot of SerialPort profiles do not set a custom service
uuid as ServiceId nor do they set the SerialPort UUID as ServiceId. Often they
provide the SerialPort uuid via the ServiceClassIds only.
This patch ensures that the internal service discovery is started if the
ServiceId is known or if the ServiceClassIds contains the SerialPort
uuid.
Furthermore the internal discovery did not apply the complete uuid filter.
If a ServiceClassId was added then the ServiceId was discarded which
could lead to services not being found.
Task-number: QTBUG-47593
Change-Id: Ia6e52d1a9def0f770080fd70e2b6deb40e69fa69
Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
Reviewed-by: Christian Kandeler <christian.kandeler@theqtcompany.com>
Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
-rw-r--r-- | src/bluetooth/qbluetoothsocket.cpp | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/src/bluetooth/qbluetoothsocket.cpp b/src/bluetooth/qbluetoothsocket.cpp index f6cbf4e9..7adb56b4 100644 --- a/src/bluetooth/qbluetoothsocket.cpp +++ b/src/bluetooth/qbluetoothsocket.cpp @@ -348,7 +348,8 @@ void QBluetoothSocket::connectToService(const QBluetoothServiceInfo &service, Op d->connectToService(service.device().address(), service.serverChannel(), openMode); } else { // try doing service discovery to see if we can find the socket - if(service.serviceUuid().isNull()){ + if (service.serviceUuid().isNull() + && !service.serviceClassUuids().contains(QBluetoothUuid::SerialPort)) { qCWarning(QT_BT) << "No port, no PSM, and no UUID provided, unable to connect"; return; } @@ -593,7 +594,7 @@ void QBluetoothSocket::doDeviceDiscovery(const QBluetoothServiceInfo &service, O Q_D(QBluetoothSocket); setSocketState(QBluetoothSocket::ServiceLookupState); - qCDebug(QT_BT) << "Starting discovery"; + qCDebug(QT_BT) << "Starting Bluetooth Socket discovery"; if(d->discoveryAgent) { d->discoveryAgent->stop(); @@ -610,11 +611,12 @@ void QBluetoothSocket::doDeviceDiscovery(const QBluetoothServiceInfo &service, O d->openMode = openMode; + QList<QBluetoothUuid> filterUuids = service.serviceClassUuids(); if(!service.serviceUuid().isNull()) - d->discoveryAgent->setUuidFilter(service.serviceUuid()); + filterUuids.append(service.serviceUuid()); - if(!service.serviceClassUuids().isEmpty()) - d->discoveryAgent->setUuidFilter(service.serviceClassUuids()); + if (!filterUuids.isEmpty()) + d->discoveryAgent->setUuidFilter(filterUuids); // we have to ID the service somehow Q_ASSERT(!d->discoveryAgent->uuidFilter().isEmpty()); |