#!/bin/sh # /etc/rc.conf: # # ifwi=YES # ifwi_list="ath0" # wireless NICs you have onboard, white-space separated # # setup differents wireless ids with corresponding NICs # in the following example, ath0 with id "work" # please note id is NOT the ssid but an id of your choice # # ifwi_ath0_work="inet 192.168.0.200/24 chan 11 ssid \"work wi\" media \ # DS11 mode 11b nwkey 0x0102030405" # # another link, with id "home" # # ifwi_ath0_home="inet 192.168.2.2/24 chan 6 ssid \"home wi\" mediaopt \ # adhoc mode 11b" # # ifwi_ath0_friend="chan 6 ssid \"somewhere\" -nwkey" # # define default routes corresponding to id's # # router_ath0_home="192.168.2.1" # router_ath0_work="192.168.0.254" # # start dhclient for this id # # dhcp_ath0_friend="YES" # # usage # # ifwi start home # will start with home id # ifwi show # show availables APs # ifwi start downtown # scan availables APs and up on any matching AP ssid, # # for example, here ifwi will match on downtown2, # # "the downtown", ... # # IP / routing / dhclient call must be done manually # ifwi stop # ifconfig down every listed wireless interface # # comments / patches: id=$2 . /etc/rc.subr name="ifwi" rcvar=$name extra_commands="show" start_cmd="${name}_start" stop_cmd="${name}_stop" show_cmd="${name}_show" # override rc.subr classic rc_usage() as we need additionnal parameter rc_usage() { echo "Usage: $0 (start | stop | show)" exit 1 } getval() { value=`echo $ap | awk -F"$key" '{print $2}' | \ sed -e 's/\ *\].*//' -e 's/.*\[\ *//'` } ifwi_scan() { out=`wiconfig $if -D` # extract first matching AP from AP list ap=`echo $out | sed 's/.*\([^B]SSID.*${id}.*\)/\1/'` if [ -n "$ap" ]; then key=SSID; getval; ssid=$value key=Channel; getval; channel=$value else echo "no matching ap" fi } ifwi_start() { if [ -z $ifwi_list ]; then echo "no \$ifwi_list parameter set" exit 1 fi if [ -z "$id" ]; then usage fi for if in $ifwi_list; do # interface setup eval args=\$ifwi_${if}_${id} if [ -n "$args" ]; then # there was an ifwi__ def in rc.conf ifconfig_args="$if $args" else # no def, scan for a network matching argument ifwi_scan if [ -z "$ssid" ] && [ -z "$channel" ]; then echo "no ap found" exit 1 fi ifconfig_args="$if inet ssid \"$ssid\" chan $channel -nwkey" fi echo "[$name] running ifconfig $ifconfig_args" eval "ifconfig $ifconfig_args up" eval args=\$dhcp_${if}_${id} if [ -n "$args" ] && checkyesno args; then eval "dhclient $if" else # route setup eval args=\$router_${if}_${id} if [ -n "$args" ]; then # delete previous default route if any route delete default > /dev/null 2>&1 route add default $args > /dev/null 2>&1 echo "[$name] default route set to $args" fi fi # dhcp done } ifwi_stop() { for if in $ifwi_list; do ifconfig $if down echo "[$name] shutting $if" done } ifwi_show() { for if in $ifwi_list; do echo "[$name] access points list for $if" wiconfig $if -D done } load_rc_config $name run_rc_command "$1"