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 # make sure the interfaces are down and removed from all bridges
105 for dev in $device ${device}-1 ${device}-2 ${device}-3; do
106 ifconfig "$dev" down 2>/dev/null >/dev/null && {
117 config_get channel "$device" channel
118 config_get country "$device" country
119 config_get maxassoc "$device" maxassoc
120 config_get wds "$device" wds
121 config_get vifs "$device" vifs
122 config_get distance "$device" distance
123 config_get slottime "$device" slottime
124 config_get rxantenna "$device" rxantenna
125 config_get txantenna "$device" txantenna
126 config_get_bool frameburst "$device" frameburst
127 config_get macfilter "$device" macfilter
128 config_get maclist "$device" maclist
129 config_get macaddr "$device" macaddr
130 config_get txpower "$device" txpower
131 config_get frag "$device" frag
132 config_get rts "$device" rts
133 config_get hwmode "$device" hwmode
134 config_get htmode "$device" htmode
135 local vif_pre_up vif_post_up vif_do_up vif_txpower
144 [ -z "$slottime" ] && {
145 [ -n "$distance" ] && {
146 # slottime = 9 + (distance / 150) + (distance % 150 ? 1 : 0)
147 slottime="$((9 + ($distance / 150) + 1 - (150 - ($distance % 150)) / 150 ))"
150 slottime="${slottime:--1}"
165 [ ${channel:-0} -ge 1 -a ${channel:-0} -le 14 ] && band=2
166 [ ${channel:-0} -ge 36 ] && band=1
169 *na) nmode=1; nreqd=0;;
171 *ng) gmode=1; nmode=1; nreqd=0;;
172 *n) nmode=1; nreqd=1;;
173 *b) gmode=0; nmode=0;;
174 *bg) gmode=1; nmode=0;;
175 *g) gmode=2; nmode=0;;
176 *gst) gmode=4; nmode=0;;
177 *lrs) gmode=5; nmode=0;;
179 2) gmode=1; nmode=1; nreqd=0;;
180 1) nmode=1; nreqd=0;;
181 *) gmode=1; nmode=1; nreqd=0;;
186 # Use 'nmode' for N-Phy only
187 [ "$(wlc ifname $device phytype)" = 4 ] || nmode=
189 # Use 'chanspec' instead of 'channel' for 'N' modes (See bcmwifi.h)
190 [ ${nmode:-0} -ne 0 -a -n "$band" ] && {
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 config_get vif_txpower "$vif" txpower
202 config_get mode "$vif" mode
203 append vif_pre_up "vif $_c" "$N"
204 append vif_post_up "vif $_c" "$N"
205 append vif_do_up "vif $_c" "$N"
207 config_get_bool wmm "$vif" wmm "$wmm"
208 config_get_bool doth "$vif" doth "$doth"
210 [ "$mode" = "sta" ] || {
211 config_get_bool hidden "$vif" hidden 0
212 append vif_pre_up "closed $hidden" "$N"
213 config_get_bool isolate "$vif" isolate 0
214 append vif_pre_up "ap_isolate $isolate" "$N"
222 config_get enc "$vif" encryption
228 config_get key "$vif" key
230 *shared*) append vif_do_up "wepauth 1" "$N";;
231 *) append vif_do_up "wepauth 0" "$N";;
236 for knr in 1 2 3 4; do
237 config_get k "$vif" key$knr
238 [ -n "$k" ] || continue
239 [ "$defkey" = "$knr" ] && def="=" || def=""
240 append vif_do_up "wepkey $def$knr,$k" "$N"
244 *) append vif_do_up "wepkey =1,$key" "$N";;
249 config_get key "$vif" key
251 # psk version + default cipher
253 *mixed*|*psk+psk2*) auth=132; wsec=6;;
254 *psk2*) auth=128; wsec=4;;
260 *tkip+aes*|*tkip+ccmp*|*aes+tkip*|*ccmp+tkip*) wsec=6;;
261 *aes*|*ccmp*) wsec=4;;
265 # group rekey interval
266 config_get rekey "$vif" wpa_group_rekey
268 eval "${vif}_key=\"\$key\""
269 nasopts="-k \"\$${vif}_key\"${rekey:+ -g $rekey}"
274 config_get auth_server "$vif" auth_server
275 [ -z "$auth_server" ] && config_get auth_server "$vif" server
276 config_get auth_port "$vif" auth_port
277 [ -z "$auth_port" ] && config_get auth_port "$vif" port
278 config_get auth_secret "$vif" auth_secret
279 [ -z "$auth_secret" ] && config_get auth_secret "$vif" key
281 # wpa version + default cipher
283 *mixed*|*wpa+wpa2*) auth=66; wsec=6;;
284 *wpa2*) auth=64; wsec=4;;
290 *tkip+aes*|*tkip+ccmp*|*aes+tkip*|*ccmp+tkip*) wsec=6;;
291 *aes*|*ccmp*) wsec=4;;
295 # group rekey interval
296 config_get rekey "$vif" wpa_group_rekey
298 eval "${vif}_key=\"\$auth_secret\""
299 nasopts="-r \"\$${vif}_key\" -h $auth_server -p ${auth_port:-1812}${rekey:+ -g $rekey}"
302 append vif_do_up "wsec $wsec" "$N"
303 append vif_do_up "wpa_auth $auth" "$N"
304 append vif_do_up "wsec_restrict $wsec_r" "$N"
305 append vif_do_up "eap_restrict $eap_r" "$N"
307 config_get ssid "$vif" ssid
308 append vif_post_up "vlan_mode 0" "$N"
309 append vif_post_up "ssid $ssid" "$N"
310 append vif_do_up "ssid $ssid" "$N"
312 [ "$mode" = "monitor" ] && {
313 append vif_post_up "monitor $monitor" "$N"
316 [ "$mode" = "adhoc" ] && {
317 config_get bssid "$vif" bssid
319 append vif_pre_up "bssid $bssid" "$N"
320 append vif_pre_up "ibss_merge 0" "$N"
322 append vif_pre_up "ibss_merge 1" "$N"
326 append vif_post_up "enabled 1" "$N"
328 config_get ifname "$vif" ifname
329 #append if_up "ifconfig $ifname up" ";$N"
332 net_cfg="$(find_net_config "$vif")"
333 [ -z "$net_cfg" ] || {
334 append if_up "set_wifi_up '$vif' '$ifname'" ";$N"
335 append if_up "start_net '$ifname' '$net_cfg'" ";$N"
337 [ -z "$nas" -o -z "$nasopts" ] || {
338 eval "${vif}_ssid=\"\$ssid\""
340 [ "$mode" = "sta" ] && nas_mode="-S"
341 [ -z "$nas_cmd" ] && {
342 local pid_file=/var/run/nas.$device.pid
343 nas_cmd="start-stop-daemon -S -b -p $pid_file -x $nas -- -P $pid_file -H 34954"
345 append nas_cmd "-i $ifname $nas_mode -m $auth -w $wsec -s \"\$${vif}_ssid\" -g 3600 -F $nasopts"
349 killall -KILL nas >&- 2>&-
350 wlc ifname "$device" stdin <<EOF
353 ${nmode:+band ${band:-0}}
354 ${nmode:+nmode $nmode}
355 ${nmode:+${nreqd:+nreqd $nreqd}}
356 ${gmode:+gmode $gmode}
359 ${mssid:+mssid $mssid}
365 rxant ${rxantenna:-3}
366 txant ${txantenna:-3}
367 fragthresh ${frag:-2346}
368 rtsthresh ${rts:-2347}
369 monitor ${monitor:-0}
372 macfilter ${macfilter:-0}
373 maclist ${maclist:-none}
376 country ${country:-US}
377 ${channel:+channel $channel}
378 ${chanspec:+chanspec $chanspec}
379 maxassoc ${maxassoc:-128}
380 slottime ${slottime:--1}
381 ${frameburst:+frameburst $frameburst}
388 wlc ifname "$device" stdin <<EOF
392 # use vif_txpower (from last wifi-iface) instead of txpower (from
393 # wifi-device) if the latter does not exist
394 txpower=${txpower:-$vif_txpower}
395 [ -z "$txpower" ] || iwconfig $device txpower ${txpower}dBm
404 while grep -qs "^ *wl$((++i)):" /proc/net/dev; do
407 config_get type wl${i} type
408 [ "$type" = broadcom ] && continue
409 channel=`wlc ifname wl${i} channel`
411 config wifi-device wl${i}
413 option channel ${channel:-11}
415 # REMOVE THIS LINE TO ENABLE WIFI:
422 option ssid OpenWrt${i#0}
423 option encryption none