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
103 local pid_file
=/var
/run
/nas.
$device.pid
104 [ -e $pid_file ] && start-stop-daemon
-K -q -s SIGKILL
-p $pid_file && rm $pid_file
106 # make sure the interfaces are down and removed from all bridges
108 for dev
in $device ${device}-1 ${device}-2 ${device}-3; do
109 ifconfig
"$dev" down
2>/dev
/null
>/dev
/null
&& {
119 local channel country maxassoc wds vifs distance slottime rxantenna txantenna
120 local frameburst macfilter maclist macaddr txpower frag rts hwmode htmode
121 config_get channel
"$device" channel
122 config_get country
"$device" country
123 config_get maxassoc
"$device" maxassoc
124 config_get wds
"$device" wds
125 config_get vifs
"$device" vifs
126 config_get distance
"$device" distance
127 config_get slottime
"$device" slottime
128 config_get rxantenna
"$device" rxantenna
129 config_get txantenna
"$device" txantenna
130 config_get_bool frameburst
"$device" frameburst
131 config_get macfilter
"$device" macfilter
132 config_get maclist
"$device" maclist
133 config_get macaddr
"$device" macaddr $
(wlc ifname
"$device" default_bssid
)
134 config_get txpower
"$device" txpower
135 config_get frag
"$device" frag
136 config_get rts
"$device" rts
137 config_get hwmode
"$device" hwmode
138 config_get htmode
"$device" htmode
142 [ -z "$slottime" ] && {
143 [ -n "$distance" ] && {
144 # slottime = 9 + (distance / 150) + (distance % 150 ? 1 : 0)
145 slottime
="$((9 + ($distance / 150) + 1 - (150 - ($distance % 150)) / 150 ))"
148 slottime
="${slottime:--1}"
163 local gmode
=2 nmode
=0 nreqd
=
171 *) nmode
=1; nreqd
=0;;
175 n|
11n
) nmode
=1; nreqd
=1;;
176 *n
*) nmode
=1; nreqd
=0;;
179 # Use 'nmode' for N-Phy only
180 [ "$(wlc ifname "$device" phytype)" = 4 ] || nmode
=
183 [ ${channel:-0} -ge 1 -a ${channel:-0} -le 14 ] && band
=2
184 [ ${channel:-0} -ge 36 ] && {
189 # Use 'chanspec' instead of 'channel' for 'N' modes (See bcmwifi.h)
190 [ ${nmode:-0} -ne 0 -a -n "$band" -a -n "$channel" ] && {
192 HT40-
) chanspec
=$
(printf 0x
%x
%x
%02x
$band 0xe $
(($channel - 2))); channel
=;;
193 HT40
+) chanspec
=$
(printf 0x
%x
%x
%02x
$band 0xd $
(($channel + 2))); channel
=;;
194 HT20
) chanspec
=$
(printf 0x
%x
%x
%02x
$band 0xb $channel); channel
=;;
200 local nas
="$(which nas)"
201 local if_pre_up if_up nas_cmd
202 local vif vif_pre_up vif_post_up vif_do_up vif_txpower
205 config_get vif_txpower
"$vif" txpower
208 config_get mode
"$vif" mode
209 append vif_pre_up
"vif $_c" "$N"
210 append vif_post_up
"vif $_c" "$N"
211 append vif_do_up
"vif $_c" "$N"
213 config_get_bool wmm
"$vif" wmm
"$wmm"
214 config_get_bool doth
"$vif" doth
"$doth"
216 [ "$mode" = "sta" ] ||
{
218 config_get_bool hidden
"$vif" hidden
0
219 append vif_pre_up
"closed $hidden" "$N"
220 config_get_bool isolate
"$vif" isolate
0
221 append vif_pre_up
"ap_isolate $isolate" "$N"
231 config_get enc
"$vif" encryption
234 local def defkey k knr
238 config_get key
"$vif" key
240 *shared
*) append vif_do_up
"wepauth 1" "$N";;
241 *) append vif_do_up
"wepauth 0" "$N";;
246 for knr
in 1 2 3 4; do
247 config_get k
"$vif" key
$knr
248 [ -n "$k" ] ||
continue
249 [ "$defkey" = "$knr" ] && def
="=" || def
=""
250 append vif_do_up
"wepkey $def$knr,$k" "$N"
254 *) append vif_do_up
"wepkey =1,$key" "$N";;
259 config_get key
"$vif" key
261 # psk version + default cipher
263 *mixed
*|
*psk
+psk2
*) auth
=132; wsec
=6;;
264 *psk2
*) auth
=128; wsec
=4;;
270 *tkip
+aes
*|
*tkip
+ccmp
*|
*aes
+tkip
*|
*ccmp
+tkip
*) wsec
=6;;
271 *aes
*|
*ccmp
*) wsec
=4;;
275 # group rekey interval
276 config_get rekey
"$vif" wpa_group_rekey
278 eval "${vif}_key=\"\$key\""
279 nasopts
="-k \"\$${vif}_key\"${rekey:+ -g $rekey}"
282 local auth_port auth_secret auth_server
285 config_get auth_server
"$vif" auth_server
286 [ -z "$auth_server" ] && config_get auth_server
"$vif" server
287 config_get auth_port
"$vif" auth_port
288 [ -z "$auth_port" ] && config_get auth_port
"$vif" port
289 config_get auth_secret
"$vif" auth_secret
290 [ -z "$auth_secret" ] && config_get auth_secret
"$vif" key
292 # wpa version + default cipher
294 *mixed
*|
*wpa
+wpa2
*) auth
=66; wsec
=6;;
295 *wpa2
*) auth
=64; wsec
=4;;
301 *tkip
+aes
*|
*tkip
+ccmp
*|
*aes
+tkip
*|
*ccmp
+tkip
*) wsec
=6;;
302 *aes
*|
*ccmp
*) wsec
=4;;
306 # group rekey interval
307 config_get rekey
"$vif" wpa_group_rekey
309 eval "${vif}_key=\"\$auth_secret\""
310 nasopts
="-r \"\$${vif}_key\" -h $auth_server -p ${auth_port:-1812}${rekey:+ -g $rekey}"
313 append vif_do_up
"wsec $wsec" "$N"
314 append vif_do_up
"wpa_auth $auth" "$N"
315 append vif_do_up
"wsec_restrict $wsec_r" "$N"
316 append vif_do_up
"eap_restrict $eap_r" "$N"
319 config_get ssid
"$vif" ssid
320 append vif_post_up
"vlan_mode 0" "$N"
321 append vif_pre_up
"ssid $ssid" "$N"
323 [ "$mode" = "monitor" ] && {
324 append vif_post_up
"monitor $monitor" "$N"
327 [ "$mode" = "adhoc" ] && {
329 config_get bssid
"$vif" bssid
331 append vif_pre_up
"bssid $bssid" "$N"
332 append vif_pre_up
"ibss_merge 0" "$N"
334 append vif_pre_up
"ibss_merge 1" "$N"
338 append vif_post_up
"enabled 1" "$N"
341 config_get ifname
"$vif" ifname
342 local if_cmd
="if_pre_up"
343 [ "$ifname" != "${ifname##${device}-}" ] && if_cmd
="if_up"
344 append
$if_cmd "macaddr=\$(wlc ifname '$ifname' cur_etheraddr)" ";$N"
345 append
$if_cmd "ifconfig '$ifname' \${macaddr:+hw ether \$macaddr}" ";$N"
347 local net_cfg
="$(find_net_config "$vif")"
348 [ -z "$net_cfg" ] ||
{
349 append if_up
"set_wifi_up '$vif' '$ifname'" ";$N"
350 append if_up
"start_net '$ifname' '$net_cfg'" ";$N"
352 [ -z "$nas" -o -z "$nasopts" ] ||
{
353 eval "${vif}_ssid=\"\$ssid\""
355 [ "$mode" = "sta" ] && nas_mode
="-S"
356 [ -z "$nas_cmd" ] && {
357 local pid_file
=/var
/run
/nas.
$device.pid
358 nas_cmd
="start-stop-daemon -S -b -p $pid_file -x $nas -- -P $pid_file -H 34954"
360 append nas_cmd
"-i $ifname $nas_mode -m $auth -w $wsec -s \"\$${vif}_ssid\" -g 3600 -F $nasopts"
364 wlc ifname
"$device" stdin
<<EOF
367 ${macaddr:+bssid $macaddr}
368 ${macaddr:+cur_etheraddr $macaddr}
370 ${nmode:+nmode $nmode}
371 ${nmode:+${nreqd:+nreqd $nreqd}}
372 ${gmode:+gmode $gmode}
375 ${mssid:+mssid $mssid}
381 rxant ${rxantenna:-3}
382 txant ${txantenna:-3}
383 fragthresh ${frag:-2346}
384 rtsthresh ${rts:-2347}
385 monitor ${monitor:-0}
388 macfilter ${macfilter:-0}
389 maclist ${maclist:-none}
392 country ${country:-US}
393 ${channel:+channel $channel}
394 ${chanspec:+chanspec $chanspec}
395 maxassoc ${maxassoc:-128}
396 slottime ${slottime:--1}
397 ${frameburst:+frameburst $frameburst}
402 wlc ifname
"$device" stdin
<<EOF
407 wlc ifname
"$device" stdin
<<EOF
411 # use vif_txpower (from last wifi-iface) instead of txpower (from
412 # wifi-device) if the latter does not exist
413 txpower
=${txpower:-$vif_txpower}
414 [ -z "$txpower" ] || iwconfig
$device txpower
${txpower}dBm
423 while grep -qs "^ *wl$((++i)):" /proc
/net
/dev
; do
426 config_get
type wl
${i} type
427 [ "$type" = broadcom
] && continue
428 channel
=`wlc ifname wl${i} channel`
430 config wifi-device wl${i}
432 option channel ${channel:-11}
434 # REMOVE THIS LINE TO ENABLE WIFI:
441 option ssid OpenWrt${i#0}
442 option encryption none