#!/bin/sh # The driver site: http://damien.bergamini.free.fr/ipw/ # This script requires cdialog (console) and Xdialog (X) to run. # Jun 14 2005 by yazzy[at]yazzy[dot]org # Some variables: SUDO=${SUDO:-`which sudo`} # Location of cdrdao IWICTRL=${IWICTRL:-`which iwicontrol`} WICTRL=${WICTRL:-`which wicontrol`} IFCONFIG=${IFCONFIG:-`which ifconfig`} ROUTE=${ROUTE:-`which route`} WLAN_NIC0="iwi0" # Name of the WLAN nic IP_ADDRESS="192.168.1.10" # IP address of the WLAN nic SSID="YOUR_SSID" # SSID of the AP we connect to GW_IP="192.168.1.254" # Our default route NETMASK="255.255.255.0" # Netmask CHECKLIST=`mktemp /tmp/checklist.tmp.XXXXXXXX` # Temp file if [ -z $DISPLAY ] then DIALOG=${DIALOG:-`which cdialog`} else DIALOG=${DIALOG:-`which Xdialog`} fi # Our functions: iwi_start() { # Add if_iwi_load="YES" to /boot/loader.conf to automaticly load the kernel module kldstat | grep iwi 1>/dev/null 2>/dev/null if [ "$?" = "1" ] then ${SUDO} kldload if_iwi else echo "" echo "The ${WLAN_NIC0} module already loaded, proceeding..." echo "" fi ${SUDO} ${IWICTRL} -i ${WLAN_NIC0} -d /usr/local/libdata/if_iwi -m bss >|/tmp/ERRORS$$ 2>&1 ${SUDO} ${IWICTRL} -i ${WLAN_NIC0} -r >> /tmp/ERRORS$$ 2>&1 ${SUDO} ${IFCONFIG} ${WLAN_NIC0} inet ${IP_ADDRESS} netmask ${NETMASK} ssid ${SSID} >>/tmp/ERRORS$$ 2>&1 ${SUDO} ${ROUTE} delete default >>/tmp/ERRORS$$ 2>&1 ${SUDO} ${ROUTE} add default ${GW_IP} >>/tmp/ERRORS$$ 2>&1 # zero status indicates the command was successful, 255 indicates failure. if [ "$?" = "0" ] then $DIALOG --title "Proceeding request on ${WLAN_NIC0} nic." --msgbox "The command was completed successfully." 10 50 else # Something failed, display error log $DIALOG --title "Starting the ${WLAN_NIC0} nic." --msgbox "Action failed -- Press to see error log." 10 50 $DIALOG --title "Error Log" --textbox /tmp/ERRORS$$ 22 83 fi rm -f /tmp/ERRORS$$ run_script } # Kill the formware and reset adapter iwi_stop() { (echo "10" ; sleep 2 ; ${SUDO} ${IWICTRL} -i ${WLAN_NIC0} -k >|/tmp/ERRORS$$ 2>&1 ${SUDO} kldunload if_iwi >>/tmp/ERRORS$$ 2>&1 echo "75" ; sleep 1 echo "100") | \ $DIALOG --title "Proceeding request" --gauge "Please wait..." 10 40 0 # zero status indicates the command was successful if [ "$?" = "0" ] then $DIALOG --title "Request on ${WLAN_NIC0} nic." --msgbox "The command was completed successfully." 10 50 else # Something failed, display error log $DIALOG --title "Stopping the ${WLAN_NIC0} nic." --msgbox "Action failed -- Press to see error log." 10 50 $DIALOG --title "Error Log" --textbox /tmp/ERRORS$$ 22 83 fi rm -f /tmp/ERRORS$$ run_script # clear } iwi_restart() { iwi_stop iwi_start } # List avaliable access points iwi_list() { ${SUDO} ${WICTRL} -i ${WLAN_NIC0} -l >|/tmp/ERRORS$$ 2>&1 $DIALOG --title "Avaliable access points" --textbox /tmp/ERRORS$$ 25 60 rm -f /tmp/ERRORS$$ run_script } # Show the stats iwi_stats() { (echo "10" ; sleep 2 ; ${SUDO} ${IWICTRL} -i ${WLAN_NIC0} >|/tmp/ERRORS$$ 2>&1 echo "75" ; sleep 1 echo "100") | \ $DIALOG --title "Proceeding request" --gauge "Please wait..." 10 40 0 $DIALOG --title "Connection stats" --textbox /tmp/ERRORS$$ 45 60 rm -f /tmp/ERRORS$$ run_script } iwi_quit() { if [ "$?" = 255 ] ; then echo "Bye !" fi } run_script() { MAINMENU=`cat <<-EOF This is simple frontend to setup your WLAN card. Press chose an option. EOF ` ${DIALOG} --title "Menu of ${WLAN_NIC0} setup." --clear \ --radiolist "${MAINMENU}" 24 42 5 \ "START" "Start your ${WLAN_NIC0} nic." off \ "STOP" "Stop your ${WLAN_NIC0} nic." off \ "RESTART" "Restart your ${WLAN_NIC0} nic." off \ "STATS" "Stats of your ${WLAN_NIC0} nic." off \ "LIST" "List avaliable connections." off \ "QUIT" "Quit this application." on 2> ${CHECKLIST} || exit $? CHOICE=`cat ${CHECKLIST}` rm -f ${CHECKLIST} #echo "CHOICE = ${CHOICE}" case ${CHOICE} in START) iwi_start ;; STOP) iwi_stop ;; RESTART) iwi_restart ;; STATS) iwi_stats ;; LIST) iwi_list ;; QUIT) iwi_quit ;; esac # # Exit with no errors. # exit 0 } run_script rm -f ${CHECKLIST}