Message ID | 20220607151719.2305134-3-angelo@amarulasolutions.com |
---|---|
State | Superseded |
Headers | show |
Series | Better wifi handling | expand |
On 07/06/2022 17:17, Angelo Compagnucci wrote: > Actually, 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. > > Signed-off-by: Angelo Compagnucci <angelo@amarulasolutions.com> > --- > 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 > > diff --git a/package/wpa_supplicant/ifupdown.sh b/package/wpa_supplicant/ifupdown.sh > new file mode 100755 > index 0000000000..7321c7602f > --- /dev/null > +++ b/package/wpa_supplicant/ifupdown.sh > @@ -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} > + ;; 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. > + esac > + ;; > +esac > + > +exit 0 > diff --git a/package/wpa_supplicant/wpa_supplicant.mk b/package/wpa_supplicant/wpa_supplicant.mk > index c4cfe03371..d38bf572db 100644 > --- a/package/wpa_supplicant/wpa_supplicant.mk > +++ b/package/wpa_supplicant/wpa_supplicant.mk > [...] > @@ -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.
diff --git a/package/wpa_supplicant/ifupdown.sh b/package/wpa_supplicant/ifupdown.sh new file mode 100755 index 0000000000..7321c7602f --- /dev/null +++ b/package/wpa_supplicant/ifupdown.sh @@ -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 diff --git a/package/wpa_supplicant/wpa_supplicant.mk b/package/wpa_supplicant/wpa_supplicant.mk index c4cfe03371..d38bf572db 100644 --- a/package/wpa_supplicant/wpa_supplicant.mk +++ b/package/wpa_supplicant/wpa_supplicant.mk @@ -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
Actually, 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. Signed-off-by: Angelo Compagnucci <angelo@amarulasolutions.com> --- 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