mirror of
https://github.com/espressif/openthread.git
synced 2026-08-03 01:17:46 +00:00
[coap] add new helper to allocate and init CoAP message (#7631)
This commit adds new helper methods in `Coap` to allocate a new message and initialize it as a confirmable or non-confirmable post to a given URI path. It also adds a new helper method to allocate a CoAP response message for a given request. These methods help simplify the preparation of CoAP and TMF messages.
This commit is contained in:
@@ -302,13 +302,11 @@ void Manager::SendMulticastListenerRegistrationResponse(const Coap::Message &
|
||||
Ip6::Address * aFailedAddresses,
|
||||
uint8_t aFailedAddressNum)
|
||||
{
|
||||
Error error = kErrorNone;
|
||||
Coap::Message *message = nullptr;
|
||||
Error error = kErrorNone;
|
||||
Coap::Message *message;
|
||||
|
||||
VerifyOrExit((message = Get<Tmf::Agent>().NewMessage()) != nullptr, error = kErrorNoBufs);
|
||||
|
||||
SuccessOrExit(message->SetDefaultResponseHeader(aMessage));
|
||||
SuccessOrExit(message->SetPayloadMarker());
|
||||
message = Get<Tmf::Agent>().NewResponseMessage(aMessage);
|
||||
VerifyOrExit(message != nullptr, error = kErrorNoBufs);
|
||||
|
||||
SuccessOrExit(Tlv::Append<ThreadStatusTlv>(*message, aStatus));
|
||||
|
||||
@@ -345,10 +343,8 @@ void Manager::SendBackboneMulticastListenerRegistration(const Ip6::Address *aAdd
|
||||
|
||||
OT_ASSERT(aAddressNum >= kIp6AddressesNumMin && aAddressNum <= kIp6AddressesNumMax);
|
||||
|
||||
VerifyOrExit((message = backboneTmf.NewMessage()) != nullptr, error = kErrorNoBufs);
|
||||
|
||||
SuccessOrExit(error = message->InitAsNonConfirmablePost(UriPath::kBackboneMlr));
|
||||
SuccessOrExit(error = message->SetPayloadMarker());
|
||||
message = backboneTmf.NewNonConfirmablePostMessage(UriPath::kBackboneMlr);
|
||||
VerifyOrExit(message != nullptr, error = kErrorNoBufs);
|
||||
|
||||
addressesTlv.Init();
|
||||
addressesTlv.SetLength(sizeof(Ip6::Address) * aAddressNum);
|
||||
@@ -454,13 +450,11 @@ void Manager::SendDuaRegistrationResponse(const Coap::Message & aMessage,
|
||||
const Ip6::Address & aTarget,
|
||||
ThreadStatusTlv::DuaStatus aStatus)
|
||||
{
|
||||
Error error = kErrorNone;
|
||||
Coap::Message *message = nullptr;
|
||||
Error error = kErrorNone;
|
||||
Coap::Message *message;
|
||||
|
||||
VerifyOrExit((message = Get<Tmf::Agent>().NewMessage()) != nullptr, error = kErrorNoBufs);
|
||||
|
||||
SuccessOrExit(message->SetDefaultResponseHeader(aMessage));
|
||||
SuccessOrExit(message->SetPayloadMarker());
|
||||
message = Get<Tmf::Agent>().NewResponseMessage(aMessage);
|
||||
VerifyOrExit(message != nullptr, error = kErrorNoBufs);
|
||||
|
||||
SuccessOrExit(Tlv::Append<ThreadStatusTlv>(*message, aStatus));
|
||||
SuccessOrExit(Tlv::Append<ThreadTargetTlv>(*message, aTarget));
|
||||
@@ -535,10 +529,8 @@ Error Manager::SendBackboneQuery(const Ip6::Address &aDua, uint16_t aRloc16)
|
||||
|
||||
VerifyOrExit(Get<Local>().IsPrimary(), error = kErrorInvalidState);
|
||||
|
||||
VerifyOrExit((message = mBackboneTmfAgent.NewPriorityMessage()) != nullptr, error = kErrorNoBufs);
|
||||
|
||||
SuccessOrExit(error = message->InitAsNonConfirmablePost(UriPath::kBackboneQuery));
|
||||
SuccessOrExit(error = message->SetPayloadMarker());
|
||||
message = mBackboneTmfAgent.NewPriorityNonConfirmablePostMessage(UriPath::kBackboneQuery);
|
||||
VerifyOrExit(message != nullptr, error = kErrorNoBufs);
|
||||
|
||||
SuccessOrExit(error = Tlv::Append<ThreadTargetTlv>(*message, aDua));
|
||||
|
||||
|
||||
@@ -139,6 +139,64 @@ exit:
|
||||
return message;
|
||||
}
|
||||
|
||||
Message *CoapBase::NewPriorityConfirmablePostMessage(const char *aUriPath)
|
||||
{
|
||||
return InitMessage(NewPriorityMessage(), kTypeConfirmable, aUriPath);
|
||||
}
|
||||
|
||||
Message *CoapBase::NewConfirmablePostMessage(const char *aUriPath)
|
||||
{
|
||||
return InitMessage(NewMessage(), kTypeConfirmable, aUriPath);
|
||||
}
|
||||
|
||||
Message *CoapBase::NewPriorityNonConfirmablePostMessage(const char *aUriPath)
|
||||
{
|
||||
return InitMessage(NewPriorityMessage(), kTypeNonConfirmable, aUriPath);
|
||||
}
|
||||
|
||||
Message *CoapBase::NewNonConfirmablePostMessage(const char *aUriPath)
|
||||
{
|
||||
return InitMessage(NewMessage(), kTypeNonConfirmable, aUriPath);
|
||||
}
|
||||
|
||||
Message *CoapBase::NewPriorityResponseMessage(const Message &aRequest)
|
||||
{
|
||||
return InitResponse(NewPriorityMessage(), aRequest);
|
||||
}
|
||||
|
||||
Message *CoapBase::NewResponseMessage(const Message &aRequest)
|
||||
{
|
||||
return InitResponse(NewMessage(), aRequest);
|
||||
}
|
||||
|
||||
Message *CoapBase::InitMessage(Message *aMessage, Type aType, const char *aUriPath)
|
||||
{
|
||||
Error error = kErrorNone;
|
||||
|
||||
VerifyOrExit(aMessage != nullptr);
|
||||
|
||||
SuccessOrExit(error = aMessage->Init(aType, kCodePost, aUriPath));
|
||||
SuccessOrExit(error = aMessage->SetPayloadMarker());
|
||||
|
||||
exit:
|
||||
FreeAndNullMessageOnError(aMessage, error);
|
||||
return aMessage;
|
||||
}
|
||||
|
||||
Message *CoapBase::InitResponse(Message *aMessage, const Message &aResponse)
|
||||
{
|
||||
Error error = kErrorNone;
|
||||
|
||||
VerifyOrExit(aMessage != nullptr);
|
||||
|
||||
SuccessOrExit(error = aMessage->SetDefaultResponseHeader(aResponse));
|
||||
SuccessOrExit(error = aMessage->SetPayloadMarker());
|
||||
|
||||
exit:
|
||||
FreeAndNullMessageOnError(aMessage, error);
|
||||
return aMessage;
|
||||
}
|
||||
|
||||
Error CoapBase::Send(ot::Message &aMessage, const Ip6::MessageInfo &aMessageInfo)
|
||||
{
|
||||
Error error;
|
||||
|
||||
+94
-2
@@ -435,7 +435,7 @@ public:
|
||||
void SetDefaultHandler(RequestHandler aHandler, void *aContext);
|
||||
|
||||
/**
|
||||
* This method creates a new message with a CoAP header.
|
||||
* This method allocates a new message with a CoAP header.
|
||||
*
|
||||
* @param[in] aSettings The message settings.
|
||||
*
|
||||
@@ -445,7 +445,7 @@ public:
|
||||
Message *NewMessage(const Message::Settings &aSettings = Message::Settings::GetDefault());
|
||||
|
||||
/**
|
||||
* This method creates a new message with a CoAP header that has Network Control priority level.
|
||||
* This method allocates a new message with a CoAP header that has Network Control priority level.
|
||||
*
|
||||
* @returns A pointer to the message or `nullptr` if failed to allocate message.
|
||||
*
|
||||
@@ -455,6 +455,95 @@ public:
|
||||
return NewMessage(Message::Settings(Message::kWithLinkSecurity, Message::kPriorityNet));
|
||||
}
|
||||
|
||||
/**
|
||||
* This method allocates and initializes a new CoAP Confirmable Post message with Network Control priority level.
|
||||
*
|
||||
* The CoAP header is initialized as `kTypeConfirmable` and `kCodePost` with a given URI path and a randomly
|
||||
* generated token (of default length). This method also sets the payload marker (`SetPayloadMarker()` on message.
|
||||
* Even if message has no payload, calling `SetPayloadMarker()` is harmless, since `SendMessage()` will check and
|
||||
* remove the payload marker when there is no payload.
|
||||
*
|
||||
* @param[in] aUriPath The URI path string.
|
||||
*
|
||||
* @returns A pointer to the message or `nullptr` if failed to allocate message.
|
||||
*
|
||||
*/
|
||||
Message *NewPriorityConfirmablePostMessage(const char *aUriPath);
|
||||
|
||||
/**
|
||||
* This method allocates and initializes a new CoAP Confirmable Post message with normal priority level.
|
||||
*
|
||||
* The CoAP header is initialized as `kTypeConfirmable` and `kCodePost` with a given URI path and a randomly
|
||||
* generated token (of default length). This method also sets the payload marker (calling `SetPayloadMarker()`).
|
||||
* Even if message has no payload, calling `SetPayloadMarker()` is harmless, since `SendMessage()` will check and
|
||||
* remove the payload marker when there is no payload.
|
||||
*
|
||||
* @param[in] aUriPath The URI path string.
|
||||
*
|
||||
* @returns A pointer to the message or `nullptr` if failed to allocate message.
|
||||
*
|
||||
*/
|
||||
Message *NewConfirmablePostMessage(const char *aUriPath);
|
||||
|
||||
/**
|
||||
* This method allocates and initializes a new CoAP Non-confirmable Post message with Network Control priority
|
||||
* level.
|
||||
*
|
||||
* The CoAP header is initialized as `kTypeNonConfirmable` and `kCodePost` with a given URI path and a randomly
|
||||
* generated token (of default length). This method also sets the payload marker (calling `SetPayloadMarker()`).
|
||||
* Even if message has no payload, calling `SetPayloadMarker()` is harmless, since `SendMessage()` will check and
|
||||
* remove the payload marker when there is no payload.
|
||||
*
|
||||
* @param[in] aUriPath The URI path string.
|
||||
*
|
||||
* @returns A pointer to the message or `nullptr` if failed to allocate message.
|
||||
*
|
||||
*/
|
||||
Message *NewPriorityNonConfirmablePostMessage(const char *aUriPath);
|
||||
|
||||
/**
|
||||
* This method allocates and initializes a new CoAP Non-confirmable Post message with normal priority level.
|
||||
*
|
||||
* The CoAP header is initialized as `kTypeNonConfirmable` and `kCodePost` with a given URI path and a randomly
|
||||
* generated token (of default length). This method also sets the payload marker (calling `SetPayloadMarker()`).
|
||||
* Even if message has no payload, calling `SetPayloadMarker()` is harmless, since `SendMessage()` will check and
|
||||
* remove the payload marker when there is no payload.
|
||||
*
|
||||
* @param[in] aUriPath The URI path string.
|
||||
*
|
||||
* @returns A pointer to the message or `nullptr` if failed to allocate message.
|
||||
*
|
||||
*/
|
||||
Message *NewNonConfirmablePostMessage(const char *aUriPath);
|
||||
|
||||
/**
|
||||
* This method allocates and initializes a new CoAP response message with Network Control priority level for a
|
||||
* given request message.
|
||||
*
|
||||
* The CoAP header is initialized as `kTypeAck` with `kCodeChanged`. The token and message ID is copied from
|
||||
* @p aRequest. This method also sets the payload marker (calling `SetPayloadMarker()`). Even if message has
|
||||
* no payload, calling `SetPayloadMarker()` is harmless, since `SendMessage()` will check and remove the payload
|
||||
* marker when there is no payload.
|
||||
*
|
||||
* @returns A pointer to the message or `nullptr` if failed to allocate message.
|
||||
*
|
||||
*/
|
||||
Message *NewPriorityResponseMessage(const Message &aRequest);
|
||||
|
||||
/**
|
||||
* This method allocates and initializes a new CoAP response message with regular priority level for a given
|
||||
* request message.
|
||||
*
|
||||
* The CoAP header is initialized as `kTypeAck` with `kCodeChanged`. The token and message ID is copied from
|
||||
* @p aRequest. This method also sets the payload marker (calling `SetPayloadMarker()`). Even if message has
|
||||
* no payload, calling `SetPayloadMarker()` is harmless, since `SendMessage()` will check and remove the payload
|
||||
* marker when there is no payload.
|
||||
*
|
||||
* @returns A pointer to the message or `nullptr` if failed to allocate message.
|
||||
*
|
||||
*/
|
||||
Message *NewResponseMessage(const Message &aRequest);
|
||||
|
||||
#if OPENTHREAD_CONFIG_COAP_BLOCKWISE_TRANSFER_ENABLE
|
||||
/**
|
||||
* This method sends a CoAP message block-wise with custom transmission parameters.
|
||||
@@ -718,6 +807,9 @@ private:
|
||||
#endif
|
||||
};
|
||||
|
||||
Message *InitMessage(Message *aMessage, Type aType, const char *aUriPath);
|
||||
Message *InitResponse(Message *aMessage, const Message &aResponse);
|
||||
|
||||
static void HandleRetransmissionTimer(Timer &aTimer);
|
||||
void HandleRetransmissionTimer(void);
|
||||
|
||||
|
||||
@@ -79,26 +79,6 @@ exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
void Message::InitAsConfirmablePost(void)
|
||||
{
|
||||
Init(kTypeConfirmable, kCodePost);
|
||||
}
|
||||
|
||||
void Message::InitAsNonConfirmablePost(void)
|
||||
{
|
||||
Init(kTypeNonConfirmable, kCodePost);
|
||||
}
|
||||
|
||||
Error Message::InitAsConfirmablePost(const char *aUriPath)
|
||||
{
|
||||
return Init(kTypeConfirmable, kCodePost, aUriPath);
|
||||
}
|
||||
|
||||
Error Message::InitAsNonConfirmablePost(const char *aUriPath)
|
||||
{
|
||||
return Init(kTypeNonConfirmable, kCodePost, aUriPath);
|
||||
}
|
||||
|
||||
Error Message::InitAsPost(const Ip6::Address &aDestination, const char *aUriPath)
|
||||
{
|
||||
return Init(aDestination.IsMulticast() ? kTypeNonConfirmable : kTypeConfirmable, kCodePost, aUriPath);
|
||||
|
||||
@@ -203,18 +203,6 @@ public:
|
||||
*/
|
||||
void Init(Type aType, Code aCode);
|
||||
|
||||
/**
|
||||
* This method initializes the CoAP header as `kTypeConfirmable` and `kCodePost`.
|
||||
*
|
||||
*/
|
||||
void InitAsConfirmablePost(void);
|
||||
|
||||
/**
|
||||
* This method initializes the CoAP header as `kTypeNonConfirmable` and `kCodePost`.
|
||||
*
|
||||
*/
|
||||
void InitAsNonConfirmablePost(void);
|
||||
|
||||
/**
|
||||
* This method initializes the CoAP header with specific Type and Code.
|
||||
*
|
||||
@@ -228,28 +216,6 @@ public:
|
||||
*/
|
||||
Error Init(Type aType, Code aCode, const char *aUriPath);
|
||||
|
||||
/**
|
||||
* This method initializes the CoAP header as `kTypeConfirmable` and `kCodePost` with a given URI Path.
|
||||
*
|
||||
* @param[in] aUriPath A pointer to a null-terminated string.
|
||||
*
|
||||
* @retval kErrorNone Successfully appended the option.
|
||||
* @retval kErrorNoBufs The option length exceeds the buffer size.
|
||||
*
|
||||
*/
|
||||
Error InitAsConfirmablePost(const char *aUriPath);
|
||||
|
||||
/**
|
||||
* This method initializes the CoAP header as `kTypeNonConfirmable` and `kCodePost` with a given URI Path.
|
||||
*
|
||||
* @param[in] aUriPath A pointer to a null-terminated string.
|
||||
*
|
||||
* @retval kErrorNone Successfully appended the option.
|
||||
* @retval kErrorNoBufs The option length exceeds the buffer size.
|
||||
*
|
||||
*/
|
||||
Error InitAsNonConfirmablePost(const char *aUriPath);
|
||||
|
||||
/**
|
||||
* This method initializes the CoAP header as `kCodePost` with a given URI Path with its type determined from a
|
||||
* given destination IPv6 address.
|
||||
|
||||
@@ -362,11 +362,8 @@ bool BorderAgent::HandleUdpReceive(const Message &aMessage, const Ip6::MessageIn
|
||||
|
||||
VerifyOrExit(aMessage.GetLength() > 0, error = kErrorNone);
|
||||
|
||||
VerifyOrExit((message = Get<Coap::CoapSecure>().NewPriorityMessage()) != nullptr, error = kErrorNoBufs);
|
||||
|
||||
message->InitAsNonConfirmablePost();
|
||||
SuccessOrExit(error = message->AppendUriPathOptions(UriPath::kProxyRx));
|
||||
SuccessOrExit(error = message->SetPayloadMarker());
|
||||
message = Get<Coap::CoapSecure>().NewPriorityNonConfirmablePostMessage(UriPath::kProxyRx);
|
||||
VerifyOrExit(message != nullptr, error = kErrorNoBufs);
|
||||
|
||||
{
|
||||
UdpEncapsulationTlv tlv;
|
||||
@@ -403,15 +400,9 @@ void BorderAgent::HandleRelayReceive(const Coap::Message &aMessage)
|
||||
Error error;
|
||||
|
||||
VerifyOrExit(aMessage.IsNonConfirmablePostRequest(), error = kErrorDrop);
|
||||
VerifyOrExit((message = Get<Coap::CoapSecure>().NewPriorityMessage()) != nullptr, error = kErrorNoBufs);
|
||||
|
||||
message->InitAsNonConfirmablePost();
|
||||
SuccessOrExit(error = message->AppendUriPathOptions(UriPath::kRelayRx));
|
||||
|
||||
if (aMessage.GetLength() > aMessage.GetOffset())
|
||||
{
|
||||
SuccessOrExit(error = message->SetPayloadMarker());
|
||||
}
|
||||
message = Get<Coap::CoapSecure>().NewPriorityNonConfirmablePostMessage(UriPath::kRelayRx);
|
||||
VerifyOrExit(message != nullptr, error = kErrorNoBufs);
|
||||
|
||||
SuccessOrExit(error = ForwardToCommissioner(*message, aMessage));
|
||||
LogInfo("Sent to commissioner on %s", UriPath::kRelayRx);
|
||||
@@ -463,10 +454,8 @@ void BorderAgent::HandleRelayTransmit(const Coap::Message &aMessage)
|
||||
|
||||
SuccessOrExit(error = Tlv::Find<JoinerRouterLocatorTlv>(aMessage, joinerRouterRloc));
|
||||
|
||||
VerifyOrExit((message = Get<Tmf::Agent>().NewPriorityMessage()) != nullptr, error = kErrorNoBufs);
|
||||
|
||||
SuccessOrExit(error = message->InitAsNonConfirmablePost(UriPath::kRelayTx));
|
||||
SuccessOrExit(error = message->SetPayloadMarker());
|
||||
message = Get<Tmf::Agent>().NewPriorityNonConfirmablePostMessage(UriPath::kRelayTx);
|
||||
VerifyOrExit(message != nullptr, error = kErrorNoBufs);
|
||||
|
||||
offset = message->GetLength();
|
||||
SuccessOrExit(error = message->SetLength(offset + aMessage.GetLength() - aMessage.GetOffset()));
|
||||
@@ -496,8 +485,6 @@ Error BorderAgent::ForwardToLeader(const Coap::Message & aMessage,
|
||||
Coap::Message * message = nullptr;
|
||||
uint16_t offset = 0;
|
||||
|
||||
VerifyOrExit((message = Get<Tmf::Agent>().NewPriorityMessage()) != nullptr, error = kErrorNoBufs);
|
||||
|
||||
if (aSeparate)
|
||||
{
|
||||
SuccessOrExit(error = Get<Coap::CoapSecure>().SendAck(aMessage, aMessageInfo));
|
||||
@@ -508,13 +495,8 @@ Error BorderAgent::ForwardToLeader(const Coap::Message & aMessage,
|
||||
|
||||
forwardContext->Init(GetInstance(), aMessage, aPetition, aSeparate);
|
||||
|
||||
SuccessOrExit(error = message->InitAsConfirmablePost(aPath));
|
||||
|
||||
// Payload of c/cg may be empty
|
||||
if (aMessage.GetLength() - aMessage.GetOffset() > 0)
|
||||
{
|
||||
SuccessOrExit(error = message->SetPayloadMarker());
|
||||
}
|
||||
message = Get<Tmf::Agent>().NewPriorityConfirmablePostMessage(aPath);
|
||||
VerifyOrExit(message != nullptr, error = kErrorNoBufs);
|
||||
|
||||
offset = message->GetLength();
|
||||
SuccessOrExit(error = message->SetLength(offset + aMessage.GetLength() - aMessage.GetOffset()));
|
||||
|
||||
@@ -715,14 +715,8 @@ Error Commissioner::SendMgmtCommissionerGetRequest(const uint8_t *aTlvs, uint8_t
|
||||
Tmf::MessageInfo messageInfo(GetInstance());
|
||||
Tlv tlv;
|
||||
|
||||
VerifyOrExit((message = Get<Tmf::Agent>().NewPriorityMessage()) != nullptr, error = kErrorNoBufs);
|
||||
|
||||
SuccessOrExit(error = message->InitAsConfirmablePost(UriPath::kCommissionerGet));
|
||||
|
||||
if (aLength > 0)
|
||||
{
|
||||
SuccessOrExit(error = message->SetPayloadMarker());
|
||||
}
|
||||
message = Get<Tmf::Agent>().NewPriorityConfirmablePostMessage(UriPath::kCommissionerGet);
|
||||
VerifyOrExit(message != nullptr, error = kErrorNoBufs);
|
||||
|
||||
if (aLength > 0)
|
||||
{
|
||||
@@ -771,10 +765,8 @@ Error Commissioner::SendMgmtCommissionerSetRequest(const Dataset &aDataset, cons
|
||||
Coap::Message * message;
|
||||
Tmf::MessageInfo messageInfo(GetInstance());
|
||||
|
||||
VerifyOrExit((message = Get<Tmf::Agent>().NewPriorityMessage()) != nullptr, error = kErrorNoBufs);
|
||||
|
||||
SuccessOrExit(error = message->InitAsConfirmablePost(UriPath::kCommissionerSet));
|
||||
SuccessOrExit(error = message->SetPayloadMarker());
|
||||
message = Get<Tmf::Agent>().NewPriorityConfirmablePostMessage(UriPath::kCommissionerSet);
|
||||
VerifyOrExit(message != nullptr, error = kErrorNoBufs);
|
||||
|
||||
if (aDataset.IsLocatorSet())
|
||||
{
|
||||
@@ -845,10 +837,8 @@ Error Commissioner::SendPetition(void)
|
||||
|
||||
mTransmitAttempts++;
|
||||
|
||||
VerifyOrExit((message = Get<Tmf::Agent>().NewPriorityMessage()) != nullptr, error = kErrorNoBufs);
|
||||
|
||||
SuccessOrExit(error = message->InitAsConfirmablePost(UriPath::kLeaderPetition));
|
||||
SuccessOrExit(error = message->SetPayloadMarker());
|
||||
message = Get<Tmf::Agent>().NewPriorityConfirmablePostMessage(UriPath::kLeaderPetition);
|
||||
VerifyOrExit(message != nullptr, error = kErrorNoBufs);
|
||||
|
||||
commissionerIdTlv.Init();
|
||||
commissionerIdTlv.SetCommissionerId(mCommissionerId);
|
||||
@@ -937,10 +927,8 @@ void Commissioner::SendKeepAlive(uint16_t aSessionId)
|
||||
Coap::Message * message = nullptr;
|
||||
Tmf::MessageInfo messageInfo(GetInstance());
|
||||
|
||||
VerifyOrExit((message = Get<Tmf::Agent>().NewPriorityMessage()) != nullptr, error = kErrorNoBufs);
|
||||
|
||||
SuccessOrExit(error = message->InitAsConfirmablePost(UriPath::kLeaderKeepAlive));
|
||||
SuccessOrExit(error = message->SetPayloadMarker());
|
||||
message = Get<Tmf::Agent>().NewPriorityConfirmablePostMessage(UriPath::kLeaderKeepAlive);
|
||||
VerifyOrExit(message != nullptr, error = kErrorNoBufs);
|
||||
|
||||
SuccessOrExit(
|
||||
error = Tlv::Append<StateTlv>(*message, (mState == kStateActive) ? StateTlv::kAccept : StateTlv::kReject));
|
||||
@@ -1121,10 +1109,9 @@ void Commissioner::SendJoinFinalizeResponse(const Coap::Message &aRequest, State
|
||||
Ip6::MessageInfo joinerMessageInfo;
|
||||
Coap::Message * message;
|
||||
|
||||
VerifyOrExit((message = Get<Coap::CoapSecure>().NewPriorityMessage()) != nullptr, error = kErrorNoBufs);
|
||||
message = Get<Coap::CoapSecure>().NewPriorityResponseMessage(aRequest);
|
||||
VerifyOrExit(message != nullptr, error = kErrorNoBufs);
|
||||
|
||||
SuccessOrExit(error = message->SetDefaultResponseHeader(aRequest));
|
||||
SuccessOrExit(error = message->SetPayloadMarker());
|
||||
message->SetOffset(message->GetLength());
|
||||
message->SetSubType(Message::kSubTypeJoinerFinalizeResponse);
|
||||
|
||||
@@ -1174,13 +1161,10 @@ Error Commissioner::SendRelayTransmit(Message &aMessage, const Ip6::MessageInfo
|
||||
Tmf::MessageInfo messageInfo(GetInstance());
|
||||
Kek kek;
|
||||
|
||||
VerifyOrExit((message = Get<Tmf::Agent>().NewPriorityMessage()) != nullptr, error = kErrorNoBufs);
|
||||
|
||||
Get<KeyManager>().ExtractKek(kek);
|
||||
|
||||
message->InitAsNonConfirmablePost();
|
||||
SuccessOrExit(error = message->AppendUriPathOptions(UriPath::kRelayTx));
|
||||
SuccessOrExit(error = message->SetPayloadMarker());
|
||||
message = Get<Tmf::Agent>().NewPriorityNonConfirmablePostMessage(UriPath::kRelayTx);
|
||||
VerifyOrExit(message != nullptr, error = kErrorNoBufs);
|
||||
|
||||
SuccessOrExit(error = Tlv::Append<JoinerUdpPortTlv>(*message, mJoinerPort));
|
||||
SuccessOrExit(error = Tlv::Append<JoinerIidTlv>(*message, mJoinerIid));
|
||||
|
||||
@@ -278,11 +278,9 @@ void DatasetManager::SendSet(void)
|
||||
}
|
||||
}
|
||||
|
||||
VerifyOrExit((message = Get<Tmf::Agent>().NewPriorityMessage()) != nullptr, error = kErrorNoBufs);
|
||||
|
||||
SuccessOrExit(error =
|
||||
message->InitAsConfirmablePost(IsActiveDataset() ? UriPath::kActiveSet : UriPath::kPendingSet));
|
||||
SuccessOrExit(error = message->SetPayloadMarker());
|
||||
message = Get<Tmf::Agent>().NewPriorityConfirmablePostMessage(IsActiveDataset() ? UriPath::kActiveSet
|
||||
: UriPath::kPendingSet);
|
||||
VerifyOrExit(message != nullptr, error = kErrorNoBufs);
|
||||
|
||||
IgnoreError(Read(dataset));
|
||||
SuccessOrExit(error = message->AppendBytes(dataset.GetBytes(), dataset.GetSize()));
|
||||
@@ -419,10 +417,8 @@ void DatasetManager::SendGetResponse(const Coap::Message & aRequest,
|
||||
|
||||
IgnoreError(Read(dataset));
|
||||
|
||||
VerifyOrExit((message = Get<Tmf::Agent>().NewPriorityMessage()) != nullptr, error = kErrorNoBufs);
|
||||
|
||||
SuccessOrExit(error = message->SetDefaultResponseHeader(aRequest));
|
||||
SuccessOrExit(error = message->SetPayloadMarker());
|
||||
message = Get<Tmf::Agent>().NewPriorityResponseMessage(aRequest);
|
||||
VerifyOrExit(message != nullptr, error = kErrorNoBufs);
|
||||
|
||||
if (aLength == 0)
|
||||
{
|
||||
@@ -485,11 +481,9 @@ Error DatasetManager::SendSetRequest(const Dataset::Info & aDatasetInfo,
|
||||
|
||||
VerifyOrExit(!mMgmtPending, error = kErrorBusy);
|
||||
|
||||
VerifyOrExit((message = Get<Tmf::Agent>().NewPriorityMessage()) != nullptr, error = kErrorNoBufs);
|
||||
|
||||
SuccessOrExit(error =
|
||||
message->InitAsConfirmablePost(IsActiveDataset() ? UriPath::kActiveSet : UriPath::kPendingSet));
|
||||
SuccessOrExit(error = message->SetPayloadMarker());
|
||||
message = Get<Tmf::Agent>().NewPriorityConfirmablePostMessage(IsActiveDataset() ? UriPath::kActiveSet
|
||||
: UriPath::kPendingSet);
|
||||
VerifyOrExit(message != nullptr, error = kErrorNoBufs);
|
||||
|
||||
#if OPENTHREAD_CONFIG_COMMISSIONER_ENABLE && OPENTHREAD_FTD
|
||||
|
||||
@@ -612,15 +606,9 @@ Error DatasetManager::SendGetRequest(const Dataset::Components &aDatasetComponen
|
||||
datasetTlvs[length++] = Tlv::kChannelMask;
|
||||
}
|
||||
|
||||
VerifyOrExit((message = Get<Tmf::Agent>().NewPriorityMessage()) != nullptr, error = kErrorNoBufs);
|
||||
|
||||
SuccessOrExit(error =
|
||||
message->InitAsConfirmablePost(IsActiveDataset() ? UriPath::kActiveGet : UriPath::kPendingGet));
|
||||
|
||||
if (aLength + length > 0)
|
||||
{
|
||||
SuccessOrExit(error = message->SetPayloadMarker());
|
||||
}
|
||||
message = Get<Tmf::Agent>().NewPriorityConfirmablePostMessage(IsActiveDataset() ? UriPath::kActiveGet
|
||||
: UriPath::kPendingGet);
|
||||
VerifyOrExit(message != nullptr, error = kErrorNoBufs);
|
||||
|
||||
if (aLength + length > 0)
|
||||
{
|
||||
|
||||
@@ -270,10 +270,8 @@ void DatasetManager::SendSetResponse(const Coap::Message & aRequest,
|
||||
Error error = kErrorNone;
|
||||
Coap::Message *message;
|
||||
|
||||
VerifyOrExit((message = Get<Tmf::Agent>().NewPriorityMessage()) != nullptr, error = kErrorNoBufs);
|
||||
|
||||
SuccessOrExit(error = message->SetDefaultResponseHeader(aRequest));
|
||||
SuccessOrExit(error = message->SetPayloadMarker());
|
||||
message = Get<Tmf::Agent>().NewPriorityResponseMessage(aRequest);
|
||||
VerifyOrExit(message != nullptr, error = kErrorNoBufs);
|
||||
|
||||
SuccessOrExit(error = Tlv::Append<StateTlv>(*message, aState));
|
||||
|
||||
|
||||
@@ -442,11 +442,9 @@ Error Joiner::PrepareJoinerFinalizeMessage(const char *aProvisioningUrl,
|
||||
VendorStackVersionTlv vendorStackVersionTlv;
|
||||
ProvisioningUrlTlv provisioningUrlTlv;
|
||||
|
||||
VerifyOrExit((mFinalizeMessage = Get<Coap::CoapSecure>().NewPriorityMessage()) != nullptr, error = kErrorNoBufs);
|
||||
mFinalizeMessage = Get<Coap::CoapSecure>().NewPriorityConfirmablePostMessage(UriPath::kJoinerFinalize);
|
||||
VerifyOrExit(mFinalizeMessage != nullptr, error = kErrorNoBufs);
|
||||
|
||||
mFinalizeMessage->InitAsConfirmablePost();
|
||||
SuccessOrExit(error = mFinalizeMessage->AppendUriPathOptions(UriPath::kJoinerFinalize));
|
||||
SuccessOrExit(error = mFinalizeMessage->SetPayloadMarker());
|
||||
mFinalizeMessage->SetOffset(mFinalizeMessage->GetLength());
|
||||
|
||||
SuccessOrExit(error = Tlv::Append<StateTlv>(*mFinalizeMessage, StateTlv::kAccept));
|
||||
@@ -600,8 +598,9 @@ void Joiner::SendJoinerEntrustResponse(const Coap::Message &aRequest, const Ip6:
|
||||
Coap::Message * message;
|
||||
Ip6::MessageInfo responseInfo(aRequestInfo);
|
||||
|
||||
VerifyOrExit((message = Get<Tmf::Agent>().NewPriorityMessage()) != nullptr, error = kErrorNoBufs);
|
||||
SuccessOrExit(error = message->SetDefaultResponseHeader(aRequest));
|
||||
message = Get<Tmf::Agent>().NewPriorityResponseMessage(aRequest);
|
||||
VerifyOrExit(message != nullptr, error = kErrorNoBufs);
|
||||
|
||||
message->SetSubType(Message::kSubTypeJoinerEntrust);
|
||||
|
||||
responseInfo.GetSockAddr().Clear();
|
||||
|
||||
@@ -142,10 +142,8 @@ void JoinerRouter::HandleUdpReceive(Message &aMessage, const Ip6::MessageInfo &a
|
||||
|
||||
SuccessOrExit(error = GetBorderAgentRloc(Get<ThreadNetif>(), borderAgentRloc));
|
||||
|
||||
VerifyOrExit((message = Get<Tmf::Agent>().NewPriorityMessage()) != nullptr, error = kErrorNoBufs);
|
||||
|
||||
SuccessOrExit(error = message->InitAsNonConfirmablePost(UriPath::kRelayRx));
|
||||
SuccessOrExit(error = message->SetPayloadMarker());
|
||||
message = Get<Tmf::Agent>().NewPriorityNonConfirmablePostMessage(UriPath::kRelayRx);
|
||||
VerifyOrExit(message != nullptr, error = kErrorNoBufs);
|
||||
|
||||
SuccessOrExit(error = Tlv::Append<JoinerUdpPortTlv>(*message, aMessageInfo.GetPeerPort()));
|
||||
SuccessOrExit(error = Tlv::Append<JoinerIidTlv>(*message, aMessageInfo.GetPeerAddr().GetIid()));
|
||||
@@ -315,11 +313,9 @@ Coap::Message *JoinerRouter::PrepareJoinerEntrustMessage(void)
|
||||
const Tlv * tlv;
|
||||
NetworkKey networkKey;
|
||||
|
||||
VerifyOrExit((message = Get<Tmf::Agent>().NewPriorityMessage()) != nullptr, error = kErrorNoBufs);
|
||||
message = Get<Tmf::Agent>().NewPriorityConfirmablePostMessage(UriPath::kJoinerEntrust);
|
||||
VerifyOrExit(message != nullptr, error = kErrorNoBufs);
|
||||
|
||||
message->InitAsConfirmablePost();
|
||||
SuccessOrExit(error = message->AppendUriPathOptions(UriPath::kJoinerEntrust));
|
||||
SuccessOrExit(error = message->SetPayloadMarker());
|
||||
message->SetSubType(Message::kSubTypeJoinerEntrust);
|
||||
|
||||
Get<KeyManager>().GetNetworkKey(networkKey);
|
||||
|
||||
@@ -128,10 +128,8 @@ void Leader::SendPetitionResponse(const Coap::Message & aRequest,
|
||||
Error error = kErrorNone;
|
||||
Coap::Message *message;
|
||||
|
||||
VerifyOrExit((message = Get<Tmf::Agent>().NewPriorityMessage()) != nullptr, error = kErrorNoBufs);
|
||||
|
||||
SuccessOrExit(error = message->SetDefaultResponseHeader(aRequest));
|
||||
SuccessOrExit(error = message->SetPayloadMarker());
|
||||
message = Get<Tmf::Agent>().NewPriorityResponseMessage(aRequest);
|
||||
VerifyOrExit(message != nullptr, error = kErrorNoBufs);
|
||||
|
||||
SuccessOrExit(error = Tlv::Append<StateTlv>(*message, aState));
|
||||
|
||||
@@ -211,10 +209,8 @@ void Leader::SendKeepAliveResponse(const Coap::Message & aRequest,
|
||||
Error error = kErrorNone;
|
||||
Coap::Message *message;
|
||||
|
||||
VerifyOrExit((message = Get<Tmf::Agent>().NewPriorityMessage()) != nullptr, error = kErrorNoBufs);
|
||||
|
||||
SuccessOrExit(error = message->SetDefaultResponseHeader(aRequest));
|
||||
SuccessOrExit(error = message->SetPayloadMarker());
|
||||
message = Get<Tmf::Agent>().NewPriorityResponseMessage(aRequest);
|
||||
VerifyOrExit(message != nullptr, error = kErrorNoBufs);
|
||||
|
||||
SuccessOrExit(error = Tlv::Append<StateTlv>(*message, aState));
|
||||
|
||||
@@ -233,9 +229,8 @@ void Leader::SendDatasetChanged(const Ip6::Address &aAddress)
|
||||
Tmf::MessageInfo messageInfo(GetInstance());
|
||||
Coap::Message * message;
|
||||
|
||||
VerifyOrExit((message = Get<Tmf::Agent>().NewPriorityMessage()) != nullptr, error = kErrorNoBufs);
|
||||
|
||||
SuccessOrExit(error = message->InitAsConfirmablePost(UriPath::kDatasetChanged));
|
||||
message = Get<Tmf::Agent>().NewPriorityConfirmablePostMessage(UriPath::kDatasetChanged);
|
||||
VerifyOrExit(message != nullptr, error = kErrorNoBufs);
|
||||
|
||||
messageInfo.SetSockAddrToRlocPeerAddrTo(aAddress);
|
||||
SuccessOrExit(error = Get<Tmf::Agent>().SendMessage(*message, messageInfo));
|
||||
|
||||
@@ -560,11 +560,8 @@ Error AddressResolver::SendAddressQuery(const Ip6::Address &aEid)
|
||||
Coap::Message * message;
|
||||
Tmf::MessageInfo messageInfo(GetInstance());
|
||||
|
||||
VerifyOrExit((message = Get<Tmf::Agent>().NewPriorityMessage()) != nullptr, error = kErrorNoBufs);
|
||||
|
||||
message->InitAsNonConfirmablePost();
|
||||
SuccessOrExit(error = message->AppendUriPathOptions(UriPath::kAddressQuery));
|
||||
SuccessOrExit(error = message->SetPayloadMarker());
|
||||
message = Get<Tmf::Agent>().NewPriorityNonConfirmablePostMessage(UriPath::kAddressQuery);
|
||||
VerifyOrExit(message != nullptr, error = kErrorNoBufs);
|
||||
|
||||
SuccessOrExit(error = Tlv::Append<ThreadTargetTlv>(*message, aEid));
|
||||
|
||||
@@ -848,11 +845,8 @@ void AddressResolver::SendAddressQueryResponse(const Ip6::Address & a
|
||||
Coap::Message * message;
|
||||
Tmf::MessageInfo messageInfo(GetInstance());
|
||||
|
||||
VerifyOrExit((message = Get<Tmf::Agent>().NewPriorityMessage()) != nullptr, error = kErrorNoBufs);
|
||||
|
||||
message->InitAsConfirmablePost();
|
||||
SuccessOrExit(error = message->AppendUriPathOptions(UriPath::kAddressNotify));
|
||||
SuccessOrExit(error = message->SetPayloadMarker());
|
||||
message = Get<Tmf::Agent>().NewPriorityConfirmablePostMessage(UriPath::kAddressNotify);
|
||||
VerifyOrExit(message != nullptr, error = kErrorNoBufs);
|
||||
|
||||
SuccessOrExit(error = Tlv::Append<ThreadTargetTlv>(*message, aTarget));
|
||||
SuccessOrExit(error = Tlv::Append<ThreadMeshLocalEidTlv>(*message, aMeshLocalIid));
|
||||
|
||||
@@ -67,12 +67,9 @@ Error AnycastLocator::Locate(const Ip6::Address &aAnycastAddress, Callback aCall
|
||||
VerifyOrExit((aCallback != nullptr) && Get<Mle::Mle>().IsAnycastLocator(aAnycastAddress),
|
||||
error = kErrorInvalidArgs);
|
||||
|
||||
message = Get<Tmf::Agent>().NewMessage();
|
||||
message = Get<Tmf::Agent>().NewConfirmablePostMessage(UriPath::kAnycastLocate);
|
||||
VerifyOrExit(message != nullptr, error = kErrorNoBufs);
|
||||
|
||||
SuccessOrExit(error = message->InitAsConfirmablePost(UriPath::kAnycastLocate));
|
||||
SuccessOrExit(error = message->SetPayloadMarker());
|
||||
|
||||
if (mCallback != nullptr)
|
||||
{
|
||||
IgnoreError(Get<Tmf::Agent>().AbortTransaction(HandleResponse, this));
|
||||
@@ -143,12 +140,9 @@ void AnycastLocator::HandleAnycastLocate(const Coap::Message &aRequest, const Ip
|
||||
|
||||
VerifyOrExit(aRequest.IsConfirmablePostRequest());
|
||||
|
||||
message = Get<Tmf::Agent>().NewMessage();
|
||||
message = Get<Tmf::Agent>().NewResponseMessage(aRequest);
|
||||
VerifyOrExit(message != nullptr);
|
||||
|
||||
SuccessOrExit(message->SetDefaultResponseHeader(aRequest));
|
||||
SuccessOrExit(message->SetPayloadMarker());
|
||||
|
||||
SuccessOrExit(Tlv::Append<ThreadMeshLocalEidTlv>(*message, Get<Mle::Mle>().GetMeshLocal64().GetIid()));
|
||||
SuccessOrExit(Tlv::Append<ThreadRloc16Tlv>(*message, Get<Mle::Mle>().GetRloc16()));
|
||||
|
||||
|
||||
@@ -455,10 +455,8 @@ void DuaManager::PerformNextRegistration(void)
|
||||
}
|
||||
|
||||
// Prepare DUA.req
|
||||
VerifyOrExit((message = Get<Tmf::Agent>().NewPriorityMessage()) != nullptr, error = kErrorNoBufs);
|
||||
|
||||
SuccessOrExit(error = message->InitAsConfirmablePost(UriPath::kDuaRegistrationRequest));
|
||||
SuccessOrExit(error = message->SetPayloadMarker());
|
||||
message = Get<Tmf::Agent>().NewPriorityConfirmablePostMessage(UriPath::kDuaRegistrationRequest);
|
||||
VerifyOrExit(message != nullptr, error = kErrorNoBufs);
|
||||
|
||||
#if OPENTHREAD_CONFIG_DUA_ENABLE
|
||||
if (mDuaState == kToRegister && mDelay.mFields.mRegistrationDelay == 0)
|
||||
@@ -728,10 +726,8 @@ void DuaManager::SendAddressNotification(Ip6::Address & aAddress,
|
||||
Tmf::MessageInfo messageInfo(GetInstance());
|
||||
Error error;
|
||||
|
||||
VerifyOrExit((message = Get<Tmf::Agent>().NewPriorityMessage()) != nullptr, error = kErrorNoBufs);
|
||||
|
||||
SuccessOrExit(error = message->InitAsConfirmablePost(UriPath::kDuaRegistrationNotify));
|
||||
SuccessOrExit(error = message->SetPayloadMarker());
|
||||
message = Get<Tmf::Agent>().NewPriorityConfirmablePostMessage(UriPath::kDuaRegistrationNotify);
|
||||
VerifyOrExit(message != nullptr, error = kErrorNoBufs);
|
||||
|
||||
SuccessOrExit(error = Tlv::Append<ThreadStatusTlv>(*message, aStatus));
|
||||
SuccessOrExit(error = Tlv::Append<ThreadTargetTlv>(*message, aAddress));
|
||||
|
||||
@@ -177,10 +177,8 @@ void EnergyScanServer::SendReport(void)
|
||||
Tmf::MessageInfo messageInfo(GetInstance());
|
||||
Coap::Message * message;
|
||||
|
||||
VerifyOrExit((message = Get<Tmf::Agent>().NewPriorityMessage()) != nullptr, error = kErrorNoBufs);
|
||||
|
||||
SuccessOrExit(error = message->InitAsConfirmablePost(UriPath::kEnergyReport));
|
||||
SuccessOrExit(error = message->SetPayloadMarker());
|
||||
message = Get<Tmf::Agent>().NewPriorityConfirmablePostMessage(UriPath::kEnergyReport);
|
||||
VerifyOrExit(message != nullptr, error = kErrorNoBufs);
|
||||
|
||||
channelMask.Init();
|
||||
channelMask.SetChannelMask(mChannelMask);
|
||||
|
||||
@@ -3609,10 +3609,8 @@ Error MleRouter::SendAddressSolicit(ThreadStatusTlv::Status aStatus)
|
||||
|
||||
VerifyOrExit(!mAddressSolicitPending);
|
||||
|
||||
VerifyOrExit((message = Get<Tmf::Agent>().NewPriorityMessage()) != nullptr, error = kErrorNoBufs);
|
||||
|
||||
SuccessOrExit(error = message->InitAsConfirmablePost(UriPath::kAddressSolicit));
|
||||
SuccessOrExit(error = message->SetPayloadMarker());
|
||||
message = Get<Tmf::Agent>().NewPriorityConfirmablePostMessage(UriPath::kAddressSolicit);
|
||||
VerifyOrExit(message != nullptr, error = kErrorNoBufs);
|
||||
|
||||
SuccessOrExit(error = Tlv::Append<ThreadExtMacAddressTlv>(*message, Get<Mac::Mac>().GetExtAddress()));
|
||||
|
||||
@@ -3645,10 +3643,8 @@ void MleRouter::SendAddressRelease(void)
|
||||
Tmf::MessageInfo messageInfo(GetInstance());
|
||||
Coap::Message * message;
|
||||
|
||||
VerifyOrExit((message = Get<Tmf::Agent>().NewPriorityMessage()) != nullptr, error = kErrorNoBufs);
|
||||
|
||||
SuccessOrExit(error = message->InitAsConfirmablePost(UriPath::kAddressRelease));
|
||||
SuccessOrExit(error = message->SetPayloadMarker());
|
||||
message = Get<Tmf::Agent>().NewPriorityConfirmablePostMessage(UriPath::kAddressRelease);
|
||||
VerifyOrExit(message != nullptr, error = kErrorNoBufs);
|
||||
|
||||
SuccessOrExit(error = Tlv::Append<ThreadRloc16Tlv>(*message, Rloc16FromRouterId(mRouterId)));
|
||||
SuccessOrExit(error = Tlv::Append<ThreadExtMacAddressTlv>(*message, Get<Mac::Mac>().GetExtAddress()));
|
||||
@@ -3877,13 +3873,10 @@ void MleRouter::SendAddressSolicitResponse(const Coap::Message & aRequest,
|
||||
const Router * aRouter,
|
||||
const Ip6::MessageInfo &aMessageInfo)
|
||||
{
|
||||
Coap::Message *message = Get<Tmf::Agent>().NewPriorityMessage();
|
||||
Coap::Message *message = Get<Tmf::Agent>().NewPriorityResponseMessage(aRequest);
|
||||
|
||||
VerifyOrExit(message != nullptr);
|
||||
|
||||
SuccessOrExit(message->SetDefaultResponseHeader(aRequest));
|
||||
SuccessOrExit(message->SetPayloadMarker());
|
||||
|
||||
SuccessOrExit(Tlv::Append<ThreadStatusTlv>(*message, aResponseStatus));
|
||||
|
||||
if (aRouter != nullptr)
|
||||
|
||||
@@ -404,12 +404,8 @@ Error MlrManager::SendMulticastListenerRegistrationMessage(const otIp6Address *
|
||||
|
||||
VerifyOrExit(Get<BackboneRouter::Leader>().HasPrimary(), error = kErrorInvalidState);
|
||||
|
||||
VerifyOrExit((message = Get<Tmf::Agent>().NewMessage()) != nullptr, error = kErrorNoBufs);
|
||||
|
||||
message->InitAsConfirmablePost();
|
||||
SuccessOrExit(message->GenerateRandomToken(Coap::Message::kDefaultTokenLength));
|
||||
SuccessOrExit(message->AppendUriPathOptions(UriPath::kMlr));
|
||||
SuccessOrExit(message->SetPayloadMarker());
|
||||
message = Get<Tmf::Agent>().NewConfirmablePostMessage(UriPath::kMlr);
|
||||
VerifyOrExit(message != nullptr, error = kErrorNoBufs);
|
||||
|
||||
addressesTlv.Init();
|
||||
addressesTlv.SetLength(sizeof(Ip6::Address) * aAddressNum);
|
||||
|
||||
@@ -640,14 +640,12 @@ Error NetworkData::SendServerDataNotification(uint16_t aRloc16,
|
||||
Coap::ResponseHandler aHandler,
|
||||
void * aContext) const
|
||||
{
|
||||
Error error = kErrorNone;
|
||||
Coap::Message * message = nullptr;
|
||||
Error error = kErrorNone;
|
||||
Coap::Message * message;
|
||||
Tmf::MessageInfo messageInfo(GetInstance());
|
||||
|
||||
VerifyOrExit((message = Get<Tmf::Agent>().NewPriorityMessage()) != nullptr, error = kErrorNoBufs);
|
||||
|
||||
SuccessOrExit(error = message->InitAsConfirmablePost(UriPath::kServerData));
|
||||
SuccessOrExit(error = message->SetPayloadMarker());
|
||||
message = Get<Tmf::Agent>().NewPriorityConfirmablePostMessage(UriPath::kServerData);
|
||||
VerifyOrExit(message != nullptr, error = kErrorNoBufs);
|
||||
|
||||
if (aAppendNetDataTlv)
|
||||
{
|
||||
|
||||
@@ -307,10 +307,8 @@ void Leader::SendCommissioningGetResponse(const Coap::Message & aRequest,
|
||||
uint8_t * data = nullptr;
|
||||
uint8_t length = 0;
|
||||
|
||||
VerifyOrExit((message = Get<Tmf::Agent>().NewPriorityMessage()) != nullptr, error = kErrorNoBufs);
|
||||
|
||||
SuccessOrExit(error = message->SetDefaultResponseHeader(aRequest));
|
||||
SuccessOrExit(error = message->SetPayloadMarker());
|
||||
message = Get<Tmf::Agent>().NewPriorityResponseMessage(aRequest);
|
||||
VerifyOrExit(message != nullptr, error = kErrorNoBufs);
|
||||
|
||||
commDataTlv = GetCommissioningData();
|
||||
|
||||
@@ -361,10 +359,8 @@ void Leader::SendCommissioningSetResponse(const Coap::Message & aRequest,
|
||||
Error error = kErrorNone;
|
||||
Coap::Message *message;
|
||||
|
||||
VerifyOrExit((message = Get<Tmf::Agent>().NewPriorityMessage()) != nullptr, error = kErrorNoBufs);
|
||||
|
||||
SuccessOrExit(error = message->SetDefaultResponseHeader(aRequest));
|
||||
SuccessOrExit(error = message->SetPayloadMarker());
|
||||
message = Get<Tmf::Agent>().NewPriorityResponseMessage(aRequest);
|
||||
VerifyOrExit(message != nullptr, error = kErrorNoBufs);
|
||||
|
||||
SuccessOrExit(error = Tlv::Append<MeshCoP::StateTlv>(*message, aState));
|
||||
|
||||
|
||||
@@ -84,23 +84,18 @@ Error NetworkDiagnostic::SendDiagnosticGet(const Ip6::Address & aDesti
|
||||
Tmf::MessageInfo messageInfo(GetInstance());
|
||||
otCoapResponseHandler handler = nullptr;
|
||||
|
||||
VerifyOrExit((message = Get<Tmf::Agent>().NewMessage()) != nullptr, error = kErrorNoBufs);
|
||||
|
||||
if (aDestination.IsMulticast())
|
||||
{
|
||||
SuccessOrExit(error = message->InitAsNonConfirmablePost(UriPath::kDiagnosticGetQuery));
|
||||
message = Get<Tmf::Agent>().NewNonConfirmablePostMessage(UriPath::kDiagnosticGetQuery);
|
||||
messageInfo.SetMulticastLoop(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
handler = &NetworkDiagnostic::HandleDiagnosticGetResponse;
|
||||
SuccessOrExit(error = message->InitAsConfirmablePost(UriPath::kDiagnosticGetRequest));
|
||||
message = Get<Tmf::Agent>().NewConfirmablePostMessage(UriPath::kDiagnosticGetRequest);
|
||||
}
|
||||
|
||||
if (aCount > 0)
|
||||
{
|
||||
SuccessOrExit(error = message->SetPayloadMarker());
|
||||
}
|
||||
VerifyOrExit(message != nullptr, error = kErrorNoBufs);
|
||||
|
||||
if (aCount > 0)
|
||||
{
|
||||
@@ -485,14 +480,8 @@ void NetworkDiagnostic::HandleDiagnosticGetQuery(Coap::Message &aMessage, const
|
||||
}
|
||||
}
|
||||
|
||||
VerifyOrExit((message = Get<Tmf::Agent>().NewMessage()) != nullptr, error = kErrorNoBufs);
|
||||
|
||||
SuccessOrExit(error = message->InitAsConfirmablePost(UriPath::kDiagnosticGetAnswer));
|
||||
|
||||
if (networkDiagnosticTlv.GetLength() > 0)
|
||||
{
|
||||
SuccessOrExit(error = message->SetPayloadMarker());
|
||||
}
|
||||
message = Get<Tmf::Agent>().NewConfirmablePostMessage(UriPath::kDiagnosticGetAnswer);
|
||||
VerifyOrExit(message != nullptr, error = kErrorNoBufs);
|
||||
|
||||
if (aMessageInfo.GetPeerAddr().IsLinkLocal())
|
||||
{
|
||||
@@ -538,10 +527,8 @@ void NetworkDiagnostic::HandleDiagnosticGetRequest(Coap::Message &aMessage, cons
|
||||
|
||||
VerifyOrExit(networkDiagnosticTlv.GetType() == NetworkDiagnosticTlv::kTypeList, error = kErrorParse);
|
||||
|
||||
VerifyOrExit((message = Get<Tmf::Agent>().NewMessage()) != nullptr, error = kErrorNoBufs);
|
||||
|
||||
SuccessOrExit(error = message->SetDefaultResponseHeader(aMessage));
|
||||
SuccessOrExit(error = message->SetPayloadMarker());
|
||||
message = Get<Tmf::Agent>().NewResponseMessage(aMessage);
|
||||
VerifyOrExit(message != nullptr, error = kErrorNoBufs);
|
||||
|
||||
SuccessOrExit(error = FillRequestedTlvs(aMessage, *message, networkDiagnosticTlv));
|
||||
|
||||
@@ -561,14 +548,8 @@ Error NetworkDiagnostic::SendDiagnosticReset(const Ip6::Address &aDestination,
|
||||
Coap::Message * message = nullptr;
|
||||
Tmf::MessageInfo messageInfo(GetInstance());
|
||||
|
||||
VerifyOrExit((message = Get<Tmf::Agent>().NewMessage()) != nullptr, error = kErrorNoBufs);
|
||||
|
||||
SuccessOrExit(error = message->InitAsConfirmablePost(UriPath::kDiagnosticReset));
|
||||
|
||||
if (aCount > 0)
|
||||
{
|
||||
SuccessOrExit(error = message->SetPayloadMarker());
|
||||
}
|
||||
message = Get<Tmf::Agent>().NewConfirmablePostMessage(UriPath::kDiagnosticReset);
|
||||
VerifyOrExit(message != nullptr, error = kErrorNoBufs);
|
||||
|
||||
if (aCount > 0)
|
||||
{
|
||||
|
||||
@@ -117,10 +117,8 @@ void PanIdQueryServer::SendConflict(void)
|
||||
Tmf::MessageInfo messageInfo(GetInstance());
|
||||
Coap::Message * message;
|
||||
|
||||
VerifyOrExit((message = Get<Tmf::Agent>().NewPriorityMessage()) != nullptr, error = kErrorNoBufs);
|
||||
|
||||
SuccessOrExit(error = message->InitAsConfirmablePost(UriPath::kPanIdConflict));
|
||||
SuccessOrExit(error = message->SetPayloadMarker());
|
||||
message = Get<Tmf::Agent>().NewPriorityConfirmablePostMessage(UriPath::kPanIdConflict);
|
||||
VerifyOrExit(message != nullptr, error = kErrorNoBufs);
|
||||
|
||||
channelMask.Init();
|
||||
channelMask.SetChannelMask(mChannelMask);
|
||||
|
||||
@@ -85,7 +85,7 @@ Error Agent::Start(void)
|
||||
return Coap::Start(kUdpPort, OT_NETIF_THREAD);
|
||||
}
|
||||
|
||||
Error Agent::Filter(const ot::Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo, void *aContext)
|
||||
Error Agent::Filter(const Message &aMessage, const Ip6::MessageInfo &aMessageInfo, void *aContext)
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aMessage);
|
||||
|
||||
|
||||
@@ -44,6 +44,8 @@ namespace Tmf {
|
||||
|
||||
constexpr uint16_t kUdpPort = 61631; ///< TMF UDP Port
|
||||
|
||||
typedef Coap::Message Message; ///< A TMF message.
|
||||
|
||||
/**
|
||||
* This class represents message information for a TMF message.
|
||||
*
|
||||
@@ -160,7 +162,7 @@ public:
|
||||
bool IsTmfMessage(const Ip6::MessageInfo &aMessageInfo) const;
|
||||
|
||||
private:
|
||||
static Error Filter(const ot::Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo, void *aContext);
|
||||
static Error Filter(const Message &aMessage, const Ip6::MessageInfo &aMessageInfo, void *aContext);
|
||||
};
|
||||
|
||||
} // namespace Tmf
|
||||
|
||||
Reference in New Issue
Block a user