1#!/bin/bash 2# 3# Copyright (c) 2022, The OpenThread Authors. 4# All rights reserved. 5# 6# Redistribution and use in source and binary forms, with or without 7# modification, are permitted provided that the following conditions are met: 8# 1. Redistributions of source code must retain the above copyright 9# notice, this list of conditions and the following disclaimer. 10# 2. Redistributions in binary form must reproduce the above copyright 11# notice, this list of conditions and the following disclaimer in the 12# documentation and/or other materials provided with the distribution. 13# 3. Neither the name of the copyright holder nor the 14# names of its contributors may be used to endorse or promote products 15# derived from this software without specific prior written permission. 16# 17# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 21# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27# POSSIBILITY OF SUCH DAMAGE. 28 29set -euxo pipefail 30 31SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" 32readonly SCRIPT_DIR 33 34ABS_TOP_BUILDDIR="$(cd "${top_builddir:-"${SCRIPT_DIR}"/../../}" && pwd)" 35readonly ABS_TOP_BUILDDIR 36 37OTBR_AGENT="${ABS_TOP_BUILDDIR}/src/agent/otbr-agent" 38readonly OTBR_AGENT 39 40OT_CTL="${ABS_TOP_BUILDDIR}/third_party/openthread/repo/src/posix/ot-ctl" 41readonly OT_CTL 42 43OT_RCP=$(command -v ot-rcp) 44readonly OT_RCP 45 46at_exit() 47{ 48 EXIT_CODE=$? 49 50 sudo killall otbr-agent || true 51 52 exit $EXIT_CODE 53} 54 55trap at_exit INT TERM EXIT 56 57sudo "${OTBR_AGENT}" -I wpan0 -v -d 6 "spinel+hdlc+forkpty://${OT_RCP}?forkpty-arg=1" --auto-attach=invalid && exit 1 58sudo "${OTBR_AGENT}" -I wpan0 -v -d 6 "spinel+hdlc+forkpty://${OT_RCP}?forkpty-arg=1" --auto-attach= && exit 1 59sudo "${OTBR_AGENT}" -I wpan0 -v -d 6 "spinel+hdlc+forkpty://${OT_RCP}?forkpty-arg=1" --auto-attach=99999999999999999999999999999999999 && exit 1 60 61sudo cp "${ABS_TOP_BUILDDIR}/src/agent/otbr-agent.conf" /etc/dbus-1/system.d/ 62sudo chmod +r /etc/dbus-1/system.d/otbr-agent.conf 63sudo systemctl reload dbus 64 65sudo "${OTBR_AGENT}" -I wpan0 -v -d 6 "spinel+hdlc+forkpty://${OT_RCP}?forkpty-arg=1" & 66sleep 10 67sudo "${OT_CTL}" factoryreset 68sleep 1 69sudo "${OT_CTL}" dataset init new 70sudo "${OT_CTL}" dataset commit active 71sudo "${OT_CTL}" ifconfig up 72sudo "${OT_CTL}" thread start 73sleep 10 74sudo "${OT_CTL}" state | grep "leader" 75 76sudo killall otbr-agent 77sleep 10 78sudo "${OTBR_AGENT}" -I wpan0 -v -d 6 "spinel+hdlc+forkpty://${OT_RCP}?forkpty-arg=1" --auto-attach=0 & 79sleep 10 80sudo "${OT_CTL}" state | grep "disabled" 81 82sudo killall otbr-agent 83sleep 10 84sudo "${OTBR_AGENT}" -I wpan0 -v -d 6 "spinel+hdlc+forkpty://${OT_RCP}?forkpty-arg=1" --auto-attach=1 & 85sleep 40 86sudo "${OT_CTL}" state | grep "leader" 87 88sudo killall otbr-agent 89sleep 10 90sudo "${OTBR_AGENT}" -I wpan0 -v -d 6 "spinel+hdlc+forkpty://${OT_RCP}?forkpty-arg=1" --auto-attach & 91sleep 40 92sudo "${OT_CTL}" state | grep "leader" 93sudo "${OT_CTL}" reset 94sleep 1 95sudo "${OT_CTL}" state | grep "disabled" 96