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}"
54 for vif
in 0 1 2 3; do
55 append ifdown
"vif $vif" "$N"
56 append ifdown
"enabled 0" "$N"
61 if [ "$_c" -gt 1 ]; then
69 case "$adhoc:$sta:$apmode:$mon" in
98 set_wifi_down
"$device"
99 wlc ifname
"$device" down
100 wlc ifname
"$device" bssid
`wlc ifname "$device" default_bssid`
104 local pid_file
=/var
/run
/nas.
$device.pid
105 [ -e $pid_file ] && start-stop-daemon
-K -q -s SIGKILL
-p $pid_file && rm $pid_file
107 # make sure the interfaces are down and removed from all bridges
109 for dev
in $device ${device}-1 ${device}-2 ${device}-3; do
110 ifconfig
"$dev" down
2>/dev
/null
>/dev
/null
&& {
120 local channel country maxassoc wds vifs distance slottime rxantenna txantenna
121 local frameburst macfilter maclist macaddr txpower frag rts hwmode htmode
122 config_get channel
"$device" channel
123 config_get country
"$device" country
124 config_get maxassoc
"$device" maxassoc
125 config_get wds
"$device" wds
126 config_get vifs
"$device" vifs
127 config_get distance
"$device" distance
128 config_get slottime
"$device" slottime
129 config_get rxantenna
"$device" rxantenna
130 config_get txantenna
"$device" txantenna
131 config_get_bool frameburst
"$device" frameburst
132 config_get macfilter
"$device" macfilter
133 config_get maclist
"$device" maclist
134 config_get macaddr
"$device" macaddr
135 config_get txpower
"$device" txpower
136 config_get frag
"$device" frag
137 config_get rts
"$device" rts
138 config_get hwmode
"$device" hwmode
139 config_get htmode
"$device" htmode
143 [ -z "$slottime" ] && {
144 [ -n "$distance" ] && {
145 # slottime = 9 + (distance / 150) + (distance % 150 ? 1 : 0)
146 slottime
="$((9 + ($distance / 150) + 1 - (150 - ($distance % 150)) / 150 ))"
149 slottime
="${slottime:--1}"
164 local gmode
=2 nmode
=0 nreqd
=
172 *) nmode
=1; nreqd
=0;;
176 n|
11n
) nmode
=1; nreqd
=1;;
177 *n
*) nmode
=1; nreqd
=0;;
180 # Use 'nmode' for N-Phy only
181 [ "$(wlc ifname "$device" phytype)" = 4 ] || nmode
=
184 [ ${channel:-0} -ge 1 -a ${channel:-0} -le 14 ] && band
=2
185 [ ${channel:-0} -ge 36 ] && {
190 # Use 'chanspec' instead of 'channel' for 'N' modes (See bcmwifi.h)
191 [ ${nmode:-0} -ne 0 -a -n "$band" -a -n "$channel" ] && {
193 HT40-
) chanspec
=$
(printf 0x
%x
%x
%02x
$band 0xe $
(($channel - 2))); channel
=;;
194 HT40
+) chanspec
=$
(printf 0x
%x
%x
%02x
$band 0xd $
(($channel + 2))); channel
=;;
195 HT20
) chanspec
=$
(printf 0x
%x
%x
%02x
$band 0xb $channel); channel
=;;
201 local nas
="$(which nas)"
203 local vif vif_pre_up vif_post_up vif_do_up vif_txpower
206 config_get vif_txpower
"$vif" txpower
209 config_get mode
"$vif" mode
210 append vif_pre_up
"vif $_c" "$N"
211 append vif_post_up
"vif $_c" "$N"
212 append vif_do_up
"vif $_c" "$N"
214 config_get_bool wmm
"$vif" wmm
"$wmm"
215 config_get_bool doth
"$vif" doth
"$doth"
217 [ "$mode" = "sta" ] ||
{
219 config_get_bool hidden
"$vif" hidden
0
220 append vif_pre_up
"closed $hidden" "$N"
221 config_get_bool isolate
"$vif" isolate
0
222 append vif_pre_up
"ap_isolate $isolate" "$N"
232 config_get enc
"$vif" encryption
235 local def defkey k knr
239 config_get key
"$vif" key
241 *shared
*) append vif_do_up
"wepauth 1" "$N";;
242 *) append vif_do_up
"wepauth 0" "$N";;
247 for knr
in 1 2 3 4; do
248 config_get k
"$vif" key
$knr
249 [ -n "$k" ] ||
continue
250 [ "$defkey" = "$knr" ] && def
="=" || def
=""
251 append vif_do_up
"wepkey $def$knr,$k" "$N"
255 *) append vif_do_up
"wepkey =1,$key" "$N";;
260 config_get key
"$vif" key
262 # psk version + default cipher
264 *mixed
*|
*psk
+psk2
*) auth
=132; wsec
=6;;
265 *psk2
*) auth
=128; wsec
=4;;
271 *tkip
+aes
*|
*tkip
+ccmp
*|
*aes
+tkip
*|
*ccmp
+tkip
*) wsec
=6;;
272 *aes
*|
*ccmp
*) wsec
=4;;
276 # group rekey interval
277 config_get rekey
"$vif" wpa_group_rekey
279 eval "${vif}_key=\"\$key\""
280 nasopts
="-k \"\$${vif}_key\"${rekey:+ -g $rekey}"
283 local auth_port auth_secret auth_server
286 config_get auth_server
"$vif" auth_server
287 [ -z "$auth_server" ] && config_get auth_server
"$vif" server
288 config_get auth_port
"$vif" auth_port
289 [ -z "$auth_port" ] && config_get auth_port
"$vif" port
290 config_get auth_secret
"$vif" auth_secret
291 [ -z "$auth_secret" ] && config_get auth_secret
"$vif" key
293 # wpa version + default cipher
295 *mixed
*|
*wpa
+wpa2
*) auth
=66; wsec
=6;;
296 *wpa2
*) auth
=64; wsec
=4;;
302 *tkip
+aes
*|
*tkip
+ccmp
*|
*aes
+tkip
*|
*ccmp
+tkip
*) wsec
=6;;
303 *aes
*|
*ccmp
*) wsec
=4;;
307 # group rekey interval
308 config_get rekey
"$vif" wpa_group_rekey
310 eval "${vif}_key=\"\$auth_secret\""
311 nasopts
="-r \"\$${vif}_key\" -h $auth_server -p ${auth_port:-1812}${rekey:+ -g $rekey}"
314 append vif_do_up
"wsec $wsec" "$N"
315 append vif_do_up
"wpa_auth $auth" "$N"
316 append vif_do_up
"wsec_restrict $wsec_r" "$N"
317 append vif_do_up
"eap_restrict $eap_r" "$N"
320 config_get ssid
"$vif" ssid
321 append vif_post_up
"vlan_mode 0" "$N"
322 append vif_pre_up
"ssid $ssid" "$N"
324 [ "$mode" = "monitor" ] && {
325 append vif_post_up
"monitor $monitor" "$N"
328 [ "$mode" = "adhoc" ] && {
330 config_get bssid
"$vif" bssid
332 append vif_pre_up
"bssid $bssid" "$N"
333 append vif_pre_up
"ibss_merge 0" "$N"
335 append vif_pre_up
"ibss_merge 1" "$N"
339 append vif_post_up
"enabled 1" "$N"
342 config_get ifname
"$vif" ifname
343 #append if_up "ifconfig $ifname up" ";$N"
345 local net_cfg
="$(find_net_config "$vif")"
346 [ -z "$net_cfg" ] ||
{
347 append if_up
"set_wifi_up '$vif' '$ifname'" ";$N"
348 append if_up
"start_net '$ifname' '$net_cfg'" ";$N"
350 [ -z "$nas" -o -z "$nasopts" ] ||
{
351 eval "${vif}_ssid=\"\$ssid\""
353 [ "$mode" = "sta" ] && nas_mode
="-S"
354 [ -z "$nas_cmd" ] && {
355 local pid_file
=/var
/run
/nas.
$device.pid
356 nas_cmd
="start-stop-daemon -S -b -p $pid_file -x $nas -- -P $pid_file -H 34954"
358 append nas_cmd
"-i $ifname $nas_mode -m $auth -w $wsec -s \"\$${vif}_ssid\" -g 3600 -F $nasopts"
362 wlc ifname
"$device" stdin
<<EOF
366 ${nmode:+nmode $nmode}
367 ${nmode:+${nreqd:+nreqd $nreqd}}
368 ${gmode:+gmode $gmode}
371 ${mssid:+mssid $mssid}
377 rxant ${rxantenna:-3}
378 txant ${txantenna:-3}
379 fragthresh ${frag:-2346}
380 rtsthresh ${rts:-2347}
381 monitor ${monitor:-0}
384 macfilter ${macfilter:-0}
385 maclist ${maclist:-none}
388 country ${country:-US}
389 ${channel:+channel $channel}
390 ${chanspec:+chanspec $chanspec}
391 maxassoc ${maxassoc:-128}
392 slottime ${slottime:--1}
393 ${frameburst:+frameburst $frameburst}
400 wlc ifname
"$device" stdin
<<EOF
404 # use vif_txpower (from last wifi-iface) instead of txpower (from
405 # wifi-device) if the latter does not exist
406 txpower
=${txpower:-$vif_txpower}
407 [ -z "$txpower" ] || iwconfig
$device txpower
${txpower}dBm
416 while grep -qs "^ *wl$((++i)):" /proc
/net
/dev
; do
419 config_get
type wl
${i} type
420 [ "$type" = broadcom
] && continue
421 channel
=`wlc ifname wl${i} channel`
423 config wifi-device wl${i}
425 option channel ${channel:-11}
427 # REMOVE THIS LINE TO ENABLE WIFI:
434 option ssid OpenWrt${i#0}
435 option encryption none