aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTreehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com>2024-05-15 19:34:04 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2024-05-15 19:34:04 +0000
commit4f572699e6da2c6c270a3b6ee1adf6886ea065c2 (patch)
tree7e49a9b08380156915db428f67bae41875d7b632
parent07729319da9c13f1be95a5a8a4d80574d298e979 (diff)
parentfb5a3702c4e39db4b3fea1fb810113b817ec306d (diff)
downloadot-br-posix-main.tar.gz
Merge "Send the list of netdata prefixes to system server." into mainHEADmastermain
-rw-r--r--src/android/aidl/com/android/server/thread/openthread/IOtDaemonCallback.aidl8
-rw-r--r--src/android/aidl/com/android/server/thread/openthread/OnMeshPrefixConfig.aidl41
-rw-r--r--src/android/otdaemon_server.cpp44
-rw-r--r--src/android/otdaemon_server.hpp11
4 files changed, 100 insertions, 4 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 34bdfaef..fe3fbbc4 100644
--- a/src/android/aidl/com/android/server/thread/openthread/IOtDaemonCallback.aidl
+++ b/src/android/aidl/com/android/server/thread/openthread/IOtDaemonCallback.aidl
@@ -31,6 +31,7 @@ package com.android.server.thread.openthread;
import com.android.server.thread.openthread.BackboneRouterState;
import com.android.server.thread.openthread.Ipv6AddressInfo;
import com.android.server.thread.openthread.OtDaemonState;
+import com.android.server.thread.openthread.OnMeshPrefixConfig;
/** OpenThread daemon callbacks. */
oneway interface IOtDaemonCallback {
@@ -66,4 +67,11 @@ oneway interface IOtDaemonCallback {
* @param enabled {@code true} if Thread is enabled, {@code false} if Thread is disabled.
*/
void onThreadEnabledChanged(in int enabled);
+
+ /**
+ * Called when Thread on-mesh prefixes have changed.
+ *
+ * @param onMeshPrefixConfigList the list of IPv6 prefixes.
+ */
+ void onPrefixChanged(in List<OnMeshPrefixConfig> onMeshPrefixConfigList);
}
diff --git a/src/android/aidl/com/android/server/thread/openthread/OnMeshPrefixConfig.aidl b/src/android/aidl/com/android/server/thread/openthread/OnMeshPrefixConfig.aidl
new file mode 100644
index 00000000..b7ee7194
--- /dev/null
+++ b/src/android/aidl/com/android/server/thread/openthread/OnMeshPrefixConfig.aidl
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2024, The OpenThread Authors.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package com.android.server.thread.openthread;
+
+/**
+ * On-mesh prefix configuration.
+ *
+ * This is a mapping of <a href="https://openthread.io/reference/struct/ot-border-router-config">otBorderRouterConfig</a>
+ */
+parcelable OnMeshPrefixConfig {
+ byte[] prefix; // The raw IPv6 prefix bytes, should be 16 bytes
+ int prefixLength; // The IPv6 prefix length (in bits)
+
+ // More fields of otBorderRouterConfig can be added here when needed.
+}
diff --git a/src/android/otdaemon_server.cpp b/src/android/otdaemon_server.cpp
index 1401d513..4e99ff8b 100644
--- a/src/android/otdaemon_server.cpp
+++ b/src/android/otdaemon_server.cpp
@@ -155,6 +155,8 @@ void OtDaemonServer::BinderDeathCallback(void *aBinderServer)
void OtDaemonServer::StateCallback(otChangedFlags aFlags)
{
+ std::vector<OnMeshPrefixConfig> onMeshPrefixes;
+
assert(GetOtInstance() != nullptr);
if (RefreshOtDaemonState(aFlags))
@@ -168,6 +170,7 @@ void OtDaemonServer::StateCallback(otChangedFlags aFlags)
mCallback->onStateChanged(mState, -1);
}
}
+
if (aFlags & OT_CHANGED_THREAD_BACKBONE_ROUTER_STATE)
{
if (mCallback == nullptr)
@@ -179,6 +182,47 @@ void OtDaemonServer::StateCallback(otChangedFlags aFlags)
mCallback->onBackboneRouterStateChanged(GetBackboneRouterState());
}
}
+
+ if ((aFlags & OT_CHANGED_THREAD_NETDATA) && RefreshOnMeshPrefixes())
+ {
+ if (mCallback == nullptr)
+ {
+ otbrLogWarning("Ignoring OT netdata changes: callback is not set");
+ }
+ else
+ {
+ onMeshPrefixes.assign(mOnMeshPrefixes.begin(), mOnMeshPrefixes.end());
+ mCallback->onPrefixChanged(onMeshPrefixes);
+ }
+ }
+}
+
+bool OtDaemonServer::RefreshOnMeshPrefixes()
+{
+ std::set<OnMeshPrefixConfig> onMeshPrefixConfigs;
+ otNetworkDataIterator iterator = OT_NETWORK_DATA_ITERATOR_INIT;
+ otBorderRouterConfig config;
+ bool rv = false;
+
+ VerifyOrExit(GetOtInstance() != nullptr, otbrLogWarning("Can't get on mesh prefixes: OT is not initialized"));
+
+ while (otNetDataGetNextOnMeshPrefix(GetOtInstance(), &iterator, &config) == OT_ERROR_NONE)
+ {
+ OnMeshPrefixConfig onMeshPrefixConfig;
+
+ onMeshPrefixConfig.prefix.assign(std::begin(config.mPrefix.mPrefix.mFields.m8),
+ std::end(config.mPrefix.mPrefix.mFields.m8));
+ onMeshPrefixConfig.prefixLength = config.mPrefix.mLength;
+ onMeshPrefixConfigs.insert(onMeshPrefixConfig);
+ }
+
+ if (mOnMeshPrefixes != onMeshPrefixConfigs)
+ {
+ mOnMeshPrefixes = std::move(onMeshPrefixConfigs);
+ rv = true;
+ }
+exit:
+ return rv;
}
Ipv6AddressInfo OtDaemonServer::ConvertToAddressInfo(const otNetifAddress &aAddress)
diff --git a/src/android/otdaemon_server.hpp b/src/android/otdaemon_server.hpp
index 8566ca9b..91b6e046 100644
--- a/src/android/otdaemon_server.hpp
+++ b/src/android/otdaemon_server.hpp
@@ -62,6 +62,7 @@ using aidl::com::android::server::thread::openthread::IOtDaemonCallback;
using aidl::com::android::server::thread::openthread::IOtStatusReceiver;
using aidl::com::android::server::thread::openthread::Ipv6AddressInfo;
using aidl::com::android::server::thread::openthread::MeshcopTxtAttributes;
+using aidl::com::android::server::thread::openthread::OnMeshPrefixConfig;
using aidl::com::android::server::thread::openthread::OtDaemonState;
class OtDaemonServer : public BnOtDaemon, public MainloopProcessor, public vendor::VendorServer
@@ -154,10 +155,11 @@ 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);
- Ipv6AddressInfo ConvertToAddressInfo(const otNetifAddress &aAddress);
- Ipv6AddressInfo ConvertToAddressInfo(const otNetifMulticastAddress &aAddress);
+ bool RefreshOnMeshPrefixes();
+ Ipv6AddressInfo ConvertToAddressInfo(const otNetifAddress &aAddress);
+ Ipv6AddressInfo ConvertToAddressInfo(const otNetifMulticastAddress &aAddress);
+ void updateThreadEnabledState(const int aEnabled, const std::shared_ptr<IOtStatusReceiver> &aReceiver);
+ void enableThread(const std::shared_ptr<IOtStatusReceiver> &aReceiver);
int mThreadEnabled = OT_STATE_DISABLED;
otbr::Application &mApplication;
@@ -175,6 +177,7 @@ private:
std::shared_ptr<IOtStatusReceiver> mMigrationReceiver;
std::vector<LeaveCallback> mLeaveCallbacks;
BorderRouterConfigurationParcel mBorderRouterConfiguration;
+ std::set<OnMeshPrefixConfig> mOnMeshPrefixes;
static constexpr Seconds kTelemetryCheckInterval = Seconds(600); // 600 seconds
static constexpr Seconds kTelemetryUploadIntervalThreshold = Seconds(60 * 60 * 12); // 12 hours
};