mirror of
https://github.com/espressif/openthread.git
synced 2026-10-04 14:57:38 +00:00
[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.
This commit is contained in:
+6
-17
@@ -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<MeshForwarder>().HandleReceivedFrame(*aFrame);
|
||||
UpdateIdleMode();
|
||||
break;
|
||||
|
||||
default:
|
||||
mCounters.mRxOther++;
|
||||
ExitNow();
|
||||
break;
|
||||
}
|
||||
|
||||
DumpDebg("RX", aFrame->GetPsdu(), aFrame->GetLength());
|
||||
Get<MeshForwarder>().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<DataPollHandler>().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)
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -1021,38 +1021,25 @@ void MeshForwarder::HandleReceivedFrame(Mac::RxFrame &aFrame)
|
||||
|
||||
Get<SupervisionListener>().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:
|
||||
|
||||
Reference in New Issue
Block a user