blob: c3ee50677fa2e026bc1ac7f8178af1468d78bd65 [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * hostapd / Configuration helper functions
Sunil Ravia04bd252022-05-02 22:54:18 -07003 * Copyright (c) 2003-2022, 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
Hai Shaloma20dcd72022-02-04 13:43:00 -0800124 bss->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 */
Hai Shaloma20dcd72022-02-04 13:43:00 -0800168
169#ifdef CONFIG_PASN
170 /* comeback after 10 TUs */
171 bss->pasn_comeback_after = 10;
Sunil Ravi640215c2023-06-28 23:08:09 +0000172 bss->pasn_noauth = 1;
Hai Shaloma20dcd72022-02-04 13:43:00 -0800173#endif /* CONFIG_PASN */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700174}
175
176
177struct hostapd_config * hostapd_config_defaults(void)
178{
179#define ecw2cw(ecw) ((1 << (ecw)) - 1)
180
181 struct hostapd_config *conf;
182 struct hostapd_bss_config *bss;
183 const int aCWmin = 4, aCWmax = 10;
184 const struct hostapd_wmm_ac_params ac_bk =
185 { aCWmin, aCWmax, 7, 0, 0 }; /* background traffic */
186 const struct hostapd_wmm_ac_params ac_be =
187 { aCWmin, aCWmax, 3, 0, 0 }; /* best effort traffic */
188 const struct hostapd_wmm_ac_params ac_vi = /* video traffic */
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700189 { aCWmin - 1, aCWmin, 2, 3008 / 32, 0 };
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700190 const struct hostapd_wmm_ac_params ac_vo = /* voice traffic */
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700191 { aCWmin - 2, aCWmin - 1, 2, 1504 / 32, 0 };
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700192 const struct hostapd_tx_queue_params txq_bk =
193 { 7, ecw2cw(aCWmin), ecw2cw(aCWmax), 0 };
194 const struct hostapd_tx_queue_params txq_be =
195 { 3, ecw2cw(aCWmin), 4 * (ecw2cw(aCWmin) + 1) - 1, 0};
196 const struct hostapd_tx_queue_params txq_vi =
197 { 1, (ecw2cw(aCWmin) + 1) / 2 - 1, ecw2cw(aCWmin), 30};
198 const struct hostapd_tx_queue_params txq_vo =
199 { 1, (ecw2cw(aCWmin) + 1) / 4 - 1,
200 (ecw2cw(aCWmin) + 1) / 2 - 1, 15};
201
202#undef ecw2cw
203
204 conf = os_zalloc(sizeof(*conf));
205 bss = os_zalloc(sizeof(*bss));
206 if (conf == NULL || bss == NULL) {
207 wpa_printf(MSG_ERROR, "Failed to allocate memory for "
208 "configuration data.");
209 os_free(conf);
210 os_free(bss);
211 return NULL;
212 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800213 conf->bss = os_calloc(1, sizeof(struct hostapd_bss_config *));
214 if (conf->bss == NULL) {
215 os_free(conf);
216 os_free(bss);
217 return NULL;
218 }
219 conf->bss[0] = bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700220
221 bss->radius = os_zalloc(sizeof(*bss->radius));
222 if (bss->radius == NULL) {
Dmitry Shmidt97672262014-02-03 13:02:54 -0800223 os_free(conf->bss);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700224 os_free(conf);
225 os_free(bss);
226 return NULL;
227 }
228
229 hostapd_config_defaults_bss(bss);
230
231 conf->num_bss = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700232
233 conf->beacon_int = 100;
Hai Shalom021b0b52019-04-10 11:17:58 -0700234 conf->rts_threshold = -2; /* use driver default: 2347 */
235 conf->fragm_threshold = -2; /* user driver default: 2346 */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800236 /* Set to invalid value means do not add Power Constraint IE */
237 conf->local_pwr_constraint = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700238
239 conf->wmm_ac_params[0] = ac_be;
240 conf->wmm_ac_params[1] = ac_bk;
241 conf->wmm_ac_params[2] = ac_vi;
242 conf->wmm_ac_params[3] = ac_vo;
243
244 conf->tx_queue[0] = txq_vo;
245 conf->tx_queue[1] = txq_vi;
246 conf->tx_queue[2] = txq_be;
247 conf->tx_queue[3] = txq_bk;
248
249 conf->ht_capab = HT_CAP_INFO_SMPS_DISABLED;
250
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800251 conf->ap_table_max_size = 255;
252 conf->ap_table_expiration_time = 60;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800253 conf->track_sta_max_age = 180;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800254
Dmitry Shmidt8da800a2013-04-24 12:57:01 -0700255#ifdef CONFIG_TESTING_OPTIONS
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700256 conf->ignore_probe_probability = 0.0;
257 conf->ignore_auth_probability = 0.0;
258 conf->ignore_assoc_probability = 0.0;
259 conf->ignore_reassoc_probability = 0.0;
260 conf->corrupt_gtk_rekey_mic_probability = 0.0;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800261 conf->ecsa_ie_only = 0;
Kai Shie75b0652020-11-24 20:31:29 -0800262 conf->skip_send_eapol = 0;
263 conf->enable_eapol_large_timeout = 0;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -0700264#endif /* CONFIG_TESTING_OPTIONS */
265
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700266 conf->acs = 0;
267 conf->acs_ch_list.num = 0;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700268#ifdef CONFIG_ACS
269 conf->acs_num_scans = 5;
270#endif /* CONFIG_ACS */
271
Hai Shalom81f62d82019-07-22 12:10:00 -0700272#ifdef CONFIG_IEEE80211AX
273 conf->he_op.he_rts_threshold = HE_OPERATION_RTS_THRESHOLD_MASK >>
274 HE_OPERATION_RTS_THRESHOLD_OFFSET;
275 /* Set default basic MCS/NSS set to single stream MCS 0-7 */
276 conf->he_op.he_basic_mcs_nss_set = 0xfffc;
Hai Shalomfdcde762020-04-02 11:19:20 -0700277 conf->he_op.he_bss_color_disabled = 1;
278 conf->he_op.he_bss_color_partial = 0;
Hai Shaloma20dcd72022-02-04 13:43:00 -0800279 conf->he_op.he_bss_color = os_random() % 63 + 1;
280 conf->he_op.he_twt_responder = 1;
Hai Shalom60840252021-02-19 19:02:11 -0800281 conf->he_6ghz_max_mpdu = 2;
282 conf->he_6ghz_max_ampdu_len_exp = 7;
283 conf->he_6ghz_rx_ant_pat = 1;
284 conf->he_6ghz_tx_ant_pat = 1;
Hai Shalom81f62d82019-07-22 12:10:00 -0700285#endif /* CONFIG_IEEE80211AX */
286
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700287 /* The third octet of the country string uses an ASCII space character
288 * by default to indicate that the regulations encompass all
289 * environments for the current frequency band in the country. */
290 conf->country[2] = ' ';
291
Hai Shalom74f70d42019-02-11 14:42:39 -0800292 conf->rssi_reject_assoc_rssi = 0;
293 conf->rssi_reject_assoc_timeout = 30;
294
Hai Shalom81f62d82019-07-22 12:10:00 -0700295#ifdef CONFIG_AIRTIME_POLICY
296 conf->airtime_update_interval = AIRTIME_DEFAULT_UPDATE_INTERVAL;
297#endif /* CONFIG_AIRTIME_POLICY */
298
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700299 return conf;
300}
301
302
303int hostapd_mac_comp(const void *a, const void *b)
304{
305 return os_memcmp(a, b, sizeof(macaddr));
306}
307
308
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700309static int hostapd_config_read_wpa_psk(const char *fname,
310 struct hostapd_ssid *ssid)
311{
312 FILE *f;
313 char buf[128], *pos;
Hai Shalom74f70d42019-02-11 14:42:39 -0800314 const char *keyid;
315 char *context;
316 char *context2;
317 char *token;
318 char *name;
319 char *value;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700320 int line = 0, ret = 0, len, ok;
321 u8 addr[ETH_ALEN];
322 struct hostapd_wpa_psk *psk;
323
324 if (!fname)
325 return 0;
326
327 f = fopen(fname, "r");
328 if (!f) {
329 wpa_printf(MSG_ERROR, "WPA PSK file '%s' not found.", fname);
330 return -1;
331 }
332
333 while (fgets(buf, sizeof(buf), f)) {
Hai Shalom021b0b52019-04-10 11:17:58 -0700334 int vlan_id = 0;
Hai Shalomfdcde762020-04-02 11:19:20 -0700335 int wps = 0;
Hai Shalom021b0b52019-04-10 11:17:58 -0700336
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700337 line++;
338
339 if (buf[0] == '#')
340 continue;
341 pos = buf;
342 while (*pos != '\0') {
343 if (*pos == '\n') {
344 *pos = '\0';
345 break;
346 }
347 pos++;
348 }
349 if (buf[0] == '\0')
350 continue;
351
Hai Shalom74f70d42019-02-11 14:42:39 -0800352 context = NULL;
353 keyid = NULL;
354 while ((token = str_token(buf, " ", &context))) {
355 if (!os_strchr(token, '='))
356 break;
357 context2 = NULL;
358 name = str_token(token, "=", &context2);
Hai Shalom021b0b52019-04-10 11:17:58 -0700359 if (!name)
360 break;
Hai Shalom74f70d42019-02-11 14:42:39 -0800361 value = str_token(token, "", &context2);
362 if (!value)
363 value = "";
364 if (!os_strcmp(name, "keyid")) {
365 keyid = value;
Hai Shalomfdcde762020-04-02 11:19:20 -0700366 } else if (!os_strcmp(name, "wps")) {
367 wps = atoi(value);
Hai Shalom021b0b52019-04-10 11:17:58 -0700368 } else if (!os_strcmp(name, "vlanid")) {
369 vlan_id = atoi(value);
Hai Shalom74f70d42019-02-11 14:42:39 -0800370 } else {
371 wpa_printf(MSG_ERROR,
372 "Unrecognized '%s=%s' on line %d in '%s'",
373 name, value, line, fname);
374 ret = -1;
375 break;
376 }
377 }
378
379 if (ret == -1)
380 break;
381
382 if (!token)
383 token = "";
384 if (hwaddr_aton(token, addr)) {
Hai Shalomfdcde762020-04-02 11:19:20 -0700385 wpa_printf(MSG_ERROR,
386 "Invalid MAC address '%s' on line %d in '%s'",
387 token, line, fname);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700388 ret = -1;
389 break;
390 }
391
392 psk = os_zalloc(sizeof(*psk));
393 if (psk == NULL) {
394 wpa_printf(MSG_ERROR, "WPA PSK allocation failed");
395 ret = -1;
396 break;
397 }
Hai Shalom021b0b52019-04-10 11:17:58 -0700398 psk->vlan_id = vlan_id;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700399 if (is_zero_ether_addr(addr))
400 psk->group = 1;
401 else
402 os_memcpy(psk->addr, addr, ETH_ALEN);
403
Hai Shalom74f70d42019-02-11 14:42:39 -0800404 pos = str_token(buf, "", &context);
405 if (!pos) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700406 wpa_printf(MSG_ERROR, "No PSK on line %d in '%s'",
407 line, fname);
408 os_free(psk);
409 ret = -1;
410 break;
411 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700412
413 ok = 0;
414 len = os_strlen(pos);
Hai Shalomfdcde762020-04-02 11:19:20 -0700415 if (len == 2 * PMK_LEN &&
416 hexstr2bin(pos, psk->psk, PMK_LEN) == 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700417 ok = 1;
Hai Shalomfdcde762020-04-02 11:19:20 -0700418 else if (len >= 8 && len < 64 &&
419 pbkdf2_sha1(pos, ssid->ssid, ssid->ssid_len,
420 4096, psk->psk, PMK_LEN) == 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700421 ok = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700422 if (!ok) {
Hai Shalomfdcde762020-04-02 11:19:20 -0700423 wpa_printf(MSG_ERROR,
424 "Invalid PSK '%s' on line %d in '%s'",
425 pos, line, fname);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700426 os_free(psk);
427 ret = -1;
428 break;
429 }
430
Hai Shalom74f70d42019-02-11 14:42:39 -0800431 if (keyid) {
432 len = os_strlcpy(psk->keyid, keyid, sizeof(psk->keyid));
433 if ((size_t) len >= sizeof(psk->keyid)) {
434 wpa_printf(MSG_ERROR,
435 "PSK keyid too long on line %d in '%s'",
436 line, fname);
437 os_free(psk);
438 ret = -1;
439 break;
440 }
441 }
442
Hai Shalomfdcde762020-04-02 11:19:20 -0700443 psk->wps = wps;
444
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700445 psk->next = ssid->wpa_psk;
446 ssid->wpa_psk = psk;
447 }
448
449 fclose(f);
450
451 return ret;
452}
453
454
455static int hostapd_derive_psk(struct hostapd_ssid *ssid)
456{
457 ssid->wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
458 if (ssid->wpa_psk == NULL) {
459 wpa_printf(MSG_ERROR, "Unable to alloc space for PSK");
460 return -1;
461 }
462 wpa_hexdump_ascii(MSG_DEBUG, "SSID",
463 (u8 *) ssid->ssid, ssid->ssid_len);
464 wpa_hexdump_ascii_key(MSG_DEBUG, "PSK (ASCII passphrase)",
465 (u8 *) ssid->wpa_passphrase,
466 os_strlen(ssid->wpa_passphrase));
Sunil Ravia04bd252022-05-02 22:54:18 -0700467 if (pbkdf2_sha1(ssid->wpa_passphrase,
468 ssid->ssid, ssid->ssid_len,
469 4096, ssid->wpa_psk->psk, PMK_LEN) != 0) {
470 wpa_printf(MSG_ERROR, "Error in pbkdf2_sha1()");
471 return -1;
472 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700473 wpa_hexdump_key(MSG_DEBUG, "PSK (from passphrase)",
474 ssid->wpa_psk->psk, PMK_LEN);
475 return 0;
476}
477
478
Hai Shalomc3565922019-10-28 11:58:20 -0700479int hostapd_setup_sae_pt(struct hostapd_bss_config *conf)
480{
481#ifdef CONFIG_SAE
482 struct hostapd_ssid *ssid = &conf->ssid;
483 struct sae_password_entry *pw;
484
Sunil Ravi77d572f2023-01-17 23:58:31 +0000485 if ((conf->sae_pwe == SAE_PWE_HUNT_AND_PECK &&
486 !hostapd_sae_pw_id_in_use(conf) &&
Sunil Ravi89eba102022-09-13 21:04:37 -0700487 !wpa_key_mgmt_sae_ext_key(conf->wpa_key_mgmt) &&
Hai Shalom899fcc72020-10-19 14:38:18 -0700488 !hostapd_sae_pk_in_use(conf)) ||
Sunil Ravi77d572f2023-01-17 23:58:31 +0000489 conf->sae_pwe == SAE_PWE_FORCE_HUNT_AND_PECK ||
Hai Shalomfdcde762020-04-02 11:19:20 -0700490 !wpa_key_mgmt_sae(conf->wpa_key_mgmt))
Hai Shalomc3565922019-10-28 11:58:20 -0700491 return 0; /* PT not needed */
492
493 sae_deinit_pt(ssid->pt);
494 ssid->pt = NULL;
495 if (ssid->wpa_passphrase) {
496 ssid->pt = sae_derive_pt(conf->sae_groups, ssid->ssid,
497 ssid->ssid_len,
498 (const u8 *) ssid->wpa_passphrase,
499 os_strlen(ssid->wpa_passphrase),
500 NULL);
501 if (!ssid->pt)
502 return -1;
503 }
504
505 for (pw = conf->sae_passwords; pw; pw = pw->next) {
506 sae_deinit_pt(pw->pt);
507 pw->pt = sae_derive_pt(conf->sae_groups, ssid->ssid,
508 ssid->ssid_len,
509 (const u8 *) pw->password,
510 os_strlen(pw->password),
511 pw->identifier);
512 if (!pw->pt)
513 return -1;
514 }
515#endif /* CONFIG_SAE */
516
517 return 0;
518}
519
520
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700521int hostapd_setup_wpa_psk(struct hostapd_bss_config *conf)
522{
523 struct hostapd_ssid *ssid = &conf->ssid;
524
Hai Shalomc3565922019-10-28 11:58:20 -0700525 if (hostapd_setup_sae_pt(conf) < 0)
526 return -1;
527
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700528 if (ssid->wpa_passphrase != NULL) {
529 if (ssid->wpa_psk != NULL) {
530 wpa_printf(MSG_DEBUG, "Using pre-configured WPA PSK "
531 "instead of passphrase");
532 } else {
533 wpa_printf(MSG_DEBUG, "Deriving WPA PSK based on "
534 "passphrase");
535 if (hostapd_derive_psk(ssid) < 0)
536 return -1;
537 }
538 ssid->wpa_psk->group = 1;
539 }
540
Dmitry Shmidt29333592017-01-09 12:27:11 -0800541 return hostapd_config_read_wpa_psk(ssid->wpa_psk_file, &conf->ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700542}
543
544
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700545static void hostapd_config_free_radius(struct hostapd_radius_server *servers,
546 int num_servers)
547{
548 int i;
549
550 for (i = 0; i < num_servers; i++) {
551 os_free(servers[i].shared_secret);
552 }
553 os_free(servers);
554}
555
556
Dmitry Shmidt04949592012-07-19 12:16:46 -0700557struct hostapd_radius_attr *
558hostapd_config_get_radius_attr(struct hostapd_radius_attr *attr, u8 type)
559{
560 for (; attr; attr = attr->next) {
561 if (attr->type == type)
562 return attr;
563 }
564 return NULL;
565}
566
567
Hai Shalomc3565922019-10-28 11:58:20 -0700568struct hostapd_radius_attr * hostapd_parse_radius_attr(const char *value)
569{
570 const char *pos;
571 char syntax;
572 struct hostapd_radius_attr *attr;
573 size_t len;
574
575 attr = os_zalloc(sizeof(*attr));
576 if (!attr)
577 return NULL;
578
579 attr->type = atoi(value);
580
581 pos = os_strchr(value, ':');
582 if (!pos) {
583 attr->val = wpabuf_alloc(1);
584 if (!attr->val) {
585 os_free(attr);
586 return NULL;
587 }
588 wpabuf_put_u8(attr->val, 0);
589 return attr;
590 }
591
592 pos++;
593 if (pos[0] == '\0' || pos[1] != ':') {
594 os_free(attr);
595 return NULL;
596 }
597 syntax = *pos++;
598 pos++;
599
600 switch (syntax) {
601 case 's':
602 attr->val = wpabuf_alloc_copy(pos, os_strlen(pos));
603 break;
604 case 'x':
605 len = os_strlen(pos);
606 if (len & 1)
607 break;
608 len /= 2;
609 attr->val = wpabuf_alloc(len);
610 if (!attr->val)
611 break;
612 if (hexstr2bin(pos, wpabuf_put(attr->val, len), len) < 0) {
613 wpabuf_free(attr->val);
614 os_free(attr);
615 return NULL;
616 }
617 break;
618 case 'd':
619 attr->val = wpabuf_alloc(4);
620 if (attr->val)
621 wpabuf_put_be32(attr->val, atoi(pos));
622 break;
623 default:
624 os_free(attr);
625 return NULL;
626 }
627
628 if (!attr->val) {
629 os_free(attr);
630 return NULL;
631 }
632
633 return attr;
634}
635
636
637void hostapd_config_free_radius_attr(struct hostapd_radius_attr *attr)
Dmitry Shmidt04949592012-07-19 12:16:46 -0700638{
639 struct hostapd_radius_attr *prev;
640
641 while (attr) {
642 prev = attr;
643 attr = attr->next;
644 wpabuf_free(prev->val);
645 os_free(prev);
646 }
647}
648
649
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700650void hostapd_config_free_eap_user(struct hostapd_eap_user *user)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700651{
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700652 hostapd_config_free_radius_attr(user->accept_attr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700653 os_free(user->identity);
Dmitry Shmidtc2817022014-07-02 10:32:10 -0700654 bin_clear_free(user->password, user->password_len);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700655 bin_clear_free(user->salt, user->salt_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700656 os_free(user);
657}
658
659
Dmitry Shmidt29333592017-01-09 12:27:11 -0800660void hostapd_config_free_eap_users(struct hostapd_eap_user *user)
661{
662 struct hostapd_eap_user *prev_user;
663
664 while (user) {
665 prev_user = user;
666 user = user->next;
667 hostapd_config_free_eap_user(prev_user);
668 }
669}
670
671
Hai Shalomfdcde762020-04-02 11:19:20 -0700672#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700673static void hostapd_config_free_wep(struct hostapd_wep_keys *keys)
674{
675 int i;
676 for (i = 0; i < NUM_WEP_KEYS; i++) {
Dmitry Shmidtc2817022014-07-02 10:32:10 -0700677 bin_clear_free(keys->key[i], keys->len[i]);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700678 keys->key[i] = NULL;
679 }
680}
Hai Shalomfdcde762020-04-02 11:19:20 -0700681#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700682
683
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800684void hostapd_config_clear_wpa_psk(struct hostapd_wpa_psk **l)
685{
686 struct hostapd_wpa_psk *psk, *tmp;
687
688 for (psk = *l; psk;) {
689 tmp = psk;
690 psk = psk->next;
691 bin_clear_free(tmp, sizeof(*tmp));
692 }
693 *l = NULL;
694}
695
696
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800697static void hostapd_config_free_anqp_elem(struct hostapd_bss_config *conf)
698{
699 struct anqp_element *elem;
700
701 while ((elem = dl_list_first(&conf->anqp_elem, struct anqp_element,
702 list))) {
703 dl_list_del(&elem->list);
704 wpabuf_free(elem->payload);
705 os_free(elem);
706 }
707}
708
709
Dmitry Shmidt29333592017-01-09 12:27:11 -0800710static void hostapd_config_free_fils_realms(struct hostapd_bss_config *conf)
711{
712#ifdef CONFIG_FILS
713 struct fils_realm *realm;
714
715 while ((realm = dl_list_first(&conf->fils_realms, struct fils_realm,
716 list))) {
717 dl_list_del(&realm->list);
718 os_free(realm);
719 }
720#endif /* CONFIG_FILS */
721}
722
723
Roshan Pius3a1667e2018-07-03 15:17:14 -0700724static void hostapd_config_free_sae_passwords(struct hostapd_bss_config *conf)
725{
726 struct sae_password_entry *pw, *tmp;
727
728 pw = conf->sae_passwords;
729 conf->sae_passwords = NULL;
730 while (pw) {
731 tmp = pw;
732 pw = pw->next;
733 str_clear_free(tmp->password);
734 os_free(tmp->identifier);
Hai Shalomc3565922019-10-28 11:58:20 -0700735#ifdef CONFIG_SAE
736 sae_deinit_pt(tmp->pt);
737#endif /* CONFIG_SAE */
Hai Shalom899fcc72020-10-19 14:38:18 -0700738#ifdef CONFIG_SAE_PK
739 sae_deinit_pk(tmp->pk);
740#endif /* CONFIG_SAE_PK */
Roshan Pius3a1667e2018-07-03 15:17:14 -0700741 os_free(tmp);
742 }
743}
744
745
Hai Shalom81f62d82019-07-22 12:10:00 -0700746#ifdef CONFIG_DPP2
747static void hostapd_dpp_controller_conf_free(struct dpp_controller_conf *conf)
748{
749 struct dpp_controller_conf *prev;
750
751 while (conf) {
752 prev = conf;
753 conf = conf->next;
754 os_free(prev);
755 }
756}
757#endif /* CONFIG_DPP2 */
758
759
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800760void hostapd_config_free_bss(struct hostapd_bss_config *conf)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700761{
Hai Shalom81f62d82019-07-22 12:10:00 -0700762#if defined(CONFIG_WPS) || defined(CONFIG_HS20)
763 size_t i;
764#endif
765
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700766 if (conf == NULL)
767 return;
768
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800769 hostapd_config_clear_wpa_psk(&conf->ssid.wpa_psk);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700770
Dmitry Shmidtc2817022014-07-02 10:32:10 -0700771 str_clear_free(conf->ssid.wpa_passphrase);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700772 os_free(conf->ssid.wpa_psk_file);
Hai Shalomfdcde762020-04-02 11:19:20 -0700773#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700774 hostapd_config_free_wep(&conf->ssid.wep);
Hai Shalomfdcde762020-04-02 11:19:20 -0700775#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700776#ifdef CONFIG_FULL_DYNAMIC_VLAN
777 os_free(conf->ssid.vlan_tagged_interface);
778#endif /* CONFIG_FULL_DYNAMIC_VLAN */
Hai Shalomc3565922019-10-28 11:58:20 -0700779#ifdef CONFIG_SAE
780 sae_deinit_pt(conf->ssid.pt);
781#endif /* CONFIG_SAE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700782
Dmitry Shmidt29333592017-01-09 12:27:11 -0800783 hostapd_config_free_eap_users(conf->eap_user);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800784 os_free(conf->eap_user_sqlite);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700785
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700786 os_free(conf->eap_req_id_text);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800787 os_free(conf->erp_domain);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700788 os_free(conf->accept_mac);
789 os_free(conf->deny_mac);
790 os_free(conf->nas_identifier);
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800791 if (conf->radius) {
792 hostapd_config_free_radius(conf->radius->auth_servers,
793 conf->radius->num_auth_servers);
794 hostapd_config_free_radius(conf->radius->acct_servers,
795 conf->radius->num_acct_servers);
Hai Shaloma20dcd72022-02-04 13:43:00 -0800796 os_free(conf->radius->force_client_dev);
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800797 }
Dmitry Shmidt04949592012-07-19 12:16:46 -0700798 hostapd_config_free_radius_attr(conf->radius_auth_req_attr);
799 hostapd_config_free_radius_attr(conf->radius_acct_req_attr);
Hai Shalomc3565922019-10-28 11:58:20 -0700800 os_free(conf->radius_req_attr_sqlite);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700801 os_free(conf->rsn_preauth_interfaces);
802 os_free(conf->ctrl_interface);
Sunil Ravi77d572f2023-01-17 23:58:31 +0000803 os_free(conf->config_id);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700804 os_free(conf->ca_cert);
805 os_free(conf->server_cert);
Hai Shalom81f62d82019-07-22 12:10:00 -0700806 os_free(conf->server_cert2);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700807 os_free(conf->private_key);
Hai Shalom81f62d82019-07-22 12:10:00 -0700808 os_free(conf->private_key2);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700809 os_free(conf->private_key_passwd);
Hai Shalom81f62d82019-07-22 12:10:00 -0700810 os_free(conf->private_key_passwd2);
Hai Shalom021b0b52019-04-10 11:17:58 -0700811 os_free(conf->check_cert_subject);
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700812 os_free(conf->ocsp_stapling_response);
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -0800813 os_free(conf->ocsp_stapling_response_multi);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700814 os_free(conf->dh_file);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800815 os_free(conf->openssl_ciphers);
Hai Shalom74f70d42019-02-11 14:42:39 -0800816 os_free(conf->openssl_ecdh_curves);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700817 os_free(conf->pac_opaque_encr_key);
818 os_free(conf->eap_fast_a_id);
819 os_free(conf->eap_fast_a_id_info);
820 os_free(conf->eap_sim_db);
Sunil Ravia04bd252022-05-02 22:54:18 -0700821 os_free(conf->imsi_privacy_key);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700822 os_free(conf->radius_server_clients);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700823 os_free(conf->radius);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700824 os_free(conf->radius_das_shared_secret);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700825 hostapd_config_free_vlan(conf);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800826 os_free(conf->time_zone);
827
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800828#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700829 {
830 struct ft_remote_r0kh *r0kh, *r0kh_prev;
831 struct ft_remote_r1kh *r1kh, *r1kh_prev;
832
833 r0kh = conf->r0kh_list;
834 conf->r0kh_list = NULL;
835 while (r0kh) {
836 r0kh_prev = r0kh;
837 r0kh = r0kh->next;
838 os_free(r0kh_prev);
839 }
840
841 r1kh = conf->r1kh_list;
842 conf->r1kh_list = NULL;
843 while (r1kh) {
844 r1kh_prev = r1kh;
845 r1kh = r1kh->next;
846 os_free(r1kh_prev);
847 }
848 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800849#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700850
851#ifdef CONFIG_WPS
852 os_free(conf->wps_pin_requests);
853 os_free(conf->device_name);
854 os_free(conf->manufacturer);
855 os_free(conf->model_name);
856 os_free(conf->model_number);
857 os_free(conf->serial_number);
858 os_free(conf->config_methods);
859 os_free(conf->ap_pin);
860 os_free(conf->extra_cred);
861 os_free(conf->ap_settings);
Hai Shalom021b0b52019-04-10 11:17:58 -0700862 hostapd_config_clear_wpa_psk(&conf->multi_ap_backhaul_ssid.wpa_psk);
863 str_clear_free(conf->multi_ap_backhaul_ssid.wpa_passphrase);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700864 os_free(conf->upnp_iface);
865 os_free(conf->friendly_name);
866 os_free(conf->manufacturer_url);
867 os_free(conf->model_description);
868 os_free(conf->model_url);
869 os_free(conf->upc);
Hai Shalom81f62d82019-07-22 12:10:00 -0700870 for (i = 0; i < MAX_WPS_VENDOR_EXTENSIONS; i++)
871 wpabuf_free(conf->wps_vendor_ext[i]);
Hai Shalomfdcde762020-04-02 11:19:20 -0700872 wpabuf_free(conf->wps_application_ext);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700873 wpabuf_free(conf->wps_nfc_dh_pubkey);
874 wpabuf_free(conf->wps_nfc_dh_privkey);
875 wpabuf_free(conf->wps_nfc_dev_pw);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700876#endif /* CONFIG_WPS */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800877
878 os_free(conf->roaming_consortium);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700879 os_free(conf->venue_name);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700880 os_free(conf->venue_url);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700881 os_free(conf->nai_realm_data);
882 os_free(conf->network_auth_type);
883 os_free(conf->anqp_3gpp_cell_net);
884 os_free(conf->domain_name);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800885 hostapd_config_free_anqp_elem(conf);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800886
887#ifdef CONFIG_RADIUS_TEST
888 os_free(conf->dump_msk_file);
889#endif /* CONFIG_RADIUS_TEST */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700890
891#ifdef CONFIG_HS20
892 os_free(conf->hs20_oper_friendly_name);
893 os_free(conf->hs20_wan_metrics);
894 os_free(conf->hs20_connection_capability);
895 os_free(conf->hs20_operating_class);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800896 os_free(conf->hs20_icons);
897 if (conf->hs20_osu_providers) {
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800898 for (i = 0; i < conf->hs20_osu_providers_count; i++) {
899 struct hs20_osu_provider *p;
900 size_t j;
901 p = &conf->hs20_osu_providers[i];
902 os_free(p->friendly_name);
903 os_free(p->server_uri);
904 os_free(p->method_list);
905 for (j = 0; j < p->icons_count; j++)
906 os_free(p->icons[j]);
907 os_free(p->icons);
908 os_free(p->osu_nai);
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800909 os_free(p->osu_nai2);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800910 os_free(p->service_desc);
911 }
912 os_free(conf->hs20_osu_providers);
913 }
Roshan Pius3a1667e2018-07-03 15:17:14 -0700914 if (conf->hs20_operator_icon) {
Roshan Pius3a1667e2018-07-03 15:17:14 -0700915 for (i = 0; i < conf->hs20_operator_icon_count; i++)
916 os_free(conf->hs20_operator_icon[i]);
917 os_free(conf->hs20_operator_icon);
918 }
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800919 os_free(conf->subscr_remediation_url);
Hai Shalom74f70d42019-02-11 14:42:39 -0800920 os_free(conf->hs20_sim_provisioning_url);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700921 os_free(conf->t_c_filename);
922 os_free(conf->t_c_server_url);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700923#endif /* CONFIG_HS20 */
924
925 wpabuf_free(conf->vendor_elements);
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700926 wpabuf_free(conf->assocresp_elements);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800927
928 os_free(conf->sae_groups);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700929#ifdef CONFIG_OWE
930 os_free(conf->owe_groups);
931#endif /* CONFIG_OWE */
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700932
Dmitry Shmidt0207e232014-09-03 14:58:37 -0700933 os_free(conf->wowlan_triggers);
934
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700935 os_free(conf->server_id);
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800936
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800937#ifdef CONFIG_TESTING_OPTIONS
938 wpabuf_free(conf->own_ie_override);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700939 wpabuf_free(conf->sae_commit_override);
Hai Shalomfdcde762020-04-02 11:19:20 -0700940 wpabuf_free(conf->rsne_override_eapol);
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800941 wpabuf_free(conf->rsnxe_override_eapol);
Hai Shalomfdcde762020-04-02 11:19:20 -0700942 wpabuf_free(conf->rsne_override_ft);
943 wpabuf_free(conf->rsnxe_override_ft);
944 wpabuf_free(conf->gtk_rsc_override);
945 wpabuf_free(conf->igtk_rsc_override);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800946#endif /* CONFIG_TESTING_OPTIONS */
947
948 os_free(conf->no_probe_resp_if_seen_on);
949 os_free(conf->no_auth_if_seen_on);
950
Dmitry Shmidt29333592017-01-09 12:27:11 -0800951 hostapd_config_free_fils_realms(conf);
952
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700953#ifdef CONFIG_DPP
Hai Shalomc3565922019-10-28 11:58:20 -0700954 os_free(conf->dpp_name);
955 os_free(conf->dpp_mud_url);
Sunil Ravi89eba102022-09-13 21:04:37 -0700956 os_free(conf->dpp_extra_conf_req_name);
957 os_free(conf->dpp_extra_conf_req_value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700958 os_free(conf->dpp_connector);
959 wpabuf_free(conf->dpp_netaccesskey);
960 wpabuf_free(conf->dpp_csign);
Hai Shalom81f62d82019-07-22 12:10:00 -0700961#ifdef CONFIG_DPP2
962 hostapd_dpp_controller_conf_free(conf->dpp_controller);
963#endif /* CONFIG_DPP2 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700964#endif /* CONFIG_DPP */
965
Roshan Pius3a1667e2018-07-03 15:17:14 -0700966 hostapd_config_free_sae_passwords(conf);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700967
Hai Shalom81f62d82019-07-22 12:10:00 -0700968#ifdef CONFIG_AIRTIME_POLICY
969 {
970 struct airtime_sta_weight *wt, *wt_prev;
971
972 wt = conf->airtime_weight_list;
973 conf->airtime_weight_list = NULL;
974 while (wt) {
975 wt_prev = wt;
976 wt = wt->next;
977 os_free(wt_prev);
978 }
979 }
980#endif /* CONFIG_AIRTIME_POLICY */
981
Hai Shalom60840252021-02-19 19:02:11 -0800982#ifdef CONFIG_PASN
983 os_free(conf->pasn_groups);
984#endif /* CONFIG_PASN */
985
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800986 os_free(conf);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700987}
988
989
990/**
991 * hostapd_config_free - Free hostapd configuration
992 * @conf: Configuration data from hostapd_config_read().
993 */
994void hostapd_config_free(struct hostapd_config *conf)
995{
996 size_t i;
997
998 if (conf == NULL)
999 return;
1000
1001 for (i = 0; i < conf->num_bss; i++)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001002 hostapd_config_free_bss(conf->bss[i]);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001003 os_free(conf->bss);
1004 os_free(conf->supported_rates);
1005 os_free(conf->basic_rates);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07001006 os_free(conf->acs_ch_list.range);
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001007 os_free(conf->acs_freq_list.range);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001008 os_free(conf->driver_params);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001009#ifdef CONFIG_ACS
1010 os_free(conf->acs_chan_bias);
1011#endif /* CONFIG_ACS */
Dmitry Shmidt849734c2016-05-27 09:59:01 -07001012 wpabuf_free(conf->lci);
1013 wpabuf_free(conf->civic);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001014
1015 os_free(conf);
1016}
1017
1018
1019/**
1020 * hostapd_maclist_found - Find a MAC address from a list
1021 * @list: MAC address list
1022 * @num_entries: Number of addresses in the list
1023 * @addr: Address to search for
1024 * @vlan_id: Buffer for returning VLAN ID or %NULL if not needed
1025 * Returns: 1 if address is in the list or 0 if not.
1026 *
1027 * Perform a binary search for given MAC address from a pre-sorted list.
1028 */
1029int hostapd_maclist_found(struct mac_acl_entry *list, int num_entries,
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001030 const u8 *addr, struct vlan_description *vlan_id)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001031{
1032 int start, end, middle, res;
1033
1034 start = 0;
1035 end = num_entries - 1;
1036
1037 while (start <= end) {
1038 middle = (start + end) / 2;
1039 res = os_memcmp(list[middle].addr, addr, ETH_ALEN);
1040 if (res == 0) {
1041 if (vlan_id)
1042 *vlan_id = list[middle].vlan_id;
1043 return 1;
1044 }
1045 if (res < 0)
1046 start = middle + 1;
1047 else
1048 end = middle - 1;
1049 }
1050
1051 return 0;
1052}
1053
1054
1055int hostapd_rate_found(int *list, int rate)
1056{
1057 int i;
1058
1059 if (list == NULL)
1060 return 0;
1061
1062 for (i = 0; list[i] >= 0; i++)
1063 if (list[i] == rate)
1064 return 1;
1065
1066 return 0;
1067}
1068
1069
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001070int hostapd_vlan_valid(struct hostapd_vlan *vlan,
1071 struct vlan_description *vlan_desc)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001072{
1073 struct hostapd_vlan *v = vlan;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001074 int i;
1075
1076 if (!vlan_desc->notempty || vlan_desc->untagged < 0 ||
1077 vlan_desc->untagged > MAX_VLAN_ID)
1078 return 0;
1079 for (i = 0; i < MAX_NUM_TAGGED_VLAN; i++) {
1080 if (vlan_desc->tagged[i] < 0 ||
1081 vlan_desc->tagged[i] > MAX_VLAN_ID)
1082 return 0;
1083 }
1084 if (!vlan_desc->untagged && !vlan_desc->tagged[0])
1085 return 0;
1086
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001087 while (v) {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001088 if (!vlan_compare(&v->vlan_desc, vlan_desc) ||
1089 v->vlan_id == VLAN_ID_WILDCARD)
Dmitry Shmidt34af3062013-07-11 10:46:32 -07001090 return 1;
1091 v = v->next;
1092 }
1093 return 0;
1094}
1095
1096
1097const char * hostapd_get_vlan_id_ifname(struct hostapd_vlan *vlan, int vlan_id)
1098{
1099 struct hostapd_vlan *v = vlan;
1100 while (v) {
1101 if (v->vlan_id == vlan_id)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001102 return v->ifname;
1103 v = v->next;
1104 }
1105 return NULL;
1106}
1107
1108
1109const u8 * hostapd_get_psk(const struct hostapd_bss_config *conf,
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001110 const u8 *addr, const u8 *p2p_dev_addr,
Hai Shalom021b0b52019-04-10 11:17:58 -07001111 const u8 *prev_psk, int *vlan_id)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001112{
1113 struct hostapd_wpa_psk *psk;
1114 int next_ok = prev_psk == NULL;
1115
Hai Shalom021b0b52019-04-10 11:17:58 -07001116 if (vlan_id)
1117 *vlan_id = 0;
1118
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001119 if (p2p_dev_addr && !is_zero_ether_addr(p2p_dev_addr)) {
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001120 wpa_printf(MSG_DEBUG, "Searching a PSK for " MACSTR
1121 " p2p_dev_addr=" MACSTR " prev_psk=%p",
1122 MAC2STR(addr), MAC2STR(p2p_dev_addr), prev_psk);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001123 addr = NULL; /* Use P2P Device Address for matching */
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001124 } else {
1125 wpa_printf(MSG_DEBUG, "Searching a PSK for " MACSTR
1126 " prev_psk=%p",
1127 MAC2STR(addr), prev_psk);
1128 }
1129
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001130 for (psk = conf->ssid.wpa_psk; psk != NULL; psk = psk->next) {
1131 if (next_ok &&
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001132 (psk->group ||
1133 (addr && os_memcmp(psk->addr, addr, ETH_ALEN) == 0) ||
1134 (!addr && p2p_dev_addr &&
1135 os_memcmp(psk->p2p_dev_addr, p2p_dev_addr, ETH_ALEN) ==
Hai Shalom021b0b52019-04-10 11:17:58 -07001136 0))) {
1137 if (vlan_id)
1138 *vlan_id = psk->vlan_id;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001139 return psk->psk;
Hai Shalom021b0b52019-04-10 11:17:58 -07001140 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001141
1142 if (psk->psk == prev_psk)
1143 next_ok = 1;
1144 }
1145
1146 return NULL;
1147}
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001148
1149
Hai Shalom899fcc72020-10-19 14:38:18 -07001150#ifdef CONFIG_SAE_PK
1151static bool hostapd_sae_pk_password_without_pk(struct hostapd_bss_config *bss)
1152{
1153 struct sae_password_entry *pw;
1154 bool res = false;
1155
1156 if (bss->ssid.wpa_passphrase &&
1157#ifdef CONFIG_TESTING_OPTIONS
1158 !bss->sae_pk_password_check_skip &&
1159#endif /* CONFIG_TESTING_OPTIONS */
1160 sae_pk_valid_password(bss->ssid.wpa_passphrase))
1161 res = true;
1162
1163 for (pw = bss->sae_passwords; pw; pw = pw->next) {
1164 if (!pw->pk &&
1165#ifdef CONFIG_TESTING_OPTIONS
1166 !bss->sae_pk_password_check_skip &&
1167#endif /* CONFIG_TESTING_OPTIONS */
1168 sae_pk_valid_password(pw->password))
1169 return true;
1170
1171 if (bss->ssid.wpa_passphrase && res && pw->pk &&
1172 os_strcmp(bss->ssid.wpa_passphrase, pw->password) == 0)
1173 res = false;
1174 }
1175
1176 return res;
1177}
1178#endif /* CONFIG_SAE_PK */
1179
1180
Hai Shalom60840252021-02-19 19:02:11 -08001181static bool hostapd_config_check_bss_6g(struct hostapd_bss_config *bss)
1182{
1183 if (bss->wpa != WPA_PROTO_RSN) {
1184 wpa_printf(MSG_ERROR,
1185 "Pre-RSNA security methods are not allowed in 6 GHz");
1186 return false;
1187 }
1188
1189 if (bss->ieee80211w != MGMT_FRAME_PROTECTION_REQUIRED) {
1190 wpa_printf(MSG_ERROR,
1191 "Management frame protection is required in 6 GHz");
1192 return false;
1193 }
1194
1195 if (bss->wpa_key_mgmt & (WPA_KEY_MGMT_PSK |
1196 WPA_KEY_MGMT_FT_PSK |
1197 WPA_KEY_MGMT_PSK_SHA256)) {
1198 wpa_printf(MSG_ERROR, "Invalid AKM suite for 6 GHz");
1199 return false;
1200 }
1201
1202 if (bss->rsn_pairwise & (WPA_CIPHER_WEP40 |
1203 WPA_CIPHER_WEP104 |
1204 WPA_CIPHER_TKIP)) {
1205 wpa_printf(MSG_ERROR,
1206 "Invalid pairwise cipher suite for 6 GHz");
1207 return false;
1208 }
1209
1210 if (bss->wpa_group & (WPA_CIPHER_WEP40 |
1211 WPA_CIPHER_WEP104 |
1212 WPA_CIPHER_TKIP)) {
1213 wpa_printf(MSG_ERROR, "Invalid group cipher suite for 6 GHz");
1214 return false;
1215 }
1216
Sunil Ravi77d572f2023-01-17 23:58:31 +00001217#ifdef CONFIG_SAE
1218 if (wpa_key_mgmt_sae(bss->wpa_key_mgmt) &&
1219 bss->sae_pwe == SAE_PWE_HUNT_AND_PECK) {
1220 wpa_printf(MSG_INFO, "SAE: Enabling SAE H2E on 6 GHz");
1221 bss->sae_pwe = SAE_PWE_BOTH;
1222 }
1223#endif /* CONFIG_SAE */
1224
Hai Shalom60840252021-02-19 19:02:11 -08001225 return true;
1226}
1227
1228
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001229static int hostapd_config_check_bss(struct hostapd_bss_config *bss,
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001230 struct hostapd_config *conf,
1231 int full_config)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001232{
Hai Shalom60840252021-02-19 19:02:11 -08001233 if (full_config && is_6ghz_op_class(conf->op_class) &&
1234 !hostapd_config_check_bss_6g(bss))
1235 return -1;
1236
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001237 if (full_config && bss->ieee802_1x && !bss->eap_server &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001238 !bss->radius->auth_servers) {
1239 wpa_printf(MSG_ERROR, "Invalid IEEE 802.1X configuration (no "
1240 "EAP authenticator configured).");
1241 return -1;
1242 }
1243
Hai Shalomfdcde762020-04-02 11:19:20 -07001244#ifdef CONFIG_WEP
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001245 if (bss->wpa) {
1246 int wep, i;
1247
1248 wep = bss->default_wep_key_len > 0 ||
1249 bss->individual_wep_key_len > 0;
1250 for (i = 0; i < NUM_WEP_KEYS; i++) {
1251 if (bss->ssid.wep.keys_set) {
1252 wep = 1;
1253 break;
1254 }
1255 }
1256
1257 if (wep) {
1258 wpa_printf(MSG_ERROR, "WEP configuration in a WPA network is not supported");
1259 return -1;
1260 }
1261 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001262#endif /* CONFIG_WEP */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001263
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001264 if (full_config && bss->wpa &&
1265 bss->wpa_psk_radius != PSK_RADIUS_IGNORED &&
Sunil Ravia04bd252022-05-02 22:54:18 -07001266 bss->wpa_psk_radius != PSK_RADIUS_DURING_4WAY_HS &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001267 bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH) {
1268 wpa_printf(MSG_ERROR, "WPA-PSK using RADIUS enabled, but no "
1269 "RADIUS checking (macaddr_acl=2) enabled.");
1270 return -1;
1271 }
1272
Sunil Ravia04bd252022-05-02 22:54:18 -07001273 if (full_config && bss->wpa &&
1274 wpa_key_mgmt_wpa_psk_no_sae(bss->wpa_key_mgmt) &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001275 bss->ssid.wpa_psk == NULL && bss->ssid.wpa_passphrase == NULL &&
1276 bss->ssid.wpa_psk_file == NULL &&
Sunil Ravia04bd252022-05-02 22:54:18 -07001277 bss->wpa_psk_radius != PSK_RADIUS_DURING_4WAY_HS &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001278 (bss->wpa_psk_radius != PSK_RADIUS_REQUIRED ||
1279 bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH)) {
1280 wpa_printf(MSG_ERROR, "WPA-PSK enabled, but PSK or passphrase "
1281 "is not configured.");
1282 return -1;
1283 }
1284
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001285 if (full_config && !is_zero_ether_addr(bss->bssid)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001286 size_t i;
1287
1288 for (i = 0; i < conf->num_bss; i++) {
1289 if (conf->bss[i] != bss &&
1290 (hostapd_mac_comp(conf->bss[i]->bssid,
1291 bss->bssid) == 0)) {
1292 wpa_printf(MSG_ERROR, "Duplicate BSSID " MACSTR
1293 " on interface '%s' and '%s'.",
1294 MAC2STR(bss->bssid),
1295 conf->bss[i]->iface, bss->iface);
1296 return -1;
1297 }
1298 }
1299 }
1300
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001301#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001302 if (full_config && wpa_key_mgmt_ft(bss->wpa_key_mgmt) &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001303 (bss->nas_identifier == NULL ||
1304 os_strlen(bss->nas_identifier) < 1 ||
1305 os_strlen(bss->nas_identifier) > FT_R0KH_ID_MAX_LEN)) {
1306 wpa_printf(MSG_ERROR, "FT (IEEE 802.11r) requires "
1307 "nas_identifier to be configured as a 1..48 octet "
1308 "string");
1309 return -1;
1310 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001311#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001312
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001313 if (full_config && conf->ieee80211n &&
1314 conf->hw_mode == HOSTAPD_MODE_IEEE80211B) {
Hai Shalom60840252021-02-19 19:02:11 -08001315 bss->disable_11n = true;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001316 wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) in 11b mode is not "
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001317 "allowed, disabling HT capabilities");
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001318 }
1319
Hai Shalomfdcde762020-04-02 11:19:20 -07001320#ifdef CONFIG_WEP
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001321 if (full_config && conf->ieee80211n &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001322 bss->ssid.security_policy == SECURITY_STATIC_WEP) {
Hai Shalom60840252021-02-19 19:02:11 -08001323 bss->disable_11n = true;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001324 wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) with WEP is not "
1325 "allowed, disabling HT capabilities");
1326 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001327#endif /* CONFIG_WEP */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001328
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001329 if (full_config && conf->ieee80211n && bss->wpa &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001330 !(bss->wpa_pairwise & WPA_CIPHER_CCMP) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001331 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
1332 WPA_CIPHER_CCMP_256 | WPA_CIPHER_GCMP_256)))
1333 {
Hai Shalom60840252021-02-19 19:02:11 -08001334 bss->disable_11n = true;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001335 wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) with WPA/WPA2 "
1336 "requires CCMP/GCMP to be enabled, disabling HT "
1337 "capabilities");
1338 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001339
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07001340#ifdef CONFIG_IEEE80211AC
Hai Shalomfdcde762020-04-02 11:19:20 -07001341#ifdef CONFIG_WEP
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07001342 if (full_config && conf->ieee80211ac &&
1343 bss->ssid.security_policy == SECURITY_STATIC_WEP) {
Hai Shalom60840252021-02-19 19:02:11 -08001344 bss->disable_11ac = true;
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07001345 wpa_printf(MSG_ERROR,
1346 "VHT (IEEE 802.11ac) with WEP is not allowed, disabling VHT capabilities");
1347 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001348#endif /* CONFIG_WEP */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001349
1350 if (full_config && conf->ieee80211ac && bss->wpa &&
1351 !(bss->wpa_pairwise & WPA_CIPHER_CCMP) &&
1352 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
1353 WPA_CIPHER_CCMP_256 | WPA_CIPHER_GCMP_256)))
1354 {
Hai Shalom60840252021-02-19 19:02:11 -08001355 bss->disable_11ac = true;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001356 wpa_printf(MSG_ERROR,
1357 "VHT (IEEE 802.11ac) with WPA/WPA2 requires CCMP/GCMP to be enabled, disabling VHT capabilities");
1358 }
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07001359#endif /* CONFIG_IEEE80211AC */
1360
Hai Shalom60840252021-02-19 19:02:11 -08001361#ifdef CONFIG_IEEE80211AX
1362#ifdef CONFIG_WEP
1363 if (full_config && conf->ieee80211ax &&
1364 bss->ssid.security_policy == SECURITY_STATIC_WEP) {
1365 bss->disable_11ax = true;
1366 wpa_printf(MSG_ERROR,
1367 "HE (IEEE 802.11ax) with WEP is not allowed, disabling HE capabilities");
1368 }
1369#endif /* CONFIG_WEP */
1370
1371 if (full_config && conf->ieee80211ax && bss->wpa &&
1372 !(bss->wpa_pairwise & WPA_CIPHER_CCMP) &&
1373 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
1374 WPA_CIPHER_CCMP_256 | WPA_CIPHER_GCMP_256)))
1375 {
1376 bss->disable_11ax = true;
1377 wpa_printf(MSG_ERROR,
1378 "HE (IEEE 802.11ax) with WPA/WPA2 requires CCMP/GCMP to be enabled, disabling HE capabilities");
1379 }
1380#endif /* CONFIG_IEEE80211AX */
1381
Dmitry Shmidt15907092014-03-25 10:42:57 -07001382#ifdef CONFIG_WPS
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001383 if (full_config && bss->wps_state && bss->ignore_broadcast_ssid) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001384 wpa_printf(MSG_INFO, "WPS: ignore_broadcast_ssid "
1385 "configuration forced WPS to be disabled");
1386 bss->wps_state = 0;
1387 }
1388
Hai Shalomfdcde762020-04-02 11:19:20 -07001389#ifdef CONFIG_WEP
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001390 if (full_config && bss->wps_state &&
1391 bss->ssid.wep.keys_set && bss->wpa == 0) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001392 wpa_printf(MSG_INFO, "WPS: WEP configuration forced WPS to be "
1393 "disabled");
1394 bss->wps_state = 0;
1395 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001396#endif /* CONFIG_WEP */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001397
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001398 if (full_config && bss->wps_state && bss->wpa &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001399 (!(bss->wpa & 2) ||
Roshan Pius3a1667e2018-07-03 15:17:14 -07001400 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
1401 WPA_CIPHER_CCMP_256 |
1402 WPA_CIPHER_GCMP_256)))) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001403 wpa_printf(MSG_INFO, "WPS: WPA/TKIP configuration without "
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07001404 "WPA2/CCMP/GCMP forced WPS to be disabled");
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001405 bss->wps_state = 0;
1406 }
Dmitry Shmidt15907092014-03-25 10:42:57 -07001407#endif /* CONFIG_WPS */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001408
1409#ifdef CONFIG_HS20
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001410 if (full_config && bss->hs20 &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001411 (!(bss->wpa & 2) ||
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001412 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
1413 WPA_CIPHER_CCMP_256 |
1414 WPA_CIPHER_GCMP_256)))) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001415 wpa_printf(MSG_ERROR, "HS 2.0: WPA2-Enterprise/CCMP "
1416 "configuration is required for Hotspot 2.0 "
1417 "functionality");
1418 return -1;
1419 }
1420#endif /* CONFIG_HS20 */
1421
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001422#ifdef CONFIG_MBO
1423 if (full_config && bss->mbo_enabled && (bss->wpa & 2) &&
1424 bss->ieee80211w == NO_MGMT_FRAME_PROTECTION) {
1425 wpa_printf(MSG_ERROR,
1426 "MBO: PMF needs to be enabled whenever using WPA2 with MBO");
1427 return -1;
1428 }
1429#endif /* CONFIG_MBO */
1430
Hai Shalom74f70d42019-02-11 14:42:39 -08001431#ifdef CONFIG_OCV
1432 if (full_config && bss->ieee80211w == NO_MGMT_FRAME_PROTECTION &&
1433 bss->ocv) {
1434 wpa_printf(MSG_ERROR,
1435 "OCV: PMF needs to be enabled whenever using OCV");
1436 return -1;
1437 }
1438#endif /* CONFIG_OCV */
1439
Hai Shalom899fcc72020-10-19 14:38:18 -07001440#ifdef CONFIG_SAE_PK
1441 if (full_config && hostapd_sae_pk_in_use(bss) &&
1442 hostapd_sae_pk_password_without_pk(bss)) {
1443 wpa_printf(MSG_ERROR,
1444 "SAE-PK: SAE password uses SAE-PK style, but does not have PK configured");
1445 return -1;
1446 }
1447#endif /* CONFIG_SAE_PK */
1448
Hai Shaloma20dcd72022-02-04 13:43:00 -08001449#ifdef CONFIG_FILS
Sunil Ravia04bd252022-05-02 22:54:18 -07001450 if (full_config && bss->fils_discovery_max_int &&
Sunil Ravi036cec52023-03-29 11:35:17 -07001451 (!conf->ieee80211ax || bss->disable_11ax)) {
1452 wpa_printf(MSG_ERROR,
1453 "Currently IEEE 802.11ax support is mandatory to enable FILS discovery transmission.");
1454 return -1;
1455 }
1456
1457 if (full_config && bss->fils_discovery_max_int &&
Hai Shaloma20dcd72022-02-04 13:43:00 -08001458 bss->unsol_bcast_probe_resp_interval) {
1459 wpa_printf(MSG_ERROR,
1460 "Cannot enable both FILS discovery and unsolicited broadcast Probe Response at the same time");
1461 return -1;
1462 }
1463#endif /* CONFIG_FILS */
1464
Sunil Ravia04bd252022-05-02 22:54:18 -07001465#ifdef CONFIG_IEEE80211BE
1466 if (full_config && !bss->disable_11be && bss->disable_11ax) {
1467 bss->disable_11be = true;
1468 wpa_printf(MSG_INFO,
1469 "Disabling IEEE 802.11be as IEEE 802.11ax is disabled for this BSS");
1470 }
1471#endif /* CONFIG_IEEE80211BE */
1472
Sunil Ravi77d572f2023-01-17 23:58:31 +00001473 if (full_config && bss->ignore_broadcast_ssid && conf->mbssid) {
1474 wpa_printf(MSG_ERROR,
1475 "Hidden SSID is not suppored when MBSSID is enabled");
1476 return -1;
1477 }
1478
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001479 return 0;
1480}
1481
1482
Dmitry Shmidt05df46a2015-05-19 11:02:01 -07001483static int hostapd_config_check_cw(struct hostapd_config *conf, int queue)
1484{
1485 int tx_cwmin = conf->tx_queue[queue].cwmin;
1486 int tx_cwmax = conf->tx_queue[queue].cwmax;
1487 int ac_cwmin = conf->wmm_ac_params[queue].cwmin;
1488 int ac_cwmax = conf->wmm_ac_params[queue].cwmax;
1489
1490 if (tx_cwmin > tx_cwmax) {
1491 wpa_printf(MSG_ERROR,
1492 "Invalid TX queue cwMin/cwMax values. cwMin(%d) greater than cwMax(%d)",
1493 tx_cwmin, tx_cwmax);
1494 return -1;
1495 }
1496 if (ac_cwmin > ac_cwmax) {
1497 wpa_printf(MSG_ERROR,
1498 "Invalid WMM AC cwMin/cwMax values. cwMin(%d) greater than cwMax(%d)",
1499 ac_cwmin, ac_cwmax);
1500 return -1;
1501 }
1502 return 0;
1503}
1504
1505
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001506int hostapd_config_check(struct hostapd_config *conf, int full_config)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001507{
1508 size_t i;
1509
Sunil Ravia04bd252022-05-02 22:54:18 -07001510 if (full_config && is_6ghz_op_class(conf->op_class) &&
1511 !conf->hw_mode_set) {
1512 /* Use the appropriate hw_mode value automatically when the
1513 * op_class parameter has been set, but hw_mode was not. */
1514 conf->hw_mode = HOSTAPD_MODE_IEEE80211A;
1515 }
1516
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001517 if (full_config && conf->ieee80211d &&
1518 (!conf->country[0] || !conf->country[1])) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001519 wpa_printf(MSG_ERROR, "Cannot enable IEEE 802.11d without "
1520 "setting the country_code");
1521 return -1;
1522 }
1523
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001524 if (full_config && conf->ieee80211h && !conf->ieee80211d) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001525 wpa_printf(MSG_ERROR, "Cannot enable IEEE 802.11h without "
1526 "IEEE 802.11d enabled");
1527 return -1;
1528 }
1529
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001530 if (full_config && conf->local_pwr_constraint != -1 &&
1531 !conf->ieee80211d) {
1532 wpa_printf(MSG_ERROR, "Cannot add Power Constraint element without Country element");
1533 return -1;
1534 }
1535
1536 if (full_config && conf->spectrum_mgmt_required &&
1537 conf->local_pwr_constraint == -1) {
1538 wpa_printf(MSG_ERROR, "Cannot set Spectrum Management bit without Country and Power Constraint elements");
1539 return -1;
1540 }
1541
Hai Shalom81f62d82019-07-22 12:10:00 -07001542#ifdef CONFIG_AIRTIME_POLICY
1543 if (full_config && conf->airtime_mode > AIRTIME_MODE_STATIC &&
1544 !conf->airtime_update_interval) {
1545 wpa_printf(MSG_ERROR, "Airtime update interval cannot be zero");
1546 return -1;
1547 }
1548#endif /* CONFIG_AIRTIME_POLICY */
Dmitry Shmidt05df46a2015-05-19 11:02:01 -07001549 for (i = 0; i < NUM_TX_QUEUES; i++) {
1550 if (hostapd_config_check_cw(conf, i))
1551 return -1;
1552 }
1553
Sunil Ravia04bd252022-05-02 22:54:18 -07001554#ifdef CONFIG_IEEE80211BE
1555 if (full_config && conf->ieee80211be && !conf->ieee80211ax) {
1556 wpa_printf(MSG_ERROR,
1557 "Cannot set ieee80211be without ieee80211ax");
1558 return -1;
1559 }
1560#endif /* CONFIG_IEEE80211BE */
1561
Sunil Ravi77d572f2023-01-17 23:58:31 +00001562 if (full_config && conf->mbssid && !conf->ieee80211ax) {
1563 wpa_printf(MSG_ERROR,
1564 "Cannot enable multiple BSSID support without ieee80211ax");
1565 return -1;
1566 }
1567
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001568 for (i = 0; i < conf->num_bss; i++) {
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001569 if (hostapd_config_check_bss(conf->bss[i], conf, full_config))
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001570 return -1;
1571 }
1572
1573 return 0;
1574}
1575
1576
Dmitry Shmidt71757432014-06-02 13:50:35 -07001577void hostapd_set_security_params(struct hostapd_bss_config *bss,
1578 int full_config)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001579{
Hai Shalomfdcde762020-04-02 11:19:20 -07001580#ifdef CONFIG_WEP
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001581 if (bss->individual_wep_key_len == 0) {
1582 /* individual keys are not use; can use key idx0 for
1583 * broadcast keys */
1584 bss->broadcast_key_idx_min = 0;
1585 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001586#endif /* CONFIG_WEP */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001587
1588 if ((bss->wpa & 2) && bss->rsn_pairwise == 0)
1589 bss->rsn_pairwise = bss->wpa_pairwise;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001590 if (bss->group_cipher)
1591 bss->wpa_group = bss->group_cipher;
1592 else
1593 bss->wpa_group = wpa_select_ap_group_cipher(bss->wpa,
1594 bss->wpa_pairwise,
1595 bss->rsn_pairwise);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001596 if (!bss->wpa_group_rekey_set)
1597 bss->wpa_group_rekey = bss->wpa_group == WPA_CIPHER_TKIP ?
1598 600 : 86400;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001599
Dmitry Shmidt71757432014-06-02 13:50:35 -07001600 if (full_config) {
1601 bss->radius->auth_server = bss->radius->auth_servers;
1602 bss->radius->acct_server = bss->radius->acct_servers;
1603 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001604
1605 if (bss->wpa && bss->ieee802_1x) {
1606 bss->ssid.security_policy = SECURITY_WPA;
1607 } else if (bss->wpa) {
1608 bss->ssid.security_policy = SECURITY_WPA_PSK;
1609 } else if (bss->ieee802_1x) {
1610 int cipher = WPA_CIPHER_NONE;
1611 bss->ssid.security_policy = SECURITY_IEEE_802_1X;
Hai Shalomfdcde762020-04-02 11:19:20 -07001612#ifdef CONFIG_WEP
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001613 bss->ssid.wep.default_len = bss->default_wep_key_len;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001614 if (full_config && bss->default_wep_key_len) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001615 cipher = bss->default_wep_key_len >= 13 ?
1616 WPA_CIPHER_WEP104 : WPA_CIPHER_WEP40;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001617 } else if (full_config && bss->ssid.wep.keys_set) {
1618 if (bss->ssid.wep.len[0] >= 13)
1619 cipher = WPA_CIPHER_WEP104;
1620 else
1621 cipher = WPA_CIPHER_WEP40;
1622 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001623#endif /* CONFIG_WEP */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001624 bss->wpa_group = cipher;
1625 bss->wpa_pairwise = cipher;
1626 bss->rsn_pairwise = cipher;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001627 if (full_config)
1628 bss->wpa_key_mgmt = WPA_KEY_MGMT_IEEE8021X_NO_WPA;
Hai Shalomfdcde762020-04-02 11:19:20 -07001629#ifdef CONFIG_WEP
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001630 } else if (bss->ssid.wep.keys_set) {
1631 int cipher = WPA_CIPHER_WEP40;
1632 if (bss->ssid.wep.len[0] >= 13)
1633 cipher = WPA_CIPHER_WEP104;
1634 bss->ssid.security_policy = SECURITY_STATIC_WEP;
1635 bss->wpa_group = cipher;
1636 bss->wpa_pairwise = cipher;
1637 bss->rsn_pairwise = cipher;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001638 if (full_config)
1639 bss->wpa_key_mgmt = WPA_KEY_MGMT_NONE;
Hai Shalomfdcde762020-04-02 11:19:20 -07001640#endif /* CONFIG_WEP */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001641 } else if (bss->osen) {
1642 bss->ssid.security_policy = SECURITY_OSEN;
1643 bss->wpa_group = WPA_CIPHER_CCMP;
1644 bss->wpa_pairwise = 0;
1645 bss->rsn_pairwise = WPA_CIPHER_CCMP;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001646 } else {
1647 bss->ssid.security_policy = SECURITY_PLAINTEXT;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001648 if (full_config) {
1649 bss->wpa_group = WPA_CIPHER_NONE;
1650 bss->wpa_pairwise = WPA_CIPHER_NONE;
1651 bss->rsn_pairwise = WPA_CIPHER_NONE;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001652 bss->wpa_key_mgmt = WPA_KEY_MGMT_NONE;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001653 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001654 }
1655}
Hai Shalom74f70d42019-02-11 14:42:39 -08001656
1657
1658int hostapd_sae_pw_id_in_use(struct hostapd_bss_config *conf)
1659{
1660 int with_id = 0, without_id = 0;
1661 struct sae_password_entry *pw;
1662
1663 if (conf->ssid.wpa_passphrase)
1664 without_id = 1;
1665
1666 for (pw = conf->sae_passwords; pw; pw = pw->next) {
1667 if (pw->identifier)
1668 with_id = 1;
1669 else
1670 without_id = 1;
1671 if (with_id && without_id)
1672 break;
1673 }
1674
1675 if (with_id && !without_id)
1676 return 2;
1677 return with_id;
1678}
Hai Shalom899fcc72020-10-19 14:38:18 -07001679
1680
1681bool hostapd_sae_pk_in_use(struct hostapd_bss_config *conf)
1682{
1683#ifdef CONFIG_SAE_PK
1684 struct sae_password_entry *pw;
1685
1686 for (pw = conf->sae_passwords; pw; pw = pw->next) {
1687 if (pw->pk)
1688 return true;
1689 }
1690#endif /* CONFIG_SAE_PK */
1691
1692 return false;
1693}
1694
1695
1696#ifdef CONFIG_SAE_PK
1697bool hostapd_sae_pk_exclusively(struct hostapd_bss_config *conf)
1698{
1699 bool with_pk = false;
1700 struct sae_password_entry *pw;
1701
1702 if (conf->ssid.wpa_passphrase)
1703 return false;
1704
1705 for (pw = conf->sae_passwords; pw; pw = pw->next) {
1706 if (!pw->pk)
1707 return false;
1708 with_pk = true;
1709 }
1710
1711 return with_pk;
1712}
1713#endif /* CONFIG_SAE_PK */
Sunil Ravia04bd252022-05-02 22:54:18 -07001714
1715
1716int hostapd_acl_comp(const void *a, const void *b)
1717{
1718 const struct mac_acl_entry *aa = a;
1719 const struct mac_acl_entry *bb = b;
1720 return os_memcmp(aa->addr, bb->addr, sizeof(macaddr));
1721}
1722
1723
1724int hostapd_add_acl_maclist(struct mac_acl_entry **acl, int *num,
1725 int vlan_id, const u8 *addr)
1726{
1727 struct mac_acl_entry *newacl;
1728
1729 newacl = os_realloc_array(*acl, *num + 1, sizeof(**acl));
1730 if (!newacl) {
1731 wpa_printf(MSG_ERROR, "MAC list reallocation failed");
1732 return -1;
1733 }
1734
1735 *acl = newacl;
1736 os_memcpy((*acl)[*num].addr, addr, ETH_ALEN);
1737 os_memset(&(*acl)[*num].vlan_id, 0, sizeof((*acl)[*num].vlan_id));
1738 (*acl)[*num].vlan_id.untagged = vlan_id;
1739 (*acl)[*num].vlan_id.notempty = !!vlan_id;
1740 (*num)++;
1741
1742 return 0;
1743}
1744
1745
1746void hostapd_remove_acl_mac(struct mac_acl_entry **acl, int *num,
1747 const u8 *addr)
1748{
1749 int i = 0;
1750
1751 while (i < *num) {
1752 if (os_memcmp((*acl)[i].addr, addr, ETH_ALEN) == 0) {
1753 os_remove_in_array(*acl, *num, sizeof(**acl), i);
1754 (*num)--;
1755 } else {
1756 i++;
1757 }
1758 }
1759}