Bug 72964 - [patch] rc.d script needed to create wireless associations before dhclient runs
Summary: [patch] rc.d script needed to create wireless associations before dhclient runs
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: conf (show other bugs)
Version: Unspecified
Hardware: Any Any
: Normal Affects Only Me
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-10-21 15:40 UTC by Vlad Manilici
Modified: 2005-06-19 18:39 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Vlad Manilici freebsd_committer freebsd_triage 2004-10-21 15:40:27 UTC
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: ---
Comment 1 Vlad Manilici 2004-10-23 15:01:08 UTC
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
Comment 2 Matteo Riondato freebsd_committer freebsd_triage 2005-06-19 18:38:21 UTC
State Changed
From-To: open->closed

ifconfig_NIC entries in rc.conf already handle this.