summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2020-10-23 06:45:11 +0200
committerSven Gothel <[email protected]>2020-10-23 06:45:11 +0200
commita698ecf7f3e24e8769bab12d80dcdbb36dab8b1d (patch)
tree2d9c32db259ae35d41ce47696e5bbb80881294fb
parent49186b1b6faa8e3215b27c2e607fa37d972c96dc (diff)
More graceful takedown @ powered-off: Don't attempt futile HCI disconnect (DBTDevice) or stopDiscovery (DBTAdapter) commands
Note: stopDiscovery and disconnected events will be sent!
-rw-r--r--src/direct_bt/DBTAdapter.cpp14
-rw-r--r--src/direct_bt/DBTDevice.cpp9
2 files changed, 18 insertions, 5 deletions
diff --git a/src/direct_bt/DBTAdapter.cpp b/src/direct_bt/DBTAdapter.cpp
index c317af20..8c61eda6 100644
--- a/src/direct_bt/DBTAdapter.cpp
+++ b/src/direct_bt/DBTAdapter.cpp
@@ -263,8 +263,9 @@ void DBTAdapter::poweredOff() noexcept {
DBG_PRINT("DBTAdapter::poweredOff: ... %p %s", this, toString(false).c_str());
keep_le_scan_alive = false;
- // Removes all device references from the lists: connectedDevices, discoveredDevices, sharedDevices
stopDiscovery();
+
+ // Removes all device references from the lists: connectedDevices, discoveredDevices, sharedDevices
disconnectAllDevices();
removeDiscoveredDevices();
@@ -450,7 +451,7 @@ HCIStatusCode DBTAdapter::startDiscovery(const bool keepAlive, const HCILEOwnAdd
if( !isEnabled() ) {
WARN_PRINT("DBTAdapter::startDiscovery: Adapter not enabled/powered: %s", toString().c_str());
- return HCIStatusCode::INTERNAL_FAILURE;
+ return HCIStatusCode::UNSPECIFIED_ERROR;
}
const std::lock_guard<std::mutex> lock(mtx_discovery); // RAII-style acquire and relinquish via destructor
@@ -547,9 +548,16 @@ HCIStatusCode DBTAdapter::stopDiscovery() noexcept {
}
HCIStatusCode status;
+ if( !isPowered() ) {
+ WARN_PRINT("DBTAdapter::stopDiscovery: Powered off: %s", toString().c_str());
+ hci.setCurrentScanType(ScanType::NONE);
+ currentMetaScanType = ScanType::NONE;
+ status = HCIStatusCode::UNSPECIFIED_ERROR;
+ goto exit;
+ }
if( !hci.isOpen() ) {
ERR_PRINT("DBTAdapter::stopDiscovery: HCI closed: %s", toString().c_str());
- status = HCIStatusCode::INTERNAL_FAILURE;
+ status = HCIStatusCode::UNSPECIFIED_ERROR;
goto exit;
}
diff --git a/src/direct_bt/DBTDevice.cpp b/src/direct_bt/DBTDevice.cpp
index 5c3a0603..13cc837d 100644
--- a/src/direct_bt/DBTDevice.cpp
+++ b/src/direct_bt/DBTDevice.cpp
@@ -450,9 +450,14 @@ HCIStatusCode DBTDevice::disconnect(const HCIStatusCode reason) noexcept {
goto exit;
}
+ if( !adapter.isPowered() ) {
+ WARN_PRINT("DBTDevice::disconnect: Powered off: %s", toString().c_str());
+ res = HCIStatusCode::UNSPECIFIED_ERROR; // powered-off
+ goto exit;
+ }
if( !hci.isOpen() ) {
- ERR_PRINT("DBTDevice::disconnect: Skip disconnect: HCI closed: %s", toString().c_str());
- res = HCIStatusCode::UNSPECIFIED_ERROR; // powered-off?
+ ERR_PRINT("DBTDevice::disconnect: HCI closed: %s", toString().c_str());
+ res = HCIStatusCode::UNSPECIFIED_ERROR;
goto exit;
}