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