blob: 69550cf25e7c6d08709baf34f6f7740201d0bacf [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 */
Sunil Ravi876a49b2025-02-03 19:18:32 +0000796 os_free(tmp->success_mac);
797 os_free(tmp->fail_mac);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700798 os_free(tmp);
799 }
800}
801
802
Hai Shalom81f62d82019-07-22 12:10:00 -0700803#ifdef CONFIG_DPP2
804static void hostapd_dpp_controller_conf_free(struct dpp_controller_conf *conf)
805{
806 struct dpp_controller_conf *prev;
807
808 while (conf) {
809 prev = conf;
810 conf = conf->next;
811 os_free(prev);
812 }
813}
814#endif /* CONFIG_DPP2 */
815
816
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800817void hostapd_config_free_bss(struct hostapd_bss_config *conf)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700818{
Hai Shalom81f62d82019-07-22 12:10:00 -0700819#if defined(CONFIG_WPS) || defined(CONFIG_HS20)
820 size_t i;
821#endif
822
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700823 if (conf == NULL)
824 return;
825
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800826 hostapd_config_clear_wpa_psk(&conf->ssid.wpa_psk);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700827
Dmitry Shmidtc2817022014-07-02 10:32:10 -0700828 str_clear_free(conf->ssid.wpa_passphrase);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700829 os_free(conf->ssid.wpa_psk_file);
Hai Shalomfdcde762020-04-02 11:19:20 -0700830#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700831 hostapd_config_free_wep(&conf->ssid.wep);
Hai Shalomfdcde762020-04-02 11:19:20 -0700832#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700833#ifdef CONFIG_FULL_DYNAMIC_VLAN
834 os_free(conf->ssid.vlan_tagged_interface);
835#endif /* CONFIG_FULL_DYNAMIC_VLAN */
Hai Shalomc3565922019-10-28 11:58:20 -0700836#ifdef CONFIG_SAE
837 sae_deinit_pt(conf->ssid.pt);
838#endif /* CONFIG_SAE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700839
Dmitry Shmidt29333592017-01-09 12:27:11 -0800840 hostapd_config_free_eap_users(conf->eap_user);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800841 os_free(conf->eap_user_sqlite);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700842
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700843 os_free(conf->eap_req_id_text);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800844 os_free(conf->erp_domain);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700845 os_free(conf->accept_mac);
846 os_free(conf->deny_mac);
847 os_free(conf->nas_identifier);
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800848 if (conf->radius) {
849 hostapd_config_free_radius(conf->radius->auth_servers,
850 conf->radius->num_auth_servers);
851 hostapd_config_free_radius(conf->radius->acct_servers,
852 conf->radius->num_acct_servers);
Hai Shaloma20dcd72022-02-04 13:43:00 -0800853 os_free(conf->radius->force_client_dev);
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800854 }
Dmitry Shmidt04949592012-07-19 12:16:46 -0700855 hostapd_config_free_radius_attr(conf->radius_auth_req_attr);
856 hostapd_config_free_radius_attr(conf->radius_acct_req_attr);
Hai Shalomc3565922019-10-28 11:58:20 -0700857 os_free(conf->radius_req_attr_sqlite);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700858 os_free(conf->rsn_preauth_interfaces);
859 os_free(conf->ctrl_interface);
Sunil Ravi77d572f2023-01-17 23:58:31 +0000860 os_free(conf->config_id);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700861 os_free(conf->ca_cert);
862 os_free(conf->server_cert);
Hai Shalom81f62d82019-07-22 12:10:00 -0700863 os_free(conf->server_cert2);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700864 os_free(conf->private_key);
Hai Shalom81f62d82019-07-22 12:10:00 -0700865 os_free(conf->private_key2);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700866 os_free(conf->private_key_passwd);
Hai Shalom81f62d82019-07-22 12:10:00 -0700867 os_free(conf->private_key_passwd2);
Hai Shalom021b0b52019-04-10 11:17:58 -0700868 os_free(conf->check_cert_subject);
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700869 os_free(conf->ocsp_stapling_response);
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -0800870 os_free(conf->ocsp_stapling_response_multi);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700871 os_free(conf->dh_file);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800872 os_free(conf->openssl_ciphers);
Hai Shalom74f70d42019-02-11 14:42:39 -0800873 os_free(conf->openssl_ecdh_curves);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700874 os_free(conf->pac_opaque_encr_key);
875 os_free(conf->eap_fast_a_id);
876 os_free(conf->eap_fast_a_id_info);
877 os_free(conf->eap_sim_db);
Sunil Ravia04bd252022-05-02 22:54:18 -0700878 os_free(conf->imsi_privacy_key);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700879 os_free(conf->radius_server_clients);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700880 os_free(conf->radius);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700881 os_free(conf->radius_das_shared_secret);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700882 hostapd_config_free_vlan(conf);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800883 os_free(conf->time_zone);
884
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800885#ifdef CONFIG_IEEE80211R_AP
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000886 hostapd_config_clear_rxkhs(conf);
887 os_free(conf->rxkh_file);
888 conf->rxkh_file = NULL;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800889#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700890
891#ifdef CONFIG_WPS
892 os_free(conf->wps_pin_requests);
893 os_free(conf->device_name);
894 os_free(conf->manufacturer);
895 os_free(conf->model_name);
896 os_free(conf->model_number);
897 os_free(conf->serial_number);
898 os_free(conf->config_methods);
899 os_free(conf->ap_pin);
900 os_free(conf->extra_cred);
901 os_free(conf->ap_settings);
Hai Shalom021b0b52019-04-10 11:17:58 -0700902 hostapd_config_clear_wpa_psk(&conf->multi_ap_backhaul_ssid.wpa_psk);
903 str_clear_free(conf->multi_ap_backhaul_ssid.wpa_passphrase);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700904 os_free(conf->upnp_iface);
905 os_free(conf->friendly_name);
906 os_free(conf->manufacturer_url);
907 os_free(conf->model_description);
908 os_free(conf->model_url);
909 os_free(conf->upc);
Hai Shalom81f62d82019-07-22 12:10:00 -0700910 for (i = 0; i < MAX_WPS_VENDOR_EXTENSIONS; i++)
911 wpabuf_free(conf->wps_vendor_ext[i]);
Hai Shalomfdcde762020-04-02 11:19:20 -0700912 wpabuf_free(conf->wps_application_ext);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700913 wpabuf_free(conf->wps_nfc_dh_pubkey);
914 wpabuf_free(conf->wps_nfc_dh_privkey);
915 wpabuf_free(conf->wps_nfc_dev_pw);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700916#endif /* CONFIG_WPS */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800917
918 os_free(conf->roaming_consortium);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700919 os_free(conf->venue_name);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700920 os_free(conf->venue_url);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700921 os_free(conf->nai_realm_data);
922 os_free(conf->network_auth_type);
923 os_free(conf->anqp_3gpp_cell_net);
924 os_free(conf->domain_name);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800925 hostapd_config_free_anqp_elem(conf);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800926
927#ifdef CONFIG_RADIUS_TEST
928 os_free(conf->dump_msk_file);
929#endif /* CONFIG_RADIUS_TEST */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700930
931#ifdef CONFIG_HS20
932 os_free(conf->hs20_oper_friendly_name);
933 os_free(conf->hs20_wan_metrics);
934 os_free(conf->hs20_connection_capability);
935 os_free(conf->hs20_operating_class);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700936 os_free(conf->t_c_filename);
937 os_free(conf->t_c_server_url);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700938#endif /* CONFIG_HS20 */
939
940 wpabuf_free(conf->vendor_elements);
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700941 wpabuf_free(conf->assocresp_elements);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800942
943 os_free(conf->sae_groups);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700944#ifdef CONFIG_OWE
945 os_free(conf->owe_groups);
946#endif /* CONFIG_OWE */
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700947
Dmitry Shmidt0207e232014-09-03 14:58:37 -0700948 os_free(conf->wowlan_triggers);
949
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700950 os_free(conf->server_id);
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800951
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800952#ifdef CONFIG_TESTING_OPTIONS
953 wpabuf_free(conf->own_ie_override);
Sunil Ravic0f5d412024-09-11 22:12:49 +0000954 wpabuf_free(conf->rsne_override);
955 wpabuf_free(conf->rsnoe_override);
956 wpabuf_free(conf->rsno2e_override);
957 wpabuf_free(conf->rsnxe_override);
958 wpabuf_free(conf->rsnxoe_override);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700959 wpabuf_free(conf->sae_commit_override);
Hai Shalomfdcde762020-04-02 11:19:20 -0700960 wpabuf_free(conf->rsne_override_eapol);
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800961 wpabuf_free(conf->rsnxe_override_eapol);
Hai Shalomfdcde762020-04-02 11:19:20 -0700962 wpabuf_free(conf->rsne_override_ft);
963 wpabuf_free(conf->rsnxe_override_ft);
964 wpabuf_free(conf->gtk_rsc_override);
965 wpabuf_free(conf->igtk_rsc_override);
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000966 wpabuf_free(conf->eapol_m1_elements);
967 wpabuf_free(conf->eapol_m3_elements);
Sunil Ravi7f769292024-07-23 22:21:32 +0000968 wpabuf_free(conf->presp_elements);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800969#endif /* CONFIG_TESTING_OPTIONS */
970
971 os_free(conf->no_probe_resp_if_seen_on);
972 os_free(conf->no_auth_if_seen_on);
973
Dmitry Shmidt29333592017-01-09 12:27:11 -0800974 hostapd_config_free_fils_realms(conf);
975
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700976#ifdef CONFIG_DPP
Hai Shalomc3565922019-10-28 11:58:20 -0700977 os_free(conf->dpp_name);
978 os_free(conf->dpp_mud_url);
Sunil Ravi89eba102022-09-13 21:04:37 -0700979 os_free(conf->dpp_extra_conf_req_name);
980 os_free(conf->dpp_extra_conf_req_value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700981 os_free(conf->dpp_connector);
982 wpabuf_free(conf->dpp_netaccesskey);
983 wpabuf_free(conf->dpp_csign);
Hai Shalom81f62d82019-07-22 12:10:00 -0700984#ifdef CONFIG_DPP2
985 hostapd_dpp_controller_conf_free(conf->dpp_controller);
986#endif /* CONFIG_DPP2 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700987#endif /* CONFIG_DPP */
988
Roshan Pius3a1667e2018-07-03 15:17:14 -0700989 hostapd_config_free_sae_passwords(conf);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700990
Hai Shalom81f62d82019-07-22 12:10:00 -0700991#ifdef CONFIG_AIRTIME_POLICY
992 {
993 struct airtime_sta_weight *wt, *wt_prev;
994
995 wt = conf->airtime_weight_list;
996 conf->airtime_weight_list = NULL;
997 while (wt) {
998 wt_prev = wt;
999 wt = wt->next;
1000 os_free(wt_prev);
1001 }
1002 }
1003#endif /* CONFIG_AIRTIME_POLICY */
1004
Hai Shalom60840252021-02-19 19:02:11 -08001005#ifdef CONFIG_PASN
1006 os_free(conf->pasn_groups);
1007#endif /* CONFIG_PASN */
1008
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001009 os_free(conf);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001010}
1011
1012
1013/**
1014 * hostapd_config_free - Free hostapd configuration
1015 * @conf: Configuration data from hostapd_config_read().
1016 */
1017void hostapd_config_free(struct hostapd_config *conf)
1018{
1019 size_t i;
1020
1021 if (conf == NULL)
1022 return;
1023
1024 for (i = 0; i < conf->num_bss; i++)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001025 hostapd_config_free_bss(conf->bss[i]);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001026 os_free(conf->bss);
1027 os_free(conf->supported_rates);
1028 os_free(conf->basic_rates);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07001029 os_free(conf->acs_ch_list.range);
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001030 os_free(conf->acs_freq_list.range);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001031 os_free(conf->driver_params);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001032#ifdef CONFIG_ACS
1033 os_free(conf->acs_chan_bias);
1034#endif /* CONFIG_ACS */
Dmitry Shmidt849734c2016-05-27 09:59:01 -07001035 wpabuf_free(conf->lci);
1036 wpabuf_free(conf->civic);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001037
1038 os_free(conf);
1039}
1040
1041
1042/**
1043 * hostapd_maclist_found - Find a MAC address from a list
1044 * @list: MAC address list
1045 * @num_entries: Number of addresses in the list
1046 * @addr: Address to search for
1047 * @vlan_id: Buffer for returning VLAN ID or %NULL if not needed
1048 * Returns: 1 if address is in the list or 0 if not.
1049 *
1050 * Perform a binary search for given MAC address from a pre-sorted list.
1051 */
1052int hostapd_maclist_found(struct mac_acl_entry *list, int num_entries,
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001053 const u8 *addr, struct vlan_description *vlan_id)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001054{
1055 int start, end, middle, res;
1056
1057 start = 0;
1058 end = num_entries - 1;
1059
1060 while (start <= end) {
1061 middle = (start + end) / 2;
1062 res = os_memcmp(list[middle].addr, addr, ETH_ALEN);
1063 if (res == 0) {
1064 if (vlan_id)
1065 *vlan_id = list[middle].vlan_id;
1066 return 1;
1067 }
1068 if (res < 0)
1069 start = middle + 1;
1070 else
1071 end = middle - 1;
1072 }
1073
1074 return 0;
1075}
1076
1077
1078int hostapd_rate_found(int *list, int rate)
1079{
1080 int i;
1081
1082 if (list == NULL)
1083 return 0;
1084
1085 for (i = 0; list[i] >= 0; i++)
1086 if (list[i] == rate)
1087 return 1;
1088
1089 return 0;
1090}
1091
1092
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001093int hostapd_vlan_valid(struct hostapd_vlan *vlan,
1094 struct vlan_description *vlan_desc)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001095{
1096 struct hostapd_vlan *v = vlan;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001097 int i;
1098
1099 if (!vlan_desc->notempty || vlan_desc->untagged < 0 ||
1100 vlan_desc->untagged > MAX_VLAN_ID)
1101 return 0;
1102 for (i = 0; i < MAX_NUM_TAGGED_VLAN; i++) {
1103 if (vlan_desc->tagged[i] < 0 ||
1104 vlan_desc->tagged[i] > MAX_VLAN_ID)
1105 return 0;
1106 }
1107 if (!vlan_desc->untagged && !vlan_desc->tagged[0])
1108 return 0;
1109
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001110 while (v) {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001111 if (!vlan_compare(&v->vlan_desc, vlan_desc) ||
1112 v->vlan_id == VLAN_ID_WILDCARD)
Dmitry Shmidt34af3062013-07-11 10:46:32 -07001113 return 1;
1114 v = v->next;
1115 }
1116 return 0;
1117}
1118
1119
1120const char * hostapd_get_vlan_id_ifname(struct hostapd_vlan *vlan, int vlan_id)
1121{
1122 struct hostapd_vlan *v = vlan;
1123 while (v) {
1124 if (v->vlan_id == vlan_id)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001125 return v->ifname;
1126 v = v->next;
1127 }
1128 return NULL;
1129}
1130
1131
1132const u8 * hostapd_get_psk(const struct hostapd_bss_config *conf,
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001133 const u8 *addr, const u8 *p2p_dev_addr,
Hai Shalom021b0b52019-04-10 11:17:58 -07001134 const u8 *prev_psk, int *vlan_id)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001135{
1136 struct hostapd_wpa_psk *psk;
1137 int next_ok = prev_psk == NULL;
1138
Hai Shalom021b0b52019-04-10 11:17:58 -07001139 if (vlan_id)
1140 *vlan_id = 0;
1141
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001142 if (p2p_dev_addr && !is_zero_ether_addr(p2p_dev_addr)) {
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001143 wpa_printf(MSG_DEBUG, "Searching a PSK for " MACSTR
1144 " p2p_dev_addr=" MACSTR " prev_psk=%p",
1145 MAC2STR(addr), MAC2STR(p2p_dev_addr), prev_psk);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001146 addr = NULL; /* Use P2P Device Address for matching */
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001147 } else {
1148 wpa_printf(MSG_DEBUG, "Searching a PSK for " MACSTR
1149 " prev_psk=%p",
1150 MAC2STR(addr), prev_psk);
1151 }
1152
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001153 for (psk = conf->ssid.wpa_psk; psk != NULL; psk = psk->next) {
1154 if (next_ok &&
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001155 (psk->group ||
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001156 (addr && ether_addr_equal(psk->addr, addr)) ||
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001157 (!addr && p2p_dev_addr &&
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001158 ether_addr_equal(psk->p2p_dev_addr, p2p_dev_addr)))) {
Hai Shalom021b0b52019-04-10 11:17:58 -07001159 if (vlan_id)
1160 *vlan_id = psk->vlan_id;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001161 return psk->psk;
Hai Shalom021b0b52019-04-10 11:17:58 -07001162 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001163
1164 if (psk->psk == prev_psk)
1165 next_ok = 1;
1166 }
1167
1168 return NULL;
1169}
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001170
1171
Hai Shalom899fcc72020-10-19 14:38:18 -07001172#ifdef CONFIG_SAE_PK
1173static bool hostapd_sae_pk_password_without_pk(struct hostapd_bss_config *bss)
1174{
1175 struct sae_password_entry *pw;
1176 bool res = false;
1177
1178 if (bss->ssid.wpa_passphrase &&
1179#ifdef CONFIG_TESTING_OPTIONS
1180 !bss->sae_pk_password_check_skip &&
1181#endif /* CONFIG_TESTING_OPTIONS */
1182 sae_pk_valid_password(bss->ssid.wpa_passphrase))
1183 res = true;
1184
1185 for (pw = bss->sae_passwords; pw; pw = pw->next) {
1186 if (!pw->pk &&
1187#ifdef CONFIG_TESTING_OPTIONS
1188 !bss->sae_pk_password_check_skip &&
1189#endif /* CONFIG_TESTING_OPTIONS */
1190 sae_pk_valid_password(pw->password))
1191 return true;
1192
1193 if (bss->ssid.wpa_passphrase && res && pw->pk &&
1194 os_strcmp(bss->ssid.wpa_passphrase, pw->password) == 0)
1195 res = false;
1196 }
1197
1198 return res;
1199}
1200#endif /* CONFIG_SAE_PK */
1201
1202
Hai Shalom60840252021-02-19 19:02:11 -08001203static bool hostapd_config_check_bss_6g(struct hostapd_bss_config *bss)
1204{
1205 if (bss->wpa != WPA_PROTO_RSN) {
1206 wpa_printf(MSG_ERROR,
1207 "Pre-RSNA security methods are not allowed in 6 GHz");
1208 return false;
1209 }
1210
1211 if (bss->ieee80211w != MGMT_FRAME_PROTECTION_REQUIRED) {
1212 wpa_printf(MSG_ERROR,
1213 "Management frame protection is required in 6 GHz");
1214 return false;
1215 }
1216
1217 if (bss->wpa_key_mgmt & (WPA_KEY_MGMT_PSK |
1218 WPA_KEY_MGMT_FT_PSK |
1219 WPA_KEY_MGMT_PSK_SHA256)) {
1220 wpa_printf(MSG_ERROR, "Invalid AKM suite for 6 GHz");
1221 return false;
1222 }
1223
1224 if (bss->rsn_pairwise & (WPA_CIPHER_WEP40 |
1225 WPA_CIPHER_WEP104 |
1226 WPA_CIPHER_TKIP)) {
1227 wpa_printf(MSG_ERROR,
1228 "Invalid pairwise cipher suite for 6 GHz");
1229 return false;
1230 }
1231
1232 if (bss->wpa_group & (WPA_CIPHER_WEP40 |
1233 WPA_CIPHER_WEP104 |
1234 WPA_CIPHER_TKIP)) {
1235 wpa_printf(MSG_ERROR, "Invalid group cipher suite for 6 GHz");
1236 return false;
1237 }
1238
Sunil Ravi77d572f2023-01-17 23:58:31 +00001239#ifdef CONFIG_SAE
1240 if (wpa_key_mgmt_sae(bss->wpa_key_mgmt) &&
1241 bss->sae_pwe == SAE_PWE_HUNT_AND_PECK) {
1242 wpa_printf(MSG_INFO, "SAE: Enabling SAE H2E on 6 GHz");
1243 bss->sae_pwe = SAE_PWE_BOTH;
1244 }
1245#endif /* CONFIG_SAE */
1246
Hai Shalom60840252021-02-19 19:02:11 -08001247 return true;
1248}
1249
1250
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001251static int hostapd_config_check_bss(struct hostapd_bss_config *bss,
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001252 struct hostapd_config *conf,
1253 int full_config)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001254{
Hai Shalom60840252021-02-19 19:02:11 -08001255 if (full_config && is_6ghz_op_class(conf->op_class) &&
1256 !hostapd_config_check_bss_6g(bss))
1257 return -1;
1258
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001259 if (full_config && bss->ieee802_1x && !bss->eap_server &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001260 !bss->radius->auth_servers) {
1261 wpa_printf(MSG_ERROR, "Invalid IEEE 802.1X configuration (no "
1262 "EAP authenticator configured).");
1263 return -1;
1264 }
1265
Hai Shalomfdcde762020-04-02 11:19:20 -07001266#ifdef CONFIG_WEP
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001267 if (bss->wpa) {
1268 int wep, i;
1269
1270 wep = bss->default_wep_key_len > 0 ||
1271 bss->individual_wep_key_len > 0;
1272 for (i = 0; i < NUM_WEP_KEYS; i++) {
1273 if (bss->ssid.wep.keys_set) {
1274 wep = 1;
1275 break;
1276 }
1277 }
1278
1279 if (wep) {
1280 wpa_printf(MSG_ERROR, "WEP configuration in a WPA network is not supported");
1281 return -1;
1282 }
1283 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001284#endif /* CONFIG_WEP */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001285
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001286 if (full_config && bss->wpa &&
1287 bss->wpa_psk_radius != PSK_RADIUS_IGNORED &&
Sunil Ravia04bd252022-05-02 22:54:18 -07001288 bss->wpa_psk_radius != PSK_RADIUS_DURING_4WAY_HS &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001289 bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH) {
1290 wpa_printf(MSG_ERROR, "WPA-PSK using RADIUS enabled, but no "
1291 "RADIUS checking (macaddr_acl=2) enabled.");
1292 return -1;
1293 }
1294
Sunil Ravia04bd252022-05-02 22:54:18 -07001295 if (full_config && bss->wpa &&
1296 wpa_key_mgmt_wpa_psk_no_sae(bss->wpa_key_mgmt) &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001297 bss->ssid.wpa_psk == NULL && bss->ssid.wpa_passphrase == NULL &&
1298 bss->ssid.wpa_psk_file == NULL &&
Sunil Ravia04bd252022-05-02 22:54:18 -07001299 bss->wpa_psk_radius != PSK_RADIUS_DURING_4WAY_HS &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001300 (bss->wpa_psk_radius != PSK_RADIUS_REQUIRED ||
1301 bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH)) {
1302 wpa_printf(MSG_ERROR, "WPA-PSK enabled, but PSK or passphrase "
1303 "is not configured.");
1304 return -1;
1305 }
1306
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001307 if (full_config && !is_zero_ether_addr(bss->bssid)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001308 size_t i;
1309
1310 for (i = 0; i < conf->num_bss; i++) {
1311 if (conf->bss[i] != bss &&
1312 (hostapd_mac_comp(conf->bss[i]->bssid,
1313 bss->bssid) == 0)) {
1314 wpa_printf(MSG_ERROR, "Duplicate BSSID " MACSTR
1315 " on interface '%s' and '%s'.",
1316 MAC2STR(bss->bssid),
1317 conf->bss[i]->iface, bss->iface);
1318 return -1;
1319 }
1320 }
1321 }
1322
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001323#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001324 if (full_config && wpa_key_mgmt_ft(bss->wpa_key_mgmt) &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001325 (bss->nas_identifier == NULL ||
1326 os_strlen(bss->nas_identifier) < 1 ||
1327 os_strlen(bss->nas_identifier) > FT_R0KH_ID_MAX_LEN)) {
1328 wpa_printf(MSG_ERROR, "FT (IEEE 802.11r) requires "
1329 "nas_identifier to be configured as a 1..48 octet "
1330 "string");
1331 return -1;
1332 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001333#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001334
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001335 if (full_config && conf->ieee80211n &&
1336 conf->hw_mode == HOSTAPD_MODE_IEEE80211B) {
Hai Shalom60840252021-02-19 19:02:11 -08001337 bss->disable_11n = true;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001338 wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) in 11b mode is not "
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001339 "allowed, disabling HT capabilities");
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001340 }
1341
Hai Shalomfdcde762020-04-02 11:19:20 -07001342#ifdef CONFIG_WEP
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001343 if (full_config && conf->ieee80211n &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001344 bss->ssid.security_policy == SECURITY_STATIC_WEP) {
Hai Shalom60840252021-02-19 19:02:11 -08001345 bss->disable_11n = true;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001346 wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) with WEP is not "
1347 "allowed, disabling HT capabilities");
1348 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001349#endif /* CONFIG_WEP */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001350
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001351 if (full_config && conf->ieee80211n && bss->wpa &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001352 !(bss->wpa_pairwise & WPA_CIPHER_CCMP) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001353 !(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_11n = true;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001357 wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) with WPA/WPA2 "
1358 "requires CCMP/GCMP to be enabled, disabling HT "
1359 "capabilities");
1360 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001361
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07001362#ifdef CONFIG_IEEE80211AC
Hai Shalomfdcde762020-04-02 11:19:20 -07001363#ifdef CONFIG_WEP
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07001364 if (full_config && conf->ieee80211ac &&
1365 bss->ssid.security_policy == SECURITY_STATIC_WEP) {
Hai Shalom60840252021-02-19 19:02:11 -08001366 bss->disable_11ac = true;
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07001367 wpa_printf(MSG_ERROR,
1368 "VHT (IEEE 802.11ac) with WEP is not allowed, disabling VHT capabilities");
1369 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001370#endif /* CONFIG_WEP */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001371
1372 if (full_config && conf->ieee80211ac && 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 {
Hai Shalom60840252021-02-19 19:02:11 -08001377 bss->disable_11ac = true;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001378 wpa_printf(MSG_ERROR,
1379 "VHT (IEEE 802.11ac) with WPA/WPA2 requires CCMP/GCMP to be enabled, disabling VHT capabilities");
1380 }
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07001381#endif /* CONFIG_IEEE80211AC */
1382
Hai Shalom60840252021-02-19 19:02:11 -08001383#ifdef CONFIG_IEEE80211AX
1384#ifdef CONFIG_WEP
1385 if (full_config && conf->ieee80211ax &&
1386 bss->ssid.security_policy == SECURITY_STATIC_WEP) {
1387 bss->disable_11ax = true;
1388 wpa_printf(MSG_ERROR,
1389 "HE (IEEE 802.11ax) with WEP is not allowed, disabling HE capabilities");
1390 }
1391#endif /* CONFIG_WEP */
1392
1393 if (full_config && conf->ieee80211ax && bss->wpa &&
1394 !(bss->wpa_pairwise & WPA_CIPHER_CCMP) &&
1395 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
1396 WPA_CIPHER_CCMP_256 | WPA_CIPHER_GCMP_256)))
1397 {
1398 bss->disable_11ax = true;
1399 wpa_printf(MSG_ERROR,
1400 "HE (IEEE 802.11ax) with WPA/WPA2 requires CCMP/GCMP to be enabled, disabling HE capabilities");
1401 }
1402#endif /* CONFIG_IEEE80211AX */
1403
Dmitry Shmidt15907092014-03-25 10:42:57 -07001404#ifdef CONFIG_WPS
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001405 if (full_config && bss->wps_state && bss->ignore_broadcast_ssid) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001406 wpa_printf(MSG_INFO, "WPS: ignore_broadcast_ssid "
1407 "configuration forced WPS to be disabled");
1408 bss->wps_state = 0;
1409 }
1410
Hai Shalomfdcde762020-04-02 11:19:20 -07001411#ifdef CONFIG_WEP
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001412 if (full_config && bss->wps_state &&
1413 bss->ssid.wep.keys_set && bss->wpa == 0) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001414 wpa_printf(MSG_INFO, "WPS: WEP configuration forced WPS to be "
1415 "disabled");
1416 bss->wps_state = 0;
1417 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001418#endif /* CONFIG_WEP */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001419
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001420 if (full_config && bss->wps_state && bss->wpa &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001421 (!(bss->wpa & 2) ||
Roshan Pius3a1667e2018-07-03 15:17:14 -07001422 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
1423 WPA_CIPHER_CCMP_256 |
1424 WPA_CIPHER_GCMP_256)))) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001425 wpa_printf(MSG_INFO, "WPS: WPA/TKIP configuration without "
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07001426 "WPA2/CCMP/GCMP forced WPS to be disabled");
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001427 bss->wps_state = 0;
1428 }
Dmitry Shmidt15907092014-03-25 10:42:57 -07001429#endif /* CONFIG_WPS */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001430
1431#ifdef CONFIG_HS20
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001432 if (full_config && bss->hs20 &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001433 (!(bss->wpa & 2) ||
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001434 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
1435 WPA_CIPHER_CCMP_256 |
1436 WPA_CIPHER_GCMP_256)))) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001437 wpa_printf(MSG_ERROR, "HS 2.0: WPA2-Enterprise/CCMP "
1438 "configuration is required for Hotspot 2.0 "
1439 "functionality");
1440 return -1;
1441 }
1442#endif /* CONFIG_HS20 */
1443
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001444#ifdef CONFIG_MBO
1445 if (full_config && bss->mbo_enabled && (bss->wpa & 2) &&
1446 bss->ieee80211w == NO_MGMT_FRAME_PROTECTION) {
1447 wpa_printf(MSG_ERROR,
1448 "MBO: PMF needs to be enabled whenever using WPA2 with MBO");
1449 return -1;
1450 }
1451#endif /* CONFIG_MBO */
1452
Hai Shalom74f70d42019-02-11 14:42:39 -08001453#ifdef CONFIG_OCV
1454 if (full_config && bss->ieee80211w == NO_MGMT_FRAME_PROTECTION &&
1455 bss->ocv) {
1456 wpa_printf(MSG_ERROR,
1457 "OCV: PMF needs to be enabled whenever using OCV");
1458 return -1;
1459 }
1460#endif /* CONFIG_OCV */
1461
Hai Shalom899fcc72020-10-19 14:38:18 -07001462#ifdef CONFIG_SAE_PK
1463 if (full_config && hostapd_sae_pk_in_use(bss) &&
1464 hostapd_sae_pk_password_without_pk(bss)) {
1465 wpa_printf(MSG_ERROR,
1466 "SAE-PK: SAE password uses SAE-PK style, but does not have PK configured");
1467 return -1;
1468 }
1469#endif /* CONFIG_SAE_PK */
1470
Hai Shaloma20dcd72022-02-04 13:43:00 -08001471#ifdef CONFIG_FILS
Sunil Ravia04bd252022-05-02 22:54:18 -07001472 if (full_config && bss->fils_discovery_max_int &&
Sunil Ravi036cec52023-03-29 11:35:17 -07001473 (!conf->ieee80211ax || bss->disable_11ax)) {
1474 wpa_printf(MSG_ERROR,
1475 "Currently IEEE 802.11ax support is mandatory to enable FILS discovery transmission.");
1476 return -1;
1477 }
1478
1479 if (full_config && bss->fils_discovery_max_int &&
Hai Shaloma20dcd72022-02-04 13:43:00 -08001480 bss->unsol_bcast_probe_resp_interval) {
1481 wpa_printf(MSG_ERROR,
1482 "Cannot enable both FILS discovery and unsolicited broadcast Probe Response at the same time");
1483 return -1;
1484 }
1485#endif /* CONFIG_FILS */
1486
Sunil Ravia04bd252022-05-02 22:54:18 -07001487#ifdef CONFIG_IEEE80211BE
1488 if (full_config && !bss->disable_11be && bss->disable_11ax) {
1489 bss->disable_11be = true;
1490 wpa_printf(MSG_INFO,
1491 "Disabling IEEE 802.11be as IEEE 802.11ax is disabled for this BSS");
1492 }
Sunil Ravi876a49b2025-02-03 19:18:32 +00001493
1494 if (full_config && conf->ieee80211be && !bss->disable_11be &&
1495 !bss->beacon_prot && ap_pmf_enabled(bss)) {
1496 bss->beacon_prot = 1;
1497 wpa_printf(MSG_INFO,
1498 "Enabling beacon protection as IEEE 802.11be is enabled for this BSS");
1499 }
Sunil Ravia04bd252022-05-02 22:54:18 -07001500#endif /* CONFIG_IEEE80211BE */
1501
Sunil Ravi77d572f2023-01-17 23:58:31 +00001502 if (full_config && bss->ignore_broadcast_ssid && conf->mbssid) {
1503 wpa_printf(MSG_ERROR,
1504 "Hidden SSID is not suppored when MBSSID is enabled");
1505 return -1;
1506 }
1507
Sunil Ravi876a49b2025-02-03 19:18:32 +00001508 /* Do not advertise SPP A-MSDU support if not using CCMP/GCMP */
1509 if (full_config && bss->spp_amsdu &&
1510 !(bss->wpa &&
1511 bss->rsn_pairwise & (WPA_CIPHER_CCMP_256 | WPA_CIPHER_CCMP |
1512 WPA_CIPHER_GCMP_256 | WPA_CIPHER_GCMP)))
1513 bss->spp_amsdu = false;
1514
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001515 return 0;
1516}
1517
1518
Dmitry Shmidt05df46a2015-05-19 11:02:01 -07001519static int hostapd_config_check_cw(struct hostapd_config *conf, int queue)
1520{
1521 int tx_cwmin = conf->tx_queue[queue].cwmin;
1522 int tx_cwmax = conf->tx_queue[queue].cwmax;
1523 int ac_cwmin = conf->wmm_ac_params[queue].cwmin;
1524 int ac_cwmax = conf->wmm_ac_params[queue].cwmax;
1525
1526 if (tx_cwmin > tx_cwmax) {
1527 wpa_printf(MSG_ERROR,
1528 "Invalid TX queue cwMin/cwMax values. cwMin(%d) greater than cwMax(%d)",
1529 tx_cwmin, tx_cwmax);
1530 return -1;
1531 }
1532 if (ac_cwmin > ac_cwmax) {
1533 wpa_printf(MSG_ERROR,
1534 "Invalid WMM AC cwMin/cwMax values. cwMin(%d) greater than cwMax(%d)",
1535 ac_cwmin, ac_cwmax);
1536 return -1;
1537 }
1538 return 0;
1539}
1540
1541
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001542int hostapd_config_check(struct hostapd_config *conf, int full_config)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001543{
1544 size_t i;
1545
Sunil Ravia04bd252022-05-02 22:54:18 -07001546 if (full_config && is_6ghz_op_class(conf->op_class) &&
1547 !conf->hw_mode_set) {
1548 /* Use the appropriate hw_mode value automatically when the
1549 * op_class parameter has been set, but hw_mode was not. */
1550 conf->hw_mode = HOSTAPD_MODE_IEEE80211A;
1551 }
1552
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001553 if (full_config && conf->ieee80211d &&
1554 (!conf->country[0] || !conf->country[1])) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001555 wpa_printf(MSG_ERROR, "Cannot enable IEEE 802.11d without "
1556 "setting the country_code");
1557 return -1;
1558 }
1559
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001560 if (full_config && conf->ieee80211h && !conf->ieee80211d) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001561 wpa_printf(MSG_ERROR, "Cannot enable IEEE 802.11h without "
1562 "IEEE 802.11d enabled");
1563 return -1;
1564 }
1565
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001566 if (full_config && conf->local_pwr_constraint != -1 &&
1567 !conf->ieee80211d) {
1568 wpa_printf(MSG_ERROR, "Cannot add Power Constraint element without Country element");
1569 return -1;
1570 }
1571
1572 if (full_config && conf->spectrum_mgmt_required &&
1573 conf->local_pwr_constraint == -1) {
1574 wpa_printf(MSG_ERROR, "Cannot set Spectrum Management bit without Country and Power Constraint elements");
1575 return -1;
1576 }
1577
Hai Shalom81f62d82019-07-22 12:10:00 -07001578#ifdef CONFIG_AIRTIME_POLICY
1579 if (full_config && conf->airtime_mode > AIRTIME_MODE_STATIC &&
1580 !conf->airtime_update_interval) {
1581 wpa_printf(MSG_ERROR, "Airtime update interval cannot be zero");
1582 return -1;
1583 }
1584#endif /* CONFIG_AIRTIME_POLICY */
Dmitry Shmidt05df46a2015-05-19 11:02:01 -07001585 for (i = 0; i < NUM_TX_QUEUES; i++) {
1586 if (hostapd_config_check_cw(conf, i))
1587 return -1;
1588 }
1589
Sunil Ravia04bd252022-05-02 22:54:18 -07001590#ifdef CONFIG_IEEE80211BE
1591 if (full_config && conf->ieee80211be && !conf->ieee80211ax) {
1592 wpa_printf(MSG_ERROR,
1593 "Cannot set ieee80211be without ieee80211ax");
1594 return -1;
1595 }
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001596
1597 if (full_config)
1598 hostapd_set_and_check_bw320_offset(conf,
1599 conf->eht_bw320_offset);
Sunil Ravia04bd252022-05-02 22:54:18 -07001600#endif /* CONFIG_IEEE80211BE */
1601
Sunil Ravi77d572f2023-01-17 23:58:31 +00001602 if (full_config && conf->mbssid && !conf->ieee80211ax) {
1603 wpa_printf(MSG_ERROR,
1604 "Cannot enable multiple BSSID support without ieee80211ax");
1605 return -1;
1606 }
1607
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001608 for (i = 0; i < conf->num_bss; i++) {
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001609 if (hostapd_config_check_bss(conf->bss[i], conf, full_config))
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001610 return -1;
1611 }
1612
1613 return 0;
1614}
1615
1616
Dmitry Shmidt71757432014-06-02 13:50:35 -07001617void hostapd_set_security_params(struct hostapd_bss_config *bss,
1618 int full_config)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001619{
Hai Shalomfdcde762020-04-02 11:19:20 -07001620#ifdef CONFIG_WEP
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001621 if (bss->individual_wep_key_len == 0) {
1622 /* individual keys are not use; can use key idx0 for
1623 * broadcast keys */
1624 bss->broadcast_key_idx_min = 0;
1625 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001626#endif /* CONFIG_WEP */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001627
1628 if ((bss->wpa & 2) && bss->rsn_pairwise == 0)
1629 bss->rsn_pairwise = bss->wpa_pairwise;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001630 if (bss->group_cipher)
1631 bss->wpa_group = bss->group_cipher;
1632 else
1633 bss->wpa_group = wpa_select_ap_group_cipher(bss->wpa,
1634 bss->wpa_pairwise,
1635 bss->rsn_pairwise);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001636 if (!bss->wpa_group_rekey_set)
1637 bss->wpa_group_rekey = bss->wpa_group == WPA_CIPHER_TKIP ?
1638 600 : 86400;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001639
Dmitry Shmidt71757432014-06-02 13:50:35 -07001640 if (full_config) {
1641 bss->radius->auth_server = bss->radius->auth_servers;
1642 bss->radius->acct_server = bss->radius->acct_servers;
1643 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001644
1645 if (bss->wpa && bss->ieee802_1x) {
1646 bss->ssid.security_policy = SECURITY_WPA;
1647 } else if (bss->wpa) {
1648 bss->ssid.security_policy = SECURITY_WPA_PSK;
1649 } else if (bss->ieee802_1x) {
1650 int cipher = WPA_CIPHER_NONE;
1651 bss->ssid.security_policy = SECURITY_IEEE_802_1X;
Hai Shalomfdcde762020-04-02 11:19:20 -07001652#ifdef CONFIG_WEP
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001653 bss->ssid.wep.default_len = bss->default_wep_key_len;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001654 if (full_config && bss->default_wep_key_len) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001655 cipher = bss->default_wep_key_len >= 13 ?
1656 WPA_CIPHER_WEP104 : WPA_CIPHER_WEP40;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001657 } else if (full_config && bss->ssid.wep.keys_set) {
1658 if (bss->ssid.wep.len[0] >= 13)
1659 cipher = WPA_CIPHER_WEP104;
1660 else
1661 cipher = WPA_CIPHER_WEP40;
1662 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001663#endif /* CONFIG_WEP */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001664 bss->wpa_group = cipher;
1665 bss->wpa_pairwise = cipher;
1666 bss->rsn_pairwise = cipher;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001667 if (full_config)
1668 bss->wpa_key_mgmt = WPA_KEY_MGMT_IEEE8021X_NO_WPA;
Hai Shalomfdcde762020-04-02 11:19:20 -07001669#ifdef CONFIG_WEP
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001670 } else if (bss->ssid.wep.keys_set) {
1671 int cipher = WPA_CIPHER_WEP40;
1672 if (bss->ssid.wep.len[0] >= 13)
1673 cipher = WPA_CIPHER_WEP104;
1674 bss->ssid.security_policy = SECURITY_STATIC_WEP;
1675 bss->wpa_group = cipher;
1676 bss->wpa_pairwise = cipher;
1677 bss->rsn_pairwise = cipher;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001678 if (full_config)
1679 bss->wpa_key_mgmt = WPA_KEY_MGMT_NONE;
Hai Shalomfdcde762020-04-02 11:19:20 -07001680#endif /* CONFIG_WEP */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001681 } else {
1682 bss->ssid.security_policy = SECURITY_PLAINTEXT;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001683 if (full_config) {
1684 bss->wpa_group = WPA_CIPHER_NONE;
1685 bss->wpa_pairwise = WPA_CIPHER_NONE;
1686 bss->rsn_pairwise = WPA_CIPHER_NONE;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001687 bss->wpa_key_mgmt = WPA_KEY_MGMT_NONE;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001688 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001689 }
1690}
Hai Shalom74f70d42019-02-11 14:42:39 -08001691
1692
1693int hostapd_sae_pw_id_in_use(struct hostapd_bss_config *conf)
1694{
1695 int with_id = 0, without_id = 0;
1696 struct sae_password_entry *pw;
1697
1698 if (conf->ssid.wpa_passphrase)
1699 without_id = 1;
1700
1701 for (pw = conf->sae_passwords; pw; pw = pw->next) {
1702 if (pw->identifier)
1703 with_id = 1;
1704 else
1705 without_id = 1;
1706 if (with_id && without_id)
1707 break;
1708 }
1709
1710 if (with_id && !without_id)
1711 return 2;
1712 return with_id;
1713}
Hai Shalom899fcc72020-10-19 14:38:18 -07001714
1715
1716bool hostapd_sae_pk_in_use(struct hostapd_bss_config *conf)
1717{
1718#ifdef CONFIG_SAE_PK
1719 struct sae_password_entry *pw;
1720
1721 for (pw = conf->sae_passwords; pw; pw = pw->next) {
1722 if (pw->pk)
1723 return true;
1724 }
1725#endif /* CONFIG_SAE_PK */
1726
1727 return false;
1728}
1729
1730
1731#ifdef CONFIG_SAE_PK
1732bool hostapd_sae_pk_exclusively(struct hostapd_bss_config *conf)
1733{
1734 bool with_pk = false;
1735 struct sae_password_entry *pw;
1736
1737 if (conf->ssid.wpa_passphrase)
1738 return false;
1739
1740 for (pw = conf->sae_passwords; pw; pw = pw->next) {
1741 if (!pw->pk)
1742 return false;
1743 with_pk = true;
1744 }
1745
1746 return with_pk;
1747}
1748#endif /* CONFIG_SAE_PK */
Sunil Ravia04bd252022-05-02 22:54:18 -07001749
1750
1751int hostapd_acl_comp(const void *a, const void *b)
1752{
1753 const struct mac_acl_entry *aa = a;
1754 const struct mac_acl_entry *bb = b;
1755 return os_memcmp(aa->addr, bb->addr, sizeof(macaddr));
1756}
1757
1758
1759int hostapd_add_acl_maclist(struct mac_acl_entry **acl, int *num,
1760 int vlan_id, const u8 *addr)
1761{
1762 struct mac_acl_entry *newacl;
1763
1764 newacl = os_realloc_array(*acl, *num + 1, sizeof(**acl));
1765 if (!newacl) {
1766 wpa_printf(MSG_ERROR, "MAC list reallocation failed");
1767 return -1;
1768 }
1769
1770 *acl = newacl;
1771 os_memcpy((*acl)[*num].addr, addr, ETH_ALEN);
1772 os_memset(&(*acl)[*num].vlan_id, 0, sizeof((*acl)[*num].vlan_id));
1773 (*acl)[*num].vlan_id.untagged = vlan_id;
1774 (*acl)[*num].vlan_id.notempty = !!vlan_id;
1775 (*num)++;
1776
1777 return 0;
1778}
1779
1780
1781void hostapd_remove_acl_mac(struct mac_acl_entry **acl, int *num,
1782 const u8 *addr)
1783{
1784 int i = 0;
1785
1786 while (i < *num) {
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001787 if (ether_addr_equal((*acl)[i].addr, addr)) {
Sunil Ravia04bd252022-05-02 22:54:18 -07001788 os_remove_in_array(*acl, *num, sizeof(**acl), i);
1789 (*num)--;
1790 } else {
1791 i++;
1792 }
1793 }
1794}