Skip to content

Commit

Permalink
Do not disable BLE if a fabric has not been provisioned on the device (
Browse files Browse the repository at this point in the history
…#9933)

* Check if a fabric has been provisioned before disabling BLE

* Update src/app/server/Server.cpp

Co-authored-by: Boris Zbarsky <[email protected]>

* check for network configuration as well

Co-authored-by: Boris Zbarsky <[email protected]>
  • Loading branch information
2 people authored and pull[bot] committed Sep 29, 2021
1 parent fa7453c commit 4322168
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/app/server/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,11 @@ CHIP_ERROR Server::Init(AppDelegate * delegate, uint16_t secureServicePort, uint
ChipLogProgress(AppServer, "Rendezvous and secure pairing skipped");
SuccessOrExit(err = AddTestCommissioning());
}
else if (DeviceLayer::ConnectivityMgr().IsWiFiStationProvisioned() || DeviceLayer::ConnectivityMgr().IsThreadProvisioned())
else if ((DeviceLayer::ConnectivityMgr().IsWiFiStationProvisioned() || DeviceLayer::ConnectivityMgr().IsThreadProvisioned()) &&
(GetFabricTable().FabricCount() != 0))
{
// If the network is already provisioned, proactively disable BLE advertisement.
ChipLogProgress(AppServer, "Network already provisioned. Disabling BLE advertisement");
// The device is already commissioned, proactively disable BLE advertisement.
ChipLogProgress(AppServer, "Fabric already commissioned. Disabling BLE advertisement");
chip::DeviceLayer::ConnectivityMgr().SetBLEAdvertisingEnabled(false);
}
else
Expand Down
15 changes: 14 additions & 1 deletion src/transport/FabricTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,7 @@ CHIP_ERROR FabricTable::AddNewFabric(FabricInfo & newFabric, FabricIndex * outpu
ReturnErrorOnFailure(Store(i));
mNextAvailableFabricIndex = static_cast<FabricIndex>((i + 1) % UINT8_MAX);
*outputIndex = i;
mFabricCount++;
return CHIP_NO_ERROR;
}
}
Expand All @@ -508,6 +509,7 @@ CHIP_ERROR FabricTable::AddNewFabric(FabricInfo & newFabric, FabricIndex * outpu
ReturnErrorOnFailure(Store(i));
mNextAvailableFabricIndex = static_cast<FabricIndex>((i + 1) % UINT8_MAX);
*outputIndex = i;
mFabricCount++;
return CHIP_NO_ERROR;
}
}
Expand All @@ -532,6 +534,14 @@ CHIP_ERROR FabricTable::Delete(FabricIndex id)
ReleaseFabricIndex(id);
if (mDelegate != nullptr && fabricIsInitialized)
{
if (mFabricCount == 0)
{
ChipLogError(Discovery, "!!Trying to delete a fabric, but the current fabric count is already 0");
}
else
{
mFabricCount--;
}
ChipLogProgress(Discovery, "Fabric (%d) deleted. Calling OnFabricDeletedFromStorage", id);
mDelegate->OnFabricDeletedFromStorage(id);
}
Expand Down Expand Up @@ -561,7 +571,10 @@ CHIP_ERROR FabricTable::Init(PersistentStorageDelegate * storage)
for (FabricIndex i = kMinValidFabricIndex; i <= kMaxValidFabricIndex; i++)
{
FabricInfo * fabric = &mStates[i - kMinValidFabricIndex];
LoadFromStorage(fabric);
if (LoadFromStorage(fabric) == CHIP_NO_ERROR)
{
mFabricCount++;
}
}

return CHIP_NO_ERROR;
Expand Down
3 changes: 3 additions & 0 deletions src/transport/FabricTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,8 @@ class DLL_EXPORT FabricTable
CHIP_ERROR Init(PersistentStorageDelegate * storage);
CHIP_ERROR SetFabricDelegate(FabricTableDelegate * delegate);

uint8_t FabricCount() const { return mFabricCount; }

ConstFabricIterator cbegin() const { return ConstFabricIterator(mStates, 0, CHIP_CONFIG_MAX_DEVICE_ADMINS); }
ConstFabricIterator cend() const
{
Expand All @@ -398,6 +400,7 @@ class DLL_EXPORT FabricTable
FabricTableDelegate * mDelegate = nullptr;

FabricIndex mNextAvailableFabricIndex = kMinValidFabricIndex;
uint8_t mFabricCount = 0;
};

} // namespace Transport
Expand Down

0 comments on commit 4322168

Please sign in to comment.