blob: c8fbb6adaba6a740c2d67a745f751c5781234919 [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;
Sunil Ravi7f769292024-07-23 22:21:32 +000095 bss->bss_max_idle = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070096 bss->eapol_version = EAPOL_VERSION;
97
98 bss->max_listen_interval = 65535;
99
100 bss->pwd_group = 19; /* ECC: GF(p=256) */
101
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700102 bss->assoc_sa_query_max_timeout = 1000;
103 bss->assoc_sa_query_retry_timeout = 201;
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700104 bss->group_mgmt_cipher = WPA_CIPHER_AES_128_CMAC;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700105#ifdef EAP_SERVER_FAST
106 /* both anonymous and authenticated provisioning */
107 bss->eap_fast_prov = 3;
108 bss->pac_key_lifetime = 7 * 24 * 60 * 60;
109 bss->pac_key_refresh_time = 1 * 24 * 60 * 60;
110#endif /* EAP_SERVER_FAST */
111
112 /* Set to -1 as defaults depends on HT in setup */
113 bss->wmm_enabled = -1;
114
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800115#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700116 bss->ft_over_ds = 1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700117 bss->rkh_pos_timeout = 86400;
118 bss->rkh_neg_timeout = 60;
119 bss->rkh_pull_timeout = 1000;
120 bss->rkh_pull_retries = 4;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700121 bss->r0_key_lifetime = 1209600;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800122#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt04949592012-07-19 12:16:46 -0700123
124 bss->radius_das_time_window = 300;
Sunil Ravi7f769292024-07-23 22:21:32 +0000125 bss->radius_require_message_authenticator = 1;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800126
Hai Shaloma20dcd72022-02-04 13:43:00 -0800127 bss->anti_clogging_threshold = 5;
Sunil Ravi7f769292024-07-23 22:21:32 +0000128 bss->sae_sync = 3;
Dmitry Shmidt29333592017-01-09 12:27:11 -0800129
130 bss->gas_frag_limit = 1400;
131
132#ifdef CONFIG_FILS
133 dl_list_init(&bss->fils_realms);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800134 bss->fils_hlp_wait_time = 30;
135 bss->dhcp_server_port = DHCP_SERVER_PORT;
136 bss->dhcp_relay_port = DHCP_SERVER_PORT;
Hai Shalom60840252021-02-19 19:02:11 -0800137 bss->fils_discovery_min_int = 20;
Dmitry Shmidt29333592017-01-09 12:27:11 -0800138#endif /* CONFIG_FILS */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700139
140 bss->broadcast_deauth = 1;
141
142#ifdef CONFIG_MBO
143 bss->mbo_cell_data_conn_pref = -1;
144#endif /* CONFIG_MBO */
Roshan Pius3a1667e2018-07-03 15:17:14 -0700145
146 /* Disable TLS v1.3 by default for now to avoid interoperability issue.
147 * This can be enabled by default once the implementation has been fully
148 * completed and tested with other implementations. */
149 bss->tls_flags = TLS_CONN_DISABLE_TLSv1_3;
Hai Shalom74f70d42019-02-11 14:42:39 -0800150
Hai Shalomc3565922019-10-28 11:58:20 -0700151 bss->max_auth_rounds = 100;
152 bss->max_auth_rounds_short = 50;
153
Hai Shalom74f70d42019-02-11 14:42:39 -0800154 bss->send_probe_response = 1;
155
156#ifdef CONFIG_HS20
157 bss->hs20_release = (HS20_VERSION >> 4) + 1;
158#endif /* CONFIG_HS20 */
159
Hai Shalom81f62d82019-07-22 12:10:00 -0700160#ifdef CONFIG_MACSEC
161 bss->mka_priority = DEFAULT_PRIO_NOT_KEY_SERVER;
162 bss->macsec_port = 1;
163#endif /* CONFIG_MACSEC */
164
Hai Shalom74f70d42019-02-11 14:42:39 -0800165 /* Default to strict CRL checking. */
166 bss->check_crl_strict = 1;
Hai Shalom899fcc72020-10-19 14:38:18 -0700167
Sunil Ravi99c035e2024-07-12 01:42:03 +0000168 bss->multi_ap_profile = MULTI_AP_PROFILE_2;
169
Hai Shalom899fcc72020-10-19 14:38:18 -0700170#ifdef CONFIG_TESTING_OPTIONS
171 bss->sae_commit_status = -1;
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000172 bss->test_assoc_comeback_type = -1;
Hai Shalom899fcc72020-10-19 14:38:18 -0700173#endif /* CONFIG_TESTING_OPTIONS */
Hai Shaloma20dcd72022-02-04 13:43:00 -0800174
175#ifdef CONFIG_PASN
176 /* comeback after 10 TUs */
177 bss->pasn_comeback_after = 10;
Sunil Ravi640215c2023-06-28 23:08:09 +0000178 bss->pasn_noauth = 1;
Hai Shaloma20dcd72022-02-04 13:43:00 -0800179#endif /* CONFIG_PASN */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700180}
181
182
183struct hostapd_config * hostapd_config_defaults(void)
184{
185#define ecw2cw(ecw) ((1 << (ecw)) - 1)
186
187 struct hostapd_config *conf;
188 struct hostapd_bss_config *bss;
189 const int aCWmin = 4, aCWmax = 10;
190 const struct hostapd_wmm_ac_params ac_bk =
191 { aCWmin, aCWmax, 7, 0, 0 }; /* background traffic */
192 const struct hostapd_wmm_ac_params ac_be =
193 { aCWmin, aCWmax, 3, 0, 0 }; /* best effort traffic */
194 const struct hostapd_wmm_ac_params ac_vi = /* video traffic */
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700195 { aCWmin - 1, aCWmin, 2, 3008 / 32, 0 };
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700196 const struct hostapd_wmm_ac_params ac_vo = /* voice traffic */
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700197 { aCWmin - 2, aCWmin - 1, 2, 1504 / 32, 0 };
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700198 const struct hostapd_tx_queue_params txq_bk =
199 { 7, ecw2cw(aCWmin), ecw2cw(aCWmax), 0 };
200 const struct hostapd_tx_queue_params txq_be =
201 { 3, ecw2cw(aCWmin), 4 * (ecw2cw(aCWmin) + 1) - 1, 0};
202 const struct hostapd_tx_queue_params txq_vi =
203 { 1, (ecw2cw(aCWmin) + 1) / 2 - 1, ecw2cw(aCWmin), 30};
204 const struct hostapd_tx_queue_params txq_vo =
205 { 1, (ecw2cw(aCWmin) + 1) / 4 - 1,
206 (ecw2cw(aCWmin) + 1) / 2 - 1, 15};
207
208#undef ecw2cw
209
210 conf = os_zalloc(sizeof(*conf));
211 bss = os_zalloc(sizeof(*bss));
212 if (conf == NULL || bss == NULL) {
213 wpa_printf(MSG_ERROR, "Failed to allocate memory for "
214 "configuration data.");
215 os_free(conf);
216 os_free(bss);
217 return NULL;
218 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800219 conf->bss = os_calloc(1, sizeof(struct hostapd_bss_config *));
220 if (conf->bss == NULL) {
221 os_free(conf);
222 os_free(bss);
223 return NULL;
224 }
225 conf->bss[0] = bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700226
227 bss->radius = os_zalloc(sizeof(*bss->radius));
228 if (bss->radius == NULL) {
Dmitry Shmidt97672262014-02-03 13:02:54 -0800229 os_free(conf->bss);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700230 os_free(conf);
231 os_free(bss);
232 return NULL;
233 }
234
235 hostapd_config_defaults_bss(bss);
236
237 conf->num_bss = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700238
239 conf->beacon_int = 100;
Hai Shalom021b0b52019-04-10 11:17:58 -0700240 conf->rts_threshold = -2; /* use driver default: 2347 */
241 conf->fragm_threshold = -2; /* user driver default: 2346 */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800242 /* Set to invalid value means do not add Power Constraint IE */
243 conf->local_pwr_constraint = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700244
245 conf->wmm_ac_params[0] = ac_be;
246 conf->wmm_ac_params[1] = ac_bk;
247 conf->wmm_ac_params[2] = ac_vi;
248 conf->wmm_ac_params[3] = ac_vo;
249
250 conf->tx_queue[0] = txq_vo;
251 conf->tx_queue[1] = txq_vi;
252 conf->tx_queue[2] = txq_be;
253 conf->tx_queue[3] = txq_bk;
254
255 conf->ht_capab = HT_CAP_INFO_SMPS_DISABLED;
256
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800257 conf->ap_table_max_size = 255;
258 conf->ap_table_expiration_time = 60;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800259 conf->track_sta_max_age = 180;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800260
Dmitry Shmidt8da800a2013-04-24 12:57:01 -0700261#ifdef CONFIG_TESTING_OPTIONS
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700262 conf->ignore_probe_probability = 0.0;
263 conf->ignore_auth_probability = 0.0;
264 conf->ignore_assoc_probability = 0.0;
265 conf->ignore_reassoc_probability = 0.0;
266 conf->corrupt_gtk_rekey_mic_probability = 0.0;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800267 conf->ecsa_ie_only = 0;
Kai Shie75b0652020-11-24 20:31:29 -0800268 conf->skip_send_eapol = 0;
269 conf->enable_eapol_large_timeout = 0;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -0700270#endif /* CONFIG_TESTING_OPTIONS */
271
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700272 conf->acs = 0;
273 conf->acs_ch_list.num = 0;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700274#ifdef CONFIG_ACS
275 conf->acs_num_scans = 5;
276#endif /* CONFIG_ACS */
277
Hai Shalom81f62d82019-07-22 12:10:00 -0700278#ifdef CONFIG_IEEE80211AX
279 conf->he_op.he_rts_threshold = HE_OPERATION_RTS_THRESHOLD_MASK >>
280 HE_OPERATION_RTS_THRESHOLD_OFFSET;
281 /* Set default basic MCS/NSS set to single stream MCS 0-7 */
282 conf->he_op.he_basic_mcs_nss_set = 0xfffc;
Hai Shalomfdcde762020-04-02 11:19:20 -0700283 conf->he_op.he_bss_color_disabled = 1;
284 conf->he_op.he_bss_color_partial = 0;
Hai Shaloma20dcd72022-02-04 13:43:00 -0800285 conf->he_op.he_bss_color = os_random() % 63 + 1;
286 conf->he_op.he_twt_responder = 1;
Hai Shalom60840252021-02-19 19:02:11 -0800287 conf->he_6ghz_max_mpdu = 2;
288 conf->he_6ghz_max_ampdu_len_exp = 7;
289 conf->he_6ghz_rx_ant_pat = 1;
290 conf->he_6ghz_tx_ant_pat = 1;
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000291 conf->he_6ghz_reg_pwr_type = HE_REG_INFO_6GHZ_AP_TYPE_VLP;
292 conf->reg_def_cli_eirp_psd = -1;
293 conf->reg_sub_cli_eirp_psd = -1;
294 conf->reg_def_cli_eirp = -1;
Hai Shalom81f62d82019-07-22 12:10:00 -0700295#endif /* CONFIG_IEEE80211AX */
296
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700297 /* The third octet of the country string uses an ASCII space character
298 * by default to indicate that the regulations encompass all
299 * environments for the current frequency band in the country. */
300 conf->country[2] = ' ';
301
Hai Shalom74f70d42019-02-11 14:42:39 -0800302 conf->rssi_reject_assoc_rssi = 0;
303 conf->rssi_reject_assoc_timeout = 30;
304
Hai Shalom81f62d82019-07-22 12:10:00 -0700305#ifdef CONFIG_AIRTIME_POLICY
306 conf->airtime_update_interval = AIRTIME_DEFAULT_UPDATE_INTERVAL;
307#endif /* CONFIG_AIRTIME_POLICY */
308
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000309 hostapd_set_and_check_bw320_offset(conf, 0);
310
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700311 return conf;
312}
313
314
315int hostapd_mac_comp(const void *a, const void *b)
316{
317 return os_memcmp(a, b, sizeof(macaddr));
318}
319
320
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700321static int hostapd_config_read_wpa_psk(const char *fname,
322 struct hostapd_ssid *ssid)
323{
324 FILE *f;
325 char buf[128], *pos;
Hai Shalom74f70d42019-02-11 14:42:39 -0800326 const char *keyid;
327 char *context;
328 char *context2;
329 char *token;
330 char *name;
331 char *value;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700332 int line = 0, ret = 0, len, ok;
333 u8 addr[ETH_ALEN];
334 struct hostapd_wpa_psk *psk;
335
336 if (!fname)
337 return 0;
338
339 f = fopen(fname, "r");
340 if (!f) {
341 wpa_printf(MSG_ERROR, "WPA PSK file '%s' not found.", fname);
342 return -1;
343 }
344
345 while (fgets(buf, sizeof(buf), f)) {
Hai Shalom021b0b52019-04-10 11:17:58 -0700346 int vlan_id = 0;
Hai Shalomfdcde762020-04-02 11:19:20 -0700347 int wps = 0;
Hai Shalom021b0b52019-04-10 11:17:58 -0700348
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700349 line++;
350
351 if (buf[0] == '#')
352 continue;
353 pos = buf;
354 while (*pos != '\0') {
355 if (*pos == '\n') {
356 *pos = '\0';
357 break;
358 }
359 pos++;
360 }
361 if (buf[0] == '\0')
362 continue;
363
Hai Shalom74f70d42019-02-11 14:42:39 -0800364 context = NULL;
365 keyid = NULL;
366 while ((token = str_token(buf, " ", &context))) {
367 if (!os_strchr(token, '='))
368 break;
369 context2 = NULL;
370 name = str_token(token, "=", &context2);
Hai Shalom021b0b52019-04-10 11:17:58 -0700371 if (!name)
372 break;
Hai Shalom74f70d42019-02-11 14:42:39 -0800373 value = str_token(token, "", &context2);
374 if (!value)
375 value = "";
376 if (!os_strcmp(name, "keyid")) {
377 keyid = value;
Hai Shalomfdcde762020-04-02 11:19:20 -0700378 } else if (!os_strcmp(name, "wps")) {
379 wps = atoi(value);
Hai Shalom021b0b52019-04-10 11:17:58 -0700380 } else if (!os_strcmp(name, "vlanid")) {
381 vlan_id = atoi(value);
Hai Shalom74f70d42019-02-11 14:42:39 -0800382 } else {
383 wpa_printf(MSG_ERROR,
384 "Unrecognized '%s=%s' on line %d in '%s'",
385 name, value, line, fname);
386 ret = -1;
387 break;
388 }
389 }
390
391 if (ret == -1)
392 break;
393
394 if (!token)
395 token = "";
396 if (hwaddr_aton(token, addr)) {
Hai Shalomfdcde762020-04-02 11:19:20 -0700397 wpa_printf(MSG_ERROR,
398 "Invalid MAC address '%s' on line %d in '%s'",
399 token, line, fname);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700400 ret = -1;
401 break;
402 }
403
404 psk = os_zalloc(sizeof(*psk));
405 if (psk == NULL) {
406 wpa_printf(MSG_ERROR, "WPA PSK allocation failed");
407 ret = -1;
408 break;
409 }
Hai Shalom021b0b52019-04-10 11:17:58 -0700410 psk->vlan_id = vlan_id;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700411 if (is_zero_ether_addr(addr))
412 psk->group = 1;
413 else
414 os_memcpy(psk->addr, addr, ETH_ALEN);
415
Hai Shalom74f70d42019-02-11 14:42:39 -0800416 pos = str_token(buf, "", &context);
417 if (!pos) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700418 wpa_printf(MSG_ERROR, "No PSK on line %d in '%s'",
419 line, fname);
420 os_free(psk);
421 ret = -1;
422 break;
423 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700424
425 ok = 0;
426 len = os_strlen(pos);
Hai Shalomfdcde762020-04-02 11:19:20 -0700427 if (len == 2 * PMK_LEN &&
428 hexstr2bin(pos, psk->psk, PMK_LEN) == 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700429 ok = 1;
Hai Shalomfdcde762020-04-02 11:19:20 -0700430 else if (len >= 8 && len < 64 &&
431 pbkdf2_sha1(pos, ssid->ssid, ssid->ssid_len,
432 4096, psk->psk, PMK_LEN) == 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700433 ok = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700434 if (!ok) {
Hai Shalomfdcde762020-04-02 11:19:20 -0700435 wpa_printf(MSG_ERROR,
436 "Invalid PSK '%s' on line %d in '%s'",
437 pos, line, fname);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700438 os_free(psk);
439 ret = -1;
440 break;
441 }
442
Hai Shalom74f70d42019-02-11 14:42:39 -0800443 if (keyid) {
444 len = os_strlcpy(psk->keyid, keyid, sizeof(psk->keyid));
445 if ((size_t) len >= sizeof(psk->keyid)) {
446 wpa_printf(MSG_ERROR,
447 "PSK keyid too long on line %d in '%s'",
448 line, fname);
449 os_free(psk);
450 ret = -1;
451 break;
452 }
453 }
454
Hai Shalomfdcde762020-04-02 11:19:20 -0700455 psk->wps = wps;
456
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700457 psk->next = ssid->wpa_psk;
458 ssid->wpa_psk = psk;
459 }
460
461 fclose(f);
462
463 return ret;
464}
465
466
467static int hostapd_derive_psk(struct hostapd_ssid *ssid)
468{
469 ssid->wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
470 if (ssid->wpa_psk == NULL) {
471 wpa_printf(MSG_ERROR, "Unable to alloc space for PSK");
472 return -1;
473 }
474 wpa_hexdump_ascii(MSG_DEBUG, "SSID",
475 (u8 *) ssid->ssid, ssid->ssid_len);
476 wpa_hexdump_ascii_key(MSG_DEBUG, "PSK (ASCII passphrase)",
477 (u8 *) ssid->wpa_passphrase,
478 os_strlen(ssid->wpa_passphrase));
Sunil Ravia04bd252022-05-02 22:54:18 -0700479 if (pbkdf2_sha1(ssid->wpa_passphrase,
480 ssid->ssid, ssid->ssid_len,
481 4096, ssid->wpa_psk->psk, PMK_LEN) != 0) {
482 wpa_printf(MSG_ERROR, "Error in pbkdf2_sha1()");
483 return -1;
484 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700485 wpa_hexdump_key(MSG_DEBUG, "PSK (from passphrase)",
486 ssid->wpa_psk->psk, PMK_LEN);
487 return 0;
488}
489
490
Hai Shalomc3565922019-10-28 11:58:20 -0700491int hostapd_setup_sae_pt(struct hostapd_bss_config *conf)
492{
493#ifdef CONFIG_SAE
494 struct hostapd_ssid *ssid = &conf->ssid;
495 struct sae_password_entry *pw;
Sunil Ravic0f5d412024-09-11 22:12:49 +0000496 int *groups = conf->sae_groups;
497 int default_groups[] = { 19, 0, 0 };
Hai Shalomc3565922019-10-28 11:58:20 -0700498
Sunil Ravi77d572f2023-01-17 23:58:31 +0000499 if ((conf->sae_pwe == SAE_PWE_HUNT_AND_PECK &&
500 !hostapd_sae_pw_id_in_use(conf) &&
Sunil Ravi7f769292024-07-23 22:21:32 +0000501 !wpa_key_mgmt_sae_ext_key(conf->wpa_key_mgmt |
502 conf->rsn_override_key_mgmt |
503 conf->rsn_override_key_mgmt_2) &&
Hai Shalom899fcc72020-10-19 14:38:18 -0700504 !hostapd_sae_pk_in_use(conf)) ||
Sunil Ravi77d572f2023-01-17 23:58:31 +0000505 conf->sae_pwe == SAE_PWE_FORCE_HUNT_AND_PECK ||
Sunil Ravi7f769292024-07-23 22:21:32 +0000506 !wpa_key_mgmt_sae(conf->wpa_key_mgmt |
507 conf->rsn_override_key_mgmt |
508 conf->rsn_override_key_mgmt_2))
Hai Shalomc3565922019-10-28 11:58:20 -0700509 return 0; /* PT not needed */
510
Sunil Ravic0f5d412024-09-11 22:12:49 +0000511 if (!groups) {
512 groups = default_groups;
513 if (wpa_key_mgmt_sae_ext_key(conf->wpa_key_mgmt |
514 conf->rsn_override_key_mgmt |
515 conf->rsn_override_key_mgmt_2))
516 default_groups[1] = 20;
517 }
518
Hai Shalomc3565922019-10-28 11:58:20 -0700519 sae_deinit_pt(ssid->pt);
520 ssid->pt = NULL;
521 if (ssid->wpa_passphrase) {
Sunil Ravic0f5d412024-09-11 22:12:49 +0000522 ssid->pt = sae_derive_pt(groups, ssid->ssid, ssid->ssid_len,
Hai Shalomc3565922019-10-28 11:58:20 -0700523 (const u8 *) ssid->wpa_passphrase,
524 os_strlen(ssid->wpa_passphrase),
525 NULL);
526 if (!ssid->pt)
527 return -1;
528 }
529
530 for (pw = conf->sae_passwords; pw; pw = pw->next) {
531 sae_deinit_pt(pw->pt);
Sunil Ravic0f5d412024-09-11 22:12:49 +0000532 pw->pt = sae_derive_pt(groups, ssid->ssid, ssid->ssid_len,
Hai Shalomc3565922019-10-28 11:58:20 -0700533 (const u8 *) pw->password,
534 os_strlen(pw->password),
535 pw->identifier);
536 if (!pw->pt)
537 return -1;
538 }
539#endif /* CONFIG_SAE */
540
541 return 0;
542}
543
544
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700545int hostapd_setup_wpa_psk(struct hostapd_bss_config *conf)
546{
547 struct hostapd_ssid *ssid = &conf->ssid;
548
Hai Shalomc3565922019-10-28 11:58:20 -0700549 if (hostapd_setup_sae_pt(conf) < 0)
550 return -1;
551
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700552 if (ssid->wpa_passphrase != NULL) {
553 if (ssid->wpa_psk != NULL) {
554 wpa_printf(MSG_DEBUG, "Using pre-configured WPA PSK "
555 "instead of passphrase");
556 } else {
557 wpa_printf(MSG_DEBUG, "Deriving WPA PSK based on "
558 "passphrase");
559 if (hostapd_derive_psk(ssid) < 0)
560 return -1;
561 }
562 ssid->wpa_psk->group = 1;
563 }
564
Dmitry Shmidt29333592017-01-09 12:27:11 -0800565 return hostapd_config_read_wpa_psk(ssid->wpa_psk_file, &conf->ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700566}
567
568
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700569static void hostapd_config_free_radius(struct hostapd_radius_server *servers,
570 int num_servers)
571{
572 int i;
573
574 for (i = 0; i < num_servers; i++) {
575 os_free(servers[i].shared_secret);
Sunil Ravi99c035e2024-07-12 01:42:03 +0000576 os_free(servers[i].ca_cert);
577 os_free(servers[i].client_cert);
578 os_free(servers[i].private_key);
579 os_free(servers[i].private_key_passwd);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700580 }
581 os_free(servers);
582}
583
584
Dmitry Shmidt04949592012-07-19 12:16:46 -0700585struct hostapd_radius_attr *
586hostapd_config_get_radius_attr(struct hostapd_radius_attr *attr, u8 type)
587{
588 for (; attr; attr = attr->next) {
589 if (attr->type == type)
590 return attr;
591 }
592 return NULL;
593}
594
595
Hai Shalomc3565922019-10-28 11:58:20 -0700596struct hostapd_radius_attr * hostapd_parse_radius_attr(const char *value)
597{
598 const char *pos;
599 char syntax;
600 struct hostapd_radius_attr *attr;
601 size_t len;
602
603 attr = os_zalloc(sizeof(*attr));
604 if (!attr)
605 return NULL;
606
607 attr->type = atoi(value);
608
609 pos = os_strchr(value, ':');
610 if (!pos) {
611 attr->val = wpabuf_alloc(1);
612 if (!attr->val) {
613 os_free(attr);
614 return NULL;
615 }
616 wpabuf_put_u8(attr->val, 0);
617 return attr;
618 }
619
620 pos++;
621 if (pos[0] == '\0' || pos[1] != ':') {
622 os_free(attr);
623 return NULL;
624 }
625 syntax = *pos++;
626 pos++;
627
628 switch (syntax) {
629 case 's':
630 attr->val = wpabuf_alloc_copy(pos, os_strlen(pos));
631 break;
632 case 'x':
633 len = os_strlen(pos);
634 if (len & 1)
635 break;
636 len /= 2;
637 attr->val = wpabuf_alloc(len);
638 if (!attr->val)
639 break;
640 if (hexstr2bin(pos, wpabuf_put(attr->val, len), len) < 0) {
641 wpabuf_free(attr->val);
642 os_free(attr);
643 return NULL;
644 }
645 break;
646 case 'd':
647 attr->val = wpabuf_alloc(4);
648 if (attr->val)
649 wpabuf_put_be32(attr->val, atoi(pos));
650 break;
651 default:
652 os_free(attr);
653 return NULL;
654 }
655
656 if (!attr->val) {
657 os_free(attr);
658 return NULL;
659 }
660
661 return attr;
662}
663
664
665void hostapd_config_free_radius_attr(struct hostapd_radius_attr *attr)
Dmitry Shmidt04949592012-07-19 12:16:46 -0700666{
667 struct hostapd_radius_attr *prev;
668
669 while (attr) {
670 prev = attr;
671 attr = attr->next;
672 wpabuf_free(prev->val);
673 os_free(prev);
674 }
675}
676
677
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700678void hostapd_config_free_eap_user(struct hostapd_eap_user *user)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700679{
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700680 hostapd_config_free_radius_attr(user->accept_attr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700681 os_free(user->identity);
Dmitry Shmidtc2817022014-07-02 10:32:10 -0700682 bin_clear_free(user->password, user->password_len);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700683 bin_clear_free(user->salt, user->salt_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700684 os_free(user);
685}
686
687
Dmitry Shmidt29333592017-01-09 12:27:11 -0800688void hostapd_config_free_eap_users(struct hostapd_eap_user *user)
689{
690 struct hostapd_eap_user *prev_user;
691
692 while (user) {
693 prev_user = user;
694 user = user->next;
695 hostapd_config_free_eap_user(prev_user);
696 }
697}
698
699
Hai Shalomfdcde762020-04-02 11:19:20 -0700700#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700701static void hostapd_config_free_wep(struct hostapd_wep_keys *keys)
702{
703 int i;
704 for (i = 0; i < NUM_WEP_KEYS; i++) {
Dmitry Shmidtc2817022014-07-02 10:32:10 -0700705 bin_clear_free(keys->key[i], keys->len[i]);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700706 keys->key[i] = NULL;
707 }
708}
Hai Shalomfdcde762020-04-02 11:19:20 -0700709#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700710
711
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800712void hostapd_config_clear_wpa_psk(struct hostapd_wpa_psk **l)
713{
714 struct hostapd_wpa_psk *psk, *tmp;
715
716 for (psk = *l; psk;) {
717 tmp = psk;
718 psk = psk->next;
719 bin_clear_free(tmp, sizeof(*tmp));
720 }
721 *l = NULL;
722}
723
724
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000725#ifdef CONFIG_IEEE80211R_AP
726
727void hostapd_config_clear_rxkhs(struct hostapd_bss_config *conf)
728{
729 struct ft_remote_r0kh *r0kh, *r0kh_prev;
730 struct ft_remote_r1kh *r1kh, *r1kh_prev;
731
732 r0kh = conf->r0kh_list;
733 conf->r0kh_list = NULL;
734 while (r0kh) {
735 r0kh_prev = r0kh;
736 r0kh = r0kh->next;
737 os_free(r0kh_prev);
738 }
739
740 r1kh = conf->r1kh_list;
741 conf->r1kh_list = NULL;
742 while (r1kh) {
743 r1kh_prev = r1kh;
744 r1kh = r1kh->next;
745 os_free(r1kh_prev);
746 }
747}
748
749#endif /* CONFIG_IEEE80211R_AP */
750
751
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800752static void hostapd_config_free_anqp_elem(struct hostapd_bss_config *conf)
753{
754 struct anqp_element *elem;
755
756 while ((elem = dl_list_first(&conf->anqp_elem, struct anqp_element,
757 list))) {
758 dl_list_del(&elem->list);
759 wpabuf_free(elem->payload);
760 os_free(elem);
761 }
762}
763
764
Dmitry Shmidt29333592017-01-09 12:27:11 -0800765static void hostapd_config_free_fils_realms(struct hostapd_bss_config *conf)
766{
767#ifdef CONFIG_FILS
768 struct fils_realm *realm;
769
770 while ((realm = dl_list_first(&conf->fils_realms, struct fils_realm,
771 list))) {
772 dl_list_del(&realm->list);
773 os_free(realm);
774 }
775#endif /* CONFIG_FILS */
776}
777
778
Roshan Pius3a1667e2018-07-03 15:17:14 -0700779static void hostapd_config_free_sae_passwords(struct hostapd_bss_config *conf)
780{
781 struct sae_password_entry *pw, *tmp;
782
783 pw = conf->sae_passwords;
784 conf->sae_passwords = NULL;
785 while (pw) {
786 tmp = pw;
787 pw = pw->next;
788 str_clear_free(tmp->password);
789 os_free(tmp->identifier);
Hai Shalomc3565922019-10-28 11:58:20 -0700790#ifdef CONFIG_SAE
791 sae_deinit_pt(tmp->pt);
792#endif /* CONFIG_SAE */
Hai Shalom899fcc72020-10-19 14:38:18 -0700793#ifdef CONFIG_SAE_PK
794 sae_deinit_pk(tmp->pk);
795#endif /* CONFIG_SAE_PK */
Roshan Pius3a1667e2018-07-03 15:17:14 -0700796 os_free(tmp);
797 }
798}
799
800
Hai Shalom81f62d82019-07-22 12:10:00 -0700801#ifdef CONFIG_DPP2
802static void hostapd_dpp_controller_conf_free(struct dpp_controller_conf *conf)
803{
804 struct dpp_controller_conf *prev;
805
806 while (conf) {
807 prev = conf;
808 conf = conf->next;
809 os_free(prev);
810 }
811}
812#endif /* CONFIG_DPP2 */
813
814
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800815void hostapd_config_free_bss(struct hostapd_bss_config *conf)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700816{
Hai Shalom81f62d82019-07-22 12:10:00 -0700817#if defined(CONFIG_WPS) || defined(CONFIG_HS20)
818 size_t i;
819#endif
820
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700821 if (conf == NULL)
822 return;
823
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800824 hostapd_config_clear_wpa_psk(&conf->ssid.wpa_psk);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700825
Dmitry Shmidtc2817022014-07-02 10:32:10 -0700826 str_clear_free(conf->ssid.wpa_passphrase);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700827 os_free(conf->ssid.wpa_psk_file);
Hai Shalomfdcde762020-04-02 11:19:20 -0700828#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700829 hostapd_config_free_wep(&conf->ssid.wep);
Hai Shalomfdcde762020-04-02 11:19:20 -0700830#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700831#ifdef CONFIG_FULL_DYNAMIC_VLAN
832 os_free(conf->ssid.vlan_tagged_interface);
833#endif /* CONFIG_FULL_DYNAMIC_VLAN */
Hai Shalomc3565922019-10-28 11:58:20 -0700834#ifdef CONFIG_SAE
835 sae_deinit_pt(conf->ssid.pt);
836#endif /* CONFIG_SAE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700837
Dmitry Shmidt29333592017-01-09 12:27:11 -0800838 hostapd_config_free_eap_users(conf->eap_user);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800839 os_free(conf->eap_user_sqlite);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700840
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700841 os_free(conf->eap_req_id_text);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800842 os_free(conf->erp_domain);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700843 os_free(conf->accept_mac);
844 os_free(conf->deny_mac);
845 os_free(conf->nas_identifier);
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800846 if (conf->radius) {
847 hostapd_config_free_radius(conf->radius->auth_servers,
848 conf->radius->num_auth_servers);
849 hostapd_config_free_radius(conf->radius->acct_servers,
850 conf->radius->num_acct_servers);
Hai Shaloma20dcd72022-02-04 13:43:00 -0800851 os_free(conf->radius->force_client_dev);
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800852 }
Dmitry Shmidt04949592012-07-19 12:16:46 -0700853 hostapd_config_free_radius_attr(conf->radius_auth_req_attr);
854 hostapd_config_free_radius_attr(conf->radius_acct_req_attr);
Hai Shalomc3565922019-10-28 11:58:20 -0700855 os_free(conf->radius_req_attr_sqlite);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700856 os_free(conf->rsn_preauth_interfaces);
857 os_free(conf->ctrl_interface);
Sunil Ravi77d572f2023-01-17 23:58:31 +0000858 os_free(conf->config_id);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700859 os_free(conf->ca_cert);
860 os_free(conf->server_cert);
Hai Shalom81f62d82019-07-22 12:10:00 -0700861 os_free(conf->server_cert2);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700862 os_free(conf->private_key);
Hai Shalom81f62d82019-07-22 12:10:00 -0700863 os_free(conf->private_key2);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700864 os_free(conf->private_key_passwd);
Hai Shalom81f62d82019-07-22 12:10:00 -0700865 os_free(conf->private_key_passwd2);
Hai Shalom021b0b52019-04-10 11:17:58 -0700866 os_free(conf->check_cert_subject);
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700867 os_free(conf->ocsp_stapling_response);
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -0800868 os_free(conf->ocsp_stapling_response_multi);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700869 os_free(conf->dh_file);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800870 os_free(conf->openssl_ciphers);
Hai Shalom74f70d42019-02-11 14:42:39 -0800871 os_free(conf->openssl_ecdh_curves);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700872 os_free(conf->pac_opaque_encr_key);
873 os_free(conf->eap_fast_a_id);
874 os_free(conf->eap_fast_a_id_info);
875 os_free(conf->eap_sim_db);
Sunil Ravia04bd252022-05-02 22:54:18 -0700876 os_free(conf->imsi_privacy_key);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700877 os_free(conf->radius_server_clients);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700878 os_free(conf->radius);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700879 os_free(conf->radius_das_shared_secret);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700880 hostapd_config_free_vlan(conf);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800881 os_free(conf->time_zone);
882
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800883#ifdef CONFIG_IEEE80211R_AP
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000884 hostapd_config_clear_rxkhs(conf);
885 os_free(conf->rxkh_file);
886 conf->rxkh_file = NULL;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800887#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700888
889#ifdef CONFIG_WPS
890 os_free(conf->wps_pin_requests);
891 os_free(conf->device_name);
892 os_free(conf->manufacturer);
893 os_free(conf->model_name);
894 os_free(conf->model_number);
895 os_free(conf->serial_number);
896 os_free(conf->config_methods);
897 os_free(conf->ap_pin);
898 os_free(conf->extra_cred);
899 os_free(conf->ap_settings);
Hai Shalom021b0b52019-04-10 11:17:58 -0700900 hostapd_config_clear_wpa_psk(&conf->multi_ap_backhaul_ssid.wpa_psk);
901 str_clear_free(conf->multi_ap_backhaul_ssid.wpa_passphrase);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700902 os_free(conf->upnp_iface);
903 os_free(conf->friendly_name);
904 os_free(conf->manufacturer_url);
905 os_free(conf->model_description);
906 os_free(conf->model_url);
907 os_free(conf->upc);
Hai Shalom81f62d82019-07-22 12:10:00 -0700908 for (i = 0; i < MAX_WPS_VENDOR_EXTENSIONS; i++)
909 wpabuf_free(conf->wps_vendor_ext[i]);
Hai Shalomfdcde762020-04-02 11:19:20 -0700910 wpabuf_free(conf->wps_application_ext);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700911 wpabuf_free(conf->wps_nfc_dh_pubkey);
912 wpabuf_free(conf->wps_nfc_dh_privkey);
913 wpabuf_free(conf->wps_nfc_dev_pw);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700914#endif /* CONFIG_WPS */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800915
916 os_free(conf->roaming_consortium);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700917 os_free(conf->venue_name);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700918 os_free(conf->venue_url);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700919 os_free(conf->nai_realm_data);
920 os_free(conf->network_auth_type);
921 os_free(conf->anqp_3gpp_cell_net);
922 os_free(conf->domain_name);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800923 hostapd_config_free_anqp_elem(conf);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800924
925#ifdef CONFIG_RADIUS_TEST
926 os_free(conf->dump_msk_file);
927#endif /* CONFIG_RADIUS_TEST */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700928
929#ifdef CONFIG_HS20
930 os_free(conf->hs20_oper_friendly_name);
931 os_free(conf->hs20_wan_metrics);
932 os_free(conf->hs20_connection_capability);
933 os_free(conf->hs20_operating_class);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800934 os_free(conf->hs20_icons);
935 if (conf->hs20_osu_providers) {
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800936 for (i = 0; i < conf->hs20_osu_providers_count; i++) {
937 struct hs20_osu_provider *p;
938 size_t j;
939 p = &conf->hs20_osu_providers[i];
940 os_free(p->friendly_name);
941 os_free(p->server_uri);
942 os_free(p->method_list);
943 for (j = 0; j < p->icons_count; j++)
944 os_free(p->icons[j]);
945 os_free(p->icons);
946 os_free(p->osu_nai);
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800947 os_free(p->osu_nai2);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800948 os_free(p->service_desc);
949 }
950 os_free(conf->hs20_osu_providers);
951 }
Roshan Pius3a1667e2018-07-03 15:17:14 -0700952 if (conf->hs20_operator_icon) {
Roshan Pius3a1667e2018-07-03 15:17:14 -0700953 for (i = 0; i < conf->hs20_operator_icon_count; i++)
954 os_free(conf->hs20_operator_icon[i]);
955 os_free(conf->hs20_operator_icon);
956 }
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800957 os_free(conf->subscr_remediation_url);
Hai Shalom74f70d42019-02-11 14:42:39 -0800958 os_free(conf->hs20_sim_provisioning_url);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700959 os_free(conf->t_c_filename);
960 os_free(conf->t_c_server_url);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700961#endif /* CONFIG_HS20 */
962
963 wpabuf_free(conf->vendor_elements);
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700964 wpabuf_free(conf->assocresp_elements);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800965
966 os_free(conf->sae_groups);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700967#ifdef CONFIG_OWE
968 os_free(conf->owe_groups);
969#endif /* CONFIG_OWE */
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700970
Dmitry Shmidt0207e232014-09-03 14:58:37 -0700971 os_free(conf->wowlan_triggers);
972
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700973 os_free(conf->server_id);
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800974
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800975#ifdef CONFIG_TESTING_OPTIONS
976 wpabuf_free(conf->own_ie_override);
Sunil Ravic0f5d412024-09-11 22:12:49 +0000977 wpabuf_free(conf->rsne_override);
978 wpabuf_free(conf->rsnoe_override);
979 wpabuf_free(conf->rsno2e_override);
980 wpabuf_free(conf->rsnxe_override);
981 wpabuf_free(conf->rsnxoe_override);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700982 wpabuf_free(conf->sae_commit_override);
Hai Shalomfdcde762020-04-02 11:19:20 -0700983 wpabuf_free(conf->rsne_override_eapol);
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800984 wpabuf_free(conf->rsnxe_override_eapol);
Hai Shalomfdcde762020-04-02 11:19:20 -0700985 wpabuf_free(conf->rsne_override_ft);
986 wpabuf_free(conf->rsnxe_override_ft);
987 wpabuf_free(conf->gtk_rsc_override);
988 wpabuf_free(conf->igtk_rsc_override);
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000989 wpabuf_free(conf->eapol_m1_elements);
990 wpabuf_free(conf->eapol_m3_elements);
Sunil Ravi7f769292024-07-23 22:21:32 +0000991 wpabuf_free(conf->presp_elements);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800992#endif /* CONFIG_TESTING_OPTIONS */
993
994 os_free(conf->no_probe_resp_if_seen_on);
995 os_free(conf->no_auth_if_seen_on);
996
Dmitry Shmidt29333592017-01-09 12:27:11 -0800997 hostapd_config_free_fils_realms(conf);
998
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700999#ifdef CONFIG_DPP
Hai Shalomc3565922019-10-28 11:58:20 -07001000 os_free(conf->dpp_name);
1001 os_free(conf->dpp_mud_url);
Sunil Ravi89eba102022-09-13 21:04:37 -07001002 os_free(conf->dpp_extra_conf_req_name);
1003 os_free(conf->dpp_extra_conf_req_value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001004 os_free(conf->dpp_connector);
1005 wpabuf_free(conf->dpp_netaccesskey);
1006 wpabuf_free(conf->dpp_csign);
Hai Shalom81f62d82019-07-22 12:10:00 -07001007#ifdef CONFIG_DPP2
1008 hostapd_dpp_controller_conf_free(conf->dpp_controller);
1009#endif /* CONFIG_DPP2 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001010#endif /* CONFIG_DPP */
1011
Roshan Pius3a1667e2018-07-03 15:17:14 -07001012 hostapd_config_free_sae_passwords(conf);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001013
Hai Shalom81f62d82019-07-22 12:10:00 -07001014#ifdef CONFIG_AIRTIME_POLICY
1015 {
1016 struct airtime_sta_weight *wt, *wt_prev;
1017
1018 wt = conf->airtime_weight_list;
1019 conf->airtime_weight_list = NULL;
1020 while (wt) {
1021 wt_prev = wt;
1022 wt = wt->next;
1023 os_free(wt_prev);
1024 }
1025 }
1026#endif /* CONFIG_AIRTIME_POLICY */
1027
Hai Shalom60840252021-02-19 19:02:11 -08001028#ifdef CONFIG_PASN
1029 os_free(conf->pasn_groups);
1030#endif /* CONFIG_PASN */
1031
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001032 os_free(conf);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001033}
1034
1035
1036/**
1037 * hostapd_config_free - Free hostapd configuration
1038 * @conf: Configuration data from hostapd_config_read().
1039 */
1040void hostapd_config_free(struct hostapd_config *conf)
1041{
1042 size_t i;
1043
1044 if (conf == NULL)
1045 return;
1046
1047 for (i = 0; i < conf->num_bss; i++)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001048 hostapd_config_free_bss(conf->bss[i]);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001049 os_free(conf->bss);
1050 os_free(conf->supported_rates);
1051 os_free(conf->basic_rates);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07001052 os_free(conf->acs_ch_list.range);
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001053 os_free(conf->acs_freq_list.range);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001054 os_free(conf->driver_params);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001055#ifdef CONFIG_ACS
1056 os_free(conf->acs_chan_bias);
1057#endif /* CONFIG_ACS */
Dmitry Shmidt849734c2016-05-27 09:59:01 -07001058 wpabuf_free(conf->lci);
1059 wpabuf_free(conf->civic);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001060
1061 os_free(conf);
1062}
1063
1064
1065/**
1066 * hostapd_maclist_found - Find a MAC address from a list
1067 * @list: MAC address list
1068 * @num_entries: Number of addresses in the list
1069 * @addr: Address to search for
1070 * @vlan_id: Buffer for returning VLAN ID or %NULL if not needed
1071 * Returns: 1 if address is in the list or 0 if not.
1072 *
1073 * Perform a binary search for given MAC address from a pre-sorted list.
1074 */
1075int hostapd_maclist_found(struct mac_acl_entry *list, int num_entries,
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001076 const u8 *addr, struct vlan_description *vlan_id)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001077{
1078 int start, end, middle, res;
1079
1080 start = 0;
1081 end = num_entries - 1;
1082
1083 while (start <= end) {
1084 middle = (start + end) / 2;
1085 res = os_memcmp(list[middle].addr, addr, ETH_ALEN);
1086 if (res == 0) {
1087 if (vlan_id)
1088 *vlan_id = list[middle].vlan_id;
1089 return 1;
1090 }
1091 if (res < 0)
1092 start = middle + 1;
1093 else
1094 end = middle - 1;
1095 }
1096
1097 return 0;
1098}
1099
1100
1101int hostapd_rate_found(int *list, int rate)
1102{
1103 int i;
1104
1105 if (list == NULL)
1106 return 0;
1107
1108 for (i = 0; list[i] >= 0; i++)
1109 if (list[i] == rate)
1110 return 1;
1111
1112 return 0;
1113}
1114
1115
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001116int hostapd_vlan_valid(struct hostapd_vlan *vlan,
1117 struct vlan_description *vlan_desc)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001118{
1119 struct hostapd_vlan *v = vlan;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001120 int i;
1121
1122 if (!vlan_desc->notempty || vlan_desc->untagged < 0 ||
1123 vlan_desc->untagged > MAX_VLAN_ID)
1124 return 0;
1125 for (i = 0; i < MAX_NUM_TAGGED_VLAN; i++) {
1126 if (vlan_desc->tagged[i] < 0 ||
1127 vlan_desc->tagged[i] > MAX_VLAN_ID)
1128 return 0;
1129 }
1130 if (!vlan_desc->untagged && !vlan_desc->tagged[0])
1131 return 0;
1132
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001133 while (v) {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001134 if (!vlan_compare(&v->vlan_desc, vlan_desc) ||
1135 v->vlan_id == VLAN_ID_WILDCARD)
Dmitry Shmidt34af3062013-07-11 10:46:32 -07001136 return 1;
1137 v = v->next;
1138 }
1139 return 0;
1140}
1141
1142
1143const char * hostapd_get_vlan_id_ifname(struct hostapd_vlan *vlan, int vlan_id)
1144{
1145 struct hostapd_vlan *v = vlan;
1146 while (v) {
1147 if (v->vlan_id == vlan_id)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001148 return v->ifname;
1149 v = v->next;
1150 }
1151 return NULL;
1152}
1153
1154
1155const u8 * hostapd_get_psk(const struct hostapd_bss_config *conf,
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001156 const u8 *addr, const u8 *p2p_dev_addr,
Hai Shalom021b0b52019-04-10 11:17:58 -07001157 const u8 *prev_psk, int *vlan_id)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001158{
1159 struct hostapd_wpa_psk *psk;
1160 int next_ok = prev_psk == NULL;
1161
Hai Shalom021b0b52019-04-10 11:17:58 -07001162 if (vlan_id)
1163 *vlan_id = 0;
1164
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001165 if (p2p_dev_addr && !is_zero_ether_addr(p2p_dev_addr)) {
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001166 wpa_printf(MSG_DEBUG, "Searching a PSK for " MACSTR
1167 " p2p_dev_addr=" MACSTR " prev_psk=%p",
1168 MAC2STR(addr), MAC2STR(p2p_dev_addr), prev_psk);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001169 addr = NULL; /* Use P2P Device Address for matching */
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001170 } else {
1171 wpa_printf(MSG_DEBUG, "Searching a PSK for " MACSTR
1172 " prev_psk=%p",
1173 MAC2STR(addr), prev_psk);
1174 }
1175
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001176 for (psk = conf->ssid.wpa_psk; psk != NULL; psk = psk->next) {
1177 if (next_ok &&
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001178 (psk->group ||
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001179 (addr && ether_addr_equal(psk->addr, addr)) ||
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001180 (!addr && p2p_dev_addr &&
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001181 ether_addr_equal(psk->p2p_dev_addr, p2p_dev_addr)))) {
Hai Shalom021b0b52019-04-10 11:17:58 -07001182 if (vlan_id)
1183 *vlan_id = psk->vlan_id;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001184 return psk->psk;
Hai Shalom021b0b52019-04-10 11:17:58 -07001185 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001186
1187 if (psk->psk == prev_psk)
1188 next_ok = 1;
1189 }
1190
1191 return NULL;
1192}
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001193
1194
Hai Shalom899fcc72020-10-19 14:38:18 -07001195#ifdef CONFIG_SAE_PK
1196static bool hostapd_sae_pk_password_without_pk(struct hostapd_bss_config *bss)
1197{
1198 struct sae_password_entry *pw;
1199 bool res = false;
1200
1201 if (bss->ssid.wpa_passphrase &&
1202#ifdef CONFIG_TESTING_OPTIONS
1203 !bss->sae_pk_password_check_skip &&
1204#endif /* CONFIG_TESTING_OPTIONS */
1205 sae_pk_valid_password(bss->ssid.wpa_passphrase))
1206 res = true;
1207
1208 for (pw = bss->sae_passwords; pw; pw = pw->next) {
1209 if (!pw->pk &&
1210#ifdef CONFIG_TESTING_OPTIONS
1211 !bss->sae_pk_password_check_skip &&
1212#endif /* CONFIG_TESTING_OPTIONS */
1213 sae_pk_valid_password(pw->password))
1214 return true;
1215
1216 if (bss->ssid.wpa_passphrase && res && pw->pk &&
1217 os_strcmp(bss->ssid.wpa_passphrase, pw->password) == 0)
1218 res = false;
1219 }
1220
1221 return res;
1222}
1223#endif /* CONFIG_SAE_PK */
1224
1225
Hai Shalom60840252021-02-19 19:02:11 -08001226static bool hostapd_config_check_bss_6g(struct hostapd_bss_config *bss)
1227{
1228 if (bss->wpa != WPA_PROTO_RSN) {
1229 wpa_printf(MSG_ERROR,
1230 "Pre-RSNA security methods are not allowed in 6 GHz");
1231 return false;
1232 }
1233
1234 if (bss->ieee80211w != MGMT_FRAME_PROTECTION_REQUIRED) {
1235 wpa_printf(MSG_ERROR,
1236 "Management frame protection is required in 6 GHz");
1237 return false;
1238 }
1239
1240 if (bss->wpa_key_mgmt & (WPA_KEY_MGMT_PSK |
1241 WPA_KEY_MGMT_FT_PSK |
1242 WPA_KEY_MGMT_PSK_SHA256)) {
1243 wpa_printf(MSG_ERROR, "Invalid AKM suite for 6 GHz");
1244 return false;
1245 }
1246
1247 if (bss->rsn_pairwise & (WPA_CIPHER_WEP40 |
1248 WPA_CIPHER_WEP104 |
1249 WPA_CIPHER_TKIP)) {
1250 wpa_printf(MSG_ERROR,
1251 "Invalid pairwise cipher suite for 6 GHz");
1252 return false;
1253 }
1254
1255 if (bss->wpa_group & (WPA_CIPHER_WEP40 |
1256 WPA_CIPHER_WEP104 |
1257 WPA_CIPHER_TKIP)) {
1258 wpa_printf(MSG_ERROR, "Invalid group cipher suite for 6 GHz");
1259 return false;
1260 }
1261
Sunil Ravi77d572f2023-01-17 23:58:31 +00001262#ifdef CONFIG_SAE
1263 if (wpa_key_mgmt_sae(bss->wpa_key_mgmt) &&
1264 bss->sae_pwe == SAE_PWE_HUNT_AND_PECK) {
1265 wpa_printf(MSG_INFO, "SAE: Enabling SAE H2E on 6 GHz");
1266 bss->sae_pwe = SAE_PWE_BOTH;
1267 }
1268#endif /* CONFIG_SAE */
1269
Hai Shalom60840252021-02-19 19:02:11 -08001270 return true;
1271}
1272
1273
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001274static int hostapd_config_check_bss(struct hostapd_bss_config *bss,
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001275 struct hostapd_config *conf,
1276 int full_config)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001277{
Hai Shalom60840252021-02-19 19:02:11 -08001278 if (full_config && is_6ghz_op_class(conf->op_class) &&
1279 !hostapd_config_check_bss_6g(bss))
1280 return -1;
1281
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001282 if (full_config && bss->ieee802_1x && !bss->eap_server &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001283 !bss->radius->auth_servers) {
1284 wpa_printf(MSG_ERROR, "Invalid IEEE 802.1X configuration (no "
1285 "EAP authenticator configured).");
1286 return -1;
1287 }
1288
Hai Shalomfdcde762020-04-02 11:19:20 -07001289#ifdef CONFIG_WEP
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001290 if (bss->wpa) {
1291 int wep, i;
1292
1293 wep = bss->default_wep_key_len > 0 ||
1294 bss->individual_wep_key_len > 0;
1295 for (i = 0; i < NUM_WEP_KEYS; i++) {
1296 if (bss->ssid.wep.keys_set) {
1297 wep = 1;
1298 break;
1299 }
1300 }
1301
1302 if (wep) {
1303 wpa_printf(MSG_ERROR, "WEP configuration in a WPA network is not supported");
1304 return -1;
1305 }
1306 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001307#endif /* CONFIG_WEP */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001308
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001309 if (full_config && bss->wpa &&
1310 bss->wpa_psk_radius != PSK_RADIUS_IGNORED &&
Sunil Ravia04bd252022-05-02 22:54:18 -07001311 bss->wpa_psk_radius != PSK_RADIUS_DURING_4WAY_HS &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001312 bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH) {
1313 wpa_printf(MSG_ERROR, "WPA-PSK using RADIUS enabled, but no "
1314 "RADIUS checking (macaddr_acl=2) enabled.");
1315 return -1;
1316 }
1317
Sunil Ravia04bd252022-05-02 22:54:18 -07001318 if (full_config && bss->wpa &&
1319 wpa_key_mgmt_wpa_psk_no_sae(bss->wpa_key_mgmt) &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001320 bss->ssid.wpa_psk == NULL && bss->ssid.wpa_passphrase == NULL &&
1321 bss->ssid.wpa_psk_file == NULL &&
Sunil Ravia04bd252022-05-02 22:54:18 -07001322 bss->wpa_psk_radius != PSK_RADIUS_DURING_4WAY_HS &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001323 (bss->wpa_psk_radius != PSK_RADIUS_REQUIRED ||
1324 bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH)) {
1325 wpa_printf(MSG_ERROR, "WPA-PSK enabled, but PSK or passphrase "
1326 "is not configured.");
1327 return -1;
1328 }
1329
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001330 if (full_config && !is_zero_ether_addr(bss->bssid)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001331 size_t i;
1332
1333 for (i = 0; i < conf->num_bss; i++) {
1334 if (conf->bss[i] != bss &&
1335 (hostapd_mac_comp(conf->bss[i]->bssid,
1336 bss->bssid) == 0)) {
1337 wpa_printf(MSG_ERROR, "Duplicate BSSID " MACSTR
1338 " on interface '%s' and '%s'.",
1339 MAC2STR(bss->bssid),
1340 conf->bss[i]->iface, bss->iface);
1341 return -1;
1342 }
1343 }
1344 }
1345
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001346#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001347 if (full_config && wpa_key_mgmt_ft(bss->wpa_key_mgmt) &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001348 (bss->nas_identifier == NULL ||
1349 os_strlen(bss->nas_identifier) < 1 ||
1350 os_strlen(bss->nas_identifier) > FT_R0KH_ID_MAX_LEN)) {
1351 wpa_printf(MSG_ERROR, "FT (IEEE 802.11r) requires "
1352 "nas_identifier to be configured as a 1..48 octet "
1353 "string");
1354 return -1;
1355 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001356#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001357
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001358 if (full_config && conf->ieee80211n &&
1359 conf->hw_mode == HOSTAPD_MODE_IEEE80211B) {
Hai Shalom60840252021-02-19 19:02:11 -08001360 bss->disable_11n = true;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001361 wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) in 11b mode is not "
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001362 "allowed, disabling HT capabilities");
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001363 }
1364
Hai Shalomfdcde762020-04-02 11:19:20 -07001365#ifdef CONFIG_WEP
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001366 if (full_config && conf->ieee80211n &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001367 bss->ssid.security_policy == SECURITY_STATIC_WEP) {
Hai Shalom60840252021-02-19 19:02:11 -08001368 bss->disable_11n = true;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001369 wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) with WEP is not "
1370 "allowed, disabling HT capabilities");
1371 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001372#endif /* CONFIG_WEP */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001373
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001374 if (full_config && conf->ieee80211n && bss->wpa &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001375 !(bss->wpa_pairwise & WPA_CIPHER_CCMP) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001376 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
1377 WPA_CIPHER_CCMP_256 | WPA_CIPHER_GCMP_256)))
1378 {
Hai Shalom60840252021-02-19 19:02:11 -08001379 bss->disable_11n = true;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001380 wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) with WPA/WPA2 "
1381 "requires CCMP/GCMP to be enabled, disabling HT "
1382 "capabilities");
1383 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001384
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07001385#ifdef CONFIG_IEEE80211AC
Hai Shalomfdcde762020-04-02 11:19:20 -07001386#ifdef CONFIG_WEP
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07001387 if (full_config && conf->ieee80211ac &&
1388 bss->ssid.security_policy == SECURITY_STATIC_WEP) {
Hai Shalom60840252021-02-19 19:02:11 -08001389 bss->disable_11ac = true;
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07001390 wpa_printf(MSG_ERROR,
1391 "VHT (IEEE 802.11ac) with WEP is not allowed, disabling VHT capabilities");
1392 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001393#endif /* CONFIG_WEP */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001394
1395 if (full_config && conf->ieee80211ac && bss->wpa &&
1396 !(bss->wpa_pairwise & WPA_CIPHER_CCMP) &&
1397 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
1398 WPA_CIPHER_CCMP_256 | WPA_CIPHER_GCMP_256)))
1399 {
Hai Shalom60840252021-02-19 19:02:11 -08001400 bss->disable_11ac = true;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001401 wpa_printf(MSG_ERROR,
1402 "VHT (IEEE 802.11ac) with WPA/WPA2 requires CCMP/GCMP to be enabled, disabling VHT capabilities");
1403 }
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07001404#endif /* CONFIG_IEEE80211AC */
1405
Hai Shalom60840252021-02-19 19:02:11 -08001406#ifdef CONFIG_IEEE80211AX
1407#ifdef CONFIG_WEP
1408 if (full_config && conf->ieee80211ax &&
1409 bss->ssid.security_policy == SECURITY_STATIC_WEP) {
1410 bss->disable_11ax = true;
1411 wpa_printf(MSG_ERROR,
1412 "HE (IEEE 802.11ax) with WEP is not allowed, disabling HE capabilities");
1413 }
1414#endif /* CONFIG_WEP */
1415
1416 if (full_config && conf->ieee80211ax && bss->wpa &&
1417 !(bss->wpa_pairwise & WPA_CIPHER_CCMP) &&
1418 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
1419 WPA_CIPHER_CCMP_256 | WPA_CIPHER_GCMP_256)))
1420 {
1421 bss->disable_11ax = true;
1422 wpa_printf(MSG_ERROR,
1423 "HE (IEEE 802.11ax) with WPA/WPA2 requires CCMP/GCMP to be enabled, disabling HE capabilities");
1424 }
1425#endif /* CONFIG_IEEE80211AX */
1426
Dmitry Shmidt15907092014-03-25 10:42:57 -07001427#ifdef CONFIG_WPS
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001428 if (full_config && bss->wps_state && bss->ignore_broadcast_ssid) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001429 wpa_printf(MSG_INFO, "WPS: ignore_broadcast_ssid "
1430 "configuration forced WPS to be disabled");
1431 bss->wps_state = 0;
1432 }
1433
Hai Shalomfdcde762020-04-02 11:19:20 -07001434#ifdef CONFIG_WEP
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001435 if (full_config && bss->wps_state &&
1436 bss->ssid.wep.keys_set && bss->wpa == 0) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001437 wpa_printf(MSG_INFO, "WPS: WEP configuration forced WPS to be "
1438 "disabled");
1439 bss->wps_state = 0;
1440 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001441#endif /* CONFIG_WEP */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001442
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001443 if (full_config && bss->wps_state && bss->wpa &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001444 (!(bss->wpa & 2) ||
Roshan Pius3a1667e2018-07-03 15:17:14 -07001445 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
1446 WPA_CIPHER_CCMP_256 |
1447 WPA_CIPHER_GCMP_256)))) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001448 wpa_printf(MSG_INFO, "WPS: WPA/TKIP configuration without "
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07001449 "WPA2/CCMP/GCMP forced WPS to be disabled");
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001450 bss->wps_state = 0;
1451 }
Dmitry Shmidt15907092014-03-25 10:42:57 -07001452#endif /* CONFIG_WPS */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001453
1454#ifdef CONFIG_HS20
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001455 if (full_config && bss->hs20 &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001456 (!(bss->wpa & 2) ||
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001457 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
1458 WPA_CIPHER_CCMP_256 |
1459 WPA_CIPHER_GCMP_256)))) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001460 wpa_printf(MSG_ERROR, "HS 2.0: WPA2-Enterprise/CCMP "
1461 "configuration is required for Hotspot 2.0 "
1462 "functionality");
1463 return -1;
1464 }
1465#endif /* CONFIG_HS20 */
1466
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001467#ifdef CONFIG_MBO
1468 if (full_config && bss->mbo_enabled && (bss->wpa & 2) &&
1469 bss->ieee80211w == NO_MGMT_FRAME_PROTECTION) {
1470 wpa_printf(MSG_ERROR,
1471 "MBO: PMF needs to be enabled whenever using WPA2 with MBO");
1472 return -1;
1473 }
1474#endif /* CONFIG_MBO */
1475
Hai Shalom74f70d42019-02-11 14:42:39 -08001476#ifdef CONFIG_OCV
1477 if (full_config && bss->ieee80211w == NO_MGMT_FRAME_PROTECTION &&
1478 bss->ocv) {
1479 wpa_printf(MSG_ERROR,
1480 "OCV: PMF needs to be enabled whenever using OCV");
1481 return -1;
1482 }
1483#endif /* CONFIG_OCV */
1484
Hai Shalom899fcc72020-10-19 14:38:18 -07001485#ifdef CONFIG_SAE_PK
1486 if (full_config && hostapd_sae_pk_in_use(bss) &&
1487 hostapd_sae_pk_password_without_pk(bss)) {
1488 wpa_printf(MSG_ERROR,
1489 "SAE-PK: SAE password uses SAE-PK style, but does not have PK configured");
1490 return -1;
1491 }
1492#endif /* CONFIG_SAE_PK */
1493
Hai Shaloma20dcd72022-02-04 13:43:00 -08001494#ifdef CONFIG_FILS
Sunil Ravia04bd252022-05-02 22:54:18 -07001495 if (full_config && bss->fils_discovery_max_int &&
Sunil Ravi036cec52023-03-29 11:35:17 -07001496 (!conf->ieee80211ax || bss->disable_11ax)) {
1497 wpa_printf(MSG_ERROR,
1498 "Currently IEEE 802.11ax support is mandatory to enable FILS discovery transmission.");
1499 return -1;
1500 }
1501
1502 if (full_config && bss->fils_discovery_max_int &&
Hai Shaloma20dcd72022-02-04 13:43:00 -08001503 bss->unsol_bcast_probe_resp_interval) {
1504 wpa_printf(MSG_ERROR,
1505 "Cannot enable both FILS discovery and unsolicited broadcast Probe Response at the same time");
1506 return -1;
1507 }
1508#endif /* CONFIG_FILS */
1509
Sunil Ravia04bd252022-05-02 22:54:18 -07001510#ifdef CONFIG_IEEE80211BE
1511 if (full_config && !bss->disable_11be && bss->disable_11ax) {
1512 bss->disable_11be = true;
1513 wpa_printf(MSG_INFO,
1514 "Disabling IEEE 802.11be as IEEE 802.11ax is disabled for this BSS");
1515 }
1516#endif /* CONFIG_IEEE80211BE */
1517
Sunil Ravi77d572f2023-01-17 23:58:31 +00001518 if (full_config && bss->ignore_broadcast_ssid && conf->mbssid) {
1519 wpa_printf(MSG_ERROR,
1520 "Hidden SSID is not suppored when MBSSID is enabled");
1521 return -1;
1522 }
1523
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001524 return 0;
1525}
1526
1527
Dmitry Shmidt05df46a2015-05-19 11:02:01 -07001528static int hostapd_config_check_cw(struct hostapd_config *conf, int queue)
1529{
1530 int tx_cwmin = conf->tx_queue[queue].cwmin;
1531 int tx_cwmax = conf->tx_queue[queue].cwmax;
1532 int ac_cwmin = conf->wmm_ac_params[queue].cwmin;
1533 int ac_cwmax = conf->wmm_ac_params[queue].cwmax;
1534
1535 if (tx_cwmin > tx_cwmax) {
1536 wpa_printf(MSG_ERROR,
1537 "Invalid TX queue cwMin/cwMax values. cwMin(%d) greater than cwMax(%d)",
1538 tx_cwmin, tx_cwmax);
1539 return -1;
1540 }
1541 if (ac_cwmin > ac_cwmax) {
1542 wpa_printf(MSG_ERROR,
1543 "Invalid WMM AC cwMin/cwMax values. cwMin(%d) greater than cwMax(%d)",
1544 ac_cwmin, ac_cwmax);
1545 return -1;
1546 }
1547 return 0;
1548}
1549
1550
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001551int hostapd_config_check(struct hostapd_config *conf, int full_config)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001552{
1553 size_t i;
1554
Sunil Ravia04bd252022-05-02 22:54:18 -07001555 if (full_config && is_6ghz_op_class(conf->op_class) &&
1556 !conf->hw_mode_set) {
1557 /* Use the appropriate hw_mode value automatically when the
1558 * op_class parameter has been set, but hw_mode was not. */
1559 conf->hw_mode = HOSTAPD_MODE_IEEE80211A;
1560 }
1561
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001562 if (full_config && conf->ieee80211d &&
1563 (!conf->country[0] || !conf->country[1])) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001564 wpa_printf(MSG_ERROR, "Cannot enable IEEE 802.11d without "
1565 "setting the country_code");
1566 return -1;
1567 }
1568
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001569 if (full_config && conf->ieee80211h && !conf->ieee80211d) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001570 wpa_printf(MSG_ERROR, "Cannot enable IEEE 802.11h without "
1571 "IEEE 802.11d enabled");
1572 return -1;
1573 }
1574
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001575 if (full_config && conf->local_pwr_constraint != -1 &&
1576 !conf->ieee80211d) {
1577 wpa_printf(MSG_ERROR, "Cannot add Power Constraint element without Country element");
1578 return -1;
1579 }
1580
1581 if (full_config && conf->spectrum_mgmt_required &&
1582 conf->local_pwr_constraint == -1) {
1583 wpa_printf(MSG_ERROR, "Cannot set Spectrum Management bit without Country and Power Constraint elements");
1584 return -1;
1585 }
1586
Hai Shalom81f62d82019-07-22 12:10:00 -07001587#ifdef CONFIG_AIRTIME_POLICY
1588 if (full_config && conf->airtime_mode > AIRTIME_MODE_STATIC &&
1589 !conf->airtime_update_interval) {
1590 wpa_printf(MSG_ERROR, "Airtime update interval cannot be zero");
1591 return -1;
1592 }
1593#endif /* CONFIG_AIRTIME_POLICY */
Dmitry Shmidt05df46a2015-05-19 11:02:01 -07001594 for (i = 0; i < NUM_TX_QUEUES; i++) {
1595 if (hostapd_config_check_cw(conf, i))
1596 return -1;
1597 }
1598
Sunil Ravia04bd252022-05-02 22:54:18 -07001599#ifdef CONFIG_IEEE80211BE
1600 if (full_config && conf->ieee80211be && !conf->ieee80211ax) {
1601 wpa_printf(MSG_ERROR,
1602 "Cannot set ieee80211be without ieee80211ax");
1603 return -1;
1604 }
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001605
1606 if (full_config)
1607 hostapd_set_and_check_bw320_offset(conf,
1608 conf->eht_bw320_offset);
Sunil Ravia04bd252022-05-02 22:54:18 -07001609#endif /* CONFIG_IEEE80211BE */
1610
Sunil Ravi77d572f2023-01-17 23:58:31 +00001611 if (full_config && conf->mbssid && !conf->ieee80211ax) {
1612 wpa_printf(MSG_ERROR,
1613 "Cannot enable multiple BSSID support without ieee80211ax");
1614 return -1;
1615 }
1616
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001617 for (i = 0; i < conf->num_bss; i++) {
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001618 if (hostapd_config_check_bss(conf->bss[i], conf, full_config))
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001619 return -1;
1620 }
1621
1622 return 0;
1623}
1624
1625
Dmitry Shmidt71757432014-06-02 13:50:35 -07001626void hostapd_set_security_params(struct hostapd_bss_config *bss,
1627 int full_config)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001628{
Hai Shalomfdcde762020-04-02 11:19:20 -07001629#ifdef CONFIG_WEP
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001630 if (bss->individual_wep_key_len == 0) {
1631 /* individual keys are not use; can use key idx0 for
1632 * broadcast keys */
1633 bss->broadcast_key_idx_min = 0;
1634 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001635#endif /* CONFIG_WEP */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001636
1637 if ((bss->wpa & 2) && bss->rsn_pairwise == 0)
1638 bss->rsn_pairwise = bss->wpa_pairwise;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001639 if (bss->group_cipher)
1640 bss->wpa_group = bss->group_cipher;
1641 else
1642 bss->wpa_group = wpa_select_ap_group_cipher(bss->wpa,
1643 bss->wpa_pairwise,
1644 bss->rsn_pairwise);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001645 if (!bss->wpa_group_rekey_set)
1646 bss->wpa_group_rekey = bss->wpa_group == WPA_CIPHER_TKIP ?
1647 600 : 86400;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001648
Dmitry Shmidt71757432014-06-02 13:50:35 -07001649 if (full_config) {
1650 bss->radius->auth_server = bss->radius->auth_servers;
1651 bss->radius->acct_server = bss->radius->acct_servers;
1652 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001653
1654 if (bss->wpa && bss->ieee802_1x) {
1655 bss->ssid.security_policy = SECURITY_WPA;
1656 } else if (bss->wpa) {
1657 bss->ssid.security_policy = SECURITY_WPA_PSK;
1658 } else if (bss->ieee802_1x) {
1659 int cipher = WPA_CIPHER_NONE;
1660 bss->ssid.security_policy = SECURITY_IEEE_802_1X;
Hai Shalomfdcde762020-04-02 11:19:20 -07001661#ifdef CONFIG_WEP
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001662 bss->ssid.wep.default_len = bss->default_wep_key_len;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001663 if (full_config && bss->default_wep_key_len) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001664 cipher = bss->default_wep_key_len >= 13 ?
1665 WPA_CIPHER_WEP104 : WPA_CIPHER_WEP40;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001666 } else if (full_config && bss->ssid.wep.keys_set) {
1667 if (bss->ssid.wep.len[0] >= 13)
1668 cipher = WPA_CIPHER_WEP104;
1669 else
1670 cipher = WPA_CIPHER_WEP40;
1671 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001672#endif /* CONFIG_WEP */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001673 bss->wpa_group = cipher;
1674 bss->wpa_pairwise = cipher;
1675 bss->rsn_pairwise = cipher;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001676 if (full_config)
1677 bss->wpa_key_mgmt = WPA_KEY_MGMT_IEEE8021X_NO_WPA;
Hai Shalomfdcde762020-04-02 11:19:20 -07001678#ifdef CONFIG_WEP
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001679 } else if (bss->ssid.wep.keys_set) {
1680 int cipher = WPA_CIPHER_WEP40;
1681 if (bss->ssid.wep.len[0] >= 13)
1682 cipher = WPA_CIPHER_WEP104;
1683 bss->ssid.security_policy = SECURITY_STATIC_WEP;
1684 bss->wpa_group = cipher;
1685 bss->wpa_pairwise = cipher;
1686 bss->rsn_pairwise = cipher;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001687 if (full_config)
1688 bss->wpa_key_mgmt = WPA_KEY_MGMT_NONE;
Hai Shalomfdcde762020-04-02 11:19:20 -07001689#endif /* CONFIG_WEP */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001690 } else if (bss->osen) {
1691 bss->ssid.security_policy = SECURITY_OSEN;
1692 bss->wpa_group = WPA_CIPHER_CCMP;
1693 bss->wpa_pairwise = 0;
1694 bss->rsn_pairwise = WPA_CIPHER_CCMP;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001695 } else {
1696 bss->ssid.security_policy = SECURITY_PLAINTEXT;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001697 if (full_config) {
1698 bss->wpa_group = WPA_CIPHER_NONE;
1699 bss->wpa_pairwise = WPA_CIPHER_NONE;
1700 bss->rsn_pairwise = WPA_CIPHER_NONE;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001701 bss->wpa_key_mgmt = WPA_KEY_MGMT_NONE;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001702 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001703 }
1704}
Hai Shalom74f70d42019-02-11 14:42:39 -08001705
1706
1707int hostapd_sae_pw_id_in_use(struct hostapd_bss_config *conf)
1708{
1709 int with_id = 0, without_id = 0;
1710 struct sae_password_entry *pw;
1711
1712 if (conf->ssid.wpa_passphrase)
1713 without_id = 1;
1714
1715 for (pw = conf->sae_passwords; pw; pw = pw->next) {
1716 if (pw->identifier)
1717 with_id = 1;
1718 else
1719 without_id = 1;
1720 if (with_id && without_id)
1721 break;
1722 }
1723
1724 if (with_id && !without_id)
1725 return 2;
1726 return with_id;
1727}
Hai Shalom899fcc72020-10-19 14:38:18 -07001728
1729
1730bool hostapd_sae_pk_in_use(struct hostapd_bss_config *conf)
1731{
1732#ifdef CONFIG_SAE_PK
1733 struct sae_password_entry *pw;
1734
1735 for (pw = conf->sae_passwords; pw; pw = pw->next) {
1736 if (pw->pk)
1737 return true;
1738 }
1739#endif /* CONFIG_SAE_PK */
1740
1741 return false;
1742}
1743
1744
1745#ifdef CONFIG_SAE_PK
1746bool hostapd_sae_pk_exclusively(struct hostapd_bss_config *conf)
1747{
1748 bool with_pk = false;
1749 struct sae_password_entry *pw;
1750
1751 if (conf->ssid.wpa_passphrase)
1752 return false;
1753
1754 for (pw = conf->sae_passwords; pw; pw = pw->next) {
1755 if (!pw->pk)
1756 return false;
1757 with_pk = true;
1758 }
1759
1760 return with_pk;
1761}
1762#endif /* CONFIG_SAE_PK */
Sunil Ravia04bd252022-05-02 22:54:18 -07001763
1764
1765int hostapd_acl_comp(const void *a, const void *b)
1766{
1767 const struct mac_acl_entry *aa = a;
1768 const struct mac_acl_entry *bb = b;
1769 return os_memcmp(aa->addr, bb->addr, sizeof(macaddr));
1770}
1771
1772
1773int hostapd_add_acl_maclist(struct mac_acl_entry **acl, int *num,
1774 int vlan_id, const u8 *addr)
1775{
1776 struct mac_acl_entry *newacl;
1777
1778 newacl = os_realloc_array(*acl, *num + 1, sizeof(**acl));
1779 if (!newacl) {
1780 wpa_printf(MSG_ERROR, "MAC list reallocation failed");
1781 return -1;
1782 }
1783
1784 *acl = newacl;
1785 os_memcpy((*acl)[*num].addr, addr, ETH_ALEN);
1786 os_memset(&(*acl)[*num].vlan_id, 0, sizeof((*acl)[*num].vlan_id));
1787 (*acl)[*num].vlan_id.untagged = vlan_id;
1788 (*acl)[*num].vlan_id.notempty = !!vlan_id;
1789 (*num)++;
1790
1791 return 0;
1792}
1793
1794
1795void hostapd_remove_acl_mac(struct mac_acl_entry **acl, int *num,
1796 const u8 *addr)
1797{
1798 int i = 0;
1799
1800 while (i < *num) {
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001801 if (ether_addr_equal((*acl)[i].addr, addr)) {
Sunil Ravia04bd252022-05-02 22:54:18 -07001802 os_remove_in_array(*acl, *num, sizeof(**acl), i);
1803 (*num)--;
1804 } else {
1805 i++;
1806 }
1807 }
1808}