#!/sbin/runscript # Writen by guido socher # Distributed under the terms of the GNU General Public License v2 depend() { need localmount after bootmisc hostname net.eth0 } start() { local retval=0 if (ifconfig eth0 | egrep UP) > /dev/null 2>&1; then ewarn "eth0: eth0 already up, will not start wlan0" return 1 fi ebegin "wlan0: Bringing wlan0 up" ifconfig wlan0 up # we need to do this to bring the radio up # wait for wlan to initialize einfo "wlan0: scanning for wlans ..." sleep 1 # wait for startup and firmware # cache this isn a file, zero the file first cp /dev/null /var/log/wlans.log iwlist wlan0 scanning > /var/log/wlans.log # make a nice printout egrep 'ESSID|Quality' /var/log/wlans.log| perl -pe 's/\s+Signal\s+level=/, /;s/^\s+//;chomp unless(/ESSID/);' if grep -q "sansfil" /var/log/wlans.log ; then ESSID="sansfil" fi if [ -n "$ESSID" ]; then einfo "wlan0: configure for AP ${ESSID} ..." # wep encryption: iwconfig wlan0 mode Managed iwconfig wlan0 key restricted c78ca48918c0d8c84a7e817c8e # associate: iwconfig wlan0 essid ${ESSID} || eerror "wlan0: ERROR: could not set essid ${ESSID}" #wpa_supplicant -Bw -c/etc/wpa_supplicant.conf -iwlan0 -Dwext n=0 # wait max 7 sec: associated=0 while [ "$n" -lt "7" ]; do sleep 1 # we have either # wlan0 unassociated ESSID:"sansfil" # or # wlan0 IEEE 802.11g ESSID:"sansfil" if iwconfig wlan0 | egrep -q 'IEEE.*ESSID:' ; then associated=1 n=20 else n=`expr $n + 1` fi done if [ "$associated" == "0" ]; then ifconfig wlan0 down eerror "wlan0: ERROR: could not associate" fi einfo `iwconfig wlan0 | egrep 'ESSID|Quality|Rate'| perl -pe 's/ Tx-Power.*//;s/ Signal.*//;s/\s+/ /g;s/^.*ESSID/ESSID/;chomp;'` # enable power management #iwpriv wlan0 set_power 7 ifconfig wlan0 10.0.0.5 netmask 255.255.255.0 route add default gw 10.0.0.2 else ifconfig wlan0 down eend 1 "wlan0: sansfil ap not available" return 1 fi if ! ifconfig wlan0| grep -q UP; then eend 1 "wlan0: down" return 1 fi #einfo "${IFACE}: running /sbin/dhcpcd ${dhcpcd_IFACE} ${IFACE} ..." #/sbin/dhcpcd ${dhcpcd_IFACE} ${IFACE} >/dev/null || { # retval=$? # eend ${retval} "Failed to bring ${IFACE} up" # return ${retval} #} #if [ "${retval}" = "0" ]; then # if grep -q 10.0.0.2 /etc/resolv.conf ; then if [ -f /etc/resolv.conf.flockedns ]; then einfo "wlan0: using /etc/resolv.conf.flockedns ..." if [ -f /etc/resolv.conf ]; then mv -f /etc/resolv.conf /etc/resolv.conf.bak fi cp /etc/resolv.conf.flockedns /etc/resolv.conf fi eend 0 } stop() { ebegin "Bringing wlan0 down" /sbin/ifconfig wlan0 down # dhcpcdpid=`pidof dhcpcd` # if [ "${iface_IFACE}" = "dhcp" -a -n "$dhcpcdpid" ] # then # local count=0 # while ifconfig | egrep "^${IFACE}" >/dev/null && [ "${count}" -lt 4 ] # do # /sbin/dhcpcd -k ${IFACE} # # Give dhcpcd time to properly shutdown # sleep 1 # count=$((count + 1)) # done # if [ "${count}" -ge 2 ] # then # eerror "Timed out trying to stop dhcpcd" # fi # else # /sbin/ifconfig ${IFACE} down >/dev/null # fi #killall wpa_supplicant eend 0 } # vim:ts=4 et