[v2,1/5] fff-hoods: manually create wifi station interface

Submitted by Fabian Blaese on March 11, 2020, 5:11 p.m.

Details

Message ID 20200311171105.3558036-2-fabian@blaese.de
State Superseded
Headers show

Commit Message

Fabian Blaese March 11, 2020, 5:11 p.m.
The mac80211 interface script in OpenWrt depends on wpa_supplicant
for the creation of station interfaces. While this is conveniant, it
isn't strictly necessary for connecting to unencrypted networks.

To be able to create station interfaces if wpa_supplicant is removed,
the station interface for obtaining the initial configuration is now
created using iw commands only.

This makes it possible to replace wpad-mini with hostapd-mini, which
does not include wpa_supplicant and therefore shrinks the uncompressed
binary by around 200KiB.

Signed-off-by: Fabian Bläse <fabian@blaese.de>
Acked-by: Christian Dresel <fff@chrisi01.de>
Reviewed-by: Robert Langhammer <rlanghammer@web.de>
---
Changes in v2:
- Remove leftover configsta uci config from configurehood
- Bump PKG_RELEASE
---
 src/packages/fff/fff-hoods/Makefile           |  2 +-
 .../files/etc/uci-defaults/24c-fff-wXsta      | 27 -----------------
 .../files/usr/lib/functions/fff/hoodfile      | 30 +++++++++++--------
 .../fff-hoods/files/usr/sbin/configurehood    |  3 +-
 4 files changed, 19 insertions(+), 43 deletions(-)
 delete mode 100644 src/packages/fff/fff-hoods/files/etc/uci-defaults/24c-fff-wXsta

Patch hide | download patch | download mbox

diff --git a/src/packages/fff/fff-hoods/Makefile b/src/packages/fff/fff-hoods/Makefile
index 5eb20ca..423403c 100644
--- a/src/packages/fff/fff-hoods/Makefile
+++ b/src/packages/fff/fff-hoods/Makefile
@@ -1,7 +1,7 @@ 
 include $(TOPDIR)/rules.mk
 
 PKG_NAME:=fff-hoods
-PKG_RELEASE:=7
+PKG_RELEASE:=8
 
 PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
 
diff --git a/src/packages/fff/fff-hoods/files/etc/uci-defaults/24c-fff-wXsta b/src/packages/fff/fff-hoods/files/etc/uci-defaults/24c-fff-wXsta
deleted file mode 100644
index e9867b9..0000000
--- a/src/packages/fff/fff-hoods/files/etc/uci-defaults/24c-fff-wXsta
+++ /dev/null
@@ -1,27 +0,0 @@ 
-#!/bin/sh
-
-. /lib/functions/fff/wireless
-
-# Set up wXsta
-for radio in $(wifiListRadio); do
-	# wXsta: We can use $freq here, as the initial radios are not set up with auto
-	freq="$(wifiGetFreq $radio)"
-
-	uci batch <<-__EOF__
-		set network.configsta${freq}=interface
-		set network.configsta${freq}.proto='static'
-
-		set wireless.w${freq}sta='wifi-iface'
-		set wireless.w${freq}sta.device='${radio}'
-		set wireless.w${freq}sta.network='configsta${freq}'
-		set wireless.w${freq}sta.ifname='w${freq}sta'
-		set wireless.w${freq}sta.mode='sta'
-		set wireless.w${freq}sta.ssid='config.franken.freifunk.net'
-		set wireless.w${freq}sta.disabled='1'
-	__EOF__
-done
-
-uci commit network
-uci commit wireless
-
-# vim: set noexpandtab:tabstop=4
diff --git a/src/packages/fff/fff-hoods/files/usr/lib/functions/fff/hoodfile b/src/packages/fff/fff-hoods/files/usr/lib/functions/fff/hoodfile
index b148eca..d9119ac 100644
--- a/src/packages/fff/fff-hoods/files/usr/lib/functions/fff/hoodfile
+++ b/src/packages/fff/fff-hoods/files/usr/lib/functions/fff/hoodfile
@@ -15,29 +15,33 @@  getWirelessHoodfile() {
 
 	# Set channel to auto, enable wXsta, disable other interfaces
 	for radio in $(wifiListRadio); do
-		uci set "wireless.${radio}.channel=auto"
-
 		freq="$(wifiGetFreq $radio)"
 		uci set wireless.w${freq}ap.disabled='1'
 		uci set wireless.w${freq}mesh.disabled='1'
 		uci set wireless.w${freq}configap.disabled='1'
-		uci set wireless.w${freq}sta.disabled='0'
 	done
 
 	uci commit wireless
 	reload_config
 
-	wifi
-	# wait a moment to start the interface
-	sleep 10;
+	# wait for wireless interfaces to vanish
+	sleep 5;
 
-	if /bin/busybox wget -T15 -O "$file" "http://[fe80::1%w2sta]:2342/keyxchangev2data"; then
-		return 0
-	elif /bin/busybox wget -T15 -O "$file" "http://[fe80::1%w5sta]:2342/keyxchangev2data"; then
-		return 0
-	else
-		return 1
-	fi
+
+	for phy in $(ls /sys/class/ieee80211); do
+		iw phy $phy interface add configsta type managed
+		ip link set up configsta
+		iw dev configsta connect -w config.franken.freifunk.net 2>/dev/null
+
+		if /bin/busybox wget -T15 -O "$file" "http://[fe80::1%configsta]:2342/keyxchangev2data"; then
+			iw dev configsta del
+			return 0
+		fi
+
+		iw dev configsta del
+	done
+
+	return 1
 }
 
 getEthernetHoodfile() {
diff --git a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
index d5dc2c0..dcdba89 100755
--- a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
+++ b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
@@ -158,8 +158,7 @@  if [ -s "$hoodfiletmp" ]; then
 				mesh_type="$mesh_type2"
 			fi
 
-			# Disable wXsta, wXconfigap
-			uci set wireless.w${freq}sta.disabled='1'
+			# Disable wXconfigap
 			uci set wireless.w${freq}configap.disabled='1'
 
 			# Configure wXap

Comments

Adrian Schmutzler March 11, 2020, 6 p.m.
Hi,

Reviewed-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
Tested-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>

Ich bilde mir ein, dass das sleep 5 in einzelnen Fällen zu kurz war, und dann die Konfiguration verstorben ist, weil das ganze wiphy Zeug eh asynchron ist.

Das würde sich auch mit der beobachteten Zeit decken, die WiFi nach reload_config braucht, um an oder aus zu gehen. 5 Sekunden sollte dabei nur leicht oberhalb des Mittelwerts liegen, also wären 10 Sec. wahrscheinlich besser.

Review gilt erstmal nur für 1/5, den würde ich auch sehr zeitnah applien.

Grüße

Adrian

> -----Original Message-----
> From: franken-dev [mailto:franken-dev-bounces@freifunk.net] On Behalf Of
> Fabian Bläse
> Sent: Mittwoch, 11. März 2020 18:11
> To: franken-dev@freifunk.net
> Subject: [PATCH v2 1/5] fff-hoods: manually create wifi station interface
> 
> The mac80211 interface script in OpenWrt depends on wpa_supplicant
> for the creation of station interfaces. While this is conveniant, it
> isn't strictly necessary for connecting to unencrypted networks.
> 
> To be able to create station interfaces if wpa_supplicant is removed,
> the station interface for obtaining the initial configuration is now
> created using iw commands only.
> 
> This makes it possible to replace wpad-mini with hostapd-mini, which
> does not include wpa_supplicant and therefore shrinks the uncompressed
> binary by around 200KiB.
> 
> Signed-off-by: Fabian Bläse <fabian@blaese.de>
> Acked-by: Christian Dresel <fff@chrisi01.de>
> Reviewed-by: Robert Langhammer <rlanghammer@web.de>
> ---
> Changes in v2:
> - Remove leftover configsta uci config from configurehood
> - Bump PKG_RELEASE
> ---
>  src/packages/fff/fff-hoods/Makefile           |  2 +-
>  .../files/etc/uci-defaults/24c-fff-wXsta      | 27 -----------------
>  .../files/usr/lib/functions/fff/hoodfile      | 30 +++++++++++--------
>  .../fff-hoods/files/usr/sbin/configurehood    |  3 +-
>  4 files changed, 19 insertions(+), 43 deletions(-)
>  delete mode 100644 src/packages/fff/fff-hoods/files/etc/uci-defaults/24c-fff-
> wXsta
> 
> diff --git a/src/packages/fff/fff-hoods/Makefile b/src/packages/fff/fff-
> hoods/Makefile
> index 5eb20ca..423403c 100644
> --- a/src/packages/fff/fff-hoods/Makefile
> +++ b/src/packages/fff/fff-hoods/Makefile
> @@ -1,7 +1,7 @@
>  include $(TOPDIR)/rules.mk
> 
>  PKG_NAME:=fff-hoods
> -PKG_RELEASE:=7
> +PKG_RELEASE:=8
> 
>  PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
> 
> diff --git a/src/packages/fff/fff-hoods/files/etc/uci-defaults/24c-fff-wXsta
> b/src/packages/fff/fff-hoods/files/etc/uci-defaults/24c-fff-wXsta
> deleted file mode 100644
> index e9867b9..0000000
> --- a/src/packages/fff/fff-hoods/files/etc/uci-defaults/24c-fff-wXsta
> +++ /dev/null
> @@ -1,27 +0,0 @@
> -#!/bin/sh
> -
> -. /lib/functions/fff/wireless
> -
> -# Set up wXsta
> -for radio in $(wifiListRadio); do
> -	# wXsta: We can use $freq here, as the initial radios are not set up with
> auto
> -	freq="$(wifiGetFreq $radio)"
> -
> -	uci batch <<-__EOF__
> -		set network.configsta${freq}=interface
> -		set network.configsta${freq}.proto='static'
> -
> -		set wireless.w${freq}sta='wifi-iface'
> -		set wireless.w${freq}sta.device='${radio}'
> -		set wireless.w${freq}sta.network='configsta${freq}'
> -		set wireless.w${freq}sta.ifname='w${freq}sta'
> -		set wireless.w${freq}sta.mode='sta'
> -		set wireless.w${freq}sta.ssid='config.franken.freifunk.net'
> -		set wireless.w${freq}sta.disabled='1'
> -	__EOF__
> -done
> -
> -uci commit network
> -uci commit wireless
> -
> -# vim: set noexpandtab:tabstop=4
> diff --git a/src/packages/fff/fff-hoods/files/usr/lib/functions/fff/hoodfile
> b/src/packages/fff/fff-hoods/files/usr/lib/functions/fff/hoodfile
> index b148eca..d9119ac 100644
> --- a/src/packages/fff/fff-hoods/files/usr/lib/functions/fff/hoodfile
> +++ b/src/packages/fff/fff-hoods/files/usr/lib/functions/fff/hoodfile
> @@ -15,29 +15,33 @@ getWirelessHoodfile() {
> 
>  	# Set channel to auto, enable wXsta, disable other interfaces
>  	for radio in $(wifiListRadio); do
> -		uci set "wireless.${radio}.channel=auto"
> -
>  		freq="$(wifiGetFreq $radio)"
>  		uci set wireless.w${freq}ap.disabled='1'
>  		uci set wireless.w${freq}mesh.disabled='1'
>  		uci set wireless.w${freq}configap.disabled='1'
> -		uci set wireless.w${freq}sta.disabled='0'
>  	done
> 
>  	uci commit wireless
>  	reload_config
> 
> -	wifi
> -	# wait a moment to start the interface
> -	sleep 10;
> +	# wait for wireless interfaces to vanish
> +	sleep 5;
> 
> -	if /bin/busybox wget -T15 -O "$file"
> "http://[fe80::1%w2sta]:2342/keyxchangev2data"; then
> -		return 0
> -	elif /bin/busybox wget -T15 -O "$file"
> "http://[fe80::1%w5sta]:2342/keyxchangev2data"; then
> -		return 0
> -	else
> -		return 1
> -	fi
> +
> +	for phy in $(ls /sys/class/ieee80211); do
> +		iw phy $phy interface add configsta type managed
> +		ip link set up configsta
> +		iw dev configsta connect -w config.franken.freifunk.net
> 2>/dev/null
> +
> +		if /bin/busybox wget -T15 -O "$file"
> "http://[fe80::1%configsta]:2342/keyxchangev2data"; then
> +			iw dev configsta del
> +			return 0
> +		fi
> +
> +		iw dev configsta del
> +	done
> +
> +	return 1
>  }
> 
>  getEthernetHoodfile() {
> diff --git a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> index d5dc2c0..dcdba89 100755
> --- a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> +++ b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> @@ -158,8 +158,7 @@ if [ -s "$hoodfiletmp" ]; then
>  				mesh_type="$mesh_type2"
>  			fi
> 
> -			# Disable wXsta, wXconfigap
> -			uci set wireless.w${freq}sta.disabled='1'
> +			# Disable wXconfigap
>  			uci set wireless.w${freq}configap.disabled='1'
> 
>  			# Configure wXap
> --
> 2.25.1
Fabian Blaese March 11, 2020, 6:36 p.m.
On 11.03.20 19:00, Adrian Schmutzler wrote:
> Ich bilde mir ein, dass das sleep 5 in einzelnen Fällen zu kurz war, und dann die Konfiguration verstorben ist, weil das ganze wiphy Zeug eh asynchron ist.
> 
> Das würde sich auch mit der beobachteten Zeit decken, die WiFi nach reload_config braucht, um an oder aus zu gehen. 5 Sekunden sollte dabei nur leicht oberhalb des Mittelwerts liegen, also wären 10 Sec. wahrscheinlich besser.
Über 5 Sekunden um bissl Wifi Interfaces zu löschen? Hmm.
Hatte ich nicht beobachtet, kann man aber ggf. noch anpassen. Ich hab aber auch nur auf relativ flotter Hardware getestet

Gruß
Fabian
Adrian Schmutzler March 11, 2020, 6:57 p.m.
> -----Original Message-----
> From: Fabian Bläse [mailto:fabian@blaese.de]
> Sent: Mittwoch, 11. März 2020 19:37
> To: Adrian Schmutzler <mail@adrianschmutzler.de>; franken-dev@freifunk.net
> Subject: Re: [PATCH v2 1/5] fff-hoods: manually create wifi station interface
> 
> On 11.03.20 19:00, Adrian Schmutzler wrote:
> > Ich bilde mir ein, dass das sleep 5 in einzelnen Fällen zu kurz war, und dann die
> Konfiguration verstorben ist, weil das ganze wiphy Zeug eh asynchron ist.
> >
> > Das würde sich auch mit der beobachteten Zeit decken, die WiFi nach
> reload_config braucht, um an oder aus zu gehen. 5 Sekunden sollte dabei nur
> leicht oberhalb des Mittelwerts liegen, also wären 10 Sec. wahrscheinlich besser.
> Über 5 Sekunden um bissl Wifi Interfaces zu löschen? Hmm.
> Hatte ich nicht beobachtet, kann man aber ggf. noch anpassen. Ich hab aber auch
> nur auf relativ flotter Hardware getestet

Nimm einen einfachen OpenWrt-Router, und ändere den Wert (des radio) für disabled in der /etc/config/wireless.
Danach nur "reload_config" ausführen (wifi ist nicht nötig), und kucken, was passiert.

Normalerweise passiert 2 sec. nichts (SSH ist responsiv), dann wird 2 sec. der WiFi state geändert und dann nach weiteren 0-2 Sekunden reagiert das SSH wieder.

Ist aber sicher auch von der Hardware abhängig, und wir machen natürlich keinen disable des radio, wie in diesem Test, sondern fügen nur ein Interface hinzu...

> 
> Gruß
> Fabian