From nobody@FreeBSD.org  Thu Oct 21 14:35:56 2004
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id DCE7316A4CE
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 21 Oct 2004 14:35:56 +0000 (GMT)
Received: from www.freebsd.org (www.freebsd.org [216.136.204.117])
	by mx1.FreeBSD.org (Postfix) with ESMTP id B448043D39
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 21 Oct 2004 14:35:56 +0000 (GMT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.12.11/8.12.11) with ESMTP id i9LEZuft038940
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 21 Oct 2004 14:35:56 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.12.11/8.12.11/Submit) id i9LEZuR8038939;
	Thu, 21 Oct 2004 14:35:56 GMT
	(envelope-from nobody)
Message-Id: <200410211435.i9LEZuR8038939@www.freebsd.org>
Date: Thu, 21 Oct 2004 14:35:56 GMT
From: Vlad Manilici <rot13@FreeBSD.org (izna@gzbx.pbz)>
To: freebsd-gnats-submit@FreeBSD.org
Subject: rc.d script needed to create wireless associations before dhclient runs
X-Send-Pr-Version: www-2.3

>Number:         72964
>Category:       conf
>Synopsis:       [patch] rc.d script needed to create wireless associations before dhclient runs
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Thu Oct 21 14:40:27 GMT 2004
>Closed-Date:    Sun Jun 19 17:39:07 GMT 2005
>Last-Modified:  Sun Jun 19 17:39:07 GMT 2005
>Originator:     Vlad Manilici
>Release:        FreeBSD 5.2.1
>Organization:
>Environment:
FreeBSD XXX 5.2.1-RELEASE-p11 FreeBSD 5.2.1-RELEASE-p11 #21: Fri Oct  8 14:12:55 CEST 2004 XXX@XXX:/usr/obj/usr/src/sys/FX  i386
>Description:
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"

>How-To-Repeat:
---
>Fix:
---
>Release-Note:
>Audit-Trail:

From: Vlad Manilici <vman@fx.homeunix.org>
To: freebsd-gnats-submit@FreeBSD.org
Cc:  
Subject: Re: conf/72964
Date: Sat, 23 Oct 2004 16:01:08 +0200

 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 
State-Changed-By: matteo 
State-Changed-When: Sun Jun 19 17:38:21 GMT 2005 
State-Changed-Why:  
ifconfig_NIC entries in rc.conf already handle this. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=72964 
>Unformatted:
