File:  [ELWIX - Embedded LightWeight unIX -] / elwix / config / etc / default / rc.wifi
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Tue Jul 5 23:43:00 2011 UTC (13 years ago) by misho
Branches: misho
CVS tags: start, elwix1_5, elwix1_4, Patch1
ELWIX project

# Common loader functions for WIFI boot scripts
#  (C)`09 AITNET ltd - Sofia/Bulgaria <misho@aitbg.com>
#
# $Id: rc.wifi,v 1.1.1.1 2011/07/05 23:43:00 misho Exp $


# regdomain() <iface> <regdomain> [additional options]
regdomain()
{
	if [ $# -ne 2 ]; then
		echo "regdomain() Not enough parameters ..."
		return 1
	fi

	if [ X"$2" != X"" ]; then
	else
		ifconfig $1 regdomain $2
	fi

	if [ $# -gt 2 ]; then
		shift 2
		ifconfig $1 $*
	fi
}

# country() <iface> <country>
country()
{
	if [ $# -ne 2 ]; then
		echo "country() Not enough parameters ..."
		return 1
	fi

	if [ X"$2" != X"" ]; then
	else
		ifconfig $1 country $2
	fi
}

# speedset() <iface> <ucast_speed> [mcast_speed] [mgmt_speed]
speedset()
{
	if [ $# -lt 2 ]; then
		echo "setspeed() Not enough parameters ..."
		return 1
	fi

	if [ X"$2" != X"" ]; then
		return 0
	fi

	ARGS="ucastrate $2"
	if [ $# -gt 2 ]; then
		ARGS=$ARGS" mcastrate $3"
	fi
	if [ $# -gt 3 ]; then
		ARGS=$ARGS" mgtrate $4"
	fi

	ifconfig $1 $ARGS
}

# createwlan() <iface> <wlandev> <ap|sta|adhoc|tdma|wds|mesh> [wdsbssid]
createwlan()
{
	if [ $# -lt 3 ]; then
		echo "createwlan() Not enough parameters ..."
		return 1
	fi

	ARGS="create wlandev $2 wlanmode $3"
	if [ $# -gt 3 ]; then
		shift 3
		ARGS=$ARGS" $*"
	fi

	ifconfig $1 $ARGS
}

# setchan() <iface> <channel> [mode]
setchan()
{
	if [ $# -lt 2 ]; then
		echo "setchan() Not enough parameters ..."
		return 1
	fi

	ARGS="channel $2"
	if [ $# -gt 2 ]; then
		ARGS=$ARGS" mode $3"
	fi

	ifconfig $1 $ARGS
}

# setwifiopts() <iface> <wifiopts>
setwifiopts()
{
	if [ $# -lt 1 ]; then
		echo "setwifiopts() Not enough parameters ..."
		return 1
	fi

	if [ $# -gt 1 ]; then
		shift 1
		ifconfig $1 $*
	fi
}

# setWEP() <iface> <default_key> <key1> [key2] [key3] [key4]
setWEP()
{
	if [ $# -lt 3 ]; then
		echo "setWEP() Not enough parameters ..."
		return 1
	fi

	ARGS="wep deftxkey $2 wepkey 1:$3"
	if [ $# -gt 3 ]; then
		ARGS=$ARGS" wepkey 2:$4"
	fi
	if [ $# -gt 4 ]; then
		ARGS=$ARGS" wepkey 3:$5"
	fi
	if [ $# -gt 5 ]; then
		ARGS=$ARGS" wepkey 4:$6"
	fi

	ifconfig $1 $ARGS
}

# mkhostconf() <iface> <host_mode> <wpa_pass> [wep_key]
mkhostconf()
{
	if [ $# -lt 3 ]; then
		echo "mkhostconf() Not enough parameters ..."
		return 1
	fi

	case $2 in
		wpa1|1)
			WPA_MODE=1
			WPA_PAIR=CCMP
			;;
		wpa1_tkip)
			WPA_MODE=1
			WPA_PAIR=TKIP
			;;
		wpa2|2)
			WPA_MODE=2
			WPA_PAIR=CCMP
			;;
		wpa2_tkip)
			WPA_MODE=2
			WPA_PAIR=TKIP
			;;
		wpa|3)
			WPA_MODE=3
			WPA_PAIR=CCMP
			;;
		tsn)
			if [ -z $4 ]; then
				echo "mkhostconf() Not enough parameters ..."
				return 1;
			else
				WEP_KEY0=$4
			fi

			WPA_MODE=1
			WPA_PAIR=TKIP
			;;
		*)
			echo "mkhostconf() Unknown WPA mode ..."
			return 1
			;;
	esac

	CONF=/var/tmp/hostapd_$1.conf
	rm -f $CONF

	cat >$CONF <<_EOF
interface=$1
ctrl_interface=/var/run/hostapd_$1.sock
dump_file=/var/tmp/hostapd_$1.dump
logger_syslog=-1
logger_syslog_level=0
logger_stdout=-1
logger_stdout_level=0
debug=4
wpa_psk_file=/etc/hostapd.wpa_psk
wpa=$WPA_MODE
wpa_pairwise=$WPA_PAIR
wpa_key_mgmt=WPA-PSK
wpa_passphrase=$3
_EOF

	if [ ${#WEP_KEY0} -ne 0 ]; then
		cat >>$CONF <<_EOF
tsn=1
wep_key0=$WEP_KEY0
_EOF
	fi
}

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>