#!/bin/bash

WEPKEY=xxxxxxxxxxxxxxxxxxxxxxxxxx

insmod=/sbin/modprobe
lsmod=/sbin/lsmod
rmmod="/sbin/modprobe -r"
iwpriv="/usr/sbin/iwpriv wlan0"
ifconfig="/sbin/ifconfig wlan0"

wp="$iwpriv wlan_para"
we="$iwpriv enable"
wd="$iwpriv disable"

. /etc/rc.status
 
case "$1" in
    start)
	echo -n "Starting WLAN"

	#Load module
	$lsmod | grep rtl8180_24x >/dev/null || $insmod rtl8180_24x

	#Set SSID
	for i in channel=1 \
		 ssid2scan= \
		 authtype=both \
		 wepmode=wep104 \
		 wepdkeyid=0 \
		 wepkey104_1=$WEPKEY; do
	    $wp $i
	done
	$we
	dhcpcd wlan0 &
	rc_status -v
	;;
    stop)
	echo -n "Shutting WLAN down"

	#Shut down wlan0 net interface
	$ifconfig down 

	#Disable wireless lan driver
	$wd

	#Unload module
	$rmmod rtl8180_24x
	rc_status -v
	;;
esac
