From patchwork Sat Apr 13 23:25:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [v2,10/10] Add support for second port of Nanostation M From: Adrian Schmutzler X-Patchwork-Id: 1058 Message-Id: <20190413232535.9834-11-freifunk@adrianschmutzler.de> To: franken-dev@freifunk.net Date: Sun, 14 Apr 2019 01:25:35 +0200 Signed-off-by: Adrian Schmutzler Reviewed-by: Christian Dresel --- This is not tested. Changes in v2: - Added patch --- .../files/etc/uci-defaults/22b-config-ports | 6 +++- .../files/lib/functions/fff/networksetup | 33 ++++++++++++++++++++++ .../fff/fff-network/files/usr/sbin/settwoeth | 26 +++++++++++++++++ 3 files changed, 64 insertions(+), 1 deletion(-) create mode 100755 src/packages/fff/fff-network/files/usr/sbin/settwoeth diff --git a/src/packages/fff/fff-network/files/etc/uci-defaults/22b-config-ports b/src/packages/fff/fff-network/files/etc/uci-defaults/22b-config-ports index e2887228..372a6c59 100644 --- a/src/packages/fff/fff-network/files/etc/uci-defaults/22b-config-ports +++ b/src/packages/fff/fff-network/files/etc/uci-defaults/22b-config-ports @@ -71,6 +71,11 @@ case "$BOARD" in setupSwitch "eth0" "1 2 0t" "3 4 0t" "5 0t" setupWan "eth0.2" ;; + ubnt-nano-m) + setupOnePort "eth0" "WAN" + setup2ndEth "eth1" "CLIENT" + uci -q set "fff.ui.portsetup=twoeth" + ;; cpe210-v2|\ cpe210-v3|\ tl-mr3020-v1|\ @@ -80,7 +85,6 @@ case "$BOARD" in ubnt-bullet-m|\ ubnt-loco-m|\ ubnt-loco-m-xw|\ - ubnt-nano-m|\ ubnt-pico-m|\ ubnt-power-m-xw|\ ubnt-unifi|\ diff --git a/src/packages/fff/fff-network/files/lib/functions/fff/networksetup b/src/packages/fff/fff-network/files/lib/functions/fff/networksetup index d9f91200..0478cf59 100644 --- a/src/packages/fff/fff-network/files/lib/functions/fff/networksetup +++ b/src/packages/fff/fff-network/files/lib/functions/fff/networksetup @@ -161,3 +161,36 @@ setupOnePort() { fi uci commit network } + +setup2ndEth() { + # Set up second port for devices with to ports directly connected to ethX (no switch) + # This is intended for initial setup and for updates + # + # Use this in combination with setupOnePort() for the first port. + # Calling setupOnePort() will overwrite the settings made here, so always call in succession, e.g. + # setupOnePort eth0 "WAN" + # setup2ndEth eth1 "BATMAN" + # + # Usage: setup2ndEth + + local DEV=$1 + local ETHMODE=$2 + + uci set "network.$DEV=interface" + uci set "network.$DEV.ifname=$DEV" + + local meshif="$(uci -q get network.mesh.ifname | sed "s/ *$DEV//")" + local ethmeshif="$(uci -q get network.ethmesh.ifname | sed "s/ *$DEV//")" + if [ "$ETHMODE" = "CLIENT" ] ; then + uci set network.mesh.ifname="$meshif $DEV" + if [ -n "$ethmesif" ]; then + uci set network.ethmesh.ifname="$ethmesif" + else + uci del network.ethmesh.ifname + fi + else # default=BATMAN + uci set network.mesh.ifname="$meshif" + uci set network.ethmesh.ifname="$ethmesif $DEV" + fi + uci commit network +} diff --git a/src/packages/fff/fff-network/files/usr/sbin/settwoeth b/src/packages/fff/fff-network/files/usr/sbin/settwoeth new file mode 100755 index 00000000..b2489789 --- /dev/null +++ b/src/packages/fff/fff-network/files/usr/sbin/settwoeth @@ -0,0 +1,26 @@ +#!/bin/sh + +if ! [ "$(uci -q get fff.ui.portsetup)" = "twoeth" ] ; then + echo "Wrong device. This is for Nanostation M only!" + exit 1 +fi + +. /lib/functions/fff/networksetup + +ETHMODE1=$1 +ETHMODE2=$2 + +if ! ([ "$ETHMODE1" = "WAN" ] || [ "$ETHMODE1" = "CLIENT" ] || [ "$ETHMODE1" = "BATMAN" ]); then + echo "Wrong port mode for first port. Choose one of: WAN, CLIENT, BATMAN" + exit 1 +fi +if ! ([ "$ETHMODE2" = "CLIENT" ] || [ "$ETHMODE2" = "BATMAN" ]); then + echo "Wrong port mode for second port. Choose one of: CLIENT, BATMAN" + exit 1 +fi + +setupOnePort "eth0" "$ETHMODE1" +setup2ndEth "eth1" "$ETHMODE2" +/etc/init.d/network restart +echo "Port updated successfully." +