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