1 append DRIVERS
"broadcom"
6 local adhoc sta apmode mon disabled
7 local adhoc_if sta_if ap_if mon_if
9 config_get vifs
"$device" vifs
11 config_get_bool disabled
"$vif" disabled
0
12 [ $disabled -eq 0 ] ||
continue
15 config_get mode
"$vif" mode
27 ap_if
="${ap_if:+$ap_if }$vif"
31 config_get addr
"$vif" bssid
33 addr
=$
(echo "$addr" |
tr 'A-F' 'a-f')
41 *) echo "$device($vif): Invalid mode";;
44 config_set
"$device" wds
"$wds"
47 for vif
in ${adhoc_if:-$sta_if $ap_if $mon_if}; do
48 config_set
"$vif" ifname
"${device}${_c:+-$_c}"
51 config_set
"$device" vifs
"${adhoc_if:-$sta_if $ap_if $mon_if}"
55 if [ "$_c" -gt 1 ]; then
63 case "$adhoc:$sta:$apmode:$mon" in
92 set_wifi_down
"$device"
96 local pid_file
=/var
/run
/nas.
$device.pid
97 [ -e $pid_file ] && start-stop-daemon
-K -q -s SIGKILL
-p $pid_file && rm $pid_file
99 # make sure the interfaces are down and removed from all bridges
101 for dev
in /sys
/class
/net
/wds
${device##wl}-* /sys/class/net/${device}-* /sys/class/net/${device}; do
102 if [ -e "$dev" ]; then
103 ifname
=${dev##/sys/class/net/}
104 ifconfig
"$ifname" down
109 # make sure all of the devices are disabled in the driver
112 append ifdown
"down" "$N"
113 append ifdown
"wds none" "$N"
114 for vif
in 3 2 1 0; do
115 append ifdown
"vif $vif" "$N"
116 append ifdown
"enabled 0" "$N"
119 wlc ifname
"$device" stdin
<<EOF
128 local channel country maxassoc wds vifs distance slottime rxantenna txantenna
129 local frameburst macfilter maclist macaddr txpower frag rts hwmode htmode
130 config_get channel
"$device" channel
131 config_get country
"$device" country
132 config_get maxassoc
"$device" maxassoc
133 config_get wds
"$device" wds
134 config_get vifs
"$device" vifs
135 config_get distance
"$device" distance
136 config_get slottime
"$device" slottime
137 config_get rxantenna
"$device" rxantenna
138 config_get txantenna
"$device" txantenna
139 config_get_bool frameburst
"$device" frameburst
140 config_get macfilter
"$device" macfilter
141 config_get maclist
"$device" maclist
142 config_get macaddr
"$device" macaddr $
(wlc ifname
"$device" default_bssid
)
143 config_get txpower
"$device" txpower
144 config_get frag
"$device" frag
145 config_get rts
"$device" rts
146 config_get hwmode
"$device" hwmode
147 config_get htmode
"$device" htmode
151 [ -z "$slottime" ] && {
152 [ -n "$distance" ] && {
153 # slottime = 9 + (distance / 150) + (distance % 150 ? 1 : 0)
154 slottime
="$((9 + ($distance / 150) + 1 - (150 - ($distance % 150)) / 150 ))"
157 slottime
="${slottime:--1}"
172 local gmode
=2 nmode
=0 nreqd
=
180 *) nmode
=1; nreqd
=0;;
184 n|
11n
) nmode
=1; nreqd
=1;;
185 *n
*) nmode
=1; nreqd
=0;;
188 # Use 'nmode' for N-Phy only
189 [ "$(wlc ifname "$device" phytype)" = 4 ] || nmode
=
192 [ ${channel:-0} -ge 1 -a ${channel:-0} -le 14 ] && band
=2
193 [ ${channel:-0} -ge 36 ] && {
198 # Use 'chanspec' instead of 'channel' for 'N' modes (See bcmwifi.h)
199 [ ${nmode:-0} -ne 0 -a -n "$band" -a -n "$channel" ] && {
201 HT40-
) chanspec
=$
(printf 0x
%x
%x
%02x
$band 0xe $
(($channel - 2))); channel
=;;
202 HT40
+) chanspec
=$
(printf 0x
%x
%x
%02x
$band 0xd $
(($channel + 2))); channel
=;;
203 HT20
) chanspec
=$
(printf 0x
%x
%x
%02x
$band 0xb $channel); channel
=;;
209 local nas
="$(which nas)"
210 local if_pre_up if_up nas_cmd
211 local vif vif_pre_up vif_post_up vif_do_up vif_txpower
214 config_get vif_txpower
"$vif" txpower
217 config_get mode
"$vif" mode
218 append vif_pre_up
"vif $_c" "$N"
219 append vif_post_up
"vif $_c" "$N"
220 append vif_do_up
"vif $_c" "$N"
222 config_get_bool wmm
"$vif" wmm
"$wmm"
223 config_get_bool doth
"$vif" doth
"$doth"
225 [ "$mode" = "sta" ] ||
{
227 config_get_bool hidden
"$vif" hidden
0
228 append vif_pre_up
"closed $hidden" "$N"
229 config_get_bool isolate
"$vif" isolate
0
230 append vif_pre_up
"ap_isolate $isolate" "$N"
240 config_get enc
"$vif" encryption
243 local def defkey k knr
247 config_get key
"$vif" key
249 *shared
*) append vif_do_up
"wepauth 1" "$N";;
250 *) append vif_do_up
"wepauth 0" "$N";;
255 for knr
in 1 2 3 4; do
256 config_get k
"$vif" key
$knr
257 [ -n "$k" ] ||
continue
258 [ "$defkey" = "$knr" ] && def
="=" || def
=""
259 append vif_do_up
"wepkey $def$knr,$k" "$N"
263 *) append vif_do_up
"wepkey =1,$key" "$N";;
268 config_get key
"$vif" key
270 # psk version + default cipher
272 *mixed
*|
*psk
+psk2
*) auth
=132; wsec
=6;;
273 *psk2
*) auth
=128; wsec
=4;;
279 *tkip
+aes
*|
*tkip
+ccmp
*|
*aes
+tkip
*|
*ccmp
+tkip
*) wsec
=6;;
280 *aes
*|
*ccmp
*) wsec
=4;;
284 # group rekey interval
285 config_get rekey
"$vif" wpa_group_rekey
287 eval "${vif}_key=\"\$key\""
288 nasopts
="-k \"\$${vif}_key\"${rekey:+ -g $rekey}"
291 local auth_port auth_secret auth_server
294 config_get auth_server
"$vif" auth_server
295 [ -z "$auth_server" ] && config_get auth_server
"$vif" server
296 config_get auth_port
"$vif" auth_port
297 [ -z "$auth_port" ] && config_get auth_port
"$vif" port
298 config_get auth_secret
"$vif" auth_secret
299 [ -z "$auth_secret" ] && config_get auth_secret
"$vif" key
301 # wpa version + default cipher
303 *mixed
*|
*wpa
+wpa2
*) auth
=66; wsec
=6;;
304 *wpa2
*) auth
=64; wsec
=4;;
310 *tkip
+aes
*|
*tkip
+ccmp
*|
*aes
+tkip
*|
*ccmp
+tkip
*) wsec
=6;;
311 *aes
*|
*ccmp
*) wsec
=4;;
315 # group rekey interval
316 config_get rekey
"$vif" wpa_group_rekey
318 eval "${vif}_key=\"\$auth_secret\""
319 nasopts
="-r \"\$${vif}_key\" -h $auth_server -p ${auth_port:-1812}${rekey:+ -g $rekey}"
322 append vif_do_up
"wsec $wsec" "$N"
323 append vif_do_up
"wpa_auth $auth" "$N"
324 append vif_do_up
"wsec_restrict $wsec_r" "$N"
325 append vif_do_up
"eap_restrict $eap_r" "$N"
328 config_get ssid
"$vif" ssid
329 append vif_post_up
"vlan_mode 0" "$N"
330 append vif_pre_up
"ssid $ssid" "$N"
332 [ "$mode" = "monitor" ] && {
333 append vif_post_up
"monitor $monitor" "$N"
336 [ "$mode" = "adhoc" ] && {
338 config_get bssid
"$vif" bssid
340 append vif_pre_up
"bssid $bssid" "$N"
341 append vif_pre_up
"ibss_merge 0" "$N"
343 append vif_pre_up
"ibss_merge 1" "$N"
347 append vif_post_up
"enabled 1" "$N"
350 config_get ifname
"$vif" ifname
351 local if_cmd
="if_pre_up"
352 [ "$ifname" != "${ifname##${device}-}" ] && if_cmd
="if_up"
353 append
$if_cmd "macaddr=\$(wlc ifname '$ifname' cur_etheraddr)" ";$N"
354 append
$if_cmd "ifconfig '$ifname' \${macaddr:+hw ether \$macaddr}" ";$N"
356 local net_cfg
="$(find_net_config "$vif")"
357 [ -z "$net_cfg" ] ||
{
358 append if_up
"set_wifi_up '$vif' '$ifname'" ";$N"
359 append if_up
"start_net '$ifname' '$net_cfg'" ";$N"
361 [ -z "$nas" -o -z "$nasopts" ] ||
{
362 eval "${vif}_ssid=\"\$ssid\""
364 [ "$mode" = "sta" ] && nas_mode
="-S"
365 [ -z "$nas_cmd" ] && {
366 local pid_file
=/var
/run
/nas.
$device.pid
367 nas_cmd
="start-stop-daemon -S -b -p $pid_file -x $nas -- -P $pid_file -H 34954"
369 append nas_cmd
"-i $ifname $nas_mode -m $auth -w $wsec -s \"\$${vif}_ssid\" -g 3600 -F $nasopts"
373 wlc ifname
"$device" stdin
<<EOF
374 ${macaddr:+bssid $macaddr}
375 ${macaddr:+cur_etheraddr $macaddr}
377 ${nmode:+nmode $nmode}
378 ${nmode:+${nreqd:+nreqd $nreqd}}
379 ${gmode:+gmode $gmode}
382 ${mssid:+mssid $mssid}
388 rxant ${rxantenna:-3}
389 txant ${txantenna:-3}
390 fragthresh ${frag:-2346}
391 rtsthresh ${rts:-2347}
392 monitor ${monitor:-0}
395 macfilter ${macfilter:-0}
396 maclist ${maclist:-none}
398 country ${country:-US}
399 ${channel:+channel $channel}
400 ${chanspec:+chanspec $chanspec}
401 maxassoc ${maxassoc:-128}
402 slottime ${slottime:--1}
403 ${frameburst:+frameburst $frameburst}
408 wlc ifname
"$device" stdin
<<EOF
413 wlc ifname
"$device" stdin
<<EOF
417 # use vif_txpower (from last wifi-iface) instead of txpower (from
418 # wifi-device) if the latter does not exist
419 txpower
=${txpower:-$vif_txpower}
420 [ -z "$txpower" ] || iwconfig
$device txpower
${txpower}dBm
429 while grep -qs "^ *wl$((++i)):" /proc
/net
/dev
; do
432 config_get
type wl
${i} type
433 [ "$type" = broadcom
] && continue
434 channel
=`wlc ifname wl${i} channel`
436 config wifi-device wl${i}
438 option channel ${channel:-11}
440 # REMOVE THIS LINE TO ENABLE WIFI:
447 option ssid OpenWrt${i#0}
448 option encryption none