#!/bin/sh
####################################################################
## killVAP
##
## This script is used to destroy a VAP, or if you want complete
## destruction, specify all.  Using the all option will also unload
## the wlan modules.
##
## The form of the command is
##
## killVAP <VAP>
##
## Where VAP is the name of the VAP (e.g. ath0).  Specifying "ALL"
## for the VAP will cause all VAPs to be removed, and the module unload
## script to be executed.
##
## Examples:
##      killVAP ath1
##      killVAP all
##
###################################################################
. ./apcfg

if [ "${1}" = "" ]; then
    echo "    killVAP usage"
    echo "    killVAP [VAP]"
    exit
fi

##
## If the modules are already unloaded, we don't need to do anything
##

MODLIST=`lsmod | grep ath_hal`

if [ "${MODLIST}" = "" ]; then
   echo "Modules already unloaded"
   exit
fi

SUPPLIST=`ps -e | grep wpa_supplicant | cut -b 1-5`
if [ "${SUPPLIST}" != "" ]; then
    for i in $SUPPLIST ; do
        echo "killing $i"
        kill -9 $i
    done
fi

#
# Bring the interface down
#

ifconfig $1 down
sleep 1
echo "killing $1"
wlanconfig $1 destroy

SUPPLIST=`ps | grep sup$1 | cut -b 1-5`
if [ "${SUPPLIST}" != "" ]; then
    for i in $SUPPLIST ; do
        echo "killing $i"
        kill -9 $i
    done
fi

modprobe -r wlan_acl
modprobe -r wlan_wep
modprobe -r wlan_tkip
modprobe -r wlan_ccmp
modprobe -r wlan_xauth
modprobe -r wlan_scan_sta
