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
131 local channel country maxassoc wds vifs distance slottime rxantenna txantenna
132 local frameburst macfilter maclist macaddr txpower frag rts hwmode htmode
133 config_get channel "$device" channel
134 config_get country "$device" country
135 config_get maxassoc "$device" maxassoc
136 config_get wds "$device" wds
137 config_get vifs "$device" vifs
138 config_get distance "$device" distance
139 config_get slottime "$device" slottime
140 config_get rxantenna "$device" rxantenna
141 config_get txantenna "$device" txantenna
142 config_get_bool frameburst "$device" frameburst
143 config_get macfilter "$device" macfilter
144 config_get maclist "$device" maclist
145 config_get macaddr "$device" macaddr $(wlc ifname "$device" default_bssid)
146 config_get txpower "$device" txpower
147 config_get frag "$device" frag
148 config_get rts "$device" rts
149 config_get hwmode "$device" hwmode
150 config_get htmode "$device" htmode
154 [ -z "$slottime" ] && {
155 [ -n "$distance" ] && {
156 # slottime = 9 + (distance / 150) + (distance % 150 ? 1 : 0)
157 slottime="$((9 + ($distance / 150) + 1 - (150 - ($distance % 150)) / 150 ))"
160 slottime="${slottime:--1}"
175 local gmode=2 nmode=0 nreqd=
183 *) nmode=1; nreqd=0;;
187 n|11n) nmode=1; nreqd=1;;
188 *n*) nmode=1; nreqd=0;;
191 # Use 'nmode' for N-Phy only
192 [ "$(wlc ifname "$device" phytype)" = 4 ] || nmode=
195 [ ${channel:-0} -ge 1 -a ${channel:-0} -le 14 ] && band=2
196 [ ${channel:-0} -ge 36 ] && {
201 # Use 'chanspec' instead of 'channel' for 'N' modes (See bcmwifi.h)
202 [ -n "$nmode" -a -n "$band" -a -n "$channel" ] && {
205 if [ -n "$gmode" ]; then
206 [ $channel -lt 7 ] && htmode="HT40+" || htmode="HT40-"
208 [ $(( ($channel / 4) % 2 )) -eq 1 ] && htmode="HT40+" || htmode="HT40-"
213 HT40-) chanspec=$(printf 0x%x%x%02x $band 0xe $(($channel - 2))); nmode=1; channel=;;
214 HT40+) chanspec=$(printf 0x%x%x%02x $band 0xd $(($channel + 2))); nmode=1; channel=;;
215 HT20) chanspec=$(printf 0x%x%x%02x $band 0xb $channel); nmode=1; channel=;;
220 local leddc=$(wlc ifname "$device" leddc)
221 [ "$leddc" -eq 0xffff ] || {
226 local nas="$(which nas)"
227 local if_pre_up if_up nas_cmd
228 local vif vif_pre_up vif_post_up vif_do_up vif_txpower
229 local bssmax=$(wlc ifname "$device" bssmax)
233 [ $_c -ge $bssmax ] && break
235 config_get vif_txpower "$vif" txpower
238 config_get mode "$vif" mode
239 append vif_pre_up "vif $_c" "$N"
240 append vif_post_up "vif $_c" "$N"
241 append vif_do_up "vif $_c" "$N"
243 config_get_bool wmm "$vif" wmm "$wmm"
244 config_get_bool doth "$vif" doth "$doth"
246 [ "$mode" = "sta" ] || {
248 config_get_bool hidden "$vif" hidden 0
249 append vif_pre_up "closed $hidden" "$N"
250 config_get_bool isolate "$vif" isolate 0
251 append vif_pre_up "ap_isolate $isolate" "$N"
261 config_get enc "$vif" encryption
264 local def defkey k knr
268 config_get key "$vif" key
270 *shared*) append vif_do_up "wepauth 1" "$N";;
271 *) append vif_do_up "wepauth 0" "$N";;
276 for knr in 1 2 3 4; do
277 config_get k "$vif" key$knr
278 [ -n "$k" ] || continue
279 [ "$defkey" = "$knr" ] && def="=" || def=""
280 append vif_do_up "wepkey $def$knr,$k" "$N"
284 *) append vif_do_up "wepkey =1,$key" "$N";;
289 config_get key "$vif" key
291 # psk version + default cipher
293 *mixed*|*psk+psk2*) auth=132; wsec=6;;
294 *psk2*) auth=128; wsec=4;;
300 *tkip+aes*|*tkip+ccmp*|*aes+tkip*|*ccmp+tkip*) wsec=6;;
301 *aes*|*ccmp*) wsec=4;;
305 # group rekey interval
306 config_get rekey "$vif" wpa_group_rekey
308 eval "${vif}_key=\"\$key\""
309 nasopts="-k \"\$${vif}_key\"${rekey:+ -g $rekey}"
312 local auth_port auth_secret auth_server
315 config_get auth_server "$vif" auth_server
316 [ -z "$auth_server" ] && config_get auth_server "$vif" server
317 config_get auth_port "$vif" auth_port
318 [ -z "$auth_port" ] && config_get auth_port "$vif" port
319 config_get auth_secret "$vif" auth_secret
320 [ -z "$auth_secret" ] && config_get auth_secret "$vif" key
322 # wpa version + default cipher
324 *mixed*|*wpa+wpa2*) auth=66; wsec=6;;
325 *wpa2*) auth=64; wsec=4;;
331 *tkip+aes*|*tkip+ccmp*|*aes+tkip*|*ccmp+tkip*) wsec=6;;
332 *aes*|*ccmp*) wsec=4;;
336 # group rekey interval
337 config_get rekey "$vif" wpa_group_rekey
339 eval "${vif}_key=\"\$auth_secret\""
340 nasopts="-r \"\$${vif}_key\" -h $auth_server -p ${auth_port:-1812}${rekey:+ -g $rekey}"
343 append vif_do_up "wsec $wsec" "$N"
344 append vif_do_up "wpa_auth $auth" "$N"
345 append vif_do_up "wsec_restrict $wsec_r" "$N"
346 append vif_do_up "eap_restrict $eap_r" "$N"
349 config_get ssid "$vif" ssid
350 append vif_post_up "vlan_mode 0" "$N"
351 append vif_pre_up "ssid $ssid" "$N"
353 [ "$mode" = "monitor" ] && {
354 append vif_post_up "monitor $monitor" "$N"
357 [ "$mode" = "adhoc" ] && {
359 config_get bssid "$vif" bssid
361 append vif_pre_up "bssid $bssid" "$N"
362 append vif_pre_up "ibss_merge 0" "$N"
364 append vif_pre_up "ibss_merge 1" "$N"
368 append vif_post_up "enabled 1" "$N"
371 config_get ifname "$vif" ifname
372 local if_cmd="if_pre_up"
373 [ "$ifname" != "${ifname##${device}-}" ] && if_cmd="if_up"
374 append $if_cmd "macaddr=\$(wlc ifname '$ifname' cur_etheraddr)" ";$N"
375 append $if_cmd "ifconfig '$ifname' \${macaddr:+hw ether \$macaddr}" ";$N"
376 append if_up "ifconfig '$ifname' up" ";$N"
378 local net_cfg="$(find_net_config "$vif")"
379 [ -z "$net_cfg" ] || {
380 append if_up "set_wifi_up '$vif' '$ifname'" ";$N"
381 append if_up "start_net '$ifname' '$net_cfg'" ";$N"
383 [ -z "$nas" -o -z "$nasopts" ] || {
384 eval "${vif}_ssid=\"\$ssid\""
386 [ "$mode" = "sta" ] && nas_mode="-S"
387 [ -z "$nas_cmd" ] && {
388 local pid_file=/var/run/nas.$device.pid
389 nas_cmd="start-stop-daemon -S -b -p $pid_file -x $nas -- -P $pid_file -H 34954"
391 append nas_cmd "-i $ifname $nas_mode -m $auth -w $wsec -s \"\$${vif}_ssid\" -g 3600 -F $nasopts"
395 wlc ifname "$device" stdin <<EOF
396 ${macaddr:+bssid $macaddr}
397 ${macaddr:+cur_etheraddr $macaddr}
399 ${nmode:+nmode $nmode}
400 ${nmode:+${nreqd:+nreqd $nreqd}}
401 ${gmode:+gmode $gmode}
405 ${mssid:+mssid $mssid}
411 rxant ${rxantenna:-3}
412 txant ${txantenna:-3}
413 fragthresh ${frag:-2346}
414 rtsthresh ${rts:-2347}
415 monitor ${monitor:-0}
418 macfilter ${macfilter:-0}
419 maclist ${maclist:-none}
421 country ${country:-US}
422 ${channel:+channel $channel}
423 ${chanspec:+chanspec $chanspec}
424 maxassoc ${maxassoc:-128}
425 slottime ${slottime:--1}
426 ${frameburst:+frameburst $frameburst}
431 wlc ifname "$device" stdin <<EOF
436 wlc ifname "$device" stdin <<EOF
440 # use vif_txpower (from last wifi-iface) instead of txpower (from
441 # wifi-device) if the latter does not exist
442 txpower=${txpower:-$vif_txpower}
443 [ -z "$txpower" ] || iwconfig $device txpower ${txpower}dBm
452 while grep -qs "^ *wl$((++i)):" /proc/net/dev; do
455 config_get type wl${i} type
456 [ "$type" = broadcom ] && continue
457 channel=`wlc ifname wl${i} channel`
459 config wifi-device wl${i}
461 option channel ${channel:-11}
464 # REMOVE THIS LINE TO ENABLE WIFI:
471 option ssid OpenWrt${i#0}
472 option encryption none