[coap] simplify response handler and use Msg class (#12338)

This commit updates `Coap::ResponseHandler` to use a single
`Coap::Msg` pointer instead of separate `Message` and `MessageInfo`
pointers. The `Msg` class encapsulates both the CoAP message and its
associated IP message info, simplifying the handler signature and
usage.

It retains support for the legacy `otCoapResponseHandler` signature
(which uses separate parameters) for the public API by introducing
`SendMessageWithResponseHandlerSeparateParams`. This ensures that
public APIs like `otCoapSendRequest` continue to work without
breaking changes while allowing internal modules to benefit from the
simplified interface.

It introduces `CoapBase::SendCallbacks` to consolidate the storage and
invocation logic for different callback types, including the new
`ResponseHandler`, the legacy `ResponseHandlerSeparateParams`, and
block-wise transfer hooks.

All internal modules (MLE, MeshCoP, Network Data, etc.) are updated to
define their response handlers using the new `ResponseHandler`
signature with `Msg` input.
This commit is contained in:
Abtin Keshavarzian
2026-01-29 07:55:26 -08:00
committed by GitHub
parent 2a76e91081
commit 397f5b4291
27 changed files with 425 additions and 401 deletions
+9 -9
View File
@@ -72,7 +72,7 @@ void Mle::HandlePartitionChange(void)
mPreviousPartitionIdTimeout = GetNetworkIdTimeout();
Get<AddressResolver>().Clear();
IgnoreError(Get<Tmf::Agent>().AbortTransaction(&Mle::HandleAddressSolicitResponse, this));
IgnoreError(Get<Tmf::Agent>().AbortTransaction(HandleAddressSolicitResponse, this));
mRouterTable.Clear();
}
@@ -3288,7 +3288,7 @@ Error Mle::SendAddressSolicit(RouterUpgradeReason aReason)
messageInfo.SetSockAddrToRlocPeerAddrToLeaderRloc();
SuccessOrExit(error = Get<Tmf::Agent>().SendMessage(*message, messageInfo, &HandleAddressSolicitResponse, this));
SuccessOrExit(error = Get<Tmf::Agent>().SendMessage(*message, messageInfo, HandleAddressSolicitResponse, this));
mAddressSolicitPending = true;
Log(kMessageSend, kTypeAddressSolicit, messageInfo.GetPeerAddr());
@@ -3321,7 +3321,7 @@ exit:
LogSendError(kTypeAddressRelease, error);
}
void Mle::HandleAddressSolicitResponse(Coap::Message *aMessage, const Ip6::MessageInfo *aMessageInfo, Error aResult)
void Mle::HandleAddressSolicitResponse(Coap::Msg *aMsg, Error aResult)
{
uint8_t status;
uint16_t rloc16;
@@ -3331,13 +3331,13 @@ void Mle::HandleAddressSolicitResponse(Coap::Message *aMessage, const Ip6::Messa
mAddressSolicitPending = false;
VerifyOrExit(aResult == kErrorNone && aMessage != nullptr && aMessageInfo != nullptr);
VerifyOrExit(aResult == kErrorNone && aMsg != nullptr);
VerifyOrExit(aMessage->ReadCode() == Coap::kCodeChanged);
VerifyOrExit(aMsg->GetCode() == Coap::kCodeChanged);
Log(kMessageReceive, kTypeAddressReply, aMessageInfo->GetPeerAddr());
Log(kMessageReceive, kTypeAddressReply, aMsg->mMessageInfo.GetPeerAddr());
SuccessOrExit(Tlv::Find<ThreadStatusTlv>(*aMessage, status));
SuccessOrExit(Tlv::Find<ThreadStatusTlv>(aMsg->mMessage, status));
if (status != kAddrSolicitSuccess)
{
@@ -3356,10 +3356,10 @@ void Mle::HandleAddressSolicitResponse(Coap::Message *aMessage, const Ip6::Messa
ExitNow();
}
SuccessOrExit(Tlv::Find<ThreadRloc16Tlv>(*aMessage, rloc16));
SuccessOrExit(Tlv::Find<ThreadRloc16Tlv>(aMsg->mMessage, rloc16));
routerId = RouterIdFromRloc16(rloc16);
SuccessOrExit(Tlv::FindTlv(*aMessage, routerMaskTlv));
SuccessOrExit(Tlv::FindTlv(aMsg->mMessage, routerMaskTlv));
VerifyOrExit(routerMaskTlv.IsValid());
SetAlternateRloc16(GetRloc16());