mirror of
https://github.com/espressif/openthread.git
synced 2026-08-29 13:29:54 +00:00
[mle] simplify ThreadStatusTlv handling (#11782)
The Status TLV is used in several TMF messages (Address Solicit, DUA Registration, MLR), and the meaning of its value is context-dependent. This commit refactors the TLV definitions by moving the status enums from the generic `ThreadStatusTlv` class into the modules where they are used. The main changes are: - The Address Solicit status is split into two more specific enums: - `RouterUpgradeReason` for Address Solicit requests. - `AddrSolicitResponse` for Address Solicit responses. - `MlrStatus` and `DuaStatus` enums are moved to `mlr` and `dua` modules respectively. - `ThreadStatusTlv` is simplified to a `typedef`. This change improves code clarity, modularity, and type safety by ensuring that status codes are defined and used within their proper context.
This commit is contained in:
@@ -612,7 +612,7 @@ Error DuaManager::ProcessDuaResponse(Coap::Message &aMessage)
|
||||
|
||||
if (aMessage.GetCode() >= Coap::kCodeBadRequest)
|
||||
{
|
||||
status = ThreadStatusTlv::kDuaGeneralFailure;
|
||||
status = kDuaGeneralFailure;
|
||||
target = mRegisteringDua;
|
||||
}
|
||||
else
|
||||
@@ -626,29 +626,29 @@ Error DuaManager::ProcessDuaResponse(Coap::Message &aMessage)
|
||||
#if OPENTHREAD_CONFIG_DUA_ENABLE
|
||||
if (Get<ThreadNetif>().HasUnicastAddress(target))
|
||||
{
|
||||
switch (static_cast<ThreadStatusTlv::DuaStatus>(status))
|
||||
switch (static_cast<DuaStatus>(status))
|
||||
{
|
||||
case ThreadStatusTlv::kDuaSuccess:
|
||||
case kDuaSuccess:
|
||||
mLastRegistrationTime = TimerMilli::GetNow();
|
||||
mDuaState = kRegistered;
|
||||
break;
|
||||
case ThreadStatusTlv::kDuaReRegister:
|
||||
case kDuaReRegister:
|
||||
if (Get<ThreadNetif>().HasUnicastAddress(GetDomainUnicastAddress()))
|
||||
{
|
||||
RemoveDomainUnicastAddress();
|
||||
AddDomainUnicastAddress();
|
||||
}
|
||||
break;
|
||||
case ThreadStatusTlv::kDuaInvalid:
|
||||
case kDuaInvalid:
|
||||
// Domain Prefix might be invalid.
|
||||
RemoveDomainUnicastAddress();
|
||||
break;
|
||||
case ThreadStatusTlv::kDuaDuplicate:
|
||||
case kDuaDuplicate:
|
||||
NotifyDuplicateDomainUnicastAddress();
|
||||
break;
|
||||
case ThreadStatusTlv::kDuaNoResources:
|
||||
case ThreadStatusTlv::kDuaNotPrimary:
|
||||
case ThreadStatusTlv::kDuaGeneralFailure:
|
||||
case kDuaNoResources:
|
||||
case kDuaNotPrimary:
|
||||
case kDuaGeneralFailure:
|
||||
UpdateReregistrationDelay();
|
||||
break;
|
||||
}
|
||||
@@ -675,34 +675,34 @@ Error DuaManager::ProcessDuaResponse(Coap::Message &aMessage)
|
||||
|
||||
switch (status)
|
||||
{
|
||||
case ThreadStatusTlv::kDuaSuccess:
|
||||
case kDuaSuccess:
|
||||
// Mark as Registered
|
||||
if (mChildDuaMask.Has(childIndex))
|
||||
{
|
||||
mChildDuaRegisteredMask.Add(childIndex);
|
||||
}
|
||||
break;
|
||||
case ThreadStatusTlv::kDuaReRegister:
|
||||
case kDuaReRegister:
|
||||
// Parent stops registering for the Child's DUA until next Child Update Request
|
||||
mChildDuaMask.Remove(childIndex);
|
||||
mChildDuaRegisteredMask.Remove(childIndex);
|
||||
break;
|
||||
case ThreadStatusTlv::kDuaInvalid:
|
||||
case ThreadStatusTlv::kDuaDuplicate:
|
||||
case kDuaInvalid:
|
||||
case kDuaDuplicate:
|
||||
IgnoreError(child->RemoveIp6Address(target));
|
||||
mChildDuaMask.Remove(childIndex);
|
||||
mChildDuaRegisteredMask.Remove(childIndex);
|
||||
break;
|
||||
case ThreadStatusTlv::kDuaNoResources:
|
||||
case ThreadStatusTlv::kDuaNotPrimary:
|
||||
case ThreadStatusTlv::kDuaGeneralFailure:
|
||||
case kDuaNoResources:
|
||||
case kDuaNotPrimary:
|
||||
case kDuaGeneralFailure:
|
||||
UpdateReregistrationDelay();
|
||||
break;
|
||||
}
|
||||
|
||||
if (status != ThreadStatusTlv::kDuaSuccess)
|
||||
if (status != kDuaSuccess)
|
||||
{
|
||||
SendAddressNotification(target, static_cast<ThreadStatusTlv::DuaStatus>(status), *child);
|
||||
SendAddressNotification(target, static_cast<DuaStatus>(status), *child);
|
||||
}
|
||||
}
|
||||
#endif // OPENTHREAD_FTD && OPENTHREAD_CONFIG_TMF_PROXY_DUA_ENABLE
|
||||
@@ -713,9 +713,7 @@ exit:
|
||||
}
|
||||
|
||||
#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_TMF_PROXY_DUA_ENABLE
|
||||
void DuaManager::SendAddressNotification(Ip6::Address &aAddress,
|
||||
ThreadStatusTlv::DuaStatus aStatus,
|
||||
const Child &aChild)
|
||||
void DuaManager::SendAddressNotification(Ip6::Address &aAddress, DuaStatus aStatus, const Child &aChild)
|
||||
{
|
||||
Coap::Message *message = nullptr;
|
||||
Tmf::MessageInfo messageInfo(GetInstance());
|
||||
|
||||
Reference in New Issue
Block a user