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