From patchwork Sun Jan 21 14:47:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [v3, 1/2] fff-config: Provide options to permanently disable WiFi devices From: Adrian Schmutzler X-Patchwork-Id: 756 Message-Id: <1516546069-2586-1-git-send-email-freifunk@adrianschmutzler.de> To: franken-dev@freifunk.net Date: Sun, 21 Jan 2018 15:47:48 +0100 Signed-off-by: Adrian Schmutzler Tested-by: Adrian Schmutzler --- Changes in v2: none Changes in v3: - Added functions to set state Comments: - Since I set the fffconfig values in the function, I do NOT call them in the uci-default script. - I will not include the wifi command in the functions, so one can decide whether he wants to apply the settings at ones or adds something before calling WiFi --- src/packages/fff/fff-config/Makefile | 2 +- .../files/etc/uci-defaults/98-configure-fff | 21 ++++++ .../fff-wireless/files/lib/functions/fff/wireless | 86 ++++++++++++++++++++++ 3 files changed, 108 insertions(+), 1 deletion(-) diff --git a/src/packages/fff/fff-config/Makefile b/src/packages/fff/fff-config/Makefile index fe4f5df..690719a 100644 --- a/src/packages/fff/fff-config/Makefile +++ b/src/packages/fff/fff-config/Makefile @@ -1,7 +1,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=fff-config -PKG_VERSION:=1 +PKG_VERSION:=2 PKG_RELEASE:=1 PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME) diff --git a/src/packages/fff/fff-config/files/etc/uci-defaults/98-configure-fff b/src/packages/fff/fff-config/files/etc/uci-defaults/98-configure-fff index aa6ac42..02d716c 100644 --- a/src/packages/fff/fff-config/files/etc/uci-defaults/98-configure-fff +++ b/src/packages/fff/fff-config/files/etc/uci-defaults/98-configure-fff @@ -28,3 +28,24 @@ poe_passthrough=$(uci -q get "fff.poe_passthrough.active") if [ "$poe_passthrough" = "1" ] && [ -s /usr/lib/fff-support/activate_poe_passthrough.sh ] ; then /usr/lib/fff-support/activate_poe_passthrough.sh fi + +. /lib/functions/fff/wireless + +if [ "$(uci -q get 'fff.wifi.disable24ghz')" = "1" ] ; then + radio="$(wifiGetPhy "2")" + [ -n "$radio" ] && uci -q set "wireless.${radio}.disabled=1" +fi + +if [ "$(uci -q get 'fff.wifi.disable5ghz')" = "1" ] ; then + radio="$(wifiGetPhy "5")" + [ -n "$radio" ] && uci -q set "wireless.${radio}.disabled=1" +fi + +if [ "$(uci -q get 'fff.wifi.disablewifi')" = "1" ] ; then + for phy in $(iw phy | awk '/^Wiphy/{ print $2 }'); do + radio="radio$(echo "$phy" | tr -d -C "0-9")" + uci -q set "wireless.${radio}.disabled=1" + done +fi + +uci -q commit wireless diff --git a/src/packages/fff/fff-wireless/files/lib/functions/fff/wireless b/src/packages/fff/fff-wireless/files/lib/functions/fff/wireless index 5b63397..ae70791 100644 --- a/src/packages/fff/fff-wireless/files/lib/functions/fff/wireless +++ b/src/packages/fff/fff-wireless/files/lib/functions/fff/wireless @@ -228,4 +228,90 @@ wifiAddMesh() { echo "${iface}" return 0 } + +wifiGetPhy() { + # Returns the wifi-device (radioX) for a given frequency (2 or 5) + + if [ $# -ne "1" ] + then + return 1 + fi + + local freq=$1 + local radio="" + + for phy in $(iw phy | awk '/^Wiphy/{ print $2 }'); do + if iw phy "$phy" info | grep -q -m1 "${freq}... MHz"; then + radio="radio$(echo "$phy" | tr -d -C "0-9")" + fi + done + + echo "$radio" + return 0 # also returns success if outermost if is false +} + +wifiSetActive() { + # En- or disables WiFi permanently (upgrade-safe) + # + # wifiSetActive + # + # freq: 2 or 5 + # setto: 0 (disabled) or 1 (enabled) + + if [ $# -ne "2" ] + then + return 1 + fi + + local freq=$1 + local setto=$2 + + [ "$setto" = "1" ] && disabled="0" || disabled="1" + + radio="$(wifiGetPhy "$freq")" + if [ -n "$radio" ] ; then + uci -q set fff.wifi=fff + if [ "$freq" = "2" ] ; then + uci -q set "fff.wifi.disable24ghz=$disabled" + else + uci -q set "fff.wifi.disable5ghz=$disabled" + fi + uci -q set "wireless.${radio}.disabled=$disabled" + else + return 1 + fi + uci -q commit fff + uci -q commit wireless + + return 0 +} + +wifiSetAllActive() { + # En- or disables all WiFi interfaces permanently (upgrade-safe) + # + # wifiSetActive + # + # setto: 0 (disabled) or 1 (enabled) + + if [ $# -ne "1" ] + then + return 1 + fi + + local setto=$1 + + [ "$setto" = "1" ] && disabled="0" || disabled="1" + + uci -q set fff.wifi=fff + uci -q set "fff.wifi.disablewifi=$disabled" + for phy in $(iw phy | awk '/^Wiphy/{ print $2 }'); do + radio="radio$(echo "$phy" | tr -d -C "0-9")" + uci -q set "wireless.${radio}.disabled=$disabled" + done + uci -q commit fff + uci -q commit wireless + + return 0 +} + # vim: set noexpandtab:tabstop=4