From df6b10cb829e4d992170318fa2ed02461d8392db Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Fri, 12 May 2017 15:42:01 +0200 Subject: Fix readvertisement failure on peripheral restart on BlueZ When the QLowEnergyController disconnects and immediately restarts the re-advertisement, it fails when sending the OcfLeSetAdvEnable ocf command. Subsequenly an advertisement error is thrown which stops the QLowEnergyCOntroller instance itself. Starting with this patch we choose to ignore failures when trying to disable advertisement. The API cannot report the error back anyway. Task-number: QTBUG-58941 Change-Id: Ifd6b43193c41e6cdc22d4876441bcdcbcc2ca7b6 Reviewed-by: Christian Kandeler --- src/bluetooth/qleadvertiser_bluez.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'src/bluetooth/qleadvertiser_bluez.cpp') diff --git a/src/bluetooth/qleadvertiser_bluez.cpp b/src/bluetooth/qleadvertiser_bluez.cpp index ff00b2b1..652d28f9 100644 --- a/src/bluetooth/qleadvertiser_bluez.cpp +++ b/src/bluetooth/qleadvertiser_bluez.cpp @@ -102,7 +102,6 @@ void QLeAdvertiserBluez::doStartAdvertising() return; } - m_disableCommandFinished = false; m_sendPowerLevel = advertisingData().includePowerLevel() || scanResponseData().includePowerLevel(); if (m_sendPowerLevel) @@ -408,14 +407,17 @@ void QLeAdvertiserBluez::handleCommandCompleted(quint16 opCode, quint8 status, if (m_pendingCommands.isEmpty()) return; const quint16 ocf = ocfFromOpCode(opCode); - if (m_pendingCommands.first().ocf != ocf) + const Command currentCmd = m_pendingCommands.first(); + if (currentCmd.ocf != ocf) return; // Not one of our commands. m_pendingCommands.takeFirst(); if (status != 0) { qCDebug(QT_BT_BLUEZ) << "command" << ocf << "failed with status" << status; - if (ocf == OcfLeSetAdvEnable && !m_disableCommandFinished && status == 0xc) { - qCDebug(QT_BT_BLUEZ) << "initial advertising disable failed, ignoring"; - m_disableCommandFinished = true; + if (ocf == OcfLeSetAdvEnable && status == 0xc && currentCmd.data == QByteArray(1, '\0')) { + // we ignore OcfLeSetAdvEnable if it tries to disable an active advertisement + // it seems the platform often automatically turns off advertisements + // subsequently the explicit stopAdvertisement call fails when re-issued + qCDebug(QT_BT_BLUEZ) << "Advertising disable failed, ignoring"; sendNextCommand(); return; } @@ -439,10 +441,6 @@ void QLeAdvertiserBluez::handleCommandCompleted(quint16 opCode, quint8 status, } queueAdvertisingCommands(); break; - case OcfLeSetAdvEnable: - if (!m_disableCommandFinished) - m_disableCommandFinished = true; - break; default: break; } -- cgit v1.2.3