ar71xx: fix AR934X clock frequency calculation
[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=0
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 key "$vif" key
249 config_get server "$vif" server
250 config_get port "$vif" port
251
252 # wpa version + default cipher
253 case "$enc" in
254 *mixed*|*wpa+wpa2*) auth=66; wsec=6;;
255 *wpa2*) auth=64; wsec=4;;
256 *) auth=2; wsec=2;;
257 esac
258
259 # cipher override
260 case "$enc" in
261 *tkip+aes*|*tkip+ccmp*|*aes+tkip*|*ccmp+tkip*) wsec=6;;
262 *aes*|*ccmp*) wsec=4;;
263 *tkip*) wsec=2;;
264 esac
265
266 # group rekey interval
267 config_get rekey "$vif" wpa_group_rekey
268
269 eval "${vif}_key=\"\$key\""
270 nasopts="-r \"\$${vif}_key\" -h $server -p ${port:-1812}${rekey:+ -g $rekey}"
271 ;;
272 esac
273 append vif_do_up "wsec $wsec" "$N"
274 append vif_do_up "wpa_auth $auth" "$N"
275 append vif_do_up "wsec_restrict $wsec_r" "$N"
276 append vif_do_up "eap_restrict $eap_r" "$N"
277
278 config_get ssid "$vif" ssid
279 append vif_post_up "vlan_mode 0" "$N"
280 append vif_post_up "ssid $ssid" "$N"
281 append vif_do_up "ssid $ssid" "$N"
282
283 [ "$mode" = "monitor" ] && {
284 append vif_post_up "monitor $monitor" "$N"
285 }
286
287 [ "$mode" = "adhoc" ] && {
288 config_get bssid "$vif" bssid
289 [ -n "$bssid" ] && {
290 append vif_pre_up "bssid $bssid" "$N"
291 append vif_pre_up "ibss_merge 0" "$N"
292 } || {
293 append vif_pre_up "ibss_merge 1" "$N"
294 }
295 }
296
297 append vif_post_up "enabled 1" "$N"
298
299 config_get ifname "$vif" ifname
300 #append if_up "ifconfig $ifname up" ";$N"
301
302 local net_cfg
303 net_cfg="$(find_net_config "$vif")"
304 [ -z "$net_cfg" ] || {
305 append if_up "set_wifi_up '$vif' '$ifname'" ";$N"
306 append if_up "start_net '$ifname' '$net_cfg'" ";$N"
307 }
308 [ -z "$nasopts" ] || {
309 eval "${vif}_ssid=\"\$ssid\""
310 nas_mode="-A"
311 [ "$mode" = "sta" ] && nas_mode="-S"
312 [ -z "$nas" ] || {
313 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"
314 }
315 }
316 _c=$(($_c + 1))
317 done
318 killall -KILL nas >&- 2>&-
319 wlc ifname "$device" stdin <<EOF
320 $ifdown
321
322 gmode ${hwmode:-1}
323 apsta $apsta
324 ap $ap
325 ${mssid:+mssid $mssid}
326 infra $infra
327 ${wet:+wet 1}
328 802.11d 0
329 802.11h ${doth:-0}
330 wme ${wmm:-0}
331 rxant ${rxantenna:-3}
332 txant ${txantenna:-3}
333 fragthresh ${frag:-2346}
334 rtsthresh ${rts:-2347}
335 monitor ${monitor:-0}
336
337 radio ${radio:-1}
338 macfilter ${macfilter:-0}
339 maclist ${maclist:-none}
340 wds none
341 ${wds:+wds $wds}
342 country ${country:-US}
343 ${channel:+channel $channel}
344 maxassoc ${maxassoc:-128}
345 slottime ${slottime:--1}
346 ${frameburst:+frameburst $frameburst}
347
348 $vif_pre_up
349 up
350 $vif_post_up
351 EOF
352 eval "$if_up"
353 wlc ifname "$device" stdin <<EOF
354 $vif_do_up
355 EOF
356
357 # use vif_txpower (from last wifi-iface) instead of txpower (from
358 # wifi-device) if the latter does not exist
359 txpower=${txpower:-$vif_txpower}
360 [ -z "$txpower" ] || iwconfig $device txpower ${txpower}dBm
361
362 eval "$nas_cmd"
363 }
364
365
366 detect_broadcom() {
367 local i=-1
368
369 while grep -qs "^ *wl$((++i)):" /proc/net/dev; do
370 config_get type wl${i} type
371 [ "$type" = broadcom ] && continue
372 cat <<EOF
373 config wifi-device wl${i}
374 option type broadcom
375 option channel 11
376
377 # REMOVE THIS LINE TO ENABLE WIFI:
378 option disabled 1
379
380 config wifi-iface
381 option device wl${i}
382 option network lan
383 option mode ap
384 option ssid OpenWrt${i#0}
385 option encryption none
386
387 EOF
388 done
389 }
This page took 0.068075 seconds and 5 git commands to generate.