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