blob: b0d8ec86b9b354465d8820f3197e185e6e81671e [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;
Hai Shalom60840252021-02-19 19:02:11 -0800134 bss->fils_discovery_min_int = 20;
Dmitry Shmidt29333592017-01-09 12:27:11 -0800135#endif /* CONFIG_FILS */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700136
137 bss->broadcast_deauth = 1;
138
139#ifdef CONFIG_MBO
140 bss->mbo_cell_data_conn_pref = -1;
141#endif /* CONFIG_MBO */
Roshan Pius3a1667e2018-07-03 15:17:14 -0700142
143 /* Disable TLS v1.3 by default for now to avoid interoperability issue.
144 * This can be enabled by default once the implementation has been fully
145 * completed and tested with other implementations. */
146 bss->tls_flags = TLS_CONN_DISABLE_TLSv1_3;
Hai Shalom74f70d42019-02-11 14:42:39 -0800147
Hai Shalomc3565922019-10-28 11:58:20 -0700148 bss->max_auth_rounds = 100;
149 bss->max_auth_rounds_short = 50;
150
Hai Shalom74f70d42019-02-11 14:42:39 -0800151 bss->send_probe_response = 1;
152
153#ifdef CONFIG_HS20
154 bss->hs20_release = (HS20_VERSION >> 4) + 1;
155#endif /* CONFIG_HS20 */
156
Hai Shalom81f62d82019-07-22 12:10:00 -0700157#ifdef CONFIG_MACSEC
158 bss->mka_priority = DEFAULT_PRIO_NOT_KEY_SERVER;
159 bss->macsec_port = 1;
160#endif /* CONFIG_MACSEC */
161
Hai Shalom74f70d42019-02-11 14:42:39 -0800162 /* Default to strict CRL checking. */
163 bss->check_crl_strict = 1;
Hai Shalom899fcc72020-10-19 14:38:18 -0700164
165#ifdef CONFIG_TESTING_OPTIONS
166 bss->sae_commit_status = -1;
167#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700168}
169
170
171struct hostapd_config * hostapd_config_defaults(void)
172{
173#define ecw2cw(ecw) ((1 << (ecw)) - 1)
174
175 struct hostapd_config *conf;
176 struct hostapd_bss_config *bss;
177 const int aCWmin = 4, aCWmax = 10;
178 const struct hostapd_wmm_ac_params ac_bk =
179 { aCWmin, aCWmax, 7, 0, 0 }; /* background traffic */
180 const struct hostapd_wmm_ac_params ac_be =
181 { aCWmin, aCWmax, 3, 0, 0 }; /* best effort traffic */
182 const struct hostapd_wmm_ac_params ac_vi = /* video traffic */
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700183 { aCWmin - 1, aCWmin, 2, 3008 / 32, 0 };
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700184 const struct hostapd_wmm_ac_params ac_vo = /* voice traffic */
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700185 { aCWmin - 2, aCWmin - 1, 2, 1504 / 32, 0 };
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700186 const struct hostapd_tx_queue_params txq_bk =
187 { 7, ecw2cw(aCWmin), ecw2cw(aCWmax), 0 };
188 const struct hostapd_tx_queue_params txq_be =
189 { 3, ecw2cw(aCWmin), 4 * (ecw2cw(aCWmin) + 1) - 1, 0};
190 const struct hostapd_tx_queue_params txq_vi =
191 { 1, (ecw2cw(aCWmin) + 1) / 2 - 1, ecw2cw(aCWmin), 30};
192 const struct hostapd_tx_queue_params txq_vo =
193 { 1, (ecw2cw(aCWmin) + 1) / 4 - 1,
194 (ecw2cw(aCWmin) + 1) / 2 - 1, 15};
195
196#undef ecw2cw
197
198 conf = os_zalloc(sizeof(*conf));
199 bss = os_zalloc(sizeof(*bss));
200 if (conf == NULL || bss == NULL) {
201 wpa_printf(MSG_ERROR, "Failed to allocate memory for "
202 "configuration data.");
203 os_free(conf);
204 os_free(bss);
205 return NULL;
206 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800207 conf->bss = os_calloc(1, sizeof(struct hostapd_bss_config *));
208 if (conf->bss == NULL) {
209 os_free(conf);
210 os_free(bss);
211 return NULL;
212 }
213 conf->bss[0] = bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700214
215 bss->radius = os_zalloc(sizeof(*bss->radius));
216 if (bss->radius == NULL) {
Dmitry Shmidt97672262014-02-03 13:02:54 -0800217 os_free(conf->bss);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700218 os_free(conf);
219 os_free(bss);
220 return NULL;
221 }
222
223 hostapd_config_defaults_bss(bss);
224
225 conf->num_bss = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700226
227 conf->beacon_int = 100;
Hai Shalom021b0b52019-04-10 11:17:58 -0700228 conf->rts_threshold = -2; /* use driver default: 2347 */
229 conf->fragm_threshold = -2; /* user driver default: 2346 */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800230 /* Set to invalid value means do not add Power Constraint IE */
231 conf->local_pwr_constraint = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700232
233 conf->wmm_ac_params[0] = ac_be;
234 conf->wmm_ac_params[1] = ac_bk;
235 conf->wmm_ac_params[2] = ac_vi;
236 conf->wmm_ac_params[3] = ac_vo;
237
238 conf->tx_queue[0] = txq_vo;
239 conf->tx_queue[1] = txq_vi;
240 conf->tx_queue[2] = txq_be;
241 conf->tx_queue[3] = txq_bk;
242
243 conf->ht_capab = HT_CAP_INFO_SMPS_DISABLED;
244
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800245 conf->ap_table_max_size = 255;
246 conf->ap_table_expiration_time = 60;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800247 conf->track_sta_max_age = 180;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800248
Dmitry Shmidt8da800a2013-04-24 12:57:01 -0700249#ifdef CONFIG_TESTING_OPTIONS
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700250 conf->ignore_probe_probability = 0.0;
251 conf->ignore_auth_probability = 0.0;
252 conf->ignore_assoc_probability = 0.0;
253 conf->ignore_reassoc_probability = 0.0;
254 conf->corrupt_gtk_rekey_mic_probability = 0.0;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800255 conf->ecsa_ie_only = 0;
Kai Shie75b0652020-11-24 20:31:29 -0800256 conf->skip_send_eapol = 0;
257 conf->enable_eapol_large_timeout = 0;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -0700258#endif /* CONFIG_TESTING_OPTIONS */
259
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700260 conf->acs = 0;
261 conf->acs_ch_list.num = 0;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700262#ifdef CONFIG_ACS
263 conf->acs_num_scans = 5;
264#endif /* CONFIG_ACS */
265
Hai Shalom81f62d82019-07-22 12:10:00 -0700266#ifdef CONFIG_IEEE80211AX
267 conf->he_op.he_rts_threshold = HE_OPERATION_RTS_THRESHOLD_MASK >>
268 HE_OPERATION_RTS_THRESHOLD_OFFSET;
269 /* Set default basic MCS/NSS set to single stream MCS 0-7 */
270 conf->he_op.he_basic_mcs_nss_set = 0xfffc;
Hai Shalomfdcde762020-04-02 11:19:20 -0700271 conf->he_op.he_bss_color_disabled = 1;
272 conf->he_op.he_bss_color_partial = 0;
273 conf->he_op.he_bss_color = 1;
Hai Shalom60840252021-02-19 19:02:11 -0800274 conf->he_6ghz_max_mpdu = 2;
275 conf->he_6ghz_max_ampdu_len_exp = 7;
276 conf->he_6ghz_rx_ant_pat = 1;
277 conf->he_6ghz_tx_ant_pat = 1;
Hai Shalom81f62d82019-07-22 12:10:00 -0700278#endif /* CONFIG_IEEE80211AX */
279
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700280 /* The third octet of the country string uses an ASCII space character
281 * by default to indicate that the regulations encompass all
282 * environments for the current frequency band in the country. */
283 conf->country[2] = ' ';
284
Hai Shalom74f70d42019-02-11 14:42:39 -0800285 conf->rssi_reject_assoc_rssi = 0;
286 conf->rssi_reject_assoc_timeout = 30;
287
Hai Shalom81f62d82019-07-22 12:10:00 -0700288#ifdef CONFIG_AIRTIME_POLICY
289 conf->airtime_update_interval = AIRTIME_DEFAULT_UPDATE_INTERVAL;
290#endif /* CONFIG_AIRTIME_POLICY */
291
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700292 return conf;
293}
294
295
296int hostapd_mac_comp(const void *a, const void *b)
297{
298 return os_memcmp(a, b, sizeof(macaddr));
299}
300
301
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700302static int hostapd_config_read_wpa_psk(const char *fname,
303 struct hostapd_ssid *ssid)
304{
305 FILE *f;
306 char buf[128], *pos;
Hai Shalom74f70d42019-02-11 14:42:39 -0800307 const char *keyid;
308 char *context;
309 char *context2;
310 char *token;
311 char *name;
312 char *value;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700313 int line = 0, ret = 0, len, ok;
314 u8 addr[ETH_ALEN];
315 struct hostapd_wpa_psk *psk;
316
317 if (!fname)
318 return 0;
319
320 f = fopen(fname, "r");
321 if (!f) {
322 wpa_printf(MSG_ERROR, "WPA PSK file '%s' not found.", fname);
323 return -1;
324 }
325
326 while (fgets(buf, sizeof(buf), f)) {
Hai Shalom021b0b52019-04-10 11:17:58 -0700327 int vlan_id = 0;
Hai Shalomfdcde762020-04-02 11:19:20 -0700328 int wps = 0;
Hai Shalom021b0b52019-04-10 11:17:58 -0700329
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700330 line++;
331
332 if (buf[0] == '#')
333 continue;
334 pos = buf;
335 while (*pos != '\0') {
336 if (*pos == '\n') {
337 *pos = '\0';
338 break;
339 }
340 pos++;
341 }
342 if (buf[0] == '\0')
343 continue;
344
Hai Shalom74f70d42019-02-11 14:42:39 -0800345 context = NULL;
346 keyid = NULL;
347 while ((token = str_token(buf, " ", &context))) {
348 if (!os_strchr(token, '='))
349 break;
350 context2 = NULL;
351 name = str_token(token, "=", &context2);
Hai Shalom021b0b52019-04-10 11:17:58 -0700352 if (!name)
353 break;
Hai Shalom74f70d42019-02-11 14:42:39 -0800354 value = str_token(token, "", &context2);
355 if (!value)
356 value = "";
357 if (!os_strcmp(name, "keyid")) {
358 keyid = value;
Hai Shalomfdcde762020-04-02 11:19:20 -0700359 } else if (!os_strcmp(name, "wps")) {
360 wps = atoi(value);
Hai Shalom021b0b52019-04-10 11:17:58 -0700361 } else if (!os_strcmp(name, "vlanid")) {
362 vlan_id = atoi(value);
Hai Shalom74f70d42019-02-11 14:42:39 -0800363 } else {
364 wpa_printf(MSG_ERROR,
365 "Unrecognized '%s=%s' on line %d in '%s'",
366 name, value, line, fname);
367 ret = -1;
368 break;
369 }
370 }
371
372 if (ret == -1)
373 break;
374
375 if (!token)
376 token = "";
377 if (hwaddr_aton(token, addr)) {
Hai Shalomfdcde762020-04-02 11:19:20 -0700378 wpa_printf(MSG_ERROR,
379 "Invalid MAC address '%s' on line %d in '%s'",
380 token, line, fname);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700381 ret = -1;
382 break;
383 }
384
385 psk = os_zalloc(sizeof(*psk));
386 if (psk == NULL) {
387 wpa_printf(MSG_ERROR, "WPA PSK allocation failed");
388 ret = -1;
389 break;
390 }
Hai Shalom021b0b52019-04-10 11:17:58 -0700391 psk->vlan_id = vlan_id;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700392 if (is_zero_ether_addr(addr))
393 psk->group = 1;
394 else
395 os_memcpy(psk->addr, addr, ETH_ALEN);
396
Hai Shalom74f70d42019-02-11 14:42:39 -0800397 pos = str_token(buf, "", &context);
398 if (!pos) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700399 wpa_printf(MSG_ERROR, "No PSK on line %d in '%s'",
400 line, fname);
401 os_free(psk);
402 ret = -1;
403 break;
404 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700405
406 ok = 0;
407 len = os_strlen(pos);
Hai Shalomfdcde762020-04-02 11:19:20 -0700408 if (len == 2 * PMK_LEN &&
409 hexstr2bin(pos, psk->psk, PMK_LEN) == 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700410 ok = 1;
Hai Shalomfdcde762020-04-02 11:19:20 -0700411 else if (len >= 8 && len < 64 &&
412 pbkdf2_sha1(pos, ssid->ssid, ssid->ssid_len,
413 4096, psk->psk, PMK_LEN) == 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700414 ok = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700415 if (!ok) {
Hai Shalomfdcde762020-04-02 11:19:20 -0700416 wpa_printf(MSG_ERROR,
417 "Invalid PSK '%s' on line %d in '%s'",
418 pos, line, fname);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700419 os_free(psk);
420 ret = -1;
421 break;
422 }
423
Hai Shalom74f70d42019-02-11 14:42:39 -0800424 if (keyid) {
425 len = os_strlcpy(psk->keyid, keyid, sizeof(psk->keyid));
426 if ((size_t) len >= sizeof(psk->keyid)) {
427 wpa_printf(MSG_ERROR,
428 "PSK keyid too long on line %d in '%s'",
429 line, fname);
430 os_free(psk);
431 ret = -1;
432 break;
433 }
434 }
435
Hai Shalomfdcde762020-04-02 11:19:20 -0700436 psk->wps = wps;
437
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700438 psk->next = ssid->wpa_psk;
439 ssid->wpa_psk = psk;
440 }
441
442 fclose(f);
443
444 return ret;
445}
446
447
448static int hostapd_derive_psk(struct hostapd_ssid *ssid)
449{
450 ssid->wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
451 if (ssid->wpa_psk == NULL) {
452 wpa_printf(MSG_ERROR, "Unable to alloc space for PSK");
453 return -1;
454 }
455 wpa_hexdump_ascii(MSG_DEBUG, "SSID",
456 (u8 *) ssid->ssid, ssid->ssid_len);
457 wpa_hexdump_ascii_key(MSG_DEBUG, "PSK (ASCII passphrase)",
458 (u8 *) ssid->wpa_passphrase,
459 os_strlen(ssid->wpa_passphrase));
460 pbkdf2_sha1(ssid->wpa_passphrase,
461 ssid->ssid, ssid->ssid_len,
462 4096, ssid->wpa_psk->psk, PMK_LEN);
463 wpa_hexdump_key(MSG_DEBUG, "PSK (from passphrase)",
464 ssid->wpa_psk->psk, PMK_LEN);
465 return 0;
466}
467
468
Hai Shalomc3565922019-10-28 11:58:20 -0700469int hostapd_setup_sae_pt(struct hostapd_bss_config *conf)
470{
471#ifdef CONFIG_SAE
472 struct hostapd_ssid *ssid = &conf->ssid;
473 struct sae_password_entry *pw;
474
Hai Shalom899fcc72020-10-19 14:38:18 -0700475 if ((conf->sae_pwe == 0 && !hostapd_sae_pw_id_in_use(conf) &&
476 !hostapd_sae_pk_in_use(conf)) ||
Hai Shalomfdcde762020-04-02 11:19:20 -0700477 conf->sae_pwe == 3 ||
478 !wpa_key_mgmt_sae(conf->wpa_key_mgmt))
Hai Shalomc3565922019-10-28 11:58:20 -0700479 return 0; /* PT not needed */
480
481 sae_deinit_pt(ssid->pt);
482 ssid->pt = NULL;
483 if (ssid->wpa_passphrase) {
484 ssid->pt = sae_derive_pt(conf->sae_groups, ssid->ssid,
485 ssid->ssid_len,
486 (const u8 *) ssid->wpa_passphrase,
487 os_strlen(ssid->wpa_passphrase),
488 NULL);
489 if (!ssid->pt)
490 return -1;
491 }
492
493 for (pw = conf->sae_passwords; pw; pw = pw->next) {
494 sae_deinit_pt(pw->pt);
495 pw->pt = sae_derive_pt(conf->sae_groups, ssid->ssid,
496 ssid->ssid_len,
497 (const u8 *) pw->password,
498 os_strlen(pw->password),
499 pw->identifier);
500 if (!pw->pt)
501 return -1;
502 }
503#endif /* CONFIG_SAE */
504
505 return 0;
506}
507
508
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700509int hostapd_setup_wpa_psk(struct hostapd_bss_config *conf)
510{
511 struct hostapd_ssid *ssid = &conf->ssid;
512
Hai Shalomc3565922019-10-28 11:58:20 -0700513 if (hostapd_setup_sae_pt(conf) < 0)
514 return -1;
515
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700516 if (ssid->wpa_passphrase != NULL) {
517 if (ssid->wpa_psk != NULL) {
518 wpa_printf(MSG_DEBUG, "Using pre-configured WPA PSK "
519 "instead of passphrase");
520 } else {
521 wpa_printf(MSG_DEBUG, "Deriving WPA PSK based on "
522 "passphrase");
523 if (hostapd_derive_psk(ssid) < 0)
524 return -1;
525 }
526 ssid->wpa_psk->group = 1;
527 }
528
Dmitry Shmidt29333592017-01-09 12:27:11 -0800529 return hostapd_config_read_wpa_psk(ssid->wpa_psk_file, &conf->ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700530}
531
532
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700533static void hostapd_config_free_radius(struct hostapd_radius_server *servers,
534 int num_servers)
535{
536 int i;
537
538 for (i = 0; i < num_servers; i++) {
539 os_free(servers[i].shared_secret);
540 }
541 os_free(servers);
542}
543
544
Dmitry Shmidt04949592012-07-19 12:16:46 -0700545struct hostapd_radius_attr *
546hostapd_config_get_radius_attr(struct hostapd_radius_attr *attr, u8 type)
547{
548 for (; attr; attr = attr->next) {
549 if (attr->type == type)
550 return attr;
551 }
552 return NULL;
553}
554
555
Hai Shalomc3565922019-10-28 11:58:20 -0700556struct hostapd_radius_attr * hostapd_parse_radius_attr(const char *value)
557{
558 const char *pos;
559 char syntax;
560 struct hostapd_radius_attr *attr;
561 size_t len;
562
563 attr = os_zalloc(sizeof(*attr));
564 if (!attr)
565 return NULL;
566
567 attr->type = atoi(value);
568
569 pos = os_strchr(value, ':');
570 if (!pos) {
571 attr->val = wpabuf_alloc(1);
572 if (!attr->val) {
573 os_free(attr);
574 return NULL;
575 }
576 wpabuf_put_u8(attr->val, 0);
577 return attr;
578 }
579
580 pos++;
581 if (pos[0] == '\0' || pos[1] != ':') {
582 os_free(attr);
583 return NULL;
584 }
585 syntax = *pos++;
586 pos++;
587
588 switch (syntax) {
589 case 's':
590 attr->val = wpabuf_alloc_copy(pos, os_strlen(pos));
591 break;
592 case 'x':
593 len = os_strlen(pos);
594 if (len & 1)
595 break;
596 len /= 2;
597 attr->val = wpabuf_alloc(len);
598 if (!attr->val)
599 break;
600 if (hexstr2bin(pos, wpabuf_put(attr->val, len), len) < 0) {
601 wpabuf_free(attr->val);
602 os_free(attr);
603 return NULL;
604 }
605 break;
606 case 'd':
607 attr->val = wpabuf_alloc(4);
608 if (attr->val)
609 wpabuf_put_be32(attr->val, atoi(pos));
610 break;
611 default:
612 os_free(attr);
613 return NULL;
614 }
615
616 if (!attr->val) {
617 os_free(attr);
618 return NULL;
619 }
620
621 return attr;
622}
623
624
625void hostapd_config_free_radius_attr(struct hostapd_radius_attr *attr)
Dmitry Shmidt04949592012-07-19 12:16:46 -0700626{
627 struct hostapd_radius_attr *prev;
628
629 while (attr) {
630 prev = attr;
631 attr = attr->next;
632 wpabuf_free(prev->val);
633 os_free(prev);
634 }
635}
636
637
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700638void hostapd_config_free_eap_user(struct hostapd_eap_user *user)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700639{
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700640 hostapd_config_free_radius_attr(user->accept_attr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700641 os_free(user->identity);
Dmitry Shmidtc2817022014-07-02 10:32:10 -0700642 bin_clear_free(user->password, user->password_len);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700643 bin_clear_free(user->salt, user->salt_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700644 os_free(user);
645}
646
647
Dmitry Shmidt29333592017-01-09 12:27:11 -0800648void hostapd_config_free_eap_users(struct hostapd_eap_user *user)
649{
650 struct hostapd_eap_user *prev_user;
651
652 while (user) {
653 prev_user = user;
654 user = user->next;
655 hostapd_config_free_eap_user(prev_user);
656 }
657}
658
659
Hai Shalomfdcde762020-04-02 11:19:20 -0700660#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700661static void hostapd_config_free_wep(struct hostapd_wep_keys *keys)
662{
663 int i;
664 for (i = 0; i < NUM_WEP_KEYS; i++) {
Dmitry Shmidtc2817022014-07-02 10:32:10 -0700665 bin_clear_free(keys->key[i], keys->len[i]);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700666 keys->key[i] = NULL;
667 }
668}
Hai Shalomfdcde762020-04-02 11:19:20 -0700669#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700670
671
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800672void hostapd_config_clear_wpa_psk(struct hostapd_wpa_psk **l)
673{
674 struct hostapd_wpa_psk *psk, *tmp;
675
676 for (psk = *l; psk;) {
677 tmp = psk;
678 psk = psk->next;
679 bin_clear_free(tmp, sizeof(*tmp));
680 }
681 *l = NULL;
682}
683
684
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800685static void hostapd_config_free_anqp_elem(struct hostapd_bss_config *conf)
686{
687 struct anqp_element *elem;
688
689 while ((elem = dl_list_first(&conf->anqp_elem, struct anqp_element,
690 list))) {
691 dl_list_del(&elem->list);
692 wpabuf_free(elem->payload);
693 os_free(elem);
694 }
695}
696
697
Dmitry Shmidt29333592017-01-09 12:27:11 -0800698static void hostapd_config_free_fils_realms(struct hostapd_bss_config *conf)
699{
700#ifdef CONFIG_FILS
701 struct fils_realm *realm;
702
703 while ((realm = dl_list_first(&conf->fils_realms, struct fils_realm,
704 list))) {
705 dl_list_del(&realm->list);
706 os_free(realm);
707 }
708#endif /* CONFIG_FILS */
709}
710
711
Roshan Pius3a1667e2018-07-03 15:17:14 -0700712static void hostapd_config_free_sae_passwords(struct hostapd_bss_config *conf)
713{
714 struct sae_password_entry *pw, *tmp;
715
716 pw = conf->sae_passwords;
717 conf->sae_passwords = NULL;
718 while (pw) {
719 tmp = pw;
720 pw = pw->next;
721 str_clear_free(tmp->password);
722 os_free(tmp->identifier);
Hai Shalomc3565922019-10-28 11:58:20 -0700723#ifdef CONFIG_SAE
724 sae_deinit_pt(tmp->pt);
725#endif /* CONFIG_SAE */
Hai Shalom899fcc72020-10-19 14:38:18 -0700726#ifdef CONFIG_SAE_PK
727 sae_deinit_pk(tmp->pk);
728#endif /* CONFIG_SAE_PK */
Roshan Pius3a1667e2018-07-03 15:17:14 -0700729 os_free(tmp);
730 }
731}
732
733
Hai Shalom81f62d82019-07-22 12:10:00 -0700734#ifdef CONFIG_DPP2
735static void hostapd_dpp_controller_conf_free(struct dpp_controller_conf *conf)
736{
737 struct dpp_controller_conf *prev;
738
739 while (conf) {
740 prev = conf;
741 conf = conf->next;
742 os_free(prev);
743 }
744}
745#endif /* CONFIG_DPP2 */
746
747
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800748void hostapd_config_free_bss(struct hostapd_bss_config *conf)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700749{
Hai Shalom81f62d82019-07-22 12:10:00 -0700750#if defined(CONFIG_WPS) || defined(CONFIG_HS20)
751 size_t i;
752#endif
753
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700754 if (conf == NULL)
755 return;
756
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800757 hostapd_config_clear_wpa_psk(&conf->ssid.wpa_psk);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700758
Dmitry Shmidtc2817022014-07-02 10:32:10 -0700759 str_clear_free(conf->ssid.wpa_passphrase);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700760 os_free(conf->ssid.wpa_psk_file);
Hai Shalomfdcde762020-04-02 11:19:20 -0700761#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700762 hostapd_config_free_wep(&conf->ssid.wep);
Hai Shalomfdcde762020-04-02 11:19:20 -0700763#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700764#ifdef CONFIG_FULL_DYNAMIC_VLAN
765 os_free(conf->ssid.vlan_tagged_interface);
766#endif /* CONFIG_FULL_DYNAMIC_VLAN */
Hai Shalomc3565922019-10-28 11:58:20 -0700767#ifdef CONFIG_SAE
768 sae_deinit_pt(conf->ssid.pt);
769#endif /* CONFIG_SAE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700770
Dmitry Shmidt29333592017-01-09 12:27:11 -0800771 hostapd_config_free_eap_users(conf->eap_user);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800772 os_free(conf->eap_user_sqlite);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700773
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700774 os_free(conf->eap_req_id_text);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800775 os_free(conf->erp_domain);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700776 os_free(conf->accept_mac);
777 os_free(conf->deny_mac);
778 os_free(conf->nas_identifier);
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800779 if (conf->radius) {
780 hostapd_config_free_radius(conf->radius->auth_servers,
781 conf->radius->num_auth_servers);
782 hostapd_config_free_radius(conf->radius->acct_servers,
783 conf->radius->num_acct_servers);
784 }
Dmitry Shmidt04949592012-07-19 12:16:46 -0700785 hostapd_config_free_radius_attr(conf->radius_auth_req_attr);
786 hostapd_config_free_radius_attr(conf->radius_acct_req_attr);
Hai Shalomc3565922019-10-28 11:58:20 -0700787 os_free(conf->radius_req_attr_sqlite);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700788 os_free(conf->rsn_preauth_interfaces);
789 os_free(conf->ctrl_interface);
790 os_free(conf->ca_cert);
791 os_free(conf->server_cert);
Hai Shalom81f62d82019-07-22 12:10:00 -0700792 os_free(conf->server_cert2);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700793 os_free(conf->private_key);
Hai Shalom81f62d82019-07-22 12:10:00 -0700794 os_free(conf->private_key2);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700795 os_free(conf->private_key_passwd);
Hai Shalom81f62d82019-07-22 12:10:00 -0700796 os_free(conf->private_key_passwd2);
Hai Shalom021b0b52019-04-10 11:17:58 -0700797 os_free(conf->check_cert_subject);
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700798 os_free(conf->ocsp_stapling_response);
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -0800799 os_free(conf->ocsp_stapling_response_multi);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700800 os_free(conf->dh_file);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800801 os_free(conf->openssl_ciphers);
Hai Shalom74f70d42019-02-11 14:42:39 -0800802 os_free(conf->openssl_ecdh_curves);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700803 os_free(conf->pac_opaque_encr_key);
804 os_free(conf->eap_fast_a_id);
805 os_free(conf->eap_fast_a_id_info);
806 os_free(conf->eap_sim_db);
807 os_free(conf->radius_server_clients);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700808 os_free(conf->radius);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700809 os_free(conf->radius_das_shared_secret);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700810 hostapd_config_free_vlan(conf);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800811 os_free(conf->time_zone);
812
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800813#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700814 {
815 struct ft_remote_r0kh *r0kh, *r0kh_prev;
816 struct ft_remote_r1kh *r1kh, *r1kh_prev;
817
818 r0kh = conf->r0kh_list;
819 conf->r0kh_list = NULL;
820 while (r0kh) {
821 r0kh_prev = r0kh;
822 r0kh = r0kh->next;
823 os_free(r0kh_prev);
824 }
825
826 r1kh = conf->r1kh_list;
827 conf->r1kh_list = NULL;
828 while (r1kh) {
829 r1kh_prev = r1kh;
830 r1kh = r1kh->next;
831 os_free(r1kh_prev);
832 }
833 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800834#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700835
836#ifdef CONFIG_WPS
837 os_free(conf->wps_pin_requests);
838 os_free(conf->device_name);
839 os_free(conf->manufacturer);
840 os_free(conf->model_name);
841 os_free(conf->model_number);
842 os_free(conf->serial_number);
843 os_free(conf->config_methods);
844 os_free(conf->ap_pin);
845 os_free(conf->extra_cred);
846 os_free(conf->ap_settings);
Hai Shalom021b0b52019-04-10 11:17:58 -0700847 hostapd_config_clear_wpa_psk(&conf->multi_ap_backhaul_ssid.wpa_psk);
848 str_clear_free(conf->multi_ap_backhaul_ssid.wpa_passphrase);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700849 os_free(conf->upnp_iface);
850 os_free(conf->friendly_name);
851 os_free(conf->manufacturer_url);
852 os_free(conf->model_description);
853 os_free(conf->model_url);
854 os_free(conf->upc);
Hai Shalom81f62d82019-07-22 12:10:00 -0700855 for (i = 0; i < MAX_WPS_VENDOR_EXTENSIONS; i++)
856 wpabuf_free(conf->wps_vendor_ext[i]);
Hai Shalomfdcde762020-04-02 11:19:20 -0700857 wpabuf_free(conf->wps_application_ext);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700858 wpabuf_free(conf->wps_nfc_dh_pubkey);
859 wpabuf_free(conf->wps_nfc_dh_privkey);
860 wpabuf_free(conf->wps_nfc_dev_pw);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700861#endif /* CONFIG_WPS */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800862
863 os_free(conf->roaming_consortium);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700864 os_free(conf->venue_name);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700865 os_free(conf->venue_url);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700866 os_free(conf->nai_realm_data);
867 os_free(conf->network_auth_type);
868 os_free(conf->anqp_3gpp_cell_net);
869 os_free(conf->domain_name);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800870 hostapd_config_free_anqp_elem(conf);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800871
872#ifdef CONFIG_RADIUS_TEST
873 os_free(conf->dump_msk_file);
874#endif /* CONFIG_RADIUS_TEST */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700875
876#ifdef CONFIG_HS20
877 os_free(conf->hs20_oper_friendly_name);
878 os_free(conf->hs20_wan_metrics);
879 os_free(conf->hs20_connection_capability);
880 os_free(conf->hs20_operating_class);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800881 os_free(conf->hs20_icons);
882 if (conf->hs20_osu_providers) {
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800883 for (i = 0; i < conf->hs20_osu_providers_count; i++) {
884 struct hs20_osu_provider *p;
885 size_t j;
886 p = &conf->hs20_osu_providers[i];
887 os_free(p->friendly_name);
888 os_free(p->server_uri);
889 os_free(p->method_list);
890 for (j = 0; j < p->icons_count; j++)
891 os_free(p->icons[j]);
892 os_free(p->icons);
893 os_free(p->osu_nai);
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800894 os_free(p->osu_nai2);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800895 os_free(p->service_desc);
896 }
897 os_free(conf->hs20_osu_providers);
898 }
Roshan Pius3a1667e2018-07-03 15:17:14 -0700899 if (conf->hs20_operator_icon) {
Roshan Pius3a1667e2018-07-03 15:17:14 -0700900 for (i = 0; i < conf->hs20_operator_icon_count; i++)
901 os_free(conf->hs20_operator_icon[i]);
902 os_free(conf->hs20_operator_icon);
903 }
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800904 os_free(conf->subscr_remediation_url);
Hai Shalom74f70d42019-02-11 14:42:39 -0800905 os_free(conf->hs20_sim_provisioning_url);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700906 os_free(conf->t_c_filename);
907 os_free(conf->t_c_server_url);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700908#endif /* CONFIG_HS20 */
909
910 wpabuf_free(conf->vendor_elements);
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700911 wpabuf_free(conf->assocresp_elements);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800912
913 os_free(conf->sae_groups);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700914#ifdef CONFIG_OWE
915 os_free(conf->owe_groups);
916#endif /* CONFIG_OWE */
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700917
Dmitry Shmidt0207e232014-09-03 14:58:37 -0700918 os_free(conf->wowlan_triggers);
919
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700920 os_free(conf->server_id);
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800921
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800922#ifdef CONFIG_TESTING_OPTIONS
923 wpabuf_free(conf->own_ie_override);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700924 wpabuf_free(conf->sae_commit_override);
Hai Shalomfdcde762020-04-02 11:19:20 -0700925 wpabuf_free(conf->rsne_override_eapol);
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800926 wpabuf_free(conf->rsnxe_override_eapol);
Hai Shalomfdcde762020-04-02 11:19:20 -0700927 wpabuf_free(conf->rsne_override_ft);
928 wpabuf_free(conf->rsnxe_override_ft);
929 wpabuf_free(conf->gtk_rsc_override);
930 wpabuf_free(conf->igtk_rsc_override);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800931#endif /* CONFIG_TESTING_OPTIONS */
932
933 os_free(conf->no_probe_resp_if_seen_on);
934 os_free(conf->no_auth_if_seen_on);
935
Dmitry Shmidt29333592017-01-09 12:27:11 -0800936 hostapd_config_free_fils_realms(conf);
937
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700938#ifdef CONFIG_DPP
Hai Shalomc3565922019-10-28 11:58:20 -0700939 os_free(conf->dpp_name);
940 os_free(conf->dpp_mud_url);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700941 os_free(conf->dpp_connector);
942 wpabuf_free(conf->dpp_netaccesskey);
943 wpabuf_free(conf->dpp_csign);
Hai Shalom81f62d82019-07-22 12:10:00 -0700944#ifdef CONFIG_DPP2
945 hostapd_dpp_controller_conf_free(conf->dpp_controller);
946#endif /* CONFIG_DPP2 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700947#endif /* CONFIG_DPP */
948
Roshan Pius3a1667e2018-07-03 15:17:14 -0700949 hostapd_config_free_sae_passwords(conf);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700950
Hai Shalom81f62d82019-07-22 12:10:00 -0700951#ifdef CONFIG_AIRTIME_POLICY
952 {
953 struct airtime_sta_weight *wt, *wt_prev;
954
955 wt = conf->airtime_weight_list;
956 conf->airtime_weight_list = NULL;
957 while (wt) {
958 wt_prev = wt;
959 wt = wt->next;
960 os_free(wt_prev);
961 }
962 }
963#endif /* CONFIG_AIRTIME_POLICY */
964
Hai Shalom60840252021-02-19 19:02:11 -0800965#ifdef CONFIG_PASN
966 os_free(conf->pasn_groups);
967#endif /* CONFIG_PASN */
968
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800969 os_free(conf);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700970}
971
972
973/**
974 * hostapd_config_free - Free hostapd configuration
975 * @conf: Configuration data from hostapd_config_read().
976 */
977void hostapd_config_free(struct hostapd_config *conf)
978{
979 size_t i;
980
981 if (conf == NULL)
982 return;
983
984 for (i = 0; i < conf->num_bss; i++)
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800985 hostapd_config_free_bss(conf->bss[i]);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700986 os_free(conf->bss);
987 os_free(conf->supported_rates);
988 os_free(conf->basic_rates);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700989 os_free(conf->acs_ch_list.range);
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800990 os_free(conf->acs_freq_list.range);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800991 os_free(conf->driver_params);
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800992#ifdef CONFIG_ACS
993 os_free(conf->acs_chan_bias);
994#endif /* CONFIG_ACS */
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700995 wpabuf_free(conf->lci);
996 wpabuf_free(conf->civic);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700997
998 os_free(conf);
999}
1000
1001
1002/**
1003 * hostapd_maclist_found - Find a MAC address from a list
1004 * @list: MAC address list
1005 * @num_entries: Number of addresses in the list
1006 * @addr: Address to search for
1007 * @vlan_id: Buffer for returning VLAN ID or %NULL if not needed
1008 * Returns: 1 if address is in the list or 0 if not.
1009 *
1010 * Perform a binary search for given MAC address from a pre-sorted list.
1011 */
1012int hostapd_maclist_found(struct mac_acl_entry *list, int num_entries,
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001013 const u8 *addr, struct vlan_description *vlan_id)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001014{
1015 int start, end, middle, res;
1016
1017 start = 0;
1018 end = num_entries - 1;
1019
1020 while (start <= end) {
1021 middle = (start + end) / 2;
1022 res = os_memcmp(list[middle].addr, addr, ETH_ALEN);
1023 if (res == 0) {
1024 if (vlan_id)
1025 *vlan_id = list[middle].vlan_id;
1026 return 1;
1027 }
1028 if (res < 0)
1029 start = middle + 1;
1030 else
1031 end = middle - 1;
1032 }
1033
1034 return 0;
1035}
1036
1037
1038int hostapd_rate_found(int *list, int rate)
1039{
1040 int i;
1041
1042 if (list == NULL)
1043 return 0;
1044
1045 for (i = 0; list[i] >= 0; i++)
1046 if (list[i] == rate)
1047 return 1;
1048
1049 return 0;
1050}
1051
1052
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001053int hostapd_vlan_valid(struct hostapd_vlan *vlan,
1054 struct vlan_description *vlan_desc)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001055{
1056 struct hostapd_vlan *v = vlan;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001057 int i;
1058
1059 if (!vlan_desc->notempty || vlan_desc->untagged < 0 ||
1060 vlan_desc->untagged > MAX_VLAN_ID)
1061 return 0;
1062 for (i = 0; i < MAX_NUM_TAGGED_VLAN; i++) {
1063 if (vlan_desc->tagged[i] < 0 ||
1064 vlan_desc->tagged[i] > MAX_VLAN_ID)
1065 return 0;
1066 }
1067 if (!vlan_desc->untagged && !vlan_desc->tagged[0])
1068 return 0;
1069
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001070 while (v) {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001071 if (!vlan_compare(&v->vlan_desc, vlan_desc) ||
1072 v->vlan_id == VLAN_ID_WILDCARD)
Dmitry Shmidt34af3062013-07-11 10:46:32 -07001073 return 1;
1074 v = v->next;
1075 }
1076 return 0;
1077}
1078
1079
1080const char * hostapd_get_vlan_id_ifname(struct hostapd_vlan *vlan, int vlan_id)
1081{
1082 struct hostapd_vlan *v = vlan;
1083 while (v) {
1084 if (v->vlan_id == vlan_id)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001085 return v->ifname;
1086 v = v->next;
1087 }
1088 return NULL;
1089}
1090
1091
1092const u8 * hostapd_get_psk(const struct hostapd_bss_config *conf,
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001093 const u8 *addr, const u8 *p2p_dev_addr,
Hai Shalom021b0b52019-04-10 11:17:58 -07001094 const u8 *prev_psk, int *vlan_id)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001095{
1096 struct hostapd_wpa_psk *psk;
1097 int next_ok = prev_psk == NULL;
1098
Hai Shalom021b0b52019-04-10 11:17:58 -07001099 if (vlan_id)
1100 *vlan_id = 0;
1101
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001102 if (p2p_dev_addr && !is_zero_ether_addr(p2p_dev_addr)) {
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001103 wpa_printf(MSG_DEBUG, "Searching a PSK for " MACSTR
1104 " p2p_dev_addr=" MACSTR " prev_psk=%p",
1105 MAC2STR(addr), MAC2STR(p2p_dev_addr), prev_psk);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001106 addr = NULL; /* Use P2P Device Address for matching */
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001107 } else {
1108 wpa_printf(MSG_DEBUG, "Searching a PSK for " MACSTR
1109 " prev_psk=%p",
1110 MAC2STR(addr), prev_psk);
1111 }
1112
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001113 for (psk = conf->ssid.wpa_psk; psk != NULL; psk = psk->next) {
1114 if (next_ok &&
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001115 (psk->group ||
1116 (addr && os_memcmp(psk->addr, addr, ETH_ALEN) == 0) ||
1117 (!addr && p2p_dev_addr &&
1118 os_memcmp(psk->p2p_dev_addr, p2p_dev_addr, ETH_ALEN) ==
Hai Shalom021b0b52019-04-10 11:17:58 -07001119 0))) {
1120 if (vlan_id)
1121 *vlan_id = psk->vlan_id;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001122 return psk->psk;
Hai Shalom021b0b52019-04-10 11:17:58 -07001123 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001124
1125 if (psk->psk == prev_psk)
1126 next_ok = 1;
1127 }
1128
1129 return NULL;
1130}
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001131
1132
Hai Shalom899fcc72020-10-19 14:38:18 -07001133#ifdef CONFIG_SAE_PK
1134static bool hostapd_sae_pk_password_without_pk(struct hostapd_bss_config *bss)
1135{
1136 struct sae_password_entry *pw;
1137 bool res = false;
1138
1139 if (bss->ssid.wpa_passphrase &&
1140#ifdef CONFIG_TESTING_OPTIONS
1141 !bss->sae_pk_password_check_skip &&
1142#endif /* CONFIG_TESTING_OPTIONS */
1143 sae_pk_valid_password(bss->ssid.wpa_passphrase))
1144 res = true;
1145
1146 for (pw = bss->sae_passwords; pw; pw = pw->next) {
1147 if (!pw->pk &&
1148#ifdef CONFIG_TESTING_OPTIONS
1149 !bss->sae_pk_password_check_skip &&
1150#endif /* CONFIG_TESTING_OPTIONS */
1151 sae_pk_valid_password(pw->password))
1152 return true;
1153
1154 if (bss->ssid.wpa_passphrase && res && pw->pk &&
1155 os_strcmp(bss->ssid.wpa_passphrase, pw->password) == 0)
1156 res = false;
1157 }
1158
1159 return res;
1160}
1161#endif /* CONFIG_SAE_PK */
1162
1163
Hai Shalom60840252021-02-19 19:02:11 -08001164static bool hostapd_config_check_bss_6g(struct hostapd_bss_config *bss)
1165{
1166 if (bss->wpa != WPA_PROTO_RSN) {
1167 wpa_printf(MSG_ERROR,
1168 "Pre-RSNA security methods are not allowed in 6 GHz");
1169 return false;
1170 }
1171
1172 if (bss->ieee80211w != MGMT_FRAME_PROTECTION_REQUIRED) {
1173 wpa_printf(MSG_ERROR,
1174 "Management frame protection is required in 6 GHz");
1175 return false;
1176 }
1177
1178 if (bss->wpa_key_mgmt & (WPA_KEY_MGMT_PSK |
1179 WPA_KEY_MGMT_FT_PSK |
1180 WPA_KEY_MGMT_PSK_SHA256)) {
1181 wpa_printf(MSG_ERROR, "Invalid AKM suite for 6 GHz");
1182 return false;
1183 }
1184
1185 if (bss->rsn_pairwise & (WPA_CIPHER_WEP40 |
1186 WPA_CIPHER_WEP104 |
1187 WPA_CIPHER_TKIP)) {
1188 wpa_printf(MSG_ERROR,
1189 "Invalid pairwise cipher suite for 6 GHz");
1190 return false;
1191 }
1192
1193 if (bss->wpa_group & (WPA_CIPHER_WEP40 |
1194 WPA_CIPHER_WEP104 |
1195 WPA_CIPHER_TKIP)) {
1196 wpa_printf(MSG_ERROR, "Invalid group cipher suite for 6 GHz");
1197 return false;
1198 }
1199
1200 return true;
1201}
1202
1203
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001204static int hostapd_config_check_bss(struct hostapd_bss_config *bss,
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001205 struct hostapd_config *conf,
1206 int full_config)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001207{
Hai Shalom60840252021-02-19 19:02:11 -08001208 if (full_config && is_6ghz_op_class(conf->op_class) &&
1209 !hostapd_config_check_bss_6g(bss))
1210 return -1;
1211
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001212 if (full_config && bss->ieee802_1x && !bss->eap_server &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001213 !bss->radius->auth_servers) {
1214 wpa_printf(MSG_ERROR, "Invalid IEEE 802.1X configuration (no "
1215 "EAP authenticator configured).");
1216 return -1;
1217 }
1218
Hai Shalomfdcde762020-04-02 11:19:20 -07001219#ifdef CONFIG_WEP
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001220 if (bss->wpa) {
1221 int wep, i;
1222
1223 wep = bss->default_wep_key_len > 0 ||
1224 bss->individual_wep_key_len > 0;
1225 for (i = 0; i < NUM_WEP_KEYS; i++) {
1226 if (bss->ssid.wep.keys_set) {
1227 wep = 1;
1228 break;
1229 }
1230 }
1231
1232 if (wep) {
1233 wpa_printf(MSG_ERROR, "WEP configuration in a WPA network is not supported");
1234 return -1;
1235 }
1236 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001237#endif /* CONFIG_WEP */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001238
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001239 if (full_config && bss->wpa &&
1240 bss->wpa_psk_radius != PSK_RADIUS_IGNORED &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001241 bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH) {
1242 wpa_printf(MSG_ERROR, "WPA-PSK using RADIUS enabled, but no "
1243 "RADIUS checking (macaddr_acl=2) enabled.");
1244 return -1;
1245 }
1246
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001247 if (full_config && bss->wpa && (bss->wpa_key_mgmt & WPA_KEY_MGMT_PSK) &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001248 bss->ssid.wpa_psk == NULL && bss->ssid.wpa_passphrase == NULL &&
1249 bss->ssid.wpa_psk_file == NULL &&
1250 (bss->wpa_psk_radius != PSK_RADIUS_REQUIRED ||
1251 bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH)) {
1252 wpa_printf(MSG_ERROR, "WPA-PSK enabled, but PSK or passphrase "
1253 "is not configured.");
1254 return -1;
1255 }
1256
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001257 if (full_config && !is_zero_ether_addr(bss->bssid)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001258 size_t i;
1259
1260 for (i = 0; i < conf->num_bss; i++) {
1261 if (conf->bss[i] != bss &&
1262 (hostapd_mac_comp(conf->bss[i]->bssid,
1263 bss->bssid) == 0)) {
1264 wpa_printf(MSG_ERROR, "Duplicate BSSID " MACSTR
1265 " on interface '%s' and '%s'.",
1266 MAC2STR(bss->bssid),
1267 conf->bss[i]->iface, bss->iface);
1268 return -1;
1269 }
1270 }
1271 }
1272
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001273#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001274 if (full_config && wpa_key_mgmt_ft(bss->wpa_key_mgmt) &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001275 (bss->nas_identifier == NULL ||
1276 os_strlen(bss->nas_identifier) < 1 ||
1277 os_strlen(bss->nas_identifier) > FT_R0KH_ID_MAX_LEN)) {
1278 wpa_printf(MSG_ERROR, "FT (IEEE 802.11r) requires "
1279 "nas_identifier to be configured as a 1..48 octet "
1280 "string");
1281 return -1;
1282 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001283#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001284
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001285 if (full_config && conf->ieee80211n &&
1286 conf->hw_mode == HOSTAPD_MODE_IEEE80211B) {
Hai Shalom60840252021-02-19 19:02:11 -08001287 bss->disable_11n = true;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001288 wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) in 11b mode is not "
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001289 "allowed, disabling HT capabilities");
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001290 }
1291
Hai Shalomfdcde762020-04-02 11:19:20 -07001292#ifdef CONFIG_WEP
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001293 if (full_config && conf->ieee80211n &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001294 bss->ssid.security_policy == SECURITY_STATIC_WEP) {
Hai Shalom60840252021-02-19 19:02:11 -08001295 bss->disable_11n = true;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001296 wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) with WEP is not "
1297 "allowed, disabling HT capabilities");
1298 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001299#endif /* CONFIG_WEP */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001300
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001301 if (full_config && conf->ieee80211n && bss->wpa &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001302 !(bss->wpa_pairwise & WPA_CIPHER_CCMP) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001303 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
1304 WPA_CIPHER_CCMP_256 | WPA_CIPHER_GCMP_256)))
1305 {
Hai Shalom60840252021-02-19 19:02:11 -08001306 bss->disable_11n = true;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001307 wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) with WPA/WPA2 "
1308 "requires CCMP/GCMP to be enabled, disabling HT "
1309 "capabilities");
1310 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001311
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07001312#ifdef CONFIG_IEEE80211AC
Hai Shalomfdcde762020-04-02 11:19:20 -07001313#ifdef CONFIG_WEP
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07001314 if (full_config && conf->ieee80211ac &&
1315 bss->ssid.security_policy == SECURITY_STATIC_WEP) {
Hai Shalom60840252021-02-19 19:02:11 -08001316 bss->disable_11ac = true;
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07001317 wpa_printf(MSG_ERROR,
1318 "VHT (IEEE 802.11ac) with WEP is not allowed, disabling VHT capabilities");
1319 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001320#endif /* CONFIG_WEP */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001321
1322 if (full_config && conf->ieee80211ac && bss->wpa &&
1323 !(bss->wpa_pairwise & WPA_CIPHER_CCMP) &&
1324 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
1325 WPA_CIPHER_CCMP_256 | WPA_CIPHER_GCMP_256)))
1326 {
Hai Shalom60840252021-02-19 19:02:11 -08001327 bss->disable_11ac = true;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001328 wpa_printf(MSG_ERROR,
1329 "VHT (IEEE 802.11ac) with WPA/WPA2 requires CCMP/GCMP to be enabled, disabling VHT capabilities");
1330 }
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07001331#endif /* CONFIG_IEEE80211AC */
1332
Hai Shalom60840252021-02-19 19:02:11 -08001333#ifdef CONFIG_IEEE80211AX
1334#ifdef CONFIG_WEP
1335 if (full_config && conf->ieee80211ax &&
1336 bss->ssid.security_policy == SECURITY_STATIC_WEP) {
1337 bss->disable_11ax = true;
1338 wpa_printf(MSG_ERROR,
1339 "HE (IEEE 802.11ax) with WEP is not allowed, disabling HE capabilities");
1340 }
1341#endif /* CONFIG_WEP */
1342
1343 if (full_config && conf->ieee80211ax && bss->wpa &&
1344 !(bss->wpa_pairwise & WPA_CIPHER_CCMP) &&
1345 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
1346 WPA_CIPHER_CCMP_256 | WPA_CIPHER_GCMP_256)))
1347 {
1348 bss->disable_11ax = true;
1349 wpa_printf(MSG_ERROR,
1350 "HE (IEEE 802.11ax) with WPA/WPA2 requires CCMP/GCMP to be enabled, disabling HE capabilities");
1351 }
1352#endif /* CONFIG_IEEE80211AX */
1353
Dmitry Shmidt15907092014-03-25 10:42:57 -07001354#ifdef CONFIG_WPS
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001355 if (full_config && bss->wps_state && bss->ignore_broadcast_ssid) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001356 wpa_printf(MSG_INFO, "WPS: ignore_broadcast_ssid "
1357 "configuration forced WPS to be disabled");
1358 bss->wps_state = 0;
1359 }
1360
Hai Shalomfdcde762020-04-02 11:19:20 -07001361#ifdef CONFIG_WEP
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001362 if (full_config && bss->wps_state &&
1363 bss->ssid.wep.keys_set && bss->wpa == 0) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001364 wpa_printf(MSG_INFO, "WPS: WEP configuration forced WPS to be "
1365 "disabled");
1366 bss->wps_state = 0;
1367 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001368#endif /* CONFIG_WEP */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001369
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001370 if (full_config && bss->wps_state && bss->wpa &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001371 (!(bss->wpa & 2) ||
Roshan Pius3a1667e2018-07-03 15:17:14 -07001372 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
1373 WPA_CIPHER_CCMP_256 |
1374 WPA_CIPHER_GCMP_256)))) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001375 wpa_printf(MSG_INFO, "WPS: WPA/TKIP configuration without "
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07001376 "WPA2/CCMP/GCMP forced WPS to be disabled");
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001377 bss->wps_state = 0;
1378 }
Dmitry Shmidt15907092014-03-25 10:42:57 -07001379#endif /* CONFIG_WPS */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001380
1381#ifdef CONFIG_HS20
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001382 if (full_config && bss->hs20 &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001383 (!(bss->wpa & 2) ||
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001384 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
1385 WPA_CIPHER_CCMP_256 |
1386 WPA_CIPHER_GCMP_256)))) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001387 wpa_printf(MSG_ERROR, "HS 2.0: WPA2-Enterprise/CCMP "
1388 "configuration is required for Hotspot 2.0 "
1389 "functionality");
1390 return -1;
1391 }
1392#endif /* CONFIG_HS20 */
1393
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001394#ifdef CONFIG_MBO
1395 if (full_config && bss->mbo_enabled && (bss->wpa & 2) &&
1396 bss->ieee80211w == NO_MGMT_FRAME_PROTECTION) {
1397 wpa_printf(MSG_ERROR,
1398 "MBO: PMF needs to be enabled whenever using WPA2 with MBO");
1399 return -1;
1400 }
1401#endif /* CONFIG_MBO */
1402
Hai Shalom74f70d42019-02-11 14:42:39 -08001403#ifdef CONFIG_OCV
1404 if (full_config && bss->ieee80211w == NO_MGMT_FRAME_PROTECTION &&
1405 bss->ocv) {
1406 wpa_printf(MSG_ERROR,
1407 "OCV: PMF needs to be enabled whenever using OCV");
1408 return -1;
1409 }
1410#endif /* CONFIG_OCV */
1411
Hai Shalom899fcc72020-10-19 14:38:18 -07001412#ifdef CONFIG_SAE_PK
1413 if (full_config && hostapd_sae_pk_in_use(bss) &&
1414 hostapd_sae_pk_password_without_pk(bss)) {
1415 wpa_printf(MSG_ERROR,
1416 "SAE-PK: SAE password uses SAE-PK style, but does not have PK configured");
1417 return -1;
1418 }
1419#endif /* CONFIG_SAE_PK */
1420
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001421 return 0;
1422}
1423
1424
Dmitry Shmidt05df46a2015-05-19 11:02:01 -07001425static int hostapd_config_check_cw(struct hostapd_config *conf, int queue)
1426{
1427 int tx_cwmin = conf->tx_queue[queue].cwmin;
1428 int tx_cwmax = conf->tx_queue[queue].cwmax;
1429 int ac_cwmin = conf->wmm_ac_params[queue].cwmin;
1430 int ac_cwmax = conf->wmm_ac_params[queue].cwmax;
1431
1432 if (tx_cwmin > tx_cwmax) {
1433 wpa_printf(MSG_ERROR,
1434 "Invalid TX queue cwMin/cwMax values. cwMin(%d) greater than cwMax(%d)",
1435 tx_cwmin, tx_cwmax);
1436 return -1;
1437 }
1438 if (ac_cwmin > ac_cwmax) {
1439 wpa_printf(MSG_ERROR,
1440 "Invalid WMM AC cwMin/cwMax values. cwMin(%d) greater than cwMax(%d)",
1441 ac_cwmin, ac_cwmax);
1442 return -1;
1443 }
1444 return 0;
1445}
1446
1447
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001448int hostapd_config_check(struct hostapd_config *conf, int full_config)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001449{
1450 size_t i;
1451
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001452 if (full_config && conf->ieee80211d &&
1453 (!conf->country[0] || !conf->country[1])) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001454 wpa_printf(MSG_ERROR, "Cannot enable IEEE 802.11d without "
1455 "setting the country_code");
1456 return -1;
1457 }
1458
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001459 if (full_config && conf->ieee80211h && !conf->ieee80211d) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001460 wpa_printf(MSG_ERROR, "Cannot enable IEEE 802.11h without "
1461 "IEEE 802.11d enabled");
1462 return -1;
1463 }
1464
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001465 if (full_config && conf->local_pwr_constraint != -1 &&
1466 !conf->ieee80211d) {
1467 wpa_printf(MSG_ERROR, "Cannot add Power Constraint element without Country element");
1468 return -1;
1469 }
1470
1471 if (full_config && conf->spectrum_mgmt_required &&
1472 conf->local_pwr_constraint == -1) {
1473 wpa_printf(MSG_ERROR, "Cannot set Spectrum Management bit without Country and Power Constraint elements");
1474 return -1;
1475 }
1476
Hai Shalom81f62d82019-07-22 12:10:00 -07001477#ifdef CONFIG_AIRTIME_POLICY
1478 if (full_config && conf->airtime_mode > AIRTIME_MODE_STATIC &&
1479 !conf->airtime_update_interval) {
1480 wpa_printf(MSG_ERROR, "Airtime update interval cannot be zero");
1481 return -1;
1482 }
1483#endif /* CONFIG_AIRTIME_POLICY */
Dmitry Shmidt05df46a2015-05-19 11:02:01 -07001484 for (i = 0; i < NUM_TX_QUEUES; i++) {
1485 if (hostapd_config_check_cw(conf, i))
1486 return -1;
1487 }
1488
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001489 for (i = 0; i < conf->num_bss; i++) {
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001490 if (hostapd_config_check_bss(conf->bss[i], conf, full_config))
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001491 return -1;
1492 }
1493
1494 return 0;
1495}
1496
1497
Dmitry Shmidt71757432014-06-02 13:50:35 -07001498void hostapd_set_security_params(struct hostapd_bss_config *bss,
1499 int full_config)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001500{
Hai Shalomfdcde762020-04-02 11:19:20 -07001501#ifdef CONFIG_WEP
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001502 if (bss->individual_wep_key_len == 0) {
1503 /* individual keys are not use; can use key idx0 for
1504 * broadcast keys */
1505 bss->broadcast_key_idx_min = 0;
1506 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001507#endif /* CONFIG_WEP */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001508
1509 if ((bss->wpa & 2) && bss->rsn_pairwise == 0)
1510 bss->rsn_pairwise = bss->wpa_pairwise;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001511 if (bss->group_cipher)
1512 bss->wpa_group = bss->group_cipher;
1513 else
1514 bss->wpa_group = wpa_select_ap_group_cipher(bss->wpa,
1515 bss->wpa_pairwise,
1516 bss->rsn_pairwise);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001517 if (!bss->wpa_group_rekey_set)
1518 bss->wpa_group_rekey = bss->wpa_group == WPA_CIPHER_TKIP ?
1519 600 : 86400;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001520
Dmitry Shmidt71757432014-06-02 13:50:35 -07001521 if (full_config) {
1522 bss->radius->auth_server = bss->radius->auth_servers;
1523 bss->radius->acct_server = bss->radius->acct_servers;
1524 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001525
1526 if (bss->wpa && bss->ieee802_1x) {
1527 bss->ssid.security_policy = SECURITY_WPA;
1528 } else if (bss->wpa) {
1529 bss->ssid.security_policy = SECURITY_WPA_PSK;
1530 } else if (bss->ieee802_1x) {
1531 int cipher = WPA_CIPHER_NONE;
1532 bss->ssid.security_policy = SECURITY_IEEE_802_1X;
Hai Shalomfdcde762020-04-02 11:19:20 -07001533#ifdef CONFIG_WEP
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001534 bss->ssid.wep.default_len = bss->default_wep_key_len;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001535 if (full_config && bss->default_wep_key_len) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001536 cipher = bss->default_wep_key_len >= 13 ?
1537 WPA_CIPHER_WEP104 : WPA_CIPHER_WEP40;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001538 } else if (full_config && bss->ssid.wep.keys_set) {
1539 if (bss->ssid.wep.len[0] >= 13)
1540 cipher = WPA_CIPHER_WEP104;
1541 else
1542 cipher = WPA_CIPHER_WEP40;
1543 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001544#endif /* CONFIG_WEP */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001545 bss->wpa_group = cipher;
1546 bss->wpa_pairwise = cipher;
1547 bss->rsn_pairwise = cipher;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001548 if (full_config)
1549 bss->wpa_key_mgmt = WPA_KEY_MGMT_IEEE8021X_NO_WPA;
Hai Shalomfdcde762020-04-02 11:19:20 -07001550#ifdef CONFIG_WEP
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001551 } else if (bss->ssid.wep.keys_set) {
1552 int cipher = WPA_CIPHER_WEP40;
1553 if (bss->ssid.wep.len[0] >= 13)
1554 cipher = WPA_CIPHER_WEP104;
1555 bss->ssid.security_policy = SECURITY_STATIC_WEP;
1556 bss->wpa_group = cipher;
1557 bss->wpa_pairwise = cipher;
1558 bss->rsn_pairwise = cipher;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001559 if (full_config)
1560 bss->wpa_key_mgmt = WPA_KEY_MGMT_NONE;
Hai Shalomfdcde762020-04-02 11:19:20 -07001561#endif /* CONFIG_WEP */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001562 } else if (bss->osen) {
1563 bss->ssid.security_policy = SECURITY_OSEN;
1564 bss->wpa_group = WPA_CIPHER_CCMP;
1565 bss->wpa_pairwise = 0;
1566 bss->rsn_pairwise = WPA_CIPHER_CCMP;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001567 } else {
1568 bss->ssid.security_policy = SECURITY_PLAINTEXT;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001569 if (full_config) {
1570 bss->wpa_group = WPA_CIPHER_NONE;
1571 bss->wpa_pairwise = WPA_CIPHER_NONE;
1572 bss->rsn_pairwise = WPA_CIPHER_NONE;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001573 bss->wpa_key_mgmt = WPA_KEY_MGMT_NONE;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001574 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001575 }
1576}
Hai Shalom74f70d42019-02-11 14:42:39 -08001577
1578
1579int hostapd_sae_pw_id_in_use(struct hostapd_bss_config *conf)
1580{
1581 int with_id = 0, without_id = 0;
1582 struct sae_password_entry *pw;
1583
1584 if (conf->ssid.wpa_passphrase)
1585 without_id = 1;
1586
1587 for (pw = conf->sae_passwords; pw; pw = pw->next) {
1588 if (pw->identifier)
1589 with_id = 1;
1590 else
1591 without_id = 1;
1592 if (with_id && without_id)
1593 break;
1594 }
1595
1596 if (with_id && !without_id)
1597 return 2;
1598 return with_id;
1599}
Hai Shalom899fcc72020-10-19 14:38:18 -07001600
1601
1602bool hostapd_sae_pk_in_use(struct hostapd_bss_config *conf)
1603{
1604#ifdef CONFIG_SAE_PK
1605 struct sae_password_entry *pw;
1606
1607 for (pw = conf->sae_passwords; pw; pw = pw->next) {
1608 if (pw->pk)
1609 return true;
1610 }
1611#endif /* CONFIG_SAE_PK */
1612
1613 return false;
1614}
1615
1616
1617#ifdef CONFIG_SAE_PK
1618bool hostapd_sae_pk_exclusively(struct hostapd_bss_config *conf)
1619{
1620 bool with_pk = false;
1621 struct sae_password_entry *pw;
1622
1623 if (conf->ssid.wpa_passphrase)
1624 return false;
1625
1626 for (pw = conf->sae_passwords; pw; pw = pw->next) {
1627 if (!pw->pk)
1628 return false;
1629 with_pk = true;
1630 }
1631
1632 return with_pk;
1633}
1634#endif /* CONFIG_SAE_PK */