From 317321fef2c59a403e21ae78441b291cca47e223 Mon Sep 17 00:00:00 2001 From: Zhanglong Xia Date: Tue, 28 Oct 2025 00:26:31 +0800 Subject: [PATCH] [api] add API to extract an extended address from an IPv6 address (#11933) The application of the P2P module may only record the P2P peer's link-local address for communication. This commit adds an API to convert the peer's link-local unicast address to the peer's extended address for tearing down the P2P link. --- include/openthread/instance.h | 2 +- include/openthread/ip6.h | 8 ++++++++ src/core/api/ip6_api.cpp | 5 +++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/include/openthread/instance.h b/include/openthread/instance.h index 450d18993..23fe89621 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 (545) +#define OPENTHREAD_API_VERSION (546) /** * @addtogroup api-instance diff --git a/include/openthread/ip6.h b/include/openthread/ip6.h index 948fcefc2..889451cb9 100644 --- a/include/openthread/ip6.h +++ b/include/openthread/ip6.h @@ -576,6 +576,14 @@ bool otIp6IsLinkLocalUnicast(const otIp6Address *aAddress); */ void otIp6FormLinkLocalAddressFromExtAddress(const otExtAddress *aExtAddress, otIp6Address *aAddress); +/** + * Extracts the MAC Extended Address from the Interface Identifier of the given IPv6 address. + * + * @param[in] aAddress A pointer to the IPv6 address. + * @param[out] aExtAddress A pointer to output the MAC Extended Address (generated from the IID). + */ +void otIp6ExtractExtAddressFromIp6AddressIid(const otIp6Address *aAddress, otExtAddress *aExtAddress); + /** * 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 ef61ef7b0..89c22f0d6 100644 --- a/src/core/api/ip6_api.cpp +++ b/src/core/api/ip6_api.cpp @@ -178,6 +178,11 @@ void otIp6FormLinkLocalAddressFromExtAddress(const otExtAddress *aExtAddress, ot AsCoreType(aAddress).SetToLinkLocalAddress(AsCoreType(aExtAddress)); } +void otIp6ExtractExtAddressFromIp6AddressIid(const otIp6Address *aAddress, otExtAddress *aExtAddress) +{ + AsCoreType(aExtAddress).SetFromIid(AsCoreType(aAddress).GetIid()); +} + bool otIp6ArePrefixesEqual(const otIp6Prefix *aFirst, const otIp6Prefix *aSecond) { return AsCoreType(aFirst) == AsCoreType(aSecond);