diff --git a/src/messaging/ExchangeMgr.cpp b/src/messaging/ExchangeMgr.cpp index fc5bea10b83e22..369a3c977626cf 100644 --- a/src/messaging/ExchangeMgr.cpp +++ b/src/messaging/ExchangeMgr.cpp @@ -342,5 +342,16 @@ void ExchangeManager::CloseAllContextsForDelegate(const ExchangeDelegate * deleg }); } +void ExchangeManager::AbortExchangeForNodeExceptOne(const ScopedNodeId & node, ExchangeContext * stay) +{ + mContextPool.ForEachActiveObject([&](auto * ec) { + if (ec != stay && ec->HasSessionHandle() && ec->GetSessionHandle()->GetPeer() == node) + { + ec->Abort(); + } + return Loop::Continue; + }); +} + } // namespace Messaging } // namespace chip diff --git a/src/messaging/ExchangeMgr.h b/src/messaging/ExchangeMgr.h index 1c0a783703a343..9d08cd5587ab42 100644 --- a/src/messaging/ExchangeMgr.h +++ b/src/messaging/ExchangeMgr.h @@ -183,6 +183,9 @@ class DLL_EXPORT ExchangeManager : public SessionMessageDelegate */ void CloseAllContextsForDelegate(const ExchangeDelegate * delegate); + // This API is used by UpdateNOC command, to invalid all exchanges except the given one. + void AbortExchangeForNodeExceptOne(const ScopedNodeId & node, ExchangeContext * stay); + SessionManager * GetSessionManager() const { return mSessionManager; } ReliableMessageMgr * GetReliableMessageMgr() { return &mReliableMessageMgr; }; diff --git a/src/transport/SessionManager.cpp b/src/transport/SessionManager.cpp index 0298e4595f09ab..fa56b6ee6f9fda 100644 --- a/src/transport/SessionManager.cpp +++ b/src/transport/SessionManager.cpp @@ -387,6 +387,17 @@ void SessionManager::ExpireAllPASEPairings() }); } +void SessionManager::ReleaseSessionForNodeExceptOne(const ScopedNodeId & node, const SessionHandle & stay) +{ + mSecureSessions.ForEachSession([&](auto session) { + if (session->GetPeer() == node && session != stay->AsSecureSession()) + { + session->MarkForRemoval(); + } + return Loop::Continue; + }); +} + Optional SessionManager::AllocateSession(SecureSession::Type secureSessionType) { return mSecureSessions.CreateNewSecureSession(secureSessionType); diff --git a/src/transport/SessionManager.h b/src/transport/SessionManager.h index a3ed1f5b440474..2d60d77e45a71f 100644 --- a/src/transport/SessionManager.h +++ b/src/transport/SessionManager.h @@ -171,6 +171,9 @@ class DLL_EXPORT SessionManager : public TransportMgrDelegate void ExpireAllPairingsForFabric(FabricIndex fabric); void ExpireAllPASEPairings(); + // This API is used by UpdateNOC command, to invalid all sessions except the given one. + void ReleaseSessionForNodeExceptOne(const ScopedNodeId & node, const SessionHandle & stay); + /** * @brief * Return the System Layer pointer used by current SessionManager.