Skip to content

Commit 47bd885

Browse files
[ICD]Add SAT Common TXT key (#28123)
* Add SAT key to the commissionable node adv * Add tests fix some issues * Update after rebase * Fix lint complaint * Fix Darwin Tidy issue, attempt to try Linux mdnsPlatform.Advertise tests * address naming comments * Restyled by clang-format * Fix unit test on linux * address comment --------- Co-authored-by: Restyled.io <[email protected]>
1 parent 37d9608 commit 47bd885

27 files changed

+284
-109
lines changed

src/app/ReadClient.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,7 @@ CHIP_ERROR ReadClient::ComputeLivenessCheckTimerTimeout(System::Clock::Timeout *
832832
const auto & ourMrpConfig = GetDefaultMRPConfig();
833833
auto publisherTransmissionTimeout =
834834
GetRetransmissionTimeout(ourMrpConfig.mActiveRetransTimeout, ourMrpConfig.mIdleRetransTimeout,
835-
System::SystemClock().GetMonotonicTimestamp(), Transport::kMinActiveTime);
835+
System::SystemClock().GetMonotonicTimestamp(), ourMrpConfig.mActiveThresholdTime);
836836
*aTimeout = System::Clock::Seconds16(mMaxInterval) + publisherTransmissionTimeout;
837837
return CHIP_NO_ERROR;
838838
}

src/app/icd/ICDManager.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ using namespace chip::app;
3535
using namespace chip::app::Clusters;
3636
using namespace chip::app::Clusters::IcdManagement;
3737

38-
void ICDManager::ICDManager::Init(PersistentStorageDelegate * storage, FabricTable * fabricTable)
38+
void ICDManager::Init(PersistentStorageDelegate * storage, FabricTable * fabricTable)
3939
{
4040
VerifyOrDie(storage != nullptr);
4141
VerifyOrDie(fabricTable != nullptr);
@@ -44,11 +44,12 @@ void ICDManager::ICDManager::Init(PersistentStorageDelegate * storage, FabricTab
4444

4545
uint32_t activeModeInterval = IcdManagementServer::GetInstance().GetActiveModeInterval();
4646
VerifyOrDie(kFastPollingInterval.count() < activeModeInterval);
47+
4748
UpdateIcdMode();
4849
UpdateOperationState(OperationalState::ActiveMode);
4950
}
5051

51-
void ICDManager::ICDManager::Shutdown()
52+
void ICDManager::Shutdown()
5253
{
5354
// cancel any running timer of the icd
5455
DeviceLayer::SystemLayer().CancelTimer(OnIdleModeDone, this);

src/controller/tests/data_model/TestRead.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -4651,7 +4651,7 @@ System::Clock::Timeout TestReadInteraction::ComputeSubscriptionTimeout(System::C
46514651
const auto & ourMrpConfig = GetDefaultMRPConfig();
46524652
auto publisherTransmissionTimeout =
46534653
GetRetransmissionTimeout(ourMrpConfig.mActiveRetransTimeout, ourMrpConfig.mIdleRetransTimeout,
4654-
System::SystemClock().GetMonotonicTimestamp(), Transport::kMinActiveTime);
4654+
System::SystemClock().GetMonotonicTimestamp(), ourMrpConfig.mActiveThresholdTime);
46554655

46564656
return publisherTransmissionTimeout + aMaxInterval + System::Clock::Milliseconds32(1000);
46574657
}

src/lib/address_resolve/tool.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class PrintOutNodeListener : public chip::AddressResolve::NodeListener
5959
ChipLogProgress(Discovery, " Supports TCP: %s", result.supportsTcp ? "YES" : "NO");
6060
ChipLogProgress(Discovery, " MRP IDLE retransmit timeout: %u ms", result.mrpRemoteConfig.mIdleRetransTimeout.count());
6161
ChipLogProgress(Discovery, " MRP ACTIVE retransmit timeout: %u ms", result.mrpRemoteConfig.mActiveRetransTimeout.count());
62+
ChipLogProgress(Discovery, " MRP ACTIVE Threshold timet: %u ms", result.mrpRemoteConfig.mActiveThresholdTime.count());
6263
NotifyDone();
6364
}
6465

src/lib/dnssd/Advertiser_ImplMinimalMdns.cpp

+21-8
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,11 @@ class AdvertiserMinMdns : public ServiceAdvertiser,
213213
struct CommonTxtEntryStorage
214214
{
215215
// +2 for all to account for '=' and terminating nullchar
216-
char sleepyIdleIntervalBuf[KeySize(TxtFieldKey::kSleepyIdleInterval) + ValSize(TxtFieldKey::kSleepyIdleInterval) + 2];
217-
char sleepyActiveIntervalBuf[KeySize(TxtFieldKey::kSleepyActiveInterval) + ValSize(TxtFieldKey::kSleepyActiveInterval) + 2];
216+
char sessionIdleIntervalBuf[KeySize(TxtFieldKey::kSessionIdleInterval) + ValSize(TxtFieldKey::kSessionIdleInterval) + 2];
217+
char sessionActiveIntervalBuf[KeySize(TxtFieldKey::kSessionActiveInterval) + ValSize(TxtFieldKey::kSessionActiveInterval) +
218+
2];
219+
char sessionActiveThresholdBuf[KeySize(TxtFieldKey::kSessionActiveThreshold) +
220+
ValSize(TxtFieldKey::kSessionActiveThreshold) + 2];
218221
char tcpSupportedBuf[KeySize(TxtFieldKey::kTcpSupported) + ValSize(TxtFieldKey::kTcpSupported) + 2];
219222
};
220223
template <class Derived>
@@ -234,13 +237,13 @@ class AdvertiserMinMdns : public ServiceAdvertiser,
234237
mrp.mIdleRetransTimeout = kMaxRetryInterval;
235238
}
236239
size_t writtenCharactersNumber =
237-
static_cast<size_t>(snprintf(storage.sleepyIdleIntervalBuf, sizeof(storage.sleepyIdleIntervalBuf),
240+
static_cast<size_t>(snprintf(storage.sessionIdleIntervalBuf, sizeof(storage.sessionIdleIntervalBuf),
238241
"SII=%" PRIu32, mrp.mIdleRetransTimeout.count()));
239242
VerifyOrReturnError((writtenCharactersNumber > 0) &&
240-
(writtenCharactersNumber < sizeof(storage.sleepyIdleIntervalBuf)),
243+
(writtenCharactersNumber < sizeof(storage.sessionIdleIntervalBuf)),
241244
CHIP_ERROR_INVALID_STRING_LENGTH);
242245

243-
txtFields[numTxtFields++] = storage.sleepyIdleIntervalBuf;
246+
txtFields[numTxtFields++] = storage.sessionIdleIntervalBuf;
244247
}
245248

246249
{
@@ -251,12 +254,22 @@ class AdvertiserMinMdns : public ServiceAdvertiser,
251254
mrp.mActiveRetransTimeout = kMaxRetryInterval;
252255
}
253256
size_t writtenCharactersNumber =
254-
static_cast<size_t>(snprintf(storage.sleepyActiveIntervalBuf, sizeof(storage.sleepyActiveIntervalBuf),
257+
static_cast<size_t>(snprintf(storage.sessionActiveIntervalBuf, sizeof(storage.sessionActiveIntervalBuf),
255258
"SAI=%" PRIu32, mrp.mActiveRetransTimeout.count()));
256259
VerifyOrReturnError((writtenCharactersNumber > 0) &&
257-
(writtenCharactersNumber < sizeof(storage.sleepyActiveIntervalBuf)),
260+
(writtenCharactersNumber < sizeof(storage.sessionActiveIntervalBuf)),
258261
CHIP_ERROR_INVALID_STRING_LENGTH);
259-
txtFields[numTxtFields++] = storage.sleepyActiveIntervalBuf;
262+
txtFields[numTxtFields++] = storage.sessionActiveIntervalBuf;
263+
}
264+
265+
{
266+
size_t writtenCharactersNumber =
267+
static_cast<size_t>(snprintf(storage.sessionActiveThresholdBuf, sizeof(storage.sessionActiveThresholdBuf),
268+
"SAT=%u", mrp.mActiveThresholdTime.count()));
269+
VerifyOrReturnError((writtenCharactersNumber > 0) &&
270+
(writtenCharactersNumber < sizeof(storage.sessionActiveThresholdBuf)),
271+
CHIP_ERROR_INVALID_STRING_LENGTH);
272+
txtFields[numTxtFields++] = storage.sessionActiveThresholdBuf;
260273
}
261274
}
262275
if (params.GetTcpSupported().HasValue())

src/lib/dnssd/Discovery_ImplPlatform.cpp

+30-15
Original file line numberDiff line numberDiff line change
@@ -252,20 +252,32 @@ CHIP_ERROR CopyTextRecordValue(char * buffer, size_t bufferLen, chip::Optional<u
252252
}
253253

254254
CHIP_ERROR CopyTextRecordValue(char * buffer, size_t bufferLen, const chip::Optional<ReliableMessageProtocolConfig> optional,
255-
bool isIdle)
255+
TxtFieldKey key)
256256
{
257+
VerifyOrReturnError((key == TxtFieldKey::kSessionIdleInterval || key == TxtFieldKey::kSessionActiveInterval ||
258+
key == TxtFieldKey::kSessionActiveThreshold),
259+
CHIP_ERROR_INVALID_ARGUMENT);
257260
VerifyOrReturnError(optional.HasValue(), CHIP_ERROR_WELL_UNINITIALIZED);
258261

259-
auto retryInterval = isIdle ? optional.Value().mIdleRetransTimeout : optional.Value().mActiveRetransTimeout;
260-
261-
if (retryInterval > kMaxRetryInterval)
262+
CHIP_ERROR err;
263+
if (key == TxtFieldKey::kSessionActiveThreshold)
262264
{
263-
ChipLogProgress(Discovery, "MRP retry interval %s value exceeds allowed range of 1 hour, using maximum available",
264-
isIdle ? "idle" : "active");
265-
retryInterval = kMaxRetryInterval;
265+
err = CopyTextRecordValue(buffer, bufferLen, optional.Value().mActiveThresholdTime.count());
266+
}
267+
else
268+
{
269+
bool isIdle = (key == TxtFieldKey::kSessionIdleInterval);
270+
auto retryInterval = isIdle ? optional.Value().mIdleRetransTimeout : optional.Value().mActiveRetransTimeout;
271+
if (retryInterval > kMaxRetryInterval)
272+
{
273+
ChipLogProgress(Discovery, "MRP retry interval %s value exceeds allowed range of 1 hour, using maximum available",
274+
isIdle ? "idle" : "active");
275+
retryInterval = kMaxRetryInterval;
276+
}
277+
err = CopyTextRecordValue(buffer, bufferLen, retryInterval.count());
266278
}
267279

268-
return CopyTextRecordValue(buffer, bufferLen, retryInterval.count());
280+
return err;
269281
}
270282

271283
template <class T>
@@ -275,9 +287,10 @@ CHIP_ERROR CopyTxtRecord(TxtFieldKey key, char * buffer, size_t bufferLen, const
275287
{
276288
case TxtFieldKey::kTcpSupported:
277289
return CopyTextRecordValue(buffer, bufferLen, params.GetTcpSupported());
278-
case TxtFieldKey::kSleepyIdleInterval:
279-
case TxtFieldKey::kSleepyActiveInterval:
280-
return CopyTextRecordValue(buffer, bufferLen, params.GetLocalMRPConfig(), key == TxtFieldKey::kSleepyIdleInterval);
290+
case TxtFieldKey::kSessionIdleInterval:
291+
case TxtFieldKey::kSessionActiveInterval:
292+
case TxtFieldKey::kSessionActiveThreshold:
293+
return CopyTextRecordValue(buffer, bufferLen, params.GetLocalMRPConfig(), key);
281294
default:
282295
return CHIP_ERROR_INVALID_ARGUMENT;
283296
}
@@ -552,8 +565,9 @@ CHIP_ERROR DiscoveryImplPlatform::Advertise(const OperationalAdvertisingParamete
552565
{
553566
PREPARE_RECORDS(Operational);
554567

555-
ADD_TXT_RECORD(SleepyIdleInterval);
556-
ADD_TXT_RECORD(SleepyActiveInterval);
568+
ADD_TXT_RECORD(SessionIdleInterval);
569+
ADD_TXT_RECORD(SessionActiveInterval);
570+
ADD_TXT_RECORD(SessionActiveThreshold);
557571
ADD_TXT_RECORD(TcpSupported);
558572

559573
ADD_PTR_RECORD(CompressedFabricId);
@@ -570,8 +584,9 @@ CHIP_ERROR DiscoveryImplPlatform::Advertise(const CommissionAdvertisingParameter
570584
ADD_TXT_RECORD(VendorProduct);
571585
ADD_TXT_RECORD(DeviceType);
572586
ADD_TXT_RECORD(DeviceName);
573-
ADD_TXT_RECORD(SleepyIdleInterval);
574-
ADD_TXT_RECORD(SleepyActiveInterval);
587+
ADD_TXT_RECORD(SessionIdleInterval);
588+
ADD_TXT_RECORD(SessionActiveInterval);
589+
ADD_TXT_RECORD(SessionActiveThreshold);
575590
ADD_TXT_RECORD(TcpSupported);
576591

577592
ADD_PTR_RECORD(VendorId);

src/lib/dnssd/Resolver.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ struct CommonResolutionData
5050
bool supportsTcp = false;
5151
Optional<System::Clock::Milliseconds32> mrpRetryIntervalIdle;
5252
Optional<System::Clock::Milliseconds32> mrpRetryIntervalActive;
53+
Optional<System::Clock::Milliseconds16> mrpRetryActiveThreshold;
5354

5455
CommonResolutionData() { Reset(); }
5556

@@ -59,10 +60,12 @@ struct CommonResolutionData
5960
{
6061
const ReliableMessageProtocolConfig defaultConfig = GetDefaultMRPConfig();
6162
return ReliableMessageProtocolConfig(GetMrpRetryIntervalIdle().ValueOr(defaultConfig.mIdleRetransTimeout),
62-
GetMrpRetryIntervalActive().ValueOr(defaultConfig.mActiveRetransTimeout));
63+
GetMrpRetryIntervalActive().ValueOr(defaultConfig.mActiveRetransTimeout),
64+
GetMrpRetryActiveThreshold().ValueOr(defaultConfig.mActiveThresholdTime));
6365
}
6466
Optional<System::Clock::Milliseconds32> GetMrpRetryIntervalIdle() const { return mrpRetryIntervalIdle; }
6567
Optional<System::Clock::Milliseconds32> GetMrpRetryIntervalActive() const { return mrpRetryIntervalActive; }
68+
Optional<System::Clock::Milliseconds16> GetMrpRetryActiveThreshold() const { return mrpRetryActiveThreshold; }
6669

6770
bool IsDeviceTreatedAsSleepy(const ReliableMessageProtocolConfig * defaultMRPConfig) const
6871
{

src/lib/dnssd/TxtFields.cpp

+17-2
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,18 @@ Optional<System::Clock::Milliseconds32> GetRetryInterval(const ByteSpan & value)
184184
return NullOptional;
185185
}
186186

187+
Optional<System::Clock::Milliseconds16> GetRetryActiveThreshold(const ByteSpan & value)
188+
{
189+
const auto retryInterval = MakeU16FromAsciiDecimal(value);
190+
191+
if (retryInterval == 0)
192+
{
193+
return NullOptional;
194+
}
195+
196+
return MakeOptional(System::Clock::Milliseconds16(retryInterval));
197+
}
198+
187199
TxtFieldKey GetTxtFieldKey(const ByteSpan & key)
188200
{
189201
for (auto & info : txtFieldInfo)
@@ -237,12 +249,15 @@ void FillNodeDataFromTxt(const ByteSpan & key, const ByteSpan & value, CommonRes
237249
{
238250
switch (Internal::GetTxtFieldKey(key))
239251
{
240-
case TxtFieldKey::kSleepyIdleInterval:
252+
case TxtFieldKey::kSessionIdleInterval:
241253
nodeData.mrpRetryIntervalIdle = Internal::GetRetryInterval(value);
242254
break;
243-
case TxtFieldKey::kSleepyActiveInterval:
255+
case TxtFieldKey::kSessionActiveInterval:
244256
nodeData.mrpRetryIntervalActive = Internal::GetRetryInterval(value);
245257
break;
258+
case TxtFieldKey::kSessionActiveThreshold:
259+
nodeData.mrpRetryActiveThreshold = Internal::GetRetryActiveThreshold(value);
260+
break;
246261
case TxtFieldKey::kTcpSupported:
247262
nodeData.supportsTcp = Internal::MakeBoolFromAsciiDecimal(value);
248263
break;

src/lib/dnssd/TxtFields.h

+9-6
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ namespace Dnssd {
3131
using namespace System::Clock::Literals;
3232

3333
// Operational node TXT entries
34-
static constexpr size_t kKeySleepyIdleIntervalMaxLength = 7; // [SII] 0-3600000
35-
static constexpr size_t kKeySleepyActiveIntervalMaxLength = 7; // [SAI] 0-3600000
34+
static constexpr size_t kKeySessionIdleIntervalMaxLength = 7; // [SII] 0-3600000
35+
static constexpr size_t kKeySessionActiveIntervalMaxLength = 7; // [SAI] 0-3600000
36+
static constexpr size_t kKeySessionActiveThresholdMaxLength = 5; // [SAT] 0-65535
3637
static constexpr System::Clock::Milliseconds32 kMaxRetryInterval = 3600000_ms32;
3738
static constexpr size_t kKeyTcpSupportedMaxLength = 1;
3839

@@ -66,8 +67,9 @@ enum class TxtFieldKey : uint8_t
6667
kRotatingDeviceId,
6768
kPairingInstruction,
6869
kPairingHint,
69-
kSleepyIdleInterval,
70-
kSleepyActiveInterval,
70+
kSessionIdleInterval,
71+
kSessionActiveInterval,
72+
kSessionActiveThreshold,
7173
kTcpSupported,
7274
kCount,
7375
};
@@ -92,8 +94,9 @@ constexpr const TxtFieldInfo txtFieldInfo[static_cast<size_t>(TxtFieldKey::kCoun
9294
{ TxtFieldKey::kRotatingDeviceId, kKeyRotatingDeviceIdMaxLength, "RI", TxtKeyUse::kCommission },
9395
{ TxtFieldKey::kPairingInstruction, kKeyPairingInstructionMaxLength, "PI", TxtKeyUse::kCommission },
9496
{ TxtFieldKey::kPairingHint, kKeyPairingHintMaxLength, "PH", TxtKeyUse::kCommission },
95-
{ TxtFieldKey::kSleepyIdleInterval, kKeySleepyIdleIntervalMaxLength, "SII", TxtKeyUse::kCommon },
96-
{ TxtFieldKey::kSleepyActiveInterval, kKeySleepyActiveIntervalMaxLength, "SAI", TxtKeyUse::kCommon },
97+
{ TxtFieldKey::kSessionIdleInterval, kKeySessionIdleIntervalMaxLength, "SII", TxtKeyUse::kCommon },
98+
{ TxtFieldKey::kSessionActiveInterval, kKeySessionActiveIntervalMaxLength, "SAI", TxtKeyUse::kCommon },
99+
{ TxtFieldKey::kSessionActiveThreshold, kKeySessionActiveThresholdMaxLength, "SAT", TxtKeyUse::kCommon },
97100
{ TxtFieldKey::kTcpSupported, kKeyTcpSupportedMaxLength, "T", TxtKeyUse::kCommon },
98101
};
99102
#ifdef CHIP_CONFIG_TEST

src/lib/dnssd/minimal_mdns/tests/CheckOnlyServer.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ class CheckOnlyServer : private chip::PoolImpl<ServerBase::EndpointInfo, 0, chip
311311
found = false;
312312
}
313313
};
314-
static constexpr size_t kMaxExpectedTxt = 11;
314+
static constexpr size_t kMaxExpectedTxt = 12;
315315
KV mExpectedTxt[kMaxExpectedTxt];
316316
size_t mNumExpectedTxtRecords = 0;
317317
size_t mNumReceivedTxtRecords = 0;

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

+5-4
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ OperationalAdvertisingParameters operationalParams1 =
8080
.SetPort(CHIP_PORT)
8181
.EnableIpV4(true)
8282
.SetTcpSupported(chip::Optional<bool>(false))
83-
.SetLocalMRPConfig(Optional<ReliableMessageProtocolConfig>::Value(32_ms32, 30_ms32)); // Match SII, SAI below
83+
.SetLocalMRPConfig(chip::Optional<ReliableMessageProtocolConfig>::Value(
84+
32_ms32, 30_ms32)); // Match SII, SAI. SAT not provided so it uses default 4000ms
8485
OperationalAdvertisingParameters operationalParams2 =
8586
OperationalAdvertisingParameters().SetPeerId(kPeerId2).SetMac(ByteSpan(kMac)).SetPort(CHIP_PORT).EnableIpV4(true);
8687
OperationalAdvertisingParameters operationalParams3 =
@@ -91,7 +92,7 @@ OperationalAdvertisingParameters operationalParams5 =
9192
OperationalAdvertisingParameters().SetPeerId(kPeerId5).SetMac(ByteSpan(kMac)).SetPort(CHIP_PORT).EnableIpV4(true);
9293
OperationalAdvertisingParameters operationalParams6 =
9394
OperationalAdvertisingParameters().SetPeerId(kPeerId6).SetMac(ByteSpan(kMac)).SetPort(CHIP_PORT).EnableIpV4(true);
94-
const QNamePart txtOperational1Parts[] = { "SII=32", "SAI=30", "T=0" };
95+
const QNamePart txtOperational1Parts[] = { "SII=32", "SAI=30", "SAT=4000", "T=0" };
9596
PtrResourceRecord ptrOperationalService = PtrResourceRecord(kDnsSdQueryName, kMatterOperationalQueryName);
9697
PtrResourceRecord ptrOperational1 = PtrResourceRecord(kMatterOperationalQueryName, kInstanceName1);
9798
SrvResourceRecord srvOperational1 = SrvResourceRecord(kInstanceName1, kHostnameName, CHIP_PORT);
@@ -181,10 +182,10 @@ CommissionAdvertisingParameters commissionableNodeParamsLargeEnhanced =
181182
.SetRotatingDeviceId(chip::Optional<const char *>("id_that_spins"))
182183
.SetTcpSupported(chip::Optional<bool>(true))
183184
// 3600005 is more than the max so should be adjusted down
184-
.SetLocalMRPConfig(Optional<ReliableMessageProtocolConfig>::Value(3600000_ms32, 3600005_ms32));
185+
.SetLocalMRPConfig(Optional<ReliableMessageProtocolConfig>::Value(3600000_ms32, 3600005_ms32, 65535_ms16));
185186
QNamePart txtCommissionableNodeParamsLargeEnhancedParts[] = { "D=22", "VP=555+897", "CM=2", "DT=70000",
186187
"DN=testy-test", "RI=id_that_spins", "PI=Pair me", "PH=3",
187-
"SAI=3600000", "SII=3600000", "T=1" };
188+
"SAI=3600000", "SII=3600000", "SAT=65535", "T=1" };
188189
FullQName txtCommissionableNodeParamsLargeEnhancedName = FullQName(txtCommissionableNodeParamsLargeEnhancedParts);
189190
TxtResourceRecord txtCommissionableNodeParamsLargeEnhanced =
190191
TxtResourceRecord(instanceName, txtCommissionableNodeParamsLargeEnhancedName);

0 commit comments

Comments
 (0)