From 7f394ea47e1951882ee550a9ea6f1ec8594f055e Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Tue, 25 Aug 2026 20:01:21 -0700 Subject: [PATCH] [mac] pass only data frames to MeshForwarder (#13552) This commit simplifies frame dispatch in `Mac::HandleReceivedFrame()` so that only MAC Data frames (`kTypeData`) are forwarded to `MeshForwarder::HandleReceivedFrame()`: - Consumes MAC command frames (`kTypeMacCmd`) and Beacon frames (`kTypeBeacon`) entirely within the MAC layer, avoiding unnecessary forwarding to `MeshForwarder`. - Changes `Mac::HandleMacCommand()` return type to `void` since all MAC command frames are handled at the MAC layer. - Scopes `DumpDebg("RX", ...)`, `MeshForwarder::HandleReceivedFrame()`, and `UpdateIdleMode()` directly to `case Frame::kTypeData`. - Removes the outer `switch (aFrame.GetType())` in `MeshForwarder::HandleReceivedFrame()`, allowing it to directly parse 6LoWPAN headers and eliminating redundant address/payload parsing and supervision listener updates for non-data frames. --- src/core/mac/mac.cpp | 23 +++++----------- src/core/mac/mac.hpp | 2 +- src/core/thread/mesh_forwarder.cpp | 43 +++++++++++------------------- 3 files changed, 22 insertions(+), 46 deletions(-) diff --git a/src/core/mac/mac.cpp b/src/core/mac/mac.cpp index dcac46e33..6431b24f9 100644 --- a/src/core/mac/mac.cpp +++ b/src/core/mac/mac.cpp @@ -2072,11 +2072,7 @@ void Mac::HandleReceivedFrame(RxFrame *aFrame, Error aError) switch (aFrame->GetType()) { case Frame::kTypeMacCmd: - if (HandleMacCommand(*aFrame)) // returns `true` when handled - { - ExitNow(error = kErrorNone); - } - + HandleMacCommand(*aFrame); break; case Frame::kTypeBeacon: @@ -2085,18 +2081,16 @@ void Mac::HandleReceivedFrame(RxFrame *aFrame, Error aError) case Frame::kTypeData: mCounters.mRxData++; + DumpDebg("RX", aFrame->GetPsdu(), aFrame->GetLength()); + Get().HandleReceivedFrame(*aFrame); + UpdateIdleMode(); break; default: mCounters.mRxOther++; - ExitNow(); + break; } - DumpDebg("RX", aFrame->GetPsdu(), aFrame->GetLength()); - Get().HandleReceivedFrame(*aFrame); - - UpdateIdleMode(); - exit: if (error != kErrorNone) @@ -2195,9 +2189,8 @@ exit: return; } -bool Mac::HandleMacCommand(RxFrame &aFrame) +void Mac::HandleMacCommand(RxFrame &aFrame) { - bool didHandle = false; uint8_t commandId; IgnoreError(aFrame.GetCommandId(commandId)); @@ -2216,14 +2209,12 @@ bool Mac::HandleMacCommand(RxFrame &aFrame) StartOperation(kOperationTransmitBeacon); } - didHandle = true; break; case Frame::kMacCmdDataRequest: mCounters.mRxDataPoll++; #if OPENTHREAD_FTD Get().HandleDataPoll(aFrame); - didHandle = true; #endif break; @@ -2231,8 +2222,6 @@ bool Mac::HandleMacCommand(RxFrame &aFrame) mCounters.mRxOther++; break; } - - return didHandle; } void Mac::SetPromiscuous(bool aPromiscuous) diff --git a/src/core/mac/mac.hpp b/src/core/mac/mac.hpp index b16247bc4..ca9ce45f5 100644 --- a/src/core/mac/mac.hpp +++ b/src/core/mac/mac.hpp @@ -790,7 +790,7 @@ private: void BeginTransmit(void); Error FilterDestShortAddress(ShortAddress aDestAddress) const; void UpdateNeighborLinkInfo(Neighbor &aNeighbor, const RxFrame &aRxFrame); - bool HandleMacCommand(RxFrame &aFrame); + void HandleMacCommand(RxFrame &aFrame); void HandleTimer(void); #if OPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE Error ProcessTxDone(TxFrame &aFrame, RxFrame *aAckFrame, Error &aError); diff --git a/src/core/thread/mesh_forwarder.cpp b/src/core/thread/mesh_forwarder.cpp index 6c7236742..dc3b29692 100644 --- a/src/core/thread/mesh_forwarder.cpp +++ b/src/core/thread/mesh_forwarder.cpp @@ -1021,38 +1021,25 @@ void MeshForwarder::HandleReceivedFrame(Mac::RxFrame &aFrame) Get().UpdateOnReceive(rxInfo.mMacAddrs.mSource, rxInfo.IsLinkSecurityEnabled()); - switch (aFrame.GetType()) + if (Lowpan::MeshHeader::IsMeshHeader(rxInfo.mFrameData)) { - case Mac::Frame::kTypeData: - if (Lowpan::MeshHeader::IsMeshHeader(rxInfo.mFrameData)) - { #if OPENTHREAD_FTD - HandleMesh(rxInfo); + HandleMesh(rxInfo); #endif - } - else if (Lowpan::FragmentHeader::IsFragmentHeader(rxInfo.mFrameData)) - { - HandleFragment(rxInfo); - } - else if (Lowpan::Lowpan::IsLowpanHc(rxInfo.mFrameData)) - { - HandleLowpanHc(rxInfo); - } - else - { - VerifyOrExit(rxInfo.mFrameData.GetLength() == 0, error = kErrorNotLowpanDataFrame); + } + else if (Lowpan::FragmentHeader::IsFragmentHeader(rxInfo.mFrameData)) + { + HandleFragment(rxInfo); + } + else if (Lowpan::Lowpan::IsLowpanHc(rxInfo.mFrameData)) + { + HandleLowpanHc(rxInfo); + } + else + { + VerifyOrExit(rxInfo.mFrameData.GetLength() == 0, error = kErrorNotLowpanDataFrame); - LogFrame("Received empty payload frame", aFrame, kErrorNone); - } - - break; - - case Mac::Frame::kTypeBeacon: - break; - - default: - error = kErrorDrop; - break; + LogFrame("Received empty payload frame", aFrame, kErrorNone); } exit: