summaryrefslogtreecommitdiffstats
path: root/src/bluetooth/qleadvertiser_bluez.cpp
diff options
context:
space:
mode:
authorAlex Blasche <alexander.blasche@qt.io>2017-05-12 15:42:01 +0200
committerAlex Blasche <alexander.blasche@qt.io>2017-05-15 10:45:05 +0000
commitdf6b10cb829e4d992170318fa2ed02461d8392db (patch)
tree7d4b74fe740ed42df1b3848be39c0b5c6337cf45 /src/bluetooth/qleadvertiser_bluez.cpp
parent6b3640d28f2ef47c47ada0f8d44117a1b7a28098 (diff)
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 <christian.kandeler@qt.io>
Diffstat (limited to 'src/bluetooth/qleadvertiser_bluez.cpp')
-rw-r--r--src/bluetooth/qleadvertiser_bluez.cpp16
1 files changed, 7 insertions, 9 deletions
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;
}