Skip to content

Commit

Permalink
[mesh-forwarder] verify data request is ack with fp=1 (#3785)
Browse files Browse the repository at this point in the history
  • Loading branch information
bukepo authored and jwhui committed May 1, 2019
1 parent d348ce2 commit 617f895
Show file tree
Hide file tree
Showing 24 changed files with 91 additions and 15 deletions.
3 changes: 2 additions & 1 deletion doc/spinel-protocol-src/spinel-prop-core.md
Expand Up @@ -529,7 +529,8 @@ The bit values in `MD_FLAG` are defined as follows:
15 | 0x0001 | MD_FLAG_TX | Packet was transmitted, not received.
13 | 0x0004 | MD_FLAG_BAD_FCS | Packet was received with bad FCS
12 | 0x0008 | MD_FLAG_DUPE | Packet seems to be a duplicate
0-11, 14 | 0xFFF2 | MD_FLAG_RESERVED | Flags reserved for future use.
11 | 0x0010 | MD_FLAG_ACKED_FP | Packet was acknowledged with frame pending set
0-10, 14 | 0xFFE2 | MD_FLAG_RESERVED | Flags reserved for future use.

The format of `MD_PHY` is specified by the PHY layer currently in use,
and may contain information such as the channel, LQI, antenna, or other
Expand Down
3 changes: 3 additions & 0 deletions examples/platforms/cc1352/radio.c
Expand Up @@ -1881,6 +1881,9 @@ static void cc1352RadioProcessTransmitDone(otInstance * aInstance,

static void cc1352RadioProcessReceiveDone(otInstance *aInstance, otRadioFrame *aReceiveFrame, otError aReceiveError)
{
// TODO Set this flag only when the packet is really acknowledged with frame pending set.
// See https://github.com/openthread/openthread/pull/3785
aReceiveFrame->mInfo.mRxInfo.mAckedWithFramePending = true;
#if OPENTHREAD_ENABLE_DIAG

if (otPlatDiagModeGet())
Expand Down
3 changes: 3 additions & 0 deletions examples/platforms/cc2538/radio.c
Expand Up @@ -711,6 +711,9 @@ void cc2538RadioProcess(otInstance *aInstance)
if ((sState == OT_RADIO_STATE_RECEIVE && sReceiveFrame.mLength > 0) ||
(sState == OT_RADIO_STATE_TRANSMIT && sReceiveFrame.mLength > IEEE802154_ACK_LENGTH))
{
// TODO Set this flag only when the packet is really acknowledged with frame pending set.
// See https://github.com/openthread/openthread/pull/3785
sReceiveFrame.mInfo.mRxInfo.mAckedWithFramePending = true;
#if OPENTHREAD_ENABLE_DIAG

if (otPlatDiagModeGet())
Expand Down
3 changes: 3 additions & 0 deletions examples/platforms/cc2650/radio.c
Expand Up @@ -1798,6 +1798,9 @@ static void cc2650RadioProcessTransmitDone(otInstance * aInstance,

static void cc2650RadioProcessReceiveDone(otInstance *aInstance, otRadioFrame *aReceiveFrame, otError aReceiveError)
{
// TODO Set this flag only when the packet is really acknowledged with frame pending set.
// See https://github.com/openthread/openthread/pull/3785
aReceiveFrame->mInfo.mRxInfo.mAckedWithFramePending = true;
#if OPENTHREAD_ENABLE_DIAG

if (otPlatDiagModeGet())
Expand Down
3 changes: 3 additions & 0 deletions examples/platforms/cc2652/radio.c
Expand Up @@ -1861,6 +1861,9 @@ static void cc2652RadioProcessTransmitDone(otInstance * aInstance,

static void cc2652RadioProcessReceiveDone(otInstance *aInstance, otRadioFrame *aReceiveFrame, otError aReceiveError)
{
// TODO Set this flag only when the packet is really acknowledged with frame pending set.
// See https://github.com/openthread/openthread/pull/3785
aReceiveFrame->mInfo.mRxInfo.mAckedWithFramePending = true;
#if OPENTHREAD_ENABLE_DIAG

if (otPlatDiagModeGet())
Expand Down
4 changes: 4 additions & 0 deletions examples/platforms/da15000/radio.c
Expand Up @@ -508,6 +508,10 @@ void da15000RadioProcess(otInstance *aInstance)
sAckFrame = true;
}

// TODO Set this flag only when the packet is really acknowledged with frame pending set.
// See https://github.com/openthread/openthread/pull/3785
sReceiveFrame[sReadFrame].mInfo.mRxInfo.mAckedWithFramePending = true;

otPlatRadioReceiveDone(sThreadInstance, &sReceiveFrame[sReadFrame], OT_ERROR_NONE);

sReadFrame = (sReadFrame + 1) % RADIO_FRAMES_BUFFER_SIZE;
Expand Down
4 changes: 4 additions & 0 deletions examples/platforms/efr32/radio.c
Expand Up @@ -680,6 +680,10 @@ static void processNextRxPacket(otInstance *aInstance, RAIL_Handle_t aRailHandle

sReceiveError = OT_ERROR_NONE;

// TODO Set this flag only when the packet is really acknowledged with frame pending set.
// See https://github.com/openthread/openthread/pull/3785
sReceiveFrame.mInfo.mRxInfo.mAckedWithFramePending = true;

#if OPENTHREAD_ENABLE_DIAG

if (otPlatDiagModeGet())
Expand Down
3 changes: 3 additions & 0 deletions examples/platforms/emsk/radio.c
Expand Up @@ -564,6 +564,9 @@ void emskRadioProcess(otInstance *aInstance)

if ((sState == OT_RADIO_STATE_RECEIVE) && (sReceiveFrame.mLength > 0))
{
// TODO Set this flag only when the packet is really acknowledged with frame pending set.
// See https://github.com/openthread/openthread/pull/3785
sReceiveFrame.mInfo.mRxInfo.mAckedWithFramePending = true;
otPlatRadioReceiveDone(aInstance, &sReceiveFrame, sReceiveError);
}

Expand Down
4 changes: 4 additions & 0 deletions examples/platforms/gp712/radio.c
Expand Up @@ -226,6 +226,10 @@ void cbQorvoRadioReceiveDone(otRadioFrame *aPacket, otError aError)
sLastReceivedPower = aPacket->mInfo.mRxInfo.mRssi;
}

// TODO Set this flag only when the packet is really acknowledged with frame pending set.
// See https://github.com/openthread/openthread/pull/3785
aPacket->mInfo.mRxInfo.mAckedWithFramePending = true;

otPlatRadioReceiveDone(pQorvoInstance, aPacket, aError);
}

Expand Down
4 changes: 4 additions & 0 deletions examples/platforms/kw41z/radio.c
Expand Up @@ -987,6 +987,10 @@ void kw41zRadioProcess(otInstance *aInstance)

if (sRxDone)
{
// TODO Set this flag only when the packet is really acknowledged with frame pending set.
// See https://github.com/openthread/openthread/pull/3785
sRxFrame.mInfo.mRxInfo.mAckedWithFramePending = true;

#if OPENTHREAD_ENABLE_DIAG

if (otPlatDiagModeGet())
Expand Down
4 changes: 4 additions & 0 deletions examples/platforms/nrf52811/radio.c
Expand Up @@ -552,6 +552,10 @@ void nrf5RadioProcess(otInstance *aInstance)
{
if (sReceivedFrames[i].mPsdu != NULL)
{
// TODO Set this flag only when the packet is really acknowledged with frame pending set.
// See https://github.com/openthread/openthread/pull/3785
sReceivedFrames[i].mInfo.mRxInfo.mAckedWithFramePending = true;

#if OPENTHREAD_ENABLE_DIAG

if (otPlatDiagModeGet())
Expand Down
4 changes: 4 additions & 0 deletions examples/platforms/nrf52840/radio.c
Expand Up @@ -552,6 +552,10 @@ void nrf5RadioProcess(otInstance *aInstance)
{
if (sReceivedFrames[i].mPsdu != NULL)
{
// TODO Set this flag only when the packet is really acknowledged with frame pending set.
// See https://github.com/openthread/openthread/pull/3785
sReceivedFrames[i].mInfo.mRxInfo.mAckedWithFramePending = true;

#if OPENTHREAD_ENABLE_DIAG

if (otPlatDiagModeGet())
Expand Down
2 changes: 2 additions & 0 deletions examples/platforms/posix/radio.c
Expand Up @@ -776,6 +776,7 @@ void radioSendAck(void)
if (isDataRequestAndHasFramePending(sReceiveFrame.mPsdu))
{
sAckMessage.mPsdu[0] |= IEEE802154_FRAME_PENDING;
sReceiveFrame.mInfo.mRxInfo.mAckedWithFramePending = true;
}

sAckMessage.mPsdu[1] = 0;
Expand Down Expand Up @@ -824,6 +825,7 @@ void radioProcessFrame(otInstance *aInstance)
sReceiveFrame.mInfo.mRxInfo.mRssi = -20;
sReceiveFrame.mInfo.mRxInfo.mLqi = OT_RADIO_LQI_NONE;

sReceiveFrame.mInfo.mRxInfo.mAckedWithFramePending = false;
// generate acknowledgment
if (isAckRequested(sReceiveFrame.mPsdu))
{
Expand Down
2 changes: 2 additions & 0 deletions examples/platforms/posix/sim/radio-sim.c
Expand Up @@ -642,6 +642,7 @@ void radioSendAck(void)
if (isDataRequestAndHasFramePending(sReceiveFrame.mPsdu))
{
sAckMessage.mPsdu[0] |= IEEE802154_FRAME_PENDING;
sReceiveFrame.mInfo.mRxInfo.mAckedWithFramePending = true;
}

sAckMessage.mPsdu[1] = 0;
Expand Down Expand Up @@ -690,6 +691,7 @@ void radioProcessFrame(otInstance *aInstance)
sReceiveFrame.mInfo.mRxInfo.mRssi = -20;
sReceiveFrame.mInfo.mRxInfo.mLqi = OT_RADIO_LQI_NONE;

sReceiveFrame.mInfo.mRxInfo.mAckedWithFramePending = false;
// generate acknowledgment
if (isAckRequested(sReceiveFrame.mPsdu))
{
Expand Down
4 changes: 4 additions & 0 deletions examples/platforms/qpg6095/radio.c
Expand Up @@ -217,6 +217,10 @@ void cbQorvoRadioTransmitDone(otRadioFrame *aPacket, bool aFramePending, otError

void cbQorvoRadioReceiveDone(otRadioFrame *aPacket, otError aError)
{
// TODO Set this flag only when the packet is really acknowledged with frame pending set.
// See https://github.com/openthread/openthread/pull/3785
aPacket->mInfo.mRxInfo.mAckedWithFramePending = true;

otPlatRadioReceiveDone(pQorvoInstance, aPacket, aError);
}

Expand Down
4 changes: 4 additions & 0 deletions examples/platforms/samr21/radio.c
Expand Up @@ -225,6 +225,10 @@ static void handleRx(void)
sReceiveFrame.mInfo.mRxInfo.mUsec = 0; // Don't support microsecond timer for now.
}

// TODO Set this flag only when the packet is really acknowledged with frame pending set.
// See https://github.com/openthread/openthread/pull/3785
sReceiveFrame.mInfo.mRxInfo.mAckedWithFramePending = true;

#if OPENTHREAD_ENABLE_DIAG

if (otPlatDiagModeGet())
Expand Down
16 changes: 9 additions & 7 deletions include/openthread/platform/radio.h
Expand Up @@ -202,22 +202,24 @@ typedef struct otRadioFrame
*/
struct
{
int8_t mRssi; ///< Received signal strength indicator in dBm for received frames.
uint8_t mLqi; ///< Link Quality Indicator for received frames.

/**
* The timestamp when the frame was received (microseconds, the offset to mMsec).
* The timestamp when the frame was received (milliseconds).
* Applicable/Required only when raw-link-api feature (`OPENTHREAD_ENABLE_RAW_LINK_API`) is enabled.
*
*/
uint16_t mUsec;
uint32_t mMsec;

/**
* The timestamp when the frame was received (milliseconds).
* The timestamp when the frame was received (microseconds, the offset to mMsec).
* Applicable/Required only when raw-link-api feature (`OPENTHREAD_ENABLE_RAW_LINK_API`) is enabled.
*
*/
uint32_t mMsec;
uint16_t mUsec;
int8_t mRssi; ///< Received signal strength indicator in dBm for received frames.
uint8_t mLqi; ///< Link Quality Indicator for received frames.

// Flags
bool mAckedWithFramePending : 1; /// This indicates if this frame was acknowledged with frame pending set.
} mRxInfo;
} mInfo;
} otRadioFrame;
Expand Down
9 changes: 9 additions & 0 deletions src/core/mac/mac_frame.hpp
Expand Up @@ -1017,6 +1017,15 @@ class Frame : public otRadioFrame
*/
bool IsARetransmission(void) const { return mInfo.mTxInfo.mIsARetx; }

/**
* This method indicates whether or not the received frame is acknowledged with frame pending set.
*
* @retval TRUE This frame is acknowledged with frame pending set.
* @retval FALSE This frame is acknowledged with frame pending not set.
*
*/
bool IsAckedWithFramePending(void) const { return mInfo.mRxInfo.mAckedWithFramePending; }

/**
* This method sets the retransmission flag attribute.
*
Expand Down
2 changes: 1 addition & 1 deletion src/core/thread/mesh_forwarder.cpp
Expand Up @@ -1269,7 +1269,7 @@ void MeshForwarder::HandleReceivedFrame(Mac::Frame &aFrame)

if (commandId == Mac::Frame::kMacCmdDataRequest)
{
HandleDataRequest(macSource, linkInfo);
HandleDataRequest(aFrame, macSource, linkInfo);
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion src/core/thread/mesh_forwarder.hpp
Expand Up @@ -398,7 +398,7 @@ class MeshForwarder : public InstanceLocator
const Mac::Address & aMacSource,
const Mac::Address & aMacDest,
const otThreadLinkInfo &aLinkInfo);
void HandleDataRequest(const Mac::Address &aMacSource, const otThreadLinkInfo &aLinkInfo);
void HandleDataRequest(const Mac::Frame &aFrame, const Mac::Address &aMacSource, const otThreadLinkInfo &aLinkInfo);

static otError GetFragmentHeader(const uint8_t * aFrame,
uint8_t aFrameLength,
Expand Down
10 changes: 7 additions & 3 deletions src/core/thread/mesh_forwarder_ftd.cpp
Expand Up @@ -551,7 +551,9 @@ void MeshForwarder::SendMesh(Message &aMessage, Mac::Frame &aFrame)
mMessageNextOffset = aMessage.GetLength();
}

void MeshForwarder::HandleDataRequest(const Mac::Address &aMacSource, const otThreadLinkInfo &aLinkInfo)
void MeshForwarder::HandleDataRequest(const Mac::Frame & aFrame,
const Mac::Address & aMacSource,
const otThreadLinkInfo &aLinkInfo)
{
Child * child;
uint16_t indirectMsgCount;
Expand All @@ -568,15 +570,17 @@ void MeshForwarder::HandleDataRequest(const Mac::Address &aMacSource, const otTh
child->ResetLinkFailures();
indirectMsgCount = child->GetIndirectMessageCount();

otLogInfoMac("Rx data poll, src:0x%04x, qed_msgs:%d, rss:%d ack-fp:%d", child->GetRloc16(), indirectMsgCount,
aLinkInfo.mRss, aFrame.IsAckedWithFramePending());
VerifyOrExit(aFrame.IsAckedWithFramePending());

if (!mSourceMatchController.IsEnabled() || (indirectMsgCount > 0))
{
child->SetDataRequestPending(true);
}

mScheduleTransmissionTask.Post();

otLogInfoMac("Rx data poll, src:0x%04x, qed_msgs:%d, rss:%d", child->GetRloc16(), indirectMsgCount, aLinkInfo.mRss);

exit:
return;
}
Expand Down
8 changes: 7 additions & 1 deletion src/ncp/ncp_base_radio.cpp
Expand Up @@ -78,7 +78,13 @@ void NcpBase::LinkRawReceiveDone(otRadioFrame *aFrame, otError aError)
// Append metadata (rssi, etc)
SuccessOrExit(mEncoder.WriteInt8(aFrame->mInfo.mRxInfo.mRssi)); // RSSI
SuccessOrExit(mEncoder.WriteInt8(-128)); // Noise Floor (Currently unused)
SuccessOrExit(mEncoder.WriteUint16(flags)); // Flags

if (aFrame->mInfo.mRxInfo.mAckedWithFramePending)
{
flags |= SPINEL_MD_FLAG_ACKED_FP;
}

SuccessOrExit(mEncoder.WriteUint16(flags)); // Flags

SuccessOrExit(mEncoder.OpenStruct()); // PHY-data
SuccessOrExit(mEncoder.WriteUint8(aFrame->mChannel)); // 802.15.4 channel (Receive channel)
Expand Down
3 changes: 2 additions & 1 deletion src/ncp/spinel.h
Expand Up @@ -399,7 +399,8 @@ enum
SPINEL_MD_FLAG_TX = 0x0001, //!< Packet was transmitted, not received.
SPINEL_MD_FLAG_BAD_FCS = 0x0004, //!< Packet was received with bad FCS
SPINEL_MD_FLAG_DUPE = 0x0008, //!< Packet seems to be a duplicate
SPINEL_MD_FLAG_RESERVED = 0xFFF2, //!< Flags reserved for future use.
SPINEL_MD_FLAG_ACKED_FP = 0x0010, //!< Packet was acknowledged with frame pending set
SPINEL_MD_FLAG_RESERVED = 0xFFE2, //!< Flags reserved for future use.
};

enum
Expand Down
2 changes: 2 additions & 0 deletions src/posix/platform/radio_spinel.cpp
Expand Up @@ -635,6 +635,8 @@ otError RadioSpinel::ParseRadioFrame(otRadioFrame &aFrame, const uint8_t *aBuffe
if (receiveError == OT_ERROR_NONE)
{
aFrame.mLength = static_cast<uint8_t>(size);

aFrame.mInfo.mRxInfo.mAckedWithFramePending = ((flags & SPINEL_MD_FLAG_ACKED_FP) != 0);
}
else if (receiveError < OT_NUM_ERRORS)
{
Expand Down

0 comments on commit 617f895

Please sign in to comment.