it would be nice to have the possibility to automatically configure wireless connections when booting. some services need an internet connection in order to start (like ntpdate). if you start wireless later, you lose the opportunity to initialize these. unfortunately, dhclient is of no use with a non-associated wireless card. the possibility to associate early with an access point is missing. i would like to have something like this in rc.conf.local: wireless_enable="YES" wiereless_flags="wi0 SSID0 0xKEY0 wi1 SSID1 0xKEY1" the following script (to be installed in /etc/rc.d) does the job: #!/bin/sh # $Id: wireless,v 1.2 2004/10/21 14:10:27 root Exp $ # PROVIDE: wireless # REQUIRE: mountcritlocal # BEFORE: dhclient # KEYWORD: FreeBSD . /etc/rc.subr name="wireless" rcvar=`set_rcvar` start_cmd="wireless_start" wireless_start(){ for item in ${wireless_flags} do # read items if [ -z "$if" ]; then if=$item elif [ -z "$ssid" ]; then ssid=$item elif [ -z "$key" ]; then key=$item fi # configure if [ -n "$if" -a -n "$ssid" -a -n "$key" ]; then echo -n configuring interface $if / $ssid ... if ifconfig $if 2>&1|grep -q 'does not exist'; then echo ' does not exist' elif ifconfig $if | grep -q 'status: associated'; then echo ' already configured' else ifconfig $if inet 0.0.0.0 powersave wepmode on\ station wlan ssid $ssid wepkey $key if ifconfig $if | grep -q 'status: associated'; then echo ' ok' else echo ' no association' ifconfig $if down fi fi if='' ssid='' key='' fi done } load_rc_config $name run_rc_command "$1" Fix: --- How-To-Repeat: ---
hi, an updated version of the script: - code rearrange - allow for non-WEP setup (keyword: "none") - shutdown the interfaces ================================================================================ #!/bin/sh # $Id: wireless,v 1.10 2004/10/23 14:00:21 root Exp $ # PROVIDE: wireless # REQUIRE: mountcritlocal # BEFORE: dhclient # KEYWORD: FreeBSD . /etc/rc.subr name="wireless" rcvar=`set_rcvar` start_cmd="wireless_start" stop_cmd="wireless_stop" # global: list of processed interfaces ifs='' # if_start $if $ssid $key if_start(){ if=$1 ssid=$2 key=$3 echo -n configuring interface $if / $ssid ... if ifconfig $if 2>&1|grep -q 'does not exist'; then echo ' does not exist' elif ifconfig $if | grep -q 'status: associated'; then echo ' already configured' else if [ "$key" = "none" ]; then ifconfig $if inet 0.0.0.0 powersave\ station wlan ssid $ssid else ifconfig $if inet 0.0.0.0 powersave wepmode on\ station wlan ssid $ssid wepkey $key fi # delay sleep 1; wicontrol -L >&- if ifconfig $if | grep -q 'status: associated'; then echo ' ok' else echo ' no association' ifconfig $if down fi fi } # if_stop $if if_stop(){ if=$1 # skip if already processed if echo $ifs|grep -qv $if; then echo -n stopping interface $if ... # remember this interface ifs="$ifs $if" if ifconfig $if 2>&1|grep -q 'does not exist'; then echo ' does not exist' elif ifconfig $if | grep -q 'status: associated'; then ifconfig $if down if ifconfig $if | grep -q 'status: associated'; then echo ' error' else echo ' down' fi else echo ' no association' fi fi } # cycle start|stop cycle(){ action=$1 # read configuration for item in ${wireless_flags}; do # read items if [ -z "$if" ]; then if=$item elif [ -z "$ssid" ]; then ssid=$item elif [ -z "$key" ]; then key=$item fi # configure if [ -n "$if" -a -n "$ssid" -a -n "$key" ]; then if [ "$action" = "start" ]; then # start if_start $if $ssid $key elif [ "$action" = "stop" ]; then # stop if_stop $if fi # clean items if='' ssid='' key='' fi done } wireless_start(){ cycle start } wireless_stop(){ cycle stop } load_rc_config $name run_rc_command "$1" ================================================================================ vlad
State Changed From-To: open->closed ifconfig_NIC entries in rc.conf already handle this.