blob: 60d356696ceb8038165bcab4c24b908a894b4cce [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;
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;
168#endif /* CONFIG_TESTING_OPTIONS */
Hai Shaloma20dcd72022-02-04 13:43:00 -0800169
170#ifdef CONFIG_PASN
171 /* comeback after 10 TUs */
172 bss->pasn_comeback_after = 10;
Sunil Ravi640215c2023-06-28 23:08:09 +0000173 bss->pasn_noauth = 1;
Hai Shaloma20dcd72022-02-04 13:43:00 -0800174#endif /* CONFIG_PASN */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700175}
176
177
178struct hostapd_config * hostapd_config_defaults(void)
179{
180#define ecw2cw(ecw) ((1 << (ecw)) - 1)
181
182 struct hostapd_config *conf;
183 struct hostapd_bss_config *bss;
184 const int aCWmin = 4, aCWmax = 10;
185 const struct hostapd_wmm_ac_params ac_bk =
186 { aCWmin, aCWmax, 7, 0, 0 }; /* background traffic */
187 const struct hostapd_wmm_ac_params ac_be =
188 { aCWmin, aCWmax, 3, 0, 0 }; /* best effort traffic */
189 const struct hostapd_wmm_ac_params ac_vi = /* video traffic */
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700190 { aCWmin - 1, aCWmin, 2, 3008 / 32, 0 };
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700191 const struct hostapd_wmm_ac_params ac_vo = /* voice traffic */
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700192 { aCWmin - 2, aCWmin - 1, 2, 1504 / 32, 0 };
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700193 const struct hostapd_tx_queue_params txq_bk =
194 { 7, ecw2cw(aCWmin), ecw2cw(aCWmax), 0 };
195 const struct hostapd_tx_queue_params txq_be =
196 { 3, ecw2cw(aCWmin), 4 * (ecw2cw(aCWmin) + 1) - 1, 0};
197 const struct hostapd_tx_queue_params txq_vi =
198 { 1, (ecw2cw(aCWmin) + 1) / 2 - 1, ecw2cw(aCWmin), 30};
199 const struct hostapd_tx_queue_params txq_vo =
200 { 1, (ecw2cw(aCWmin) + 1) / 4 - 1,
201 (ecw2cw(aCWmin) + 1) / 2 - 1, 15};
202
203#undef ecw2cw
204
205 conf = os_zalloc(sizeof(*conf));
206 bss = os_zalloc(sizeof(*bss));
207 if (conf == NULL || bss == NULL) {
208 wpa_printf(MSG_ERROR, "Failed to allocate memory for "
209 "configuration data.");
210 os_free(conf);
211 os_free(bss);
212 return NULL;
213 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800214 conf->bss = os_calloc(1, sizeof(struct hostapd_bss_config *));
215 if (conf->bss == NULL) {
216 os_free(conf);
217 os_free(bss);
218 return NULL;
219 }
220 conf->bss[0] = bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700221
222 bss->radius = os_zalloc(sizeof(*bss->radius));
223 if (bss->radius == NULL) {
Dmitry Shmidt97672262014-02-03 13:02:54 -0800224 os_free(conf->bss);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700225 os_free(conf);
226 os_free(bss);
227 return NULL;
228 }
229
230 hostapd_config_defaults_bss(bss);
231
232 conf->num_bss = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700233
234 conf->beacon_int = 100;
Hai Shalom021b0b52019-04-10 11:17:58 -0700235 conf->rts_threshold = -2; /* use driver default: 2347 */
236 conf->fragm_threshold = -2; /* user driver default: 2346 */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800237 /* Set to invalid value means do not add Power Constraint IE */
238 conf->local_pwr_constraint = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700239
240 conf->wmm_ac_params[0] = ac_be;
241 conf->wmm_ac_params[1] = ac_bk;
242 conf->wmm_ac_params[2] = ac_vi;
243 conf->wmm_ac_params[3] = ac_vo;
244
245 conf->tx_queue[0] = txq_vo;
246 conf->tx_queue[1] = txq_vi;
247 conf->tx_queue[2] = txq_be;
248 conf->tx_queue[3] = txq_bk;
249
250 conf->ht_capab = HT_CAP_INFO_SMPS_DISABLED;
251
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800252 conf->ap_table_max_size = 255;
253 conf->ap_table_expiration_time = 60;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800254 conf->track_sta_max_age = 180;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800255
Dmitry Shmidt8da800a2013-04-24 12:57:01 -0700256#ifdef CONFIG_TESTING_OPTIONS
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700257 conf->ignore_probe_probability = 0.0;
258 conf->ignore_auth_probability = 0.0;
259 conf->ignore_assoc_probability = 0.0;
260 conf->ignore_reassoc_probability = 0.0;
261 conf->corrupt_gtk_rekey_mic_probability = 0.0;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800262 conf->ecsa_ie_only = 0;
Kai Shie75b0652020-11-24 20:31:29 -0800263 conf->skip_send_eapol = 0;
264 conf->enable_eapol_large_timeout = 0;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -0700265#endif /* CONFIG_TESTING_OPTIONS */
266
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700267 conf->acs = 0;
268 conf->acs_ch_list.num = 0;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700269#ifdef CONFIG_ACS
270 conf->acs_num_scans = 5;
271#endif /* CONFIG_ACS */
272
Hai Shalom81f62d82019-07-22 12:10:00 -0700273#ifdef CONFIG_IEEE80211AX
274 conf->he_op.he_rts_threshold = HE_OPERATION_RTS_THRESHOLD_MASK >>
275 HE_OPERATION_RTS_THRESHOLD_OFFSET;
276 /* Set default basic MCS/NSS set to single stream MCS 0-7 */
277 conf->he_op.he_basic_mcs_nss_set = 0xfffc;
Hai Shalomfdcde762020-04-02 11:19:20 -0700278 conf->he_op.he_bss_color_disabled = 1;
279 conf->he_op.he_bss_color_partial = 0;
Hai Shaloma20dcd72022-02-04 13:43:00 -0800280 conf->he_op.he_bss_color = os_random() % 63 + 1;
281 conf->he_op.he_twt_responder = 1;
Hai Shalom60840252021-02-19 19:02:11 -0800282 conf->he_6ghz_max_mpdu = 2;
283 conf->he_6ghz_max_ampdu_len_exp = 7;
284 conf->he_6ghz_rx_ant_pat = 1;
285 conf->he_6ghz_tx_ant_pat = 1;
Hai Shalom81f62d82019-07-22 12:10:00 -0700286#endif /* CONFIG_IEEE80211AX */
287
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700288 /* The third octet of the country string uses an ASCII space character
289 * by default to indicate that the regulations encompass all
290 * environments for the current frequency band in the country. */
291 conf->country[2] = ' ';
292
Hai Shalom74f70d42019-02-11 14:42:39 -0800293 conf->rssi_reject_assoc_rssi = 0;
294 conf->rssi_reject_assoc_timeout = 30;
295
Hai Shalom81f62d82019-07-22 12:10:00 -0700296#ifdef CONFIG_AIRTIME_POLICY
297 conf->airtime_update_interval = AIRTIME_DEFAULT_UPDATE_INTERVAL;
298#endif /* CONFIG_AIRTIME_POLICY */
299
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700300 return conf;
301}
302
303
304int hostapd_mac_comp(const void *a, const void *b)
305{
306 return os_memcmp(a, b, sizeof(macaddr));
307}
308
309
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700310static int hostapd_config_read_wpa_psk(const char *fname,
311 struct hostapd_ssid *ssid)
312{
313 FILE *f;
314 char buf[128], *pos;
Hai Shalom74f70d42019-02-11 14:42:39 -0800315 const char *keyid;
316 char *context;
317 char *context2;
318 char *token;
319 char *name;
320 char *value;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700321 int line = 0, ret = 0, len, ok;
322 u8 addr[ETH_ALEN];
323 struct hostapd_wpa_psk *psk;
324
325 if (!fname)
326 return 0;
327
328 f = fopen(fname, "r");
329 if (!f) {
330 wpa_printf(MSG_ERROR, "WPA PSK file '%s' not found.", fname);
331 return -1;
332 }
333
334 while (fgets(buf, sizeof(buf), f)) {
Hai Shalom021b0b52019-04-10 11:17:58 -0700335 int vlan_id = 0;
Hai Shalomfdcde762020-04-02 11:19:20 -0700336 int wps = 0;
Hai Shalom021b0b52019-04-10 11:17:58 -0700337
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700338 line++;
339
340 if (buf[0] == '#')
341 continue;
342 pos = buf;
343 while (*pos != '\0') {
344 if (*pos == '\n') {
345 *pos = '\0';
346 break;
347 }
348 pos++;
349 }
350 if (buf[0] == '\0')
351 continue;
352
Hai Shalom74f70d42019-02-11 14:42:39 -0800353 context = NULL;
354 keyid = NULL;
355 while ((token = str_token(buf, " ", &context))) {
356 if (!os_strchr(token, '='))
357 break;
358 context2 = NULL;
359 name = str_token(token, "=", &context2);
Hai Shalom021b0b52019-04-10 11:17:58 -0700360 if (!name)
361 break;
Hai Shalom74f70d42019-02-11 14:42:39 -0800362 value = str_token(token, "", &context2);
363 if (!value)
364 value = "";
365 if (!os_strcmp(name, "keyid")) {
366 keyid = value;
Hai Shalomfdcde762020-04-02 11:19:20 -0700367 } else if (!os_strcmp(name, "wps")) {
368 wps = atoi(value);
Hai Shalom021b0b52019-04-10 11:17:58 -0700369 } else if (!os_strcmp(name, "vlanid")) {
370 vlan_id = atoi(value);
Hai Shalom74f70d42019-02-11 14:42:39 -0800371 } else {
372 wpa_printf(MSG_ERROR,
373 "Unrecognized '%s=%s' on line %d in '%s'",
374 name, value, line, fname);
375 ret = -1;
376 break;
377 }
378 }
379
380 if (ret == -1)
381 break;
382
383 if (!token)
384 token = "";
385 if (hwaddr_aton(token, addr)) {
Hai Shalomfdcde762020-04-02 11:19:20 -0700386 wpa_printf(MSG_ERROR,
387 "Invalid MAC address '%s' on line %d in '%s'",
388 token, line, fname);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700389 ret = -1;
390 break;
391 }
392
393 psk = os_zalloc(sizeof(*psk));
394 if (psk == NULL) {
395 wpa_printf(MSG_ERROR, "WPA PSK allocation failed");
396 ret = -1;
397 break;
398 }
Hai Shalom021b0b52019-04-10 11:17:58 -0700399 psk->vlan_id = vlan_id;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700400 if (is_zero_ether_addr(addr))
401 psk->group = 1;
402 else
403 os_memcpy(psk->addr, addr, ETH_ALEN);
404
Hai Shalom74f70d42019-02-11 14:42:39 -0800405 pos = str_token(buf, "", &context);
406 if (!pos) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700407 wpa_printf(MSG_ERROR, "No PSK on line %d in '%s'",
408 line, fname);
409 os_free(psk);
410 ret = -1;
411 break;
412 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700413
414 ok = 0;
415 len = os_strlen(pos);
Hai Shalomfdcde762020-04-02 11:19:20 -0700416 if (len == 2 * PMK_LEN &&
417 hexstr2bin(pos, psk->psk, PMK_LEN) == 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700418 ok = 1;
Hai Shalomfdcde762020-04-02 11:19:20 -0700419 else if (len >= 8 && len < 64 &&
420 pbkdf2_sha1(pos, ssid->ssid, ssid->ssid_len,
421 4096, psk->psk, PMK_LEN) == 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700422 ok = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700423 if (!ok) {
Hai Shalomfdcde762020-04-02 11:19:20 -0700424 wpa_printf(MSG_ERROR,
425 "Invalid PSK '%s' on line %d in '%s'",
426 pos, line, fname);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700427 os_free(psk);
428 ret = -1;
429 break;
430 }
431
Hai Shalom74f70d42019-02-11 14:42:39 -0800432 if (keyid) {
433 len = os_strlcpy(psk->keyid, keyid, sizeof(psk->keyid));
434 if ((size_t) len >= sizeof(psk->keyid)) {
435 wpa_printf(MSG_ERROR,
436 "PSK keyid too long on line %d in '%s'",
437 line, fname);
438 os_free(psk);
439 ret = -1;
440 break;
441 }
442 }
443
Hai Shalomfdcde762020-04-02 11:19:20 -0700444 psk->wps = wps;
445
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700446 psk->next = ssid->wpa_psk;
447 ssid->wpa_psk = psk;
448 }
449
450 fclose(f);
451
452 return ret;
453}
454
455
456static int hostapd_derive_psk(struct hostapd_ssid *ssid)
457{
458 ssid->wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
459 if (ssid->wpa_psk == NULL) {
460 wpa_printf(MSG_ERROR, "Unable to alloc space for PSK");
461 return -1;
462 }
463 wpa_hexdump_ascii(MSG_DEBUG, "SSID",
464 (u8 *) ssid->ssid, ssid->ssid_len);
465 wpa_hexdump_ascii_key(MSG_DEBUG, "PSK (ASCII passphrase)",
466 (u8 *) ssid->wpa_passphrase,
467 os_strlen(ssid->wpa_passphrase));
Sunil Ravia04bd252022-05-02 22:54:18 -0700468 if (pbkdf2_sha1(ssid->wpa_passphrase,
469 ssid->ssid, ssid->ssid_len,
470 4096, ssid->wpa_psk->psk, PMK_LEN) != 0) {
471 wpa_printf(MSG_ERROR, "Error in pbkdf2_sha1()");
472 return -1;
473 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700474 wpa_hexdump_key(MSG_DEBUG, "PSK (from passphrase)",
475 ssid->wpa_psk->psk, PMK_LEN);
476 return 0;
477}
478
479
Hai Shalomc3565922019-10-28 11:58:20 -0700480int hostapd_setup_sae_pt(struct hostapd_bss_config *conf)
481{
482#ifdef CONFIG_SAE
483 struct hostapd_ssid *ssid = &conf->ssid;
484 struct sae_password_entry *pw;
485
Sunil Ravi77d572f2023-01-17 23:58:31 +0000486 if ((conf->sae_pwe == SAE_PWE_HUNT_AND_PECK &&
487 !hostapd_sae_pw_id_in_use(conf) &&
Sunil Ravi89eba102022-09-13 21:04:37 -0700488 !wpa_key_mgmt_sae_ext_key(conf->wpa_key_mgmt) &&
Hai Shalom899fcc72020-10-19 14:38:18 -0700489 !hostapd_sae_pk_in_use(conf)) ||
Sunil Ravi77d572f2023-01-17 23:58:31 +0000490 conf->sae_pwe == SAE_PWE_FORCE_HUNT_AND_PECK ||
Hai Shalomfdcde762020-04-02 11:19:20 -0700491 !wpa_key_mgmt_sae(conf->wpa_key_mgmt))
Hai Shalomc3565922019-10-28 11:58:20 -0700492 return 0; /* PT not needed */
493
494 sae_deinit_pt(ssid->pt);
495 ssid->pt = NULL;
496 if (ssid->wpa_passphrase) {
497 ssid->pt = sae_derive_pt(conf->sae_groups, ssid->ssid,
498 ssid->ssid_len,
499 (const u8 *) ssid->wpa_passphrase,
500 os_strlen(ssid->wpa_passphrase),
501 NULL);
502 if (!ssid->pt)
503 return -1;
504 }
505
506 for (pw = conf->sae_passwords; pw; pw = pw->next) {
507 sae_deinit_pt(pw->pt);
508 pw->pt = sae_derive_pt(conf->sae_groups, ssid->ssid,
509 ssid->ssid_len,
510 (const u8 *) pw->password,
511 os_strlen(pw->password),
512 pw->identifier);
513 if (!pw->pt)
514 return -1;
515 }
516#endif /* CONFIG_SAE */
517
518 return 0;
519}
520
521
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700522int hostapd_setup_wpa_psk(struct hostapd_bss_config *conf)
523{
524 struct hostapd_ssid *ssid = &conf->ssid;
525
Hai Shalomc3565922019-10-28 11:58:20 -0700526 if (hostapd_setup_sae_pt(conf) < 0)
527 return -1;
528
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700529 if (ssid->wpa_passphrase != NULL) {
530 if (ssid->wpa_psk != NULL) {
531 wpa_printf(MSG_DEBUG, "Using pre-configured WPA PSK "
532 "instead of passphrase");
533 } else {
534 wpa_printf(MSG_DEBUG, "Deriving WPA PSK based on "
535 "passphrase");
536 if (hostapd_derive_psk(ssid) < 0)
537 return -1;
538 }
539 ssid->wpa_psk->group = 1;
540 }
541
Dmitry Shmidt29333592017-01-09 12:27:11 -0800542 return hostapd_config_read_wpa_psk(ssid->wpa_psk_file, &conf->ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700543}
544
545
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700546static void hostapd_config_free_radius(struct hostapd_radius_server *servers,
547 int num_servers)
548{
549 int i;
550
551 for (i = 0; i < num_servers; i++) {
552 os_free(servers[i].shared_secret);
553 }
554 os_free(servers);
555}
556
557
Dmitry Shmidt04949592012-07-19 12:16:46 -0700558struct hostapd_radius_attr *
559hostapd_config_get_radius_attr(struct hostapd_radius_attr *attr, u8 type)
560{
561 for (; attr; attr = attr->next) {
562 if (attr->type == type)
563 return attr;
564 }
565 return NULL;
566}
567
568
Hai Shalomc3565922019-10-28 11:58:20 -0700569struct hostapd_radius_attr * hostapd_parse_radius_attr(const char *value)
570{
571 const char *pos;
572 char syntax;
573 struct hostapd_radius_attr *attr;
574 size_t len;
575
576 attr = os_zalloc(sizeof(*attr));
577 if (!attr)
578 return NULL;
579
580 attr->type = atoi(value);
581
582 pos = os_strchr(value, ':');
583 if (!pos) {
584 attr->val = wpabuf_alloc(1);
585 if (!attr->val) {
586 os_free(attr);
587 return NULL;
588 }
589 wpabuf_put_u8(attr->val, 0);
590 return attr;
591 }
592
593 pos++;
594 if (pos[0] == '\0' || pos[1] != ':') {
595 os_free(attr);
596 return NULL;
597 }
598 syntax = *pos++;
599 pos++;
600
601 switch (syntax) {
602 case 's':
603 attr->val = wpabuf_alloc_copy(pos, os_strlen(pos));
604 break;
605 case 'x':
606 len = os_strlen(pos);
607 if (len & 1)
608 break;
609 len /= 2;
610 attr->val = wpabuf_alloc(len);
611 if (!attr->val)
612 break;
613 if (hexstr2bin(pos, wpabuf_put(attr->val, len), len) < 0) {
614 wpabuf_free(attr->val);
615 os_free(attr);
616 return NULL;
617 }
618 break;
619 case 'd':
620 attr->val = wpabuf_alloc(4);
621 if (attr->val)
622 wpabuf_put_be32(attr->val, atoi(pos));
623 break;
624 default:
625 os_free(attr);
626 return NULL;
627 }
628
629 if (!attr->val) {
630 os_free(attr);
631 return NULL;
632 }
633
634 return attr;
635}
636
637
638void hostapd_config_free_radius_attr(struct hostapd_radius_attr *attr)
Dmitry Shmidt04949592012-07-19 12:16:46 -0700639{
640 struct hostapd_radius_attr *prev;
641
642 while (attr) {
643 prev = attr;
644 attr = attr->next;
645 wpabuf_free(prev->val);
646 os_free(prev);
647 }
648}
649
650
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700651void hostapd_config_free_eap_user(struct hostapd_eap_user *user)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700652{
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700653 hostapd_config_free_radius_attr(user->accept_attr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700654 os_free(user->identity);
Dmitry Shmidtc2817022014-07-02 10:32:10 -0700655 bin_clear_free(user->password, user->password_len);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700656 bin_clear_free(user->salt, user->salt_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700657 os_free(user);
658}
659
660
Dmitry Shmidt29333592017-01-09 12:27:11 -0800661void hostapd_config_free_eap_users(struct hostapd_eap_user *user)
662{
663 struct hostapd_eap_user *prev_user;
664
665 while (user) {
666 prev_user = user;
667 user = user->next;
668 hostapd_config_free_eap_user(prev_user);
669 }
670}
671
672
Hai Shalomfdcde762020-04-02 11:19:20 -0700673#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700674static void hostapd_config_free_wep(struct hostapd_wep_keys *keys)
675{
676 int i;
677 for (i = 0; i < NUM_WEP_KEYS; i++) {
Dmitry Shmidtc2817022014-07-02 10:32:10 -0700678 bin_clear_free(keys->key[i], keys->len[i]);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700679 keys->key[i] = NULL;
680 }
681}
Hai Shalomfdcde762020-04-02 11:19:20 -0700682#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700683
684
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800685void hostapd_config_clear_wpa_psk(struct hostapd_wpa_psk **l)
686{
687 struct hostapd_wpa_psk *psk, *tmp;
688
689 for (psk = *l; psk;) {
690 tmp = psk;
691 psk = psk->next;
692 bin_clear_free(tmp, sizeof(*tmp));
693 }
694 *l = NULL;
695}
696
697
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800698static void hostapd_config_free_anqp_elem(struct hostapd_bss_config *conf)
699{
700 struct anqp_element *elem;
701
702 while ((elem = dl_list_first(&conf->anqp_elem, struct anqp_element,
703 list))) {
704 dl_list_del(&elem->list);
705 wpabuf_free(elem->payload);
706 os_free(elem);
707 }
708}
709
710
Dmitry Shmidt29333592017-01-09 12:27:11 -0800711static void hostapd_config_free_fils_realms(struct hostapd_bss_config *conf)
712{
713#ifdef CONFIG_FILS
714 struct fils_realm *realm;
715
716 while ((realm = dl_list_first(&conf->fils_realms, struct fils_realm,
717 list))) {
718 dl_list_del(&realm->list);
719 os_free(realm);
720 }
721#endif /* CONFIG_FILS */
722}
723
724
Roshan Pius3a1667e2018-07-03 15:17:14 -0700725static void hostapd_config_free_sae_passwords(struct hostapd_bss_config *conf)
726{
727 struct sae_password_entry *pw, *tmp;
728
729 pw = conf->sae_passwords;
730 conf->sae_passwords = NULL;
731 while (pw) {
732 tmp = pw;
733 pw = pw->next;
734 str_clear_free(tmp->password);
735 os_free(tmp->identifier);
Hai Shalomc3565922019-10-28 11:58:20 -0700736#ifdef CONFIG_SAE
737 sae_deinit_pt(tmp->pt);
738#endif /* CONFIG_SAE */
Hai Shalom899fcc72020-10-19 14:38:18 -0700739#ifdef CONFIG_SAE_PK
740 sae_deinit_pk(tmp->pk);
741#endif /* CONFIG_SAE_PK */
Roshan Pius3a1667e2018-07-03 15:17:14 -0700742 os_free(tmp);
743 }
744}
745
746
Hai Shalom81f62d82019-07-22 12:10:00 -0700747#ifdef CONFIG_DPP2
748static void hostapd_dpp_controller_conf_free(struct dpp_controller_conf *conf)
749{
750 struct dpp_controller_conf *prev;
751
752 while (conf) {
753 prev = conf;
754 conf = conf->next;
755 os_free(prev);
756 }
757}
758#endif /* CONFIG_DPP2 */
759
760
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800761void hostapd_config_free_bss(struct hostapd_bss_config *conf)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700762{
Hai Shalom81f62d82019-07-22 12:10:00 -0700763#if defined(CONFIG_WPS) || defined(CONFIG_HS20)
764 size_t i;
765#endif
766
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700767 if (conf == NULL)
768 return;
769
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800770 hostapd_config_clear_wpa_psk(&conf->ssid.wpa_psk);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700771
Dmitry Shmidtc2817022014-07-02 10:32:10 -0700772 str_clear_free(conf->ssid.wpa_passphrase);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700773 os_free(conf->ssid.wpa_psk_file);
Hai Shalomfdcde762020-04-02 11:19:20 -0700774#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700775 hostapd_config_free_wep(&conf->ssid.wep);
Hai Shalomfdcde762020-04-02 11:19:20 -0700776#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700777#ifdef CONFIG_FULL_DYNAMIC_VLAN
778 os_free(conf->ssid.vlan_tagged_interface);
779#endif /* CONFIG_FULL_DYNAMIC_VLAN */
Hai Shalomc3565922019-10-28 11:58:20 -0700780#ifdef CONFIG_SAE
781 sae_deinit_pt(conf->ssid.pt);
782#endif /* CONFIG_SAE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700783
Dmitry Shmidt29333592017-01-09 12:27:11 -0800784 hostapd_config_free_eap_users(conf->eap_user);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800785 os_free(conf->eap_user_sqlite);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700786
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700787 os_free(conf->eap_req_id_text);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800788 os_free(conf->erp_domain);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700789 os_free(conf->accept_mac);
790 os_free(conf->deny_mac);
791 os_free(conf->nas_identifier);
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800792 if (conf->radius) {
793 hostapd_config_free_radius(conf->radius->auth_servers,
794 conf->radius->num_auth_servers);
795 hostapd_config_free_radius(conf->radius->acct_servers,
796 conf->radius->num_acct_servers);
Hai Shaloma20dcd72022-02-04 13:43:00 -0800797 os_free(conf->radius->force_client_dev);
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800798 }
Dmitry Shmidt04949592012-07-19 12:16:46 -0700799 hostapd_config_free_radius_attr(conf->radius_auth_req_attr);
800 hostapd_config_free_radius_attr(conf->radius_acct_req_attr);
Hai Shalomc3565922019-10-28 11:58:20 -0700801 os_free(conf->radius_req_attr_sqlite);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700802 os_free(conf->rsn_preauth_interfaces);
803 os_free(conf->ctrl_interface);
Sunil Ravi77d572f2023-01-17 23:58:31 +0000804 os_free(conf->config_id);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700805 os_free(conf->ca_cert);
806 os_free(conf->server_cert);
Hai Shalom81f62d82019-07-22 12:10:00 -0700807 os_free(conf->server_cert2);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700808 os_free(conf->private_key);
Hai Shalom81f62d82019-07-22 12:10:00 -0700809 os_free(conf->private_key2);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700810 os_free(conf->private_key_passwd);
Hai Shalom81f62d82019-07-22 12:10:00 -0700811 os_free(conf->private_key_passwd2);
Hai Shalom021b0b52019-04-10 11:17:58 -0700812 os_free(conf->check_cert_subject);
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700813 os_free(conf->ocsp_stapling_response);
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -0800814 os_free(conf->ocsp_stapling_response_multi);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700815 os_free(conf->dh_file);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800816 os_free(conf->openssl_ciphers);
Hai Shalom74f70d42019-02-11 14:42:39 -0800817 os_free(conf->openssl_ecdh_curves);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700818 os_free(conf->pac_opaque_encr_key);
819 os_free(conf->eap_fast_a_id);
820 os_free(conf->eap_fast_a_id_info);
821 os_free(conf->eap_sim_db);
Sunil Ravia04bd252022-05-02 22:54:18 -0700822 os_free(conf->imsi_privacy_key);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700823 os_free(conf->radius_server_clients);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700824 os_free(conf->radius);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700825 os_free(conf->radius_das_shared_secret);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700826 hostapd_config_free_vlan(conf);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800827 os_free(conf->time_zone);
828
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800829#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700830 {
831 struct ft_remote_r0kh *r0kh, *r0kh_prev;
832 struct ft_remote_r1kh *r1kh, *r1kh_prev;
833
834 r0kh = conf->r0kh_list;
835 conf->r0kh_list = NULL;
836 while (r0kh) {
837 r0kh_prev = r0kh;
838 r0kh = r0kh->next;
839 os_free(r0kh_prev);
840 }
841
842 r1kh = conf->r1kh_list;
843 conf->r1kh_list = NULL;
844 while (r1kh) {
845 r1kh_prev = r1kh;
846 r1kh = r1kh->next;
847 os_free(r1kh_prev);
848 }
849 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800850#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700851
852#ifdef CONFIG_WPS
853 os_free(conf->wps_pin_requests);
854 os_free(conf->device_name);
855 os_free(conf->manufacturer);
856 os_free(conf->model_name);
857 os_free(conf->model_number);
858 os_free(conf->serial_number);
859 os_free(conf->config_methods);
860 os_free(conf->ap_pin);
861 os_free(conf->extra_cred);
862 os_free(conf->ap_settings);
Hai Shalom021b0b52019-04-10 11:17:58 -0700863 hostapd_config_clear_wpa_psk(&conf->multi_ap_backhaul_ssid.wpa_psk);
864 str_clear_free(conf->multi_ap_backhaul_ssid.wpa_passphrase);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700865 os_free(conf->upnp_iface);
866 os_free(conf->friendly_name);
867 os_free(conf->manufacturer_url);
868 os_free(conf->model_description);
869 os_free(conf->model_url);
870 os_free(conf->upc);
Hai Shalom81f62d82019-07-22 12:10:00 -0700871 for (i = 0; i < MAX_WPS_VENDOR_EXTENSIONS; i++)
872 wpabuf_free(conf->wps_vendor_ext[i]);
Hai Shalomfdcde762020-04-02 11:19:20 -0700873 wpabuf_free(conf->wps_application_ext);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700874 wpabuf_free(conf->wps_nfc_dh_pubkey);
875 wpabuf_free(conf->wps_nfc_dh_privkey);
876 wpabuf_free(conf->wps_nfc_dev_pw);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700877#endif /* CONFIG_WPS */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800878
879 os_free(conf->roaming_consortium);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700880 os_free(conf->venue_name);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700881 os_free(conf->venue_url);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700882 os_free(conf->nai_realm_data);
883 os_free(conf->network_auth_type);
884 os_free(conf->anqp_3gpp_cell_net);
885 os_free(conf->domain_name);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800886 hostapd_config_free_anqp_elem(conf);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800887
888#ifdef CONFIG_RADIUS_TEST
889 os_free(conf->dump_msk_file);
890#endif /* CONFIG_RADIUS_TEST */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700891
892#ifdef CONFIG_HS20
893 os_free(conf->hs20_oper_friendly_name);
894 os_free(conf->hs20_wan_metrics);
895 os_free(conf->hs20_connection_capability);
896 os_free(conf->hs20_operating_class);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800897 os_free(conf->hs20_icons);
898 if (conf->hs20_osu_providers) {
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800899 for (i = 0; i < conf->hs20_osu_providers_count; i++) {
900 struct hs20_osu_provider *p;
901 size_t j;
902 p = &conf->hs20_osu_providers[i];
903 os_free(p->friendly_name);
904 os_free(p->server_uri);
905 os_free(p->method_list);
906 for (j = 0; j < p->icons_count; j++)
907 os_free(p->icons[j]);
908 os_free(p->icons);
909 os_free(p->osu_nai);
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800910 os_free(p->osu_nai2);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800911 os_free(p->service_desc);
912 }
913 os_free(conf->hs20_osu_providers);
914 }
Roshan Pius3a1667e2018-07-03 15:17:14 -0700915 if (conf->hs20_operator_icon) {
Roshan Pius3a1667e2018-07-03 15:17:14 -0700916 for (i = 0; i < conf->hs20_operator_icon_count; i++)
917 os_free(conf->hs20_operator_icon[i]);
918 os_free(conf->hs20_operator_icon);
919 }
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800920 os_free(conf->subscr_remediation_url);
Hai Shalom74f70d42019-02-11 14:42:39 -0800921 os_free(conf->hs20_sim_provisioning_url);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700922 os_free(conf->t_c_filename);
923 os_free(conf->t_c_server_url);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700924#endif /* CONFIG_HS20 */
925
926 wpabuf_free(conf->vendor_elements);
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700927 wpabuf_free(conf->assocresp_elements);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800928
929 os_free(conf->sae_groups);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700930#ifdef CONFIG_OWE
931 os_free(conf->owe_groups);
932#endif /* CONFIG_OWE */
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700933
Dmitry Shmidt0207e232014-09-03 14:58:37 -0700934 os_free(conf->wowlan_triggers);
935
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700936 os_free(conf->server_id);
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800937
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800938#ifdef CONFIG_TESTING_OPTIONS
939 wpabuf_free(conf->own_ie_override);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700940 wpabuf_free(conf->sae_commit_override);
Hai Shalomfdcde762020-04-02 11:19:20 -0700941 wpabuf_free(conf->rsne_override_eapol);
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800942 wpabuf_free(conf->rsnxe_override_eapol);
Hai Shalomfdcde762020-04-02 11:19:20 -0700943 wpabuf_free(conf->rsne_override_ft);
944 wpabuf_free(conf->rsnxe_override_ft);
945 wpabuf_free(conf->gtk_rsc_override);
946 wpabuf_free(conf->igtk_rsc_override);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800947#endif /* CONFIG_TESTING_OPTIONS */
948
949 os_free(conf->no_probe_resp_if_seen_on);
950 os_free(conf->no_auth_if_seen_on);
951
Dmitry Shmidt29333592017-01-09 12:27:11 -0800952 hostapd_config_free_fils_realms(conf);
953
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700954#ifdef CONFIG_DPP
Hai Shalomc3565922019-10-28 11:58:20 -0700955 os_free(conf->dpp_name);
956 os_free(conf->dpp_mud_url);
Sunil Ravi89eba102022-09-13 21:04:37 -0700957 os_free(conf->dpp_extra_conf_req_name);
958 os_free(conf->dpp_extra_conf_req_value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700959 os_free(conf->dpp_connector);
960 wpabuf_free(conf->dpp_netaccesskey);
961 wpabuf_free(conf->dpp_csign);
Hai Shalom81f62d82019-07-22 12:10:00 -0700962#ifdef CONFIG_DPP2
963 hostapd_dpp_controller_conf_free(conf->dpp_controller);
964#endif /* CONFIG_DPP2 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700965#endif /* CONFIG_DPP */
966
Roshan Pius3a1667e2018-07-03 15:17:14 -0700967 hostapd_config_free_sae_passwords(conf);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700968
Hai Shalom81f62d82019-07-22 12:10:00 -0700969#ifdef CONFIG_AIRTIME_POLICY
970 {
971 struct airtime_sta_weight *wt, *wt_prev;
972
973 wt = conf->airtime_weight_list;
974 conf->airtime_weight_list = NULL;
975 while (wt) {
976 wt_prev = wt;
977 wt = wt->next;
978 os_free(wt_prev);
979 }
980 }
981#endif /* CONFIG_AIRTIME_POLICY */
982
Hai Shalom60840252021-02-19 19:02:11 -0800983#ifdef CONFIG_PASN
984 os_free(conf->pasn_groups);
985#endif /* CONFIG_PASN */
986
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800987 os_free(conf);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700988}
989
990
991/**
992 * hostapd_config_free - Free hostapd configuration
993 * @conf: Configuration data from hostapd_config_read().
994 */
995void hostapd_config_free(struct hostapd_config *conf)
996{
997 size_t i;
998
999 if (conf == NULL)
1000 return;
1001
1002 for (i = 0; i < conf->num_bss; i++)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001003 hostapd_config_free_bss(conf->bss[i]);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001004 os_free(conf->bss);
1005 os_free(conf->supported_rates);
1006 os_free(conf->basic_rates);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07001007 os_free(conf->acs_ch_list.range);
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001008 os_free(conf->acs_freq_list.range);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001009 os_free(conf->driver_params);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001010#ifdef CONFIG_ACS
1011 os_free(conf->acs_chan_bias);
1012#endif /* CONFIG_ACS */
Dmitry Shmidt849734c2016-05-27 09:59:01 -07001013 wpabuf_free(conf->lci);
1014 wpabuf_free(conf->civic);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001015
1016 os_free(conf);
1017}
1018
1019
1020/**
1021 * hostapd_maclist_found - Find a MAC address from a list
1022 * @list: MAC address list
1023 * @num_entries: Number of addresses in the list
1024 * @addr: Address to search for
1025 * @vlan_id: Buffer for returning VLAN ID or %NULL if not needed
1026 * Returns: 1 if address is in the list or 0 if not.
1027 *
1028 * Perform a binary search for given MAC address from a pre-sorted list.
1029 */
1030int hostapd_maclist_found(struct mac_acl_entry *list, int num_entries,
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001031 const u8 *addr, struct vlan_description *vlan_id)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001032{
1033 int start, end, middle, res;
1034
1035 start = 0;
1036 end = num_entries - 1;
1037
1038 while (start <= end) {
1039 middle = (start + end) / 2;
1040 res = os_memcmp(list[middle].addr, addr, ETH_ALEN);
1041 if (res == 0) {
1042 if (vlan_id)
1043 *vlan_id = list[middle].vlan_id;
1044 return 1;
1045 }
1046 if (res < 0)
1047 start = middle + 1;
1048 else
1049 end = middle - 1;
1050 }
1051
1052 return 0;
1053}
1054
1055
1056int hostapd_rate_found(int *list, int rate)
1057{
1058 int i;
1059
1060 if (list == NULL)
1061 return 0;
1062
1063 for (i = 0; list[i] >= 0; i++)
1064 if (list[i] == rate)
1065 return 1;
1066
1067 return 0;
1068}
1069
1070
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001071int hostapd_vlan_valid(struct hostapd_vlan *vlan,
1072 struct vlan_description *vlan_desc)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001073{
1074 struct hostapd_vlan *v = vlan;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001075 int i;
1076
1077 if (!vlan_desc->notempty || vlan_desc->untagged < 0 ||
1078 vlan_desc->untagged > MAX_VLAN_ID)
1079 return 0;
1080 for (i = 0; i < MAX_NUM_TAGGED_VLAN; i++) {
1081 if (vlan_desc->tagged[i] < 0 ||
1082 vlan_desc->tagged[i] > MAX_VLAN_ID)
1083 return 0;
1084 }
1085 if (!vlan_desc->untagged && !vlan_desc->tagged[0])
1086 return 0;
1087
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001088 while (v) {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001089 if (!vlan_compare(&v->vlan_desc, vlan_desc) ||
1090 v->vlan_id == VLAN_ID_WILDCARD)
Dmitry Shmidt34af3062013-07-11 10:46:32 -07001091 return 1;
1092 v = v->next;
1093 }
1094 return 0;
1095}
1096
1097
1098const char * hostapd_get_vlan_id_ifname(struct hostapd_vlan *vlan, int vlan_id)
1099{
1100 struct hostapd_vlan *v = vlan;
1101 while (v) {
1102 if (v->vlan_id == vlan_id)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001103 return v->ifname;
1104 v = v->next;
1105 }
1106 return NULL;
1107}
1108
1109
1110const u8 * hostapd_get_psk(const struct hostapd_bss_config *conf,
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001111 const u8 *addr, const u8 *p2p_dev_addr,
Hai Shalom021b0b52019-04-10 11:17:58 -07001112 const u8 *prev_psk, int *vlan_id)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001113{
1114 struct hostapd_wpa_psk *psk;
1115 int next_ok = prev_psk == NULL;
1116
Hai Shalom021b0b52019-04-10 11:17:58 -07001117 if (vlan_id)
1118 *vlan_id = 0;
1119
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001120 if (p2p_dev_addr && !is_zero_ether_addr(p2p_dev_addr)) {
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001121 wpa_printf(MSG_DEBUG, "Searching a PSK for " MACSTR
1122 " p2p_dev_addr=" MACSTR " prev_psk=%p",
1123 MAC2STR(addr), MAC2STR(p2p_dev_addr), prev_psk);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001124 addr = NULL; /* Use P2P Device Address for matching */
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001125 } else {
1126 wpa_printf(MSG_DEBUG, "Searching a PSK for " MACSTR
1127 " prev_psk=%p",
1128 MAC2STR(addr), prev_psk);
1129 }
1130
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001131 for (psk = conf->ssid.wpa_psk; psk != NULL; psk = psk->next) {
1132 if (next_ok &&
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001133 (psk->group ||
1134 (addr && os_memcmp(psk->addr, addr, ETH_ALEN) == 0) ||
1135 (!addr && p2p_dev_addr &&
1136 os_memcmp(psk->p2p_dev_addr, p2p_dev_addr, ETH_ALEN) ==
Hai Shalom021b0b52019-04-10 11:17:58 -07001137 0))) {
1138 if (vlan_id)
1139 *vlan_id = psk->vlan_id;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001140 return psk->psk;
Hai Shalom021b0b52019-04-10 11:17:58 -07001141 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001142
1143 if (psk->psk == prev_psk)
1144 next_ok = 1;
1145 }
1146
1147 return NULL;
1148}
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001149
1150
Hai Shalom899fcc72020-10-19 14:38:18 -07001151#ifdef CONFIG_SAE_PK
1152static bool hostapd_sae_pk_password_without_pk(struct hostapd_bss_config *bss)
1153{
1154 struct sae_password_entry *pw;
1155 bool res = false;
1156
1157 if (bss->ssid.wpa_passphrase &&
1158#ifdef CONFIG_TESTING_OPTIONS
1159 !bss->sae_pk_password_check_skip &&
1160#endif /* CONFIG_TESTING_OPTIONS */
1161 sae_pk_valid_password(bss->ssid.wpa_passphrase))
1162 res = true;
1163
1164 for (pw = bss->sae_passwords; pw; pw = pw->next) {
1165 if (!pw->pk &&
1166#ifdef CONFIG_TESTING_OPTIONS
1167 !bss->sae_pk_password_check_skip &&
1168#endif /* CONFIG_TESTING_OPTIONS */
1169 sae_pk_valid_password(pw->password))
1170 return true;
1171
1172 if (bss->ssid.wpa_passphrase && res && pw->pk &&
1173 os_strcmp(bss->ssid.wpa_passphrase, pw->password) == 0)
1174 res = false;
1175 }
1176
1177 return res;
1178}
1179#endif /* CONFIG_SAE_PK */
1180
1181
Hai Shalom60840252021-02-19 19:02:11 -08001182static bool hostapd_config_check_bss_6g(struct hostapd_bss_config *bss)
1183{
1184 if (bss->wpa != WPA_PROTO_RSN) {
1185 wpa_printf(MSG_ERROR,
1186 "Pre-RSNA security methods are not allowed in 6 GHz");
1187 return false;
1188 }
1189
1190 if (bss->ieee80211w != MGMT_FRAME_PROTECTION_REQUIRED) {
1191 wpa_printf(MSG_ERROR,
1192 "Management frame protection is required in 6 GHz");
1193 return false;
1194 }
1195
1196 if (bss->wpa_key_mgmt & (WPA_KEY_MGMT_PSK |
1197 WPA_KEY_MGMT_FT_PSK |
1198 WPA_KEY_MGMT_PSK_SHA256)) {
1199 wpa_printf(MSG_ERROR, "Invalid AKM suite for 6 GHz");
1200 return false;
1201 }
1202
1203 if (bss->rsn_pairwise & (WPA_CIPHER_WEP40 |
1204 WPA_CIPHER_WEP104 |
1205 WPA_CIPHER_TKIP)) {
1206 wpa_printf(MSG_ERROR,
1207 "Invalid pairwise cipher suite for 6 GHz");
1208 return false;
1209 }
1210
1211 if (bss->wpa_group & (WPA_CIPHER_WEP40 |
1212 WPA_CIPHER_WEP104 |
1213 WPA_CIPHER_TKIP)) {
1214 wpa_printf(MSG_ERROR, "Invalid group cipher suite for 6 GHz");
1215 return false;
1216 }
1217
Sunil Ravi77d572f2023-01-17 23:58:31 +00001218#ifdef CONFIG_SAE
1219 if (wpa_key_mgmt_sae(bss->wpa_key_mgmt) &&
1220 bss->sae_pwe == SAE_PWE_HUNT_AND_PECK) {
1221 wpa_printf(MSG_INFO, "SAE: Enabling SAE H2E on 6 GHz");
1222 bss->sae_pwe = SAE_PWE_BOTH;
1223 }
1224#endif /* CONFIG_SAE */
1225
Hai Shalom60840252021-02-19 19:02:11 -08001226 return true;
1227}
1228
1229
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001230static int hostapd_config_check_bss(struct hostapd_bss_config *bss,
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001231 struct hostapd_config *conf,
1232 int full_config)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001233{
Hai Shalom60840252021-02-19 19:02:11 -08001234 if (full_config && is_6ghz_op_class(conf->op_class) &&
1235 !hostapd_config_check_bss_6g(bss))
1236 return -1;
1237
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001238 if (full_config && bss->ieee802_1x && !bss->eap_server &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001239 !bss->radius->auth_servers) {
1240 wpa_printf(MSG_ERROR, "Invalid IEEE 802.1X configuration (no "
1241 "EAP authenticator configured).");
1242 return -1;
1243 }
1244
Hai Shalomfdcde762020-04-02 11:19:20 -07001245#ifdef CONFIG_WEP
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001246 if (bss->wpa) {
1247 int wep, i;
1248
1249 wep = bss->default_wep_key_len > 0 ||
1250 bss->individual_wep_key_len > 0;
1251 for (i = 0; i < NUM_WEP_KEYS; i++) {
1252 if (bss->ssid.wep.keys_set) {
1253 wep = 1;
1254 break;
1255 }
1256 }
1257
1258 if (wep) {
1259 wpa_printf(MSG_ERROR, "WEP configuration in a WPA network is not supported");
1260 return -1;
1261 }
1262 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001263#endif /* CONFIG_WEP */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001264
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001265 if (full_config && bss->wpa &&
1266 bss->wpa_psk_radius != PSK_RADIUS_IGNORED &&
Sunil Ravia04bd252022-05-02 22:54:18 -07001267 bss->wpa_psk_radius != PSK_RADIUS_DURING_4WAY_HS &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001268 bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH) {
1269 wpa_printf(MSG_ERROR, "WPA-PSK using RADIUS enabled, but no "
1270 "RADIUS checking (macaddr_acl=2) enabled.");
1271 return -1;
1272 }
1273
Sunil Ravia04bd252022-05-02 22:54:18 -07001274 if (full_config && bss->wpa &&
1275 wpa_key_mgmt_wpa_psk_no_sae(bss->wpa_key_mgmt) &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001276 bss->ssid.wpa_psk == NULL && bss->ssid.wpa_passphrase == NULL &&
1277 bss->ssid.wpa_psk_file == NULL &&
Sunil Ravia04bd252022-05-02 22:54:18 -07001278 bss->wpa_psk_radius != PSK_RADIUS_DURING_4WAY_HS &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001279 (bss->wpa_psk_radius != PSK_RADIUS_REQUIRED ||
1280 bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH)) {
1281 wpa_printf(MSG_ERROR, "WPA-PSK enabled, but PSK or passphrase "
1282 "is not configured.");
1283 return -1;
1284 }
1285
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001286 if (full_config && !is_zero_ether_addr(bss->bssid)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001287 size_t i;
1288
1289 for (i = 0; i < conf->num_bss; i++) {
1290 if (conf->bss[i] != bss &&
1291 (hostapd_mac_comp(conf->bss[i]->bssid,
1292 bss->bssid) == 0)) {
1293 wpa_printf(MSG_ERROR, "Duplicate BSSID " MACSTR
1294 " on interface '%s' and '%s'.",
1295 MAC2STR(bss->bssid),
1296 conf->bss[i]->iface, bss->iface);
1297 return -1;
1298 }
1299 }
1300 }
1301
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001302#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001303 if (full_config && wpa_key_mgmt_ft(bss->wpa_key_mgmt) &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001304 (bss->nas_identifier == NULL ||
1305 os_strlen(bss->nas_identifier) < 1 ||
1306 os_strlen(bss->nas_identifier) > FT_R0KH_ID_MAX_LEN)) {
1307 wpa_printf(MSG_ERROR, "FT (IEEE 802.11r) requires "
1308 "nas_identifier to be configured as a 1..48 octet "
1309 "string");
1310 return -1;
1311 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001312#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001313
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001314 if (full_config && conf->ieee80211n &&
1315 conf->hw_mode == HOSTAPD_MODE_IEEE80211B) {
Hai Shalom60840252021-02-19 19:02:11 -08001316 bss->disable_11n = true;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001317 wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) in 11b mode is not "
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001318 "allowed, disabling HT capabilities");
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001319 }
1320
Hai Shalomfdcde762020-04-02 11:19:20 -07001321#ifdef CONFIG_WEP
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001322 if (full_config && conf->ieee80211n &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001323 bss->ssid.security_policy == SECURITY_STATIC_WEP) {
Hai Shalom60840252021-02-19 19:02:11 -08001324 bss->disable_11n = true;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001325 wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) with WEP is not "
1326 "allowed, disabling HT capabilities");
1327 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001328#endif /* CONFIG_WEP */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001329
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001330 if (full_config && conf->ieee80211n && bss->wpa &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001331 !(bss->wpa_pairwise & WPA_CIPHER_CCMP) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001332 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
1333 WPA_CIPHER_CCMP_256 | WPA_CIPHER_GCMP_256)))
1334 {
Hai Shalom60840252021-02-19 19:02:11 -08001335 bss->disable_11n = true;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001336 wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) with WPA/WPA2 "
1337 "requires CCMP/GCMP to be enabled, disabling HT "
1338 "capabilities");
1339 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001340
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07001341#ifdef CONFIG_IEEE80211AC
Hai Shalomfdcde762020-04-02 11:19:20 -07001342#ifdef CONFIG_WEP
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07001343 if (full_config && conf->ieee80211ac &&
1344 bss->ssid.security_policy == SECURITY_STATIC_WEP) {
Hai Shalom60840252021-02-19 19:02:11 -08001345 bss->disable_11ac = true;
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07001346 wpa_printf(MSG_ERROR,
1347 "VHT (IEEE 802.11ac) with WEP is not allowed, disabling VHT capabilities");
1348 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001349#endif /* CONFIG_WEP */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001350
1351 if (full_config && conf->ieee80211ac && bss->wpa &&
1352 !(bss->wpa_pairwise & WPA_CIPHER_CCMP) &&
1353 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
1354 WPA_CIPHER_CCMP_256 | WPA_CIPHER_GCMP_256)))
1355 {
Hai Shalom60840252021-02-19 19:02:11 -08001356 bss->disable_11ac = true;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001357 wpa_printf(MSG_ERROR,
1358 "VHT (IEEE 802.11ac) with WPA/WPA2 requires CCMP/GCMP to be enabled, disabling VHT capabilities");
1359 }
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07001360#endif /* CONFIG_IEEE80211AC */
1361
Hai Shalom60840252021-02-19 19:02:11 -08001362#ifdef CONFIG_IEEE80211AX
1363#ifdef CONFIG_WEP
1364 if (full_config && conf->ieee80211ax &&
1365 bss->ssid.security_policy == SECURITY_STATIC_WEP) {
1366 bss->disable_11ax = true;
1367 wpa_printf(MSG_ERROR,
1368 "HE (IEEE 802.11ax) with WEP is not allowed, disabling HE capabilities");
1369 }
1370#endif /* CONFIG_WEP */
1371
1372 if (full_config && conf->ieee80211ax && bss->wpa &&
1373 !(bss->wpa_pairwise & WPA_CIPHER_CCMP) &&
1374 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
1375 WPA_CIPHER_CCMP_256 | WPA_CIPHER_GCMP_256)))
1376 {
1377 bss->disable_11ax = true;
1378 wpa_printf(MSG_ERROR,
1379 "HE (IEEE 802.11ax) with WPA/WPA2 requires CCMP/GCMP to be enabled, disabling HE capabilities");
1380 }
1381#endif /* CONFIG_IEEE80211AX */
1382
Dmitry Shmidt15907092014-03-25 10:42:57 -07001383#ifdef CONFIG_WPS
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001384 if (full_config && bss->wps_state && bss->ignore_broadcast_ssid) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001385 wpa_printf(MSG_INFO, "WPS: ignore_broadcast_ssid "
1386 "configuration forced WPS to be disabled");
1387 bss->wps_state = 0;
1388 }
1389
Hai Shalomfdcde762020-04-02 11:19:20 -07001390#ifdef CONFIG_WEP
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001391 if (full_config && bss->wps_state &&
1392 bss->ssid.wep.keys_set && bss->wpa == 0) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001393 wpa_printf(MSG_INFO, "WPS: WEP configuration forced WPS to be "
1394 "disabled");
1395 bss->wps_state = 0;
1396 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001397#endif /* CONFIG_WEP */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001398
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001399 if (full_config && bss->wps_state && bss->wpa &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001400 (!(bss->wpa & 2) ||
Roshan Pius3a1667e2018-07-03 15:17:14 -07001401 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
1402 WPA_CIPHER_CCMP_256 |
1403 WPA_CIPHER_GCMP_256)))) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001404 wpa_printf(MSG_INFO, "WPS: WPA/TKIP configuration without "
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07001405 "WPA2/CCMP/GCMP forced WPS to be disabled");
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001406 bss->wps_state = 0;
1407 }
Dmitry Shmidt15907092014-03-25 10:42:57 -07001408#endif /* CONFIG_WPS */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001409
1410#ifdef CONFIG_HS20
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001411 if (full_config && bss->hs20 &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001412 (!(bss->wpa & 2) ||
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001413 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
1414 WPA_CIPHER_CCMP_256 |
1415 WPA_CIPHER_GCMP_256)))) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001416 wpa_printf(MSG_ERROR, "HS 2.0: WPA2-Enterprise/CCMP "
1417 "configuration is required for Hotspot 2.0 "
1418 "functionality");
1419 return -1;
1420 }
1421#endif /* CONFIG_HS20 */
1422
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001423#ifdef CONFIG_MBO
1424 if (full_config && bss->mbo_enabled && (bss->wpa & 2) &&
1425 bss->ieee80211w == NO_MGMT_FRAME_PROTECTION) {
1426 wpa_printf(MSG_ERROR,
1427 "MBO: PMF needs to be enabled whenever using WPA2 with MBO");
1428 return -1;
1429 }
1430#endif /* CONFIG_MBO */
1431
Hai Shalom74f70d42019-02-11 14:42:39 -08001432#ifdef CONFIG_OCV
1433 if (full_config && bss->ieee80211w == NO_MGMT_FRAME_PROTECTION &&
1434 bss->ocv) {
1435 wpa_printf(MSG_ERROR,
1436 "OCV: PMF needs to be enabled whenever using OCV");
1437 return -1;
1438 }
1439#endif /* CONFIG_OCV */
1440
Hai Shalom899fcc72020-10-19 14:38:18 -07001441#ifdef CONFIG_SAE_PK
1442 if (full_config && hostapd_sae_pk_in_use(bss) &&
1443 hostapd_sae_pk_password_without_pk(bss)) {
1444 wpa_printf(MSG_ERROR,
1445 "SAE-PK: SAE password uses SAE-PK style, but does not have PK configured");
1446 return -1;
1447 }
1448#endif /* CONFIG_SAE_PK */
1449
Hai Shaloma20dcd72022-02-04 13:43:00 -08001450#ifdef CONFIG_FILS
Sunil Ravia04bd252022-05-02 22:54:18 -07001451 if (full_config && bss->fils_discovery_max_int &&
Sunil Ravi036cec52023-03-29 11:35:17 -07001452 (!conf->ieee80211ax || bss->disable_11ax)) {
1453 wpa_printf(MSG_ERROR,
1454 "Currently IEEE 802.11ax support is mandatory to enable FILS discovery transmission.");
1455 return -1;
1456 }
1457
1458 if (full_config && bss->fils_discovery_max_int &&
Hai Shaloma20dcd72022-02-04 13:43:00 -08001459 bss->unsol_bcast_probe_resp_interval) {
1460 wpa_printf(MSG_ERROR,
1461 "Cannot enable both FILS discovery and unsolicited broadcast Probe Response at the same time");
1462 return -1;
1463 }
1464#endif /* CONFIG_FILS */
1465
Sunil Ravia04bd252022-05-02 22:54:18 -07001466#ifdef CONFIG_IEEE80211BE
1467 if (full_config && !bss->disable_11be && bss->disable_11ax) {
1468 bss->disable_11be = true;
1469 wpa_printf(MSG_INFO,
1470 "Disabling IEEE 802.11be as IEEE 802.11ax is disabled for this BSS");
1471 }
1472#endif /* CONFIG_IEEE80211BE */
1473
Sunil Ravi77d572f2023-01-17 23:58:31 +00001474 if (full_config && bss->ignore_broadcast_ssid && conf->mbssid) {
1475 wpa_printf(MSG_ERROR,
1476 "Hidden SSID is not suppored when MBSSID is enabled");
1477 return -1;
1478 }
1479
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001480 return 0;
1481}
1482
1483
Dmitry Shmidt05df46a2015-05-19 11:02:01 -07001484static int hostapd_config_check_cw(struct hostapd_config *conf, int queue)
1485{
1486 int tx_cwmin = conf->tx_queue[queue].cwmin;
1487 int tx_cwmax = conf->tx_queue[queue].cwmax;
1488 int ac_cwmin = conf->wmm_ac_params[queue].cwmin;
1489 int ac_cwmax = conf->wmm_ac_params[queue].cwmax;
1490
1491 if (tx_cwmin > tx_cwmax) {
1492 wpa_printf(MSG_ERROR,
1493 "Invalid TX queue cwMin/cwMax values. cwMin(%d) greater than cwMax(%d)",
1494 tx_cwmin, tx_cwmax);
1495 return -1;
1496 }
1497 if (ac_cwmin > ac_cwmax) {
1498 wpa_printf(MSG_ERROR,
1499 "Invalid WMM AC cwMin/cwMax values. cwMin(%d) greater than cwMax(%d)",
1500 ac_cwmin, ac_cwmax);
1501 return -1;
1502 }
1503 return 0;
1504}
1505
1506
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001507int hostapd_config_check(struct hostapd_config *conf, int full_config)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001508{
1509 size_t i;
1510
Sunil Ravia04bd252022-05-02 22:54:18 -07001511 if (full_config && is_6ghz_op_class(conf->op_class) &&
1512 !conf->hw_mode_set) {
1513 /* Use the appropriate hw_mode value automatically when the
1514 * op_class parameter has been set, but hw_mode was not. */
1515 conf->hw_mode = HOSTAPD_MODE_IEEE80211A;
1516 }
1517
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001518 if (full_config && conf->ieee80211d &&
1519 (!conf->country[0] || !conf->country[1])) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001520 wpa_printf(MSG_ERROR, "Cannot enable IEEE 802.11d without "
1521 "setting the country_code");
1522 return -1;
1523 }
1524
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001525 if (full_config && conf->ieee80211h && !conf->ieee80211d) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001526 wpa_printf(MSG_ERROR, "Cannot enable IEEE 802.11h without "
1527 "IEEE 802.11d enabled");
1528 return -1;
1529 }
1530
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001531 if (full_config && conf->local_pwr_constraint != -1 &&
1532 !conf->ieee80211d) {
1533 wpa_printf(MSG_ERROR, "Cannot add Power Constraint element without Country element");
1534 return -1;
1535 }
1536
1537 if (full_config && conf->spectrum_mgmt_required &&
1538 conf->local_pwr_constraint == -1) {
1539 wpa_printf(MSG_ERROR, "Cannot set Spectrum Management bit without Country and Power Constraint elements");
1540 return -1;
1541 }
1542
Hai Shalom81f62d82019-07-22 12:10:00 -07001543#ifdef CONFIG_AIRTIME_POLICY
1544 if (full_config && conf->airtime_mode > AIRTIME_MODE_STATIC &&
1545 !conf->airtime_update_interval) {
1546 wpa_printf(MSG_ERROR, "Airtime update interval cannot be zero");
1547 return -1;
1548 }
1549#endif /* CONFIG_AIRTIME_POLICY */
Dmitry Shmidt05df46a2015-05-19 11:02:01 -07001550 for (i = 0; i < NUM_TX_QUEUES; i++) {
1551 if (hostapd_config_check_cw(conf, i))
1552 return -1;
1553 }
1554
Sunil Ravia04bd252022-05-02 22:54:18 -07001555#ifdef CONFIG_IEEE80211BE
1556 if (full_config && conf->ieee80211be && !conf->ieee80211ax) {
1557 wpa_printf(MSG_ERROR,
1558 "Cannot set ieee80211be without ieee80211ax");
1559 return -1;
1560 }
1561#endif /* CONFIG_IEEE80211BE */
1562
Sunil Ravi77d572f2023-01-17 23:58:31 +00001563 if (full_config && conf->mbssid && !conf->ieee80211ax) {
1564 wpa_printf(MSG_ERROR,
1565 "Cannot enable multiple BSSID support without ieee80211ax");
1566 return -1;
1567 }
1568
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001569 for (i = 0; i < conf->num_bss; i++) {
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001570 if (hostapd_config_check_bss(conf->bss[i], conf, full_config))
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001571 return -1;
1572 }
1573
1574 return 0;
1575}
1576
1577
Dmitry Shmidt71757432014-06-02 13:50:35 -07001578void hostapd_set_security_params(struct hostapd_bss_config *bss,
1579 int full_config)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001580{
Hai Shalomfdcde762020-04-02 11:19:20 -07001581#ifdef CONFIG_WEP
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001582 if (bss->individual_wep_key_len == 0) {
1583 /* individual keys are not use; can use key idx0 for
1584 * broadcast keys */
1585 bss->broadcast_key_idx_min = 0;
1586 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001587#endif /* CONFIG_WEP */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001588
1589 if ((bss->wpa & 2) && bss->rsn_pairwise == 0)
1590 bss->rsn_pairwise = bss->wpa_pairwise;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001591 if (bss->group_cipher)
1592 bss->wpa_group = bss->group_cipher;
1593 else
1594 bss->wpa_group = wpa_select_ap_group_cipher(bss->wpa,
1595 bss->wpa_pairwise,
1596 bss->rsn_pairwise);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001597 if (!bss->wpa_group_rekey_set)
1598 bss->wpa_group_rekey = bss->wpa_group == WPA_CIPHER_TKIP ?
1599 600 : 86400;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001600
Dmitry Shmidt71757432014-06-02 13:50:35 -07001601 if (full_config) {
1602 bss->radius->auth_server = bss->radius->auth_servers;
1603 bss->radius->acct_server = bss->radius->acct_servers;
1604 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001605
1606 if (bss->wpa && bss->ieee802_1x) {
1607 bss->ssid.security_policy = SECURITY_WPA;
1608 } else if (bss->wpa) {
1609 bss->ssid.security_policy = SECURITY_WPA_PSK;
1610 } else if (bss->ieee802_1x) {
1611 int cipher = WPA_CIPHER_NONE;
1612 bss->ssid.security_policy = SECURITY_IEEE_802_1X;
Hai Shalomfdcde762020-04-02 11:19:20 -07001613#ifdef CONFIG_WEP
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001614 bss->ssid.wep.default_len = bss->default_wep_key_len;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001615 if (full_config && bss->default_wep_key_len) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001616 cipher = bss->default_wep_key_len >= 13 ?
1617 WPA_CIPHER_WEP104 : WPA_CIPHER_WEP40;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001618 } else if (full_config && bss->ssid.wep.keys_set) {
1619 if (bss->ssid.wep.len[0] >= 13)
1620 cipher = WPA_CIPHER_WEP104;
1621 else
1622 cipher = WPA_CIPHER_WEP40;
1623 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001624#endif /* CONFIG_WEP */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001625 bss->wpa_group = cipher;
1626 bss->wpa_pairwise = cipher;
1627 bss->rsn_pairwise = cipher;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001628 if (full_config)
1629 bss->wpa_key_mgmt = WPA_KEY_MGMT_IEEE8021X_NO_WPA;
Hai Shalomfdcde762020-04-02 11:19:20 -07001630#ifdef CONFIG_WEP
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001631 } else if (bss->ssid.wep.keys_set) {
1632 int cipher = WPA_CIPHER_WEP40;
1633 if (bss->ssid.wep.len[0] >= 13)
1634 cipher = WPA_CIPHER_WEP104;
1635 bss->ssid.security_policy = SECURITY_STATIC_WEP;
1636 bss->wpa_group = cipher;
1637 bss->wpa_pairwise = cipher;
1638 bss->rsn_pairwise = cipher;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001639 if (full_config)
1640 bss->wpa_key_mgmt = WPA_KEY_MGMT_NONE;
Hai Shalomfdcde762020-04-02 11:19:20 -07001641#endif /* CONFIG_WEP */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001642 } else if (bss->osen) {
1643 bss->ssid.security_policy = SECURITY_OSEN;
1644 bss->wpa_group = WPA_CIPHER_CCMP;
1645 bss->wpa_pairwise = 0;
1646 bss->rsn_pairwise = WPA_CIPHER_CCMP;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001647 } else {
1648 bss->ssid.security_policy = SECURITY_PLAINTEXT;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001649 if (full_config) {
1650 bss->wpa_group = WPA_CIPHER_NONE;
1651 bss->wpa_pairwise = WPA_CIPHER_NONE;
1652 bss->rsn_pairwise = WPA_CIPHER_NONE;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001653 bss->wpa_key_mgmt = WPA_KEY_MGMT_NONE;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001654 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001655 }
1656}
Hai Shalom74f70d42019-02-11 14:42:39 -08001657
1658
1659int hostapd_sae_pw_id_in_use(struct hostapd_bss_config *conf)
1660{
1661 int with_id = 0, without_id = 0;
1662 struct sae_password_entry *pw;
1663
1664 if (conf->ssid.wpa_passphrase)
1665 without_id = 1;
1666
1667 for (pw = conf->sae_passwords; pw; pw = pw->next) {
1668 if (pw->identifier)
1669 with_id = 1;
1670 else
1671 without_id = 1;
1672 if (with_id && without_id)
1673 break;
1674 }
1675
1676 if (with_id && !without_id)
1677 return 2;
1678 return with_id;
1679}
Hai Shalom899fcc72020-10-19 14:38:18 -07001680
1681
1682bool hostapd_sae_pk_in_use(struct hostapd_bss_config *conf)
1683{
1684#ifdef CONFIG_SAE_PK
1685 struct sae_password_entry *pw;
1686
1687 for (pw = conf->sae_passwords; pw; pw = pw->next) {
1688 if (pw->pk)
1689 return true;
1690 }
1691#endif /* CONFIG_SAE_PK */
1692
1693 return false;
1694}
1695
1696
1697#ifdef CONFIG_SAE_PK
1698bool hostapd_sae_pk_exclusively(struct hostapd_bss_config *conf)
1699{
1700 bool with_pk = false;
1701 struct sae_password_entry *pw;
1702
1703 if (conf->ssid.wpa_passphrase)
1704 return false;
1705
1706 for (pw = conf->sae_passwords; pw; pw = pw->next) {
1707 if (!pw->pk)
1708 return false;
1709 with_pk = true;
1710 }
1711
1712 return with_pk;
1713}
1714#endif /* CONFIG_SAE_PK */
Sunil Ravia04bd252022-05-02 22:54:18 -07001715
1716
1717int hostapd_acl_comp(const void *a, const void *b)
1718{
1719 const struct mac_acl_entry *aa = a;
1720 const struct mac_acl_entry *bb = b;
1721 return os_memcmp(aa->addr, bb->addr, sizeof(macaddr));
1722}
1723
1724
1725int hostapd_add_acl_maclist(struct mac_acl_entry **acl, int *num,
1726 int vlan_id, const u8 *addr)
1727{
1728 struct mac_acl_entry *newacl;
1729
1730 newacl = os_realloc_array(*acl, *num + 1, sizeof(**acl));
1731 if (!newacl) {
1732 wpa_printf(MSG_ERROR, "MAC list reallocation failed");
1733 return -1;
1734 }
1735
1736 *acl = newacl;
1737 os_memcpy((*acl)[*num].addr, addr, ETH_ALEN);
1738 os_memset(&(*acl)[*num].vlan_id, 0, sizeof((*acl)[*num].vlan_id));
1739 (*acl)[*num].vlan_id.untagged = vlan_id;
1740 (*acl)[*num].vlan_id.notempty = !!vlan_id;
1741 (*num)++;
1742
1743 return 0;
1744}
1745
1746
1747void hostapd_remove_acl_mac(struct mac_acl_entry **acl, int *num,
1748 const u8 *addr)
1749{
1750 int i = 0;
1751
1752 while (i < *num) {
1753 if (os_memcmp((*acl)[i].addr, addr, ETH_ALEN) == 0) {
1754 os_remove_in_array(*acl, *num, sizeof(**acl), i);
1755 (*num)--;
1756 } else {
1757 i++;
1758 }
1759 }
1760}