diff --git a/include/openthread/link.h b/include/openthread/link.h index 446e42700..ef099a278 100644 --- a/include/openthread/link.h +++ b/include/openthread/link.h @@ -801,26 +801,6 @@ otError otLinkSetEnabled(otInstance *aInstance, bool aEnable); */ bool otLinkIsEnabled(otInstance *aInstance); -/** - * This function gets the minimum channel number of IEEE 802.15.4 physical layer. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * - * @returns The minimum channel number. - * - */ -OTAPI uint8_t OTCALL otLinkGetPhyChannelMin(otInstance *aInstance); - -/** - * This function gets the maximum channel number of IEEE 802.15.4 physical layer. - * - * @param[in] aInstance A pointer to an OpenThread instance. - * - * @returns The maximum channel number. - * - */ -OTAPI uint8_t OTCALL otLinkGetPhyChannelMax(otInstance *aInstance); - /** * @} * diff --git a/src/cli/cli.cpp b/src/cli/cli.cpp index 561dd1321..4eebdce42 100644 --- a/src/cli/cli.cpp +++ b/src/cli/cli.cpp @@ -554,16 +554,25 @@ void Interpreter::ProcessChannel(int argc, char *argv[]) mServer->OutputFormat("enabled: %d\r\n", otChannelMonitorIsEnabled(mInstance)); if (otChannelMonitorIsEnabled(mInstance)) { + uint32_t channelMask = otLinkGetSupportedChannelMask(mInstance); + uint8_t channelNum = sizeof(channelMask) * CHAR_BIT; + mServer->OutputFormat("interval: %lu\r\n", otChannelMonitorGetSampleInterval(mInstance)); mServer->OutputFormat("threshold: %d\r\n", otChannelMonitorGetRssiThreshold(mInstance)); mServer->OutputFormat("window: %lu\r\n", otChannelMonitorGetSampleWindow(mInstance)); mServer->OutputFormat("count: %lu\r\n", otChannelMonitorGetSampleCount(mInstance)); mServer->OutputFormat("occupancies:\r\n"); - for (uint8_t channel = otLinkGetPhyChannelMin(mInstance); channel <= otLinkGetPhyChannelMax(mInstance); - channel++) + for (uint8_t channel = 0; channel < channelNum; channel++) { - uint32_t occupancy = otChannelMonitorGetChannelOccupancy(mInstance, channel); + uint32_t occupancy = 0; + + if (!((1UL << channel) & channelMask)) + { + continue; + } + + occupancy = otChannelMonitorGetChannelOccupancy(mInstance, channel); mServer->OutputFormat("ch %d (0x%04x) ", channel, occupancy); occupancy = (occupancy * 10000) / 0xffff; diff --git a/src/core/api/link_api.cpp b/src/core/api/link_api.cpp index 27203d8c5..cf13e750c 100644 --- a/src/core/api/link_api.cpp +++ b/src/core/api/link_api.cpp @@ -431,15 +431,3 @@ uint16_t otLinkGetCcaFailureRate(otInstance *aInstance) return instance.Get().GetCcaFailureRate(); } - -uint8_t otLinkGetPhyChannelMin(otInstance *aInstance) -{ - OT_UNUSED_VARIABLE(aInstance); - return Phy::kChannelMin; -} - -uint8_t otLinkGetPhyChannelMax(otInstance *aInstance) -{ - OT_UNUSED_VARIABLE(aInstance); - return Phy::kChannelMax; -} diff --git a/src/diag/diag_process.cpp b/src/diag/diag_process.cpp index 16cf2396b..c34a9aa13 100644 --- a/src/diag/diag_process.cpp +++ b/src/diag/diag_process.cpp @@ -40,6 +40,7 @@ #include #include "common/code_utils.hpp" +#include "phy/phy.hpp" #include "utils/wrap_string.h" namespace ot { @@ -191,8 +192,7 @@ void Diag::ProcessChannel(int aArgCount, char *aArgVector[], char *aOutput, size long value; SuccessOrExit(error = ParseLong(aArgVector[0], value)); - VerifyOrExit(value >= otLinkGetPhyChannelMin(sInstance) && value <= otLinkGetPhyChannelMax(sInstance), - error = OT_ERROR_INVALID_ARGS); + VerifyOrExit(value >= Phy::kChannelMin && value <= Phy::kChannelMax, error = OT_ERROR_INVALID_ARGS); sChannel = static_cast(value); otPlatRadioReceive(sInstance, sChannel); diff --git a/src/ncp/ncp_base_mtd.cpp b/src/ncp/ncp_base_mtd.cpp index 649443882..83294edb7 100644 --- a/src/ncp/ncp_base_mtd.cpp +++ b/src/ncp/ncp_base_mtd.cpp @@ -2060,10 +2060,17 @@ template <> otError NcpBase::HandlePropertyGet otError NcpBase::HandlePropertyGet(void) { - otError error = OT_ERROR_NONE; + otError error = OT_ERROR_NONE; + uint32_t channelMask = otLinkGetSupportedChannelMask(mInstance); + uint8_t channelNum = sizeof(channelMask) * CHAR_BIT; - for (uint8_t channel = otLinkGetPhyChannelMin(mInstance); channel <= otLinkGetPhyChannelMax(mInstance); channel++) + for (uint8_t channel = 0; channel < channelNum; channel++) { + if (!((1UL << channel) & channelMask)) + { + continue; + } + SuccessOrExit(error = mEncoder.OpenStruct()); SuccessOrExit(error = mEncoder.WriteUint8(channel));