From e8c2a6f3859a64ffc10f5aae0d3ae299087bc6e5 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Thu, 2 Jun 2022 20:46:19 -0400 Subject: [PATCH] Allow commissioning window to work even if BLE advertising is not supported (#19121) * Allow commissioning window to work even if BLE advertising is not supported. An application might be built against an CHIP library that has BLE support compieled in (e.g. so it can do discovery over BLE) but does not support commissionable advertising over BLE. In that case, we should not fail to open a commissioning window just because we can't advertise over BLE; we can still advertise over DNS-SD. * Address review comments. --- src/app/server/CommissioningWindowManager.cpp | 15 +++++++++++++-- src/include/platform/ConnectivityManager.h | 6 ++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/app/server/CommissioningWindowManager.cpp b/src/app/server/CommissioningWindowManager.cpp index 98f59cbb2ae1bd..63528b8aaceb4f 100644 --- a/src/app/server/CommissioningWindowManager.cpp +++ b/src/app/server/CommissioningWindowManager.cpp @@ -354,7 +354,15 @@ CHIP_ERROR CommissioningWindowManager::StartAdvertisement() #if CONFIG_NETWORK_LAYER_BLE if (mIsBLE) { - ReturnErrorOnFailure(chip::DeviceLayer::ConnectivityMgr().SetBLEAdvertisingEnabled(true)); + CHIP_ERROR err = chip::DeviceLayer::ConnectivityMgr().SetBLEAdvertisingEnabled(true); + // BLE advertising may just not be supported. That should not prevent + // us from opening a commissioning window and advertising over IP. + if (err == CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE) + { + ChipLogProgress(AppServer, "BLE networking available but BLE advertising is not supported"); + err = CHIP_NO_ERROR; + } + ReturnErrorOnFailure(err); } #endif // CONFIG_NETWORK_LAYER_BLE @@ -405,7 +413,10 @@ CHIP_ERROR CommissioningWindowManager::StopAdvertisement(bool aShuttingDown) #if CONFIG_NETWORK_LAYER_BLE if (mIsBLE) { - ReturnErrorOnFailure(chip::DeviceLayer::ConnectivityMgr().SetBLEAdvertisingEnabled(false)); + // Ignore errors from SetBLEAdvertisingEnabled (which could be due to + // BLE advertising not being supported at all). Our commissioning + // window is now closed and we need to notify our delegate of that. + (void) chip::DeviceLayer::ConnectivityMgr().SetBLEAdvertisingEnabled(false); } #endif // CONFIG_NETWORK_LAYER_BLE diff --git a/src/include/platform/ConnectivityManager.h b/src/include/platform/ConnectivityManager.h index 105f70a74ee506..a44b1c53321a96 100644 --- a/src/include/platform/ConnectivityManager.h +++ b/src/include/platform/ConnectivityManager.h @@ -221,6 +221,12 @@ class ConnectivityManager CHIPoBLEServiceMode GetCHIPoBLEServiceMode(); CHIP_ERROR SetCHIPoBLEServiceMode(CHIPoBLEServiceMode val); bool IsBLEAdvertisingEnabled(); + /** + * Enable or disable BLE advertising. + * + * @return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE if BLE advertising is not + * supported or other error on other failures. + */ CHIP_ERROR SetBLEAdvertisingEnabled(bool val); bool IsBLEAdvertising(); CHIP_ERROR SetBLEAdvertisingMode(BLEAdvertisingMode mode);