From 155fd878f347b27d10c48dad36fb440ff11885d8 Mon Sep 17 00:00:00 2001
From: Stefan Schmidt <stefan.schmidt@huawei.com>
Date: Thu, 17 Jun 2021 18:07:28 +0200
Subject: [PATCH] ot-br-posix: Add bbappend to add configuration script

A simple configuration script to set the Thread border router up.
Wrapped into a systemd service to handle execution and service
dependencies.

Signed-off-by: Stefan Schmidt <stefan.schmidt@huawei.com>
---
 .../openthread/ot-br-posix/otbr-configuration | 23 +++++++++++++++++++
 .../ot-br-posix/otbr-configuration.service    | 13 +++++++++++
 .../openthread/ot-br-posix_%.bbappend         | 10 +++++++-
 3 files changed, 45 insertions(+), 1 deletion(-)
 create mode 100755 meta-ohos-blueprints/recipes-connectivity/openthread/ot-br-posix/otbr-configuration
 create mode 100644 meta-ohos-blueprints/recipes-connectivity/openthread/ot-br-posix/otbr-configuration.service

diff --git a/meta-ohos-blueprints/recipes-connectivity/openthread/ot-br-posix/otbr-configuration b/meta-ohos-blueprints/recipes-connectivity/openthread/ot-br-posix/otbr-configuration
new file mode 100755
index 00000000..ecb1f189
--- /dev/null
+++ b/meta-ohos-blueprints/recipes-connectivity/openthread/ot-br-posix/otbr-configuration
@@ -0,0 +1,23 @@
+#!/bin/sh
+# SPDX-FileCopyrightText: Huawei Inc.
+#
+# SPDX-License-Identifier: Apache-2.0
+
+set -e
+
+# Bring up a OpenThread border router for the given configuration
+ot-ctl thread stop
+ot-ctl ifconfig down
+ot-ctl dataset clear
+ot-ctl dataset init new
+ot-ctl dataset panid 0x1357
+ot-ctl dataset extpanid 11112222deadbeef
+ot-ctl dataset networkname "ASOS\ Thread"
+ot-ctl dataset channel 26
+ot-ctl dataset masterkey 00112233445566778899aabbccddeeff
+ot-ctl dataset commit active
+ot-ctl ifconfig up
+ot-ctl thread start
+#ot-ctl prefix add 2001::/64 paros
+#ot-ctl prefix add fd11:22::/64 pasor
+#ot-ctl dataset meshlocalprefix fdde:00be:ef00:aaaa::
diff --git a/meta-ohos-blueprints/recipes-connectivity/openthread/ot-br-posix/otbr-configuration.service b/meta-ohos-blueprints/recipes-connectivity/openthread/ot-br-posix/otbr-configuration.service
new file mode 100644
index 00000000..453f03a7
--- /dev/null
+++ b/meta-ohos-blueprints/recipes-connectivity/openthread/ot-br-posix/otbr-configuration.service
@@ -0,0 +1,13 @@
+# SPDX-FileCopyrightText: Huawei Inc.
+#
+# SPDX-License-Identifier: Apache-2.0
+
+[Unit]
+Description=OpenThread Border Router Configuration
+ConditionPathExists=/usr/sbin/otbr-configuration
+After=sys-subsystem-net-devices-wpan0.device
+BindsTo=sys-subsystem-net-devices-wpan0.device
+
+[Service]
+Type=oneshot
+ExecStart=/usr/sbin/otbr-configuration
diff --git a/meta-ohos-blueprints/recipes-connectivity/openthread/ot-br-posix_%.bbappend b/meta-ohos-blueprints/recipes-connectivity/openthread/ot-br-posix_%.bbappend
index d8c49415..edef76c7 100644
--- a/meta-ohos-blueprints/recipes-connectivity/openthread/ot-br-posix_%.bbappend
+++ b/meta-ohos-blueprints/recipes-connectivity/openthread/ot-br-posix_%.bbappend
@@ -1,8 +1,16 @@
 FILESEXTRAPATHS_prepend := "${THISDIR}/ot-br-posix:"
 
-SRC_URI_append = "file://60-otbr-ip-forward.conf"
+SRC_URI_append = " \
+                  file://60-otbr-ip-forward.conf \
+                  file://otbr-configuration \
+                  file://otbr-configuration.service \
+                 "
 
 do_install_append() {
     install -d ${D}${sysconfdir}/sysctl.d/
     install -m 0644 ${WORKDIR}/60-otbr-ip-forward.conf ${D}${sysconfdir}/sysctl.d/
+    install -D ${WORKDIR}/otbr-configuration ${D}${sbindir}/
+    install -D -m 0644 ${WORKDIR}/otbr-configuration.service ${D}${systemd_unitdir}/system/
 }
+
+SYSTEMD_SERVICE_${PN} += " otbr-configuration.service"
-- 
GitLab