blob: 68af3c1d167dcb648ae3179ad7188e12280ab0d5 [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
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800444 if (conf->sae_pwe == 0 || !wpa_key_mgmt_sae(conf->wpa_key_mgmt))
Hai Shalomc3565922019-10-28 11:58:20 -0700445 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);
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800883 wpabuf_free(conf->rsnxe_override_eapol);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800884#endif /* CONFIG_TESTING_OPTIONS */
885
886 os_free(conf->no_probe_resp_if_seen_on);
887 os_free(conf->no_auth_if_seen_on);
888
Dmitry Shmidt29333592017-01-09 12:27:11 -0800889 hostapd_config_free_fils_realms(conf);
890
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700891#ifdef CONFIG_DPP
Hai Shalomc3565922019-10-28 11:58:20 -0700892 os_free(conf->dpp_name);
893 os_free(conf->dpp_mud_url);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700894 os_free(conf->dpp_connector);
895 wpabuf_free(conf->dpp_netaccesskey);
896 wpabuf_free(conf->dpp_csign);
Hai Shalom81f62d82019-07-22 12:10:00 -0700897#ifdef CONFIG_DPP2
898 hostapd_dpp_controller_conf_free(conf->dpp_controller);
899#endif /* CONFIG_DPP2 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700900#endif /* CONFIG_DPP */
901
Roshan Pius3a1667e2018-07-03 15:17:14 -0700902 hostapd_config_free_sae_passwords(conf);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700903
Hai Shalom81f62d82019-07-22 12:10:00 -0700904#ifdef CONFIG_AIRTIME_POLICY
905 {
906 struct airtime_sta_weight *wt, *wt_prev;
907
908 wt = conf->airtime_weight_list;
909 conf->airtime_weight_list = NULL;
910 while (wt) {
911 wt_prev = wt;
912 wt = wt->next;
913 os_free(wt_prev);
914 }
915 }
916#endif /* CONFIG_AIRTIME_POLICY */
917
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800918 os_free(conf);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700919}
920
921
922/**
923 * hostapd_config_free - Free hostapd configuration
924 * @conf: Configuration data from hostapd_config_read().
925 */
926void hostapd_config_free(struct hostapd_config *conf)
927{
928 size_t i;
929
930 if (conf == NULL)
931 return;
932
933 for (i = 0; i < conf->num_bss; i++)
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800934 hostapd_config_free_bss(conf->bss[i]);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700935 os_free(conf->bss);
936 os_free(conf->supported_rates);
937 os_free(conf->basic_rates);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700938 os_free(conf->acs_ch_list.range);
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800939 os_free(conf->acs_freq_list.range);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800940 os_free(conf->driver_params);
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800941#ifdef CONFIG_ACS
942 os_free(conf->acs_chan_bias);
943#endif /* CONFIG_ACS */
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700944 wpabuf_free(conf->lci);
945 wpabuf_free(conf->civic);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700946
947 os_free(conf);
948}
949
950
951/**
952 * hostapd_maclist_found - Find a MAC address from a list
953 * @list: MAC address list
954 * @num_entries: Number of addresses in the list
955 * @addr: Address to search for
956 * @vlan_id: Buffer for returning VLAN ID or %NULL if not needed
957 * Returns: 1 if address is in the list or 0 if not.
958 *
959 * Perform a binary search for given MAC address from a pre-sorted list.
960 */
961int hostapd_maclist_found(struct mac_acl_entry *list, int num_entries,
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800962 const u8 *addr, struct vlan_description *vlan_id)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700963{
964 int start, end, middle, res;
965
966 start = 0;
967 end = num_entries - 1;
968
969 while (start <= end) {
970 middle = (start + end) / 2;
971 res = os_memcmp(list[middle].addr, addr, ETH_ALEN);
972 if (res == 0) {
973 if (vlan_id)
974 *vlan_id = list[middle].vlan_id;
975 return 1;
976 }
977 if (res < 0)
978 start = middle + 1;
979 else
980 end = middle - 1;
981 }
982
983 return 0;
984}
985
986
987int hostapd_rate_found(int *list, int rate)
988{
989 int i;
990
991 if (list == NULL)
992 return 0;
993
994 for (i = 0; list[i] >= 0; i++)
995 if (list[i] == rate)
996 return 1;
997
998 return 0;
999}
1000
1001
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001002int hostapd_vlan_valid(struct hostapd_vlan *vlan,
1003 struct vlan_description *vlan_desc)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001004{
1005 struct hostapd_vlan *v = vlan;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001006 int i;
1007
1008 if (!vlan_desc->notempty || vlan_desc->untagged < 0 ||
1009 vlan_desc->untagged > MAX_VLAN_ID)
1010 return 0;
1011 for (i = 0; i < MAX_NUM_TAGGED_VLAN; i++) {
1012 if (vlan_desc->tagged[i] < 0 ||
1013 vlan_desc->tagged[i] > MAX_VLAN_ID)
1014 return 0;
1015 }
1016 if (!vlan_desc->untagged && !vlan_desc->tagged[0])
1017 return 0;
1018
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001019 while (v) {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001020 if (!vlan_compare(&v->vlan_desc, vlan_desc) ||
1021 v->vlan_id == VLAN_ID_WILDCARD)
Dmitry Shmidt34af3062013-07-11 10:46:32 -07001022 return 1;
1023 v = v->next;
1024 }
1025 return 0;
1026}
1027
1028
1029const char * hostapd_get_vlan_id_ifname(struct hostapd_vlan *vlan, int vlan_id)
1030{
1031 struct hostapd_vlan *v = vlan;
1032 while (v) {
1033 if (v->vlan_id == vlan_id)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001034 return v->ifname;
1035 v = v->next;
1036 }
1037 return NULL;
1038}
1039
1040
1041const u8 * hostapd_get_psk(const struct hostapd_bss_config *conf,
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001042 const u8 *addr, const u8 *p2p_dev_addr,
Hai Shalom021b0b52019-04-10 11:17:58 -07001043 const u8 *prev_psk, int *vlan_id)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001044{
1045 struct hostapd_wpa_psk *psk;
1046 int next_ok = prev_psk == NULL;
1047
Hai Shalom021b0b52019-04-10 11:17:58 -07001048 if (vlan_id)
1049 *vlan_id = 0;
1050
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001051 if (p2p_dev_addr && !is_zero_ether_addr(p2p_dev_addr)) {
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001052 wpa_printf(MSG_DEBUG, "Searching a PSK for " MACSTR
1053 " p2p_dev_addr=" MACSTR " prev_psk=%p",
1054 MAC2STR(addr), MAC2STR(p2p_dev_addr), prev_psk);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001055 addr = NULL; /* Use P2P Device Address for matching */
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001056 } else {
1057 wpa_printf(MSG_DEBUG, "Searching a PSK for " MACSTR
1058 " prev_psk=%p",
1059 MAC2STR(addr), prev_psk);
1060 }
1061
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001062 for (psk = conf->ssid.wpa_psk; psk != NULL; psk = psk->next) {
1063 if (next_ok &&
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001064 (psk->group ||
1065 (addr && os_memcmp(psk->addr, addr, ETH_ALEN) == 0) ||
1066 (!addr && p2p_dev_addr &&
1067 os_memcmp(psk->p2p_dev_addr, p2p_dev_addr, ETH_ALEN) ==
Hai Shalom021b0b52019-04-10 11:17:58 -07001068 0))) {
1069 if (vlan_id)
1070 *vlan_id = psk->vlan_id;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001071 return psk->psk;
Hai Shalom021b0b52019-04-10 11:17:58 -07001072 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001073
1074 if (psk->psk == prev_psk)
1075 next_ok = 1;
1076 }
1077
1078 return NULL;
1079}
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001080
1081
1082static int hostapd_config_check_bss(struct hostapd_bss_config *bss,
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001083 struct hostapd_config *conf,
1084 int full_config)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001085{
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001086 if (full_config && bss->ieee802_1x && !bss->eap_server &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001087 !bss->radius->auth_servers) {
1088 wpa_printf(MSG_ERROR, "Invalid IEEE 802.1X configuration (no "
1089 "EAP authenticator configured).");
1090 return -1;
1091 }
1092
1093 if (bss->wpa) {
1094 int wep, i;
1095
1096 wep = bss->default_wep_key_len > 0 ||
1097 bss->individual_wep_key_len > 0;
1098 for (i = 0; i < NUM_WEP_KEYS; i++) {
1099 if (bss->ssid.wep.keys_set) {
1100 wep = 1;
1101 break;
1102 }
1103 }
1104
1105 if (wep) {
1106 wpa_printf(MSG_ERROR, "WEP configuration in a WPA network is not supported");
1107 return -1;
1108 }
1109 }
1110
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001111 if (full_config && bss->wpa &&
1112 bss->wpa_psk_radius != PSK_RADIUS_IGNORED &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001113 bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH) {
1114 wpa_printf(MSG_ERROR, "WPA-PSK using RADIUS enabled, but no "
1115 "RADIUS checking (macaddr_acl=2) enabled.");
1116 return -1;
1117 }
1118
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001119 if (full_config && bss->wpa && (bss->wpa_key_mgmt & WPA_KEY_MGMT_PSK) &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001120 bss->ssid.wpa_psk == NULL && bss->ssid.wpa_passphrase == NULL &&
1121 bss->ssid.wpa_psk_file == NULL &&
1122 (bss->wpa_psk_radius != PSK_RADIUS_REQUIRED ||
1123 bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH)) {
1124 wpa_printf(MSG_ERROR, "WPA-PSK enabled, but PSK or passphrase "
1125 "is not configured.");
1126 return -1;
1127 }
1128
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001129 if (full_config && !is_zero_ether_addr(bss->bssid)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001130 size_t i;
1131
1132 for (i = 0; i < conf->num_bss; i++) {
1133 if (conf->bss[i] != bss &&
1134 (hostapd_mac_comp(conf->bss[i]->bssid,
1135 bss->bssid) == 0)) {
1136 wpa_printf(MSG_ERROR, "Duplicate BSSID " MACSTR
1137 " on interface '%s' and '%s'.",
1138 MAC2STR(bss->bssid),
1139 conf->bss[i]->iface, bss->iface);
1140 return -1;
1141 }
1142 }
1143 }
1144
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001145#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001146 if (full_config && wpa_key_mgmt_ft(bss->wpa_key_mgmt) &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001147 (bss->nas_identifier == NULL ||
1148 os_strlen(bss->nas_identifier) < 1 ||
1149 os_strlen(bss->nas_identifier) > FT_R0KH_ID_MAX_LEN)) {
1150 wpa_printf(MSG_ERROR, "FT (IEEE 802.11r) requires "
1151 "nas_identifier to be configured as a 1..48 octet "
1152 "string");
1153 return -1;
1154 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001155#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001156
1157#ifdef CONFIG_IEEE80211N
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001158 if (full_config && conf->ieee80211n &&
1159 conf->hw_mode == HOSTAPD_MODE_IEEE80211B) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001160 bss->disable_11n = 1;
1161 wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) in 11b mode is not "
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001162 "allowed, disabling HT capabilities");
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001163 }
1164
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001165 if (full_config && conf->ieee80211n &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001166 bss->ssid.security_policy == SECURITY_STATIC_WEP) {
1167 bss->disable_11n = 1;
1168 wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) with WEP is not "
1169 "allowed, disabling HT capabilities");
1170 }
1171
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001172 if (full_config && conf->ieee80211n && bss->wpa &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001173 !(bss->wpa_pairwise & WPA_CIPHER_CCMP) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001174 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
1175 WPA_CIPHER_CCMP_256 | WPA_CIPHER_GCMP_256)))
1176 {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001177 bss->disable_11n = 1;
1178 wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) with WPA/WPA2 "
1179 "requires CCMP/GCMP to be enabled, disabling HT "
1180 "capabilities");
1181 }
1182#endif /* CONFIG_IEEE80211N */
1183
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07001184#ifdef CONFIG_IEEE80211AC
1185 if (full_config && conf->ieee80211ac &&
1186 bss->ssid.security_policy == SECURITY_STATIC_WEP) {
1187 bss->disable_11ac = 1;
1188 wpa_printf(MSG_ERROR,
1189 "VHT (IEEE 802.11ac) with WEP is not allowed, disabling VHT capabilities");
1190 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001191
1192 if (full_config && conf->ieee80211ac && bss->wpa &&
1193 !(bss->wpa_pairwise & WPA_CIPHER_CCMP) &&
1194 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
1195 WPA_CIPHER_CCMP_256 | WPA_CIPHER_GCMP_256)))
1196 {
1197 bss->disable_11ac = 1;
1198 wpa_printf(MSG_ERROR,
1199 "VHT (IEEE 802.11ac) with WPA/WPA2 requires CCMP/GCMP to be enabled, disabling VHT capabilities");
1200 }
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07001201#endif /* CONFIG_IEEE80211AC */
1202
Dmitry Shmidt15907092014-03-25 10:42:57 -07001203#ifdef CONFIG_WPS
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001204 if (full_config && bss->wps_state && bss->ignore_broadcast_ssid) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001205 wpa_printf(MSG_INFO, "WPS: ignore_broadcast_ssid "
1206 "configuration forced WPS to be disabled");
1207 bss->wps_state = 0;
1208 }
1209
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001210 if (full_config && bss->wps_state &&
1211 bss->ssid.wep.keys_set && bss->wpa == 0) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001212 wpa_printf(MSG_INFO, "WPS: WEP configuration forced WPS to be "
1213 "disabled");
1214 bss->wps_state = 0;
1215 }
1216
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001217 if (full_config && bss->wps_state && bss->wpa &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001218 (!(bss->wpa & 2) ||
Roshan Pius3a1667e2018-07-03 15:17:14 -07001219 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
1220 WPA_CIPHER_CCMP_256 |
1221 WPA_CIPHER_GCMP_256)))) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001222 wpa_printf(MSG_INFO, "WPS: WPA/TKIP configuration without "
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07001223 "WPA2/CCMP/GCMP forced WPS to be disabled");
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001224 bss->wps_state = 0;
1225 }
Dmitry Shmidt15907092014-03-25 10:42:57 -07001226#endif /* CONFIG_WPS */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001227
1228#ifdef CONFIG_HS20
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001229 if (full_config && bss->hs20 &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001230 (!(bss->wpa & 2) ||
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001231 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
1232 WPA_CIPHER_CCMP_256 |
1233 WPA_CIPHER_GCMP_256)))) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001234 wpa_printf(MSG_ERROR, "HS 2.0: WPA2-Enterprise/CCMP "
1235 "configuration is required for Hotspot 2.0 "
1236 "functionality");
1237 return -1;
1238 }
1239#endif /* CONFIG_HS20 */
1240
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001241#ifdef CONFIG_MBO
1242 if (full_config && bss->mbo_enabled && (bss->wpa & 2) &&
1243 bss->ieee80211w == NO_MGMT_FRAME_PROTECTION) {
1244 wpa_printf(MSG_ERROR,
1245 "MBO: PMF needs to be enabled whenever using WPA2 with MBO");
1246 return -1;
1247 }
1248#endif /* CONFIG_MBO */
1249
Hai Shalom74f70d42019-02-11 14:42:39 -08001250#ifdef CONFIG_OCV
1251 if (full_config && bss->ieee80211w == NO_MGMT_FRAME_PROTECTION &&
1252 bss->ocv) {
1253 wpa_printf(MSG_ERROR,
1254 "OCV: PMF needs to be enabled whenever using OCV");
1255 return -1;
1256 }
1257#endif /* CONFIG_OCV */
1258
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001259 return 0;
1260}
1261
1262
Dmitry Shmidt05df46a2015-05-19 11:02:01 -07001263static int hostapd_config_check_cw(struct hostapd_config *conf, int queue)
1264{
1265 int tx_cwmin = conf->tx_queue[queue].cwmin;
1266 int tx_cwmax = conf->tx_queue[queue].cwmax;
1267 int ac_cwmin = conf->wmm_ac_params[queue].cwmin;
1268 int ac_cwmax = conf->wmm_ac_params[queue].cwmax;
1269
1270 if (tx_cwmin > tx_cwmax) {
1271 wpa_printf(MSG_ERROR,
1272 "Invalid TX queue cwMin/cwMax values. cwMin(%d) greater than cwMax(%d)",
1273 tx_cwmin, tx_cwmax);
1274 return -1;
1275 }
1276 if (ac_cwmin > ac_cwmax) {
1277 wpa_printf(MSG_ERROR,
1278 "Invalid WMM AC cwMin/cwMax values. cwMin(%d) greater than cwMax(%d)",
1279 ac_cwmin, ac_cwmax);
1280 return -1;
1281 }
1282 return 0;
1283}
1284
1285
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001286int hostapd_config_check(struct hostapd_config *conf, int full_config)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001287{
1288 size_t i;
1289
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001290 if (full_config && conf->ieee80211d &&
1291 (!conf->country[0] || !conf->country[1])) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001292 wpa_printf(MSG_ERROR, "Cannot enable IEEE 802.11d without "
1293 "setting the country_code");
1294 return -1;
1295 }
1296
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001297 if (full_config && conf->ieee80211h && !conf->ieee80211d) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001298 wpa_printf(MSG_ERROR, "Cannot enable IEEE 802.11h without "
1299 "IEEE 802.11d enabled");
1300 return -1;
1301 }
1302
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001303 if (full_config && conf->local_pwr_constraint != -1 &&
1304 !conf->ieee80211d) {
1305 wpa_printf(MSG_ERROR, "Cannot add Power Constraint element without Country element");
1306 return -1;
1307 }
1308
1309 if (full_config && conf->spectrum_mgmt_required &&
1310 conf->local_pwr_constraint == -1) {
1311 wpa_printf(MSG_ERROR, "Cannot set Spectrum Management bit without Country and Power Constraint elements");
1312 return -1;
1313 }
1314
Hai Shalom81f62d82019-07-22 12:10:00 -07001315#ifdef CONFIG_AIRTIME_POLICY
1316 if (full_config && conf->airtime_mode > AIRTIME_MODE_STATIC &&
1317 !conf->airtime_update_interval) {
1318 wpa_printf(MSG_ERROR, "Airtime update interval cannot be zero");
1319 return -1;
1320 }
1321#endif /* CONFIG_AIRTIME_POLICY */
Dmitry Shmidt05df46a2015-05-19 11:02:01 -07001322 for (i = 0; i < NUM_TX_QUEUES; i++) {
1323 if (hostapd_config_check_cw(conf, i))
1324 return -1;
1325 }
1326
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001327 for (i = 0; i < conf->num_bss; i++) {
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001328 if (hostapd_config_check_bss(conf->bss[i], conf, full_config))
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001329 return -1;
1330 }
1331
1332 return 0;
1333}
1334
1335
Dmitry Shmidt71757432014-06-02 13:50:35 -07001336void hostapd_set_security_params(struct hostapd_bss_config *bss,
1337 int full_config)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001338{
1339 if (bss->individual_wep_key_len == 0) {
1340 /* individual keys are not use; can use key idx0 for
1341 * broadcast keys */
1342 bss->broadcast_key_idx_min = 0;
1343 }
1344
1345 if ((bss->wpa & 2) && bss->rsn_pairwise == 0)
1346 bss->rsn_pairwise = bss->wpa_pairwise;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001347 if (bss->group_cipher)
1348 bss->wpa_group = bss->group_cipher;
1349 else
1350 bss->wpa_group = wpa_select_ap_group_cipher(bss->wpa,
1351 bss->wpa_pairwise,
1352 bss->rsn_pairwise);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001353 if (!bss->wpa_group_rekey_set)
1354 bss->wpa_group_rekey = bss->wpa_group == WPA_CIPHER_TKIP ?
1355 600 : 86400;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001356
Dmitry Shmidt71757432014-06-02 13:50:35 -07001357 if (full_config) {
1358 bss->radius->auth_server = bss->radius->auth_servers;
1359 bss->radius->acct_server = bss->radius->acct_servers;
1360 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001361
1362 if (bss->wpa && bss->ieee802_1x) {
1363 bss->ssid.security_policy = SECURITY_WPA;
1364 } else if (bss->wpa) {
1365 bss->ssid.security_policy = SECURITY_WPA_PSK;
1366 } else if (bss->ieee802_1x) {
1367 int cipher = WPA_CIPHER_NONE;
1368 bss->ssid.security_policy = SECURITY_IEEE_802_1X;
1369 bss->ssid.wep.default_len = bss->default_wep_key_len;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001370 if (full_config && bss->default_wep_key_len) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001371 cipher = bss->default_wep_key_len >= 13 ?
1372 WPA_CIPHER_WEP104 : WPA_CIPHER_WEP40;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001373 } else if (full_config && bss->ssid.wep.keys_set) {
1374 if (bss->ssid.wep.len[0] >= 13)
1375 cipher = WPA_CIPHER_WEP104;
1376 else
1377 cipher = WPA_CIPHER_WEP40;
1378 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001379 bss->wpa_group = cipher;
1380 bss->wpa_pairwise = cipher;
1381 bss->rsn_pairwise = cipher;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001382 if (full_config)
1383 bss->wpa_key_mgmt = WPA_KEY_MGMT_IEEE8021X_NO_WPA;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001384 } else if (bss->ssid.wep.keys_set) {
1385 int cipher = WPA_CIPHER_WEP40;
1386 if (bss->ssid.wep.len[0] >= 13)
1387 cipher = WPA_CIPHER_WEP104;
1388 bss->ssid.security_policy = SECURITY_STATIC_WEP;
1389 bss->wpa_group = cipher;
1390 bss->wpa_pairwise = cipher;
1391 bss->rsn_pairwise = cipher;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001392 if (full_config)
1393 bss->wpa_key_mgmt = WPA_KEY_MGMT_NONE;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001394 } else if (bss->osen) {
1395 bss->ssid.security_policy = SECURITY_OSEN;
1396 bss->wpa_group = WPA_CIPHER_CCMP;
1397 bss->wpa_pairwise = 0;
1398 bss->rsn_pairwise = WPA_CIPHER_CCMP;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001399 } else {
1400 bss->ssid.security_policy = SECURITY_PLAINTEXT;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001401 if (full_config) {
1402 bss->wpa_group = WPA_CIPHER_NONE;
1403 bss->wpa_pairwise = WPA_CIPHER_NONE;
1404 bss->rsn_pairwise = WPA_CIPHER_NONE;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001405 bss->wpa_key_mgmt = WPA_KEY_MGMT_NONE;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001406 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001407 }
1408}
Hai Shalom74f70d42019-02-11 14:42:39 -08001409
1410
1411int hostapd_sae_pw_id_in_use(struct hostapd_bss_config *conf)
1412{
1413 int with_id = 0, without_id = 0;
1414 struct sae_password_entry *pw;
1415
1416 if (conf->ssid.wpa_passphrase)
1417 without_id = 1;
1418
1419 for (pw = conf->sae_passwords; pw; pw = pw->next) {
1420 if (pw->identifier)
1421 with_id = 1;
1422 else
1423 without_id = 1;
1424 if (with_id && without_id)
1425 break;
1426 }
1427
1428 if (with_id && !without_id)
1429 return 2;
1430 return with_id;
1431}