[nexus] update transmit frames with IEEE 802.15.4 FCS (#12347)

This commit adds IEEE 802.15.4 FCS (Frame Check Sequence) computation
to the Nexus radio driver. Each frame to be transmitted is updated
with the proper CRC16-CCITT before being passed to the simulation.

Motivation for this change is to ensure that frames captured from
the Nexus simulation have a valid FCS, enabling proper decoding and
display in Wireshark when using pcap output.
This commit is contained in:
Jonathan Hui
2026-01-29 13:49:29 -08:00
committed by GitHub
parent 8614dc01a1
commit b4d6b52f93
2 changed files with 23 additions and 0 deletions
+18
View File
@@ -30,6 +30,7 @@
#include "nexus_core.hpp"
#include "nexus_node.hpp"
#include "common/crc.hpp"
namespace ot {
namespace Nexus {
@@ -134,6 +135,9 @@ otError otPlatRadioTransmit(otInstance *aInstance, otRadioFrame *aFrame)
VerifyOrExit(radio.mState == Radio::kStateReceive, error = kErrorInvalidState);
OT_ASSERT(aFrame == &AsNode(aInstance).mRadio.mTxFrame);
static_cast<Radio::Frame *>(aFrame)->UpdateFcs();
radio.mState = Radio::kStateTransmit;
Core::Get().MarkPendingAction();
@@ -353,5 +357,19 @@ Radio::Frame::Frame(const Frame &aFrame)
memcpy(mPsdu, aFrame.mPsdu, mLength);
}
void Radio::Frame::UpdateFcs(void)
{
uint16_t fcs;
VerifyOrExit(mLength >= k154FcsSize);
fcs = CrcCalculator<uint16_t>(kCrc16CcittPolynomial).FeedBytes(mPsdu, mLength - k154FcsSize);
LittleEndian::WriteUint16(fcs, &mPsdu[mLength - k154FcsSize]);
exit:
return;
}
} // namespace Nexus
} // namespace ot
+5
View File
@@ -55,6 +55,11 @@ struct Radio
Frame(void);
explicit Frame(const Frame &aFrame);
/**
* Updates the frame with the proper IEEE 802.15.4 FCS.
*/
void UpdateFcs(void);
uint8_t mPsduBuffer[kMaxFrameSize];
};