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)