blob: a5a821b4372666e289712401f379b63af090ca79 [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;
496
Sunil Ravi77d572f2023-01-17 23:58:31 +0000497 if ((conf->sae_pwe == SAE_PWE_HUNT_AND_PECK &&
498 !hostapd_sae_pw_id_in_use(conf) &&
Sunil Ravi7f769292024-07-23 22:21:32 +0000499 !wpa_key_mgmt_sae_ext_key(conf->wpa_key_mgmt |
500 conf->rsn_override_key_mgmt |
501 conf->rsn_override_key_mgmt_2) &&
Hai Shalom899fcc72020-10-19 14:38:18 -0700502 !hostapd_sae_pk_in_use(conf)) ||
Sunil Ravi77d572f2023-01-17 23:58:31 +0000503 conf->sae_pwe == SAE_PWE_FORCE_HUNT_AND_PECK ||
Sunil Ravi7f769292024-07-23 22:21:32 +0000504 !wpa_key_mgmt_sae(conf->wpa_key_mgmt |
505 conf->rsn_override_key_mgmt |
506 conf->rsn_override_key_mgmt_2))
Hai Shalomc3565922019-10-28 11:58:20 -0700507 return 0; /* PT not needed */
508
509 sae_deinit_pt(ssid->pt);
510 ssid->pt = NULL;
511 if (ssid->wpa_passphrase) {
512 ssid->pt = sae_derive_pt(conf->sae_groups, ssid->ssid,
513 ssid->ssid_len,
514 (const u8 *) ssid->wpa_passphrase,
515 os_strlen(ssid->wpa_passphrase),
516 NULL);
517 if (!ssid->pt)
518 return -1;
519 }
520
521 for (pw = conf->sae_passwords; pw; pw = pw->next) {
522 sae_deinit_pt(pw->pt);
523 pw->pt = sae_derive_pt(conf->sae_groups, ssid->ssid,
524 ssid->ssid_len,
525 (const u8 *) pw->password,
526 os_strlen(pw->password),
527 pw->identifier);
528 if (!pw->pt)
529 return -1;
530 }
531#endif /* CONFIG_SAE */
532
533 return 0;
534}
535
536
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700537int hostapd_setup_wpa_psk(struct hostapd_bss_config *conf)
538{
539 struct hostapd_ssid *ssid = &conf->ssid;
540
Hai Shalomc3565922019-10-28 11:58:20 -0700541 if (hostapd_setup_sae_pt(conf) < 0)
542 return -1;
543
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700544 if (ssid->wpa_passphrase != NULL) {
545 if (ssid->wpa_psk != NULL) {
546 wpa_printf(MSG_DEBUG, "Using pre-configured WPA PSK "
547 "instead of passphrase");
548 } else {
549 wpa_printf(MSG_DEBUG, "Deriving WPA PSK based on "
550 "passphrase");
551 if (hostapd_derive_psk(ssid) < 0)
552 return -1;
553 }
554 ssid->wpa_psk->group = 1;
555 }
556
Dmitry Shmidt29333592017-01-09 12:27:11 -0800557 return hostapd_config_read_wpa_psk(ssid->wpa_psk_file, &conf->ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700558}
559
560
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700561static void hostapd_config_free_radius(struct hostapd_radius_server *servers,
562 int num_servers)
563{
564 int i;
565
566 for (i = 0; i < num_servers; i++) {
567 os_free(servers[i].shared_secret);
Sunil Ravi99c035e2024-07-12 01:42:03 +0000568 os_free(servers[i].ca_cert);
569 os_free(servers[i].client_cert);
570 os_free(servers[i].private_key);
571 os_free(servers[i].private_key_passwd);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700572 }
573 os_free(servers);
574}
575
576
Dmitry Shmidt04949592012-07-19 12:16:46 -0700577struct hostapd_radius_attr *
578hostapd_config_get_radius_attr(struct hostapd_radius_attr *attr, u8 type)
579{
580 for (; attr; attr = attr->next) {
581 if (attr->type == type)
582 return attr;
583 }
584 return NULL;
585}
586
587
Hai Shalomc3565922019-10-28 11:58:20 -0700588struct hostapd_radius_attr * hostapd_parse_radius_attr(const char *value)
589{
590 const char *pos;
591 char syntax;
592 struct hostapd_radius_attr *attr;
593 size_t len;
594
595 attr = os_zalloc(sizeof(*attr));
596 if (!attr)
597 return NULL;
598
599 attr->type = atoi(value);
600
601 pos = os_strchr(value, ':');
602 if (!pos) {
603 attr->val = wpabuf_alloc(1);
604 if (!attr->val) {
605 os_free(attr);
606 return NULL;
607 }
608 wpabuf_put_u8(attr->val, 0);
609 return attr;
610 }
611
612 pos++;
613 if (pos[0] == '\0' || pos[1] != ':') {
614 os_free(attr);
615 return NULL;
616 }
617 syntax = *pos++;
618 pos++;
619
620 switch (syntax) {
621 case 's':
622 attr->val = wpabuf_alloc_copy(pos, os_strlen(pos));
623 break;
624 case 'x':
625 len = os_strlen(pos);
626 if (len & 1)
627 break;
628 len /= 2;
629 attr->val = wpabuf_alloc(len);
630 if (!attr->val)
631 break;
632 if (hexstr2bin(pos, wpabuf_put(attr->val, len), len) < 0) {
633 wpabuf_free(attr->val);
634 os_free(attr);
635 return NULL;
636 }
637 break;
638 case 'd':
639 attr->val = wpabuf_alloc(4);
640 if (attr->val)
641 wpabuf_put_be32(attr->val, atoi(pos));
642 break;
643 default:
644 os_free(attr);
645 return NULL;
646 }
647
648 if (!attr->val) {
649 os_free(attr);
650 return NULL;
651 }
652
653 return attr;
654}
655
656
657void hostapd_config_free_radius_attr(struct hostapd_radius_attr *attr)
Dmitry Shmidt04949592012-07-19 12:16:46 -0700658{
659 struct hostapd_radius_attr *prev;
660
661 while (attr) {
662 prev = attr;
663 attr = attr->next;
664 wpabuf_free(prev->val);
665 os_free(prev);
666 }
667}
668
669
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700670void hostapd_config_free_eap_user(struct hostapd_eap_user *user)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700671{
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700672 hostapd_config_free_radius_attr(user->accept_attr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700673 os_free(user->identity);
Dmitry Shmidtc2817022014-07-02 10:32:10 -0700674 bin_clear_free(user->password, user->password_len);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700675 bin_clear_free(user->salt, user->salt_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700676 os_free(user);
677}
678
679
Dmitry Shmidt29333592017-01-09 12:27:11 -0800680void hostapd_config_free_eap_users(struct hostapd_eap_user *user)
681{
682 struct hostapd_eap_user *prev_user;
683
684 while (user) {
685 prev_user = user;
686 user = user->next;
687 hostapd_config_free_eap_user(prev_user);
688 }
689}
690
691
Hai Shalomfdcde762020-04-02 11:19:20 -0700692#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700693static void hostapd_config_free_wep(struct hostapd_wep_keys *keys)
694{
695 int i;
696 for (i = 0; i < NUM_WEP_KEYS; i++) {
Dmitry Shmidtc2817022014-07-02 10:32:10 -0700697 bin_clear_free(keys->key[i], keys->len[i]);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700698 keys->key[i] = NULL;
699 }
700}
Hai Shalomfdcde762020-04-02 11:19:20 -0700701#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700702
703
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800704void hostapd_config_clear_wpa_psk(struct hostapd_wpa_psk **l)
705{
706 struct hostapd_wpa_psk *psk, *tmp;
707
708 for (psk = *l; psk;) {
709 tmp = psk;
710 psk = psk->next;
711 bin_clear_free(tmp, sizeof(*tmp));
712 }
713 *l = NULL;
714}
715
716
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000717#ifdef CONFIG_IEEE80211R_AP
718
719void hostapd_config_clear_rxkhs(struct hostapd_bss_config *conf)
720{
721 struct ft_remote_r0kh *r0kh, *r0kh_prev;
722 struct ft_remote_r1kh *r1kh, *r1kh_prev;
723
724 r0kh = conf->r0kh_list;
725 conf->r0kh_list = NULL;
726 while (r0kh) {
727 r0kh_prev = r0kh;
728 r0kh = r0kh->next;
729 os_free(r0kh_prev);
730 }
731
732 r1kh = conf->r1kh_list;
733 conf->r1kh_list = NULL;
734 while (r1kh) {
735 r1kh_prev = r1kh;
736 r1kh = r1kh->next;
737 os_free(r1kh_prev);
738 }
739}
740
741#endif /* CONFIG_IEEE80211R_AP */
742
743
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800744static void hostapd_config_free_anqp_elem(struct hostapd_bss_config *conf)
745{
746 struct anqp_element *elem;
747
748 while ((elem = dl_list_first(&conf->anqp_elem, struct anqp_element,
749 list))) {
750 dl_list_del(&elem->list);
751 wpabuf_free(elem->payload);
752 os_free(elem);
753 }
754}
755
756
Dmitry Shmidt29333592017-01-09 12:27:11 -0800757static void hostapd_config_free_fils_realms(struct hostapd_bss_config *conf)
758{
759#ifdef CONFIG_FILS
760 struct fils_realm *realm;
761
762 while ((realm = dl_list_first(&conf->fils_realms, struct fils_realm,
763 list))) {
764 dl_list_del(&realm->list);
765 os_free(realm);
766 }
767#endif /* CONFIG_FILS */
768}
769
770
Roshan Pius3a1667e2018-07-03 15:17:14 -0700771static void hostapd_config_free_sae_passwords(struct hostapd_bss_config *conf)
772{
773 struct sae_password_entry *pw, *tmp;
774
775 pw = conf->sae_passwords;
776 conf->sae_passwords = NULL;
777 while (pw) {
778 tmp = pw;
779 pw = pw->next;
780 str_clear_free(tmp->password);
781 os_free(tmp->identifier);
Hai Shalomc3565922019-10-28 11:58:20 -0700782#ifdef CONFIG_SAE
783 sae_deinit_pt(tmp->pt);
784#endif /* CONFIG_SAE */
Hai Shalom899fcc72020-10-19 14:38:18 -0700785#ifdef CONFIG_SAE_PK
786 sae_deinit_pk(tmp->pk);
787#endif /* CONFIG_SAE_PK */
Roshan Pius3a1667e2018-07-03 15:17:14 -0700788 os_free(tmp);
789 }
790}
791
792
Hai Shalom81f62d82019-07-22 12:10:00 -0700793#ifdef CONFIG_DPP2
794static void hostapd_dpp_controller_conf_free(struct dpp_controller_conf *conf)
795{
796 struct dpp_controller_conf *prev;
797
798 while (conf) {
799 prev = conf;
800 conf = conf->next;
801 os_free(prev);
802 }
803}
804#endif /* CONFIG_DPP2 */
805
806
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800807void hostapd_config_free_bss(struct hostapd_bss_config *conf)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700808{
Hai Shalom81f62d82019-07-22 12:10:00 -0700809#if defined(CONFIG_WPS) || defined(CONFIG_HS20)
810 size_t i;
811#endif
812
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700813 if (conf == NULL)
814 return;
815
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800816 hostapd_config_clear_wpa_psk(&conf->ssid.wpa_psk);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700817
Dmitry Shmidtc2817022014-07-02 10:32:10 -0700818 str_clear_free(conf->ssid.wpa_passphrase);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700819 os_free(conf->ssid.wpa_psk_file);
Hai Shalomfdcde762020-04-02 11:19:20 -0700820#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700821 hostapd_config_free_wep(&conf->ssid.wep);
Hai Shalomfdcde762020-04-02 11:19:20 -0700822#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700823#ifdef CONFIG_FULL_DYNAMIC_VLAN
824 os_free(conf->ssid.vlan_tagged_interface);
825#endif /* CONFIG_FULL_DYNAMIC_VLAN */
Hai Shalomc3565922019-10-28 11:58:20 -0700826#ifdef CONFIG_SAE
827 sae_deinit_pt(conf->ssid.pt);
828#endif /* CONFIG_SAE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700829
Dmitry Shmidt29333592017-01-09 12:27:11 -0800830 hostapd_config_free_eap_users(conf->eap_user);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800831 os_free(conf->eap_user_sqlite);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700832
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700833 os_free(conf->eap_req_id_text);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800834 os_free(conf->erp_domain);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700835 os_free(conf->accept_mac);
836 os_free(conf->deny_mac);
837 os_free(conf->nas_identifier);
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800838 if (conf->radius) {
839 hostapd_config_free_radius(conf->radius->auth_servers,
840 conf->radius->num_auth_servers);
841 hostapd_config_free_radius(conf->radius->acct_servers,
842 conf->radius->num_acct_servers);
Hai Shaloma20dcd72022-02-04 13:43:00 -0800843 os_free(conf->radius->force_client_dev);
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800844 }
Dmitry Shmidt04949592012-07-19 12:16:46 -0700845 hostapd_config_free_radius_attr(conf->radius_auth_req_attr);
846 hostapd_config_free_radius_attr(conf->radius_acct_req_attr);
Hai Shalomc3565922019-10-28 11:58:20 -0700847 os_free(conf->radius_req_attr_sqlite);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700848 os_free(conf->rsn_preauth_interfaces);
849 os_free(conf->ctrl_interface);
Sunil Ravi77d572f2023-01-17 23:58:31 +0000850 os_free(conf->config_id);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700851 os_free(conf->ca_cert);
852 os_free(conf->server_cert);
Hai Shalom81f62d82019-07-22 12:10:00 -0700853 os_free(conf->server_cert2);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700854 os_free(conf->private_key);
Hai Shalom81f62d82019-07-22 12:10:00 -0700855 os_free(conf->private_key2);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700856 os_free(conf->private_key_passwd);
Hai Shalom81f62d82019-07-22 12:10:00 -0700857 os_free(conf->private_key_passwd2);
Hai Shalom021b0b52019-04-10 11:17:58 -0700858 os_free(conf->check_cert_subject);
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700859 os_free(conf->ocsp_stapling_response);
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -0800860 os_free(conf->ocsp_stapling_response_multi);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700861 os_free(conf->dh_file);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800862 os_free(conf->openssl_ciphers);
Hai Shalom74f70d42019-02-11 14:42:39 -0800863 os_free(conf->openssl_ecdh_curves);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700864 os_free(conf->pac_opaque_encr_key);
865 os_free(conf->eap_fast_a_id);
866 os_free(conf->eap_fast_a_id_info);
867 os_free(conf->eap_sim_db);
Sunil Ravia04bd252022-05-02 22:54:18 -0700868 os_free(conf->imsi_privacy_key);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700869 os_free(conf->radius_server_clients);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700870 os_free(conf->radius);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700871 os_free(conf->radius_das_shared_secret);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700872 hostapd_config_free_vlan(conf);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800873 os_free(conf->time_zone);
874
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800875#ifdef CONFIG_IEEE80211R_AP
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000876 hostapd_config_clear_rxkhs(conf);
877 os_free(conf->rxkh_file);
878 conf->rxkh_file = NULL;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800879#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700880
881#ifdef CONFIG_WPS
882 os_free(conf->wps_pin_requests);
883 os_free(conf->device_name);
884 os_free(conf->manufacturer);
885 os_free(conf->model_name);
886 os_free(conf->model_number);
887 os_free(conf->serial_number);
888 os_free(conf->config_methods);
889 os_free(conf->ap_pin);
890 os_free(conf->extra_cred);
891 os_free(conf->ap_settings);
Hai Shalom021b0b52019-04-10 11:17:58 -0700892 hostapd_config_clear_wpa_psk(&conf->multi_ap_backhaul_ssid.wpa_psk);
893 str_clear_free(conf->multi_ap_backhaul_ssid.wpa_passphrase);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700894 os_free(conf->upnp_iface);
895 os_free(conf->friendly_name);
896 os_free(conf->manufacturer_url);
897 os_free(conf->model_description);
898 os_free(conf->model_url);
899 os_free(conf->upc);
Hai Shalom81f62d82019-07-22 12:10:00 -0700900 for (i = 0; i < MAX_WPS_VENDOR_EXTENSIONS; i++)
901 wpabuf_free(conf->wps_vendor_ext[i]);
Hai Shalomfdcde762020-04-02 11:19:20 -0700902 wpabuf_free(conf->wps_application_ext);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700903 wpabuf_free(conf->wps_nfc_dh_pubkey);
904 wpabuf_free(conf->wps_nfc_dh_privkey);
905 wpabuf_free(conf->wps_nfc_dev_pw);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700906#endif /* CONFIG_WPS */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800907
908 os_free(conf->roaming_consortium);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700909 os_free(conf->venue_name);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700910 os_free(conf->venue_url);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700911 os_free(conf->nai_realm_data);
912 os_free(conf->network_auth_type);
913 os_free(conf->anqp_3gpp_cell_net);
914 os_free(conf->domain_name);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800915 hostapd_config_free_anqp_elem(conf);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800916
917#ifdef CONFIG_RADIUS_TEST
918 os_free(conf->dump_msk_file);
919#endif /* CONFIG_RADIUS_TEST */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700920
921#ifdef CONFIG_HS20
922 os_free(conf->hs20_oper_friendly_name);
923 os_free(conf->hs20_wan_metrics);
924 os_free(conf->hs20_connection_capability);
925 os_free(conf->hs20_operating_class);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800926 os_free(conf->hs20_icons);
927 if (conf->hs20_osu_providers) {
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800928 for (i = 0; i < conf->hs20_osu_providers_count; i++) {
929 struct hs20_osu_provider *p;
930 size_t j;
931 p = &conf->hs20_osu_providers[i];
932 os_free(p->friendly_name);
933 os_free(p->server_uri);
934 os_free(p->method_list);
935 for (j = 0; j < p->icons_count; j++)
936 os_free(p->icons[j]);
937 os_free(p->icons);
938 os_free(p->osu_nai);
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800939 os_free(p->osu_nai2);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800940 os_free(p->service_desc);
941 }
942 os_free(conf->hs20_osu_providers);
943 }
Roshan Pius3a1667e2018-07-03 15:17:14 -0700944 if (conf->hs20_operator_icon) {
Roshan Pius3a1667e2018-07-03 15:17:14 -0700945 for (i = 0; i < conf->hs20_operator_icon_count; i++)
946 os_free(conf->hs20_operator_icon[i]);
947 os_free(conf->hs20_operator_icon);
948 }
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800949 os_free(conf->subscr_remediation_url);
Hai Shalom74f70d42019-02-11 14:42:39 -0800950 os_free(conf->hs20_sim_provisioning_url);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700951 os_free(conf->t_c_filename);
952 os_free(conf->t_c_server_url);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700953#endif /* CONFIG_HS20 */
954
955 wpabuf_free(conf->vendor_elements);
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700956 wpabuf_free(conf->assocresp_elements);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800957
958 os_free(conf->sae_groups);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700959#ifdef CONFIG_OWE
960 os_free(conf->owe_groups);
961#endif /* CONFIG_OWE */
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700962
Dmitry Shmidt0207e232014-09-03 14:58:37 -0700963 os_free(conf->wowlan_triggers);
964
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700965 os_free(conf->server_id);
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800966
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800967#ifdef CONFIG_TESTING_OPTIONS
968 wpabuf_free(conf->own_ie_override);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700969 wpabuf_free(conf->sae_commit_override);
Hai Shalomfdcde762020-04-02 11:19:20 -0700970 wpabuf_free(conf->rsne_override_eapol);
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800971 wpabuf_free(conf->rsnxe_override_eapol);
Hai Shalomfdcde762020-04-02 11:19:20 -0700972 wpabuf_free(conf->rsne_override_ft);
973 wpabuf_free(conf->rsnxe_override_ft);
974 wpabuf_free(conf->gtk_rsc_override);
975 wpabuf_free(conf->igtk_rsc_override);
Sunil Ravib0ac25f2024-07-12 01:42:03 +0000976 wpabuf_free(conf->eapol_m1_elements);
977 wpabuf_free(conf->eapol_m3_elements);
Sunil Ravi7f769292024-07-23 22:21:32 +0000978 wpabuf_free(conf->presp_elements);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800979#endif /* CONFIG_TESTING_OPTIONS */
980
981 os_free(conf->no_probe_resp_if_seen_on);
982 os_free(conf->no_auth_if_seen_on);
983
Dmitry Shmidt29333592017-01-09 12:27:11 -0800984 hostapd_config_free_fils_realms(conf);
985
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700986#ifdef CONFIG_DPP
Hai Shalomc3565922019-10-28 11:58:20 -0700987 os_free(conf->dpp_name);
988 os_free(conf->dpp_mud_url);
Sunil Ravi89eba102022-09-13 21:04:37 -0700989 os_free(conf->dpp_extra_conf_req_name);
990 os_free(conf->dpp_extra_conf_req_value);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700991 os_free(conf->dpp_connector);
992 wpabuf_free(conf->dpp_netaccesskey);
993 wpabuf_free(conf->dpp_csign);
Hai Shalom81f62d82019-07-22 12:10:00 -0700994#ifdef CONFIG_DPP2
995 hostapd_dpp_controller_conf_free(conf->dpp_controller);
996#endif /* CONFIG_DPP2 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700997#endif /* CONFIG_DPP */
998
Roshan Pius3a1667e2018-07-03 15:17:14 -0700999 hostapd_config_free_sae_passwords(conf);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001000
Hai Shalom81f62d82019-07-22 12:10:00 -07001001#ifdef CONFIG_AIRTIME_POLICY
1002 {
1003 struct airtime_sta_weight *wt, *wt_prev;
1004
1005 wt = conf->airtime_weight_list;
1006 conf->airtime_weight_list = NULL;
1007 while (wt) {
1008 wt_prev = wt;
1009 wt = wt->next;
1010 os_free(wt_prev);
1011 }
1012 }
1013#endif /* CONFIG_AIRTIME_POLICY */
1014
Hai Shalom60840252021-02-19 19:02:11 -08001015#ifdef CONFIG_PASN
1016 os_free(conf->pasn_groups);
1017#endif /* CONFIG_PASN */
1018
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001019 os_free(conf);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001020}
1021
1022
1023/**
1024 * hostapd_config_free - Free hostapd configuration
1025 * @conf: Configuration data from hostapd_config_read().
1026 */
1027void hostapd_config_free(struct hostapd_config *conf)
1028{
1029 size_t i;
1030
1031 if (conf == NULL)
1032 return;
1033
1034 for (i = 0; i < conf->num_bss; i++)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001035 hostapd_config_free_bss(conf->bss[i]);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001036 os_free(conf->bss);
1037 os_free(conf->supported_rates);
1038 os_free(conf->basic_rates);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07001039 os_free(conf->acs_ch_list.range);
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001040 os_free(conf->acs_freq_list.range);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001041 os_free(conf->driver_params);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001042#ifdef CONFIG_ACS
1043 os_free(conf->acs_chan_bias);
1044#endif /* CONFIG_ACS */
Dmitry Shmidt849734c2016-05-27 09:59:01 -07001045 wpabuf_free(conf->lci);
1046 wpabuf_free(conf->civic);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001047
1048 os_free(conf);
1049}
1050
1051
1052/**
1053 * hostapd_maclist_found - Find a MAC address from a list
1054 * @list: MAC address list
1055 * @num_entries: Number of addresses in the list
1056 * @addr: Address to search for
1057 * @vlan_id: Buffer for returning VLAN ID or %NULL if not needed
1058 * Returns: 1 if address is in the list or 0 if not.
1059 *
1060 * Perform a binary search for given MAC address from a pre-sorted list.
1061 */
1062int hostapd_maclist_found(struct mac_acl_entry *list, int num_entries,
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001063 const u8 *addr, struct vlan_description *vlan_id)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001064{
1065 int start, end, middle, res;
1066
1067 start = 0;
1068 end = num_entries - 1;
1069
1070 while (start <= end) {
1071 middle = (start + end) / 2;
1072 res = os_memcmp(list[middle].addr, addr, ETH_ALEN);
1073 if (res == 0) {
1074 if (vlan_id)
1075 *vlan_id = list[middle].vlan_id;
1076 return 1;
1077 }
1078 if (res < 0)
1079 start = middle + 1;
1080 else
1081 end = middle - 1;
1082 }
1083
1084 return 0;
1085}
1086
1087
1088int hostapd_rate_found(int *list, int rate)
1089{
1090 int i;
1091
1092 if (list == NULL)
1093 return 0;
1094
1095 for (i = 0; list[i] >= 0; i++)
1096 if (list[i] == rate)
1097 return 1;
1098
1099 return 0;
1100}
1101
1102
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001103int hostapd_vlan_valid(struct hostapd_vlan *vlan,
1104 struct vlan_description *vlan_desc)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001105{
1106 struct hostapd_vlan *v = vlan;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001107 int i;
1108
1109 if (!vlan_desc->notempty || vlan_desc->untagged < 0 ||
1110 vlan_desc->untagged > MAX_VLAN_ID)
1111 return 0;
1112 for (i = 0; i < MAX_NUM_TAGGED_VLAN; i++) {
1113 if (vlan_desc->tagged[i] < 0 ||
1114 vlan_desc->tagged[i] > MAX_VLAN_ID)
1115 return 0;
1116 }
1117 if (!vlan_desc->untagged && !vlan_desc->tagged[0])
1118 return 0;
1119
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001120 while (v) {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001121 if (!vlan_compare(&v->vlan_desc, vlan_desc) ||
1122 v->vlan_id == VLAN_ID_WILDCARD)
Dmitry Shmidt34af3062013-07-11 10:46:32 -07001123 return 1;
1124 v = v->next;
1125 }
1126 return 0;
1127}
1128
1129
1130const char * hostapd_get_vlan_id_ifname(struct hostapd_vlan *vlan, int vlan_id)
1131{
1132 struct hostapd_vlan *v = vlan;
1133 while (v) {
1134 if (v->vlan_id == vlan_id)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001135 return v->ifname;
1136 v = v->next;
1137 }
1138 return NULL;
1139}
1140
1141
1142const u8 * hostapd_get_psk(const struct hostapd_bss_config *conf,
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001143 const u8 *addr, const u8 *p2p_dev_addr,
Hai Shalom021b0b52019-04-10 11:17:58 -07001144 const u8 *prev_psk, int *vlan_id)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001145{
1146 struct hostapd_wpa_psk *psk;
1147 int next_ok = prev_psk == NULL;
1148
Hai Shalom021b0b52019-04-10 11:17:58 -07001149 if (vlan_id)
1150 *vlan_id = 0;
1151
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001152 if (p2p_dev_addr && !is_zero_ether_addr(p2p_dev_addr)) {
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001153 wpa_printf(MSG_DEBUG, "Searching a PSK for " MACSTR
1154 " p2p_dev_addr=" MACSTR " prev_psk=%p",
1155 MAC2STR(addr), MAC2STR(p2p_dev_addr), prev_psk);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001156 addr = NULL; /* Use P2P Device Address for matching */
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001157 } else {
1158 wpa_printf(MSG_DEBUG, "Searching a PSK for " MACSTR
1159 " prev_psk=%p",
1160 MAC2STR(addr), prev_psk);
1161 }
1162
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001163 for (psk = conf->ssid.wpa_psk; psk != NULL; psk = psk->next) {
1164 if (next_ok &&
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001165 (psk->group ||
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001166 (addr && ether_addr_equal(psk->addr, addr)) ||
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001167 (!addr && p2p_dev_addr &&
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001168 ether_addr_equal(psk->p2p_dev_addr, p2p_dev_addr)))) {
Hai Shalom021b0b52019-04-10 11:17:58 -07001169 if (vlan_id)
1170 *vlan_id = psk->vlan_id;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001171 return psk->psk;
Hai Shalom021b0b52019-04-10 11:17:58 -07001172 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001173
1174 if (psk->psk == prev_psk)
1175 next_ok = 1;
1176 }
1177
1178 return NULL;
1179}
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001180
1181
Hai Shalom899fcc72020-10-19 14:38:18 -07001182#ifdef CONFIG_SAE_PK
1183static bool hostapd_sae_pk_password_without_pk(struct hostapd_bss_config *bss)
1184{
1185 struct sae_password_entry *pw;
1186 bool res = false;
1187
1188 if (bss->ssid.wpa_passphrase &&
1189#ifdef CONFIG_TESTING_OPTIONS
1190 !bss->sae_pk_password_check_skip &&
1191#endif /* CONFIG_TESTING_OPTIONS */
1192 sae_pk_valid_password(bss->ssid.wpa_passphrase))
1193 res = true;
1194
1195 for (pw = bss->sae_passwords; pw; pw = pw->next) {
1196 if (!pw->pk &&
1197#ifdef CONFIG_TESTING_OPTIONS
1198 !bss->sae_pk_password_check_skip &&
1199#endif /* CONFIG_TESTING_OPTIONS */
1200 sae_pk_valid_password(pw->password))
1201 return true;
1202
1203 if (bss->ssid.wpa_passphrase && res && pw->pk &&
1204 os_strcmp(bss->ssid.wpa_passphrase, pw->password) == 0)
1205 res = false;
1206 }
1207
1208 return res;
1209}
1210#endif /* CONFIG_SAE_PK */
1211
1212
Hai Shalom60840252021-02-19 19:02:11 -08001213static bool hostapd_config_check_bss_6g(struct hostapd_bss_config *bss)
1214{
1215 if (bss->wpa != WPA_PROTO_RSN) {
1216 wpa_printf(MSG_ERROR,
1217 "Pre-RSNA security methods are not allowed in 6 GHz");
1218 return false;
1219 }
1220
1221 if (bss->ieee80211w != MGMT_FRAME_PROTECTION_REQUIRED) {
1222 wpa_printf(MSG_ERROR,
1223 "Management frame protection is required in 6 GHz");
1224 return false;
1225 }
1226
1227 if (bss->wpa_key_mgmt & (WPA_KEY_MGMT_PSK |
1228 WPA_KEY_MGMT_FT_PSK |
1229 WPA_KEY_MGMT_PSK_SHA256)) {
1230 wpa_printf(MSG_ERROR, "Invalid AKM suite for 6 GHz");
1231 return false;
1232 }
1233
1234 if (bss->rsn_pairwise & (WPA_CIPHER_WEP40 |
1235 WPA_CIPHER_WEP104 |
1236 WPA_CIPHER_TKIP)) {
1237 wpa_printf(MSG_ERROR,
1238 "Invalid pairwise cipher suite for 6 GHz");
1239 return false;
1240 }
1241
1242 if (bss->wpa_group & (WPA_CIPHER_WEP40 |
1243 WPA_CIPHER_WEP104 |
1244 WPA_CIPHER_TKIP)) {
1245 wpa_printf(MSG_ERROR, "Invalid group cipher suite for 6 GHz");
1246 return false;
1247 }
1248
Sunil Ravi77d572f2023-01-17 23:58:31 +00001249#ifdef CONFIG_SAE
1250 if (wpa_key_mgmt_sae(bss->wpa_key_mgmt) &&
1251 bss->sae_pwe == SAE_PWE_HUNT_AND_PECK) {
1252 wpa_printf(MSG_INFO, "SAE: Enabling SAE H2E on 6 GHz");
1253 bss->sae_pwe = SAE_PWE_BOTH;
1254 }
1255#endif /* CONFIG_SAE */
1256
Hai Shalom60840252021-02-19 19:02:11 -08001257 return true;
1258}
1259
1260
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001261static int hostapd_config_check_bss(struct hostapd_bss_config *bss,
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001262 struct hostapd_config *conf,
1263 int full_config)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001264{
Hai Shalom60840252021-02-19 19:02:11 -08001265 if (full_config && is_6ghz_op_class(conf->op_class) &&
1266 !hostapd_config_check_bss_6g(bss))
1267 return -1;
1268
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001269 if (full_config && bss->ieee802_1x && !bss->eap_server &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001270 !bss->radius->auth_servers) {
1271 wpa_printf(MSG_ERROR, "Invalid IEEE 802.1X configuration (no "
1272 "EAP authenticator configured).");
1273 return -1;
1274 }
1275
Hai Shalomfdcde762020-04-02 11:19:20 -07001276#ifdef CONFIG_WEP
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001277 if (bss->wpa) {
1278 int wep, i;
1279
1280 wep = bss->default_wep_key_len > 0 ||
1281 bss->individual_wep_key_len > 0;
1282 for (i = 0; i < NUM_WEP_KEYS; i++) {
1283 if (bss->ssid.wep.keys_set) {
1284 wep = 1;
1285 break;
1286 }
1287 }
1288
1289 if (wep) {
1290 wpa_printf(MSG_ERROR, "WEP configuration in a WPA network is not supported");
1291 return -1;
1292 }
1293 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001294#endif /* CONFIG_WEP */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001295
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001296 if (full_config && bss->wpa &&
1297 bss->wpa_psk_radius != PSK_RADIUS_IGNORED &&
Sunil Ravia04bd252022-05-02 22:54:18 -07001298 bss->wpa_psk_radius != PSK_RADIUS_DURING_4WAY_HS &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001299 bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH) {
1300 wpa_printf(MSG_ERROR, "WPA-PSK using RADIUS enabled, but no "
1301 "RADIUS checking (macaddr_acl=2) enabled.");
1302 return -1;
1303 }
1304
Sunil Ravia04bd252022-05-02 22:54:18 -07001305 if (full_config && bss->wpa &&
1306 wpa_key_mgmt_wpa_psk_no_sae(bss->wpa_key_mgmt) &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001307 bss->ssid.wpa_psk == NULL && bss->ssid.wpa_passphrase == NULL &&
1308 bss->ssid.wpa_psk_file == NULL &&
Sunil Ravia04bd252022-05-02 22:54:18 -07001309 bss->wpa_psk_radius != PSK_RADIUS_DURING_4WAY_HS &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001310 (bss->wpa_psk_radius != PSK_RADIUS_REQUIRED ||
1311 bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH)) {
1312 wpa_printf(MSG_ERROR, "WPA-PSK enabled, but PSK or passphrase "
1313 "is not configured.");
1314 return -1;
1315 }
1316
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001317 if (full_config && !is_zero_ether_addr(bss->bssid)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001318 size_t i;
1319
1320 for (i = 0; i < conf->num_bss; i++) {
1321 if (conf->bss[i] != bss &&
1322 (hostapd_mac_comp(conf->bss[i]->bssid,
1323 bss->bssid) == 0)) {
1324 wpa_printf(MSG_ERROR, "Duplicate BSSID " MACSTR
1325 " on interface '%s' and '%s'.",
1326 MAC2STR(bss->bssid),
1327 conf->bss[i]->iface, bss->iface);
1328 return -1;
1329 }
1330 }
1331 }
1332
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001333#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001334 if (full_config && wpa_key_mgmt_ft(bss->wpa_key_mgmt) &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001335 (bss->nas_identifier == NULL ||
1336 os_strlen(bss->nas_identifier) < 1 ||
1337 os_strlen(bss->nas_identifier) > FT_R0KH_ID_MAX_LEN)) {
1338 wpa_printf(MSG_ERROR, "FT (IEEE 802.11r) requires "
1339 "nas_identifier to be configured as a 1..48 octet "
1340 "string");
1341 return -1;
1342 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001343#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001344
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001345 if (full_config && conf->ieee80211n &&
1346 conf->hw_mode == HOSTAPD_MODE_IEEE80211B) {
Hai Shalom60840252021-02-19 19:02:11 -08001347 bss->disable_11n = true;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001348 wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) in 11b mode is not "
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001349 "allowed, disabling HT capabilities");
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001350 }
1351
Hai Shalomfdcde762020-04-02 11:19:20 -07001352#ifdef CONFIG_WEP
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001353 if (full_config && conf->ieee80211n &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001354 bss->ssid.security_policy == SECURITY_STATIC_WEP) {
Hai Shalom60840252021-02-19 19:02:11 -08001355 bss->disable_11n = true;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001356 wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) with WEP is not "
1357 "allowed, disabling HT capabilities");
1358 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001359#endif /* CONFIG_WEP */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001360
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001361 if (full_config && conf->ieee80211n && bss->wpa &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001362 !(bss->wpa_pairwise & WPA_CIPHER_CCMP) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001363 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
1364 WPA_CIPHER_CCMP_256 | WPA_CIPHER_GCMP_256)))
1365 {
Hai Shalom60840252021-02-19 19:02:11 -08001366 bss->disable_11n = true;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001367 wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) with WPA/WPA2 "
1368 "requires CCMP/GCMP to be enabled, disabling HT "
1369 "capabilities");
1370 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001371
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07001372#ifdef CONFIG_IEEE80211AC
Hai Shalomfdcde762020-04-02 11:19:20 -07001373#ifdef CONFIG_WEP
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07001374 if (full_config && conf->ieee80211ac &&
1375 bss->ssid.security_policy == SECURITY_STATIC_WEP) {
Hai Shalom60840252021-02-19 19:02:11 -08001376 bss->disable_11ac = true;
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07001377 wpa_printf(MSG_ERROR,
1378 "VHT (IEEE 802.11ac) with WEP is not allowed, disabling VHT capabilities");
1379 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001380#endif /* CONFIG_WEP */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001381
1382 if (full_config && conf->ieee80211ac && bss->wpa &&
1383 !(bss->wpa_pairwise & WPA_CIPHER_CCMP) &&
1384 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
1385 WPA_CIPHER_CCMP_256 | WPA_CIPHER_GCMP_256)))
1386 {
Hai Shalom60840252021-02-19 19:02:11 -08001387 bss->disable_11ac = true;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001388 wpa_printf(MSG_ERROR,
1389 "VHT (IEEE 802.11ac) with WPA/WPA2 requires CCMP/GCMP to be enabled, disabling VHT capabilities");
1390 }
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07001391#endif /* CONFIG_IEEE80211AC */
1392
Hai Shalom60840252021-02-19 19:02:11 -08001393#ifdef CONFIG_IEEE80211AX
1394#ifdef CONFIG_WEP
1395 if (full_config && conf->ieee80211ax &&
1396 bss->ssid.security_policy == SECURITY_STATIC_WEP) {
1397 bss->disable_11ax = true;
1398 wpa_printf(MSG_ERROR,
1399 "HE (IEEE 802.11ax) with WEP is not allowed, disabling HE capabilities");
1400 }
1401#endif /* CONFIG_WEP */
1402
1403 if (full_config && conf->ieee80211ax && bss->wpa &&
1404 !(bss->wpa_pairwise & WPA_CIPHER_CCMP) &&
1405 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
1406 WPA_CIPHER_CCMP_256 | WPA_CIPHER_GCMP_256)))
1407 {
1408 bss->disable_11ax = true;
1409 wpa_printf(MSG_ERROR,
1410 "HE (IEEE 802.11ax) with WPA/WPA2 requires CCMP/GCMP to be enabled, disabling HE capabilities");
1411 }
1412#endif /* CONFIG_IEEE80211AX */
1413
Dmitry Shmidt15907092014-03-25 10:42:57 -07001414#ifdef CONFIG_WPS
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001415 if (full_config && bss->wps_state && bss->ignore_broadcast_ssid) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001416 wpa_printf(MSG_INFO, "WPS: ignore_broadcast_ssid "
1417 "configuration forced WPS to be disabled");
1418 bss->wps_state = 0;
1419 }
1420
Hai Shalomfdcde762020-04-02 11:19:20 -07001421#ifdef CONFIG_WEP
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001422 if (full_config && bss->wps_state &&
1423 bss->ssid.wep.keys_set && bss->wpa == 0) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001424 wpa_printf(MSG_INFO, "WPS: WEP configuration forced WPS to be "
1425 "disabled");
1426 bss->wps_state = 0;
1427 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001428#endif /* CONFIG_WEP */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001429
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001430 if (full_config && bss->wps_state && bss->wpa &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001431 (!(bss->wpa & 2) ||
Roshan Pius3a1667e2018-07-03 15:17:14 -07001432 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
1433 WPA_CIPHER_CCMP_256 |
1434 WPA_CIPHER_GCMP_256)))) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001435 wpa_printf(MSG_INFO, "WPS: WPA/TKIP configuration without "
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07001436 "WPA2/CCMP/GCMP forced WPS to be disabled");
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001437 bss->wps_state = 0;
1438 }
Dmitry Shmidt15907092014-03-25 10:42:57 -07001439#endif /* CONFIG_WPS */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001440
1441#ifdef CONFIG_HS20
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001442 if (full_config && bss->hs20 &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001443 (!(bss->wpa & 2) ||
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001444 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
1445 WPA_CIPHER_CCMP_256 |
1446 WPA_CIPHER_GCMP_256)))) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001447 wpa_printf(MSG_ERROR, "HS 2.0: WPA2-Enterprise/CCMP "
1448 "configuration is required for Hotspot 2.0 "
1449 "functionality");
1450 return -1;
1451 }
1452#endif /* CONFIG_HS20 */
1453
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001454#ifdef CONFIG_MBO
1455 if (full_config && bss->mbo_enabled && (bss->wpa & 2) &&
1456 bss->ieee80211w == NO_MGMT_FRAME_PROTECTION) {
1457 wpa_printf(MSG_ERROR,
1458 "MBO: PMF needs to be enabled whenever using WPA2 with MBO");
1459 return -1;
1460 }
1461#endif /* CONFIG_MBO */
1462
Hai Shalom74f70d42019-02-11 14:42:39 -08001463#ifdef CONFIG_OCV
1464 if (full_config && bss->ieee80211w == NO_MGMT_FRAME_PROTECTION &&
1465 bss->ocv) {
1466 wpa_printf(MSG_ERROR,
1467 "OCV: PMF needs to be enabled whenever using OCV");
1468 return -1;
1469 }
1470#endif /* CONFIG_OCV */
1471
Hai Shalom899fcc72020-10-19 14:38:18 -07001472#ifdef CONFIG_SAE_PK
1473 if (full_config && hostapd_sae_pk_in_use(bss) &&
1474 hostapd_sae_pk_password_without_pk(bss)) {
1475 wpa_printf(MSG_ERROR,
1476 "SAE-PK: SAE password uses SAE-PK style, but does not have PK configured");
1477 return -1;
1478 }
1479#endif /* CONFIG_SAE_PK */
1480
Hai Shaloma20dcd72022-02-04 13:43:00 -08001481#ifdef CONFIG_FILS
Sunil Ravia04bd252022-05-02 22:54:18 -07001482 if (full_config && bss->fils_discovery_max_int &&
Sunil Ravi036cec52023-03-29 11:35:17 -07001483 (!conf->ieee80211ax || bss->disable_11ax)) {
1484 wpa_printf(MSG_ERROR,
1485 "Currently IEEE 802.11ax support is mandatory to enable FILS discovery transmission.");
1486 return -1;
1487 }
1488
1489 if (full_config && bss->fils_discovery_max_int &&
Hai Shaloma20dcd72022-02-04 13:43:00 -08001490 bss->unsol_bcast_probe_resp_interval) {
1491 wpa_printf(MSG_ERROR,
1492 "Cannot enable both FILS discovery and unsolicited broadcast Probe Response at the same time");
1493 return -1;
1494 }
1495#endif /* CONFIG_FILS */
1496
Sunil Ravia04bd252022-05-02 22:54:18 -07001497#ifdef CONFIG_IEEE80211BE
1498 if (full_config && !bss->disable_11be && bss->disable_11ax) {
1499 bss->disable_11be = true;
1500 wpa_printf(MSG_INFO,
1501 "Disabling IEEE 802.11be as IEEE 802.11ax is disabled for this BSS");
1502 }
1503#endif /* CONFIG_IEEE80211BE */
1504
Sunil Ravi77d572f2023-01-17 23:58:31 +00001505 if (full_config && bss->ignore_broadcast_ssid && conf->mbssid) {
1506 wpa_printf(MSG_ERROR,
1507 "Hidden SSID is not suppored when MBSSID is enabled");
1508 return -1;
1509 }
1510
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001511 return 0;
1512}
1513
1514
Dmitry Shmidt05df46a2015-05-19 11:02:01 -07001515static int hostapd_config_check_cw(struct hostapd_config *conf, int queue)
1516{
1517 int tx_cwmin = conf->tx_queue[queue].cwmin;
1518 int tx_cwmax = conf->tx_queue[queue].cwmax;
1519 int ac_cwmin = conf->wmm_ac_params[queue].cwmin;
1520 int ac_cwmax = conf->wmm_ac_params[queue].cwmax;
1521
1522 if (tx_cwmin > tx_cwmax) {
1523 wpa_printf(MSG_ERROR,
1524 "Invalid TX queue cwMin/cwMax values. cwMin(%d) greater than cwMax(%d)",
1525 tx_cwmin, tx_cwmax);
1526 return -1;
1527 }
1528 if (ac_cwmin > ac_cwmax) {
1529 wpa_printf(MSG_ERROR,
1530 "Invalid WMM AC cwMin/cwMax values. cwMin(%d) greater than cwMax(%d)",
1531 ac_cwmin, ac_cwmax);
1532 return -1;
1533 }
1534 return 0;
1535}
1536
1537
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001538int hostapd_config_check(struct hostapd_config *conf, int full_config)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001539{
1540 size_t i;
1541
Sunil Ravia04bd252022-05-02 22:54:18 -07001542 if (full_config && is_6ghz_op_class(conf->op_class) &&
1543 !conf->hw_mode_set) {
1544 /* Use the appropriate hw_mode value automatically when the
1545 * op_class parameter has been set, but hw_mode was not. */
1546 conf->hw_mode = HOSTAPD_MODE_IEEE80211A;
1547 }
1548
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001549 if (full_config && conf->ieee80211d &&
1550 (!conf->country[0] || !conf->country[1])) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001551 wpa_printf(MSG_ERROR, "Cannot enable IEEE 802.11d without "
1552 "setting the country_code");
1553 return -1;
1554 }
1555
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001556 if (full_config && conf->ieee80211h && !conf->ieee80211d) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001557 wpa_printf(MSG_ERROR, "Cannot enable IEEE 802.11h without "
1558 "IEEE 802.11d enabled");
1559 return -1;
1560 }
1561
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001562 if (full_config && conf->local_pwr_constraint != -1 &&
1563 !conf->ieee80211d) {
1564 wpa_printf(MSG_ERROR, "Cannot add Power Constraint element without Country element");
1565 return -1;
1566 }
1567
1568 if (full_config && conf->spectrum_mgmt_required &&
1569 conf->local_pwr_constraint == -1) {
1570 wpa_printf(MSG_ERROR, "Cannot set Spectrum Management bit without Country and Power Constraint elements");
1571 return -1;
1572 }
1573
Hai Shalom81f62d82019-07-22 12:10:00 -07001574#ifdef CONFIG_AIRTIME_POLICY
1575 if (full_config && conf->airtime_mode > AIRTIME_MODE_STATIC &&
1576 !conf->airtime_update_interval) {
1577 wpa_printf(MSG_ERROR, "Airtime update interval cannot be zero");
1578 return -1;
1579 }
1580#endif /* CONFIG_AIRTIME_POLICY */
Dmitry Shmidt05df46a2015-05-19 11:02:01 -07001581 for (i = 0; i < NUM_TX_QUEUES; i++) {
1582 if (hostapd_config_check_cw(conf, i))
1583 return -1;
1584 }
1585
Sunil Ravia04bd252022-05-02 22:54:18 -07001586#ifdef CONFIG_IEEE80211BE
1587 if (full_config && conf->ieee80211be && !conf->ieee80211ax) {
1588 wpa_printf(MSG_ERROR,
1589 "Cannot set ieee80211be without ieee80211ax");
1590 return -1;
1591 }
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001592
1593 if (full_config)
1594 hostapd_set_and_check_bw320_offset(conf,
1595 conf->eht_bw320_offset);
Sunil Ravia04bd252022-05-02 22:54:18 -07001596#endif /* CONFIG_IEEE80211BE */
1597
Sunil Ravi77d572f2023-01-17 23:58:31 +00001598 if (full_config && conf->mbssid && !conf->ieee80211ax) {
1599 wpa_printf(MSG_ERROR,
1600 "Cannot enable multiple BSSID support without ieee80211ax");
1601 return -1;
1602 }
1603
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001604 for (i = 0; i < conf->num_bss; i++) {
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001605 if (hostapd_config_check_bss(conf->bss[i], conf, full_config))
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001606 return -1;
1607 }
1608
1609 return 0;
1610}
1611
1612
Dmitry Shmidt71757432014-06-02 13:50:35 -07001613void hostapd_set_security_params(struct hostapd_bss_config *bss,
1614 int full_config)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001615{
Hai Shalomfdcde762020-04-02 11:19:20 -07001616#ifdef CONFIG_WEP
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001617 if (bss->individual_wep_key_len == 0) {
1618 /* individual keys are not use; can use key idx0 for
1619 * broadcast keys */
1620 bss->broadcast_key_idx_min = 0;
1621 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001622#endif /* CONFIG_WEP */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001623
1624 if ((bss->wpa & 2) && bss->rsn_pairwise == 0)
1625 bss->rsn_pairwise = bss->wpa_pairwise;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001626 if (bss->group_cipher)
1627 bss->wpa_group = bss->group_cipher;
1628 else
1629 bss->wpa_group = wpa_select_ap_group_cipher(bss->wpa,
1630 bss->wpa_pairwise,
1631 bss->rsn_pairwise);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001632 if (!bss->wpa_group_rekey_set)
1633 bss->wpa_group_rekey = bss->wpa_group == WPA_CIPHER_TKIP ?
1634 600 : 86400;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001635
Dmitry Shmidt71757432014-06-02 13:50:35 -07001636 if (full_config) {
1637 bss->radius->auth_server = bss->radius->auth_servers;
1638 bss->radius->acct_server = bss->radius->acct_servers;
1639 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001640
1641 if (bss->wpa && bss->ieee802_1x) {
1642 bss->ssid.security_policy = SECURITY_WPA;
1643 } else if (bss->wpa) {
1644 bss->ssid.security_policy = SECURITY_WPA_PSK;
1645 } else if (bss->ieee802_1x) {
1646 int cipher = WPA_CIPHER_NONE;
1647 bss->ssid.security_policy = SECURITY_IEEE_802_1X;
Hai Shalomfdcde762020-04-02 11:19:20 -07001648#ifdef CONFIG_WEP
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001649 bss->ssid.wep.default_len = bss->default_wep_key_len;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001650 if (full_config && bss->default_wep_key_len) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001651 cipher = bss->default_wep_key_len >= 13 ?
1652 WPA_CIPHER_WEP104 : WPA_CIPHER_WEP40;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001653 } else if (full_config && bss->ssid.wep.keys_set) {
1654 if (bss->ssid.wep.len[0] >= 13)
1655 cipher = WPA_CIPHER_WEP104;
1656 else
1657 cipher = WPA_CIPHER_WEP40;
1658 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001659#endif /* CONFIG_WEP */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001660 bss->wpa_group = cipher;
1661 bss->wpa_pairwise = cipher;
1662 bss->rsn_pairwise = cipher;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001663 if (full_config)
1664 bss->wpa_key_mgmt = WPA_KEY_MGMT_IEEE8021X_NO_WPA;
Hai Shalomfdcde762020-04-02 11:19:20 -07001665#ifdef CONFIG_WEP
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001666 } else if (bss->ssid.wep.keys_set) {
1667 int cipher = WPA_CIPHER_WEP40;
1668 if (bss->ssid.wep.len[0] >= 13)
1669 cipher = WPA_CIPHER_WEP104;
1670 bss->ssid.security_policy = SECURITY_STATIC_WEP;
1671 bss->wpa_group = cipher;
1672 bss->wpa_pairwise = cipher;
1673 bss->rsn_pairwise = cipher;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001674 if (full_config)
1675 bss->wpa_key_mgmt = WPA_KEY_MGMT_NONE;
Hai Shalomfdcde762020-04-02 11:19:20 -07001676#endif /* CONFIG_WEP */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001677 } else if (bss->osen) {
1678 bss->ssid.security_policy = SECURITY_OSEN;
1679 bss->wpa_group = WPA_CIPHER_CCMP;
1680 bss->wpa_pairwise = 0;
1681 bss->rsn_pairwise = WPA_CIPHER_CCMP;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001682 } else {
1683 bss->ssid.security_policy = SECURITY_PLAINTEXT;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001684 if (full_config) {
1685 bss->wpa_group = WPA_CIPHER_NONE;
1686 bss->wpa_pairwise = WPA_CIPHER_NONE;
1687 bss->rsn_pairwise = WPA_CIPHER_NONE;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001688 bss->wpa_key_mgmt = WPA_KEY_MGMT_NONE;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001689 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001690 }
1691}
Hai Shalom74f70d42019-02-11 14:42:39 -08001692
1693
1694int hostapd_sae_pw_id_in_use(struct hostapd_bss_config *conf)
1695{
1696 int with_id = 0, without_id = 0;
1697 struct sae_password_entry *pw;
1698
1699 if (conf->ssid.wpa_passphrase)
1700 without_id = 1;
1701
1702 for (pw = conf->sae_passwords; pw; pw = pw->next) {
1703 if (pw->identifier)
1704 with_id = 1;
1705 else
1706 without_id = 1;
1707 if (with_id && without_id)
1708 break;
1709 }
1710
1711 if (with_id && !without_id)
1712 return 2;
1713 return with_id;
1714}
Hai Shalom899fcc72020-10-19 14:38:18 -07001715
1716
1717bool hostapd_sae_pk_in_use(struct hostapd_bss_config *conf)
1718{
1719#ifdef CONFIG_SAE_PK
1720 struct sae_password_entry *pw;
1721
1722 for (pw = conf->sae_passwords; pw; pw = pw->next) {
1723 if (pw->pk)
1724 return true;
1725 }
1726#endif /* CONFIG_SAE_PK */
1727
1728 return false;
1729}
1730
1731
1732#ifdef CONFIG_SAE_PK
1733bool hostapd_sae_pk_exclusively(struct hostapd_bss_config *conf)
1734{
1735 bool with_pk = false;
1736 struct sae_password_entry *pw;
1737
1738 if (conf->ssid.wpa_passphrase)
1739 return false;
1740
1741 for (pw = conf->sae_passwords; pw; pw = pw->next) {
1742 if (!pw->pk)
1743 return false;
1744 with_pk = true;
1745 }
1746
1747 return with_pk;
1748}
1749#endif /* CONFIG_SAE_PK */
Sunil Ravia04bd252022-05-02 22:54:18 -07001750
1751
1752int hostapd_acl_comp(const void *a, const void *b)
1753{
1754 const struct mac_acl_entry *aa = a;
1755 const struct mac_acl_entry *bb = b;
1756 return os_memcmp(aa->addr, bb->addr, sizeof(macaddr));
1757}
1758
1759
1760int hostapd_add_acl_maclist(struct mac_acl_entry **acl, int *num,
1761 int vlan_id, const u8 *addr)
1762{
1763 struct mac_acl_entry *newacl;
1764
1765 newacl = os_realloc_array(*acl, *num + 1, sizeof(**acl));
1766 if (!newacl) {
1767 wpa_printf(MSG_ERROR, "MAC list reallocation failed");
1768 return -1;
1769 }
1770
1771 *acl = newacl;
1772 os_memcpy((*acl)[*num].addr, addr, ETH_ALEN);
1773 os_memset(&(*acl)[*num].vlan_id, 0, sizeof((*acl)[*num].vlan_id));
1774 (*acl)[*num].vlan_id.untagged = vlan_id;
1775 (*acl)[*num].vlan_id.notempty = !!vlan_id;
1776 (*num)++;
1777
1778 return 0;
1779}
1780
1781
1782void hostapd_remove_acl_mac(struct mac_acl_entry **acl, int *num,
1783 const u8 *addr)
1784{
1785 int i = 0;
1786
1787 while (i < *num) {
Sunil Ravib0ac25f2024-07-12 01:42:03 +00001788 if (ether_addr_equal((*acl)[i].addr, addr)) {
Sunil Ravia04bd252022-05-02 22:54:18 -07001789 os_remove_in_array(*acl, *num, sizeof(**acl), i);
1790 (*num)--;
1791 } else {
1792 i++;
1793 }
1794 }
1795}