[package] [docs] implement doth (802.11h) and wmm (802.11e) options for broadcom...
[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 "wl0${_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 passive=0
67 case "$adhoc:$sta:$apmode:$mon" in
68 1*)
69 ap=0
70 mssid=
71 infra=0
72 ;;
73 :1:1:)
74 apsta=1
75 wet=1
76 ;;
77 :1::)
78 wet=1
79 ap=0
80 mssid=
81 ;;
82 :::1)
83 wet=1
84 ap=0
85 mssid=
86 monitor=1
87 passive=1
88 ;;
89 ::)
90 radio=0
91 ;;
92 esac
93 }
94
95 disable_broadcom() {
96 set_wifi_down "$1"
97 wlc down
98 (
99 include /lib/network
100
101 # make sure the interfaces are down and removed from all bridges
102 for dev in wl0 wl0.1 wl0.2 wl0.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 _c
113 config_get channel "$device" channel
114 config_get country "$device" country
115 config_get maxassoc "$device" maxassoc
116 config_get wds "$device" wds
117 config_get vifs "$device" vifs
118 config_get distance "$device" distance
119 config_get slottime "$device" slottime
120 config_get rxantenna "$device" rxantenna
121 config_get txantenna "$device" txantenna
122 config_get_bool frameburst "$device" frameburst
123 config_get macfilter "$device" macfilter
124 config_get maclist "$device" maclist
125 config_get macaddr "$device" macaddr
126 config_get txpower "$device" txpower
127 local vif_pre_up vif_post_up vif_do_up vif_txpower
128 local doth=0
129 local wmm=0
130
131 _c=0
132 nas="$(which nas)"
133 nas_cmd=
134 if_up=
135
136 [ -z "$slottime" ] && {
137 [ -n "$distance" ] && {
138 # slottime = 9 + (distance / 150) + (distance % 150 ? 1 : 0)
139 slottime="$((9 + ($distance / 150) + 1 - (150 - ($distance % 150)) / 150 ))"
140 }
141 } || {
142 slottime="${slottime:--1}"
143 }
144
145 case "$macfilter" in
146 allow|2)
147 macfilter=2;
148 ;;
149 deny|1)
150 macfilter=1;
151 ;;
152 disable|none|0)
153 macfilter=0;
154 ;;
155 esac
156
157 for vif in $vifs; do
158 config_get vif_txpower "$vif" txpower
159
160 config_get mode "$vif" mode
161 append vif_pre_up "vif $_c" "$N"
162 append vif_post_up "vif $_c" "$N"
163 append vif_do_up "vif $_c" "$N"
164
165 config_get_bool wmm "$vif" wmm "$wmm"
166 config_get_bool doth "$vif" doth "$doth"
167
168 [ "$mode" = "sta" ] || {
169 config_get_bool hidden "$vif" hidden 0
170 append vif_pre_up "closed $hidden" "$N"
171 config_get_bool isolate "$vif" isolate 0
172 append vif_pre_up "ap_isolate $isolate" "$N"
173 }
174
175 wsec_r=0
176 eap_r=0
177 wsec=0
178 auth=0
179 nasopts=
180 config_get enc "$vif" encryption
181 case "$enc" in
182 WEP|wep)
183 wsec_r=1
184 wsec=1
185 defkey=1
186 config_get key "$vif" key
187 case "$key" in
188 [1234])
189 defkey="$key"
190 for knr in 1 2 3 4; do
191 config_get k "$vif" key$knr
192 [ -n "$k" ] || continue
193 [ "$defkey" = "$knr" ] && def="=" || def=""
194 append vif_do_up "wepkey $def$knr,$k" "$N"
195 done
196 ;;
197 "");;
198 *) append vif_do_up "wepkey =1,$key" "$N";;
199 esac
200 ;;
201 *psk*|*PSK*)
202 wsec_r=1
203 config_get key "$vif" key
204 case "$enc" in
205 wpa*+wpa2*|WPA*+WPA2*|*psk+*psk2|*PSK+*PSK2) auth=132; wsec=6;;
206 wpa2*|WPA2*|*PSK2|*psk2) auth=128; wsec=4;;
207 *aes|*AES) auth=4; wsec=4;;
208 *) auth=4; wsec=2;;
209 esac
210 eval "${vif}_key=\"\$key\""
211 nasopts="-k \"\$${vif}_key\""
212 ;;
213 *wpa*|*WPA*)
214 wsec_r=1
215 eap_r=1
216 config_get key "$vif" key
217 config_get server "$vif" server
218 config_get port "$vif" port
219 case "$enc" in
220 wpa*+wpa2*|WPA*+WPA2*) auth=66; wsec=6;;
221 wpa2*|WPA2*) auth=64; wsec=4;;
222 *) auth=2; wsec=2;;
223 esac
224 eval "${vif}_key=\"\$key\""
225 nasopts="-r \"\$${vif}_key\" -h $server -p ${port:-1812}"
226 ;;
227 esac
228 append vif_do_up "wsec $wsec" "$N"
229 append vif_do_up "wpa_auth $auth" "$N"
230 append vif_do_up "wsec_restrict $wsec_r" "$N"
231 append vif_do_up "eap_restrict $eap_r" "$N"
232
233 config_get ssid "$vif" ssid
234 append vif_post_up "vlan_mode 0" "$N"
235 append vif_post_up "ssid $ssid" "$N"
236 append vif_do_up "ssid $ssid" "$N"
237
238 [ "$mode" = "monitor" ] && {
239 append vif_post_up "monitor $monitor" "$N"
240 append vif_post_up "passive $passive" "$N"
241 }
242
243 [ "$mode" = "adhoc" ] && {
244 config_get bssid "$vif" bssid
245 [ -n "$bssid" ] && {
246 append vif_pre_up "des_bssid $bssid" "$N"
247 append vif_pre_up "allow_mode 1" "$N"
248 }
249 } || append vif_pre_up "allow_mode 0" "$N"
250
251 append vif_post_up "enabled 1" "$N"
252
253 config_get ifname "$vif" ifname
254 #append if_up "ifconfig $ifname up" ";$N"
255
256 local net_cfg bridge
257 net_cfg="$(find_net_config "$vif")"
258 [ -z "$net_cfg" ] || {
259 bridge="$(bridge_interface "$net_cfg")"
260 append if_up "set_wifi_up '$vif' '$ifname'" ";$N"
261 append if_up "start_net '$ifname' '$net_cfg' \$(wlc ifname '$ifname' bssid)" ";$N"
262 }
263 [ -z "$nasopts" ] || {
264 eval "${vif}_ssid=\"\$ssid\""
265 nas_mode="-A"
266 use_nas=1
267 [ "$mode" = "sta" ] && {
268 nas_mode="-S"
269 [ -z "$bridge" ] || {
270 append vif_post_up "supplicant 1" "$N"
271 append vif_post_up "passphrase $key" "$N"
272
273 use_nas=0
274 }
275 }
276 [ -z "$nas" -o "$use_nas" = "0" ] || nas_cmd="${nas_cmd:+$nas_cmd$N}$nas -P /var/run/nas.$ifname.pid -H 34954 ${bridge:+ -l $bridge} -i $ifname $nas_mode -m $auth -w $wsec -s \"\$${vif}_ssid\" -g 3600 $nasopts &"
277 }
278 _c=$(($_c + 1))
279 done
280 killall -KILL nas >&- 2>&-
281 wlc stdin <<EOF
282 $ifdown
283
284 apsta $apsta
285 ap $ap
286 ${mssid:+mssid $mssid}
287 infra $infra
288 ${wet:+wet 1}
289 802.11d 0
290 802.11h ${doth:-0}
291 wme ${wmm:-0}
292 rxant ${rxantenna:-3}
293 txant ${txantenna:-3}
294 monitor ${monitor:-0}
295 passive ${passive:-0}
296
297 radio ${radio:-1}
298 macfilter ${macfilter:-0}
299 maclist ${maclist:-none}
300 wds none
301 ${wds:+wds $wds}
302 country ${country:-IL0}
303 ${channel:+channel $channel}
304 maxassoc ${maxassoc:-128}
305 slottime ${slottime:--1}
306 ${frameburst:+frameburst $frameburst}
307
308 $vif_pre_up
309 up
310 $vif_post_up
311 EOF
312 eval "$if_up"
313 wlc stdin <<EOF
314 $vif_do_up
315 EOF
316
317 # use vif_txpower (from last wifi-iface) instead of txpower (from
318 # wifi-device) if the latter does not exist
319 txpower=${txpower:-$vif_txpower}
320 [ -z "$txpower" ] || iwconfig $device txpower ${txpower}dBm
321
322 eval "$nas_cmd"
323 }
324
325
326 detect_broadcom() {
327 [ -f /proc/net/wl0 ] || return
328 config_get type wl0 type
329 [ "$type" = broadcom ] && return
330 cat <<EOF
331 config wifi-device wl0
332 option type broadcom
333 option channel 5
334
335 # REMOVE THIS LINE TO ENABLE WIFI:
336 option disabled 1
337
338 config wifi-iface
339 option device wl0
340 option network lan
341 option mode ap
342 option ssid OpenWrt
343 option encryption none
344 EOF
345 }
This page took 0.06021 seconds and 5 git commands to generate.