aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYang Sun <sunytt@google.com>2024-04-10 02:13:12 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2024-04-10 02:13:12 +0000
commit7588011e851fa674d18d6016891e77d0ff9370aa (patch)
tree9efb72e081ce6ae5c7501144cada5e821a50be43
parenta7f6b2393e664bfbbe3148b11b8fdfc4a6fb82b0 (diff)
parent304a371d2c26c19e1945e4bc6791101f6ee5fc53 (diff)
downloadot-br-posix-7588011e851fa674d18d6016891e77d0ff9370aa.tar.gz
Merge "Send list of unicast & multicast addresses in address callback." into main
-rw-r--r--src/android/aidl/com/android/server/thread/openthread/IOtDaemonCallback.aidl7
-rw-r--r--src/android/aidl/com/android/server/thread/openthread/Ipv6AddressInfo.aidl5
-rw-r--r--src/android/otdaemon_server.cpp51
-rw-r--r--src/android/otdaemon_server.hpp6
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<Ipv6AddressInfo> 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<OtDaemonServer *>(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<OtDaemonServer *>(aBinderServer);
+ std::vector<Ipv6AddressInfo> 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<IOtStatusReceiver> &aReceiver);
- void enableThread(const std::shared_ptr<IOtStatusReceiver> &aReceiver);
+ void updateThreadEnabledState(const int aEnabled, const std::shared_ptr<IOtStatusReceiver> &aReceiver);
+ void enableThread(const std::shared_ptr<IOtStatusReceiver> &aReceiver);
+ Ipv6AddressInfo ConvertToAddressInfo(const otNetifAddress &aAddress);
+ Ipv6AddressInfo ConvertToAddressInfo(const otNetifMulticastAddress &aAddress);
int mThreadEnabled = OT_STATE_DISABLED;
otbr::Application &mApplication;