[v8] fff-hoods: Use channel provided by gateway

Submitted by Adrian Schmutzler on Oct. 26, 2017, 6:57 a.m.

Details

Message ID 1509001032-5352-1-git-send-email-freifunk@adrianschmutzler.de
State Accepted
Headers show

Commit Message

Adrian Schmutzler Oct. 26, 2017, 6:57 a.m.
ALTERNATIVE PATCH: This prevents setup if a channel
is missing (json defective)

I personally however still prefer v7 with default channel

Changes in v2:
- rebase due to conflict with 802.11s

Changes in v3:
- Fix wrong variable name introduced in v2

Changes in v4:
- Fixed comment
- Fixed channel comparison for wXsta

Changes in v5:
- Make radio in wifiAddPhyCond local

Changes in v6:
- Rebase

Changes in v7:
- Check if channel set and default otherwise
- Remove obsolete channel variables at beginning of script

Changes in v8:
- Exit if channel missing

Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
Signed-off-by: Fabian Bläse <fabian@blaese.de>
---
 .../fff/fff-hoods/files/usr/sbin/configurehood     | 27 ++++++++++++++--------
 .../fff-wireless/files/lib/functions/fff/wireless  | 17 +++++++-------
 2 files changed, 25 insertions(+), 19 deletions(-)

Patch hide | download patch | download mbox

diff --git a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
index 88f6f53..b30e942 100755
--- a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
+++ b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
@@ -28,9 +28,6 @@  hasInternet() {
 	return 1
 }
 
-chan2ghz="1"
-chan5ghz="36"
-
 # Hidden AP check
 
 if [ -f /tmp/hiddenapflag ]; then
@@ -78,12 +75,17 @@  else
 		fi
 		#now we look for phy and add this
 		for phy in $(iw phy | awk '/^Wiphy/{ print $2 }'); do
-			radio="$(wifiAddPhyCond "$phy" "2" "$chan2ghz")"
-			radio5="$(wifiAddPhyCond "$phy" "5" "$chan5ghz")"
-			[ -n "$radio5" ] && radio="$radio5"
+			radio="$(wifiAddPhyCond "$phy" "2" "auto")"
+			radio5="$(wifiAddPhyCond "$phy" "5" "auto5")"
+			if [ -n "$radio5" ] ; then
+				radio="$radio5"
+				staiface="w5sta"
+			else
+				staiface="w2sta"
+			fi
 
 			#and here we add the station
-			if ! wifiAddSta "$radio" "config.franken.freifunk.net" "configSta"; then
+			if ! wifiAddSta "$radio" "config.franken.freifunk.net" "configSta" "$staiface" ; then
 				echo "Can't add Sta interface on $radio."
 				exit 1
 			else
@@ -128,17 +130,22 @@  if [ -s /tmp/keyxchangev2data ]; then
 		json_get_var mesh_essid mesh_essid
 		json_get_var essid essid
 		json_get_var ntpip ntp_ip
-		# i think the next things we don't active this in the first version! we can do it later
-		#json_get_var channel2 channel2
+		# Additional parameters may be activated in future versions
+		json_get_var chan2ghz channel2
 		#json_get_var mode2 mode2
 		json_get_var mesh_type2 mesh_type2
-		#json_get_var channel5 channel5
+		json_get_var chan5ghz channel5
 		#json_get_var mode5 mode5
 		json_get_var mesh_type5 mesh_type5
 		#json_get_var protocol protocol
 		
 		json_select ".." # back to root
 
+		if ! ([ -n "$chan2ghz" ] && [ -n "$chan5ghz" ]) ; then
+			# If channel is missing, do nothing
+			exit 0
+		fi
+
 		echo "Setting hood name: $hood"
 		uci set "system.@system[0].hood=$hood"
 
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 7e418c2..b1ff5a9 100644
--- a/src/packages/fff/fff-wireless/files/lib/functions/fff/wireless
+++ b/src/packages/fff/fff-wireless/files/lib/functions/fff/wireless
@@ -25,7 +25,10 @@  wifiAddPhy() {
 	local channel=$2
 	local radio="radio$(echo "$phy" | tr -d -C "0-9")"
 	local hwmode="11g"
-	if [ "$channel" -gt "14" ]; then
+	if [ "$channel" = "auto5" ] ; then
+		hwmode="11a"
+		channel="auto"
+	elif ( ! [ "$channel" = "auto" ] ) && [ "$channel" -gt "14" ]; then
 		hwmode="11a"
 	fi
 
@@ -60,7 +63,7 @@  wifiAddPhyCond() {
 	local freq=$2
 	local channel=$3
 	local radio=""
-	
+
 	if iw phy "$phy" info | grep -q -m1 "${freq}... MHz"; then
 		radio="$(wifiAddPhy "$phy" "$channel")"
 		if [ -z "$radio" ]; then
@@ -148,21 +151,17 @@  wifiAddAP() {
 }
 
 wifiAddSta() {
-	if [ $# -ne "3" ]
+	if [ $# -ne "4" ]
 	then
-		echo "Usage: wifiAddSta <radio> <essid> <network>"
+		echo "Usage: wifiAddSta <radio> <essid> <network> <iface>"
 		return 1
 	fi
 
 	local radio=$1
 	local essid=$2
 	local network=$3
+	local iface=$4
 
-	local channel=$(uci get "wireless.${radio}.channel")
-	local iface="w2sta"
-	if [ "$channel" -gt "14" ]; then
-		iface="w5sta"
-	fi
 	uci batch <<-__EOF__
 		set wireless.${iface}='wifi-iface'
 		set wireless.${iface}.device='${radio}'

Comments

Christian Dresel Oct. 30, 2017, 6:16 p.m.
Hi

danke für deine Arbeit und den Stress mit mir im IRC ;) Hab das Ding nun
endlich begriffen und auch getestet. Sieht soweit gut aus. Nach diesem
Patch sollte am besten auch gleich "[PATCH v5] fff-hoods: Introduce
sector files for custom settings" mit applied werden.

Kleine Anmerkung noch inline, vielleicht kann man das einfach beim
applien anpassen

Reviewed-by: Christian Dresel <fff@chrisi01.de>

On 26.10.2017 08:57, Adrian Schmutzler wrote:
> ALTERNATIVE PATCH: This prevents setup if a channel
> is missing (json defective)
> 
> I personally however still prefer v7 with default channel
> 
> Changes in v2:
> - rebase due to conflict with 802.11s
> 
> Changes in v3:
> - Fix wrong variable name introduced in v2
> 
> Changes in v4:
> - Fixed comment
> - Fixed channel comparison for wXsta
> 
> Changes in v5:
> - Make radio in wifiAddPhyCond local
> 
> Changes in v6:
> - Rebase
> 
> Changes in v7:
> - Check if channel set and default otherwise
> - Remove obsolete channel variables at beginning of script
> 
> Changes in v8:
> - Exit if channel missing
> 
> Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
> Signed-off-by: Fabian Bläse <fabian@blaese.de>
> ---
>  .../fff/fff-hoods/files/usr/sbin/configurehood     | 27 ++++++++++++++--------
>  .../fff-wireless/files/lib/functions/fff/wireless  | 17 +++++++-------
>  2 files changed, 25 insertions(+), 19 deletions(-)
> 
> diff --git a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> index 88f6f53..b30e942 100755
> --- a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> +++ b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> @@ -28,9 +28,6 @@ hasInternet() {
>  	return 1
>  }
>  
> -chan2ghz="1"
> -chan5ghz="36"
> -
>  # Hidden AP check
>  
>  if [ -f /tmp/hiddenapflag ]; then
> @@ -78,12 +75,17 @@ else
>  		fi
>  		#now we look for phy and add this
>  		for phy in $(iw phy | awk '/^Wiphy/{ print $2 }'); do
> -			radio="$(wifiAddPhyCond "$phy" "2" "$chan2ghz")"
> -			radio5="$(wifiAddPhyCond "$phy" "5" "$chan5ghz")"
> -			[ -n "$radio5" ] && radio="$radio5"
> +			radio="$(wifiAddPhyCond "$phy" "2" "auto")"
> +			radio5="$(wifiAddPhyCond "$phy" "5" "auto5")"
> +			if [ -n "$radio5" ] ; then
> +				radio="$radio5"
> +				staiface="w5sta"
> +			else
> +				staiface="w2sta"
> +			fi
>  
>  			#and here we add the station
> -			if ! wifiAddSta "$radio" "config.franken.freifunk.net" "configSta"; then
> +			if ! wifiAddSta "$radio" "config.franken.freifunk.net" "configSta" "$staiface" ; then

das Leerzeichen vor dem ; könnte man noch eben entfernen ;)

mfg

Christian

>  				echo "Can't add Sta interface on $radio."
>  				exit 1
>  			else
> @@ -128,17 +130,22 @@ if [ -s /tmp/keyxchangev2data ]; then
>  		json_get_var mesh_essid mesh_essid
>  		json_get_var essid essid
>  		json_get_var ntpip ntp_ip
> -		# i think the next things we don't active this in the first version! we can do it later
> -		#json_get_var channel2 channel2
> +		# Additional parameters may be activated in future versions
> +		json_get_var chan2ghz channel2
>  		#json_get_var mode2 mode2
>  		json_get_var mesh_type2 mesh_type2
> -		#json_get_var channel5 channel5
> +		json_get_var chan5ghz channel5
>  		#json_get_var mode5 mode5
>  		json_get_var mesh_type5 mesh_type5
>  		#json_get_var protocol protocol
>  		
>  		json_select ".." # back to root
>  
> +		if ! ([ -n "$chan2ghz" ] && [ -n "$chan5ghz" ]) ; then
> +			# If channel is missing, do nothing
> +			exit 0
> +		fi
> +
>  		echo "Setting hood name: $hood"
>  		uci set "system.@system[0].hood=$hood"
>  
> 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 7e418c2..b1ff5a9 100644
> --- a/src/packages/fff/fff-wireless/files/lib/functions/fff/wireless
> +++ b/src/packages/fff/fff-wireless/files/lib/functions/fff/wireless
> @@ -25,7 +25,10 @@ wifiAddPhy() {
>  	local channel=$2
>  	local radio="radio$(echo "$phy" | tr -d -C "0-9")"
>  	local hwmode="11g"
> -	if [ "$channel" -gt "14" ]; then
> +	if [ "$channel" = "auto5" ] ; then
> +		hwmode="11a"
> +		channel="auto"
> +	elif ( ! [ "$channel" = "auto" ] ) && [ "$channel" -gt "14" ]; then
>  		hwmode="11a"
>  	fi
>  
> @@ -60,7 +63,7 @@ wifiAddPhyCond() {
>  	local freq=$2
>  	local channel=$3
>  	local radio=""
> -	
> +
>  	if iw phy "$phy" info | grep -q -m1 "${freq}... MHz"; then
>  		radio="$(wifiAddPhy "$phy" "$channel")"
>  		if [ -z "$radio" ]; then
> @@ -148,21 +151,17 @@ wifiAddAP() {
>  }
>  
>  wifiAddSta() {
> -	if [ $# -ne "3" ]
> +	if [ $# -ne "4" ]
>  	then
> -		echo "Usage: wifiAddSta <radio> <essid> <network>"
> +		echo "Usage: wifiAddSta <radio> <essid> <network> <iface>"
>  		return 1
>  	fi
>  
>  	local radio=$1
>  	local essid=$2
>  	local network=$3
> +	local iface=$4
>  
> -	local channel=$(uci get "wireless.${radio}.channel")
> -	local iface="w2sta"
> -	if [ "$channel" -gt "14" ]; then
> -		iface="w5sta"
> -	fi
>  	uci batch <<-__EOF__
>  		set wireless.${iface}='wifi-iface'
>  		set wireless.${iface}.device='${radio}'
>
Robert Langhammer Nov. 1, 2017, 7:38 p.m.
Hallo,
sieht gut aus!

Reviewed-by:Robert Langhammer rlanghammer@web.de

Am 26.10.2017 um 08:57 schrieb Adrian Schmutzler:
> ALTERNATIVE PATCH: This prevents setup if a channel
> is missing (json defective)
>
> I personally however still prefer v7 with default channel
>
> Changes in v2:
> - rebase due to conflict with 802.11s
>
> Changes in v3:
> - Fix wrong variable name introduced in v2
>
> Changes in v4:
> - Fixed comment
> - Fixed channel comparison for wXsta
>
> Changes in v5:
> - Make radio in wifiAddPhyCond local
>
> Changes in v6:
> - Rebase
>
> Changes in v7:
> - Check if channel set and default otherwise
> - Remove obsolete channel variables at beginning of script
>
> Changes in v8:
> - Exit if channel missing
>
> Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
> Signed-off-by: Fabian Bläse <fabian@blaese.de>
> ---
>  .../fff/fff-hoods/files/usr/sbin/configurehood     | 27 ++++++++++++++--------
>  .../fff-wireless/files/lib/functions/fff/wireless  | 17 +++++++-------
>  2 files changed, 25 insertions(+), 19 deletions(-)
>
> diff --git a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> index 88f6f53..b30e942 100755
> --- a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> +++ b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> @@ -28,9 +28,6 @@ hasInternet() {
>  	return 1
>  }
>  
> -chan2ghz="1"
> -chan5ghz="36"
> -
>  # Hidden AP check
>  
>  if [ -f /tmp/hiddenapflag ]; then
> @@ -78,12 +75,17 @@ else
>  		fi
>  		#now we look for phy and add this
>  		for phy in $(iw phy | awk '/^Wiphy/{ print $2 }'); do
> -			radio="$(wifiAddPhyCond "$phy" "2" "$chan2ghz")"
> -			radio5="$(wifiAddPhyCond "$phy" "5" "$chan5ghz")"
> -			[ -n "$radio5" ] && radio="$radio5"
> +			radio="$(wifiAddPhyCond "$phy" "2" "auto")"
> +			radio5="$(wifiAddPhyCond "$phy" "5" "auto5")"
> +			if [ -n "$radio5" ] ; then
> +				radio="$radio5"
> +				staiface="w5sta"
> +			else
> +				staiface="w2sta"
> +			fi
>  
>  			#and here we add the station
> -			if ! wifiAddSta "$radio" "config.franken.freifunk.net" "configSta"; then
> +			if ! wifiAddSta "$radio" "config.franken.freifunk.net" "configSta" "$staiface" ; then
>  				echo "Can't add Sta interface on $radio."
>  				exit 1
>  			else
> @@ -128,17 +130,22 @@ if [ -s /tmp/keyxchangev2data ]; then
>  		json_get_var mesh_essid mesh_essid
>  		json_get_var essid essid
>  		json_get_var ntpip ntp_ip
> -		# i think the next things we don't active this in the first version! we can do it later
> -		#json_get_var channel2 channel2
> +		# Additional parameters may be activated in future versions
> +		json_get_var chan2ghz channel2
>  		#json_get_var mode2 mode2
>  		json_get_var mesh_type2 mesh_type2
> -		#json_get_var channel5 channel5
> +		json_get_var chan5ghz channel5
>  		#json_get_var mode5 mode5
>  		json_get_var mesh_type5 mesh_type5
>  		#json_get_var protocol protocol
>  		
>  		json_select ".." # back to root
>  
> +		if ! ([ -n "$chan2ghz" ] && [ -n "$chan5ghz" ]) ; then
> +			# If channel is missing, do nothing
> +			exit 0
> +		fi
> +
>  		echo "Setting hood name: $hood"
>  		uci set "system.@system[0].hood=$hood"
>  
> 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 7e418c2..b1ff5a9 100644
> --- a/src/packages/fff/fff-wireless/files/lib/functions/fff/wireless
> +++ b/src/packages/fff/fff-wireless/files/lib/functions/fff/wireless
> @@ -25,7 +25,10 @@ wifiAddPhy() {
>  	local channel=$2
>  	local radio="radio$(echo "$phy" | tr -d -C "0-9")"
>  	local hwmode="11g"
> -	if [ "$channel" -gt "14" ]; then
> +	if [ "$channel" = "auto5" ] ; then
> +		hwmode="11a"
> +		channel="auto"
> +	elif ( ! [ "$channel" = "auto" ] ) && [ "$channel" -gt "14" ]; then
>  		hwmode="11a"
>  	fi
>  
> @@ -60,7 +63,7 @@ wifiAddPhyCond() {
>  	local freq=$2
>  	local channel=$3
>  	local radio=""
> -	
> +
>  	if iw phy "$phy" info | grep -q -m1 "${freq}... MHz"; then
>  		radio="$(wifiAddPhy "$phy" "$channel")"
>  		if [ -z "$radio" ]; then
> @@ -148,21 +151,17 @@ wifiAddAP() {
>  }
>  
>  wifiAddSta() {
> -	if [ $# -ne "3" ]
> +	if [ $# -ne "4" ]
>  	then
> -		echo "Usage: wifiAddSta <radio> <essid> <network>"
> +		echo "Usage: wifiAddSta <radio> <essid> <network> <iface>"
>  		return 1
>  	fi
>  
>  	local radio=$1
>  	local essid=$2
>  	local network=$3
> +	local iface=$4
>  
> -	local channel=$(uci get "wireless.${radio}.channel")
> -	local iface="w2sta"
> -	if [ "$channel" -gt "14" ]; then
> -		iface="w5sta"
> -	fi
>  	uci batch <<-__EOF__
>  		set wireless.${iface}='wifi-iface'
>  		set wireless.${iface}.device='${radio}'
Tim Niemeyer Nov. 2, 2017, 7:44 p.m.
Hi

Und.. Applied.

Am Montag, den 30.10.2017, 19:16 +0100 schrieb Christian Dresel:
> Hi
> 
> danke für deine Arbeit und den Stress mit mir im IRC ;) Hab das Ding nun
> endlich begriffen und auch getestet. Sieht soweit gut aus. Nach diesem
> Patch sollte am besten auch gleich "[PATCH v5] fff-hoods: Introduce
> sector files for custom settings" mit applied werden.
> 
> Kleine Anmerkung noch inline, vielleicht kann man das einfach beim
> applien anpassen
> 
> Reviewed-by: Christian Dresel <fff@chrisi01.de>
> 
> On 26.10.2017 08:57, Adrian Schmutzler wrote:
Leider ist auch in diesem Patch wieder die Commit-Message falsch. Commit
message (nicht wirklich vorhanden) und Kommentare für die Reviewer (wie
z.B. die Changes) sind beide in der Commit-Message vermischt.

Ein paar Patches lang werde ich das noch nachbearbeiten, aber irgendwann
werde ich sowas einfach nicht mehr applien!

> > ALTERNATIVE PATCH: This prevents setup if a channel
> > is missing (json defective)
> > 
> > I personally however still prefer v7 with default channel
> > 
> > Changes in v2:
> > - rebase due to conflict with 802.11s
> > 
> > Changes in v3:
> > - Fix wrong variable name introduced in v2
> > 
> > Changes in v4:
> > - Fixed comment
> > - Fixed channel comparison for wXsta
> > 
> > Changes in v5:
> > - Make radio in wifiAddPhyCond local
> > 
> > Changes in v6:
> > - Rebase
> > 
> > Changes in v7:
> > - Check if channel set and default otherwise
> > - Remove obsolete channel variables at beginning of script
> > 
> > Changes in v8:
> > - Exit if channel missing
> > 
> > Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
> > Signed-off-by: Fabian Bläse <fabian@blaese.de>
> > ---
> >  .../fff/fff-hoods/files/usr/sbin/configurehood     | 27 ++++++++++++++--------
> >  .../fff-wireless/files/lib/functions/fff/wireless  | 17 +++++++-------
> >  2 files changed, 25 insertions(+), 19 deletions(-)
> > 
> > diff --git a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> > index 88f6f53..b30e942 100755
> > --- a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> > +++ b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
[..]
> >  			#and here we add the station
> > -			if ! wifiAddSta "$radio" "config.franken.freifunk.net" "configSta"; then
> > +			if ! wifiAddSta "$radio" "config.franken.freifunk.net" "configSta" "$staiface" ; then
> 
> das Leerzeichen vor dem ; könnte man noch eben entfernen ;)

Stimme dir da sehr zu. Ich finde das optisch auch unglaublich
unappetitlich.. ;)

Leider sind in den entsprechenden Files noch mehr davon da drin, so dass
ich das beim Applien jetzt nicht hier an der einen Stelle nachbessern
möchte.

Ich fänd es sehr gut, wenn du das anpasst und ein Patch schickst.

Tim