ath9k: fix misplaced ifdef
[openwrt.git] / package / broadcom-wl / files / lib / wifi / broadcom.sh
1 append DRIVERS "broadcom"
2
3 scan_broadcom() {
4 local device="$1"
5 local wds
6 local adhoc sta apmode mon disabled
7 local adhoc_if sta_if ap_if mon_if
8 local _c=0
9
10 config_get vifs "$device" vifs
11 for vif in $vifs; do
12 config_get_bool disabled "$vif" disabled 0
13 [ $disabled -eq 0 ] || continue
14
15 config_get mode "$vif" mode
16 _c=$(($_c + 1))
17 case "$mode" in
18 adhoc)
19 adhoc=1
20 adhoc_if="$vif"
21 ;;
22 sta)
23 sta=1
24 sta_if="$vif"
25 ;;
26 ap)
27 apmode=1
28 ap_if="${ap_if:+$ap_if }$vif"
29 ;;
30 wds)
31 config_get addr "$vif" bssid
32 [ -z "$addr" ] || {
33 addr=$(echo "$addr" | tr 'A-F' 'a-f')
34 append wds "$addr"
35 }
36 ;;
37 monitor)
38 mon=1
39 mon_if="$vif"
40 ;;
41 *) echo "$device($vif): Invalid mode";;
42 esac
43 done
44 config_set "$device" wds "$wds"
45
46 local _c=
47 for vif in ${adhoc_if:-$sta_if $ap_if $mon_if}; do
48 config_set "$vif" ifname "${device}${_c:+.$_c}"
49 _c=$((${_c:-0} + 1))
50 done
51 config_set "$device" vifs "${adhoc_if:-$sta_if $ap_if $mon_if}"
52
53 ifdown="down"
54 for vif in 0 1 2 3; do
55 append ifdown "vif $vif" "$N"
56 append ifdown "enabled 0" "$N"
57 done
58
59 ap=1
60 infra=1
61 if [ "$_c" -gt 1 ]; then
62 mssid=1
63 else
64 mssid=
65 fi
66 apsta=0
67 radio=1
68 monitor=0
69 case "$adhoc:$sta:$apmode:$mon" in
70 1*)
71 ap=0
72 mssid=
73 infra=0
74 ;;
75 :1:1:)
76 apsta=1
77 wet=1
78 ;;
79 :1::)
80 wet=1
81 ap=0
82 mssid=
83 ;;
84 :::1)
85 wet=1
86 ap=0
87 mssid=
88 monitor=1
89 ;;
90 ::)
91 radio=0
92 ;;
93 esac
94 }
95
96 disable_broadcom() {
97 local device="$1"
98 set_wifi_down "$device"
99 wlc ifname "$device" down
100 wlc ifname "$device" bssid `wlc ifname "$device" default_bssid`
101 (
102 include /lib/network
103
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 && {
107 unbridge "$dev"
108 }
109 done
110 )
111 true
112 }
113
114 enable_broadcom() {
115 local device="$1"
116 local _c
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 local vif_pre_up vif_post_up vif_do_up vif_txpower
135 local doth=0
136 local wmm=1
137
138 _c=0
139 nas="$(which nas)"
140 nas_cmd=
141 if_up=
142
143 [ -z "$slottime" ] && {
144 [ -n "$distance" ] && {
145 # slottime = 9 + (distance / 150) + (distance % 150 ? 1 : 0)
146 slottime="$((9 + ($distance / 150) + 1 - (150 - ($distance % 150)) / 150 ))"
147 }
148 } || {
149 slottime="${slottime:--1}"
150 }
151
152 case "$macfilter" in
153 allow|2)
154 macfilter=2;
155 ;;
156 deny|1)
157 macfilter=1;
158 ;;
159 disable|none|0)
160 macfilter=0;
161 ;;
162 esac
163
164 case "$hwmode" in
165 *b) hwmode=0;;
166 *bg) hwmode=1;;
167 *g) hwmode=2;;
168 *gst) hwmode=4;;
169 *lrs) hwmode=5;;
170 *) hwmode=1;;
171 esac
172
173 for vif in $vifs; do
174 config_get vif_txpower "$vif" txpower
175
176 config_get mode "$vif" mode
177 append vif_pre_up "vif $_c" "$N"
178 append vif_post_up "vif $_c" "$N"
179 append vif_do_up "vif $_c" "$N"
180
181 config_get_bool wmm "$vif" wmm "$wmm"
182 config_get_bool doth "$vif" doth "$doth"
183
184 [ "$mode" = "sta" ] || {
185 config_get_bool hidden "$vif" hidden 0
186 append vif_pre_up "closed $hidden" "$N"
187 config_get_bool isolate "$vif" isolate 0
188 append vif_pre_up "ap_isolate $isolate" "$N"
189 }
190
191 wsec_r=0
192 eap_r=0
193 wsec=0
194 auth=0
195 nasopts=
196 config_get enc "$vif" encryption
197 case "$enc" in
198 *wep*)
199 wsec_r=1
200 wsec=1
201 defkey=1
202 config_get key "$vif" key
203 case "$enc" in
204 *shared*) append vif_do_up "wepauth 1" "$N";;
205 *) append vif_do_up "wepauth 0" "$N";;
206 esac
207 case "$key" in
208 [1234])
209 defkey="$key"
210 for knr in 1 2 3 4; do
211 config_get k "$vif" key$knr
212 [ -n "$k" ] || continue
213 [ "$defkey" = "$knr" ] && def="=" || def=""
214 append vif_do_up "wepkey $def$knr,$k" "$N"
215 done
216 ;;
217 "");;
218 *) append vif_do_up "wepkey =1,$key" "$N";;
219 esac
220 ;;
221 *psk*)
222 wsec_r=1
223 config_get key "$vif" key
224
225 # psk version + default cipher
226 case "$enc" in
227 *mixed*|*psk+psk2*) auth=132; wsec=6;;
228 *psk2*) auth=128; wsec=4;;
229 *) auth=4; wsec=2;;
230 esac
231
232 # cipher override
233 case "$enc" in
234 *tkip+aes*|*tkip+ccmp*|*aes+tkip*|*ccmp+tkip*) wsec=6;;
235 *aes*|*ccmp*) wsec=4;;
236 *tkip*) wsec=2;;
237 esac
238
239 # group rekey interval
240 config_get rekey "$vif" wpa_group_rekey
241
242 eval "${vif}_key=\"\$key\""
243 nasopts="-k \"\$${vif}_key\"${rekey:+ -g $rekey}"
244 ;;
245 *wpa*)
246 wsec_r=1
247 eap_r=1
248 config_get auth_server "$vif" auth_server
249 [ -z "$auth_server" ] && config_get auth_server "$vif" server
250 config_get auth_port "$vif" auth_port
251 [ -z "$auth_port" ] && config_get auth_port "$vif" port
252 config_get auth_secret "$vif" auth_secret
253 [ -z "$auth_secret" ] && config_get auth_secret "$vif" key
254
255 # wpa version + default cipher
256 case "$enc" in
257 *mixed*|*wpa+wpa2*) auth=66; wsec=6;;
258 *wpa2*) auth=64; wsec=4;;
259 *) auth=2; wsec=2;;
260 esac
261
262 # cipher override
263 case "$enc" in
264 *tkip+aes*|*tkip+ccmp*|*aes+tkip*|*ccmp+tkip*) wsec=6;;
265 *aes*|*ccmp*) wsec=4;;
266 *tkip*) wsec=2;;
267 esac
268
269 # group rekey interval
270 config_get rekey "$vif" wpa_group_rekey
271
272 eval "${vif}_key=\"\$auth_secret\""
273 nasopts="-r \"\$${vif}_key\" -h $auth_server -p ${auth_port:-1812}${rekey:+ -g $rekey}"
274 ;;
275 esac
276 append vif_do_up "wsec $wsec" "$N"
277 append vif_do_up "wpa_auth $auth" "$N"
278 append vif_do_up "wsec_restrict $wsec_r" "$N"
279 append vif_do_up "eap_restrict $eap_r" "$N"
280
281 config_get ssid "$vif" ssid
282 append vif_post_up "vlan_mode 0" "$N"
283 append vif_post_up "ssid $ssid" "$N"
284 append vif_do_up "ssid $ssid" "$N"
285
286 [ "$mode" = "monitor" ] && {
287 append vif_post_up "monitor $monitor" "$N"
288 }
289
290 [ "$mode" = "adhoc" ] && {
291 config_get bssid "$vif" bssid
292 [ -n "$bssid" ] && {
293 append vif_pre_up "bssid $bssid" "$N"
294 append vif_pre_up "ibss_merge 0" "$N"
295 } || {
296 append vif_pre_up "ibss_merge 1" "$N"
297 }
298 }
299
300 append vif_post_up "enabled 1" "$N"
301
302 config_get ifname "$vif" ifname
303 #append if_up "ifconfig $ifname up" ";$N"
304
305 local net_cfg
306 net_cfg="$(find_net_config "$vif")"
307 [ -z "$net_cfg" ] || {
308 append if_up "set_wifi_up '$vif' '$ifname'" ";$N"
309 append if_up "start_net '$ifname' '$net_cfg'" ";$N"
310 }
311 [ -z "$nasopts" ] || {
312 eval "${vif}_ssid=\"\$ssid\""
313 nas_mode="-A"
314 [ "$mode" = "sta" ] && nas_mode="-S"
315 [ -z "$nas" ] || {
316 nas_cmd="${nas_cmd:+$nas_cmd$N}start-stop-daemon -S -b -p /var/run/nas.$ifname.pid -x $nas -- -P /var/run/nas.$ifname.pid -H 34954 -i $ifname $nas_mode -m $auth -w $wsec -s \"\$${vif}_ssid\" -g 3600 -F $nasopts"
317 }
318 }
319 _c=$(($_c + 1))
320 done
321 killall -KILL nas >&- 2>&-
322 wlc ifname "$device" stdin <<EOF
323 $ifdown
324
325 gmode ${hwmode:-1}
326 apsta $apsta
327 ap $ap
328 ${mssid:+mssid $mssid}
329 infra $infra
330 ${wet:+wet 1}
331 802.11d 0
332 802.11h ${doth:-0}
333 wme ${wmm:-1}
334 rxant ${rxantenna:-3}
335 txant ${txantenna:-3}
336 fragthresh ${frag:-2346}
337 rtsthresh ${rts:-2347}
338 monitor ${monitor:-0}
339
340 radio ${radio:-1}
341 macfilter ${macfilter:-0}
342 maclist ${maclist:-none}
343 wds none
344 ${wds:+wds $wds}
345 country ${country:-US}
346 ${channel:+channel $channel}
347 maxassoc ${maxassoc:-128}
348 slottime ${slottime:--1}
349 ${frameburst:+frameburst $frameburst}
350
351 $vif_pre_up
352 up
353 $vif_post_up
354 EOF
355 eval "$if_up"
356 wlc ifname "$device" stdin <<EOF
357 $vif_do_up
358 EOF
359
360 # use vif_txpower (from last wifi-iface) instead of txpower (from
361 # wifi-device) if the latter does not exist
362 txpower=${txpower:-$vif_txpower}
363 [ -z "$txpower" ] || iwconfig $device txpower ${txpower}dBm
364
365 eval "$nas_cmd"
366 }
367
368
369 detect_broadcom() {
370 local i=-1
371
372 while grep -qs "^ *wl$((++i)):" /proc/net/dev; do
373 config_get type wl${i} type
374 [ "$type" = broadcom ] && continue
375 cat <<EOF
376 config wifi-device wl${i}
377 option type broadcom
378 option channel 11
379
380 # REMOVE THIS LINE TO ENABLE WIFI:
381 option disabled 1
382
383 config wifi-iface
384 option device wl${i}
385 option network lan
386 option mode ap
387 option ssid OpenWrt${i#0}
388 option encryption none
389
390 EOF
391 done
392 }
This page took 0.071349 seconds and 5 git commands to generate.