Skip to content

Commit f6e2216

Browse files
Add a way to dynamically change whether a node identity should be advertised.
In some cases, a node may need to stop or restart advertising its identity without actually tearing down the relevant CHIPDeviceController.
1 parent cc5ea19 commit f6e2216

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/credentials/FabricTable.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -2164,4 +2164,17 @@ CHIP_ERROR FabricTable::SetFabricIndexForNextAddition(FabricIndex fabricIndex)
21642164
return CHIP_NO_ERROR;
21652165
}
21662166

2167+
CHIP_ERROR FabricTable::SetShouldAdvertiseIdentity(FabricIndex fabricIndex, AdvertiseIdentity advertiseIdentity)
2168+
{
2169+
VerifyOrReturnError(IsValidFabricIndex(fabricIndex), CHIP_ERROR_INVALID_FABRIC_INDEX);
2170+
2171+
FabricInfo * fabricInfo = GetMutableFabricByIndex(fabricIndex);
2172+
bool fabricIsInitialized = (fabricInfo != nullptr) && fabricInfo->IsInitialized();
2173+
VerifyOrReturnError(fabricIsInitialized, CHIP_ERROR_INVALID_FABRIC_INDEX);
2174+
2175+
fabricInfo->SetShouldAdvertiseIdentity(advertiseIdentity == AdvertiseIdentity::Yes);
2176+
2177+
return CHIP_NO_ERROR;
2178+
}
2179+
21672180
} // namespace chip

src/credentials/FabricTable.h

+14
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,8 @@ class DLL_EXPORT FabricInfo
212212
mNodeId = kUndefinedNodeId;
213213
}
214214

215+
void SetShouldAdvertiseIdentity(bool advertiseIdentity) { mShouldAdvertiseIdentity = advertiseIdentity; }
216+
215217
static constexpr size_t MetadataTLVMaxSize()
216218
{
217219
return TLV::EstimateStructOverhead(sizeof(uint16_t), kFabricLabelMaxLengthInBytes);
@@ -1027,6 +1029,18 @@ class DLL_EXPORT FabricTable
10271029
*/
10281030
CHIP_ERROR SetFabricIndexForNextAddition(FabricIndex fabricIndex);
10291031

1032+
/**
1033+
* @brief Set the advertising behavior for the fabric identified by `fabricIndex`.
1034+
*
1035+
* It is the caller's responsibility to actually restart DNS-SD advertising
1036+
* as needed after updating this state.
1037+
*
1038+
* @param fabricIndex - Fabric Index for which to set the label
1039+
* @param advertiseIdentity - whether the identity for this fabric should be advertised.
1040+
* @retval CHIP_ERROR_INVALID_FABRIC_INDEX if fabricIndex does not refer to a fabric in the table
1041+
*/
1042+
CHIP_ERROR SetShouldAdvertiseIdentity(FabricIndex fabricIndex, AdvertiseIdentity advertiseIdentity);
1043+
10301044
private:
10311045
enum class StateFlags : uint16_t
10321046
{

0 commit comments

Comments
 (0)