diff options
-rw-r--r-- | dist/changes-5.3.2 | 2 | ||||
-rw-r--r-- | src/bluetooth/qbluetoothserver.cpp | 4 | ||||
-rw-r--r-- | src/bluetooth/qbluetoothsocket.cpp | 4 | ||||
-rw-r--r-- | tests/bttestui/btlocaldevice.cpp | 22 |
4 files changed, 23 insertions, 9 deletions
diff --git a/dist/changes-5.3.2 b/dist/changes-5.3.2 index 59a52917..e700e85e 100644 --- a/dist/changes-5.3.2 +++ b/dist/changes-5.3.2 @@ -45,3 +45,5 @@ Linux ----- - Removed undesirable system header includes from the Bluez code base. + - Fixed incomplete SDP entries when using L2CP sockets and avoided + crash on client side when incomplete SDP entry is encountered. diff --git a/src/bluetooth/qbluetoothserver.cpp b/src/bluetooth/qbluetoothserver.cpp index 3123b032..667c3306 100644 --- a/src/bluetooth/qbluetoothserver.cpp +++ b/src/bluetooth/qbluetoothserver.cpp @@ -226,6 +226,8 @@ QBluetoothServiceInfo QBluetoothServer::listen(const QBluetoothUuid &uuid, const QBluetoothServiceInfo::Sequence protocolDescriptorList; QBluetoothServiceInfo::Sequence protocol; protocol << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::L2cap)); + if (d->serverType == QBluetoothServiceInfo::L2capProtocol) + protocol << QVariant::fromValue(serverPort()); protocolDescriptorList.append(QVariant::fromValue(protocol)); protocol.clear(); //! [listen] @@ -233,10 +235,10 @@ QBluetoothServiceInfo QBluetoothServer::listen(const QBluetoothUuid &uuid, const //! [listen2] protocol << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::Rfcomm)) << QVariant::fromValue(quint8(serverPort())); + protocolDescriptorList.append(QVariant::fromValue(protocol)); //! [listen2] } //! [listen3] - protocolDescriptorList.append(QVariant::fromValue(protocol)); serviceInfo.setAttribute(QBluetoothServiceInfo::ProtocolDescriptorList, protocolDescriptorList); bool result = serviceInfo.registerService(); diff --git a/src/bluetooth/qbluetoothsocket.cpp b/src/bluetooth/qbluetoothsocket.cpp index 0c514887..87456a2e 100644 --- a/src/bluetooth/qbluetoothsocket.cpp +++ b/src/bluetooth/qbluetoothsocket.cpp @@ -572,10 +572,12 @@ void QBluetoothSocket::serviceDiscovered(const QBluetoothServiceInfo &service) { Q_D(QBluetoothSocket); qCDebug(QT_BT) << "FOUND SERVICE!" << service; - if(service.protocolServiceMultiplexer() != 0 || service.serverChannel() != 0) { + if (service.protocolServiceMultiplexer() > 0 || service.serverChannel() > 0) { connectToService(service, d->openMode); d->discoveryAgent->deleteLater(); d->discoveryAgent = 0; + } else { + qCDebug(QT_BT) << "Could not find port/psm for potential remote service"; } } diff --git a/tests/bttestui/btlocaldevice.cpp b/tests/bttestui/btlocaldevice.cpp index 8c85599f..a14709ee 100644 --- a/tests/bttestui/btlocaldevice.cpp +++ b/tests/bttestui/btlocaldevice.cpp @@ -49,6 +49,9 @@ //same uuid as examples/bluetooth/btchat #define TEST_SERVICE_UUID "e8e10f95-1a70-4b27-9ccf-02010264e9c8" +#define SOCKET_PROTOCOL QBluetoothServiceInfo::RfcommProtocol +//#define SOCKET_PROTOCOL QBluetoothServiceInfo::L2capProtocol + BtLocalDevice::BtLocalDevice(QObject *parent) : QObject(parent) { @@ -87,7 +90,7 @@ BtLocalDevice::BtLocalDevice(QObject *parent) : connect(serviceAgent, SIGNAL(error(QBluetoothServiceDiscoveryAgent::Error)), this, SLOT(serviceDiscoveryError(QBluetoothServiceDiscoveryAgent::Error))); - socket = new QBluetoothSocket(this); + socket = new QBluetoothSocket(SOCKET_PROTOCOL, this); connect(socket, SIGNAL(stateChanged(QBluetoothSocket::SocketState)), this, SLOT(socketStateChanged(QBluetoothSocket::SocketState))); connect(socket, SIGNAL(error(QBluetoothSocket::SocketError)), @@ -96,7 +99,7 @@ BtLocalDevice::BtLocalDevice(QObject *parent) : connect(socket, SIGNAL(disconnected()), this, SLOT(socketDisconnected())); connect(socket, SIGNAL(readyRead()), this, SLOT(readData())); - server = new QBluetoothServer(QBluetoothServiceInfo::RfcommProtocol, this); + server = new QBluetoothServer(SOCKET_PROTOCOL, this); server->setSecurityFlags(QBluetooth::NoSecurity); connect(server, SIGNAL(newConnection()), this, SLOT(serverNewConnection())); connect(server, SIGNAL(error(QBluetoothServer::Error)), @@ -537,16 +540,21 @@ void BtLocalDevice::serverListenPort() QBluetoothServiceInfo::Sequence protocolDescriptorList; QBluetoothServiceInfo::Sequence protocol; protocol << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::L2cap)); + if (server->serverType() == QBluetoothServiceInfo::L2capProtocol) + protocol << QVariant::fromValue(server->serverPort()); protocolDescriptorList.append(QVariant::fromValue(protocol)); - protocol.clear(); - protocol << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::Rfcomm)) - << QVariant::fromValue(quint8(server->serverPort())); - protocolDescriptorList.append(QVariant::fromValue(protocol)); + + if (server->serverType() == QBluetoothServiceInfo::RfcommProtocol) { + protocol.clear(); + protocol << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::Rfcomm)) + << QVariant::fromValue(quint8(server->serverPort())); + protocolDescriptorList.append(QVariant::fromValue(protocol)); + } serviceInfo.setAttribute(QBluetoothServiceInfo::ProtocolDescriptorList, protocolDescriptorList); //Register service - qDebug() << "###### Registering service on" << localDevice->address().toString(); + qDebug() << "###### Registering service on" << localDevice->address().toString() << server->serverPort(); bool result = serviceInfo.registerService(localDevice->address()); if (!result) { server->close(); |