Skip to content

Commit 4fef04b

Browse files
[ICD]Convert the ICD DNS advertiser variable from optional bool to an enum class (#32080)
* Convert the ICD DNS advertiser variable from optional bool to an enum class * Apply suggestions from code review Co-authored-by: mkardous-silabs <84793247+mkardous-silabs@users.noreply.github.com> * default mICDModeAdvertise to kNone --------- Co-authored-by: mkardous-silabs <84793247+mkardous-silabs@users.noreply.github.com>
1 parent f216481 commit 4fef04b

File tree

6 files changed

+39
-25
lines changed

6 files changed

+39
-25
lines changed

src/app/server/Dnssd.cpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,21 @@ void DnssdServer::AddICDKeyToAdvertisement(AdvertisingParams & advParams)
147147
VerifyOrDieWithMsg(mICDManager != nullptr, Discovery,
148148
"Invalid pointer to the ICDManager which is required for the LIT operating mode");
149149

150+
Dnssd::ICDModeAdvertise ICDModeToAdvertise = Dnssd::ICDModeAdvertise::kNone;
150151
// Only advertise the ICD key if the device can operate as a LIT
151152
if (mICDManager->SupportsFeature(Clusters::IcdManagement::Feature::kLongIdleTimeSupport))
152153
{
153-
advParams.SetICDOperatingAsLIT(Optional<bool>(mICDManager->GetICDMode() == ICDConfigurationData::ICDMode::LIT));
154+
if (mICDManager->GetICDMode() == ICDConfigurationData::ICDMode::LIT)
155+
{
156+
ICDModeToAdvertise = Dnssd::ICDModeAdvertise::kLIT;
157+
}
158+
else
159+
{
160+
ICDModeToAdvertise = Dnssd::ICDModeAdvertise::kSIT;
161+
}
154162
}
163+
164+
advParams.SetICDModeToAdvertise(ICDModeToAdvertise);
155165
}
156166
#endif
157167

src/lib/dnssd/Advertiser.h

+11-4
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ enum class CommissioningMode
4848
kEnabledEnhanced // Enhanced Commissioning Mode, CM=2 in DNS-SD key/value pairs
4949
};
5050

51+
enum class ICDModeAdvertise : uint8_t
52+
{
53+
kNone, // The device does not support the LIT feature-set. No ICD= key is advertised in DNS-SD.
54+
kSIT, // The ICD supports the LIT feature-set, but is currently operating as a SIT. ICD=0 in DNS-SD key/value pairs.
55+
kLIT, // The ICD is currently operating as a LIT. ICD=1 in DNS-SD key/value pairs.
56+
};
57+
5158
template <class Derived>
5259
class BaseAdvertisingParams
5360
{
@@ -103,12 +110,12 @@ class BaseAdvertisingParams
103110
}
104111
Optional<bool> GetTcpSupported() const { return mTcpSupported; }
105112

106-
Derived & SetICDOperatingAsLIT(Optional<bool> operatesAsLIT)
113+
Derived & SetICDModeToAdvertise(ICDModeAdvertise operatingMode)
107114
{
108-
mICDOperatesAsLIT = operatesAsLIT;
115+
mICDModeAdvertise = operatingMode;
109116
return *reinterpret_cast<Derived *>(this);
110117
}
111-
Optional<bool> GetICDOperatingAsLIT() const { return mICDOperatesAsLIT; }
118+
ICDModeAdvertise GetICDModeToAdvertise() const { return mICDModeAdvertise; }
112119

113120
private:
114121
uint16_t mPort = CHIP_PORT;
@@ -118,7 +125,7 @@ class BaseAdvertisingParams
118125
size_t mMacLength = 0;
119126
Optional<ReliableMessageProtocolConfig> mLocalMRPConfig;
120127
Optional<bool> mTcpSupported;
121-
Optional<bool> mICDOperatesAsLIT;
128+
ICDModeAdvertise mICDModeAdvertise = ICDModeAdvertise::kNone;
122129
};
123130

124131
/// Defines parameters required for advertising a CHIP node

src/lib/dnssd/Advertiser_ImplMinimalMdns.cpp

+5-9
Original file line numberDiff line numberDiff line change
@@ -232,13 +232,9 @@ class AdvertiserMinMdns : public ServiceAdvertiser,
232232
{
233233
auto mrp = optionalMrp.Value();
234234

235-
#if CHIP_CONFIG_ENABLE_ICD_SERVER
236-
// An ICD operating as a LIT should not advertise its slow polling interval.
237-
// When the ICD doesn't support the LIT feature, it doesn't set nor advertise the GetICDOperatingAsLIT entry.
238-
// Therefore when GetICDOperatingAsLIT has no value or a value of 0, we advertise the slow polling interval
239-
// otherwise we don't include the SII key in the advertisement.
240-
if (!params.GetICDOperatingAsLIT().ValueOr(false))
241-
#endif
235+
// An ICD operating as a LIT shall not advertise its slow polling interval.
236+
// Don't include the SII key in the advertisement when operating as so.
237+
if (params.GetICDModeToAdvertise() != ICDModeAdvertise::kLIT)
242238
{
243239
if (mrp.mIdleRetransTimeout > kMaxRetryInterval)
244240
{
@@ -290,11 +286,11 @@ class AdvertiserMinMdns : public ServiceAdvertiser,
290286
CHIP_ERROR_INVALID_STRING_LENGTH);
291287
txtFields[numTxtFields++] = storage.tcpSupportedBuf;
292288
}
293-
if (params.GetICDOperatingAsLIT().HasValue())
289+
if (params.GetICDModeToAdvertise() != ICDModeAdvertise::kNone)
294290
{
295291
size_t writtenCharactersNumber =
296292
static_cast<size_t>(snprintf(storage.operatingICDAsLITBuf, sizeof(storage.operatingICDAsLITBuf), "ICD=%d",
297-
params.GetICDOperatingAsLIT().Value()));
293+
(params.GetICDModeToAdvertise() == ICDModeAdvertise::kLIT)));
298294
VerifyOrReturnError((writtenCharactersNumber > 0) && (writtenCharactersNumber < sizeof(storage.operatingICDAsLITBuf)),
299295
CHIP_ERROR_INVALID_STRING_LENGTH);
300296
txtFields[numTxtFields++] = storage.operatingICDAsLITBuf;

src/lib/dnssd/Discovery_ImplPlatform.cpp

+8-7
Original file line numberDiff line numberDiff line change
@@ -213,19 +213,20 @@ CHIP_ERROR CopyTxtRecord(TxtFieldKey key, char * buffer, size_t bufferLen, const
213213
case TxtFieldKey::kSessionIdleInterval:
214214
#if CHIP_CONFIG_ENABLE_ICD_SERVER
215215
// A ICD operating as a LIT should not advertise its slow polling interval
216-
if (params.GetICDOperatingAsLIT().HasValue() && params.GetICDOperatingAsLIT().Value())
217-
{
218-
// Returning UNINITIALIZED ensures that the SII string isn't added by the AddTxtRecord
219-
// without erroring out the action.
220-
return CHIP_ERROR_UNINITIALIZED;
221-
}
216+
// Returning UNINITIALIZED ensures that the SII string isn't added by the AddTxtRecord
217+
// without erroring out the action.
218+
VerifyOrReturnError(params.GetICDModeToAdvertise() != ICDModeAdvertise::kLIT, CHIP_ERROR_UNINITIALIZED);
222219
FALLTHROUGH;
223220
#endif
224221
case TxtFieldKey::kSessionActiveInterval:
225222
case TxtFieldKey::kSessionActiveThreshold:
226223
return CopyTextRecordValue(buffer, bufferLen, params.GetLocalMRPConfig(), key);
227224
case TxtFieldKey::kLongIdleTimeICD:
228-
return CopyTextRecordValue(buffer, bufferLen, params.GetICDOperatingAsLIT());
225+
// The ICD key is only added to the advertissment when the device supports the ICD LIT feature-set.
226+
// Return UNINITIALIZED when the operating mode is kNone to ensure that the ICD string isn't added
227+
// by the AddTxtRecord without erroring out the action.
228+
VerifyOrReturnError(params.GetICDModeToAdvertise() != ICDModeAdvertise::kNone, CHIP_ERROR_UNINITIALIZED);
229+
return CopyTextRecordValue(buffer, bufferLen, (params.GetICDModeToAdvertise() == ICDModeAdvertise::kLIT));
229230
default:
230231
return CHIP_ERROR_INVALID_ARGUMENT;
231232
}

src/lib/dnssd/minimal_mdns/tests/TestAdvertiser.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ CommissionAdvertisingParameters commissionableNodeParamsLargeEnhanced =
180180
.SetPairingInstruction(chip::Optional<const char *>("Pair me"))
181181
.SetProductId(chip::Optional<uint16_t>(897))
182182
.SetRotatingDeviceId(chip::Optional<const char *>("id_that_spins"))
183-
.SetICDOperatingAsLIT(chip::Optional<bool>(false))
183+
.SetICDModeToAdvertise(ICDModeAdvertise::kSIT)
184184
// 3600005 is more than the max so should be adjusted down
185185
.SetLocalMRPConfig(Optional<ReliableMessageProtocolConfig>::Value(3600000_ms32, 3600005_ms32, 65535_ms16));
186186
QNamePart txtCommissionableNodeParamsLargeEnhancedParts[] = { "D=22", "VP=555+897", "CM=2", "DT=70000",
@@ -204,7 +204,7 @@ CommissionAdvertisingParameters commissionableNodeParamsEnhancedAsICDLIT =
204204
.SetPairingHint(chip::Optional<uint16_t>(3))
205205
.SetPairingInstruction(chip::Optional<const char *>("Pair me"))
206206
.SetProductId(chip::Optional<uint16_t>(897))
207-
.SetICDOperatingAsLIT(chip::Optional<bool>(true))
207+
.SetICDModeToAdvertise(ICDModeAdvertise::kLIT)
208208
.SetLocalMRPConfig(Optional<ReliableMessageProtocolConfig>::Value(3600000_ms32, 3600000_ms32, 65535_ms16));
209209
// With ICD Operation as LIT, SII key will not be added to the advertisement
210210
QNamePart txtCommissionableNodeParamsEnhancedAsICDLITParts[] = { "D=22", "VP=555+897", "CM=2", "DT=70000",

src/lib/dnssd/platform/tests/TestPlatform.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ OperationalAdvertisingParameters operationalParams2 =
5353
.SetPort(CHIP_PORT)
5454
.EnableIpV4(true)
5555
.SetLocalMRPConfig(Optional<ReliableMessageProtocolConfig>::Value(32_ms32, 30_ms32, 10_ms16)) // SII and SAI to match below
56-
.SetICDOperatingAsLIT(Optional<bool>(false));
56+
.SetICDModeToAdvertise(ICDModeAdvertise::kSIT);
5757
test::ExpectedCall operationalCall2 = test::ExpectedCall()
5858
.SetProtocol(DnssdServiceProtocol::kDnssdProtocolTcp)
5959
.SetServiceName("_matter")
@@ -95,7 +95,7 @@ CommissionAdvertisingParameters commissionableNodeParamsLargeBasic =
9595
.SetPairingInstruction(Optional<const char *>("Pair me"))
9696
.SetProductId(Optional<uint16_t>(897))
9797
.SetRotatingDeviceId(Optional<const char *>("id_that_spins"))
98-
.SetICDOperatingAsLIT(Optional<bool>(false))
98+
.SetICDModeToAdvertise(ICDModeAdvertise::kSIT)
9999
// 3600005 is over the max, so this should be adjusted by the platform
100100
.SetLocalMRPConfig(Optional<ReliableMessageProtocolConfig>::Value(3600000_ms32, 3600005_ms32, 65535_ms16));
101101

0 commit comments

Comments
 (0)