From bfea9bc0c100087d798ca20026419a05c3c06477 Mon Sep 17 00:00:00 2001 From: Tim Lunn Date: Tue, 26 Mar 2024 23:12:07 +1100 Subject: [PATCH 01/10] Add socat network socket support for otbr addon --- openthread_border_router/config.yaml | 3 ++- .../s6-overlay/s6-rc.d/socat-otbr-tcp/data/check | 4 ++++ .../s6-rc.d/socat-otbr-tcp/notification-fd | 1 + .../etc/s6-overlay/s6-rc.d/socat-otbr-tcp/run | 13 +++++++++++++ .../etc/s6-overlay/s6-rc.d/socat-otbr-tcp/type | 1 + .../scripts/socat-otbr-tcp-enable-check.sh | 10 ++++++++++ 6 files changed, 31 insertions(+), 1 deletion(-) create mode 100755 openthread_border_router/rootfs/etc/s6-overlay/s6-rc.d/socat-otbr-tcp/data/check create mode 100644 openthread_border_router/rootfs/etc/s6-overlay/s6-rc.d/socat-otbr-tcp/notification-fd create mode 100755 openthread_border_router/rootfs/etc/s6-overlay/s6-rc.d/socat-otbr-tcp/run create mode 100644 openthread_border_router/rootfs/etc/s6-overlay/s6-rc.d/socat-otbr-tcp/type create mode 100755 openthread_border_router/rootfs/etc/s6-overlay/scripts/socat-otbr-tcp-enable-check.sh diff --git a/openthread_border_router/config.yaml b/openthread_border_router/config.yaml index 275a0ab66bf..daff5b8cba5 100644 --- a/openthread_border_router/config.yaml +++ b/openthread_border_router/config.yaml @@ -37,9 +37,10 @@ ports_description: 8080/tcp: OpenThread Web port 8081/tcp: OpenThread REST API port schema: - device: device(subsystem=tty) + device: device(subsystem=tty)? baudrate: list(57600|115200|230400|460800|921600) flow_control: bool + network_device: str? autoflash_firmware: bool otbr_log_level: list(debug|info|notice|warning|error|critical|alert|emergency) firewall: bool diff --git a/openthread_border_router/rootfs/etc/s6-overlay/s6-rc.d/socat-otbr-tcp/data/check b/openthread_border_router/rootfs/etc/s6-overlay/s6-rc.d/socat-otbr-tcp/data/check new file mode 100755 index 00000000000..b41abdafe79 --- /dev/null +++ b/openthread_border_router/rootfs/etc/s6-overlay/s6-rc.d/socat-otbr-tcp/data/check @@ -0,0 +1,4 @@ +#!/bin/sh + +test -c /tmp/ttyOTBR +exit diff --git a/openthread_border_router/rootfs/etc/s6-overlay/s6-rc.d/socat-otbr-tcp/notification-fd b/openthread_border_router/rootfs/etc/s6-overlay/s6-rc.d/socat-otbr-tcp/notification-fd new file mode 100644 index 00000000000..00750edc07d --- /dev/null +++ b/openthread_border_router/rootfs/etc/s6-overlay/s6-rc.d/socat-otbr-tcp/notification-fd @@ -0,0 +1 @@ +3 diff --git a/openthread_border_router/rootfs/etc/s6-overlay/s6-rc.d/socat-otbr-tcp/run b/openthread_border_router/rootfs/etc/s6-overlay/s6-rc.d/socat-otbr-tcp/run new file mode 100755 index 00000000000..a2084ea7dac --- /dev/null +++ b/openthread_border_router/rootfs/etc/s6-overlay/s6-rc.d/socat-otbr-tcp/run @@ -0,0 +1,13 @@ +#!/usr/bin/with-contenv bashio +# ============================================================================== +# Start socat TCP client for CPC daemon +# ============================================================================== + +declare network_device + +network_device=$(bashio::config 'network_device') + +bashio::log.info "Starting socat TCP client for OTBR daemon..." +exec s6-notifyoncheck -d -s 300 -w 300 \ + "/usr/bin/socat" -d pty,raw,echo=0,link=/tmp/ttyOTBR,ignoreeof \ + "tcp:${network_device}" diff --git a/openthread_border_router/rootfs/etc/s6-overlay/s6-rc.d/socat-otbr-tcp/type b/openthread_border_router/rootfs/etc/s6-overlay/s6-rc.d/socat-otbr-tcp/type new file mode 100644 index 00000000000..5883cff0cd1 --- /dev/null +++ b/openthread_border_router/rootfs/etc/s6-overlay/s6-rc.d/socat-otbr-tcp/type @@ -0,0 +1 @@ +longrun diff --git a/openthread_border_router/rootfs/etc/s6-overlay/scripts/socat-otbr-tcp-enable-check.sh b/openthread_border_router/rootfs/etc/s6-overlay/scripts/socat-otbr-tcp-enable-check.sh new file mode 100755 index 00000000000..7f9c4ecefb2 --- /dev/null +++ b/openthread_border_router/rootfs/etc/s6-overlay/scripts/socat-otbr-tcp-enable-check.sh @@ -0,0 +1,10 @@ +#!/usr/bin/with-contenv bashio +# ============================================================================== +# Enable socat-otbr-tcp service if needed +# ============================================================================== + +if bashio::config.has_value 'network_device'; then + touch /etc/s6-overlay/s6-rc.d/user/contents.d/socat-otbr-tcp + touch /etc/s6-overlay/s6-rc.d/otbr-agent/dependencies.d/socat-otbr-tcp + bashio::log.info "Enabled socat-otbr-tcp." +fi From 49f31797d7f60aab94a9448d6ffa73edb715cd0c Mon Sep 17 00:00:00 2001 From: Tim Lunn Date: Tue, 26 Mar 2024 23:17:20 +1100 Subject: [PATCH 02/10] Use socat device in otbr-agent --- .../rootfs/etc/s6-overlay/s6-rc.d/otbr-agent/run | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/openthread_border_router/rootfs/etc/s6-overlay/s6-rc.d/otbr-agent/run b/openthread_border_router/rootfs/etc/s6-overlay/s6-rc.d/otbr-agent/run index 41dea6a24f4..f2e7bd0c32a 100755 --- a/openthread_border_router/rootfs/etc/s6-overlay/s6-rc.d/otbr-agent/run +++ b/openthread_border_router/rootfs/etc/s6-overlay/s6-rc.d/otbr-agent/run @@ -16,6 +16,11 @@ declare otbr_rest_listen_port backbone_if="$(bashio::api.supervisor 'GET' '/network/info' '' 'first(.interfaces[] | select (.primary == true)) .interface')" device=$(bashio::config 'device') + +if bashio::config.has_value 'network_device'; then + device="/tmp/ttyOTBR" +fi + baudrate=$(bashio::config 'baudrate') flow_control="" From 31bb43b00db44aa313e07f58bb565a3a849d3591 Mon Sep 17 00:00:00 2001 From: Tim Lunn Date: Mon, 25 Mar 2024 18:16:12 +1100 Subject: [PATCH 03/10] Include socat in Docker image --- openthread_border_router/Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/openthread_border_router/Dockerfile b/openthread_border_router/Dockerfile index 69f7d257faf..9cb2e401fe1 100644 --- a/openthread_border_router/Dockerfile +++ b/openthread_border_router/Dockerfile @@ -43,6 +43,7 @@ RUN \ python3-pip \ lsb-release \ netcat-openbsd \ + socat \ sudo \ git \ nodejs \ From cc5e1bfc4b0674f8600a743169afbe3ee22fb1b1 Mon Sep 17 00:00:00 2001 From: Tim Lunn Date: Mon, 25 Mar 2024 18:36:21 +1100 Subject: [PATCH 04/10] Add socat service to enable check --- openthread_border_router/Dockerfile | 2 +- .../rootfs/etc/s6-overlay/scripts/enable-check.sh | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100755 openthread_border_router/rootfs/etc/s6-overlay/scripts/enable-check.sh diff --git a/openthread_border_router/Dockerfile b/openthread_border_router/Dockerfile index 9cb2e401fe1..af5c9ba6d05 100644 --- a/openthread_border_router/Dockerfile +++ b/openthread_border_router/Dockerfile @@ -105,4 +105,4 @@ RUN \ COPY rootfs / ENV \ - S6_STAGE2_HOOK=/etc/s6-overlay/scripts/otbr-web-enable-check.sh + S6_STAGE2_HOOK=/etc/s6-overlay/scripts/enable-check.sh diff --git a/openthread_border_router/rootfs/etc/s6-overlay/scripts/enable-check.sh b/openthread_border_router/rootfs/etc/s6-overlay/scripts/enable-check.sh new file mode 100755 index 00000000000..ec75e762a9b --- /dev/null +++ b/openthread_border_router/rootfs/etc/s6-overlay/scripts/enable-check.sh @@ -0,0 +1,2 @@ +/etc/s6-overlay/scripts/otbr-web-enable-check.sh +/etc/s6-overlay/scripts/socat-otbr-tcp-enable-check.sh \ No newline at end of file From 440eda9f90c33808f34db2e386b8578247be2d19 Mon Sep 17 00:00:00 2001 From: Tim Lunn Date: Wed, 3 Apr 2024 23:26:11 +1100 Subject: [PATCH 05/10] squash enable checks into enable-check hook script --- .../etc/s6-overlay/scripts/enable-check.sh | 24 +++++++++++++++++-- .../scripts/otbr-web-enable-check.sh | 12 ---------- .../scripts/socat-otbr-tcp-enable-check.sh | 10 -------- 3 files changed, 22 insertions(+), 24 deletions(-) delete mode 100755 openthread_border_router/rootfs/etc/s6-overlay/scripts/otbr-web-enable-check.sh delete mode 100755 openthread_border_router/rootfs/etc/s6-overlay/scripts/socat-otbr-tcp-enable-check.sh diff --git a/openthread_border_router/rootfs/etc/s6-overlay/scripts/enable-check.sh b/openthread_border_router/rootfs/etc/s6-overlay/scripts/enable-check.sh index ec75e762a9b..072b3ff21f2 100755 --- a/openthread_border_router/rootfs/etc/s6-overlay/scripts/enable-check.sh +++ b/openthread_border_router/rootfs/etc/s6-overlay/scripts/enable-check.sh @@ -1,2 +1,22 @@ -/etc/s6-overlay/scripts/otbr-web-enable-check.sh -/etc/s6-overlay/scripts/socat-otbr-tcp-enable-check.sh \ No newline at end of file +#!/usr/bin/with-contenv bashio +# ============================================================================== +# Disable OTBR Web if necessary ports are not exposed +# ============================================================================== + +if bashio::var.has_value "$(bashio::addon.port 8080)" \ + && bashio::var.has_value "$(bashio::addon.port 8081)"; then + bashio::log.info "Web UI and REST API port are exposed, starting otbr-web." +else + rm /etc/s6-overlay/s6-rc.d/user/contents.d/otbr-web + bashio::log.info "The otbr-web is disabled." +fi + +# ============================================================================== +# Enable socat-otbr-tcp service if needed +# ============================================================================== + +if bashio::config.has_value 'network_device'; then + touch /etc/s6-overlay/s6-rc.d/user/contents.d/socat-otbr-tcp + touch /etc/s6-overlay/s6-rc.d/otbr-agent/dependencies.d/socat-otbr-tcp + bashio::log.info "Enabled socat-otbr-tcp." +fi diff --git a/openthread_border_router/rootfs/etc/s6-overlay/scripts/otbr-web-enable-check.sh b/openthread_border_router/rootfs/etc/s6-overlay/scripts/otbr-web-enable-check.sh deleted file mode 100755 index 8bd256fd9f1..00000000000 --- a/openthread_border_router/rootfs/etc/s6-overlay/scripts/otbr-web-enable-check.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/with-contenv bashio -# ============================================================================== -# Disable OTBR Web if necessary ports are not exposed -# ============================================================================== - -if bashio::var.has_value "$(bashio::addon.port 8080)" \ - && bashio::var.has_value "$(bashio::addon.port 8081)"; then - bashio::log.info "Web UI and REST API port are exposed, starting otbr-web." -else - rm /etc/s6-overlay/s6-rc.d/user/contents.d/otbr-web - bashio::log.info "The otbr-web is disabled." -fi diff --git a/openthread_border_router/rootfs/etc/s6-overlay/scripts/socat-otbr-tcp-enable-check.sh b/openthread_border_router/rootfs/etc/s6-overlay/scripts/socat-otbr-tcp-enable-check.sh deleted file mode 100755 index 7f9c4ecefb2..00000000000 --- a/openthread_border_router/rootfs/etc/s6-overlay/scripts/socat-otbr-tcp-enable-check.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/with-contenv bashio -# ============================================================================== -# Enable socat-otbr-tcp service if needed -# ============================================================================== - -if bashio::config.has_value 'network_device'; then - touch /etc/s6-overlay/s6-rc.d/user/contents.d/socat-otbr-tcp - touch /etc/s6-overlay/s6-rc.d/otbr-agent/dependencies.d/socat-otbr-tcp - bashio::log.info "Enabled socat-otbr-tcp." -fi From 6e35e9b08eefa60942ea90cb6a86195a13f26df3 Mon Sep 17 00:00:00 2001 From: Tim Lunn Date: Wed, 3 Apr 2024 23:29:11 +1100 Subject: [PATCH 06/10] Bump version 2.6.0 --- openthread_border_router/CHANGELOG.md | 4 ++++ openthread_border_router/config.yaml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/openthread_border_router/CHANGELOG.md b/openthread_border_router/CHANGELOG.md index 0e89831e56c..a86c4ee987b 100644 --- a/openthread_border_router/CHANGELOG.md +++ b/openthread_border_router/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 2.6.0 + +- Add support for network sockets using socat + ## 2.5.1 - Support Home Assistant Connect ZBT-1. diff --git a/openthread_border_router/config.yaml b/openthread_border_router/config.yaml index daff5b8cba5..bb28fc564a0 100644 --- a/openthread_border_router/config.yaml +++ b/openthread_border_router/config.yaml @@ -1,5 +1,5 @@ --- -version: 2.5.1 +version: 2.6.0 slug: openthread_border_router name: OpenThread Border Router description: OpenThread Border Router add-on From 1101805eed60551facff08ef9d718dc71b0dff21 Mon Sep 17 00:00:00 2001 From: TimL Date: Thu, 4 Apr 2024 18:25:04 +1100 Subject: [PATCH 07/10] Update typo in otbr run script Co-authored-by: Stefan Agner --- .../rootfs/etc/s6-overlay/s6-rc.d/socat-otbr-tcp/run | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openthread_border_router/rootfs/etc/s6-overlay/s6-rc.d/socat-otbr-tcp/run b/openthread_border_router/rootfs/etc/s6-overlay/s6-rc.d/socat-otbr-tcp/run index a2084ea7dac..9ae7451c100 100755 --- a/openthread_border_router/rootfs/etc/s6-overlay/s6-rc.d/socat-otbr-tcp/run +++ b/openthread_border_router/rootfs/etc/s6-overlay/s6-rc.d/socat-otbr-tcp/run @@ -1,6 +1,6 @@ #!/usr/bin/with-contenv bashio # ============================================================================== -# Start socat TCP client for CPC daemon +# Start socat TCP client for OTBR agent daemon # ============================================================================== declare network_device From c884b02d58ab41e32d93efa3d20748d228c85158 Mon Sep 17 00:00:00 2001 From: Tim Lunn Date: Thu, 25 Apr 2024 20:22:29 +1000 Subject: [PATCH 08/10] Add network_device to transations --- openthread_border_router/translations/en.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/openthread_border_router/translations/en.yaml b/openthread_border_router/translations/en.yaml index 22d67e1e332..194a7e54680 100644 --- a/openthread_border_router/translations/en.yaml +++ b/openthread_border_router/translations/en.yaml @@ -10,6 +10,11 @@ configuration: flow_control: name: Hardware flow control description: Enable hardware flow control for serial port. + network_device: + name: Network Device + description: >- + when connecting to a device via sockets (takes precedence + over above configuration). Not suitable for Wifi connections. autoflash_firmware: name: Automatically flash firmware description: >- From 36e640233733b7a7124cf07800f36d86a7140bf6 Mon Sep 17 00:00:00 2001 From: TimL Date: Thu, 25 Apr 2024 22:33:32 +1000 Subject: [PATCH 09/10] Update openthread_border_router/translations/en.yaml Co-authored-by: Stefan Agner --- openthread_border_router/translations/en.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/openthread_border_router/translations/en.yaml b/openthread_border_router/translations/en.yaml index 194a7e54680..46ecb6930d5 100644 --- a/openthread_border_router/translations/en.yaml +++ b/openthread_border_router/translations/en.yaml @@ -14,7 +14,8 @@ configuration: name: Network Device description: >- when connecting to a device via sockets (takes precedence - over above configuration). Not suitable for Wifi connections. + over above configuration). Not suitable for WiFi or other high latency + connections. autoflash_firmware: name: Automatically flash firmware description: >- From dedb22b8d23b73b776ea618dfa2527df9a17ecc0 Mon Sep 17 00:00:00 2001 From: Tim Lunn Date: Thu, 25 Apr 2024 22:36:29 +1000 Subject: [PATCH 10/10] drop optional schema on device, this doesnt work in conjunction with null default. --- openthread_border_router/config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openthread_border_router/config.yaml b/openthread_border_router/config.yaml index bb28fc564a0..2a9d33a8cc7 100644 --- a/openthread_border_router/config.yaml +++ b/openthread_border_router/config.yaml @@ -37,7 +37,7 @@ ports_description: 8080/tcp: OpenThread Web port 8081/tcp: OpenThread REST API port schema: - device: device(subsystem=tty)? + device: device(subsystem=tty) baudrate: list(57600|115200|230400|460800|921600) flow_control: bool network_device: str?