Skip to content

Commit

Permalink
Add a way to dynamically change whether a node identity should be adv…
Browse files Browse the repository at this point in the history
…ertised.

In some cases, a node may need to stop or restart advertising its identity
without actually tearing down the relevant CHIPDeviceController.
  • Loading branch information
bzbarsky-apple committed Sep 17, 2024
1 parent cc5ea19 commit f6e2216
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/credentials/FabricTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2164,4 +2164,17 @@ CHIP_ERROR FabricTable::SetFabricIndexForNextAddition(FabricIndex fabricIndex)
return CHIP_NO_ERROR;
}

CHIP_ERROR FabricTable::SetShouldAdvertiseIdentity(FabricIndex fabricIndex, AdvertiseIdentity advertiseIdentity)
{
VerifyOrReturnError(IsValidFabricIndex(fabricIndex), CHIP_ERROR_INVALID_FABRIC_INDEX);

FabricInfo * fabricInfo = GetMutableFabricByIndex(fabricIndex);
bool fabricIsInitialized = (fabricInfo != nullptr) && fabricInfo->IsInitialized();
VerifyOrReturnError(fabricIsInitialized, CHIP_ERROR_INVALID_FABRIC_INDEX);

fabricInfo->SetShouldAdvertiseIdentity(advertiseIdentity == AdvertiseIdentity::Yes);

return CHIP_NO_ERROR;
}

} // namespace chip
14 changes: 14 additions & 0 deletions src/credentials/FabricTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ class DLL_EXPORT FabricInfo
mNodeId = kUndefinedNodeId;
}

void SetShouldAdvertiseIdentity(bool advertiseIdentity) { mShouldAdvertiseIdentity = advertiseIdentity; }

static constexpr size_t MetadataTLVMaxSize()
{
return TLV::EstimateStructOverhead(sizeof(uint16_t), kFabricLabelMaxLengthInBytes);
Expand Down Expand Up @@ -1027,6 +1029,18 @@ class DLL_EXPORT FabricTable
*/
CHIP_ERROR SetFabricIndexForNextAddition(FabricIndex fabricIndex);

/**
* @brief Set the advertising behavior for the fabric identified by `fabricIndex`.
*
* It is the caller's responsibility to actually restart DNS-SD advertising
* as needed after updating this state.
*
* @param fabricIndex - Fabric Index for which to set the label
* @param advertiseIdentity - whether the identity for this fabric should be advertised.
* @retval CHIP_ERROR_INVALID_FABRIC_INDEX if fabricIndex does not refer to a fabric in the table
*/
CHIP_ERROR SetShouldAdvertiseIdentity(FabricIndex fabricIndex, AdvertiseIdentity advertiseIdentity);

private:
enum class StateFlags : uint16_t
{
Expand Down

0 comments on commit f6e2216

Please sign in to comment.