Better wifi handling
v2 cover Better wifi handling
While adding and testing for a new wifi driver, I could notice the sad state of wifi interface bringup in buildroot, so I tried to have something simple enough to work on the most common cases.
What problems we had:
* Wrong syntax for wpa_supplicant.conf when using default build options.
* Lack of a proper ifup/ifdown support to have wpa_supplicant automatically started.
* Due to this, the recommended way of configuring a wifi via the "interfaces" file wasn't working at all.
Angelo Compagnucci (3):
package/wpa_supplicant: fixing "Invalid configuration line" package/wpa_supplicant: adding ifupdown support package/busybox: make udhcp discover faster
package/busybox/busybox.config | 2 +- package/wpa_supplicant/ifupdown.sh | 48 ++++++++++++++++++++++ package/wpa_supplicant/wpa_supplicant.conf | 1 - package/wpa_supplicant/wpa_supplicant.mk | 10 +++++ 4 files changed, 59 insertions(+), 2 deletions(-) create mode 100755 package/wpa_supplicant/ifupdown.sh
Signature · 6 lines
2.25.1 _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
PATCH v2 1/3 package/wpa_supplicant: fixing "Invalid configuration line"
Default configuration file is wrong for the default compiling options.
Fixes:
Successfully initialized wpa_supplicant
Line 1: unknown global field 'ctrl_interface=/var/run/wpa_supplicant'. Line 1: Invalid configuration line 'ctrl_interface=/var/run/wpa_supplicant'.
Failed to read or parse configuration '/etc/wpa_supplicant.conf'.
--- package/wpa_supplicant/wpa_supplicant.conf | 1 - 1 file changed, 1 deletion(-)
package/wpa_supplicant/wpa_supplicant.conf +0 -1
@@ -1,4 +1,3 @@ -ctrl_interface=/var/run/wpa_supplicant ap_scan=1 network={
Signature · 6 lines
2.25.1 _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
PATCH v2 2/3 package/wpa_supplicant: adding ifupdown support
In reply to Angelo CompagnucciActually, configuring a wifi interface as per "interfaces" man:
auto wlan0
iface wlan0 inet dhcp
wpa-conf /etc/wpa_supplicant.conf
doesn't work on buildroot because the line wpa-conf is ignored due to the lack of a proper ifupdown script to handle the wpa_supplicant initialization.
---
v1 -> v2:
* Simplify script to the minimum to have the service started (Thomas, Nicolas)
package/wpa_supplicant/ifupdown.sh | 48 ++++++++++++++++++++++++ package/wpa_supplicant/wpa_supplicant.mk | 10 +++++ 2 files changed, 58 insertions(+) create mode 100755 package/wpa_supplicant/ifupdown.sh
package/wpa_supplicant/ifupdown.sh new file +48 -0
@@ -0,0 +1,48 @@ +#!/bin/sh + +# This file is executed by ifupdown in pre-up, post-up, pre-down and +# post-down phases of network interface configuration. + +WPA_SUP_BIN="/usr/sbin/wpa_supplicant" + +# Allow wpa_supplicant interface to be specified via wpa-iface +# useful for starting wpa_supplicant on one interface of a bridge +if [ -n "$IF_WPA_IFACE" ]; then + WPA_IFACE="$IF_WPA_IFACE" +else + WPA_IFACE="$IFACE" +fi + +WPA_SUP_PIDFILE="/run/wpa_supplicant.${WPA_IFACE}.pid" + +do_start () { + [ -z "$IF_WPA_CONF" ] && exit 0 + + if [ ! -s "$IF_WPA_CONF" ]; then + echo "cannot read contents of $IF_WPA_CONF" + exit 1 + fi + WPA_SUP_CONF="-c $IF_WPA_CONF" +} + +case "$MODE" in + start) + do_start + case "$PHASE" in + post-up) + start-stop-daemon -S -q -x ${WPA_SUP_BIN} \ + -- -B -i ${WPA_IFACE} ${WPA_SUP_CONF} -P ${WPA_SUP_PIDFILE} + ;; + esac + ;; + + stop) + case "$PHASE" in + pre-down) + start-stop-daemon -K -p ${WPA_SUP_PIDFILE} + ;; + esac + ;; +esac + +exit 0
package/wpa_supplicant/wpa_supplicant.mk +10 -0
@@ -250,6 +250,14 @@ define WPA_SUPPLICANT_INSTALL_STAGING_CMDS $(WPA_SUPPLICANT_INSTALL_STAGING_WPA_CLIENT_SO) endef +ifeq ($(BR2_PACKAGE_IFUPDOWN_SCRIPTS),y) +define WPA_SUPPLICANT_INSTALL_IFUP_SCRIPTS + $(INSTALL) -m 0755 -D package/wpa_supplicant/ifupdown.sh \ + $(TARGET_DIR)/etc/network/if-up.d/wpasupplicant + ln -sf ../if-up.d/wpasupplicant $(TARGET_DIR)/etc/network/if-down.d/wpasupplicant +endef +endif + define WPA_SUPPLICANT_INSTALL_TARGET_CMDS $(INSTALL) -m 0755 -D $(@D)/$(WPA_SUPPLICANT_SUBDIR)/wpa_supplicant \ $(TARGET_DIR)/usr/sbin/wpa_supplicant
@@ -259,8 +267,10 @@ define WPA_SUPPLICANT_INSTALL_TARGET_CMDS $(WPA_SUPPLICANT_INSTALL_PASSPHRASE) $(WPA_SUPPLICANT_INSTALL_DBUS) $(WPA_SUPPLICANT_INSTALL_WPA_CLIENT_SO) + $(WPA_SUPPLICANT_INSTALL_IFUP_SCRIPTS) endef + define WPA_SUPPLICANT_INSTALL_INIT_SYSTEMD $(INSTALL) -m 0644 -D $(@D)/$(WPA_SUPPLICANT_SUBDIR)/systemd/wpa_supplicant.service \ $(TARGET_DIR)/usr/lib/systemd/system/wpa_supplicant.service
Signature · 6 lines
2.25.1 _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
Re: [Buildroot] [PATCH v2 2/3] package/wpa_supplicant: adding ifupdown support
Quoted 60 lines · Angelo Compagnucci
Actually, configuring a wifi interface as per "interfaces" man:
auto wlan0
iface wlan0 inet dhcp
wpa-conf/etc/wpa_supplicant.confdoesn't work on buildroot because the line wpa-conf is ignored due to the lack of a proper ifupdown script to handle the
wpa_supplicantinitialization.Signed-off-by Angelo Compagnucci <[email protected]>---
v1 -> v2:
* Simplify script to the minimum to have the service started (Thomas, Nicolas)package/wpa_supplicant/ifupdown.sh | 48 ++++++++++++++++++++++++ package/wpa_supplicant/wpa_supplicant.mk | 10 +++++ 2 files changed, 58 insertions(+)create mode 100755
package/wpa_supplicant/ifupdown.shpackage/wpa_supplicant/ifupdown.sh new file +33
-0@@ -0,0 +1,48 @@ +#!/bin/sh + +# This file is executed by ifupdown in pre-up, post-up, pre-down and +# post-down phases of network interface configuration. + +WPA_SUP_BIN="/usr/sbin/wpa_supplicant" + +# Allow wpa_supplicant interface to be specified via wpa-iface +# useful for starting wpa_supplicant on one interface of a bridge +if [ -n "$IF_WPA_IFACE" ]; then + WPA_IFACE="$IF_WPA_IFACE" +else + WPA_IFACE="$IFACE" +fi + +WPA_SUP_PIDFILE="/run/wpa_supplicant.${WPA_IFACE}.pid" + +do_start () { + [ -z "$IF_WPA_CONF" ] && exit 0 + + if [ ! -s "$IF_WPA_CONF" ]; then + echo "cannot read contents of $IF_WPA_CONF" + exit 1 + fi + WPA_SUP_CONF="-c $IF_WPA_CONF" +} + +case "$MODE" in + start) + do_start + case "$PHASE" in + post-up) + start-stop-daemon -S -q -x ${WPA_SUP_BIN} \
package/wpa_supplicant/ifupdown.sh line 43
Quoted 10 lines
package/wpa_supplicant/ifupdown.sh new file +10
-0+ -- -B -i ${WPA_IFACE} ${WPA_SUP_CONF} -P ${WPA_SUP_PIDFILE} + ;; + esac + ;; + + stop) + case "$PHASE" in + pre-down) + start-stop-daemon -K -p ${WPA_SUP_PIDFILE} + ;;
Now this script will still attempt to stop wpa_supplicant on all interfaces even without a wpa-conf option. The [ -z "$IF_WPA_CONF" ] check need to be done earlier.
Quoted 11 lines
package/wpa_supplicant/ifupdown.sh new file +5
-0+ esac + ;; +esac + +exit 0package/wpa_supplicant/wpa_supplicant.mk +0
-0
package/wpa_supplicant/wpa_supplicant.mk define WPA_SUPPLICANT_INSTALL_TARGET_CMDS · line 273
Quoted 7 lines
package/wpa_supplicant/wpa_supplicant.mk +2
-0@@ -259,8 +267,10 @@ define WPA_SUPPLICANT_INSTALL_TARGET_CMDS $(WPA_SUPPLICANT_INSTALL_PASSPHRASE) $(WPA_SUPPLICANT_INSTALL_DBUS) $(WPA_SUPPLICANT_INSTALL_WPA_CLIENT_SO) + $(WPA_SUPPLICANT_INSTALL_IFUP_SCRIPTS) endef +
This added blank line should probably go away.
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
PATCH v2 3/3 package/busybox: make udhcp discover faster
In reply to Angelo CompagnucciInstead of waiting almost 10 seconds foreground (3 discovery packets for 3 seconds retry delay) at each boot, make only one request then fork to background. This way, the behavior is the same for working interfaces, but it's way faster for interfaces where the address cannot be obtained straight away.
--- package/busybox/busybox.config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
package/busybox/busybox.config +1 -1
@@ -1022,7 +1022,7 @@ CONFIG_UDHCP_DEBUG=0 CONFIG_UDHCPC_SLACK_FOR_BUGGY_SERVERS=80 CONFIG_FEATURE_UDHCP_RFC3397=y CONFIG_FEATURE_UDHCP_8021Q=y -CONFIG_IFUPDOWN_UDHCPC_CMD_OPTIONS="-b -R -O search" +CONFIG_IFUPDOWN_UDHCPC_CMD_OPTIONS="-t1 -b -R -O search" # # Print Utilities
Signature · 6 lines
2.25.1 _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot