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