implement network callbacks for broadcom wl
[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 }
107
108 enable_broadcom() {
109 local _c
110 config_get channel "$device" channel
111 config_get country "$device" country
112 config_get maxassoc "$device" maxassoc
113
114 _c=0
115 nas="$(which nas)"
116 nas_cmd=
117 if_up=
118 for vif in ${adhoc_if:-$sta_if $ap_if}; do
119 append vif_pre_up "vif $_c" "$N"
120 append vif_post_up "vif $_c" "$N"
121
122 [ "$vif" = "$sta_if" ] || {
123 config_get_bool hidden "$vif" hidden 1
124 append vif_pre_up "closed $hidden" "$N"
125 config_get_bool isolate "$vif" isolate
126 append vif_pre_up "ap_isolate $hidden" "$N"
127 }
128
129 wsec_r=0
130 eap_r=0
131 wsec=0
132 auth=0
133 nasopts=
134 config_get enc "$vif" encryption
135 case "$enc" in
136 WEP|wep)
137 wsec_r=1
138 ;;
139 *psk*|*PSK*)
140 wsec_r=1
141 config_get key "$vif" key
142 case "$enc" in
143 wpa2*|WPA2*|PSK2*|psk2*) auth=128; wsec=4;;
144 *) auth=4; crypto=2;;
145 esac
146 eval "${vif}_key=\"\$key\""
147 nasopts="-k \"\$${vif}_key\""
148 ;;
149 *wpa*|*WPA*)
150 wsec_r=1
151 eap_r=1
152 config_get key "$vif" key
153 config_get server "$vif" server
154 config_get port "$vif" port
155 case "$enc" in
156 wpa2*|WPA2*) auth=64; wsec=4;;
157 *) auth=2; crypto=2;;
158 esac
159 eval "${vif}_key=\"\$key\""
160 nasopts="-r \"\$${vif}_key\" -h $server -p $port"
161 ;;
162 esac
163 append vif_post_up "wsec $wsec" "$N"
164 append vif_post_up "wpa_auth $auth" "$N"
165 append vif_post_up "wsec_restrict $wsec_r" "$N"
166 append vif_post_up "eap_restrict $eap_r" "$N"
167
168 config_get ssid "$vif" ssid
169 append vif_post_up "vlan_mode 0"
170 append vif_post_up "ssid $ssid" "$N"
171 append vif_post_up "enabled 1" "$N"
172
173 config_get ifname "$vif" ifname
174 append if_up "ifconfig $ifname up" ";$N"
175 net_cfg="$(find_vif_config "$vif")"
176 [ -z "$net_cfg" ] || {
177 bridge="$(bridge_interface "$net_cfg")"
178 append if_up "start_net '$ifname' '$net_cfg'" ";$N"
179 }
180 [ -z "$nasopts" ] || {
181 eval "${vif}_ssid=\"\$ssid\""
182 mode="-A"
183 [ "$vif" = "$sta_if" ] && mode="-S"
184 [ -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 &"
185 }
186 _c=$(($_c + 1))
187 done
188 killall -KILL nas >&- 2>&-
189 wlc stdin <<EOF
190 $ifdown
191
192 mssid $mssid
193 ap $ap
194 apsta $apsta
195 infra $infra
196 ${wet:+wet 1}
197
198 radio ${radio:-1}
199 macfilter 0
200 maclist none
201 wds none
202 channel ${channel:-0}
203 country ${country:-IL0}
204 maxassoc ${maxassoc:-128}
205
206 $vif_pre_up
207 up
208 $vif_post_up
209 EOF
210 eval "$if_up"
211 eval "$nas_cmd"
212 }
213
214
215 detect_broadcom() {
216 [ -f /proc/net/wl0 ] || return
217 config_get type wl0 type
218 [ "$type" = broadcom ] && return
219 cat <<EOF
220 config wifi-device wl0
221 option type broadcom
222 option channel 5
223
224 config wifi-iface
225 option device wl0
226 option mode ap
227 option ssid OpenWrt
228 option hidden 0
229 option encryption none
230
231 EOF
232 }
This page took 0.050453 seconds and 5 git commands to generate.