From 93b6fea3aa10e26f17ad2b877f002ca2cd81b745 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Wa=C5=84czyk?= Date: Fri, 5 Mar 2021 00:47:56 +0100 Subject: [PATCH] [spinel] add interface identifier of the Thread Domain Unicast Address (#6200) This commit adds new spinel property to configure Interface Identifier of the Thread Domain Unicast Address. --- src/lib/spinel/spinel.h | 16 +++++++++++ src/ncp/ncp_base.cpp | 4 +++ src/ncp/ncp_base_dispatcher.cpp | 6 +++++ src/ncp/ncp_base_ftd.cpp | 47 +++++++++++++++++++++++++++++++++ 4 files changed, 73 insertions(+) diff --git a/src/lib/spinel/spinel.h b/src/lib/spinel/spinel.h index 3c1ef6f78..1c070314c 100644 --- a/src/lib/spinel/spinel.h +++ b/src/lib/spinel/spinel.h @@ -1187,6 +1187,7 @@ enum SPINEL_CAP_MAC_RETRY_HISTOGRAM = (SPINEL_CAP_OPENTHREAD__BEGIN + 12), SPINEL_CAP_MULTI_RADIO = (SPINEL_CAP_OPENTHREAD__BEGIN + 13), SPINEL_CAP_SRP_CLIENT = (SPINEL_CAP_OPENTHREAD__BEGIN + 14), + SPINEL_CAP_DUA = (SPINEL_CAP_OPENTHREAD__BEGIN + 15), SPINEL_CAP_OPENTHREAD__END = 640, SPINEL_CAP_THREAD__BEGIN = 1024, @@ -2944,6 +2945,21 @@ enum */ SPINEL_PROP_THREAD_DOMAIN_NAME = SPINEL_PROP_THREAD_EXT__BEGIN + 44, + /// Interface Identifier specified for Thread Domain Unicast Address. + /** Format: `A(C)` - Read-write + * + * `A(C)`: Interface Identifier (8 bytes). + * + * Required capability: SPINEL_CAP_DUA + * + * If write to this property is performed without specified parameter + * the Interface Identifier of the Thread Domain Unicast Address will be cleared. + * If the DUA Interface Identifier is cleared on the NCP device, + * the get spinel property command will be returned successfully without specified parameter. + * + */ + SPINEL_PROP_THREAD_DUA_ID = SPINEL_PROP_THREAD_EXT__BEGIN + 54, + SPINEL_PROP_THREAD_EXT__END = 0x1600, SPINEL_PROP_IPV6__BEGIN = 0x60, diff --git a/src/ncp/ncp_base.cpp b/src/ncp/ncp_base.cpp index 73c496088..78632e738 100644 --- a/src/ncp/ncp_base.cpp +++ b/src/ncp/ncp_base.cpp @@ -1931,6 +1931,10 @@ template <> otError NcpBase::HandlePropertyGet(void) SuccessOrExit(error = mEncoder.WriteUintPacked(SPINEL_CAP_SRP_CLIENT)); #endif +#if OPENTHREAD_CONFIG_DUA_ENABLE + SuccessOrExit(error = mEncoder.WriteUintPacked(SPINEL_CAP_DUA)); +#endif + #endif // OPENTHREAD_MTD || OPENTHREAD_FTD exit: diff --git a/src/ncp/ncp_base_dispatcher.cpp b/src/ncp/ncp_base_dispatcher.cpp index 0fafc5886..f79bf6dc3 100644 --- a/src/ncp/ncp_base_dispatcher.cpp +++ b/src/ncp/ncp_base_dispatcher.cpp @@ -310,6 +310,9 @@ NcpBase::PropertyHandler NcpBase::FindGetPropertyHandler(spinel_prop_key_t aKey) #if (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2) OT_NCP_GET_HANDLER_ENTRY(SPINEL_PROP_THREAD_DOMAIN_NAME), #endif +#if OPENTHREAD_CONFIG_DUA_ENABLE + OT_NCP_GET_HANDLER_ENTRY(SPINEL_PROP_THREAD_DUA_ID), +#endif #if OPENTHREAD_CONFIG_CHANNEL_MANAGER_ENABLE OT_NCP_GET_HANDLER_ENTRY(SPINEL_PROP_CHANNEL_MANAGER_NEW_CHANNEL), OT_NCP_GET_HANDLER_ENTRY(SPINEL_PROP_CHANNEL_MANAGER_DELAY), @@ -541,6 +544,9 @@ NcpBase::PropertyHandler NcpBase::FindSetPropertyHandler(spinel_prop_key_t aKey) #if (OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2) OT_NCP_SET_HANDLER_ENTRY(SPINEL_PROP_THREAD_DOMAIN_NAME), #endif +#if OPENTHREAD_CONFIG_DUA_ENABLE + OT_NCP_SET_HANDLER_ENTRY(SPINEL_PROP_THREAD_DUA_ID), +#endif #if OPENTHREAD_CONFIG_COMMISSIONER_ENABLE OT_NCP_SET_HANDLER_ENTRY(SPINEL_PROP_MESHCOP_COMMISSIONER_ANNOUNCE_BEGIN), OT_NCP_SET_HANDLER_ENTRY(SPINEL_PROP_MESHCOP_COMMISSIONER_ENERGY_SCAN), diff --git a/src/ncp/ncp_base_ftd.cpp b/src/ncp/ncp_base_ftd.cpp index cbb69e2f9..d576978f0 100644 --- a/src/ncp/ncp_base_ftd.cpp +++ b/src/ncp/ncp_base_ftd.cpp @@ -351,6 +351,53 @@ exit: } #endif +#if OPENTHREAD_CONFIG_DUA_ENABLE +template <> otError NcpBase::HandlePropertyGet(void) +{ + const otIp6InterfaceIdentifier *iid = otThreadGetFixedDuaInterfaceIdentifier(mInstance); + otError error = OT_ERROR_NONE; + + if (iid == nullptr) + { + // send empty response + } + else + { + for (size_t i = 0; i < sizeof(otIp6InterfaceIdentifier); i++) + { + SuccessOrExit(error = mEncoder.WriteUint8(iid->mFields.m8[i])); + } + } + +exit: + return error; +} + +template <> otError NcpBase::HandlePropertySet(void) +{ + otError error = OT_ERROR_NONE; + + if (mDecoder.GetRemainingLength() == 0) + { + SuccessOrExit(error = otThreadSetFixedDuaInterfaceIdentifier(mInstance, nullptr)); + } + else + { + otIp6InterfaceIdentifier iid; + + for (size_t i = 0; i < sizeof(otIp6InterfaceIdentifier); i++) + { + SuccessOrExit(error = mDecoder.ReadUint8(iid.mFields.m8[i])); + } + + SuccessOrExit(error = otThreadSetFixedDuaInterfaceIdentifier(mInstance, &iid)); + } + +exit: + return error; +} +#endif // OPENTHREAD_CONFIG_DUA_ENABLE + template <> otError NcpBase::HandlePropertyGet(void) { return mEncoder.WriteData(otThreadGetPskc(mInstance)->m8, sizeof(spinel_net_pskc_t));