blob: 5dc8a8f04f6df4f5f9de43798a97c616cc24334c [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;
172#endif /* CONFIG_PASN */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700173}
174
175
176struct hostapd_config * hostapd_config_defaults(void)
177{
178#define ecw2cw(ecw) ((1 << (ecw)) - 1)
179
180 struct hostapd_config *conf;
181 struct hostapd_bss_config *bss;
182 const int aCWmin = 4, aCWmax = 10;
183 const struct hostapd_wmm_ac_params ac_bk =
184 { aCWmin, aCWmax, 7, 0, 0 }; /* background traffic */
185 const struct hostapd_wmm_ac_params ac_be =
186 { aCWmin, aCWmax, 3, 0, 0 }; /* best effort traffic */
187 const struct hostapd_wmm_ac_params ac_vi = /* video traffic */
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700188 { aCWmin - 1, aCWmin, 2, 3008 / 32, 0 };
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700189 const struct hostapd_wmm_ac_params ac_vo = /* voice traffic */
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700190 { aCWmin - 2, aCWmin - 1, 2, 1504 / 32, 0 };
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700191 const struct hostapd_tx_queue_params txq_bk =
192 { 7, ecw2cw(aCWmin), ecw2cw(aCWmax), 0 };
193 const struct hostapd_tx_queue_params txq_be =
194 { 3, ecw2cw(aCWmin), 4 * (ecw2cw(aCWmin) + 1) - 1, 0};
195 const struct hostapd_tx_queue_params txq_vi =
196 { 1, (ecw2cw(aCWmin) + 1) / 2 - 1, ecw2cw(aCWmin), 30};
197 const struct hostapd_tx_queue_params txq_vo =
198 { 1, (ecw2cw(aCWmin) + 1) / 4 - 1,
199 (ecw2cw(aCWmin) + 1) / 2 - 1, 15};
200
201#undef ecw2cw
202
203 conf = os_zalloc(sizeof(*conf));
204 bss = os_zalloc(sizeof(*bss));
205 if (conf == NULL || bss == NULL) {
206 wpa_printf(MSG_ERROR, "Failed to allocate memory for "
207 "configuration data.");
208 os_free(conf);
209 os_free(bss);
210 return NULL;
211 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800212 conf->bss = os_calloc(1, sizeof(struct hostapd_bss_config *));
213 if (conf->bss == NULL) {
214 os_free(conf);
215 os_free(bss);
216 return NULL;
217 }
218 conf->bss[0] = bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700219
220 bss->radius = os_zalloc(sizeof(*bss->radius));
221 if (bss->radius == NULL) {
Dmitry Shmidt97672262014-02-03 13:02:54 -0800222 os_free(conf->bss);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700223 os_free(conf);
224 os_free(bss);
225 return NULL;
226 }
227
228 hostapd_config_defaults_bss(bss);
229
230 conf->num_bss = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700231
232 conf->beacon_int = 100;
Hai Shalom021b0b52019-04-10 11:17:58 -0700233 conf->rts_threshold = -2; /* use driver default: 2347 */
234 conf->fragm_threshold = -2; /* user driver default: 2346 */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800235 /* Set to invalid value means do not add Power Constraint IE */
236 conf->local_pwr_constraint = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700237
238 conf->wmm_ac_params[0] = ac_be;
239 conf->wmm_ac_params[1] = ac_bk;
240 conf->wmm_ac_params[2] = ac_vi;
241 conf->wmm_ac_params[3] = ac_vo;
242
243 conf->tx_queue[0] = txq_vo;
244 conf->tx_queue[1] = txq_vi;
245 conf->tx_queue[2] = txq_be;
246 conf->tx_queue[3] = txq_bk;
247
248 conf->ht_capab = HT_CAP_INFO_SMPS_DISABLED;
249
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800250 conf->ap_table_max_size = 255;
251 conf->ap_table_expiration_time = 60;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800252 conf->track_sta_max_age = 180;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800253
Dmitry Shmidt8da800a2013-04-24 12:57:01 -0700254#ifdef CONFIG_TESTING_OPTIONS
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700255 conf->ignore_probe_probability = 0.0;
256 conf->ignore_auth_probability = 0.0;
257 conf->ignore_assoc_probability = 0.0;
258 conf->ignore_reassoc_probability = 0.0;
259 conf->corrupt_gtk_rekey_mic_probability = 0.0;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800260 conf->ecsa_ie_only = 0;
Kai Shie75b0652020-11-24 20:31:29 -0800261 conf->skip_send_eapol = 0;
262 conf->enable_eapol_large_timeout = 0;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -0700263#endif /* CONFIG_TESTING_OPTIONS */
264
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700265 conf->acs = 0;
266 conf->acs_ch_list.num = 0;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700267#ifdef CONFIG_ACS
268 conf->acs_num_scans = 5;
269#endif /* CONFIG_ACS */
270
Hai Shalom81f62d82019-07-22 12:10:00 -0700271#ifdef CONFIG_IEEE80211AX
272 conf->he_op.he_rts_threshold = HE_OPERATION_RTS_THRESHOLD_MASK >>
273 HE_OPERATION_RTS_THRESHOLD_OFFSET;
274 /* Set default basic MCS/NSS set to single stream MCS 0-7 */
275 conf->he_op.he_basic_mcs_nss_set = 0xfffc;
Hai Shalomfdcde762020-04-02 11:19:20 -0700276 conf->he_op.he_bss_color_disabled = 1;
277 conf->he_op.he_bss_color_partial = 0;
Hai Shaloma20dcd72022-02-04 13:43:00 -0800278 conf->he_op.he_bss_color = os_random() % 63 + 1;
279 conf->he_op.he_twt_responder = 1;
Hai Shalom60840252021-02-19 19:02:11 -0800280 conf->he_6ghz_max_mpdu = 2;
281 conf->he_6ghz_max_ampdu_len_exp = 7;
282 conf->he_6ghz_rx_ant_pat = 1;
283 conf->he_6ghz_tx_ant_pat = 1;
Hai Shalom81f62d82019-07-22 12:10:00 -0700284#endif /* CONFIG_IEEE80211AX */
285
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700286 /* The third octet of the country string uses an ASCII space character
287 * by default to indicate that the regulations encompass all
288 * environments for the current frequency band in the country. */
289 conf->country[2] = ' ';
290
Hai Shalom74f70d42019-02-11 14:42:39 -0800291 conf->rssi_reject_assoc_rssi = 0;
292 conf->rssi_reject_assoc_timeout = 30;
293
Hai Shalom81f62d82019-07-22 12:10:00 -0700294#ifdef CONFIG_AIRTIME_POLICY
295 conf->airtime_update_interval = AIRTIME_DEFAULT_UPDATE_INTERVAL;
296#endif /* CONFIG_AIRTIME_POLICY */
297
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700298 return conf;
299}
300
301
302int hostapd_mac_comp(const void *a, const void *b)
303{
304 return os_memcmp(a, b, sizeof(macaddr));
305}
306
307
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700308static int hostapd_config_read_wpa_psk(const char *fname,
309 struct hostapd_ssid *ssid)
310{
311 FILE *f;
312 char buf[128], *pos;
Hai Shalom74f70d42019-02-11 14:42:39 -0800313 const char *keyid;
314 char *context;
315 char *context2;
316 char *token;
317 char *name;
318 char *value;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700319 int line = 0, ret = 0, len, ok;
320 u8 addr[ETH_ALEN];
321 struct hostapd_wpa_psk *psk;
322
323 if (!fname)
324 return 0;
325
326 f = fopen(fname, "r");
327 if (!f) {
328 wpa_printf(MSG_ERROR, "WPA PSK file '%s' not found.", fname);
329 return -1;
330 }
331
332 while (fgets(buf, sizeof(buf), f)) {
Hai Shalom021b0b52019-04-10 11:17:58 -0700333 int vlan_id = 0;
Hai Shalomfdcde762020-04-02 11:19:20 -0700334 int wps = 0;
Hai Shalom021b0b52019-04-10 11:17:58 -0700335
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700336 line++;
337
338 if (buf[0] == '#')
339 continue;
340 pos = buf;
341 while (*pos != '\0') {
342 if (*pos == '\n') {
343 *pos = '\0';
344 break;
345 }
346 pos++;
347 }
348 if (buf[0] == '\0')
349 continue;
350
Hai Shalom74f70d42019-02-11 14:42:39 -0800351 context = NULL;
352 keyid = NULL;
353 while ((token = str_token(buf, " ", &context))) {
354 if (!os_strchr(token, '='))
355 break;
356 context2 = NULL;
357 name = str_token(token, "=", &context2);
Hai Shalom021b0b52019-04-10 11:17:58 -0700358 if (!name)
359 break;
Hai Shalom74f70d42019-02-11 14:42:39 -0800360 value = str_token(token, "", &context2);
361 if (!value)
362 value = "";
363 if (!os_strcmp(name, "keyid")) {
364 keyid = value;
Hai Shalomfdcde762020-04-02 11:19:20 -0700365 } else if (!os_strcmp(name, "wps")) {
366 wps = atoi(value);
Hai Shalom021b0b52019-04-10 11:17:58 -0700367 } else if (!os_strcmp(name, "vlanid")) {
368 vlan_id = atoi(value);
Hai Shalom74f70d42019-02-11 14:42:39 -0800369 } else {
370 wpa_printf(MSG_ERROR,
371 "Unrecognized '%s=%s' on line %d in '%s'",
372 name, value, line, fname);
373 ret = -1;
374 break;
375 }
376 }
377
378 if (ret == -1)
379 break;
380
381 if (!token)
382 token = "";
383 if (hwaddr_aton(token, addr)) {
Hai Shalomfdcde762020-04-02 11:19:20 -0700384 wpa_printf(MSG_ERROR,
385 "Invalid MAC address '%s' on line %d in '%s'",
386 token, line, fname);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700387 ret = -1;
388 break;
389 }
390
391 psk = os_zalloc(sizeof(*psk));
392 if (psk == NULL) {
393 wpa_printf(MSG_ERROR, "WPA PSK allocation failed");
394 ret = -1;
395 break;
396 }
Hai Shalom021b0b52019-04-10 11:17:58 -0700397 psk->vlan_id = vlan_id;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700398 if (is_zero_ether_addr(addr))
399 psk->group = 1;
400 else
401 os_memcpy(psk->addr, addr, ETH_ALEN);
402
Hai Shalom74f70d42019-02-11 14:42:39 -0800403 pos = str_token(buf, "", &context);
404 if (!pos) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700405 wpa_printf(MSG_ERROR, "No PSK on line %d in '%s'",
406 line, fname);
407 os_free(psk);
408 ret = -1;
409 break;
410 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700411
412 ok = 0;
413 len = os_strlen(pos);
Hai Shalomfdcde762020-04-02 11:19:20 -0700414 if (len == 2 * PMK_LEN &&
415 hexstr2bin(pos, psk->psk, PMK_LEN) == 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700416 ok = 1;
Hai Shalomfdcde762020-04-02 11:19:20 -0700417 else if (len >= 8 && len < 64 &&
418 pbkdf2_sha1(pos, ssid->ssid, ssid->ssid_len,
419 4096, psk->psk, PMK_LEN) == 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700420 ok = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700421 if (!ok) {
Hai Shalomfdcde762020-04-02 11:19:20 -0700422 wpa_printf(MSG_ERROR,
423 "Invalid PSK '%s' on line %d in '%s'",
424 pos, line, fname);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700425 os_free(psk);
426 ret = -1;
427 break;
428 }
429
Hai Shalom74f70d42019-02-11 14:42:39 -0800430 if (keyid) {
431 len = os_strlcpy(psk->keyid, keyid, sizeof(psk->keyid));
432 if ((size_t) len >= sizeof(psk->keyid)) {
433 wpa_printf(MSG_ERROR,
434 "PSK keyid too long on line %d in '%s'",
435 line, fname);
436 os_free(psk);
437 ret = -1;
438 break;
439 }
440 }
441
Hai Shalomfdcde762020-04-02 11:19:20 -0700442 psk->wps = wps;
443
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700444 psk->next = ssid->wpa_psk;
445 ssid->wpa_psk = psk;
446 }
447
448 fclose(f);
449
450 return ret;
451}
452
453
454static int hostapd_derive_psk(struct hostapd_ssid *ssid)
455{
456 ssid->wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
457 if (ssid->wpa_psk == NULL) {
458 wpa_printf(MSG_ERROR, "Unable to alloc space for PSK");
459 return -1;
460 }
461 wpa_hexdump_ascii(MSG_DEBUG, "SSID",
462 (u8 *) ssid->ssid, ssid->ssid_len);
463 wpa_hexdump_ascii_key(MSG_DEBUG, "PSK (ASCII passphrase)",
464 (u8 *) ssid->wpa_passphrase,
465 os_strlen(ssid->wpa_passphrase));
Sunil Ravia04bd252022-05-02 22:54:18 -0700466 if (pbkdf2_sha1(ssid->wpa_passphrase,
467 ssid->ssid, ssid->ssid_len,
468 4096, ssid->wpa_psk->psk, PMK_LEN) != 0) {
469 wpa_printf(MSG_ERROR, "Error in pbkdf2_sha1()");
470 return -1;
471 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700472 wpa_hexdump_key(MSG_DEBUG, "PSK (from passphrase)",
473 ssid->wpa_psk->psk, PMK_LEN);
474 return 0;
475}
476
477
Hai Shalomc3565922019-10-28 11:58:20 -0700478int hostapd_setup_sae_pt(struct hostapd_bss_config *conf)
479{
480#ifdef CONFIG_SAE
481 struct hostapd_ssid *ssid = &conf->ssid;
482 struct sae_password_entry *pw;
483
Sunil Ravi77d572f2023-01-17 23:58:31 +0000484 if ((conf->sae_pwe == SAE_PWE_HUNT_AND_PECK &&
485 !hostapd_sae_pw_id_in_use(conf) &&
Sunil Ravi89eba102022-09-13 21:04:37 -0700486 !wpa_key_mgmt_sae_ext_key(conf->wpa_key_mgmt) &&
Hai Shalom899fcc72020-10-19 14:38:18 -0700487 !hostapd_sae_pk_in_use(conf)) ||
Sunil Ravi77d572f2023-01-17 23:58:31 +0000488 conf->sae_pwe == SAE_PWE_FORCE_HUNT_AND_PECK ||
Hai Shalomfdcde762020-04-02 11:19:20 -0700489 !wpa_key_mgmt_sae(conf->wpa_key_mgmt))
Hai Shalomc3565922019-10-28 11:58:20 -0700490 return 0; /* PT not needed */
491
492 sae_deinit_pt(ssid->pt);
493 ssid->pt = NULL;
494 if (ssid->wpa_passphrase) {
495 ssid->pt = sae_derive_pt(conf->sae_groups, ssid->ssid,
496 ssid->ssid_len,
497 (const u8 *) ssid->wpa_passphrase,
498 os_strlen(ssid->wpa_passphrase),
499 NULL);
500 if (!ssid->pt)
501 return -1;
502 }
503
504 for (pw = conf->sae_passwords; pw; pw = pw->next) {
505 sae_deinit_pt(pw->pt);
506 pw->pt = sae_derive_pt(conf->sae_groups, ssid->ssid,
507 ssid->ssid_len,
508 (const u8 *) pw->password,
509 os_strlen(pw->password),
510 pw->identifier);
511 if (!pw->pt)
512 return -1;
513 }
514#endif /* CONFIG_SAE */
515
516 return 0;
517}
518
519
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700520int hostapd_setup_wpa_psk(struct hostapd_bss_config *conf)
521{
522 struct hostapd_ssid *ssid = &conf->ssid;
523
Hai Shalomc3565922019-10-28 11:58:20 -0700524 if (hostapd_setup_sae_pt(conf) < 0)
525 return -1;
526
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700527 if (ssid->wpa_passphrase != NULL) {
528 if (ssid->wpa_psk != NULL) {
529 wpa_printf(MSG_DEBUG, "Using pre-configured WPA PSK "
530 "instead of passphrase");
531 } else {
532 wpa_printf(MSG_DEBUG, "Deriving WPA PSK based on "
533 "passphrase");
534 if (hostapd_derive_psk(ssid) < 0)
535 return -1;
536 }
537 ssid->wpa_psk->group = 1;
538 }
539
Dmitry Shmidt29333592017-01-09 12:27:11 -0800540 return hostapd_config_read_wpa_psk(ssid->wpa_psk_file, &conf->ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700541}
542
543
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700544static void hostapd_config_free_radius(struct hostapd_radius_server *servers,
545 int num_servers)
546{
547 int i;
548
549 for (i = 0; i < num_servers; i++) {
550 os_free(servers[i].shared_secret);
551 }
552 os_free(servers);
553}
554
555
Dmitry Shmidt04949592012-07-19 12:16:46 -0700556struct hostapd_radius_attr *
557hostapd_config_get_radius_attr(struct hostapd_radius_attr *attr, u8 type)
558{
559 for (; attr; attr = attr->next) {
560 if (attr->type == type)
561 return attr;
562 }
563 return NULL;
564}
565
566
Hai Shalomc3565922019-10-28 11:58:20 -0700567struct hostapd_radius_attr * hostapd_parse_radius_attr(const char *value)
568{
569 const char *pos;
570 char syntax;
571 struct hostapd_radius_attr *attr;
572 size_t len;
573
574 attr = os_zalloc(sizeof(*attr));
575 if (!attr)
576 return NULL;
577
578 attr->type = atoi(value);
579
580 pos = os_strchr(value, ':');
581 if (!pos) {
582 attr->val = wpabuf_alloc(1);
583 if (!attr->val) {
584 os_free(attr);
585 return NULL;
586 }
587 wpabuf_put_u8(attr->val, 0);
588 return attr;
589 }
590
591 pos++;
592 if (pos[0] == '\0' || pos[1] != ':') {
593 os_free(attr);
594 return NULL;
595 }
596 syntax = *pos++;
597 pos++;
598
599 switch (syntax) {
600 case 's':
601 attr->val = wpabuf_alloc_copy(pos, os_strlen(pos));
602 break;
603 case 'x':
604 len = os_strlen(pos);
605 if (len & 1)
606 break;
607 len /= 2;
608 attr->val = wpabuf_alloc(len);
609 if (!attr->val)
610 break;
611 if (hexstr2bin(pos, wpabuf_put(attr->val, len), len) < 0) {
612 wpabuf_free(attr->val);
613 os_free(attr);
614 return NULL;
615 }
616 break;
617 case 'd':
618 attr->val = wpabuf_alloc(4);
619 if (attr->val)
620 wpabuf_put_be32(attr->val, atoi(pos));
621 break;
622 default:
623 os_free(attr);
624 return NULL;
625 }
626
627 if (!attr->val) {
628 os_free(attr);
629 return NULL;
630 }
631
632 return attr;
633}
634
635
636void hostapd_config_free_radius_attr(struct hostapd_radius_attr *attr)
Dmitry Shmidt04949592012-07-19 12:16:46 -0700637{
638 struct hostapd_radius_attr *prev;
639
640 while (attr) {
641 prev = attr;
642 attr = attr->next;
643 wpabuf_free(prev->val);
644 os_free(prev);
645 }
646}
647
648
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700649void hostapd_config_free_eap_user(struct hostapd_eap_user *user)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700650{
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700651 hostapd_config_free_radius_attr(user->accept_attr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700652 os_free(user->identity);
Dmitry Shmidtc2817022014-07-02 10:32:10 -0700653 bin_clear_free(user->password, user->password_len);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700654 bin_clear_free(user->salt, user->salt_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700655 os_free(user);
656}
657
658
Dmitry Shmidt29333592017-01-09 12:27:11 -0800659void hostapd_config_free_eap_users(struct hostapd_eap_user *user)
660{
661 struct hostapd_eap_user *prev_user;
662
663 while (user) {
664 prev_user = user;
665 user = user->next;
666 hostapd_config_free_eap_user(prev_user);
667 }
668}
669
670
Hai Shalomfdcde762020-04-02 11:19:20 -0700671#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700672static void hostapd_config_free_wep(struct hostapd_wep_keys *keys)
673{
674 int i;
675 for (i = 0; i < NUM_WEP_KEYS; i++) {
Dmitry Shmidtc2817022014-07-02 10:32:10 -0700676 bin_clear_free(keys->key[i], keys->len[i]);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700677 keys->key[i] = NULL;
678 }
679}
Hai Shalomfdcde762020-04-02 11:19:20 -0700680#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700681
682
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800683void hostapd_config_clear_wpa_psk(struct hostapd_wpa_psk **l)
684{
685 struct hostapd_wpa_psk *psk, *tmp;
686
687 for (psk = *l; psk;) {
688 tmp = psk;
689 psk = psk->next;
690 bin_clear_free(tmp, sizeof(*tmp));
691 }
692 *l = NULL;
693}
694
695
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800696static void hostapd_config_free_anqp_elem(struct hostapd_bss_config *conf)
697{
698 struct anqp_element *elem;
699
700 while ((elem = dl_list_first(&conf->anqp_elem, struct anqp_element,
701 list))) {
702 dl_list_del(&elem->list);
703 wpabuf_free(elem->payload);
704 os_free(elem);
705 }
706}
707
708
Dmitry Shmidt29333592017-01-09 12:27:11 -0800709static void hostapd_config_free_fils_realms(struct hostapd_bss_config *conf)
710{
711#ifdef CONFIG_FILS
712 struct fils_realm *realm;
713
714 while ((realm = dl_list_first(&conf->fils_realms, struct fils_realm,
715 list))) {
716 dl_list_del(&realm->list);
717 os_free(realm);
718 }
719#endif /* CONFIG_FILS */
720}
721
722
Roshan Pius3a1667e2018-07-03 15:17:14 -0700723static void hostapd_config_free_sae_passwords(struct hostapd_bss_config *conf)
724{
725 struct sae_password_entry *pw, *tmp;
726
727 pw = conf->sae_passwords;
728 conf->sae_passwords = NULL;
729 while (pw) {
730 tmp = pw;
731 pw = pw->next;
732 str_clear_free(tmp->password);
733 os_free(tmp->identifier);
Hai Shalomc3565922019-10-28 11:58:20 -0700734#ifdef CONFIG_SAE
735 sae_deinit_pt(tmp->pt);
736#endif /* CONFIG_SAE */
Hai Shalom899fcc72020-10-19 14:38:18 -0700737#ifdef CONFIG_SAE_PK
738 sae_deinit_pk(tmp->pk);
739#endif /* CONFIG_SAE_PK */
Roshan Pius3a1667e2018-07-03 15:17:14 -0700740 os_free(tmp);
741 }
742}
743
744
Hai Shalom81f62d82019-07-22 12:10:00 -0700745#ifdef CONFIG_DPP2
746static void hostapd_dpp_controller_conf_free(struct dpp_controller_conf *conf)
747{
748 struct dpp_controller_conf *prev;
749
750 while (conf) {
751 prev = conf;
752 conf = conf->next;
753 os_free(prev);
754 }
755}
756#endif /* CONFIG_DPP2 */
757
758
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800759void hostapd_config_free_bss(struct hostapd_bss_config *conf)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700760{
Hai Shalom81f62d82019-07-22 12:10:00 -0700761#if defined(CONFIG_WPS) || defined(CONFIG_HS20)
762 size_t i;
763#endif
764
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700765 if (conf == NULL)
766 return;
767
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800768 hostapd_config_clear_wpa_psk(&conf->ssid.wpa_psk);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700769
Dmitry Shmidtc2817022014-07-02 10:32:10 -0700770 str_clear_free(conf->ssid.wpa_passphrase);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700771 os_free(conf->ssid.wpa_psk_file);
Hai Shalomfdcde762020-04-02 11:19:20 -0700772#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700773 hostapd_config_free_wep(&conf->ssid.wep);
Hai Shalomfdcde762020-04-02 11:19:20 -0700774#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700775#ifdef CONFIG_FULL_DYNAMIC_VLAN
776 os_free(conf->ssid.vlan_tagged_interface);
777#endif /* CONFIG_FULL_DYNAMIC_VLAN */
Hai Shalomc3565922019-10-28 11:58:20 -0700778#ifdef CONFIG_SAE
779 sae_deinit_pt(conf->ssid.pt);
780#endif /* CONFIG_SAE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700781
Dmitry Shmidt29333592017-01-09 12:27:11 -0800782 hostapd_config_free_eap_users(conf->eap_user);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800783 os_free(conf->eap_user_sqlite);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700784
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700785 os_free(conf->eap_req_id_text);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800786 os_free(conf->erp_domain);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700787 os_free(conf->accept_mac);
788 os_free(conf->deny_mac);
789 os_free(conf->nas_identifier);
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800790 if (conf->radius) {
791 hostapd_config_free_radius(conf->radius->auth_servers,
792 conf->radius->num_auth_servers);
793 hostapd_config_free_radius(conf->radius->acct_servers,
794 conf->radius->num_acct_servers);
Hai Shaloma20dcd72022-02-04 13:43:00 -0800795 os_free(conf->radius->force_client_dev);
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800796 }
Dmitry Shmidt04949592012-07-19 12:16:46 -0700797 hostapd_config_free_radius_attr(conf->radius_auth_req_attr);
798 hostapd_config_free_radius_attr(conf->radius_acct_req_attr);
Hai Shalomc3565922019-10-28 11:58:20 -0700799 os_free(conf->radius_req_attr_sqlite);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700800 os_free(conf->rsn_preauth_interfaces);
801 os_free(conf->ctrl_interface);
Sunil Ravi77d572f2023-01-17 23:58:31 +0000802 os_free(conf->config_id);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700803 os_free(conf->ca_cert);
804 os_free(conf->server_cert);
Hai Shalom81f62d82019-07-22 12:10:00 -0700805 os_free(conf->server_cert2);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700806 os_free(conf->private_key);
Hai Shalom81f62d82019-07-22 12:10:00 -0700807 os_free(conf->private_key2);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700808 os_free(conf->private_key_passwd);
Hai Shalom81f62d82019-07-22 12:10:00 -0700809 os_free(conf->private_key_passwd2);
Hai Shalom021b0b52019-04-10 11:17:58 -0700810 os_free(conf->check_cert_subject);
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700811 os_free(conf->ocsp_stapling_response);
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -0800812 os_free(conf->ocsp_stapling_response_multi);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700813 os_free(conf->dh_file);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800814 os_free(conf->openssl_ciphers);
Hai Shalom74f70d42019-02-11 14:42:39 -0800815 os_free(conf->openssl_ecdh_curves);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700816 os_free(conf->pac_opaque_encr_key);
817 os_free(conf->eap_fast_a_id);
818 os_free(conf->eap_fast_a_id_info);
819 os_free(conf->eap_sim_db);
Sunil Ravia04bd252022-05-02 22:54:18 -0700820 os_free(conf->imsi_privacy_key);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700821 os_free(conf->radius_server_clients);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700822 os_free(conf->radius);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700823 os_free(conf->radius_das_shared_secret);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700824 hostapd_config_free_vlan(conf);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800825 os_free(conf->time_zone);
826
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800827#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700828 {
829 struct ft_remote_r0kh *r0kh, *r0kh_prev;
830 struct ft_remote_r1kh *r1kh, *r1kh_prev;
831
832 r0kh = conf->r0kh_list;
833 conf->r0kh_list = NULL;
834 while (r0kh) {
835 r0kh_prev = r0kh;
836 r0kh = r0kh->next;
837 os_free(r0kh_prev);
838 }
839
840 r1kh = conf->r1kh_list;
841 conf->r1kh_list = NULL;
842 while (r1kh) {
843 r1kh_prev = r1kh;
844 r1kh = r1kh->next;
845 os_free(r1kh_prev);
846 }
847 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800848#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700849
850#ifdef CONFIG_WPS
851 os_free(conf->wps_pin_requests);
852 os_free(conf->device_name);
853 os_free(conf->manufacturer);
854 os_free(conf->model_name);
855 os_free(conf->model_number);
856 os_free(conf->serial_number);
857 os_free(conf->config_methods);
858 os_free(conf->ap_pin);
859 os_free(conf->extra_cred);
860 os_free(conf->ap_settings);
Hai Shalom021b0b52019-04-10 11:17:58 -0700861 hostapd_config_clear_wpa_psk(&conf->multi_ap_backhaul_ssid.wpa_psk);
862 str_clear_free(conf->multi_ap_backhaul_ssid.wpa_passphrase);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700863 os_free(conf->upnp_iface);
864 os_free(conf->friendly_name);
865 os_free(conf->manufacturer_url);
866 os_free(conf->model_description);
867 os_free(conf->model_url);
868 os_free(conf->upc);
Hai Shalom81f62d82019-07-22 12:10:00 -0700869 for (i = 0; i < MAX_WPS_VENDOR_EXTENSIONS; i++)
870 wpabuf_free(conf->wps_vendor_ext[i]);
Hai Shalomfdcde762020-04-02 11:19:20 -0700871 wpabuf_free(conf->wps_application_ext);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700872 wpabuf_free(conf->wps_nfc_dh_pubkey);
873 wpabuf_free(conf->wps_nfc_dh_privkey);
874 wpabuf_free(conf->wps_nfc_dev_pw);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700875#endif /* CONFIG_WPS */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800876
877 os_free(conf->roaming_consortium);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700878 os_free(conf->venue_name);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700879 os_free(conf->venue_url);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700880 os_free(conf->nai_realm_data);
881 os_free(conf->network_auth_type);
882 os_free(conf->anqp_3gpp_cell_net);
883 os_free(conf->domain_name);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800884 hostapd_config_free_anqp_elem(conf);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800885
886#ifdef CONFIG_RADIUS_TEST
887 os_free(conf->dump_msk_file);
888#endif /* CONFIG_RADIUS_TEST */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700889
890#ifdef CONFIG_HS20
891 os_free(conf->hs20_oper_friendly_name);
892 os_free(conf->hs20_wan_metrics);
893 os_free(conf->hs20_connection_capability);
894 os_free(conf->hs20_operating_class);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800895 os_free(conf->hs20_icons);
896 if (conf->hs20_osu_providers) {
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800897 for (i = 0; i < conf->hs20_osu_providers_count; i++) {
898 struct hs20_osu_provider *p;
899 size_t j;
900 p = &conf->hs20_osu_providers[i];
901 os_free(p->friendly_name);
902 os_free(p->server_uri);
903 os_free(p->method_list);
904 for (j = 0; j < p->icons_count; j++)
905 os_free(p->icons[j]);
906 os_free(p->icons);
907 os_free(p->osu_nai);
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800908 os_free(p->osu_nai2);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800909 os_free(p->service_desc);
910 }
911 os_free(conf->hs20_osu_providers);
912 }
Roshan Pius3a1667e2018-07-03 15:17:14 -0700913 if (conf->hs20_operator_icon) {
Roshan Pius3a1667e2018-07-03 15:17:14 -0700914 for (i = 0; i < conf->hs20_operator_icon_count; i++)
915 os_free(conf->hs20_operator_icon[i]);
916 os_free(conf->hs20_operator_icon);
917 }
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800918 os_free(conf->subscr_remediation_url);
Hai Shalom74f70d42019-02-11 14:42:39 -0800919 os_free(conf->hs20_sim_provisioning_url);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700920 os_free(conf->t_c_filename);
921 os_free(conf->t_c_server_url);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700922#endif /* CONFIG_HS20 */
923
924 wpabuf_free(conf->vendor_elements);
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700925 wpabuf_free(conf->assocresp_elements);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800926
927 os_free(conf->sae_groups);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700928#ifdef CONFIG_OWE
929 os_free(conf->owe_groups);
930#endif /* CONFIG_OWE */
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700931
Dmitry Shmidt0207e232014-09-03 14:58:37 -0700932 os_free(conf->wowlan_triggers);
933
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700934 os_free(conf->server_id);
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800935
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800936#ifdef CONFIG_TESTING_OPTIONS
937 wpabuf_free(conf->own_ie_override);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700938 wpabuf_free(conf->sae_commit_override);
Hai Shalomfdcde762020-04-02 11:19:20 -0700939 wpabuf_free(conf->rsne_override_eapol);
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800940 wpabuf_free(conf->rsnxe_override_eapol);
Hai Shalomfdcde762020-04-02 11:19:20 -0700941 wpabuf_free(conf->rsne_override_ft);
942 wpabuf_free(conf->rsnxe_override_ft);
943 wpabuf_free(conf->gtk_rsc_override);
944 wpabuf_free(conf->igtk_rsc_override);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800945#endif /* CONFIG_TESTING_OPTIONS */
946
947 os_free(conf->no_probe_resp_if_seen_on);
948 os_free(conf->no_auth_if_seen_on);
949
Dmitry Shmidt29333592017-01-09 12:27:11 -0800950 hostapd_config_free_fils_realms(conf);
951
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700952#ifdef CONFIG_DPP
Hai Shalomc3565922019-10-28 11:58:20 -0700953 os_free(conf->dpp_name);
954 os_free(conf->dpp_mud_url);
Sunil Ravi89eba102022-09-13 21:04:37 -0700955 os_free(conf->dpp_extra_conf_req_name);
956 os_free(conf->dpp_extra_conf_req_value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700957 os_free(conf->dpp_connector);
958 wpabuf_free(conf->dpp_netaccesskey);
959 wpabuf_free(conf->dpp_csign);
Hai Shalom81f62d82019-07-22 12:10:00 -0700960#ifdef CONFIG_DPP2
961 hostapd_dpp_controller_conf_free(conf->dpp_controller);
962#endif /* CONFIG_DPP2 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700963#endif /* CONFIG_DPP */
964
Roshan Pius3a1667e2018-07-03 15:17:14 -0700965 hostapd_config_free_sae_passwords(conf);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700966
Hai Shalom81f62d82019-07-22 12:10:00 -0700967#ifdef CONFIG_AIRTIME_POLICY
968 {
969 struct airtime_sta_weight *wt, *wt_prev;
970
971 wt = conf->airtime_weight_list;
972 conf->airtime_weight_list = NULL;
973 while (wt) {
974 wt_prev = wt;
975 wt = wt->next;
976 os_free(wt_prev);
977 }
978 }
979#endif /* CONFIG_AIRTIME_POLICY */
980
Hai Shalom60840252021-02-19 19:02:11 -0800981#ifdef CONFIG_PASN
982 os_free(conf->pasn_groups);
983#endif /* CONFIG_PASN */
984
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800985 os_free(conf);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700986}
987
988
989/**
990 * hostapd_config_free - Free hostapd configuration
991 * @conf: Configuration data from hostapd_config_read().
992 */
993void hostapd_config_free(struct hostapd_config *conf)
994{
995 size_t i;
996
997 if (conf == NULL)
998 return;
999
1000 for (i = 0; i < conf->num_bss; i++)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001001 hostapd_config_free_bss(conf->bss[i]);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001002 os_free(conf->bss);
1003 os_free(conf->supported_rates);
1004 os_free(conf->basic_rates);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07001005 os_free(conf->acs_ch_list.range);
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001006 os_free(conf->acs_freq_list.range);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001007 os_free(conf->driver_params);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001008#ifdef CONFIG_ACS
1009 os_free(conf->acs_chan_bias);
1010#endif /* CONFIG_ACS */
Dmitry Shmidt849734c2016-05-27 09:59:01 -07001011 wpabuf_free(conf->lci);
1012 wpabuf_free(conf->civic);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001013
1014 os_free(conf);
1015}
1016
1017
1018/**
1019 * hostapd_maclist_found - Find a MAC address from a list
1020 * @list: MAC address list
1021 * @num_entries: Number of addresses in the list
1022 * @addr: Address to search for
1023 * @vlan_id: Buffer for returning VLAN ID or %NULL if not needed
1024 * Returns: 1 if address is in the list or 0 if not.
1025 *
1026 * Perform a binary search for given MAC address from a pre-sorted list.
1027 */
1028int hostapd_maclist_found(struct mac_acl_entry *list, int num_entries,
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001029 const u8 *addr, struct vlan_description *vlan_id)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001030{
1031 int start, end, middle, res;
1032
1033 start = 0;
1034 end = num_entries - 1;
1035
1036 while (start <= end) {
1037 middle = (start + end) / 2;
1038 res = os_memcmp(list[middle].addr, addr, ETH_ALEN);
1039 if (res == 0) {
1040 if (vlan_id)
1041 *vlan_id = list[middle].vlan_id;
1042 return 1;
1043 }
1044 if (res < 0)
1045 start = middle + 1;
1046 else
1047 end = middle - 1;
1048 }
1049
1050 return 0;
1051}
1052
1053
1054int hostapd_rate_found(int *list, int rate)
1055{
1056 int i;
1057
1058 if (list == NULL)
1059 return 0;
1060
1061 for (i = 0; list[i] >= 0; i++)
1062 if (list[i] == rate)
1063 return 1;
1064
1065 return 0;
1066}
1067
1068
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001069int hostapd_vlan_valid(struct hostapd_vlan *vlan,
1070 struct vlan_description *vlan_desc)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001071{
1072 struct hostapd_vlan *v = vlan;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001073 int i;
1074
1075 if (!vlan_desc->notempty || vlan_desc->untagged < 0 ||
1076 vlan_desc->untagged > MAX_VLAN_ID)
1077 return 0;
1078 for (i = 0; i < MAX_NUM_TAGGED_VLAN; i++) {
1079 if (vlan_desc->tagged[i] < 0 ||
1080 vlan_desc->tagged[i] > MAX_VLAN_ID)
1081 return 0;
1082 }
1083 if (!vlan_desc->untagged && !vlan_desc->tagged[0])
1084 return 0;
1085
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001086 while (v) {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001087 if (!vlan_compare(&v->vlan_desc, vlan_desc) ||
1088 v->vlan_id == VLAN_ID_WILDCARD)
Dmitry Shmidt34af3062013-07-11 10:46:32 -07001089 return 1;
1090 v = v->next;
1091 }
1092 return 0;
1093}
1094
1095
1096const char * hostapd_get_vlan_id_ifname(struct hostapd_vlan *vlan, int vlan_id)
1097{
1098 struct hostapd_vlan *v = vlan;
1099 while (v) {
1100 if (v->vlan_id == vlan_id)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001101 return v->ifname;
1102 v = v->next;
1103 }
1104 return NULL;
1105}
1106
1107
1108const u8 * hostapd_get_psk(const struct hostapd_bss_config *conf,
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001109 const u8 *addr, const u8 *p2p_dev_addr,
Hai Shalom021b0b52019-04-10 11:17:58 -07001110 const u8 *prev_psk, int *vlan_id)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001111{
1112 struct hostapd_wpa_psk *psk;
1113 int next_ok = prev_psk == NULL;
1114
Hai Shalom021b0b52019-04-10 11:17:58 -07001115 if (vlan_id)
1116 *vlan_id = 0;
1117
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001118 if (p2p_dev_addr && !is_zero_ether_addr(p2p_dev_addr)) {
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001119 wpa_printf(MSG_DEBUG, "Searching a PSK for " MACSTR
1120 " p2p_dev_addr=" MACSTR " prev_psk=%p",
1121 MAC2STR(addr), MAC2STR(p2p_dev_addr), prev_psk);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001122 addr = NULL; /* Use P2P Device Address for matching */
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001123 } else {
1124 wpa_printf(MSG_DEBUG, "Searching a PSK for " MACSTR
1125 " prev_psk=%p",
1126 MAC2STR(addr), prev_psk);
1127 }
1128
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001129 for (psk = conf->ssid.wpa_psk; psk != NULL; psk = psk->next) {
1130 if (next_ok &&
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001131 (psk->group ||
1132 (addr && os_memcmp(psk->addr, addr, ETH_ALEN) == 0) ||
1133 (!addr && p2p_dev_addr &&
1134 os_memcmp(psk->p2p_dev_addr, p2p_dev_addr, ETH_ALEN) ==
Hai Shalom021b0b52019-04-10 11:17:58 -07001135 0))) {
1136 if (vlan_id)
1137 *vlan_id = psk->vlan_id;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001138 return psk->psk;
Hai Shalom021b0b52019-04-10 11:17:58 -07001139 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001140
1141 if (psk->psk == prev_psk)
1142 next_ok = 1;
1143 }
1144
1145 return NULL;
1146}
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001147
1148
Hai Shalom899fcc72020-10-19 14:38:18 -07001149#ifdef CONFIG_SAE_PK
1150static bool hostapd_sae_pk_password_without_pk(struct hostapd_bss_config *bss)
1151{
1152 struct sae_password_entry *pw;
1153 bool res = false;
1154
1155 if (bss->ssid.wpa_passphrase &&
1156#ifdef CONFIG_TESTING_OPTIONS
1157 !bss->sae_pk_password_check_skip &&
1158#endif /* CONFIG_TESTING_OPTIONS */
1159 sae_pk_valid_password(bss->ssid.wpa_passphrase))
1160 res = true;
1161
1162 for (pw = bss->sae_passwords; pw; pw = pw->next) {
1163 if (!pw->pk &&
1164#ifdef CONFIG_TESTING_OPTIONS
1165 !bss->sae_pk_password_check_skip &&
1166#endif /* CONFIG_TESTING_OPTIONS */
1167 sae_pk_valid_password(pw->password))
1168 return true;
1169
1170 if (bss->ssid.wpa_passphrase && res && pw->pk &&
1171 os_strcmp(bss->ssid.wpa_passphrase, pw->password) == 0)
1172 res = false;
1173 }
1174
1175 return res;
1176}
1177#endif /* CONFIG_SAE_PK */
1178
1179
Hai Shalom60840252021-02-19 19:02:11 -08001180static bool hostapd_config_check_bss_6g(struct hostapd_bss_config *bss)
1181{
1182 if (bss->wpa != WPA_PROTO_RSN) {
1183 wpa_printf(MSG_ERROR,
1184 "Pre-RSNA security methods are not allowed in 6 GHz");
1185 return false;
1186 }
1187
1188 if (bss->ieee80211w != MGMT_FRAME_PROTECTION_REQUIRED) {
1189 wpa_printf(MSG_ERROR,
1190 "Management frame protection is required in 6 GHz");
1191 return false;
1192 }
1193
1194 if (bss->wpa_key_mgmt & (WPA_KEY_MGMT_PSK |
1195 WPA_KEY_MGMT_FT_PSK |
1196 WPA_KEY_MGMT_PSK_SHA256)) {
1197 wpa_printf(MSG_ERROR, "Invalid AKM suite for 6 GHz");
1198 return false;
1199 }
1200
1201 if (bss->rsn_pairwise & (WPA_CIPHER_WEP40 |
1202 WPA_CIPHER_WEP104 |
1203 WPA_CIPHER_TKIP)) {
1204 wpa_printf(MSG_ERROR,
1205 "Invalid pairwise cipher suite for 6 GHz");
1206 return false;
1207 }
1208
1209 if (bss->wpa_group & (WPA_CIPHER_WEP40 |
1210 WPA_CIPHER_WEP104 |
1211 WPA_CIPHER_TKIP)) {
1212 wpa_printf(MSG_ERROR, "Invalid group cipher suite for 6 GHz");
1213 return false;
1214 }
1215
Sunil Ravi77d572f2023-01-17 23:58:31 +00001216#ifdef CONFIG_SAE
1217 if (wpa_key_mgmt_sae(bss->wpa_key_mgmt) &&
1218 bss->sae_pwe == SAE_PWE_HUNT_AND_PECK) {
1219 wpa_printf(MSG_INFO, "SAE: Enabling SAE H2E on 6 GHz");
1220 bss->sae_pwe = SAE_PWE_BOTH;
1221 }
1222#endif /* CONFIG_SAE */
1223
Hai Shalom60840252021-02-19 19:02:11 -08001224 return true;
1225}
1226
1227
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001228static int hostapd_config_check_bss(struct hostapd_bss_config *bss,
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001229 struct hostapd_config *conf,
1230 int full_config)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001231{
Hai Shalom60840252021-02-19 19:02:11 -08001232 if (full_config && is_6ghz_op_class(conf->op_class) &&
1233 !hostapd_config_check_bss_6g(bss))
1234 return -1;
1235
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001236 if (full_config && bss->ieee802_1x && !bss->eap_server &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001237 !bss->radius->auth_servers) {
1238 wpa_printf(MSG_ERROR, "Invalid IEEE 802.1X configuration (no "
1239 "EAP authenticator configured).");
1240 return -1;
1241 }
1242
Hai Shalomfdcde762020-04-02 11:19:20 -07001243#ifdef CONFIG_WEP
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001244 if (bss->wpa) {
1245 int wep, i;
1246
1247 wep = bss->default_wep_key_len > 0 ||
1248 bss->individual_wep_key_len > 0;
1249 for (i = 0; i < NUM_WEP_KEYS; i++) {
1250 if (bss->ssid.wep.keys_set) {
1251 wep = 1;
1252 break;
1253 }
1254 }
1255
1256 if (wep) {
1257 wpa_printf(MSG_ERROR, "WEP configuration in a WPA network is not supported");
1258 return -1;
1259 }
1260 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001261#endif /* CONFIG_WEP */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001262
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001263 if (full_config && bss->wpa &&
1264 bss->wpa_psk_radius != PSK_RADIUS_IGNORED &&
Sunil Ravia04bd252022-05-02 22:54:18 -07001265 bss->wpa_psk_radius != PSK_RADIUS_DURING_4WAY_HS &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001266 bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH) {
1267 wpa_printf(MSG_ERROR, "WPA-PSK using RADIUS enabled, but no "
1268 "RADIUS checking (macaddr_acl=2) enabled.");
1269 return -1;
1270 }
1271
Sunil Ravia04bd252022-05-02 22:54:18 -07001272 if (full_config && bss->wpa &&
1273 wpa_key_mgmt_wpa_psk_no_sae(bss->wpa_key_mgmt) &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001274 bss->ssid.wpa_psk == NULL && bss->ssid.wpa_passphrase == NULL &&
1275 bss->ssid.wpa_psk_file == NULL &&
Sunil Ravia04bd252022-05-02 22:54:18 -07001276 bss->wpa_psk_radius != PSK_RADIUS_DURING_4WAY_HS &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001277 (bss->wpa_psk_radius != PSK_RADIUS_REQUIRED ||
1278 bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH)) {
1279 wpa_printf(MSG_ERROR, "WPA-PSK enabled, but PSK or passphrase "
1280 "is not configured.");
1281 return -1;
1282 }
1283
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001284 if (full_config && !is_zero_ether_addr(bss->bssid)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001285 size_t i;
1286
1287 for (i = 0; i < conf->num_bss; i++) {
1288 if (conf->bss[i] != bss &&
1289 (hostapd_mac_comp(conf->bss[i]->bssid,
1290 bss->bssid) == 0)) {
1291 wpa_printf(MSG_ERROR, "Duplicate BSSID " MACSTR
1292 " on interface '%s' and '%s'.",
1293 MAC2STR(bss->bssid),
1294 conf->bss[i]->iface, bss->iface);
1295 return -1;
1296 }
1297 }
1298 }
1299
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001300#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001301 if (full_config && wpa_key_mgmt_ft(bss->wpa_key_mgmt) &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001302 (bss->nas_identifier == NULL ||
1303 os_strlen(bss->nas_identifier) < 1 ||
1304 os_strlen(bss->nas_identifier) > FT_R0KH_ID_MAX_LEN)) {
1305 wpa_printf(MSG_ERROR, "FT (IEEE 802.11r) requires "
1306 "nas_identifier to be configured as a 1..48 octet "
1307 "string");
1308 return -1;
1309 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001310#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001311
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001312 if (full_config && conf->ieee80211n &&
1313 conf->hw_mode == HOSTAPD_MODE_IEEE80211B) {
Hai Shalom60840252021-02-19 19:02:11 -08001314 bss->disable_11n = true;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001315 wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) in 11b mode is not "
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001316 "allowed, disabling HT capabilities");
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001317 }
1318
Hai Shalomfdcde762020-04-02 11:19:20 -07001319#ifdef CONFIG_WEP
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001320 if (full_config && conf->ieee80211n &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001321 bss->ssid.security_policy == SECURITY_STATIC_WEP) {
Hai Shalom60840252021-02-19 19:02:11 -08001322 bss->disable_11n = true;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001323 wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) with WEP is not "
1324 "allowed, disabling HT capabilities");
1325 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001326#endif /* CONFIG_WEP */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001327
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001328 if (full_config && conf->ieee80211n && bss->wpa &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001329 !(bss->wpa_pairwise & WPA_CIPHER_CCMP) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001330 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
1331 WPA_CIPHER_CCMP_256 | WPA_CIPHER_GCMP_256)))
1332 {
Hai Shalom60840252021-02-19 19:02:11 -08001333 bss->disable_11n = true;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001334 wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) with WPA/WPA2 "
1335 "requires CCMP/GCMP to be enabled, disabling HT "
1336 "capabilities");
1337 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001338
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07001339#ifdef CONFIG_IEEE80211AC
Hai Shalomfdcde762020-04-02 11:19:20 -07001340#ifdef CONFIG_WEP
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07001341 if (full_config && conf->ieee80211ac &&
1342 bss->ssid.security_policy == SECURITY_STATIC_WEP) {
Hai Shalom60840252021-02-19 19:02:11 -08001343 bss->disable_11ac = true;
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07001344 wpa_printf(MSG_ERROR,
1345 "VHT (IEEE 802.11ac) with WEP is not allowed, disabling VHT capabilities");
1346 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001347#endif /* CONFIG_WEP */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001348
1349 if (full_config && conf->ieee80211ac && bss->wpa &&
1350 !(bss->wpa_pairwise & WPA_CIPHER_CCMP) &&
1351 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
1352 WPA_CIPHER_CCMP_256 | WPA_CIPHER_GCMP_256)))
1353 {
Hai Shalom60840252021-02-19 19:02:11 -08001354 bss->disable_11ac = true;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001355 wpa_printf(MSG_ERROR,
1356 "VHT (IEEE 802.11ac) with WPA/WPA2 requires CCMP/GCMP to be enabled, disabling VHT capabilities");
1357 }
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07001358#endif /* CONFIG_IEEE80211AC */
1359
Hai Shalom60840252021-02-19 19:02:11 -08001360#ifdef CONFIG_IEEE80211AX
1361#ifdef CONFIG_WEP
1362 if (full_config && conf->ieee80211ax &&
1363 bss->ssid.security_policy == SECURITY_STATIC_WEP) {
1364 bss->disable_11ax = true;
1365 wpa_printf(MSG_ERROR,
1366 "HE (IEEE 802.11ax) with WEP is not allowed, disabling HE capabilities");
1367 }
1368#endif /* CONFIG_WEP */
1369
1370 if (full_config && conf->ieee80211ax && bss->wpa &&
1371 !(bss->wpa_pairwise & WPA_CIPHER_CCMP) &&
1372 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
1373 WPA_CIPHER_CCMP_256 | WPA_CIPHER_GCMP_256)))
1374 {
1375 bss->disable_11ax = true;
1376 wpa_printf(MSG_ERROR,
1377 "HE (IEEE 802.11ax) with WPA/WPA2 requires CCMP/GCMP to be enabled, disabling HE capabilities");
1378 }
1379#endif /* CONFIG_IEEE80211AX */
1380
Dmitry Shmidt15907092014-03-25 10:42:57 -07001381#ifdef CONFIG_WPS
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001382 if (full_config && bss->wps_state && bss->ignore_broadcast_ssid) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001383 wpa_printf(MSG_INFO, "WPS: ignore_broadcast_ssid "
1384 "configuration forced WPS to be disabled");
1385 bss->wps_state = 0;
1386 }
1387
Hai Shalomfdcde762020-04-02 11:19:20 -07001388#ifdef CONFIG_WEP
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001389 if (full_config && bss->wps_state &&
1390 bss->ssid.wep.keys_set && bss->wpa == 0) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001391 wpa_printf(MSG_INFO, "WPS: WEP configuration forced WPS to be "
1392 "disabled");
1393 bss->wps_state = 0;
1394 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001395#endif /* CONFIG_WEP */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001396
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001397 if (full_config && bss->wps_state && bss->wpa &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001398 (!(bss->wpa & 2) ||
Roshan Pius3a1667e2018-07-03 15:17:14 -07001399 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
1400 WPA_CIPHER_CCMP_256 |
1401 WPA_CIPHER_GCMP_256)))) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001402 wpa_printf(MSG_INFO, "WPS: WPA/TKIP configuration without "
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07001403 "WPA2/CCMP/GCMP forced WPS to be disabled");
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001404 bss->wps_state = 0;
1405 }
Dmitry Shmidt15907092014-03-25 10:42:57 -07001406#endif /* CONFIG_WPS */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001407
1408#ifdef CONFIG_HS20
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001409 if (full_config && bss->hs20 &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001410 (!(bss->wpa & 2) ||
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001411 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
1412 WPA_CIPHER_CCMP_256 |
1413 WPA_CIPHER_GCMP_256)))) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001414 wpa_printf(MSG_ERROR, "HS 2.0: WPA2-Enterprise/CCMP "
1415 "configuration is required for Hotspot 2.0 "
1416 "functionality");
1417 return -1;
1418 }
1419#endif /* CONFIG_HS20 */
1420
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001421#ifdef CONFIG_MBO
1422 if (full_config && bss->mbo_enabled && (bss->wpa & 2) &&
1423 bss->ieee80211w == NO_MGMT_FRAME_PROTECTION) {
1424 wpa_printf(MSG_ERROR,
1425 "MBO: PMF needs to be enabled whenever using WPA2 with MBO");
1426 return -1;
1427 }
1428#endif /* CONFIG_MBO */
1429
Hai Shalom74f70d42019-02-11 14:42:39 -08001430#ifdef CONFIG_OCV
1431 if (full_config && bss->ieee80211w == NO_MGMT_FRAME_PROTECTION &&
1432 bss->ocv) {
1433 wpa_printf(MSG_ERROR,
1434 "OCV: PMF needs to be enabled whenever using OCV");
1435 return -1;
1436 }
1437#endif /* CONFIG_OCV */
1438
Hai Shalom899fcc72020-10-19 14:38:18 -07001439#ifdef CONFIG_SAE_PK
1440 if (full_config && hostapd_sae_pk_in_use(bss) &&
1441 hostapd_sae_pk_password_without_pk(bss)) {
1442 wpa_printf(MSG_ERROR,
1443 "SAE-PK: SAE password uses SAE-PK style, but does not have PK configured");
1444 return -1;
1445 }
1446#endif /* CONFIG_SAE_PK */
1447
Hai Shaloma20dcd72022-02-04 13:43:00 -08001448#ifdef CONFIG_FILS
Sunil Ravia04bd252022-05-02 22:54:18 -07001449 if (full_config && bss->fils_discovery_max_int &&
Hai Shaloma20dcd72022-02-04 13:43:00 -08001450 bss->unsol_bcast_probe_resp_interval) {
1451 wpa_printf(MSG_ERROR,
1452 "Cannot enable both FILS discovery and unsolicited broadcast Probe Response at the same time");
1453 return -1;
1454 }
1455#endif /* CONFIG_FILS */
1456
Sunil Ravia04bd252022-05-02 22:54:18 -07001457#ifdef CONFIG_IEEE80211BE
1458 if (full_config && !bss->disable_11be && bss->disable_11ax) {
1459 bss->disable_11be = true;
1460 wpa_printf(MSG_INFO,
1461 "Disabling IEEE 802.11be as IEEE 802.11ax is disabled for this BSS");
1462 }
1463#endif /* CONFIG_IEEE80211BE */
1464
Sunil Ravi77d572f2023-01-17 23:58:31 +00001465 if (full_config && bss->ignore_broadcast_ssid && conf->mbssid) {
1466 wpa_printf(MSG_ERROR,
1467 "Hidden SSID is not suppored when MBSSID is enabled");
1468 return -1;
1469 }
1470
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001471 return 0;
1472}
1473
1474
Dmitry Shmidt05df46a2015-05-19 11:02:01 -07001475static int hostapd_config_check_cw(struct hostapd_config *conf, int queue)
1476{
1477 int tx_cwmin = conf->tx_queue[queue].cwmin;
1478 int tx_cwmax = conf->tx_queue[queue].cwmax;
1479 int ac_cwmin = conf->wmm_ac_params[queue].cwmin;
1480 int ac_cwmax = conf->wmm_ac_params[queue].cwmax;
1481
1482 if (tx_cwmin > tx_cwmax) {
1483 wpa_printf(MSG_ERROR,
1484 "Invalid TX queue cwMin/cwMax values. cwMin(%d) greater than cwMax(%d)",
1485 tx_cwmin, tx_cwmax);
1486 return -1;
1487 }
1488 if (ac_cwmin > ac_cwmax) {
1489 wpa_printf(MSG_ERROR,
1490 "Invalid WMM AC cwMin/cwMax values. cwMin(%d) greater than cwMax(%d)",
1491 ac_cwmin, ac_cwmax);
1492 return -1;
1493 }
1494 return 0;
1495}
1496
1497
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001498int hostapd_config_check(struct hostapd_config *conf, int full_config)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001499{
1500 size_t i;
1501
Sunil Ravia04bd252022-05-02 22:54:18 -07001502 if (full_config && is_6ghz_op_class(conf->op_class) &&
1503 !conf->hw_mode_set) {
1504 /* Use the appropriate hw_mode value automatically when the
1505 * op_class parameter has been set, but hw_mode was not. */
1506 conf->hw_mode = HOSTAPD_MODE_IEEE80211A;
1507 }
1508
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001509 if (full_config && conf->ieee80211d &&
1510 (!conf->country[0] || !conf->country[1])) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001511 wpa_printf(MSG_ERROR, "Cannot enable IEEE 802.11d without "
1512 "setting the country_code");
1513 return -1;
1514 }
1515
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001516 if (full_config && conf->ieee80211h && !conf->ieee80211d) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001517 wpa_printf(MSG_ERROR, "Cannot enable IEEE 802.11h without "
1518 "IEEE 802.11d enabled");
1519 return -1;
1520 }
1521
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001522 if (full_config && conf->local_pwr_constraint != -1 &&
1523 !conf->ieee80211d) {
1524 wpa_printf(MSG_ERROR, "Cannot add Power Constraint element without Country element");
1525 return -1;
1526 }
1527
1528 if (full_config && conf->spectrum_mgmt_required &&
1529 conf->local_pwr_constraint == -1) {
1530 wpa_printf(MSG_ERROR, "Cannot set Spectrum Management bit without Country and Power Constraint elements");
1531 return -1;
1532 }
1533
Hai Shalom81f62d82019-07-22 12:10:00 -07001534#ifdef CONFIG_AIRTIME_POLICY
1535 if (full_config && conf->airtime_mode > AIRTIME_MODE_STATIC &&
1536 !conf->airtime_update_interval) {
1537 wpa_printf(MSG_ERROR, "Airtime update interval cannot be zero");
1538 return -1;
1539 }
1540#endif /* CONFIG_AIRTIME_POLICY */
Dmitry Shmidt05df46a2015-05-19 11:02:01 -07001541 for (i = 0; i < NUM_TX_QUEUES; i++) {
1542 if (hostapd_config_check_cw(conf, i))
1543 return -1;
1544 }
1545
Sunil Ravia04bd252022-05-02 22:54:18 -07001546#ifdef CONFIG_IEEE80211BE
1547 if (full_config && conf->ieee80211be && !conf->ieee80211ax) {
1548 wpa_printf(MSG_ERROR,
1549 "Cannot set ieee80211be without ieee80211ax");
1550 return -1;
1551 }
1552#endif /* CONFIG_IEEE80211BE */
1553
Sunil Ravi77d572f2023-01-17 23:58:31 +00001554 if (full_config && conf->mbssid && !conf->ieee80211ax) {
1555 wpa_printf(MSG_ERROR,
1556 "Cannot enable multiple BSSID support without ieee80211ax");
1557 return -1;
1558 }
1559
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001560 for (i = 0; i < conf->num_bss; i++) {
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001561 if (hostapd_config_check_bss(conf->bss[i], conf, full_config))
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001562 return -1;
1563 }
1564
1565 return 0;
1566}
1567
1568
Dmitry Shmidt71757432014-06-02 13:50:35 -07001569void hostapd_set_security_params(struct hostapd_bss_config *bss,
1570 int full_config)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001571{
Hai Shalomfdcde762020-04-02 11:19:20 -07001572#ifdef CONFIG_WEP
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001573 if (bss->individual_wep_key_len == 0) {
1574 /* individual keys are not use; can use key idx0 for
1575 * broadcast keys */
1576 bss->broadcast_key_idx_min = 0;
1577 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001578#endif /* CONFIG_WEP */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001579
1580 if ((bss->wpa & 2) && bss->rsn_pairwise == 0)
1581 bss->rsn_pairwise = bss->wpa_pairwise;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001582 if (bss->group_cipher)
1583 bss->wpa_group = bss->group_cipher;
1584 else
1585 bss->wpa_group = wpa_select_ap_group_cipher(bss->wpa,
1586 bss->wpa_pairwise,
1587 bss->rsn_pairwise);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001588 if (!bss->wpa_group_rekey_set)
1589 bss->wpa_group_rekey = bss->wpa_group == WPA_CIPHER_TKIP ?
1590 600 : 86400;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001591
Dmitry Shmidt71757432014-06-02 13:50:35 -07001592 if (full_config) {
1593 bss->radius->auth_server = bss->radius->auth_servers;
1594 bss->radius->acct_server = bss->radius->acct_servers;
1595 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001596
1597 if (bss->wpa && bss->ieee802_1x) {
1598 bss->ssid.security_policy = SECURITY_WPA;
1599 } else if (bss->wpa) {
1600 bss->ssid.security_policy = SECURITY_WPA_PSK;
1601 } else if (bss->ieee802_1x) {
1602 int cipher = WPA_CIPHER_NONE;
1603 bss->ssid.security_policy = SECURITY_IEEE_802_1X;
Hai Shalomfdcde762020-04-02 11:19:20 -07001604#ifdef CONFIG_WEP
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001605 bss->ssid.wep.default_len = bss->default_wep_key_len;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001606 if (full_config && bss->default_wep_key_len) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001607 cipher = bss->default_wep_key_len >= 13 ?
1608 WPA_CIPHER_WEP104 : WPA_CIPHER_WEP40;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001609 } else if (full_config && bss->ssid.wep.keys_set) {
1610 if (bss->ssid.wep.len[0] >= 13)
1611 cipher = WPA_CIPHER_WEP104;
1612 else
1613 cipher = WPA_CIPHER_WEP40;
1614 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001615#endif /* CONFIG_WEP */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001616 bss->wpa_group = cipher;
1617 bss->wpa_pairwise = cipher;
1618 bss->rsn_pairwise = cipher;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001619 if (full_config)
1620 bss->wpa_key_mgmt = WPA_KEY_MGMT_IEEE8021X_NO_WPA;
Hai Shalomfdcde762020-04-02 11:19:20 -07001621#ifdef CONFIG_WEP
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001622 } else if (bss->ssid.wep.keys_set) {
1623 int cipher = WPA_CIPHER_WEP40;
1624 if (bss->ssid.wep.len[0] >= 13)
1625 cipher = WPA_CIPHER_WEP104;
1626 bss->ssid.security_policy = SECURITY_STATIC_WEP;
1627 bss->wpa_group = cipher;
1628 bss->wpa_pairwise = cipher;
1629 bss->rsn_pairwise = cipher;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001630 if (full_config)
1631 bss->wpa_key_mgmt = WPA_KEY_MGMT_NONE;
Hai Shalomfdcde762020-04-02 11:19:20 -07001632#endif /* CONFIG_WEP */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001633 } else if (bss->osen) {
1634 bss->ssid.security_policy = SECURITY_OSEN;
1635 bss->wpa_group = WPA_CIPHER_CCMP;
1636 bss->wpa_pairwise = 0;
1637 bss->rsn_pairwise = WPA_CIPHER_CCMP;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001638 } else {
1639 bss->ssid.security_policy = SECURITY_PLAINTEXT;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001640 if (full_config) {
1641 bss->wpa_group = WPA_CIPHER_NONE;
1642 bss->wpa_pairwise = WPA_CIPHER_NONE;
1643 bss->rsn_pairwise = WPA_CIPHER_NONE;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001644 bss->wpa_key_mgmt = WPA_KEY_MGMT_NONE;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001645 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001646 }
1647}
Hai Shalom74f70d42019-02-11 14:42:39 -08001648
1649
1650int hostapd_sae_pw_id_in_use(struct hostapd_bss_config *conf)
1651{
1652 int with_id = 0, without_id = 0;
1653 struct sae_password_entry *pw;
1654
1655 if (conf->ssid.wpa_passphrase)
1656 without_id = 1;
1657
1658 for (pw = conf->sae_passwords; pw; pw = pw->next) {
1659 if (pw->identifier)
1660 with_id = 1;
1661 else
1662 without_id = 1;
1663 if (with_id && without_id)
1664 break;
1665 }
1666
1667 if (with_id && !without_id)
1668 return 2;
1669 return with_id;
1670}
Hai Shalom899fcc72020-10-19 14:38:18 -07001671
1672
1673bool hostapd_sae_pk_in_use(struct hostapd_bss_config *conf)
1674{
1675#ifdef CONFIG_SAE_PK
1676 struct sae_password_entry *pw;
1677
1678 for (pw = conf->sae_passwords; pw; pw = pw->next) {
1679 if (pw->pk)
1680 return true;
1681 }
1682#endif /* CONFIG_SAE_PK */
1683
1684 return false;
1685}
1686
1687
1688#ifdef CONFIG_SAE_PK
1689bool hostapd_sae_pk_exclusively(struct hostapd_bss_config *conf)
1690{
1691 bool with_pk = false;
1692 struct sae_password_entry *pw;
1693
1694 if (conf->ssid.wpa_passphrase)
1695 return false;
1696
1697 for (pw = conf->sae_passwords; pw; pw = pw->next) {
1698 if (!pw->pk)
1699 return false;
1700 with_pk = true;
1701 }
1702
1703 return with_pk;
1704}
1705#endif /* CONFIG_SAE_PK */
Sunil Ravia04bd252022-05-02 22:54:18 -07001706
1707
1708int hostapd_acl_comp(const void *a, const void *b)
1709{
1710 const struct mac_acl_entry *aa = a;
1711 const struct mac_acl_entry *bb = b;
1712 return os_memcmp(aa->addr, bb->addr, sizeof(macaddr));
1713}
1714
1715
1716int hostapd_add_acl_maclist(struct mac_acl_entry **acl, int *num,
1717 int vlan_id, const u8 *addr)
1718{
1719 struct mac_acl_entry *newacl;
1720
1721 newacl = os_realloc_array(*acl, *num + 1, sizeof(**acl));
1722 if (!newacl) {
1723 wpa_printf(MSG_ERROR, "MAC list reallocation failed");
1724 return -1;
1725 }
1726
1727 *acl = newacl;
1728 os_memcpy((*acl)[*num].addr, addr, ETH_ALEN);
1729 os_memset(&(*acl)[*num].vlan_id, 0, sizeof((*acl)[*num].vlan_id));
1730 (*acl)[*num].vlan_id.untagged = vlan_id;
1731 (*acl)[*num].vlan_id.notempty = !!vlan_id;
1732 (*num)++;
1733
1734 return 0;
1735}
1736
1737
1738void hostapd_remove_acl_mac(struct mac_acl_entry **acl, int *num,
1739 const u8 *addr)
1740{
1741 int i = 0;
1742
1743 while (i < *num) {
1744 if (os_memcmp((*acl)[i].addr, addr, ETH_ALEN) == 0) {
1745 os_remove_in_array(*acl, *num, sizeof(**acl), i);
1746 (*num)--;
1747 } else {
1748 i++;
1749 }
1750 }
1751}