Create a gist now

Instantly share code, notes, and snippets.

@skl /hostapd
Last active May 12, 2017

What would you like to do?
Reliable hostapd init script - example with brcmfmac driver in GB region - See http://skl.me/#wifi-access-point-in-debian
#!/bin/sh
### BEGIN INIT INFO
# Provides: hostapd
# Required-Start: $remote_fs
# Required-Stop: $remote_fs
# Should-Start: $network
# Should-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Advanced IEEE 802.11 management daemon
# Description: Userspace IEEE 802.11 AP and IEEE 802.1X/WPA/WPA2/EAP
# Authenticator
### END INIT INFO
PATH=/sbin:/bin:/usr/sbin:/usr/bin
DAEMON_SBIN=/usr/sbin/hostapd
DAEMON_CONF=/etc/hostapd/hostapd.conf
NAME=hostapd
DESC="advanced IEEE 802.11 management"
PIDFILE=/var/run/hostapd.pid
[ -x "$DAEMON_SBIN" ] || exit 0
[ -n "$DAEMON_CONF" ] || exit 0
DAEMON_OPTS="-B -P $PIDFILE $DAEMON_OPTS $DAEMON_CONF"
. /lib/lsb/init-functions
case "$1" in
start)
log_daemon_msg "Starting $DESC" "$NAME"
modprobe brcmfmac
sleep 2
rfkill unblock wifi
ip link set wlan0 up
iw wlan0 set power_save off
ifconfig wlan0 192.168.100.1
start-stop-daemon --start --quiet --exec "$DAEMON_SBIN" \
--pidfile "$PIDFILE" -- $DAEMON_OPTS >/dev/null
log_end_msg "$?"
;;
stop)
log_daemon_msg "Stopping $DESC" "$NAME"
start-stop-daemon --stop --quiet --exec "$DAEMON_SBIN" \
--pidfile "$PIDFILE"
ip link set wlan0 down
modprobe -r brcmfmac
log_end_msg "$?"
;;
reload)
log_daemon_msg "Reloading $DESC" "$NAME"
start-stop-daemon --stop --signal HUP --exec "$DAEMON_SBIN" \
--pidfile "$PIDFILE"
log_end_msg "$?"
;;
restart|force-reload)
$0 stop
sleep 2
$0 start
;;
status)
start-stop-daemon -p "$PIDFILE" --status
exit $?
;;
*)
N=/etc/init.d/$NAME
echo "Usage: $N {start|stop|restart|force-reload|reload|status}" >&2
exit 1
;;
esac
exit 0
ssid=
wpa_passphrase=
interface=wlan0
hw_mode=g
channel=6
country_code=GB
ieee80211d=1
ieee80211h=1
ieee80211n=1
wmm_enabled=1
wme_enabled=1
auth_algs=1
wpa=2
wpa_key_mgmt=WPA-PSK
rsn_pairwise=CCMP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment