always return true in disable_broadcom()
[openwrt.git] / package / broadcom-wl / files / lib / wifi / broadcom.sh
1 append DRIVERS "broadcom"
2
3 find_vif_config() {(
4 local vif="$1"
5 local cfg
6 local ifname
7
8 config_get cfg "$vif" network
9
10 [ -z "$cfg" ] && {
11 include /lib/network
12 scan_interfaces
13
14 config_get ifname "$vif" ifnamea
15
16 cfg="$(find_config "$ifname")"
17 }
18 [ -z "$cfg" ] && return 0
19 echo "$cfg"
20 )}
21
22 bridge_interface() {(
23 local cfg="$1"
24 [ -z "$cfg" ] && return 0
25
26 include /lib/network
27 scan_interfaces
28
29 config_get iftype "$cfg" type
30 [ "$iftype" = bridge ] && config_get "$iftype" ifname
31 )}
32
33 scan_broadcom() {
34 local device="$1"
35
36 config_get vifs "$device" vifs
37 for vif in $vifs; do
38 config_get mode "$vif" mode
39 case "$mode" in
40 adhoc)
41 adhoc=1
42 adhoc_if="$vif"
43 ;;
44 sta)
45 sta=1
46 sta_if="$vif"
47 ;;
48 ap)
49 ap=1
50 ap_if="${ap_if:+$ap_if }$vif"
51 ;;
52 *) echo "$device($vif): Invalid mode";;
53 esac
54 done
55
56 local _c=
57 for vif in ${adhoc_if:-$sta_if $ap_if}; do
58 config_set "$vif" ifname "wl0${_c:+.$_c}"
59 _c=$((${_c:-0} + 1))
60 done
61
62 ifdown="down"
63 for vif in 0 1 2 3; do
64 append ifdown "vif $vif" "$N"
65 append ifdown "enabled 0" "$N"
66 done
67
68 ap=1
69 infra=1
70 mssid=1
71 apsta=0
72 radio=1
73 case "$adhoc:$sta:$ap" in
74 1*)
75 ap=0
76 mssid=0
77 infra=0
78 ;;
79 :1:1)
80 apsta=1
81 wet=1
82 ;;
83 :1:)
84 wet=1
85 ap=0
86 mssid=0
87 ;;
88 ::)
89 radio=0
90 ;;
91 esac
92 }
93
94 disable_broadcom() {
95 wlc down
96 (
97 include /lib/network
98
99 # make sure the interfaces are down and removed from all bridges
100 for dev in wl0 wl0.1 wl0.2 wl0.3; do
101 ifconfig "$dev" down 2>/dev/null >/dev/null && {
102 unbridge "$dev"
103 }
104 done
105 )
106 true
107 }
108
109 enable_broadcom() {
110 local _c
111 config_get channel "$device" channel
112 config_get country "$device" country
113 config_get maxassoc "$device" maxassoc
114
115 _c=0
116 nas="$(which nas)"
117 nas_cmd=
118 if_up=
119 for vif in ${adhoc_if:-$sta_if $ap_if}; do
120 append vif_pre_up "vif $_c" "$N"
121 append vif_post_up "vif $_c" "$N"
122
123 [ "$vif" = "$sta_if" ] || {
124 config_get_bool hidden "$vif" hidden 1
125 append vif_pre_up "closed $hidden" "$N"
126 config_get_bool isolate "$vif" isolate
127 append vif_pre_up "ap_isolate $hidden" "$N"
128 }
129
130 wsec_r=0
131 eap_r=0
132 wsec=0
133 auth=0
134 nasopts=
135 config_get enc "$vif" encryption
136 case "$enc" in
137 WEP|wep)
138 wsec_r=1
139 ;;
140 *psk*|*PSK*)
141 wsec_r=1
142 config_get key "$vif" key
143 case "$enc" in
144 wpa2*|WPA2*|PSK2*|psk2*) auth=128; wsec=4;;
145 *) auth=4; crypto=2;;
146 esac
147 eval "${vif}_key=\"\$key\""
148 nasopts="-k \"\$${vif}_key\""
149 ;;
150 *wpa*|*WPA*)
151 wsec_r=1
152 eap_r=1
153 config_get key "$vif" key
154 config_get server "$vif" server
155 config_get port "$vif" port
156 case "$enc" in
157 wpa2*|WPA2*) auth=64; wsec=4;;
158 *) auth=2; crypto=2;;
159 esac
160 eval "${vif}_key=\"\$key\""
161 nasopts="-r \"\$${vif}_key\" -h $server -p $port"
162 ;;
163 esac
164 append vif_post_up "wsec $wsec" "$N"
165 append vif_post_up "wpa_auth $auth" "$N"
166 append vif_post_up "wsec_restrict $wsec_r" "$N"
167 append vif_post_up "eap_restrict $eap_r" "$N"
168
169 config_get ssid "$vif" ssid
170 append vif_post_up "vlan_mode 0"
171 append vif_post_up "ssid $ssid" "$N"
172 append vif_post_up "enabled 1" "$N"
173
174 config_get ifname "$vif" ifname
175 append if_up "ifconfig $ifname up" ";$N"
176 net_cfg="$(find_vif_config "$vif")"
177 [ -z "$net_cfg" ] || {
178 bridge="$(bridge_interface "$net_cfg")"
179 append if_up "start_net '$ifname' '$net_cfg'" ";$N"
180 }
181 [ -z "$nasopts" ] || {
182 eval "${vif}_ssid=\"\$ssid\""
183 mode="-A"
184 [ "$vif" = "$sta_if" ] && mode="-S"
185 [ -z "$nas" ] || nas_cmd="${nas_cmd:+$nas_cmd$N}$nas -P /var/run/nas.$ifname.pid -H 34954 ${bridge:+ -l $bridge} -i $ifname $mode -m $auth -w $crypto -s \"\$${vif}_ssid\" -g 3600 $nasopts &"
186 }
187 _c=$(($_c + 1))
188 done
189 killall -KILL nas >&- 2>&-
190 wlc stdin <<EOF
191 $ifdown
192
193 mssid $mssid
194 ap $ap
195 apsta $apsta
196 infra $infra
197 ${wet:+wet 1}
198
199 radio ${radio:-1}
200 macfilter 0
201 maclist none
202 wds none
203 channel ${channel:-0}
204 country ${country:-IL0}
205 maxassoc ${maxassoc:-128}
206
207 $vif_pre_up
208 up
209 $vif_post_up
210 EOF
211 eval "$if_up"
212 eval "$nas_cmd"
213 }
214
215
216 detect_broadcom() {
217 [ -f /proc/net/wl0 ] || return
218 config_get type wl0 type
219 [ "$type" = broadcom ] && return
220 cat <<EOF
221 config wifi-device wl0
222 option type broadcom
223 option channel 5
224
225 config wifi-iface
226 option device wl0
227 option mode ap
228 option ssid OpenWrt
229 option hidden 0
230 option encryption none
231
232 EOF
233 }
This page took 0.04972 seconds and 5 git commands to generate.