diff --git a/src/protocols/secure_channel/CASESession.cpp b/src/protocols/secure_channel/CASESession.cpp index ca15c021416f75..50afc4383ff9c1 100644 --- a/src/protocols/secure_channel/CASESession.cpp +++ b/src/protocols/secure_channel/CASESession.cpp @@ -137,8 +137,6 @@ void CASESession::Clear() mState = State::kInitialized; Crypto::ClearSecretData(mIPK); - AbortExchange(); - mLocalNodeId = kUndefinedNodeId; mPeerNodeId = kUndefinedNodeId; mFabricInfo = nullptr; diff --git a/src/protocols/secure_channel/PASESession.cpp b/src/protocols/secure_channel/PASESession.cpp index 942fb065312f17..790fd5c530f83c 100644 --- a/src/protocols/secure_channel/PASESession.cpp +++ b/src/protocols/secure_channel/PASESession.cpp @@ -96,7 +96,6 @@ void PASESession::Clear() mKeLen = sizeof(mKe); mPairingComplete = false; PairingSession::Clear(); - CloseExchange(); } CHIP_ERROR PASESession::Init(SessionManager & sessionManager, uint32_t setupCode, SessionEstablishmentDelegate * delegate) diff --git a/src/protocols/secure_channel/PairingSession.cpp b/src/protocols/secure_channel/PairingSession.cpp index 51011bd2dcf3e8..f93b79e81989b1 100644 --- a/src/protocols/secure_channel/PairingSession.cpp +++ b/src/protocols/secure_channel/PairingSession.cpp @@ -75,28 +75,6 @@ void PairingSession::Finish() } } -void PairingSession::AbortExchange() -{ - if (mExchangeCtxt != nullptr) - { - // The only time we reach this is if we are getting destroyed in the - // middle of our handshake. In that case, there is no point trying to - // do MRP resends of the last message we sent, so abort the exchange - // instead of just closing it. - mExchangeCtxt->Abort(); - mExchangeCtxt = nullptr; - } -} - -void PairingSession::CloseExchange() -{ - if (mExchangeCtxt != nullptr) - { - mExchangeCtxt->Close(); - mExchangeCtxt = nullptr; - } -} - void PairingSession::DiscardExchange() { if (mExchangeCtxt != nullptr) @@ -162,6 +140,19 @@ CHIP_ERROR PairingSession::DecodeMRPParametersIfPresent(TLV::Tag expectedTag, TL void PairingSession::Clear() { + // Clear acts like the destructor if PairingSession, if it is call during + // middle of a pairing, means we should terminate the exchange. For normal + // path, the exchange should already be discarded before calling Clear. + if (mExchangeCtxt != nullptr) + { + // The only time we reach this is if we are getting destroyed in the + // middle of our handshake. In that case, there is no point trying to + // do MRP resends of the last message we sent, so abort the exchange + // instead of just closing it. + mExchangeCtxt->Abort(); + mExchangeCtxt = nullptr; + } + if (mSessionManager != nullptr) { if (mSecureSessionHolder && !mSecureSessionHolder->AsSecureSession()->IsActiveSession()) diff --git a/src/protocols/secure_channel/PairingSession.h b/src/protocols/secure_channel/PairingSession.h index 5aaa9f7ddb9785..de75684384f71d 100644 --- a/src/protocols/secure_channel/PairingSession.h +++ b/src/protocols/secure_channel/PairingSession.h @@ -98,9 +98,7 @@ class DLL_EXPORT PairingSession void Finish(); - void AbortExchange(); - void CloseExchange(); - void DiscardExchange(); + void DiscardExchange(); // Clear our reference to our exchange context pointer so that it can close itself at some later time. void SetPeerSessionId(uint16_t id) { mPeerSessionId.SetValue(id); } virtual void OnSuccessStatusReport() {}