From 9c09577d528bcf89f0197a68b9db775915ebebfd Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Thu, 1 Jun 2017 13:20:44 -0700 Subject: [PATCH] NcpBase: Implement get handler for `IPV6_LL_ADDR` spinel property (#1826) This commit add a new API `otThreadGetLinkLocalIp6Address()` to get the Thread link-local address (which is is derived using IEEE802.15.4 Extended Address as Interface Identifier). The new API is then used to implement the get handler for spinel property `IPV6_LL_ADDR` in `NcpBase` class. --- include/openthread/thread.h | 11 +++++++++++ src/core/api/thread_api.cpp | 5 +++++ src/core/thread/mle.cpp | 5 +++++ src/core/thread/mle.hpp | 10 ++++++++++ src/ncp/ncp_base.cpp | 26 +++++++++++++++++++++++--- 5 files changed, 54 insertions(+), 3 deletions(-) diff --git a/include/openthread/thread.h b/include/openthread/thread.h index d11c3b96d..140a51bab 100644 --- a/include/openthread/thread.h +++ b/include/openthread/thread.h @@ -275,6 +275,17 @@ OTAPI const uint8_t *OTCALL otThreadGetMeshLocalPrefix(otInstance *aInstance); */ OTAPI otError OTCALL otThreadSetMeshLocalPrefix(otInstance *aInstance, const uint8_t *aMeshLocalPrefix); +/** + * This function returns the Thread link-local IPv6 address. + * + * The Thread link local address is derived using IEEE802.15.4 Extended Address as Interface Identifier. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * + * @returns A pointer to Thread link-local IPv6 address. + */ +const otIp6Address *otThreadGetLinkLocalIp6Address(otInstance *aInstance); + /** * Get the Thread Network Name. * diff --git a/src/core/api/thread_api.cpp b/src/core/api/thread_api.cpp index 653b0f489..5426b6d1a 100644 --- a/src/core/api/thread_api.cpp +++ b/src/core/api/thread_api.cpp @@ -195,6 +195,11 @@ exit: return error; } +const otIp6Address *otThreadGetLinkLocalIp6Address(otInstance *aInstance) +{ + return &aInstance->mThreadNetif.GetMle().GetLinkLocalAddress(); +} + const char *otThreadGetNetworkName(otInstance *aInstance) { return aInstance->mThreadNetif.GetMac().GetNetworkName(); diff --git a/src/core/thread/mle.cpp b/src/core/thread/mle.cpp index cc1722334..30f98f253 100644 --- a/src/core/thread/mle.cpp +++ b/src/core/thread/mle.cpp @@ -675,6 +675,11 @@ exit: return error; } +const Ip6::Address &Mle::GetLinkLocalAddress(void) const +{ + return mLinkLocal64.GetAddress(); +} + otError Mle::UpdateLinkLocalAddress(void) { mNetif.RemoveUnicastAddress(mLinkLocal64); diff --git a/src/core/thread/mle.hpp b/src/core/thread/mle.hpp index 3c94ff039..ac586df89 100644 --- a/src/core/thread/mle.hpp +++ b/src/core/thread/mle.hpp @@ -650,6 +650,16 @@ public: */ otError SetMeshLocalPrefix(const uint8_t *aPrefix); + /** + * This method returns a reference to the Thread link-local address. + * + * The Thread link local address is derived using IEEE802.15.4 Extended Address as Interface Identifier. + * + * @returns A reference to the Thread link local address. + * + */ + const Ip6::Address &GetLinkLocalAddress(void) const; + /** * This method updates the link local address. * diff --git a/src/ncp/ncp_base.cpp b/src/ncp/ncp_base.cpp index 4ea3d8c3e..c2be77470 100644 --- a/src/ncp/ncp_base.cpp +++ b/src/ncp/ncp_base.cpp @@ -3131,10 +3131,30 @@ otError NcpBase::GetPropertyHandler_IPV6_ML_ADDR(uint8_t header, spinel_prop_key otError NcpBase::GetPropertyHandler_IPV6_LL_ADDR(uint8_t header, spinel_prop_key_t key) { - // TODO! - (void)key; + otError errorCode = OT_ERROR_NONE; + const otIp6Address *address = otThreadGetLinkLocalIp6Address(mInstance); - return SendLastStatus(header, SPINEL_STATUS_UNIMPLEMENTED); + if (address) + { + errorCode = SendPropertyUpdate( + header, + SPINEL_CMD_PROP_VALUE_IS, + key, + SPINEL_DATATYPE_IPv6ADDR_S, + address + ); + } + else + { + errorCode = SendPropertyUpdate( + header, + SPINEL_CMD_PROP_VALUE_IS, + key, + SPINEL_DATATYPE_VOID_S + ); + } + + return errorCode; } otError NcpBase::GetPropertyHandler_IPV6_ADDRESS_TABLE(uint8_t header, spinel_prop_key_t key)