From 304a371d2c26c19e1945e4bc6791101f6ee5fc53 Mon Sep 17 00:00:00 2001 From: Yang Sun Date: Fri, 29 Mar 2024 00:46:19 -0700 Subject: Send list of unicast & multicast addresses in address callback. Added isMeshLocal and isActiveOmr to Ipv6AddressInfo, removed scope from Ipv6AddressInfo as it's not used and is hard to get from otNetifAddress. Bug: 323624146 Test: atest ThreadNetworkIntegrationTests Change-Id: Iad694092b6c0c495f547bc00485e32480f4f5050 --- .../thread/openthread/IOtDaemonCallback.aidl | 7 +-- .../server/thread/openthread/Ipv6AddressInfo.aidl | 5 ++- src/android/otdaemon_server.cpp | 51 ++++++++++++++++------ src/android/otdaemon_server.hpp | 6 ++- 4 files changed, 47 insertions(+), 22 deletions(-) diff --git a/src/android/aidl/com/android/server/thread/openthread/IOtDaemonCallback.aidl b/src/android/aidl/com/android/server/thread/openthread/IOtDaemonCallback.aidl index afc07959..34bdfaef 100644 --- a/src/android/aidl/com/android/server/thread/openthread/IOtDaemonCallback.aidl +++ b/src/android/aidl/com/android/server/thread/openthread/IOtDaemonCallback.aidl @@ -47,12 +47,9 @@ oneway interface IOtDaemonCallback { /** * Called when Thread interface address has been changed. * - * @param addressInfo the IPv6 address which has been updated. This can be both unicast and - * multicast addresses - * @param isAdded {@code true} if this address is being added to the Thread interface; - * Otherwise, this address is being removed + * @param addressInfoList the list of unicast and multicast IPv6 addresses. */ - void onAddressChanged(in Ipv6AddressInfo addressInfo, boolean isAdded); + void onAddressChanged(in List addressInfoList); /** * Called when backbone router state or multicast forwarding listening addresses has been diff --git a/src/android/aidl/com/android/server/thread/openthread/Ipv6AddressInfo.aidl b/src/android/aidl/com/android/server/thread/openthread/Ipv6AddressInfo.aidl index 2aba3c8a..6be019f3 100644 --- a/src/android/aidl/com/android/server/thread/openthread/Ipv6AddressInfo.aidl +++ b/src/android/aidl/com/android/server/thread/openthread/Ipv6AddressInfo.aidl @@ -35,7 +35,10 @@ package com.android.server.thread.openthread; */ parcelable Ipv6AddressInfo { byte[] address; // The raw IPv6 addres bytes, should be 16 bytes - int scope; // The scope of the address int prefixLength; // Valid for only unicast addresses boolean isPreferred; // Valid for only unicast addresses + boolean isMeshLocal; // Valid for only unicast addresses + boolean isActiveOmr; // Valid for only unicast addresses. Active OMR means the prefix is added + // to netdata, if the OMR prefix is removed from netdata then the address + // is not active OMR anymore. } diff --git a/src/android/otdaemon_server.cpp b/src/android/otdaemon_server.cpp index 9ffeb7bf..c3d3b1ce 100644 --- a/src/android/otdaemon_server.cpp +++ b/src/android/otdaemon_server.cpp @@ -89,17 +89,6 @@ static void PropagateResult(int aError, } } -static Ipv6AddressInfo ConvertToAddressInfo(const otIp6AddressInfo &aAddressInfo) -{ - Ipv6AddressInfo addrInfo; - - addrInfo.address.assign(aAddressInfo.mAddress->mFields.m8, BYTE_ARR_END(aAddressInfo.mAddress->mFields.m8)); - addrInfo.prefixLength = aAddressInfo.mPrefixLength; - addrInfo.scope = aAddressInfo.mScope; - addrInfo.isPreferred = aAddressInfo.mPreferred; - return addrInfo; -} - static const char *ThreadEnabledStateToString(int enabledState) { switch (enabledState) @@ -191,13 +180,47 @@ void OtDaemonServer::StateCallback(otChangedFlags aFlags) } } -void OtDaemonServer::AddressCallback(const otIp6AddressInfo *aAddressInfo, bool aIsAdded, void *aBinderServer) +Ipv6AddressInfo OtDaemonServer::ConvertToAddressInfo(const otNetifAddress &aAddress) { - OtDaemonServer *thisServer = static_cast(aBinderServer); + Ipv6AddressInfo addrInfo; + otIp6Prefix addressPrefix{aAddress.mAddress, aAddress.mPrefixLength}; + + addrInfo.address.assign(std::begin(aAddress.mAddress.mFields.m8), std::end(aAddress.mAddress.mFields.m8)); + addrInfo.prefixLength = aAddress.mPrefixLength; + addrInfo.isPreferred = aAddress.mPreferred; + addrInfo.isMeshLocal = aAddress.mMeshLocal; + addrInfo.isActiveOmr = otNetDataContainsOmrPrefix(GetOtInstance(), &addressPrefix); + return addrInfo; +} +Ipv6AddressInfo OtDaemonServer::ConvertToAddressInfo(const otNetifMulticastAddress &aAddress) +{ + Ipv6AddressInfo addrInfo; + + addrInfo.address.assign(std::begin(aAddress.mAddress.mFields.m8), std::end(aAddress.mAddress.mFields.m8)); + return addrInfo; +} + +void OtDaemonServer::AddressCallback(const otIp6AddressInfo *aAddressInfo, bool aIsAdded, void *aBinderServer) +{ + OT_UNUSED_VARIABLE(aAddressInfo); + OT_UNUSED_VARIABLE(aIsAdded); + OtDaemonServer *thisServer = static_cast(aBinderServer); + std::vector addrInfoList; + const otNetifAddress *unicastAddrs = otIp6GetUnicastAddresses(thisServer->GetOtInstance()); + const otNetifMulticastAddress *multicastAddrs = otIp6GetMulticastAddresses(thisServer->GetOtInstance()); + + for (const otNetifAddress *addr = unicastAddrs; addr != nullptr; addr = addr->mNext) + { + addrInfoList.push_back(thisServer->ConvertToAddressInfo(*addr)); + } + for (const otNetifMulticastAddress *maddr = multicastAddrs; maddr != nullptr; maddr = maddr->mNext) + { + addrInfoList.push_back(thisServer->ConvertToAddressInfo(*maddr)); + } if (thisServer->mCallback != nullptr) { - thisServer->mCallback->onAddressChanged(ConvertToAddressInfo(*aAddressInfo), aIsAdded); + thisServer->mCallback->onAddressChanged(addrInfoList); } else { diff --git a/src/android/otdaemon_server.hpp b/src/android/otdaemon_server.hpp index 81249523..8566ca9b 100644 --- a/src/android/otdaemon_server.hpp +++ b/src/android/otdaemon_server.hpp @@ -154,8 +154,10 @@ private: otBackboneRouterMulticastListenerEvent aEvent, const otIp6Address *aAddress); void PushTelemetryIfConditionMatch(); - void updateThreadEnabledState(const int aEnabled, const std::shared_ptr &aReceiver); - void enableThread(const std::shared_ptr &aReceiver); + void updateThreadEnabledState(const int aEnabled, const std::shared_ptr &aReceiver); + void enableThread(const std::shared_ptr &aReceiver); + Ipv6AddressInfo ConvertToAddressInfo(const otNetifAddress &aAddress); + Ipv6AddressInfo ConvertToAddressInfo(const otNetifMulticastAddress &aAddress); int mThreadEnabled = OT_STATE_DISABLED; otbr::Application &mApplication; -- cgit v1.2.3