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