diff options
-rw-r--r-- | src/direct_bt/DBTAdapter.cpp | 14 | ||||
-rw-r--r-- | src/direct_bt/DBTDevice.cpp | 9 |
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; } |