cb35ef1f78c8d66d618b62845a67a111b9121c1b
[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
7 local adhoc_if sta_if ap_if
8 local macfilter
9
10 config_get vifs "$device" vifs
11 for vif in $vifs; do
12 config_get mode "$vif" mode
13 case "$mode" in
14 adhoc)
15 adhoc=1
16 adhoc_if="$vif"
17 ;;
18 sta)
19 sta=1
20 sta_if="$vif"
21 ;;
22 ap)
23 apmode=1
24 ap_if="${ap_if:+$ap_if }$vif"
25 ;;
26 wds)
27 config_get addr "$vif" bssid
28 [ -z "$addr" ] || append wds "$addr"
29 ;;
30 *) echo "$device($vif): Invalid mode";;
31 esac
32 done
33 config_set "$device" wds "$wds"
34
35 local _c=
36 for vif in ${adhoc_if:-$sta_if $ap_if}; do
37 config_set "$vif" ifname "wl0${_c:+.$_c}"
38 _c=$((${_c:-0} + 1))
39 done
40 config_set "$device" vifs "${adhoc_if:-$sta_if $ap_if}"
41
42 ifdown="down"
43 for vif in 0 1 2 3; do
44 append ifdown "vif $vif" "$N"
45 append ifdown "enabled 0" "$N"
46 done
47
48 ap=1
49 infra=1
50 mssid=1
51 apsta=0
52 radio=1
53 case "$adhoc:$sta:$apmode" in
54 1*)
55 ap=0
56 mssid=0
57 infra=0
58 ;;
59 :1:1)
60 apsta=1
61 wet=1
62 ;;
63 :1:)
64 wet=1
65 ap=0
66 mssid=0
67 ;;
68 ::)
69 radio=0
70 ;;
71 esac
72 macfilter=0
73 case "$macfilter" in
74 allow|2)
75 macfilter=allow;
76 ;;
77 deny|1)
78 macfilter=deny;
79 ;;
80 disable|0)
81 macfilter=disabled;
82 ;;
83 esac
84 }
85
86 disable_broadcom() {
87 set_wifi_down "$1"
88 wlc down
89 (
90 include /lib/network
91
92 # make sure the interfaces are down and removed from all bridges
93 for dev in wl0 wl0.1 wl0.2 wl0.3; do
94 ifconfig "$dev" down 2>/dev/null >/dev/null && {
95 unbridge "$dev"
96 }
97 done
98 )
99 true
100 }
101
102 enable_broadcom() {
103 local _c
104 config_get channel "$device" channel
105 config_get country "$device" country
106 config_get maxassoc "$device" maxassoc
107 config_get wds "$device" wds
108 config_get vifs "$device" vifs
109 config_get distance "$device" distance
110 config_get slottime "$device" slottime
111 config_get rxant "$device" rxant
112 config_get txant "$device" txant
113 config_get macfilter "$device" macfilter
114 config_get maclist "$device" maclist
115 local vif_pre_up vif_post_up vif_do_up
116
117 _c=0
118 nas="$(which nas)"
119 nas_cmd=
120 if_up=
121
122 [ -z "$slottime" ] && {
123 [ -n "$distance" ] && {
124 # slottime = 9 + (distance / 150) + (distance % 150 ? 1 : 0)
125 slottime="$((9 + ($distance / 150) + 1 - (150 - ($distance % 150)) / 150 ))"
126 }
127 } || {
128 slottime="${slottime:--1}"
129 }
130
131 for vif in $vifs; do
132 config_get mode "$vif" mode
133 append vif_pre_up "vif $_c" "$N"
134 append vif_post_up "vif $_c" "$N"
135
136 [ "$mode" = "sta" ] || {
137 config_get_bool hidden "$vif" hidden 0
138 append vif_pre_up "closed $hidden" "$N"
139 config_get_bool isolate "$vif" isolate 0
140 append vif_pre_up "ap_isolate $isolate" "$N"
141 }
142
143 wsec_r=0
144 eap_r=0
145 wsec=0
146 auth=0
147 nasopts=
148 config_get enc "$vif" encryption
149 case "$enc" in
150 WEP|wep)
151 wsec_r=1
152 wsec=1
153 defkey=1
154 config_get key "$vif" key
155 case "$key" in
156 [1234])
157 defkey="$key"
158 for knr in 1 2 3 4; do
159 config_get k "$vif" key$knr
160 [ -n "$k" ] || continue
161 [ "$defkey" = "$knr" ] && def="=" || def=""
162 append vif_pre_up "wepkey $def$knr,$k" "$N"
163 done
164 ;;
165 "");;
166 *) append vif_pre_up "wepkey =1,$key" "$N";;
167 esac
168 ;;
169 *psk*|*PSK*)
170 wsec_r=1
171 config_get key "$vif" key
172 case "$enc" in
173 wpa*+wpa2*|WPA*+WPA2*|*psk+*psk2|*PSK+*PSK2) auth=132; wsec=6;;
174 wpa2*|WPA2*|*PSK2|*psk2) auth=128; wsec=4;;
175 *) auth=4; wsec=2;;
176 esac
177 eval "${vif}_key=\"\$key\""
178 nasopts="-k \"\$${vif}_key\""
179 ;;
180 *wpa*|*WPA*)
181 wsec_r=1
182 eap_r=1
183 config_get key "$vif" key
184 config_get server "$vif" server
185 config_get port "$vif" port
186 case "$enc" in
187 wpa*+wpa2*|WPA*+WPA2*) auth=66; wsec=6;;
188 wpa2*|WPA2*) auth=64; wsec=4;;
189 *) auth=2; wsec=2;;
190 esac
191 eval "${vif}_key=\"\$key\""
192 nasopts="-r \"\$${vif}_key\" -h $server -p $port"
193 ;;
194 esac
195 append vif_post_up "wsec $wsec" "$N"
196 append vif_post_up "wpa_auth $auth" "$N"
197 append vif_post_up "wsec_restrict $wsec_r" "$N"
198 append vif_post_up "eap_restrict $eap_r" "$N"
199
200 config_get ssid "$vif" ssid
201 append vif_post_up "vlan_mode 0" "$N"
202 append vif_post_up "ssid $ssid" "$N"
203 case "$mode" in
204 sta|adhoc) append vif_do_up "ssid $ssid" "$N";;
205 esac
206
207 append vif_post_up "enabled 1" "$N"
208
209 config_get ifname "$vif" ifname
210 #append if_up "ifconfig $ifname up" ";$N"
211 local net_cfg bridge
212 net_cfg="$(find_net_config "$vif")"
213 [ -z "$net_cfg" ] || {
214 bridge="$(bridge_interface "$net_cfg")"
215 append if_up "start_net '$ifname' '$net_cfg'" ";$N"
216 append if_up "set_wifi_up '$vif' '$ifname'" ";$N"
217 }
218 [ -z "$nasopts" ] || {
219 eval "${vif}_ssid=\"\$ssid\""
220 nas_mode="-A"
221 use_nas=1
222 [ "$mode" = "sta" ] && {
223 nas_mode="-S"
224 [ -z "$bridge" ] || {
225 append vif_pre_up "supplicant 1" "$N"
226 append vif_pre_up "passphrase $key" "$N"
227
228 use_nas=0
229 }
230 }
231 [ -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 &"
232 }
233 _c=$(($_c + 1))
234 done
235 killall -KILL nas >&- 2>&-
236 wlc stdin <<EOF
237 $ifdown
238
239 ap $ap
240 mssid $mssid
241 apsta $apsta
242 infra $infra
243 ${wet:+wet 1}
244 802.11d 0
245 802.11h 0
246 rxant ${rxant:-3}
247 txant ${txant:-3}
248
249 radio ${radio:-1}
250 macfilter ${macfilter:-disabled}
251 maclist ${maclist:-none}
252 wds none
253 ${wds:+wds $wds}
254 ${channel:+channel $channel}
255 country ${country:-IL0}
256 maxassoc ${maxassoc:-128}
257 slottime ${slottime:--1}
258
259 $vif_pre_up
260 up
261 $vif_post_up
262 EOF
263 eval "$if_up"
264 wlc stdin <<EOF
265 $vif_do_up
266 EOF
267 eval "$nas_cmd"
268 }
269
270
271 detect_broadcom() {
272 [ -f /proc/net/wl0 ] || return
273 config_get type wl0 type
274 [ "$type" = broadcom ] && return
275 cat <<EOF
276 config wifi-device wl0
277 option type broadcom
278 option channel 5
279
280 # REMOVE THIS LINE TO ENABLE WIFI:
281 option disabled 1
282
283 config wifi-iface
284 option device wl0
285 option network lan
286 option mode ap
287 option ssid OpenWrt
288 option encryption none
289 EOF
290 }
This page took 0.102719 seconds and 3 git commands to generate.