blob: 33c68d4382045ebca8833da48527b4dae89064de [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * hostapd / Configuration helper functions
Dmitry Shmidt344abd32014-01-14 13:17:00 -08003 * Copyright (c) 2003-2014, 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;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070093 bss->ap_max_inactivity = AP_MAX_INACTIVITY;
94 bss->eapol_version = EAPOL_VERSION;
95
96 bss->max_listen_interval = 65535;
97
98 bss->pwd_group = 19; /* ECC: GF(p=256) */
99
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700100 bss->assoc_sa_query_max_timeout = 1000;
101 bss->assoc_sa_query_retry_timeout = 201;
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700102 bss->group_mgmt_cipher = WPA_CIPHER_AES_128_CMAC;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700103#ifdef EAP_SERVER_FAST
104 /* both anonymous and authenticated provisioning */
105 bss->eap_fast_prov = 3;
106 bss->pac_key_lifetime = 7 * 24 * 60 * 60;
107 bss->pac_key_refresh_time = 1 * 24 * 60 * 60;
108#endif /* EAP_SERVER_FAST */
109
110 /* Set to -1 as defaults depends on HT in setup */
111 bss->wmm_enabled = -1;
112
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800113#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700114 bss->ft_over_ds = 1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700115 bss->rkh_pos_timeout = 86400;
116 bss->rkh_neg_timeout = 60;
117 bss->rkh_pull_timeout = 1000;
118 bss->rkh_pull_retries = 4;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700119 bss->r0_key_lifetime = 1209600;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800120#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt04949592012-07-19 12:16:46 -0700121
122 bss->radius_das_time_window = 300;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800123
Hai Shaloma20dcd72022-02-04 13:43:00 -0800124 bss->anti_clogging_threshold = 5;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700125 bss->sae_sync = 5;
Dmitry Shmidt29333592017-01-09 12:27:11 -0800126
127 bss->gas_frag_limit = 1400;
128
129#ifdef CONFIG_FILS
130 dl_list_init(&bss->fils_realms);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800131 bss->fils_hlp_wait_time = 30;
132 bss->dhcp_server_port = DHCP_SERVER_PORT;
133 bss->dhcp_relay_port = DHCP_SERVER_PORT;
Hai Shalom60840252021-02-19 19:02:11 -0800134 bss->fils_discovery_min_int = 20;
Dmitry Shmidt29333592017-01-09 12:27:11 -0800135#endif /* CONFIG_FILS */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700136
137 bss->broadcast_deauth = 1;
138
139#ifdef CONFIG_MBO
140 bss->mbo_cell_data_conn_pref = -1;
141#endif /* CONFIG_MBO */
Roshan Pius3a1667e2018-07-03 15:17:14 -0700142
143 /* Disable TLS v1.3 by default for now to avoid interoperability issue.
144 * This can be enabled by default once the implementation has been fully
145 * completed and tested with other implementations. */
146 bss->tls_flags = TLS_CONN_DISABLE_TLSv1_3;
Hai Shalom74f70d42019-02-11 14:42:39 -0800147
Hai Shalomc3565922019-10-28 11:58:20 -0700148 bss->max_auth_rounds = 100;
149 bss->max_auth_rounds_short = 50;
150
Hai Shalom74f70d42019-02-11 14:42:39 -0800151 bss->send_probe_response = 1;
152
153#ifdef CONFIG_HS20
154 bss->hs20_release = (HS20_VERSION >> 4) + 1;
155#endif /* CONFIG_HS20 */
156
Hai Shalom81f62d82019-07-22 12:10:00 -0700157#ifdef CONFIG_MACSEC
158 bss->mka_priority = DEFAULT_PRIO_NOT_KEY_SERVER;
159 bss->macsec_port = 1;
160#endif /* CONFIG_MACSEC */
161
Hai Shalom74f70d42019-02-11 14:42:39 -0800162 /* Default to strict CRL checking. */
163 bss->check_crl_strict = 1;
Hai Shalom899fcc72020-10-19 14:38:18 -0700164
165#ifdef CONFIG_TESTING_OPTIONS
166 bss->sae_commit_status = -1;
167#endif /* CONFIG_TESTING_OPTIONS */
Hai Shaloma20dcd72022-02-04 13:43:00 -0800168
169#ifdef CONFIG_PASN
170 /* comeback after 10 TUs */
171 bss->pasn_comeback_after = 10;
172#endif /* CONFIG_PASN */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700173}
174
175
176struct hostapd_config * hostapd_config_defaults(void)
177{
178#define ecw2cw(ecw) ((1 << (ecw)) - 1)
179
180 struct hostapd_config *conf;
181 struct hostapd_bss_config *bss;
182 const int aCWmin = 4, aCWmax = 10;
183 const struct hostapd_wmm_ac_params ac_bk =
184 { aCWmin, aCWmax, 7, 0, 0 }; /* background traffic */
185 const struct hostapd_wmm_ac_params ac_be =
186 { aCWmin, aCWmax, 3, 0, 0 }; /* best effort traffic */
187 const struct hostapd_wmm_ac_params ac_vi = /* video traffic */
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700188 { aCWmin - 1, aCWmin, 2, 3008 / 32, 0 };
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700189 const struct hostapd_wmm_ac_params ac_vo = /* voice traffic */
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700190 { aCWmin - 2, aCWmin - 1, 2, 1504 / 32, 0 };
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700191 const struct hostapd_tx_queue_params txq_bk =
192 { 7, ecw2cw(aCWmin), ecw2cw(aCWmax), 0 };
193 const struct hostapd_tx_queue_params txq_be =
194 { 3, ecw2cw(aCWmin), 4 * (ecw2cw(aCWmin) + 1) - 1, 0};
195 const struct hostapd_tx_queue_params txq_vi =
196 { 1, (ecw2cw(aCWmin) + 1) / 2 - 1, ecw2cw(aCWmin), 30};
197 const struct hostapd_tx_queue_params txq_vo =
198 { 1, (ecw2cw(aCWmin) + 1) / 4 - 1,
199 (ecw2cw(aCWmin) + 1) / 2 - 1, 15};
200
201#undef ecw2cw
202
203 conf = os_zalloc(sizeof(*conf));
204 bss = os_zalloc(sizeof(*bss));
205 if (conf == NULL || bss == NULL) {
206 wpa_printf(MSG_ERROR, "Failed to allocate memory for "
207 "configuration data.");
208 os_free(conf);
209 os_free(bss);
210 return NULL;
211 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800212 conf->bss = os_calloc(1, sizeof(struct hostapd_bss_config *));
213 if (conf->bss == NULL) {
214 os_free(conf);
215 os_free(bss);
216 return NULL;
217 }
218 conf->bss[0] = bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700219
220 bss->radius = os_zalloc(sizeof(*bss->radius));
221 if (bss->radius == NULL) {
Dmitry Shmidt97672262014-02-03 13:02:54 -0800222 os_free(conf->bss);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700223 os_free(conf);
224 os_free(bss);
225 return NULL;
226 }
227
228 hostapd_config_defaults_bss(bss);
229
230 conf->num_bss = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700231
232 conf->beacon_int = 100;
Hai Shalom021b0b52019-04-10 11:17:58 -0700233 conf->rts_threshold = -2; /* use driver default: 2347 */
234 conf->fragm_threshold = -2; /* user driver default: 2346 */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800235 /* Set to invalid value means do not add Power Constraint IE */
236 conf->local_pwr_constraint = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700237
238 conf->wmm_ac_params[0] = ac_be;
239 conf->wmm_ac_params[1] = ac_bk;
240 conf->wmm_ac_params[2] = ac_vi;
241 conf->wmm_ac_params[3] = ac_vo;
242
243 conf->tx_queue[0] = txq_vo;
244 conf->tx_queue[1] = txq_vi;
245 conf->tx_queue[2] = txq_be;
246 conf->tx_queue[3] = txq_bk;
247
248 conf->ht_capab = HT_CAP_INFO_SMPS_DISABLED;
249
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800250 conf->ap_table_max_size = 255;
251 conf->ap_table_expiration_time = 60;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800252 conf->track_sta_max_age = 180;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800253
Dmitry Shmidt8da800a2013-04-24 12:57:01 -0700254#ifdef CONFIG_TESTING_OPTIONS
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700255 conf->ignore_probe_probability = 0.0;
256 conf->ignore_auth_probability = 0.0;
257 conf->ignore_assoc_probability = 0.0;
258 conf->ignore_reassoc_probability = 0.0;
259 conf->corrupt_gtk_rekey_mic_probability = 0.0;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800260 conf->ecsa_ie_only = 0;
Kai Shie75b0652020-11-24 20:31:29 -0800261 conf->skip_send_eapol = 0;
262 conf->enable_eapol_large_timeout = 0;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -0700263#endif /* CONFIG_TESTING_OPTIONS */
264
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700265 conf->acs = 0;
266 conf->acs_ch_list.num = 0;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700267#ifdef CONFIG_ACS
268 conf->acs_num_scans = 5;
269#endif /* CONFIG_ACS */
270
Hai Shalom81f62d82019-07-22 12:10:00 -0700271#ifdef CONFIG_IEEE80211AX
272 conf->he_op.he_rts_threshold = HE_OPERATION_RTS_THRESHOLD_MASK >>
273 HE_OPERATION_RTS_THRESHOLD_OFFSET;
274 /* Set default basic MCS/NSS set to single stream MCS 0-7 */
275 conf->he_op.he_basic_mcs_nss_set = 0xfffc;
Hai Shalomfdcde762020-04-02 11:19:20 -0700276 conf->he_op.he_bss_color_disabled = 1;
277 conf->he_op.he_bss_color_partial = 0;
Hai Shaloma20dcd72022-02-04 13:43:00 -0800278 conf->he_op.he_bss_color = os_random() % 63 + 1;
279 conf->he_op.he_twt_responder = 1;
Hai Shalom60840252021-02-19 19:02:11 -0800280 conf->he_6ghz_max_mpdu = 2;
281 conf->he_6ghz_max_ampdu_len_exp = 7;
282 conf->he_6ghz_rx_ant_pat = 1;
283 conf->he_6ghz_tx_ant_pat = 1;
Hai Shalom81f62d82019-07-22 12:10:00 -0700284#endif /* CONFIG_IEEE80211AX */
285
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700286 /* The third octet of the country string uses an ASCII space character
287 * by default to indicate that the regulations encompass all
288 * environments for the current frequency band in the country. */
289 conf->country[2] = ' ';
290
Hai Shalom74f70d42019-02-11 14:42:39 -0800291 conf->rssi_reject_assoc_rssi = 0;
292 conf->rssi_reject_assoc_timeout = 30;
293
Hai Shalom81f62d82019-07-22 12:10:00 -0700294#ifdef CONFIG_AIRTIME_POLICY
295 conf->airtime_update_interval = AIRTIME_DEFAULT_UPDATE_INTERVAL;
296#endif /* CONFIG_AIRTIME_POLICY */
297
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700298 return conf;
299}
300
301
302int hostapd_mac_comp(const void *a, const void *b)
303{
304 return os_memcmp(a, b, sizeof(macaddr));
305}
306
307
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700308static int hostapd_config_read_wpa_psk(const char *fname,
309 struct hostapd_ssid *ssid)
310{
311 FILE *f;
312 char buf[128], *pos;
Hai Shalom74f70d42019-02-11 14:42:39 -0800313 const char *keyid;
314 char *context;
315 char *context2;
316 char *token;
317 char *name;
318 char *value;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700319 int line = 0, ret = 0, len, ok;
320 u8 addr[ETH_ALEN];
321 struct hostapd_wpa_psk *psk;
322
323 if (!fname)
324 return 0;
325
326 f = fopen(fname, "r");
327 if (!f) {
328 wpa_printf(MSG_ERROR, "WPA PSK file '%s' not found.", fname);
329 return -1;
330 }
331
332 while (fgets(buf, sizeof(buf), f)) {
Hai Shalom021b0b52019-04-10 11:17:58 -0700333 int vlan_id = 0;
Hai Shalomfdcde762020-04-02 11:19:20 -0700334 int wps = 0;
Hai Shalom021b0b52019-04-10 11:17:58 -0700335
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700336 line++;
337
338 if (buf[0] == '#')
339 continue;
340 pos = buf;
341 while (*pos != '\0') {
342 if (*pos == '\n') {
343 *pos = '\0';
344 break;
345 }
346 pos++;
347 }
348 if (buf[0] == '\0')
349 continue;
350
Hai Shalom74f70d42019-02-11 14:42:39 -0800351 context = NULL;
352 keyid = NULL;
353 while ((token = str_token(buf, " ", &context))) {
354 if (!os_strchr(token, '='))
355 break;
356 context2 = NULL;
357 name = str_token(token, "=", &context2);
Hai Shalom021b0b52019-04-10 11:17:58 -0700358 if (!name)
359 break;
Hai Shalom74f70d42019-02-11 14:42:39 -0800360 value = str_token(token, "", &context2);
361 if (!value)
362 value = "";
363 if (!os_strcmp(name, "keyid")) {
364 keyid = value;
Hai Shalomfdcde762020-04-02 11:19:20 -0700365 } else if (!os_strcmp(name, "wps")) {
366 wps = atoi(value);
Hai Shalom021b0b52019-04-10 11:17:58 -0700367 } else if (!os_strcmp(name, "vlanid")) {
368 vlan_id = atoi(value);
Hai Shalom74f70d42019-02-11 14:42:39 -0800369 } else {
370 wpa_printf(MSG_ERROR,
371 "Unrecognized '%s=%s' on line %d in '%s'",
372 name, value, line, fname);
373 ret = -1;
374 break;
375 }
376 }
377
378 if (ret == -1)
379 break;
380
381 if (!token)
382 token = "";
383 if (hwaddr_aton(token, addr)) {
Hai Shalomfdcde762020-04-02 11:19:20 -0700384 wpa_printf(MSG_ERROR,
385 "Invalid MAC address '%s' on line %d in '%s'",
386 token, line, fname);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700387 ret = -1;
388 break;
389 }
390
391 psk = os_zalloc(sizeof(*psk));
392 if (psk == NULL) {
393 wpa_printf(MSG_ERROR, "WPA PSK allocation failed");
394 ret = -1;
395 break;
396 }
Hai Shalom021b0b52019-04-10 11:17:58 -0700397 psk->vlan_id = vlan_id;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700398 if (is_zero_ether_addr(addr))
399 psk->group = 1;
400 else
401 os_memcpy(psk->addr, addr, ETH_ALEN);
402
Hai Shalom74f70d42019-02-11 14:42:39 -0800403 pos = str_token(buf, "", &context);
404 if (!pos) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700405 wpa_printf(MSG_ERROR, "No PSK on line %d in '%s'",
406 line, fname);
407 os_free(psk);
408 ret = -1;
409 break;
410 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700411
412 ok = 0;
413 len = os_strlen(pos);
Hai Shalomfdcde762020-04-02 11:19:20 -0700414 if (len == 2 * PMK_LEN &&
415 hexstr2bin(pos, psk->psk, PMK_LEN) == 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700416 ok = 1;
Hai Shalomfdcde762020-04-02 11:19:20 -0700417 else if (len >= 8 && len < 64 &&
418 pbkdf2_sha1(pos, ssid->ssid, ssid->ssid_len,
419 4096, psk->psk, PMK_LEN) == 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700420 ok = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700421 if (!ok) {
Hai Shalomfdcde762020-04-02 11:19:20 -0700422 wpa_printf(MSG_ERROR,
423 "Invalid PSK '%s' on line %d in '%s'",
424 pos, line, fname);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700425 os_free(psk);
426 ret = -1;
427 break;
428 }
429
Hai Shalom74f70d42019-02-11 14:42:39 -0800430 if (keyid) {
431 len = os_strlcpy(psk->keyid, keyid, sizeof(psk->keyid));
432 if ((size_t) len >= sizeof(psk->keyid)) {
433 wpa_printf(MSG_ERROR,
434 "PSK keyid too long on line %d in '%s'",
435 line, fname);
436 os_free(psk);
437 ret = -1;
438 break;
439 }
440 }
441
Hai Shalomfdcde762020-04-02 11:19:20 -0700442 psk->wps = wps;
443
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700444 psk->next = ssid->wpa_psk;
445 ssid->wpa_psk = psk;
446 }
447
448 fclose(f);
449
450 return ret;
451}
452
453
454static int hostapd_derive_psk(struct hostapd_ssid *ssid)
455{
456 ssid->wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
457 if (ssid->wpa_psk == NULL) {
458 wpa_printf(MSG_ERROR, "Unable to alloc space for PSK");
459 return -1;
460 }
461 wpa_hexdump_ascii(MSG_DEBUG, "SSID",
462 (u8 *) ssid->ssid, ssid->ssid_len);
463 wpa_hexdump_ascii_key(MSG_DEBUG, "PSK (ASCII passphrase)",
464 (u8 *) ssid->wpa_passphrase,
465 os_strlen(ssid->wpa_passphrase));
466 pbkdf2_sha1(ssid->wpa_passphrase,
467 ssid->ssid, ssid->ssid_len,
468 4096, ssid->wpa_psk->psk, PMK_LEN);
469 wpa_hexdump_key(MSG_DEBUG, "PSK (from passphrase)",
470 ssid->wpa_psk->psk, PMK_LEN);
471 return 0;
472}
473
474
Hai Shalomc3565922019-10-28 11:58:20 -0700475int hostapd_setup_sae_pt(struct hostapd_bss_config *conf)
476{
477#ifdef CONFIG_SAE
478 struct hostapd_ssid *ssid = &conf->ssid;
479 struct sae_password_entry *pw;
480
Hai Shalom899fcc72020-10-19 14:38:18 -0700481 if ((conf->sae_pwe == 0 && !hostapd_sae_pw_id_in_use(conf) &&
482 !hostapd_sae_pk_in_use(conf)) ||
Hai Shalomfdcde762020-04-02 11:19:20 -0700483 conf->sae_pwe == 3 ||
484 !wpa_key_mgmt_sae(conf->wpa_key_mgmt))
Hai Shalomc3565922019-10-28 11:58:20 -0700485 return 0; /* PT not needed */
486
487 sae_deinit_pt(ssid->pt);
488 ssid->pt = NULL;
489 if (ssid->wpa_passphrase) {
490 ssid->pt = sae_derive_pt(conf->sae_groups, ssid->ssid,
491 ssid->ssid_len,
492 (const u8 *) ssid->wpa_passphrase,
493 os_strlen(ssid->wpa_passphrase),
494 NULL);
495 if (!ssid->pt)
496 return -1;
497 }
498
499 for (pw = conf->sae_passwords; pw; pw = pw->next) {
500 sae_deinit_pt(pw->pt);
501 pw->pt = sae_derive_pt(conf->sae_groups, ssid->ssid,
502 ssid->ssid_len,
503 (const u8 *) pw->password,
504 os_strlen(pw->password),
505 pw->identifier);
506 if (!pw->pt)
507 return -1;
508 }
509#endif /* CONFIG_SAE */
510
511 return 0;
512}
513
514
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700515int hostapd_setup_wpa_psk(struct hostapd_bss_config *conf)
516{
517 struct hostapd_ssid *ssid = &conf->ssid;
518
Hai Shalomc3565922019-10-28 11:58:20 -0700519 if (hostapd_setup_sae_pt(conf) < 0)
520 return -1;
521
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700522 if (ssid->wpa_passphrase != NULL) {
523 if (ssid->wpa_psk != NULL) {
524 wpa_printf(MSG_DEBUG, "Using pre-configured WPA PSK "
525 "instead of passphrase");
526 } else {
527 wpa_printf(MSG_DEBUG, "Deriving WPA PSK based on "
528 "passphrase");
529 if (hostapd_derive_psk(ssid) < 0)
530 return -1;
531 }
532 ssid->wpa_psk->group = 1;
533 }
534
Dmitry Shmidt29333592017-01-09 12:27:11 -0800535 return hostapd_config_read_wpa_psk(ssid->wpa_psk_file, &conf->ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700536}
537
538
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700539static void hostapd_config_free_radius(struct hostapd_radius_server *servers,
540 int num_servers)
541{
542 int i;
543
544 for (i = 0; i < num_servers; i++) {
545 os_free(servers[i].shared_secret);
546 }
547 os_free(servers);
548}
549
550
Dmitry Shmidt04949592012-07-19 12:16:46 -0700551struct hostapd_radius_attr *
552hostapd_config_get_radius_attr(struct hostapd_radius_attr *attr, u8 type)
553{
554 for (; attr; attr = attr->next) {
555 if (attr->type == type)
556 return attr;
557 }
558 return NULL;
559}
560
561
Hai Shalomc3565922019-10-28 11:58:20 -0700562struct hostapd_radius_attr * hostapd_parse_radius_attr(const char *value)
563{
564 const char *pos;
565 char syntax;
566 struct hostapd_radius_attr *attr;
567 size_t len;
568
569 attr = os_zalloc(sizeof(*attr));
570 if (!attr)
571 return NULL;
572
573 attr->type = atoi(value);
574
575 pos = os_strchr(value, ':');
576 if (!pos) {
577 attr->val = wpabuf_alloc(1);
578 if (!attr->val) {
579 os_free(attr);
580 return NULL;
581 }
582 wpabuf_put_u8(attr->val, 0);
583 return attr;
584 }
585
586 pos++;
587 if (pos[0] == '\0' || pos[1] != ':') {
588 os_free(attr);
589 return NULL;
590 }
591 syntax = *pos++;
592 pos++;
593
594 switch (syntax) {
595 case 's':
596 attr->val = wpabuf_alloc_copy(pos, os_strlen(pos));
597 break;
598 case 'x':
599 len = os_strlen(pos);
600 if (len & 1)
601 break;
602 len /= 2;
603 attr->val = wpabuf_alloc(len);
604 if (!attr->val)
605 break;
606 if (hexstr2bin(pos, wpabuf_put(attr->val, len), len) < 0) {
607 wpabuf_free(attr->val);
608 os_free(attr);
609 return NULL;
610 }
611 break;
612 case 'd':
613 attr->val = wpabuf_alloc(4);
614 if (attr->val)
615 wpabuf_put_be32(attr->val, atoi(pos));
616 break;
617 default:
618 os_free(attr);
619 return NULL;
620 }
621
622 if (!attr->val) {
623 os_free(attr);
624 return NULL;
625 }
626
627 return attr;
628}
629
630
631void hostapd_config_free_radius_attr(struct hostapd_radius_attr *attr)
Dmitry Shmidt04949592012-07-19 12:16:46 -0700632{
633 struct hostapd_radius_attr *prev;
634
635 while (attr) {
636 prev = attr;
637 attr = attr->next;
638 wpabuf_free(prev->val);
639 os_free(prev);
640 }
641}
642
643
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700644void hostapd_config_free_eap_user(struct hostapd_eap_user *user)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700645{
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700646 hostapd_config_free_radius_attr(user->accept_attr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700647 os_free(user->identity);
Dmitry Shmidtc2817022014-07-02 10:32:10 -0700648 bin_clear_free(user->password, user->password_len);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700649 bin_clear_free(user->salt, user->salt_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700650 os_free(user);
651}
652
653
Dmitry Shmidt29333592017-01-09 12:27:11 -0800654void hostapd_config_free_eap_users(struct hostapd_eap_user *user)
655{
656 struct hostapd_eap_user *prev_user;
657
658 while (user) {
659 prev_user = user;
660 user = user->next;
661 hostapd_config_free_eap_user(prev_user);
662 }
663}
664
665
Hai Shalomfdcde762020-04-02 11:19:20 -0700666#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700667static void hostapd_config_free_wep(struct hostapd_wep_keys *keys)
668{
669 int i;
670 for (i = 0; i < NUM_WEP_KEYS; i++) {
Dmitry Shmidtc2817022014-07-02 10:32:10 -0700671 bin_clear_free(keys->key[i], keys->len[i]);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700672 keys->key[i] = NULL;
673 }
674}
Hai Shalomfdcde762020-04-02 11:19:20 -0700675#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700676
677
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800678void hostapd_config_clear_wpa_psk(struct hostapd_wpa_psk **l)
679{
680 struct hostapd_wpa_psk *psk, *tmp;
681
682 for (psk = *l; psk;) {
683 tmp = psk;
684 psk = psk->next;
685 bin_clear_free(tmp, sizeof(*tmp));
686 }
687 *l = NULL;
688}
689
690
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800691static void hostapd_config_free_anqp_elem(struct hostapd_bss_config *conf)
692{
693 struct anqp_element *elem;
694
695 while ((elem = dl_list_first(&conf->anqp_elem, struct anqp_element,
696 list))) {
697 dl_list_del(&elem->list);
698 wpabuf_free(elem->payload);
699 os_free(elem);
700 }
701}
702
703
Dmitry Shmidt29333592017-01-09 12:27:11 -0800704static void hostapd_config_free_fils_realms(struct hostapd_bss_config *conf)
705{
706#ifdef CONFIG_FILS
707 struct fils_realm *realm;
708
709 while ((realm = dl_list_first(&conf->fils_realms, struct fils_realm,
710 list))) {
711 dl_list_del(&realm->list);
712 os_free(realm);
713 }
714#endif /* CONFIG_FILS */
715}
716
717
Roshan Pius3a1667e2018-07-03 15:17:14 -0700718static void hostapd_config_free_sae_passwords(struct hostapd_bss_config *conf)
719{
720 struct sae_password_entry *pw, *tmp;
721
722 pw = conf->sae_passwords;
723 conf->sae_passwords = NULL;
724 while (pw) {
725 tmp = pw;
726 pw = pw->next;
727 str_clear_free(tmp->password);
728 os_free(tmp->identifier);
Hai Shalomc3565922019-10-28 11:58:20 -0700729#ifdef CONFIG_SAE
730 sae_deinit_pt(tmp->pt);
731#endif /* CONFIG_SAE */
Hai Shalom899fcc72020-10-19 14:38:18 -0700732#ifdef CONFIG_SAE_PK
733 sae_deinit_pk(tmp->pk);
734#endif /* CONFIG_SAE_PK */
Roshan Pius3a1667e2018-07-03 15:17:14 -0700735 os_free(tmp);
736 }
737}
738
739
Hai Shalom81f62d82019-07-22 12:10:00 -0700740#ifdef CONFIG_DPP2
741static void hostapd_dpp_controller_conf_free(struct dpp_controller_conf *conf)
742{
743 struct dpp_controller_conf *prev;
744
745 while (conf) {
746 prev = conf;
747 conf = conf->next;
748 os_free(prev);
749 }
750}
751#endif /* CONFIG_DPP2 */
752
753
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800754void hostapd_config_free_bss(struct hostapd_bss_config *conf)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700755{
Hai Shalom81f62d82019-07-22 12:10:00 -0700756#if defined(CONFIG_WPS) || defined(CONFIG_HS20)
757 size_t i;
758#endif
759
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700760 if (conf == NULL)
761 return;
762
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800763 hostapd_config_clear_wpa_psk(&conf->ssid.wpa_psk);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700764
Dmitry Shmidtc2817022014-07-02 10:32:10 -0700765 str_clear_free(conf->ssid.wpa_passphrase);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700766 os_free(conf->ssid.wpa_psk_file);
Hai Shalomfdcde762020-04-02 11:19:20 -0700767#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700768 hostapd_config_free_wep(&conf->ssid.wep);
Hai Shalomfdcde762020-04-02 11:19:20 -0700769#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700770#ifdef CONFIG_FULL_DYNAMIC_VLAN
771 os_free(conf->ssid.vlan_tagged_interface);
772#endif /* CONFIG_FULL_DYNAMIC_VLAN */
Hai Shalomc3565922019-10-28 11:58:20 -0700773#ifdef CONFIG_SAE
774 sae_deinit_pt(conf->ssid.pt);
775#endif /* CONFIG_SAE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700776
Dmitry Shmidt29333592017-01-09 12:27:11 -0800777 hostapd_config_free_eap_users(conf->eap_user);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800778 os_free(conf->eap_user_sqlite);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700779
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700780 os_free(conf->eap_req_id_text);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800781 os_free(conf->erp_domain);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700782 os_free(conf->accept_mac);
783 os_free(conf->deny_mac);
784 os_free(conf->nas_identifier);
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800785 if (conf->radius) {
786 hostapd_config_free_radius(conf->radius->auth_servers,
787 conf->radius->num_auth_servers);
788 hostapd_config_free_radius(conf->radius->acct_servers,
789 conf->radius->num_acct_servers);
Hai Shaloma20dcd72022-02-04 13:43:00 -0800790 os_free(conf->radius->force_client_dev);
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800791 }
Dmitry Shmidt04949592012-07-19 12:16:46 -0700792 hostapd_config_free_radius_attr(conf->radius_auth_req_attr);
793 hostapd_config_free_radius_attr(conf->radius_acct_req_attr);
Hai Shalomc3565922019-10-28 11:58:20 -0700794 os_free(conf->radius_req_attr_sqlite);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700795 os_free(conf->rsn_preauth_interfaces);
796 os_free(conf->ctrl_interface);
797 os_free(conf->ca_cert);
798 os_free(conf->server_cert);
Hai Shalom81f62d82019-07-22 12:10:00 -0700799 os_free(conf->server_cert2);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700800 os_free(conf->private_key);
Hai Shalom81f62d82019-07-22 12:10:00 -0700801 os_free(conf->private_key2);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700802 os_free(conf->private_key_passwd);
Hai Shalom81f62d82019-07-22 12:10:00 -0700803 os_free(conf->private_key_passwd2);
Hai Shalom021b0b52019-04-10 11:17:58 -0700804 os_free(conf->check_cert_subject);
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700805 os_free(conf->ocsp_stapling_response);
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -0800806 os_free(conf->ocsp_stapling_response_multi);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700807 os_free(conf->dh_file);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800808 os_free(conf->openssl_ciphers);
Hai Shalom74f70d42019-02-11 14:42:39 -0800809 os_free(conf->openssl_ecdh_curves);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700810 os_free(conf->pac_opaque_encr_key);
811 os_free(conf->eap_fast_a_id);
812 os_free(conf->eap_fast_a_id_info);
813 os_free(conf->eap_sim_db);
814 os_free(conf->radius_server_clients);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700815 os_free(conf->radius);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700816 os_free(conf->radius_das_shared_secret);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700817 hostapd_config_free_vlan(conf);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800818 os_free(conf->time_zone);
819
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800820#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700821 {
822 struct ft_remote_r0kh *r0kh, *r0kh_prev;
823 struct ft_remote_r1kh *r1kh, *r1kh_prev;
824
825 r0kh = conf->r0kh_list;
826 conf->r0kh_list = NULL;
827 while (r0kh) {
828 r0kh_prev = r0kh;
829 r0kh = r0kh->next;
830 os_free(r0kh_prev);
831 }
832
833 r1kh = conf->r1kh_list;
834 conf->r1kh_list = NULL;
835 while (r1kh) {
836 r1kh_prev = r1kh;
837 r1kh = r1kh->next;
838 os_free(r1kh_prev);
839 }
840 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800841#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700842
843#ifdef CONFIG_WPS
844 os_free(conf->wps_pin_requests);
845 os_free(conf->device_name);
846 os_free(conf->manufacturer);
847 os_free(conf->model_name);
848 os_free(conf->model_number);
849 os_free(conf->serial_number);
850 os_free(conf->config_methods);
851 os_free(conf->ap_pin);
852 os_free(conf->extra_cred);
853 os_free(conf->ap_settings);
Hai Shalom021b0b52019-04-10 11:17:58 -0700854 hostapd_config_clear_wpa_psk(&conf->multi_ap_backhaul_ssid.wpa_psk);
855 str_clear_free(conf->multi_ap_backhaul_ssid.wpa_passphrase);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700856 os_free(conf->upnp_iface);
857 os_free(conf->friendly_name);
858 os_free(conf->manufacturer_url);
859 os_free(conf->model_description);
860 os_free(conf->model_url);
861 os_free(conf->upc);
Hai Shalom81f62d82019-07-22 12:10:00 -0700862 for (i = 0; i < MAX_WPS_VENDOR_EXTENSIONS; i++)
863 wpabuf_free(conf->wps_vendor_ext[i]);
Hai Shalomfdcde762020-04-02 11:19:20 -0700864 wpabuf_free(conf->wps_application_ext);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700865 wpabuf_free(conf->wps_nfc_dh_pubkey);
866 wpabuf_free(conf->wps_nfc_dh_privkey);
867 wpabuf_free(conf->wps_nfc_dev_pw);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700868#endif /* CONFIG_WPS */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800869
870 os_free(conf->roaming_consortium);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700871 os_free(conf->venue_name);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700872 os_free(conf->venue_url);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700873 os_free(conf->nai_realm_data);
874 os_free(conf->network_auth_type);
875 os_free(conf->anqp_3gpp_cell_net);
876 os_free(conf->domain_name);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800877 hostapd_config_free_anqp_elem(conf);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800878
879#ifdef CONFIG_RADIUS_TEST
880 os_free(conf->dump_msk_file);
881#endif /* CONFIG_RADIUS_TEST */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700882
883#ifdef CONFIG_HS20
884 os_free(conf->hs20_oper_friendly_name);
885 os_free(conf->hs20_wan_metrics);
886 os_free(conf->hs20_connection_capability);
887 os_free(conf->hs20_operating_class);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800888 os_free(conf->hs20_icons);
889 if (conf->hs20_osu_providers) {
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800890 for (i = 0; i < conf->hs20_osu_providers_count; i++) {
891 struct hs20_osu_provider *p;
892 size_t j;
893 p = &conf->hs20_osu_providers[i];
894 os_free(p->friendly_name);
895 os_free(p->server_uri);
896 os_free(p->method_list);
897 for (j = 0; j < p->icons_count; j++)
898 os_free(p->icons[j]);
899 os_free(p->icons);
900 os_free(p->osu_nai);
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800901 os_free(p->osu_nai2);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800902 os_free(p->service_desc);
903 }
904 os_free(conf->hs20_osu_providers);
905 }
Roshan Pius3a1667e2018-07-03 15:17:14 -0700906 if (conf->hs20_operator_icon) {
Roshan Pius3a1667e2018-07-03 15:17:14 -0700907 for (i = 0; i < conf->hs20_operator_icon_count; i++)
908 os_free(conf->hs20_operator_icon[i]);
909 os_free(conf->hs20_operator_icon);
910 }
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800911 os_free(conf->subscr_remediation_url);
Hai Shalom74f70d42019-02-11 14:42:39 -0800912 os_free(conf->hs20_sim_provisioning_url);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700913 os_free(conf->t_c_filename);
914 os_free(conf->t_c_server_url);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700915#endif /* CONFIG_HS20 */
916
917 wpabuf_free(conf->vendor_elements);
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700918 wpabuf_free(conf->assocresp_elements);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800919
920 os_free(conf->sae_groups);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700921#ifdef CONFIG_OWE
922 os_free(conf->owe_groups);
923#endif /* CONFIG_OWE */
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700924
Dmitry Shmidt0207e232014-09-03 14:58:37 -0700925 os_free(conf->wowlan_triggers);
926
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700927 os_free(conf->server_id);
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800928
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800929#ifdef CONFIG_TESTING_OPTIONS
930 wpabuf_free(conf->own_ie_override);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700931 wpabuf_free(conf->sae_commit_override);
Hai Shalomfdcde762020-04-02 11:19:20 -0700932 wpabuf_free(conf->rsne_override_eapol);
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800933 wpabuf_free(conf->rsnxe_override_eapol);
Hai Shalomfdcde762020-04-02 11:19:20 -0700934 wpabuf_free(conf->rsne_override_ft);
935 wpabuf_free(conf->rsnxe_override_ft);
936 wpabuf_free(conf->gtk_rsc_override);
937 wpabuf_free(conf->igtk_rsc_override);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800938#endif /* CONFIG_TESTING_OPTIONS */
939
940 os_free(conf->no_probe_resp_if_seen_on);
941 os_free(conf->no_auth_if_seen_on);
942
Dmitry Shmidt29333592017-01-09 12:27:11 -0800943 hostapd_config_free_fils_realms(conf);
944
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700945#ifdef CONFIG_DPP
Hai Shalomc3565922019-10-28 11:58:20 -0700946 os_free(conf->dpp_name);
947 os_free(conf->dpp_mud_url);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700948 os_free(conf->dpp_connector);
949 wpabuf_free(conf->dpp_netaccesskey);
950 wpabuf_free(conf->dpp_csign);
Hai Shalom81f62d82019-07-22 12:10:00 -0700951#ifdef CONFIG_DPP2
952 hostapd_dpp_controller_conf_free(conf->dpp_controller);
953#endif /* CONFIG_DPP2 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700954#endif /* CONFIG_DPP */
955
Roshan Pius3a1667e2018-07-03 15:17:14 -0700956 hostapd_config_free_sae_passwords(conf);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700957
Hai Shalom81f62d82019-07-22 12:10:00 -0700958#ifdef CONFIG_AIRTIME_POLICY
959 {
960 struct airtime_sta_weight *wt, *wt_prev;
961
962 wt = conf->airtime_weight_list;
963 conf->airtime_weight_list = NULL;
964 while (wt) {
965 wt_prev = wt;
966 wt = wt->next;
967 os_free(wt_prev);
968 }
969 }
970#endif /* CONFIG_AIRTIME_POLICY */
971
Hai Shalom60840252021-02-19 19:02:11 -0800972#ifdef CONFIG_PASN
973 os_free(conf->pasn_groups);
974#endif /* CONFIG_PASN */
975
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800976 os_free(conf);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700977}
978
979
980/**
981 * hostapd_config_free - Free hostapd configuration
982 * @conf: Configuration data from hostapd_config_read().
983 */
984void hostapd_config_free(struct hostapd_config *conf)
985{
986 size_t i;
987
988 if (conf == NULL)
989 return;
990
991 for (i = 0; i < conf->num_bss; i++)
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800992 hostapd_config_free_bss(conf->bss[i]);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700993 os_free(conf->bss);
994 os_free(conf->supported_rates);
995 os_free(conf->basic_rates);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700996 os_free(conf->acs_ch_list.range);
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800997 os_free(conf->acs_freq_list.range);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800998 os_free(conf->driver_params);
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800999#ifdef CONFIG_ACS
1000 os_free(conf->acs_chan_bias);
1001#endif /* CONFIG_ACS */
Dmitry Shmidt849734c2016-05-27 09:59:01 -07001002 wpabuf_free(conf->lci);
1003 wpabuf_free(conf->civic);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001004
1005 os_free(conf);
1006}
1007
1008
1009/**
1010 * hostapd_maclist_found - Find a MAC address from a list
1011 * @list: MAC address list
1012 * @num_entries: Number of addresses in the list
1013 * @addr: Address to search for
1014 * @vlan_id: Buffer for returning VLAN ID or %NULL if not needed
1015 * Returns: 1 if address is in the list or 0 if not.
1016 *
1017 * Perform a binary search for given MAC address from a pre-sorted list.
1018 */
1019int hostapd_maclist_found(struct mac_acl_entry *list, int num_entries,
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001020 const u8 *addr, struct vlan_description *vlan_id)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001021{
1022 int start, end, middle, res;
1023
1024 start = 0;
1025 end = num_entries - 1;
1026
1027 while (start <= end) {
1028 middle = (start + end) / 2;
1029 res = os_memcmp(list[middle].addr, addr, ETH_ALEN);
1030 if (res == 0) {
1031 if (vlan_id)
1032 *vlan_id = list[middle].vlan_id;
1033 return 1;
1034 }
1035 if (res < 0)
1036 start = middle + 1;
1037 else
1038 end = middle - 1;
1039 }
1040
1041 return 0;
1042}
1043
1044
1045int hostapd_rate_found(int *list, int rate)
1046{
1047 int i;
1048
1049 if (list == NULL)
1050 return 0;
1051
1052 for (i = 0; list[i] >= 0; i++)
1053 if (list[i] == rate)
1054 return 1;
1055
1056 return 0;
1057}
1058
1059
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001060int hostapd_vlan_valid(struct hostapd_vlan *vlan,
1061 struct vlan_description *vlan_desc)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001062{
1063 struct hostapd_vlan *v = vlan;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001064 int i;
1065
1066 if (!vlan_desc->notempty || vlan_desc->untagged < 0 ||
1067 vlan_desc->untagged > MAX_VLAN_ID)
1068 return 0;
1069 for (i = 0; i < MAX_NUM_TAGGED_VLAN; i++) {
1070 if (vlan_desc->tagged[i] < 0 ||
1071 vlan_desc->tagged[i] > MAX_VLAN_ID)
1072 return 0;
1073 }
1074 if (!vlan_desc->untagged && !vlan_desc->tagged[0])
1075 return 0;
1076
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001077 while (v) {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001078 if (!vlan_compare(&v->vlan_desc, vlan_desc) ||
1079 v->vlan_id == VLAN_ID_WILDCARD)
Dmitry Shmidt34af3062013-07-11 10:46:32 -07001080 return 1;
1081 v = v->next;
1082 }
1083 return 0;
1084}
1085
1086
1087const char * hostapd_get_vlan_id_ifname(struct hostapd_vlan *vlan, int vlan_id)
1088{
1089 struct hostapd_vlan *v = vlan;
1090 while (v) {
1091 if (v->vlan_id == vlan_id)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001092 return v->ifname;
1093 v = v->next;
1094 }
1095 return NULL;
1096}
1097
1098
1099const u8 * hostapd_get_psk(const struct hostapd_bss_config *conf,
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001100 const u8 *addr, const u8 *p2p_dev_addr,
Hai Shalom021b0b52019-04-10 11:17:58 -07001101 const u8 *prev_psk, int *vlan_id)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001102{
1103 struct hostapd_wpa_psk *psk;
1104 int next_ok = prev_psk == NULL;
1105
Hai Shalom021b0b52019-04-10 11:17:58 -07001106 if (vlan_id)
1107 *vlan_id = 0;
1108
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001109 if (p2p_dev_addr && !is_zero_ether_addr(p2p_dev_addr)) {
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001110 wpa_printf(MSG_DEBUG, "Searching a PSK for " MACSTR
1111 " p2p_dev_addr=" MACSTR " prev_psk=%p",
1112 MAC2STR(addr), MAC2STR(p2p_dev_addr), prev_psk);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001113 addr = NULL; /* Use P2P Device Address for matching */
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001114 } else {
1115 wpa_printf(MSG_DEBUG, "Searching a PSK for " MACSTR
1116 " prev_psk=%p",
1117 MAC2STR(addr), prev_psk);
1118 }
1119
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001120 for (psk = conf->ssid.wpa_psk; psk != NULL; psk = psk->next) {
1121 if (next_ok &&
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001122 (psk->group ||
1123 (addr && os_memcmp(psk->addr, addr, ETH_ALEN) == 0) ||
1124 (!addr && p2p_dev_addr &&
1125 os_memcmp(psk->p2p_dev_addr, p2p_dev_addr, ETH_ALEN) ==
Hai Shalom021b0b52019-04-10 11:17:58 -07001126 0))) {
1127 if (vlan_id)
1128 *vlan_id = psk->vlan_id;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001129 return psk->psk;
Hai Shalom021b0b52019-04-10 11:17:58 -07001130 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001131
1132 if (psk->psk == prev_psk)
1133 next_ok = 1;
1134 }
1135
1136 return NULL;
1137}
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001138
1139
Hai Shalom899fcc72020-10-19 14:38:18 -07001140#ifdef CONFIG_SAE_PK
1141static bool hostapd_sae_pk_password_without_pk(struct hostapd_bss_config *bss)
1142{
1143 struct sae_password_entry *pw;
1144 bool res = false;
1145
1146 if (bss->ssid.wpa_passphrase &&
1147#ifdef CONFIG_TESTING_OPTIONS
1148 !bss->sae_pk_password_check_skip &&
1149#endif /* CONFIG_TESTING_OPTIONS */
1150 sae_pk_valid_password(bss->ssid.wpa_passphrase))
1151 res = true;
1152
1153 for (pw = bss->sae_passwords; pw; pw = pw->next) {
1154 if (!pw->pk &&
1155#ifdef CONFIG_TESTING_OPTIONS
1156 !bss->sae_pk_password_check_skip &&
1157#endif /* CONFIG_TESTING_OPTIONS */
1158 sae_pk_valid_password(pw->password))
1159 return true;
1160
1161 if (bss->ssid.wpa_passphrase && res && pw->pk &&
1162 os_strcmp(bss->ssid.wpa_passphrase, pw->password) == 0)
1163 res = false;
1164 }
1165
1166 return res;
1167}
1168#endif /* CONFIG_SAE_PK */
1169
1170
Hai Shalom60840252021-02-19 19:02:11 -08001171static bool hostapd_config_check_bss_6g(struct hostapd_bss_config *bss)
1172{
1173 if (bss->wpa != WPA_PROTO_RSN) {
1174 wpa_printf(MSG_ERROR,
1175 "Pre-RSNA security methods are not allowed in 6 GHz");
1176 return false;
1177 }
1178
1179 if (bss->ieee80211w != MGMT_FRAME_PROTECTION_REQUIRED) {
1180 wpa_printf(MSG_ERROR,
1181 "Management frame protection is required in 6 GHz");
1182 return false;
1183 }
1184
1185 if (bss->wpa_key_mgmt & (WPA_KEY_MGMT_PSK |
1186 WPA_KEY_MGMT_FT_PSK |
1187 WPA_KEY_MGMT_PSK_SHA256)) {
1188 wpa_printf(MSG_ERROR, "Invalid AKM suite for 6 GHz");
1189 return false;
1190 }
1191
1192 if (bss->rsn_pairwise & (WPA_CIPHER_WEP40 |
1193 WPA_CIPHER_WEP104 |
1194 WPA_CIPHER_TKIP)) {
1195 wpa_printf(MSG_ERROR,
1196 "Invalid pairwise cipher suite for 6 GHz");
1197 return false;
1198 }
1199
1200 if (bss->wpa_group & (WPA_CIPHER_WEP40 |
1201 WPA_CIPHER_WEP104 |
1202 WPA_CIPHER_TKIP)) {
1203 wpa_printf(MSG_ERROR, "Invalid group cipher suite for 6 GHz");
1204 return false;
1205 }
1206
1207 return true;
1208}
1209
1210
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001211static int hostapd_config_check_bss(struct hostapd_bss_config *bss,
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001212 struct hostapd_config *conf,
1213 int full_config)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001214{
Hai Shalom60840252021-02-19 19:02:11 -08001215 if (full_config && is_6ghz_op_class(conf->op_class) &&
1216 !hostapd_config_check_bss_6g(bss))
1217 return -1;
1218
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001219 if (full_config && bss->ieee802_1x && !bss->eap_server &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001220 !bss->radius->auth_servers) {
1221 wpa_printf(MSG_ERROR, "Invalid IEEE 802.1X configuration (no "
1222 "EAP authenticator configured).");
1223 return -1;
1224 }
1225
Hai Shalomfdcde762020-04-02 11:19:20 -07001226#ifdef CONFIG_WEP
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001227 if (bss->wpa) {
1228 int wep, i;
1229
1230 wep = bss->default_wep_key_len > 0 ||
1231 bss->individual_wep_key_len > 0;
1232 for (i = 0; i < NUM_WEP_KEYS; i++) {
1233 if (bss->ssid.wep.keys_set) {
1234 wep = 1;
1235 break;
1236 }
1237 }
1238
1239 if (wep) {
1240 wpa_printf(MSG_ERROR, "WEP configuration in a WPA network is not supported");
1241 return -1;
1242 }
1243 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001244#endif /* CONFIG_WEP */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001245
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001246 if (full_config && bss->wpa &&
1247 bss->wpa_psk_radius != PSK_RADIUS_IGNORED &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001248 bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH) {
1249 wpa_printf(MSG_ERROR, "WPA-PSK using RADIUS enabled, but no "
1250 "RADIUS checking (macaddr_acl=2) enabled.");
1251 return -1;
1252 }
1253
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001254 if (full_config && bss->wpa && (bss->wpa_key_mgmt & WPA_KEY_MGMT_PSK) &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001255 bss->ssid.wpa_psk == NULL && bss->ssid.wpa_passphrase == NULL &&
1256 bss->ssid.wpa_psk_file == NULL &&
1257 (bss->wpa_psk_radius != PSK_RADIUS_REQUIRED ||
1258 bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH)) {
1259 wpa_printf(MSG_ERROR, "WPA-PSK enabled, but PSK or passphrase "
1260 "is not configured.");
1261 return -1;
1262 }
1263
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001264 if (full_config && !is_zero_ether_addr(bss->bssid)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001265 size_t i;
1266
1267 for (i = 0; i < conf->num_bss; i++) {
1268 if (conf->bss[i] != bss &&
1269 (hostapd_mac_comp(conf->bss[i]->bssid,
1270 bss->bssid) == 0)) {
1271 wpa_printf(MSG_ERROR, "Duplicate BSSID " MACSTR
1272 " on interface '%s' and '%s'.",
1273 MAC2STR(bss->bssid),
1274 conf->bss[i]->iface, bss->iface);
1275 return -1;
1276 }
1277 }
1278 }
1279
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001280#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001281 if (full_config && wpa_key_mgmt_ft(bss->wpa_key_mgmt) &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001282 (bss->nas_identifier == NULL ||
1283 os_strlen(bss->nas_identifier) < 1 ||
1284 os_strlen(bss->nas_identifier) > FT_R0KH_ID_MAX_LEN)) {
1285 wpa_printf(MSG_ERROR, "FT (IEEE 802.11r) requires "
1286 "nas_identifier to be configured as a 1..48 octet "
1287 "string");
1288 return -1;
1289 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001290#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001291
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001292 if (full_config && conf->ieee80211n &&
1293 conf->hw_mode == HOSTAPD_MODE_IEEE80211B) {
Hai Shalom60840252021-02-19 19:02:11 -08001294 bss->disable_11n = true;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001295 wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) in 11b mode is not "
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001296 "allowed, disabling HT capabilities");
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001297 }
1298
Hai Shalomfdcde762020-04-02 11:19:20 -07001299#ifdef CONFIG_WEP
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001300 if (full_config && conf->ieee80211n &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001301 bss->ssid.security_policy == SECURITY_STATIC_WEP) {
Hai Shalom60840252021-02-19 19:02:11 -08001302 bss->disable_11n = true;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001303 wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) with WEP is not "
1304 "allowed, disabling HT capabilities");
1305 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001306#endif /* CONFIG_WEP */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001307
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001308 if (full_config && conf->ieee80211n && bss->wpa &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001309 !(bss->wpa_pairwise & WPA_CIPHER_CCMP) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001310 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
1311 WPA_CIPHER_CCMP_256 | WPA_CIPHER_GCMP_256)))
1312 {
Hai Shalom60840252021-02-19 19:02:11 -08001313 bss->disable_11n = true;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001314 wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) with WPA/WPA2 "
1315 "requires CCMP/GCMP to be enabled, disabling HT "
1316 "capabilities");
1317 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001318
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07001319#ifdef CONFIG_IEEE80211AC
Hai Shalomfdcde762020-04-02 11:19:20 -07001320#ifdef CONFIG_WEP
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07001321 if (full_config && conf->ieee80211ac &&
1322 bss->ssid.security_policy == SECURITY_STATIC_WEP) {
Hai Shalom60840252021-02-19 19:02:11 -08001323 bss->disable_11ac = true;
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07001324 wpa_printf(MSG_ERROR,
1325 "VHT (IEEE 802.11ac) with WEP is not allowed, disabling VHT capabilities");
1326 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001327#endif /* CONFIG_WEP */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001328
1329 if (full_config && conf->ieee80211ac && bss->wpa &&
1330 !(bss->wpa_pairwise & WPA_CIPHER_CCMP) &&
1331 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
1332 WPA_CIPHER_CCMP_256 | WPA_CIPHER_GCMP_256)))
1333 {
Hai Shalom60840252021-02-19 19:02:11 -08001334 bss->disable_11ac = true;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001335 wpa_printf(MSG_ERROR,
1336 "VHT (IEEE 802.11ac) with WPA/WPA2 requires CCMP/GCMP to be enabled, disabling VHT capabilities");
1337 }
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07001338#endif /* CONFIG_IEEE80211AC */
1339
Hai Shalom60840252021-02-19 19:02:11 -08001340#ifdef CONFIG_IEEE80211AX
1341#ifdef CONFIG_WEP
1342 if (full_config && conf->ieee80211ax &&
1343 bss->ssid.security_policy == SECURITY_STATIC_WEP) {
1344 bss->disable_11ax = true;
1345 wpa_printf(MSG_ERROR,
1346 "HE (IEEE 802.11ax) with WEP is not allowed, disabling HE capabilities");
1347 }
1348#endif /* CONFIG_WEP */
1349
1350 if (full_config && conf->ieee80211ax && bss->wpa &&
1351 !(bss->wpa_pairwise & WPA_CIPHER_CCMP) &&
1352 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
1353 WPA_CIPHER_CCMP_256 | WPA_CIPHER_GCMP_256)))
1354 {
1355 bss->disable_11ax = true;
1356 wpa_printf(MSG_ERROR,
1357 "HE (IEEE 802.11ax) with WPA/WPA2 requires CCMP/GCMP to be enabled, disabling HE capabilities");
1358 }
1359#endif /* CONFIG_IEEE80211AX */
1360
Dmitry Shmidt15907092014-03-25 10:42:57 -07001361#ifdef CONFIG_WPS
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001362 if (full_config && bss->wps_state && bss->ignore_broadcast_ssid) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001363 wpa_printf(MSG_INFO, "WPS: ignore_broadcast_ssid "
1364 "configuration forced WPS to be disabled");
1365 bss->wps_state = 0;
1366 }
1367
Hai Shalomfdcde762020-04-02 11:19:20 -07001368#ifdef CONFIG_WEP
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001369 if (full_config && bss->wps_state &&
1370 bss->ssid.wep.keys_set && bss->wpa == 0) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001371 wpa_printf(MSG_INFO, "WPS: WEP configuration forced WPS to be "
1372 "disabled");
1373 bss->wps_state = 0;
1374 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001375#endif /* CONFIG_WEP */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001376
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001377 if (full_config && bss->wps_state && bss->wpa &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001378 (!(bss->wpa & 2) ||
Roshan Pius3a1667e2018-07-03 15:17:14 -07001379 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
1380 WPA_CIPHER_CCMP_256 |
1381 WPA_CIPHER_GCMP_256)))) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001382 wpa_printf(MSG_INFO, "WPS: WPA/TKIP configuration without "
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07001383 "WPA2/CCMP/GCMP forced WPS to be disabled");
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001384 bss->wps_state = 0;
1385 }
Dmitry Shmidt15907092014-03-25 10:42:57 -07001386#endif /* CONFIG_WPS */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001387
1388#ifdef CONFIG_HS20
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001389 if (full_config && bss->hs20 &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001390 (!(bss->wpa & 2) ||
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001391 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
1392 WPA_CIPHER_CCMP_256 |
1393 WPA_CIPHER_GCMP_256)))) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001394 wpa_printf(MSG_ERROR, "HS 2.0: WPA2-Enterprise/CCMP "
1395 "configuration is required for Hotspot 2.0 "
1396 "functionality");
1397 return -1;
1398 }
1399#endif /* CONFIG_HS20 */
1400
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001401#ifdef CONFIG_MBO
1402 if (full_config && bss->mbo_enabled && (bss->wpa & 2) &&
1403 bss->ieee80211w == NO_MGMT_FRAME_PROTECTION) {
1404 wpa_printf(MSG_ERROR,
1405 "MBO: PMF needs to be enabled whenever using WPA2 with MBO");
1406 return -1;
1407 }
1408#endif /* CONFIG_MBO */
1409
Hai Shalom74f70d42019-02-11 14:42:39 -08001410#ifdef CONFIG_OCV
1411 if (full_config && bss->ieee80211w == NO_MGMT_FRAME_PROTECTION &&
1412 bss->ocv) {
1413 wpa_printf(MSG_ERROR,
1414 "OCV: PMF needs to be enabled whenever using OCV");
1415 return -1;
1416 }
1417#endif /* CONFIG_OCV */
1418
Hai Shalom899fcc72020-10-19 14:38:18 -07001419#ifdef CONFIG_SAE_PK
1420 if (full_config && hostapd_sae_pk_in_use(bss) &&
1421 hostapd_sae_pk_password_without_pk(bss)) {
1422 wpa_printf(MSG_ERROR,
1423 "SAE-PK: SAE password uses SAE-PK style, but does not have PK configured");
1424 return -1;
1425 }
1426#endif /* CONFIG_SAE_PK */
1427
Hai Shaloma20dcd72022-02-04 13:43:00 -08001428#ifdef CONFIG_FILS
1429 if (full_config && bss->fils_discovery_min_int &&
1430 bss->unsol_bcast_probe_resp_interval) {
1431 wpa_printf(MSG_ERROR,
1432 "Cannot enable both FILS discovery and unsolicited broadcast Probe Response at the same time");
1433 return -1;
1434 }
1435#endif /* CONFIG_FILS */
1436
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001437 return 0;
1438}
1439
1440
Dmitry Shmidt05df46a2015-05-19 11:02:01 -07001441static int hostapd_config_check_cw(struct hostapd_config *conf, int queue)
1442{
1443 int tx_cwmin = conf->tx_queue[queue].cwmin;
1444 int tx_cwmax = conf->tx_queue[queue].cwmax;
1445 int ac_cwmin = conf->wmm_ac_params[queue].cwmin;
1446 int ac_cwmax = conf->wmm_ac_params[queue].cwmax;
1447
1448 if (tx_cwmin > tx_cwmax) {
1449 wpa_printf(MSG_ERROR,
1450 "Invalid TX queue cwMin/cwMax values. cwMin(%d) greater than cwMax(%d)",
1451 tx_cwmin, tx_cwmax);
1452 return -1;
1453 }
1454 if (ac_cwmin > ac_cwmax) {
1455 wpa_printf(MSG_ERROR,
1456 "Invalid WMM AC cwMin/cwMax values. cwMin(%d) greater than cwMax(%d)",
1457 ac_cwmin, ac_cwmax);
1458 return -1;
1459 }
1460 return 0;
1461}
1462
1463
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001464int hostapd_config_check(struct hostapd_config *conf, int full_config)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001465{
1466 size_t i;
1467
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001468 if (full_config && conf->ieee80211d &&
1469 (!conf->country[0] || !conf->country[1])) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001470 wpa_printf(MSG_ERROR, "Cannot enable IEEE 802.11d without "
1471 "setting the country_code");
1472 return -1;
1473 }
1474
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001475 if (full_config && conf->ieee80211h && !conf->ieee80211d) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001476 wpa_printf(MSG_ERROR, "Cannot enable IEEE 802.11h without "
1477 "IEEE 802.11d enabled");
1478 return -1;
1479 }
1480
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001481 if (full_config && conf->local_pwr_constraint != -1 &&
1482 !conf->ieee80211d) {
1483 wpa_printf(MSG_ERROR, "Cannot add Power Constraint element without Country element");
1484 return -1;
1485 }
1486
1487 if (full_config && conf->spectrum_mgmt_required &&
1488 conf->local_pwr_constraint == -1) {
1489 wpa_printf(MSG_ERROR, "Cannot set Spectrum Management bit without Country and Power Constraint elements");
1490 return -1;
1491 }
1492
Hai Shalom81f62d82019-07-22 12:10:00 -07001493#ifdef CONFIG_AIRTIME_POLICY
1494 if (full_config && conf->airtime_mode > AIRTIME_MODE_STATIC &&
1495 !conf->airtime_update_interval) {
1496 wpa_printf(MSG_ERROR, "Airtime update interval cannot be zero");
1497 return -1;
1498 }
1499#endif /* CONFIG_AIRTIME_POLICY */
Dmitry Shmidt05df46a2015-05-19 11:02:01 -07001500 for (i = 0; i < NUM_TX_QUEUES; i++) {
1501 if (hostapd_config_check_cw(conf, i))
1502 return -1;
1503 }
1504
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001505 for (i = 0; i < conf->num_bss; i++) {
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001506 if (hostapd_config_check_bss(conf->bss[i], conf, full_config))
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001507 return -1;
1508 }
1509
1510 return 0;
1511}
1512
1513
Dmitry Shmidt71757432014-06-02 13:50:35 -07001514void hostapd_set_security_params(struct hostapd_bss_config *bss,
1515 int full_config)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001516{
Hai Shalomfdcde762020-04-02 11:19:20 -07001517#ifdef CONFIG_WEP
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001518 if (bss->individual_wep_key_len == 0) {
1519 /* individual keys are not use; can use key idx0 for
1520 * broadcast keys */
1521 bss->broadcast_key_idx_min = 0;
1522 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001523#endif /* CONFIG_WEP */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001524
1525 if ((bss->wpa & 2) && bss->rsn_pairwise == 0)
1526 bss->rsn_pairwise = bss->wpa_pairwise;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001527 if (bss->group_cipher)
1528 bss->wpa_group = bss->group_cipher;
1529 else
1530 bss->wpa_group = wpa_select_ap_group_cipher(bss->wpa,
1531 bss->wpa_pairwise,
1532 bss->rsn_pairwise);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001533 if (!bss->wpa_group_rekey_set)
1534 bss->wpa_group_rekey = bss->wpa_group == WPA_CIPHER_TKIP ?
1535 600 : 86400;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001536
Dmitry Shmidt71757432014-06-02 13:50:35 -07001537 if (full_config) {
1538 bss->radius->auth_server = bss->radius->auth_servers;
1539 bss->radius->acct_server = bss->radius->acct_servers;
1540 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001541
1542 if (bss->wpa && bss->ieee802_1x) {
1543 bss->ssid.security_policy = SECURITY_WPA;
1544 } else if (bss->wpa) {
1545 bss->ssid.security_policy = SECURITY_WPA_PSK;
1546 } else if (bss->ieee802_1x) {
1547 int cipher = WPA_CIPHER_NONE;
1548 bss->ssid.security_policy = SECURITY_IEEE_802_1X;
Hai Shalomfdcde762020-04-02 11:19:20 -07001549#ifdef CONFIG_WEP
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001550 bss->ssid.wep.default_len = bss->default_wep_key_len;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001551 if (full_config && bss->default_wep_key_len) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001552 cipher = bss->default_wep_key_len >= 13 ?
1553 WPA_CIPHER_WEP104 : WPA_CIPHER_WEP40;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001554 } else if (full_config && bss->ssid.wep.keys_set) {
1555 if (bss->ssid.wep.len[0] >= 13)
1556 cipher = WPA_CIPHER_WEP104;
1557 else
1558 cipher = WPA_CIPHER_WEP40;
1559 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001560#endif /* CONFIG_WEP */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001561 bss->wpa_group = cipher;
1562 bss->wpa_pairwise = cipher;
1563 bss->rsn_pairwise = cipher;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001564 if (full_config)
1565 bss->wpa_key_mgmt = WPA_KEY_MGMT_IEEE8021X_NO_WPA;
Hai Shalomfdcde762020-04-02 11:19:20 -07001566#ifdef CONFIG_WEP
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001567 } else if (bss->ssid.wep.keys_set) {
1568 int cipher = WPA_CIPHER_WEP40;
1569 if (bss->ssid.wep.len[0] >= 13)
1570 cipher = WPA_CIPHER_WEP104;
1571 bss->ssid.security_policy = SECURITY_STATIC_WEP;
1572 bss->wpa_group = cipher;
1573 bss->wpa_pairwise = cipher;
1574 bss->rsn_pairwise = cipher;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001575 if (full_config)
1576 bss->wpa_key_mgmt = WPA_KEY_MGMT_NONE;
Hai Shalomfdcde762020-04-02 11:19:20 -07001577#endif /* CONFIG_WEP */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001578 } else if (bss->osen) {
1579 bss->ssid.security_policy = SECURITY_OSEN;
1580 bss->wpa_group = WPA_CIPHER_CCMP;
1581 bss->wpa_pairwise = 0;
1582 bss->rsn_pairwise = WPA_CIPHER_CCMP;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001583 } else {
1584 bss->ssid.security_policy = SECURITY_PLAINTEXT;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001585 if (full_config) {
1586 bss->wpa_group = WPA_CIPHER_NONE;
1587 bss->wpa_pairwise = WPA_CIPHER_NONE;
1588 bss->rsn_pairwise = WPA_CIPHER_NONE;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001589 bss->wpa_key_mgmt = WPA_KEY_MGMT_NONE;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001590 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001591 }
1592}
Hai Shalom74f70d42019-02-11 14:42:39 -08001593
1594
1595int hostapd_sae_pw_id_in_use(struct hostapd_bss_config *conf)
1596{
1597 int with_id = 0, without_id = 0;
1598 struct sae_password_entry *pw;
1599
1600 if (conf->ssid.wpa_passphrase)
1601 without_id = 1;
1602
1603 for (pw = conf->sae_passwords; pw; pw = pw->next) {
1604 if (pw->identifier)
1605 with_id = 1;
1606 else
1607 without_id = 1;
1608 if (with_id && without_id)
1609 break;
1610 }
1611
1612 if (with_id && !without_id)
1613 return 2;
1614 return with_id;
1615}
Hai Shalom899fcc72020-10-19 14:38:18 -07001616
1617
1618bool hostapd_sae_pk_in_use(struct hostapd_bss_config *conf)
1619{
1620#ifdef CONFIG_SAE_PK
1621 struct sae_password_entry *pw;
1622
1623 for (pw = conf->sae_passwords; pw; pw = pw->next) {
1624 if (pw->pk)
1625 return true;
1626 }
1627#endif /* CONFIG_SAE_PK */
1628
1629 return false;
1630}
1631
1632
1633#ifdef CONFIG_SAE_PK
1634bool hostapd_sae_pk_exclusively(struct hostapd_bss_config *conf)
1635{
1636 bool with_pk = false;
1637 struct sae_password_entry *pw;
1638
1639 if (conf->ssid.wpa_passphrase)
1640 return false;
1641
1642 for (pw = conf->sae_passwords; pw; pw = pw->next) {
1643 if (!pw->pk)
1644 return false;
1645 with_pk = true;
1646 }
1647
1648 return with_pk;
1649}
1650#endif /* CONFIG_SAE_PK */