From ab28127a2a9e7b7212e1bd943d3f55a4d9db5f4a Mon Sep 17 00:00:00 2001 From: Zhangwx Date: Thu, 25 Jan 2024 07:05:36 +0800 Subject: [PATCH] [spinel] fix passing an unexpected transmit error to mac layer (#9745) For the Spinel layer, when the state is transmitting, if the received Spinel frame fails parsing, the current implementation passes the `OT_ERROR_PARSE` error code to the sub_mac layer via the tx done handler. This causes an assert because the error code `OT_ERROR_PARSE` is not a valid one for `SubMac::HandleTransmitDone`. Additionally, I believe that when the received Spinel frame fails parsing, we should not trigger a transmit done to the sub_mac layer, as the `TxFrame` and the `AckFrame` may not be valid for further processing. In this corner case, I suggest considering ignoring the parsing-failed received packets, waiting for the tx timeout, and then raising a tx timeout failure to recover the RCP. This might be a reasonable approach. --- src/lib/spinel/radio_spinel.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/lib/spinel/radio_spinel.cpp b/src/lib/spinel/radio_spinel.cpp index 495a9bb1c..15d90b542 100644 --- a/src/lib/spinel/radio_spinel.cpp +++ b/src/lib/spinel/radio_spinel.cpp @@ -1763,8 +1763,18 @@ void RadioSpinel::HandleTransmitDone(uint32_t aCommand, } exit: - mState = kStateTransmitDone; - mTxError = error; + // A parse error indicates an RCP misbehavior, so recover the RCP immediately. + mState = kStateTransmitDone; + if (error != OT_ERROR_PARSE) + { + mTxError = error; + } + else + { + mTxError = kErrorAbort; + HandleRcpTimeout(); + RecoverFromRcpFailure(); + } UpdateParseErrorCount(error); LogIfFail("Handle transmit done failed", error); }