#!/bin/sh
# $Id: ifup-wlan0,v 1.2 2006/06/30 19:20:03 bsd3 Exp $

# list of modules to load; DON'T change the order here! 
MODULES=` cat <<EOL
net/ieee80211/ieee80211_crypt-rtl.ko 
net/ieee80211/ieee80211_crypt_wep-rtl.ko 
net/ieee80211/ieee80211_crypt_tkip-rtl.ko 
net/ieee80211/ieee80211_crypt_ccmp-rtl.ko 
net/ieee80211/ieee80211-rtl.ko 
drivers/net/wireless/rtl818x/rtl818x.ko 
EOL
`

# do we have all the requisite modules? 
for module in ${MODULES}; do
    if [ ! -f ${module} ]; then
	MISSING="yes"
    fi
done

# exit, if modules missing
if [ -n "${MISSING}" ]; then
    echo -e "ifup-wlan0: requisite modules not found! try running make./a"
    exit -1
fi

# make sure the wlan0 interface is down, and remove the stale 
# moudules
. ./ifdown-wlan0

# wanna test via ndiswarpper?
if [ "${1}" = "ndis" ]; then 
    modprobe ndiswrapper
else
    # remove module ndiswrapper! silently.
    rmmod ndiswrapper >/dev/null 2>&1

    # insmod all modules
    for module in ${MODULES}; do
	insmod ${module} >/dev/null 2>&1
    done
fi

# make it up
ifup wlan0

# that's all :)
