1 append DRIVERS "broadcom"
6 local adhoc sta apmode mon disabled
7 local adhoc_if sta_if ap_if mon_if
10 config_get vifs "$device" vifs
12 config_get_bool disabled "$vif" disabled 0
13 [ $disabled -eq 0 ] || continue
15 config_get mode "$vif" mode
28 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
108 for dev in $device ${device}-1 ${device}-2 ${device}-3; do
109 ifconfig "$dev" down 2>/dev/null >/dev/null && {
120 config_get channel "$device" channel
121 config_get country "$device" country
122 config_get maxassoc "$device" maxassoc
123 config_get wds "$device" wds
124 config_get vifs "$device" vifs
125 config_get distance "$device" distance
126 config_get slottime "$device" slottime
127 config_get rxantenna "$device" rxantenna
128 config_get txantenna "$device" txantenna
129 config_get_bool frameburst "$device" frameburst
130 config_get macfilter "$device" macfilter
131 config_get maclist "$device" maclist
132 config_get macaddr "$device" macaddr
133 config_get txpower "$device" txpower
134 config_get frag "$device" frag
135 config_get rts "$device" rts
136 config_get hwmode "$device" hwmode
137 config_get htmode "$device" htmode
138 local vif_pre_up vif_post_up vif_do_up vif_txpower
147 [ -z "$slottime" ] && {
148 [ -n "$distance" ] && {
149 # slottime = 9 + (distance / 150) + (distance % 150 ? 1 : 0)
150 slottime="$((9 + ($distance / 150) + 1 - (150 - ($distance % 150)) / 150 ))"
153 slottime="${slottime:--1}"
168 local gmode=2 nmode=0 nreqd=
176 *) nmode=1; nreqd=0;;
180 n|11n) nmode=1; nreqd=1;;
181 *n*) nmode=1; nreqd=0;;
184 # Use 'nmode' for N-Phy only
185 [ "$(wlc ifname "$device" phytype)" = 4 ] || nmode=
188 [ ${channel:-0} -ge 1 -a ${channel:-0} -le 14 ] && band=2
189 [ ${channel:-0} -ge 36 ] && {
194 # Use 'chanspec' instead of 'channel' for 'N' modes (See bcmwifi.h)
195 [ ${nmode:-0} -ne 0 -a -n "$band" -a -n "$channel" ] && {
197 HT40-) chanspec=$(printf 0x%x%x%02x $band 0xe $(($channel - 2))); channel=;;
198 HT40+) chanspec=$(printf 0x%x%x%02x $band 0xd $(($channel + 2))); channel=;;
199 HT20) chanspec=$(printf 0x%x%x%02x $band 0xb $channel); channel=;;
205 config_get vif_txpower "$vif" txpower
207 config_get mode "$vif" mode
208 append vif_pre_up "vif $_c" "$N"
209 append vif_post_up "vif $_c" "$N"
210 append vif_do_up "vif $_c" "$N"
212 config_get_bool wmm "$vif" wmm "$wmm"
213 config_get_bool doth "$vif" doth "$doth"
215 [ "$mode" = "sta" ] || {
216 config_get_bool hidden "$vif" hidden 0
217 append vif_pre_up "closed $hidden" "$N"
218 config_get_bool isolate "$vif" isolate 0
219 append vif_pre_up "ap_isolate $isolate" "$N"
227 config_get enc "$vif" encryption
233 config_get key "$vif" key
235 *shared*) append vif_do_up "wepauth 1" "$N";;
236 *) append vif_do_up "wepauth 0" "$N";;
241 for knr in 1 2 3 4; do
242 config_get k "$vif" key$knr
243 [ -n "$k" ] || continue
244 [ "$defkey" = "$knr" ] && def="=" || def=""
245 append vif_do_up "wepkey $def$knr,$k" "$N"
249 *) append vif_do_up "wepkey =1,$key" "$N";;
254 config_get key "$vif" key
256 # psk version + default cipher
258 *mixed*|*psk+psk2*) auth=132; wsec=6;;
259 *psk2*) auth=128; wsec=4;;
265 *tkip+aes*|*tkip+ccmp*|*aes+tkip*|*ccmp+tkip*) wsec=6;;
266 *aes*|*ccmp*) wsec=4;;
270 # group rekey interval
271 config_get rekey "$vif" wpa_group_rekey
273 eval "${vif}_key=\"\$key\""
274 nasopts="-k \"\$${vif}_key\"${rekey:+ -g $rekey}"
279 config_get auth_server "$vif" auth_server
280 [ -z "$auth_server" ] && config_get auth_server "$vif" server
281 config_get auth_port "$vif" auth_port
282 [ -z "$auth_port" ] && config_get auth_port "$vif" port
283 config_get auth_secret "$vif" auth_secret
284 [ -z "$auth_secret" ] && config_get auth_secret "$vif" key
286 # wpa version + default cipher
288 *mixed*|*wpa+wpa2*) auth=66; wsec=6;;
289 *wpa2*) auth=64; wsec=4;;
295 *tkip+aes*|*tkip+ccmp*|*aes+tkip*|*ccmp+tkip*) wsec=6;;
296 *aes*|*ccmp*) wsec=4;;
300 # group rekey interval
301 config_get rekey "$vif" wpa_group_rekey
303 eval "${vif}_key=\"\$auth_secret\""
304 nasopts="-r \"\$${vif}_key\" -h $auth_server -p ${auth_port:-1812}${rekey:+ -g $rekey}"
307 append vif_do_up "wsec $wsec" "$N"
308 append vif_do_up "wpa_auth $auth" "$N"
309 append vif_do_up "wsec_restrict $wsec_r" "$N"
310 append vif_do_up "eap_restrict $eap_r" "$N"
312 config_get ssid "$vif" ssid
313 append vif_post_up "vlan_mode 0" "$N"
314 append vif_post_up "ssid $ssid" "$N"
315 append vif_do_up "ssid $ssid" "$N"
317 [ "$mode" = "monitor" ] && {
318 append vif_post_up "monitor $monitor" "$N"
321 [ "$mode" = "adhoc" ] && {
322 config_get bssid "$vif" bssid
324 append vif_pre_up "bssid $bssid" "$N"
325 append vif_pre_up "ibss_merge 0" "$N"
327 append vif_pre_up "ibss_merge 1" "$N"
331 append vif_post_up "enabled 1" "$N"
333 config_get ifname "$vif" ifname
334 #append if_up "ifconfig $ifname up" ";$N"
337 net_cfg="$(find_net_config "$vif")"
338 [ -z "$net_cfg" ] || {
339 append if_up "set_wifi_up '$vif' '$ifname'" ";$N"
340 append if_up "start_net '$ifname' '$net_cfg'" ";$N"
342 [ -z "$nas" -o -z "$nasopts" ] || {
343 eval "${vif}_ssid=\"\$ssid\""
345 [ "$mode" = "sta" ] && nas_mode="-S"
346 [ -z "$nas_cmd" ] && {
347 local pid_file=/var/run/nas.$device.pid
348 nas_cmd="start-stop-daemon -S -b -p $pid_file -x $nas -- -P $pid_file -H 34954"
350 append nas_cmd "-i $ifname $nas_mode -m $auth -w $wsec -s \"\$${vif}_ssid\" -g 3600 -F $nasopts"
354 wlc ifname "$device" stdin <<EOF
358 ${nmode:+nmode $nmode}
359 ${nmode:+${nreqd:+nreqd $nreqd}}
360 ${gmode:+gmode $gmode}
363 ${mssid:+mssid $mssid}
369 rxant ${rxantenna:-3}
370 txant ${txantenna:-3}
371 fragthresh ${frag:-2346}
372 rtsthresh ${rts:-2347}
373 monitor ${monitor:-0}
376 macfilter ${macfilter:-0}
377 maclist ${maclist:-none}
380 country ${country:-US}
381 ${channel:+channel $channel}
382 ${chanspec:+chanspec $chanspec}
383 maxassoc ${maxassoc:-128}
384 slottime ${slottime:--1}
385 ${frameburst:+frameburst $frameburst}
392 wlc ifname "$device" stdin <<EOF
396 # use vif_txpower (from last wifi-iface) instead of txpower (from
397 # wifi-device) if the latter does not exist
398 txpower=${txpower:-$vif_txpower}
399 [ -z "$txpower" ] || iwconfig $device txpower ${txpower}dBm
408 while grep -qs "^ *wl$((++i)):" /proc/net/dev; do
411 config_get type wl${i} type
412 [ "$type" = broadcom ] && continue
413 channel=`wlc ifname wl${i} channel`
415 config wifi-device wl${i}
417 option channel ${channel:-11}
419 # REMOVE THIS LINE TO ENABLE WIFI:
426 option ssid OpenWrt${i#0}
427 option encryption none