]>
Commit | Line | Data |
---|---|---|
6fc6879b | 1 | /* |
41d719d6 | 2 | * hostapd / Configuration helper functions |
08081ad8 | 3 | * Copyright (c) 2003-2014, Jouni Malinen <j@w1.fi> |
6fc6879b | 4 | * |
0f3d578e JM |
5 | * This software may be distributed under the terms of the BSD license. |
6 | * See README for more details. | |
6fc6879b JM |
7 | */ |
8 | ||
6226e38d | 9 | #include "utils/includes.h" |
6fc6879b | 10 | |
6226e38d | 11 | #include "utils/common.h" |
03da66bd | 12 | #include "crypto/sha1.h" |
d501c27c | 13 | #include "crypto/tls.h" |
6fc6879b | 14 | #include "radius/radius_client.h" |
df84268a | 15 | #include "common/ieee802_11_defs.h" |
41d719d6 | 16 | #include "common/eapol_common.h" |
91d91abf | 17 | #include "common/dhcp.h" |
03da66bd JM |
18 | #include "eap_common/eap_wsc_common.h" |
19 | #include "eap_server/eap.h" | |
6226e38d | 20 | #include "wpa_auth.h" |
97234b50 | 21 | #include "sta_info.h" |
6226e38d | 22 | #include "ap_config.h" |
6fc6879b JM |
23 | |
24 | ||
6fc6879b JM |
25 | static void hostapd_config_free_vlan(struct hostapd_bss_config *bss) |
26 | { | |
27 | struct hostapd_vlan *vlan, *prev; | |
28 | ||
29 | vlan = bss->vlan; | |
30 | prev = NULL; | |
31 | while (vlan) { | |
32 | prev = vlan; | |
33 | vlan = vlan->next; | |
34 | os_free(prev); | |
35 | } | |
36 | ||
37 | bss->vlan = NULL; | |
38 | } | |
39 | ||
40 | ||
6f234c1e JM |
41 | #ifndef DEFAULT_WPA_DISABLE_EAPOL_KEY_RETRIES |
42 | #define DEFAULT_WPA_DISABLE_EAPOL_KEY_RETRIES 0 | |
43 | #endif /* DEFAULT_WPA_DISABLE_EAPOL_KEY_RETRIES */ | |
44 | ||
41d719d6 | 45 | void hostapd_config_defaults_bss(struct hostapd_bss_config *bss) |
6fc6879b | 46 | { |
695dbbea JM |
47 | dl_list_init(&bss->anqp_elem); |
48 | ||
6fc6879b JM |
49 | bss->logger_syslog_level = HOSTAPD_LEVEL_INFO; |
50 | bss->logger_stdout_level = HOSTAPD_LEVEL_INFO; | |
51 | bss->logger_syslog = (unsigned int) -1; | |
52 | bss->logger_stdout = (unsigned int) -1; | |
53 | ||
54 | bss->auth_algs = WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED; | |
55 | ||
56 | bss->wep_rekeying_period = 300; | |
57 | /* use key0 in individual key and key1 in broadcast key */ | |
58 | bss->broadcast_key_idx_min = 1; | |
59 | bss->broadcast_key_idx_max = 2; | |
60 | bss->eap_reauth_period = 3600; | |
61 | ||
62 | bss->wpa_group_rekey = 600; | |
63 | bss->wpa_gmk_rekey = 86400; | |
41f140d3 GK |
64 | bss->wpa_group_update_count = 4; |
65 | bss->wpa_pairwise_update_count = 4; | |
6f234c1e JM |
66 | bss->wpa_disable_eapol_key_retries = |
67 | DEFAULT_WPA_DISABLE_EAPOL_KEY_RETRIES; | |
6fc6879b JM |
68 | bss->wpa_key_mgmt = WPA_KEY_MGMT_PSK; |
69 | bss->wpa_pairwise = WPA_CIPHER_TKIP; | |
70 | bss->wpa_group = WPA_CIPHER_TKIP; | |
71 | bss->rsn_pairwise = 0; | |
72 | ||
73 | bss->max_num_sta = MAX_STA_COUNT; | |
74 | ||
75 | bss->dtim_period = 2; | |
76 | ||
77 | bss->radius_server_auth_port = 1812; | |
7b0f5500 | 78 | bss->eap_sim_db_timeout = 1; |
6fc6879b JM |
79 | bss->ap_max_inactivity = AP_MAX_INACTIVITY; |
80 | bss->eapol_version = EAPOL_VERSION; | |
b0194fe0 JM |
81 | |
82 | bss->max_listen_interval = 65535; | |
5d22a1d5 | 83 | |
df684d82 DH |
84 | bss->pwd_group = 19; /* ECC: GF(p=256) */ |
85 | ||
5d22a1d5 | 86 | #ifdef CONFIG_IEEE80211W |
45c94154 JM |
87 | bss->assoc_sa_query_max_timeout = 1000; |
88 | bss->assoc_sa_query_retry_timeout = 201; | |
8dd9f9cd | 89 | bss->group_mgmt_cipher = WPA_CIPHER_AES_128_CMAC; |
5d22a1d5 | 90 | #endif /* CONFIG_IEEE80211W */ |
1e5839e0 | 91 | #ifdef EAP_SERVER_FAST |
378eae5e JM |
92 | /* both anonymous and authenticated provisioning */ |
93 | bss->eap_fast_prov = 3; | |
a11c90a6 JM |
94 | bss->pac_key_lifetime = 7 * 24 * 60 * 60; |
95 | bss->pac_key_refresh_time = 1 * 24 * 60 * 60; | |
1e5839e0 | 96 | #endif /* EAP_SERVER_FAST */ |
d2da2249 JB |
97 | |
98 | /* Set to -1 as defaults depends on HT in setup */ | |
99 | bss->wmm_enabled = -1; | |
d7956add | 100 | |
4ec1fd8e | 101 | #ifdef CONFIG_IEEE80211R_AP |
d7956add | 102 | bss->ft_over_ds = 1; |
3a46cf93 MB |
103 | bss->rkh_pos_timeout = 86400; |
104 | bss->rkh_neg_timeout = 60; | |
105 | bss->rkh_pull_timeout = 1000; | |
106 | bss->rkh_pull_retries = 4; | |
83fe4bd3 | 107 | bss->r0_key_lifetime = 1209600; |
4ec1fd8e | 108 | #endif /* CONFIG_IEEE80211R_AP */ |
bde7ba6c JM |
109 | |
110 | bss->radius_das_time_window = 300; | |
d136c376 JM |
111 | |
112 | bss->sae_anti_clogging_threshold = 5; | |
d8b841eb | 113 | bss->sae_sync = 5; |
26bf70e3 | 114 | |
2977f519 JM |
115 | bss->gas_frag_limit = 1400; |
116 | ||
26bf70e3 JM |
117 | #ifdef CONFIG_FILS |
118 | dl_list_init(&bss->fils_realms); | |
91d91abf JM |
119 | bss->fils_hlp_wait_time = 30; |
120 | bss->dhcp_server_port = DHCP_SERVER_PORT; | |
121 | bss->dhcp_relay_port = DHCP_SERVER_PORT; | |
26bf70e3 | 122 | #endif /* CONFIG_FILS */ |
57a2aaca JM |
123 | |
124 | bss->broadcast_deauth = 1; | |
941caed9 JM |
125 | |
126 | #ifdef CONFIG_MBO | |
127 | bss->mbo_cell_data_conn_pref = -1; | |
128 | #endif /* CONFIG_MBO */ | |
d501c27c JM |
129 | |
130 | /* Disable TLS v1.3 by default for now to avoid interoperability issue. | |
131 | * This can be enabled by default once the implementation has been fully | |
132 | * completed and tested with other implementations. */ | |
133 | bss->tls_flags = TLS_CONN_DISABLE_TLSv1_3; | |
678d8410 JM |
134 | |
135 | bss->send_probe_response = 1; | |
6ae04d7b JM |
136 | |
137 | #ifdef CONFIG_HS20 | |
138 | bss->hs20_release = (HS20_VERSION >> 4) + 1; | |
139 | #endif /* CONFIG_HS20 */ | |
dd5d325b SV |
140 | |
141 | /* Default to strict CRL checking. */ | |
142 | bss->check_crl_strict = 1; | |
6fc6879b JM |
143 | } |
144 | ||
145 | ||
89111f3b | 146 | struct hostapd_config * hostapd_config_defaults(void) |
6fc6879b | 147 | { |
d2da2249 JB |
148 | #define ecw2cw(ecw) ((1 << (ecw)) - 1) |
149 | ||
6fc6879b JM |
150 | struct hostapd_config *conf; |
151 | struct hostapd_bss_config *bss; | |
594cf8b9 | 152 | const int aCWmin = 4, aCWmax = 10; |
3ae0800c | 153 | const struct hostapd_wmm_ac_params ac_bk = |
6fc6879b | 154 | { aCWmin, aCWmax, 7, 0, 0 }; /* background traffic */ |
3ae0800c | 155 | const struct hostapd_wmm_ac_params ac_be = |
6fc6879b | 156 | { aCWmin, aCWmax, 3, 0, 0 }; /* best effort traffic */ |
3ae0800c | 157 | const struct hostapd_wmm_ac_params ac_vi = /* video traffic */ |
f4e3860f | 158 | { aCWmin - 1, aCWmin, 2, 3008 / 32, 0 }; |
3ae0800c | 159 | const struct hostapd_wmm_ac_params ac_vo = /* voice traffic */ |
f4e3860f | 160 | { aCWmin - 2, aCWmin - 1, 2, 1504 / 32, 0 }; |
d2da2249 JB |
161 | const struct hostapd_tx_queue_params txq_bk = |
162 | { 7, ecw2cw(aCWmin), ecw2cw(aCWmax), 0 }; | |
163 | const struct hostapd_tx_queue_params txq_be = | |
164 | { 3, ecw2cw(aCWmin), 4 * (ecw2cw(aCWmin) + 1) - 1, 0}; | |
165 | const struct hostapd_tx_queue_params txq_vi = | |
166 | { 1, (ecw2cw(aCWmin) + 1) / 2 - 1, ecw2cw(aCWmin), 30}; | |
167 | const struct hostapd_tx_queue_params txq_vo = | |
168 | { 1, (ecw2cw(aCWmin) + 1) / 4 - 1, | |
169 | (ecw2cw(aCWmin) + 1) / 2 - 1, 15}; | |
170 | ||
171 | #undef ecw2cw | |
6fc6879b JM |
172 | |
173 | conf = os_zalloc(sizeof(*conf)); | |
174 | bss = os_zalloc(sizeof(*bss)); | |
175 | if (conf == NULL || bss == NULL) { | |
10656fc2 JM |
176 | wpa_printf(MSG_ERROR, "Failed to allocate memory for " |
177 | "configuration data."); | |
6fc6879b JM |
178 | os_free(conf); |
179 | os_free(bss); | |
180 | return NULL; | |
181 | } | |
ebd79f07 JM |
182 | conf->bss = os_calloc(1, sizeof(struct hostapd_bss_config *)); |
183 | if (conf->bss == NULL) { | |
184 | os_free(conf); | |
185 | os_free(bss); | |
186 | return NULL; | |
187 | } | |
188 | conf->bss[0] = bss; | |
6fc6879b | 189 | |
6fc6879b JM |
190 | bss->radius = os_zalloc(sizeof(*bss->radius)); |
191 | if (bss->radius == NULL) { | |
04c366cb | 192 | os_free(conf->bss); |
6fc6879b JM |
193 | os_free(conf); |
194 | os_free(bss); | |
195 | return NULL; | |
196 | } | |
197 | ||
198 | hostapd_config_defaults_bss(bss); | |
199 | ||
200 | conf->num_bss = 1; | |
6fc6879b JM |
201 | |
202 | conf->beacon_int = 100; | |
203 | conf->rts_threshold = -1; /* use driver default: 2347 */ | |
204 | conf->fragm_threshold = -1; /* user driver default: 2346 */ | |
e0392f82 S |
205 | /* Set to invalid value means do not add Power Constraint IE */ |
206 | conf->local_pwr_constraint = -1; | |
6fc6879b | 207 | |
3ae0800c JM |
208 | conf->wmm_ac_params[0] = ac_be; |
209 | conf->wmm_ac_params[1] = ac_bk; | |
210 | conf->wmm_ac_params[2] = ac_vi; | |
211 | conf->wmm_ac_params[3] = ac_vo; | |
6fc6879b | 212 | |
d2da2249 JB |
213 | conf->tx_queue[0] = txq_vo; |
214 | conf->tx_queue[1] = txq_vi; | |
215 | conf->tx_queue[2] = txq_be; | |
216 | conf->tx_queue[3] = txq_bk; | |
217 | ||
fc14f567 | 218 | conf->ht_capab = HT_CAP_INFO_SMPS_DISABLED; |
de9289c8 | 219 | |
f1b44874 SE |
220 | conf->ap_table_max_size = 255; |
221 | conf->ap_table_expiration_time = 60; | |
a65a9b8d | 222 | conf->track_sta_max_age = 180; |
f1b44874 | 223 | |
c2aff6b1 | 224 | #ifdef CONFIG_TESTING_OPTIONS |
06df2aa6 JM |
225 | conf->ignore_probe_probability = 0.0; |
226 | conf->ignore_auth_probability = 0.0; | |
227 | conf->ignore_assoc_probability = 0.0; | |
228 | conf->ignore_reassoc_probability = 0.0; | |
229 | conf->corrupt_gtk_rekey_mic_probability = 0.0; | |
2b6e1216 | 230 | conf->ecsa_ie_only = 0; |
c2aff6b1 JB |
231 | #endif /* CONFIG_TESTING_OPTIONS */ |
232 | ||
857d9422 MM |
233 | conf->acs = 0; |
234 | conf->acs_ch_list.num = 0; | |
50f4f2a0 MK |
235 | #ifdef CONFIG_ACS |
236 | conf->acs_num_scans = 5; | |
237 | #endif /* CONFIG_ACS */ | |
238 | ||
ff936bc7 JM |
239 | /* The third octet of the country string uses an ASCII space character |
240 | * by default to indicate that the regulations encompass all | |
241 | * environments for the current frequency band in the country. */ | |
242 | conf->country[2] = ' '; | |
243 | ||
076f1ea1 BL |
244 | conf->rssi_reject_assoc_rssi = 0; |
245 | conf->rssi_reject_assoc_timeout = 30; | |
246 | ||
6fc6879b JM |
247 | return conf; |
248 | } | |
249 | ||
250 | ||
251 | int hostapd_mac_comp(const void *a, const void *b) | |
252 | { | |
253 | return os_memcmp(a, b, sizeof(macaddr)); | |
254 | } | |
255 | ||
256 | ||
6fc6879b JM |
257 | static int hostapd_config_read_wpa_psk(const char *fname, |
258 | struct hostapd_ssid *ssid) | |
259 | { | |
260 | FILE *f; | |
261 | char buf[128], *pos; | |
262 | int line = 0, ret = 0, len, ok; | |
263 | u8 addr[ETH_ALEN]; | |
264 | struct hostapd_wpa_psk *psk; | |
265 | ||
266 | if (!fname) | |
267 | return 0; | |
268 | ||
269 | f = fopen(fname, "r"); | |
270 | if (!f) { | |
10656fc2 | 271 | wpa_printf(MSG_ERROR, "WPA PSK file '%s' not found.", fname); |
6fc6879b JM |
272 | return -1; |
273 | } | |
274 | ||
275 | while (fgets(buf, sizeof(buf), f)) { | |
276 | line++; | |
277 | ||
278 | if (buf[0] == '#') | |
279 | continue; | |
280 | pos = buf; | |
281 | while (*pos != '\0') { | |
282 | if (*pos == '\n') { | |
283 | *pos = '\0'; | |
284 | break; | |
285 | } | |
286 | pos++; | |
287 | } | |
288 | if (buf[0] == '\0') | |
289 | continue; | |
290 | ||
291 | if (hwaddr_aton(buf, addr)) { | |
10656fc2 JM |
292 | wpa_printf(MSG_ERROR, "Invalid MAC address '%s' on " |
293 | "line %d in '%s'", buf, line, fname); | |
6fc6879b JM |
294 | ret = -1; |
295 | break; | |
296 | } | |
297 | ||
298 | psk = os_zalloc(sizeof(*psk)); | |
299 | if (psk == NULL) { | |
10656fc2 | 300 | wpa_printf(MSG_ERROR, "WPA PSK allocation failed"); |
6fc6879b JM |
301 | ret = -1; |
302 | break; | |
303 | } | |
a8e16edc | 304 | if (is_zero_ether_addr(addr)) |
6fc6879b JM |
305 | psk->group = 1; |
306 | else | |
307 | os_memcpy(psk->addr, addr, ETH_ALEN); | |
308 | ||
309 | pos = buf + 17; | |
5306f43f | 310 | if (*pos == '\0') { |
10656fc2 JM |
311 | wpa_printf(MSG_ERROR, "No PSK on line %d in '%s'", |
312 | line, fname); | |
6fc6879b JM |
313 | os_free(psk); |
314 | ret = -1; | |
315 | break; | |
316 | } | |
317 | pos++; | |
318 | ||
319 | ok = 0; | |
320 | len = os_strlen(pos); | |
321 | if (len == 64 && hexstr2bin(pos, psk->psk, PMK_LEN) == 0) | |
322 | ok = 1; | |
323 | else if (len >= 8 && len < 64) { | |
324 | pbkdf2_sha1(pos, ssid->ssid, ssid->ssid_len, | |
325 | 4096, psk->psk, PMK_LEN); | |
326 | ok = 1; | |
327 | } | |
328 | if (!ok) { | |
10656fc2 JM |
329 | wpa_printf(MSG_ERROR, "Invalid PSK '%s' on line %d in " |
330 | "'%s'", pos, line, fname); | |
6fc6879b JM |
331 | os_free(psk); |
332 | ret = -1; | |
333 | break; | |
334 | } | |
335 | ||
336 | psk->next = ssid->wpa_psk; | |
337 | ssid->wpa_psk = psk; | |
338 | } | |
339 | ||
340 | fclose(f); | |
341 | ||
342 | return ret; | |
343 | } | |
344 | ||
345 | ||
0ae687bd JM |
346 | static int hostapd_derive_psk(struct hostapd_ssid *ssid) |
347 | { | |
348 | ssid->wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk)); | |
349 | if (ssid->wpa_psk == NULL) { | |
350 | wpa_printf(MSG_ERROR, "Unable to alloc space for PSK"); | |
351 | return -1; | |
352 | } | |
353 | wpa_hexdump_ascii(MSG_DEBUG, "SSID", | |
354 | (u8 *) ssid->ssid, ssid->ssid_len); | |
355 | wpa_hexdump_ascii_key(MSG_DEBUG, "PSK (ASCII passphrase)", | |
356 | (u8 *) ssid->wpa_passphrase, | |
357 | os_strlen(ssid->wpa_passphrase)); | |
358 | pbkdf2_sha1(ssid->wpa_passphrase, | |
359 | ssid->ssid, ssid->ssid_len, | |
360 | 4096, ssid->wpa_psk->psk, PMK_LEN); | |
361 | wpa_hexdump_key(MSG_DEBUG, "PSK (from passphrase)", | |
362 | ssid->wpa_psk->psk, PMK_LEN); | |
363 | return 0; | |
364 | } | |
365 | ||
366 | ||
6fc6879b JM |
367 | int hostapd_setup_wpa_psk(struct hostapd_bss_config *conf) |
368 | { | |
369 | struct hostapd_ssid *ssid = &conf->ssid; | |
370 | ||
371 | if (ssid->wpa_passphrase != NULL) { | |
372 | if (ssid->wpa_psk != NULL) { | |
0ae687bd JM |
373 | wpa_printf(MSG_DEBUG, "Using pre-configured WPA PSK " |
374 | "instead of passphrase"); | |
375 | } else { | |
376 | wpa_printf(MSG_DEBUG, "Deriving WPA PSK based on " | |
377 | "passphrase"); | |
378 | if (hostapd_derive_psk(ssid) < 0) | |
379 | return -1; | |
6fc6879b | 380 | } |
6fc6879b | 381 | ssid->wpa_psk->group = 1; |
6fc6879b JM |
382 | } |
383 | ||
34e29dfd | 384 | return hostapd_config_read_wpa_psk(ssid->wpa_psk_file, &conf->ssid); |
6fc6879b JM |
385 | } |
386 | ||
387 | ||
6fc6879b JM |
388 | static void hostapd_config_free_radius(struct hostapd_radius_server *servers, |
389 | int num_servers) | |
390 | { | |
391 | int i; | |
392 | ||
393 | for (i = 0; i < num_servers; i++) { | |
394 | os_free(servers[i].shared_secret); | |
395 | } | |
396 | os_free(servers); | |
397 | } | |
398 | ||
399 | ||
af35e7af JM |
400 | struct hostapd_radius_attr * |
401 | hostapd_config_get_radius_attr(struct hostapd_radius_attr *attr, u8 type) | |
402 | { | |
403 | for (; attr; attr = attr->next) { | |
404 | if (attr->type == type) | |
405 | return attr; | |
406 | } | |
407 | return NULL; | |
408 | } | |
409 | ||
410 | ||
411 | static void hostapd_config_free_radius_attr(struct hostapd_radius_attr *attr) | |
412 | { | |
413 | struct hostapd_radius_attr *prev; | |
414 | ||
415 | while (attr) { | |
416 | prev = attr; | |
417 | attr = attr->next; | |
418 | wpabuf_free(prev->val); | |
419 | os_free(prev); | |
420 | } | |
421 | } | |
422 | ||
423 | ||
d0ee16ed | 424 | void hostapd_config_free_eap_user(struct hostapd_eap_user *user) |
6fc6879b | 425 | { |
d0ee16ed | 426 | hostapd_config_free_radius_attr(user->accept_attr); |
6fc6879b | 427 | os_free(user->identity); |
b7175b4d | 428 | bin_clear_free(user->password, user->password_len); |
d52ead3d | 429 | bin_clear_free(user->salt, user->salt_len); |
6fc6879b JM |
430 | os_free(user); |
431 | } | |
432 | ||
433 | ||
78022c83 JM |
434 | void hostapd_config_free_eap_users(struct hostapd_eap_user *user) |
435 | { | |
436 | struct hostapd_eap_user *prev_user; | |
437 | ||
438 | while (user) { | |
439 | prev_user = user; | |
440 | user = user->next; | |
441 | hostapd_config_free_eap_user(prev_user); | |
442 | } | |
443 | } | |
444 | ||
445 | ||
6fc6879b JM |
446 | static void hostapd_config_free_wep(struct hostapd_wep_keys *keys) |
447 | { | |
448 | int i; | |
449 | for (i = 0; i < NUM_WEP_KEYS; i++) { | |
b7175b4d | 450 | bin_clear_free(keys->key[i], keys->len[i]); |
6fc6879b JM |
451 | keys->key[i] = NULL; |
452 | } | |
453 | } | |
454 | ||
455 | ||
891dfb33 ST |
456 | void hostapd_config_clear_wpa_psk(struct hostapd_wpa_psk **l) |
457 | { | |
458 | struct hostapd_wpa_psk *psk, *tmp; | |
459 | ||
460 | for (psk = *l; psk;) { | |
461 | tmp = psk; | |
462 | psk = psk->next; | |
463 | bin_clear_free(tmp, sizeof(*tmp)); | |
464 | } | |
465 | *l = NULL; | |
466 | } | |
467 | ||
468 | ||
695dbbea JM |
469 | static void hostapd_config_free_anqp_elem(struct hostapd_bss_config *conf) |
470 | { | |
471 | struct anqp_element *elem; | |
472 | ||
473 | while ((elem = dl_list_first(&conf->anqp_elem, struct anqp_element, | |
474 | list))) { | |
475 | dl_list_del(&elem->list); | |
476 | wpabuf_free(elem->payload); | |
477 | os_free(elem); | |
478 | } | |
479 | } | |
480 | ||
481 | ||
26bf70e3 JM |
482 | static void hostapd_config_free_fils_realms(struct hostapd_bss_config *conf) |
483 | { | |
484 | #ifdef CONFIG_FILS | |
485 | struct fils_realm *realm; | |
486 | ||
487 | while ((realm = dl_list_first(&conf->fils_realms, struct fils_realm, | |
488 | list))) { | |
489 | dl_list_del(&realm->list); | |
490 | os_free(realm); | |
491 | } | |
492 | #endif /* CONFIG_FILS */ | |
493 | } | |
494 | ||
495 | ||
9be19d0b JM |
496 | static void hostapd_config_free_sae_passwords(struct hostapd_bss_config *conf) |
497 | { | |
498 | struct sae_password_entry *pw, *tmp; | |
499 | ||
500 | pw = conf->sae_passwords; | |
501 | conf->sae_passwords = NULL; | |
502 | while (pw) { | |
503 | tmp = pw; | |
504 | pw = pw->next; | |
505 | str_clear_free(tmp->password); | |
506 | os_free(tmp->identifier); | |
507 | os_free(tmp); | |
508 | } | |
509 | } | |
510 | ||
511 | ||
55920658 | 512 | void hostapd_config_free_bss(struct hostapd_bss_config *conf) |
6fc6879b | 513 | { |
6fc6879b JM |
514 | if (conf == NULL) |
515 | return; | |
516 | ||
891dfb33 | 517 | hostapd_config_clear_wpa_psk(&conf->ssid.wpa_psk); |
6fc6879b | 518 | |
b7175b4d | 519 | str_clear_free(conf->ssid.wpa_passphrase); |
6fc6879b | 520 | os_free(conf->ssid.wpa_psk_file); |
43dd46b3 | 521 | hostapd_config_free_wep(&conf->ssid.wep); |
6fc6879b JM |
522 | #ifdef CONFIG_FULL_DYNAMIC_VLAN |
523 | os_free(conf->ssid.vlan_tagged_interface); | |
524 | #endif /* CONFIG_FULL_DYNAMIC_VLAN */ | |
525 | ||
78022c83 | 526 | hostapd_config_free_eap_users(conf->eap_user); |
ee431d77 | 527 | os_free(conf->eap_user_sqlite); |
6fc6879b | 528 | |
6fc6879b | 529 | os_free(conf->eap_req_id_text); |
2a5156a6 | 530 | os_free(conf->erp_domain); |
6fc6879b JM |
531 | os_free(conf->accept_mac); |
532 | os_free(conf->deny_mac); | |
533 | os_free(conf->nas_identifier); | |
5afaa067 JM |
534 | if (conf->radius) { |
535 | hostapd_config_free_radius(conf->radius->auth_servers, | |
536 | conf->radius->num_auth_servers); | |
537 | hostapd_config_free_radius(conf->radius->acct_servers, | |
538 | conf->radius->num_acct_servers); | |
539 | } | |
af35e7af JM |
540 | hostapd_config_free_radius_attr(conf->radius_auth_req_attr); |
541 | hostapd_config_free_radius_attr(conf->radius_acct_req_attr); | |
6fc6879b JM |
542 | os_free(conf->rsn_preauth_interfaces); |
543 | os_free(conf->ctrl_interface); | |
544 | os_free(conf->ca_cert); | |
545 | os_free(conf->server_cert); | |
546 | os_free(conf->private_key); | |
547 | os_free(conf->private_key_passwd); | |
080585c0 | 548 | os_free(conf->ocsp_stapling_response); |
5addb0df | 549 | os_free(conf->ocsp_stapling_response_multi); |
6fc6879b | 550 | os_free(conf->dh_file); |
f8995f8f | 551 | os_free(conf->openssl_ciphers); |
d01203ca | 552 | os_free(conf->openssl_ecdh_curves); |
6fc6879b JM |
553 | os_free(conf->pac_opaque_encr_key); |
554 | os_free(conf->eap_fast_a_id); | |
2d867244 | 555 | os_free(conf->eap_fast_a_id_info); |
6fc6879b JM |
556 | os_free(conf->eap_sim_db); |
557 | os_free(conf->radius_server_clients); | |
6fc6879b | 558 | os_free(conf->radius); |
b031338c | 559 | os_free(conf->radius_das_shared_secret); |
6fc6879b | 560 | hostapd_config_free_vlan(conf); |
39b97072 JM |
561 | os_free(conf->time_zone); |
562 | ||
4ec1fd8e | 563 | #ifdef CONFIG_IEEE80211R_AP |
6fc6879b JM |
564 | { |
565 | struct ft_remote_r0kh *r0kh, *r0kh_prev; | |
566 | struct ft_remote_r1kh *r1kh, *r1kh_prev; | |
567 | ||
568 | r0kh = conf->r0kh_list; | |
569 | conf->r0kh_list = NULL; | |
570 | while (r0kh) { | |
571 | r0kh_prev = r0kh; | |
572 | r0kh = r0kh->next; | |
573 | os_free(r0kh_prev); | |
574 | } | |
575 | ||
576 | r1kh = conf->r1kh_list; | |
577 | conf->r1kh_list = NULL; | |
578 | while (r1kh) { | |
579 | r1kh_prev = r1kh; | |
580 | r1kh = r1kh->next; | |
581 | os_free(r1kh_prev); | |
582 | } | |
583 | } | |
4ec1fd8e | 584 | #endif /* CONFIG_IEEE80211R_AP */ |
ad08c363 JM |
585 | |
586 | #ifdef CONFIG_WPS | |
587 | os_free(conf->wps_pin_requests); | |
588 | os_free(conf->device_name); | |
589 | os_free(conf->manufacturer); | |
590 | os_free(conf->model_name); | |
591 | os_free(conf->model_number); | |
592 | os_free(conf->serial_number); | |
ad08c363 JM |
593 | os_free(conf->config_methods); |
594 | os_free(conf->ap_pin); | |
62966253 | 595 | os_free(conf->extra_cred); |
4c29cae9 | 596 | os_free(conf->ap_settings); |
f620268f JM |
597 | os_free(conf->upnp_iface); |
598 | os_free(conf->friendly_name); | |
599 | os_free(conf->manufacturer_url); | |
600 | os_free(conf->model_description); | |
601 | os_free(conf->model_url); | |
602 | os_free(conf->upc); | |
8509fb5c JM |
603 | { |
604 | unsigned int i; | |
605 | ||
606 | for (i = 0; i < MAX_WPS_VENDOR_EXTENSIONS; i++) | |
607 | wpabuf_free(conf->wps_vendor_ext[i]); | |
608 | } | |
ffdaa05a JM |
609 | wpabuf_free(conf->wps_nfc_dh_pubkey); |
610 | wpabuf_free(conf->wps_nfc_dh_privkey); | |
611 | wpabuf_free(conf->wps_nfc_dev_pw); | |
ad08c363 | 612 | #endif /* CONFIG_WPS */ |
4b2a77ab JM |
613 | |
614 | os_free(conf->roaming_consortium); | |
648cc711 | 615 | os_free(conf->venue_name); |
7e1d3ee9 | 616 | os_free(conf->venue_url); |
8047b186 | 617 | os_free(conf->nai_realm_data); |
550a3958 | 618 | os_free(conf->network_auth_type); |
7515adb2 | 619 | os_free(conf->anqp_3gpp_cell_net); |
26fac8b6 | 620 | os_free(conf->domain_name); |
695dbbea | 621 | hostapd_config_free_anqp_elem(conf); |
505a3694 JM |
622 | |
623 | #ifdef CONFIG_RADIUS_TEST | |
624 | os_free(conf->dump_msk_file); | |
625 | #endif /* CONFIG_RADIUS_TEST */ | |
df5934f1 JK |
626 | |
627 | #ifdef CONFIG_HS20 | |
a9277e85 | 628 | os_free(conf->hs20_oper_friendly_name); |
4065a309 | 629 | os_free(conf->hs20_wan_metrics); |
5ccc54aa | 630 | os_free(conf->hs20_connection_capability); |
df5934f1 | 631 | os_free(conf->hs20_operating_class); |
f7bd7a01 | 632 | os_free(conf->hs20_icons); |
ae6d15c7 JM |
633 | if (conf->hs20_osu_providers) { |
634 | size_t i; | |
635 | for (i = 0; i < conf->hs20_osu_providers_count; i++) { | |
636 | struct hs20_osu_provider *p; | |
637 | size_t j; | |
638 | p = &conf->hs20_osu_providers[i]; | |
639 | os_free(p->friendly_name); | |
640 | os_free(p->server_uri); | |
641 | os_free(p->method_list); | |
642 | for (j = 0; j < p->icons_count; j++) | |
643 | os_free(p->icons[j]); | |
644 | os_free(p->icons); | |
645 | os_free(p->osu_nai); | |
cad810a9 | 646 | os_free(p->osu_nai2); |
ae6d15c7 JM |
647 | os_free(p->service_desc); |
648 | } | |
649 | os_free(conf->hs20_osu_providers); | |
650 | } | |
0e450db2 JM |
651 | if (conf->hs20_operator_icon) { |
652 | size_t i; | |
653 | ||
654 | for (i = 0; i < conf->hs20_operator_icon_count; i++) | |
655 | os_free(conf->hs20_operator_icon[i]); | |
656 | os_free(conf->hs20_operator_icon); | |
657 | } | |
8d2a9921 | 658 | os_free(conf->subscr_remediation_url); |
7bd8c76a | 659 | os_free(conf->hs20_sim_provisioning_url); |
6cb8f4f3 | 660 | os_free(conf->t_c_filename); |
8760b984 | 661 | os_free(conf->t_c_server_url); |
df5934f1 | 662 | #endif /* CONFIG_HS20 */ |
b52f084c JM |
663 | |
664 | wpabuf_free(conf->vendor_elements); | |
a9112270 | 665 | wpabuf_free(conf->assocresp_elements); |
625f202a JM |
666 | |
667 | os_free(conf->sae_groups); | |
91cc34bf JM |
668 | #ifdef CONFIG_OWE |
669 | os_free(conf->owe_groups); | |
670 | #endif /* CONFIG_OWE */ | |
67fe933d | 671 | |
88cb27c7 DS |
672 | os_free(conf->wowlan_triggers); |
673 | ||
67fe933d | 674 | os_free(conf->server_id); |
ebd79f07 | 675 | |
bc02843e JM |
676 | #ifdef CONFIG_TESTING_OPTIONS |
677 | wpabuf_free(conf->own_ie_override); | |
3648d8a1 | 678 | wpabuf_free(conf->sae_commit_override); |
bc02843e JM |
679 | #endif /* CONFIG_TESTING_OPTIONS */ |
680 | ||
964f64e2 | 681 | os_free(conf->no_probe_resp_if_seen_on); |
0e2412d0 | 682 | os_free(conf->no_auth_if_seen_on); |
964f64e2 | 683 | |
26bf70e3 JM |
684 | hostapd_config_free_fils_realms(conf); |
685 | ||
56c75495 JM |
686 | #ifdef CONFIG_DPP |
687 | os_free(conf->dpp_connector); | |
688 | wpabuf_free(conf->dpp_netaccesskey); | |
689 | wpabuf_free(conf->dpp_csign); | |
690 | #endif /* CONFIG_DPP */ | |
691 | ||
9be19d0b | 692 | hostapd_config_free_sae_passwords(conf); |
2377c1ca | 693 | |
ebd79f07 | 694 | os_free(conf); |
6fc6879b JM |
695 | } |
696 | ||
697 | ||
1c6e69cc JM |
698 | /** |
699 | * hostapd_config_free - Free hostapd configuration | |
700 | * @conf: Configuration data from hostapd_config_read(). | |
701 | */ | |
6fc6879b JM |
702 | void hostapd_config_free(struct hostapd_config *conf) |
703 | { | |
704 | size_t i; | |
705 | ||
706 | if (conf == NULL) | |
707 | return; | |
708 | ||
709 | for (i = 0; i < conf->num_bss; i++) | |
ebd79f07 | 710 | hostapd_config_free_bss(conf->bss[i]); |
6fc6879b | 711 | os_free(conf->bss); |
79d6c85f JM |
712 | os_free(conf->supported_rates); |
713 | os_free(conf->basic_rates); | |
857d9422 | 714 | os_free(conf->acs_ch_list.range); |
0ecff8d7 | 715 | os_free(conf->driver_params); |
68fa00c3 JM |
716 | #ifdef CONFIG_ACS |
717 | os_free(conf->acs_chan_bias); | |
718 | #endif /* CONFIG_ACS */ | |
74e982d8 DS |
719 | wpabuf_free(conf->lci); |
720 | wpabuf_free(conf->civic); | |
6fc6879b JM |
721 | |
722 | os_free(conf); | |
723 | } | |
724 | ||
725 | ||
1c6e69cc JM |
726 | /** |
727 | * hostapd_maclist_found - Find a MAC address from a list | |
728 | * @list: MAC address list | |
729 | * @num_entries: Number of addresses in the list | |
730 | * @addr: Address to search for | |
731 | * @vlan_id: Buffer for returning VLAN ID or %NULL if not needed | |
732 | * Returns: 1 if address is in the list or 0 if not. | |
733 | * | |
734 | * Perform a binary search for given MAC address from a pre-sorted list. | |
735 | */ | |
271d2830 | 736 | int hostapd_maclist_found(struct mac_acl_entry *list, int num_entries, |
1889af2e | 737 | const u8 *addr, struct vlan_description *vlan_id) |
6fc6879b JM |
738 | { |
739 | int start, end, middle, res; | |
740 | ||
741 | start = 0; | |
742 | end = num_entries - 1; | |
743 | ||
744 | while (start <= end) { | |
745 | middle = (start + end) / 2; | |
271d2830 JM |
746 | res = os_memcmp(list[middle].addr, addr, ETH_ALEN); |
747 | if (res == 0) { | |
748 | if (vlan_id) | |
749 | *vlan_id = list[middle].vlan_id; | |
6fc6879b | 750 | return 1; |
271d2830 | 751 | } |
6fc6879b JM |
752 | if (res < 0) |
753 | start = middle + 1; | |
754 | else | |
755 | end = middle - 1; | |
756 | } | |
757 | ||
758 | return 0; | |
759 | } | |
760 | ||
761 | ||
762 | int hostapd_rate_found(int *list, int rate) | |
763 | { | |
764 | int i; | |
765 | ||
766 | if (list == NULL) | |
767 | return 0; | |
768 | ||
769 | for (i = 0; list[i] >= 0; i++) | |
770 | if (list[i] == rate) | |
771 | return 1; | |
772 | ||
773 | return 0; | |
774 | } | |
775 | ||
776 | ||
1889af2e MB |
777 | int hostapd_vlan_valid(struct hostapd_vlan *vlan, |
778 | struct vlan_description *vlan_desc) | |
6fc6879b JM |
779 | { |
780 | struct hostapd_vlan *v = vlan; | |
8e44c192 | 781 | int i; |
1889af2e | 782 | |
8e44c192 | 783 | if (!vlan_desc->notempty || vlan_desc->untagged < 0 || |
1889af2e MB |
784 | vlan_desc->untagged > MAX_VLAN_ID) |
785 | return 0; | |
8e44c192 MB |
786 | for (i = 0; i < MAX_NUM_TAGGED_VLAN; i++) { |
787 | if (vlan_desc->tagged[i] < 0 || | |
788 | vlan_desc->tagged[i] > MAX_VLAN_ID) | |
789 | return 0; | |
790 | } | |
791 | if (!vlan_desc->untagged && !vlan_desc->tagged[0]) | |
792 | return 0; | |
1889af2e | 793 | |
6fc6879b | 794 | while (v) { |
1889af2e MB |
795 | if (!vlan_compare(&v->vlan_desc, vlan_desc) || |
796 | v->vlan_id == VLAN_ID_WILDCARD) | |
80ebfd95 MB |
797 | return 1; |
798 | v = v->next; | |
799 | } | |
800 | return 0; | |
801 | } | |
802 | ||
803 | ||
804 | const char * hostapd_get_vlan_id_ifname(struct hostapd_vlan *vlan, int vlan_id) | |
805 | { | |
806 | struct hostapd_vlan *v = vlan; | |
807 | while (v) { | |
808 | if (v->vlan_id == vlan_id) | |
6fc6879b JM |
809 | return v->ifname; |
810 | v = v->next; | |
811 | } | |
812 | return NULL; | |
813 | } | |
814 | ||
815 | ||
816 | const u8 * hostapd_get_psk(const struct hostapd_bss_config *conf, | |
759fd76b JM |
817 | const u8 *addr, const u8 *p2p_dev_addr, |
818 | const u8 *prev_psk) | |
6fc6879b JM |
819 | { |
820 | struct hostapd_wpa_psk *psk; | |
821 | int next_ok = prev_psk == NULL; | |
822 | ||
dc87541e | 823 | if (p2p_dev_addr && !is_zero_ether_addr(p2p_dev_addr)) { |
759fd76b JM |
824 | wpa_printf(MSG_DEBUG, "Searching a PSK for " MACSTR |
825 | " p2p_dev_addr=" MACSTR " prev_psk=%p", | |
826 | MAC2STR(addr), MAC2STR(p2p_dev_addr), prev_psk); | |
dc87541e | 827 | addr = NULL; /* Use P2P Device Address for matching */ |
759fd76b JM |
828 | } else { |
829 | wpa_printf(MSG_DEBUG, "Searching a PSK for " MACSTR | |
830 | " prev_psk=%p", | |
831 | MAC2STR(addr), prev_psk); | |
832 | } | |
833 | ||
6fc6879b JM |
834 | for (psk = conf->ssid.wpa_psk; psk != NULL; psk = psk->next) { |
835 | if (next_ok && | |
759fd76b JM |
836 | (psk->group || |
837 | (addr && os_memcmp(psk->addr, addr, ETH_ALEN) == 0) || | |
838 | (!addr && p2p_dev_addr && | |
839 | os_memcmp(psk->p2p_dev_addr, p2p_dev_addr, ETH_ALEN) == | |
840 | 0))) | |
6fc6879b JM |
841 | return psk->psk; |
842 | ||
843 | if (psk->psk == prev_psk) | |
844 | next_ok = 1; | |
845 | } | |
846 | ||
847 | return NULL; | |
848 | } | |
eff0fd1e JM |
849 | |
850 | ||
851 | static int hostapd_config_check_bss(struct hostapd_bss_config *bss, | |
08081ad8 JM |
852 | struct hostapd_config *conf, |
853 | int full_config) | |
eff0fd1e | 854 | { |
08081ad8 | 855 | if (full_config && bss->ieee802_1x && !bss->eap_server && |
eff0fd1e JM |
856 | !bss->radius->auth_servers) { |
857 | wpa_printf(MSG_ERROR, "Invalid IEEE 802.1X configuration (no " | |
858 | "EAP authenticator configured)."); | |
859 | return -1; | |
860 | } | |
861 | ||
862 | if (bss->wpa) { | |
863 | int wep, i; | |
864 | ||
865 | wep = bss->default_wep_key_len > 0 || | |
866 | bss->individual_wep_key_len > 0; | |
867 | for (i = 0; i < NUM_WEP_KEYS; i++) { | |
868 | if (bss->ssid.wep.keys_set) { | |
869 | wep = 1; | |
870 | break; | |
871 | } | |
872 | } | |
873 | ||
874 | if (wep) { | |
875 | wpa_printf(MSG_ERROR, "WEP configuration in a WPA network is not supported"); | |
876 | return -1; | |
877 | } | |
878 | } | |
879 | ||
08081ad8 JM |
880 | if (full_config && bss->wpa && |
881 | bss->wpa_psk_radius != PSK_RADIUS_IGNORED && | |
eff0fd1e JM |
882 | bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH) { |
883 | wpa_printf(MSG_ERROR, "WPA-PSK using RADIUS enabled, but no " | |
884 | "RADIUS checking (macaddr_acl=2) enabled."); | |
885 | return -1; | |
886 | } | |
887 | ||
08081ad8 | 888 | if (full_config && bss->wpa && (bss->wpa_key_mgmt & WPA_KEY_MGMT_PSK) && |
eff0fd1e JM |
889 | bss->ssid.wpa_psk == NULL && bss->ssid.wpa_passphrase == NULL && |
890 | bss->ssid.wpa_psk_file == NULL && | |
891 | (bss->wpa_psk_radius != PSK_RADIUS_REQUIRED || | |
892 | bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH)) { | |
893 | wpa_printf(MSG_ERROR, "WPA-PSK enabled, but PSK or passphrase " | |
894 | "is not configured."); | |
895 | return -1; | |
896 | } | |
897 | ||
902c07a7 | 898 | if (full_config && !is_zero_ether_addr(bss->bssid)) { |
eff0fd1e JM |
899 | size_t i; |
900 | ||
901 | for (i = 0; i < conf->num_bss; i++) { | |
902 | if (conf->bss[i] != bss && | |
903 | (hostapd_mac_comp(conf->bss[i]->bssid, | |
904 | bss->bssid) == 0)) { | |
905 | wpa_printf(MSG_ERROR, "Duplicate BSSID " MACSTR | |
906 | " on interface '%s' and '%s'.", | |
907 | MAC2STR(bss->bssid), | |
908 | conf->bss[i]->iface, bss->iface); | |
909 | return -1; | |
910 | } | |
911 | } | |
912 | } | |
913 | ||
4ec1fd8e | 914 | #ifdef CONFIG_IEEE80211R_AP |
08081ad8 | 915 | if (full_config && wpa_key_mgmt_ft(bss->wpa_key_mgmt) && |
eff0fd1e JM |
916 | (bss->nas_identifier == NULL || |
917 | os_strlen(bss->nas_identifier) < 1 || | |
918 | os_strlen(bss->nas_identifier) > FT_R0KH_ID_MAX_LEN)) { | |
919 | wpa_printf(MSG_ERROR, "FT (IEEE 802.11r) requires " | |
920 | "nas_identifier to be configured as a 1..48 octet " | |
921 | "string"); | |
922 | return -1; | |
923 | } | |
4ec1fd8e | 924 | #endif /* CONFIG_IEEE80211R_AP */ |
eff0fd1e JM |
925 | |
926 | #ifdef CONFIG_IEEE80211N | |
08081ad8 JM |
927 | if (full_config && conf->ieee80211n && |
928 | conf->hw_mode == HOSTAPD_MODE_IEEE80211B) { | |
eff0fd1e JM |
929 | bss->disable_11n = 1; |
930 | wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) in 11b mode is not " | |
8c6f4a5a | 931 | "allowed, disabling HT capabilities"); |
eff0fd1e JM |
932 | } |
933 | ||
08081ad8 | 934 | if (full_config && conf->ieee80211n && |
eff0fd1e JM |
935 | bss->ssid.security_policy == SECURITY_STATIC_WEP) { |
936 | bss->disable_11n = 1; | |
937 | wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) with WEP is not " | |
938 | "allowed, disabling HT capabilities"); | |
939 | } | |
940 | ||
08081ad8 | 941 | if (full_config && conf->ieee80211n && bss->wpa && |
eff0fd1e | 942 | !(bss->wpa_pairwise & WPA_CIPHER_CCMP) && |
30675c34 JM |
943 | !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP | |
944 | WPA_CIPHER_CCMP_256 | WPA_CIPHER_GCMP_256))) | |
945 | { | |
eff0fd1e JM |
946 | bss->disable_11n = 1; |
947 | wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) with WPA/WPA2 " | |
948 | "requires CCMP/GCMP to be enabled, disabling HT " | |
949 | "capabilities"); | |
950 | } | |
951 | #endif /* CONFIG_IEEE80211N */ | |
952 | ||
551817a5 WG |
953 | #ifdef CONFIG_IEEE80211AC |
954 | if (full_config && conf->ieee80211ac && | |
955 | bss->ssid.security_policy == SECURITY_STATIC_WEP) { | |
956 | bss->disable_11ac = 1; | |
957 | wpa_printf(MSG_ERROR, | |
958 | "VHT (IEEE 802.11ac) with WEP is not allowed, disabling VHT capabilities"); | |
959 | } | |
59d7cff7 FM |
960 | |
961 | if (full_config && conf->ieee80211ac && bss->wpa && | |
962 | !(bss->wpa_pairwise & WPA_CIPHER_CCMP) && | |
963 | !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP | | |
964 | WPA_CIPHER_CCMP_256 | WPA_CIPHER_GCMP_256))) | |
965 | { | |
966 | bss->disable_11ac = 1; | |
967 | wpa_printf(MSG_ERROR, | |
968 | "VHT (IEEE 802.11ac) with WPA/WPA2 requires CCMP/GCMP to be enabled, disabling VHT capabilities"); | |
969 | } | |
551817a5 WG |
970 | #endif /* CONFIG_IEEE80211AC */ |
971 | ||
c201f93a | 972 | #ifdef CONFIG_WPS |
08081ad8 | 973 | if (full_config && bss->wps_state && bss->ignore_broadcast_ssid) { |
eff0fd1e JM |
974 | wpa_printf(MSG_INFO, "WPS: ignore_broadcast_ssid " |
975 | "configuration forced WPS to be disabled"); | |
976 | bss->wps_state = 0; | |
977 | } | |
978 | ||
08081ad8 JM |
979 | if (full_config && bss->wps_state && |
980 | bss->ssid.wep.keys_set && bss->wpa == 0) { | |
eff0fd1e JM |
981 | wpa_printf(MSG_INFO, "WPS: WEP configuration forced WPS to be " |
982 | "disabled"); | |
983 | bss->wps_state = 0; | |
984 | } | |
985 | ||
08081ad8 | 986 | if (full_config && bss->wps_state && bss->wpa && |
eff0fd1e | 987 | (!(bss->wpa & 2) || |
a2660890 SSG |
988 | !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP | |
989 | WPA_CIPHER_CCMP_256 | | |
990 | WPA_CIPHER_GCMP_256)))) { | |
eff0fd1e | 991 | wpa_printf(MSG_INFO, "WPS: WPA/TKIP configuration without " |
01a02593 | 992 | "WPA2/CCMP/GCMP forced WPS to be disabled"); |
eff0fd1e JM |
993 | bss->wps_state = 0; |
994 | } | |
c201f93a | 995 | #endif /* CONFIG_WPS */ |
eff0fd1e JM |
996 | |
997 | #ifdef CONFIG_HS20 | |
08081ad8 | 998 | if (full_config && bss->hs20 && |
eff0fd1e | 999 | (!(bss->wpa & 2) || |
30675c34 JM |
1000 | !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP | |
1001 | WPA_CIPHER_CCMP_256 | | |
1002 | WPA_CIPHER_GCMP_256)))) { | |
eff0fd1e JM |
1003 | wpa_printf(MSG_ERROR, "HS 2.0: WPA2-Enterprise/CCMP " |
1004 | "configuration is required for Hotspot 2.0 " | |
1005 | "functionality"); | |
1006 | return -1; | |
1007 | } | |
1008 | #endif /* CONFIG_HS20 */ | |
1009 | ||
4c572281 JM |
1010 | #ifdef CONFIG_MBO |
1011 | if (full_config && bss->mbo_enabled && (bss->wpa & 2) && | |
1012 | bss->ieee80211w == NO_MGMT_FRAME_PROTECTION) { | |
1013 | wpa_printf(MSG_ERROR, | |
1014 | "MBO: PMF needs to be enabled whenever using WPA2 with MBO"); | |
1015 | return -1; | |
1016 | } | |
1017 | #endif /* CONFIG_MBO */ | |
1018 | ||
9c55fdb0 MV |
1019 | #ifdef CONFIG_OCV |
1020 | if (full_config && bss->ieee80211w == NO_MGMT_FRAME_PROTECTION && | |
1021 | bss->ocv) { | |
1022 | wpa_printf(MSG_ERROR, | |
1023 | "OCV: PMF needs to be enabled whenever using OCV"); | |
1024 | return -1; | |
1025 | } | |
1026 | #endif /* CONFIG_OCV */ | |
1027 | ||
eff0fd1e JM |
1028 | return 0; |
1029 | } | |
1030 | ||
1031 | ||
8884ce03 MM |
1032 | static int hostapd_config_check_cw(struct hostapd_config *conf, int queue) |
1033 | { | |
1034 | int tx_cwmin = conf->tx_queue[queue].cwmin; | |
1035 | int tx_cwmax = conf->tx_queue[queue].cwmax; | |
1036 | int ac_cwmin = conf->wmm_ac_params[queue].cwmin; | |
1037 | int ac_cwmax = conf->wmm_ac_params[queue].cwmax; | |
1038 | ||
1039 | if (tx_cwmin > tx_cwmax) { | |
1040 | wpa_printf(MSG_ERROR, | |
1041 | "Invalid TX queue cwMin/cwMax values. cwMin(%d) greater than cwMax(%d)", | |
1042 | tx_cwmin, tx_cwmax); | |
1043 | return -1; | |
1044 | } | |
1045 | if (ac_cwmin > ac_cwmax) { | |
1046 | wpa_printf(MSG_ERROR, | |
1047 | "Invalid WMM AC cwMin/cwMax values. cwMin(%d) greater than cwMax(%d)", | |
1048 | ac_cwmin, ac_cwmax); | |
1049 | return -1; | |
1050 | } | |
1051 | return 0; | |
1052 | } | |
1053 | ||
1054 | ||
08081ad8 | 1055 | int hostapd_config_check(struct hostapd_config *conf, int full_config) |
eff0fd1e JM |
1056 | { |
1057 | size_t i; | |
1058 | ||
08081ad8 JM |
1059 | if (full_config && conf->ieee80211d && |
1060 | (!conf->country[0] || !conf->country[1])) { | |
eff0fd1e JM |
1061 | wpa_printf(MSG_ERROR, "Cannot enable IEEE 802.11d without " |
1062 | "setting the country_code"); | |
1063 | return -1; | |
1064 | } | |
1065 | ||
08081ad8 | 1066 | if (full_config && conf->ieee80211h && !conf->ieee80211d) { |
eff0fd1e JM |
1067 | wpa_printf(MSG_ERROR, "Cannot enable IEEE 802.11h without " |
1068 | "IEEE 802.11d enabled"); | |
1069 | return -1; | |
1070 | } | |
1071 | ||
e0392f82 S |
1072 | if (full_config && conf->local_pwr_constraint != -1 && |
1073 | !conf->ieee80211d) { | |
1074 | wpa_printf(MSG_ERROR, "Cannot add Power Constraint element without Country element"); | |
1075 | return -1; | |
1076 | } | |
1077 | ||
3d7ad2f6 C |
1078 | if (full_config && conf->spectrum_mgmt_required && |
1079 | conf->local_pwr_constraint == -1) { | |
1080 | wpa_printf(MSG_ERROR, "Cannot set Spectrum Management bit without Country and Power Constraint elements"); | |
1081 | return -1; | |
1082 | } | |
1083 | ||
8884ce03 MM |
1084 | for (i = 0; i < NUM_TX_QUEUES; i++) { |
1085 | if (hostapd_config_check_cw(conf, i)) | |
1086 | return -1; | |
1087 | } | |
1088 | ||
eff0fd1e | 1089 | for (i = 0; i < conf->num_bss; i++) { |
08081ad8 | 1090 | if (hostapd_config_check_bss(conf->bss[i], conf, full_config)) |
eff0fd1e JM |
1091 | return -1; |
1092 | } | |
1093 | ||
1094 | return 0; | |
1095 | } | |
1096 | ||
1097 | ||
5d67bf15 JM |
1098 | void hostapd_set_security_params(struct hostapd_bss_config *bss, |
1099 | int full_config) | |
eff0fd1e JM |
1100 | { |
1101 | if (bss->individual_wep_key_len == 0) { | |
1102 | /* individual keys are not use; can use key idx0 for | |
1103 | * broadcast keys */ | |
1104 | bss->broadcast_key_idx_min = 0; | |
1105 | } | |
1106 | ||
1107 | if ((bss->wpa & 2) && bss->rsn_pairwise == 0) | |
1108 | bss->rsn_pairwise = bss->wpa_pairwise; | |
27781c0a JM |
1109 | if (bss->group_cipher) |
1110 | bss->wpa_group = bss->group_cipher; | |
1111 | else | |
1112 | bss->wpa_group = wpa_select_ap_group_cipher(bss->wpa, | |
1113 | bss->wpa_pairwise, | |
1114 | bss->rsn_pairwise); | |
90f837b0 JM |
1115 | if (!bss->wpa_group_rekey_set) |
1116 | bss->wpa_group_rekey = bss->wpa_group == WPA_CIPHER_TKIP ? | |
1117 | 600 : 86400; | |
eff0fd1e | 1118 | |
5d67bf15 JM |
1119 | if (full_config) { |
1120 | bss->radius->auth_server = bss->radius->auth_servers; | |
1121 | bss->radius->acct_server = bss->radius->acct_servers; | |
1122 | } | |
eff0fd1e JM |
1123 | |
1124 | if (bss->wpa && bss->ieee802_1x) { | |
1125 | bss->ssid.security_policy = SECURITY_WPA; | |
1126 | } else if (bss->wpa) { | |
1127 | bss->ssid.security_policy = SECURITY_WPA_PSK; | |
1128 | } else if (bss->ieee802_1x) { | |
1129 | int cipher = WPA_CIPHER_NONE; | |
1130 | bss->ssid.security_policy = SECURITY_IEEE_802_1X; | |
1131 | bss->ssid.wep.default_len = bss->default_wep_key_len; | |
13a3a20d | 1132 | if (full_config && bss->default_wep_key_len) { |
eff0fd1e JM |
1133 | cipher = bss->default_wep_key_len >= 13 ? |
1134 | WPA_CIPHER_WEP104 : WPA_CIPHER_WEP40; | |
13a3a20d JM |
1135 | } else if (full_config && bss->ssid.wep.keys_set) { |
1136 | if (bss->ssid.wep.len[0] >= 13) | |
1137 | cipher = WPA_CIPHER_WEP104; | |
1138 | else | |
1139 | cipher = WPA_CIPHER_WEP40; | |
1140 | } | |
eff0fd1e JM |
1141 | bss->wpa_group = cipher; |
1142 | bss->wpa_pairwise = cipher; | |
1143 | bss->rsn_pairwise = cipher; | |
13a3a20d JM |
1144 | if (full_config) |
1145 | bss->wpa_key_mgmt = WPA_KEY_MGMT_IEEE8021X_NO_WPA; | |
eff0fd1e JM |
1146 | } else if (bss->ssid.wep.keys_set) { |
1147 | int cipher = WPA_CIPHER_WEP40; | |
1148 | if (bss->ssid.wep.len[0] >= 13) | |
1149 | cipher = WPA_CIPHER_WEP104; | |
1150 | bss->ssid.security_policy = SECURITY_STATIC_WEP; | |
1151 | bss->wpa_group = cipher; | |
1152 | bss->wpa_pairwise = cipher; | |
1153 | bss->rsn_pairwise = cipher; | |
13a3a20d JM |
1154 | if (full_config) |
1155 | bss->wpa_key_mgmt = WPA_KEY_MGMT_NONE; | |
a14896e8 JM |
1156 | } else if (bss->osen) { |
1157 | bss->ssid.security_policy = SECURITY_OSEN; | |
1158 | bss->wpa_group = WPA_CIPHER_CCMP; | |
1159 | bss->wpa_pairwise = 0; | |
1160 | bss->rsn_pairwise = WPA_CIPHER_CCMP; | |
eff0fd1e JM |
1161 | } else { |
1162 | bss->ssid.security_policy = SECURITY_PLAINTEXT; | |
29767152 JM |
1163 | if (full_config) { |
1164 | bss->wpa_group = WPA_CIPHER_NONE; | |
1165 | bss->wpa_pairwise = WPA_CIPHER_NONE; | |
1166 | bss->rsn_pairwise = WPA_CIPHER_NONE; | |
13a3a20d | 1167 | bss->wpa_key_mgmt = WPA_KEY_MGMT_NONE; |
29767152 | 1168 | } |
eff0fd1e JM |
1169 | } |
1170 | } | |
42d30863 JM |
1171 | |
1172 | ||
1173 | int hostapd_sae_pw_id_in_use(struct hostapd_bss_config *conf) | |
1174 | { | |
1175 | int with_id = 0, without_id = 0; | |
1176 | struct sae_password_entry *pw; | |
1177 | ||
1178 | if (conf->ssid.wpa_passphrase) | |
1179 | without_id = 1; | |
1180 | ||
1181 | for (pw = conf->sae_passwords; pw; pw = pw->next) { | |
1182 | if (pw->identifier) | |
1183 | with_id = 1; | |
1184 | else | |
1185 | without_id = 1; | |
1186 | if (with_id && without_id) | |
1187 | break; | |
1188 | } | |
1189 | ||
1190 | if (with_id && !without_id) | |
1191 | return 2; | |
1192 | return with_id; | |
1193 | } |