From patchwork Thu Oct 5 22:17:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [v2] fff-hoods: Use function for conditional wifiAddPhy From: Adrian Schmutzler X-Patchwork-Id: 532 Message-Id: <1507241877-21833-1-git-send-email-freifunk@adrianschmutzler.de> To: franken-dev@freifunk.net Date: Fri, 6 Oct 2017 00:17:57 +0200 Just a little tidying up. Apply only after fff-hoods patchset! Changes in v2: - Removed echos from function Signed-off-by: Adrian Schmutzler Tested-by: Adrian Schmutzler --- .../fff/fff-hoods/files/usr/sbin/configurehood | 39 ++++------------------ .../fff-wireless/files/lib/functions/fff/wireless | 23 +++++++++++++ 2 files changed, 30 insertions(+), 32 deletions(-) diff --git a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood index ba9a193..8155111 100755 --- a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood +++ b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood @@ -72,22 +72,10 @@ else fi #now we look for phy and add this for phy in $(iw phy | awk '/^Wiphy/{ print $2 }'); do - if iw phy "$phy" info | grep -q -m1 "2... MHz"; then - echo "$phy is 2.4 GHz" - radio="$(wifiAddPhy "$phy" "$chan2ghz")" - if [ -z "$radio" ]; then - echo "Can't create radio for $phy" - exit 1 - fi - fi - if iw phy "$phy" info | grep -q -m1 "5... MHz"; then - echo "$phy is 5 GHz" - radio="$(wifiAddPhy "$phy" "$chan5ghz")" - if [ -z "$radio" ]; then - echo "Can't create radio for $phy" - exit 1 - fi - fi + radio="$(wifiAddPhyCond "$phy" "2" "$chan2ghz")" + radio5="$(wifiAddPhyCond "$phy" "5" "$chan5ghz")" + [ -n "$radio5" ] && radio="$radio5" + #and here we add the station if ! wifiAddSta "$radio" "config.franken.freifunk.net" "configSta"; then echo "Can't add Sta interface on $radio." @@ -153,22 +141,9 @@ if [ -s /tmp/keyxchangev2data ]; then fi for phy in $(iw phy | awk '/^Wiphy/{ print $2 }'); do - if iw phy "$phy" info | grep -q -m1 "2... MHz"; then - echo "$phy is 2.4 GHz" - radio="$(wifiAddPhy "$phy" "$chan2ghz")" - if [ -z "$radio" ]; then - echo "Can't create radio for $phy" - exit 1 - fi - fi - if iw phy "$phy" info | grep -q -m1 "5... MHz"; then - echo "$phy is 5 GHz" - radio="$(wifiAddPhy "$phy" "$chan5ghz")" - if [ -z "$radio" ]; then - echo "Can't create radio for $phy" - exit 1 - fi - fi + radio="$(wifiAddPhyCond "$phy" "2" "$chan2ghz")" + radio5="$(wifiAddPhyCond "$phy" "5" "$chan5ghz")" + [ -n "$radio5" ] && radio="$radio5" if ! wifiAddAP "$radio" "$essid" "mesh" "ap" "0"; then echo "Can't add AP interface on $radio." 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 8ba9463..2c6dff8 100644 --- a/src/packages/fff/fff-wireless/files/lib/functions/fff/wireless +++ b/src/packages/fff/fff-wireless/files/lib/functions/fff/wireless @@ -50,6 +50,27 @@ wifiAddPhy() { return 0 } +wifiAddPhyCond() { + if [ $# -ne "3" ] + then + return 1 + fi + + local phy=$1 + local freq=$2 + local channel=$3 + + if iw phy "$phy" info | grep -q -m1 "${freq}... MHz"; then + radio="$(wifiAddPhy "$phy" "$channel")" + if [ -z "$radio" ]; then + return 1 + fi + fi + + echo "$radio" + return 0 # also returns success if outermost if is false +} + wifiAddAdHocMesh() { if [ $# -ne "3" ] then @@ -122,6 +143,7 @@ wifiAddAP() { __EOF__ echo "${iface}" + return 0 } wifiAddSta() { @@ -152,6 +174,7 @@ wifiAddSta() { __EOF__ echo "${iface}" + return 0 } # vim: set noexpandtab:tabstop=4