From 6469b1e8165f6788bc900c3b9945e30a4754838b Mon Sep 17 00:00:00 2001 From: Zhanglong Xia Date: Wed, 22 Oct 2025 16:16:45 +0800 Subject: [PATCH] [api] add API to convert an extended address to a link-local unicast IPv6 address (#11932) After the P2P link is established, the P2P peer's extended address is returned as the P2P handle. This commit adds an API to convert the peer's extended address to the peer's link-local unicast address. --- include/openthread/instance.h | 2 +- include/openthread/ip6.h | 10 ++++++++++ src/core/api/ip6_api.cpp | 5 +++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/include/openthread/instance.h b/include/openthread/instance.h index 684909dcd..42995e885 100644 --- a/include/openthread/instance.h +++ b/include/openthread/instance.h @@ -52,7 +52,7 @@ extern "C" { * * @note This number versions both OpenThread platform and user APIs. */ -#define OPENTHREAD_API_VERSION (543) +#define OPENTHREAD_API_VERSION (544) /** * @addtogroup api-instance diff --git a/include/openthread/ip6.h b/include/openthread/ip6.h index 0e5131bd1..948fcefc2 100644 --- a/include/openthread/ip6.h +++ b/include/openthread/ip6.h @@ -41,6 +41,7 @@ #include #include #include +#include #include #ifdef __cplusplus @@ -566,6 +567,15 @@ bool otIp6IsAddressEqual(const otIp6Address *aFirst, const otIp6Address *aSecond */ bool otIp6IsLinkLocalUnicast(const otIp6Address *aAddress); +/** + * Forms a link-local unicast IPv6 address from the Interface Identifier generated from the given + * MAC Extended Address with the universal/local bit inverted. + * + * @param[in] aExtAddress A pointer to the MAC Extended Address (used to generate the IID). + * @param[out] aAddress A pointer to output the IPv6 link-local unicast address. + */ +void otIp6FormLinkLocalAddressFromExtAddress(const otExtAddress *aExtAddress, otIp6Address *aAddress); + /** * Test if two IPv6 prefixes are the same. * diff --git a/src/core/api/ip6_api.cpp b/src/core/api/ip6_api.cpp index 4ad0fda39..ef61ef7b0 100644 --- a/src/core/api/ip6_api.cpp +++ b/src/core/api/ip6_api.cpp @@ -173,6 +173,11 @@ bool otIp6IsAddressEqual(const otIp6Address *aFirst, const otIp6Address *aSecond bool otIp6IsLinkLocalUnicast(const otIp6Address *aAddress) { return AsCoreType(aAddress).IsLinkLocalUnicast(); } +void otIp6FormLinkLocalAddressFromExtAddress(const otExtAddress *aExtAddress, otIp6Address *aAddress) +{ + AsCoreType(aAddress).SetToLinkLocalAddress(AsCoreType(aExtAddress)); +} + bool otIp6ArePrefixesEqual(const otIp6Prefix *aFirst, const otIp6Prefix *aSecond) { return AsCoreType(aFirst) == AsCoreType(aSecond);