mirror of
https://github.com/espressif/openthread.git
synced 2026-08-01 08:37:47 +00:00
[mac] ensure to apply RSS filter on all rx frame including ack (#8651)
This commit updates how we apply `Mac::Filter` ensuring the fixed RSS filter is applied to all rx frames including received ack frames. We add a new method `Mac::Filter::ApplyToRxFrame()` which applies the filter rules directly to a rx frame, potentially updating its signal strength to a fixed RSS. This common method is then called from `Mac::HandleReceivedFrame()` replacing the existing code and also from `Mac::RecordFrameTransmitStatus()` to a received `aAckFrame`. This ensures that fixed RSS is correctly tracked on the corresponding neighbor. This commit also updates `Mac::Filter` methods which do not change the `Filter` to be marked as `const`.
This commit is contained in:
@@ -274,7 +274,7 @@ exit:
|
||||
#if OT_SHOULD_LOG_AT(OT_LOG_LEVEL_INFO)
|
||||
|
||||
void LinkRaw::RecordFrameTransmitStatus(const TxFrame &aFrame,
|
||||
const RxFrame *aAckFrame,
|
||||
RxFrame *aAckFrame,
|
||||
Error aError,
|
||||
uint8_t aRetryCount,
|
||||
bool aWillRetx)
|
||||
|
||||
@@ -298,12 +298,12 @@ public:
|
||||
*
|
||||
*/
|
||||
void RecordFrameTransmitStatus(const TxFrame &aFrame,
|
||||
const RxFrame *aAckFrame,
|
||||
RxFrame *aAckFrame,
|
||||
Error aError,
|
||||
uint8_t aRetryCount,
|
||||
bool aWillRetx);
|
||||
#else
|
||||
void RecordFrameTransmitStatus(const TxFrame &, const RxFrame *, Error, uint8_t, bool) {}
|
||||
void RecordFrameTransmitStatus(const TxFrame &, RxFrame *, Error, uint8_t, bool) {}
|
||||
#endif
|
||||
|
||||
private:
|
||||
|
||||
+6
-18
@@ -1124,7 +1124,7 @@ void Mac::RecordCcaStatus(bool aCcaSuccess, uint8_t aChannel)
|
||||
}
|
||||
|
||||
void Mac::RecordFrameTransmitStatus(const TxFrame &aFrame,
|
||||
const RxFrame *aAckFrame,
|
||||
RxFrame *aAckFrame,
|
||||
Error aError,
|
||||
uint8_t aRetryCount,
|
||||
bool aWillRetx)
|
||||
@@ -1187,6 +1187,10 @@ void Mac::RecordFrameTransmitStatus(const TxFrame &aFrame,
|
||||
|
||||
if ((aError == kErrorNone) && ackRequested && (aAckFrame != nullptr) && (neighbor != nullptr))
|
||||
{
|
||||
#if OPENTHREAD_CONFIG_MAC_FILTER_ENABLE
|
||||
SuccessOrExit(mFilter.ApplyToRxFrame(*aAckFrame, neighbor->GetExtAddress(), neighbor));
|
||||
#endif
|
||||
|
||||
neighbor->GetLinkInfo().AddRss(aAckFrame->GetRssi());
|
||||
#if OPENTHREAD_CONFIG_MLE_LINK_METRICS_SUBJECT_ENABLE
|
||||
neighbor->AggregateLinkMetrics(/* aSeriesId */ 0, aAckFrame->GetType(), aAckFrame->GetLqi(),
|
||||
@@ -1787,23 +1791,7 @@ void Mac::HandleReceivedFrame(RxFrame *aFrame, Error aError)
|
||||
VerifyOrExit(srcaddr.GetExtended() != GetExtAddress(), error = kErrorInvalidSourceAddress);
|
||||
|
||||
#if OPENTHREAD_CONFIG_MAC_FILTER_ENABLE
|
||||
{
|
||||
int8_t fixedRss;
|
||||
|
||||
SuccessOrExit(error = mFilter.Apply(srcaddr.GetExtended(), fixedRss));
|
||||
|
||||
if (fixedRss != Filter::kFixedRssDisabled)
|
||||
{
|
||||
aFrame->SetRssi(fixedRss);
|
||||
|
||||
// Clear any previous link info to ensure the fixed RSSI
|
||||
// value takes effect quickly.
|
||||
if (neighbor != nullptr)
|
||||
{
|
||||
neighbor->GetLinkInfo().Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
SuccessOrExit(error = mFilter.ApplyToRxFrame(*aFrame, srcaddr.GetExtended(), neighbor));
|
||||
#endif
|
||||
|
||||
break;
|
||||
|
||||
@@ -412,7 +412,7 @@ public:
|
||||
*
|
||||
*/
|
||||
void RecordFrameTransmitStatus(const TxFrame &aFrame,
|
||||
const RxFrame *aAckFrame,
|
||||
RxFrame *aAckFrame,
|
||||
Error aError,
|
||||
uint8_t aRetryCount,
|
||||
bool aWillRetx);
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
#include "common/array.hpp"
|
||||
#include "common/as_core_type.hpp"
|
||||
#include "common/code_utils.hpp"
|
||||
#include "thread/topology.hpp"
|
||||
|
||||
namespace ot {
|
||||
namespace Mac {
|
||||
@@ -53,11 +54,11 @@ Filter::Filter(void)
|
||||
}
|
||||
}
|
||||
|
||||
Filter::FilterEntry *Filter::FindEntry(const ExtAddress &aExtAddress)
|
||||
const Filter::FilterEntry *Filter::FindEntry(const ExtAddress &aExtAddress) const
|
||||
{
|
||||
FilterEntry *rval = nullptr;
|
||||
const FilterEntry *rval = nullptr;
|
||||
|
||||
for (FilterEntry &entry : mFilterEntries)
|
||||
for (const FilterEntry &entry : mFilterEntries)
|
||||
{
|
||||
if (entry.IsInUse() && (aExtAddress == entry.mExtAddress))
|
||||
{
|
||||
@@ -182,13 +183,13 @@ void Filter::ClearAllRssIn(void)
|
||||
mDefaultRssIn = kFixedRssDisabled;
|
||||
}
|
||||
|
||||
Error Filter::GetNextRssIn(Iterator &aIterator, Entry &aEntry)
|
||||
Error Filter::GetNextRssIn(Iterator &aIterator, Entry &aEntry) const
|
||||
{
|
||||
Error error = kErrorNotFound;
|
||||
|
||||
for (; aIterator < GetArrayLength(mFilterEntries); aIterator++)
|
||||
{
|
||||
FilterEntry &entry = mFilterEntries[aIterator];
|
||||
const FilterEntry &entry = mFilterEntries[aIterator];
|
||||
|
||||
if (entry.mRssIn != kFixedRssDisabled)
|
||||
{
|
||||
@@ -213,11 +214,11 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
Error Filter::Apply(const ExtAddress &aExtAddress, int8_t &aRss)
|
||||
Error Filter::Apply(const ExtAddress &aExtAddress, int8_t &aRss) const
|
||||
{
|
||||
Error error = kErrorNone;
|
||||
FilterEntry *entry = FindEntry(aExtAddress);
|
||||
bool isInFilterList;
|
||||
Error error = kErrorNone;
|
||||
const FilterEntry *entry = FindEntry(aExtAddress);
|
||||
bool isInFilterList;
|
||||
|
||||
// Use the default RssIn setting for all receiving messages first.
|
||||
aRss = mDefaultRssIn;
|
||||
@@ -250,6 +251,28 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
Error Filter::ApplyToRxFrame(RxFrame &aRxFrame, const ExtAddress &aExtAddress, Neighbor *aNeighbor) const
|
||||
{
|
||||
Error error;
|
||||
int8_t fixedRss;
|
||||
|
||||
SuccessOrExit(error = Apply(aExtAddress, fixedRss));
|
||||
|
||||
VerifyOrExit(fixedRss != kFixedRssDisabled);
|
||||
|
||||
aRxFrame.SetRssi(fixedRss);
|
||||
|
||||
if (aNeighbor != nullptr)
|
||||
{
|
||||
// Clear the previous RSS average to ensure the fixed RSS
|
||||
// value takes effect quickly.
|
||||
aNeighbor->GetLinkInfo().CleaAverageRss();
|
||||
}
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
} // namespace Mac
|
||||
} // namespace ot
|
||||
|
||||
|
||||
@@ -41,10 +41,14 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#include "common/as_core_type.hpp"
|
||||
#include "common/const_cast.hpp"
|
||||
#include "common/non_copyable.hpp"
|
||||
#include "mac/mac_frame.hpp"
|
||||
|
||||
namespace ot {
|
||||
|
||||
class Neighbor;
|
||||
|
||||
namespace Mac {
|
||||
|
||||
/**
|
||||
@@ -208,7 +212,7 @@ public:
|
||||
* @retval kErrorNotFound No subsequent entry exists.
|
||||
*
|
||||
*/
|
||||
Error GetNextRssIn(Iterator &aIterator, Entry &aEntry);
|
||||
Error GetNextRssIn(Iterator &aIterator, Entry &aEntry) const;
|
||||
|
||||
/**
|
||||
* This method applies the filter rules on a given Extended Address.
|
||||
@@ -220,7 +224,24 @@ public:
|
||||
* @retval kErrorAddressFiltered Address filter (allowlist or denylist) is enabled and @p aExtAddress is filtered.
|
||||
*
|
||||
*/
|
||||
Error Apply(const ExtAddress &aExtAddress, int8_t &aRss);
|
||||
Error Apply(const ExtAddress &aExtAddress, int8_t &aRss) const;
|
||||
|
||||
/**
|
||||
* This method applies the filter rules to a received frame from a given Extended Address.
|
||||
*
|
||||
* This method can potentially update the signal strength value on the received frame @p aRxFrame. If @p aNeighbor
|
||||
* is not `nullptr` and filter applies a fixed RSS to the @p aRxFrame, this method will also clear the current RSS
|
||||
* average on @p aNeighbor to ensure that the new fixed RSS takes effect quickly.
|
||||
*
|
||||
* @param[out] aRxFrame The received frame.
|
||||
* @param[in] aExtAddress The extended address from which @p aRxFrame was received.
|
||||
* @param[in] aNeighbor A pointer to the neighbor (can be `nullptr` if not known).
|
||||
*
|
||||
* @retval kErrorNone Successfully applied the filter, @p aRxFrame RSS may be updated.
|
||||
* @retval kErrorAddressFiltered Address filter (allowlist or denylist) is enabled and @p aExtAddress is filtered.
|
||||
*
|
||||
*/
|
||||
Error ApplyToRxFrame(RxFrame &aRxFrame, const ExtAddress &aExtAddress, Neighbor *aNeighbor = nullptr) const;
|
||||
|
||||
private:
|
||||
static constexpr uint16_t kMaxEntries = OPENTHREAD_CONFIG_MAC_FILTER_SIZE;
|
||||
@@ -234,8 +255,9 @@ private:
|
||||
bool IsInUse(void) const { return mFiltered || (mRssIn != kFixedRssDisabled); }
|
||||
};
|
||||
|
||||
FilterEntry *FindAvailableEntry(void);
|
||||
FilterEntry *FindEntry(const ExtAddress &aExtAddress);
|
||||
FilterEntry *FindAvailableEntry(void);
|
||||
const FilterEntry *FindEntry(const ExtAddress &aExtAddress) const;
|
||||
FilterEntry *FindEntry(const ExtAddress &aExtAddress) { return AsNonConst(AsConst(this)->FindEntry(aExtAddress)); }
|
||||
|
||||
Mode mMode;
|
||||
int8_t mDefaultRssIn;
|
||||
|
||||
@@ -166,7 +166,7 @@ public:
|
||||
*
|
||||
*/
|
||||
void RecordFrameTransmitStatus(const TxFrame &aFrame,
|
||||
const RxFrame *aAckFrame,
|
||||
RxFrame *aAckFrame,
|
||||
Error aError,
|
||||
uint8_t aRetryCount,
|
||||
bool aWillRetx);
|
||||
|
||||
@@ -71,7 +71,7 @@ void SubMac::Callbacks::RecordCcaStatus(bool aCcaSuccess, uint8_t aChannel)
|
||||
}
|
||||
|
||||
void SubMac::Callbacks::RecordFrameTransmitStatus(const TxFrame &aFrame,
|
||||
const RxFrame *aAckFrame,
|
||||
RxFrame *aAckFrame,
|
||||
Error aError,
|
||||
uint8_t aRetryCount,
|
||||
bool aWillRetx)
|
||||
@@ -119,7 +119,7 @@ void SubMac::Callbacks::ReceiveDone(RxFrame *aFrame, Error aError) { Get<LinkRaw
|
||||
void SubMac::Callbacks::RecordCcaStatus(bool, uint8_t) {}
|
||||
|
||||
void SubMac::Callbacks::RecordFrameTransmitStatus(const TxFrame &aFrame,
|
||||
const RxFrame *aAckFrame,
|
||||
RxFrame *aAckFrame,
|
||||
Error aError,
|
||||
uint8_t aRetryCount,
|
||||
bool aWillRetx)
|
||||
|
||||
@@ -322,6 +322,12 @@ public:
|
||||
*/
|
||||
void Clear(void);
|
||||
|
||||
/**
|
||||
* This method clears the average RSS value.
|
||||
*
|
||||
*/
|
||||
void CleaAverageRss(void) { mRssAverager.Clear(); }
|
||||
|
||||
/**
|
||||
* This method adds a new received signal strength (RSS) value to the average.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user