The following init script will setup your Broadcom BCM4318 using WPA, assuming you have a wpa_supplicant.conf script in /etc.
Code:
#! /bin/sh
### BEGIN INIT INFO
# Provides: wpa-connect
# Required-Start: networking
# Required-Stop: networking
# Default-Start: 2 3 4 5
# Default-Stop: S 0 1 6
# Short-Description: Connects a wireless interface to an access point using WPA
# Description: This file should be used to construct scripts to be
# placed in /etc/init.d.
### END INIT INFO
# Author: David Cullen <dcullen@kerneldriver.org>
#
# Please remove the "Author" lines above and replace them
# with your own name if you copy and modify this script.
# Do NOT "set -e"
# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/usr/sbin:/usr/bin:/sbin:/bin
INTERFACE="eth1"
DESC="wpa-connect"
NAME="${DESC}-${INTERFACE}"
LOGFILE="/var/log/wpa-connect.log"
# Load the VERBOSE setting and other rcS variables
[ -f /etc/default/rcS ] && . /etc/default/rcS
# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions
#
# Function that starts the daemon/service
#
wpa_connect()
{
# Return
# 0 if daemon has been started
# 1 if daemon was already running
# 2 if daemon could not be started
echo "Connecting to access point using WPA..." >> ${LOGFILE}
if ! /sbin/wpa_supplicant -Dwext -i${INTERFACE} -c/etc/wpa_supplicant/wpa_supplicant.conf -B >> ${LOGFILE} 2>&1 ; then
echo "Could not configure WPA for ${INTERFACE}" >> ${LOGFILE}
return 1;
fi
echo "Done." >> ${LOGFILE}
echo "Starting DHCP..." >> ${LOGFILE}
if ! dhclient ${INTERFACE} >> ${LOGFILE} 2>&1 ; then
echo "Could start DHCP for ${INTERFACE}" >> ${LOGFILE}
return 1;
fi
echo "Done." >> ${LOGFILE}
return $RETVAL
}
wpa_disconnect()
{
# Return
# 0 if daemon has been stopped
# 1 if daemon was already stopped
# 2 if daemon could not be stopped
# other if a failure occurred
echo "Stopping DHCP..." >> ${LOGFILE}
if ! skill dhclient >> ${LOGFILE} 2>&1 ; then
echo "Could not stop DHCP" >> ${LOGFILE}
return 1;
fi
echo "Done." >> ${LOGFILE}
echo "Disconnecting WPA..." >> ${LOGFILE}
if ! skill wpa_supplicant >> ${LOGFILE} 2>&1 ; then
echo "Could not disconnect WPA" >> ${LOGFILE}
return 1;
fi
echo "Done." >> ${LOGFILE}
return $RETVAL
}
start()
{
log_begin_msg "Connecting ${INTERFACE} to access point using WPA..."
wpa_connect
RETVAL=$?
[ $RETVAL -eq 0 ] && log_end_msg 0 || log_end_msg 1
echo
return $RETVAL
}
stop()
{
log_begin_msg "Disconnection ${INTERFACE} from access point using WPA..."
wpa_disconnect
RETVAL=$?
[ $RETVAL -eq 0 ] && log_end_msg 0 || log_end_msg 1
echo
return $RETVAL
}
case "$1" in
start)
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
start
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
stop)
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
stop
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
#reload|force-reload)
#
# If do_reload() is not implemented then leave this commented out
# and leave 'force-reload' as an alias for 'restart'.
#
#log_daemon_msg "Reloading $DESC" "$NAME"
#do_reload
#log_end_msg $?
#;;
restart|force-reload)
#
# If the "reload" option is implemented then remove the
# 'force-reload' alias
#
log_daemon_msg "Restarting $DESC" "$NAME"
stop
case "$?" in
0|1)
start
case "$?" in
0) log_end_msg 0 ;;
1) log_end_msg 1 ;; # Old process is still running
*) log_end_msg 1 ;; # Failed to start
esac
;;
*)
# Failed to stop
log_end_msg 1
;;
esac
;;
*)
#echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
exit 3
;;
esac
:
You will need a wpa_supplicant.conf file that looks like this:
Code:
ctrl_interface=/var/run/wpa_supplicant
network={
ssid="Your SSID"
psk="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
key_mgmt=WPA-PSK
proto=WPA
pairwise=TKIP
group=TKIP
}
You install it using
# update-rc.d wlan-config defaults
You uninstall it using
# update-rc.d -f wlan-config remove