From d71e8e56d107c126bac736bd814f95889fa4bc4b Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Tue, 22 Mar 2022 15:03:56 -0400 Subject: [PATCH] Don't lose enableServerInteractions state when controller restarts. (#16504) When we shut down and restart the last controller, we shut down and reinitialize the system state. Since we were not storing the enableServerInteractions state in either the SystemState or the CHIPDeviceControllerFactory, it was getting lost during this process. The fix is to store the state in CHIPDeviceControllerFactory. --- src/controller/CHIPDeviceControllerFactory.cpp | 12 ++++++++---- src/controller/CHIPDeviceControllerFactory.h | 1 + 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/controller/CHIPDeviceControllerFactory.cpp b/src/controller/CHIPDeviceControllerFactory.cpp index 213ffddafb46e7..d04f56e83123a4 100644 --- a/src/controller/CHIPDeviceControllerFactory.cpp +++ b/src/controller/CHIPDeviceControllerFactory.cpp @@ -55,8 +55,11 @@ CHIP_ERROR DeviceControllerFactory::Init(FactoryInitParams params) return CHIP_NO_ERROR; } + // Save our initialization state that we can't recover later from a + // created-but-shut-down system state. mListenPort = params.listenPort; mFabricIndependentStorage = params.fabricIndependentStorage; + mEnableServerInteractions = params.enableServerInteractions; CHIP_ERROR err = InitSystemState(params); @@ -74,10 +77,11 @@ CHIP_ERROR DeviceControllerFactory::InitSystemState() #if CONFIG_NETWORK_LAYER_BLE params.bleLayer = mSystemState->BleLayer(); #endif + params.listenPort = mListenPort; + params.fabricIndependentStorage = mFabricIndependentStorage; + params.enableServerInteractions = mEnableServerInteractions; } - params.fabricIndependentStorage = mFabricIndependentStorage; - return InitSystemState(params); } @@ -128,12 +132,12 @@ CHIP_ERROR DeviceControllerFactory::InitSystemState(FactoryInitParams params) // ReturnErrorOnFailure(stateParams.transportMgr->Init(Transport::UdpListenParameters(stateParams.udpEndPointManager) .SetAddressType(Inet::IPAddressType::kIPv6) - .SetListenPort(mListenPort) + .SetListenPort(params.listenPort) #if INET_CONFIG_ENABLE_IPV4 , Transport::UdpListenParameters(stateParams.udpEndPointManager) .SetAddressType(Inet::IPAddressType::kIPv4) - .SetListenPort(mListenPort) + .SetListenPort(params.listenPort) #endif #if CONFIG_NETWORK_LAYER_BLE , diff --git a/src/controller/CHIPDeviceControllerFactory.h b/src/controller/CHIPDeviceControllerFactory.h index 0477aa3d4a69cd..be6ae934b3cd52 100644 --- a/src/controller/CHIPDeviceControllerFactory.h +++ b/src/controller/CHIPDeviceControllerFactory.h @@ -182,6 +182,7 @@ class DeviceControllerFactory uint16_t mListenPort; DeviceControllerSystemState * mSystemState = nullptr; PersistentStorageDelegate * mFabricIndependentStorage = nullptr; + bool mEnableServerInteractions = false; }; } // namespace Controller