From a17d12a263ec12636713fbd582a2b1c225124d7b Mon Sep 17 00:00:00 2001 From: Sagar Chinchani <54454029+schinchani@users.noreply.github.com> Date: Thu, 20 May 2021 20:16:24 -0400 Subject: [PATCH] [radio] remove `OT_RADIO_CHANNEL_PAGE_MAX` and address gcc warnings (#6646) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit modifies the (<=) usage in two ‘if’ conditions as these operations as written today (with constants), are resulting in the compile time warnings (and cmake errors) specifically when working with proprietary radio configurations and setting Channel Min to 0. Updated the radio header to get rid of OT_RADIO_CHANNEL_PAGE_MAX. Also adds a compile-time error, if a user sets the proprietary channel page to a value greater than 31, as it is currently not supported. --- include/openthread/instance.h | 2 +- include/openthread/platform/radio.h | 1 - src/core/config/platform.h | 4 ++++ src/core/meshcop/meshcop_tlvs.cpp | 10 +++++++--- src/core/radio/radio.hpp | 3 ++- 5 files changed, 14 insertions(+), 6 deletions(-) diff --git a/include/openthread/instance.h b/include/openthread/instance.h index 84d1d2268..b4d7fda9c 100644 --- a/include/openthread/instance.h +++ b/include/openthread/instance.h @@ -53,7 +53,7 @@ extern "C" { * @note This number versions both OpenThread platform and user APIs. * */ -#define OPENTHREAD_API_VERSION (115) +#define OPENTHREAD_API_VERSION (116) /** * @addtogroup api-instance diff --git a/include/openthread/platform/radio.h b/include/openthread/platform/radio.h index 5ec08182e..2d25cd65f 100644 --- a/include/openthread/platform/radio.h +++ b/include/openthread/platform/radio.h @@ -88,7 +88,6 @@ enum OT_RADIO_CHANNEL_PAGE_0_MASK = (1U << OT_RADIO_CHANNEL_PAGE_0), ///< 2.4 GHz IEEE 802.15.4-2006 OT_RADIO_CHANNEL_PAGE_2 = 2, ///< 915 MHz IEEE 802.15.4-2006 OT_RADIO_CHANNEL_PAGE_2_MASK = (1U << OT_RADIO_CHANNEL_PAGE_2), ///< 915 MHz IEEE 802.15.4-2006 - OT_RADIO_CHANNEL_PAGE_MAX = OT_RADIO_CHANNEL_PAGE_2, ///< Maximum supported channel page value }; /** diff --git a/src/core/config/platform.h b/src/core/config/platform.h index 66282ac39..59539f799 100644 --- a/src/core/config/platform.h +++ b/src/core/config/platform.h @@ -140,6 +140,10 @@ OPENTHREAD_CONFIG_PLATFORM_RADIO_PROPRIETARY_CHANNEL_MASK\ to be defined by Platform." #endif + +#if OPENTHREAD_CONFIG_PLATFORM_RADIO_PROPRIETARY_CHANNEL_PAGE > 31 +#error "Maximum Proprietary Channel Page value currently supported is 31." +#endif #endif #endif // CONFIG_PLATFORM_H_ diff --git a/src/core/meshcop/meshcop_tlvs.cpp b/src/core/meshcop/meshcop_tlvs.cpp index bdebdfa2f..eb1a999cd 100644 --- a/src/core/meshcop/meshcop_tlvs.cpp +++ b/src/core/meshcop/meshcop_tlvs.cpp @@ -173,7 +173,6 @@ bool ChannelTlv::IsValid(void) const bool ret = false; VerifyOrExit(GetLength() == sizeof(*this) - sizeof(Tlv)); - VerifyOrExit(mChannelPage <= OT_RADIO_CHANNEL_PAGE_MAX); VerifyOrExit((1U << mChannelPage) & Radio::kSupportedChannelPages); VerifyOrExit(Radio::kChannelMin <= GetChannel() && GetChannel() <= Radio::kChannelMax); ret = true; @@ -201,8 +200,9 @@ void ChannelTlv::SetChannel(uint16_t aChannel) #endif #if OPENTHREAD_CONFIG_PLATFORM_RADIO_PROPRIETARY_SUPPORT - if ((OPENTHREAD_CONFIG_PLATFORM_RADIO_PROPRIETARY_CHANNEL_MIN <= aChannel) && - (aChannel <= OPENTHREAD_CONFIG_PLATFORM_RADIO_PROPRIETARY_CHANNEL_MAX)) + if ((OPENTHREAD_CONFIG_PLATFORM_RADIO_PROPRIETARY_CHANNEL_MIN == aChannel) || + ((OPENTHREAD_CONFIG_PLATFORM_RADIO_PROPRIETARY_CHANNEL_MIN < aChannel) && + (aChannel <= OPENTHREAD_CONFIG_PLATFORM_RADIO_PROPRIETARY_CHANNEL_MAX))) { channelPage = OPENTHREAD_CONFIG_PLATFORM_RADIO_PROPRIETARY_CHANNEL_PAGE; } @@ -228,7 +228,11 @@ bool ChannelMaskBaseTlv::IsValid(void) const channelPage = cur->GetChannelPage(); +#if OPENTHREAD_CONFIG_PLATFORM_RADIO_PROPRIETARY_SUPPORT + if (channelPage == OPENTHREAD_CONFIG_PLATFORM_RADIO_PROPRIETARY_CHANNEL_PAGE) +#else if ((channelPage == OT_RADIO_CHANNEL_PAGE_0) || (channelPage == OT_RADIO_CHANNEL_PAGE_2)) +#endif { VerifyOrExit(static_cast(cur)->IsValid()); } diff --git a/src/core/radio/radio.hpp b/src/core/radio/radio.hpp index aafe37073..a5073d629 100644 --- a/src/core/radio/radio.hpp +++ b/src/core/radio/radio.hpp @@ -635,7 +635,8 @@ public: */ static bool IsCslChannelValid(uint8_t aCslChannel) { - return (aCslChannel == 0) || ((kChannelMin <= aCslChannel) && (aCslChannel <= kChannelMax)); + return ((aCslChannel == 0) || + ((kChannelMin == aCslChannel) || ((kChannelMin < aCslChannel) && (aCslChannel <= kChannelMax)))); } private: