blob: 58fc3e9880236a4c685c15cd0a6856ac9658f232 [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * hostapd / Configuration helper functions
Dmitry Shmidt344abd32014-01-14 13:17:00 -08003 * Copyright (c) 2003-2014, Jouni Malinen <j@w1.fi>
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004 *
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007 */
8
9#include "utils/includes.h"
10
11#include "utils/common.h"
12#include "crypto/sha1.h"
Roshan Pius3a1667e2018-07-03 15:17:14 -070013#include "crypto/tls.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070014#include "radius/radius_client.h"
15#include "common/ieee802_11_defs.h"
Hai Shalom81f62d82019-07-22 12:10:00 -070016#include "common/ieee802_1x_defs.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070017#include "common/eapol_common.h"
Dmitry Shmidtebd93af2017-02-21 13:40:44 -080018#include "common/dhcp.h"
Hai Shalomc3565922019-10-28 11:58:20 -070019#include "common/sae.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070020#include "eap_common/eap_wsc_common.h"
21#include "eap_server/eap.h"
22#include "wpa_auth.h"
23#include "sta_info.h"
Hai Shalom81f62d82019-07-22 12:10:00 -070024#include "airtime_policy.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070025#include "ap_config.h"
26
27
28static 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
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070044#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
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070048void hostapd_config_defaults_bss(struct hostapd_bss_config *bss)
49{
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080050 dl_list_init(&bss->anqp_elem);
51
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070052 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 bss->auth_algs = WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED;
58
59 bss->wep_rekeying_period = 300;
60 /* use key0 in individual key and key1 in broadcast key */
61 bss->broadcast_key_idx_min = 1;
62 bss->broadcast_key_idx_max = 2;
63 bss->eap_reauth_period = 3600;
64
65 bss->wpa_group_rekey = 600;
66 bss->wpa_gmk_rekey = 86400;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -080067 bss->wpa_group_update_count = 4;
68 bss->wpa_pairwise_update_count = 4;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070069 bss->wpa_disable_eapol_key_retries =
70 DEFAULT_WPA_DISABLE_EAPOL_KEY_RETRIES;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070071 bss->wpa_key_mgmt = WPA_KEY_MGMT_PSK;
72 bss->wpa_pairwise = WPA_CIPHER_TKIP;
73 bss->wpa_group = WPA_CIPHER_TKIP;
74 bss->rsn_pairwise = 0;
75
76 bss->max_num_sta = MAX_STA_COUNT;
77
78 bss->dtim_period = 2;
79
80 bss->radius_server_auth_port = 1812;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080081 bss->eap_sim_db_timeout = 1;
Hai Shalomc3565922019-10-28 11:58:20 -070082 bss->eap_sim_id = 3;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070083 bss->ap_max_inactivity = AP_MAX_INACTIVITY;
84 bss->eapol_version = EAPOL_VERSION;
85
86 bss->max_listen_interval = 65535;
87
88 bss->pwd_group = 19; /* ECC: GF(p=256) */
89
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070090 bss->assoc_sa_query_max_timeout = 1000;
91 bss->assoc_sa_query_retry_timeout = 201;
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -070092 bss->group_mgmt_cipher = WPA_CIPHER_AES_128_CMAC;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070093#ifdef EAP_SERVER_FAST
94 /* both anonymous and authenticated provisioning */
95 bss->eap_fast_prov = 3;
96 bss->pac_key_lifetime = 7 * 24 * 60 * 60;
97 bss->pac_key_refresh_time = 1 * 24 * 60 * 60;
98#endif /* EAP_SERVER_FAST */
99
100 /* Set to -1 as defaults depends on HT in setup */
101 bss->wmm_enabled = -1;
102
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800103#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700104 bss->ft_over_ds = 1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700105 bss->rkh_pos_timeout = 86400;
106 bss->rkh_neg_timeout = 60;
107 bss->rkh_pull_timeout = 1000;
108 bss->rkh_pull_retries = 4;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700109 bss->r0_key_lifetime = 1209600;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800110#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt04949592012-07-19 12:16:46 -0700111
112 bss->radius_das_time_window = 300;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800113
114 bss->sae_anti_clogging_threshold = 5;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700115 bss->sae_sync = 5;
Dmitry Shmidt29333592017-01-09 12:27:11 -0800116
117 bss->gas_frag_limit = 1400;
118
119#ifdef CONFIG_FILS
120 dl_list_init(&bss->fils_realms);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800121 bss->fils_hlp_wait_time = 30;
122 bss->dhcp_server_port = DHCP_SERVER_PORT;
123 bss->dhcp_relay_port = DHCP_SERVER_PORT;
Dmitry Shmidt29333592017-01-09 12:27:11 -0800124#endif /* CONFIG_FILS */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700125
126 bss->broadcast_deauth = 1;
127
128#ifdef CONFIG_MBO
129 bss->mbo_cell_data_conn_pref = -1;
130#endif /* CONFIG_MBO */
Roshan Pius3a1667e2018-07-03 15:17:14 -0700131
132 /* Disable TLS v1.3 by default for now to avoid interoperability issue.
133 * This can be enabled by default once the implementation has been fully
134 * completed and tested with other implementations. */
135 bss->tls_flags = TLS_CONN_DISABLE_TLSv1_3;
Hai Shalom74f70d42019-02-11 14:42:39 -0800136
Hai Shalomc3565922019-10-28 11:58:20 -0700137 bss->max_auth_rounds = 100;
138 bss->max_auth_rounds_short = 50;
139
Hai Shalom74f70d42019-02-11 14:42:39 -0800140 bss->send_probe_response = 1;
141
142#ifdef CONFIG_HS20
143 bss->hs20_release = (HS20_VERSION >> 4) + 1;
144#endif /* CONFIG_HS20 */
145
Hai Shalom81f62d82019-07-22 12:10:00 -0700146#ifdef CONFIG_MACSEC
147 bss->mka_priority = DEFAULT_PRIO_NOT_KEY_SERVER;
148 bss->macsec_port = 1;
149#endif /* CONFIG_MACSEC */
150
Hai Shalom74f70d42019-02-11 14:42:39 -0800151 /* Default to strict CRL checking. */
152 bss->check_crl_strict = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700153}
154
155
156struct hostapd_config * hostapd_config_defaults(void)
157{
158#define ecw2cw(ecw) ((1 << (ecw)) - 1)
159
160 struct hostapd_config *conf;
161 struct hostapd_bss_config *bss;
162 const int aCWmin = 4, aCWmax = 10;
163 const struct hostapd_wmm_ac_params ac_bk =
164 { aCWmin, aCWmax, 7, 0, 0 }; /* background traffic */
165 const struct hostapd_wmm_ac_params ac_be =
166 { aCWmin, aCWmax, 3, 0, 0 }; /* best effort traffic */
167 const struct hostapd_wmm_ac_params ac_vi = /* video traffic */
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700168 { aCWmin - 1, aCWmin, 2, 3008 / 32, 0 };
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700169 const struct hostapd_wmm_ac_params ac_vo = /* voice traffic */
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700170 { aCWmin - 2, aCWmin - 1, 2, 1504 / 32, 0 };
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700171 const struct hostapd_tx_queue_params txq_bk =
172 { 7, ecw2cw(aCWmin), ecw2cw(aCWmax), 0 };
173 const struct hostapd_tx_queue_params txq_be =
174 { 3, ecw2cw(aCWmin), 4 * (ecw2cw(aCWmin) + 1) - 1, 0};
175 const struct hostapd_tx_queue_params txq_vi =
176 { 1, (ecw2cw(aCWmin) + 1) / 2 - 1, ecw2cw(aCWmin), 30};
177 const struct hostapd_tx_queue_params txq_vo =
178 { 1, (ecw2cw(aCWmin) + 1) / 4 - 1,
179 (ecw2cw(aCWmin) + 1) / 2 - 1, 15};
180
181#undef ecw2cw
182
183 conf = os_zalloc(sizeof(*conf));
184 bss = os_zalloc(sizeof(*bss));
185 if (conf == NULL || bss == NULL) {
186 wpa_printf(MSG_ERROR, "Failed to allocate memory for "
187 "configuration data.");
188 os_free(conf);
189 os_free(bss);
190 return NULL;
191 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800192 conf->bss = os_calloc(1, sizeof(struct hostapd_bss_config *));
193 if (conf->bss == NULL) {
194 os_free(conf);
195 os_free(bss);
196 return NULL;
197 }
198 conf->bss[0] = bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700199
200 bss->radius = os_zalloc(sizeof(*bss->radius));
201 if (bss->radius == NULL) {
Dmitry Shmidt97672262014-02-03 13:02:54 -0800202 os_free(conf->bss);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700203 os_free(conf);
204 os_free(bss);
205 return NULL;
206 }
207
208 hostapd_config_defaults_bss(bss);
209
210 conf->num_bss = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700211
212 conf->beacon_int = 100;
Hai Shalom021b0b52019-04-10 11:17:58 -0700213 conf->rts_threshold = -2; /* use driver default: 2347 */
214 conf->fragm_threshold = -2; /* user driver default: 2346 */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800215 /* Set to invalid value means do not add Power Constraint IE */
216 conf->local_pwr_constraint = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700217
218 conf->wmm_ac_params[0] = ac_be;
219 conf->wmm_ac_params[1] = ac_bk;
220 conf->wmm_ac_params[2] = ac_vi;
221 conf->wmm_ac_params[3] = ac_vo;
222
223 conf->tx_queue[0] = txq_vo;
224 conf->tx_queue[1] = txq_vi;
225 conf->tx_queue[2] = txq_be;
226 conf->tx_queue[3] = txq_bk;
227
228 conf->ht_capab = HT_CAP_INFO_SMPS_DISABLED;
229
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800230 conf->ap_table_max_size = 255;
231 conf->ap_table_expiration_time = 60;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800232 conf->track_sta_max_age = 180;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800233
Dmitry Shmidt8da800a2013-04-24 12:57:01 -0700234#ifdef CONFIG_TESTING_OPTIONS
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700235 conf->ignore_probe_probability = 0.0;
236 conf->ignore_auth_probability = 0.0;
237 conf->ignore_assoc_probability = 0.0;
238 conf->ignore_reassoc_probability = 0.0;
239 conf->corrupt_gtk_rekey_mic_probability = 0.0;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800240 conf->ecsa_ie_only = 0;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -0700241#endif /* CONFIG_TESTING_OPTIONS */
242
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700243 conf->acs = 0;
244 conf->acs_ch_list.num = 0;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700245#ifdef CONFIG_ACS
246 conf->acs_num_scans = 5;
247#endif /* CONFIG_ACS */
248
Hai Shalom81f62d82019-07-22 12:10:00 -0700249#ifdef CONFIG_IEEE80211AX
250 conf->he_op.he_rts_threshold = HE_OPERATION_RTS_THRESHOLD_MASK >>
251 HE_OPERATION_RTS_THRESHOLD_OFFSET;
252 /* Set default basic MCS/NSS set to single stream MCS 0-7 */
253 conf->he_op.he_basic_mcs_nss_set = 0xfffc;
254#endif /* CONFIG_IEEE80211AX */
255
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700256 /* The third octet of the country string uses an ASCII space character
257 * by default to indicate that the regulations encompass all
258 * environments for the current frequency band in the country. */
259 conf->country[2] = ' ';
260
Hai Shalom74f70d42019-02-11 14:42:39 -0800261 conf->rssi_reject_assoc_rssi = 0;
262 conf->rssi_reject_assoc_timeout = 30;
263
Hai Shalom81f62d82019-07-22 12:10:00 -0700264#ifdef CONFIG_AIRTIME_POLICY
265 conf->airtime_update_interval = AIRTIME_DEFAULT_UPDATE_INTERVAL;
266#endif /* CONFIG_AIRTIME_POLICY */
267
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700268 return conf;
269}
270
271
272int hostapd_mac_comp(const void *a, const void *b)
273{
274 return os_memcmp(a, b, sizeof(macaddr));
275}
276
277
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700278static int hostapd_config_read_wpa_psk(const char *fname,
279 struct hostapd_ssid *ssid)
280{
281 FILE *f;
282 char buf[128], *pos;
Hai Shalom74f70d42019-02-11 14:42:39 -0800283 const char *keyid;
284 char *context;
285 char *context2;
286 char *token;
287 char *name;
288 char *value;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700289 int line = 0, ret = 0, len, ok;
290 u8 addr[ETH_ALEN];
291 struct hostapd_wpa_psk *psk;
292
293 if (!fname)
294 return 0;
295
296 f = fopen(fname, "r");
297 if (!f) {
298 wpa_printf(MSG_ERROR, "WPA PSK file '%s' not found.", fname);
299 return -1;
300 }
301
302 while (fgets(buf, sizeof(buf), f)) {
Hai Shalom021b0b52019-04-10 11:17:58 -0700303 int vlan_id = 0;
304
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700305 line++;
306
307 if (buf[0] == '#')
308 continue;
309 pos = buf;
310 while (*pos != '\0') {
311 if (*pos == '\n') {
312 *pos = '\0';
313 break;
314 }
315 pos++;
316 }
317 if (buf[0] == '\0')
318 continue;
319
Hai Shalom74f70d42019-02-11 14:42:39 -0800320 context = NULL;
321 keyid = NULL;
322 while ((token = str_token(buf, " ", &context))) {
323 if (!os_strchr(token, '='))
324 break;
325 context2 = NULL;
326 name = str_token(token, "=", &context2);
Hai Shalom021b0b52019-04-10 11:17:58 -0700327 if (!name)
328 break;
Hai Shalom74f70d42019-02-11 14:42:39 -0800329 value = str_token(token, "", &context2);
330 if (!value)
331 value = "";
332 if (!os_strcmp(name, "keyid")) {
333 keyid = value;
Hai Shalom021b0b52019-04-10 11:17:58 -0700334 } else if (!os_strcmp(name, "vlanid")) {
335 vlan_id = atoi(value);
Hai Shalom74f70d42019-02-11 14:42:39 -0800336 } else {
337 wpa_printf(MSG_ERROR,
338 "Unrecognized '%s=%s' on line %d in '%s'",
339 name, value, line, fname);
340 ret = -1;
341 break;
342 }
343 }
344
345 if (ret == -1)
346 break;
347
348 if (!token)
349 token = "";
350 if (hwaddr_aton(token, addr)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700351 wpa_printf(MSG_ERROR, "Invalid MAC address '%s' on "
Hai Shalom74f70d42019-02-11 14:42:39 -0800352 "line %d in '%s'", token, line, fname);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700353 ret = -1;
354 break;
355 }
356
357 psk = os_zalloc(sizeof(*psk));
358 if (psk == NULL) {
359 wpa_printf(MSG_ERROR, "WPA PSK allocation failed");
360 ret = -1;
361 break;
362 }
Hai Shalom021b0b52019-04-10 11:17:58 -0700363 psk->vlan_id = vlan_id;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700364 if (is_zero_ether_addr(addr))
365 psk->group = 1;
366 else
367 os_memcpy(psk->addr, addr, ETH_ALEN);
368
Hai Shalom74f70d42019-02-11 14:42:39 -0800369 pos = str_token(buf, "", &context);
370 if (!pos) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700371 wpa_printf(MSG_ERROR, "No PSK on line %d in '%s'",
372 line, fname);
373 os_free(psk);
374 ret = -1;
375 break;
376 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700377
378 ok = 0;
379 len = os_strlen(pos);
380 if (len == 64 && hexstr2bin(pos, psk->psk, PMK_LEN) == 0)
381 ok = 1;
382 else if (len >= 8 && len < 64) {
383 pbkdf2_sha1(pos, ssid->ssid, ssid->ssid_len,
384 4096, psk->psk, PMK_LEN);
385 ok = 1;
386 }
387 if (!ok) {
388 wpa_printf(MSG_ERROR, "Invalid PSK '%s' on line %d in "
389 "'%s'", pos, line, fname);
390 os_free(psk);
391 ret = -1;
392 break;
393 }
394
Hai Shalom74f70d42019-02-11 14:42:39 -0800395 if (keyid) {
396 len = os_strlcpy(psk->keyid, keyid, sizeof(psk->keyid));
397 if ((size_t) len >= sizeof(psk->keyid)) {
398 wpa_printf(MSG_ERROR,
399 "PSK keyid too long on line %d in '%s'",
400 line, fname);
401 os_free(psk);
402 ret = -1;
403 break;
404 }
405 }
406
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700407 psk->next = ssid->wpa_psk;
408 ssid->wpa_psk = psk;
409 }
410
411 fclose(f);
412
413 return ret;
414}
415
416
417static int hostapd_derive_psk(struct hostapd_ssid *ssid)
418{
419 ssid->wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
420 if (ssid->wpa_psk == NULL) {
421 wpa_printf(MSG_ERROR, "Unable to alloc space for PSK");
422 return -1;
423 }
424 wpa_hexdump_ascii(MSG_DEBUG, "SSID",
425 (u8 *) ssid->ssid, ssid->ssid_len);
426 wpa_hexdump_ascii_key(MSG_DEBUG, "PSK (ASCII passphrase)",
427 (u8 *) ssid->wpa_passphrase,
428 os_strlen(ssid->wpa_passphrase));
429 pbkdf2_sha1(ssid->wpa_passphrase,
430 ssid->ssid, ssid->ssid_len,
431 4096, ssid->wpa_psk->psk, PMK_LEN);
432 wpa_hexdump_key(MSG_DEBUG, "PSK (from passphrase)",
433 ssid->wpa_psk->psk, PMK_LEN);
434 return 0;
435}
436
437
Hai Shalomc3565922019-10-28 11:58:20 -0700438int hostapd_setup_sae_pt(struct hostapd_bss_config *conf)
439{
440#ifdef CONFIG_SAE
441 struct hostapd_ssid *ssid = &conf->ssid;
442 struct sae_password_entry *pw;
443
444 if (conf->sae_pwe == 0)
445 return 0; /* PT not needed */
446
447 sae_deinit_pt(ssid->pt);
448 ssid->pt = NULL;
449 if (ssid->wpa_passphrase) {
450 ssid->pt = sae_derive_pt(conf->sae_groups, ssid->ssid,
451 ssid->ssid_len,
452 (const u8 *) ssid->wpa_passphrase,
453 os_strlen(ssid->wpa_passphrase),
454 NULL);
455 if (!ssid->pt)
456 return -1;
457 }
458
459 for (pw = conf->sae_passwords; pw; pw = pw->next) {
460 sae_deinit_pt(pw->pt);
461 pw->pt = sae_derive_pt(conf->sae_groups, ssid->ssid,
462 ssid->ssid_len,
463 (const u8 *) pw->password,
464 os_strlen(pw->password),
465 pw->identifier);
466 if (!pw->pt)
467 return -1;
468 }
469#endif /* CONFIG_SAE */
470
471 return 0;
472}
473
474
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700475int hostapd_setup_wpa_psk(struct hostapd_bss_config *conf)
476{
477 struct hostapd_ssid *ssid = &conf->ssid;
478
Hai Shalomc3565922019-10-28 11:58:20 -0700479 if (hostapd_setup_sae_pt(conf) < 0)
480 return -1;
481
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700482 if (ssid->wpa_passphrase != NULL) {
483 if (ssid->wpa_psk != NULL) {
484 wpa_printf(MSG_DEBUG, "Using pre-configured WPA PSK "
485 "instead of passphrase");
486 } else {
487 wpa_printf(MSG_DEBUG, "Deriving WPA PSK based on "
488 "passphrase");
489 if (hostapd_derive_psk(ssid) < 0)
490 return -1;
491 }
492 ssid->wpa_psk->group = 1;
493 }
494
Dmitry Shmidt29333592017-01-09 12:27:11 -0800495 return hostapd_config_read_wpa_psk(ssid->wpa_psk_file, &conf->ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700496}
497
498
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700499static void hostapd_config_free_radius(struct hostapd_radius_server *servers,
500 int num_servers)
501{
502 int i;
503
504 for (i = 0; i < num_servers; i++) {
505 os_free(servers[i].shared_secret);
506 }
507 os_free(servers);
508}
509
510
Dmitry Shmidt04949592012-07-19 12:16:46 -0700511struct hostapd_radius_attr *
512hostapd_config_get_radius_attr(struct hostapd_radius_attr *attr, u8 type)
513{
514 for (; attr; attr = attr->next) {
515 if (attr->type == type)
516 return attr;
517 }
518 return NULL;
519}
520
521
Hai Shalomc3565922019-10-28 11:58:20 -0700522struct hostapd_radius_attr * hostapd_parse_radius_attr(const char *value)
523{
524 const char *pos;
525 char syntax;
526 struct hostapd_radius_attr *attr;
527 size_t len;
528
529 attr = os_zalloc(sizeof(*attr));
530 if (!attr)
531 return NULL;
532
533 attr->type = atoi(value);
534
535 pos = os_strchr(value, ':');
536 if (!pos) {
537 attr->val = wpabuf_alloc(1);
538 if (!attr->val) {
539 os_free(attr);
540 return NULL;
541 }
542 wpabuf_put_u8(attr->val, 0);
543 return attr;
544 }
545
546 pos++;
547 if (pos[0] == '\0' || pos[1] != ':') {
548 os_free(attr);
549 return NULL;
550 }
551 syntax = *pos++;
552 pos++;
553
554 switch (syntax) {
555 case 's':
556 attr->val = wpabuf_alloc_copy(pos, os_strlen(pos));
557 break;
558 case 'x':
559 len = os_strlen(pos);
560 if (len & 1)
561 break;
562 len /= 2;
563 attr->val = wpabuf_alloc(len);
564 if (!attr->val)
565 break;
566 if (hexstr2bin(pos, wpabuf_put(attr->val, len), len) < 0) {
567 wpabuf_free(attr->val);
568 os_free(attr);
569 return NULL;
570 }
571 break;
572 case 'd':
573 attr->val = wpabuf_alloc(4);
574 if (attr->val)
575 wpabuf_put_be32(attr->val, atoi(pos));
576 break;
577 default:
578 os_free(attr);
579 return NULL;
580 }
581
582 if (!attr->val) {
583 os_free(attr);
584 return NULL;
585 }
586
587 return attr;
588}
589
590
591void hostapd_config_free_radius_attr(struct hostapd_radius_attr *attr)
Dmitry Shmidt04949592012-07-19 12:16:46 -0700592{
593 struct hostapd_radius_attr *prev;
594
595 while (attr) {
596 prev = attr;
597 attr = attr->next;
598 wpabuf_free(prev->val);
599 os_free(prev);
600 }
601}
602
603
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700604void hostapd_config_free_eap_user(struct hostapd_eap_user *user)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700605{
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700606 hostapd_config_free_radius_attr(user->accept_attr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700607 os_free(user->identity);
Dmitry Shmidtc2817022014-07-02 10:32:10 -0700608 bin_clear_free(user->password, user->password_len);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700609 bin_clear_free(user->salt, user->salt_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700610 os_free(user);
611}
612
613
Dmitry Shmidt29333592017-01-09 12:27:11 -0800614void hostapd_config_free_eap_users(struct hostapd_eap_user *user)
615{
616 struct hostapd_eap_user *prev_user;
617
618 while (user) {
619 prev_user = user;
620 user = user->next;
621 hostapd_config_free_eap_user(prev_user);
622 }
623}
624
625
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700626static void hostapd_config_free_wep(struct hostapd_wep_keys *keys)
627{
628 int i;
629 for (i = 0; i < NUM_WEP_KEYS; i++) {
Dmitry Shmidtc2817022014-07-02 10:32:10 -0700630 bin_clear_free(keys->key[i], keys->len[i]);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700631 keys->key[i] = NULL;
632 }
633}
634
635
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800636void hostapd_config_clear_wpa_psk(struct hostapd_wpa_psk **l)
637{
638 struct hostapd_wpa_psk *psk, *tmp;
639
640 for (psk = *l; psk;) {
641 tmp = psk;
642 psk = psk->next;
643 bin_clear_free(tmp, sizeof(*tmp));
644 }
645 *l = NULL;
646}
647
648
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800649static void hostapd_config_free_anqp_elem(struct hostapd_bss_config *conf)
650{
651 struct anqp_element *elem;
652
653 while ((elem = dl_list_first(&conf->anqp_elem, struct anqp_element,
654 list))) {
655 dl_list_del(&elem->list);
656 wpabuf_free(elem->payload);
657 os_free(elem);
658 }
659}
660
661
Dmitry Shmidt29333592017-01-09 12:27:11 -0800662static void hostapd_config_free_fils_realms(struct hostapd_bss_config *conf)
663{
664#ifdef CONFIG_FILS
665 struct fils_realm *realm;
666
667 while ((realm = dl_list_first(&conf->fils_realms, struct fils_realm,
668 list))) {
669 dl_list_del(&realm->list);
670 os_free(realm);
671 }
672#endif /* CONFIG_FILS */
673}
674
675
Roshan Pius3a1667e2018-07-03 15:17:14 -0700676static void hostapd_config_free_sae_passwords(struct hostapd_bss_config *conf)
677{
678 struct sae_password_entry *pw, *tmp;
679
680 pw = conf->sae_passwords;
681 conf->sae_passwords = NULL;
682 while (pw) {
683 tmp = pw;
684 pw = pw->next;
685 str_clear_free(tmp->password);
686 os_free(tmp->identifier);
Hai Shalomc3565922019-10-28 11:58:20 -0700687#ifdef CONFIG_SAE
688 sae_deinit_pt(tmp->pt);
689#endif /* CONFIG_SAE */
Roshan Pius3a1667e2018-07-03 15:17:14 -0700690 os_free(tmp);
691 }
692}
693
694
Hai Shalom81f62d82019-07-22 12:10:00 -0700695#ifdef CONFIG_DPP2
696static void hostapd_dpp_controller_conf_free(struct dpp_controller_conf *conf)
697{
698 struct dpp_controller_conf *prev;
699
700 while (conf) {
701 prev = conf;
702 conf = conf->next;
703 os_free(prev);
704 }
705}
706#endif /* CONFIG_DPP2 */
707
708
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800709void hostapd_config_free_bss(struct hostapd_bss_config *conf)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700710{
Hai Shalom81f62d82019-07-22 12:10:00 -0700711#if defined(CONFIG_WPS) || defined(CONFIG_HS20)
712 size_t i;
713#endif
714
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700715 if (conf == NULL)
716 return;
717
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800718 hostapd_config_clear_wpa_psk(&conf->ssid.wpa_psk);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700719
Dmitry Shmidtc2817022014-07-02 10:32:10 -0700720 str_clear_free(conf->ssid.wpa_passphrase);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700721 os_free(conf->ssid.wpa_psk_file);
722 hostapd_config_free_wep(&conf->ssid.wep);
723#ifdef CONFIG_FULL_DYNAMIC_VLAN
724 os_free(conf->ssid.vlan_tagged_interface);
725#endif /* CONFIG_FULL_DYNAMIC_VLAN */
Hai Shalomc3565922019-10-28 11:58:20 -0700726#ifdef CONFIG_SAE
727 sae_deinit_pt(conf->ssid.pt);
728#endif /* CONFIG_SAE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700729
Dmitry Shmidt29333592017-01-09 12:27:11 -0800730 hostapd_config_free_eap_users(conf->eap_user);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800731 os_free(conf->eap_user_sqlite);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700732
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700733 os_free(conf->eap_req_id_text);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800734 os_free(conf->erp_domain);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700735 os_free(conf->accept_mac);
736 os_free(conf->deny_mac);
737 os_free(conf->nas_identifier);
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800738 if (conf->radius) {
739 hostapd_config_free_radius(conf->radius->auth_servers,
740 conf->radius->num_auth_servers);
741 hostapd_config_free_radius(conf->radius->acct_servers,
742 conf->radius->num_acct_servers);
743 }
Dmitry Shmidt04949592012-07-19 12:16:46 -0700744 hostapd_config_free_radius_attr(conf->radius_auth_req_attr);
745 hostapd_config_free_radius_attr(conf->radius_acct_req_attr);
Hai Shalomc3565922019-10-28 11:58:20 -0700746 os_free(conf->radius_req_attr_sqlite);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700747 os_free(conf->rsn_preauth_interfaces);
748 os_free(conf->ctrl_interface);
749 os_free(conf->ca_cert);
750 os_free(conf->server_cert);
Hai Shalom81f62d82019-07-22 12:10:00 -0700751 os_free(conf->server_cert2);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700752 os_free(conf->private_key);
Hai Shalom81f62d82019-07-22 12:10:00 -0700753 os_free(conf->private_key2);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700754 os_free(conf->private_key_passwd);
Hai Shalom81f62d82019-07-22 12:10:00 -0700755 os_free(conf->private_key_passwd2);
Hai Shalom021b0b52019-04-10 11:17:58 -0700756 os_free(conf->check_cert_subject);
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700757 os_free(conf->ocsp_stapling_response);
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -0800758 os_free(conf->ocsp_stapling_response_multi);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700759 os_free(conf->dh_file);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800760 os_free(conf->openssl_ciphers);
Hai Shalom74f70d42019-02-11 14:42:39 -0800761 os_free(conf->openssl_ecdh_curves);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700762 os_free(conf->pac_opaque_encr_key);
763 os_free(conf->eap_fast_a_id);
764 os_free(conf->eap_fast_a_id_info);
765 os_free(conf->eap_sim_db);
766 os_free(conf->radius_server_clients);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700767 os_free(conf->radius);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700768 os_free(conf->radius_das_shared_secret);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700769 hostapd_config_free_vlan(conf);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800770 os_free(conf->time_zone);
771
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800772#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700773 {
774 struct ft_remote_r0kh *r0kh, *r0kh_prev;
775 struct ft_remote_r1kh *r1kh, *r1kh_prev;
776
777 r0kh = conf->r0kh_list;
778 conf->r0kh_list = NULL;
779 while (r0kh) {
780 r0kh_prev = r0kh;
781 r0kh = r0kh->next;
782 os_free(r0kh_prev);
783 }
784
785 r1kh = conf->r1kh_list;
786 conf->r1kh_list = NULL;
787 while (r1kh) {
788 r1kh_prev = r1kh;
789 r1kh = r1kh->next;
790 os_free(r1kh_prev);
791 }
792 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800793#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700794
795#ifdef CONFIG_WPS
796 os_free(conf->wps_pin_requests);
797 os_free(conf->device_name);
798 os_free(conf->manufacturer);
799 os_free(conf->model_name);
800 os_free(conf->model_number);
801 os_free(conf->serial_number);
802 os_free(conf->config_methods);
803 os_free(conf->ap_pin);
804 os_free(conf->extra_cred);
805 os_free(conf->ap_settings);
Hai Shalom021b0b52019-04-10 11:17:58 -0700806 hostapd_config_clear_wpa_psk(&conf->multi_ap_backhaul_ssid.wpa_psk);
807 str_clear_free(conf->multi_ap_backhaul_ssid.wpa_passphrase);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700808 os_free(conf->upnp_iface);
809 os_free(conf->friendly_name);
810 os_free(conf->manufacturer_url);
811 os_free(conf->model_description);
812 os_free(conf->model_url);
813 os_free(conf->upc);
Hai Shalom81f62d82019-07-22 12:10:00 -0700814 for (i = 0; i < MAX_WPS_VENDOR_EXTENSIONS; i++)
815 wpabuf_free(conf->wps_vendor_ext[i]);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700816 wpabuf_free(conf->wps_nfc_dh_pubkey);
817 wpabuf_free(conf->wps_nfc_dh_privkey);
818 wpabuf_free(conf->wps_nfc_dev_pw);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700819#endif /* CONFIG_WPS */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800820
821 os_free(conf->roaming_consortium);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700822 os_free(conf->venue_name);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700823 os_free(conf->venue_url);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700824 os_free(conf->nai_realm_data);
825 os_free(conf->network_auth_type);
826 os_free(conf->anqp_3gpp_cell_net);
827 os_free(conf->domain_name);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800828 hostapd_config_free_anqp_elem(conf);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800829
830#ifdef CONFIG_RADIUS_TEST
831 os_free(conf->dump_msk_file);
832#endif /* CONFIG_RADIUS_TEST */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700833
834#ifdef CONFIG_HS20
835 os_free(conf->hs20_oper_friendly_name);
836 os_free(conf->hs20_wan_metrics);
837 os_free(conf->hs20_connection_capability);
838 os_free(conf->hs20_operating_class);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800839 os_free(conf->hs20_icons);
840 if (conf->hs20_osu_providers) {
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800841 for (i = 0; i < conf->hs20_osu_providers_count; i++) {
842 struct hs20_osu_provider *p;
843 size_t j;
844 p = &conf->hs20_osu_providers[i];
845 os_free(p->friendly_name);
846 os_free(p->server_uri);
847 os_free(p->method_list);
848 for (j = 0; j < p->icons_count; j++)
849 os_free(p->icons[j]);
850 os_free(p->icons);
851 os_free(p->osu_nai);
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800852 os_free(p->osu_nai2);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800853 os_free(p->service_desc);
854 }
855 os_free(conf->hs20_osu_providers);
856 }
Roshan Pius3a1667e2018-07-03 15:17:14 -0700857 if (conf->hs20_operator_icon) {
Roshan Pius3a1667e2018-07-03 15:17:14 -0700858 for (i = 0; i < conf->hs20_operator_icon_count; i++)
859 os_free(conf->hs20_operator_icon[i]);
860 os_free(conf->hs20_operator_icon);
861 }
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800862 os_free(conf->subscr_remediation_url);
Hai Shalom74f70d42019-02-11 14:42:39 -0800863 os_free(conf->hs20_sim_provisioning_url);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700864 os_free(conf->t_c_filename);
865 os_free(conf->t_c_server_url);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700866#endif /* CONFIG_HS20 */
867
868 wpabuf_free(conf->vendor_elements);
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700869 wpabuf_free(conf->assocresp_elements);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800870
871 os_free(conf->sae_groups);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700872#ifdef CONFIG_OWE
873 os_free(conf->owe_groups);
874#endif /* CONFIG_OWE */
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700875
Dmitry Shmidt0207e232014-09-03 14:58:37 -0700876 os_free(conf->wowlan_triggers);
877
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700878 os_free(conf->server_id);
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800879
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800880#ifdef CONFIG_TESTING_OPTIONS
881 wpabuf_free(conf->own_ie_override);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700882 wpabuf_free(conf->sae_commit_override);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800883#endif /* CONFIG_TESTING_OPTIONS */
884
885 os_free(conf->no_probe_resp_if_seen_on);
886 os_free(conf->no_auth_if_seen_on);
887
Dmitry Shmidt29333592017-01-09 12:27:11 -0800888 hostapd_config_free_fils_realms(conf);
889
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700890#ifdef CONFIG_DPP
Hai Shalomc3565922019-10-28 11:58:20 -0700891 os_free(conf->dpp_name);
892 os_free(conf->dpp_mud_url);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700893 os_free(conf->dpp_connector);
894 wpabuf_free(conf->dpp_netaccesskey);
895 wpabuf_free(conf->dpp_csign);
Hai Shalom81f62d82019-07-22 12:10:00 -0700896#ifdef CONFIG_DPP2
897 hostapd_dpp_controller_conf_free(conf->dpp_controller);
898#endif /* CONFIG_DPP2 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700899#endif /* CONFIG_DPP */
900
Roshan Pius3a1667e2018-07-03 15:17:14 -0700901 hostapd_config_free_sae_passwords(conf);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700902
Hai Shalom81f62d82019-07-22 12:10:00 -0700903#ifdef CONFIG_AIRTIME_POLICY
904 {
905 struct airtime_sta_weight *wt, *wt_prev;
906
907 wt = conf->airtime_weight_list;
908 conf->airtime_weight_list = NULL;
909 while (wt) {
910 wt_prev = wt;
911 wt = wt->next;
912 os_free(wt_prev);
913 }
914 }
915#endif /* CONFIG_AIRTIME_POLICY */
916
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800917 os_free(conf);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700918}
919
920
921/**
922 * hostapd_config_free - Free hostapd configuration
923 * @conf: Configuration data from hostapd_config_read().
924 */
925void hostapd_config_free(struct hostapd_config *conf)
926{
927 size_t i;
928
929 if (conf == NULL)
930 return;
931
932 for (i = 0; i < conf->num_bss; i++)
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800933 hostapd_config_free_bss(conf->bss[i]);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700934 os_free(conf->bss);
935 os_free(conf->supported_rates);
936 os_free(conf->basic_rates);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700937 os_free(conf->acs_ch_list.range);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800938 os_free(conf->driver_params);
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800939#ifdef CONFIG_ACS
940 os_free(conf->acs_chan_bias);
941#endif /* CONFIG_ACS */
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700942 wpabuf_free(conf->lci);
943 wpabuf_free(conf->civic);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700944
945 os_free(conf);
946}
947
948
949/**
950 * hostapd_maclist_found - Find a MAC address from a list
951 * @list: MAC address list
952 * @num_entries: Number of addresses in the list
953 * @addr: Address to search for
954 * @vlan_id: Buffer for returning VLAN ID or %NULL if not needed
955 * Returns: 1 if address is in the list or 0 if not.
956 *
957 * Perform a binary search for given MAC address from a pre-sorted list.
958 */
959int hostapd_maclist_found(struct mac_acl_entry *list, int num_entries,
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800960 const u8 *addr, struct vlan_description *vlan_id)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700961{
962 int start, end, middle, res;
963
964 start = 0;
965 end = num_entries - 1;
966
967 while (start <= end) {
968 middle = (start + end) / 2;
969 res = os_memcmp(list[middle].addr, addr, ETH_ALEN);
970 if (res == 0) {
971 if (vlan_id)
972 *vlan_id = list[middle].vlan_id;
973 return 1;
974 }
975 if (res < 0)
976 start = middle + 1;
977 else
978 end = middle - 1;
979 }
980
981 return 0;
982}
983
984
985int hostapd_rate_found(int *list, int rate)
986{
987 int i;
988
989 if (list == NULL)
990 return 0;
991
992 for (i = 0; list[i] >= 0; i++)
993 if (list[i] == rate)
994 return 1;
995
996 return 0;
997}
998
999
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001000int hostapd_vlan_valid(struct hostapd_vlan *vlan,
1001 struct vlan_description *vlan_desc)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001002{
1003 struct hostapd_vlan *v = vlan;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001004 int i;
1005
1006 if (!vlan_desc->notempty || vlan_desc->untagged < 0 ||
1007 vlan_desc->untagged > MAX_VLAN_ID)
1008 return 0;
1009 for (i = 0; i < MAX_NUM_TAGGED_VLAN; i++) {
1010 if (vlan_desc->tagged[i] < 0 ||
1011 vlan_desc->tagged[i] > MAX_VLAN_ID)
1012 return 0;
1013 }
1014 if (!vlan_desc->untagged && !vlan_desc->tagged[0])
1015 return 0;
1016
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001017 while (v) {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001018 if (!vlan_compare(&v->vlan_desc, vlan_desc) ||
1019 v->vlan_id == VLAN_ID_WILDCARD)
Dmitry Shmidt34af3062013-07-11 10:46:32 -07001020 return 1;
1021 v = v->next;
1022 }
1023 return 0;
1024}
1025
1026
1027const char * hostapd_get_vlan_id_ifname(struct hostapd_vlan *vlan, int vlan_id)
1028{
1029 struct hostapd_vlan *v = vlan;
1030 while (v) {
1031 if (v->vlan_id == vlan_id)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001032 return v->ifname;
1033 v = v->next;
1034 }
1035 return NULL;
1036}
1037
1038
1039const u8 * hostapd_get_psk(const struct hostapd_bss_config *conf,
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001040 const u8 *addr, const u8 *p2p_dev_addr,
Hai Shalom021b0b52019-04-10 11:17:58 -07001041 const u8 *prev_psk, int *vlan_id)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001042{
1043 struct hostapd_wpa_psk *psk;
1044 int next_ok = prev_psk == NULL;
1045
Hai Shalom021b0b52019-04-10 11:17:58 -07001046 if (vlan_id)
1047 *vlan_id = 0;
1048
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001049 if (p2p_dev_addr && !is_zero_ether_addr(p2p_dev_addr)) {
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001050 wpa_printf(MSG_DEBUG, "Searching a PSK for " MACSTR
1051 " p2p_dev_addr=" MACSTR " prev_psk=%p",
1052 MAC2STR(addr), MAC2STR(p2p_dev_addr), prev_psk);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001053 addr = NULL; /* Use P2P Device Address for matching */
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001054 } else {
1055 wpa_printf(MSG_DEBUG, "Searching a PSK for " MACSTR
1056 " prev_psk=%p",
1057 MAC2STR(addr), prev_psk);
1058 }
1059
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001060 for (psk = conf->ssid.wpa_psk; psk != NULL; psk = psk->next) {
1061 if (next_ok &&
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001062 (psk->group ||
1063 (addr && os_memcmp(psk->addr, addr, ETH_ALEN) == 0) ||
1064 (!addr && p2p_dev_addr &&
1065 os_memcmp(psk->p2p_dev_addr, p2p_dev_addr, ETH_ALEN) ==
Hai Shalom021b0b52019-04-10 11:17:58 -07001066 0))) {
1067 if (vlan_id)
1068 *vlan_id = psk->vlan_id;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001069 return psk->psk;
Hai Shalom021b0b52019-04-10 11:17:58 -07001070 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001071
1072 if (psk->psk == prev_psk)
1073 next_ok = 1;
1074 }
1075
1076 return NULL;
1077}
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001078
1079
1080static int hostapd_config_check_bss(struct hostapd_bss_config *bss,
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001081 struct hostapd_config *conf,
1082 int full_config)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001083{
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001084 if (full_config && bss->ieee802_1x && !bss->eap_server &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001085 !bss->radius->auth_servers) {
1086 wpa_printf(MSG_ERROR, "Invalid IEEE 802.1X configuration (no "
1087 "EAP authenticator configured).");
1088 return -1;
1089 }
1090
1091 if (bss->wpa) {
1092 int wep, i;
1093
1094 wep = bss->default_wep_key_len > 0 ||
1095 bss->individual_wep_key_len > 0;
1096 for (i = 0; i < NUM_WEP_KEYS; i++) {
1097 if (bss->ssid.wep.keys_set) {
1098 wep = 1;
1099 break;
1100 }
1101 }
1102
1103 if (wep) {
1104 wpa_printf(MSG_ERROR, "WEP configuration in a WPA network is not supported");
1105 return -1;
1106 }
1107 }
1108
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001109 if (full_config && bss->wpa &&
1110 bss->wpa_psk_radius != PSK_RADIUS_IGNORED &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001111 bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH) {
1112 wpa_printf(MSG_ERROR, "WPA-PSK using RADIUS enabled, but no "
1113 "RADIUS checking (macaddr_acl=2) enabled.");
1114 return -1;
1115 }
1116
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001117 if (full_config && bss->wpa && (bss->wpa_key_mgmt & WPA_KEY_MGMT_PSK) &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001118 bss->ssid.wpa_psk == NULL && bss->ssid.wpa_passphrase == NULL &&
1119 bss->ssid.wpa_psk_file == NULL &&
1120 (bss->wpa_psk_radius != PSK_RADIUS_REQUIRED ||
1121 bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH)) {
1122 wpa_printf(MSG_ERROR, "WPA-PSK enabled, but PSK or passphrase "
1123 "is not configured.");
1124 return -1;
1125 }
1126
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001127 if (full_config && !is_zero_ether_addr(bss->bssid)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001128 size_t i;
1129
1130 for (i = 0; i < conf->num_bss; i++) {
1131 if (conf->bss[i] != bss &&
1132 (hostapd_mac_comp(conf->bss[i]->bssid,
1133 bss->bssid) == 0)) {
1134 wpa_printf(MSG_ERROR, "Duplicate BSSID " MACSTR
1135 " on interface '%s' and '%s'.",
1136 MAC2STR(bss->bssid),
1137 conf->bss[i]->iface, bss->iface);
1138 return -1;
1139 }
1140 }
1141 }
1142
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001143#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001144 if (full_config && wpa_key_mgmt_ft(bss->wpa_key_mgmt) &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001145 (bss->nas_identifier == NULL ||
1146 os_strlen(bss->nas_identifier) < 1 ||
1147 os_strlen(bss->nas_identifier) > FT_R0KH_ID_MAX_LEN)) {
1148 wpa_printf(MSG_ERROR, "FT (IEEE 802.11r) requires "
1149 "nas_identifier to be configured as a 1..48 octet "
1150 "string");
1151 return -1;
1152 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001153#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001154
1155#ifdef CONFIG_IEEE80211N
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001156 if (full_config && conf->ieee80211n &&
1157 conf->hw_mode == HOSTAPD_MODE_IEEE80211B) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001158 bss->disable_11n = 1;
1159 wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) in 11b mode is not "
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001160 "allowed, disabling HT capabilities");
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001161 }
1162
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001163 if (full_config && conf->ieee80211n &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001164 bss->ssid.security_policy == SECURITY_STATIC_WEP) {
1165 bss->disable_11n = 1;
1166 wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) with WEP is not "
1167 "allowed, disabling HT capabilities");
1168 }
1169
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001170 if (full_config && conf->ieee80211n && bss->wpa &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001171 !(bss->wpa_pairwise & WPA_CIPHER_CCMP) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001172 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
1173 WPA_CIPHER_CCMP_256 | WPA_CIPHER_GCMP_256)))
1174 {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001175 bss->disable_11n = 1;
1176 wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) with WPA/WPA2 "
1177 "requires CCMP/GCMP to be enabled, disabling HT "
1178 "capabilities");
1179 }
1180#endif /* CONFIG_IEEE80211N */
1181
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07001182#ifdef CONFIG_IEEE80211AC
1183 if (full_config && conf->ieee80211ac &&
1184 bss->ssid.security_policy == SECURITY_STATIC_WEP) {
1185 bss->disable_11ac = 1;
1186 wpa_printf(MSG_ERROR,
1187 "VHT (IEEE 802.11ac) with WEP is not allowed, disabling VHT capabilities");
1188 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001189
1190 if (full_config && conf->ieee80211ac && bss->wpa &&
1191 !(bss->wpa_pairwise & WPA_CIPHER_CCMP) &&
1192 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
1193 WPA_CIPHER_CCMP_256 | WPA_CIPHER_GCMP_256)))
1194 {
1195 bss->disable_11ac = 1;
1196 wpa_printf(MSG_ERROR,
1197 "VHT (IEEE 802.11ac) with WPA/WPA2 requires CCMP/GCMP to be enabled, disabling VHT capabilities");
1198 }
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07001199#endif /* CONFIG_IEEE80211AC */
1200
Dmitry Shmidt15907092014-03-25 10:42:57 -07001201#ifdef CONFIG_WPS
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001202 if (full_config && bss->wps_state && bss->ignore_broadcast_ssid) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001203 wpa_printf(MSG_INFO, "WPS: ignore_broadcast_ssid "
1204 "configuration forced WPS to be disabled");
1205 bss->wps_state = 0;
1206 }
1207
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001208 if (full_config && bss->wps_state &&
1209 bss->ssid.wep.keys_set && bss->wpa == 0) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001210 wpa_printf(MSG_INFO, "WPS: WEP configuration forced WPS to be "
1211 "disabled");
1212 bss->wps_state = 0;
1213 }
1214
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001215 if (full_config && bss->wps_state && bss->wpa &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001216 (!(bss->wpa & 2) ||
Roshan Pius3a1667e2018-07-03 15:17:14 -07001217 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
1218 WPA_CIPHER_CCMP_256 |
1219 WPA_CIPHER_GCMP_256)))) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001220 wpa_printf(MSG_INFO, "WPS: WPA/TKIP configuration without "
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07001221 "WPA2/CCMP/GCMP forced WPS to be disabled");
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001222 bss->wps_state = 0;
1223 }
Dmitry Shmidt15907092014-03-25 10:42:57 -07001224#endif /* CONFIG_WPS */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001225
1226#ifdef CONFIG_HS20
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001227 if (full_config && bss->hs20 &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001228 (!(bss->wpa & 2) ||
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001229 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
1230 WPA_CIPHER_CCMP_256 |
1231 WPA_CIPHER_GCMP_256)))) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001232 wpa_printf(MSG_ERROR, "HS 2.0: WPA2-Enterprise/CCMP "
1233 "configuration is required for Hotspot 2.0 "
1234 "functionality");
1235 return -1;
1236 }
1237#endif /* CONFIG_HS20 */
1238
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001239#ifdef CONFIG_MBO
1240 if (full_config && bss->mbo_enabled && (bss->wpa & 2) &&
1241 bss->ieee80211w == NO_MGMT_FRAME_PROTECTION) {
1242 wpa_printf(MSG_ERROR,
1243 "MBO: PMF needs to be enabled whenever using WPA2 with MBO");
1244 return -1;
1245 }
1246#endif /* CONFIG_MBO */
1247
Hai Shalom74f70d42019-02-11 14:42:39 -08001248#ifdef CONFIG_OCV
1249 if (full_config && bss->ieee80211w == NO_MGMT_FRAME_PROTECTION &&
1250 bss->ocv) {
1251 wpa_printf(MSG_ERROR,
1252 "OCV: PMF needs to be enabled whenever using OCV");
1253 return -1;
1254 }
1255#endif /* CONFIG_OCV */
1256
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001257 return 0;
1258}
1259
1260
Dmitry Shmidt05df46a2015-05-19 11:02:01 -07001261static int hostapd_config_check_cw(struct hostapd_config *conf, int queue)
1262{
1263 int tx_cwmin = conf->tx_queue[queue].cwmin;
1264 int tx_cwmax = conf->tx_queue[queue].cwmax;
1265 int ac_cwmin = conf->wmm_ac_params[queue].cwmin;
1266 int ac_cwmax = conf->wmm_ac_params[queue].cwmax;
1267
1268 if (tx_cwmin > tx_cwmax) {
1269 wpa_printf(MSG_ERROR,
1270 "Invalid TX queue cwMin/cwMax values. cwMin(%d) greater than cwMax(%d)",
1271 tx_cwmin, tx_cwmax);
1272 return -1;
1273 }
1274 if (ac_cwmin > ac_cwmax) {
1275 wpa_printf(MSG_ERROR,
1276 "Invalid WMM AC cwMin/cwMax values. cwMin(%d) greater than cwMax(%d)",
1277 ac_cwmin, ac_cwmax);
1278 return -1;
1279 }
1280 return 0;
1281}
1282
1283
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001284int hostapd_config_check(struct hostapd_config *conf, int full_config)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001285{
1286 size_t i;
1287
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001288 if (full_config && conf->ieee80211d &&
1289 (!conf->country[0] || !conf->country[1])) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001290 wpa_printf(MSG_ERROR, "Cannot enable IEEE 802.11d without "
1291 "setting the country_code");
1292 return -1;
1293 }
1294
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001295 if (full_config && conf->ieee80211h && !conf->ieee80211d) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001296 wpa_printf(MSG_ERROR, "Cannot enable IEEE 802.11h without "
1297 "IEEE 802.11d enabled");
1298 return -1;
1299 }
1300
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001301 if (full_config && conf->local_pwr_constraint != -1 &&
1302 !conf->ieee80211d) {
1303 wpa_printf(MSG_ERROR, "Cannot add Power Constraint element without Country element");
1304 return -1;
1305 }
1306
1307 if (full_config && conf->spectrum_mgmt_required &&
1308 conf->local_pwr_constraint == -1) {
1309 wpa_printf(MSG_ERROR, "Cannot set Spectrum Management bit without Country and Power Constraint elements");
1310 return -1;
1311 }
1312
Hai Shalom81f62d82019-07-22 12:10:00 -07001313#ifdef CONFIG_AIRTIME_POLICY
1314 if (full_config && conf->airtime_mode > AIRTIME_MODE_STATIC &&
1315 !conf->airtime_update_interval) {
1316 wpa_printf(MSG_ERROR, "Airtime update interval cannot be zero");
1317 return -1;
1318 }
1319#endif /* CONFIG_AIRTIME_POLICY */
Dmitry Shmidt05df46a2015-05-19 11:02:01 -07001320 for (i = 0; i < NUM_TX_QUEUES; i++) {
1321 if (hostapd_config_check_cw(conf, i))
1322 return -1;
1323 }
1324
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001325 for (i = 0; i < conf->num_bss; i++) {
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001326 if (hostapd_config_check_bss(conf->bss[i], conf, full_config))
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001327 return -1;
1328 }
1329
1330 return 0;
1331}
1332
1333
Dmitry Shmidt71757432014-06-02 13:50:35 -07001334void hostapd_set_security_params(struct hostapd_bss_config *bss,
1335 int full_config)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001336{
1337 if (bss->individual_wep_key_len == 0) {
1338 /* individual keys are not use; can use key idx0 for
1339 * broadcast keys */
1340 bss->broadcast_key_idx_min = 0;
1341 }
1342
1343 if ((bss->wpa & 2) && bss->rsn_pairwise == 0)
1344 bss->rsn_pairwise = bss->wpa_pairwise;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001345 if (bss->group_cipher)
1346 bss->wpa_group = bss->group_cipher;
1347 else
1348 bss->wpa_group = wpa_select_ap_group_cipher(bss->wpa,
1349 bss->wpa_pairwise,
1350 bss->rsn_pairwise);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001351 if (!bss->wpa_group_rekey_set)
1352 bss->wpa_group_rekey = bss->wpa_group == WPA_CIPHER_TKIP ?
1353 600 : 86400;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001354
Dmitry Shmidt71757432014-06-02 13:50:35 -07001355 if (full_config) {
1356 bss->radius->auth_server = bss->radius->auth_servers;
1357 bss->radius->acct_server = bss->radius->acct_servers;
1358 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001359
1360 if (bss->wpa && bss->ieee802_1x) {
1361 bss->ssid.security_policy = SECURITY_WPA;
1362 } else if (bss->wpa) {
1363 bss->ssid.security_policy = SECURITY_WPA_PSK;
1364 } else if (bss->ieee802_1x) {
1365 int cipher = WPA_CIPHER_NONE;
1366 bss->ssid.security_policy = SECURITY_IEEE_802_1X;
1367 bss->ssid.wep.default_len = bss->default_wep_key_len;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001368 if (full_config && bss->default_wep_key_len) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001369 cipher = bss->default_wep_key_len >= 13 ?
1370 WPA_CIPHER_WEP104 : WPA_CIPHER_WEP40;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001371 } else if (full_config && bss->ssid.wep.keys_set) {
1372 if (bss->ssid.wep.len[0] >= 13)
1373 cipher = WPA_CIPHER_WEP104;
1374 else
1375 cipher = WPA_CIPHER_WEP40;
1376 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001377 bss->wpa_group = cipher;
1378 bss->wpa_pairwise = cipher;
1379 bss->rsn_pairwise = cipher;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001380 if (full_config)
1381 bss->wpa_key_mgmt = WPA_KEY_MGMT_IEEE8021X_NO_WPA;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001382 } else if (bss->ssid.wep.keys_set) {
1383 int cipher = WPA_CIPHER_WEP40;
1384 if (bss->ssid.wep.len[0] >= 13)
1385 cipher = WPA_CIPHER_WEP104;
1386 bss->ssid.security_policy = SECURITY_STATIC_WEP;
1387 bss->wpa_group = cipher;
1388 bss->wpa_pairwise = cipher;
1389 bss->rsn_pairwise = cipher;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001390 if (full_config)
1391 bss->wpa_key_mgmt = WPA_KEY_MGMT_NONE;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001392 } else if (bss->osen) {
1393 bss->ssid.security_policy = SECURITY_OSEN;
1394 bss->wpa_group = WPA_CIPHER_CCMP;
1395 bss->wpa_pairwise = 0;
1396 bss->rsn_pairwise = WPA_CIPHER_CCMP;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001397 } else {
1398 bss->ssid.security_policy = SECURITY_PLAINTEXT;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001399 if (full_config) {
1400 bss->wpa_group = WPA_CIPHER_NONE;
1401 bss->wpa_pairwise = WPA_CIPHER_NONE;
1402 bss->rsn_pairwise = WPA_CIPHER_NONE;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001403 bss->wpa_key_mgmt = WPA_KEY_MGMT_NONE;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001404 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001405 }
1406}
Hai Shalom74f70d42019-02-11 14:42:39 -08001407
1408
1409int hostapd_sae_pw_id_in_use(struct hostapd_bss_config *conf)
1410{
1411 int with_id = 0, without_id = 0;
1412 struct sae_password_entry *pw;
1413
1414 if (conf->ssid.wpa_passphrase)
1415 without_id = 1;
1416
1417 for (pw = conf->sae_passwords; pw; pw = pw->next) {
1418 if (pw->identifier)
1419 with_id = 1;
1420 else
1421 without_id = 1;
1422 if (with_id && without_id)
1423 break;
1424 }
1425
1426 if (with_id && !without_id)
1427 return 2;
1428 return with_id;
1429}