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