3 # SPDX-FileCopyrightText: 2023 Stijn Tintel <stijn@linux-ipv6.be>
4 # SPDX-License-Identifier: GPL-2.0-only
6 OTCTL
="/usr/sbin/ot-ctl"
7 PROG
="/usr/sbin/otbr-agent"
9 [ -x "$PROG" ] ||
exit 0
11 [ -n "$INCLUDE_ONLY" ] ||
{
13 .
/lib
/functions
/network.sh
18 proto_openthread_add_prefix
() {
20 # shellcheck disable=SC2086
21 [ -n "$prefix" ] && $OTCTL prefix add
$prefix
24 proto_openthread_check_service
() {
28 json_add_string name
"$service"
29 ubus call service list
"$(json_dump)" | jsonfilter
-e '@[*].instances[*]["running"]' > /dev
/null
36 proto_openthread_init_config
() {
37 proto_config_add_array
'prefix:list(string)'
38 proto_config_add_boolean verbose
39 proto_config_add_string backbone_network
40 proto_config_add_string dataset
41 proto_config_add_string radio_url
42 proto_config_add_string foobar
48 proto_openthread_setup_error
() {
51 proto_notify_error
"$interface" "$error"
52 # prevent netifd from trying to bring up interface over and over
53 proto_block_restart
"$interface"
54 proto_setup_failed
"$interface"
58 proto_openthread_setup
() {
62 json_get_vars backbone_network dataset device radio_url verbose
:0
64 [ -n "$backbone_network" ] || proto_openthread_setup_error
"$interface" MISSING_BACKBONE_NETWORK
65 proto_add_host_dependency
"$interface" "" "$backbone_network"
66 network_get_device backbone_ifname
"$backbone_network"
68 [ -n "$backbone_ifname" ] || proto_openthread_setup_error
"$interface" MISSING_BACKBONE_IFNAME
69 [ -n "$device" ] || proto_openthread_setup_error
"$interface" MISSING_DEVICE
70 [ -n "$radio_url" ] || proto_openthread_setup_error
"$interface" MISSING_RADIO_URL
72 # run in subshell to prevent wiping json data needed for prefixes
73 ( proto_openthread_check_service mdnsd
) || proto_openthread_setup_error
"$interface" MISSING_SVC_MDNSD
75 opts
="--auto-attach=0"
76 [ "$verbose" -eq 0 ] || append opts
-v
77 append opts
"-I$device"
78 append opts
"-B$backbone_ifname"
79 append opts
"$radio_url"
80 append opts
"trel://$backbone_ifname"
81 # run in subshell to prevent wiping json data needed for prefixes
82 ( proto_run_command
"$interface" "$PROG" $opts )
84 ubus
-t30 wait_for otbr
86 [ -n "$dataset" ] && {
87 $OTCTL dataset
set active
"$dataset"
90 json_for_each_item proto_openthread_add_prefix prefix
91 ubus call otbr threadstart || proto_openthread_setup_error
"$interface" MISSING_UBUS_OBJ
92 $OTCTL netdata register
94 proto_init_update
"$device" 1 1
95 proto_send_update
"$interface"
98 proto_openthread_teardown
() {
100 ubus call otbr threadstop
101 proto_kill_command
"$interface"
104 [ -n "$INCLUDE_ONLY" ] ||
{
105 add_protocol openthread