mirror of
https://github.com/espressif/openthread.git
synced 2026-10-11 10:17:35 +00:00
[core] use Tlv::AppendTlv helper to simplify TLV appends (#12252)
This commit updates various modules to use the `Tlv::AppendTlv` helper method when appending a TLV with its value to a `Message`.
This commit is contained in:
@@ -606,17 +606,13 @@ Error Commissioner::SendMgmtCommissionerGetRequest(const uint8_t *aTlvs, uint8_t
|
||||
Error error = kErrorNone;
|
||||
OwnedPtr<Coap::Message> message;
|
||||
Tmf::MessageInfo messageInfo(GetInstance());
|
||||
Tlv tlv;
|
||||
|
||||
message.Reset(Get<Tmf::Agent>().NewPriorityConfirmablePostMessage(kUriCommissionerGet));
|
||||
VerifyOrExit(message != nullptr, error = kErrorNoBufs);
|
||||
|
||||
if (aLength > 0)
|
||||
{
|
||||
tlv.SetType(Tlv::kGet);
|
||||
tlv.SetLength(aLength);
|
||||
SuccessOrExit(error = message->Append(tlv));
|
||||
SuccessOrExit(error = message->AppendBytes(aTlvs, aLength));
|
||||
SuccessOrExit(error = Tlv::AppendTlv(*message, Tlv::kGet, aTlvs, aLength));
|
||||
}
|
||||
|
||||
messageInfo.SetSockAddrToRlocPeerAddrToLeaderAloc();
|
||||
|
||||
@@ -99,12 +99,7 @@ Error Initiator::AppendLinkMetricsQueryTlv(Message &aMessage, const QueryInfo &a
|
||||
|
||||
if (aInfo.mTypeIdCount != 0)
|
||||
{
|
||||
QueryOptionsSubTlv queryOptionsTlv;
|
||||
|
||||
queryOptionsTlv.Init();
|
||||
queryOptionsTlv.SetLength(aInfo.mTypeIdCount);
|
||||
SuccessOrExit(error = aMessage.Append(queryOptionsTlv));
|
||||
SuccessOrExit(error = aMessage.AppendBytes(aInfo.mTypeIds, aInfo.mTypeIdCount));
|
||||
SuccessOrExit(error = Tlv::AppendTlv(aMessage, QueryOptionsSubTlv::kType, aInfo.mTypeIds, aInfo.mTypeIdCount));
|
||||
}
|
||||
|
||||
error = Tlv::EndTlv(aMessage, tlvBookmark);
|
||||
|
||||
@@ -79,6 +79,11 @@ typedef UintTlvInfo<SubTlv::kQueryId, uint8_t> QueryIdSubTlv;
|
||||
*/
|
||||
typedef UintTlvInfo<SubTlv::kStatus, uint8_t> StatusSubTlv;
|
||||
|
||||
/**
|
||||
* Defines Query Option Sub-TLV constants and types.
|
||||
*/
|
||||
typedef TlvInfo<SubTlv::kQueryOptions> QueryOptionsSubTlv;
|
||||
|
||||
/**
|
||||
* Implements Link Metrics Report Sub-TLV generation and parsing.
|
||||
*/
|
||||
@@ -160,32 +165,6 @@ private:
|
||||
} mMetricsValue;
|
||||
} OT_TOOL_PACKED_END;
|
||||
|
||||
/**
|
||||
* Implements Link Metrics Query Options Sub-TLV generation and parsing.
|
||||
*/
|
||||
OT_TOOL_PACKED_BEGIN
|
||||
class QueryOptionsSubTlv : public Tlv, public TlvInfo<SubTlv::kQueryOptions>
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Initializes the TLV.
|
||||
*/
|
||||
void Init(void)
|
||||
{
|
||||
SetType(SubTlv::kQueryOptions);
|
||||
SetLength(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 GetLength() >= sizeof(uint8_t); }
|
||||
|
||||
} OT_TOOL_PACKED_END;
|
||||
|
||||
/**
|
||||
* Defines Link Metrics Forward Probing Registration Sub-TLV.
|
||||
*/
|
||||
|
||||
@@ -3041,15 +3041,11 @@ Error Mle::SendLinkMetricsManagementRequest(const Ip6::Address &aDestination, co
|
||||
{
|
||||
Error error = kErrorNone;
|
||||
TxMessage *message = NewMleMessage(kCommandLinkMetricsManagementRequest);
|
||||
Tlv tlv;
|
||||
|
||||
VerifyOrExit(message != nullptr, error = kErrorNoBufs);
|
||||
|
||||
tlv.SetType(Tlv::kLinkMetricsManagement);
|
||||
tlv.SetLength(static_cast<uint8_t>(aSubTlv.GetSize()));
|
||||
|
||||
SuccessOrExit(error = message->Append(tlv));
|
||||
SuccessOrExit(error = aSubTlv.AppendTo(*message));
|
||||
SuccessOrExit(error = Tlv::AppendTlv(*message, Tlv::kLinkMetricsManagement, &aSubTlv,
|
||||
static_cast<uint16_t>(aSubTlv.GetSize())));
|
||||
|
||||
error = message->SendTo(aDestination);
|
||||
|
||||
|
||||
@@ -192,12 +192,8 @@ Error Notifier::SendServerDataNotification(uint16_t aOldRloc16, const NetworkDat
|
||||
|
||||
if (aNetworkData != nullptr)
|
||||
{
|
||||
ThreadTlv tlv;
|
||||
|
||||
tlv.SetType(ThreadTlv::kThreadNetworkData);
|
||||
tlv.SetLength(aNetworkData->GetLength());
|
||||
SuccessOrExit(error = message->Append(tlv));
|
||||
SuccessOrExit(error = message->AppendBytes(aNetworkData->GetBytes(), aNetworkData->GetLength()));
|
||||
SuccessOrExit(error = Tlv::AppendTlv(*message, ThreadTlv::kThreadNetworkData, aNetworkData->GetBytes(),
|
||||
aNetworkData->GetLength()));
|
||||
|
||||
#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_BORDER_ROUTER_SIGNAL_NETWORK_DATA_FULL
|
||||
Get<Leader>().CheckForNetDataGettingFull(*aNetworkData, aOldRloc16);
|
||||
|
||||
Reference in New Issue
Block a user