From c5631d3725d7c40fa72360ae25ae11c8245915d3 Mon Sep 17 00:00:00 2001 From: David Wagner Date: Sat, 17 Aug 2024 15:47:46 +0200 Subject: [PATCH] wrt: Configure Wi-Fi repeater using AP+STA mode --- router/config-ap-sta | 49 ++++++++++++++++++++++++++++++++++++++++++++ router/setup.sh | 2 +- 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 router/config-ap-sta diff --git a/router/config-ap-sta b/router/config-ap-sta new file mode 100644 index 0000000..e837cb4 --- /dev/null +++ b/router/config-ap-sta @@ -0,0 +1,49 @@ +#!/bin/sh +# Setup Wi-Fi Repeater using AP+STA mode +# Reference: https://openwrt.org/docs/guide-user/network/wifi/wifiextenders/ap_sta +set -o errexit + +if [ "$#" -ne 2 ]; then + echo "Usage: $0 WIFI_SSID WIFI_KEY" >&2 + exit 1 +fi + +WIFI_SSID="$1" +WIFI_KEY="$2" + +# Add the WWAN network is in the WAN firewall zone +while uci -q delete firewall.@zone[1].network; do :; done +uci add_list firewall.@zone[1].network="wan" +uci add_list firewall.@zone[1].network="wan6" +uci add_list firewall.@zone[1].network="wwan" + +# The WWAN interface is the "uplink". It obtains a DHCP address from the upstream hotspot. +uci set network.wwan="interface" +uci set network.wwan.proto="dhcp" + +# Add the Wi-Fi interface for the uplink. +uci set wireless.wwan="wifi-iface" +uci set wireless.wwan.device="radio0" +uci set wireless.wwan.network="wwan" +uci set wireless.wwan.mode="sta" + +uci set wireless.wwan.encryption="psk2" +uci set wireless.wwan.ssid="$WIFI_SSID" +uci set wireless.wwan.key="$WIFI_KEY" + +CHANGES=$(uci changes) +if [ -n "$CHANGES" ]; then + echo "Changes:" + uci changes + echo "" + echo "" + echo "This script doesn't restart any services. You may need to run:" + echo "- service firewall restart" + echo "- service network restart" + echo "- wifi reload" + echo "" + echo "Or just reboot the device" +else + echo "No changes. Configuration is up-to-date!" +fi +uci commit diff --git a/router/setup.sh b/router/setup.sh index 63d7f87..318d4f4 100755 --- a/router/setup.sh +++ b/router/setup.sh @@ -11,4 +11,4 @@ HERE=$(dirname "$(readlink -f "$0")") $SSH_COMMAND sh -s \ "$(printf "%q" "$(pass Home/wifi_ssid)")" \ "$(printf "%q" "$(pass Home/wifi_key)")" \ - < "$HERE"/config + < <(cat "$HERE"/config "$HERE"/config-ap-sta)