From 3e7befcd5801645fa4f7f84d5f1805ae615f28c3 Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Wed, 27 Apr 2016 10:44:18 +0200 Subject: 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 Reviewed-by: Christian Kandeler Reviewed-by: Alex Blasche --- src/bluetooth/qbluetoothsocket.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src/bluetooth/qbluetoothsocket.cpp') 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 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()); -- cgit v1.2.3