blob: 445d9634a728d18491f385ca7e92b56f212fdbc4 [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
166#ifdef CONFIG_TESTING_OPTIONS
167 bss->sae_commit_status = -1;
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000168 bss->test_assoc_comeback_type = -1;
Hai Shalom899fcc72020-10-19 14:38:18 -0700169#endif /* CONFIG_TESTING_OPTIONS */
Hai Shaloma20dcd72022-02-04 13:43:00 -0800170
171#ifdef CONFIG_PASN
172 /* comeback after 10 TUs */
173 bss->pasn_comeback_after = 10;
Sunil Ravi640215c2023-06-28 23:08:09 +0000174 bss->pasn_noauth = 1;
Hai Shaloma20dcd72022-02-04 13:43:00 -0800175#endif /* CONFIG_PASN */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700176}
177
178
179struct hostapd_config * hostapd_config_defaults(void)
180{
181#define ecw2cw(ecw) ((1 << (ecw)) - 1)
182
183 struct hostapd_config *conf;
184 struct hostapd_bss_config *bss;
185 const int aCWmin = 4, aCWmax = 10;
186 const struct hostapd_wmm_ac_params ac_bk =
187 { aCWmin, aCWmax, 7, 0, 0 }; /* background traffic */
188 const struct hostapd_wmm_ac_params ac_be =
189 { aCWmin, aCWmax, 3, 0, 0 }; /* best effort traffic */
190 const struct hostapd_wmm_ac_params ac_vi = /* video traffic */
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700191 { aCWmin - 1, aCWmin, 2, 3008 / 32, 0 };
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700192 const struct hostapd_wmm_ac_params ac_vo = /* voice traffic */
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700193 { aCWmin - 2, aCWmin - 1, 2, 1504 / 32, 0 };
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700194 const struct hostapd_tx_queue_params txq_bk =
195 { 7, ecw2cw(aCWmin), ecw2cw(aCWmax), 0 };
196 const struct hostapd_tx_queue_params txq_be =
197 { 3, ecw2cw(aCWmin), 4 * (ecw2cw(aCWmin) + 1) - 1, 0};
198 const struct hostapd_tx_queue_params txq_vi =
199 { 1, (ecw2cw(aCWmin) + 1) / 2 - 1, ecw2cw(aCWmin), 30};
200 const struct hostapd_tx_queue_params txq_vo =
201 { 1, (ecw2cw(aCWmin) + 1) / 4 - 1,
202 (ecw2cw(aCWmin) + 1) / 2 - 1, 15};
203
204#undef ecw2cw
205
206 conf = os_zalloc(sizeof(*conf));
207 bss = os_zalloc(sizeof(*bss));
208 if (conf == NULL || bss == NULL) {
209 wpa_printf(MSG_ERROR, "Failed to allocate memory for "
210 "configuration data.");
211 os_free(conf);
212 os_free(bss);
213 return NULL;
214 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800215 conf->bss = os_calloc(1, sizeof(struct hostapd_bss_config *));
216 if (conf->bss == NULL) {
217 os_free(conf);
218 os_free(bss);
219 return NULL;
220 }
221 conf->bss[0] = bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700222
223 bss->radius = os_zalloc(sizeof(*bss->radius));
224 if (bss->radius == NULL) {
Dmitry Shmidt97672262014-02-03 13:02:54 -0800225 os_free(conf->bss);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700226 os_free(conf);
227 os_free(bss);
228 return NULL;
229 }
230
231 hostapd_config_defaults_bss(bss);
232
233 conf->num_bss = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700234
235 conf->beacon_int = 100;
Hai Shalom021b0b52019-04-10 11:17:58 -0700236 conf->rts_threshold = -2; /* use driver default: 2347 */
237 conf->fragm_threshold = -2; /* user driver default: 2346 */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800238 /* Set to invalid value means do not add Power Constraint IE */
239 conf->local_pwr_constraint = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700240
241 conf->wmm_ac_params[0] = ac_be;
242 conf->wmm_ac_params[1] = ac_bk;
243 conf->wmm_ac_params[2] = ac_vi;
244 conf->wmm_ac_params[3] = ac_vo;
245
246 conf->tx_queue[0] = txq_vo;
247 conf->tx_queue[1] = txq_vi;
248 conf->tx_queue[2] = txq_be;
249 conf->tx_queue[3] = txq_bk;
250
251 conf->ht_capab = HT_CAP_INFO_SMPS_DISABLED;
252
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800253 conf->ap_table_max_size = 255;
254 conf->ap_table_expiration_time = 60;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800255 conf->track_sta_max_age = 180;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800256
Dmitry Shmidt8da800a2013-04-24 12:57:01 -0700257#ifdef CONFIG_TESTING_OPTIONS
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700258 conf->ignore_probe_probability = 0.0;
259 conf->ignore_auth_probability = 0.0;
260 conf->ignore_assoc_probability = 0.0;
261 conf->ignore_reassoc_probability = 0.0;
262 conf->corrupt_gtk_rekey_mic_probability = 0.0;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800263 conf->ecsa_ie_only = 0;
Kai Shie75b0652020-11-24 20:31:29 -0800264 conf->skip_send_eapol = 0;
265 conf->enable_eapol_large_timeout = 0;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -0700266#endif /* CONFIG_TESTING_OPTIONS */
267
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700268 conf->acs = 0;
269 conf->acs_ch_list.num = 0;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700270#ifdef CONFIG_ACS
271 conf->acs_num_scans = 5;
272#endif /* CONFIG_ACS */
273
Hai Shalom81f62d82019-07-22 12:10:00 -0700274#ifdef CONFIG_IEEE80211AX
275 conf->he_op.he_rts_threshold = HE_OPERATION_RTS_THRESHOLD_MASK >>
276 HE_OPERATION_RTS_THRESHOLD_OFFSET;
277 /* Set default basic MCS/NSS set to single stream MCS 0-7 */
278 conf->he_op.he_basic_mcs_nss_set = 0xfffc;
Hai Shalomfdcde762020-04-02 11:19:20 -0700279 conf->he_op.he_bss_color_disabled = 1;
280 conf->he_op.he_bss_color_partial = 0;
Hai Shaloma20dcd72022-02-04 13:43:00 -0800281 conf->he_op.he_bss_color = os_random() % 63 + 1;
282 conf->he_op.he_twt_responder = 1;
Hai Shalom60840252021-02-19 19:02:11 -0800283 conf->he_6ghz_max_mpdu = 2;
284 conf->he_6ghz_max_ampdu_len_exp = 7;
285 conf->he_6ghz_rx_ant_pat = 1;
286 conf->he_6ghz_tx_ant_pat = 1;
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000287 conf->he_6ghz_reg_pwr_type = HE_REG_INFO_6GHZ_AP_TYPE_VLP;
288 conf->reg_def_cli_eirp_psd = -1;
289 conf->reg_sub_cli_eirp_psd = -1;
290 conf->reg_def_cli_eirp = -1;
Hai Shalom81f62d82019-07-22 12:10:00 -0700291#endif /* CONFIG_IEEE80211AX */
292
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700293 /* The third octet of the country string uses an ASCII space character
294 * by default to indicate that the regulations encompass all
295 * environments for the current frequency band in the country. */
296 conf->country[2] = ' ';
297
Hai Shalom74f70d42019-02-11 14:42:39 -0800298 conf->rssi_reject_assoc_rssi = 0;
299 conf->rssi_reject_assoc_timeout = 30;
300
Hai Shalom81f62d82019-07-22 12:10:00 -0700301#ifdef CONFIG_AIRTIME_POLICY
302 conf->airtime_update_interval = AIRTIME_DEFAULT_UPDATE_INTERVAL;
303#endif /* CONFIG_AIRTIME_POLICY */
304
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000305 hostapd_set_and_check_bw320_offset(conf, 0);
306
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700307 return conf;
308}
309
310
311int hostapd_mac_comp(const void *a, const void *b)
312{
313 return os_memcmp(a, b, sizeof(macaddr));
314}
315
316
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700317static int hostapd_config_read_wpa_psk(const char *fname,
318 struct hostapd_ssid *ssid)
319{
320 FILE *f;
321 char buf[128], *pos;
Hai Shalom74f70d42019-02-11 14:42:39 -0800322 const char *keyid;
323 char *context;
324 char *context2;
325 char *token;
326 char *name;
327 char *value;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700328 int line = 0, ret = 0, len, ok;
329 u8 addr[ETH_ALEN];
330 struct hostapd_wpa_psk *psk;
331
332 if (!fname)
333 return 0;
334
335 f = fopen(fname, "r");
336 if (!f) {
337 wpa_printf(MSG_ERROR, "WPA PSK file '%s' not found.", fname);
338 return -1;
339 }
340
341 while (fgets(buf, sizeof(buf), f)) {
Hai Shalom021b0b52019-04-10 11:17:58 -0700342 int vlan_id = 0;
Hai Shalomfdcde762020-04-02 11:19:20 -0700343 int wps = 0;
Hai Shalom021b0b52019-04-10 11:17:58 -0700344
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700345 line++;
346
347 if (buf[0] == '#')
348 continue;
349 pos = buf;
350 while (*pos != '\0') {
351 if (*pos == '\n') {
352 *pos = '\0';
353 break;
354 }
355 pos++;
356 }
357 if (buf[0] == '\0')
358 continue;
359
Hai Shalom74f70d42019-02-11 14:42:39 -0800360 context = NULL;
361 keyid = NULL;
362 while ((token = str_token(buf, " ", &context))) {
363 if (!os_strchr(token, '='))
364 break;
365 context2 = NULL;
366 name = str_token(token, "=", &context2);
Hai Shalom021b0b52019-04-10 11:17:58 -0700367 if (!name)
368 break;
Hai Shalom74f70d42019-02-11 14:42:39 -0800369 value = str_token(token, "", &context2);
370 if (!value)
371 value = "";
372 if (!os_strcmp(name, "keyid")) {
373 keyid = value;
Hai Shalomfdcde762020-04-02 11:19:20 -0700374 } else if (!os_strcmp(name, "wps")) {
375 wps = atoi(value);
Hai Shalom021b0b52019-04-10 11:17:58 -0700376 } else if (!os_strcmp(name, "vlanid")) {
377 vlan_id = atoi(value);
Hai Shalom74f70d42019-02-11 14:42:39 -0800378 } else {
379 wpa_printf(MSG_ERROR,
380 "Unrecognized '%s=%s' on line %d in '%s'",
381 name, value, line, fname);
382 ret = -1;
383 break;
384 }
385 }
386
387 if (ret == -1)
388 break;
389
390 if (!token)
391 token = "";
392 if (hwaddr_aton(token, addr)) {
Hai Shalomfdcde762020-04-02 11:19:20 -0700393 wpa_printf(MSG_ERROR,
394 "Invalid MAC address '%s' on line %d in '%s'",
395 token, line, fname);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700396 ret = -1;
397 break;
398 }
399
400 psk = os_zalloc(sizeof(*psk));
401 if (psk == NULL) {
402 wpa_printf(MSG_ERROR, "WPA PSK allocation failed");
403 ret = -1;
404 break;
405 }
Hai Shalom021b0b52019-04-10 11:17:58 -0700406 psk->vlan_id = vlan_id;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700407 if (is_zero_ether_addr(addr))
408 psk->group = 1;
409 else
410 os_memcpy(psk->addr, addr, ETH_ALEN);
411
Hai Shalom74f70d42019-02-11 14:42:39 -0800412 pos = str_token(buf, "", &context);
413 if (!pos) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700414 wpa_printf(MSG_ERROR, "No PSK on line %d in '%s'",
415 line, fname);
416 os_free(psk);
417 ret = -1;
418 break;
419 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700420
421 ok = 0;
422 len = os_strlen(pos);
Hai Shalomfdcde762020-04-02 11:19:20 -0700423 if (len == 2 * PMK_LEN &&
424 hexstr2bin(pos, psk->psk, PMK_LEN) == 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700425 ok = 1;
Hai Shalomfdcde762020-04-02 11:19:20 -0700426 else if (len >= 8 && len < 64 &&
427 pbkdf2_sha1(pos, ssid->ssid, ssid->ssid_len,
428 4096, psk->psk, PMK_LEN) == 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700429 ok = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700430 if (!ok) {
Hai Shalomfdcde762020-04-02 11:19:20 -0700431 wpa_printf(MSG_ERROR,
432 "Invalid PSK '%s' on line %d in '%s'",
433 pos, line, fname);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700434 os_free(psk);
435 ret = -1;
436 break;
437 }
438
Hai Shalom74f70d42019-02-11 14:42:39 -0800439 if (keyid) {
440 len = os_strlcpy(psk->keyid, keyid, sizeof(psk->keyid));
441 if ((size_t) len >= sizeof(psk->keyid)) {
442 wpa_printf(MSG_ERROR,
443 "PSK keyid too long on line %d in '%s'",
444 line, fname);
445 os_free(psk);
446 ret = -1;
447 break;
448 }
449 }
450
Hai Shalomfdcde762020-04-02 11:19:20 -0700451 psk->wps = wps;
452
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700453 psk->next = ssid->wpa_psk;
454 ssid->wpa_psk = psk;
455 }
456
457 fclose(f);
458
459 return ret;
460}
461
462
463static int hostapd_derive_psk(struct hostapd_ssid *ssid)
464{
465 ssid->wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
466 if (ssid->wpa_psk == NULL) {
467 wpa_printf(MSG_ERROR, "Unable to alloc space for PSK");
468 return -1;
469 }
470 wpa_hexdump_ascii(MSG_DEBUG, "SSID",
471 (u8 *) ssid->ssid, ssid->ssid_len);
472 wpa_hexdump_ascii_key(MSG_DEBUG, "PSK (ASCII passphrase)",
473 (u8 *) ssid->wpa_passphrase,
474 os_strlen(ssid->wpa_passphrase));
Sunil Ravia04bd252022-05-02 22:54:18 -0700475 if (pbkdf2_sha1(ssid->wpa_passphrase,
476 ssid->ssid, ssid->ssid_len,
477 4096, ssid->wpa_psk->psk, PMK_LEN) != 0) {
478 wpa_printf(MSG_ERROR, "Error in pbkdf2_sha1()");
479 return -1;
480 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700481 wpa_hexdump_key(MSG_DEBUG, "PSK (from passphrase)",
482 ssid->wpa_psk->psk, PMK_LEN);
483 return 0;
484}
485
486
Hai Shalomc3565922019-10-28 11:58:20 -0700487int hostapd_setup_sae_pt(struct hostapd_bss_config *conf)
488{
489#ifdef CONFIG_SAE
490 struct hostapd_ssid *ssid = &conf->ssid;
491 struct sae_password_entry *pw;
492
Sunil Ravi77d572f2023-01-17 23:58:31 +0000493 if ((conf->sae_pwe == SAE_PWE_HUNT_AND_PECK &&
494 !hostapd_sae_pw_id_in_use(conf) &&
Sunil Ravi89eba102022-09-13 21:04:37 -0700495 !wpa_key_mgmt_sae_ext_key(conf->wpa_key_mgmt) &&
Hai Shalom899fcc72020-10-19 14:38:18 -0700496 !hostapd_sae_pk_in_use(conf)) ||
Sunil Ravi77d572f2023-01-17 23:58:31 +0000497 conf->sae_pwe == SAE_PWE_FORCE_HUNT_AND_PECK ||
Hai Shalomfdcde762020-04-02 11:19:20 -0700498 !wpa_key_mgmt_sae(conf->wpa_key_mgmt))
Hai Shalomc3565922019-10-28 11:58:20 -0700499 return 0; /* PT not needed */
500
501 sae_deinit_pt(ssid->pt);
502 ssid->pt = NULL;
503 if (ssid->wpa_passphrase) {
504 ssid->pt = sae_derive_pt(conf->sae_groups, ssid->ssid,
505 ssid->ssid_len,
506 (const u8 *) ssid->wpa_passphrase,
507 os_strlen(ssid->wpa_passphrase),
508 NULL);
509 if (!ssid->pt)
510 return -1;
511 }
512
513 for (pw = conf->sae_passwords; pw; pw = pw->next) {
514 sae_deinit_pt(pw->pt);
515 pw->pt = sae_derive_pt(conf->sae_groups, ssid->ssid,
516 ssid->ssid_len,
517 (const u8 *) pw->password,
518 os_strlen(pw->password),
519 pw->identifier);
520 if (!pw->pt)
521 return -1;
522 }
523#endif /* CONFIG_SAE */
524
525 return 0;
526}
527
528
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700529int hostapd_setup_wpa_psk(struct hostapd_bss_config *conf)
530{
531 struct hostapd_ssid *ssid = &conf->ssid;
532
Hai Shalomc3565922019-10-28 11:58:20 -0700533 if (hostapd_setup_sae_pt(conf) < 0)
534 return -1;
535
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700536 if (ssid->wpa_passphrase != NULL) {
537 if (ssid->wpa_psk != NULL) {
538 wpa_printf(MSG_DEBUG, "Using pre-configured WPA PSK "
539 "instead of passphrase");
540 } else {
541 wpa_printf(MSG_DEBUG, "Deriving WPA PSK based on "
542 "passphrase");
543 if (hostapd_derive_psk(ssid) < 0)
544 return -1;
545 }
546 ssid->wpa_psk->group = 1;
547 }
548
Dmitry Shmidt29333592017-01-09 12:27:11 -0800549 return hostapd_config_read_wpa_psk(ssid->wpa_psk_file, &conf->ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700550}
551
552
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700553static void hostapd_config_free_radius(struct hostapd_radius_server *servers,
554 int num_servers)
555{
556 int i;
557
558 for (i = 0; i < num_servers; i++) {
559 os_free(servers[i].shared_secret);
560 }
561 os_free(servers);
562}
563
564
Dmitry Shmidt04949592012-07-19 12:16:46 -0700565struct hostapd_radius_attr *
566hostapd_config_get_radius_attr(struct hostapd_radius_attr *attr, u8 type)
567{
568 for (; attr; attr = attr->next) {
569 if (attr->type == type)
570 return attr;
571 }
572 return NULL;
573}
574
575
Hai Shalomc3565922019-10-28 11:58:20 -0700576struct hostapd_radius_attr * hostapd_parse_radius_attr(const char *value)
577{
578 const char *pos;
579 char syntax;
580 struct hostapd_radius_attr *attr;
581 size_t len;
582
583 attr = os_zalloc(sizeof(*attr));
584 if (!attr)
585 return NULL;
586
587 attr->type = atoi(value);
588
589 pos = os_strchr(value, ':');
590 if (!pos) {
591 attr->val = wpabuf_alloc(1);
592 if (!attr->val) {
593 os_free(attr);
594 return NULL;
595 }
596 wpabuf_put_u8(attr->val, 0);
597 return attr;
598 }
599
600 pos++;
601 if (pos[0] == '\0' || pos[1] != ':') {
602 os_free(attr);
603 return NULL;
604 }
605 syntax = *pos++;
606 pos++;
607
608 switch (syntax) {
609 case 's':
610 attr->val = wpabuf_alloc_copy(pos, os_strlen(pos));
611 break;
612 case 'x':
613 len = os_strlen(pos);
614 if (len & 1)
615 break;
616 len /= 2;
617 attr->val = wpabuf_alloc(len);
618 if (!attr->val)
619 break;
620 if (hexstr2bin(pos, wpabuf_put(attr->val, len), len) < 0) {
621 wpabuf_free(attr->val);
622 os_free(attr);
623 return NULL;
624 }
625 break;
626 case 'd':
627 attr->val = wpabuf_alloc(4);
628 if (attr->val)
629 wpabuf_put_be32(attr->val, atoi(pos));
630 break;
631 default:
632 os_free(attr);
633 return NULL;
634 }
635
636 if (!attr->val) {
637 os_free(attr);
638 return NULL;
639 }
640
641 return attr;
642}
643
644
645void hostapd_config_free_radius_attr(struct hostapd_radius_attr *attr)
Dmitry Shmidt04949592012-07-19 12:16:46 -0700646{
647 struct hostapd_radius_attr *prev;
648
649 while (attr) {
650 prev = attr;
651 attr = attr->next;
652 wpabuf_free(prev->val);
653 os_free(prev);
654 }
655}
656
657
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700658void hostapd_config_free_eap_user(struct hostapd_eap_user *user)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700659{
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700660 hostapd_config_free_radius_attr(user->accept_attr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700661 os_free(user->identity);
Dmitry Shmidtc2817022014-07-02 10:32:10 -0700662 bin_clear_free(user->password, user->password_len);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700663 bin_clear_free(user->salt, user->salt_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700664 os_free(user);
665}
666
667
Dmitry Shmidt29333592017-01-09 12:27:11 -0800668void hostapd_config_free_eap_users(struct hostapd_eap_user *user)
669{
670 struct hostapd_eap_user *prev_user;
671
672 while (user) {
673 prev_user = user;
674 user = user->next;
675 hostapd_config_free_eap_user(prev_user);
676 }
677}
678
679
Hai Shalomfdcde762020-04-02 11:19:20 -0700680#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700681static void hostapd_config_free_wep(struct hostapd_wep_keys *keys)
682{
683 int i;
684 for (i = 0; i < NUM_WEP_KEYS; i++) {
Dmitry Shmidtc2817022014-07-02 10:32:10 -0700685 bin_clear_free(keys->key[i], keys->len[i]);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700686 keys->key[i] = NULL;
687 }
688}
Hai Shalomfdcde762020-04-02 11:19:20 -0700689#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700690
691
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800692void hostapd_config_clear_wpa_psk(struct hostapd_wpa_psk **l)
693{
694 struct hostapd_wpa_psk *psk, *tmp;
695
696 for (psk = *l; psk;) {
697 tmp = psk;
698 psk = psk->next;
699 bin_clear_free(tmp, sizeof(*tmp));
700 }
701 *l = NULL;
702}
703
704
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000705#ifdef CONFIG_IEEE80211R_AP
706
707void hostapd_config_clear_rxkhs(struct hostapd_bss_config *conf)
708{
709 struct ft_remote_r0kh *r0kh, *r0kh_prev;
710 struct ft_remote_r1kh *r1kh, *r1kh_prev;
711
712 r0kh = conf->r0kh_list;
713 conf->r0kh_list = NULL;
714 while (r0kh) {
715 r0kh_prev = r0kh;
716 r0kh = r0kh->next;
717 os_free(r0kh_prev);
718 }
719
720 r1kh = conf->r1kh_list;
721 conf->r1kh_list = NULL;
722 while (r1kh) {
723 r1kh_prev = r1kh;
724 r1kh = r1kh->next;
725 os_free(r1kh_prev);
726 }
727}
728
729#endif /* CONFIG_IEEE80211R_AP */
730
731
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800732static void hostapd_config_free_anqp_elem(struct hostapd_bss_config *conf)
733{
734 struct anqp_element *elem;
735
736 while ((elem = dl_list_first(&conf->anqp_elem, struct anqp_element,
737 list))) {
738 dl_list_del(&elem->list);
739 wpabuf_free(elem->payload);
740 os_free(elem);
741 }
742}
743
744
Dmitry Shmidt29333592017-01-09 12:27:11 -0800745static void hostapd_config_free_fils_realms(struct hostapd_bss_config *conf)
746{
747#ifdef CONFIG_FILS
748 struct fils_realm *realm;
749
750 while ((realm = dl_list_first(&conf->fils_realms, struct fils_realm,
751 list))) {
752 dl_list_del(&realm->list);
753 os_free(realm);
754 }
755#endif /* CONFIG_FILS */
756}
757
758
Roshan Pius3a1667e2018-07-03 15:17:14 -0700759static void hostapd_config_free_sae_passwords(struct hostapd_bss_config *conf)
760{
761 struct sae_password_entry *pw, *tmp;
762
763 pw = conf->sae_passwords;
764 conf->sae_passwords = NULL;
765 while (pw) {
766 tmp = pw;
767 pw = pw->next;
768 str_clear_free(tmp->password);
769 os_free(tmp->identifier);
Hai Shalomc3565922019-10-28 11:58:20 -0700770#ifdef CONFIG_SAE
771 sae_deinit_pt(tmp->pt);
772#endif /* CONFIG_SAE */
Hai Shalom899fcc72020-10-19 14:38:18 -0700773#ifdef CONFIG_SAE_PK
774 sae_deinit_pk(tmp->pk);
775#endif /* CONFIG_SAE_PK */
Roshan Pius3a1667e2018-07-03 15:17:14 -0700776 os_free(tmp);
777 }
778}
779
780
Hai Shalom81f62d82019-07-22 12:10:00 -0700781#ifdef CONFIG_DPP2
782static void hostapd_dpp_controller_conf_free(struct dpp_controller_conf *conf)
783{
784 struct dpp_controller_conf *prev;
785
786 while (conf) {
787 prev = conf;
788 conf = conf->next;
789 os_free(prev);
790 }
791}
792#endif /* CONFIG_DPP2 */
793
794
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800795void hostapd_config_free_bss(struct hostapd_bss_config *conf)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700796{
Hai Shalom81f62d82019-07-22 12:10:00 -0700797#if defined(CONFIG_WPS) || defined(CONFIG_HS20)
798 size_t i;
799#endif
800
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700801 if (conf == NULL)
802 return;
803
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800804 hostapd_config_clear_wpa_psk(&conf->ssid.wpa_psk);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700805
Dmitry Shmidtc2817022014-07-02 10:32:10 -0700806 str_clear_free(conf->ssid.wpa_passphrase);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700807 os_free(conf->ssid.wpa_psk_file);
Hai Shalomfdcde762020-04-02 11:19:20 -0700808#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700809 hostapd_config_free_wep(&conf->ssid.wep);
Hai Shalomfdcde762020-04-02 11:19:20 -0700810#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700811#ifdef CONFIG_FULL_DYNAMIC_VLAN
812 os_free(conf->ssid.vlan_tagged_interface);
813#endif /* CONFIG_FULL_DYNAMIC_VLAN */
Hai Shalomc3565922019-10-28 11:58:20 -0700814#ifdef CONFIG_SAE
815 sae_deinit_pt(conf->ssid.pt);
816#endif /* CONFIG_SAE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700817
Dmitry Shmidt29333592017-01-09 12:27:11 -0800818 hostapd_config_free_eap_users(conf->eap_user);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800819 os_free(conf->eap_user_sqlite);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700820
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700821 os_free(conf->eap_req_id_text);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800822 os_free(conf->erp_domain);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700823 os_free(conf->accept_mac);
824 os_free(conf->deny_mac);
825 os_free(conf->nas_identifier);
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800826 if (conf->radius) {
827 hostapd_config_free_radius(conf->radius->auth_servers,
828 conf->radius->num_auth_servers);
829 hostapd_config_free_radius(conf->radius->acct_servers,
830 conf->radius->num_acct_servers);
Hai Shaloma20dcd72022-02-04 13:43:00 -0800831 os_free(conf->radius->force_client_dev);
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800832 }
Dmitry Shmidt04949592012-07-19 12:16:46 -0700833 hostapd_config_free_radius_attr(conf->radius_auth_req_attr);
834 hostapd_config_free_radius_attr(conf->radius_acct_req_attr);
Hai Shalomc3565922019-10-28 11:58:20 -0700835 os_free(conf->radius_req_attr_sqlite);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700836 os_free(conf->rsn_preauth_interfaces);
837 os_free(conf->ctrl_interface);
Sunil Ravi77d572f2023-01-17 23:58:31 +0000838 os_free(conf->config_id);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700839 os_free(conf->ca_cert);
840 os_free(conf->server_cert);
Hai Shalom81f62d82019-07-22 12:10:00 -0700841 os_free(conf->server_cert2);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700842 os_free(conf->private_key);
Hai Shalom81f62d82019-07-22 12:10:00 -0700843 os_free(conf->private_key2);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700844 os_free(conf->private_key_passwd);
Hai Shalom81f62d82019-07-22 12:10:00 -0700845 os_free(conf->private_key_passwd2);
Hai Shalom021b0b52019-04-10 11:17:58 -0700846 os_free(conf->check_cert_subject);
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700847 os_free(conf->ocsp_stapling_response);
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -0800848 os_free(conf->ocsp_stapling_response_multi);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700849 os_free(conf->dh_file);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800850 os_free(conf->openssl_ciphers);
Hai Shalom74f70d42019-02-11 14:42:39 -0800851 os_free(conf->openssl_ecdh_curves);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700852 os_free(conf->pac_opaque_encr_key);
853 os_free(conf->eap_fast_a_id);
854 os_free(conf->eap_fast_a_id_info);
855 os_free(conf->eap_sim_db);
Sunil Ravia04bd252022-05-02 22:54:18 -0700856 os_free(conf->imsi_privacy_key);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700857 os_free(conf->radius_server_clients);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700858 os_free(conf->radius);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700859 os_free(conf->radius_das_shared_secret);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700860 hostapd_config_free_vlan(conf);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800861 os_free(conf->time_zone);
862
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800863#ifdef CONFIG_IEEE80211R_AP
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000864 hostapd_config_clear_rxkhs(conf);
865 os_free(conf->rxkh_file);
866 conf->rxkh_file = NULL;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800867#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700868
869#ifdef CONFIG_WPS
870 os_free(conf->wps_pin_requests);
871 os_free(conf->device_name);
872 os_free(conf->manufacturer);
873 os_free(conf->model_name);
874 os_free(conf->model_number);
875 os_free(conf->serial_number);
876 os_free(conf->config_methods);
877 os_free(conf->ap_pin);
878 os_free(conf->extra_cred);
879 os_free(conf->ap_settings);
Hai Shalom021b0b52019-04-10 11:17:58 -0700880 hostapd_config_clear_wpa_psk(&conf->multi_ap_backhaul_ssid.wpa_psk);
881 str_clear_free(conf->multi_ap_backhaul_ssid.wpa_passphrase);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700882 os_free(conf->upnp_iface);
883 os_free(conf->friendly_name);
884 os_free(conf->manufacturer_url);
885 os_free(conf->model_description);
886 os_free(conf->model_url);
887 os_free(conf->upc);
Hai Shalom81f62d82019-07-22 12:10:00 -0700888 for (i = 0; i < MAX_WPS_VENDOR_EXTENSIONS; i++)
889 wpabuf_free(conf->wps_vendor_ext[i]);
Hai Shalomfdcde762020-04-02 11:19:20 -0700890 wpabuf_free(conf->wps_application_ext);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700891 wpabuf_free(conf->wps_nfc_dh_pubkey);
892 wpabuf_free(conf->wps_nfc_dh_privkey);
893 wpabuf_free(conf->wps_nfc_dev_pw);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700894#endif /* CONFIG_WPS */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800895
896 os_free(conf->roaming_consortium);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700897 os_free(conf->venue_name);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700898 os_free(conf->venue_url);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700899 os_free(conf->nai_realm_data);
900 os_free(conf->network_auth_type);
901 os_free(conf->anqp_3gpp_cell_net);
902 os_free(conf->domain_name);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800903 hostapd_config_free_anqp_elem(conf);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800904
905#ifdef CONFIG_RADIUS_TEST
906 os_free(conf->dump_msk_file);
907#endif /* CONFIG_RADIUS_TEST */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700908
909#ifdef CONFIG_HS20
910 os_free(conf->hs20_oper_friendly_name);
911 os_free(conf->hs20_wan_metrics);
912 os_free(conf->hs20_connection_capability);
913 os_free(conf->hs20_operating_class);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800914 os_free(conf->hs20_icons);
915 if (conf->hs20_osu_providers) {
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800916 for (i = 0; i < conf->hs20_osu_providers_count; i++) {
917 struct hs20_osu_provider *p;
918 size_t j;
919 p = &conf->hs20_osu_providers[i];
920 os_free(p->friendly_name);
921 os_free(p->server_uri);
922 os_free(p->method_list);
923 for (j = 0; j < p->icons_count; j++)
924 os_free(p->icons[j]);
925 os_free(p->icons);
926 os_free(p->osu_nai);
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800927 os_free(p->osu_nai2);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800928 os_free(p->service_desc);
929 }
930 os_free(conf->hs20_osu_providers);
931 }
Roshan Pius3a1667e2018-07-03 15:17:14 -0700932 if (conf->hs20_operator_icon) {
Roshan Pius3a1667e2018-07-03 15:17:14 -0700933 for (i = 0; i < conf->hs20_operator_icon_count; i++)
934 os_free(conf->hs20_operator_icon[i]);
935 os_free(conf->hs20_operator_icon);
936 }
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800937 os_free(conf->subscr_remediation_url);
Hai Shalom74f70d42019-02-11 14:42:39 -0800938 os_free(conf->hs20_sim_provisioning_url);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700939 os_free(conf->t_c_filename);
940 os_free(conf->t_c_server_url);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700941#endif /* CONFIG_HS20 */
942
943 wpabuf_free(conf->vendor_elements);
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700944 wpabuf_free(conf->assocresp_elements);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800945
946 os_free(conf->sae_groups);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700947#ifdef CONFIG_OWE
948 os_free(conf->owe_groups);
949#endif /* CONFIG_OWE */
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700950
Dmitry Shmidt0207e232014-09-03 14:58:37 -0700951 os_free(conf->wowlan_triggers);
952
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700953 os_free(conf->server_id);
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800954
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800955#ifdef CONFIG_TESTING_OPTIONS
956 wpabuf_free(conf->own_ie_override);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700957 wpabuf_free(conf->sae_commit_override);
Hai Shalomfdcde762020-04-02 11:19:20 -0700958 wpabuf_free(conf->rsne_override_eapol);
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800959 wpabuf_free(conf->rsnxe_override_eapol);
Hai Shalomfdcde762020-04-02 11:19:20 -0700960 wpabuf_free(conf->rsne_override_ft);
961 wpabuf_free(conf->rsnxe_override_ft);
962 wpabuf_free(conf->gtk_rsc_override);
963 wpabuf_free(conf->igtk_rsc_override);
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000964 wpabuf_free(conf->eapol_m1_elements);
965 wpabuf_free(conf->eapol_m3_elements);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800966#endif /* CONFIG_TESTING_OPTIONS */
967
968 os_free(conf->no_probe_resp_if_seen_on);
969 os_free(conf->no_auth_if_seen_on);
970
Dmitry Shmidt29333592017-01-09 12:27:11 -0800971 hostapd_config_free_fils_realms(conf);
972
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700973#ifdef CONFIG_DPP
Hai Shalomc3565922019-10-28 11:58:20 -0700974 os_free(conf->dpp_name);
975 os_free(conf->dpp_mud_url);
Sunil Ravi89eba102022-09-13 21:04:37 -0700976 os_free(conf->dpp_extra_conf_req_name);
977 os_free(conf->dpp_extra_conf_req_value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700978 os_free(conf->dpp_connector);
979 wpabuf_free(conf->dpp_netaccesskey);
980 wpabuf_free(conf->dpp_csign);
Hai Shalom81f62d82019-07-22 12:10:00 -0700981#ifdef CONFIG_DPP2
982 hostapd_dpp_controller_conf_free(conf->dpp_controller);
983#endif /* CONFIG_DPP2 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700984#endif /* CONFIG_DPP */
985
Roshan Pius3a1667e2018-07-03 15:17:14 -0700986 hostapd_config_free_sae_passwords(conf);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700987
Hai Shalom81f62d82019-07-22 12:10:00 -0700988#ifdef CONFIG_AIRTIME_POLICY
989 {
990 struct airtime_sta_weight *wt, *wt_prev;
991
992 wt = conf->airtime_weight_list;
993 conf->airtime_weight_list = NULL;
994 while (wt) {
995 wt_prev = wt;
996 wt = wt->next;
997 os_free(wt_prev);
998 }
999 }
1000#endif /* CONFIG_AIRTIME_POLICY */
1001
Hai Shalom60840252021-02-19 19:02:11 -08001002#ifdef CONFIG_PASN
1003 os_free(conf->pasn_groups);
1004#endif /* CONFIG_PASN */
1005
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001006 os_free(conf);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001007}
1008
1009
1010/**
1011 * hostapd_config_free - Free hostapd configuration
1012 * @conf: Configuration data from hostapd_config_read().
1013 */
1014void hostapd_config_free(struct hostapd_config *conf)
1015{
1016 size_t i;
1017
1018 if (conf == NULL)
1019 return;
1020
1021 for (i = 0; i < conf->num_bss; i++)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001022 hostapd_config_free_bss(conf->bss[i]);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001023 os_free(conf->bss);
1024 os_free(conf->supported_rates);
1025 os_free(conf->basic_rates);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07001026 os_free(conf->acs_ch_list.range);
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001027 os_free(conf->acs_freq_list.range);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001028 os_free(conf->driver_params);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001029#ifdef CONFIG_ACS
1030 os_free(conf->acs_chan_bias);
1031#endif /* CONFIG_ACS */
Dmitry Shmidt849734c2016-05-27 09:59:01 -07001032 wpabuf_free(conf->lci);
1033 wpabuf_free(conf->civic);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001034
1035 os_free(conf);
1036}
1037
1038
1039/**
1040 * hostapd_maclist_found - Find a MAC address from a list
1041 * @list: MAC address list
1042 * @num_entries: Number of addresses in the list
1043 * @addr: Address to search for
1044 * @vlan_id: Buffer for returning VLAN ID or %NULL if not needed
1045 * Returns: 1 if address is in the list or 0 if not.
1046 *
1047 * Perform a binary search for given MAC address from a pre-sorted list.
1048 */
1049int hostapd_maclist_found(struct mac_acl_entry *list, int num_entries,
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001050 const u8 *addr, struct vlan_description *vlan_id)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001051{
1052 int start, end, middle, res;
1053
1054 start = 0;
1055 end = num_entries - 1;
1056
1057 while (start <= end) {
1058 middle = (start + end) / 2;
1059 res = os_memcmp(list[middle].addr, addr, ETH_ALEN);
1060 if (res == 0) {
1061 if (vlan_id)
1062 *vlan_id = list[middle].vlan_id;
1063 return 1;
1064 }
1065 if (res < 0)
1066 start = middle + 1;
1067 else
1068 end = middle - 1;
1069 }
1070
1071 return 0;
1072}
1073
1074
1075int hostapd_rate_found(int *list, int rate)
1076{
1077 int i;
1078
1079 if (list == NULL)
1080 return 0;
1081
1082 for (i = 0; list[i] >= 0; i++)
1083 if (list[i] == rate)
1084 return 1;
1085
1086 return 0;
1087}
1088
1089
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001090int hostapd_vlan_valid(struct hostapd_vlan *vlan,
1091 struct vlan_description *vlan_desc)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001092{
1093 struct hostapd_vlan *v = vlan;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001094 int i;
1095
1096 if (!vlan_desc->notempty || vlan_desc->untagged < 0 ||
1097 vlan_desc->untagged > MAX_VLAN_ID)
1098 return 0;
1099 for (i = 0; i < MAX_NUM_TAGGED_VLAN; i++) {
1100 if (vlan_desc->tagged[i] < 0 ||
1101 vlan_desc->tagged[i] > MAX_VLAN_ID)
1102 return 0;
1103 }
1104 if (!vlan_desc->untagged && !vlan_desc->tagged[0])
1105 return 0;
1106
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001107 while (v) {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001108 if (!vlan_compare(&v->vlan_desc, vlan_desc) ||
1109 v->vlan_id == VLAN_ID_WILDCARD)
Dmitry Shmidt34af3062013-07-11 10:46:32 -07001110 return 1;
1111 v = v->next;
1112 }
1113 return 0;
1114}
1115
1116
1117const char * hostapd_get_vlan_id_ifname(struct hostapd_vlan *vlan, int vlan_id)
1118{
1119 struct hostapd_vlan *v = vlan;
1120 while (v) {
1121 if (v->vlan_id == vlan_id)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001122 return v->ifname;
1123 v = v->next;
1124 }
1125 return NULL;
1126}
1127
1128
1129const u8 * hostapd_get_psk(const struct hostapd_bss_config *conf,
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001130 const u8 *addr, const u8 *p2p_dev_addr,
Hai Shalom021b0b52019-04-10 11:17:58 -07001131 const u8 *prev_psk, int *vlan_id)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001132{
1133 struct hostapd_wpa_psk *psk;
1134 int next_ok = prev_psk == NULL;
1135
Hai Shalom021b0b52019-04-10 11:17:58 -07001136 if (vlan_id)
1137 *vlan_id = 0;
1138
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001139 if (p2p_dev_addr && !is_zero_ether_addr(p2p_dev_addr)) {
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001140 wpa_printf(MSG_DEBUG, "Searching a PSK for " MACSTR
1141 " p2p_dev_addr=" MACSTR " prev_psk=%p",
1142 MAC2STR(addr), MAC2STR(p2p_dev_addr), prev_psk);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001143 addr = NULL; /* Use P2P Device Address for matching */
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001144 } else {
1145 wpa_printf(MSG_DEBUG, "Searching a PSK for " MACSTR
1146 " prev_psk=%p",
1147 MAC2STR(addr), prev_psk);
1148 }
1149
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001150 for (psk = conf->ssid.wpa_psk; psk != NULL; psk = psk->next) {
1151 if (next_ok &&
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001152 (psk->group ||
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001153 (addr && ether_addr_equal(psk->addr, addr)) ||
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001154 (!addr && p2p_dev_addr &&
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001155 ether_addr_equal(psk->p2p_dev_addr, p2p_dev_addr)))) {
Hai Shalom021b0b52019-04-10 11:17:58 -07001156 if (vlan_id)
1157 *vlan_id = psk->vlan_id;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001158 return psk->psk;
Hai Shalom021b0b52019-04-10 11:17:58 -07001159 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001160
1161 if (psk->psk == prev_psk)
1162 next_ok = 1;
1163 }
1164
1165 return NULL;
1166}
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001167
1168
Hai Shalom899fcc72020-10-19 14:38:18 -07001169#ifdef CONFIG_SAE_PK
1170static bool hostapd_sae_pk_password_without_pk(struct hostapd_bss_config *bss)
1171{
1172 struct sae_password_entry *pw;
1173 bool res = false;
1174
1175 if (bss->ssid.wpa_passphrase &&
1176#ifdef CONFIG_TESTING_OPTIONS
1177 !bss->sae_pk_password_check_skip &&
1178#endif /* CONFIG_TESTING_OPTIONS */
1179 sae_pk_valid_password(bss->ssid.wpa_passphrase))
1180 res = true;
1181
1182 for (pw = bss->sae_passwords; pw; pw = pw->next) {
1183 if (!pw->pk &&
1184#ifdef CONFIG_TESTING_OPTIONS
1185 !bss->sae_pk_password_check_skip &&
1186#endif /* CONFIG_TESTING_OPTIONS */
1187 sae_pk_valid_password(pw->password))
1188 return true;
1189
1190 if (bss->ssid.wpa_passphrase && res && pw->pk &&
1191 os_strcmp(bss->ssid.wpa_passphrase, pw->password) == 0)
1192 res = false;
1193 }
1194
1195 return res;
1196}
1197#endif /* CONFIG_SAE_PK */
1198
1199
Hai Shalom60840252021-02-19 19:02:11 -08001200static bool hostapd_config_check_bss_6g(struct hostapd_bss_config *bss)
1201{
1202 if (bss->wpa != WPA_PROTO_RSN) {
1203 wpa_printf(MSG_ERROR,
1204 "Pre-RSNA security methods are not allowed in 6 GHz");
1205 return false;
1206 }
1207
1208 if (bss->ieee80211w != MGMT_FRAME_PROTECTION_REQUIRED) {
1209 wpa_printf(MSG_ERROR,
1210 "Management frame protection is required in 6 GHz");
1211 return false;
1212 }
1213
1214 if (bss->wpa_key_mgmt & (WPA_KEY_MGMT_PSK |
1215 WPA_KEY_MGMT_FT_PSK |
1216 WPA_KEY_MGMT_PSK_SHA256)) {
1217 wpa_printf(MSG_ERROR, "Invalid AKM suite for 6 GHz");
1218 return false;
1219 }
1220
1221 if (bss->rsn_pairwise & (WPA_CIPHER_WEP40 |
1222 WPA_CIPHER_WEP104 |
1223 WPA_CIPHER_TKIP)) {
1224 wpa_printf(MSG_ERROR,
1225 "Invalid pairwise cipher suite for 6 GHz");
1226 return false;
1227 }
1228
1229 if (bss->wpa_group & (WPA_CIPHER_WEP40 |
1230 WPA_CIPHER_WEP104 |
1231 WPA_CIPHER_TKIP)) {
1232 wpa_printf(MSG_ERROR, "Invalid group cipher suite for 6 GHz");
1233 return false;
1234 }
1235
Sunil Ravi77d572f2023-01-17 23:58:31 +00001236#ifdef CONFIG_SAE
1237 if (wpa_key_mgmt_sae(bss->wpa_key_mgmt) &&
1238 bss->sae_pwe == SAE_PWE_HUNT_AND_PECK) {
1239 wpa_printf(MSG_INFO, "SAE: Enabling SAE H2E on 6 GHz");
1240 bss->sae_pwe = SAE_PWE_BOTH;
1241 }
1242#endif /* CONFIG_SAE */
1243
Hai Shalom60840252021-02-19 19:02:11 -08001244 return true;
1245}
1246
1247
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001248static int hostapd_config_check_bss(struct hostapd_bss_config *bss,
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001249 struct hostapd_config *conf,
1250 int full_config)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001251{
Hai Shalom60840252021-02-19 19:02:11 -08001252 if (full_config && is_6ghz_op_class(conf->op_class) &&
1253 !hostapd_config_check_bss_6g(bss))
1254 return -1;
1255
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001256 if (full_config && bss->ieee802_1x && !bss->eap_server &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001257 !bss->radius->auth_servers) {
1258 wpa_printf(MSG_ERROR, "Invalid IEEE 802.1X configuration (no "
1259 "EAP authenticator configured).");
1260 return -1;
1261 }
1262
Hai Shalomfdcde762020-04-02 11:19:20 -07001263#ifdef CONFIG_WEP
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001264 if (bss->wpa) {
1265 int wep, i;
1266
1267 wep = bss->default_wep_key_len > 0 ||
1268 bss->individual_wep_key_len > 0;
1269 for (i = 0; i < NUM_WEP_KEYS; i++) {
1270 if (bss->ssid.wep.keys_set) {
1271 wep = 1;
1272 break;
1273 }
1274 }
1275
1276 if (wep) {
1277 wpa_printf(MSG_ERROR, "WEP configuration in a WPA network is not supported");
1278 return -1;
1279 }
1280 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001281#endif /* CONFIG_WEP */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001282
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001283 if (full_config && bss->wpa &&
1284 bss->wpa_psk_radius != PSK_RADIUS_IGNORED &&
Sunil Ravia04bd252022-05-02 22:54:18 -07001285 bss->wpa_psk_radius != PSK_RADIUS_DURING_4WAY_HS &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001286 bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH) {
1287 wpa_printf(MSG_ERROR, "WPA-PSK using RADIUS enabled, but no "
1288 "RADIUS checking (macaddr_acl=2) enabled.");
1289 return -1;
1290 }
1291
Sunil Ravia04bd252022-05-02 22:54:18 -07001292 if (full_config && bss->wpa &&
1293 wpa_key_mgmt_wpa_psk_no_sae(bss->wpa_key_mgmt) &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001294 bss->ssid.wpa_psk == NULL && bss->ssid.wpa_passphrase == NULL &&
1295 bss->ssid.wpa_psk_file == NULL &&
Sunil Ravia04bd252022-05-02 22:54:18 -07001296 bss->wpa_psk_radius != PSK_RADIUS_DURING_4WAY_HS &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001297 (bss->wpa_psk_radius != PSK_RADIUS_REQUIRED ||
1298 bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH)) {
1299 wpa_printf(MSG_ERROR, "WPA-PSK enabled, but PSK or passphrase "
1300 "is not configured.");
1301 return -1;
1302 }
1303
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001304 if (full_config && !is_zero_ether_addr(bss->bssid)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001305 size_t i;
1306
1307 for (i = 0; i < conf->num_bss; i++) {
1308 if (conf->bss[i] != bss &&
1309 (hostapd_mac_comp(conf->bss[i]->bssid,
1310 bss->bssid) == 0)) {
1311 wpa_printf(MSG_ERROR, "Duplicate BSSID " MACSTR
1312 " on interface '%s' and '%s'.",
1313 MAC2STR(bss->bssid),
1314 conf->bss[i]->iface, bss->iface);
1315 return -1;
1316 }
1317 }
1318 }
1319
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001320#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001321 if (full_config && wpa_key_mgmt_ft(bss->wpa_key_mgmt) &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001322 (bss->nas_identifier == NULL ||
1323 os_strlen(bss->nas_identifier) < 1 ||
1324 os_strlen(bss->nas_identifier) > FT_R0KH_ID_MAX_LEN)) {
1325 wpa_printf(MSG_ERROR, "FT (IEEE 802.11r) requires "
1326 "nas_identifier to be configured as a 1..48 octet "
1327 "string");
1328 return -1;
1329 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001330#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001331
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001332 if (full_config && conf->ieee80211n &&
1333 conf->hw_mode == HOSTAPD_MODE_IEEE80211B) {
Hai Shalom60840252021-02-19 19:02:11 -08001334 bss->disable_11n = true;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001335 wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) in 11b mode is not "
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001336 "allowed, disabling HT capabilities");
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001337 }
1338
Hai Shalomfdcde762020-04-02 11:19:20 -07001339#ifdef CONFIG_WEP
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001340 if (full_config && conf->ieee80211n &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001341 bss->ssid.security_policy == SECURITY_STATIC_WEP) {
Hai Shalom60840252021-02-19 19:02:11 -08001342 bss->disable_11n = true;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001343 wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) with WEP is not "
1344 "allowed, disabling HT capabilities");
1345 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001346#endif /* CONFIG_WEP */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001347
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001348 if (full_config && conf->ieee80211n && bss->wpa &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001349 !(bss->wpa_pairwise & WPA_CIPHER_CCMP) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001350 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
1351 WPA_CIPHER_CCMP_256 | WPA_CIPHER_GCMP_256)))
1352 {
Hai Shalom60840252021-02-19 19:02:11 -08001353 bss->disable_11n = true;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001354 wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) with WPA/WPA2 "
1355 "requires CCMP/GCMP to be enabled, disabling HT "
1356 "capabilities");
1357 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001358
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07001359#ifdef CONFIG_IEEE80211AC
Hai Shalomfdcde762020-04-02 11:19:20 -07001360#ifdef CONFIG_WEP
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07001361 if (full_config && conf->ieee80211ac &&
1362 bss->ssid.security_policy == SECURITY_STATIC_WEP) {
Hai Shalom60840252021-02-19 19:02:11 -08001363 bss->disable_11ac = true;
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07001364 wpa_printf(MSG_ERROR,
1365 "VHT (IEEE 802.11ac) with WEP is not allowed, disabling VHT capabilities");
1366 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001367#endif /* CONFIG_WEP */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001368
1369 if (full_config && conf->ieee80211ac && bss->wpa &&
1370 !(bss->wpa_pairwise & WPA_CIPHER_CCMP) &&
1371 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
1372 WPA_CIPHER_CCMP_256 | WPA_CIPHER_GCMP_256)))
1373 {
Hai Shalom60840252021-02-19 19:02:11 -08001374 bss->disable_11ac = true;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001375 wpa_printf(MSG_ERROR,
1376 "VHT (IEEE 802.11ac) with WPA/WPA2 requires CCMP/GCMP to be enabled, disabling VHT capabilities");
1377 }
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07001378#endif /* CONFIG_IEEE80211AC */
1379
Hai Shalom60840252021-02-19 19:02:11 -08001380#ifdef CONFIG_IEEE80211AX
1381#ifdef CONFIG_WEP
1382 if (full_config && conf->ieee80211ax &&
1383 bss->ssid.security_policy == SECURITY_STATIC_WEP) {
1384 bss->disable_11ax = true;
1385 wpa_printf(MSG_ERROR,
1386 "HE (IEEE 802.11ax) with WEP is not allowed, disabling HE capabilities");
1387 }
1388#endif /* CONFIG_WEP */
1389
1390 if (full_config && conf->ieee80211ax && bss->wpa &&
1391 !(bss->wpa_pairwise & WPA_CIPHER_CCMP) &&
1392 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
1393 WPA_CIPHER_CCMP_256 | WPA_CIPHER_GCMP_256)))
1394 {
1395 bss->disable_11ax = true;
1396 wpa_printf(MSG_ERROR,
1397 "HE (IEEE 802.11ax) with WPA/WPA2 requires CCMP/GCMP to be enabled, disabling HE capabilities");
1398 }
1399#endif /* CONFIG_IEEE80211AX */
1400
Dmitry Shmidt15907092014-03-25 10:42:57 -07001401#ifdef CONFIG_WPS
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001402 if (full_config && bss->wps_state && bss->ignore_broadcast_ssid) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001403 wpa_printf(MSG_INFO, "WPS: ignore_broadcast_ssid "
1404 "configuration forced WPS to be disabled");
1405 bss->wps_state = 0;
1406 }
1407
Hai Shalomfdcde762020-04-02 11:19:20 -07001408#ifdef CONFIG_WEP
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001409 if (full_config && bss->wps_state &&
1410 bss->ssid.wep.keys_set && bss->wpa == 0) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001411 wpa_printf(MSG_INFO, "WPS: WEP configuration forced WPS to be "
1412 "disabled");
1413 bss->wps_state = 0;
1414 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001415#endif /* CONFIG_WEP */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001416
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001417 if (full_config && bss->wps_state && bss->wpa &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001418 (!(bss->wpa & 2) ||
Roshan Pius3a1667e2018-07-03 15:17:14 -07001419 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
1420 WPA_CIPHER_CCMP_256 |
1421 WPA_CIPHER_GCMP_256)))) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001422 wpa_printf(MSG_INFO, "WPS: WPA/TKIP configuration without "
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07001423 "WPA2/CCMP/GCMP forced WPS to be disabled");
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001424 bss->wps_state = 0;
1425 }
Dmitry Shmidt15907092014-03-25 10:42:57 -07001426#endif /* CONFIG_WPS */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001427
1428#ifdef CONFIG_HS20
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001429 if (full_config && bss->hs20 &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001430 (!(bss->wpa & 2) ||
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001431 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
1432 WPA_CIPHER_CCMP_256 |
1433 WPA_CIPHER_GCMP_256)))) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001434 wpa_printf(MSG_ERROR, "HS 2.0: WPA2-Enterprise/CCMP "
1435 "configuration is required for Hotspot 2.0 "
1436 "functionality");
1437 return -1;
1438 }
1439#endif /* CONFIG_HS20 */
1440
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001441#ifdef CONFIG_MBO
1442 if (full_config && bss->mbo_enabled && (bss->wpa & 2) &&
1443 bss->ieee80211w == NO_MGMT_FRAME_PROTECTION) {
1444 wpa_printf(MSG_ERROR,
1445 "MBO: PMF needs to be enabled whenever using WPA2 with MBO");
1446 return -1;
1447 }
1448#endif /* CONFIG_MBO */
1449
Hai Shalom74f70d42019-02-11 14:42:39 -08001450#ifdef CONFIG_OCV
1451 if (full_config && bss->ieee80211w == NO_MGMT_FRAME_PROTECTION &&
1452 bss->ocv) {
1453 wpa_printf(MSG_ERROR,
1454 "OCV: PMF needs to be enabled whenever using OCV");
1455 return -1;
1456 }
1457#endif /* CONFIG_OCV */
1458
Hai Shalom899fcc72020-10-19 14:38:18 -07001459#ifdef CONFIG_SAE_PK
1460 if (full_config && hostapd_sae_pk_in_use(bss) &&
1461 hostapd_sae_pk_password_without_pk(bss)) {
1462 wpa_printf(MSG_ERROR,
1463 "SAE-PK: SAE password uses SAE-PK style, but does not have PK configured");
1464 return -1;
1465 }
1466#endif /* CONFIG_SAE_PK */
1467
Hai Shaloma20dcd72022-02-04 13:43:00 -08001468#ifdef CONFIG_FILS
Sunil Ravia04bd252022-05-02 22:54:18 -07001469 if (full_config && bss->fils_discovery_max_int &&
Sunil Ravi036cec52023-03-29 11:35:17 -07001470 (!conf->ieee80211ax || bss->disable_11ax)) {
1471 wpa_printf(MSG_ERROR,
1472 "Currently IEEE 802.11ax support is mandatory to enable FILS discovery transmission.");
1473 return -1;
1474 }
1475
1476 if (full_config && bss->fils_discovery_max_int &&
Hai Shaloma20dcd72022-02-04 13:43:00 -08001477 bss->unsol_bcast_probe_resp_interval) {
1478 wpa_printf(MSG_ERROR,
1479 "Cannot enable both FILS discovery and unsolicited broadcast Probe Response at the same time");
1480 return -1;
1481 }
1482#endif /* CONFIG_FILS */
1483
Sunil Ravia04bd252022-05-02 22:54:18 -07001484#ifdef CONFIG_IEEE80211BE
1485 if (full_config && !bss->disable_11be && bss->disable_11ax) {
1486 bss->disable_11be = true;
1487 wpa_printf(MSG_INFO,
1488 "Disabling IEEE 802.11be as IEEE 802.11ax is disabled for this BSS");
1489 }
1490#endif /* CONFIG_IEEE80211BE */
1491
Sunil Ravi77d572f2023-01-17 23:58:31 +00001492 if (full_config && bss->ignore_broadcast_ssid && conf->mbssid) {
1493 wpa_printf(MSG_ERROR,
1494 "Hidden SSID is not suppored when MBSSID is enabled");
1495 return -1;
1496 }
1497
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001498 return 0;
1499}
1500
1501
Dmitry Shmidt05df46a2015-05-19 11:02:01 -07001502static int hostapd_config_check_cw(struct hostapd_config *conf, int queue)
1503{
1504 int tx_cwmin = conf->tx_queue[queue].cwmin;
1505 int tx_cwmax = conf->tx_queue[queue].cwmax;
1506 int ac_cwmin = conf->wmm_ac_params[queue].cwmin;
1507 int ac_cwmax = conf->wmm_ac_params[queue].cwmax;
1508
1509 if (tx_cwmin > tx_cwmax) {
1510 wpa_printf(MSG_ERROR,
1511 "Invalid TX queue cwMin/cwMax values. cwMin(%d) greater than cwMax(%d)",
1512 tx_cwmin, tx_cwmax);
1513 return -1;
1514 }
1515 if (ac_cwmin > ac_cwmax) {
1516 wpa_printf(MSG_ERROR,
1517 "Invalid WMM AC cwMin/cwMax values. cwMin(%d) greater than cwMax(%d)",
1518 ac_cwmin, ac_cwmax);
1519 return -1;
1520 }
1521 return 0;
1522}
1523
1524
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001525int hostapd_config_check(struct hostapd_config *conf, int full_config)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001526{
1527 size_t i;
1528
Sunil Ravia04bd252022-05-02 22:54:18 -07001529 if (full_config && is_6ghz_op_class(conf->op_class) &&
1530 !conf->hw_mode_set) {
1531 /* Use the appropriate hw_mode value automatically when the
1532 * op_class parameter has been set, but hw_mode was not. */
1533 conf->hw_mode = HOSTAPD_MODE_IEEE80211A;
1534 }
1535
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001536 if (full_config && conf->ieee80211d &&
1537 (!conf->country[0] || !conf->country[1])) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001538 wpa_printf(MSG_ERROR, "Cannot enable IEEE 802.11d without "
1539 "setting the country_code");
1540 return -1;
1541 }
1542
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001543 if (full_config && conf->ieee80211h && !conf->ieee80211d) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001544 wpa_printf(MSG_ERROR, "Cannot enable IEEE 802.11h without "
1545 "IEEE 802.11d enabled");
1546 return -1;
1547 }
1548
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001549 if (full_config && conf->local_pwr_constraint != -1 &&
1550 !conf->ieee80211d) {
1551 wpa_printf(MSG_ERROR, "Cannot add Power Constraint element without Country element");
1552 return -1;
1553 }
1554
1555 if (full_config && conf->spectrum_mgmt_required &&
1556 conf->local_pwr_constraint == -1) {
1557 wpa_printf(MSG_ERROR, "Cannot set Spectrum Management bit without Country and Power Constraint elements");
1558 return -1;
1559 }
1560
Hai Shalom81f62d82019-07-22 12:10:00 -07001561#ifdef CONFIG_AIRTIME_POLICY
1562 if (full_config && conf->airtime_mode > AIRTIME_MODE_STATIC &&
1563 !conf->airtime_update_interval) {
1564 wpa_printf(MSG_ERROR, "Airtime update interval cannot be zero");
1565 return -1;
1566 }
1567#endif /* CONFIG_AIRTIME_POLICY */
Dmitry Shmidt05df46a2015-05-19 11:02:01 -07001568 for (i = 0; i < NUM_TX_QUEUES; i++) {
1569 if (hostapd_config_check_cw(conf, i))
1570 return -1;
1571 }
1572
Sunil Ravia04bd252022-05-02 22:54:18 -07001573#ifdef CONFIG_IEEE80211BE
1574 if (full_config && conf->ieee80211be && !conf->ieee80211ax) {
1575 wpa_printf(MSG_ERROR,
1576 "Cannot set ieee80211be without ieee80211ax");
1577 return -1;
1578 }
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001579
1580 if (full_config)
1581 hostapd_set_and_check_bw320_offset(conf,
1582 conf->eht_bw320_offset);
Sunil Ravia04bd252022-05-02 22:54:18 -07001583#endif /* CONFIG_IEEE80211BE */
1584
Sunil Ravi77d572f2023-01-17 23:58:31 +00001585 if (full_config && conf->mbssid && !conf->ieee80211ax) {
1586 wpa_printf(MSG_ERROR,
1587 "Cannot enable multiple BSSID support without ieee80211ax");
1588 return -1;
1589 }
1590
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001591 for (i = 0; i < conf->num_bss; i++) {
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001592 if (hostapd_config_check_bss(conf->bss[i], conf, full_config))
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001593 return -1;
1594 }
1595
1596 return 0;
1597}
1598
1599
Dmitry Shmidt71757432014-06-02 13:50:35 -07001600void hostapd_set_security_params(struct hostapd_bss_config *bss,
1601 int full_config)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001602{
Hai Shalomfdcde762020-04-02 11:19:20 -07001603#ifdef CONFIG_WEP
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001604 if (bss->individual_wep_key_len == 0) {
1605 /* individual keys are not use; can use key idx0 for
1606 * broadcast keys */
1607 bss->broadcast_key_idx_min = 0;
1608 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001609#endif /* CONFIG_WEP */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001610
1611 if ((bss->wpa & 2) && bss->rsn_pairwise == 0)
1612 bss->rsn_pairwise = bss->wpa_pairwise;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001613 if (bss->group_cipher)
1614 bss->wpa_group = bss->group_cipher;
1615 else
1616 bss->wpa_group = wpa_select_ap_group_cipher(bss->wpa,
1617 bss->wpa_pairwise,
1618 bss->rsn_pairwise);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001619 if (!bss->wpa_group_rekey_set)
1620 bss->wpa_group_rekey = bss->wpa_group == WPA_CIPHER_TKIP ?
1621 600 : 86400;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001622
Dmitry Shmidt71757432014-06-02 13:50:35 -07001623 if (full_config) {
1624 bss->radius->auth_server = bss->radius->auth_servers;
1625 bss->radius->acct_server = bss->radius->acct_servers;
1626 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001627
1628 if (bss->wpa && bss->ieee802_1x) {
1629 bss->ssid.security_policy = SECURITY_WPA;
1630 } else if (bss->wpa) {
1631 bss->ssid.security_policy = SECURITY_WPA_PSK;
1632 } else if (bss->ieee802_1x) {
1633 int cipher = WPA_CIPHER_NONE;
1634 bss->ssid.security_policy = SECURITY_IEEE_802_1X;
Hai Shalomfdcde762020-04-02 11:19:20 -07001635#ifdef CONFIG_WEP
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001636 bss->ssid.wep.default_len = bss->default_wep_key_len;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001637 if (full_config && bss->default_wep_key_len) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001638 cipher = bss->default_wep_key_len >= 13 ?
1639 WPA_CIPHER_WEP104 : WPA_CIPHER_WEP40;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001640 } else if (full_config && bss->ssid.wep.keys_set) {
1641 if (bss->ssid.wep.len[0] >= 13)
1642 cipher = WPA_CIPHER_WEP104;
1643 else
1644 cipher = WPA_CIPHER_WEP40;
1645 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001646#endif /* CONFIG_WEP */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001647 bss->wpa_group = cipher;
1648 bss->wpa_pairwise = cipher;
1649 bss->rsn_pairwise = cipher;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001650 if (full_config)
1651 bss->wpa_key_mgmt = WPA_KEY_MGMT_IEEE8021X_NO_WPA;
Hai Shalomfdcde762020-04-02 11:19:20 -07001652#ifdef CONFIG_WEP
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001653 } else if (bss->ssid.wep.keys_set) {
1654 int cipher = WPA_CIPHER_WEP40;
1655 if (bss->ssid.wep.len[0] >= 13)
1656 cipher = WPA_CIPHER_WEP104;
1657 bss->ssid.security_policy = SECURITY_STATIC_WEP;
1658 bss->wpa_group = cipher;
1659 bss->wpa_pairwise = cipher;
1660 bss->rsn_pairwise = cipher;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001661 if (full_config)
1662 bss->wpa_key_mgmt = WPA_KEY_MGMT_NONE;
Hai Shalomfdcde762020-04-02 11:19:20 -07001663#endif /* CONFIG_WEP */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001664 } else if (bss->osen) {
1665 bss->ssid.security_policy = SECURITY_OSEN;
1666 bss->wpa_group = WPA_CIPHER_CCMP;
1667 bss->wpa_pairwise = 0;
1668 bss->rsn_pairwise = WPA_CIPHER_CCMP;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001669 } else {
1670 bss->ssid.security_policy = SECURITY_PLAINTEXT;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001671 if (full_config) {
1672 bss->wpa_group = WPA_CIPHER_NONE;
1673 bss->wpa_pairwise = WPA_CIPHER_NONE;
1674 bss->rsn_pairwise = WPA_CIPHER_NONE;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001675 bss->wpa_key_mgmt = WPA_KEY_MGMT_NONE;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001676 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001677 }
1678}
Hai Shalom74f70d42019-02-11 14:42:39 -08001679
1680
1681int hostapd_sae_pw_id_in_use(struct hostapd_bss_config *conf)
1682{
1683 int with_id = 0, without_id = 0;
1684 struct sae_password_entry *pw;
1685
1686 if (conf->ssid.wpa_passphrase)
1687 without_id = 1;
1688
1689 for (pw = conf->sae_passwords; pw; pw = pw->next) {
1690 if (pw->identifier)
1691 with_id = 1;
1692 else
1693 without_id = 1;
1694 if (with_id && without_id)
1695 break;
1696 }
1697
1698 if (with_id && !without_id)
1699 return 2;
1700 return with_id;
1701}
Hai Shalom899fcc72020-10-19 14:38:18 -07001702
1703
1704bool hostapd_sae_pk_in_use(struct hostapd_bss_config *conf)
1705{
1706#ifdef CONFIG_SAE_PK
1707 struct sae_password_entry *pw;
1708
1709 for (pw = conf->sae_passwords; pw; pw = pw->next) {
1710 if (pw->pk)
1711 return true;
1712 }
1713#endif /* CONFIG_SAE_PK */
1714
1715 return false;
1716}
1717
1718
1719#ifdef CONFIG_SAE_PK
1720bool hostapd_sae_pk_exclusively(struct hostapd_bss_config *conf)
1721{
1722 bool with_pk = false;
1723 struct sae_password_entry *pw;
1724
1725 if (conf->ssid.wpa_passphrase)
1726 return false;
1727
1728 for (pw = conf->sae_passwords; pw; pw = pw->next) {
1729 if (!pw->pk)
1730 return false;
1731 with_pk = true;
1732 }
1733
1734 return with_pk;
1735}
1736#endif /* CONFIG_SAE_PK */
Sunil Ravia04bd252022-05-02 22:54:18 -07001737
1738
1739int hostapd_acl_comp(const void *a, const void *b)
1740{
1741 const struct mac_acl_entry *aa = a;
1742 const struct mac_acl_entry *bb = b;
1743 return os_memcmp(aa->addr, bb->addr, sizeof(macaddr));
1744}
1745
1746
1747int hostapd_add_acl_maclist(struct mac_acl_entry **acl, int *num,
1748 int vlan_id, const u8 *addr)
1749{
1750 struct mac_acl_entry *newacl;
1751
1752 newacl = os_realloc_array(*acl, *num + 1, sizeof(**acl));
1753 if (!newacl) {
1754 wpa_printf(MSG_ERROR, "MAC list reallocation failed");
1755 return -1;
1756 }
1757
1758 *acl = newacl;
1759 os_memcpy((*acl)[*num].addr, addr, ETH_ALEN);
1760 os_memset(&(*acl)[*num].vlan_id, 0, sizeof((*acl)[*num].vlan_id));
1761 (*acl)[*num].vlan_id.untagged = vlan_id;
1762 (*acl)[*num].vlan_id.notempty = !!vlan_id;
1763 (*num)++;
1764
1765 return 0;
1766}
1767
1768
1769void hostapd_remove_acl_mac(struct mac_acl_entry **acl, int *num,
1770 const u8 *addr)
1771{
1772 int i = 0;
1773
1774 while (i < *num) {
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001775 if (ether_addr_equal((*acl)[i].addr, addr)) {
Sunil Ravia04bd252022-05-02 22:54:18 -07001776 os_remove_in_array(*acl, *num, sizeof(**acl), i);
1777 (*num)--;
1778 } else {
1779 i++;
1780 }
1781 }
1782}