hostapd: parametrize hostapd init script per interface

The original init script hardcodes the configuration file to use so it
cannot be re-utilized for concurrent AP/AP mode where two interfaces can
be used as SoftAP.

This commit uses the variable ${IFACE} to:
- select a specific configuration file per interface:
  /etc/hostapd_${IFACE}.conf
- create a specific PID file per interface:
  /var/run/hostapd.${IFACE}.pid

With this, the /etc/network/interfaces can use the script for using SoftAP
in different wireless interfaces.

Signed-off-by: Hector Palacios <hector.palacios@digi.com>
This commit is contained in:
Hector Palacios 2017-03-31 13:00:43 +02:00
parent 5d2d0011d0
commit 2dcf33b283
4 changed files with 72 additions and 5 deletions

View File

@ -4,7 +4,7 @@ interface=wlan1
driver=nl80211 driver=nl80211
# WPA2-AES encryption # WPA2-AES encryption
ssid=ap-wpa2aes_a ssid=ap-wlan1-wpa2aes_a
auth_algs=1 auth_algs=1
wpa=2 wpa=2
wpa_key_mgmt=WPA-PSK wpa_key_mgmt=WPA-PSK

View File

@ -4,7 +4,7 @@ interface=wlan0
driver=nl80211 driver=nl80211
# WPA2-AES encryption # WPA2-AES encryption
ssid=ap-wpa2aes_a ssid=ap-wlan0-wpa2aes_a
auth_algs=1 auth_algs=1
wpa=2 wpa=2
wpa_key_mgmt=WPA-PSK wpa_key_mgmt=WPA-PSK

View File

@ -0,0 +1,59 @@
#!/bin/sh
DAEMON=/usr/sbin/hostapd
NAME=hostapd
DESC="HOSTAP Daemon"
PIDFILE="/var/run/hostapd.${IFACE}.pid"
ARGS="/etc/hostapd_${IFACE}.conf -B -P ${PIDFILE}"
test -f $DAEMON || exit 0
set -e
# source function library
. /etc/init.d/functions
delay_stop() {
count=0
while [ $count -lt 9 ] ; do
if pidof $DAEMON >/dev/null; then
sleep 1
else
return 0
fi
count=`expr $count + 1`
done
echo "Failed to stop $DESC."
return 1
}
case "$1" in
start)
echo -n "Starting $DESC: "
start-stop-daemon -S -x $DAEMON -- $ARGS
echo "$NAME."
;;
stop)
echo -n "Stopping $DESC: "
start-stop-daemon -K --oknodo -x $DAEMON -p ${PIDFILE}
echo "$NAME."
;;
restart)
$0 stop
delay_stop && $0 start
;;
reload)
echo -n "Reloading $DESC: "
killall -HUP $(basename ${DAEMON})
echo "$NAME."
;;
status)
status $DAEMON
exit $?
;;
*)
echo "Usage: $0 {start|stop|restart|reload|status}"
exit 1
;;
esac
exit 0

View File

@ -2,11 +2,19 @@
FILESEXTRAPATHS_prepend := "${THISDIR}/${BPN}:" FILESEXTRAPATHS_prepend := "${THISDIR}/${BPN}:"
SRC_URI += "file://hostapd.conf" SRC_URI_append = " file://hostapd_wlan0.conf"
SRC_URI_append_ccimx6ul = " file://hostapd_wlan1.conf"
do_install_append() { do_install_append() {
# Overwrite the default hostapd.conf with our custom file # Remove the default hostapd.conf
install -m 0644 ${WORKDIR}/hostapd.conf ${D}${sysconfdir} rm -f ${WORKDIR}/hostapd.conf
# Install custom hostapd_IFACE.conf file
install -m 0644 ${WORKDIR}/hostapd_wlan0.conf ${D}${sysconfdir}
}
do_install_append_ccimx6ul() {
# Install custom hostapd_IFACE.conf file
install -m 0644 ${WORKDIR}/hostapd_wlan1.conf ${D}${sysconfdir}
} }
# Do not autostart hostapd daemon, it will conflict with wpa-supplicant. # Do not autostart hostapd daemon, it will conflict with wpa-supplicant.