#!/bin/sh
# Copyright 2011 Paul Parsons
# Distributed under the terms of the GNU General Public License v3 or later

depend="base"
service --depend ${depend} || exit 1

case $1 in
"start")
	echo "/sbin/hotplug" > /proc/sys/kernel/hotplug
	modprobe acx-mac80211 || exit 1
	echo "" > /proc/sys/kernel/hotplug

	daemon --start --label=$0.wpa /usr/sbin/wpa_supplicant -c /etc/wpa_supplicant.conf -i wlan0 -D nl80211
	while [ ! -S /var/run/wpa_supplicant/wlan0 ]
	do
		sleep 0.25
	done

	daemon --start --label=$0.dhcp /usr/sbin/udhcpc -f -i wlan0
	;;
"stop")
	daemon --stop --label=$0.dhcp
	daemon --stop --label=$0.wpa
	rmmod acx-mac80211
	;;
esac

exit 0
