From 37fef5ed547421e627b69193798d2556b3cebe19 Mon Sep 17 00:00:00 2001 From: Ashish <104561745+aashu216@users.noreply.github.com> Date: Wed, 28 Feb 2024 05:31:29 +0530 Subject: [PATCH] [spinel] drop received frames between RCP disable and reset (#9793) Signed-off-by: Ashishkumar Vara --- src/lib/spinel/multi_frame_buffer.hpp | 2 +- src/lib/spinel/radio_spinel.cpp | 3 +++ src/lib/spinel/spinel_encoder.cpp | 2 ++ src/lib/spinel/spinel_encoder.hpp | 6 ++++++ src/ncp/ncp_base.cpp | 2 ++ 5 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/lib/spinel/multi_frame_buffer.hpp b/src/lib/spinel/multi_frame_buffer.hpp index ab1ef835b..61945a5ca 100644 --- a/src/lib/spinel/multi_frame_buffer.hpp +++ b/src/lib/spinel/multi_frame_buffer.hpp @@ -371,7 +371,7 @@ public: aFrame = (aFrame == nullptr) ? mBuffer : aFrame + aLength; - if (aFrame != mWriteFrameStart) + if (HasSavedFrame() && (aFrame != mWriteFrameStart)) { uint16_t totalLength = LittleEndian::ReadUint16(aFrame + kHeaderTotalLengthOffset); uint16_t skipLength = LittleEndian::ReadUint16(aFrame + kHeaderSkipLengthOffset); diff --git a/src/lib/spinel/radio_spinel.cpp b/src/lib/spinel/radio_spinel.cpp index b41fde342..a0ab17238 100644 --- a/src/lib/spinel/radio_spinel.cpp +++ b/src/lib/spinel/radio_spinel.cpp @@ -670,6 +670,9 @@ void RadioSpinel::HandleValueIs(spinel_prop_key_t aKey, const uint8_t *aBuffer, ExitNow(); } + // this clear is necessary in case the RCP has sent messages between disable and reset + mRxFrameBuffer.Clear(); + LogInfo("RCP reset: %s", spinel_status_to_cstr(status)); sIsReady = true; } diff --git a/src/lib/spinel/spinel_encoder.cpp b/src/lib/spinel/spinel_encoder.cpp index 91a9ec36c..6cd390486 100644 --- a/src/lib/spinel/spinel_encoder.cpp +++ b/src/lib/spinel/spinel_encoder.cpp @@ -291,5 +291,7 @@ exit: return error; } +void Encoder::ClearNcpBuffer(void) { mNcpBuffer.Clear(); } + } // namespace Spinel } // namespace ot diff --git a/src/lib/spinel/spinel_encoder.hpp b/src/lib/spinel/spinel_encoder.hpp index 6b9ea983d..c678519b4 100644 --- a/src/lib/spinel/spinel_encoder.hpp +++ b/src/lib/spinel/spinel_encoder.hpp @@ -676,6 +676,12 @@ public: */ otError ResetToSaved(void); + /** + * Clear NCP buffer on reset command. + * + */ + void ClearNcpBuffer(void); + private: enum { diff --git a/src/ncp/ncp_base.cpp b/src/ncp/ncp_base.cpp index e0b4c1881..a1ad3adb3 100644 --- a/src/ncp/ncp_base.cpp +++ b/src/ncp/ncp_base.cpp @@ -1285,6 +1285,8 @@ otError NcpBase::CommandHandler_RESET(uint8_t aHeader) ResetCounters(); + mEncoder.ClearNcpBuffer(); + SuccessOrAssert(error = WriteLastStatusFrame(SPINEL_HEADER_FLAG | SPINEL_HEADER_TX_NOTIFICATION_IID, SPINEL_STATUS_RESET_POWER_ON)); }