blob: 35a32a13052812f93e4df586b975db3712e12a04 [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
Hai Shalomfdcde762020-04-02 11:19:20 -070057#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070058 bss->auth_algs = WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED;
59
60 bss->wep_rekeying_period = 300;
61 /* use key0 in individual key and key1 in broadcast key */
62 bss->broadcast_key_idx_min = 1;
63 bss->broadcast_key_idx_max = 2;
Hai Shalomfdcde762020-04-02 11:19:20 -070064#else /* CONFIG_WEP */
65 bss->auth_algs = WPA_AUTH_ALG_OPEN;
66#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070067 bss->eap_reauth_period = 3600;
68
69 bss->wpa_group_rekey = 600;
70 bss->wpa_gmk_rekey = 86400;
Hai Shalomfdcde762020-04-02 11:19:20 -070071 bss->wpa_deny_ptk0_rekey = PTK0_REKEY_ALLOW_ALWAYS;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -080072 bss->wpa_group_update_count = 4;
73 bss->wpa_pairwise_update_count = 4;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070074 bss->wpa_disable_eapol_key_retries =
75 DEFAULT_WPA_DISABLE_EAPOL_KEY_RETRIES;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070076 bss->wpa_key_mgmt = WPA_KEY_MGMT_PSK;
Hai Shalomb755a2a2020-04-23 21:49:02 -070077#ifdef CONFIG_NO_TKIP
78 bss->wpa_pairwise = WPA_CIPHER_CCMP;
79 bss->wpa_group = WPA_CIPHER_CCMP;
80#else /* CONFIG_NO_TKIP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070081 bss->wpa_pairwise = WPA_CIPHER_TKIP;
82 bss->wpa_group = WPA_CIPHER_TKIP;
Hai Shalomb755a2a2020-04-23 21:49:02 -070083#endif /* CONFIG_NO_TKIP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070084 bss->rsn_pairwise = 0;
85
86 bss->max_num_sta = MAX_STA_COUNT;
87
88 bss->dtim_period = 2;
89
90 bss->radius_server_auth_port = 1812;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080091 bss->eap_sim_db_timeout = 1;
Hai Shalomc3565922019-10-28 11:58:20 -070092 bss->eap_sim_id = 3;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070093 bss->ap_max_inactivity = AP_MAX_INACTIVITY;
94 bss->eapol_version = EAPOL_VERSION;
95
96 bss->max_listen_interval = 65535;
97
98 bss->pwd_group = 19; /* ECC: GF(p=256) */
99
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700100 bss->assoc_sa_query_max_timeout = 1000;
101 bss->assoc_sa_query_retry_timeout = 201;
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700102 bss->group_mgmt_cipher = WPA_CIPHER_AES_128_CMAC;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700103#ifdef EAP_SERVER_FAST
104 /* both anonymous and authenticated provisioning */
105 bss->eap_fast_prov = 3;
106 bss->pac_key_lifetime = 7 * 24 * 60 * 60;
107 bss->pac_key_refresh_time = 1 * 24 * 60 * 60;
108#endif /* EAP_SERVER_FAST */
109
110 /* Set to -1 as defaults depends on HT in setup */
111 bss->wmm_enabled = -1;
112
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800113#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700114 bss->ft_over_ds = 1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700115 bss->rkh_pos_timeout = 86400;
116 bss->rkh_neg_timeout = 60;
117 bss->rkh_pull_timeout = 1000;
118 bss->rkh_pull_retries = 4;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700119 bss->r0_key_lifetime = 1209600;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800120#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt04949592012-07-19 12:16:46 -0700121
122 bss->radius_das_time_window = 300;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800123
124 bss->sae_anti_clogging_threshold = 5;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700125 bss->sae_sync = 5;
Dmitry Shmidt29333592017-01-09 12:27:11 -0800126
127 bss->gas_frag_limit = 1400;
128
129#ifdef CONFIG_FILS
130 dl_list_init(&bss->fils_realms);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800131 bss->fils_hlp_wait_time = 30;
132 bss->dhcp_server_port = DHCP_SERVER_PORT;
133 bss->dhcp_relay_port = DHCP_SERVER_PORT;
Dmitry Shmidt29333592017-01-09 12:27:11 -0800134#endif /* CONFIG_FILS */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700135
136 bss->broadcast_deauth = 1;
137
138#ifdef CONFIG_MBO
139 bss->mbo_cell_data_conn_pref = -1;
140#endif /* CONFIG_MBO */
Roshan Pius3a1667e2018-07-03 15:17:14 -0700141
142 /* Disable TLS v1.3 by default for now to avoid interoperability issue.
143 * This can be enabled by default once the implementation has been fully
144 * completed and tested with other implementations. */
145 bss->tls_flags = TLS_CONN_DISABLE_TLSv1_3;
Hai Shalom74f70d42019-02-11 14:42:39 -0800146
Hai Shalomc3565922019-10-28 11:58:20 -0700147 bss->max_auth_rounds = 100;
148 bss->max_auth_rounds_short = 50;
149
Hai Shalom74f70d42019-02-11 14:42:39 -0800150 bss->send_probe_response = 1;
151
152#ifdef CONFIG_HS20
153 bss->hs20_release = (HS20_VERSION >> 4) + 1;
154#endif /* CONFIG_HS20 */
155
Hai Shalom81f62d82019-07-22 12:10:00 -0700156#ifdef CONFIG_MACSEC
157 bss->mka_priority = DEFAULT_PRIO_NOT_KEY_SERVER;
158 bss->macsec_port = 1;
159#endif /* CONFIG_MACSEC */
160
Hai Shalom74f70d42019-02-11 14:42:39 -0800161 /* Default to strict CRL checking. */
162 bss->check_crl_strict = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700163}
164
165
166struct hostapd_config * hostapd_config_defaults(void)
167{
168#define ecw2cw(ecw) ((1 << (ecw)) - 1)
169
170 struct hostapd_config *conf;
171 struct hostapd_bss_config *bss;
172 const int aCWmin = 4, aCWmax = 10;
173 const struct hostapd_wmm_ac_params ac_bk =
174 { aCWmin, aCWmax, 7, 0, 0 }; /* background traffic */
175 const struct hostapd_wmm_ac_params ac_be =
176 { aCWmin, aCWmax, 3, 0, 0 }; /* best effort traffic */
177 const struct hostapd_wmm_ac_params ac_vi = /* video traffic */
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700178 { aCWmin - 1, aCWmin, 2, 3008 / 32, 0 };
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700179 const struct hostapd_wmm_ac_params ac_vo = /* voice traffic */
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700180 { aCWmin - 2, aCWmin - 1, 2, 1504 / 32, 0 };
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700181 const struct hostapd_tx_queue_params txq_bk =
182 { 7, ecw2cw(aCWmin), ecw2cw(aCWmax), 0 };
183 const struct hostapd_tx_queue_params txq_be =
184 { 3, ecw2cw(aCWmin), 4 * (ecw2cw(aCWmin) + 1) - 1, 0};
185 const struct hostapd_tx_queue_params txq_vi =
186 { 1, (ecw2cw(aCWmin) + 1) / 2 - 1, ecw2cw(aCWmin), 30};
187 const struct hostapd_tx_queue_params txq_vo =
188 { 1, (ecw2cw(aCWmin) + 1) / 4 - 1,
189 (ecw2cw(aCWmin) + 1) / 2 - 1, 15};
190
191#undef ecw2cw
192
193 conf = os_zalloc(sizeof(*conf));
194 bss = os_zalloc(sizeof(*bss));
195 if (conf == NULL || bss == NULL) {
196 wpa_printf(MSG_ERROR, "Failed to allocate memory for "
197 "configuration data.");
198 os_free(conf);
199 os_free(bss);
200 return NULL;
201 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800202 conf->bss = os_calloc(1, sizeof(struct hostapd_bss_config *));
203 if (conf->bss == NULL) {
204 os_free(conf);
205 os_free(bss);
206 return NULL;
207 }
208 conf->bss[0] = bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700209
210 bss->radius = os_zalloc(sizeof(*bss->radius));
211 if (bss->radius == NULL) {
Dmitry Shmidt97672262014-02-03 13:02:54 -0800212 os_free(conf->bss);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700213 os_free(conf);
214 os_free(bss);
215 return NULL;
216 }
217
218 hostapd_config_defaults_bss(bss);
219
220 conf->num_bss = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700221
222 conf->beacon_int = 100;
Hai Shalom021b0b52019-04-10 11:17:58 -0700223 conf->rts_threshold = -2; /* use driver default: 2347 */
224 conf->fragm_threshold = -2; /* user driver default: 2346 */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800225 /* Set to invalid value means do not add Power Constraint IE */
226 conf->local_pwr_constraint = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700227
228 conf->wmm_ac_params[0] = ac_be;
229 conf->wmm_ac_params[1] = ac_bk;
230 conf->wmm_ac_params[2] = ac_vi;
231 conf->wmm_ac_params[3] = ac_vo;
232
233 conf->tx_queue[0] = txq_vo;
234 conf->tx_queue[1] = txq_vi;
235 conf->tx_queue[2] = txq_be;
236 conf->tx_queue[3] = txq_bk;
237
238 conf->ht_capab = HT_CAP_INFO_SMPS_DISABLED;
239
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800240 conf->ap_table_max_size = 255;
241 conf->ap_table_expiration_time = 60;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800242 conf->track_sta_max_age = 180;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800243
Dmitry Shmidt8da800a2013-04-24 12:57:01 -0700244#ifdef CONFIG_TESTING_OPTIONS
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700245 conf->ignore_probe_probability = 0.0;
246 conf->ignore_auth_probability = 0.0;
247 conf->ignore_assoc_probability = 0.0;
248 conf->ignore_reassoc_probability = 0.0;
249 conf->corrupt_gtk_rekey_mic_probability = 0.0;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800250 conf->ecsa_ie_only = 0;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -0700251#endif /* CONFIG_TESTING_OPTIONS */
252
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700253 conf->acs = 0;
254 conf->acs_ch_list.num = 0;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700255#ifdef CONFIG_ACS
256 conf->acs_num_scans = 5;
257#endif /* CONFIG_ACS */
258
Hai Shalom81f62d82019-07-22 12:10:00 -0700259#ifdef CONFIG_IEEE80211AX
260 conf->he_op.he_rts_threshold = HE_OPERATION_RTS_THRESHOLD_MASK >>
261 HE_OPERATION_RTS_THRESHOLD_OFFSET;
262 /* Set default basic MCS/NSS set to single stream MCS 0-7 */
263 conf->he_op.he_basic_mcs_nss_set = 0xfffc;
Hai Shalomfdcde762020-04-02 11:19:20 -0700264 conf->he_op.he_bss_color_disabled = 1;
265 conf->he_op.he_bss_color_partial = 0;
266 conf->he_op.he_bss_color = 1;
Hai Shalom81f62d82019-07-22 12:10:00 -0700267#endif /* CONFIG_IEEE80211AX */
268
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700269 /* The third octet of the country string uses an ASCII space character
270 * by default to indicate that the regulations encompass all
271 * environments for the current frequency band in the country. */
272 conf->country[2] = ' ';
273
Hai Shalom74f70d42019-02-11 14:42:39 -0800274 conf->rssi_reject_assoc_rssi = 0;
275 conf->rssi_reject_assoc_timeout = 30;
276
Hai Shalom81f62d82019-07-22 12:10:00 -0700277#ifdef CONFIG_AIRTIME_POLICY
278 conf->airtime_update_interval = AIRTIME_DEFAULT_UPDATE_INTERVAL;
279#endif /* CONFIG_AIRTIME_POLICY */
280
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700281 return conf;
282}
283
284
285int hostapd_mac_comp(const void *a, const void *b)
286{
287 return os_memcmp(a, b, sizeof(macaddr));
288}
289
290
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700291static int hostapd_config_read_wpa_psk(const char *fname,
292 struct hostapd_ssid *ssid)
293{
294 FILE *f;
295 char buf[128], *pos;
Hai Shalom74f70d42019-02-11 14:42:39 -0800296 const char *keyid;
297 char *context;
298 char *context2;
299 char *token;
300 char *name;
301 char *value;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700302 int line = 0, ret = 0, len, ok;
303 u8 addr[ETH_ALEN];
304 struct hostapd_wpa_psk *psk;
305
306 if (!fname)
307 return 0;
308
309 f = fopen(fname, "r");
310 if (!f) {
311 wpa_printf(MSG_ERROR, "WPA PSK file '%s' not found.", fname);
312 return -1;
313 }
314
315 while (fgets(buf, sizeof(buf), f)) {
Hai Shalom021b0b52019-04-10 11:17:58 -0700316 int vlan_id = 0;
Hai Shalomfdcde762020-04-02 11:19:20 -0700317 int wps = 0;
Hai Shalom021b0b52019-04-10 11:17:58 -0700318
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700319 line++;
320
321 if (buf[0] == '#')
322 continue;
323 pos = buf;
324 while (*pos != '\0') {
325 if (*pos == '\n') {
326 *pos = '\0';
327 break;
328 }
329 pos++;
330 }
331 if (buf[0] == '\0')
332 continue;
333
Hai Shalom74f70d42019-02-11 14:42:39 -0800334 context = NULL;
335 keyid = NULL;
336 while ((token = str_token(buf, " ", &context))) {
337 if (!os_strchr(token, '='))
338 break;
339 context2 = NULL;
340 name = str_token(token, "=", &context2);
Hai Shalom021b0b52019-04-10 11:17:58 -0700341 if (!name)
342 break;
Hai Shalom74f70d42019-02-11 14:42:39 -0800343 value = str_token(token, "", &context2);
344 if (!value)
345 value = "";
346 if (!os_strcmp(name, "keyid")) {
347 keyid = value;
Hai Shalomfdcde762020-04-02 11:19:20 -0700348 } else if (!os_strcmp(name, "wps")) {
349 wps = atoi(value);
Hai Shalom021b0b52019-04-10 11:17:58 -0700350 } else if (!os_strcmp(name, "vlanid")) {
351 vlan_id = atoi(value);
Hai Shalom74f70d42019-02-11 14:42:39 -0800352 } else {
353 wpa_printf(MSG_ERROR,
354 "Unrecognized '%s=%s' on line %d in '%s'",
355 name, value, line, fname);
356 ret = -1;
357 break;
358 }
359 }
360
361 if (ret == -1)
362 break;
363
364 if (!token)
365 token = "";
366 if (hwaddr_aton(token, addr)) {
Hai Shalomfdcde762020-04-02 11:19:20 -0700367 wpa_printf(MSG_ERROR,
368 "Invalid MAC address '%s' on line %d in '%s'",
369 token, line, fname);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700370 ret = -1;
371 break;
372 }
373
374 psk = os_zalloc(sizeof(*psk));
375 if (psk == NULL) {
376 wpa_printf(MSG_ERROR, "WPA PSK allocation failed");
377 ret = -1;
378 break;
379 }
Hai Shalom021b0b52019-04-10 11:17:58 -0700380 psk->vlan_id = vlan_id;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700381 if (is_zero_ether_addr(addr))
382 psk->group = 1;
383 else
384 os_memcpy(psk->addr, addr, ETH_ALEN);
385
Hai Shalom74f70d42019-02-11 14:42:39 -0800386 pos = str_token(buf, "", &context);
387 if (!pos) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700388 wpa_printf(MSG_ERROR, "No PSK on line %d in '%s'",
389 line, fname);
390 os_free(psk);
391 ret = -1;
392 break;
393 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700394
395 ok = 0;
396 len = os_strlen(pos);
Hai Shalomfdcde762020-04-02 11:19:20 -0700397 if (len == 2 * PMK_LEN &&
398 hexstr2bin(pos, psk->psk, PMK_LEN) == 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700399 ok = 1;
Hai Shalomfdcde762020-04-02 11:19:20 -0700400 else if (len >= 8 && len < 64 &&
401 pbkdf2_sha1(pos, ssid->ssid, ssid->ssid_len,
402 4096, psk->psk, PMK_LEN) == 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700403 ok = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700404 if (!ok) {
Hai Shalomfdcde762020-04-02 11:19:20 -0700405 wpa_printf(MSG_ERROR,
406 "Invalid PSK '%s' on line %d in '%s'",
407 pos, line, fname);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700408 os_free(psk);
409 ret = -1;
410 break;
411 }
412
Hai Shalom74f70d42019-02-11 14:42:39 -0800413 if (keyid) {
414 len = os_strlcpy(psk->keyid, keyid, sizeof(psk->keyid));
415 if ((size_t) len >= sizeof(psk->keyid)) {
416 wpa_printf(MSG_ERROR,
417 "PSK keyid too long on line %d in '%s'",
418 line, fname);
419 os_free(psk);
420 ret = -1;
421 break;
422 }
423 }
424
Hai Shalomfdcde762020-04-02 11:19:20 -0700425 psk->wps = wps;
426
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700427 psk->next = ssid->wpa_psk;
428 ssid->wpa_psk = psk;
429 }
430
431 fclose(f);
432
433 return ret;
434}
435
436
437static int hostapd_derive_psk(struct hostapd_ssid *ssid)
438{
439 ssid->wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
440 if (ssid->wpa_psk == NULL) {
441 wpa_printf(MSG_ERROR, "Unable to alloc space for PSK");
442 return -1;
443 }
444 wpa_hexdump_ascii(MSG_DEBUG, "SSID",
445 (u8 *) ssid->ssid, ssid->ssid_len);
446 wpa_hexdump_ascii_key(MSG_DEBUG, "PSK (ASCII passphrase)",
447 (u8 *) ssid->wpa_passphrase,
448 os_strlen(ssid->wpa_passphrase));
449 pbkdf2_sha1(ssid->wpa_passphrase,
450 ssid->ssid, ssid->ssid_len,
451 4096, ssid->wpa_psk->psk, PMK_LEN);
452 wpa_hexdump_key(MSG_DEBUG, "PSK (from passphrase)",
453 ssid->wpa_psk->psk, PMK_LEN);
454 return 0;
455}
456
457
Hai Shalomc3565922019-10-28 11:58:20 -0700458int hostapd_setup_sae_pt(struct hostapd_bss_config *conf)
459{
460#ifdef CONFIG_SAE
461 struct hostapd_ssid *ssid = &conf->ssid;
462 struct sae_password_entry *pw;
463
Hai Shalomfdcde762020-04-02 11:19:20 -0700464 if ((conf->sae_pwe == 0 && !hostapd_sae_pw_id_in_use(conf)) ||
465 conf->sae_pwe == 3 ||
466 !wpa_key_mgmt_sae(conf->wpa_key_mgmt))
Hai Shalomc3565922019-10-28 11:58:20 -0700467 return 0; /* PT not needed */
468
469 sae_deinit_pt(ssid->pt);
470 ssid->pt = NULL;
471 if (ssid->wpa_passphrase) {
472 ssid->pt = sae_derive_pt(conf->sae_groups, ssid->ssid,
473 ssid->ssid_len,
474 (const u8 *) ssid->wpa_passphrase,
475 os_strlen(ssid->wpa_passphrase),
476 NULL);
477 if (!ssid->pt)
478 return -1;
479 }
480
481 for (pw = conf->sae_passwords; pw; pw = pw->next) {
482 sae_deinit_pt(pw->pt);
483 pw->pt = sae_derive_pt(conf->sae_groups, ssid->ssid,
484 ssid->ssid_len,
485 (const u8 *) pw->password,
486 os_strlen(pw->password),
487 pw->identifier);
488 if (!pw->pt)
489 return -1;
490 }
491#endif /* CONFIG_SAE */
492
493 return 0;
494}
495
496
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700497int hostapd_setup_wpa_psk(struct hostapd_bss_config *conf)
498{
499 struct hostapd_ssid *ssid = &conf->ssid;
500
Hai Shalomc3565922019-10-28 11:58:20 -0700501 if (hostapd_setup_sae_pt(conf) < 0)
502 return -1;
503
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700504 if (ssid->wpa_passphrase != NULL) {
505 if (ssid->wpa_psk != NULL) {
506 wpa_printf(MSG_DEBUG, "Using pre-configured WPA PSK "
507 "instead of passphrase");
508 } else {
509 wpa_printf(MSG_DEBUG, "Deriving WPA PSK based on "
510 "passphrase");
511 if (hostapd_derive_psk(ssid) < 0)
512 return -1;
513 }
514 ssid->wpa_psk->group = 1;
515 }
516
Dmitry Shmidt29333592017-01-09 12:27:11 -0800517 return hostapd_config_read_wpa_psk(ssid->wpa_psk_file, &conf->ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700518}
519
520
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700521static void hostapd_config_free_radius(struct hostapd_radius_server *servers,
522 int num_servers)
523{
524 int i;
525
526 for (i = 0; i < num_servers; i++) {
527 os_free(servers[i].shared_secret);
528 }
529 os_free(servers);
530}
531
532
Dmitry Shmidt04949592012-07-19 12:16:46 -0700533struct hostapd_radius_attr *
534hostapd_config_get_radius_attr(struct hostapd_radius_attr *attr, u8 type)
535{
536 for (; attr; attr = attr->next) {
537 if (attr->type == type)
538 return attr;
539 }
540 return NULL;
541}
542
543
Hai Shalomc3565922019-10-28 11:58:20 -0700544struct hostapd_radius_attr * hostapd_parse_radius_attr(const char *value)
545{
546 const char *pos;
547 char syntax;
548 struct hostapd_radius_attr *attr;
549 size_t len;
550
551 attr = os_zalloc(sizeof(*attr));
552 if (!attr)
553 return NULL;
554
555 attr->type = atoi(value);
556
557 pos = os_strchr(value, ':');
558 if (!pos) {
559 attr->val = wpabuf_alloc(1);
560 if (!attr->val) {
561 os_free(attr);
562 return NULL;
563 }
564 wpabuf_put_u8(attr->val, 0);
565 return attr;
566 }
567
568 pos++;
569 if (pos[0] == '\0' || pos[1] != ':') {
570 os_free(attr);
571 return NULL;
572 }
573 syntax = *pos++;
574 pos++;
575
576 switch (syntax) {
577 case 's':
578 attr->val = wpabuf_alloc_copy(pos, os_strlen(pos));
579 break;
580 case 'x':
581 len = os_strlen(pos);
582 if (len & 1)
583 break;
584 len /= 2;
585 attr->val = wpabuf_alloc(len);
586 if (!attr->val)
587 break;
588 if (hexstr2bin(pos, wpabuf_put(attr->val, len), len) < 0) {
589 wpabuf_free(attr->val);
590 os_free(attr);
591 return NULL;
592 }
593 break;
594 case 'd':
595 attr->val = wpabuf_alloc(4);
596 if (attr->val)
597 wpabuf_put_be32(attr->val, atoi(pos));
598 break;
599 default:
600 os_free(attr);
601 return NULL;
602 }
603
604 if (!attr->val) {
605 os_free(attr);
606 return NULL;
607 }
608
609 return attr;
610}
611
612
613void hostapd_config_free_radius_attr(struct hostapd_radius_attr *attr)
Dmitry Shmidt04949592012-07-19 12:16:46 -0700614{
615 struct hostapd_radius_attr *prev;
616
617 while (attr) {
618 prev = attr;
619 attr = attr->next;
620 wpabuf_free(prev->val);
621 os_free(prev);
622 }
623}
624
625
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700626void hostapd_config_free_eap_user(struct hostapd_eap_user *user)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700627{
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700628 hostapd_config_free_radius_attr(user->accept_attr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700629 os_free(user->identity);
Dmitry Shmidtc2817022014-07-02 10:32:10 -0700630 bin_clear_free(user->password, user->password_len);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700631 bin_clear_free(user->salt, user->salt_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700632 os_free(user);
633}
634
635
Dmitry Shmidt29333592017-01-09 12:27:11 -0800636void hostapd_config_free_eap_users(struct hostapd_eap_user *user)
637{
638 struct hostapd_eap_user *prev_user;
639
640 while (user) {
641 prev_user = user;
642 user = user->next;
643 hostapd_config_free_eap_user(prev_user);
644 }
645}
646
647
Hai Shalomfdcde762020-04-02 11:19:20 -0700648#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700649static void hostapd_config_free_wep(struct hostapd_wep_keys *keys)
650{
651 int i;
652 for (i = 0; i < NUM_WEP_KEYS; i++) {
Dmitry Shmidtc2817022014-07-02 10:32:10 -0700653 bin_clear_free(keys->key[i], keys->len[i]);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700654 keys->key[i] = NULL;
655 }
656}
Hai Shalomfdcde762020-04-02 11:19:20 -0700657#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700658
659
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800660void hostapd_config_clear_wpa_psk(struct hostapd_wpa_psk **l)
661{
662 struct hostapd_wpa_psk *psk, *tmp;
663
664 for (psk = *l; psk;) {
665 tmp = psk;
666 psk = psk->next;
667 bin_clear_free(tmp, sizeof(*tmp));
668 }
669 *l = NULL;
670}
671
672
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800673static void hostapd_config_free_anqp_elem(struct hostapd_bss_config *conf)
674{
675 struct anqp_element *elem;
676
677 while ((elem = dl_list_first(&conf->anqp_elem, struct anqp_element,
678 list))) {
679 dl_list_del(&elem->list);
680 wpabuf_free(elem->payload);
681 os_free(elem);
682 }
683}
684
685
Dmitry Shmidt29333592017-01-09 12:27:11 -0800686static void hostapd_config_free_fils_realms(struct hostapd_bss_config *conf)
687{
688#ifdef CONFIG_FILS
689 struct fils_realm *realm;
690
691 while ((realm = dl_list_first(&conf->fils_realms, struct fils_realm,
692 list))) {
693 dl_list_del(&realm->list);
694 os_free(realm);
695 }
696#endif /* CONFIG_FILS */
697}
698
699
Roshan Pius3a1667e2018-07-03 15:17:14 -0700700static void hostapd_config_free_sae_passwords(struct hostapd_bss_config *conf)
701{
702 struct sae_password_entry *pw, *tmp;
703
704 pw = conf->sae_passwords;
705 conf->sae_passwords = NULL;
706 while (pw) {
707 tmp = pw;
708 pw = pw->next;
709 str_clear_free(tmp->password);
710 os_free(tmp->identifier);
Hai Shalomc3565922019-10-28 11:58:20 -0700711#ifdef CONFIG_SAE
712 sae_deinit_pt(tmp->pt);
713#endif /* CONFIG_SAE */
Roshan Pius3a1667e2018-07-03 15:17:14 -0700714 os_free(tmp);
715 }
716}
717
718
Hai Shalom81f62d82019-07-22 12:10:00 -0700719#ifdef CONFIG_DPP2
720static void hostapd_dpp_controller_conf_free(struct dpp_controller_conf *conf)
721{
722 struct dpp_controller_conf *prev;
723
724 while (conf) {
725 prev = conf;
726 conf = conf->next;
727 os_free(prev);
728 }
729}
730#endif /* CONFIG_DPP2 */
731
732
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800733void hostapd_config_free_bss(struct hostapd_bss_config *conf)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700734{
Hai Shalom81f62d82019-07-22 12:10:00 -0700735#if defined(CONFIG_WPS) || defined(CONFIG_HS20)
736 size_t i;
737#endif
738
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700739 if (conf == NULL)
740 return;
741
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800742 hostapd_config_clear_wpa_psk(&conf->ssid.wpa_psk);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700743
Dmitry Shmidtc2817022014-07-02 10:32:10 -0700744 str_clear_free(conf->ssid.wpa_passphrase);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700745 os_free(conf->ssid.wpa_psk_file);
Hai Shalomfdcde762020-04-02 11:19:20 -0700746#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700747 hostapd_config_free_wep(&conf->ssid.wep);
Hai Shalomfdcde762020-04-02 11:19:20 -0700748#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700749#ifdef CONFIG_FULL_DYNAMIC_VLAN
750 os_free(conf->ssid.vlan_tagged_interface);
751#endif /* CONFIG_FULL_DYNAMIC_VLAN */
Hai Shalomc3565922019-10-28 11:58:20 -0700752#ifdef CONFIG_SAE
753 sae_deinit_pt(conf->ssid.pt);
754#endif /* CONFIG_SAE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700755
Dmitry Shmidt29333592017-01-09 12:27:11 -0800756 hostapd_config_free_eap_users(conf->eap_user);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800757 os_free(conf->eap_user_sqlite);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700758
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700759 os_free(conf->eap_req_id_text);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800760 os_free(conf->erp_domain);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700761 os_free(conf->accept_mac);
762 os_free(conf->deny_mac);
763 os_free(conf->nas_identifier);
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800764 if (conf->radius) {
765 hostapd_config_free_radius(conf->radius->auth_servers,
766 conf->radius->num_auth_servers);
767 hostapd_config_free_radius(conf->radius->acct_servers,
768 conf->radius->num_acct_servers);
769 }
Dmitry Shmidt04949592012-07-19 12:16:46 -0700770 hostapd_config_free_radius_attr(conf->radius_auth_req_attr);
771 hostapd_config_free_radius_attr(conf->radius_acct_req_attr);
Hai Shalomc3565922019-10-28 11:58:20 -0700772 os_free(conf->radius_req_attr_sqlite);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700773 os_free(conf->rsn_preauth_interfaces);
774 os_free(conf->ctrl_interface);
775 os_free(conf->ca_cert);
776 os_free(conf->server_cert);
Hai Shalom81f62d82019-07-22 12:10:00 -0700777 os_free(conf->server_cert2);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700778 os_free(conf->private_key);
Hai Shalom81f62d82019-07-22 12:10:00 -0700779 os_free(conf->private_key2);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700780 os_free(conf->private_key_passwd);
Hai Shalom81f62d82019-07-22 12:10:00 -0700781 os_free(conf->private_key_passwd2);
Hai Shalom021b0b52019-04-10 11:17:58 -0700782 os_free(conf->check_cert_subject);
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700783 os_free(conf->ocsp_stapling_response);
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -0800784 os_free(conf->ocsp_stapling_response_multi);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700785 os_free(conf->dh_file);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800786 os_free(conf->openssl_ciphers);
Hai Shalom74f70d42019-02-11 14:42:39 -0800787 os_free(conf->openssl_ecdh_curves);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700788 os_free(conf->pac_opaque_encr_key);
789 os_free(conf->eap_fast_a_id);
790 os_free(conf->eap_fast_a_id_info);
791 os_free(conf->eap_sim_db);
792 os_free(conf->radius_server_clients);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700793 os_free(conf->radius);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700794 os_free(conf->radius_das_shared_secret);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700795 hostapd_config_free_vlan(conf);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800796 os_free(conf->time_zone);
797
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800798#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700799 {
800 struct ft_remote_r0kh *r0kh, *r0kh_prev;
801 struct ft_remote_r1kh *r1kh, *r1kh_prev;
802
803 r0kh = conf->r0kh_list;
804 conf->r0kh_list = NULL;
805 while (r0kh) {
806 r0kh_prev = r0kh;
807 r0kh = r0kh->next;
808 os_free(r0kh_prev);
809 }
810
811 r1kh = conf->r1kh_list;
812 conf->r1kh_list = NULL;
813 while (r1kh) {
814 r1kh_prev = r1kh;
815 r1kh = r1kh->next;
816 os_free(r1kh_prev);
817 }
818 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800819#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700820
821#ifdef CONFIG_WPS
822 os_free(conf->wps_pin_requests);
823 os_free(conf->device_name);
824 os_free(conf->manufacturer);
825 os_free(conf->model_name);
826 os_free(conf->model_number);
827 os_free(conf->serial_number);
828 os_free(conf->config_methods);
829 os_free(conf->ap_pin);
830 os_free(conf->extra_cred);
831 os_free(conf->ap_settings);
Hai Shalom021b0b52019-04-10 11:17:58 -0700832 hostapd_config_clear_wpa_psk(&conf->multi_ap_backhaul_ssid.wpa_psk);
833 str_clear_free(conf->multi_ap_backhaul_ssid.wpa_passphrase);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700834 os_free(conf->upnp_iface);
835 os_free(conf->friendly_name);
836 os_free(conf->manufacturer_url);
837 os_free(conf->model_description);
838 os_free(conf->model_url);
839 os_free(conf->upc);
Hai Shalom81f62d82019-07-22 12:10:00 -0700840 for (i = 0; i < MAX_WPS_VENDOR_EXTENSIONS; i++)
841 wpabuf_free(conf->wps_vendor_ext[i]);
Hai Shalomfdcde762020-04-02 11:19:20 -0700842 wpabuf_free(conf->wps_application_ext);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700843 wpabuf_free(conf->wps_nfc_dh_pubkey);
844 wpabuf_free(conf->wps_nfc_dh_privkey);
845 wpabuf_free(conf->wps_nfc_dev_pw);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700846#endif /* CONFIG_WPS */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800847
848 os_free(conf->roaming_consortium);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700849 os_free(conf->venue_name);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700850 os_free(conf->venue_url);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700851 os_free(conf->nai_realm_data);
852 os_free(conf->network_auth_type);
853 os_free(conf->anqp_3gpp_cell_net);
854 os_free(conf->domain_name);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800855 hostapd_config_free_anqp_elem(conf);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800856
857#ifdef CONFIG_RADIUS_TEST
858 os_free(conf->dump_msk_file);
859#endif /* CONFIG_RADIUS_TEST */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700860
861#ifdef CONFIG_HS20
862 os_free(conf->hs20_oper_friendly_name);
863 os_free(conf->hs20_wan_metrics);
864 os_free(conf->hs20_connection_capability);
865 os_free(conf->hs20_operating_class);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800866 os_free(conf->hs20_icons);
867 if (conf->hs20_osu_providers) {
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800868 for (i = 0; i < conf->hs20_osu_providers_count; i++) {
869 struct hs20_osu_provider *p;
870 size_t j;
871 p = &conf->hs20_osu_providers[i];
872 os_free(p->friendly_name);
873 os_free(p->server_uri);
874 os_free(p->method_list);
875 for (j = 0; j < p->icons_count; j++)
876 os_free(p->icons[j]);
877 os_free(p->icons);
878 os_free(p->osu_nai);
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800879 os_free(p->osu_nai2);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800880 os_free(p->service_desc);
881 }
882 os_free(conf->hs20_osu_providers);
883 }
Roshan Pius3a1667e2018-07-03 15:17:14 -0700884 if (conf->hs20_operator_icon) {
Roshan Pius3a1667e2018-07-03 15:17:14 -0700885 for (i = 0; i < conf->hs20_operator_icon_count; i++)
886 os_free(conf->hs20_operator_icon[i]);
887 os_free(conf->hs20_operator_icon);
888 }
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800889 os_free(conf->subscr_remediation_url);
Hai Shalom74f70d42019-02-11 14:42:39 -0800890 os_free(conf->hs20_sim_provisioning_url);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700891 os_free(conf->t_c_filename);
892 os_free(conf->t_c_server_url);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700893#endif /* CONFIG_HS20 */
894
895 wpabuf_free(conf->vendor_elements);
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700896 wpabuf_free(conf->assocresp_elements);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800897
898 os_free(conf->sae_groups);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700899#ifdef CONFIG_OWE
900 os_free(conf->owe_groups);
901#endif /* CONFIG_OWE */
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700902
Dmitry Shmidt0207e232014-09-03 14:58:37 -0700903 os_free(conf->wowlan_triggers);
904
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700905 os_free(conf->server_id);
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800906
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800907#ifdef CONFIG_TESTING_OPTIONS
908 wpabuf_free(conf->own_ie_override);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700909 wpabuf_free(conf->sae_commit_override);
Hai Shalomfdcde762020-04-02 11:19:20 -0700910 wpabuf_free(conf->rsne_override_eapol);
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800911 wpabuf_free(conf->rsnxe_override_eapol);
Hai Shalomfdcde762020-04-02 11:19:20 -0700912 wpabuf_free(conf->rsne_override_ft);
913 wpabuf_free(conf->rsnxe_override_ft);
914 wpabuf_free(conf->gtk_rsc_override);
915 wpabuf_free(conf->igtk_rsc_override);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800916#endif /* CONFIG_TESTING_OPTIONS */
917
918 os_free(conf->no_probe_resp_if_seen_on);
919 os_free(conf->no_auth_if_seen_on);
920
Dmitry Shmidt29333592017-01-09 12:27:11 -0800921 hostapd_config_free_fils_realms(conf);
922
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700923#ifdef CONFIG_DPP
Hai Shalomc3565922019-10-28 11:58:20 -0700924 os_free(conf->dpp_name);
925 os_free(conf->dpp_mud_url);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700926 os_free(conf->dpp_connector);
927 wpabuf_free(conf->dpp_netaccesskey);
928 wpabuf_free(conf->dpp_csign);
Hai Shalom81f62d82019-07-22 12:10:00 -0700929#ifdef CONFIG_DPP2
930 hostapd_dpp_controller_conf_free(conf->dpp_controller);
931#endif /* CONFIG_DPP2 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700932#endif /* CONFIG_DPP */
933
Roshan Pius3a1667e2018-07-03 15:17:14 -0700934 hostapd_config_free_sae_passwords(conf);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700935
Hai Shalom81f62d82019-07-22 12:10:00 -0700936#ifdef CONFIG_AIRTIME_POLICY
937 {
938 struct airtime_sta_weight *wt, *wt_prev;
939
940 wt = conf->airtime_weight_list;
941 conf->airtime_weight_list = NULL;
942 while (wt) {
943 wt_prev = wt;
944 wt = wt->next;
945 os_free(wt_prev);
946 }
947 }
948#endif /* CONFIG_AIRTIME_POLICY */
949
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800950 os_free(conf);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700951}
952
953
954/**
955 * hostapd_config_free - Free hostapd configuration
956 * @conf: Configuration data from hostapd_config_read().
957 */
958void hostapd_config_free(struct hostapd_config *conf)
959{
960 size_t i;
961
962 if (conf == NULL)
963 return;
964
965 for (i = 0; i < conf->num_bss; i++)
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800966 hostapd_config_free_bss(conf->bss[i]);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700967 os_free(conf->bss);
968 os_free(conf->supported_rates);
969 os_free(conf->basic_rates);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700970 os_free(conf->acs_ch_list.range);
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800971 os_free(conf->acs_freq_list.range);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800972 os_free(conf->driver_params);
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800973#ifdef CONFIG_ACS
974 os_free(conf->acs_chan_bias);
975#endif /* CONFIG_ACS */
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700976 wpabuf_free(conf->lci);
977 wpabuf_free(conf->civic);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700978
979 os_free(conf);
980}
981
982
983/**
984 * hostapd_maclist_found - Find a MAC address from a list
985 * @list: MAC address list
986 * @num_entries: Number of addresses in the list
987 * @addr: Address to search for
988 * @vlan_id: Buffer for returning VLAN ID or %NULL if not needed
989 * Returns: 1 if address is in the list or 0 if not.
990 *
991 * Perform a binary search for given MAC address from a pre-sorted list.
992 */
993int hostapd_maclist_found(struct mac_acl_entry *list, int num_entries,
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800994 const u8 *addr, struct vlan_description *vlan_id)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700995{
996 int start, end, middle, res;
997
998 start = 0;
999 end = num_entries - 1;
1000
1001 while (start <= end) {
1002 middle = (start + end) / 2;
1003 res = os_memcmp(list[middle].addr, addr, ETH_ALEN);
1004 if (res == 0) {
1005 if (vlan_id)
1006 *vlan_id = list[middle].vlan_id;
1007 return 1;
1008 }
1009 if (res < 0)
1010 start = middle + 1;
1011 else
1012 end = middle - 1;
1013 }
1014
1015 return 0;
1016}
1017
1018
1019int hostapd_rate_found(int *list, int rate)
1020{
1021 int i;
1022
1023 if (list == NULL)
1024 return 0;
1025
1026 for (i = 0; list[i] >= 0; i++)
1027 if (list[i] == rate)
1028 return 1;
1029
1030 return 0;
1031}
1032
1033
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001034int hostapd_vlan_valid(struct hostapd_vlan *vlan,
1035 struct vlan_description *vlan_desc)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001036{
1037 struct hostapd_vlan *v = vlan;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001038 int i;
1039
1040 if (!vlan_desc->notempty || vlan_desc->untagged < 0 ||
1041 vlan_desc->untagged > MAX_VLAN_ID)
1042 return 0;
1043 for (i = 0; i < MAX_NUM_TAGGED_VLAN; i++) {
1044 if (vlan_desc->tagged[i] < 0 ||
1045 vlan_desc->tagged[i] > MAX_VLAN_ID)
1046 return 0;
1047 }
1048 if (!vlan_desc->untagged && !vlan_desc->tagged[0])
1049 return 0;
1050
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001051 while (v) {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001052 if (!vlan_compare(&v->vlan_desc, vlan_desc) ||
1053 v->vlan_id == VLAN_ID_WILDCARD)
Dmitry Shmidt34af3062013-07-11 10:46:32 -07001054 return 1;
1055 v = v->next;
1056 }
1057 return 0;
1058}
1059
1060
1061const char * hostapd_get_vlan_id_ifname(struct hostapd_vlan *vlan, int vlan_id)
1062{
1063 struct hostapd_vlan *v = vlan;
1064 while (v) {
1065 if (v->vlan_id == vlan_id)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001066 return v->ifname;
1067 v = v->next;
1068 }
1069 return NULL;
1070}
1071
1072
1073const u8 * hostapd_get_psk(const struct hostapd_bss_config *conf,
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001074 const u8 *addr, const u8 *p2p_dev_addr,
Hai Shalom021b0b52019-04-10 11:17:58 -07001075 const u8 *prev_psk, int *vlan_id)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001076{
1077 struct hostapd_wpa_psk *psk;
1078 int next_ok = prev_psk == NULL;
1079
Hai Shalom021b0b52019-04-10 11:17:58 -07001080 if (vlan_id)
1081 *vlan_id = 0;
1082
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001083 if (p2p_dev_addr && !is_zero_ether_addr(p2p_dev_addr)) {
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001084 wpa_printf(MSG_DEBUG, "Searching a PSK for " MACSTR
1085 " p2p_dev_addr=" MACSTR " prev_psk=%p",
1086 MAC2STR(addr), MAC2STR(p2p_dev_addr), prev_psk);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001087 addr = NULL; /* Use P2P Device Address for matching */
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001088 } else {
1089 wpa_printf(MSG_DEBUG, "Searching a PSK for " MACSTR
1090 " prev_psk=%p",
1091 MAC2STR(addr), prev_psk);
1092 }
1093
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001094 for (psk = conf->ssid.wpa_psk; psk != NULL; psk = psk->next) {
1095 if (next_ok &&
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001096 (psk->group ||
1097 (addr && os_memcmp(psk->addr, addr, ETH_ALEN) == 0) ||
1098 (!addr && p2p_dev_addr &&
1099 os_memcmp(psk->p2p_dev_addr, p2p_dev_addr, ETH_ALEN) ==
Hai Shalom021b0b52019-04-10 11:17:58 -07001100 0))) {
1101 if (vlan_id)
1102 *vlan_id = psk->vlan_id;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001103 return psk->psk;
Hai Shalom021b0b52019-04-10 11:17:58 -07001104 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001105
1106 if (psk->psk == prev_psk)
1107 next_ok = 1;
1108 }
1109
1110 return NULL;
1111}
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001112
1113
1114static int hostapd_config_check_bss(struct hostapd_bss_config *bss,
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001115 struct hostapd_config *conf,
1116 int full_config)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001117{
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001118 if (full_config && bss->ieee802_1x && !bss->eap_server &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001119 !bss->radius->auth_servers) {
1120 wpa_printf(MSG_ERROR, "Invalid IEEE 802.1X configuration (no "
1121 "EAP authenticator configured).");
1122 return -1;
1123 }
1124
Hai Shalomfdcde762020-04-02 11:19:20 -07001125#ifdef CONFIG_WEP
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001126 if (bss->wpa) {
1127 int wep, i;
1128
1129 wep = bss->default_wep_key_len > 0 ||
1130 bss->individual_wep_key_len > 0;
1131 for (i = 0; i < NUM_WEP_KEYS; i++) {
1132 if (bss->ssid.wep.keys_set) {
1133 wep = 1;
1134 break;
1135 }
1136 }
1137
1138 if (wep) {
1139 wpa_printf(MSG_ERROR, "WEP configuration in a WPA network is not supported");
1140 return -1;
1141 }
1142 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001143#endif /* CONFIG_WEP */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001144
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001145 if (full_config && bss->wpa &&
1146 bss->wpa_psk_radius != PSK_RADIUS_IGNORED &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001147 bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH) {
1148 wpa_printf(MSG_ERROR, "WPA-PSK using RADIUS enabled, but no "
1149 "RADIUS checking (macaddr_acl=2) enabled.");
1150 return -1;
1151 }
1152
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001153 if (full_config && bss->wpa && (bss->wpa_key_mgmt & WPA_KEY_MGMT_PSK) &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001154 bss->ssid.wpa_psk == NULL && bss->ssid.wpa_passphrase == NULL &&
1155 bss->ssid.wpa_psk_file == NULL &&
1156 (bss->wpa_psk_radius != PSK_RADIUS_REQUIRED ||
1157 bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH)) {
1158 wpa_printf(MSG_ERROR, "WPA-PSK enabled, but PSK or passphrase "
1159 "is not configured.");
1160 return -1;
1161 }
1162
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001163 if (full_config && !is_zero_ether_addr(bss->bssid)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001164 size_t i;
1165
1166 for (i = 0; i < conf->num_bss; i++) {
1167 if (conf->bss[i] != bss &&
1168 (hostapd_mac_comp(conf->bss[i]->bssid,
1169 bss->bssid) == 0)) {
1170 wpa_printf(MSG_ERROR, "Duplicate BSSID " MACSTR
1171 " on interface '%s' and '%s'.",
1172 MAC2STR(bss->bssid),
1173 conf->bss[i]->iface, bss->iface);
1174 return -1;
1175 }
1176 }
1177 }
1178
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001179#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001180 if (full_config && wpa_key_mgmt_ft(bss->wpa_key_mgmt) &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001181 (bss->nas_identifier == NULL ||
1182 os_strlen(bss->nas_identifier) < 1 ||
1183 os_strlen(bss->nas_identifier) > FT_R0KH_ID_MAX_LEN)) {
1184 wpa_printf(MSG_ERROR, "FT (IEEE 802.11r) requires "
1185 "nas_identifier to be configured as a 1..48 octet "
1186 "string");
1187 return -1;
1188 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001189#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001190
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001191 if (full_config && conf->ieee80211n &&
1192 conf->hw_mode == HOSTAPD_MODE_IEEE80211B) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001193 bss->disable_11n = 1;
1194 wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) in 11b mode is not "
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001195 "allowed, disabling HT capabilities");
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001196 }
1197
Hai Shalomfdcde762020-04-02 11:19:20 -07001198#ifdef CONFIG_WEP
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001199 if (full_config && conf->ieee80211n &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001200 bss->ssid.security_policy == SECURITY_STATIC_WEP) {
1201 bss->disable_11n = 1;
1202 wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) with WEP is not "
1203 "allowed, disabling HT capabilities");
1204 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001205#endif /* CONFIG_WEP */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001206
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001207 if (full_config && conf->ieee80211n && bss->wpa &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001208 !(bss->wpa_pairwise & WPA_CIPHER_CCMP) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001209 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
1210 WPA_CIPHER_CCMP_256 | WPA_CIPHER_GCMP_256)))
1211 {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001212 bss->disable_11n = 1;
1213 wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) with WPA/WPA2 "
1214 "requires CCMP/GCMP to be enabled, disabling HT "
1215 "capabilities");
1216 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001217
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07001218#ifdef CONFIG_IEEE80211AC
Hai Shalomfdcde762020-04-02 11:19:20 -07001219#ifdef CONFIG_WEP
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07001220 if (full_config && conf->ieee80211ac &&
1221 bss->ssid.security_policy == SECURITY_STATIC_WEP) {
1222 bss->disable_11ac = 1;
1223 wpa_printf(MSG_ERROR,
1224 "VHT (IEEE 802.11ac) with WEP is not allowed, disabling VHT capabilities");
1225 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001226#endif /* CONFIG_WEP */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001227
1228 if (full_config && conf->ieee80211ac && bss->wpa &&
1229 !(bss->wpa_pairwise & WPA_CIPHER_CCMP) &&
1230 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
1231 WPA_CIPHER_CCMP_256 | WPA_CIPHER_GCMP_256)))
1232 {
1233 bss->disable_11ac = 1;
1234 wpa_printf(MSG_ERROR,
1235 "VHT (IEEE 802.11ac) with WPA/WPA2 requires CCMP/GCMP to be enabled, disabling VHT capabilities");
1236 }
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07001237#endif /* CONFIG_IEEE80211AC */
1238
Dmitry Shmidt15907092014-03-25 10:42:57 -07001239#ifdef CONFIG_WPS
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001240 if (full_config && bss->wps_state && bss->ignore_broadcast_ssid) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001241 wpa_printf(MSG_INFO, "WPS: ignore_broadcast_ssid "
1242 "configuration forced WPS to be disabled");
1243 bss->wps_state = 0;
1244 }
1245
Hai Shalomfdcde762020-04-02 11:19:20 -07001246#ifdef CONFIG_WEP
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001247 if (full_config && bss->wps_state &&
1248 bss->ssid.wep.keys_set && bss->wpa == 0) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001249 wpa_printf(MSG_INFO, "WPS: WEP configuration forced WPS to be "
1250 "disabled");
1251 bss->wps_state = 0;
1252 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001253#endif /* CONFIG_WEP */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001254
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001255 if (full_config && bss->wps_state && bss->wpa &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001256 (!(bss->wpa & 2) ||
Roshan Pius3a1667e2018-07-03 15:17:14 -07001257 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
1258 WPA_CIPHER_CCMP_256 |
1259 WPA_CIPHER_GCMP_256)))) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001260 wpa_printf(MSG_INFO, "WPS: WPA/TKIP configuration without "
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07001261 "WPA2/CCMP/GCMP forced WPS to be disabled");
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001262 bss->wps_state = 0;
1263 }
Dmitry Shmidt15907092014-03-25 10:42:57 -07001264#endif /* CONFIG_WPS */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001265
1266#ifdef CONFIG_HS20
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001267 if (full_config && bss->hs20 &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001268 (!(bss->wpa & 2) ||
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001269 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
1270 WPA_CIPHER_CCMP_256 |
1271 WPA_CIPHER_GCMP_256)))) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001272 wpa_printf(MSG_ERROR, "HS 2.0: WPA2-Enterprise/CCMP "
1273 "configuration is required for Hotspot 2.0 "
1274 "functionality");
1275 return -1;
1276 }
1277#endif /* CONFIG_HS20 */
1278
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001279#ifdef CONFIG_MBO
1280 if (full_config && bss->mbo_enabled && (bss->wpa & 2) &&
1281 bss->ieee80211w == NO_MGMT_FRAME_PROTECTION) {
1282 wpa_printf(MSG_ERROR,
1283 "MBO: PMF needs to be enabled whenever using WPA2 with MBO");
1284 return -1;
1285 }
1286#endif /* CONFIG_MBO */
1287
Hai Shalom74f70d42019-02-11 14:42:39 -08001288#ifdef CONFIG_OCV
1289 if (full_config && bss->ieee80211w == NO_MGMT_FRAME_PROTECTION &&
1290 bss->ocv) {
1291 wpa_printf(MSG_ERROR,
1292 "OCV: PMF needs to be enabled whenever using OCV");
1293 return -1;
1294 }
1295#endif /* CONFIG_OCV */
1296
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001297 return 0;
1298}
1299
1300
Dmitry Shmidt05df46a2015-05-19 11:02:01 -07001301static int hostapd_config_check_cw(struct hostapd_config *conf, int queue)
1302{
1303 int tx_cwmin = conf->tx_queue[queue].cwmin;
1304 int tx_cwmax = conf->tx_queue[queue].cwmax;
1305 int ac_cwmin = conf->wmm_ac_params[queue].cwmin;
1306 int ac_cwmax = conf->wmm_ac_params[queue].cwmax;
1307
1308 if (tx_cwmin > tx_cwmax) {
1309 wpa_printf(MSG_ERROR,
1310 "Invalid TX queue cwMin/cwMax values. cwMin(%d) greater than cwMax(%d)",
1311 tx_cwmin, tx_cwmax);
1312 return -1;
1313 }
1314 if (ac_cwmin > ac_cwmax) {
1315 wpa_printf(MSG_ERROR,
1316 "Invalid WMM AC cwMin/cwMax values. cwMin(%d) greater than cwMax(%d)",
1317 ac_cwmin, ac_cwmax);
1318 return -1;
1319 }
1320 return 0;
1321}
1322
1323
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001324int hostapd_config_check(struct hostapd_config *conf, int full_config)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001325{
1326 size_t i;
1327
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001328 if (full_config && conf->ieee80211d &&
1329 (!conf->country[0] || !conf->country[1])) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001330 wpa_printf(MSG_ERROR, "Cannot enable IEEE 802.11d without "
1331 "setting the country_code");
1332 return -1;
1333 }
1334
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001335 if (full_config && conf->ieee80211h && !conf->ieee80211d) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001336 wpa_printf(MSG_ERROR, "Cannot enable IEEE 802.11h without "
1337 "IEEE 802.11d enabled");
1338 return -1;
1339 }
1340
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001341 if (full_config && conf->local_pwr_constraint != -1 &&
1342 !conf->ieee80211d) {
1343 wpa_printf(MSG_ERROR, "Cannot add Power Constraint element without Country element");
1344 return -1;
1345 }
1346
1347 if (full_config && conf->spectrum_mgmt_required &&
1348 conf->local_pwr_constraint == -1) {
1349 wpa_printf(MSG_ERROR, "Cannot set Spectrum Management bit without Country and Power Constraint elements");
1350 return -1;
1351 }
1352
Hai Shalom81f62d82019-07-22 12:10:00 -07001353#ifdef CONFIG_AIRTIME_POLICY
1354 if (full_config && conf->airtime_mode > AIRTIME_MODE_STATIC &&
1355 !conf->airtime_update_interval) {
1356 wpa_printf(MSG_ERROR, "Airtime update interval cannot be zero");
1357 return -1;
1358 }
1359#endif /* CONFIG_AIRTIME_POLICY */
Dmitry Shmidt05df46a2015-05-19 11:02:01 -07001360 for (i = 0; i < NUM_TX_QUEUES; i++) {
1361 if (hostapd_config_check_cw(conf, i))
1362 return -1;
1363 }
1364
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001365 for (i = 0; i < conf->num_bss; i++) {
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001366 if (hostapd_config_check_bss(conf->bss[i], conf, full_config))
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001367 return -1;
1368 }
1369
1370 return 0;
1371}
1372
1373
Dmitry Shmidt71757432014-06-02 13:50:35 -07001374void hostapd_set_security_params(struct hostapd_bss_config *bss,
1375 int full_config)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001376{
Hai Shalomfdcde762020-04-02 11:19:20 -07001377#ifdef CONFIG_WEP
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001378 if (bss->individual_wep_key_len == 0) {
1379 /* individual keys are not use; can use key idx0 for
1380 * broadcast keys */
1381 bss->broadcast_key_idx_min = 0;
1382 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001383#endif /* CONFIG_WEP */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001384
1385 if ((bss->wpa & 2) && bss->rsn_pairwise == 0)
1386 bss->rsn_pairwise = bss->wpa_pairwise;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001387 if (bss->group_cipher)
1388 bss->wpa_group = bss->group_cipher;
1389 else
1390 bss->wpa_group = wpa_select_ap_group_cipher(bss->wpa,
1391 bss->wpa_pairwise,
1392 bss->rsn_pairwise);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001393 if (!bss->wpa_group_rekey_set)
1394 bss->wpa_group_rekey = bss->wpa_group == WPA_CIPHER_TKIP ?
1395 600 : 86400;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001396
Dmitry Shmidt71757432014-06-02 13:50:35 -07001397 if (full_config) {
1398 bss->radius->auth_server = bss->radius->auth_servers;
1399 bss->radius->acct_server = bss->radius->acct_servers;
1400 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001401
1402 if (bss->wpa && bss->ieee802_1x) {
1403 bss->ssid.security_policy = SECURITY_WPA;
1404 } else if (bss->wpa) {
1405 bss->ssid.security_policy = SECURITY_WPA_PSK;
1406 } else if (bss->ieee802_1x) {
1407 int cipher = WPA_CIPHER_NONE;
1408 bss->ssid.security_policy = SECURITY_IEEE_802_1X;
Hai Shalomfdcde762020-04-02 11:19:20 -07001409#ifdef CONFIG_WEP
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001410 bss->ssid.wep.default_len = bss->default_wep_key_len;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001411 if (full_config && bss->default_wep_key_len) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001412 cipher = bss->default_wep_key_len >= 13 ?
1413 WPA_CIPHER_WEP104 : WPA_CIPHER_WEP40;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001414 } else if (full_config && bss->ssid.wep.keys_set) {
1415 if (bss->ssid.wep.len[0] >= 13)
1416 cipher = WPA_CIPHER_WEP104;
1417 else
1418 cipher = WPA_CIPHER_WEP40;
1419 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001420#endif /* CONFIG_WEP */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001421 bss->wpa_group = cipher;
1422 bss->wpa_pairwise = cipher;
1423 bss->rsn_pairwise = cipher;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001424 if (full_config)
1425 bss->wpa_key_mgmt = WPA_KEY_MGMT_IEEE8021X_NO_WPA;
Hai Shalomfdcde762020-04-02 11:19:20 -07001426#ifdef CONFIG_WEP
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001427 } else if (bss->ssid.wep.keys_set) {
1428 int cipher = WPA_CIPHER_WEP40;
1429 if (bss->ssid.wep.len[0] >= 13)
1430 cipher = WPA_CIPHER_WEP104;
1431 bss->ssid.security_policy = SECURITY_STATIC_WEP;
1432 bss->wpa_group = cipher;
1433 bss->wpa_pairwise = cipher;
1434 bss->rsn_pairwise = cipher;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001435 if (full_config)
1436 bss->wpa_key_mgmt = WPA_KEY_MGMT_NONE;
Hai Shalomfdcde762020-04-02 11:19:20 -07001437#endif /* CONFIG_WEP */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001438 } else if (bss->osen) {
1439 bss->ssid.security_policy = SECURITY_OSEN;
1440 bss->wpa_group = WPA_CIPHER_CCMP;
1441 bss->wpa_pairwise = 0;
1442 bss->rsn_pairwise = WPA_CIPHER_CCMP;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001443 } else {
1444 bss->ssid.security_policy = SECURITY_PLAINTEXT;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001445 if (full_config) {
1446 bss->wpa_group = WPA_CIPHER_NONE;
1447 bss->wpa_pairwise = WPA_CIPHER_NONE;
1448 bss->rsn_pairwise = WPA_CIPHER_NONE;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001449 bss->wpa_key_mgmt = WPA_KEY_MGMT_NONE;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001450 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001451 }
1452}
Hai Shalom74f70d42019-02-11 14:42:39 -08001453
1454
1455int hostapd_sae_pw_id_in_use(struct hostapd_bss_config *conf)
1456{
1457 int with_id = 0, without_id = 0;
1458 struct sae_password_entry *pw;
1459
1460 if (conf->ssid.wpa_passphrase)
1461 without_id = 1;
1462
1463 for (pw = conf->sae_passwords; pw; pw = pw->next) {
1464 if (pw->identifier)
1465 with_id = 1;
1466 else
1467 without_id = 1;
1468 if (with_id && without_id)
1469 break;
1470 }
1471
1472 if (with_id && !without_id)
1473 return 2;
1474 return with_id;
1475}