File:  [ELWIX - Embedded LightWeight unIX -] / elwix / config / etc / default / rc.wifi
Revision 1.1: download - view: text, annotated - select for diffs - revision graph
Tue Jul 5 23:43:00 2011 UTC (12 years, 11 months ago) by misho
Branches: MAIN
CVS tags: HEAD
Initial revision

    1: # Common loader functions for WIFI boot scripts
    2: #  (C)`09 AITNET ltd - Sofia/Bulgaria <misho@aitbg.com>
    3: #
    4: # $Id: rc.wifi,v 1.1 2011/07/05 23:43:00 misho Exp $
    5: 
    6: 
    7: # regdomain() <iface> <regdomain> [additional options]
    8: regdomain()
    9: {
   10: 	if [ $# -ne 2 ]; then
   11: 		echo "regdomain() Not enough parameters ..."
   12: 		return 1
   13: 	fi
   14: 
   15: 	if [ X"$2" != X"" ]; then
   16: 	else
   17: 		ifconfig $1 regdomain $2
   18: 	fi
   19: 
   20: 	if [ $# -gt 2 ]; then
   21: 		shift 2
   22: 		ifconfig $1 $*
   23: 	fi
   24: }
   25: 
   26: # country() <iface> <country>
   27: country()
   28: {
   29: 	if [ $# -ne 2 ]; then
   30: 		echo "country() Not enough parameters ..."
   31: 		return 1
   32: 	fi
   33: 
   34: 	if [ X"$2" != X"" ]; then
   35: 	else
   36: 		ifconfig $1 country $2
   37: 	fi
   38: }
   39: 
   40: # speedset() <iface> <ucast_speed> [mcast_speed] [mgmt_speed]
   41: speedset()
   42: {
   43: 	if [ $# -lt 2 ]; then
   44: 		echo "setspeed() Not enough parameters ..."
   45: 		return 1
   46: 	fi
   47: 
   48: 	if [ X"$2" != X"" ]; then
   49: 		return 0
   50: 	fi
   51: 
   52: 	ARGS="ucastrate $2"
   53: 	if [ $# -gt 2 ]; then
   54: 		ARGS=$ARGS" mcastrate $3"
   55: 	fi
   56: 	if [ $# -gt 3 ]; then
   57: 		ARGS=$ARGS" mgtrate $4"
   58: 	fi
   59: 
   60: 	ifconfig $1 $ARGS
   61: }
   62: 
   63: # createwlan() <iface> <wlandev> <ap|sta|adhoc|tdma|wds|mesh> [wdsbssid]
   64: createwlan()
   65: {
   66: 	if [ $# -lt 3 ]; then
   67: 		echo "createwlan() Not enough parameters ..."
   68: 		return 1
   69: 	fi
   70: 
   71: 	ARGS="create wlandev $2 wlanmode $3"
   72: 	if [ $# -gt 3 ]; then
   73: 		shift 3
   74: 		ARGS=$ARGS" $*"
   75: 	fi
   76: 
   77: 	ifconfig $1 $ARGS
   78: }
   79: 
   80: # setchan() <iface> <channel> [mode]
   81: setchan()
   82: {
   83: 	if [ $# -lt 2 ]; then
   84: 		echo "setchan() Not enough parameters ..."
   85: 		return 1
   86: 	fi
   87: 
   88: 	ARGS="channel $2"
   89: 	if [ $# -gt 2 ]; then
   90: 		ARGS=$ARGS" mode $3"
   91: 	fi
   92: 
   93: 	ifconfig $1 $ARGS
   94: }
   95: 
   96: # setwifiopts() <iface> <wifiopts>
   97: setwifiopts()
   98: {
   99: 	if [ $# -lt 1 ]; then
  100: 		echo "setwifiopts() Not enough parameters ..."
  101: 		return 1
  102: 	fi
  103: 
  104: 	if [ $# -gt 1 ]; then
  105: 		shift 1
  106: 		ifconfig $1 $*
  107: 	fi
  108: }
  109: 
  110: # setWEP() <iface> <default_key> <key1> [key2] [key3] [key4]
  111: setWEP()
  112: {
  113: 	if [ $# -lt 3 ]; then
  114: 		echo "setWEP() Not enough parameters ..."
  115: 		return 1
  116: 	fi
  117: 
  118: 	ARGS="wep deftxkey $2 wepkey 1:$3"
  119: 	if [ $# -gt 3 ]; then
  120: 		ARGS=$ARGS" wepkey 2:$4"
  121: 	fi
  122: 	if [ $# -gt 4 ]; then
  123: 		ARGS=$ARGS" wepkey 3:$5"
  124: 	fi
  125: 	if [ $# -gt 5 ]; then
  126: 		ARGS=$ARGS" wepkey 4:$6"
  127: 	fi
  128: 
  129: 	ifconfig $1 $ARGS
  130: }
  131: 
  132: # mkhostconf() <iface> <host_mode> <wpa_pass> [wep_key]
  133: mkhostconf()
  134: {
  135: 	if [ $# -lt 3 ]; then
  136: 		echo "mkhostconf() Not enough parameters ..."
  137: 		return 1
  138: 	fi
  139: 
  140: 	case $2 in
  141: 		wpa1|1)
  142: 			WPA_MODE=1
  143: 			WPA_PAIR=CCMP
  144: 			;;
  145: 		wpa1_tkip)
  146: 			WPA_MODE=1
  147: 			WPA_PAIR=TKIP
  148: 			;;
  149: 		wpa2|2)
  150: 			WPA_MODE=2
  151: 			WPA_PAIR=CCMP
  152: 			;;
  153: 		wpa2_tkip)
  154: 			WPA_MODE=2
  155: 			WPA_PAIR=TKIP
  156: 			;;
  157: 		wpa|3)
  158: 			WPA_MODE=3
  159: 			WPA_PAIR=CCMP
  160: 			;;
  161: 		tsn)
  162: 			if [ -z $4 ]; then
  163: 				echo "mkhostconf() Not enough parameters ..."
  164: 				return 1;
  165: 			else
  166: 				WEP_KEY0=$4
  167: 			fi
  168: 
  169: 			WPA_MODE=1
  170: 			WPA_PAIR=TKIP
  171: 			;;
  172: 		*)
  173: 			echo "mkhostconf() Unknown WPA mode ..."
  174: 			return 1
  175: 			;;
  176: 	esac
  177: 
  178: 	CONF=/var/tmp/hostapd_$1.conf
  179: 	rm -f $CONF
  180: 
  181: 	cat >$CONF <<_EOF
  182: interface=$1
  183: ctrl_interface=/var/run/hostapd_$1.sock
  184: dump_file=/var/tmp/hostapd_$1.dump
  185: logger_syslog=-1
  186: logger_syslog_level=0
  187: logger_stdout=-1
  188: logger_stdout_level=0
  189: debug=4
  190: wpa_psk_file=/etc/hostapd.wpa_psk
  191: wpa=$WPA_MODE
  192: wpa_pairwise=$WPA_PAIR
  193: wpa_key_mgmt=WPA-PSK
  194: wpa_passphrase=$3
  195: _EOF
  196: 
  197: 	if [ ${#WEP_KEY0} -ne 0 ]; then
  198: 		cat >>$CONF <<_EOF
  199: tsn=1
  200: wep_key0=$WEP_KEY0
  201: _EOF
  202: 	fi
  203: }

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