[PATCH] fff-hoods: Use function for conditional wifiAddPhy

Adrian Schmutzler freifunk at adrianschmutzler.de
Mi Okt 4 12:51:19 CEST 2017


Just a little tidying up.

Apply only after fff-hoods patchset!

Signed-off-by: Adrian Schmutzler <freifunk at adrianschmutzler.de>
---
 .../fff/fff-hoods/files/usr/sbin/configurehood     | 39 ++++------------------
 .../fff-wireless/files/lib/functions/fff/wireless  | 30 +++++++++++++++++
 2 files changed, 37 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 65155f1..06c7697 100755
--- a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
+++ b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
@@ -74,22 +74,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."
@@ -155,22 +143,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..9e7611f 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,34 @@ wifiAddPhy() {
 	return 0
 }
 
+wifiAddPhyCond() {
+	if [ $# -ne "3" ]
+	then
+		echo "Usage: wifiAddPhyCond <phy> <freq: 2 or 5> <channel>"
+		return 1
+	fi
+
+	local phy=$1
+	local freq=$2
+	local channel=$3
+	
+	if iw phy "$phy" info | grep -q -m1 "${freq}... MHz"; then
+		if [ "$freq" = "2" ] ; then
+			echo "$phy is 2.4 GHz"
+		else
+			echo "$phy is $freq GHz"
+		fi
+		radio="$(wifiAddPhy "$phy" "$channel")"
+		if [ -z "$radio" ]; then
+			echo "Can't create radio for $phy"
+			return 1
+		fi
+	fi
+	
+	echo "$radio"
+	return 0 # also returns success if outermost if is false
+}
+
 wifiAddAdHocMesh() {
 	if [ $# -ne "3" ]
 	then
@@ -122,6 +150,7 @@ wifiAddAP() {
 	__EOF__
 
 	echo "${iface}"
+	return 0
 }
 
 wifiAddSta() {
@@ -152,6 +181,7 @@ wifiAddSta() {
 	__EOF__
 	
 	echo "${iface}"
+	return 0
 }
 
 # vim: set noexpandtab:tabstop=4
-- 
2.7.4



Mehr Informationen über die Mailingliste franken-dev