diff --git a/src/core/meshcop/border_agent.cpp b/src/core/meshcop/border_agent.cpp index b23ebba30..a0e3d8e14 100644 --- a/src/core/meshcop/border_agent.cpp +++ b/src/core/meshcop/border_agent.cpp @@ -746,6 +746,20 @@ void BorderAgent::SetState(otBorderAgentState aState) } } +void BorderAgent::ApplyMeshLocalPrefix(void) +{ + VerifyOrExit(mState == OT_BORDER_AGENT_STATE_ACTIVE, OT_NOOP); + + if (Get().RemoveUnicastAddress(mCommissionerAloc) == OT_ERROR_NONE) + { + mCommissionerAloc.GetAddress().SetPrefix(Get().GetMeshLocalPrefix()); + Get().AddUnicastAddress(mCommissionerAloc); + } + +exit: + return; +} + } // namespace MeshCoP } // namespace ot diff --git a/src/core/meshcop/border_agent.hpp b/src/core/meshcop/border_agent.hpp index c3b8cf757..ef0e37bf0 100644 --- a/src/core/meshcop/border_agent.hpp +++ b/src/core/meshcop/border_agent.hpp @@ -86,6 +86,12 @@ public: */ otBorderAgentState GetState(void) const { return mState; } + /** + * This method applies the Mesh Local Prefix. + * + */ + void ApplyMeshLocalPrefix(void); + private: static void HandleStateChanged(Notifier::Callback &aCallback, otChangedFlags aFlags); void HandleStateChanged(otChangedFlags aFlags); diff --git a/src/core/meshcop/commissioner.cpp b/src/core/meshcop/commissioner.cpp index 1229528c5..c00aaa41f 100644 --- a/src/core/meshcop/commissioner.cpp +++ b/src/core/meshcop/commissioner.cpp @@ -1094,6 +1094,18 @@ exit: return error; } +void Commissioner::ApplyMeshLocalPrefix(void) +{ + VerifyOrExit(mState == OT_COMMISSIONER_STATE_ACTIVE, OT_NOOP); + + Get().RemoveUnicastAddress(mCommissionerAloc); + mCommissionerAloc.GetAddress().SetPrefix(Get().GetMeshLocalPrefix()); + Get().AddUnicastAddress(mCommissionerAloc); + +exit: + return; +} + // LCOV_EXCL_START #if (OPENTHREAD_CONFIG_LOG_LEVEL >= OT_LOG_LEVEL_INFO) && (OPENTHREAD_CONFIG_LOG_MLE == 1) diff --git a/src/core/meshcop/commissioner.hpp b/src/core/meshcop/commissioner.hpp index ba8e26123..aa02e6a05 100644 --- a/src/core/meshcop/commissioner.hpp +++ b/src/core/meshcop/commissioner.hpp @@ -246,6 +246,12 @@ public: */ PanIdQueryClient &GetPanIdQueryClient(void) { return mPanIdQuery; } + /** + * This method applies the Mesh Local Prefix. + * + */ + void ApplyMeshLocalPrefix(void); + private: enum { diff --git a/src/core/net/dhcp6_server.cpp b/src/core/net/dhcp6_server.cpp index c7c85f1e5..45a57f950 100644 --- a/src/core/net/dhcp6_server.cpp +++ b/src/core/net/dhcp6_server.cpp @@ -64,7 +64,7 @@ otError Dhcp6Server::UpdateService(void) Lowpan::Context lowpanContext; // remove dhcp agent aloc and prefix delegation - for (int i = 0; i < OPENTHREAD_CONFIG_DHCP6_SERVER_NUM_PREFIXES; i++) + for (uint8_t i = 0; i < OT_ARRAY_LENGTH(mPrefixAgents); i++) { bool found = false; @@ -149,7 +149,7 @@ otError Dhcp6Server::AddPrefixAgent(const otIp6Prefix &aIp6Prefix, const Lowpan: otError error = OT_ERROR_NONE; PrefixAgent *newEntry = NULL; - for (int i = 0; i < OPENTHREAD_CONFIG_DHCP6_SERVER_NUM_PREFIXES; i++) + for (uint8_t i = 0; i < OT_ARRAY_LENGTH(mPrefixAgents); i++) { if (!mPrefixAgents[i].IsValid()) { @@ -312,7 +312,7 @@ otError Dhcp6Server::ProcessIaAddress(Message &aMessage, uint16_t aOffset) error = OT_ERROR_PARSE); // mask matching prefix - for (uint8_t i = 0; i < OPENTHREAD_CONFIG_DHCP6_SERVER_NUM_PREFIXES; i++) + for (uint8_t i = 0; i < OT_ARRAY_LENGTH(mPrefixAgents); i++) { if (mPrefixAgents[i].IsValid() && mPrefixAgents[i].IsPrefixMatch(option.GetAddress())) { @@ -394,7 +394,7 @@ otError Dhcp6Server::AppendIaNa(Message &aMessage, IaNa &aIaNa) if (mPrefixAgentsMask) { - for (uint8_t i = 0; i < OPENTHREAD_CONFIG_DHCP6_SERVER_NUM_PREFIXES; i++) + for (uint8_t i = 0; i < OT_ARRAY_LENGTH(mPrefixAgents); i++) { if ((mPrefixAgentsMask & (1 << i))) { @@ -434,7 +434,7 @@ otError Dhcp6Server::AppendIaAddress(Message &aMessage, ClientIdentifier &aClien if (mPrefixAgentsMask) { // if specified, only apply specified prefixes - for (uint8_t i = 0; i < OPENTHREAD_CONFIG_DHCP6_SERVER_NUM_PREFIXES; i++) + for (uint8_t i = 0; i < OT_ARRAY_LENGTH(mPrefixAgents); i++) { if (mPrefixAgentsMask & (1 << i)) { @@ -445,7 +445,7 @@ otError Dhcp6Server::AppendIaAddress(Message &aMessage, ClientIdentifier &aClien else { // if not specified, apply all configured prefixes - for (uint8_t i = 0; i < OPENTHREAD_CONFIG_DHCP6_SERVER_NUM_PREFIXES; i++) + for (uint8_t i = 0; i < OT_ARRAY_LENGTH(mPrefixAgents); i++) { if (mPrefixAgents[i].IsValid()) { @@ -482,6 +482,20 @@ otError Dhcp6Server::AppendRapidCommit(Message &aMessage) return aMessage.Append(&option, sizeof(option)); } +void Dhcp6Server::ApplyMeshLocalPrefix(void) +{ + for (uint8_t i = 0; i < OT_ARRAY_LENGTH(mPrefixAgents); i++) + { + if (mPrefixAgents[i].IsValid()) + { + PrefixAgent *entry = &mPrefixAgents[i]; + Get().RemoveUnicastAddress(entry->GetAloc()); + entry->GetAloc().GetAddress().SetPrefix(Get().GetMeshLocalPrefix()); + Get().AddUnicastAddress(entry->GetAloc()); + } + } +} + } // namespace Dhcp6 } // namespace ot diff --git a/src/core/net/dhcp6_server.hpp b/src/core/net/dhcp6_server.hpp index ec5dd25cb..7e52eb814 100644 --- a/src/core/net/dhcp6_server.hpp +++ b/src/core/net/dhcp6_server.hpp @@ -83,6 +83,12 @@ public: */ otError UpdateService(); + /** + * This method applies the Mesh Local Prefix. + * + */ + void ApplyMeshLocalPrefix(void); + private: class PrefixAgent { diff --git a/src/core/thread/mle.cpp b/src/core/thread/mle.cpp index 5d45dc38c..300ac8114 100644 --- a/src/core/thread/mle.cpp +++ b/src/core/thread/mle.cpp @@ -953,6 +953,18 @@ void Mle::ApplyMeshLocalPrefix(void) Get().AddUnicastAddress(mLeaderAloc); } +#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_COMMISSIONER_ENABLE + Get().ApplyMeshLocalPrefix(); +#endif + +#if OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE + Get().ApplyMeshLocalPrefix(); +#endif + +#if OPENTHREAD_CONFIG_DHCP6_SERVER_ENABLE + Get().ApplyMeshLocalPrefix(); +#endif + #if OPENTHREAD_CONFIG_TMF_NETDATA_SERVICE_ENABLE for (uint8_t i = 0; i < OT_ARRAY_LENGTH(mServiceAlocs); i++)