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
111 local bssmax=$(wlc ifname "$device" bssmax)
112 local vif=$((${bssmax:-4} - 1))
113 append ifdown "down" "$N"
114 append ifdown "wds none" "$N"
115 while [ $vif -ge 0 ]; do
116 append ifdown "vif $vif" "$N"
117 append ifdown "enabled 0" "$N"
121 wlc ifname "$device" stdin <<EOF
130 local channel country maxassoc wds vifs distance slottime rxantenna txantenna
131 local frameburst macfilter maclist macaddr txpower frag rts hwmode htmode
132 config_get channel "$device" channel
133 config_get country "$device" country
134 config_get maxassoc "$device" maxassoc
135 config_get wds "$device" wds
136 config_get vifs "$device" vifs
137 config_get distance "$device" distance
138 config_get slottime "$device" slottime
139 config_get rxantenna "$device" rxantenna
140 config_get txantenna "$device" txantenna
141 config_get_bool frameburst "$device" frameburst
142 config_get macfilter "$device" macfilter
143 config_get maclist "$device" maclist
144 config_get macaddr "$device" macaddr $(wlc ifname "$device" default_bssid)
145 config_get txpower "$device" txpower
146 config_get frag "$device" frag
147 config_get rts "$device" rts
148 config_get hwmode "$device" hwmode
149 config_get htmode "$device" htmode
153 [ -z "$slottime" ] && {
154 [ -n "$distance" ] && {
155 # slottime = 9 + (distance / 150) + (distance % 150 ? 1 : 0)
156 slottime="$((9 + ($distance / 150) + 1 - (150 - ($distance % 150)) / 150 ))"
159 slottime="${slottime:--1}"
174 local gmode=2 nmode=0 nreqd=
182 *) nmode=1; nreqd=0;;
186 n|11n) nmode=1; nreqd=1;;
187 *n*) nmode=1; nreqd=0;;
190 # Use 'nmode' for N-Phy only
191 [ "$(wlc ifname "$device" phytype)" = 4 ] || nmode=
194 [ ${channel:-0} -ge 1 -a ${channel:-0} -le 14 ] && band=2
195 [ ${channel:-0} -ge 36 ] && {
200 # Use 'chanspec' instead of 'channel' for 'N' modes (See bcmwifi.h)
201 [ ${nmode:-0} -ne 0 -a -n "$band" -a -n "$channel" ] && {
203 HT40-) chanspec=$(printf 0x%x%x%02x $band 0xe $(($channel - 2))); channel=;;
204 HT40+) chanspec=$(printf 0x%x%x%02x $band 0xd $(($channel + 2))); channel=;;
205 HT20) chanspec=$(printf 0x%x%x%02x $band 0xb $channel); channel=;;
211 local nas="$(which nas)"
212 local if_pre_up if_up nas_cmd
213 local vif vif_pre_up vif_post_up vif_do_up vif_txpower
214 local bssmax=$(wlc ifname "$device" bssmax)
218 [ $_c -ge $bssmax ] && break
220 config_get vif_txpower "$vif" txpower
223 config_get mode "$vif" mode
224 append vif_pre_up "vif $_c" "$N"
225 append vif_post_up "vif $_c" "$N"
226 append vif_do_up "vif $_c" "$N"
228 config_get_bool wmm "$vif" wmm "$wmm"
229 config_get_bool doth "$vif" doth "$doth"
231 [ "$mode" = "sta" ] || {
233 config_get_bool hidden "$vif" hidden 0
234 append vif_pre_up "closed $hidden" "$N"
235 config_get_bool isolate "$vif" isolate 0
236 append vif_pre_up "ap_isolate $isolate" "$N"
246 config_get enc "$vif" encryption
249 local def defkey k knr
253 config_get key "$vif" key
255 *shared*) append vif_do_up "wepauth 1" "$N";;
256 *) append vif_do_up "wepauth 0" "$N";;
261 for knr in 1 2 3 4; do
262 config_get k "$vif" key$knr
263 [ -n "$k" ] || continue
264 [ "$defkey" = "$knr" ] && def="=" || def=""
265 append vif_do_up "wepkey $def$knr,$k" "$N"
269 *) append vif_do_up "wepkey =1,$key" "$N";;
274 config_get key "$vif" key
276 # psk version + default cipher
278 *mixed*|*psk+psk2*) auth=132; wsec=6;;
279 *psk2*) auth=128; wsec=4;;
285 *tkip+aes*|*tkip+ccmp*|*aes+tkip*|*ccmp+tkip*) wsec=6;;
286 *aes*|*ccmp*) wsec=4;;
290 # group rekey interval
291 config_get rekey "$vif" wpa_group_rekey
293 eval "${vif}_key=\"\$key\""
294 nasopts="-k \"\$${vif}_key\"${rekey:+ -g $rekey}"
297 local auth_port auth_secret auth_server
300 config_get auth_server "$vif" auth_server
301 [ -z "$auth_server" ] && config_get auth_server "$vif" server
302 config_get auth_port "$vif" auth_port
303 [ -z "$auth_port" ] && config_get auth_port "$vif" port
304 config_get auth_secret "$vif" auth_secret
305 [ -z "$auth_secret" ] && config_get auth_secret "$vif" key
307 # wpa version + default cipher
309 *mixed*|*wpa+wpa2*) auth=66; wsec=6;;
310 *wpa2*) auth=64; wsec=4;;
316 *tkip+aes*|*tkip+ccmp*|*aes+tkip*|*ccmp+tkip*) wsec=6;;
317 *aes*|*ccmp*) wsec=4;;
321 # group rekey interval
322 config_get rekey "$vif" wpa_group_rekey
324 eval "${vif}_key=\"\$auth_secret\""
325 nasopts="-r \"\$${vif}_key\" -h $auth_server -p ${auth_port:-1812}${rekey:+ -g $rekey}"
328 append vif_do_up "wsec $wsec" "$N"
329 append vif_do_up "wpa_auth $auth" "$N"
330 append vif_do_up "wsec_restrict $wsec_r" "$N"
331 append vif_do_up "eap_restrict $eap_r" "$N"
334 config_get ssid "$vif" ssid
335 append vif_post_up "vlan_mode 0" "$N"
336 append vif_pre_up "ssid $ssid" "$N"
338 [ "$mode" = "monitor" ] && {
339 append vif_post_up "monitor $monitor" "$N"
342 [ "$mode" = "adhoc" ] && {
344 config_get bssid "$vif" bssid
346 append vif_pre_up "bssid $bssid" "$N"
347 append vif_pre_up "ibss_merge 0" "$N"
349 append vif_pre_up "ibss_merge 1" "$N"
353 append vif_post_up "enabled 1" "$N"
356 config_get ifname "$vif" ifname
357 local if_cmd="if_pre_up"
358 [ "$ifname" != "${ifname##${device}-}" ] && if_cmd="if_up"
359 append $if_cmd "macaddr=\$(wlc ifname '$ifname' cur_etheraddr)" ";$N"
360 append $if_cmd "ifconfig '$ifname' \${macaddr:+hw ether \$macaddr}" ";$N"
361 append if_up "ifconfig '$ifname' up" ";$N"
363 local net_cfg="$(find_net_config "$vif")"
364 [ -z "$net_cfg" ] || {
365 append if_up "set_wifi_up '$vif' '$ifname'" ";$N"
366 append if_up "start_net '$ifname' '$net_cfg'" ";$N"
368 [ -z "$nas" -o -z "$nasopts" ] || {
369 eval "${vif}_ssid=\"\$ssid\""
371 [ "$mode" = "sta" ] && nas_mode="-S"
372 [ -z "$nas_cmd" ] && {
373 local pid_file=/var/run/nas.$device.pid
374 nas_cmd="start-stop-daemon -S -b -p $pid_file -x $nas -- -P $pid_file -H 34954"
376 append nas_cmd "-i $ifname $nas_mode -m $auth -w $wsec -s \"\$${vif}_ssid\" -g 3600 -F $nasopts"
380 wlc ifname "$device" stdin <<EOF
381 ${macaddr:+bssid $macaddr}
382 ${macaddr:+cur_etheraddr $macaddr}
384 ${nmode:+nmode $nmode}
385 ${nmode:+${nreqd:+nreqd $nreqd}}
386 ${gmode:+gmode $gmode}
389 ${mssid:+mssid $mssid}
395 rxant ${rxantenna:-3}
396 txant ${txantenna:-3}
397 fragthresh ${frag:-2346}
398 rtsthresh ${rts:-2347}
399 monitor ${monitor:-0}
402 macfilter ${macfilter:-0}
403 maclist ${maclist:-none}
405 country ${country:-US}
406 ${channel:+channel $channel}
407 ${chanspec:+chanspec $chanspec}
408 maxassoc ${maxassoc:-128}
409 slottime ${slottime:--1}
410 ${frameburst:+frameburst $frameburst}
415 wlc ifname "$device" stdin <<EOF
420 wlc ifname "$device" stdin <<EOF
424 # use vif_txpower (from last wifi-iface) instead of txpower (from
425 # wifi-device) if the latter does not exist
426 txpower=${txpower:-$vif_txpower}
427 [ -z "$txpower" ] || iwconfig $device txpower ${txpower}dBm
436 while grep -qs "^ *wl$((++i)):" /proc/net/dev; do
439 config_get type wl${i} type
440 [ "$type" = broadcom ] && continue
441 channel=`wlc ifname wl${i} channel`
443 config wifi-device wl${i}
445 option channel ${channel:-11}
447 # REMOVE THIS LINE TO ENABLE WIFI:
454 option ssid OpenWrt${i#0}
455 option encryption none