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 [ ${channel:-0} -ge 1 -a ${channel:-0} -le 14 ] && band=2
169 [ ${channel:-0} -ge 36 ] && band=1
172 *na) nmode=1; nreqd=0;;
174 *ng) gmode=1; nmode=1; nreqd=0;;
175 *n) nmode=1; nreqd=1;;
176 *b) gmode=0; nmode=0;;
177 *bg) gmode=1; nmode=0;;
178 *g) gmode=2; nmode=0;;
179 *gst) gmode=4; nmode=0;;
180 *lrs) gmode=5; nmode=0;;
182 2) gmode=1; nmode=1; nreqd=0;;
183 1) nmode=1; nreqd=0;;
184 *) gmode=1; nmode=1; nreqd=0;;
189 # Use 'nmode' for N-Phy only
190 [ "$(wlc ifname $device phytype)" = 4 ] || nmode=
192 # Use 'chanspec' instead of 'channel' for 'N' modes (See bcmwifi.h)
193 [ ${nmode:-0} -ne 0 -a -n "$band" ] && {
195 HT40-) chanspec=$(printf 0x%x%x%02x $band 0xe $(($channel - 2))); channel=;;
196 HT40+) chanspec=$(printf 0x%x%x%02x $band 0xd $(($channel + 2))); channel=;;
197 HT20) chanspec=$(printf 0x%x%x%02x $band 0xb $channel); channel=;;
203 config_get vif_txpower "$vif" txpower
205 config_get mode "$vif" mode
206 append vif_pre_up "vif $_c" "$N"
207 append vif_post_up "vif $_c" "$N"
208 append vif_do_up "vif $_c" "$N"
210 config_get_bool wmm "$vif" wmm "$wmm"
211 config_get_bool doth "$vif" doth "$doth"
213 [ "$mode" = "sta" ] || {
214 config_get_bool hidden "$vif" hidden 0
215 append vif_pre_up "closed $hidden" "$N"
216 config_get_bool isolate "$vif" isolate 0
217 append vif_pre_up "ap_isolate $isolate" "$N"
225 config_get enc "$vif" encryption
231 config_get key "$vif" key
233 *shared*) append vif_do_up "wepauth 1" "$N";;
234 *) append vif_do_up "wepauth 0" "$N";;
239 for knr in 1 2 3 4; do
240 config_get k "$vif" key$knr
241 [ -n "$k" ] || continue
242 [ "$defkey" = "$knr" ] && def="=" || def=""
243 append vif_do_up "wepkey $def$knr,$k" "$N"
247 *) append vif_do_up "wepkey =1,$key" "$N";;
252 config_get key "$vif" key
254 # psk version + default cipher
256 *mixed*|*psk+psk2*) auth=132; wsec=6;;
257 *psk2*) auth=128; wsec=4;;
263 *tkip+aes*|*tkip+ccmp*|*aes+tkip*|*ccmp+tkip*) wsec=6;;
264 *aes*|*ccmp*) wsec=4;;
268 # group rekey interval
269 config_get rekey "$vif" wpa_group_rekey
271 eval "${vif}_key=\"\$key\""
272 nasopts="-k \"\$${vif}_key\"${rekey:+ -g $rekey}"
277 config_get auth_server "$vif" auth_server
278 [ -z "$auth_server" ] && config_get auth_server "$vif" server
279 config_get auth_port "$vif" auth_port
280 [ -z "$auth_port" ] && config_get auth_port "$vif" port
281 config_get auth_secret "$vif" auth_secret
282 [ -z "$auth_secret" ] && config_get auth_secret "$vif" key
284 # wpa version + default cipher
286 *mixed*|*wpa+wpa2*) auth=66; wsec=6;;
287 *wpa2*) auth=64; wsec=4;;
293 *tkip+aes*|*tkip+ccmp*|*aes+tkip*|*ccmp+tkip*) wsec=6;;
294 *aes*|*ccmp*) wsec=4;;
298 # group rekey interval
299 config_get rekey "$vif" wpa_group_rekey
301 eval "${vif}_key=\"\$auth_secret\""
302 nasopts="-r \"\$${vif}_key\" -h $auth_server -p ${auth_port:-1812}${rekey:+ -g $rekey}"
305 append vif_do_up "wsec $wsec" "$N"
306 append vif_do_up "wpa_auth $auth" "$N"
307 append vif_do_up "wsec_restrict $wsec_r" "$N"
308 append vif_do_up "eap_restrict $eap_r" "$N"
310 config_get ssid "$vif" ssid
311 append vif_post_up "vlan_mode 0" "$N"
312 append vif_post_up "ssid $ssid" "$N"
313 append vif_do_up "ssid $ssid" "$N"
315 [ "$mode" = "monitor" ] && {
316 append vif_post_up "monitor $monitor" "$N"
319 [ "$mode" = "adhoc" ] && {
320 config_get bssid "$vif" bssid
322 append vif_pre_up "bssid $bssid" "$N"
323 append vif_pre_up "ibss_merge 0" "$N"
325 append vif_pre_up "ibss_merge 1" "$N"
329 append vif_post_up "enabled 1" "$N"
331 config_get ifname "$vif" ifname
332 #append if_up "ifconfig $ifname up" ";$N"
335 net_cfg="$(find_net_config "$vif")"
336 [ -z "$net_cfg" ] || {
337 append if_up "set_wifi_up '$vif' '$ifname'" ";$N"
338 append if_up "start_net '$ifname' '$net_cfg'" ";$N"
340 [ -z "$nas" -o -z "$nasopts" ] || {
341 eval "${vif}_ssid=\"\$ssid\""
343 [ "$mode" = "sta" ] && nas_mode="-S"
344 [ -z "$nas_cmd" ] && {
345 local pid_file=/var/run/nas.$device.pid
346 nas_cmd="start-stop-daemon -S -b -p $pid_file -x $nas -- -P $pid_file -H 34954"
348 append nas_cmd "-i $ifname $nas_mode -m $auth -w $wsec -s \"\$${vif}_ssid\" -g 3600 -F $nasopts"
352 wlc ifname "$device" stdin <<EOF
355 ${nmode:+band ${band:-0}}
356 ${nmode:+nmode $nmode}
357 ${nmode:+${nreqd:+nreqd $nreqd}}
358 ${gmode:+gmode $gmode}
361 ${mssid:+mssid $mssid}
367 rxant ${rxantenna:-3}
368 txant ${txantenna:-3}
369 fragthresh ${frag:-2346}
370 rtsthresh ${rts:-2347}
371 monitor ${monitor:-0}
374 macfilter ${macfilter:-0}
375 maclist ${maclist:-none}
378 country ${country:-US}
379 ${channel:+channel $channel}
380 ${chanspec:+chanspec $chanspec}
381 maxassoc ${maxassoc:-128}
382 slottime ${slottime:--1}
383 ${frameburst:+frameburst $frameburst}
390 wlc ifname "$device" stdin <<EOF
394 # use vif_txpower (from last wifi-iface) instead of txpower (from
395 # wifi-device) if the latter does not exist
396 txpower=${txpower:-$vif_txpower}
397 [ -z "$txpower" ] || iwconfig $device txpower ${txpower}dBm
406 while grep -qs "^ *wl$((++i)):" /proc/net/dev; do
409 config_get type wl${i} type
410 [ "$type" = broadcom ] && continue
411 channel=`wlc ifname wl${i} channel`
413 config wifi-device wl${i}
415 option channel ${channel:-11}
417 # REMOVE THIS LINE TO ENABLE WIFI:
424 option ssid OpenWrt${i#0}
425 option encryption none