1 /*
2 * hostapd / Configuration helper functions
3 * Copyright (c) 2003-2024, Jouni Malinen <j@w1.fi>
4 *
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
7 */
8
9 #include "utils/includes.h"
10
11 #include "utils/common.h"
12 #include "crypto/sha1.h"
13 #include "crypto/tls.h"
14 #include "radius/radius_client.h"
15 #include "common/ieee802_11_defs.h"
16 #include "common/ieee802_1x_defs.h"
17 #include "common/eapol_common.h"
18 /* No DHCP snooping for Zephyr */
19 #if !defined(__ZEPHYR__)
20 #include "common/dhcp.h"
21 #endif /* __ZEPHYR__ */
22 #include "common/sae.h"
23 #include "eap_common/eap_wsc_common.h"
24 #include "eap_server/eap.h"
25 #include "wpa_auth.h"
26 #include "sta_info.h"
27 #include "airtime_policy.h"
28 #include "ap_config.h"
29
30
hostapd_config_free_vlan(struct hostapd_bss_config * bss)31 static void hostapd_config_free_vlan(struct hostapd_bss_config *bss)
32 {
33 struct hostapd_vlan *vlan, *prev;
34
35 vlan = bss->vlan;
36 prev = NULL;
37 while (vlan) {
38 prev = vlan;
39 vlan = vlan->next;
40 os_free(prev);
41 }
42
43 bss->vlan = NULL;
44 }
45
46
47 #ifndef DEFAULT_WPA_DISABLE_EAPOL_KEY_RETRIES
48 #define DEFAULT_WPA_DISABLE_EAPOL_KEY_RETRIES 0
49 #endif /* DEFAULT_WPA_DISABLE_EAPOL_KEY_RETRIES */
50
hostapd_config_defaults_bss(struct hostapd_bss_config * bss)51 void hostapd_config_defaults_bss(struct hostapd_bss_config *bss)
52 {
53 dl_list_init(&bss->anqp_elem);
54
55 bss->logger_syslog_level = HOSTAPD_LEVEL_INFO;
56 bss->logger_stdout_level = HOSTAPD_LEVEL_INFO;
57 bss->logger_syslog = (unsigned int) -1;
58 bss->logger_stdout = (unsigned int) -1;
59
60 #ifdef CONFIG_WEP
61 bss->auth_algs = WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED;
62
63 bss->wep_rekeying_period = 300;
64 /* use key0 in individual key and key1 in broadcast key */
65 bss->broadcast_key_idx_min = 1;
66 bss->broadcast_key_idx_max = 2;
67 #else /* CONFIG_WEP */
68 bss->auth_algs = WPA_AUTH_ALG_OPEN;
69 #endif /* CONFIG_WEP */
70 bss->eap_reauth_period = 3600;
71
72 bss->wpa_group_rekey = 600;
73 bss->wpa_gmk_rekey = 86400;
74 bss->wpa_deny_ptk0_rekey = PTK0_REKEY_ALLOW_ALWAYS;
75 bss->wpa_group_update_count = 4;
76 bss->wpa_pairwise_update_count = 4;
77 bss->wpa_disable_eapol_key_retries =
78 DEFAULT_WPA_DISABLE_EAPOL_KEY_RETRIES;
79 bss->wpa_key_mgmt = WPA_KEY_MGMT_PSK;
80 #ifdef CONFIG_NO_TKIP
81 bss->wpa_pairwise = WPA_CIPHER_CCMP;
82 bss->wpa_group = WPA_CIPHER_CCMP;
83 #else /* CONFIG_NO_TKIP */
84 bss->wpa_pairwise = WPA_CIPHER_TKIP;
85 bss->wpa_group = WPA_CIPHER_TKIP;
86 #endif /* CONFIG_NO_TKIP */
87 bss->rsn_pairwise = 0;
88
89 bss->max_num_sta = MAX_STA_COUNT;
90
91 bss->dtim_period = 2;
92
93 bss->radius_server_auth_port = 1812;
94 bss->eap_sim_db_timeout = 1;
95 bss->eap_sim_id = 3;
96 bss->eap_sim_aka_fast_reauth_limit = 1000;
97 bss->ap_max_inactivity = AP_MAX_INACTIVITY;
98 bss->bss_max_idle = 1;
99 bss->eapol_version = EAPOL_VERSION;
100
101 bss->max_listen_interval = 65535;
102
103 bss->pwd_group = 19; /* ECC: GF(p=256) */
104
105 bss->assoc_sa_query_max_timeout = 1000;
106 bss->assoc_sa_query_retry_timeout = 201;
107 bss->group_mgmt_cipher = WPA_CIPHER_AES_128_CMAC;
108 #ifdef EAP_SERVER_FAST
109 /* both anonymous and authenticated provisioning */
110 bss->eap_fast_prov = 3;
111 bss->pac_key_lifetime = 7 * 24 * 60 * 60;
112 bss->pac_key_refresh_time = 1 * 24 * 60 * 60;
113 #endif /* EAP_SERVER_FAST */
114
115 /* Set to -1 as defaults depends on HT in setup */
116 bss->wmm_enabled = -1;
117
118 #ifdef CONFIG_IEEE80211R_AP
119 bss->ft_over_ds = 1;
120 bss->rkh_pos_timeout = 86400;
121 bss->rkh_neg_timeout = 60;
122 bss->rkh_pull_timeout = 1000;
123 bss->rkh_pull_retries = 4;
124 bss->r0_key_lifetime = 1209600;
125 #endif /* CONFIG_IEEE80211R_AP */
126
127 bss->radius_das_time_window = 300;
128 bss->radius_require_message_authenticator = 1;
129
130 bss->anti_clogging_threshold = 5;
131 bss->sae_sync = 3;
132
133 bss->gas_frag_limit = 1400;
134
135 #ifdef CONFIG_FILS
136 dl_list_init(&bss->fils_realms);
137 bss->fils_hlp_wait_time = 30;
138 bss->dhcp_server_port = DHCP_SERVER_PORT;
139 bss->dhcp_relay_port = DHCP_SERVER_PORT;
140 bss->fils_discovery_min_int = 20;
141 #endif /* CONFIG_FILS */
142
143 bss->broadcast_deauth = 1;
144
145 #ifdef CONFIG_MBO
146 bss->mbo_cell_data_conn_pref = -1;
147 #endif /* CONFIG_MBO */
148
149 /* Disable TLS v1.3 by default for now to avoid interoperability issue.
150 * This can be enabled by default once the implementation has been fully
151 * completed and tested with other implementations. */
152 bss->tls_flags = TLS_CONN_DISABLE_TLSv1_3;
153
154 bss->max_auth_rounds = 100;
155 bss->max_auth_rounds_short = 50;
156
157 bss->send_probe_response = 1;
158
159 #ifdef CONFIG_HS20
160 bss->hs20_release = (HS20_VERSION >> 4) + 1;
161 #endif /* CONFIG_HS20 */
162
163 #ifdef CONFIG_MACSEC
164 bss->mka_priority = DEFAULT_PRIO_NOT_KEY_SERVER;
165 bss->macsec_port = 1;
166 #endif /* CONFIG_MACSEC */
167
168 /* Default to strict CRL checking. */
169 bss->check_crl_strict = 1;
170
171 bss->multi_ap_profile = MULTI_AP_PROFILE_2;
172
173 #ifdef CONFIG_TESTING_OPTIONS
174 bss->sae_commit_status = -1;
175 bss->test_assoc_comeback_type = -1;
176 #endif /* CONFIG_TESTING_OPTIONS */
177
178 #ifdef CONFIG_PASN
179 /* comeback after 10 TUs */
180 bss->pasn_comeback_after = 10;
181 bss->pasn_noauth = 1;
182 #endif /* CONFIG_PASN */
183 }
184
185
hostapd_config_defaults(void)186 struct hostapd_config * hostapd_config_defaults(void)
187 {
188 #define ecw2cw(ecw) ((1 << (ecw)) - 1)
189
190 struct hostapd_config *conf;
191 struct hostapd_bss_config *bss;
192 const int aCWmin = 4, aCWmax = 10;
193 const struct hostapd_wmm_ac_params ac_bk =
194 { aCWmin, aCWmax, 7, 0, 0 }; /* background traffic */
195 const struct hostapd_wmm_ac_params ac_be =
196 { aCWmin, aCWmax, 3, 0, 0 }; /* best effort traffic */
197 const struct hostapd_wmm_ac_params ac_vi = /* video traffic */
198 { aCWmin - 1, aCWmin, 2, 3008 / 32, 0 };
199 const struct hostapd_wmm_ac_params ac_vo = /* voice traffic */
200 { aCWmin - 2, aCWmin - 1, 2, 1504 / 32, 0 };
201 const struct hostapd_tx_queue_params txq_bk =
202 { 7, ecw2cw(aCWmin), ecw2cw(aCWmax), 0 };
203 const struct hostapd_tx_queue_params txq_be =
204 { 3, ecw2cw(aCWmin), 4 * (ecw2cw(aCWmin) + 1) - 1, 0};
205 const struct hostapd_tx_queue_params txq_vi =
206 { 1, (ecw2cw(aCWmin) + 1) / 2 - 1, ecw2cw(aCWmin), 30};
207 const struct hostapd_tx_queue_params txq_vo =
208 { 1, (ecw2cw(aCWmin) + 1) / 4 - 1,
209 (ecw2cw(aCWmin) + 1) / 2 - 1, 15};
210
211 #undef ecw2cw
212
213 conf = os_zalloc(sizeof(*conf));
214 bss = os_zalloc(sizeof(*bss));
215 if (conf == NULL || bss == NULL) {
216 wpa_printf(MSG_ERROR, "Failed to allocate memory for "
217 "configuration data.");
218 os_free(conf);
219 os_free(bss);
220 return NULL;
221 }
222 conf->bss = os_calloc(1, sizeof(struct hostapd_bss_config *));
223 if (conf->bss == NULL) {
224 os_free(conf);
225 os_free(bss);
226 return NULL;
227 }
228 conf->bss[0] = bss;
229
230 bss->radius = os_zalloc(sizeof(*bss->radius));
231 if (bss->radius == NULL) {
232 os_free(conf->bss);
233 os_free(conf);
234 os_free(bss);
235 return NULL;
236 }
237
238 hostapd_config_defaults_bss(bss);
239
240 conf->num_bss = 1;
241
242 conf->beacon_int = 100;
243 conf->rts_threshold = -2; /* use driver default: 2347 */
244 conf->fragm_threshold = -2; /* user driver default: 2346 */
245 /* Set to invalid value means do not add Power Constraint IE */
246 conf->local_pwr_constraint = -1;
247
248 conf->wmm_ac_params[0] = ac_be;
249 conf->wmm_ac_params[1] = ac_bk;
250 conf->wmm_ac_params[2] = ac_vi;
251 conf->wmm_ac_params[3] = ac_vo;
252
253 conf->tx_queue[0] = txq_vo;
254 conf->tx_queue[1] = txq_vi;
255 conf->tx_queue[2] = txq_be;
256 conf->tx_queue[3] = txq_bk;
257
258 conf->ht_capab = HT_CAP_INFO_SMPS_DISABLED;
259
260 conf->ap_table_max_size = 255;
261 conf->ap_table_expiration_time = 60;
262 conf->track_sta_max_age = 180;
263
264 #ifdef CONFIG_TESTING_OPTIONS
265 conf->ignore_probe_probability = 0.0;
266 conf->ignore_auth_probability = 0.0;
267 conf->ignore_assoc_probability = 0.0;
268 conf->ignore_reassoc_probability = 0.0;
269 conf->corrupt_gtk_rekey_mic_probability = 0.0;
270 conf->ecsa_ie_only = 0;
271 #endif /* CONFIG_TESTING_OPTIONS */
272
273 conf->acs = 0;
274 conf->acs_ch_list.num = 0;
275 #ifdef CONFIG_ACS
276 conf->acs_num_scans = 5;
277 #endif /* CONFIG_ACS */
278
279 #ifdef CONFIG_IEEE80211AX
280 conf->he_op.he_rts_threshold = HE_OPERATION_RTS_THRESHOLD_MASK >>
281 HE_OPERATION_RTS_THRESHOLD_OFFSET;
282 /* Set default basic MCS/NSS set to single stream MCS 0-7 */
283 conf->he_op.he_basic_mcs_nss_set = 0xfffc;
284 conf->he_op.he_bss_color_disabled = 1;
285 conf->he_op.he_bss_color_partial = 0;
286 conf->he_op.he_bss_color = os_random() % 63 + 1;
287 conf->he_op.he_twt_responder = 1;
288 conf->he_6ghz_max_mpdu = 2;
289 conf->he_6ghz_max_ampdu_len_exp = 7;
290 conf->he_6ghz_rx_ant_pat = 1;
291 conf->he_6ghz_tx_ant_pat = 1;
292 conf->he_6ghz_reg_pwr_type = HE_REG_INFO_6GHZ_AP_TYPE_VLP;
293 conf->reg_def_cli_eirp_psd = -1;
294 conf->reg_sub_cli_eirp_psd = -1;
295 conf->reg_def_cli_eirp = -1;
296 #endif /* CONFIG_IEEE80211AX */
297
298 /* The third octet of the country string uses an ASCII space character
299 * by default to indicate that the regulations encompass all
300 * environments for the current frequency band in the country. */
301 conf->country[2] = ' ';
302
303 conf->rssi_reject_assoc_rssi = 0;
304 conf->rssi_reject_assoc_timeout = 30;
305
306 #ifdef CONFIG_AIRTIME_POLICY
307 conf->airtime_update_interval = AIRTIME_DEFAULT_UPDATE_INTERVAL;
308 #endif /* CONFIG_AIRTIME_POLICY */
309
310 hostapd_set_and_check_bw320_offset(conf, 0);
311
312 return conf;
313 }
314
315
hostapd_mac_comp(const void * a,const void * b)316 int hostapd_mac_comp(const void *a, const void *b)
317 {
318 return os_memcmp(a, b, sizeof(macaddr));
319 }
320
321
hostapd_config_read_wpa_psk(const char * fname,struct hostapd_ssid * ssid)322 static int hostapd_config_read_wpa_psk(const char *fname,
323 struct hostapd_ssid *ssid)
324 {
325 FILE *f;
326 char buf[128], *pos;
327 const char *keyid;
328 char *context;
329 char *context2;
330 char *token;
331 char *name;
332 char *value;
333 int line = 0, ret = 0, len, ok;
334 u8 addr[ETH_ALEN];
335 struct hostapd_wpa_psk *psk;
336
337 if (!fname)
338 return 0;
339
340 f = fopen(fname, "r");
341 if (!f) {
342 wpa_printf(MSG_ERROR, "WPA PSK file '%s' not found.", fname);
343 return -1;
344 }
345
346 while (fgets(buf, sizeof(buf), f)) {
347 int vlan_id = 0;
348 int wps = 0;
349
350 line++;
351
352 if (buf[0] == '#')
353 continue;
354 pos = buf;
355 while (*pos != '\0') {
356 if (*pos == '\n') {
357 *pos = '\0';
358 break;
359 }
360 pos++;
361 }
362 if (buf[0] == '\0')
363 continue;
364
365 context = NULL;
366 keyid = NULL;
367 while ((token = str_token(buf, " ", &context))) {
368 if (!os_strchr(token, '='))
369 break;
370 context2 = NULL;
371 name = str_token(token, "=", &context2);
372 if (!name)
373 break;
374 value = str_token(token, "", &context2);
375 if (!value)
376 value = "";
377 if (!os_strcmp(name, "keyid")) {
378 keyid = value;
379 } else if (!os_strcmp(name, "wps")) {
380 wps = atoi(value);
381 } else if (!os_strcmp(name, "vlanid")) {
382 vlan_id = atoi(value);
383 } else {
384 wpa_printf(MSG_ERROR,
385 "Unrecognized '%s=%s' on line %d in '%s'",
386 name, value, line, fname);
387 ret = -1;
388 break;
389 }
390 }
391
392 if (ret == -1)
393 break;
394
395 if (!token)
396 token = "";
397 if (hwaddr_aton(token, addr)) {
398 wpa_printf(MSG_ERROR,
399 "Invalid MAC address '%s' on line %d in '%s'",
400 token, line, fname);
401 ret = -1;
402 break;
403 }
404
405 psk = os_zalloc(sizeof(*psk));
406 if (psk == NULL) {
407 wpa_printf(MSG_ERROR, "WPA PSK allocation failed");
408 ret = -1;
409 break;
410 }
411 psk->vlan_id = vlan_id;
412 if (is_zero_ether_addr(addr))
413 psk->group = 1;
414 else
415 os_memcpy(psk->addr, addr, ETH_ALEN);
416
417 pos = str_token(buf, "", &context);
418 if (!pos) {
419 wpa_printf(MSG_ERROR, "No PSK on line %d in '%s'",
420 line, fname);
421 os_free(psk);
422 ret = -1;
423 break;
424 }
425
426 ok = 0;
427 len = os_strlen(pos);
428 if (len == 2 * PMK_LEN &&
429 hexstr2bin(pos, psk->psk, PMK_LEN) == 0)
430 ok = 1;
431 else if (len >= 8 && len < 64 &&
432 pbkdf2_sha1(pos, ssid->ssid, ssid->ssid_len,
433 4096, psk->psk, PMK_LEN) == 0)
434 ok = 1;
435 if (!ok) {
436 wpa_printf(MSG_ERROR,
437 "Invalid PSK '%s' on line %d in '%s'",
438 pos, line, fname);
439 os_free(psk);
440 ret = -1;
441 break;
442 }
443
444 if (keyid) {
445 len = os_strlcpy(psk->keyid, keyid, sizeof(psk->keyid));
446 if ((size_t) len >= sizeof(psk->keyid)) {
447 wpa_printf(MSG_ERROR,
448 "PSK keyid too long on line %d in '%s'",
449 line, fname);
450 os_free(psk);
451 ret = -1;
452 break;
453 }
454 }
455
456 psk->wps = wps;
457
458 psk->next = ssid->wpa_psk;
459 ssid->wpa_psk = psk;
460 }
461
462 fclose(f);
463
464 return ret;
465 }
466
467
hostapd_derive_psk(struct hostapd_ssid * ssid)468 static int hostapd_derive_psk(struct hostapd_ssid *ssid)
469 {
470 ssid->wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
471 if (ssid->wpa_psk == NULL) {
472 wpa_printf(MSG_ERROR, "Unable to alloc space for PSK");
473 return -1;
474 }
475 wpa_hexdump_ascii(MSG_DEBUG, "SSID",
476 (u8 *) ssid->ssid, ssid->ssid_len);
477 wpa_hexdump_ascii_key(MSG_DEBUG, "PSK (ASCII passphrase)",
478 (u8 *) ssid->wpa_passphrase,
479 os_strlen(ssid->wpa_passphrase));
480 if (pbkdf2_sha1(ssid->wpa_passphrase,
481 ssid->ssid, ssid->ssid_len,
482 4096, ssid->wpa_psk->psk, PMK_LEN) != 0) {
483 wpa_printf(MSG_ERROR, "Error in pbkdf2_sha1()");
484 return -1;
485 }
486 wpa_hexdump_key(MSG_DEBUG, "PSK (from passphrase)",
487 ssid->wpa_psk->psk, PMK_LEN);
488 return 0;
489 }
490
491
hostapd_setup_sae_pt(struct hostapd_bss_config * conf)492 int hostapd_setup_sae_pt(struct hostapd_bss_config *conf)
493 {
494 #ifdef CONFIG_SAE
495 struct hostapd_ssid *ssid = &conf->ssid;
496 struct sae_password_entry *pw;
497
498 if ((conf->sae_pwe == SAE_PWE_HUNT_AND_PECK &&
499 !hostapd_sae_pw_id_in_use(conf) &&
500 !wpa_key_mgmt_sae_ext_key(conf->wpa_key_mgmt |
501 conf->rsn_override_key_mgmt |
502 conf->rsn_override_key_mgmt_2) &&
503 !hostapd_sae_pk_in_use(conf)) ||
504 conf->sae_pwe == SAE_PWE_FORCE_HUNT_AND_PECK ||
505 !wpa_key_mgmt_sae(conf->wpa_key_mgmt |
506 conf->rsn_override_key_mgmt |
507 conf->rsn_override_key_mgmt_2))
508 return 0; /* PT not needed */
509
510 sae_deinit_pt(ssid->pt);
511 ssid->pt = NULL;
512 if (ssid->wpa_passphrase) {
513 ssid->pt = sae_derive_pt(conf->sae_groups, ssid->ssid,
514 ssid->ssid_len,
515 (const u8 *) ssid->wpa_passphrase,
516 os_strlen(ssid->wpa_passphrase),
517 NULL);
518 if (!ssid->pt)
519 return -1;
520 }
521
522 for (pw = conf->sae_passwords; pw; pw = pw->next) {
523 sae_deinit_pt(pw->pt);
524 pw->pt = sae_derive_pt(conf->sae_groups, ssid->ssid,
525 ssid->ssid_len,
526 (const u8 *) pw->password,
527 os_strlen(pw->password),
528 pw->identifier);
529 if (!pw->pt)
530 return -1;
531 }
532 #endif /* CONFIG_SAE */
533
534 return 0;
535 }
536
537
hostapd_setup_wpa_psk(struct hostapd_bss_config * conf)538 int hostapd_setup_wpa_psk(struct hostapd_bss_config *conf)
539 {
540 struct hostapd_ssid *ssid = &conf->ssid;
541
542 if (hostapd_setup_sae_pt(conf) < 0)
543 return -1;
544
545 if (ssid->wpa_passphrase != NULL) {
546 if (ssid->wpa_psk != NULL) {
547 wpa_printf(MSG_DEBUG, "Using pre-configured WPA PSK "
548 "instead of passphrase");
549 } else {
550 wpa_printf(MSG_DEBUG, "Deriving WPA PSK based on "
551 "passphrase");
552 if (hostapd_derive_psk(ssid) < 0)
553 return -1;
554 }
555 ssid->wpa_psk->group = 1;
556 }
557
558 return hostapd_config_read_wpa_psk(ssid->wpa_psk_file, &conf->ssid);
559 }
560
561
hostapd_config_free_radius(struct hostapd_radius_server * servers,int num_servers)562 static void hostapd_config_free_radius(struct hostapd_radius_server *servers,
563 int num_servers)
564 {
565 int i;
566
567 for (i = 0; i < num_servers; i++) {
568 os_free(servers[i].shared_secret);
569 os_free(servers[i].ca_cert);
570 os_free(servers[i].client_cert);
571 os_free(servers[i].private_key);
572 os_free(servers[i].private_key_passwd);
573 }
574 os_free(servers);
575 }
576
577
578 struct hostapd_radius_attr *
hostapd_config_get_radius_attr(struct hostapd_radius_attr * attr,u8 type)579 hostapd_config_get_radius_attr(struct hostapd_radius_attr *attr, u8 type)
580 {
581 for (; attr; attr = attr->next) {
582 if (attr->type == type)
583 return attr;
584 }
585 return NULL;
586 }
587
588
hostapd_parse_radius_attr(const char * value)589 struct hostapd_radius_attr * hostapd_parse_radius_attr(const char *value)
590 {
591 const char *pos;
592 char syntax;
593 struct hostapd_radius_attr *attr;
594 size_t len;
595
596 attr = os_zalloc(sizeof(*attr));
597 if (!attr)
598 return NULL;
599
600 attr->type = atoi(value);
601
602 pos = os_strchr(value, ':');
603 if (!pos) {
604 attr->val = wpabuf_alloc(1);
605 if (!attr->val) {
606 os_free(attr);
607 return NULL;
608 }
609 wpabuf_put_u8(attr->val, 0);
610 return attr;
611 }
612
613 pos++;
614 if (pos[0] == '\0' || pos[1] != ':') {
615 os_free(attr);
616 return NULL;
617 }
618 syntax = *pos++;
619 pos++;
620
621 switch (syntax) {
622 case 's':
623 attr->val = wpabuf_alloc_copy(pos, os_strlen(pos));
624 break;
625 case 'x':
626 len = os_strlen(pos);
627 if (len & 1)
628 break;
629 len /= 2;
630 attr->val = wpabuf_alloc(len);
631 if (!attr->val)
632 break;
633 if (hexstr2bin(pos, wpabuf_put(attr->val, len), len) < 0) {
634 wpabuf_free(attr->val);
635 os_free(attr);
636 return NULL;
637 }
638 break;
639 case 'd':
640 attr->val = wpabuf_alloc(4);
641 if (attr->val)
642 wpabuf_put_be32(attr->val, atoi(pos));
643 break;
644 default:
645 os_free(attr);
646 return NULL;
647 }
648
649 if (!attr->val) {
650 os_free(attr);
651 return NULL;
652 }
653
654 return attr;
655 }
656
657
hostapd_config_free_radius_attr(struct hostapd_radius_attr * attr)658 void hostapd_config_free_radius_attr(struct hostapd_radius_attr *attr)
659 {
660 struct hostapd_radius_attr *prev;
661
662 while (attr) {
663 prev = attr;
664 attr = attr->next;
665 wpabuf_free(prev->val);
666 os_free(prev);
667 }
668 }
669
670
hostapd_config_free_eap_user(struct hostapd_eap_user * user)671 void hostapd_config_free_eap_user(struct hostapd_eap_user *user)
672 {
673 hostapd_config_free_radius_attr(user->accept_attr);
674 os_free(user->identity);
675 bin_clear_free(user->password, user->password_len);
676 bin_clear_free(user->salt, user->salt_len);
677 os_free(user);
678 }
679
680
hostapd_config_free_eap_users(struct hostapd_eap_user * user)681 void hostapd_config_free_eap_users(struct hostapd_eap_user *user)
682 {
683 struct hostapd_eap_user *prev_user;
684
685 while (user) {
686 prev_user = user;
687 user = user->next;
688 hostapd_config_free_eap_user(prev_user);
689 }
690 }
691
692
693 #ifdef CONFIG_WEP
hostapd_config_free_wep(struct hostapd_wep_keys * keys)694 static void hostapd_config_free_wep(struct hostapd_wep_keys *keys)
695 {
696 int i;
697 for (i = 0; i < NUM_WEP_KEYS; i++) {
698 bin_clear_free(keys->key[i], keys->len[i]);
699 keys->key[i] = NULL;
700 }
701 }
702 #endif /* CONFIG_WEP */
703
704
hostapd_config_clear_wpa_psk(struct hostapd_wpa_psk ** l)705 void hostapd_config_clear_wpa_psk(struct hostapd_wpa_psk **l)
706 {
707 struct hostapd_wpa_psk *psk, *tmp;
708
709 for (psk = *l; psk;) {
710 tmp = psk;
711 psk = psk->next;
712 bin_clear_free(tmp, sizeof(*tmp));
713 }
714 *l = NULL;
715 }
716
717
718 #ifdef CONFIG_IEEE80211R_AP
719
hostapd_config_clear_rxkhs(struct hostapd_bss_config * conf)720 void hostapd_config_clear_rxkhs(struct hostapd_bss_config *conf)
721 {
722 struct ft_remote_r0kh *r0kh, *r0kh_prev;
723 struct ft_remote_r1kh *r1kh, *r1kh_prev;
724
725 r0kh = conf->r0kh_list;
726 conf->r0kh_list = NULL;
727 while (r0kh) {
728 r0kh_prev = r0kh;
729 r0kh = r0kh->next;
730 os_free(r0kh_prev);
731 }
732
733 r1kh = conf->r1kh_list;
734 conf->r1kh_list = NULL;
735 while (r1kh) {
736 r1kh_prev = r1kh;
737 r1kh = r1kh->next;
738 os_free(r1kh_prev);
739 }
740 }
741
742 #endif /* CONFIG_IEEE80211R_AP */
743
744
hostapd_config_free_anqp_elem(struct hostapd_bss_config * conf)745 static void hostapd_config_free_anqp_elem(struct hostapd_bss_config *conf)
746 {
747 struct anqp_element *elem;
748
749 while ((elem = dl_list_first(&conf->anqp_elem, struct anqp_element,
750 list))) {
751 dl_list_del(&elem->list);
752 wpabuf_free(elem->payload);
753 os_free(elem);
754 }
755 }
756
757
hostapd_config_free_fils_realms(struct hostapd_bss_config * conf)758 static void hostapd_config_free_fils_realms(struct hostapd_bss_config *conf)
759 {
760 #ifdef CONFIG_FILS
761 struct fils_realm *realm;
762
763 while ((realm = dl_list_first(&conf->fils_realms, struct fils_realm,
764 list))) {
765 dl_list_del(&realm->list);
766 os_free(realm);
767 }
768 #endif /* CONFIG_FILS */
769 }
770
771
hostapd_config_free_sae_passwords(struct hostapd_bss_config * conf)772 static void hostapd_config_free_sae_passwords(struct hostapd_bss_config *conf)
773 {
774 struct sae_password_entry *pw, *tmp;
775
776 pw = conf->sae_passwords;
777 conf->sae_passwords = NULL;
778 while (pw) {
779 tmp = pw;
780 pw = pw->next;
781 str_clear_free(tmp->password);
782 os_free(tmp->identifier);
783 #ifdef CONFIG_SAE
784 sae_deinit_pt(tmp->pt);
785 #endif /* CONFIG_SAE */
786 #ifdef CONFIG_SAE_PK
787 sae_deinit_pk(tmp->pk);
788 #endif /* CONFIG_SAE_PK */
789 os_free(tmp);
790 }
791 }
792
793
794 #ifdef CONFIG_DPP2
hostapd_dpp_controller_conf_free(struct dpp_controller_conf * conf)795 static void hostapd_dpp_controller_conf_free(struct dpp_controller_conf *conf)
796 {
797 struct dpp_controller_conf *prev;
798
799 while (conf) {
800 prev = conf;
801 conf = conf->next;
802 os_free(prev);
803 }
804 }
805 #endif /* CONFIG_DPP2 */
806
807
hostapd_config_free_bss(struct hostapd_bss_config * conf)808 void hostapd_config_free_bss(struct hostapd_bss_config *conf)
809 {
810 #if defined(CONFIG_WPS) || defined(CONFIG_HS20)
811 size_t i;
812 #endif
813
814 if (conf == NULL)
815 return;
816
817 hostapd_config_clear_wpa_psk(&conf->ssid.wpa_psk);
818
819 str_clear_free(conf->ssid.wpa_passphrase);
820 os_free(conf->ssid.wpa_psk_file);
821 #ifdef CONFIG_WEP
822 hostapd_config_free_wep(&conf->ssid.wep);
823 #endif /* CONFIG_WEP */
824 #ifdef CONFIG_FULL_DYNAMIC_VLAN
825 os_free(conf->ssid.vlan_tagged_interface);
826 #endif /* CONFIG_FULL_DYNAMIC_VLAN */
827 #ifdef CONFIG_SAE
828 sae_deinit_pt(conf->ssid.pt);
829 #endif /* CONFIG_SAE */
830
831 hostapd_config_free_eap_users(conf->eap_user);
832 os_free(conf->eap_user_sqlite);
833
834 os_free(conf->eap_req_id_text);
835 os_free(conf->erp_domain);
836 os_free(conf->accept_mac);
837 os_free(conf->deny_mac);
838 os_free(conf->nas_identifier);
839 if (conf->radius) {
840 hostapd_config_free_radius(conf->radius->auth_servers,
841 conf->radius->num_auth_servers);
842 hostapd_config_free_radius(conf->radius->acct_servers,
843 conf->radius->num_acct_servers);
844 os_free(conf->radius->force_client_dev);
845 }
846 hostapd_config_free_radius_attr(conf->radius_auth_req_attr);
847 hostapd_config_free_radius_attr(conf->radius_acct_req_attr);
848 os_free(conf->radius_req_attr_sqlite);
849 os_free(conf->rsn_preauth_interfaces);
850 os_free(conf->ctrl_interface);
851 os_free(conf->config_id);
852 os_free(conf->ca_cert);
853 os_free(conf->server_cert);
854 os_free(conf->server_cert2);
855 os_free(conf->private_key);
856 os_free(conf->private_key2);
857 os_free(conf->private_key_passwd);
858 os_free(conf->private_key_passwd2);
859 os_free(conf->check_cert_subject);
860 os_free(conf->ocsp_stapling_response);
861 os_free(conf->ocsp_stapling_response_multi);
862 os_free(conf->dh_file);
863 os_free(conf->openssl_ciphers);
864 os_free(conf->openssl_ecdh_curves);
865 os_free(conf->pac_opaque_encr_key);
866 os_free(conf->eap_fast_a_id);
867 os_free(conf->eap_fast_a_id_info);
868 os_free(conf->eap_sim_db);
869 os_free(conf->imsi_privacy_key);
870 os_free(conf->radius_server_clients);
871 os_free(conf->radius);
872 os_free(conf->radius_das_shared_secret);
873 hostapd_config_free_vlan(conf);
874 os_free(conf->time_zone);
875
876 #ifdef CONFIG_IEEE80211R_AP
877 hostapd_config_clear_rxkhs(conf);
878 os_free(conf->rxkh_file);
879 conf->rxkh_file = NULL;
880 #endif /* CONFIG_IEEE80211R_AP */
881
882 #ifdef CONFIG_WPS
883 os_free(conf->wps_pin_requests);
884 os_free(conf->device_name);
885 os_free(conf->manufacturer);
886 os_free(conf->model_name);
887 os_free(conf->model_number);
888 os_free(conf->serial_number);
889 os_free(conf->config_methods);
890 os_free(conf->ap_pin);
891 os_free(conf->extra_cred);
892 os_free(conf->ap_settings);
893 hostapd_config_clear_wpa_psk(&conf->multi_ap_backhaul_ssid.wpa_psk);
894 str_clear_free(conf->multi_ap_backhaul_ssid.wpa_passphrase);
895 os_free(conf->upnp_iface);
896 os_free(conf->friendly_name);
897 os_free(conf->manufacturer_url);
898 os_free(conf->model_description);
899 os_free(conf->model_url);
900 os_free(conf->upc);
901 for (i = 0; i < MAX_WPS_VENDOR_EXTENSIONS; i++)
902 wpabuf_free(conf->wps_vendor_ext[i]);
903 wpabuf_free(conf->wps_application_ext);
904 wpabuf_free(conf->wps_nfc_dh_pubkey);
905 wpabuf_free(conf->wps_nfc_dh_privkey);
906 wpabuf_free(conf->wps_nfc_dev_pw);
907 #endif /* CONFIG_WPS */
908
909 os_free(conf->roaming_consortium);
910 os_free(conf->venue_name);
911 os_free(conf->venue_url);
912 os_free(conf->nai_realm_data);
913 os_free(conf->network_auth_type);
914 os_free(conf->anqp_3gpp_cell_net);
915 os_free(conf->domain_name);
916 hostapd_config_free_anqp_elem(conf);
917
918 #ifdef CONFIG_RADIUS_TEST
919 os_free(conf->dump_msk_file);
920 #endif /* CONFIG_RADIUS_TEST */
921
922 #ifdef CONFIG_HS20
923 os_free(conf->hs20_oper_friendly_name);
924 os_free(conf->hs20_wan_metrics);
925 os_free(conf->hs20_connection_capability);
926 os_free(conf->hs20_operating_class);
927 os_free(conf->hs20_icons);
928 if (conf->hs20_osu_providers) {
929 for (i = 0; i < conf->hs20_osu_providers_count; i++) {
930 struct hs20_osu_provider *p;
931 size_t j;
932 p = &conf->hs20_osu_providers[i];
933 os_free(p->friendly_name);
934 os_free(p->server_uri);
935 os_free(p->method_list);
936 for (j = 0; j < p->icons_count; j++)
937 os_free(p->icons[j]);
938 os_free(p->icons);
939 os_free(p->osu_nai);
940 os_free(p->osu_nai2);
941 os_free(p->service_desc);
942 }
943 os_free(conf->hs20_osu_providers);
944 }
945 if (conf->hs20_operator_icon) {
946 for (i = 0; i < conf->hs20_operator_icon_count; i++)
947 os_free(conf->hs20_operator_icon[i]);
948 os_free(conf->hs20_operator_icon);
949 }
950 os_free(conf->subscr_remediation_url);
951 os_free(conf->hs20_sim_provisioning_url);
952 os_free(conf->t_c_filename);
953 os_free(conf->t_c_server_url);
954 #endif /* CONFIG_HS20 */
955
956 wpabuf_free(conf->vendor_elements);
957 wpabuf_free(conf->assocresp_elements);
958
959 os_free(conf->sae_groups);
960 #ifdef CONFIG_OWE
961 os_free(conf->owe_groups);
962 #endif /* CONFIG_OWE */
963
964 os_free(conf->wowlan_triggers);
965
966 os_free(conf->server_id);
967
968 #ifdef CONFIG_TESTING_OPTIONS
969 wpabuf_free(conf->own_ie_override);
970 wpabuf_free(conf->rsne_override);
971 wpabuf_free(conf->rsnoe_override);
972 wpabuf_free(conf->rsno2e_override);
973 wpabuf_free(conf->rsnxe_override);
974 wpabuf_free(conf->rsnxoe_override);
975 wpabuf_free(conf->sae_commit_override);
976 wpabuf_free(conf->rsne_override_eapol);
977 wpabuf_free(conf->rsnxe_override_eapol);
978 wpabuf_free(conf->rsne_override_ft);
979 wpabuf_free(conf->rsnxe_override_ft);
980 wpabuf_free(conf->gtk_rsc_override);
981 wpabuf_free(conf->igtk_rsc_override);
982 wpabuf_free(conf->eapol_m1_elements);
983 wpabuf_free(conf->eapol_m3_elements);
984 wpabuf_free(conf->presp_elements);
985 #endif /* CONFIG_TESTING_OPTIONS */
986
987 os_free(conf->no_probe_resp_if_seen_on);
988 os_free(conf->no_auth_if_seen_on);
989
990 hostapd_config_free_fils_realms(conf);
991
992 #ifdef CONFIG_DPP
993 os_free(conf->dpp_name);
994 os_free(conf->dpp_mud_url);
995 os_free(conf->dpp_extra_conf_req_name);
996 os_free(conf->dpp_extra_conf_req_value);
997 os_free(conf->dpp_connector);
998 wpabuf_free(conf->dpp_netaccesskey);
999 wpabuf_free(conf->dpp_csign);
1000 #ifdef CONFIG_DPP2
1001 hostapd_dpp_controller_conf_free(conf->dpp_controller);
1002 #endif /* CONFIG_DPP2 */
1003 #endif /* CONFIG_DPP */
1004
1005 hostapd_config_free_sae_passwords(conf);
1006
1007 #ifdef CONFIG_AIRTIME_POLICY
1008 {
1009 struct airtime_sta_weight *wt, *wt_prev;
1010
1011 wt = conf->airtime_weight_list;
1012 conf->airtime_weight_list = NULL;
1013 while (wt) {
1014 wt_prev = wt;
1015 wt = wt->next;
1016 os_free(wt_prev);
1017 }
1018 }
1019 #endif /* CONFIG_AIRTIME_POLICY */
1020
1021 #ifdef CONFIG_PASN
1022 os_free(conf->pasn_groups);
1023 #endif /* CONFIG_PASN */
1024
1025 os_free(conf);
1026 }
1027
1028
1029 /**
1030 * hostapd_config_free - Free hostapd configuration
1031 * @conf: Configuration data from hostapd_config_read().
1032 */
hostapd_config_free(struct hostapd_config * conf)1033 void hostapd_config_free(struct hostapd_config *conf)
1034 {
1035 size_t i;
1036
1037 if (conf == NULL)
1038 return;
1039
1040 for (i = 0; i < conf->num_bss; i++)
1041 hostapd_config_free_bss(conf->bss[i]);
1042 os_free(conf->bss);
1043 os_free(conf->supported_rates);
1044 os_free(conf->basic_rates);
1045 os_free(conf->acs_ch_list.range);
1046 os_free(conf->acs_freq_list.range);
1047 os_free(conf->driver_params);
1048 #ifdef CONFIG_ACS
1049 os_free(conf->acs_chan_bias);
1050 #endif /* CONFIG_ACS */
1051 wpabuf_free(conf->lci);
1052 wpabuf_free(conf->civic);
1053
1054 os_free(conf);
1055 }
1056
1057
1058 /**
1059 * hostapd_maclist_found - Find a MAC address from a list
1060 * @list: MAC address list
1061 * @num_entries: Number of addresses in the list
1062 * @addr: Address to search for
1063 * @vlan_id: Buffer for returning VLAN ID or %NULL if not needed
1064 * Returns: 1 if address is in the list or 0 if not.
1065 *
1066 * Perform a binary search for given MAC address from a pre-sorted list.
1067 */
hostapd_maclist_found(struct mac_acl_entry * list,int num_entries,const u8 * addr,struct vlan_description * vlan_id)1068 int hostapd_maclist_found(struct mac_acl_entry *list, int num_entries,
1069 const u8 *addr, struct vlan_description *vlan_id)
1070 {
1071 int start, end, middle, res;
1072
1073 start = 0;
1074 end = num_entries - 1;
1075
1076 while (start <= end) {
1077 middle = (start + end) / 2;
1078 res = os_memcmp(list[middle].addr, addr, ETH_ALEN);
1079 if (res == 0) {
1080 if (vlan_id)
1081 *vlan_id = list[middle].vlan_id;
1082 return 1;
1083 }
1084 if (res < 0)
1085 start = middle + 1;
1086 else
1087 end = middle - 1;
1088 }
1089
1090 return 0;
1091 }
1092
1093
hostapd_rate_found(int * list,int rate)1094 int hostapd_rate_found(int *list, int rate)
1095 {
1096 int i;
1097
1098 if (list == NULL)
1099 return 0;
1100
1101 for (i = 0; list[i] >= 0; i++)
1102 if (list[i] == rate)
1103 return 1;
1104
1105 return 0;
1106 }
1107
1108
hostapd_vlan_valid(struct hostapd_vlan * vlan,struct vlan_description * vlan_desc)1109 int hostapd_vlan_valid(struct hostapd_vlan *vlan,
1110 struct vlan_description *vlan_desc)
1111 {
1112 struct hostapd_vlan *v = vlan;
1113 int i;
1114
1115 if (!vlan_desc->notempty || vlan_desc->untagged < 0 ||
1116 vlan_desc->untagged > MAX_VLAN_ID)
1117 return 0;
1118 for (i = 0; i < MAX_NUM_TAGGED_VLAN; i++) {
1119 if (vlan_desc->tagged[i] < 0 ||
1120 vlan_desc->tagged[i] > MAX_VLAN_ID)
1121 return 0;
1122 }
1123 if (!vlan_desc->untagged && !vlan_desc->tagged[0])
1124 return 0;
1125
1126 while (v) {
1127 if (!vlan_compare(&v->vlan_desc, vlan_desc) ||
1128 v->vlan_id == VLAN_ID_WILDCARD)
1129 return 1;
1130 v = v->next;
1131 }
1132 return 0;
1133 }
1134
1135
hostapd_get_vlan_id_ifname(struct hostapd_vlan * vlan,int vlan_id)1136 const char * hostapd_get_vlan_id_ifname(struct hostapd_vlan *vlan, int vlan_id)
1137 {
1138 struct hostapd_vlan *v = vlan;
1139 while (v) {
1140 if (v->vlan_id == vlan_id)
1141 return v->ifname;
1142 v = v->next;
1143 }
1144 return NULL;
1145 }
1146
1147
hostapd_get_psk(const struct hostapd_bss_config * conf,const u8 * addr,const u8 * p2p_dev_addr,const u8 * prev_psk,int * vlan_id)1148 const u8 * hostapd_get_psk(const struct hostapd_bss_config *conf,
1149 const u8 *addr, const u8 *p2p_dev_addr,
1150 const u8 *prev_psk, int *vlan_id)
1151 {
1152 struct hostapd_wpa_psk *psk;
1153 int next_ok = prev_psk == NULL;
1154
1155 if (vlan_id)
1156 *vlan_id = 0;
1157
1158 if (p2p_dev_addr && !is_zero_ether_addr(p2p_dev_addr)) {
1159 wpa_printf(MSG_DEBUG, "Searching a PSK for " MACSTR
1160 " p2p_dev_addr=" MACSTR " prev_psk=%p",
1161 MAC2STR(addr), MAC2STR(p2p_dev_addr), prev_psk);
1162 addr = NULL; /* Use P2P Device Address for matching */
1163 } else {
1164 wpa_printf(MSG_DEBUG, "Searching a PSK for " MACSTR
1165 " prev_psk=%p",
1166 MAC2STR(addr), prev_psk);
1167 }
1168
1169 for (psk = conf->ssid.wpa_psk; psk != NULL; psk = psk->next) {
1170 if (next_ok &&
1171 (psk->group ||
1172 (addr && ether_addr_equal(psk->addr, addr)) ||
1173 (!addr && p2p_dev_addr &&
1174 ether_addr_equal(psk->p2p_dev_addr, p2p_dev_addr)))) {
1175 if (vlan_id)
1176 *vlan_id = psk->vlan_id;
1177 return psk->psk;
1178 }
1179
1180 if (psk->psk == prev_psk)
1181 next_ok = 1;
1182 }
1183
1184 return NULL;
1185 }
1186
1187
1188 #ifdef CONFIG_SAE_PK
hostapd_sae_pk_password_without_pk(struct hostapd_bss_config * bss)1189 static bool hostapd_sae_pk_password_without_pk(struct hostapd_bss_config *bss)
1190 {
1191 struct sae_password_entry *pw;
1192 bool res = false;
1193
1194 if (bss->ssid.wpa_passphrase &&
1195 #ifdef CONFIG_TESTING_OPTIONS
1196 !bss->sae_pk_password_check_skip &&
1197 #endif /* CONFIG_TESTING_OPTIONS */
1198 sae_pk_valid_password(bss->ssid.wpa_passphrase))
1199 res = true;
1200
1201 for (pw = bss->sae_passwords; pw; pw = pw->next) {
1202 if (!pw->pk &&
1203 #ifdef CONFIG_TESTING_OPTIONS
1204 !bss->sae_pk_password_check_skip &&
1205 #endif /* CONFIG_TESTING_OPTIONS */
1206 sae_pk_valid_password(pw->password))
1207 return true;
1208
1209 if (bss->ssid.wpa_passphrase && res && pw->pk &&
1210 os_strcmp(bss->ssid.wpa_passphrase, pw->password) == 0)
1211 res = false;
1212 }
1213
1214 return res;
1215 }
1216 #endif /* CONFIG_SAE_PK */
1217
1218
hostapd_config_check_bss_6g(struct hostapd_bss_config * bss)1219 static bool hostapd_config_check_bss_6g(struct hostapd_bss_config *bss)
1220 {
1221 if (bss->wpa != WPA_PROTO_RSN) {
1222 wpa_printf(MSG_ERROR,
1223 "Pre-RSNA security methods are not allowed in 6 GHz");
1224 return false;
1225 }
1226
1227 if (bss->ieee80211w != MGMT_FRAME_PROTECTION_REQUIRED) {
1228 wpa_printf(MSG_ERROR,
1229 "Management frame protection is required in 6 GHz");
1230 return false;
1231 }
1232
1233 if (bss->wpa_key_mgmt & (WPA_KEY_MGMT_PSK |
1234 WPA_KEY_MGMT_FT_PSK |
1235 WPA_KEY_MGMT_PSK_SHA256)) {
1236 wpa_printf(MSG_ERROR, "Invalid AKM suite for 6 GHz");
1237 return false;
1238 }
1239
1240 if (bss->rsn_pairwise & (WPA_CIPHER_WEP40 |
1241 WPA_CIPHER_WEP104 |
1242 WPA_CIPHER_TKIP)) {
1243 wpa_printf(MSG_ERROR,
1244 "Invalid pairwise cipher suite for 6 GHz");
1245 return false;
1246 }
1247
1248 if (bss->wpa_group & (WPA_CIPHER_WEP40 |
1249 WPA_CIPHER_WEP104 |
1250 WPA_CIPHER_TKIP)) {
1251 wpa_printf(MSG_ERROR, "Invalid group cipher suite for 6 GHz");
1252 return false;
1253 }
1254
1255 #ifdef CONFIG_SAE
1256 if (wpa_key_mgmt_sae(bss->wpa_key_mgmt) &&
1257 bss->sae_pwe == SAE_PWE_HUNT_AND_PECK) {
1258 wpa_printf(MSG_INFO, "SAE: Enabling SAE H2E on 6 GHz");
1259 bss->sae_pwe = SAE_PWE_BOTH;
1260 }
1261 #endif /* CONFIG_SAE */
1262
1263 return true;
1264 }
1265
1266
hostapd_config_check_bss(struct hostapd_bss_config * bss,struct hostapd_config * conf,int full_config)1267 static int hostapd_config_check_bss(struct hostapd_bss_config *bss,
1268 struct hostapd_config *conf,
1269 int full_config)
1270 {
1271 if (full_config && is_6ghz_op_class(conf->op_class) &&
1272 !hostapd_config_check_bss_6g(bss))
1273 return -1;
1274
1275 if (full_config && bss->ieee802_1x && !bss->eap_server &&
1276 !bss->radius->auth_servers) {
1277 wpa_printf(MSG_ERROR, "Invalid IEEE 802.1X configuration (no "
1278 "EAP authenticator configured).");
1279 return -1;
1280 }
1281
1282 #ifdef CONFIG_WEP
1283 if (bss->wpa) {
1284 int wep, i;
1285
1286 wep = bss->default_wep_key_len > 0 ||
1287 bss->individual_wep_key_len > 0;
1288 for (i = 0; i < NUM_WEP_KEYS; i++) {
1289 if (bss->ssid.wep.keys_set) {
1290 wep = 1;
1291 break;
1292 }
1293 }
1294
1295 if (wep) {
1296 wpa_printf(MSG_ERROR, "WEP configuration in a WPA network is not supported");
1297 return -1;
1298 }
1299 }
1300 #endif /* CONFIG_WEP */
1301
1302 if (full_config && bss->wpa &&
1303 bss->wpa_psk_radius != PSK_RADIUS_IGNORED &&
1304 bss->wpa_psk_radius != PSK_RADIUS_DURING_4WAY_HS &&
1305 bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH) {
1306 wpa_printf(MSG_ERROR, "WPA-PSK using RADIUS enabled, but no "
1307 "RADIUS checking (macaddr_acl=2) enabled.");
1308 return -1;
1309 }
1310
1311 if (full_config && bss->wpa &&
1312 wpa_key_mgmt_wpa_psk_no_sae(bss->wpa_key_mgmt) &&
1313 bss->ssid.wpa_psk == NULL && bss->ssid.wpa_passphrase == NULL &&
1314 bss->ssid.wpa_psk_file == NULL &&
1315 bss->wpa_psk_radius != PSK_RADIUS_DURING_4WAY_HS &&
1316 (bss->wpa_psk_radius != PSK_RADIUS_REQUIRED ||
1317 bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH)) {
1318 wpa_printf(MSG_ERROR, "WPA-PSK enabled, but PSK or passphrase "
1319 "is not configured.");
1320 return -1;
1321 }
1322
1323 if (full_config && !is_zero_ether_addr(bss->bssid)) {
1324 size_t i;
1325
1326 for (i = 0; i < conf->num_bss; i++) {
1327 if (conf->bss[i] != bss &&
1328 (hostapd_mac_comp(conf->bss[i]->bssid,
1329 bss->bssid) == 0)) {
1330 wpa_printf(MSG_ERROR, "Duplicate BSSID " MACSTR
1331 " on interface '%s' and '%s'.",
1332 MAC2STR(bss->bssid),
1333 conf->bss[i]->iface, bss->iface);
1334 return -1;
1335 }
1336 }
1337 }
1338
1339 #ifdef CONFIG_IEEE80211R_AP
1340 if (full_config && wpa_key_mgmt_ft(bss->wpa_key_mgmt) &&
1341 (bss->nas_identifier == NULL ||
1342 os_strlen(bss->nas_identifier) < 1 ||
1343 os_strlen(bss->nas_identifier) > FT_R0KH_ID_MAX_LEN)) {
1344 wpa_printf(MSG_ERROR, "FT (IEEE 802.11r) requires "
1345 "nas_identifier to be configured as a 1..48 octet "
1346 "string");
1347 return -1;
1348 }
1349 #endif /* CONFIG_IEEE80211R_AP */
1350
1351 if (full_config && conf->ieee80211n &&
1352 conf->hw_mode == HOSTAPD_MODE_IEEE80211B) {
1353 bss->disable_11n = true;
1354 wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) in 11b mode is not "
1355 "allowed, disabling HT capabilities");
1356 }
1357
1358 #ifdef CONFIG_WEP
1359 if (full_config && conf->ieee80211n &&
1360 bss->ssid.security_policy == SECURITY_STATIC_WEP) {
1361 bss->disable_11n = true;
1362 wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) with WEP is not "
1363 "allowed, disabling HT capabilities");
1364 }
1365 #endif /* CONFIG_WEP */
1366
1367 if (full_config && conf->ieee80211n && bss->wpa &&
1368 !(bss->wpa_pairwise & WPA_CIPHER_CCMP) &&
1369 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
1370 WPA_CIPHER_CCMP_256 | WPA_CIPHER_GCMP_256)))
1371 {
1372 bss->disable_11n = true;
1373 wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) with WPA/WPA2 "
1374 "requires CCMP/GCMP to be enabled, disabling HT "
1375 "capabilities");
1376 }
1377
1378 #ifdef CONFIG_IEEE80211AC
1379 #ifdef CONFIG_WEP
1380 if (full_config && conf->ieee80211ac &&
1381 bss->ssid.security_policy == SECURITY_STATIC_WEP) {
1382 bss->disable_11ac = true;
1383 wpa_printf(MSG_ERROR,
1384 "VHT (IEEE 802.11ac) with WEP is not allowed, disabling VHT capabilities");
1385 }
1386 #endif /* CONFIG_WEP */
1387
1388 if (full_config && conf->ieee80211ac && bss->wpa &&
1389 !(bss->wpa_pairwise & WPA_CIPHER_CCMP) &&
1390 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
1391 WPA_CIPHER_CCMP_256 | WPA_CIPHER_GCMP_256)))
1392 {
1393 bss->disable_11ac = true;
1394 wpa_printf(MSG_ERROR,
1395 "VHT (IEEE 802.11ac) with WPA/WPA2 requires CCMP/GCMP to be enabled, disabling VHT capabilities");
1396 }
1397 #endif /* CONFIG_IEEE80211AC */
1398
1399 #ifdef CONFIG_IEEE80211AX
1400 #ifdef CONFIG_WEP
1401 if (full_config && conf->ieee80211ax &&
1402 bss->ssid.security_policy == SECURITY_STATIC_WEP) {
1403 bss->disable_11ax = true;
1404 wpa_printf(MSG_ERROR,
1405 "HE (IEEE 802.11ax) with WEP is not allowed, disabling HE capabilities");
1406 }
1407 #endif /* CONFIG_WEP */
1408
1409 if (full_config && conf->ieee80211ax && bss->wpa &&
1410 !(bss->wpa_pairwise & WPA_CIPHER_CCMP) &&
1411 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
1412 WPA_CIPHER_CCMP_256 | WPA_CIPHER_GCMP_256)))
1413 {
1414 bss->disable_11ax = true;
1415 wpa_printf(MSG_ERROR,
1416 "HE (IEEE 802.11ax) with WPA/WPA2 requires CCMP/GCMP to be enabled, disabling HE capabilities");
1417 }
1418 #endif /* CONFIG_IEEE80211AX */
1419
1420 #ifdef CONFIG_WPS
1421 if (full_config && bss->wps_state && bss->ignore_broadcast_ssid) {
1422 wpa_printf(MSG_INFO, "WPS: ignore_broadcast_ssid "
1423 "configuration forced WPS to be disabled");
1424 bss->wps_state = 0;
1425 }
1426
1427 #ifdef CONFIG_WEP
1428 if (full_config && bss->wps_state &&
1429 bss->ssid.wep.keys_set && bss->wpa == 0) {
1430 wpa_printf(MSG_INFO, "WPS: WEP configuration forced WPS to be "
1431 "disabled");
1432 bss->wps_state = 0;
1433 }
1434 #endif /* CONFIG_WEP */
1435
1436 if (full_config && bss->wps_state && bss->wpa &&
1437 (!(bss->wpa & 2) ||
1438 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
1439 WPA_CIPHER_CCMP_256 |
1440 WPA_CIPHER_GCMP_256)))) {
1441 wpa_printf(MSG_INFO, "WPS: WPA/TKIP configuration without "
1442 "WPA2/CCMP/GCMP forced WPS to be disabled");
1443 bss->wps_state = 0;
1444 }
1445 #endif /* CONFIG_WPS */
1446
1447 #ifdef CONFIG_HS20
1448 if (full_config && bss->hs20 &&
1449 (!(bss->wpa & 2) ||
1450 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
1451 WPA_CIPHER_CCMP_256 |
1452 WPA_CIPHER_GCMP_256)))) {
1453 wpa_printf(MSG_ERROR, "HS 2.0: WPA2-Enterprise/CCMP "
1454 "configuration is required for Hotspot 2.0 "
1455 "functionality");
1456 return -1;
1457 }
1458 #endif /* CONFIG_HS20 */
1459
1460 #ifdef CONFIG_MBO
1461 if (full_config && bss->mbo_enabled && (bss->wpa & 2) &&
1462 bss->ieee80211w == NO_MGMT_FRAME_PROTECTION) {
1463 wpa_printf(MSG_ERROR,
1464 "MBO: PMF needs to be enabled whenever using WPA2 with MBO");
1465 return -1;
1466 }
1467 #endif /* CONFIG_MBO */
1468
1469 #ifdef CONFIG_OCV
1470 if (full_config && bss->ieee80211w == NO_MGMT_FRAME_PROTECTION &&
1471 bss->ocv) {
1472 wpa_printf(MSG_ERROR,
1473 "OCV: PMF needs to be enabled whenever using OCV");
1474 return -1;
1475 }
1476 #endif /* CONFIG_OCV */
1477
1478 #ifdef CONFIG_SAE_PK
1479 if (full_config && hostapd_sae_pk_in_use(bss) &&
1480 hostapd_sae_pk_password_without_pk(bss)) {
1481 wpa_printf(MSG_ERROR,
1482 "SAE-PK: SAE password uses SAE-PK style, but does not have PK configured");
1483 return -1;
1484 }
1485 #endif /* CONFIG_SAE_PK */
1486
1487 #ifdef CONFIG_FILS
1488 if (full_config && bss->fils_discovery_max_int &&
1489 (!conf->ieee80211ax || bss->disable_11ax)) {
1490 wpa_printf(MSG_ERROR,
1491 "Currently IEEE 802.11ax support is mandatory to enable FILS discovery transmission.");
1492 return -1;
1493 }
1494
1495 if (full_config && bss->fils_discovery_max_int &&
1496 bss->unsol_bcast_probe_resp_interval) {
1497 wpa_printf(MSG_ERROR,
1498 "Cannot enable both FILS discovery and unsolicited broadcast Probe Response at the same time");
1499 return -1;
1500 }
1501 #endif /* CONFIG_FILS */
1502
1503 #ifdef CONFIG_IEEE80211BE
1504 if (full_config && !bss->disable_11be && bss->disable_11ax) {
1505 bss->disable_11be = true;
1506 wpa_printf(MSG_INFO,
1507 "Disabling IEEE 802.11be as IEEE 802.11ax is disabled for this BSS");
1508 }
1509 #endif /* CONFIG_IEEE80211BE */
1510
1511 if (full_config && bss->ignore_broadcast_ssid && conf->mbssid) {
1512 wpa_printf(MSG_ERROR,
1513 "Hidden SSID is not suppored when MBSSID is enabled");
1514 return -1;
1515 }
1516
1517 return 0;
1518 }
1519
1520
hostapd_config_check_cw(struct hostapd_config * conf,int queue)1521 static int hostapd_config_check_cw(struct hostapd_config *conf, int queue)
1522 {
1523 int tx_cwmin = conf->tx_queue[queue].cwmin;
1524 int tx_cwmax = conf->tx_queue[queue].cwmax;
1525 int ac_cwmin = conf->wmm_ac_params[queue].cwmin;
1526 int ac_cwmax = conf->wmm_ac_params[queue].cwmax;
1527
1528 if (tx_cwmin > tx_cwmax) {
1529 wpa_printf(MSG_ERROR,
1530 "Invalid TX queue cwMin/cwMax values. cwMin(%d) greater than cwMax(%d)",
1531 tx_cwmin, tx_cwmax);
1532 return -1;
1533 }
1534 if (ac_cwmin > ac_cwmax) {
1535 wpa_printf(MSG_ERROR,
1536 "Invalid WMM AC cwMin/cwMax values. cwMin(%d) greater than cwMax(%d)",
1537 ac_cwmin, ac_cwmax);
1538 return -1;
1539 }
1540 return 0;
1541 }
1542
1543
hostapd_config_check(struct hostapd_config * conf,int full_config)1544 int hostapd_config_check(struct hostapd_config *conf, int full_config)
1545 {
1546 size_t i;
1547
1548 if (full_config && is_6ghz_op_class(conf->op_class) &&
1549 !conf->hw_mode_set) {
1550 /* Use the appropriate hw_mode value automatically when the
1551 * op_class parameter has been set, but hw_mode was not. */
1552 conf->hw_mode = HOSTAPD_MODE_IEEE80211A;
1553 }
1554
1555 if (full_config && conf->ieee80211d &&
1556 (!conf->country[0] || !conf->country[1])) {
1557 wpa_printf(MSG_ERROR, "Cannot enable IEEE 802.11d without "
1558 "setting the country_code");
1559 return -1;
1560 }
1561
1562 if (full_config && conf->ieee80211h && !conf->ieee80211d) {
1563 wpa_printf(MSG_ERROR, "Cannot enable IEEE 802.11h without "
1564 "IEEE 802.11d enabled");
1565 return -1;
1566 }
1567
1568 if (full_config && conf->local_pwr_constraint != -1 &&
1569 !conf->ieee80211d) {
1570 wpa_printf(MSG_ERROR, "Cannot add Power Constraint element without Country element");
1571 return -1;
1572 }
1573
1574 if (full_config && conf->spectrum_mgmt_required &&
1575 conf->local_pwr_constraint == -1) {
1576 wpa_printf(MSG_ERROR, "Cannot set Spectrum Management bit without Country and Power Constraint elements");
1577 return -1;
1578 }
1579
1580 #ifdef CONFIG_AIRTIME_POLICY
1581 if (full_config && conf->airtime_mode > AIRTIME_MODE_STATIC &&
1582 !conf->airtime_update_interval) {
1583 wpa_printf(MSG_ERROR, "Airtime update interval cannot be zero");
1584 return -1;
1585 }
1586 #endif /* CONFIG_AIRTIME_POLICY */
1587 for (i = 0; i < NUM_TX_QUEUES; i++) {
1588 if (hostapd_config_check_cw(conf, i))
1589 return -1;
1590 }
1591
1592 #ifdef CONFIG_IEEE80211BE
1593 if (full_config && conf->ieee80211be && !conf->ieee80211ax) {
1594 wpa_printf(MSG_ERROR,
1595 "Cannot set ieee80211be without ieee80211ax");
1596 return -1;
1597 }
1598
1599 if (full_config)
1600 hostapd_set_and_check_bw320_offset(conf,
1601 conf->eht_bw320_offset);
1602 #endif /* CONFIG_IEEE80211BE */
1603
1604 if (full_config && conf->mbssid && !conf->ieee80211ax) {
1605 wpa_printf(MSG_ERROR,
1606 "Cannot enable multiple BSSID support without ieee80211ax");
1607 return -1;
1608 }
1609
1610 for (i = 0; i < conf->num_bss; i++) {
1611 if (hostapd_config_check_bss(conf->bss[i], conf, full_config))
1612 return -1;
1613 }
1614
1615 return 0;
1616 }
1617
1618
hostapd_set_security_params(struct hostapd_bss_config * bss,int full_config)1619 void hostapd_set_security_params(struct hostapd_bss_config *bss,
1620 int full_config)
1621 {
1622 #ifdef CONFIG_WEP
1623 if (bss->individual_wep_key_len == 0) {
1624 /* individual keys are not use; can use key idx0 for
1625 * broadcast keys */
1626 bss->broadcast_key_idx_min = 0;
1627 }
1628 #endif /* CONFIG_WEP */
1629
1630 if ((bss->wpa & 2) && bss->rsn_pairwise == 0)
1631 bss->rsn_pairwise = bss->wpa_pairwise;
1632 if (bss->group_cipher)
1633 bss->wpa_group = bss->group_cipher;
1634 else
1635 bss->wpa_group = wpa_select_ap_group_cipher(bss->wpa,
1636 bss->wpa_pairwise,
1637 bss->rsn_pairwise);
1638 if (!bss->wpa_group_rekey_set)
1639 bss->wpa_group_rekey = bss->wpa_group == WPA_CIPHER_TKIP ?
1640 600 : 86400;
1641
1642 if (full_config) {
1643 bss->radius->auth_server = bss->radius->auth_servers;
1644 bss->radius->acct_server = bss->radius->acct_servers;
1645 }
1646
1647 if (bss->wpa && bss->ieee802_1x) {
1648 bss->ssid.security_policy = SECURITY_WPA;
1649 } else if (bss->wpa) {
1650 bss->ssid.security_policy = SECURITY_WPA_PSK;
1651 } else if (bss->ieee802_1x) {
1652 int cipher = WPA_CIPHER_NONE;
1653 bss->ssid.security_policy = SECURITY_IEEE_802_1X;
1654 #ifdef CONFIG_WEP
1655 bss->ssid.wep.default_len = bss->default_wep_key_len;
1656 if (full_config && bss->default_wep_key_len) {
1657 cipher = bss->default_wep_key_len >= 13 ?
1658 WPA_CIPHER_WEP104 : WPA_CIPHER_WEP40;
1659 } else if (full_config && bss->ssid.wep.keys_set) {
1660 if (bss->ssid.wep.len[0] >= 13)
1661 cipher = WPA_CIPHER_WEP104;
1662 else
1663 cipher = WPA_CIPHER_WEP40;
1664 }
1665 #endif /* CONFIG_WEP */
1666 bss->wpa_group = cipher;
1667 bss->wpa_pairwise = cipher;
1668 bss->rsn_pairwise = cipher;
1669 if (full_config)
1670 bss->wpa_key_mgmt = WPA_KEY_MGMT_IEEE8021X_NO_WPA;
1671 #ifdef CONFIG_WEP
1672 } else if (bss->ssid.wep.keys_set) {
1673 int cipher = WPA_CIPHER_WEP40;
1674 if (bss->ssid.wep.len[0] >= 13)
1675 cipher = WPA_CIPHER_WEP104;
1676 bss->ssid.security_policy = SECURITY_STATIC_WEP;
1677 bss->wpa_group = cipher;
1678 bss->wpa_pairwise = cipher;
1679 bss->rsn_pairwise = cipher;
1680 if (full_config)
1681 bss->wpa_key_mgmt = WPA_KEY_MGMT_NONE;
1682 #endif /* CONFIG_WEP */
1683 } else if (bss->osen) {
1684 bss->ssid.security_policy = SECURITY_OSEN;
1685 bss->wpa_group = WPA_CIPHER_CCMP;
1686 bss->wpa_pairwise = 0;
1687 bss->rsn_pairwise = WPA_CIPHER_CCMP;
1688 } else {
1689 bss->ssid.security_policy = SECURITY_PLAINTEXT;
1690 if (full_config) {
1691 bss->wpa_group = WPA_CIPHER_NONE;
1692 bss->wpa_pairwise = WPA_CIPHER_NONE;
1693 bss->rsn_pairwise = WPA_CIPHER_NONE;
1694 bss->wpa_key_mgmt = WPA_KEY_MGMT_NONE;
1695 }
1696 }
1697 }
1698
1699
hostapd_sae_pw_id_in_use(struct hostapd_bss_config * conf)1700 int hostapd_sae_pw_id_in_use(struct hostapd_bss_config *conf)
1701 {
1702 int with_id = 0, without_id = 0;
1703 struct sae_password_entry *pw;
1704
1705 if (conf->ssid.wpa_passphrase)
1706 without_id = 1;
1707
1708 for (pw = conf->sae_passwords; pw; pw = pw->next) {
1709 if (pw->identifier)
1710 with_id = 1;
1711 else
1712 without_id = 1;
1713 if (with_id && without_id)
1714 break;
1715 }
1716
1717 if (with_id && !without_id)
1718 return 2;
1719 return with_id;
1720 }
1721
1722
hostapd_sae_pk_in_use(struct hostapd_bss_config * conf)1723 bool hostapd_sae_pk_in_use(struct hostapd_bss_config *conf)
1724 {
1725 #ifdef CONFIG_SAE_PK
1726 struct sae_password_entry *pw;
1727
1728 for (pw = conf->sae_passwords; pw; pw = pw->next) {
1729 if (pw->pk)
1730 return true;
1731 }
1732 #endif /* CONFIG_SAE_PK */
1733
1734 return false;
1735 }
1736
1737
1738 #ifdef CONFIG_SAE_PK
hostapd_sae_pk_exclusively(struct hostapd_bss_config * conf)1739 bool hostapd_sae_pk_exclusively(struct hostapd_bss_config *conf)
1740 {
1741 bool with_pk = false;
1742 struct sae_password_entry *pw;
1743
1744 if (conf->ssid.wpa_passphrase)
1745 return false;
1746
1747 for (pw = conf->sae_passwords; pw; pw = pw->next) {
1748 if (!pw->pk)
1749 return false;
1750 with_pk = true;
1751 }
1752
1753 return with_pk;
1754 }
1755 #endif /* CONFIG_SAE_PK */
1756
1757
hostapd_acl_comp(const void * a,const void * b)1758 int hostapd_acl_comp(const void *a, const void *b)
1759 {
1760 const struct mac_acl_entry *aa = a;
1761 const struct mac_acl_entry *bb = b;
1762 return os_memcmp(aa->addr, bb->addr, sizeof(macaddr));
1763 }
1764
1765
hostapd_add_acl_maclist(struct mac_acl_entry ** acl,int * num,int vlan_id,const u8 * addr)1766 int hostapd_add_acl_maclist(struct mac_acl_entry **acl, int *num,
1767 int vlan_id, const u8 *addr)
1768 {
1769 struct mac_acl_entry *newacl;
1770
1771 newacl = os_realloc_array(*acl, *num + 1, sizeof(**acl));
1772 if (!newacl) {
1773 wpa_printf(MSG_ERROR, "MAC list reallocation failed");
1774 return -1;
1775 }
1776
1777 *acl = newacl;
1778 os_memcpy((*acl)[*num].addr, addr, ETH_ALEN);
1779 os_memset(&(*acl)[*num].vlan_id, 0, sizeof((*acl)[*num].vlan_id));
1780 (*acl)[*num].vlan_id.untagged = vlan_id;
1781 (*acl)[*num].vlan_id.notempty = !!vlan_id;
1782 (*num)++;
1783
1784 return 0;
1785 }
1786
1787
hostapd_remove_acl_mac(struct mac_acl_entry ** acl,int * num,const u8 * addr)1788 void hostapd_remove_acl_mac(struct mac_acl_entry **acl, int *num,
1789 const u8 *addr)
1790 {
1791 int i = 0;
1792
1793 while (i < *num) {
1794 if (ether_addr_equal((*acl)[i].addr, addr)) {
1795 os_remove_in_array(*acl, *num, sizeof(**acl), i);
1796 (*num)--;
1797 } else {
1798 i++;
1799 }
1800 }
1801 }
1802