diff --git a/src/core/meshcop/commissioner.cpp b/src/core/meshcop/commissioner.cpp index bc58599e5..687b62ba4 100644 --- a/src/core/meshcop/commissioner.cpp +++ b/src/core/meshcop/commissioner.cpp @@ -1070,8 +1070,9 @@ exit: template <> void Commissioner::HandleTmf(Coap::Msg &aMsg) { - uint32_t mask; - EnergyListTlv energyListTlv; + uint32_t mask; + OffsetRange valueOffsetRange; + uint8_t results[kMaxEnergyScanResults]; VerifyOrExit(aMsg.IsConfirmable()); @@ -1079,9 +1080,11 @@ template <> void Commissioner::HandleTmf(Coap::Msg &aMsg) SuccessOrExit(ChannelMaskTlv::FindIn(aMsg.mMessage, mask)); - SuccessOrExit(Tlv::FindTlv(aMsg.mMessage, Tlv::kEnergyList, sizeof(energyListTlv), energyListTlv)); + SuccessOrExit(Tlv::FindTlvValueOffsetRange(aMsg.mMessage, Tlv::kEnergyList, valueOffsetRange)); + valueOffsetRange.ShrinkLength(sizeof(results)); + aMsg.mMessage.ReadBytes(valueOffsetRange, results); - mEnergyReportCallback.InvokeIfSet(mask, energyListTlv.GetEnergyList(), energyListTlv.GetEnergyListLength()); + mEnergyReportCallback.InvokeIfSet(mask, results, static_cast(valueOffsetRange.GetLength())); SuccessOrExit(Get().SendAckResponse(aMsg)); diff --git a/src/core/meshcop/commissioner.hpp b/src/core/meshcop/commissioner.hpp index a7b9b0d15..53843f4f5 100644 --- a/src/core/meshcop/commissioner.hpp +++ b/src/core/meshcop/commissioner.hpp @@ -382,6 +382,8 @@ private: static constexpr uint32_t kJoinerSessionTimeoutMillis = 1000 * OPENTHREAD_CONFIG_COMMISSIONER_JOINER_SESSION_TIMEOUT; // Expiration time for active Joiner session + static constexpr uint8_t kMaxEnergyScanResults = OPENTHREAD_CONFIG_TMF_ENERGY_SCAN_MAX_RESULTS; + enum ResignMode : uint8_t { kSendKeepAliveToResign, diff --git a/src/core/meshcop/meshcop_tlvs.hpp b/src/core/meshcop/meshcop_tlvs.hpp index 7cbf20e6a..508aee22c 100644 --- a/src/core/meshcop/meshcop_tlvs.hpp +++ b/src/core/meshcop/meshcop_tlvs.hpp @@ -724,48 +724,9 @@ private: } OT_TOOL_PACKED_BEGIN; /** - * Implements Energy List TLV generation and parsing. + * Defines Energy List TLV constants and types. */ -OT_TOOL_PACKED_BEGIN -class EnergyListTlv : public Tlv, public TlvInfo -{ -public: - /** - * Initializes the TLV. - */ - void Init(void) - { - SetType(kEnergyList); - SetLength(sizeof(*this) - sizeof(Tlv)); - } - - /** - * Indicates whether or not the TLV appears to be well-formed. - * - * @retval TRUE If the TLV appears to be well-formed. - * @retval FALSE If the TLV does not appear to be well-formed. - */ - bool IsValid(void) const { return true; } - - /** - * Returns a pointer to the start of energy measurement list. - * - * @returns A pointer to the start start of energy energy measurement list. - */ - const uint8_t *GetEnergyList(void) const { return mEnergyList; } - - /** - * Returns the length of energy measurement list. - * - * @returns The length of energy measurement list. - */ - uint8_t GetEnergyListLength(void) const { return Min(kMaxListLength, GetLength()); } - -private: - static constexpr uint8_t kMaxListLength = OPENTHREAD_CONFIG_TMF_ENERGY_SCAN_MAX_RESULTS; - - uint8_t mEnergyList[kMaxListLength]; -} OT_TOOL_PACKED_END; +typedef TlvInfo EnergyListTlv; /** * Defines Provisioning TLV constants and types.