OpenWrt – Blame information for rev 3
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | . /lib/functions/network.sh |
2 | |||
3 | wpa_supplicant_add_rate() { |
||
4 | local var="$1" |
||
5 | local val="$(($2 / 1000))" |
||
6 | local sub="$((($2 / 100) % 10))" |
||
7 | append $var "$val" "," |
||
8 | [ $sub -gt 0 ] && append $var "." |
||
9 | } |
||
10 | |||
11 | hostapd_add_rate() { |
||
12 | local var="$1" |
||
13 | local val="$(($2 / 100))" |
||
14 | append $var "$val" " " |
||
15 | } |
||
16 | |||
17 | hostapd_append_wep_key() { |
||
18 | local var="$1" |
||
19 | |||
20 | wep_keyidx=0 |
||
21 | set_default key 1 |
||
22 | case "$key" in |
||
23 | [1234]) |
||
24 | for idx in 1 2 3 4; do |
||
25 | local zidx |
||
26 | zidx=$(($idx - 1)) |
||
27 | json_get_var ckey "key${idx}" |
||
28 | [ -n "$ckey" ] && \ |
||
29 | append $var "wep_key${zidx}=$(prepare_key_wep "$ckey")" "$N$T" |
||
30 | done |
||
31 | wep_keyidx=$((key - 1)) |
||
32 | ;; |
||
33 | *) |
||
34 | append $var "wep_key0=$(prepare_key_wep "$key")" "$N$T" |
||
35 | ;; |
||
36 | esac |
||
37 | } |
||
38 | |||
39 | hostapd_append_wpa_key_mgmt() { |
||
3 | office | 40 | local auth_type="$(echo $auth_type | tr 'a-z' 'A-Z')" |
1 | office | 41 | |
3 | office | 42 | append wpa_key_mgmt "WPA-$auth_type" |
43 | [ "${ieee80211r:-0}" -gt 0 ] && append wpa_key_mgmt "FT-${auth_type}" |
||
44 | [ "${ieee80211w:-0}" -gt 0 ] && append wpa_key_mgmt "WPA-${auth_type}-SHA256" |
||
1 | office | 45 | } |
46 | |||
47 | hostapd_add_log_config() { |
||
48 | config_add_boolean \ |
||
49 | log_80211 \ |
||
50 | log_8021x \ |
||
51 | log_radius \ |
||
52 | log_wpa \ |
||
53 | log_driver \ |
||
54 | log_iapp \ |
||
55 | log_mlme |
||
56 | |||
57 | config_add_int log_level |
||
58 | } |
||
59 | |||
60 | hostapd_common_add_device_config() { |
||
61 | config_add_array basic_rate |
||
62 | config_add_array supported_rates |
||
63 | |||
64 | config_add_string country |
||
65 | config_add_boolean country_ie doth |
||
66 | config_add_string require_mode |
||
67 | config_add_boolean legacy_rates |
||
68 | |||
69 | config_add_string acs_chan_bias |
||
70 | config_add_array hostapd_options |
||
71 | |||
72 | hostapd_add_log_config |
||
73 | } |
||
74 | |||
75 | hostapd_prepare_device_config() { |
||
76 | local config="$1" |
||
77 | local driver="$2" |
||
78 | |||
79 | local base="${config%%.conf}" |
||
80 | local base_cfg= |
||
81 | |||
82 | json_get_vars country country_ie beacon_int:100 doth require_mode legacy_rates acs_chan_bias |
||
83 | |||
84 | hostapd_set_log_options base_cfg |
||
85 | |||
86 | set_default country_ie 1 |
||
87 | set_default doth 1 |
||
88 | set_default legacy_rates 1 |
||
89 | |||
90 | [ "$hwmode" = "b" ] && legacy_rates=1 |
||
91 | |||
92 | [ -n "$country" ] && { |
||
93 | append base_cfg "country_code=$country" "$N" |
||
94 | |||
95 | [ "$country_ie" -gt 0 ] && append base_cfg "ieee80211d=1" "$N" |
||
96 | [ "$hwmode" = "a" -a "$doth" -gt 0 ] && append base_cfg "ieee80211h=1" "$N" |
||
97 | } |
||
98 | |||
99 | [ -n "$acs_chan_bias" ] && append base_cfg "acs_chan_bias=$acs_chan_bias" "$N" |
||
100 | |||
101 | local brlist= br |
||
102 | json_get_values basic_rate_list basic_rate |
||
103 | local rlist= r |
||
104 | json_get_values rate_list supported_rates |
||
105 | |||
106 | [ -n "$hwmode" ] && append base_cfg "hw_mode=$hwmode" "$N" |
||
107 | [ "$legacy_rates" -eq 0 ] && set_default require_mode g |
||
108 | |||
109 | [ "$hwmode" = "g" ] && { |
||
110 | [ "$legacy_rates" -eq 0 ] && set_default rate_list "6000 9000 12000 18000 24000 36000 48000 54000" |
||
111 | [ -n "$require_mode" ] && set_default basic_rate_list "6000 12000 24000" |
||
112 | } |
||
113 | |||
114 | case "$require_mode" in |
||
115 | n) append base_cfg "require_ht=1" "$N";; |
||
116 | ac) append base_cfg "require_vht=1" "$N";; |
||
117 | esac |
||
118 | |||
119 | for r in $rate_list; do |
||
120 | hostapd_add_rate rlist "$r" |
||
121 | done |
||
122 | |||
123 | for br in $basic_rate_list; do |
||
124 | hostapd_add_rate brlist "$br" |
||
125 | done |
||
126 | |||
127 | [ -n "$rlist" ] && append base_cfg "supported_rates=$rlist" "$N" |
||
128 | [ -n "$brlist" ] && append base_cfg "basic_rates=$brlist" "$N" |
||
129 | append base_cfg "beacon_int=$beacon_int" "$N" |
||
130 | |||
131 | json_get_values opts hostapd_options |
||
132 | for val in $opts; do |
||
133 | append base_cfg "$val" "$N" |
||
134 | done |
||
135 | |||
136 | cat > "$config" <<EOF |
||
137 | driver=$driver |
||
138 | $base_cfg |
||
139 | EOF |
||
140 | } |
||
141 | |||
142 | hostapd_common_add_bss_config() { |
||
143 | config_add_string 'bssid:macaddr' 'ssid:string' |
||
3 | office | 144 | config_add_boolean wds wmm uapsd hidden |
1 | office | 145 | |
146 | config_add_int maxassoc max_inactivity |
||
147 | config_add_boolean disassoc_low_ack isolate short_preamble |
||
148 | |||
149 | config_add_int \ |
||
150 | wep_rekey eap_reauth_period \ |
||
151 | wpa_group_rekey wpa_pair_rekey wpa_master_rekey |
||
152 | config_add_boolean wpa_disable_eapol_key_retries |
||
153 | |||
154 | config_add_boolean tdls_prohibit |
||
155 | |||
156 | config_add_boolean rsn_preauth auth_cache |
||
157 | config_add_int ieee80211w |
||
158 | config_add_int eapol_version |
||
159 | |||
160 | config_add_string 'auth_server:host' 'server:host' |
||
161 | config_add_string auth_secret |
||
162 | config_add_int 'auth_port:port' 'port:port' |
||
163 | |||
164 | config_add_string acct_server |
||
165 | config_add_string acct_secret |
||
166 | config_add_int acct_port |
||
167 | config_add_int acct_interval |
||
168 | |||
169 | config_add_string dae_client |
||
170 | config_add_string dae_secret |
||
171 | config_add_int dae_port |
||
172 | |||
173 | config_add_string nasid |
||
174 | config_add_string ownip |
||
175 | config_add_string radius_client_addr |
||
176 | config_add_string iapp_interface |
||
177 | config_add_string eap_type ca_cert client_cert identity anonymous_identity auth priv_key priv_key_pwd |
||
178 | config_add_string ieee80211w_mgmt_cipher |
||
179 | |||
180 | config_add_int dynamic_vlan vlan_naming |
||
181 | config_add_string vlan_tagged_interface vlan_bridge |
||
182 | config_add_string vlan_file |
||
183 | |||
184 | config_add_string 'key1:wepkey' 'key2:wepkey' 'key3:wepkey' 'key4:wepkey' 'password:wpakey' |
||
185 | |||
186 | config_add_string wpa_psk_file |
||
187 | |||
188 | config_add_boolean wps_pushbutton wps_label ext_registrar wps_pbc_in_m1 |
||
189 | config_add_int wps_ap_setup_locked wps_independent |
||
190 | config_add_string wps_device_type wps_device_name wps_manufacturer wps_pin |
||
191 | |||
192 | config_add_boolean ieee80211v wnm_sleep_mode bss_transition |
||
193 | config_add_int time_advertisement |
||
194 | config_add_string time_zone |
||
195 | |||
196 | config_add_boolean ieee80211r pmk_r1_push ft_psk_generate_local ft_over_ds |
||
197 | config_add_int r0_key_lifetime reassociation_deadline |
||
198 | config_add_string mobility_domain r1_key_holder |
||
199 | config_add_array r0kh r1kh |
||
200 | |||
201 | config_add_int ieee80211w_max_timeout ieee80211w_retry_timeout |
||
202 | |||
203 | config_add_string macfilter 'macfile:file' |
||
204 | config_add_array 'maclist:list(macaddr)' |
||
205 | |||
206 | config_add_array bssid_blacklist |
||
207 | config_add_array bssid_whitelist |
||
208 | |||
209 | config_add_int mcast_rate |
||
210 | config_add_array basic_rate |
||
211 | config_add_array supported_rates |
||
212 | } |
||
213 | |||
214 | hostapd_set_bss_options() { |
||
215 | local var="$1" |
||
216 | local phy="$2" |
||
217 | local vif="$3" |
||
218 | |||
219 | wireless_vif_parse_encryption |
||
220 | |||
221 | local bss_conf |
||
222 | local wep_rekey wpa_group_rekey wpa_pair_rekey wpa_master_rekey wpa_key_mgmt |
||
223 | |||
224 | json_get_vars \ |
||
225 | wep_rekey wpa_group_rekey wpa_pair_rekey wpa_master_rekey \ |
||
226 | wpa_disable_eapol_key_retries tdls_prohibit \ |
||
227 | maxassoc max_inactivity disassoc_low_ack isolate auth_cache \ |
||
228 | wps_pushbutton wps_label ext_registrar wps_pbc_in_m1 wps_ap_setup_locked \ |
||
229 | wps_independent wps_device_type wps_device_name wps_manufacturer wps_pin \ |
||
3 | office | 230 | macfilter ssid wmm uapsd hidden short_preamble rsn_preauth \ |
1 | office | 231 | iapp_interface eapol_version dynamic_vlan ieee80211w nasid \ |
232 | acct_server acct_secret acct_port acct_interval \ |
||
3 | office | 233 | bss_load_update_period chan_util_avg_period |
1 | office | 234 | |
235 | set_default isolate 0 |
||
236 | set_default maxassoc 0 |
||
237 | set_default max_inactivity 0 |
||
238 | set_default short_preamble 1 |
||
239 | set_default disassoc_low_ack 1 |
||
240 | set_default hidden 0 |
||
241 | set_default wmm 1 |
||
242 | set_default uapsd 1 |
||
243 | set_default wpa_disable_eapol_key_retries 0 |
||
244 | set_default tdls_prohibit 0 |
||
245 | set_default eapol_version 0 |
||
246 | set_default acct_port 1813 |
||
247 | set_default bss_load_update_period 60 |
||
248 | set_default chan_util_avg_period 600 |
||
3 | office | 249 | |
1 | office | 250 | append bss_conf "ctrl_interface=/var/run/hostapd" |
251 | if [ "$isolate" -gt 0 ]; then |
||
252 | append bss_conf "ap_isolate=$isolate" "$N" |
||
253 | fi |
||
254 | if [ "$maxassoc" -gt 0 ]; then |
||
255 | append bss_conf "max_num_sta=$maxassoc" "$N" |
||
256 | fi |
||
257 | if [ "$max_inactivity" -gt 0 ]; then |
||
258 | append bss_conf "ap_max_inactivity=$max_inactivity" "$N" |
||
259 | fi |
||
260 | |||
261 | append bss_conf "bss_load_update_period=$bss_load_update_period" "$N" |
||
262 | append bss_conf "chan_util_avg_period=$chan_util_avg_period" "$N" |
||
263 | append bss_conf "disassoc_low_ack=$disassoc_low_ack" "$N" |
||
264 | append bss_conf "preamble=$short_preamble" "$N" |
||
265 | append bss_conf "wmm_enabled=$wmm" "$N" |
||
266 | append bss_conf "ignore_broadcast_ssid=$hidden" "$N" |
||
267 | append bss_conf "uapsd_advertisement_enabled=$uapsd" "$N" |
||
268 | |||
269 | [ "$tdls_prohibit" -gt 0 ] && append bss_conf "tdls_prohibit=$tdls_prohibit" "$N" |
||
270 | |||
271 | [ "$wpa" -gt 0 ] && { |
||
272 | [ -n "$wpa_group_rekey" ] && append bss_conf "wpa_group_rekey=$wpa_group_rekey" "$N" |
||
273 | [ -n "$wpa_pair_rekey" ] && append bss_conf "wpa_ptk_rekey=$wpa_pair_rekey" "$N" |
||
274 | [ -n "$wpa_master_rekey" ] && append bss_conf "wpa_gmk_rekey=$wpa_master_rekey" "$N" |
||
275 | } |
||
276 | |||
277 | [ -n "$nasid" ] && append bss_conf "nas_identifier=$nasid" "$N" |
||
278 | [ -n "$acct_server" ] && { |
||
279 | append bss_conf "acct_server_addr=$acct_server" "$N" |
||
280 | append bss_conf "acct_server_port=$acct_port" "$N" |
||
281 | [ -n "$acct_secret" ] && \ |
||
282 | append bss_conf "acct_server_shared_secret=$acct_secret" "$N" |
||
283 | [ -n "$acct_interval" ] && \ |
||
284 | append bss_conf "radius_acct_interim_interval=$acct_interval" "$N" |
||
285 | } |
||
286 | |||
287 | local vlan_possible="" |
||
288 | |||
289 | case "$auth_type" in |
||
3 | office | 290 | none) |
1 | office | 291 | wps_possible=1 |
292 | # Here we make the assumption that if we're in open mode |
||
293 | # with WPS enabled, we got to be in unconfigured state. |
||
294 | wps_not_configured=1 |
||
295 | ;; |
||
3 | office | 296 | psk) |
1 | office | 297 | json_get_vars key wpa_psk_file |
298 | if [ ${#key} -lt 8 ]; then |
||
299 | wireless_setup_vif_failed INVALID_WPA_PSK |
||
300 | return 1 |
||
301 | elif [ ${#key} -eq 64 ]; then |
||
302 | append bss_conf "wpa_psk=$key" "$N" |
||
303 | else |
||
304 | append bss_conf "wpa_passphrase=$key" "$N" |
||
305 | fi |
||
306 | [ -n "$wpa_psk_file" ] && { |
||
307 | [ -e "$wpa_psk_file" ] || touch "$wpa_psk_file" |
||
308 | append bss_conf "wpa_psk_file=$wpa_psk_file" "$N" |
||
309 | } |
||
310 | [ "$eapol_version" -ge "1" -a "$eapol_version" -le "2" ] && append bss_conf "eapol_version=$eapol_version" "$N" |
||
311 | |||
312 | wps_possible=1 |
||
313 | ;; |
||
3 | office | 314 | eap) |
1 | office | 315 | json_get_vars \ |
316 | auth_server auth_secret auth_port \ |
||
317 | dae_client dae_secret dae_port \ |
||
318 | ownip radius_client_addr \ |
||
319 | eap_reauth_period |
||
320 | |||
321 | # radius can provide VLAN ID for clients |
||
322 | vlan_possible=1 |
||
323 | |||
324 | # legacy compatibility |
||
325 | [ -n "$auth_server" ] || json_get_var auth_server server |
||
326 | [ -n "$auth_port" ] || json_get_var auth_port port |
||
327 | [ -n "$auth_secret" ] || json_get_var auth_secret key |
||
328 | |||
329 | set_default auth_port 1812 |
||
330 | set_default dae_port 3799 |
||
331 | |||
332 | |||
333 | append bss_conf "auth_server_addr=$auth_server" "$N" |
||
334 | append bss_conf "auth_server_port=$auth_port" "$N" |
||
335 | append bss_conf "auth_server_shared_secret=$auth_secret" "$N" |
||
336 | |||
337 | [ -n "$eap_reauth_period" ] && append bss_conf "eap_reauth_period=$eap_reauth_period" "$N" |
||
338 | |||
339 | [ -n "$dae_client" -a -n "$dae_secret" ] && { |
||
340 | append bss_conf "radius_das_port=$dae_port" "$N" |
||
341 | append bss_conf "radius_das_client=$dae_client $dae_secret" "$N" |
||
342 | } |
||
343 | |||
344 | [ -n "$ownip" ] && append bss_conf "own_ip_addr=$ownip" "$N" |
||
345 | [ -n "$radius_client_addr" ] && append bss_conf "radius_client_addr=$radius_client_addr" "$N" |
||
346 | append bss_conf "eapol_key_index_workaround=1" "$N" |
||
347 | append bss_conf "ieee8021x=1" "$N" |
||
348 | |||
349 | [ "$eapol_version" -ge "1" -a "$eapol_version" -le "2" ] && append bss_conf "eapol_version=$eapol_version" "$N" |
||
350 | ;; |
||
351 | wep) |
||
352 | local wep_keyidx=0 |
||
353 | json_get_vars key |
||
354 | hostapd_append_wep_key bss_conf |
||
355 | append bss_conf "wep_default_key=$wep_keyidx" "$N" |
||
356 | [ -n "$wep_rekey" ] && append bss_conf "wep_rekey_period=$wep_rekey" "$N" |
||
357 | ;; |
||
358 | esac |
||
359 | |||
360 | local auth_algs=$((($auth_mode_shared << 1) | $auth_mode_open)) |
||
361 | append bss_conf "auth_algs=${auth_algs:-1}" "$N" |
||
362 | append bss_conf "wpa=$wpa" "$N" |
||
363 | [ -n "$wpa_pairwise" ] && append bss_conf "wpa_pairwise=$wpa_pairwise" "$N" |
||
364 | |||
365 | set_default wps_pushbutton 0 |
||
366 | set_default wps_label 0 |
||
367 | set_default wps_pbc_in_m1 0 |
||
368 | |||
369 | config_methods= |
||
370 | [ "$wps_pushbutton" -gt 0 ] && append config_methods push_button |
||
371 | [ "$wps_label" -gt 0 ] && append config_methods label |
||
372 | |||
373 | [ -n "$wps_possible" -a -n "$config_methods" ] && { |
||
374 | set_default ext_registrar 0 |
||
375 | set_default wps_device_type "6-0050F204-1" |
||
376 | set_default wps_device_name "OpenWrt AP" |
||
377 | set_default wps_manufacturer "www.openwrt.org" |
||
378 | set_default wps_independent 1 |
||
379 | |||
380 | wps_state=2 |
||
381 | [ -n "$wps_configured" ] && wps_state=1 |
||
382 | |||
383 | [ "$ext_registrar" -gt 0 -a -n "$network_bridge" ] && append bss_conf "upnp_iface=$network_bridge" "$N" |
||
384 | |||
385 | append bss_conf "eap_server=1" "$N" |
||
386 | [ -n "$wps_pin" ] && append bss_conf "ap_pin=$wps_pin" "$N" |
||
387 | append bss_conf "wps_state=$wps_state" "$N" |
||
388 | append bss_conf "device_type=$wps_device_type" "$N" |
||
389 | append bss_conf "device_name=$wps_device_name" "$N" |
||
390 | append bss_conf "manufacturer=$wps_manufacturer" "$N" |
||
391 | append bss_conf "config_methods=$config_methods" "$N" |
||
392 | append bss_conf "wps_independent=$wps_independent" "$N" |
||
393 | [ -n "$wps_ap_setup_locked" ] && append bss_conf "ap_setup_locked=$wps_ap_setup_locked" "$N" |
||
394 | [ "$wps_pbc_in_m1" -gt 0 ] && append bss_conf "pbc_in_m1=$wps_pbc_in_m1" "$N" |
||
395 | } |
||
396 | |||
397 | append bss_conf "ssid=$ssid" "$N" |
||
398 | [ -n "$network_bridge" ] && append bss_conf "bridge=$network_bridge" "$N" |
||
399 | [ -n "$iapp_interface" ] && { |
||
400 | local ifname |
||
401 | network_get_device ifname "$iapp_interface" || ifname="$iapp_interface" |
||
402 | append bss_conf "iapp_interface=$ifname" "$N" |
||
403 | } |
||
404 | |||
405 | json_get_vars ieee80211v |
||
406 | set_default ieee80211v 0 |
||
407 | if [ "$ieee80211v" -eq "1" ]; then |
||
408 | json_get_vars time_advertisement time_zone wnm_sleep_mode bss_transition |
||
409 | |||
410 | set_default time_advertisement 0 |
||
411 | set_default wnm_sleep_mode 0 |
||
412 | set_default bss_transition 0 |
||
413 | |||
414 | append bss_conf "time_advertisement=$time_advertisement" "$N" |
||
415 | [ -n "$time_zone" ] && append bss_conf "time_zone=$time_zone" "$N" |
||
416 | append bss_conf "wnm_sleep_mode=$wnm_sleep_mode" "$N" |
||
417 | append bss_conf "bss_transition=$bss_transition" "$N" |
||
418 | fi |
||
419 | |||
420 | if [ "$wpa" -ge "1" ]; then |
||
421 | json_get_vars ieee80211r |
||
422 | set_default ieee80211r 0 |
||
423 | |||
424 | if [ "$ieee80211r" -gt "0" ]; then |
||
425 | json_get_vars mobility_domain ft_psk_generate_local ft_over_ds reassociation_deadline |
||
426 | |||
427 | set_default mobility_domain "$(echo "$ssid" | md5sum | head -c 4)" |
||
428 | set_default ft_psk_generate_local 1 |
||
429 | set_default ft_over_ds 1 |
||
430 | set_default reassociation_deadline 1000 |
||
431 | |||
432 | append bss_conf "mobility_domain=$mobility_domain" "$N" |
||
433 | append bss_conf "ft_psk_generate_local=$ft_psk_generate_local" "$N" |
||
434 | append bss_conf "ft_over_ds=$ft_over_ds" "$N" |
||
435 | append bss_conf "reassociation_deadline=$reassociation_deadline" "$N" |
||
436 | [ -n "$nasid" ] || append bss_conf "nas_identifier=${macaddr//\:}" "$N" |
||
437 | |||
438 | if [ "$ft_psk_generate_local" -eq "0" ]; then |
||
439 | json_get_vars r0_key_lifetime r1_key_holder pmk_r1_push |
||
440 | json_get_values r0kh r0kh |
||
441 | json_get_values r1kh r1kh |
||
442 | |||
443 | set_default r0_key_lifetime 10000 |
||
444 | set_default pmk_r1_push 0 |
||
445 | |||
446 | [ -n "$r1_key_holder" ] && append bss_conf "r1_key_holder=$r1_key_holder" "$N" |
||
447 | append bss_conf "r0_key_lifetime=$r0_key_lifetime" "$N" |
||
448 | append bss_conf "pmk_r1_push=$pmk_r1_push" "$N" |
||
449 | |||
450 | for kh in $r0kh; do |
||
451 | append bss_conf "r0kh=${kh//,/ }" "$N" |
||
452 | done |
||
453 | for kh in $r1kh; do |
||
454 | append bss_conf "r1kh=${kh//,/ }" "$N" |
||
455 | done |
||
456 | fi |
||
457 | fi |
||
458 | |||
459 | append bss_conf "wpa_disable_eapol_key_retries=$wpa_disable_eapol_key_retries" "$N" |
||
460 | |||
461 | hostapd_append_wpa_key_mgmt |
||
462 | [ -n "$wpa_key_mgmt" ] && append bss_conf "wpa_key_mgmt=$wpa_key_mgmt" "$N" |
||
463 | fi |
||
464 | |||
465 | if [ "$wpa" -ge "2" ]; then |
||
466 | if [ -n "$network_bridge" -a "$rsn_preauth" = 1 ]; then |
||
467 | set_default auth_cache 1 |
||
468 | append bss_conf "rsn_preauth=1" "$N" |
||
469 | append bss_conf "rsn_preauth_interfaces=$network_bridge" "$N" |
||
470 | else |
||
471 | set_default auth_cache 0 |
||
472 | fi |
||
473 | |||
474 | append bss_conf "okc=$auth_cache" "$N" |
||
475 | [ "$auth_cache" = 0 ] && append bss_conf "disable_pmksa_caching=1" "$N" |
||
476 | |||
477 | # RSN -> allow management frame protection |
||
478 | case "$ieee80211w" in |
||
479 | [012]) |
||
480 | json_get_vars ieee80211w_mgmt_cipher ieee80211w_max_timeout ieee80211w_retry_timeout |
||
481 | append bss_conf "ieee80211w=$ieee80211w" "$N" |
||
482 | [ "$ieee80211w" -gt "0" ] && { |
||
483 | append bss_conf "group_mgmt_cipher=${ieee80211w_mgmt_cipher:-AES-128-CMAC}" "$N" |
||
484 | [ -n "$ieee80211w_max_timeout" ] && \ |
||
485 | append bss_conf "assoc_sa_query_max_timeout=$ieee80211w_max_timeout" "$N" |
||
486 | [ -n "$ieee80211w_retry_timeout" ] && \ |
||
487 | append bss_conf "assoc_sa_query_retry_timeout=$ieee80211w_retry_timeout" "$N" |
||
488 | } |
||
489 | ;; |
||
490 | esac |
||
491 | fi |
||
492 | |||
493 | _macfile="/var/run/hostapd-$ifname.maclist" |
||
494 | case "$macfilter" in |
||
495 | allow) |
||
496 | append bss_conf "macaddr_acl=1" "$N" |
||
497 | append bss_conf "accept_mac_file=$_macfile" "$N" |
||
498 | # accept_mac_file can be used to set MAC to VLAN ID mapping |
||
499 | vlan_possible=1 |
||
500 | ;; |
||
501 | deny) |
||
502 | append bss_conf "macaddr_acl=0" "$N" |
||
503 | append bss_conf "deny_mac_file=$_macfile" "$N" |
||
504 | ;; |
||
505 | *) |
||
506 | _macfile="" |
||
507 | ;; |
||
508 | esac |
||
509 | |||
510 | [ -n "$_macfile" ] && { |
||
511 | json_get_vars macfile |
||
512 | json_get_values maclist maclist |
||
513 | |||
514 | rm -f "$_macfile" |
||
515 | ( |
||
516 | for mac in $maclist; do |
||
517 | echo "$mac" |
||
518 | done |
||
519 | [ -n "$macfile" -a -f "$macfile" ] && cat "$macfile" |
||
520 | ) > "$_macfile" |
||
521 | } |
||
522 | |||
523 | [ -n "$vlan_possible" -a -n "$dynamic_vlan" ] && { |
||
524 | json_get_vars vlan_naming vlan_tagged_interface vlan_bridge vlan_file |
||
525 | set_default vlan_naming 1 |
||
526 | append bss_conf "dynamic_vlan=$dynamic_vlan" "$N" |
||
527 | append bss_conf "vlan_naming=$vlan_naming" "$N" |
||
528 | [ -n "$vlan_bridge" ] && \ |
||
529 | append bss_conf "vlan_bridge=$vlan_bridge" "$N" |
||
530 | [ -n "$vlan_tagged_interface" ] && \ |
||
531 | append bss_conf "vlan_tagged_interface=$vlan_tagged_interface" "$N" |
||
532 | [ -n "$vlan_file" ] && { |
||
533 | [ -e "$vlan_file" ] || touch "$vlan_file" |
||
534 | append bss_conf "vlan_file=$vlan_file" "$N" |
||
535 | } |
||
536 | } |
||
537 | |||
538 | append "$var" "$bss_conf" "$N" |
||
539 | return 0 |
||
540 | } |
||
541 | |||
542 | hostapd_set_log_options() { |
||
543 | local var="$1" |
||
544 | |||
545 | local log_level log_80211 log_8021x log_radius log_wpa log_driver log_iapp log_mlme |
||
546 | json_get_vars log_level log_80211 log_8021x log_radius log_wpa log_driver log_iapp log_mlme |
||
547 | |||
548 | set_default log_level 2 |
||
549 | set_default log_80211 1 |
||
550 | set_default log_8021x 1 |
||
551 | set_default log_radius 1 |
||
552 | set_default log_wpa 1 |
||
553 | set_default log_driver 1 |
||
554 | set_default log_iapp 1 |
||
555 | set_default log_mlme 1 |
||
556 | |||
557 | local log_mask=$(( \ |
||
558 | ($log_80211 << 0) | \ |
||
559 | ($log_8021x << 1) | \ |
||
560 | ($log_radius << 2) | \ |
||
561 | ($log_wpa << 3) | \ |
||
562 | ($log_driver << 4) | \ |
||
563 | ($log_iapp << 5) | \ |
||
564 | ($log_mlme << 6) \ |
||
565 | )) |
||
566 | |||
567 | append "$var" "logger_syslog=$log_mask" "$N" |
||
568 | append "$var" "logger_syslog_level=$log_level" "$N" |
||
569 | append "$var" "logger_stdout=$log_mask" "$N" |
||
570 | append "$var" "logger_stdout_level=$log_level" "$N" |
||
571 | |||
572 | return 0 |
||
573 | } |
||
574 | |||
575 | _wpa_supplicant_common() { |
||
576 | local ifname="$1" |
||
577 | |||
578 | _rpath="/var/run/wpa_supplicant" |
||
579 | _config="${_rpath}-$ifname.conf" |
||
580 | } |
||
581 | |||
582 | wpa_supplicant_teardown_interface() { |
||
583 | _wpa_supplicant_common "$1" |
||
584 | rm -rf "$_rpath/$1" "$_config" |
||
585 | } |
||
586 | |||
587 | wpa_supplicant_prepare_interface() { |
||
588 | local ifname="$1" |
||
589 | _w_driver="$2" |
||
590 | |||
591 | _wpa_supplicant_common "$1" |
||
592 | |||
3 | office | 593 | json_get_vars mode wds |
1 | office | 594 | |
595 | [ -n "$network_bridge" ] && { |
||
596 | fail= |
||
597 | case "$mode" in |
||
598 | adhoc) |
||
599 | fail=1 |
||
600 | ;; |
||
601 | sta) |
||
3 | office | 602 | [ "$wds" = 1 ] || fail=1 |
1 | office | 603 | ;; |
604 | esac |
||
605 | |||
606 | [ -n "$fail" ] && { |
||
607 | wireless_setup_vif_failed BRIDGE_NOT_ALLOWED |
||
608 | return 1 |
||
609 | } |
||
610 | } |
||
611 | |||
612 | local ap_scan= |
||
613 | |||
614 | _w_mode="$mode" |
||
615 | _w_modestr= |
||
616 | |||
617 | [[ "$mode" = adhoc ]] && { |
||
618 | ap_scan="ap_scan=2" |
||
619 | |||
620 | _w_modestr="mode=1" |
||
621 | } |
||
622 | |||
623 | local country_str= |
||
624 | [ -n "$country" ] && { |
||
625 | country_str="country=$country" |
||
626 | } |
||
627 | |||
628 | wpa_supplicant_teardown_interface "$ifname" |
||
629 | cat > "$_config" <<EOF |
||
630 | $ap_scan |
||
631 | $country_str |
||
632 | EOF |
||
633 | return 0 |
||
634 | } |
||
635 | |||
636 | wpa_supplicant_set_fixed_freq() { |
||
637 | local freq="$1" |
||
638 | local htmode="$2" |
||
639 | |||
640 | append network_data "fixed_freq=1" "$N$T" |
||
641 | append network_data "frequency=$freq" "$N$T" |
||
642 | case "$htmode" in |
||
643 | NOHT) append network_data "disable_ht=1" "$N$T";; |
||
644 | HT20|VHT20) append network_data "disable_ht40=1" "$N$T";; |
||
645 | HT40*|VHT40*|VHT80*|VHT160*) append network_data "ht40=1" "$N$T";; |
||
646 | esac |
||
647 | case "$htmode" in |
||
648 | VHT*) append network_data "vht=1" "$N$T";; |
||
649 | esac |
||
650 | case "$htmode" in |
||
651 | VHT80) append network_data "max_oper_chwidth=1" "$N$T";; |
||
652 | VHT160) append network_data "max_oper_chwidth=2" "$N$T";; |
||
653 | *) append network_data "max_oper_chwidth=0" "$N$T";; |
||
654 | esac |
||
655 | } |
||
656 | |||
657 | wpa_supplicant_add_network() { |
||
658 | local ifname="$1" |
||
659 | local freq="$2" |
||
660 | local htmode="$3" |
||
661 | local noscan="$4" |
||
662 | |||
663 | _wpa_supplicant_common "$1" |
||
664 | wireless_vif_parse_encryption |
||
665 | |||
666 | json_get_vars \ |
||
667 | ssid bssid key \ |
||
668 | basic_rate mcast_rate \ |
||
3 | office | 669 | ieee80211w ieee80211r |
1 | office | 670 | |
671 | set_default ieee80211r 0 |
||
672 | |||
673 | local key_mgmt='NONE' |
||
674 | local enc_str= |
||
675 | local network_data= |
||
676 | local T=" " |
||
677 | |||
678 | local scan_ssid="scan_ssid=1" |
||
679 | local freq wpa_key_mgmt |
||
680 | |||
681 | [[ "$_w_mode" = "adhoc" ]] && { |
||
682 | append network_data "mode=1" "$N$T" |
||
683 | [ -n "$freq" ] && wpa_supplicant_set_fixed_freq "$freq" "$htmode" |
||
684 | |||
685 | scan_ssid="scan_ssid=0" |
||
686 | |||
687 | [ "$_w_driver" = "nl80211" ] || append wpa_key_mgmt "WPA-NONE" |
||
688 | } |
||
689 | |||
690 | [[ "$_w_mode" = "mesh" ]] && { |
||
3 | office | 691 | json_get_vars mesh_id mesh_fwding |
1 | office | 692 | [ -n "$mesh_id" ] && ssid="${mesh_id}" |
693 | |||
694 | append network_data "mode=5" "$N$T" |
||
695 | [ -n "$mesh_fwding" ] && append network_data "mesh_fwding=${mesh_fwding}" "$N$T" |
||
696 | [ -n "$freq" ] && wpa_supplicant_set_fixed_freq "$freq" "$htmode" |
||
697 | [ "$noscan" = "1" ] && append network_data "noscan=1" "$N$T" |
||
698 | append wpa_key_mgmt "SAE" |
||
699 | scan_ssid="" |
||
700 | } |
||
701 | |||
702 | [ "$_w_mode" = "adhoc" -o "$_w_mode" = "mesh" ] && append network_data "$_w_modestr" "$N$T" |
||
703 | |||
704 | case "$auth_type" in |
||
705 | none) ;; |
||
706 | wep) |
||
707 | local wep_keyidx=0 |
||
708 | hostapd_append_wep_key network_data |
||
709 | append network_data "wep_tx_keyidx=$wep_keyidx" "$N$T" |
||
710 | ;; |
||
3 | office | 711 | psk) |
1 | office | 712 | local passphrase |
713 | |||
714 | if [ "$_w_mode" != "mesh" ]; then |
||
715 | hostapd_append_wpa_key_mgmt |
||
716 | fi |
||
717 | |||
718 | key_mgmt="$wpa_key_mgmt" |
||
719 | |||
720 | if [ ${#key} -eq 64 ]; then |
||
721 | passphrase="psk=${key}" |
||
722 | else |
||
723 | if [ "$_w_mode" = "mesh" ]; then |
||
724 | passphrase="sae_password=\"${key}\"" |
||
725 | else |
||
726 | passphrase="psk=\"${key}\"" |
||
727 | fi |
||
728 | fi |
||
729 | append network_data "$passphrase" "$N$T" |
||
730 | ;; |
||
3 | office | 731 | eap) |
1 | office | 732 | hostapd_append_wpa_key_mgmt |
733 | key_mgmt="$wpa_key_mgmt" |
||
734 | |||
735 | json_get_vars eap_type identity anonymous_identity ca_cert |
||
736 | [ -n "$ca_cert" ] && append network_data "ca_cert=\"$ca_cert\"" "$N$T" |
||
737 | [ -n "$identity" ] && append network_data "identity=\"$identity\"" "$N$T" |
||
738 | [ -n "$anonymous_identity" ] && append network_data "anonymous_identity=\"$anonymous_identity\"" "$N$T" |
||
739 | case "$eap_type" in |
||
740 | tls) |
||
741 | json_get_vars client_cert priv_key priv_key_pwd |
||
742 | append network_data "client_cert=\"$client_cert\"" "$N$T" |
||
743 | append network_data "private_key=\"$priv_key\"" "$N$T" |
||
744 | append network_data "private_key_passwd=\"$priv_key_pwd\"" "$N$T" |
||
745 | ;; |
||
746 | fast|peap|ttls) |
||
747 | json_get_vars auth password ca_cert2 client_cert2 priv_key2 priv_key2_pwd |
||
748 | set_default auth MSCHAPV2 |
||
749 | |||
750 | if [ "$auth" = "EAP-TLS" ]; then |
||
751 | [ -n "$ca_cert2" ] && |
||
752 | append network_data "ca_cert2=\"$ca_cert2\"" "$N$T" |
||
753 | append network_data "client_cert2=\"$client_cert2\"" "$N$T" |
||
754 | append network_data "private_key2=\"$priv_key2\"" "$N$T" |
||
755 | append network_data "private_key2_passwd=\"$priv_key2_pwd\"" "$N$T" |
||
756 | else |
||
757 | append network_data "password=\"$password\"" "$N$T" |
||
758 | fi |
||
759 | |||
760 | phase2proto="auth=" |
||
761 | case "$auth" in |
||
762 | "auth"*) |
||
763 | phase2proto="" |
||
764 | ;; |
||
765 | "EAP-"*) |
||
766 | auth="$(echo $auth | cut -b 5- )" |
||
767 | [ "$eap_type" = "ttls" ] && |
||
768 | phase2proto="autheap=" |
||
769 | ;; |
||
770 | esac |
||
771 | append network_data "phase2=\"$phase2proto$auth\"" "$N$T" |
||
772 | ;; |
||
773 | esac |
||
774 | append network_data "eap=$(echo $eap_type | tr 'a-z' 'A-Z')" "$N$T" |
||
775 | ;; |
||
776 | esac |
||
777 | |||
778 | [ "$mode" = mesh ] || { |
||
779 | case "$wpa" in |
||
780 | 1) |
||
781 | append network_data "proto=WPA" "$N$T" |
||
782 | ;; |
||
783 | 2) |
||
784 | append network_data "proto=RSN" "$N$T" |
||
785 | ;; |
||
786 | esac |
||
787 | |||
788 | case "$ieee80211w" in |
||
789 | [012]) |
||
790 | [ "$wpa" -ge 2 ] && append network_data "ieee80211w=$ieee80211w" "$N$T" |
||
791 | ;; |
||
792 | esac |
||
793 | } |
||
794 | [ -n "$bssid" ] && append network_data "bssid=$bssid" "$N$T" |
||
795 | [ -n "$beacon_int" ] && append network_data "beacon_int=$beacon_int" "$N$T" |
||
796 | |||
797 | local bssid_blacklist bssid_whitelist |
||
798 | json_get_values bssid_blacklist bssid_blacklist |
||
799 | json_get_values bssid_whitelist bssid_whitelist |
||
800 | |||
801 | [ -n "$bssid_blacklist" ] && append network_data "bssid_blacklist=$bssid_blacklist" "$N$T" |
||
802 | [ -n "$bssid_whitelist" ] && append network_data "bssid_whitelist=$bssid_whitelist" "$N$T" |
||
803 | |||
804 | [ -n "$basic_rate" ] && { |
||
805 | local br rate_list= |
||
806 | for br in $basic_rate; do |
||
807 | wpa_supplicant_add_rate rate_list "$br" |
||
808 | done |
||
809 | [ -n "$rate_list" ] && append network_data "rates=$rate_list" "$N$T" |
||
810 | } |
||
811 | |||
812 | [ -n "$mcast_rate" ] && { |
||
813 | local mc_rate= |
||
814 | wpa_supplicant_add_rate mc_rate "$mcast_rate" |
||
815 | append network_data "mcast_rate=$mc_rate" "$N$T" |
||
816 | } |
||
817 | |||
3 | office | 818 | cat >> "$_config" <<EOF |
1 | office | 819 | network={ |
820 | $scan_ssid |
||
821 | ssid="$ssid" |
||
822 | key_mgmt=$key_mgmt |
||
823 | $network_data |
||
824 | } |
||
825 | EOF |
||
826 | return 0 |
||
827 | } |
||
828 | |||
829 | wpa_supplicant_run() { |
||
830 | local ifname="$1"; shift |
||
831 | |||
832 | _wpa_supplicant_common "$ifname" |
||
833 | |||
3 | office | 834 | /usr/sbin/wpa_supplicant -B \ |
1 | office | 835 | ${network_bridge:+-b $network_bridge} \ |
836 | -P "/var/run/wpa_supplicant-${ifname}.pid" \ |
||
837 | -D ${_w_driver:-wext} \ |
||
838 | -i "$ifname" \ |
||
839 | -c "$_config" \ |
||
840 | -C "$_rpath" \ |
||
841 | "$@" |
||
842 | |||
843 | ret="$?" |
||
844 | wireless_add_process "$(cat "/var/run/wpa_supplicant-${ifname}.pid")" /usr/sbin/wpa_supplicant 1 |
||
845 | |||
846 | [ "$ret" != 0 ] && wireless_setup_vif_failed WPA_SUPPLICANT_FAILED |
||
847 | |||
848 | return $ret |
||
849 | } |
||
850 | |||
851 | hostapd_common_cleanup() { |
||
852 | killall hostapd wpa_supplicant meshd-nl80211 |
||
853 | } |