diff --git a/src/core/mac/mac.cpp b/src/core/mac/mac.cpp index 6c24620c3..51c0d10c1 100644 --- a/src/core/mac/mac.cpp +++ b/src/core/mac/mac.cpp @@ -1181,7 +1181,7 @@ void Mac::RecordFrameTransmitStatus(const TxFrame &aFrame, if ((aError == OT_ERROR_NONE) && ackRequested && (aAckFrame != NULL) && (neighbor != NULL)) { - neighbor->GetLinkInfo().AddRss(GetNoiseFloor(), aAckFrame->GetRssi()); + neighbor->GetLinkInfo().AddRss(aAckFrame->GetRssi()); } // Update MAC counters. @@ -1648,7 +1648,7 @@ void Mac::HandleReceivedFrame(RxFrame *aFrame, otError aError) if (neighbor != NULL) { - neighbor->GetLinkInfo().AddRss(GetNoiseFloor(), aFrame->GetRssi()); + neighbor->GetLinkInfo().AddRss(aFrame->GetRssi()); if (aFrame->GetSecurityEnabled()) { @@ -1877,11 +1877,6 @@ void Mac::ResetRetrySuccessHistogram() } #endif // OPENTHREAD_CONFIG_MAC_RETRY_SUCCESS_HISTOGRAM_ENABLE -int8_t Mac::GetNoiseFloor(void) -{ - return Get().GetReceiveSensitivity(); -} - // LCOV_EXCL_START #if (OPENTHREAD_CONFIG_LOG_LEVEL >= OT_LOG_LEVEL_INFO) && (OPENTHREAD_CONFIG_LOG_MAC == 1) diff --git a/src/core/mac/mac.hpp b/src/core/mac/mac.hpp index 24f3b1132..acf41ee70 100644 --- a/src/core/mac/mac.hpp +++ b/src/core/mac/mac.hpp @@ -609,7 +609,7 @@ public: * @returns The noise floor value in dBm. * */ - int8_t GetNoiseFloor(void); + int8_t GetNoiseFloor(void) { return mSubMac.GetNoiseFloor(); } /** * This method returns the current CCA (Clear Channel Assessment) failure rate. diff --git a/src/core/mac/sub_mac.cpp b/src/core/mac/sub_mac.cpp index 8ff1b0da6..e08b4b640 100644 --- a/src/core/mac/sub_mac.cpp +++ b/src/core/mac/sub_mac.cpp @@ -388,6 +388,11 @@ int8_t SubMac::GetRssi(void) const return Get().GetRssi(); } +int8_t SubMac::GetNoiseFloor(void) +{ + return Get().GetReceiveSensitivity(); +} + otError SubMac::EnergyScan(uint8_t aScanChannel, uint16_t aScanDuration) { otError error = OT_ERROR_NONE; diff --git a/src/core/mac/sub_mac.hpp b/src/core/mac/sub_mac.hpp index 6c086431d..bb05166f6 100644 --- a/src/core/mac/sub_mac.hpp +++ b/src/core/mac/sub_mac.hpp @@ -339,6 +339,14 @@ public: */ otError EnergyScan(uint8_t aScanChannel, uint16_t aScanDuration); + /** + * This method returns the noise floor value (currently use the radio receive sensitivity value). + * + * @returns The noise floor value in dBm. + * + */ + int8_t GetNoiseFloor(void); + private: enum { diff --git a/src/core/thread/link_quality.cpp b/src/core/thread/link_quality.cpp index 9f1c00bb0..c3739fc88 100644 --- a/src/core/thread/link_quality.cpp +++ b/src/core/thread/link_quality.cpp @@ -150,7 +150,7 @@ void LinkQualityInfo::Clear(void) mMessageErrorRate.Reset(); } -void LinkQualityInfo::AddRss(int8_t aNoiseFloor, int8_t aRss) +void LinkQualityInfo::AddRss(int8_t aRss) { uint8_t oldLinkQuality = kNoLinkQuality; @@ -165,12 +165,17 @@ void LinkQualityInfo::AddRss(int8_t aNoiseFloor, int8_t aRss) SuccessOrExit(mRssAverager.Add(aRss)); - SetLinkQuality(CalculateLinkQuality(GetLinkMargin(aNoiseFloor), oldLinkQuality)); + SetLinkQuality(CalculateLinkQuality(GetLinkMargin(), oldLinkQuality)); exit: return; } +uint8_t LinkQualityInfo::GetLinkMargin(void) const +{ + return ConvertRssToLinkMargin(Get().GetNoiseFloor(), GetAverageRss()); +} + LinkQualityInfo::InfoString LinkQualityInfo::ToInfoString(void) const { return InfoString("aveRss:%s, lastRss:%d, linkQuality:%d", mRssAverager.ToString().AsCString(), GetLastRss(), diff --git a/src/core/thread/link_quality.hpp b/src/core/thread/link_quality.hpp index b9a59412d..1f9f022f6 100644 --- a/src/core/thread/link_quality.hpp +++ b/src/core/thread/link_quality.hpp @@ -247,11 +247,10 @@ public: /** * This method adds a new received signal strength (RSS) value to the average. * - * @param[in] aNoiseFloor The noise floor value (in dBm). * @param[in] aRss A new received signal strength value (in dBm) to be added to the average. * */ - void AddRss(int8_t aNoiseFloor, int8_t aRss); + void AddRss(int8_t aRss); /** * This method returns the current average received signal strength value. @@ -282,12 +281,10 @@ public: * This method returns the link margin. The link margin is calculated using the link's current average received * signal strength (RSS) and average noise floor. * - * @param[in] aNoiseFloor The noise floor value (in dBm). - * * @returns Link margin derived from average received signal strength and average noise floor. * */ - uint8_t GetLinkMargin(int8_t aNoiseFloor) const { return ConvertRssToLinkMargin(aNoiseFloor, GetAverageRss()); } + uint8_t GetLinkMargin(void) const; /** * Returns the current one-way link quality value. The link quality value is a number 0-3. @@ -300,8 +297,6 @@ public: * frequent changes, a hysteresis of 2 dB is applied when determining the link quality. For example, the average * link margin must be at least 12 dB to change a quality 1 link to a quality 2 link. * - * @param[in] aNoiseFloor The noise floor value (in dBm). - * * @returns The current link quality value (value 0-3 as per Thread specification). * */ diff --git a/src/core/thread/mle.cpp b/src/core/thread/mle.cpp index 8851929f2..6a3127268 100644 --- a/src/core/thread/mle.cpp +++ b/src/core/thread/mle.cpp @@ -3334,7 +3334,7 @@ otError Mle::HandleParentResponse(const Message &aMessage, const Ip6::MessageInf mParentCandidate.SetDeviceMode(DeviceMode(DeviceMode::kModeFullThreadDevice | DeviceMode::kModeRxOnWhenIdle | DeviceMode::kModeFullNetworkData | DeviceMode::kModeSecureDataRequest)); mParentCandidate.GetLinkInfo().Clear(); - mParentCandidate.GetLinkInfo().AddRss(Get().GetNoiseFloor(), linkInfo->mRss); + mParentCandidate.GetLinkInfo().AddRss(linkInfo->mRss); mParentCandidate.ResetLinkFailures(); mParentCandidate.SetLinkQualityOut(LinkQualityInfo::ConvertLinkMarginToLinkQuality(linkMarginTlv.GetLinkMargin())); mParentCandidate.SetState(Neighbor::kStateParentResponse); diff --git a/src/core/thread/mle_router.cpp b/src/core/thread/mle_router.cpp index 4211387a1..fc666f944 100644 --- a/src/core/thread/mle_router.cpp +++ b/src/core/thread/mle_router.cpp @@ -615,7 +615,7 @@ otError MleRouter::HandleLinkRequest(const Message &aMessage, const Ip6::Message neighbor->SetExtAddress(macAddr); neighbor->GetLinkInfo().Clear(); - neighbor->GetLinkInfo().AddRss(Get().GetNoiseFloor(), linkInfo->mRss); + neighbor->GetLinkInfo().AddRss(linkInfo->mRss); neighbor->ResetLinkFailures(); neighbor->SetLastHeard(TimerMilli::GetNow()); neighbor->SetState(Neighbor::kStateLinkRequest); @@ -981,7 +981,7 @@ otError MleRouter::HandleLinkAccept(const Message & aMessage, router->SetDeviceMode(DeviceMode(DeviceMode::kModeFullThreadDevice | DeviceMode::kModeRxOnWhenIdle | DeviceMode::kModeFullNetworkData)); router->GetLinkInfo().Clear(); - router->GetLinkInfo().AddRss(Get().GetNoiseFloor(), linkInfo->mRss); + router->GetLinkInfo().AddRss(linkInfo->mRss); router->SetLinkQualityOut(LinkQualityInfo::ConvertLinkMarginToLinkQuality(linkMargin.GetLinkMargin())); router->ResetLinkFailures(); router->SetState(Neighbor::kStateValid); @@ -1356,7 +1356,7 @@ otError MleRouter::HandleAdvertisement(const Message & aMessage, { router->SetExtAddress(macAddr); router->GetLinkInfo().Clear(); - router->GetLinkInfo().AddRss(Get().GetNoiseFloor(), linkInfo->mRss); + router->GetLinkInfo().AddRss(linkInfo->mRss); router->ResetLinkFailures(); router->SetLastHeard(TimerMilli::GetNow()); router->SetState(Neighbor::kStateLinkRequest); @@ -1403,7 +1403,7 @@ otError MleRouter::HandleAdvertisement(const Message & aMessage, { router->SetExtAddress(macAddr); router->GetLinkInfo().Clear(); - router->GetLinkInfo().AddRss(Get().GetNoiseFloor(), linkInfo->mRss); + router->GetLinkInfo().AddRss(linkInfo->mRss); router->ResetLinkFailures(); router->SetLastHeard(TimerMilli::GetNow()); router->SetState(Neighbor::kStateLinkRequest); @@ -1660,7 +1660,7 @@ otError MleRouter::HandleParentRequest(const Message &aMessage, const Ip6::Messa // MAC Address child->SetExtAddress(macAddr); child->GetLinkInfo().Clear(); - child->GetLinkInfo().AddRss(Get().GetNoiseFloor(), linkInfo->mRss); + child->GetLinkInfo().AddRss(linkInfo->mRss); child->ResetLinkFailures(); child->SetState(Neighbor::kStateParentRequest); #if OPENTHREAD_CONFIG_TIME_SYNC_ENABLE @@ -1937,7 +1937,7 @@ void MleRouter::SendParentResponse(Child *aChild, const ChallengeTlv &aChallenge aChild->GenerateChallenge(); SuccessOrExit(error = AppendChallenge(*message, aChild->GetChallenge(), aChild->GetChallengeSize())); - error = AppendLinkMargin(*message, aChild->GetLinkInfo().GetLinkMargin(Get().GetNoiseFloor())); + error = AppendLinkMargin(*message, aChild->GetLinkInfo().GetLinkMargin()); SuccessOrExit(error); SuccessOrExit(error = AppendConnectivity(*message)); @@ -2194,7 +2194,7 @@ otError MleRouter::HandleChildIdRequest(const Message & aMessage, child->SetMleFrameCounter(mleFrameCounter.GetFrameCounter()); child->SetKeySequence(aKeySequence); child->SetDeviceMode(mode.GetMode()); - child->GetLinkInfo().AddRss(Get().GetNoiseFloor(), linkInfo->mRss); + child->GetLinkInfo().AddRss(linkInfo->mRss); child->SetTimeout(timeout.GetTimeout()); if (mode.GetMode().IsFullNetworkData()) @@ -2515,7 +2515,7 @@ otError MleRouter::HandleChildUpdateResponse(const Message & aMessage, SetChildStateToValid(*child); child->SetLastHeard(TimerMilli::GetNow()); child->SetKeySequence(aKeySequence); - child->GetLinkInfo().AddRss(Get().GetNoiseFloor(), linkInfo->mRss); + child->GetLinkInfo().AddRss(linkInfo->mRss); exit: diff --git a/tests/unit/test_link_quality.cpp b/tests/unit/test_link_quality.cpp index caa664825..6a6b46871 100644 --- a/tests/unit/test_link_quality.cpp +++ b/tests/unit/test_link_quality.cpp @@ -105,7 +105,7 @@ void TestLinkQualityData(RssTestData aRssData) rss = aRssData.mRssList[i]; min = MIN_RSS(rss, min); max = MAX_RSS(rss, max); - linkInfo.AddRss(sNoiseFloor, rss); + linkInfo.AddRss(rss); VerifyOrQuit(linkInfo.GetLastRss() == rss, "TestLinkQualityInfo failed - GetLastRss() is incorrect"); ave = linkInfo.GetAverageRss(); VerifyOrQuit(ave >= min, "TestLinkQualityInfo failed - GetAverageRss() is smaller than min value."); diff --git a/tests/unit/test_platform.cpp b/tests/unit/test_platform.cpp index 3e1df85f5..20e929879 100644 --- a/tests/unit/test_platform.cpp +++ b/tests/unit/test_platform.cpp @@ -392,7 +392,7 @@ otError otPlatRadioSetTransmitPower(otInstance *aInstance, int8_t aPower) int8_t otPlatRadioGetReceiveSensitivity(otInstance *aInstance) { OT_UNUSED_VARIABLE(aInstance); - return 0; + return -100; } // // Random