From 1188675e8d6431b56024a60488444a580a45b2d5 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Thu, 6 Apr 2023 16:30:58 -0400 Subject: [PATCH] Fix Darwin framework operational advertising for new fabrics. (#26005) Bringing up a new fabric for the very first time was not correctly starting operational advertising for that fabric, because we were not propagating that state to the actual CHIPDeviceController. It happened to work for existing fabrics, because bringing up the controller factory starts operational advertising for fabrics that are already known at that point. --- src/darwin/Framework/CHIP/MTRDeviceController.mm | 1 + src/darwin/Framework/CHIP/MTRDeviceControllerFactory.mm | 8 +++++--- .../Framework/CHIP/MTRDeviceControllerStartupParams.mm | 4 ++++ .../CHIP/MTRDeviceControllerStartupParams_Internal.h | 4 ++++ 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/darwin/Framework/CHIP/MTRDeviceController.mm b/src/darwin/Framework/CHIP/MTRDeviceController.mm index d51e3a50d7004d..a436003d7605b9 100644 --- a/src/darwin/Framework/CHIP/MTRDeviceController.mm +++ b/src/darwin/Framework/CHIP/MTRDeviceController.mm @@ -335,6 +335,7 @@ - (BOOL)startup:(MTRDeviceControllerStartupParamsInternal *)startupParams commissionerParams.controllerNOC = noc; } commissionerParams.controllerVendorId = static_cast([startupParams.vendorID unsignedShortValue]); + commissionerParams.enableServerInteractions = startupParams.advertiseOperational; commissionerParams.deviceAttestationVerifier = _factory.deviceAttestationVerifier; auto & factory = chip::Controller::DeviceControllerFactory::GetInstance(); diff --git a/src/darwin/Framework/CHIP/MTRDeviceControllerFactory.mm b/src/darwin/Framework/CHIP/MTRDeviceControllerFactory.mm index d71acaab034c11..ada02b3817529b 100644 --- a/src/darwin/Framework/CHIP/MTRDeviceControllerFactory.mm +++ b/src/darwin/Framework/CHIP/MTRDeviceControllerFactory.mm @@ -85,6 +85,7 @@ @interface MTRDeviceControllerFactory () @property (readonly) Credentials::PersistentStorageOpCertStore * opCertStore; @property (readonly) MTROperationalBrowser * operationalBrowser; @property () chip::Credentials::DeviceAttestationVerifier * deviceAttestationVerifier; +@property (readonly) BOOL advertiseOperational; - (BOOL)findMatchingFabric:(FabricTable &)fabricTable params:(MTRDeviceControllerStartupParams *)params @@ -435,9 +436,7 @@ - (BOOL)startControllerFactory:(MTRDeviceControllerFactoryParams *)startupParams if (startupParams.port != nil) { params.listenPort = [startupParams.port unsignedShortValue]; } - if (startupParams.shouldStartServer == YES) { - params.enableServerInteractions = true; - } + params.enableServerInteractions = startupParams.shouldStartServer; params.groupDataProvider = _groupDataProvider; params.sessionKeystore = _sessionKeystore; @@ -470,6 +469,7 @@ - (BOOL)startControllerFactory:(MTRDeviceControllerFactoryParams *)startupParams _controllerFactory->RetainSystemState(); _controllerFactory->ReleaseSystemState(); + self->_advertiseOperational = startupParams.shouldStartServer; self->_running = YES; }); @@ -566,6 +566,7 @@ - (MTRDeviceController * _Nullable)createControllerOnExistingFabric:(MTRDeviceCo params = [[MTRDeviceControllerStartupParamsInternal alloc] initForExistingFabric:fabricTable fabricIndex:fabric->GetFabricIndex() keystore:_keystore + advertiseOperational:self.advertiseOperational params:startupParams]; if (params == nil) { fabricError = CHIP_ERROR_NO_MEMORY; @@ -649,6 +650,7 @@ - (MTRDeviceController * _Nullable)createControllerOnNewFabric:(MTRDeviceControl params = [[MTRDeviceControllerStartupParamsInternal alloc] initForNewFabric:fabricTable keystore:_keystore + advertiseOperational:self.advertiseOperational params:startupParams]; if (params == nil) { fabricError = CHIP_ERROR_NO_MEMORY; diff --git a/src/darwin/Framework/CHIP/MTRDeviceControllerStartupParams.mm b/src/darwin/Framework/CHIP/MTRDeviceControllerStartupParams.mm index ba247576e916fa..4023220fc34396 100644 --- a/src/darwin/Framework/CHIP/MTRDeviceControllerStartupParams.mm +++ b/src/darwin/Framework/CHIP/MTRDeviceControllerStartupParams.mm @@ -207,6 +207,7 @@ - (instancetype)initWithParams:(MTRDeviceControllerStartupParams *)params - (instancetype)initForNewFabric:(chip::FabricTable *)fabricTable keystore:(chip::Crypto::OperationalKeystore *)keystore + advertiseOperational:(BOOL)advertiseOperational params:(MTRDeviceControllerStartupParams *)params { if (!(self = [self initWithParams:params])) { @@ -240,6 +241,7 @@ - (instancetype)initForNewFabric:(chip::FabricTable *)fabricTable _fabricTable = fabricTable; _keystore = keystore; + _advertiseOperational = advertiseOperational; return self; } @@ -247,6 +249,7 @@ - (instancetype)initForNewFabric:(chip::FabricTable *)fabricTable - (instancetype)initForExistingFabric:(FabricTable *)fabricTable fabricIndex:(FabricIndex)fabricIndex keystore:(chip::Crypto::OperationalKeystore *)keystore + advertiseOperational:(BOOL)advertiseOperational params:(MTRDeviceControllerStartupParams *)params { if (!(self = [self initWithParams:params])) { @@ -352,6 +355,7 @@ - (instancetype)initForExistingFabric:(FabricTable *)fabricTable _fabricTable = fabricTable; _fabricIndex.Emplace(fabricIndex); _keystore = keystore; + _advertiseOperational = advertiseOperational; return self; } diff --git a/src/darwin/Framework/CHIP/MTRDeviceControllerStartupParams_Internal.h b/src/darwin/Framework/CHIP/MTRDeviceControllerStartupParams_Internal.h index 79751cc95362e8..146a4bad978985 100644 --- a/src/darwin/Framework/CHIP/MTRDeviceControllerStartupParams_Internal.h +++ b/src/darwin/Framework/CHIP/MTRDeviceControllerStartupParams_Internal.h @@ -54,6 +54,8 @@ NS_ASSUME_NONNULL_BEGIN // Key store we're using with our fabric table, for sanity checks. @property (nonatomic, assign, readonly) chip::Crypto::OperationalKeystore * keystore; +@property (nonatomic, assign, readonly) BOOL advertiseOperational; + /** * Helper method that checks that our keypairs match our certificates. * Specifically: @@ -73,6 +75,7 @@ NS_ASSUME_NONNULL_BEGIN */ - (instancetype)initForNewFabric:(chip::FabricTable *)fabricTable keystore:(chip::Crypto::OperationalKeystore *)keystore + advertiseOperational:(BOOL)advertiseOperational params:(MTRDeviceControllerStartupParams *)params; /** @@ -81,6 +84,7 @@ NS_ASSUME_NONNULL_BEGIN - (instancetype)initForExistingFabric:(chip::FabricTable *)fabricTable fabricIndex:(chip::FabricIndex)fabricIndex keystore:(chip::Crypto::OperationalKeystore *)keystore + advertiseOperational:(BOOL)advertiseOperational params:(MTRDeviceControllerStartupParams *)params; /**