mirror of
https://github.com/espressif/openthread.git
synced 2026-08-13 06:07:48 +00:00
[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:
@@ -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
|
||||
|
||||
@@ -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];
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user