From a42ebecad6b361dfc20e314a5645b23121cdfd4a Mon Sep 17 00:00:00 2001 From: Kamil Kasperczyk Date: Wed, 27 Oct 2021 15:56:02 +0200 Subject: [PATCH] Added using CRA/CRI values in the controller for MRP intervals Controller is using default MRP retransmission interval values for all of the devices. According to spec it should use discovered CRA and CRI values for that purpose and set MRP parameters independently for every single device. * Added storing MRP intervals values in the CHIPDevice, SecureSession and UnathenticatedSession. * Added setting MRP intervals for sessions using discovered device data or if they are not available with the default values. * Added setting ReliableMessageContext config when creating every new ExchangeContext based on MRP intervals got from the SessionHandle * Changed INITIAL retransmission interval name in the Reliable Message module to IDLE as that is compatible with the spec --- src/app/server/Dnssd.cpp | 4 +-- src/channel/ChannelContext.cpp | 2 ++ src/controller/CHIPDevice.cpp | 13 ++++++++-- src/controller/CHIPDevice.h | 25 +++++++++++++------ src/controller/CHIPDeviceController.cpp | 9 ++++++- src/messaging/ExchangeMgr.cpp | 14 ++++++++++- src/messaging/ReliableMessageContext.cpp | 4 +-- src/messaging/ReliableMessageContext.h | 6 ++--- src/messaging/ReliableMessageMgr.cpp | 2 +- src/messaging/ReliableMessageProtocolConfig.h | 16 ++++++------ .../tests/TestReliableMessageProtocol.cpp | 14 +++++------ .../secure_channel/tests/TestPASESession.cpp | 4 +-- src/transport/SecureSession.h | 15 +++++++++++ src/transport/SessionHandle.cpp | 19 ++++++++++++++ src/transport/SessionHandle.h | 2 ++ src/transport/SessionManager.cpp | 2 ++ src/transport/UnauthenticatedSessionTable.h | 14 +++++++++++ 17 files changed, 129 insertions(+), 36 deletions(-) diff --git a/src/app/server/Dnssd.cpp b/src/app/server/Dnssd.cpp index 7c20d03e5fc4d9..6871d602fcd80f 100644 --- a/src/app/server/Dnssd.cpp +++ b/src/app/server/Dnssd.cpp @@ -263,7 +263,7 @@ CHIP_ERROR DnssdServer::AdvertiseOperational() .SetPeerId(fabricInfo.GetPeerId()) .SetMac(mac) .SetPort(GetSecuredPort()) - .SetMRPRetryIntervals(Optional(CHIP_CONFIG_MRP_DEFAULT_INITIAL_RETRY_INTERVAL), + .SetMRPRetryIntervals(Optional(CHIP_CONFIG_MRP_DEFAULT_IDLE_RETRY_INTERVAL), Optional(CHIP_CONFIG_MRP_DEFAULT_ACTIVE_RETRY_INTERVAL)) .SetTcpSupported(Optional(INET_CONFIG_ENABLE_TCP_ENDPOINT)) .EnableIpV4(true); @@ -344,7 +344,7 @@ CHIP_ERROR DnssdServer::Advertise(bool commissionableNode, chip::Dnssd::Commissi #endif advertiseParameters - .SetMRPRetryIntervals(Optional(CHIP_CONFIG_MRP_DEFAULT_INITIAL_RETRY_INTERVAL), + .SetMRPRetryIntervals(Optional(CHIP_CONFIG_MRP_DEFAULT_IDLE_RETRY_INTERVAL), Optional(CHIP_CONFIG_MRP_DEFAULT_ACTIVE_RETRY_INTERVAL)) .SetTcpSupported(Optional(INET_CONFIG_ENABLE_TCP_ENDPOINT)); diff --git a/src/channel/ChannelContext.cpp b/src/channel/ChannelContext.cpp index fd3e9bad30761c..e6a88ecfb926ce 100644 --- a/src/channel/ChannelContext.cpp +++ b/src/channel/ChannelContext.cpp @@ -271,6 +271,8 @@ void ChannelContext::EnterCasePairingState() EnterFailedState(CHIP_ERROR_NO_MEMORY); return; } + session.Value().GetUnauthenticatedSession()->SetMRPIntervals(CHIP_CONFIG_MRP_DEFAULT_IDLE_RETRY_INTERVAL, + CHIP_CONFIG_MRP_DEFAULT_ACTIVE_RETRY_INTERVAL); ExchangeContext * ctxt = mExchangeManager->NewContext(session.Value(), prepare.mCasePairingSession); VerifyOrReturn(ctxt != nullptr); diff --git a/src/controller/CHIPDevice.cpp b/src/controller/CHIPDevice.cpp index 04e5e6e9d6fefe..13e34886f82a45 100644 --- a/src/controller/CHIPDevice.cpp +++ b/src/controller/CHIPDevice.cpp @@ -271,6 +271,9 @@ void Device::OnNewConnection(SessionHandle session) // we need to restore the session counters along with the session information. Transport::SecureSession * secureSession = mSessionManager->GetSecureSession(mSecureSession.Value()); VerifyOrReturn(secureSession != nullptr); + + secureSession->SetMRPIntervals(mMrpIdleInterval, mMrpActiveInterval); + MessageCounter & localCounter = secureSession->GetSessionMessageCounter().GetLocalMessageCounter(); if (localCounter.SetCounter(mLocalMessageCounter) != CHIP_NO_ERROR) { @@ -420,11 +423,13 @@ CHIP_ERROR Device::CloseSession() return CHIP_NO_ERROR; } -CHIP_ERROR Device::UpdateAddress(const Transport::PeerAddress & addr) +CHIP_ERROR Device::UpdateDeviceData(const Transport::PeerAddress & addr, uint32_t mrpIdleInterval, uint32_t mrpActiveInterval) { bool didLoad; - mDeviceAddress = addr; + mDeviceAddress = addr; + mMrpIdleInterval = mrpIdleInterval; + mMrpActiveInterval = mrpActiveInterval; ReturnErrorOnFailure(LoadSecureSessionParametersIfNeeded(didLoad)); @@ -439,6 +444,7 @@ CHIP_ERROR Device::UpdateAddress(const Transport::PeerAddress & addr) Transport::SecureSession * secureSession = mSessionManager->GetSecureSession(mSecureSession.Value()); secureSession->SetPeerAddress(addr); + secureSession->SetMRPIntervals(mrpIdleInterval, mrpActiveInterval); return CHIP_NO_ERROR; } @@ -552,6 +558,9 @@ CHIP_ERROR Device::WarmupCASESession() { return CHIP_ERROR_NO_MEMORY; } + + session.Value().GetUnauthenticatedSession()->SetMRPIntervals(mMrpIdleInterval, mMrpActiveInterval); + Messaging::ExchangeContext * exchange = mExchangeMgr->NewContext(session.Value(), &mCASESession); VerifyOrReturnError(exchange != nullptr, CHIP_ERROR_INTERNAL); diff --git a/src/controller/CHIPDevice.h b/src/controller/CHIPDevice.h index ba11b8d5dd8d26..4b4922795ddbc1 100644 --- a/src/controller/CHIPDevice.h +++ b/src/controller/CHIPDevice.h @@ -348,17 +348,19 @@ class Device : public Messaging::ExchangeDelegate, public SessionEstablishmentDe /** * @brief - * Update address of the device. + * Update data of the device. * - * This function will set new IP address and port of the device. Since the device settings might - * have been moved from RAM to the persistent storage, the function will load the device settings - * first, before making the changes. + * This function will set new IP address, port and MRP retransmission intervals of the device. + * Since the device settings might have been moved from RAM to the persistent storage, the function + * will load the device settings first, before making the changes. * - * @param[in] addr Address of the device to be set. + * @param[in] addr Address of the device to be set. + * @param[in] mrpIdleInterval MRP idle retransmission interval of the device to be set. + * @param[in] mrpActiveInterval MRP active retransmision interval of the device to be set. * - * @return CHIP_NO_ERROR if the address has been updated, an error code otherwise. + * @return CHIP_NO_ERROR if the data has been updated, an error code otherwise. */ - CHIP_ERROR UpdateAddress(const Transport::PeerAddress & addr); + CHIP_ERROR UpdateDeviceData(const Transport::PeerAddress & addr, uint32_t mrpIdleInterval, uint32_t mrpActiveInterval); /** * @brief * Return whether the current device object is actively associated with a paired CHIP @@ -384,6 +386,12 @@ class Device : public Messaging::ExchangeDelegate, public SessionEstablishmentDe void SetAddress(const Inet::IPAddress & deviceAddr) { mDeviceAddress.SetIPAddress(deviceAddr); } + void GetMRPIntervals(uint32_t & idleInterval, uint32_t & activeInterval) const + { + idleInterval = mMrpIdleInterval; + activeInterval = mMrpActiveInterval; + } + PASESessionSerializable & GetPairing() { return mPairing; } uint8_t GetNextSequenceNumber() { return mSequenceNumber++; }; @@ -486,6 +494,9 @@ class Device : public Messaging::ExchangeDelegate, public SessionEstablishmentDe */ Transport::PeerAddress mDeviceAddress = Transport::PeerAddress::UDP(Inet::IPAddress::Any); + uint32_t mMrpIdleInterval = CHIP_CONFIG_MRP_DEFAULT_IDLE_RETRY_INTERVAL; + uint32_t mMrpActiveInterval = CHIP_CONFIG_MRP_DEFAULT_ACTIVE_RETRY_INTERVAL; + Inet::InetLayer * mInetLayer = nullptr; bool mActive = false; diff --git a/src/controller/CHIPDeviceController.cpp b/src/controller/CHIPDeviceController.cpp index b468d485fde26f..d4ccd3c41f6eb8 100644 --- a/src/controller/CHIPDeviceController.cpp +++ b/src/controller/CHIPDeviceController.cpp @@ -559,7 +559,9 @@ void DeviceController::OnNodeIdResolved(const chip::Dnssd::ResolvedNodeData & no interfaceId = nodeData.mInterfaceId; } - err = device->UpdateAddress(Transport::PeerAddress::UDP(nodeData.mAddress, nodeData.mPort, interfaceId)); + err = device->UpdateDeviceData(Transport::PeerAddress::UDP(nodeData.mAddress, nodeData.mPort, interfaceId), + nodeData.GetMrpRetryIntervalIdle().ValueOr(CHIP_CONFIG_MRP_DEFAULT_IDLE_RETRY_INTERVAL), + nodeData.GetMrpRetryIntervalActive().ValueOr(CHIP_CONFIG_MRP_DEFAULT_ACTIVE_RETRY_INTERVAL)); SuccessOrExit(err); PersistDevice(device); @@ -693,6 +695,7 @@ CHIP_ERROR DeviceCommissioner::PairDevice(NodeId remoteDeviceId, RendezvousParam CHIP_ERROR err = CHIP_NO_ERROR; Device * device = nullptr; Transport::PeerAddress peerAddress = Transport::PeerAddress::UDP(Inet::IPAddress::Any); + uint32_t mrpIdleInterval, mrpActiveInterval; Messaging::ExchangeContext * exchangeCtxt = nullptr; Optional session; @@ -789,6 +792,10 @@ CHIP_ERROR DeviceCommissioner::PairDevice(NodeId remoteDeviceId, RendezvousParam session = mSystemState->SessionMgr()->CreateUnauthenticatedSession(params.GetPeerAddress()); VerifyOrExit(session.HasValue(), err = CHIP_ERROR_NO_MEMORY); + // TODO: In some cases like PASE over IP, CRA and CRI values from commissionable node service should be used + device->GetMRPIntervals(mrpIdleInterval, mrpActiveInterval); + session.Value().GetUnauthenticatedSession()->SetMRPIntervals(mrpIdleInterval, mrpActiveInterval); + exchangeCtxt = mSystemState->ExchangeMgr()->NewContext(session.Value(), &mPairingSession); VerifyOrExit(exchangeCtxt != nullptr, err = CHIP_ERROR_INTERNAL); diff --git a/src/messaging/ExchangeMgr.cpp b/src/messaging/ExchangeMgr.cpp index 07a11a5be24dbc..d562331a9703e1 100644 --- a/src/messaging/ExchangeMgr.cpp +++ b/src/messaging/ExchangeMgr.cpp @@ -116,7 +116,19 @@ CHIP_ERROR ExchangeManager::Shutdown() ExchangeContext * ExchangeManager::NewContext(SessionHandle session, ExchangeDelegate * delegate) { - return mContextPool.CreateObject(this, mNextExchangeId++, session, true, delegate); + ExchangeContext * context = mContextPool.CreateObject(this, mNextExchangeId++, session, true, delegate); + + uint32_t mrpIdleInterval = CHIP_CONFIG_MRP_DEFAULT_IDLE_RETRY_INTERVAL; + uint32_t mrpActiveInterval = CHIP_CONFIG_MRP_DEFAULT_ACTIVE_RETRY_INTERVAL; + + session.GetMRPIntervals(GetSessionManager(), mrpIdleInterval, mrpActiveInterval); + + ReliableMessageProtocolConfig mrpConfig; + mrpConfig.mIdleRetransTimeoutTick = mrpIdleInterval >> CHIP_CONFIG_RMP_TIMER_DEFAULT_PERIOD_SHIFT; + mrpConfig.mActiveRetransTimeoutTick = mrpActiveInterval >> CHIP_CONFIG_RMP_TIMER_DEFAULT_PERIOD_SHIFT; + context->GetReliableMessageContext()->SetConfig(mrpConfig); + + return context; } CHIP_ERROR ExchangeManager::RegisterUnsolicitedMessageHandlerForProtocol(Protocols::Id protocolId, ExchangeDelegate * delegate) diff --git a/src/messaging/ReliableMessageContext.cpp b/src/messaging/ReliableMessageContext.cpp index e30447050e0fd4..9fa465aabda2d6 100644 --- a/src/messaging/ReliableMessageContext.cpp +++ b/src/messaging/ReliableMessageContext.cpp @@ -131,9 +131,9 @@ bool ReliableMessageContext::HasPiggybackAckPending() const return mFlags.Has(Flags::kFlagAckMessageCounterIsValid); } -uint64_t ReliableMessageContext::GetInitialRetransmitTimeoutTick() +uint64_t ReliableMessageContext::GetIdleRetransmitTimeoutTick() { - return mConfig.mInitialRetransTimeoutTick; + return mConfig.mIdleRetransTimeoutTick; } uint64_t ReliableMessageContext::GetActiveRetransmitTimeoutTick() diff --git a/src/messaging/ReliableMessageContext.h b/src/messaging/ReliableMessageContext.h index 247e7d3e4e3796..4ced8884e02ce2 100644 --- a/src/messaging/ReliableMessageContext.h +++ b/src/messaging/ReliableMessageContext.h @@ -76,12 +76,12 @@ class ReliableMessageContext bool HasPiggybackAckPending() const; /** - * Get the initial retransmission interval. It would be the time to wait before + * Get the idle retransmission interval. It would be the time to wait before * retransmission after first failure. * - * @return the initial retransmission interval. + * @return the idle retransmission interval. */ - uint64_t GetInitialRetransmitTimeoutTick(); + uint64_t GetIdleRetransmitTimeoutTick(); /** * Get the active retransmit interval. It would be the time to wait before diff --git a/src/messaging/ReliableMessageMgr.cpp b/src/messaging/ReliableMessageMgr.cpp index 05eea6d942e691..a156f7d489b07b 100644 --- a/src/messaging/ReliableMessageMgr.cpp +++ b/src/messaging/ReliableMessageMgr.cpp @@ -278,7 +278,7 @@ CHIP_ERROR ReliableMessageMgr::AddToRetransTable(ReliableMessageContext * rc, Re void ReliableMessageMgr::StartRetransmision(RetransTableEntry * entry) { - entry->nextRetransTimeTick = static_cast(entry->ec->GetInitialRetransmitTimeoutTick() + + entry->nextRetransTimeTick = static_cast(entry->ec->GetIdleRetransmitTimeoutTick() + GetTickCounterFromTimeDelta(System::SystemClock().GetMonotonicTimestamp())); // Check if the timer needs to be started and start it. diff --git a/src/messaging/ReliableMessageProtocolConfig.h b/src/messaging/ReliableMessageProtocolConfig.h index e8a93662a24e9c..fda12268157077 100644 --- a/src/messaging/ReliableMessageProtocolConfig.h +++ b/src/messaging/ReliableMessageProtocolConfig.h @@ -58,18 +58,18 @@ namespace Messaging { #endif // CHIP_CONFIG_MRP_DEFAULT_ACTIVE_RETRY_INTERVAL /** - * @def CHIP_CONFIG_MRP_DEFAULT_INITIAL_RETRY_INTERVAL + * @def CHIP_CONFIG_MRP_DEFAULT_IDLE_RETRY_INTERVAL * * @brief - * Initial retransmission interval, or time to wait before retransmission after first + * Initial base retransmission interval, or time to wait before retransmission after first * failure in milliseconds. * * This is the default value, that might be adjusted by end device depending on its * needs (e.g. sleeping period) using Service Discovery TXT record CRI key. */ -#ifndef CHIP_CONFIG_MRP_DEFAULT_INITIAL_RETRY_INTERVAL -#define CHIP_CONFIG_MRP_DEFAULT_INITIAL_RETRY_INTERVAL (5000) -#endif // CHIP_CONFIG_MRP_DEFAULT_INITIAL_RETRY_INTERVAL +#ifndef CHIP_CONFIG_MRP_DEFAULT_IDLE_RETRY_INTERVAL +#define CHIP_CONFIG_MRP_DEFAULT_IDLE_RETRY_INTERVAL (5000) +#endif // CHIP_CONFIG_MRP_DEFAULT_IDLE_RETRY_INTERVAL /** * @def CHIP_CONFIG_RMP_DEFAULT_ACK_TIMEOUT_TICK @@ -118,12 +118,12 @@ namespace Messaging { */ struct ReliableMessageProtocolConfig { - uint32_t mInitialRetransTimeoutTick; /**< Configurable timeout in msec for retransmission of the first sent message. */ - uint32_t mActiveRetransTimeoutTick; /**< Configurable timeout in msec for retransmission of all subsequent messages. */ + uint32_t mIdleRetransTimeoutTick; /**< Configurable timeout in msec for retransmission of the first sent message. */ + uint32_t mActiveRetransTimeoutTick; /**< Configurable timeout in msec for retransmission of all subsequent messages. */ }; const ReliableMessageProtocolConfig gDefaultReliableMessageProtocolConfig = { - CHIP_CONFIG_MRP_DEFAULT_INITIAL_RETRY_INTERVAL >> CHIP_CONFIG_RMP_TIMER_DEFAULT_PERIOD_SHIFT, + CHIP_CONFIG_MRP_DEFAULT_IDLE_RETRY_INTERVAL >> CHIP_CONFIG_RMP_TIMER_DEFAULT_PERIOD_SHIFT, CHIP_CONFIG_MRP_DEFAULT_ACTIVE_RETRY_INTERVAL >> CHIP_CONFIG_RMP_TIMER_DEFAULT_PERIOD_SHIFT }; diff --git a/src/messaging/tests/TestReliableMessageProtocol.cpp b/src/messaging/tests/TestReliableMessageProtocol.cpp index b11ba217793522..994170f11396d7 100644 --- a/src/messaging/tests/TestReliableMessageProtocol.cpp +++ b/src/messaging/tests/TestReliableMessageProtocol.cpp @@ -232,7 +232,7 @@ void CheckResendApplicationMessage(nlTestSuite * inSuite, void * inContext) NL_TEST_ASSERT(inSuite, rc != nullptr); rc->SetConfig({ - 1, // CHIP_CONFIG_MRP_DEFAULT_INITIAL_RETRY_INTERVAL + 1, // CHIP_CONFIG_MRP_DEFAULT_IDLE_RETRY_INTERVAL 1, // CHIP_CONFIG_MRP_DEFAULT_ACTIVE_RETRY_INTERVAL }); @@ -297,7 +297,7 @@ void CheckCloseExchangeAndResendApplicationMessage(nlTestSuite * inSuite, void * NL_TEST_ASSERT(inSuite, rc != nullptr); rc->SetConfig({ - 1, // CHIP_CONFIG_MRP_DEFAULT_INITIAL_RETRY_INTERVAL + 1, // CHIP_CONFIG_MRP_DEFAULT_IDLE_RETRY_INTERVAL 1, // CHIP_CONFIG_MRP_DEFAULT_ACTIVE_RETRY_INTERVAL }); @@ -359,7 +359,7 @@ void CheckFailedMessageRetainOnSend(nlTestSuite * inSuite, void * inContext) NL_TEST_ASSERT(inSuite, rc != nullptr); rc->SetConfig({ - 1, // CHIP_CONFIG_MRP_DEFAULT_INITIAL_RETRY_INTERVAL + 1, // CHIP_CONFIG_MRP_DEFAULT_IDLE_RETRY_INTERVAL 1, // CHIP_CONFIG_MRP_DEFAULT_ACTIVE_RETRY_INTERVAL }); @@ -455,7 +455,7 @@ void CheckResendApplicationMessageWithPeerExchange(nlTestSuite * inSuite, void * NL_TEST_ASSERT(inSuite, rc != nullptr); rc->SetConfig({ - 1, // CHIP_CONFIG_MRP_DEFAULT_INITIAL_RETRY_INTERVAL + 1, // CHIP_CONFIG_MRP_DEFAULT_IDLE_RETRY_INTERVAL 1, // CHIP_CONFIG_MRP_DEFAULT_ACTIVE_RETRY_INTERVAL }); @@ -592,7 +592,7 @@ void CheckResendSessionEstablishmentMessageWithPeerExchange(nlTestSuite * inSuit NL_TEST_ASSERT(inSuite, rc != nullptr); rc->SetConfig({ - 1, // CHIP_CONFIG_MRP_DEFAULT_INITIAL_RETRY_INTERVAL + 1, // CHIP_CONFIG_MRP_DEFAULT_IDLE_RETRY_INTERVAL 1, // CHIP_CONFIG_MRP_DEFAULT_ACTIVE_RETRY_INTERVAL }); @@ -1146,7 +1146,7 @@ void CheckLostResponseWithPiggyback(nlTestSuite * inSuite, void * inContext) // Make sure that we resend our message before the other side does. ReliableMessageContext * rc = exchange->GetReliableMessageContext(); rc->SetConfig({ - 1, // CHIP_CONFIG_MRP_DEFAULT_INITIAL_RETRY_INTERVAL + 1, // CHIP_CONFIG_MRP_DEFAULT_IDLE_RETRY_INTERVAL 1, // CHIP_CONFIG_MRP_DEFAULT_ACTIVE_RETRY_INTERVAL }); @@ -1182,7 +1182,7 @@ void CheckLostResponseWithPiggyback(nlTestSuite * inSuite, void * inContext) // that we are very unlikely to actually trigger the resends on the receiver // when we trigger the resends on the sender. receiverRc->SetConfig({ - 4, // CHIP_CONFIG_MRP_DEFAULT_INITIAL_RETRY_INTERVAL + 4, // CHIP_CONFIG_MRP_DEFAULT_IDLE_RETRY_INTERVAL 4, // CHIP_CONFIG_MRP_DEFAULT_ACTIVE_RETRY_INTERVAL }); diff --git a/src/protocols/secure_channel/tests/TestPASESession.cpp b/src/protocols/secure_channel/tests/TestPASESession.cpp index 0491207cb42a27..3d21abefeaaf40 100644 --- a/src/protocols/secure_channel/tests/TestPASESession.cpp +++ b/src/protocols/secure_channel/tests/TestPASESession.cpp @@ -175,7 +175,7 @@ void SecurePairingHandshakeTestCommon(nlTestSuite * inSuite, void * inContext, P NL_TEST_ASSERT(inSuite, rc != nullptr); rc->SetConfig({ - 1, // CHIP_CONFIG_MRP_DEFAULT_INITIAL_RETRY_INTERVAL + 1, // CHIP_CONFIG_MRP_DEFAULT_IDLE_RETRY_INTERVAL 1, // CHIP_CONFIG_MRP_DEFAULT_ACTIVE_RETRY_INTERVAL }); gLoopback.mContext = &ctx; @@ -245,7 +245,7 @@ void SecurePairingFailedHandshake(nlTestSuite * inSuite, void * inContext) NL_TEST_ASSERT(inSuite, rc != nullptr); rc->SetConfig({ - 1, // CHIP_CONFIG_MRP_DEFAULT_INITIAL_RETRY_INTERVAL + 1, // CHIP_CONFIG_MRP_DEFAULT_IDLE_RETRY_INTERVAL 1, // CHIP_CONFIG_MRP_DEFAULT_ACTIVE_RETRY_INTERVAL }); gLoopback.mContext = &ctx; diff --git a/src/transport/SecureSession.h b/src/transport/SecureSession.h index a3f098ac31d8d8..9c8ed346d957db 100644 --- a/src/transport/SecureSession.h +++ b/src/transport/SecureSession.h @@ -67,6 +67,19 @@ class SecureSession void SetPeerAddress(const PeerAddress & address) { mPeerAddress = address; } NodeId GetPeerNodeId() const { return mPeerNodeId; } + + void GetMRPIntervals(uint32_t & idleInterval, uint32_t & activeInterval) + { + idleInterval = mMRPIdleInterval; + activeInterval = mMRPActiveInterval; + } + + void SetMRPIntervals(uint32_t idleInterval, uint32_t activeInterval) + { + mMRPIdleInterval = idleInterval; + mMRPActiveInterval = activeInterval; + } + uint16_t GetLocalSessionId() const { return mLocalSessionId; } uint16_t GetPeerSessionId() const { return mPeerSessionId; } FabricIndex GetFabricIndex() const { return mFabric; } @@ -98,6 +111,8 @@ class SecureSession PeerAddress mPeerAddress; System::Clock::Timestamp mLastActivityTime = System::Clock::kZero; + uint32_t mMRPIdleInterval = 0; + uint32_t mMRPActiveInterval = 0; CryptoContext mCryptoContext; SessionMessageCounter mSessionMessageCounter; }; diff --git a/src/transport/SessionHandle.cpp b/src/transport/SessionHandle.cpp index a5af407da4a1c5..9865eb8d71321f 100644 --- a/src/transport/SessionHandle.cpp +++ b/src/transport/SessionHandle.cpp @@ -39,4 +39,23 @@ const PeerAddress * SessionHandle::GetPeerAddress(SessionManager * sessionManage return &GetUnauthenticatedSession()->GetPeerAddress(); } +CHIP_ERROR SessionHandle::GetMRPIntervals(SessionManager * sessionManager, uint32_t & mrpIdleInterval, uint32_t & mrpActiveInterval) +{ + if (IsSecure()) + { + SecureSession * secureSession = sessionManager->GetSecureSession(*this); + if (secureSession == nullptr) + { + return CHIP_ERROR_INVALID_ARGUMENT; + } + secureSession->GetMRPIntervals(mrpIdleInterval, mrpActiveInterval); + + return CHIP_NO_ERROR; + } + + GetUnauthenticatedSession()->GetMRPIntervals(mrpIdleInterval, mrpActiveInterval); + + return CHIP_NO_ERROR; +} + } // namespace chip diff --git a/src/transport/SessionHandle.h b/src/transport/SessionHandle.h index 3502e9ae3bbb9f..8de4c48595637c 100644 --- a/src/transport/SessionHandle.h +++ b/src/transport/SessionHandle.h @@ -82,6 +82,8 @@ class SessionHandle // torn down, at the very least. const Transport::PeerAddress * GetPeerAddress(SessionManager * sessionManager) const; + CHIP_ERROR GetMRPIntervals(SessionManager * sessionManager, uint32_t & mrpIdleInterval, uint32_t & mrpActiveInterval); + Transport::UnauthenticatedSessionHandle GetUnauthenticatedSession() const { return mUnauthenticatedSessionHandle.Value(); } private: diff --git a/src/transport/SessionManager.cpp b/src/transport/SessionManager.cpp index d3d0e80df9f950..94585233b723fa 100644 --- a/src/transport/SessionManager.cpp +++ b/src/transport/SessionManager.cpp @@ -284,6 +284,8 @@ CHIP_ERROR SessionManager::NewPairing(const Optional & p return CHIP_ERROR_INVALID_ARGUMENT; } + session->SetMRPIntervals(CHIP_CONFIG_MRP_DEFAULT_IDLE_RETRY_INTERVAL, CHIP_CONFIG_MRP_DEFAULT_ACTIVE_RETRY_INTERVAL); + ReturnErrorOnFailure(pairing->DeriveSecureSession(session->GetCryptoContext(), direction)); if (mCB != nullptr) diff --git a/src/transport/UnauthenticatedSessionTable.h b/src/transport/UnauthenticatedSessionTable.h index a4a3cdfa50098a..b121edd29b8f61 100644 --- a/src/transport/UnauthenticatedSessionTable.h +++ b/src/transport/UnauthenticatedSessionTable.h @@ -59,12 +59,26 @@ class UnauthenticatedSession : public ReferenceCounted