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