package/wpa_supplicant: adding ifupdown support

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>
Reviewed-by: Nicolas Cavallari <nicolas.cavallari@green-communications.fr>
Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
This commit is contained in:
Angelo Compagnucci 2022-06-13 00:07:28 +02:00 committed by Arnout Vandecappelle (Essensium/Mind)
parent a76294cd6c
commit eed183e67e
2 changed files with 58 additions and 0 deletions

View File

@ -0,0 +1,49 @@
#!/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"
# run this script only for interfaces which have wpa-conf option
[ -z "$IF_WPA_CONF" ] && exit 0
# 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 () {
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

View File

@ -256,6 +256,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
@ -265,6 +273,7 @@ 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)
$(WPA_SUPPLICANT_ENABLE_CTRL_IFACE)
endef