From 10780046c4cfbd2951d11bc0314402d9738934a7 Mon Sep 17 00:00:00 2001 From: Jean-Francois Penven <67962328+jepenven-silabs@users.noreply.github.com> Date: Fri, 11 Feb 2022 12:50:58 -0500 Subject: [PATCH] Add persistent storage to session manager (#15062) * Add persistent storage to session manager --- .../chip-tool/commands/common/CHIPCommand.cpp | 5 +++-- examples/shell/shell_common/cmd_ping.cpp | 4 ++-- examples/shell/shell_common/cmd_send.cpp | 4 ++-- examples/shell/shell_common/globals.cpp | 1 + examples/shell/shell_common/include/Globals.h | 2 ++ src/app/server/Server.cpp | 2 +- src/app/tests/TestOperationalDeviceProxy.cpp | 4 +++- src/app/tests/integration/chip_im_initiator.cpp | 2 +- src/app/tests/integration/chip_im_responder.cpp | 2 +- src/app/tests/integration/common.cpp | 1 + src/app/tests/integration/common.h | 2 ++ src/controller/CHIPDeviceControllerFactory.cpp | 15 ++++++++++----- src/controller/CHIPDeviceControllerFactory.h | 6 ++++-- .../java/AndroidDeviceControllerWrapper.cpp | 2 ++ .../ChipDeviceController-ScriptBinding.cpp | 3 ++- .../python/chip/internal/CommissionerImpl.cpp | 3 ++- src/controller/tests/TestDevice.cpp | 5 ++++- .../Framework/CHIP/CHIPDeviceController.mm | 1 + src/messaging/tests/MessagingContext.cpp | 2 +- src/messaging/tests/MessagingContext.h | 4 +++- src/messaging/tests/echo/common.cpp | 1 + src/messaging/tests/echo/common.h | 2 ++ src/messaging/tests/echo/echo_requester.cpp | 4 ++-- src/messaging/tests/echo/echo_responder.cpp | 4 ++-- .../secure_channel/tests/TestCASESession.cpp | 10 +++++----- src/transport/SessionManager.cpp | 5 ++++- src/transport/SessionManager.h | 7 ++++++- src/transport/tests/TestSessionManager.cpp | 16 +++++++++++----- 28 files changed, 81 insertions(+), 38 deletions(-) diff --git a/examples/chip-tool/commands/common/CHIPCommand.cpp b/examples/chip-tool/commands/common/CHIPCommand.cpp index 3fd71824945e8e..0bdcacfbc22730 100644 --- a/examples/chip-tool/commands/common/CHIPCommand.cpp +++ b/examples/chip-tool/commands/common/CHIPCommand.cpp @@ -48,8 +48,9 @@ CHIP_ERROR CHIPCommand::Run() ReturnLogErrorOnFailure(mFabricStorage.Initialize(&mDefaultStorage)); chip::Controller::FactoryInitParams factoryInitParams; - factoryInitParams.fabricStorage = &mFabricStorage; - factoryInitParams.listenPort = static_cast(mDefaultStorage.GetListenPort() + CurrentCommissionerId()); + factoryInitParams.fabricStorage = &mFabricStorage; + factoryInitParams.fabricIndependentStorage = &mDefaultStorage; + factoryInitParams.listenPort = static_cast(mDefaultStorage.GetListenPort() + CurrentCommissionerId()); ReturnLogErrorOnFailure(DeviceControllerFactory::GetInstance().Init(factoryInitParams)); ReturnLogErrorOnFailure(InitializeCommissioner(kIdentityNull, kIdentityNullFabricId)); diff --git a/examples/shell/shell_common/cmd_ping.cpp b/examples/shell/shell_common/cmd_ping.cpp index 6a8183d3de80b2..2dd01eda676aa5 100644 --- a/examples/shell/shell_common/cmd_ping.cpp +++ b/examples/shell/shell_common/cmd_ping.cpp @@ -306,7 +306,7 @@ void StartPinging(streamer_t * stream, char * destination) #if INET_CONFIG_ENABLE_TCP_ENDPOINT if (gPingArguments.IsUsingTCP()) { - err = gSessionManager.Init(&DeviceLayer::SystemLayer(), &gTCPManager, &gMessageCounterManager); + err = gSessionManager.Init(&DeviceLayer::SystemLayer(), &gTCPManager, &gMessageCounterManager, &gStorage); SuccessOrExit(err); err = gExchangeManager.Init(&gSessionManager); @@ -315,7 +315,7 @@ void StartPinging(streamer_t * stream, char * destination) else #endif { - err = gSessionManager.Init(&DeviceLayer::SystemLayer(), &gUDPManager, &gMessageCounterManager); + err = gSessionManager.Init(&DeviceLayer::SystemLayer(), &gUDPManager, &gMessageCounterManager, &gStorage); SuccessOrExit(err); err = gExchangeManager.Init(&gSessionManager); diff --git a/examples/shell/shell_common/cmd_send.cpp b/examples/shell/shell_common/cmd_send.cpp index c216c57578297a..0b22150f69cd83 100644 --- a/examples/shell/shell_common/cmd_send.cpp +++ b/examples/shell/shell_common/cmd_send.cpp @@ -227,7 +227,7 @@ void ProcessCommand(streamer_t * stream, char * destination) { peerAddress = Transport::PeerAddress::TCP(gDestAddr, gSendArguments.GetPort()); - err = gSessionManager.Init(&DeviceLayer::SystemLayer(), &gTCPManager, &gMessageCounterManager); + err = gSessionManager.Init(&DeviceLayer::SystemLayer(), &gTCPManager, &gMessageCounterManager, &gStorage); SuccessOrExit(err); } else @@ -235,7 +235,7 @@ void ProcessCommand(streamer_t * stream, char * destination) { peerAddress = Transport::PeerAddress::UDP(gDestAddr, gSendArguments.GetPort(), chip::Inet::InterfaceId::Null()); - err = gSessionManager.Init(&DeviceLayer::SystemLayer(), &gUDPManager, &gMessageCounterManager); + err = gSessionManager.Init(&DeviceLayer::SystemLayer(), &gUDPManager, &gMessageCounterManager, &gStorage); SuccessOrExit(err); } diff --git a/examples/shell/shell_common/globals.cpp b/examples/shell/shell_common/globals.cpp index af35b558a18d5a..ca8830977ce9c6 100644 --- a/examples/shell/shell_common/globals.cpp +++ b/examples/shell/shell_common/globals.cpp @@ -22,6 +22,7 @@ chip::Messaging::ExchangeManager gExchangeManager; chip::SessionManager gSessionManager; chip::Inet::IPAddress gDestAddr; chip::SessionHolder gSession; +chip::TestPersistentStorageDelegate gStorage; chip::FabricIndex gFabricIndex = 0; diff --git a/examples/shell/shell_common/include/Globals.h b/examples/shell/shell_common/include/Globals.h index 9db7b2de26e010..f40d11c0ecc6c5 100644 --- a/examples/shell/shell_common/include/Globals.h +++ b/examples/shell/shell_common/include/Globals.h @@ -18,6 +18,7 @@ #pragma once #include +#include #include #include #include @@ -36,6 +37,7 @@ extern chip::Messaging::ExchangeManager gExchangeManager; extern chip::SessionManager gSessionManager; extern chip::Inet::IPAddress gDestAddr; extern chip::SessionHolder gSession; +extern chip::TestPersistentStorageDelegate gStorage; extern chip::FabricIndex gFabricIndex; diff --git a/src/app/server/Server.cpp b/src/app/server/Server.cpp index 230a0b52132542..db78aeb769b639 100644 --- a/src/app/server/Server.cpp +++ b/src/app/server/Server.cpp @@ -157,7 +157,7 @@ CHIP_ERROR Server::Init(AppDelegate * delegate, uint16_t secureServicePort, uint #endif SuccessOrExit(err); - err = mSessions.Init(&DeviceLayer::SystemLayer(), &mTransports, &mMessageCounterManager); + err = mSessions.Init(&DeviceLayer::SystemLayer(), &mTransports, &mMessageCounterManager, &mDeviceStorage); SuccessOrExit(err); err = mExchangeMgr.Init(&mSessions); diff --git a/src/app/tests/TestOperationalDeviceProxy.cpp b/src/app/tests/TestOperationalDeviceProxy.cpp index 8b6101deabfecf..bc963f3837f470 100644 --- a/src/app/tests/TestOperationalDeviceProxy.cpp +++ b/src/app/tests/TestOperationalDeviceProxy.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -50,12 +51,13 @@ void TestOperationalDeviceProxy_EstablishSessionDirectly(nlTestSuite * inSuite, FabricTable * fabrics = Platform::New(); FabricInfo * fabric = fabrics->FindFabricWithIndex(1); secure_channel::MessageCounterManager messageCounterManager; + chip::TestPersistentStorageDelegate deviceStorage; SessionIDAllocator idAllocator; systemLayer.Init(); udpEndPointManager.Init(systemLayer); transportMgr.Init(UdpListenParameters(udpEndPointManager).SetAddressType(Inet::IPAddressType::kIPv4).SetListenPort(CHIP_PORT)); - sessionManager.Init(&systemLayer, &transportMgr, &messageCounterManager); + sessionManager.Init(&systemLayer, &transportMgr, &messageCounterManager, &deviceStorage); exchangeMgr.Init(&sessionManager); messageCounterManager.Init(&exchangeMgr); diff --git a/src/app/tests/integration/chip_im_initiator.cpp b/src/app/tests/integration/chip_im_initiator.cpp index 616470055caccd..49c43d1f1cbed3 100644 --- a/src/app/tests/integration/chip_im_initiator.cpp +++ b/src/app/tests/integration/chip_im_initiator.cpp @@ -703,7 +703,7 @@ int main(int argc, char * argv[]) .SetListenPort(IM_CLIENT_PORT)); SuccessOrExit(err); - err = gSessionManager.Init(&chip::DeviceLayer::SystemLayer(), &gTransportManager, &gMessageCounterManager); + err = gSessionManager.Init(&chip::DeviceLayer::SystemLayer(), &gTransportManager, &gMessageCounterManager, &gStorage); SuccessOrExit(err); err = gExchangeManager.Init(&gSessionManager); diff --git a/src/app/tests/integration/chip_im_responder.cpp b/src/app/tests/integration/chip_im_responder.cpp index 2dbce00ef57cb3..8378feb7d9e97c 100644 --- a/src/app/tests/integration/chip_im_responder.cpp +++ b/src/app/tests/integration/chip_im_responder.cpp @@ -173,7 +173,7 @@ int main(int argc, char * argv[]) .SetAddressType(chip::Inet::IPAddressType::kIPv6)); SuccessOrExit(err); - err = gSessionManager.Init(&chip::DeviceLayer::SystemLayer(), &gTransportManager, &gMessageCounterManager); + err = gSessionManager.Init(&chip::DeviceLayer::SystemLayer(), &gTransportManager, &gMessageCounterManager, &gStorage); SuccessOrExit(err); err = gExchangeManager.Init(&gSessionManager); diff --git a/src/app/tests/integration/common.cpp b/src/app/tests/integration/common.cpp index d898928cf2c5ae..48362a84abc5fc 100644 --- a/src/app/tests/integration/common.cpp +++ b/src/app/tests/integration/common.cpp @@ -36,6 +36,7 @@ chip::Messaging::ExchangeManager gExchangeManager; chip::SessionManager gSessionManager; chip::secure_channel::MessageCounterManager gMessageCounterManager; chip::SessionHolder gSession; +chip::TestPersistentStorageDelegate gStorage; void InitializeChip(void) { diff --git a/src/app/tests/integration/common.h b/src/app/tests/integration/common.h index 5ae806b1f8caf8..9df1531ed73d71 100644 --- a/src/app/tests/integration/common.h +++ b/src/app/tests/integration/common.h @@ -25,6 +25,7 @@ #pragma once #include +#include #include #include #include @@ -36,6 +37,7 @@ extern chip::Messaging::ExchangeManager gExchangeManager; extern chip::SessionManager gSessionManager; extern chip::secure_channel::MessageCounterManager gMessageCounterManager; extern chip::SessionHolder gSession; +extern chip::TestPersistentStorageDelegate gStorage; constexpr chip::NodeId kTestNodeId = 0x1ULL; constexpr chip::NodeId kTestNodeId1 = 0x2ULL; diff --git a/src/controller/CHIPDeviceControllerFactory.cpp b/src/controller/CHIPDeviceControllerFactory.cpp index 67f125270529fe..4eb72e430ac80d 100644 --- a/src/controller/CHIPDeviceControllerFactory.cpp +++ b/src/controller/CHIPDeviceControllerFactory.cpp @@ -50,8 +50,9 @@ CHIP_ERROR DeviceControllerFactory::Init(FactoryInitParams params) return CHIP_NO_ERROR; } - mListenPort = params.listenPort; - mFabricStorage = params.fabricStorage; + mListenPort = params.listenPort; + mFabricStorage = params.fabricStorage; + mFabricIndependentStorage = params.fabricIndependentStorage; CHIP_ERROR err = InitSystemState(params); @@ -71,6 +72,8 @@ CHIP_ERROR DeviceControllerFactory::InitSystemState() #endif } + params.fabricIndependentStorage = mFabricIndependentStorage; + return InitSystemState(params); } @@ -137,8 +140,9 @@ CHIP_ERROR DeviceControllerFactory::InitSystemState(FactoryInitParams params) stateParams.messageCounterManager = chip::Platform::New(); ReturnErrorOnFailure(stateParams.fabricTable->Init(mFabricStorage)); - ReturnErrorOnFailure( - stateParams.sessionMgr->Init(stateParams.systemLayer, stateParams.transportMgr, stateParams.messageCounterManager)); + + ReturnErrorOnFailure(stateParams.sessionMgr->Init(stateParams.systemLayer, stateParams.transportMgr, + stateParams.messageCounterManager, params.fabricIndependentStorage)); ReturnErrorOnFailure(stateParams.exchangeMgr->Init(stateParams.sessionMgr)); ReturnErrorOnFailure(stateParams.messageCounterManager->Init(stateParams.exchangeMgr)); @@ -222,7 +226,8 @@ void DeviceControllerFactory::Shutdown() chip::Platform::Delete(mSystemState); mSystemState = nullptr; } - mFabricStorage = nullptr; + mFabricStorage = nullptr; + mFabricIndependentStorage = nullptr; } CHIP_ERROR DeviceControllerSystemState::Shutdown() diff --git a/src/controller/CHIPDeviceControllerFactory.h b/src/controller/CHIPDeviceControllerFactory.h index 68de0144909e2e..dd4029ad71a28b 100644 --- a/src/controller/CHIPDeviceControllerFactory.h +++ b/src/controller/CHIPDeviceControllerFactory.h @@ -70,6 +70,7 @@ struct FactoryInitParams { FabricStorage * fabricStorage = nullptr; System::Layer * systemLayer = nullptr; + PersistentStorageDelegate * fabricIndependentStorage = nullptr; Inet::EndPointManager * tcpEndPointManager = nullptr; Inet::EndPointManager * udpEndPointManager = nullptr; #if CONFIG_NETWORK_LAYER_BLE @@ -130,8 +131,9 @@ class DeviceControllerFactory CHIP_ERROR InitSystemState(); uint16_t mListenPort; - FabricStorage * mFabricStorage = nullptr; - DeviceControllerSystemState * mSystemState = nullptr; + FabricStorage * mFabricStorage = nullptr; + DeviceControllerSystemState * mSystemState = nullptr; + PersistentStorageDelegate * mFabricIndependentStorage = nullptr; }; } // namespace Controller diff --git a/src/controller/java/AndroidDeviceControllerWrapper.cpp b/src/controller/java/AndroidDeviceControllerWrapper.cpp index b206e9ea103161..7612a3cee2eff6 100644 --- a/src/controller/java/AndroidDeviceControllerWrapper.cpp +++ b/src/controller/java/AndroidDeviceControllerWrapper.cpp @@ -119,6 +119,7 @@ AndroidDeviceControllerWrapper::AllocateNew(JavaVM * vm, jobject deviceControlle initParams.tcpEndPointManager = tcpEndPointManager; initParams.udpEndPointManager = udpEndPointManager; initParams.fabricStorage = wrapper.get(); + // move bleLayer into platform/android to share with app server #if CONFIG_NETWORK_LAYER_BLE initParams.bleLayer = DeviceLayer::ConnectivityMgr().GetBleLayer(); @@ -127,6 +128,7 @@ AndroidDeviceControllerWrapper::AllocateNew(JavaVM * vm, jobject deviceControlle setupParams.storageDelegate = wrapper.get(); setupParams.pairingDelegate = wrapper.get(); setupParams.operationalCredentialsDelegate = opCredsIssuer; + initParams.fabricIndependentStorage = setupParams.storageDelegate; opCredsIssuer->Initialize(*wrapper.get(), wrapper.get()->mJavaObjectRef); diff --git a/src/controller/python/ChipDeviceController-ScriptBinding.cpp b/src/controller/python/ChipDeviceController-ScriptBinding.cpp index 72d579b1fdb72e..d2af20821a5a79 100644 --- a/src/controller/python/ChipDeviceController-ScriptBinding.cpp +++ b/src/controller/python/ChipDeviceController-ScriptBinding.cpp @@ -224,7 +224,8 @@ ChipError::StorageType pychip_DeviceController_StackInit() VerifyOrReturnError(err == CHIP_NO_ERROR, err.AsInteger()); FactoryInitParams factoryParams; - factoryParams.fabricStorage = &sFabricStorage; + factoryParams.fabricStorage = &sFabricStorage; + factoryParams.fabricIndependentStorage = sStorageAdapter; ReturnErrorOnFailure(DeviceControllerFactory::GetInstance().Init(factoryParams).AsInteger()); diff --git a/src/controller/python/chip/internal/CommissionerImpl.cpp b/src/controller/python/chip/internal/CommissionerImpl.cpp index c806659327f43c..044a66401e1ef4 100644 --- a/src/controller/python/chip/internal/CommissionerImpl.cpp +++ b/src/controller/python/chip/internal/CommissionerImpl.cpp @@ -116,7 +116,8 @@ extern "C" chip::Controller::DeviceCommissioner * pychip_internal_Commissioner_N err = gFabricStorage.Initialize(&gServerStorage); SuccessOrExit(err); - factoryParams.fabricStorage = &gFabricStorage; + factoryParams.fabricStorage = &gFabricStorage; + factoryParams.fabricIndependentStorage = &gServerStorage; commissionerParams.pairingDelegate = &gPairingDelegate; commissionerParams.storageDelegate = &gServerStorage; diff --git a/src/controller/tests/TestDevice.cpp b/src/controller/tests/TestDevice.cpp index 16018a603c497e..1e7f061277ea4d 100644 --- a/src/controller/tests/TestDevice.cpp +++ b/src/controller/tests/TestDevice.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -51,6 +52,8 @@ void TestDevice_EstablishSessionDirectly(nlTestSuite * inSuite, void * inContext ExchangeManager exchangeMgr; Inet::UDPEndPointManagerImpl udpEndPointManager; System::LayerImpl systemLayer; + chip::TestPersistentStorageDelegate deviceStorage; + #if CONFIG_NETWORK_LAYER_BLE Ble::BleLayer blelayer; #endif // CONFIG_NETWORK_LAYER_BLE @@ -72,7 +75,7 @@ void TestDevice_EstablishSessionDirectly(nlTestSuite * inSuite, void * inContext BleListenParameters(&blelayer) #endif ); - sessionManager.Init(&systemLayer, &transportMgr, &messageCounterManager); + sessionManager.Init(&systemLayer, &transportMgr, &messageCounterManager, &deviceStorage;); exchangeMgr.Init(&sessionManager); messageCounterManager.Init(&exchangeMgr); diff --git a/src/darwin/Framework/CHIP/CHIPDeviceController.mm b/src/darwin/Framework/CHIP/CHIPDeviceController.mm index 383cd720b7d7ed..49c5fde0fb070f 100644 --- a/src/darwin/Framework/CHIP/CHIPDeviceController.mm +++ b/src/darwin/Framework/CHIP/CHIPDeviceController.mm @@ -196,6 +196,7 @@ - (BOOL)startup:(_Nullable id)storageDelegate chip::Credentials::SetDeviceAttestationVerifier(chip::Credentials::GetDefaultDACVerifier(testingRootStore)); params.fabricStorage = _fabricStorage; + params.fabricIndependentStorage = _persistentStorageDelegateBridge; commissionerParams.storageDelegate = _persistentStorageDelegateBridge; commissionerParams.deviceAddressUpdateDelegate = _pairingDelegateBridge; commissionerParams.pairingDelegate = _pairingDelegateBridge; diff --git a/src/messaging/tests/MessagingContext.cpp b/src/messaging/tests/MessagingContext.cpp index c11b176805e1ad..11fc5112324091 100644 --- a/src/messaging/tests/MessagingContext.cpp +++ b/src/messaging/tests/MessagingContext.cpp @@ -32,7 +32,7 @@ CHIP_ERROR MessagingContext::Init(TransportMgrBase * transport, IOContext * ioCo mTransport = transport; ReturnErrorOnFailure(PlatformMemoryUser::Init()); - ReturnErrorOnFailure(mSessionManager.Init(&GetSystemLayer(), transport, &mMessageCounterManager)); + ReturnErrorOnFailure(mSessionManager.Init(&GetSystemLayer(), transport, &mMessageCounterManager, &mStorage)); ReturnErrorOnFailure(mExchangeManager.Init(&mSessionManager)); ReturnErrorOnFailure(mMessageCounterManager.Init(&mExchangeManager)); diff --git a/src/messaging/tests/MessagingContext.h b/src/messaging/tests/MessagingContext.h index afb771123ce9f1..2f543db4191359 100644 --- a/src/messaging/tests/MessagingContext.h +++ b/src/messaging/tests/MessagingContext.h @@ -16,6 +16,7 @@ */ #pragma once +#include #include #include #include @@ -145,7 +146,8 @@ class MessagingContext : public PlatformMemoryUser Messaging::ExchangeManager mExchangeManager; secure_channel::MessageCounterManager mMessageCounterManager; IOContext * mIOContext; - TransportMgrBase * mTransport; // Only needed for InitFromExisting. + TransportMgrBase * mTransport; // Only needed for InitFromExisting. + chip::TestPersistentStorageDelegate mStorage; // for SessionManagerInit NodeId mBobNodeId = 123654; NodeId mAliceNodeId = 111222333; diff --git a/src/messaging/tests/echo/common.cpp b/src/messaging/tests/echo/common.cpp index 77d867df075c68..fdebf3e6bf1cdb 100644 --- a/src/messaging/tests/echo/common.cpp +++ b/src/messaging/tests/echo/common.cpp @@ -33,6 +33,7 @@ chip::SessionManager gSessionManager; chip::Messaging::ExchangeManager gExchangeManager; chip::secure_channel::MessageCounterManager gMessageCounterManager; +chip::TestPersistentStorageDelegate gStorage; void InitializeChip(void) { diff --git a/src/messaging/tests/echo/common.h b/src/messaging/tests/echo/common.h index 7538bc57247d83..cea330d0c93a3b 100644 --- a/src/messaging/tests/echo/common.h +++ b/src/messaging/tests/echo/common.h @@ -24,6 +24,7 @@ #pragma once +#include #include #include #include @@ -35,6 +36,7 @@ constexpr size_t kNetworkSleepTimeMsecs = (100 * 1000); extern chip::SessionManager gSessionManager; extern chip::Messaging::ExchangeManager gExchangeManager; extern chip::secure_channel::MessageCounterManager gMessageCounterManager; +extern chip::TestPersistentStorageDelegate gStorage; void InitializeChip(void); void ShutdownChip(void); diff --git a/src/messaging/tests/echo/echo_requester.cpp b/src/messaging/tests/echo/echo_requester.cpp index c94c43ffd42669..db85a300ea10d3 100644 --- a/src/messaging/tests/echo/echo_requester.cpp +++ b/src/messaging/tests/echo/echo_requester.cpp @@ -238,7 +238,7 @@ int main(int argc, char * argv[]) .SetListenPort(ECHO_CLIENT_PORT)); SuccessOrExit(err); - err = gSessionManager.Init(&chip::DeviceLayer::SystemLayer(), &gTCPManager, &gMessageCounterManager); + err = gSessionManager.Init(&chip::DeviceLayer::SystemLayer(), &gTCPManager, &gMessageCounterManager, &gStorage); SuccessOrExit(err); } else @@ -248,7 +248,7 @@ int main(int argc, char * argv[]) .SetListenPort(ECHO_CLIENT_PORT)); SuccessOrExit(err); - err = gSessionManager.Init(&chip::DeviceLayer::SystemLayer(), &gUDPManager, &gMessageCounterManager); + err = gSessionManager.Init(&chip::DeviceLayer::SystemLayer(), &gUDPManager, &gMessageCounterManager, &gStorage); SuccessOrExit(err); } diff --git a/src/messaging/tests/echo/echo_responder.cpp b/src/messaging/tests/echo/echo_responder.cpp index 6ded2338d01ab5..3702ef4974b771 100644 --- a/src/messaging/tests/echo/echo_responder.cpp +++ b/src/messaging/tests/echo/echo_responder.cpp @@ -93,7 +93,7 @@ int main(int argc, char * argv[]) ); SuccessOrExit(err); - err = gSessionManager.Init(&chip::DeviceLayer::SystemLayer(), &gTCPManager, &gMessageCounterManager); + err = gSessionManager.Init(&chip::DeviceLayer::SystemLayer(), &gTCPManager, &gMessageCounterManager, &gStorage); SuccessOrExit(err); } else @@ -102,7 +102,7 @@ int main(int argc, char * argv[]) .SetAddressType(chip::Inet::IPAddressType::kIPv6)); SuccessOrExit(err); - err = gSessionManager.Init(&chip::DeviceLayer::SystemLayer(), &gUDPManager, &gMessageCounterManager); + err = gSessionManager.Init(&chip::DeviceLayer::SystemLayer(), &gUDPManager, &gMessageCounterManager, &gStorage); SuccessOrExit(err); } diff --git a/src/protocols/secure_channel/tests/TestCASESession.cpp b/src/protocols/secure_channel/tests/TestCASESession.cpp index 7f4a09c9aa41f2..7e2b673f964ebf 100644 --- a/src/protocols/secure_channel/tests/TestCASESession.cpp +++ b/src/protocols/secure_channel/tests/TestCASESession.cpp @@ -260,10 +260,10 @@ void CASE_SecurePairingHandshakeTest(nlTestSuite * inSuite, void * inContext) CASE_SecurePairingHandshakeTestCommon(inSuite, inContext, pairingCommissioner, delegateCommissioner); } -class TestPersistentStorageDelegate : public PersistentStorageDelegate, public FabricStorage +class TestCASESessionPersistentStorageDelegate : public PersistentStorageDelegate, public FabricStorage { public: - TestPersistentStorageDelegate() + TestCASESessionPersistentStorageDelegate() { memset(keys, 0, sizeof(keys)); memset(keysize, 0, sizeof(keysize)); @@ -271,7 +271,7 @@ class TestPersistentStorageDelegate : public PersistentStorageDelegate, public F memset(valuesize, 0, sizeof(valuesize)); } - ~TestPersistentStorageDelegate() { Cleanup(); } + ~TestCASESessionPersistentStorageDelegate() { Cleanup(); } void Cleanup() { @@ -347,8 +347,8 @@ class TestPersistentStorageDelegate : public PersistentStorageDelegate, public F uint16_t valuesize[16]; }; -TestPersistentStorageDelegate gCommissionerStorageDelegate; -TestPersistentStorageDelegate gDeviceStorageDelegate; +TestCASESessionPersistentStorageDelegate gCommissionerStorageDelegate; +TestCASESessionPersistentStorageDelegate gDeviceStorageDelegate; TestCASEServerIPK gPairingServer; diff --git a/src/transport/SessionManager.cpp b/src/transport/SessionManager.cpp index 08995be7d8ce63..1c749344476477 100644 --- a/src/transport/SessionManager.cpp +++ b/src/transport/SessionManager.cpp @@ -72,15 +72,18 @@ SessionManager::SessionManager() : mState(State::kNotReady) {} SessionManager::~SessionManager() {} CHIP_ERROR SessionManager::Init(System::Layer * systemLayer, TransportMgrBase * transportMgr, - Transport::MessageCounterManagerInterface * messageCounterManager) + Transport::MessageCounterManagerInterface * messageCounterManager, + chip::PersistentStorageDelegate * storageDelegate) { VerifyOrReturnError(mState == State::kNotReady, CHIP_ERROR_INCORRECT_STATE); VerifyOrReturnError(transportMgr != nullptr, CHIP_ERROR_INVALID_ARGUMENT); + VerifyOrReturnError(storageDelegate != nullptr, CHIP_ERROR_INVALID_ARGUMENT); mState = State::kInitialized; mSystemLayer = systemLayer; mTransportMgr = transportMgr; mMessageCounterManager = messageCounterManager; + mStorage = storageDelegate; // TODO: Handle error from mGlobalEncryptedMessageCounter! Unit tests currently crash if you do! (void) mGlobalEncryptedMessageCounter.Init(); diff --git a/src/transport/SessionManager.h b/src/transport/SessionManager.h index fb84b95b48e37c..c3db1b9849b4f6 100644 --- a/src/transport/SessionManager.h +++ b/src/transport/SessionManager.h @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -184,7 +185,8 @@ class DLL_EXPORT SessionManager : public TransportMgrDelegate * @param messageCounterManager The message counter manager */ CHIP_ERROR Init(System::Layer * systemLayer, TransportMgrBase * transportMgr, - Transport::MessageCounterManagerInterface * messageCounterManager); + Transport::MessageCounterManagerInterface * messageCounterManager, + chip::PersistentStorageDelegate * storageDelegate); /** * @brief @@ -264,6 +266,9 @@ class DLL_EXPORT SessionManager : public TransportMgrDelegate TransportMgrBase * mTransportMgr = nullptr; Transport::MessageCounterManagerInterface * mMessageCounterManager = nullptr; + // Will be use once PR 14996 is merged + chip::PersistentStorageDelegate * mStorage = nullptr; + GlobalUnencryptedMessageCounter mGlobalUnencryptedMessageCounter; GlobalEncryptedMessageCounter mGlobalEncryptedMessageCounter; diff --git a/src/transport/tests/TestSessionManager.cpp b/src/transport/tests/TestSessionManager.cpp index acdc76e542afed..99c20e9c49b8c9 100644 --- a/src/transport/tests/TestSessionManager.cpp +++ b/src/transport/tests/TestSessionManager.cpp @@ -26,6 +26,7 @@ #include #include +#include #include #include #include @@ -101,13 +102,14 @@ void CheckSimpleInitTest(nlTestSuite * inSuite, void * inContext) TransportMgr transportMgr; SessionManager sessionManager; secure_channel::MessageCounterManager gMessageCounterManager; + chip::TestPersistentStorageDelegate deviceStorage; CHIP_ERROR err; err = transportMgr.Init("LOOPBACK"); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); - err = sessionManager.Init(&ctx.GetSystemLayer(), &transportMgr, &gMessageCounterManager); + err = sessionManager.Init(&ctx.GetSystemLayer(), &transportMgr, &gMessageCounterManager, &deviceStorage); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); } @@ -130,11 +132,12 @@ void CheckMessageTest(nlTestSuite * inSuite, void * inContext) TransportMgr transportMgr; SessionManager sessionManager; secure_channel::MessageCounterManager gMessageCounterManager; + chip::TestPersistentStorageDelegate deviceStorage; err = transportMgr.Init("LOOPBACK"); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); - err = sessionManager.Init(&ctx.GetSystemLayer(), &transportMgr, &gMessageCounterManager); + err = sessionManager.Init(&ctx.GetSystemLayer(), &transportMgr, &gMessageCounterManager, &deviceStorage); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); callback.mSuite = inSuite; @@ -222,11 +225,12 @@ void SendEncryptedPacketTest(nlTestSuite * inSuite, void * inContext) TransportMgr transportMgr; SessionManager sessionManager; secure_channel::MessageCounterManager gMessageCounterManager; + chip::TestPersistentStorageDelegate deviceStorage; err = transportMgr.Init("LOOPBACK"); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); - err = sessionManager.Init(&ctx.GetSystemLayer(), &transportMgr, &gMessageCounterManager); + err = sessionManager.Init(&ctx.GetSystemLayer(), &transportMgr, &gMessageCounterManager, &deviceStorage); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); callback.mSuite = inSuite; @@ -300,11 +304,12 @@ void SendBadEncryptedPacketTest(nlTestSuite * inSuite, void * inContext) TransportMgr transportMgr; SessionManager sessionManager; secure_channel::MessageCounterManager gMessageCounterManager; + chip::TestPersistentStorageDelegate deviceStorage; err = transportMgr.Init("LOOPBACK"); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); - err = sessionManager.Init(&ctx.GetSystemLayer(), &transportMgr, &gMessageCounterManager); + err = sessionManager.Init(&ctx.GetSystemLayer(), &transportMgr, &gMessageCounterManager, &deviceStorage); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); callback.mSuite = inSuite; @@ -406,11 +411,12 @@ void StaleConnectionDropTest(nlTestSuite * inSuite, void * inContext) TransportMgr transportMgr; SessionManager sessionManager; secure_channel::MessageCounterManager gMessageCounterManager; + chip::TestPersistentStorageDelegate deviceStorage; err = transportMgr.Init("LOOPBACK"); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); - err = sessionManager.Init(&ctx.GetSystemLayer(), &transportMgr, &gMessageCounterManager); + err = sessionManager.Init(&ctx.GetSystemLayer(), &transportMgr, &gMessageCounterManager, &deviceStorage); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); Optional peer(Transport::PeerAddress::UDP(addr, CHIP_PORT));