[commissioner] simplify energy list parsing in report handler (#12666)

This commit updates `Commissioner::HandleTmf<kUriEnergyReport>()` to
read the energy list data directly into a local array instead of
using a dedicated TLV class.

The report handler now uses `Tlv::FindTlvValueOffsetRange()` to locate
the TLV value, which works correctly whether the TLV is encoded as a
standard or extended TLV. With this change, the `EnergyListTlv` class
definition is replaced with a simple typedef to `TlvInfo`.
This commit is contained in:
Abtin Keshavarzian
2026-03-11 15:36:30 -05:00
committed by GitHub
parent ea94a2edf6
commit 34856e4d67
3 changed files with 11 additions and 45 deletions
+7 -4
View File
@@ -1070,8 +1070,9 @@ exit:
template <> void Commissioner::HandleTmf<kUriEnergyReport>(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<kUriEnergyReport>(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<uint8_t>(valueOffsetRange.GetLength()));
SuccessOrExit(Get<Tmf::Agent>().SendAckResponse(aMsg));
+2
View File
@@ -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,
+2 -41
View File
@@ -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<Tlv::kEnergyList>
{
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<Tlv::kEnergyList> EnergyListTlv;
/**
* Defines Provisioning TLV constants and types.