Skip to content

Commit 6a6dc09

Browse files
authored
Merge branch 'master' into feature/basic-app-install-flow
2 parents 5c4bff8 + 8ae8954 commit 6a6dc09

9 files changed

+110
-63
lines changed

src/darwin/Framework/CHIP/MTRDeviceControllerFactory.mm

+56-45
Original file line numberDiff line numberDiff line change
@@ -881,24 +881,21 @@ - (MTRDeviceController * _Nullable)maybeInitializeOTAProvider:(MTRDeviceControll
881881

882882
- (void)resetOperationalAdvertising
883883
{
884-
if (!_advertiseOperational) {
885-
// No need to reset anything; we are not advertising the things that
886-
// would need to get reset.
887-
return;
888-
}
884+
assertChipStackLockedByCurrentThread();
889885

890-
std::lock_guard lock(_controllersLock);
891-
if (_controllers.count != 0) {
892-
// We have a running controller. That means we likely need to reset
893-
// operational advertising for that controller.
894-
dispatch_async(_chipWorkQueue, ^{
895-
// StartServer() is the only API we have for resetting DNS-SD
896-
// advertising. It sure would be nice if there were a "restart"
897-
// that was a no-op if the DNS-SD server was not already
898-
// running.
899-
app::DnssdServer::Instance().StartServer();
900-
});
886+
// If we're not advertising, then there's no need to reset anything.
887+
VerifyOrReturn(_advertiseOperational);
888+
889+
// If there are no running controllers there will be no advertisements to reset.
890+
{
891+
std::lock_guard lock(_controllersLock);
892+
VerifyOrReturn(_controllers.count > 0);
901893
}
894+
895+
// StartServer() is the only API we have for resetting DNS-SD advertising.
896+
// It sure would be nice if there were a "restart" that was a no-op if the
897+
// DNS-SD server was not already running.
898+
app::DnssdServer::Instance().StartServer();
902899
}
903900

904901
- (void)controllerShuttingDown:(MTRDeviceController *)controller
@@ -1165,6 +1162,45 @@ - (MTRDeviceController * _Nullable)initializeController:(MTRDeviceController *)c
11651162
error:error];
11661163
}
11671164

1165+
- (void)setMessageReliabilityProtocolIdleRetransmitMs:(nullable NSNumber *)idleRetransmitMs
1166+
activeRetransmitMs:(nullable NSNumber *)activeRetransmitMs
1167+
activeThresholdMs:(nullable NSNumber *)activeThresholdMs
1168+
additionalRetransmitDelayMs:(nullable NSNumber *)additionalRetransmitDelayMs
1169+
{
1170+
[self _assertCurrentQueueIsNotMatterQueue];
1171+
dispatch_async(_chipWorkQueue, ^{
1172+
bool resetAdvertising;
1173+
if (idleRetransmitMs == nil && activeRetransmitMs == nil && activeThresholdMs == nil && additionalRetransmitDelayMs == nil) {
1174+
Messaging::ReliableMessageMgr::SetAdditionalMRPBackoffTime(NullOptional);
1175+
resetAdvertising = ReliableMessageProtocolConfig::SetLocalMRPConfig(NullOptional);
1176+
} else {
1177+
if (additionalRetransmitDelayMs != nil) {
1178+
System::Clock::Timeout additionalBackoff(additionalRetransmitDelayMs.unsignedLongValue);
1179+
Messaging::ReliableMessageMgr::SetAdditionalMRPBackoffTime(MakeOptional(additionalBackoff));
1180+
}
1181+
1182+
// Get current MRP parameters, then override the things we were asked to
1183+
// override.
1184+
ReliableMessageProtocolConfig mrpConfig = GetLocalMRPConfig().ValueOr(GetDefaultMRPConfig());
1185+
if (idleRetransmitMs != nil) {
1186+
mrpConfig.mIdleRetransTimeout = System::Clock::Milliseconds32(idleRetransmitMs.unsignedLongValue);
1187+
}
1188+
if (activeRetransmitMs != nil) {
1189+
mrpConfig.mActiveRetransTimeout = System::Clock::Milliseconds32(activeRetransmitMs.unsignedLongValue);
1190+
}
1191+
if (activeThresholdMs != nil) {
1192+
mrpConfig.mActiveThresholdTime = System::Clock::Milliseconds32(activeThresholdMs.unsignedLongValue);
1193+
}
1194+
1195+
resetAdvertising = ReliableMessageProtocolConfig::SetLocalMRPConfig(MakeOptional(mrpConfig));
1196+
}
1197+
1198+
if (resetAdvertising) {
1199+
[self resetOperationalAdvertising];
1200+
}
1201+
});
1202+
}
1203+
11681204
- (PersistentStorageDelegate *)storageDelegate
11691205
{
11701206
return _persistentStorageDelegate;
@@ -1327,33 +1363,8 @@ void MTRSetMessageReliabilityParameters(NSNumber * _Nullable idleRetransmitMs,
13271363
NSNumber * _Nullable activeThresholdMs,
13281364
NSNumber * _Nullable additionalRetransmitDelayMs)
13291365
{
1330-
bool resetAdvertising = false;
1331-
if (idleRetransmitMs == nil && activeRetransmitMs == nil && activeThresholdMs == nil && additionalRetransmitDelayMs == nil) {
1332-
Messaging::ReliableMessageMgr::SetAdditionalMRPBackoffTime(NullOptional);
1333-
resetAdvertising = ReliableMessageProtocolConfig::SetLocalMRPConfig(NullOptional);
1334-
} else {
1335-
if (additionalRetransmitDelayMs != nil) {
1336-
System::Clock::Timeout additionalBackoff(additionalRetransmitDelayMs.unsignedLongValue);
1337-
Messaging::ReliableMessageMgr::SetAdditionalMRPBackoffTime(MakeOptional(additionalBackoff));
1338-
}
1339-
1340-
// Get current MRP parameters, then override the things we were asked to
1341-
// override.
1342-
ReliableMessageProtocolConfig mrpConfig = GetLocalMRPConfig().ValueOr(GetDefaultMRPConfig());
1343-
if (idleRetransmitMs != nil) {
1344-
mrpConfig.mIdleRetransTimeout = System::Clock::Milliseconds32(idleRetransmitMs.unsignedLongValue);
1345-
}
1346-
if (activeRetransmitMs != nil) {
1347-
mrpConfig.mActiveRetransTimeout = System::Clock::Milliseconds32(activeRetransmitMs.unsignedLongValue);
1348-
}
1349-
if (activeThresholdMs != nil) {
1350-
mrpConfig.mActiveThresholdTime = System::Clock::Milliseconds32(activeThresholdMs.unsignedLongValue);
1351-
}
1352-
1353-
resetAdvertising = ReliableMessageProtocolConfig::SetLocalMRPConfig(MakeOptional(mrpConfig));
1354-
}
1355-
1356-
if (resetAdvertising) {
1357-
[[MTRDeviceControllerFactory sharedInstance] resetOperationalAdvertising];
1358-
}
1366+
[MTRDeviceControllerFactory.sharedInstance setMessageReliabilityProtocolIdleRetransmitMs:idleRetransmitMs
1367+
activeRetransmitMs:activeThresholdMs
1368+
activeThresholdMs:activeThresholdMs
1369+
additionalRetransmitDelayMs:additionalRetransmitDelayMs];
13591370
}

src/darwin/Framework/CHIPTests/MTRControllerTests.m

+7
Original file line numberDiff line numberDiff line change
@@ -1552,4 +1552,11 @@ - (void)testControllerCATs
15521552
XCTAssertFalse([factory isRunning]);
15531553
}
15541554

1555+
- (void)testSetMRPParameters
1556+
{
1557+
// Can be called before starting the factory
1558+
XCTAssertFalse(MTRDeviceControllerFactory.sharedInstance.running);
1559+
MTRSetMessageReliabilityParameters(@2000, @2000, @2000, @2000);
1560+
}
1561+
15551562
@end

src/darwin/Framework/CHIPTests/MTRPerControllerStorageTests.m

+16
Original file line numberDiff line numberDiff line change
@@ -2035,6 +2035,22 @@ - (void)testControllerServer
20352035
[controllerServer shutdown];
20362036
}
20372037

2038+
- (void)testSetMRPParametersWithRunningController
2039+
{
2040+
NSError * error;
2041+
__auto_type * storageDelegate = [[MTRTestPerControllerStorage alloc] initWithControllerID:[NSUUID UUID]];
2042+
MTRDeviceController * controller = [self startControllerWithRootKeys:[[MTRTestKeys alloc] init]
2043+
operationalKeys:[[MTRTestKeys alloc] init]
2044+
fabricID:@555
2045+
nodeID:@888
2046+
storage:storageDelegate
2047+
error:&error];
2048+
XCTAssertNotNil(controller);
2049+
XCTAssertTrue(controller.running);
2050+
MTRSetMessageReliabilityParameters(@2000, @2000, @2000, @2000);
2051+
[controller shutdown];
2052+
}
2053+
20382054
static NSString * const kLocalTestUserDefaultDomain = @"org.csa-iot.matter.darwintest";
20392055
static NSString * const kLocalTestUserDefaultSubscriptionPoolSizeOverrideKey = @"subscriptionPoolSizeOverride";
20402056

src/lib/core/CHIPError.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ class ChipError
132132
* The result is valid only if CanEncapsulate() is true.
133133
*/
134134
constexpr ChipError(Range range, ValueType value) : ChipError(range, value, /*file=*/nullptr, /*line=*/0) {}
135-
#if __cplusplus >= 202002L
135+
#if CHIP_CONFIG_ERROR_SOURCE && __cplusplus >= 202002L
136136
constexpr ChipError(Range range, ValueType value, const char * file, unsigned int line,
137137
std::source_location location = std::source_location::current()) :
138138
mError(MakeInteger(range, (value & MakeMask(0, kValueLength)))) CHIP_INITIALIZE_ERROR_SOURCE(file, line, location)
@@ -141,7 +141,7 @@ class ChipError
141141
constexpr ChipError(Range range, ValueType value, const char * file, unsigned int line) :
142142
mError(MakeInteger(range, (value & MakeMask(0, kValueLength)))) CHIP_INITIALIZE_ERROR_SOURCE(file, line, /*loc=*/nullptr)
143143
{}
144-
#endif // __cplusplus >= 202002L
144+
#endif // CHIP_CONFIG_ERROR_SOURCE && __cplusplus >= 202002L
145145

146146
/**
147147
* Construct a CHIP_ERROR for SdkPart @a part with @a code.
@@ -150,7 +150,7 @@ class ChipError
150150
* The macro version CHIP_SDK_ERROR checks that the numeric value is constant and well-formed.
151151
*/
152152
constexpr ChipError(SdkPart part, uint8_t code) : ChipError(part, code, /*file=*/nullptr, /*line=*/0) {}
153-
#if __cplusplus >= 202002L
153+
#if CHIP_CONFIG_ERROR_SOURCE && __cplusplus >= 202002L
154154
constexpr ChipError(SdkPart part, uint8_t code, const char * file, unsigned int line,
155155
std::source_location location = std::source_location::current()) :
156156
mError(MakeInteger(part, code)) CHIP_INITIALIZE_ERROR_SOURCE(file, line, location)
@@ -159,7 +159,7 @@ class ChipError
159159
constexpr ChipError(SdkPart part, uint8_t code, const char * file, unsigned int line) :
160160
mError(MakeInteger(part, code)) CHIP_INITIALIZE_ERROR_SOURCE(file, line, /*loc=*/nullptr)
161161
{}
162-
#endif // __cplusplus >= 202002L
162+
#endif // CHIP_CONFIG_ERROR_SOURCE && __cplusplus >= 202002L
163163

164164
/**
165165
* Construct a CHIP_ERROR constant for SdkPart @a part with @a code at the current source line.
@@ -180,7 +180,7 @@ class ChipError
180180
* This is intended to be used only in foreign function interfaces.
181181
*/
182182
explicit constexpr ChipError(StorageType error) : ChipError(error, /*file=*/nullptr, /*line=*/0) {}
183-
#if __cplusplus >= 202002L
183+
#if CHIP_CONFIG_ERROR_SOURCE && __cplusplus >= 202002L
184184
explicit constexpr ChipError(StorageType error, const char * file, unsigned int line,
185185
std::source_location location = std::source_location::current()) :
186186
mError(error) CHIP_INITIALIZE_ERROR_SOURCE(file, line, location)
@@ -189,7 +189,7 @@ class ChipError
189189
explicit constexpr ChipError(StorageType error, const char * file, unsigned int line) :
190190
mError(error) CHIP_INITIALIZE_ERROR_SOURCE(file, line, /*loc=*/nullptr)
191191
{}
192-
#endif // __cplusplus >= 202002L
192+
#endif // CHIP_CONFIG_ERROR_SOURCE && __cplusplus >= 202002L
193193

194194
#undef CHIP_INITIALIZE_ERROR_SOURCE
195195

src/platform/ESP32/CHIPDevicePlatformConfig.h

+9
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,17 @@
5454
#define CHIP_DEVICE_CONFIG_ENABLE_THREAD 0
5555
#endif // CONFIG_ENABLE_MATTER_OVER_THREAD
5656

57+
#ifdef CONFIG_OPENTHREAD_SRP_CLIENT
5758
#define CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT CONFIG_OPENTHREAD_SRP_CLIENT
59+
#else
60+
#define CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT 0
61+
#endif // CONFIG_OPENTHREAD_SRP_CLIENT
62+
63+
#ifdef CONFIG_OPENTHREAD_DNS_CLIENT
5864
#define CHIP_DEVICE_CONFIG_ENABLE_THREAD_DNS_CLIENT CONFIG_OPENTHREAD_DNS_CLIENT
65+
#else
66+
#define CHIP_DEVICE_CONFIG_ENABLE_THREAD_DNS_CLIENT 0
67+
#endif // CONFIG_OPENTHREAD_DNS_CLIENT
5968

6069
#ifdef CONFIG_ENABLE_ETHERNET_TELEMETRY
6170
#define CHIP_DEVICE_CONFIG_ENABLE_ETHERNET 1

src/platform/ESP32/DnssdImpl.cpp

+9-10
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#endif
3131

3232
using namespace ::chip::DeviceLayer;
33+
using chip::DeviceLayer::Internal::ESP32Utils;
3334

3435
namespace chip {
3536
namespace Dnssd {
@@ -39,7 +40,7 @@ CHIP_ERROR ChipDnssdInit(DnssdAsyncReturnCallback initCallback, DnssdAsyncReturn
3940
#if CHIP_DEVICE_CONFIG_ENABLE_WIFI || CHIP_DEVICE_CONFIG_ENABLE_ETHERNET
4041
ReturnErrorOnFailure(EspDnssdInit(initCallback, errorCallback, context));
4142
#endif
42-
#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
43+
#if CHIP_DEVICE_CONFIG_ENABLE_THREAD && CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT
4344
ReturnErrorOnFailure(OpenThreadDnssdInit(initCallback, errorCallback, context));
4445
#endif
4546
return CHIP_NO_ERROR;
@@ -52,7 +53,7 @@ CHIP_ERROR ChipDnssdPublishService(const DnssdService * service, DnssdPublishCal
5253
#if CHIP_DEVICE_CONFIG_ENABLE_WIFI || CHIP_DEVICE_CONFIG_ENABLE_ETHERNET
5354
ReturnErrorOnFailure(EspDnssdPublishService(service, callback, context));
5455
#endif
55-
#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
56+
#if CHIP_DEVICE_CONFIG_ENABLE_THREAD && CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT
5657
if (ConnectivityMgr().IsThreadProvisioned())
5758
{
5859
ReturnErrorOnFailure(OpenThreadDnssdPublishService(service, callback, context));
@@ -66,7 +67,7 @@ CHIP_ERROR ChipDnssdRemoveServices()
6667
#if CHIP_DEVICE_CONFIG_ENABLE_WIFI || CHIP_DEVICE_CONFIG_ENABLE_ETHERNET
6768
ReturnErrorOnFailure(EspDnssdRemoveServices());
6869
#endif
69-
#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
70+
#if CHIP_DEVICE_CONFIG_ENABLE_THREAD && CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT
7071
if (ConnectivityMgr().IsThreadProvisioned())
7172
{
7273
ReturnErrorOnFailure(OpenThreadDnssdRemoveServices());
@@ -77,7 +78,7 @@ CHIP_ERROR ChipDnssdRemoveServices()
7778

7879
CHIP_ERROR ChipDnssdFinalizeServiceUpdate()
7980
{
80-
#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
81+
#if CHIP_DEVICE_CONFIG_ENABLE_THREAD && CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT
8182
if (ConnectivityMgr().IsThreadProvisioned())
8283
{
8384
ReturnErrorOnFailure(OpenThreadDnssdFinalizeServiceUpdate());
@@ -91,13 +92,12 @@ CHIP_ERROR ChipDnssdBrowse(const char * type, DnssdServiceProtocol protocol, chi
9192
intptr_t * browseIdentifier)
9293
{
9394
#if CHIP_DEVICE_CONFIG_ENABLE_WIFI || CHIP_DEVICE_CONFIG_ENABLE_ETHERNET
94-
if (ConnectivityMgr().IsWiFiStationProvisioned() ||
95-
Internal::ESP32Utils::HasIPv6LinkLocalAddress(Internal::ESP32Utils::kDefaultEthernetNetifKey))
95+
if (ConnectivityMgr().IsWiFiStationProvisioned() || ESP32Utils::HasIPv6LinkLocalAddress(ESP32Utils::kDefaultEthernetNetifKey))
9696
{
9797
ReturnErrorOnFailure(EspDnssdBrowse(type, protocol, addressType, interface, callback, context, browseIdentifier));
9898
}
9999
#endif
100-
#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
100+
#if CHIP_DEVICE_CONFIG_ENABLE_THREAD && CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT && CHIP_DEVICE_CONFIG_ENABLE_THREAD_DNS_CLIENT
101101
if (ConnectivityMgr().IsThreadProvisioned())
102102
{
103103
ReturnErrorOnFailure(OpenThreadDnssdBrowse(type, protocol, addressType, interface, callback, context, browseIdentifier));
@@ -115,13 +115,12 @@ CHIP_ERROR ChipDnssdResolve(DnssdService * service, chip::Inet::InterfaceId inte
115115
void * context)
116116
{
117117
#if CHIP_DEVICE_CONFIG_ENABLE_WIFI || CHIP_DEVICE_CONFIG_ENABLE_ETHERNET
118-
if (ConnectivityMgr().IsWiFiStationProvisioned() ||
119-
Internal::ESP32Utils::HasIPv6LinkLocalAddress(Internal::ESP32Utils::kDefaultEthernetNetifKey))
118+
if (ConnectivityMgr().IsWiFiStationProvisioned() || ESP32Utils::HasIPv6LinkLocalAddress(ESP32Utils::kDefaultEthernetNetifKey))
120119
{
121120
ReturnErrorOnFailure(EspDnssdResolve(service, interface, callback, context));
122121
}
123122
#endif
124-
#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
123+
#if CHIP_DEVICE_CONFIG_ENABLE_THREAD && CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT && CHIP_DEVICE_CONFIG_ENABLE_THREAD_DNS_CLIENT
125124
if (ConnectivityMgr().IsThreadProvisioned())
126125
{
127126
ReturnErrorOnFailure(OpenThreadDnssdResolve(service, interface, callback, context));

src/platform/ESP32/ESP32DnssdImpl.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ static CHIP_ERROR OnBrowseDone(BrowseContext * ctx)
355355
Inet::IPAddress IPAddr;
356356
error = GetIPAddress(IPAddr, currentResult->addr);
357357
SuccessOrExit(error);
358-
ctx->mService[servicesIndex].mAddress.SetValue(IPAddr);
358+
ctx->mService[servicesIndex].mAddress.emplace(IPAddr);
359359
}
360360
currentResult = currentResult->next;
361361
servicesIndex++;

src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,6 @@ class GenericThreadStackManagerImpl_OpenThread
230230

231231
DnsBrowseCallback mDnsBrowseCallback;
232232
DnsResolveCallback mDnsResolveCallback;
233-
GeneralFaults<kMaxNetworkFaults> mNetworkFaults;
234233

235234
struct DnsServiceTxtEntries
236235
{
@@ -264,6 +263,8 @@ class GenericThreadStackManagerImpl_OpenThread
264263
#endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD_DNS_CLIENT
265264
#endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT
266265

266+
GeneralFaults<kMaxNetworkFaults> mNetworkFaults;
267+
267268
inline ImplClass * Impl() { return static_cast<ImplClass *>(this); }
268269
};
269270

src/platform/OpenThread/OpenThreadDnssdImpl.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ namespace Dnssd {
2424

2525
CHIP_ERROR OpenThreadDnssdInit(DnssdAsyncReturnCallback initCallback, DnssdAsyncReturnCallback errorCallback, void * context)
2626
{
27+
#if CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT
2728
ReturnErrorOnFailure(ThreadStackMgr().SetSrpDnsCallbacks(initCallback, errorCallback, context));
2829

2930
uint8_t macBuffer[ConfigurationManager::kPrimaryMACAddressLength];
@@ -33,6 +34,9 @@ CHIP_ERROR OpenThreadDnssdInit(DnssdAsyncReturnCallback initCallback, DnssdAsync
3334
MakeHostName(hostname, sizeof(hostname), mac);
3435

3536
return ThreadStackMgr().ClearSrpHost(hostname);
37+
#else
38+
return CHIP_ERROR_NOT_IMPLEMENTED;
39+
#endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT
3640
}
3741

3842
const char * GetProtocolString(DnssdServiceProtocol protocol)

0 commit comments

Comments
 (0)