Skip to content

Commit

Permalink
Allow commissioning window to work even if BLE advertising is not sup…
Browse files Browse the repository at this point in the history
…ported (#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.
  • Loading branch information
bzbarsky-apple authored and pull[bot] committed Sep 13, 2023
1 parent f0b4a3d commit 5410649
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/app/server/CommissioningWindowManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions src/include/platform/ConnectivityManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 5410649

Please sign in to comment.