blob: 9aa61fac1c480c141a1d6152ec7abf3f07ac19c5 [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * hostapd / Configuration helper functions
Sunil Ravib0ac25f2024-07-12 01:42:03 +00003 * Copyright (c) 2003-2024, 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;
Sunil Ravi2a14cf12023-11-21 00:54:38 +000093 bss->eap_sim_aka_fast_reauth_limit = 1000;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070094 bss->ap_max_inactivity = AP_MAX_INACTIVITY;
95 bss->eapol_version = EAPOL_VERSION;
96
97 bss->max_listen_interval = 65535;
98
99 bss->pwd_group = 19; /* ECC: GF(p=256) */
100
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700101 bss->assoc_sa_query_max_timeout = 1000;
102 bss->assoc_sa_query_retry_timeout = 201;
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700103 bss->group_mgmt_cipher = WPA_CIPHER_AES_128_CMAC;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700104#ifdef EAP_SERVER_FAST
105 /* both anonymous and authenticated provisioning */
106 bss->eap_fast_prov = 3;
107 bss->pac_key_lifetime = 7 * 24 * 60 * 60;
108 bss->pac_key_refresh_time = 1 * 24 * 60 * 60;
109#endif /* EAP_SERVER_FAST */
110
111 /* Set to -1 as defaults depends on HT in setup */
112 bss->wmm_enabled = -1;
113
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800114#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700115 bss->ft_over_ds = 1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700116 bss->rkh_pos_timeout = 86400;
117 bss->rkh_neg_timeout = 60;
118 bss->rkh_pull_timeout = 1000;
119 bss->rkh_pull_retries = 4;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700120 bss->r0_key_lifetime = 1209600;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800121#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt04949592012-07-19 12:16:46 -0700122
123 bss->radius_das_time_window = 300;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800124
Hai Shaloma20dcd72022-02-04 13:43:00 -0800125 bss->anti_clogging_threshold = 5;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700126 bss->sae_sync = 5;
Dmitry Shmidt29333592017-01-09 12:27:11 -0800127
128 bss->gas_frag_limit = 1400;
129
130#ifdef CONFIG_FILS
131 dl_list_init(&bss->fils_realms);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800132 bss->fils_hlp_wait_time = 30;
133 bss->dhcp_server_port = DHCP_SERVER_PORT;
134 bss->dhcp_relay_port = DHCP_SERVER_PORT;
Hai Shalom60840252021-02-19 19:02:11 -0800135 bss->fils_discovery_min_int = 20;
Dmitry Shmidt29333592017-01-09 12:27:11 -0800136#endif /* CONFIG_FILS */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700137
138 bss->broadcast_deauth = 1;
139
140#ifdef CONFIG_MBO
141 bss->mbo_cell_data_conn_pref = -1;
142#endif /* CONFIG_MBO */
Roshan Pius3a1667e2018-07-03 15:17:14 -0700143
144 /* Disable TLS v1.3 by default for now to avoid interoperability issue.
145 * This can be enabled by default once the implementation has been fully
146 * completed and tested with other implementations. */
147 bss->tls_flags = TLS_CONN_DISABLE_TLSv1_3;
Hai Shalom74f70d42019-02-11 14:42:39 -0800148
Hai Shalomc3565922019-10-28 11:58:20 -0700149 bss->max_auth_rounds = 100;
150 bss->max_auth_rounds_short = 50;
151
Hai Shalom74f70d42019-02-11 14:42:39 -0800152 bss->send_probe_response = 1;
153
154#ifdef CONFIG_HS20
155 bss->hs20_release = (HS20_VERSION >> 4) + 1;
156#endif /* CONFIG_HS20 */
157
Hai Shalom81f62d82019-07-22 12:10:00 -0700158#ifdef CONFIG_MACSEC
159 bss->mka_priority = DEFAULT_PRIO_NOT_KEY_SERVER;
160 bss->macsec_port = 1;
161#endif /* CONFIG_MACSEC */
162
Hai Shalom74f70d42019-02-11 14:42:39 -0800163 /* Default to strict CRL checking. */
164 bss->check_crl_strict = 1;
Hai Shalom899fcc72020-10-19 14:38:18 -0700165
Sunil Ravi99c035e2024-07-12 01:42:03 +0000166 bss->multi_ap_profile = MULTI_AP_PROFILE_2;
167
Hai Shalom899fcc72020-10-19 14:38:18 -0700168#ifdef CONFIG_TESTING_OPTIONS
169 bss->sae_commit_status = -1;
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000170 bss->test_assoc_comeback_type = -1;
Hai Shalom899fcc72020-10-19 14:38:18 -0700171#endif /* CONFIG_TESTING_OPTIONS */
Hai Shaloma20dcd72022-02-04 13:43:00 -0800172
173#ifdef CONFIG_PASN
174 /* comeback after 10 TUs */
175 bss->pasn_comeback_after = 10;
Sunil Ravi640215c2023-06-28 23:08:09 +0000176 bss->pasn_noauth = 1;
Hai Shaloma20dcd72022-02-04 13:43:00 -0800177#endif /* CONFIG_PASN */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700178}
179
180
181struct hostapd_config * hostapd_config_defaults(void)
182{
183#define ecw2cw(ecw) ((1 << (ecw)) - 1)
184
185 struct hostapd_config *conf;
186 struct hostapd_bss_config *bss;
187 const int aCWmin = 4, aCWmax = 10;
188 const struct hostapd_wmm_ac_params ac_bk =
189 { aCWmin, aCWmax, 7, 0, 0 }; /* background traffic */
190 const struct hostapd_wmm_ac_params ac_be =
191 { aCWmin, aCWmax, 3, 0, 0 }; /* best effort traffic */
192 const struct hostapd_wmm_ac_params ac_vi = /* video traffic */
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700193 { aCWmin - 1, aCWmin, 2, 3008 / 32, 0 };
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700194 const struct hostapd_wmm_ac_params ac_vo = /* voice traffic */
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700195 { aCWmin - 2, aCWmin - 1, 2, 1504 / 32, 0 };
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700196 const struct hostapd_tx_queue_params txq_bk =
197 { 7, ecw2cw(aCWmin), ecw2cw(aCWmax), 0 };
198 const struct hostapd_tx_queue_params txq_be =
199 { 3, ecw2cw(aCWmin), 4 * (ecw2cw(aCWmin) + 1) - 1, 0};
200 const struct hostapd_tx_queue_params txq_vi =
201 { 1, (ecw2cw(aCWmin) + 1) / 2 - 1, ecw2cw(aCWmin), 30};
202 const struct hostapd_tx_queue_params txq_vo =
203 { 1, (ecw2cw(aCWmin) + 1) / 4 - 1,
204 (ecw2cw(aCWmin) + 1) / 2 - 1, 15};
205
206#undef ecw2cw
207
208 conf = os_zalloc(sizeof(*conf));
209 bss = os_zalloc(sizeof(*bss));
210 if (conf == NULL || bss == NULL) {
211 wpa_printf(MSG_ERROR, "Failed to allocate memory for "
212 "configuration data.");
213 os_free(conf);
214 os_free(bss);
215 return NULL;
216 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800217 conf->bss = os_calloc(1, sizeof(struct hostapd_bss_config *));
218 if (conf->bss == NULL) {
219 os_free(conf);
220 os_free(bss);
221 return NULL;
222 }
223 conf->bss[0] = bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700224
225 bss->radius = os_zalloc(sizeof(*bss->radius));
226 if (bss->radius == NULL) {
Dmitry Shmidt97672262014-02-03 13:02:54 -0800227 os_free(conf->bss);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700228 os_free(conf);
229 os_free(bss);
230 return NULL;
231 }
232
233 hostapd_config_defaults_bss(bss);
234
235 conf->num_bss = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700236
237 conf->beacon_int = 100;
Hai Shalom021b0b52019-04-10 11:17:58 -0700238 conf->rts_threshold = -2; /* use driver default: 2347 */
239 conf->fragm_threshold = -2; /* user driver default: 2346 */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800240 /* Set to invalid value means do not add Power Constraint IE */
241 conf->local_pwr_constraint = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700242
243 conf->wmm_ac_params[0] = ac_be;
244 conf->wmm_ac_params[1] = ac_bk;
245 conf->wmm_ac_params[2] = ac_vi;
246 conf->wmm_ac_params[3] = ac_vo;
247
248 conf->tx_queue[0] = txq_vo;
249 conf->tx_queue[1] = txq_vi;
250 conf->tx_queue[2] = txq_be;
251 conf->tx_queue[3] = txq_bk;
252
253 conf->ht_capab = HT_CAP_INFO_SMPS_DISABLED;
254
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800255 conf->ap_table_max_size = 255;
256 conf->ap_table_expiration_time = 60;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800257 conf->track_sta_max_age = 180;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800258
Dmitry Shmidt8da800a2013-04-24 12:57:01 -0700259#ifdef CONFIG_TESTING_OPTIONS
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700260 conf->ignore_probe_probability = 0.0;
261 conf->ignore_auth_probability = 0.0;
262 conf->ignore_assoc_probability = 0.0;
263 conf->ignore_reassoc_probability = 0.0;
264 conf->corrupt_gtk_rekey_mic_probability = 0.0;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800265 conf->ecsa_ie_only = 0;
Kai Shie75b0652020-11-24 20:31:29 -0800266 conf->skip_send_eapol = 0;
267 conf->enable_eapol_large_timeout = 0;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -0700268#endif /* CONFIG_TESTING_OPTIONS */
269
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700270 conf->acs = 0;
271 conf->acs_ch_list.num = 0;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700272#ifdef CONFIG_ACS
273 conf->acs_num_scans = 5;
274#endif /* CONFIG_ACS */
275
Hai Shalom81f62d82019-07-22 12:10:00 -0700276#ifdef CONFIG_IEEE80211AX
277 conf->he_op.he_rts_threshold = HE_OPERATION_RTS_THRESHOLD_MASK >>
278 HE_OPERATION_RTS_THRESHOLD_OFFSET;
279 /* Set default basic MCS/NSS set to single stream MCS 0-7 */
280 conf->he_op.he_basic_mcs_nss_set = 0xfffc;
Hai Shalomfdcde762020-04-02 11:19:20 -0700281 conf->he_op.he_bss_color_disabled = 1;
282 conf->he_op.he_bss_color_partial = 0;
Hai Shaloma20dcd72022-02-04 13:43:00 -0800283 conf->he_op.he_bss_color = os_random() % 63 + 1;
284 conf->he_op.he_twt_responder = 1;
Hai Shalom60840252021-02-19 19:02:11 -0800285 conf->he_6ghz_max_mpdu = 2;
286 conf->he_6ghz_max_ampdu_len_exp = 7;
287 conf->he_6ghz_rx_ant_pat = 1;
288 conf->he_6ghz_tx_ant_pat = 1;
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000289 conf->he_6ghz_reg_pwr_type = HE_REG_INFO_6GHZ_AP_TYPE_VLP;
290 conf->reg_def_cli_eirp_psd = -1;
291 conf->reg_sub_cli_eirp_psd = -1;
292 conf->reg_def_cli_eirp = -1;
Hai Shalom81f62d82019-07-22 12:10:00 -0700293#endif /* CONFIG_IEEE80211AX */
294
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700295 /* The third octet of the country string uses an ASCII space character
296 * by default to indicate that the regulations encompass all
297 * environments for the current frequency band in the country. */
298 conf->country[2] = ' ';
299
Hai Shalom74f70d42019-02-11 14:42:39 -0800300 conf->rssi_reject_assoc_rssi = 0;
301 conf->rssi_reject_assoc_timeout = 30;
302
Hai Shalom81f62d82019-07-22 12:10:00 -0700303#ifdef CONFIG_AIRTIME_POLICY
304 conf->airtime_update_interval = AIRTIME_DEFAULT_UPDATE_INTERVAL;
305#endif /* CONFIG_AIRTIME_POLICY */
306
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000307 hostapd_set_and_check_bw320_offset(conf, 0);
308
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700309 return conf;
310}
311
312
313int hostapd_mac_comp(const void *a, const void *b)
314{
315 return os_memcmp(a, b, sizeof(macaddr));
316}
317
318
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700319static int hostapd_config_read_wpa_psk(const char *fname,
320 struct hostapd_ssid *ssid)
321{
322 FILE *f;
323 char buf[128], *pos;
Hai Shalom74f70d42019-02-11 14:42:39 -0800324 const char *keyid;
325 char *context;
326 char *context2;
327 char *token;
328 char *name;
329 char *value;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700330 int line = 0, ret = 0, len, ok;
331 u8 addr[ETH_ALEN];
332 struct hostapd_wpa_psk *psk;
333
334 if (!fname)
335 return 0;
336
337 f = fopen(fname, "r");
338 if (!f) {
339 wpa_printf(MSG_ERROR, "WPA PSK file '%s' not found.", fname);
340 return -1;
341 }
342
343 while (fgets(buf, sizeof(buf), f)) {
Hai Shalom021b0b52019-04-10 11:17:58 -0700344 int vlan_id = 0;
Hai Shalomfdcde762020-04-02 11:19:20 -0700345 int wps = 0;
Hai Shalom021b0b52019-04-10 11:17:58 -0700346
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700347 line++;
348
349 if (buf[0] == '#')
350 continue;
351 pos = buf;
352 while (*pos != '\0') {
353 if (*pos == '\n') {
354 *pos = '\0';
355 break;
356 }
357 pos++;
358 }
359 if (buf[0] == '\0')
360 continue;
361
Hai Shalom74f70d42019-02-11 14:42:39 -0800362 context = NULL;
363 keyid = NULL;
364 while ((token = str_token(buf, " ", &context))) {
365 if (!os_strchr(token, '='))
366 break;
367 context2 = NULL;
368 name = str_token(token, "=", &context2);
Hai Shalom021b0b52019-04-10 11:17:58 -0700369 if (!name)
370 break;
Hai Shalom74f70d42019-02-11 14:42:39 -0800371 value = str_token(token, "", &context2);
372 if (!value)
373 value = "";
374 if (!os_strcmp(name, "keyid")) {
375 keyid = value;
Hai Shalomfdcde762020-04-02 11:19:20 -0700376 } else if (!os_strcmp(name, "wps")) {
377 wps = atoi(value);
Hai Shalom021b0b52019-04-10 11:17:58 -0700378 } else if (!os_strcmp(name, "vlanid")) {
379 vlan_id = atoi(value);
Hai Shalom74f70d42019-02-11 14:42:39 -0800380 } else {
381 wpa_printf(MSG_ERROR,
382 "Unrecognized '%s=%s' on line %d in '%s'",
383 name, value, line, fname);
384 ret = -1;
385 break;
386 }
387 }
388
389 if (ret == -1)
390 break;
391
392 if (!token)
393 token = "";
394 if (hwaddr_aton(token, addr)) {
Hai Shalomfdcde762020-04-02 11:19:20 -0700395 wpa_printf(MSG_ERROR,
396 "Invalid MAC address '%s' on line %d in '%s'",
397 token, line, fname);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700398 ret = -1;
399 break;
400 }
401
402 psk = os_zalloc(sizeof(*psk));
403 if (psk == NULL) {
404 wpa_printf(MSG_ERROR, "WPA PSK allocation failed");
405 ret = -1;
406 break;
407 }
Hai Shalom021b0b52019-04-10 11:17:58 -0700408 psk->vlan_id = vlan_id;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700409 if (is_zero_ether_addr(addr))
410 psk->group = 1;
411 else
412 os_memcpy(psk->addr, addr, ETH_ALEN);
413
Hai Shalom74f70d42019-02-11 14:42:39 -0800414 pos = str_token(buf, "", &context);
415 if (!pos) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700416 wpa_printf(MSG_ERROR, "No PSK on line %d in '%s'",
417 line, fname);
418 os_free(psk);
419 ret = -1;
420 break;
421 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700422
423 ok = 0;
424 len = os_strlen(pos);
Hai Shalomfdcde762020-04-02 11:19:20 -0700425 if (len == 2 * PMK_LEN &&
426 hexstr2bin(pos, psk->psk, PMK_LEN) == 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700427 ok = 1;
Hai Shalomfdcde762020-04-02 11:19:20 -0700428 else if (len >= 8 && len < 64 &&
429 pbkdf2_sha1(pos, ssid->ssid, ssid->ssid_len,
430 4096, psk->psk, PMK_LEN) == 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700431 ok = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700432 if (!ok) {
Hai Shalomfdcde762020-04-02 11:19:20 -0700433 wpa_printf(MSG_ERROR,
434 "Invalid PSK '%s' on line %d in '%s'",
435 pos, line, fname);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700436 os_free(psk);
437 ret = -1;
438 break;
439 }
440
Hai Shalom74f70d42019-02-11 14:42:39 -0800441 if (keyid) {
442 len = os_strlcpy(psk->keyid, keyid, sizeof(psk->keyid));
443 if ((size_t) len >= sizeof(psk->keyid)) {
444 wpa_printf(MSG_ERROR,
445 "PSK keyid too long on line %d in '%s'",
446 line, fname);
447 os_free(psk);
448 ret = -1;
449 break;
450 }
451 }
452
Hai Shalomfdcde762020-04-02 11:19:20 -0700453 psk->wps = wps;
454
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700455 psk->next = ssid->wpa_psk;
456 ssid->wpa_psk = psk;
457 }
458
459 fclose(f);
460
461 return ret;
462}
463
464
465static int hostapd_derive_psk(struct hostapd_ssid *ssid)
466{
467 ssid->wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
468 if (ssid->wpa_psk == NULL) {
469 wpa_printf(MSG_ERROR, "Unable to alloc space for PSK");
470 return -1;
471 }
472 wpa_hexdump_ascii(MSG_DEBUG, "SSID",
473 (u8 *) ssid->ssid, ssid->ssid_len);
474 wpa_hexdump_ascii_key(MSG_DEBUG, "PSK (ASCII passphrase)",
475 (u8 *) ssid->wpa_passphrase,
476 os_strlen(ssid->wpa_passphrase));
Sunil Ravia04bd252022-05-02 22:54:18 -0700477 if (pbkdf2_sha1(ssid->wpa_passphrase,
478 ssid->ssid, ssid->ssid_len,
479 4096, ssid->wpa_psk->psk, PMK_LEN) != 0) {
480 wpa_printf(MSG_ERROR, "Error in pbkdf2_sha1()");
481 return -1;
482 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700483 wpa_hexdump_key(MSG_DEBUG, "PSK (from passphrase)",
484 ssid->wpa_psk->psk, PMK_LEN);
485 return 0;
486}
487
488
Hai Shalomc3565922019-10-28 11:58:20 -0700489int hostapd_setup_sae_pt(struct hostapd_bss_config *conf)
490{
491#ifdef CONFIG_SAE
492 struct hostapd_ssid *ssid = &conf->ssid;
493 struct sae_password_entry *pw;
494
Sunil Ravi77d572f2023-01-17 23:58:31 +0000495 if ((conf->sae_pwe == SAE_PWE_HUNT_AND_PECK &&
496 !hostapd_sae_pw_id_in_use(conf) &&
Sunil Ravi89eba102022-09-13 21:04:37 -0700497 !wpa_key_mgmt_sae_ext_key(conf->wpa_key_mgmt) &&
Hai Shalom899fcc72020-10-19 14:38:18 -0700498 !hostapd_sae_pk_in_use(conf)) ||
Sunil Ravi77d572f2023-01-17 23:58:31 +0000499 conf->sae_pwe == SAE_PWE_FORCE_HUNT_AND_PECK ||
Hai Shalomfdcde762020-04-02 11:19:20 -0700500 !wpa_key_mgmt_sae(conf->wpa_key_mgmt))
Hai Shalomc3565922019-10-28 11:58:20 -0700501 return 0; /* PT not needed */
502
503 sae_deinit_pt(ssid->pt);
504 ssid->pt = NULL;
505 if (ssid->wpa_passphrase) {
506 ssid->pt = sae_derive_pt(conf->sae_groups, ssid->ssid,
507 ssid->ssid_len,
508 (const u8 *) ssid->wpa_passphrase,
509 os_strlen(ssid->wpa_passphrase),
510 NULL);
511 if (!ssid->pt)
512 return -1;
513 }
514
515 for (pw = conf->sae_passwords; pw; pw = pw->next) {
516 sae_deinit_pt(pw->pt);
517 pw->pt = sae_derive_pt(conf->sae_groups, ssid->ssid,
518 ssid->ssid_len,
519 (const u8 *) pw->password,
520 os_strlen(pw->password),
521 pw->identifier);
522 if (!pw->pt)
523 return -1;
524 }
525#endif /* CONFIG_SAE */
526
527 return 0;
528}
529
530
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700531int hostapd_setup_wpa_psk(struct hostapd_bss_config *conf)
532{
533 struct hostapd_ssid *ssid = &conf->ssid;
534
Hai Shalomc3565922019-10-28 11:58:20 -0700535 if (hostapd_setup_sae_pt(conf) < 0)
536 return -1;
537
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700538 if (ssid->wpa_passphrase != NULL) {
539 if (ssid->wpa_psk != NULL) {
540 wpa_printf(MSG_DEBUG, "Using pre-configured WPA PSK "
541 "instead of passphrase");
542 } else {
543 wpa_printf(MSG_DEBUG, "Deriving WPA PSK based on "
544 "passphrase");
545 if (hostapd_derive_psk(ssid) < 0)
546 return -1;
547 }
548 ssid->wpa_psk->group = 1;
549 }
550
Dmitry Shmidt29333592017-01-09 12:27:11 -0800551 return hostapd_config_read_wpa_psk(ssid->wpa_psk_file, &conf->ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700552}
553
554
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700555static void hostapd_config_free_radius(struct hostapd_radius_server *servers,
556 int num_servers)
557{
558 int i;
559
560 for (i = 0; i < num_servers; i++) {
561 os_free(servers[i].shared_secret);
Sunil Ravi99c035e2024-07-12 01:42:03 +0000562 os_free(servers[i].ca_cert);
563 os_free(servers[i].client_cert);
564 os_free(servers[i].private_key);
565 os_free(servers[i].private_key_passwd);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700566 }
567 os_free(servers);
568}
569
570
Dmitry Shmidt04949592012-07-19 12:16:46 -0700571struct hostapd_radius_attr *
572hostapd_config_get_radius_attr(struct hostapd_radius_attr *attr, u8 type)
573{
574 for (; attr; attr = attr->next) {
575 if (attr->type == type)
576 return attr;
577 }
578 return NULL;
579}
580
581
Hai Shalomc3565922019-10-28 11:58:20 -0700582struct hostapd_radius_attr * hostapd_parse_radius_attr(const char *value)
583{
584 const char *pos;
585 char syntax;
586 struct hostapd_radius_attr *attr;
587 size_t len;
588
589 attr = os_zalloc(sizeof(*attr));
590 if (!attr)
591 return NULL;
592
593 attr->type = atoi(value);
594
595 pos = os_strchr(value, ':');
596 if (!pos) {
597 attr->val = wpabuf_alloc(1);
598 if (!attr->val) {
599 os_free(attr);
600 return NULL;
601 }
602 wpabuf_put_u8(attr->val, 0);
603 return attr;
604 }
605
606 pos++;
607 if (pos[0] == '\0' || pos[1] != ':') {
608 os_free(attr);
609 return NULL;
610 }
611 syntax = *pos++;
612 pos++;
613
614 switch (syntax) {
615 case 's':
616 attr->val = wpabuf_alloc_copy(pos, os_strlen(pos));
617 break;
618 case 'x':
619 len = os_strlen(pos);
620 if (len & 1)
621 break;
622 len /= 2;
623 attr->val = wpabuf_alloc(len);
624 if (!attr->val)
625 break;
626 if (hexstr2bin(pos, wpabuf_put(attr->val, len), len) < 0) {
627 wpabuf_free(attr->val);
628 os_free(attr);
629 return NULL;
630 }
631 break;
632 case 'd':
633 attr->val = wpabuf_alloc(4);
634 if (attr->val)
635 wpabuf_put_be32(attr->val, atoi(pos));
636 break;
637 default:
638 os_free(attr);
639 return NULL;
640 }
641
642 if (!attr->val) {
643 os_free(attr);
644 return NULL;
645 }
646
647 return attr;
648}
649
650
651void hostapd_config_free_radius_attr(struct hostapd_radius_attr *attr)
Dmitry Shmidt04949592012-07-19 12:16:46 -0700652{
653 struct hostapd_radius_attr *prev;
654
655 while (attr) {
656 prev = attr;
657 attr = attr->next;
658 wpabuf_free(prev->val);
659 os_free(prev);
660 }
661}
662
663
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700664void hostapd_config_free_eap_user(struct hostapd_eap_user *user)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700665{
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700666 hostapd_config_free_radius_attr(user->accept_attr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700667 os_free(user->identity);
Dmitry Shmidtc2817022014-07-02 10:32:10 -0700668 bin_clear_free(user->password, user->password_len);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700669 bin_clear_free(user->salt, user->salt_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700670 os_free(user);
671}
672
673
Dmitry Shmidt29333592017-01-09 12:27:11 -0800674void hostapd_config_free_eap_users(struct hostapd_eap_user *user)
675{
676 struct hostapd_eap_user *prev_user;
677
678 while (user) {
679 prev_user = user;
680 user = user->next;
681 hostapd_config_free_eap_user(prev_user);
682 }
683}
684
685
Hai Shalomfdcde762020-04-02 11:19:20 -0700686#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700687static void hostapd_config_free_wep(struct hostapd_wep_keys *keys)
688{
689 int i;
690 for (i = 0; i < NUM_WEP_KEYS; i++) {
Dmitry Shmidtc2817022014-07-02 10:32:10 -0700691 bin_clear_free(keys->key[i], keys->len[i]);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700692 keys->key[i] = NULL;
693 }
694}
Hai Shalomfdcde762020-04-02 11:19:20 -0700695#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700696
697
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800698void hostapd_config_clear_wpa_psk(struct hostapd_wpa_psk **l)
699{
700 struct hostapd_wpa_psk *psk, *tmp;
701
702 for (psk = *l; psk;) {
703 tmp = psk;
704 psk = psk->next;
705 bin_clear_free(tmp, sizeof(*tmp));
706 }
707 *l = NULL;
708}
709
710
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000711#ifdef CONFIG_IEEE80211R_AP
712
713void hostapd_config_clear_rxkhs(struct hostapd_bss_config *conf)
714{
715 struct ft_remote_r0kh *r0kh, *r0kh_prev;
716 struct ft_remote_r1kh *r1kh, *r1kh_prev;
717
718 r0kh = conf->r0kh_list;
719 conf->r0kh_list = NULL;
720 while (r0kh) {
721 r0kh_prev = r0kh;
722 r0kh = r0kh->next;
723 os_free(r0kh_prev);
724 }
725
726 r1kh = conf->r1kh_list;
727 conf->r1kh_list = NULL;
728 while (r1kh) {
729 r1kh_prev = r1kh;
730 r1kh = r1kh->next;
731 os_free(r1kh_prev);
732 }
733}
734
735#endif /* CONFIG_IEEE80211R_AP */
736
737
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800738static void hostapd_config_free_anqp_elem(struct hostapd_bss_config *conf)
739{
740 struct anqp_element *elem;
741
742 while ((elem = dl_list_first(&conf->anqp_elem, struct anqp_element,
743 list))) {
744 dl_list_del(&elem->list);
745 wpabuf_free(elem->payload);
746 os_free(elem);
747 }
748}
749
750
Dmitry Shmidt29333592017-01-09 12:27:11 -0800751static void hostapd_config_free_fils_realms(struct hostapd_bss_config *conf)
752{
753#ifdef CONFIG_FILS
754 struct fils_realm *realm;
755
756 while ((realm = dl_list_first(&conf->fils_realms, struct fils_realm,
757 list))) {
758 dl_list_del(&realm->list);
759 os_free(realm);
760 }
761#endif /* CONFIG_FILS */
762}
763
764
Roshan Pius3a1667e2018-07-03 15:17:14 -0700765static void hostapd_config_free_sae_passwords(struct hostapd_bss_config *conf)
766{
767 struct sae_password_entry *pw, *tmp;
768
769 pw = conf->sae_passwords;
770 conf->sae_passwords = NULL;
771 while (pw) {
772 tmp = pw;
773 pw = pw->next;
774 str_clear_free(tmp->password);
775 os_free(tmp->identifier);
Hai Shalomc3565922019-10-28 11:58:20 -0700776#ifdef CONFIG_SAE
777 sae_deinit_pt(tmp->pt);
778#endif /* CONFIG_SAE */
Hai Shalom899fcc72020-10-19 14:38:18 -0700779#ifdef CONFIG_SAE_PK
780 sae_deinit_pk(tmp->pk);
781#endif /* CONFIG_SAE_PK */
Roshan Pius3a1667e2018-07-03 15:17:14 -0700782 os_free(tmp);
783 }
784}
785
786
Hai Shalom81f62d82019-07-22 12:10:00 -0700787#ifdef CONFIG_DPP2
788static void hostapd_dpp_controller_conf_free(struct dpp_controller_conf *conf)
789{
790 struct dpp_controller_conf *prev;
791
792 while (conf) {
793 prev = conf;
794 conf = conf->next;
795 os_free(prev);
796 }
797}
798#endif /* CONFIG_DPP2 */
799
800
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800801void hostapd_config_free_bss(struct hostapd_bss_config *conf)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700802{
Hai Shalom81f62d82019-07-22 12:10:00 -0700803#if defined(CONFIG_WPS) || defined(CONFIG_HS20)
804 size_t i;
805#endif
806
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700807 if (conf == NULL)
808 return;
809
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800810 hostapd_config_clear_wpa_psk(&conf->ssid.wpa_psk);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700811
Dmitry Shmidtc2817022014-07-02 10:32:10 -0700812 str_clear_free(conf->ssid.wpa_passphrase);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700813 os_free(conf->ssid.wpa_psk_file);
Hai Shalomfdcde762020-04-02 11:19:20 -0700814#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700815 hostapd_config_free_wep(&conf->ssid.wep);
Hai Shalomfdcde762020-04-02 11:19:20 -0700816#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700817#ifdef CONFIG_FULL_DYNAMIC_VLAN
818 os_free(conf->ssid.vlan_tagged_interface);
819#endif /* CONFIG_FULL_DYNAMIC_VLAN */
Hai Shalomc3565922019-10-28 11:58:20 -0700820#ifdef CONFIG_SAE
821 sae_deinit_pt(conf->ssid.pt);
822#endif /* CONFIG_SAE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700823
Dmitry Shmidt29333592017-01-09 12:27:11 -0800824 hostapd_config_free_eap_users(conf->eap_user);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800825 os_free(conf->eap_user_sqlite);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700826
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700827 os_free(conf->eap_req_id_text);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800828 os_free(conf->erp_domain);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700829 os_free(conf->accept_mac);
830 os_free(conf->deny_mac);
831 os_free(conf->nas_identifier);
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800832 if (conf->radius) {
833 hostapd_config_free_radius(conf->radius->auth_servers,
834 conf->radius->num_auth_servers);
835 hostapd_config_free_radius(conf->radius->acct_servers,
836 conf->radius->num_acct_servers);
Hai Shaloma20dcd72022-02-04 13:43:00 -0800837 os_free(conf->radius->force_client_dev);
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800838 }
Dmitry Shmidt04949592012-07-19 12:16:46 -0700839 hostapd_config_free_radius_attr(conf->radius_auth_req_attr);
840 hostapd_config_free_radius_attr(conf->radius_acct_req_attr);
Hai Shalomc3565922019-10-28 11:58:20 -0700841 os_free(conf->radius_req_attr_sqlite);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700842 os_free(conf->rsn_preauth_interfaces);
843 os_free(conf->ctrl_interface);
Sunil Ravi77d572f2023-01-17 23:58:31 +0000844 os_free(conf->config_id);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700845 os_free(conf->ca_cert);
846 os_free(conf->server_cert);
Hai Shalom81f62d82019-07-22 12:10:00 -0700847 os_free(conf->server_cert2);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700848 os_free(conf->private_key);
Hai Shalom81f62d82019-07-22 12:10:00 -0700849 os_free(conf->private_key2);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700850 os_free(conf->private_key_passwd);
Hai Shalom81f62d82019-07-22 12:10:00 -0700851 os_free(conf->private_key_passwd2);
Hai Shalom021b0b52019-04-10 11:17:58 -0700852 os_free(conf->check_cert_subject);
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700853 os_free(conf->ocsp_stapling_response);
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -0800854 os_free(conf->ocsp_stapling_response_multi);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700855 os_free(conf->dh_file);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800856 os_free(conf->openssl_ciphers);
Hai Shalom74f70d42019-02-11 14:42:39 -0800857 os_free(conf->openssl_ecdh_curves);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700858 os_free(conf->pac_opaque_encr_key);
859 os_free(conf->eap_fast_a_id);
860 os_free(conf->eap_fast_a_id_info);
861 os_free(conf->eap_sim_db);
Sunil Ravia04bd252022-05-02 22:54:18 -0700862 os_free(conf->imsi_privacy_key);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700863 os_free(conf->radius_server_clients);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700864 os_free(conf->radius);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700865 os_free(conf->radius_das_shared_secret);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700866 hostapd_config_free_vlan(conf);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800867 os_free(conf->time_zone);
868
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800869#ifdef CONFIG_IEEE80211R_AP
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000870 hostapd_config_clear_rxkhs(conf);
871 os_free(conf->rxkh_file);
872 conf->rxkh_file = NULL;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800873#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700874
875#ifdef CONFIG_WPS
876 os_free(conf->wps_pin_requests);
877 os_free(conf->device_name);
878 os_free(conf->manufacturer);
879 os_free(conf->model_name);
880 os_free(conf->model_number);
881 os_free(conf->serial_number);
882 os_free(conf->config_methods);
883 os_free(conf->ap_pin);
884 os_free(conf->extra_cred);
885 os_free(conf->ap_settings);
Hai Shalom021b0b52019-04-10 11:17:58 -0700886 hostapd_config_clear_wpa_psk(&conf->multi_ap_backhaul_ssid.wpa_psk);
887 str_clear_free(conf->multi_ap_backhaul_ssid.wpa_passphrase);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700888 os_free(conf->upnp_iface);
889 os_free(conf->friendly_name);
890 os_free(conf->manufacturer_url);
891 os_free(conf->model_description);
892 os_free(conf->model_url);
893 os_free(conf->upc);
Hai Shalom81f62d82019-07-22 12:10:00 -0700894 for (i = 0; i < MAX_WPS_VENDOR_EXTENSIONS; i++)
895 wpabuf_free(conf->wps_vendor_ext[i]);
Hai Shalomfdcde762020-04-02 11:19:20 -0700896 wpabuf_free(conf->wps_application_ext);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700897 wpabuf_free(conf->wps_nfc_dh_pubkey);
898 wpabuf_free(conf->wps_nfc_dh_privkey);
899 wpabuf_free(conf->wps_nfc_dev_pw);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700900#endif /* CONFIG_WPS */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800901
902 os_free(conf->roaming_consortium);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700903 os_free(conf->venue_name);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700904 os_free(conf->venue_url);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700905 os_free(conf->nai_realm_data);
906 os_free(conf->network_auth_type);
907 os_free(conf->anqp_3gpp_cell_net);
908 os_free(conf->domain_name);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800909 hostapd_config_free_anqp_elem(conf);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800910
911#ifdef CONFIG_RADIUS_TEST
912 os_free(conf->dump_msk_file);
913#endif /* CONFIG_RADIUS_TEST */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700914
915#ifdef CONFIG_HS20
916 os_free(conf->hs20_oper_friendly_name);
917 os_free(conf->hs20_wan_metrics);
918 os_free(conf->hs20_connection_capability);
919 os_free(conf->hs20_operating_class);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800920 os_free(conf->hs20_icons);
921 if (conf->hs20_osu_providers) {
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800922 for (i = 0; i < conf->hs20_osu_providers_count; i++) {
923 struct hs20_osu_provider *p;
924 size_t j;
925 p = &conf->hs20_osu_providers[i];
926 os_free(p->friendly_name);
927 os_free(p->server_uri);
928 os_free(p->method_list);
929 for (j = 0; j < p->icons_count; j++)
930 os_free(p->icons[j]);
931 os_free(p->icons);
932 os_free(p->osu_nai);
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800933 os_free(p->osu_nai2);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800934 os_free(p->service_desc);
935 }
936 os_free(conf->hs20_osu_providers);
937 }
Roshan Pius3a1667e2018-07-03 15:17:14 -0700938 if (conf->hs20_operator_icon) {
Roshan Pius3a1667e2018-07-03 15:17:14 -0700939 for (i = 0; i < conf->hs20_operator_icon_count; i++)
940 os_free(conf->hs20_operator_icon[i]);
941 os_free(conf->hs20_operator_icon);
942 }
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800943 os_free(conf->subscr_remediation_url);
Hai Shalom74f70d42019-02-11 14:42:39 -0800944 os_free(conf->hs20_sim_provisioning_url);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700945 os_free(conf->t_c_filename);
946 os_free(conf->t_c_server_url);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700947#endif /* CONFIG_HS20 */
948
949 wpabuf_free(conf->vendor_elements);
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700950 wpabuf_free(conf->assocresp_elements);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800951
952 os_free(conf->sae_groups);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700953#ifdef CONFIG_OWE
954 os_free(conf->owe_groups);
955#endif /* CONFIG_OWE */
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700956
Dmitry Shmidt0207e232014-09-03 14:58:37 -0700957 os_free(conf->wowlan_triggers);
958
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700959 os_free(conf->server_id);
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800960
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800961#ifdef CONFIG_TESTING_OPTIONS
962 wpabuf_free(conf->own_ie_override);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700963 wpabuf_free(conf->sae_commit_override);
Hai Shalomfdcde762020-04-02 11:19:20 -0700964 wpabuf_free(conf->rsne_override_eapol);
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800965 wpabuf_free(conf->rsnxe_override_eapol);
Hai Shalomfdcde762020-04-02 11:19:20 -0700966 wpabuf_free(conf->rsne_override_ft);
967 wpabuf_free(conf->rsnxe_override_ft);
968 wpabuf_free(conf->gtk_rsc_override);
969 wpabuf_free(conf->igtk_rsc_override);
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000970 wpabuf_free(conf->eapol_m1_elements);
971 wpabuf_free(conf->eapol_m3_elements);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800972#endif /* CONFIG_TESTING_OPTIONS */
973
974 os_free(conf->no_probe_resp_if_seen_on);
975 os_free(conf->no_auth_if_seen_on);
976
Dmitry Shmidt29333592017-01-09 12:27:11 -0800977 hostapd_config_free_fils_realms(conf);
978
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700979#ifdef CONFIG_DPP
Hai Shalomc3565922019-10-28 11:58:20 -0700980 os_free(conf->dpp_name);
981 os_free(conf->dpp_mud_url);
Sunil Ravi89eba102022-09-13 21:04:37 -0700982 os_free(conf->dpp_extra_conf_req_name);
983 os_free(conf->dpp_extra_conf_req_value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700984 os_free(conf->dpp_connector);
985 wpabuf_free(conf->dpp_netaccesskey);
986 wpabuf_free(conf->dpp_csign);
Hai Shalom81f62d82019-07-22 12:10:00 -0700987#ifdef CONFIG_DPP2
988 hostapd_dpp_controller_conf_free(conf->dpp_controller);
989#endif /* CONFIG_DPP2 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700990#endif /* CONFIG_DPP */
991
Roshan Pius3a1667e2018-07-03 15:17:14 -0700992 hostapd_config_free_sae_passwords(conf);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700993
Hai Shalom81f62d82019-07-22 12:10:00 -0700994#ifdef CONFIG_AIRTIME_POLICY
995 {
996 struct airtime_sta_weight *wt, *wt_prev;
997
998 wt = conf->airtime_weight_list;
999 conf->airtime_weight_list = NULL;
1000 while (wt) {
1001 wt_prev = wt;
1002 wt = wt->next;
1003 os_free(wt_prev);
1004 }
1005 }
1006#endif /* CONFIG_AIRTIME_POLICY */
1007
Hai Shalom60840252021-02-19 19:02:11 -08001008#ifdef CONFIG_PASN
1009 os_free(conf->pasn_groups);
1010#endif /* CONFIG_PASN */
1011
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001012 os_free(conf);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001013}
1014
1015
1016/**
1017 * hostapd_config_free - Free hostapd configuration
1018 * @conf: Configuration data from hostapd_config_read().
1019 */
1020void hostapd_config_free(struct hostapd_config *conf)
1021{
1022 size_t i;
1023
1024 if (conf == NULL)
1025 return;
1026
1027 for (i = 0; i < conf->num_bss; i++)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001028 hostapd_config_free_bss(conf->bss[i]);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001029 os_free(conf->bss);
1030 os_free(conf->supported_rates);
1031 os_free(conf->basic_rates);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07001032 os_free(conf->acs_ch_list.range);
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001033 os_free(conf->acs_freq_list.range);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001034 os_free(conf->driver_params);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001035#ifdef CONFIG_ACS
1036 os_free(conf->acs_chan_bias);
1037#endif /* CONFIG_ACS */
Dmitry Shmidt849734c2016-05-27 09:59:01 -07001038 wpabuf_free(conf->lci);
1039 wpabuf_free(conf->civic);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001040
1041 os_free(conf);
1042}
1043
1044
1045/**
1046 * hostapd_maclist_found - Find a MAC address from a list
1047 * @list: MAC address list
1048 * @num_entries: Number of addresses in the list
1049 * @addr: Address to search for
1050 * @vlan_id: Buffer for returning VLAN ID or %NULL if not needed
1051 * Returns: 1 if address is in the list or 0 if not.
1052 *
1053 * Perform a binary search for given MAC address from a pre-sorted list.
1054 */
1055int hostapd_maclist_found(struct mac_acl_entry *list, int num_entries,
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001056 const u8 *addr, struct vlan_description *vlan_id)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001057{
1058 int start, end, middle, res;
1059
1060 start = 0;
1061 end = num_entries - 1;
1062
1063 while (start <= end) {
1064 middle = (start + end) / 2;
1065 res = os_memcmp(list[middle].addr, addr, ETH_ALEN);
1066 if (res == 0) {
1067 if (vlan_id)
1068 *vlan_id = list[middle].vlan_id;
1069 return 1;
1070 }
1071 if (res < 0)
1072 start = middle + 1;
1073 else
1074 end = middle - 1;
1075 }
1076
1077 return 0;
1078}
1079
1080
1081int hostapd_rate_found(int *list, int rate)
1082{
1083 int i;
1084
1085 if (list == NULL)
1086 return 0;
1087
1088 for (i = 0; list[i] >= 0; i++)
1089 if (list[i] == rate)
1090 return 1;
1091
1092 return 0;
1093}
1094
1095
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001096int hostapd_vlan_valid(struct hostapd_vlan *vlan,
1097 struct vlan_description *vlan_desc)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001098{
1099 struct hostapd_vlan *v = vlan;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001100 int i;
1101
1102 if (!vlan_desc->notempty || vlan_desc->untagged < 0 ||
1103 vlan_desc->untagged > MAX_VLAN_ID)
1104 return 0;
1105 for (i = 0; i < MAX_NUM_TAGGED_VLAN; i++) {
1106 if (vlan_desc->tagged[i] < 0 ||
1107 vlan_desc->tagged[i] > MAX_VLAN_ID)
1108 return 0;
1109 }
1110 if (!vlan_desc->untagged && !vlan_desc->tagged[0])
1111 return 0;
1112
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001113 while (v) {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001114 if (!vlan_compare(&v->vlan_desc, vlan_desc) ||
1115 v->vlan_id == VLAN_ID_WILDCARD)
Dmitry Shmidt34af3062013-07-11 10:46:32 -07001116 return 1;
1117 v = v->next;
1118 }
1119 return 0;
1120}
1121
1122
1123const char * hostapd_get_vlan_id_ifname(struct hostapd_vlan *vlan, int vlan_id)
1124{
1125 struct hostapd_vlan *v = vlan;
1126 while (v) {
1127 if (v->vlan_id == vlan_id)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001128 return v->ifname;
1129 v = v->next;
1130 }
1131 return NULL;
1132}
1133
1134
1135const u8 * hostapd_get_psk(const struct hostapd_bss_config *conf,
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001136 const u8 *addr, const u8 *p2p_dev_addr,
Hai Shalom021b0b52019-04-10 11:17:58 -07001137 const u8 *prev_psk, int *vlan_id)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001138{
1139 struct hostapd_wpa_psk *psk;
1140 int next_ok = prev_psk == NULL;
1141
Hai Shalom021b0b52019-04-10 11:17:58 -07001142 if (vlan_id)
1143 *vlan_id = 0;
1144
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001145 if (p2p_dev_addr && !is_zero_ether_addr(p2p_dev_addr)) {
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001146 wpa_printf(MSG_DEBUG, "Searching a PSK for " MACSTR
1147 " p2p_dev_addr=" MACSTR " prev_psk=%p",
1148 MAC2STR(addr), MAC2STR(p2p_dev_addr), prev_psk);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001149 addr = NULL; /* Use P2P Device Address for matching */
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001150 } else {
1151 wpa_printf(MSG_DEBUG, "Searching a PSK for " MACSTR
1152 " prev_psk=%p",
1153 MAC2STR(addr), prev_psk);
1154 }
1155
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001156 for (psk = conf->ssid.wpa_psk; psk != NULL; psk = psk->next) {
1157 if (next_ok &&
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001158 (psk->group ||
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001159 (addr && ether_addr_equal(psk->addr, addr)) ||
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001160 (!addr && p2p_dev_addr &&
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001161 ether_addr_equal(psk->p2p_dev_addr, p2p_dev_addr)))) {
Hai Shalom021b0b52019-04-10 11:17:58 -07001162 if (vlan_id)
1163 *vlan_id = psk->vlan_id;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001164 return psk->psk;
Hai Shalom021b0b52019-04-10 11:17:58 -07001165 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001166
1167 if (psk->psk == prev_psk)
1168 next_ok = 1;
1169 }
1170
1171 return NULL;
1172}
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001173
1174
Hai Shalom899fcc72020-10-19 14:38:18 -07001175#ifdef CONFIG_SAE_PK
1176static bool hostapd_sae_pk_password_without_pk(struct hostapd_bss_config *bss)
1177{
1178 struct sae_password_entry *pw;
1179 bool res = false;
1180
1181 if (bss->ssid.wpa_passphrase &&
1182#ifdef CONFIG_TESTING_OPTIONS
1183 !bss->sae_pk_password_check_skip &&
1184#endif /* CONFIG_TESTING_OPTIONS */
1185 sae_pk_valid_password(bss->ssid.wpa_passphrase))
1186 res = true;
1187
1188 for (pw = bss->sae_passwords; pw; pw = pw->next) {
1189 if (!pw->pk &&
1190#ifdef CONFIG_TESTING_OPTIONS
1191 !bss->sae_pk_password_check_skip &&
1192#endif /* CONFIG_TESTING_OPTIONS */
1193 sae_pk_valid_password(pw->password))
1194 return true;
1195
1196 if (bss->ssid.wpa_passphrase && res && pw->pk &&
1197 os_strcmp(bss->ssid.wpa_passphrase, pw->password) == 0)
1198 res = false;
1199 }
1200
1201 return res;
1202}
1203#endif /* CONFIG_SAE_PK */
1204
1205
Hai Shalom60840252021-02-19 19:02:11 -08001206static bool hostapd_config_check_bss_6g(struct hostapd_bss_config *bss)
1207{
1208 if (bss->wpa != WPA_PROTO_RSN) {
1209 wpa_printf(MSG_ERROR,
1210 "Pre-RSNA security methods are not allowed in 6 GHz");
1211 return false;
1212 }
1213
1214 if (bss->ieee80211w != MGMT_FRAME_PROTECTION_REQUIRED) {
1215 wpa_printf(MSG_ERROR,
1216 "Management frame protection is required in 6 GHz");
1217 return false;
1218 }
1219
1220 if (bss->wpa_key_mgmt & (WPA_KEY_MGMT_PSK |
1221 WPA_KEY_MGMT_FT_PSK |
1222 WPA_KEY_MGMT_PSK_SHA256)) {
1223 wpa_printf(MSG_ERROR, "Invalid AKM suite for 6 GHz");
1224 return false;
1225 }
1226
1227 if (bss->rsn_pairwise & (WPA_CIPHER_WEP40 |
1228 WPA_CIPHER_WEP104 |
1229 WPA_CIPHER_TKIP)) {
1230 wpa_printf(MSG_ERROR,
1231 "Invalid pairwise cipher suite for 6 GHz");
1232 return false;
1233 }
1234
1235 if (bss->wpa_group & (WPA_CIPHER_WEP40 |
1236 WPA_CIPHER_WEP104 |
1237 WPA_CIPHER_TKIP)) {
1238 wpa_printf(MSG_ERROR, "Invalid group cipher suite for 6 GHz");
1239 return false;
1240 }
1241
Sunil Ravi77d572f2023-01-17 23:58:31 +00001242#ifdef CONFIG_SAE
1243 if (wpa_key_mgmt_sae(bss->wpa_key_mgmt) &&
1244 bss->sae_pwe == SAE_PWE_HUNT_AND_PECK) {
1245 wpa_printf(MSG_INFO, "SAE: Enabling SAE H2E on 6 GHz");
1246 bss->sae_pwe = SAE_PWE_BOTH;
1247 }
1248#endif /* CONFIG_SAE */
1249
Hai Shalom60840252021-02-19 19:02:11 -08001250 return true;
1251}
1252
1253
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001254static int hostapd_config_check_bss(struct hostapd_bss_config *bss,
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001255 struct hostapd_config *conf,
1256 int full_config)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001257{
Hai Shalom60840252021-02-19 19:02:11 -08001258 if (full_config && is_6ghz_op_class(conf->op_class) &&
1259 !hostapd_config_check_bss_6g(bss))
1260 return -1;
1261
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001262 if (full_config && bss->ieee802_1x && !bss->eap_server &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001263 !bss->radius->auth_servers) {
1264 wpa_printf(MSG_ERROR, "Invalid IEEE 802.1X configuration (no "
1265 "EAP authenticator configured).");
1266 return -1;
1267 }
1268
Hai Shalomfdcde762020-04-02 11:19:20 -07001269#ifdef CONFIG_WEP
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001270 if (bss->wpa) {
1271 int wep, i;
1272
1273 wep = bss->default_wep_key_len > 0 ||
1274 bss->individual_wep_key_len > 0;
1275 for (i = 0; i < NUM_WEP_KEYS; i++) {
1276 if (bss->ssid.wep.keys_set) {
1277 wep = 1;
1278 break;
1279 }
1280 }
1281
1282 if (wep) {
1283 wpa_printf(MSG_ERROR, "WEP configuration in a WPA network is not supported");
1284 return -1;
1285 }
1286 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001287#endif /* CONFIG_WEP */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001288
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001289 if (full_config && bss->wpa &&
1290 bss->wpa_psk_radius != PSK_RADIUS_IGNORED &&
Sunil Ravia04bd252022-05-02 22:54:18 -07001291 bss->wpa_psk_radius != PSK_RADIUS_DURING_4WAY_HS &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001292 bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH) {
1293 wpa_printf(MSG_ERROR, "WPA-PSK using RADIUS enabled, but no "
1294 "RADIUS checking (macaddr_acl=2) enabled.");
1295 return -1;
1296 }
1297
Sunil Ravia04bd252022-05-02 22:54:18 -07001298 if (full_config && bss->wpa &&
1299 wpa_key_mgmt_wpa_psk_no_sae(bss->wpa_key_mgmt) &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001300 bss->ssid.wpa_psk == NULL && bss->ssid.wpa_passphrase == NULL &&
1301 bss->ssid.wpa_psk_file == NULL &&
Sunil Ravia04bd252022-05-02 22:54:18 -07001302 bss->wpa_psk_radius != PSK_RADIUS_DURING_4WAY_HS &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001303 (bss->wpa_psk_radius != PSK_RADIUS_REQUIRED ||
1304 bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH)) {
1305 wpa_printf(MSG_ERROR, "WPA-PSK enabled, but PSK or passphrase "
1306 "is not configured.");
1307 return -1;
1308 }
1309
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001310 if (full_config && !is_zero_ether_addr(bss->bssid)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001311 size_t i;
1312
1313 for (i = 0; i < conf->num_bss; i++) {
1314 if (conf->bss[i] != bss &&
1315 (hostapd_mac_comp(conf->bss[i]->bssid,
1316 bss->bssid) == 0)) {
1317 wpa_printf(MSG_ERROR, "Duplicate BSSID " MACSTR
1318 " on interface '%s' and '%s'.",
1319 MAC2STR(bss->bssid),
1320 conf->bss[i]->iface, bss->iface);
1321 return -1;
1322 }
1323 }
1324 }
1325
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001326#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001327 if (full_config && wpa_key_mgmt_ft(bss->wpa_key_mgmt) &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001328 (bss->nas_identifier == NULL ||
1329 os_strlen(bss->nas_identifier) < 1 ||
1330 os_strlen(bss->nas_identifier) > FT_R0KH_ID_MAX_LEN)) {
1331 wpa_printf(MSG_ERROR, "FT (IEEE 802.11r) requires "
1332 "nas_identifier to be configured as a 1..48 octet "
1333 "string");
1334 return -1;
1335 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001336#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001337
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001338 if (full_config && conf->ieee80211n &&
1339 conf->hw_mode == HOSTAPD_MODE_IEEE80211B) {
Hai Shalom60840252021-02-19 19:02:11 -08001340 bss->disable_11n = true;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001341 wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) in 11b mode is not "
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001342 "allowed, disabling HT capabilities");
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001343 }
1344
Hai Shalomfdcde762020-04-02 11:19:20 -07001345#ifdef CONFIG_WEP
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001346 if (full_config && conf->ieee80211n &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001347 bss->ssid.security_policy == SECURITY_STATIC_WEP) {
Hai Shalom60840252021-02-19 19:02:11 -08001348 bss->disable_11n = true;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001349 wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) with WEP is not "
1350 "allowed, disabling HT capabilities");
1351 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001352#endif /* CONFIG_WEP */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001353
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001354 if (full_config && conf->ieee80211n && bss->wpa &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001355 !(bss->wpa_pairwise & WPA_CIPHER_CCMP) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001356 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
1357 WPA_CIPHER_CCMP_256 | WPA_CIPHER_GCMP_256)))
1358 {
Hai Shalom60840252021-02-19 19:02:11 -08001359 bss->disable_11n = true;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001360 wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) with WPA/WPA2 "
1361 "requires CCMP/GCMP to be enabled, disabling HT "
1362 "capabilities");
1363 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001364
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07001365#ifdef CONFIG_IEEE80211AC
Hai Shalomfdcde762020-04-02 11:19:20 -07001366#ifdef CONFIG_WEP
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07001367 if (full_config && conf->ieee80211ac &&
1368 bss->ssid.security_policy == SECURITY_STATIC_WEP) {
Hai Shalom60840252021-02-19 19:02:11 -08001369 bss->disable_11ac = true;
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07001370 wpa_printf(MSG_ERROR,
1371 "VHT (IEEE 802.11ac) with WEP is not allowed, disabling VHT capabilities");
1372 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001373#endif /* CONFIG_WEP */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001374
1375 if (full_config && conf->ieee80211ac && bss->wpa &&
1376 !(bss->wpa_pairwise & WPA_CIPHER_CCMP) &&
1377 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
1378 WPA_CIPHER_CCMP_256 | WPA_CIPHER_GCMP_256)))
1379 {
Hai Shalom60840252021-02-19 19:02:11 -08001380 bss->disable_11ac = true;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001381 wpa_printf(MSG_ERROR,
1382 "VHT (IEEE 802.11ac) with WPA/WPA2 requires CCMP/GCMP to be enabled, disabling VHT capabilities");
1383 }
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07001384#endif /* CONFIG_IEEE80211AC */
1385
Hai Shalom60840252021-02-19 19:02:11 -08001386#ifdef CONFIG_IEEE80211AX
1387#ifdef CONFIG_WEP
1388 if (full_config && conf->ieee80211ax &&
1389 bss->ssid.security_policy == SECURITY_STATIC_WEP) {
1390 bss->disable_11ax = true;
1391 wpa_printf(MSG_ERROR,
1392 "HE (IEEE 802.11ax) with WEP is not allowed, disabling HE capabilities");
1393 }
1394#endif /* CONFIG_WEP */
1395
1396 if (full_config && conf->ieee80211ax && bss->wpa &&
1397 !(bss->wpa_pairwise & WPA_CIPHER_CCMP) &&
1398 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
1399 WPA_CIPHER_CCMP_256 | WPA_CIPHER_GCMP_256)))
1400 {
1401 bss->disable_11ax = true;
1402 wpa_printf(MSG_ERROR,
1403 "HE (IEEE 802.11ax) with WPA/WPA2 requires CCMP/GCMP to be enabled, disabling HE capabilities");
1404 }
1405#endif /* CONFIG_IEEE80211AX */
1406
Dmitry Shmidt15907092014-03-25 10:42:57 -07001407#ifdef CONFIG_WPS
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001408 if (full_config && bss->wps_state && bss->ignore_broadcast_ssid) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001409 wpa_printf(MSG_INFO, "WPS: ignore_broadcast_ssid "
1410 "configuration forced WPS to be disabled");
1411 bss->wps_state = 0;
1412 }
1413
Hai Shalomfdcde762020-04-02 11:19:20 -07001414#ifdef CONFIG_WEP
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001415 if (full_config && bss->wps_state &&
1416 bss->ssid.wep.keys_set && bss->wpa == 0) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001417 wpa_printf(MSG_INFO, "WPS: WEP configuration forced WPS to be "
1418 "disabled");
1419 bss->wps_state = 0;
1420 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001421#endif /* CONFIG_WEP */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001422
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001423 if (full_config && bss->wps_state && bss->wpa &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001424 (!(bss->wpa & 2) ||
Roshan Pius3a1667e2018-07-03 15:17:14 -07001425 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
1426 WPA_CIPHER_CCMP_256 |
1427 WPA_CIPHER_GCMP_256)))) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001428 wpa_printf(MSG_INFO, "WPS: WPA/TKIP configuration without "
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07001429 "WPA2/CCMP/GCMP forced WPS to be disabled");
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001430 bss->wps_state = 0;
1431 }
Dmitry Shmidt15907092014-03-25 10:42:57 -07001432#endif /* CONFIG_WPS */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001433
1434#ifdef CONFIG_HS20
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001435 if (full_config && bss->hs20 &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001436 (!(bss->wpa & 2) ||
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001437 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
1438 WPA_CIPHER_CCMP_256 |
1439 WPA_CIPHER_GCMP_256)))) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001440 wpa_printf(MSG_ERROR, "HS 2.0: WPA2-Enterprise/CCMP "
1441 "configuration is required for Hotspot 2.0 "
1442 "functionality");
1443 return -1;
1444 }
1445#endif /* CONFIG_HS20 */
1446
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001447#ifdef CONFIG_MBO
1448 if (full_config && bss->mbo_enabled && (bss->wpa & 2) &&
1449 bss->ieee80211w == NO_MGMT_FRAME_PROTECTION) {
1450 wpa_printf(MSG_ERROR,
1451 "MBO: PMF needs to be enabled whenever using WPA2 with MBO");
1452 return -1;
1453 }
1454#endif /* CONFIG_MBO */
1455
Hai Shalom74f70d42019-02-11 14:42:39 -08001456#ifdef CONFIG_OCV
1457 if (full_config && bss->ieee80211w == NO_MGMT_FRAME_PROTECTION &&
1458 bss->ocv) {
1459 wpa_printf(MSG_ERROR,
1460 "OCV: PMF needs to be enabled whenever using OCV");
1461 return -1;
1462 }
1463#endif /* CONFIG_OCV */
1464
Hai Shalom899fcc72020-10-19 14:38:18 -07001465#ifdef CONFIG_SAE_PK
1466 if (full_config && hostapd_sae_pk_in_use(bss) &&
1467 hostapd_sae_pk_password_without_pk(bss)) {
1468 wpa_printf(MSG_ERROR,
1469 "SAE-PK: SAE password uses SAE-PK style, but does not have PK configured");
1470 return -1;
1471 }
1472#endif /* CONFIG_SAE_PK */
1473
Hai Shaloma20dcd72022-02-04 13:43:00 -08001474#ifdef CONFIG_FILS
Sunil Ravia04bd252022-05-02 22:54:18 -07001475 if (full_config && bss->fils_discovery_max_int &&
Sunil Ravi036cec52023-03-29 11:35:17 -07001476 (!conf->ieee80211ax || bss->disable_11ax)) {
1477 wpa_printf(MSG_ERROR,
1478 "Currently IEEE 802.11ax support is mandatory to enable FILS discovery transmission.");
1479 return -1;
1480 }
1481
1482 if (full_config && bss->fils_discovery_max_int &&
Hai Shaloma20dcd72022-02-04 13:43:00 -08001483 bss->unsol_bcast_probe_resp_interval) {
1484 wpa_printf(MSG_ERROR,
1485 "Cannot enable both FILS discovery and unsolicited broadcast Probe Response at the same time");
1486 return -1;
1487 }
1488#endif /* CONFIG_FILS */
1489
Sunil Ravia04bd252022-05-02 22:54:18 -07001490#ifdef CONFIG_IEEE80211BE
1491 if (full_config && !bss->disable_11be && bss->disable_11ax) {
1492 bss->disable_11be = true;
1493 wpa_printf(MSG_INFO,
1494 "Disabling IEEE 802.11be as IEEE 802.11ax is disabled for this BSS");
1495 }
1496#endif /* CONFIG_IEEE80211BE */
1497
Sunil Ravi77d572f2023-01-17 23:58:31 +00001498 if (full_config && bss->ignore_broadcast_ssid && conf->mbssid) {
1499 wpa_printf(MSG_ERROR,
1500 "Hidden SSID is not suppored when MBSSID is enabled");
1501 return -1;
1502 }
1503
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001504 return 0;
1505}
1506
1507
Dmitry Shmidt05df46a2015-05-19 11:02:01 -07001508static int hostapd_config_check_cw(struct hostapd_config *conf, int queue)
1509{
1510 int tx_cwmin = conf->tx_queue[queue].cwmin;
1511 int tx_cwmax = conf->tx_queue[queue].cwmax;
1512 int ac_cwmin = conf->wmm_ac_params[queue].cwmin;
1513 int ac_cwmax = conf->wmm_ac_params[queue].cwmax;
1514
1515 if (tx_cwmin > tx_cwmax) {
1516 wpa_printf(MSG_ERROR,
1517 "Invalid TX queue cwMin/cwMax values. cwMin(%d) greater than cwMax(%d)",
1518 tx_cwmin, tx_cwmax);
1519 return -1;
1520 }
1521 if (ac_cwmin > ac_cwmax) {
1522 wpa_printf(MSG_ERROR,
1523 "Invalid WMM AC cwMin/cwMax values. cwMin(%d) greater than cwMax(%d)",
1524 ac_cwmin, ac_cwmax);
1525 return -1;
1526 }
1527 return 0;
1528}
1529
1530
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001531int hostapd_config_check(struct hostapd_config *conf, int full_config)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001532{
1533 size_t i;
1534
Sunil Ravia04bd252022-05-02 22:54:18 -07001535 if (full_config && is_6ghz_op_class(conf->op_class) &&
1536 !conf->hw_mode_set) {
1537 /* Use the appropriate hw_mode value automatically when the
1538 * op_class parameter has been set, but hw_mode was not. */
1539 conf->hw_mode = HOSTAPD_MODE_IEEE80211A;
1540 }
1541
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001542 if (full_config && conf->ieee80211d &&
1543 (!conf->country[0] || !conf->country[1])) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001544 wpa_printf(MSG_ERROR, "Cannot enable IEEE 802.11d without "
1545 "setting the country_code");
1546 return -1;
1547 }
1548
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001549 if (full_config && conf->ieee80211h && !conf->ieee80211d) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001550 wpa_printf(MSG_ERROR, "Cannot enable IEEE 802.11h without "
1551 "IEEE 802.11d enabled");
1552 return -1;
1553 }
1554
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001555 if (full_config && conf->local_pwr_constraint != -1 &&
1556 !conf->ieee80211d) {
1557 wpa_printf(MSG_ERROR, "Cannot add Power Constraint element without Country element");
1558 return -1;
1559 }
1560
1561 if (full_config && conf->spectrum_mgmt_required &&
1562 conf->local_pwr_constraint == -1) {
1563 wpa_printf(MSG_ERROR, "Cannot set Spectrum Management bit without Country and Power Constraint elements");
1564 return -1;
1565 }
1566
Hai Shalom81f62d82019-07-22 12:10:00 -07001567#ifdef CONFIG_AIRTIME_POLICY
1568 if (full_config && conf->airtime_mode > AIRTIME_MODE_STATIC &&
1569 !conf->airtime_update_interval) {
1570 wpa_printf(MSG_ERROR, "Airtime update interval cannot be zero");
1571 return -1;
1572 }
1573#endif /* CONFIG_AIRTIME_POLICY */
Dmitry Shmidt05df46a2015-05-19 11:02:01 -07001574 for (i = 0; i < NUM_TX_QUEUES; i++) {
1575 if (hostapd_config_check_cw(conf, i))
1576 return -1;
1577 }
1578
Sunil Ravia04bd252022-05-02 22:54:18 -07001579#ifdef CONFIG_IEEE80211BE
1580 if (full_config && conf->ieee80211be && !conf->ieee80211ax) {
1581 wpa_printf(MSG_ERROR,
1582 "Cannot set ieee80211be without ieee80211ax");
1583 return -1;
1584 }
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001585
1586 if (full_config)
1587 hostapd_set_and_check_bw320_offset(conf,
1588 conf->eht_bw320_offset);
Sunil Ravia04bd252022-05-02 22:54:18 -07001589#endif /* CONFIG_IEEE80211BE */
1590
Sunil Ravi77d572f2023-01-17 23:58:31 +00001591 if (full_config && conf->mbssid && !conf->ieee80211ax) {
1592 wpa_printf(MSG_ERROR,
1593 "Cannot enable multiple BSSID support without ieee80211ax");
1594 return -1;
1595 }
1596
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001597 for (i = 0; i < conf->num_bss; i++) {
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001598 if (hostapd_config_check_bss(conf->bss[i], conf, full_config))
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001599 return -1;
1600 }
1601
1602 return 0;
1603}
1604
1605
Dmitry Shmidt71757432014-06-02 13:50:35 -07001606void hostapd_set_security_params(struct hostapd_bss_config *bss,
1607 int full_config)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001608{
Hai Shalomfdcde762020-04-02 11:19:20 -07001609#ifdef CONFIG_WEP
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001610 if (bss->individual_wep_key_len == 0) {
1611 /* individual keys are not use; can use key idx0 for
1612 * broadcast keys */
1613 bss->broadcast_key_idx_min = 0;
1614 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001615#endif /* CONFIG_WEP */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001616
1617 if ((bss->wpa & 2) && bss->rsn_pairwise == 0)
1618 bss->rsn_pairwise = bss->wpa_pairwise;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001619 if (bss->group_cipher)
1620 bss->wpa_group = bss->group_cipher;
1621 else
1622 bss->wpa_group = wpa_select_ap_group_cipher(bss->wpa,
1623 bss->wpa_pairwise,
1624 bss->rsn_pairwise);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001625 if (!bss->wpa_group_rekey_set)
1626 bss->wpa_group_rekey = bss->wpa_group == WPA_CIPHER_TKIP ?
1627 600 : 86400;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001628
Dmitry Shmidt71757432014-06-02 13:50:35 -07001629 if (full_config) {
1630 bss->radius->auth_server = bss->radius->auth_servers;
1631 bss->radius->acct_server = bss->radius->acct_servers;
1632 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001633
1634 if (bss->wpa && bss->ieee802_1x) {
1635 bss->ssid.security_policy = SECURITY_WPA;
1636 } else if (bss->wpa) {
1637 bss->ssid.security_policy = SECURITY_WPA_PSK;
1638 } else if (bss->ieee802_1x) {
1639 int cipher = WPA_CIPHER_NONE;
1640 bss->ssid.security_policy = SECURITY_IEEE_802_1X;
Hai Shalomfdcde762020-04-02 11:19:20 -07001641#ifdef CONFIG_WEP
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001642 bss->ssid.wep.default_len = bss->default_wep_key_len;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001643 if (full_config && bss->default_wep_key_len) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001644 cipher = bss->default_wep_key_len >= 13 ?
1645 WPA_CIPHER_WEP104 : WPA_CIPHER_WEP40;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001646 } else if (full_config && bss->ssid.wep.keys_set) {
1647 if (bss->ssid.wep.len[0] >= 13)
1648 cipher = WPA_CIPHER_WEP104;
1649 else
1650 cipher = WPA_CIPHER_WEP40;
1651 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001652#endif /* CONFIG_WEP */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001653 bss->wpa_group = cipher;
1654 bss->wpa_pairwise = cipher;
1655 bss->rsn_pairwise = cipher;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001656 if (full_config)
1657 bss->wpa_key_mgmt = WPA_KEY_MGMT_IEEE8021X_NO_WPA;
Hai Shalomfdcde762020-04-02 11:19:20 -07001658#ifdef CONFIG_WEP
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001659 } else if (bss->ssid.wep.keys_set) {
1660 int cipher = WPA_CIPHER_WEP40;
1661 if (bss->ssid.wep.len[0] >= 13)
1662 cipher = WPA_CIPHER_WEP104;
1663 bss->ssid.security_policy = SECURITY_STATIC_WEP;
1664 bss->wpa_group = cipher;
1665 bss->wpa_pairwise = cipher;
1666 bss->rsn_pairwise = cipher;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001667 if (full_config)
1668 bss->wpa_key_mgmt = WPA_KEY_MGMT_NONE;
Hai Shalomfdcde762020-04-02 11:19:20 -07001669#endif /* CONFIG_WEP */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001670 } else if (bss->osen) {
1671 bss->ssid.security_policy = SECURITY_OSEN;
1672 bss->wpa_group = WPA_CIPHER_CCMP;
1673 bss->wpa_pairwise = 0;
1674 bss->rsn_pairwise = WPA_CIPHER_CCMP;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001675 } else {
1676 bss->ssid.security_policy = SECURITY_PLAINTEXT;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001677 if (full_config) {
1678 bss->wpa_group = WPA_CIPHER_NONE;
1679 bss->wpa_pairwise = WPA_CIPHER_NONE;
1680 bss->rsn_pairwise = WPA_CIPHER_NONE;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001681 bss->wpa_key_mgmt = WPA_KEY_MGMT_NONE;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001682 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001683 }
1684}
Hai Shalom74f70d42019-02-11 14:42:39 -08001685
1686
1687int hostapd_sae_pw_id_in_use(struct hostapd_bss_config *conf)
1688{
1689 int with_id = 0, without_id = 0;
1690 struct sae_password_entry *pw;
1691
1692 if (conf->ssid.wpa_passphrase)
1693 without_id = 1;
1694
1695 for (pw = conf->sae_passwords; pw; pw = pw->next) {
1696 if (pw->identifier)
1697 with_id = 1;
1698 else
1699 without_id = 1;
1700 if (with_id && without_id)
1701 break;
1702 }
1703
1704 if (with_id && !without_id)
1705 return 2;
1706 return with_id;
1707}
Hai Shalom899fcc72020-10-19 14:38:18 -07001708
1709
1710bool hostapd_sae_pk_in_use(struct hostapd_bss_config *conf)
1711{
1712#ifdef CONFIG_SAE_PK
1713 struct sae_password_entry *pw;
1714
1715 for (pw = conf->sae_passwords; pw; pw = pw->next) {
1716 if (pw->pk)
1717 return true;
1718 }
1719#endif /* CONFIG_SAE_PK */
1720
1721 return false;
1722}
1723
1724
1725#ifdef CONFIG_SAE_PK
1726bool hostapd_sae_pk_exclusively(struct hostapd_bss_config *conf)
1727{
1728 bool with_pk = false;
1729 struct sae_password_entry *pw;
1730
1731 if (conf->ssid.wpa_passphrase)
1732 return false;
1733
1734 for (pw = conf->sae_passwords; pw; pw = pw->next) {
1735 if (!pw->pk)
1736 return false;
1737 with_pk = true;
1738 }
1739
1740 return with_pk;
1741}
1742#endif /* CONFIG_SAE_PK */
Sunil Ravia04bd252022-05-02 22:54:18 -07001743
1744
1745int hostapd_acl_comp(const void *a, const void *b)
1746{
1747 const struct mac_acl_entry *aa = a;
1748 const struct mac_acl_entry *bb = b;
1749 return os_memcmp(aa->addr, bb->addr, sizeof(macaddr));
1750}
1751
1752
1753int hostapd_add_acl_maclist(struct mac_acl_entry **acl, int *num,
1754 int vlan_id, const u8 *addr)
1755{
1756 struct mac_acl_entry *newacl;
1757
1758 newacl = os_realloc_array(*acl, *num + 1, sizeof(**acl));
1759 if (!newacl) {
1760 wpa_printf(MSG_ERROR, "MAC list reallocation failed");
1761 return -1;
1762 }
1763
1764 *acl = newacl;
1765 os_memcpy((*acl)[*num].addr, addr, ETH_ALEN);
1766 os_memset(&(*acl)[*num].vlan_id, 0, sizeof((*acl)[*num].vlan_id));
1767 (*acl)[*num].vlan_id.untagged = vlan_id;
1768 (*acl)[*num].vlan_id.notempty = !!vlan_id;
1769 (*num)++;
1770
1771 return 0;
1772}
1773
1774
1775void hostapd_remove_acl_mac(struct mac_acl_entry **acl, int *num,
1776 const u8 *addr)
1777{
1778 int i = 0;
1779
1780 while (i < *num) {
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001781 if (ether_addr_equal((*acl)[i].addr, addr)) {
Sunil Ravia04bd252022-05-02 22:54:18 -07001782 os_remove_in_array(*acl, *num, sizeof(**acl), i);
1783 (*num)--;
1784 } else {
1785 i++;
1786 }
1787 }
1788}