-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c2d657e
commit 173a2cf
Showing
3 changed files
with
223 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
# Copyright (c) 2020, The OpenThread Authors. | ||
# Copyright (c) 2023-2024 Project CHIP 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. | ||
|
||
include $(TOPDIR)/rules.mk | ||
|
||
PKG_NAME:=openthread-br | ||
PKG_RELEASE:=1 | ||
PKG_SOURCE_URL:=https://github.com/openthread/ot-br-posix.git | ||
PKG_SOURCE_PROTO:=git | ||
PKG_SOURCE_MIRROR:=0 # don't try OpenWrt mirror | ||
|
||
PKG_SOURCE_DATE:=2024-08-24 | ||
PKG_SOURCE_VERSION:=f2c799d154aed339e66c0dd85f6109bd9d91c5a9 | ||
PKG_MIRROR_HASH:=e79e70c0e6ca9341ff820915e4a0926c920cd5fe9bc4b81813f3e99e5086bd07 | ||
|
||
PKG_LICENSE:=BSD-3-Clause | ||
PKG_LICENSE_FILES:=LICENSE | ||
|
||
include $(INCLUDE_DIR)/package.mk | ||
include $(INCLUDE_DIR)/cmake.mk | ||
|
||
# Disable firewall integration due to https://github.com/openthread/ot-br-posix/issues/1675 | ||
CMAKE_OPTIONS+= \ | ||
-DBUILD_TESTING=OFF \ | ||
-DCMAKE_INSTALL_PREFIX=/usr \ | ||
-DOTBR_BORDER_AGENT=ON \ | ||
-DOTBR_BORDER_ROUTING=ON \ | ||
-DOTBR_INFRA_IF_NAME=br-lan \ | ||
-DOTBR_MDNS="avahi" \ | ||
-DOTBR_OPENWRT=ON \ | ||
-DOTBR_SRP_ADVERTISING_PROXY=ON \ | ||
-DOT_FIREWALL=OFF \ | ||
-DOT_POSIX_SETTINGS_PATH=\"/etc/openthread\" \ | ||
-DOT_READLINE=OFF \ | ||
-DOTBR_NAT64=OFF \ | ||
-DNAT64_SERVICE=\"openthread\" | ||
|
||
# OpenWrt uses /var/run instead of /run | ||
TARGET_CFLAGS += -DOPENTHREAD_POSIX_CONFIG_DAEMON_SOCKET_BASENAME=\\\"/var/run/openthread-%s\\\" | ||
|
||
define Package/openthread-br | ||
SECTION:=net | ||
CATEGORY:=Network | ||
TITLE:=OpenThread Border Router | ||
URL:=https://github.com/openthread/ot-br-posix | ||
DEPENDS:=+libstdcpp +libjson-c +libubus +libblobmsg-json +libavahi-client +avahi-daemon +kmod-usb-acm +kmod-tun | ||
endef | ||
|
||
define Package/openthread-br/description | ||
OpenThread Border Router | ||
Connects a Thread Network to the Wi-Fi / Ethernet infrastructure network. | ||
Requires a Radio Co-Processor (RCP) with appropriate firmware connected via UART / USB. | ||
endef | ||
|
||
define Package/openthread-br/install | ||
$(INSTALL_DIR) $(1)/usr/sbin | ||
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/otbr-agent $(1)/usr/sbin | ||
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/ot-ctl $(1)/usr/sbin | ||
|
||
$(INSTALL_DIR) $(1)/etc/init.d | ||
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/etc/init.d/* $(1)/etc/init.d | ||
|
||
$(INSTALL_DIR) $(1)/etc/config | ||
$(INSTALL_CONF) $(PKG_INSTALL_DIR)/etc/config/* $(1)/etc/config | ||
|
||
$(INSTALL_DIR) $(1)/usr/lib/lua/luci/controller/admin | ||
$(INSTALL_BIN) $(PKG_BUILD_DIR)/src/openwrt/controller/thread.lua $(1)/usr/lib/lua/luci/controller/admin | ||
|
||
$(INSTALL_DIR) $(1)/usr/lib/lua/luci/view | ||
$(CP) $(PKG_BUILD_DIR)/src/openwrt/view/admin_thread $(1)/usr/lib/lua/luci/view | ||
|
||
$(INSTALL_DIR) $(1)/www/luci-static/resources | ||
$(CP) $(PKG_BUILD_DIR)/src/openwrt/handle_error.js $(1)/www/luci-static/resources | ||
endef | ||
|
||
$(eval $(call BuildPackage,openthread-br)) |
121 changes: 121 additions & 0 deletions
121
third_party/openthread-br/patches/010-init-script.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
diff --git a/etc/openwrt/openthread-br/README.md b/etc/openwrt/openthread-br/README.md | ||
index a4f918035c..af4b604e29 100644 | ||
--- a/etc/openwrt/openthread-br/README.md | ||
+++ b/etc/openwrt/openthread-br/README.md | ||
@@ -65,7 +65,7 @@ Start otbr-agent manually: | ||
/usr/sbin/otbr-agent -I wpan0 'spinel+hdlc+uart:///dev/ttyACM0?uart-baudrate=115200' | ||
``` | ||
|
||
-Edit the service file `/etc/init.d/otbr-agent` if RCP device is not `/dev/ttyACM0` and then start with: | ||
+Edit the service file `/etc/config/otbr-agent` if RCP device is not `/dev/ttyACM0` and then start with: | ||
|
||
```bash | ||
service otbr-agent start | ||
@@ -80,7 +80,7 @@ If you need to change the thread network interface (`wpan0` by default), you nee | ||
```bash | ||
service otbr-firewall stop | ||
service otbr-agent stop | ||
-uci set otbr-agent.service.thread_if_name=wpan1 | ||
+uci rename otbr-agent.wpan0=wpan1 | ||
uci commit otbr-agent | ||
service otbr-firewall start | ||
service otbr-agent start | ||
diff --git a/src/openwrt/CMakeLists.txt b/src/openwrt/CMakeLists.txt | ||
index 8237f38b42..52f90306a9 100644 | ||
--- a/src/openwrt/CMakeLists.txt | ||
+++ b/src/openwrt/CMakeLists.txt | ||
@@ -28,19 +28,19 @@ | ||
|
||
add_subdirectory(ubus) | ||
|
||
-configure_file(otbr-agent.init.in otbr-agent.init) | ||
+configure_file(otbr-agent.init.in otbr-agent.init @ONLY) | ||
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/otbr-agent.init | ||
DESTINATION ${CMAKE_INSTALL_FULL_SYSCONFDIR}/init.d | ||
RENAME otbr-agent) | ||
|
||
-configure_file(otbr-agent.uci-config.in otbr-agent.uci-config) | ||
+configure_file(otbr-agent.uci-config.in otbr-agent.uci-config @ONLY) | ||
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/otbr-agent.uci-config | ||
DESTINATION ${CMAKE_INSTALL_FULL_SYSCONFDIR}/config | ||
RENAME otbr-agent) | ||
|
||
|
||
if(OT_FIREWALL) | ||
- configure_file(otbr-firewall.init.in otbr-firewall.init) | ||
+ configure_file(otbr-firewall.init.in otbr-firewall.init @ONLY) | ||
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/otbr-firewall.init | ||
DESTINATION ${CMAKE_INSTALL_FULL_SYSCONFDIR}/init.d | ||
RENAME otbr-firewall) | ||
diff --git a/src/openwrt/otbr-agent.init.in b/src/openwrt/otbr-agent.init.in | ||
index 46505ff434..e942234fb9 100755 | ||
--- a/src/openwrt/otbr-agent.init.in | ||
+++ b/src/openwrt/otbr-agent.init.in | ||
@@ -30,15 +30,46 @@ | ||
START=90 | ||
|
||
USE_PROCD=1 | ||
+PROG=@CMAKE_INSTALL_FULL_SBINDIR@/otbr-agent | ||
|
||
-start_service() | ||
+validate_section_otbr() | ||
{ | ||
- local uci_thread_if_name=$(uci -q get otbr-agent.service.thread_if_name) | ||
- local uci_infra_if_name=$(uci -q get otbr-agent.service.infra_if_name) | ||
- local uci_uart_device=$(uci -q get otbr-agent.service.uart_device) | ||
- local uci_uart_baudrate=$(uci -q get otbr-agent.service.uart_baudrate) | ||
+ uci_load_validate otbr-agent otbr-agent "$1" "$2" \ | ||
+ 'thread_if_name:string' \ | ||
+ 'infra_if_name:string' \ | ||
+ 'uart_device:string' \ | ||
+ 'uart_baudrate:uinteger:115200' \ | ||
+ 'uart_flow_control:bool:1' | ||
+} | ||
+ | ||
+otbr_instance() | ||
+{ | ||
+ local cfg="$1" | ||
+ if [ "$2" != 0 ]; then | ||
+ echo "validation failed" | ||
+ return 1 | ||
+ fi | ||
+ if [ -z "$infra_if_name" ]; then | ||
+ echo "missing infra_if_name" | ||
+ return 1 | ||
+ fi | ||
+ if [ -z "$uart_device" ]; then | ||
+ echo "missing uart_device" | ||
+ return 1 | ||
+ fi | ||
+ | ||
+ local radio_url="spinel+hdlc+uart://${uart_device}?uart-baudrate=${uart_baudrate}" | ||
+ [ "$uart_flow_control" = 0 ] || radio_url="${radio_url}&uart-flow-control" | ||
+ [ -n "$thread_if_name" ] || thread_if_name="$cfg" | ||
|
||
procd_open_instance | ||
- procd_set_param command @CMAKE_INSTALL_FULL_SBINDIR@/otbr-agent -I $uci_thread_if_name -B $uci_infra_if_name spinel+hdlc+uart://$uci_uart_device?uart-baudrate=$uci_uart_baudrate trel://$uci_infra_if_name | ||
+ procd_set_param command "$PROG" -I "$thread_if_name" -B "$infra_if_name" "$radio_url" "trel://${infra_if_name}" | ||
+ procd_set_param respawn | ||
procd_close_instance | ||
} | ||
+ | ||
+start_service() | ||
+{ | ||
+ config_load otbr-agent | ||
+ config_foreach validate_section_otbr otbr-agent otbr_instance | ||
+} | ||
diff --git a/src/openwrt/otbr-agent.uci-config.in b/src/openwrt/otbr-agent.uci-config.in | ||
index 855d708852..d80d91b5ff 100644 | ||
--- a/src/openwrt/otbr-agent.uci-config.in | ||
+++ b/src/openwrt/otbr-agent.uci-config.in | ||
@@ -1,5 +1,5 @@ | ||
-config otbr-agent 'service' | ||
- option thread_if_name "wpan0" | ||
- option infra_if_name "eth0" | ||
- option uart_device "/dev/ttyACM0" | ||
- option uart_baudrate 115200 | ||
+config otbr-agent 'wpan0' | ||
+ option infra_if_name '@OTBR_INFRA_IF_NAME@' | ||
+ option uart_device '/dev/ttyACM0' | ||
+ option uart_baudrate '115200' | ||
+ option uart_flow_control '1' |