blob: f0e4236940b1664d438475a4f89028e5e24cbd5e [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
124 bss->sae_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;
Dmitry Shmidt29333592017-01-09 12:27:11 -0800134#endif /* CONFIG_FILS */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700135
136 bss->broadcast_deauth = 1;
137
138#ifdef CONFIG_MBO
139 bss->mbo_cell_data_conn_pref = -1;
140#endif /* CONFIG_MBO */
Roshan Pius3a1667e2018-07-03 15:17:14 -0700141
142 /* Disable TLS v1.3 by default for now to avoid interoperability issue.
143 * This can be enabled by default once the implementation has been fully
144 * completed and tested with other implementations. */
145 bss->tls_flags = TLS_CONN_DISABLE_TLSv1_3;
Hai Shalom74f70d42019-02-11 14:42:39 -0800146
Hai Shalomc3565922019-10-28 11:58:20 -0700147 bss->max_auth_rounds = 100;
148 bss->max_auth_rounds_short = 50;
149
Hai Shalom74f70d42019-02-11 14:42:39 -0800150 bss->send_probe_response = 1;
151
152#ifdef CONFIG_HS20
153 bss->hs20_release = (HS20_VERSION >> 4) + 1;
154#endif /* CONFIG_HS20 */
155
Hai Shalom81f62d82019-07-22 12:10:00 -0700156#ifdef CONFIG_MACSEC
157 bss->mka_priority = DEFAULT_PRIO_NOT_KEY_SERVER;
158 bss->macsec_port = 1;
159#endif /* CONFIG_MACSEC */
160
Hai Shalom74f70d42019-02-11 14:42:39 -0800161 /* Default to strict CRL checking. */
162 bss->check_crl_strict = 1;
Hai Shalom899fcc72020-10-19 14:38:18 -0700163
164#ifdef CONFIG_TESTING_OPTIONS
165 bss->sae_commit_status = -1;
166#endif /* CONFIG_TESTING_OPTIONS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700167}
168
169
170struct hostapd_config * hostapd_config_defaults(void)
171{
172#define ecw2cw(ecw) ((1 << (ecw)) - 1)
173
174 struct hostapd_config *conf;
175 struct hostapd_bss_config *bss;
176 const int aCWmin = 4, aCWmax = 10;
177 const struct hostapd_wmm_ac_params ac_bk =
178 { aCWmin, aCWmax, 7, 0, 0 }; /* background traffic */
179 const struct hostapd_wmm_ac_params ac_be =
180 { aCWmin, aCWmax, 3, 0, 0 }; /* best effort traffic */
181 const struct hostapd_wmm_ac_params ac_vi = /* video traffic */
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700182 { aCWmin - 1, aCWmin, 2, 3008 / 32, 0 };
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700183 const struct hostapd_wmm_ac_params ac_vo = /* voice traffic */
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700184 { aCWmin - 2, aCWmin - 1, 2, 1504 / 32, 0 };
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700185 const struct hostapd_tx_queue_params txq_bk =
186 { 7, ecw2cw(aCWmin), ecw2cw(aCWmax), 0 };
187 const struct hostapd_tx_queue_params txq_be =
188 { 3, ecw2cw(aCWmin), 4 * (ecw2cw(aCWmin) + 1) - 1, 0};
189 const struct hostapd_tx_queue_params txq_vi =
190 { 1, (ecw2cw(aCWmin) + 1) / 2 - 1, ecw2cw(aCWmin), 30};
191 const struct hostapd_tx_queue_params txq_vo =
192 { 1, (ecw2cw(aCWmin) + 1) / 4 - 1,
193 (ecw2cw(aCWmin) + 1) / 2 - 1, 15};
194
195#undef ecw2cw
196
197 conf = os_zalloc(sizeof(*conf));
198 bss = os_zalloc(sizeof(*bss));
199 if (conf == NULL || bss == NULL) {
200 wpa_printf(MSG_ERROR, "Failed to allocate memory for "
201 "configuration data.");
202 os_free(conf);
203 os_free(bss);
204 return NULL;
205 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800206 conf->bss = os_calloc(1, sizeof(struct hostapd_bss_config *));
207 if (conf->bss == NULL) {
208 os_free(conf);
209 os_free(bss);
210 return NULL;
211 }
212 conf->bss[0] = bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700213
214 bss->radius = os_zalloc(sizeof(*bss->radius));
215 if (bss->radius == NULL) {
Dmitry Shmidt97672262014-02-03 13:02:54 -0800216 os_free(conf->bss);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700217 os_free(conf);
218 os_free(bss);
219 return NULL;
220 }
221
222 hostapd_config_defaults_bss(bss);
223
224 conf->num_bss = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700225
226 conf->beacon_int = 100;
Hai Shalom021b0b52019-04-10 11:17:58 -0700227 conf->rts_threshold = -2; /* use driver default: 2347 */
228 conf->fragm_threshold = -2; /* user driver default: 2346 */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800229 /* Set to invalid value means do not add Power Constraint IE */
230 conf->local_pwr_constraint = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700231
232 conf->wmm_ac_params[0] = ac_be;
233 conf->wmm_ac_params[1] = ac_bk;
234 conf->wmm_ac_params[2] = ac_vi;
235 conf->wmm_ac_params[3] = ac_vo;
236
237 conf->tx_queue[0] = txq_vo;
238 conf->tx_queue[1] = txq_vi;
239 conf->tx_queue[2] = txq_be;
240 conf->tx_queue[3] = txq_bk;
241
242 conf->ht_capab = HT_CAP_INFO_SMPS_DISABLED;
243
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800244 conf->ap_table_max_size = 255;
245 conf->ap_table_expiration_time = 60;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800246 conf->track_sta_max_age = 180;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800247
Dmitry Shmidt8da800a2013-04-24 12:57:01 -0700248#ifdef CONFIG_TESTING_OPTIONS
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700249 conf->ignore_probe_probability = 0.0;
250 conf->ignore_auth_probability = 0.0;
251 conf->ignore_assoc_probability = 0.0;
252 conf->ignore_reassoc_probability = 0.0;
253 conf->corrupt_gtk_rekey_mic_probability = 0.0;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800254 conf->ecsa_ie_only = 0;
Kai Shie75b0652020-11-24 20:31:29 -0800255 conf->skip_send_eapol = 0;
256 conf->enable_eapol_large_timeout = 0;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -0700257#endif /* CONFIG_TESTING_OPTIONS */
258
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700259 conf->acs = 0;
260 conf->acs_ch_list.num = 0;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700261#ifdef CONFIG_ACS
262 conf->acs_num_scans = 5;
263#endif /* CONFIG_ACS */
264
Hai Shalom81f62d82019-07-22 12:10:00 -0700265#ifdef CONFIG_IEEE80211AX
266 conf->he_op.he_rts_threshold = HE_OPERATION_RTS_THRESHOLD_MASK >>
267 HE_OPERATION_RTS_THRESHOLD_OFFSET;
268 /* Set default basic MCS/NSS set to single stream MCS 0-7 */
269 conf->he_op.he_basic_mcs_nss_set = 0xfffc;
Hai Shalomfdcde762020-04-02 11:19:20 -0700270 conf->he_op.he_bss_color_disabled = 1;
271 conf->he_op.he_bss_color_partial = 0;
272 conf->he_op.he_bss_color = 1;
Hai Shalom81f62d82019-07-22 12:10:00 -0700273#endif /* CONFIG_IEEE80211AX */
274
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700275 /* The third octet of the country string uses an ASCII space character
276 * by default to indicate that the regulations encompass all
277 * environments for the current frequency band in the country. */
278 conf->country[2] = ' ';
279
Hai Shalom74f70d42019-02-11 14:42:39 -0800280 conf->rssi_reject_assoc_rssi = 0;
281 conf->rssi_reject_assoc_timeout = 30;
282
Hai Shalom81f62d82019-07-22 12:10:00 -0700283#ifdef CONFIG_AIRTIME_POLICY
284 conf->airtime_update_interval = AIRTIME_DEFAULT_UPDATE_INTERVAL;
285#endif /* CONFIG_AIRTIME_POLICY */
286
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700287 return conf;
288}
289
290
291int hostapd_mac_comp(const void *a, const void *b)
292{
293 return os_memcmp(a, b, sizeof(macaddr));
294}
295
296
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700297static int hostapd_config_read_wpa_psk(const char *fname,
298 struct hostapd_ssid *ssid)
299{
300 FILE *f;
301 char buf[128], *pos;
Hai Shalom74f70d42019-02-11 14:42:39 -0800302 const char *keyid;
303 char *context;
304 char *context2;
305 char *token;
306 char *name;
307 char *value;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700308 int line = 0, ret = 0, len, ok;
309 u8 addr[ETH_ALEN];
310 struct hostapd_wpa_psk *psk;
311
312 if (!fname)
313 return 0;
314
315 f = fopen(fname, "r");
316 if (!f) {
317 wpa_printf(MSG_ERROR, "WPA PSK file '%s' not found.", fname);
318 return -1;
319 }
320
321 while (fgets(buf, sizeof(buf), f)) {
Hai Shalom021b0b52019-04-10 11:17:58 -0700322 int vlan_id = 0;
Hai Shalomfdcde762020-04-02 11:19:20 -0700323 int wps = 0;
Hai Shalom021b0b52019-04-10 11:17:58 -0700324
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700325 line++;
326
327 if (buf[0] == '#')
328 continue;
329 pos = buf;
330 while (*pos != '\0') {
331 if (*pos == '\n') {
332 *pos = '\0';
333 break;
334 }
335 pos++;
336 }
337 if (buf[0] == '\0')
338 continue;
339
Hai Shalom74f70d42019-02-11 14:42:39 -0800340 context = NULL;
341 keyid = NULL;
342 while ((token = str_token(buf, " ", &context))) {
343 if (!os_strchr(token, '='))
344 break;
345 context2 = NULL;
346 name = str_token(token, "=", &context2);
Hai Shalom021b0b52019-04-10 11:17:58 -0700347 if (!name)
348 break;
Hai Shalom74f70d42019-02-11 14:42:39 -0800349 value = str_token(token, "", &context2);
350 if (!value)
351 value = "";
352 if (!os_strcmp(name, "keyid")) {
353 keyid = value;
Hai Shalomfdcde762020-04-02 11:19:20 -0700354 } else if (!os_strcmp(name, "wps")) {
355 wps = atoi(value);
Hai Shalom021b0b52019-04-10 11:17:58 -0700356 } else if (!os_strcmp(name, "vlanid")) {
357 vlan_id = atoi(value);
Hai Shalom74f70d42019-02-11 14:42:39 -0800358 } else {
359 wpa_printf(MSG_ERROR,
360 "Unrecognized '%s=%s' on line %d in '%s'",
361 name, value, line, fname);
362 ret = -1;
363 break;
364 }
365 }
366
367 if (ret == -1)
368 break;
369
370 if (!token)
371 token = "";
372 if (hwaddr_aton(token, addr)) {
Hai Shalomfdcde762020-04-02 11:19:20 -0700373 wpa_printf(MSG_ERROR,
374 "Invalid MAC address '%s' on line %d in '%s'",
375 token, line, fname);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700376 ret = -1;
377 break;
378 }
379
380 psk = os_zalloc(sizeof(*psk));
381 if (psk == NULL) {
382 wpa_printf(MSG_ERROR, "WPA PSK allocation failed");
383 ret = -1;
384 break;
385 }
Hai Shalom021b0b52019-04-10 11:17:58 -0700386 psk->vlan_id = vlan_id;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700387 if (is_zero_ether_addr(addr))
388 psk->group = 1;
389 else
390 os_memcpy(psk->addr, addr, ETH_ALEN);
391
Hai Shalom74f70d42019-02-11 14:42:39 -0800392 pos = str_token(buf, "", &context);
393 if (!pos) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700394 wpa_printf(MSG_ERROR, "No PSK on line %d in '%s'",
395 line, fname);
396 os_free(psk);
397 ret = -1;
398 break;
399 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700400
401 ok = 0;
402 len = os_strlen(pos);
Hai Shalomfdcde762020-04-02 11:19:20 -0700403 if (len == 2 * PMK_LEN &&
404 hexstr2bin(pos, psk->psk, PMK_LEN) == 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700405 ok = 1;
Hai Shalomfdcde762020-04-02 11:19:20 -0700406 else if (len >= 8 && len < 64 &&
407 pbkdf2_sha1(pos, ssid->ssid, ssid->ssid_len,
408 4096, psk->psk, PMK_LEN) == 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700409 ok = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700410 if (!ok) {
Hai Shalomfdcde762020-04-02 11:19:20 -0700411 wpa_printf(MSG_ERROR,
412 "Invalid PSK '%s' on line %d in '%s'",
413 pos, line, fname);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700414 os_free(psk);
415 ret = -1;
416 break;
417 }
418
Hai Shalom74f70d42019-02-11 14:42:39 -0800419 if (keyid) {
420 len = os_strlcpy(psk->keyid, keyid, sizeof(psk->keyid));
421 if ((size_t) len >= sizeof(psk->keyid)) {
422 wpa_printf(MSG_ERROR,
423 "PSK keyid too long on line %d in '%s'",
424 line, fname);
425 os_free(psk);
426 ret = -1;
427 break;
428 }
429 }
430
Hai Shalomfdcde762020-04-02 11:19:20 -0700431 psk->wps = wps;
432
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700433 psk->next = ssid->wpa_psk;
434 ssid->wpa_psk = psk;
435 }
436
437 fclose(f);
438
439 return ret;
440}
441
442
443static int hostapd_derive_psk(struct hostapd_ssid *ssid)
444{
445 ssid->wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
446 if (ssid->wpa_psk == NULL) {
447 wpa_printf(MSG_ERROR, "Unable to alloc space for PSK");
448 return -1;
449 }
450 wpa_hexdump_ascii(MSG_DEBUG, "SSID",
451 (u8 *) ssid->ssid, ssid->ssid_len);
452 wpa_hexdump_ascii_key(MSG_DEBUG, "PSK (ASCII passphrase)",
453 (u8 *) ssid->wpa_passphrase,
454 os_strlen(ssid->wpa_passphrase));
455 pbkdf2_sha1(ssid->wpa_passphrase,
456 ssid->ssid, ssid->ssid_len,
457 4096, ssid->wpa_psk->psk, PMK_LEN);
458 wpa_hexdump_key(MSG_DEBUG, "PSK (from passphrase)",
459 ssid->wpa_psk->psk, PMK_LEN);
460 return 0;
461}
462
463
Hai Shalomc3565922019-10-28 11:58:20 -0700464int hostapd_setup_sae_pt(struct hostapd_bss_config *conf)
465{
466#ifdef CONFIG_SAE
467 struct hostapd_ssid *ssid = &conf->ssid;
468 struct sae_password_entry *pw;
469
Hai Shalom899fcc72020-10-19 14:38:18 -0700470 if ((conf->sae_pwe == 0 && !hostapd_sae_pw_id_in_use(conf) &&
471 !hostapd_sae_pk_in_use(conf)) ||
Hai Shalomfdcde762020-04-02 11:19:20 -0700472 conf->sae_pwe == 3 ||
473 !wpa_key_mgmt_sae(conf->wpa_key_mgmt))
Hai Shalomc3565922019-10-28 11:58:20 -0700474 return 0; /* PT not needed */
475
476 sae_deinit_pt(ssid->pt);
477 ssid->pt = NULL;
478 if (ssid->wpa_passphrase) {
479 ssid->pt = sae_derive_pt(conf->sae_groups, ssid->ssid,
480 ssid->ssid_len,
481 (const u8 *) ssid->wpa_passphrase,
482 os_strlen(ssid->wpa_passphrase),
483 NULL);
484 if (!ssid->pt)
485 return -1;
486 }
487
488 for (pw = conf->sae_passwords; pw; pw = pw->next) {
489 sae_deinit_pt(pw->pt);
490 pw->pt = sae_derive_pt(conf->sae_groups, ssid->ssid,
491 ssid->ssid_len,
492 (const u8 *) pw->password,
493 os_strlen(pw->password),
494 pw->identifier);
495 if (!pw->pt)
496 return -1;
497 }
498#endif /* CONFIG_SAE */
499
500 return 0;
501}
502
503
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700504int hostapd_setup_wpa_psk(struct hostapd_bss_config *conf)
505{
506 struct hostapd_ssid *ssid = &conf->ssid;
507
Hai Shalomc3565922019-10-28 11:58:20 -0700508 if (hostapd_setup_sae_pt(conf) < 0)
509 return -1;
510
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700511 if (ssid->wpa_passphrase != NULL) {
512 if (ssid->wpa_psk != NULL) {
513 wpa_printf(MSG_DEBUG, "Using pre-configured WPA PSK "
514 "instead of passphrase");
515 } else {
516 wpa_printf(MSG_DEBUG, "Deriving WPA PSK based on "
517 "passphrase");
518 if (hostapd_derive_psk(ssid) < 0)
519 return -1;
520 }
521 ssid->wpa_psk->group = 1;
522 }
523
Dmitry Shmidt29333592017-01-09 12:27:11 -0800524 return hostapd_config_read_wpa_psk(ssid->wpa_psk_file, &conf->ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700525}
526
527
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700528static void hostapd_config_free_radius(struct hostapd_radius_server *servers,
529 int num_servers)
530{
531 int i;
532
533 for (i = 0; i < num_servers; i++) {
534 os_free(servers[i].shared_secret);
535 }
536 os_free(servers);
537}
538
539
Dmitry Shmidt04949592012-07-19 12:16:46 -0700540struct hostapd_radius_attr *
541hostapd_config_get_radius_attr(struct hostapd_radius_attr *attr, u8 type)
542{
543 for (; attr; attr = attr->next) {
544 if (attr->type == type)
545 return attr;
546 }
547 return NULL;
548}
549
550
Hai Shalomc3565922019-10-28 11:58:20 -0700551struct hostapd_radius_attr * hostapd_parse_radius_attr(const char *value)
552{
553 const char *pos;
554 char syntax;
555 struct hostapd_radius_attr *attr;
556 size_t len;
557
558 attr = os_zalloc(sizeof(*attr));
559 if (!attr)
560 return NULL;
561
562 attr->type = atoi(value);
563
564 pos = os_strchr(value, ':');
565 if (!pos) {
566 attr->val = wpabuf_alloc(1);
567 if (!attr->val) {
568 os_free(attr);
569 return NULL;
570 }
571 wpabuf_put_u8(attr->val, 0);
572 return attr;
573 }
574
575 pos++;
576 if (pos[0] == '\0' || pos[1] != ':') {
577 os_free(attr);
578 return NULL;
579 }
580 syntax = *pos++;
581 pos++;
582
583 switch (syntax) {
584 case 's':
585 attr->val = wpabuf_alloc_copy(pos, os_strlen(pos));
586 break;
587 case 'x':
588 len = os_strlen(pos);
589 if (len & 1)
590 break;
591 len /= 2;
592 attr->val = wpabuf_alloc(len);
593 if (!attr->val)
594 break;
595 if (hexstr2bin(pos, wpabuf_put(attr->val, len), len) < 0) {
596 wpabuf_free(attr->val);
597 os_free(attr);
598 return NULL;
599 }
600 break;
601 case 'd':
602 attr->val = wpabuf_alloc(4);
603 if (attr->val)
604 wpabuf_put_be32(attr->val, atoi(pos));
605 break;
606 default:
607 os_free(attr);
608 return NULL;
609 }
610
611 if (!attr->val) {
612 os_free(attr);
613 return NULL;
614 }
615
616 return attr;
617}
618
619
620void hostapd_config_free_radius_attr(struct hostapd_radius_attr *attr)
Dmitry Shmidt04949592012-07-19 12:16:46 -0700621{
622 struct hostapd_radius_attr *prev;
623
624 while (attr) {
625 prev = attr;
626 attr = attr->next;
627 wpabuf_free(prev->val);
628 os_free(prev);
629 }
630}
631
632
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700633void hostapd_config_free_eap_user(struct hostapd_eap_user *user)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700634{
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700635 hostapd_config_free_radius_attr(user->accept_attr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700636 os_free(user->identity);
Dmitry Shmidtc2817022014-07-02 10:32:10 -0700637 bin_clear_free(user->password, user->password_len);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700638 bin_clear_free(user->salt, user->salt_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700639 os_free(user);
640}
641
642
Dmitry Shmidt29333592017-01-09 12:27:11 -0800643void hostapd_config_free_eap_users(struct hostapd_eap_user *user)
644{
645 struct hostapd_eap_user *prev_user;
646
647 while (user) {
648 prev_user = user;
649 user = user->next;
650 hostapd_config_free_eap_user(prev_user);
651 }
652}
653
654
Hai Shalomfdcde762020-04-02 11:19:20 -0700655#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700656static void hostapd_config_free_wep(struct hostapd_wep_keys *keys)
657{
658 int i;
659 for (i = 0; i < NUM_WEP_KEYS; i++) {
Dmitry Shmidtc2817022014-07-02 10:32:10 -0700660 bin_clear_free(keys->key[i], keys->len[i]);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700661 keys->key[i] = NULL;
662 }
663}
Hai Shalomfdcde762020-04-02 11:19:20 -0700664#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700665
666
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800667void hostapd_config_clear_wpa_psk(struct hostapd_wpa_psk **l)
668{
669 struct hostapd_wpa_psk *psk, *tmp;
670
671 for (psk = *l; psk;) {
672 tmp = psk;
673 psk = psk->next;
674 bin_clear_free(tmp, sizeof(*tmp));
675 }
676 *l = NULL;
677}
678
679
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800680static void hostapd_config_free_anqp_elem(struct hostapd_bss_config *conf)
681{
682 struct anqp_element *elem;
683
684 while ((elem = dl_list_first(&conf->anqp_elem, struct anqp_element,
685 list))) {
686 dl_list_del(&elem->list);
687 wpabuf_free(elem->payload);
688 os_free(elem);
689 }
690}
691
692
Dmitry Shmidt29333592017-01-09 12:27:11 -0800693static void hostapd_config_free_fils_realms(struct hostapd_bss_config *conf)
694{
695#ifdef CONFIG_FILS
696 struct fils_realm *realm;
697
698 while ((realm = dl_list_first(&conf->fils_realms, struct fils_realm,
699 list))) {
700 dl_list_del(&realm->list);
701 os_free(realm);
702 }
703#endif /* CONFIG_FILS */
704}
705
706
Roshan Pius3a1667e2018-07-03 15:17:14 -0700707static void hostapd_config_free_sae_passwords(struct hostapd_bss_config *conf)
708{
709 struct sae_password_entry *pw, *tmp;
710
711 pw = conf->sae_passwords;
712 conf->sae_passwords = NULL;
713 while (pw) {
714 tmp = pw;
715 pw = pw->next;
716 str_clear_free(tmp->password);
717 os_free(tmp->identifier);
Hai Shalomc3565922019-10-28 11:58:20 -0700718#ifdef CONFIG_SAE
719 sae_deinit_pt(tmp->pt);
720#endif /* CONFIG_SAE */
Hai Shalom899fcc72020-10-19 14:38:18 -0700721#ifdef CONFIG_SAE_PK
722 sae_deinit_pk(tmp->pk);
723#endif /* CONFIG_SAE_PK */
Roshan Pius3a1667e2018-07-03 15:17:14 -0700724 os_free(tmp);
725 }
726}
727
728
Hai Shalom81f62d82019-07-22 12:10:00 -0700729#ifdef CONFIG_DPP2
730static void hostapd_dpp_controller_conf_free(struct dpp_controller_conf *conf)
731{
732 struct dpp_controller_conf *prev;
733
734 while (conf) {
735 prev = conf;
736 conf = conf->next;
737 os_free(prev);
738 }
739}
740#endif /* CONFIG_DPP2 */
741
742
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800743void hostapd_config_free_bss(struct hostapd_bss_config *conf)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700744{
Hai Shalom81f62d82019-07-22 12:10:00 -0700745#if defined(CONFIG_WPS) || defined(CONFIG_HS20)
746 size_t i;
747#endif
748
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700749 if (conf == NULL)
750 return;
751
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800752 hostapd_config_clear_wpa_psk(&conf->ssid.wpa_psk);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700753
Dmitry Shmidtc2817022014-07-02 10:32:10 -0700754 str_clear_free(conf->ssid.wpa_passphrase);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700755 os_free(conf->ssid.wpa_psk_file);
Hai Shalomfdcde762020-04-02 11:19:20 -0700756#ifdef CONFIG_WEP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700757 hostapd_config_free_wep(&conf->ssid.wep);
Hai Shalomfdcde762020-04-02 11:19:20 -0700758#endif /* CONFIG_WEP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700759#ifdef CONFIG_FULL_DYNAMIC_VLAN
760 os_free(conf->ssid.vlan_tagged_interface);
761#endif /* CONFIG_FULL_DYNAMIC_VLAN */
Hai Shalomc3565922019-10-28 11:58:20 -0700762#ifdef CONFIG_SAE
763 sae_deinit_pt(conf->ssid.pt);
764#endif /* CONFIG_SAE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700765
Dmitry Shmidt29333592017-01-09 12:27:11 -0800766 hostapd_config_free_eap_users(conf->eap_user);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800767 os_free(conf->eap_user_sqlite);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700768
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700769 os_free(conf->eap_req_id_text);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800770 os_free(conf->erp_domain);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700771 os_free(conf->accept_mac);
772 os_free(conf->deny_mac);
773 os_free(conf->nas_identifier);
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800774 if (conf->radius) {
775 hostapd_config_free_radius(conf->radius->auth_servers,
776 conf->radius->num_auth_servers);
777 hostapd_config_free_radius(conf->radius->acct_servers,
778 conf->radius->num_acct_servers);
779 }
Dmitry Shmidt04949592012-07-19 12:16:46 -0700780 hostapd_config_free_radius_attr(conf->radius_auth_req_attr);
781 hostapd_config_free_radius_attr(conf->radius_acct_req_attr);
Hai Shalomc3565922019-10-28 11:58:20 -0700782 os_free(conf->radius_req_attr_sqlite);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700783 os_free(conf->rsn_preauth_interfaces);
784 os_free(conf->ctrl_interface);
785 os_free(conf->ca_cert);
786 os_free(conf->server_cert);
Hai Shalom81f62d82019-07-22 12:10:00 -0700787 os_free(conf->server_cert2);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700788 os_free(conf->private_key);
Hai Shalom81f62d82019-07-22 12:10:00 -0700789 os_free(conf->private_key2);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700790 os_free(conf->private_key_passwd);
Hai Shalom81f62d82019-07-22 12:10:00 -0700791 os_free(conf->private_key_passwd2);
Hai Shalom021b0b52019-04-10 11:17:58 -0700792 os_free(conf->check_cert_subject);
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700793 os_free(conf->ocsp_stapling_response);
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -0800794 os_free(conf->ocsp_stapling_response_multi);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700795 os_free(conf->dh_file);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800796 os_free(conf->openssl_ciphers);
Hai Shalom74f70d42019-02-11 14:42:39 -0800797 os_free(conf->openssl_ecdh_curves);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700798 os_free(conf->pac_opaque_encr_key);
799 os_free(conf->eap_fast_a_id);
800 os_free(conf->eap_fast_a_id_info);
801 os_free(conf->eap_sim_db);
802 os_free(conf->radius_server_clients);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700803 os_free(conf->radius);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700804 os_free(conf->radius_das_shared_secret);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700805 hostapd_config_free_vlan(conf);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800806 os_free(conf->time_zone);
807
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800808#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700809 {
810 struct ft_remote_r0kh *r0kh, *r0kh_prev;
811 struct ft_remote_r1kh *r1kh, *r1kh_prev;
812
813 r0kh = conf->r0kh_list;
814 conf->r0kh_list = NULL;
815 while (r0kh) {
816 r0kh_prev = r0kh;
817 r0kh = r0kh->next;
818 os_free(r0kh_prev);
819 }
820
821 r1kh = conf->r1kh_list;
822 conf->r1kh_list = NULL;
823 while (r1kh) {
824 r1kh_prev = r1kh;
825 r1kh = r1kh->next;
826 os_free(r1kh_prev);
827 }
828 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800829#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700830
831#ifdef CONFIG_WPS
832 os_free(conf->wps_pin_requests);
833 os_free(conf->device_name);
834 os_free(conf->manufacturer);
835 os_free(conf->model_name);
836 os_free(conf->model_number);
837 os_free(conf->serial_number);
838 os_free(conf->config_methods);
839 os_free(conf->ap_pin);
840 os_free(conf->extra_cred);
841 os_free(conf->ap_settings);
Hai Shalom021b0b52019-04-10 11:17:58 -0700842 hostapd_config_clear_wpa_psk(&conf->multi_ap_backhaul_ssid.wpa_psk);
843 str_clear_free(conf->multi_ap_backhaul_ssid.wpa_passphrase);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700844 os_free(conf->upnp_iface);
845 os_free(conf->friendly_name);
846 os_free(conf->manufacturer_url);
847 os_free(conf->model_description);
848 os_free(conf->model_url);
849 os_free(conf->upc);
Hai Shalom81f62d82019-07-22 12:10:00 -0700850 for (i = 0; i < MAX_WPS_VENDOR_EXTENSIONS; i++)
851 wpabuf_free(conf->wps_vendor_ext[i]);
Hai Shalomfdcde762020-04-02 11:19:20 -0700852 wpabuf_free(conf->wps_application_ext);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700853 wpabuf_free(conf->wps_nfc_dh_pubkey);
854 wpabuf_free(conf->wps_nfc_dh_privkey);
855 wpabuf_free(conf->wps_nfc_dev_pw);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700856#endif /* CONFIG_WPS */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800857
858 os_free(conf->roaming_consortium);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700859 os_free(conf->venue_name);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700860 os_free(conf->venue_url);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700861 os_free(conf->nai_realm_data);
862 os_free(conf->network_auth_type);
863 os_free(conf->anqp_3gpp_cell_net);
864 os_free(conf->domain_name);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800865 hostapd_config_free_anqp_elem(conf);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800866
867#ifdef CONFIG_RADIUS_TEST
868 os_free(conf->dump_msk_file);
869#endif /* CONFIG_RADIUS_TEST */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700870
871#ifdef CONFIG_HS20
872 os_free(conf->hs20_oper_friendly_name);
873 os_free(conf->hs20_wan_metrics);
874 os_free(conf->hs20_connection_capability);
875 os_free(conf->hs20_operating_class);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800876 os_free(conf->hs20_icons);
877 if (conf->hs20_osu_providers) {
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800878 for (i = 0; i < conf->hs20_osu_providers_count; i++) {
879 struct hs20_osu_provider *p;
880 size_t j;
881 p = &conf->hs20_osu_providers[i];
882 os_free(p->friendly_name);
883 os_free(p->server_uri);
884 os_free(p->method_list);
885 for (j = 0; j < p->icons_count; j++)
886 os_free(p->icons[j]);
887 os_free(p->icons);
888 os_free(p->osu_nai);
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800889 os_free(p->osu_nai2);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800890 os_free(p->service_desc);
891 }
892 os_free(conf->hs20_osu_providers);
893 }
Roshan Pius3a1667e2018-07-03 15:17:14 -0700894 if (conf->hs20_operator_icon) {
Roshan Pius3a1667e2018-07-03 15:17:14 -0700895 for (i = 0; i < conf->hs20_operator_icon_count; i++)
896 os_free(conf->hs20_operator_icon[i]);
897 os_free(conf->hs20_operator_icon);
898 }
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800899 os_free(conf->subscr_remediation_url);
Hai Shalom74f70d42019-02-11 14:42:39 -0800900 os_free(conf->hs20_sim_provisioning_url);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700901 os_free(conf->t_c_filename);
902 os_free(conf->t_c_server_url);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700903#endif /* CONFIG_HS20 */
904
905 wpabuf_free(conf->vendor_elements);
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700906 wpabuf_free(conf->assocresp_elements);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800907
908 os_free(conf->sae_groups);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700909#ifdef CONFIG_OWE
910 os_free(conf->owe_groups);
911#endif /* CONFIG_OWE */
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700912
Dmitry Shmidt0207e232014-09-03 14:58:37 -0700913 os_free(conf->wowlan_triggers);
914
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700915 os_free(conf->server_id);
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800916
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800917#ifdef CONFIG_TESTING_OPTIONS
918 wpabuf_free(conf->own_ie_override);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700919 wpabuf_free(conf->sae_commit_override);
Hai Shalomfdcde762020-04-02 11:19:20 -0700920 wpabuf_free(conf->rsne_override_eapol);
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800921 wpabuf_free(conf->rsnxe_override_eapol);
Hai Shalomfdcde762020-04-02 11:19:20 -0700922 wpabuf_free(conf->rsne_override_ft);
923 wpabuf_free(conf->rsnxe_override_ft);
924 wpabuf_free(conf->gtk_rsc_override);
925 wpabuf_free(conf->igtk_rsc_override);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800926#endif /* CONFIG_TESTING_OPTIONS */
927
928 os_free(conf->no_probe_resp_if_seen_on);
929 os_free(conf->no_auth_if_seen_on);
930
Dmitry Shmidt29333592017-01-09 12:27:11 -0800931 hostapd_config_free_fils_realms(conf);
932
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700933#ifdef CONFIG_DPP
Hai Shalomc3565922019-10-28 11:58:20 -0700934 os_free(conf->dpp_name);
935 os_free(conf->dpp_mud_url);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700936 os_free(conf->dpp_connector);
937 wpabuf_free(conf->dpp_netaccesskey);
938 wpabuf_free(conf->dpp_csign);
Hai Shalom81f62d82019-07-22 12:10:00 -0700939#ifdef CONFIG_DPP2
940 hostapd_dpp_controller_conf_free(conf->dpp_controller);
941#endif /* CONFIG_DPP2 */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700942#endif /* CONFIG_DPP */
943
Roshan Pius3a1667e2018-07-03 15:17:14 -0700944 hostapd_config_free_sae_passwords(conf);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700945
Hai Shalom81f62d82019-07-22 12:10:00 -0700946#ifdef CONFIG_AIRTIME_POLICY
947 {
948 struct airtime_sta_weight *wt, *wt_prev;
949
950 wt = conf->airtime_weight_list;
951 conf->airtime_weight_list = NULL;
952 while (wt) {
953 wt_prev = wt;
954 wt = wt->next;
955 os_free(wt_prev);
956 }
957 }
958#endif /* CONFIG_AIRTIME_POLICY */
959
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800960 os_free(conf);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700961}
962
963
964/**
965 * hostapd_config_free - Free hostapd configuration
966 * @conf: Configuration data from hostapd_config_read().
967 */
968void hostapd_config_free(struct hostapd_config *conf)
969{
970 size_t i;
971
972 if (conf == NULL)
973 return;
974
975 for (i = 0; i < conf->num_bss; i++)
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800976 hostapd_config_free_bss(conf->bss[i]);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700977 os_free(conf->bss);
978 os_free(conf->supported_rates);
979 os_free(conf->basic_rates);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700980 os_free(conf->acs_ch_list.range);
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800981 os_free(conf->acs_freq_list.range);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800982 os_free(conf->driver_params);
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800983#ifdef CONFIG_ACS
984 os_free(conf->acs_chan_bias);
985#endif /* CONFIG_ACS */
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700986 wpabuf_free(conf->lci);
987 wpabuf_free(conf->civic);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700988
989 os_free(conf);
990}
991
992
993/**
994 * hostapd_maclist_found - Find a MAC address from a list
995 * @list: MAC address list
996 * @num_entries: Number of addresses in the list
997 * @addr: Address to search for
998 * @vlan_id: Buffer for returning VLAN ID or %NULL if not needed
999 * Returns: 1 if address is in the list or 0 if not.
1000 *
1001 * Perform a binary search for given MAC address from a pre-sorted list.
1002 */
1003int hostapd_maclist_found(struct mac_acl_entry *list, int num_entries,
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001004 const u8 *addr, struct vlan_description *vlan_id)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001005{
1006 int start, end, middle, res;
1007
1008 start = 0;
1009 end = num_entries - 1;
1010
1011 while (start <= end) {
1012 middle = (start + end) / 2;
1013 res = os_memcmp(list[middle].addr, addr, ETH_ALEN);
1014 if (res == 0) {
1015 if (vlan_id)
1016 *vlan_id = list[middle].vlan_id;
1017 return 1;
1018 }
1019 if (res < 0)
1020 start = middle + 1;
1021 else
1022 end = middle - 1;
1023 }
1024
1025 return 0;
1026}
1027
1028
1029int hostapd_rate_found(int *list, int rate)
1030{
1031 int i;
1032
1033 if (list == NULL)
1034 return 0;
1035
1036 for (i = 0; list[i] >= 0; i++)
1037 if (list[i] == rate)
1038 return 1;
1039
1040 return 0;
1041}
1042
1043
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001044int hostapd_vlan_valid(struct hostapd_vlan *vlan,
1045 struct vlan_description *vlan_desc)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001046{
1047 struct hostapd_vlan *v = vlan;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001048 int i;
1049
1050 if (!vlan_desc->notempty || vlan_desc->untagged < 0 ||
1051 vlan_desc->untagged > MAX_VLAN_ID)
1052 return 0;
1053 for (i = 0; i < MAX_NUM_TAGGED_VLAN; i++) {
1054 if (vlan_desc->tagged[i] < 0 ||
1055 vlan_desc->tagged[i] > MAX_VLAN_ID)
1056 return 0;
1057 }
1058 if (!vlan_desc->untagged && !vlan_desc->tagged[0])
1059 return 0;
1060
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001061 while (v) {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001062 if (!vlan_compare(&v->vlan_desc, vlan_desc) ||
1063 v->vlan_id == VLAN_ID_WILDCARD)
Dmitry Shmidt34af3062013-07-11 10:46:32 -07001064 return 1;
1065 v = v->next;
1066 }
1067 return 0;
1068}
1069
1070
1071const char * hostapd_get_vlan_id_ifname(struct hostapd_vlan *vlan, int vlan_id)
1072{
1073 struct hostapd_vlan *v = vlan;
1074 while (v) {
1075 if (v->vlan_id == vlan_id)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001076 return v->ifname;
1077 v = v->next;
1078 }
1079 return NULL;
1080}
1081
1082
1083const u8 * hostapd_get_psk(const struct hostapd_bss_config *conf,
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001084 const u8 *addr, const u8 *p2p_dev_addr,
Hai Shalom021b0b52019-04-10 11:17:58 -07001085 const u8 *prev_psk, int *vlan_id)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001086{
1087 struct hostapd_wpa_psk *psk;
1088 int next_ok = prev_psk == NULL;
1089
Hai Shalom021b0b52019-04-10 11:17:58 -07001090 if (vlan_id)
1091 *vlan_id = 0;
1092
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001093 if (p2p_dev_addr && !is_zero_ether_addr(p2p_dev_addr)) {
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001094 wpa_printf(MSG_DEBUG, "Searching a PSK for " MACSTR
1095 " p2p_dev_addr=" MACSTR " prev_psk=%p",
1096 MAC2STR(addr), MAC2STR(p2p_dev_addr), prev_psk);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -07001097 addr = NULL; /* Use P2P Device Address for matching */
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001098 } else {
1099 wpa_printf(MSG_DEBUG, "Searching a PSK for " MACSTR
1100 " prev_psk=%p",
1101 MAC2STR(addr), prev_psk);
1102 }
1103
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001104 for (psk = conf->ssid.wpa_psk; psk != NULL; psk = psk->next) {
1105 if (next_ok &&
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001106 (psk->group ||
1107 (addr && os_memcmp(psk->addr, addr, ETH_ALEN) == 0) ||
1108 (!addr && p2p_dev_addr &&
1109 os_memcmp(psk->p2p_dev_addr, p2p_dev_addr, ETH_ALEN) ==
Hai Shalom021b0b52019-04-10 11:17:58 -07001110 0))) {
1111 if (vlan_id)
1112 *vlan_id = psk->vlan_id;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001113 return psk->psk;
Hai Shalom021b0b52019-04-10 11:17:58 -07001114 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001115
1116 if (psk->psk == prev_psk)
1117 next_ok = 1;
1118 }
1119
1120 return NULL;
1121}
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001122
1123
Hai Shalom899fcc72020-10-19 14:38:18 -07001124#ifdef CONFIG_SAE_PK
1125static bool hostapd_sae_pk_password_without_pk(struct hostapd_bss_config *bss)
1126{
1127 struct sae_password_entry *pw;
1128 bool res = false;
1129
1130 if (bss->ssid.wpa_passphrase &&
1131#ifdef CONFIG_TESTING_OPTIONS
1132 !bss->sae_pk_password_check_skip &&
1133#endif /* CONFIG_TESTING_OPTIONS */
1134 sae_pk_valid_password(bss->ssid.wpa_passphrase))
1135 res = true;
1136
1137 for (pw = bss->sae_passwords; pw; pw = pw->next) {
1138 if (!pw->pk &&
1139#ifdef CONFIG_TESTING_OPTIONS
1140 !bss->sae_pk_password_check_skip &&
1141#endif /* CONFIG_TESTING_OPTIONS */
1142 sae_pk_valid_password(pw->password))
1143 return true;
1144
1145 if (bss->ssid.wpa_passphrase && res && pw->pk &&
1146 os_strcmp(bss->ssid.wpa_passphrase, pw->password) == 0)
1147 res = false;
1148 }
1149
1150 return res;
1151}
1152#endif /* CONFIG_SAE_PK */
1153
1154
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001155static int hostapd_config_check_bss(struct hostapd_bss_config *bss,
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001156 struct hostapd_config *conf,
1157 int full_config)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001158{
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001159 if (full_config && bss->ieee802_1x && !bss->eap_server &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001160 !bss->radius->auth_servers) {
1161 wpa_printf(MSG_ERROR, "Invalid IEEE 802.1X configuration (no "
1162 "EAP authenticator configured).");
1163 return -1;
1164 }
1165
Hai Shalomfdcde762020-04-02 11:19:20 -07001166#ifdef CONFIG_WEP
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001167 if (bss->wpa) {
1168 int wep, i;
1169
1170 wep = bss->default_wep_key_len > 0 ||
1171 bss->individual_wep_key_len > 0;
1172 for (i = 0; i < NUM_WEP_KEYS; i++) {
1173 if (bss->ssid.wep.keys_set) {
1174 wep = 1;
1175 break;
1176 }
1177 }
1178
1179 if (wep) {
1180 wpa_printf(MSG_ERROR, "WEP configuration in a WPA network is not supported");
1181 return -1;
1182 }
1183 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001184#endif /* CONFIG_WEP */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001185
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001186 if (full_config && bss->wpa &&
1187 bss->wpa_psk_radius != PSK_RADIUS_IGNORED &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001188 bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH) {
1189 wpa_printf(MSG_ERROR, "WPA-PSK using RADIUS enabled, but no "
1190 "RADIUS checking (macaddr_acl=2) enabled.");
1191 return -1;
1192 }
1193
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001194 if (full_config && bss->wpa && (bss->wpa_key_mgmt & WPA_KEY_MGMT_PSK) &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001195 bss->ssid.wpa_psk == NULL && bss->ssid.wpa_passphrase == NULL &&
1196 bss->ssid.wpa_psk_file == NULL &&
1197 (bss->wpa_psk_radius != PSK_RADIUS_REQUIRED ||
1198 bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH)) {
1199 wpa_printf(MSG_ERROR, "WPA-PSK enabled, but PSK or passphrase "
1200 "is not configured.");
1201 return -1;
1202 }
1203
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001204 if (full_config && !is_zero_ether_addr(bss->bssid)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001205 size_t i;
1206
1207 for (i = 0; i < conf->num_bss; i++) {
1208 if (conf->bss[i] != bss &&
1209 (hostapd_mac_comp(conf->bss[i]->bssid,
1210 bss->bssid) == 0)) {
1211 wpa_printf(MSG_ERROR, "Duplicate BSSID " MACSTR
1212 " on interface '%s' and '%s'.",
1213 MAC2STR(bss->bssid),
1214 conf->bss[i]->iface, bss->iface);
1215 return -1;
1216 }
1217 }
1218 }
1219
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001220#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001221 if (full_config && wpa_key_mgmt_ft(bss->wpa_key_mgmt) &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001222 (bss->nas_identifier == NULL ||
1223 os_strlen(bss->nas_identifier) < 1 ||
1224 os_strlen(bss->nas_identifier) > FT_R0KH_ID_MAX_LEN)) {
1225 wpa_printf(MSG_ERROR, "FT (IEEE 802.11r) requires "
1226 "nas_identifier to be configured as a 1..48 octet "
1227 "string");
1228 return -1;
1229 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001230#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001231
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001232 if (full_config && conf->ieee80211n &&
1233 conf->hw_mode == HOSTAPD_MODE_IEEE80211B) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001234 bss->disable_11n = 1;
1235 wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) in 11b mode is not "
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001236 "allowed, disabling HT capabilities");
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001237 }
1238
Hai Shalomfdcde762020-04-02 11:19:20 -07001239#ifdef CONFIG_WEP
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001240 if (full_config && conf->ieee80211n &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001241 bss->ssid.security_policy == SECURITY_STATIC_WEP) {
1242 bss->disable_11n = 1;
1243 wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) with WEP is not "
1244 "allowed, disabling HT capabilities");
1245 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001246#endif /* CONFIG_WEP */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001247
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001248 if (full_config && conf->ieee80211n && bss->wpa &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001249 !(bss->wpa_pairwise & WPA_CIPHER_CCMP) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001250 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
1251 WPA_CIPHER_CCMP_256 | WPA_CIPHER_GCMP_256)))
1252 {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001253 bss->disable_11n = 1;
1254 wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) with WPA/WPA2 "
1255 "requires CCMP/GCMP to be enabled, disabling HT "
1256 "capabilities");
1257 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001258
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07001259#ifdef CONFIG_IEEE80211AC
Hai Shalomfdcde762020-04-02 11:19:20 -07001260#ifdef CONFIG_WEP
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07001261 if (full_config && conf->ieee80211ac &&
1262 bss->ssid.security_policy == SECURITY_STATIC_WEP) {
1263 bss->disable_11ac = 1;
1264 wpa_printf(MSG_ERROR,
1265 "VHT (IEEE 802.11ac) with WEP is not allowed, disabling VHT capabilities");
1266 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001267#endif /* CONFIG_WEP */
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001268
1269 if (full_config && conf->ieee80211ac && bss->wpa &&
1270 !(bss->wpa_pairwise & WPA_CIPHER_CCMP) &&
1271 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
1272 WPA_CIPHER_CCMP_256 | WPA_CIPHER_GCMP_256)))
1273 {
1274 bss->disable_11ac = 1;
1275 wpa_printf(MSG_ERROR,
1276 "VHT (IEEE 802.11ac) with WPA/WPA2 requires CCMP/GCMP to be enabled, disabling VHT capabilities");
1277 }
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -07001278#endif /* CONFIG_IEEE80211AC */
1279
Dmitry Shmidt15907092014-03-25 10:42:57 -07001280#ifdef CONFIG_WPS
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001281 if (full_config && bss->wps_state && bss->ignore_broadcast_ssid) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001282 wpa_printf(MSG_INFO, "WPS: ignore_broadcast_ssid "
1283 "configuration forced WPS to be disabled");
1284 bss->wps_state = 0;
1285 }
1286
Hai Shalomfdcde762020-04-02 11:19:20 -07001287#ifdef CONFIG_WEP
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001288 if (full_config && bss->wps_state &&
1289 bss->ssid.wep.keys_set && bss->wpa == 0) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001290 wpa_printf(MSG_INFO, "WPS: WEP configuration forced WPS to be "
1291 "disabled");
1292 bss->wps_state = 0;
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->wps_state && bss->wpa &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001297 (!(bss->wpa & 2) ||
Roshan Pius3a1667e2018-07-03 15:17:14 -07001298 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
1299 WPA_CIPHER_CCMP_256 |
1300 WPA_CIPHER_GCMP_256)))) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001301 wpa_printf(MSG_INFO, "WPS: WPA/TKIP configuration without "
Dmitry Shmidt1d755d02015-04-28 10:34:29 -07001302 "WPA2/CCMP/GCMP forced WPS to be disabled");
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001303 bss->wps_state = 0;
1304 }
Dmitry Shmidt15907092014-03-25 10:42:57 -07001305#endif /* CONFIG_WPS */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001306
1307#ifdef CONFIG_HS20
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001308 if (full_config && bss->hs20 &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001309 (!(bss->wpa & 2) ||
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001310 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
1311 WPA_CIPHER_CCMP_256 |
1312 WPA_CIPHER_GCMP_256)))) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001313 wpa_printf(MSG_ERROR, "HS 2.0: WPA2-Enterprise/CCMP "
1314 "configuration is required for Hotspot 2.0 "
1315 "functionality");
1316 return -1;
1317 }
1318#endif /* CONFIG_HS20 */
1319
Dmitry Shmidt57c2d392016-02-23 13:40:19 -08001320#ifdef CONFIG_MBO
1321 if (full_config && bss->mbo_enabled && (bss->wpa & 2) &&
1322 bss->ieee80211w == NO_MGMT_FRAME_PROTECTION) {
1323 wpa_printf(MSG_ERROR,
1324 "MBO: PMF needs to be enabled whenever using WPA2 with MBO");
1325 return -1;
1326 }
1327#endif /* CONFIG_MBO */
1328
Hai Shalom74f70d42019-02-11 14:42:39 -08001329#ifdef CONFIG_OCV
1330 if (full_config && bss->ieee80211w == NO_MGMT_FRAME_PROTECTION &&
1331 bss->ocv) {
1332 wpa_printf(MSG_ERROR,
1333 "OCV: PMF needs to be enabled whenever using OCV");
1334 return -1;
1335 }
1336#endif /* CONFIG_OCV */
1337
Hai Shalom899fcc72020-10-19 14:38:18 -07001338#ifdef CONFIG_SAE_PK
1339 if (full_config && hostapd_sae_pk_in_use(bss) &&
1340 hostapd_sae_pk_password_without_pk(bss)) {
1341 wpa_printf(MSG_ERROR,
1342 "SAE-PK: SAE password uses SAE-PK style, but does not have PK configured");
1343 return -1;
1344 }
1345#endif /* CONFIG_SAE_PK */
1346
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001347 return 0;
1348}
1349
1350
Dmitry Shmidt05df46a2015-05-19 11:02:01 -07001351static int hostapd_config_check_cw(struct hostapd_config *conf, int queue)
1352{
1353 int tx_cwmin = conf->tx_queue[queue].cwmin;
1354 int tx_cwmax = conf->tx_queue[queue].cwmax;
1355 int ac_cwmin = conf->wmm_ac_params[queue].cwmin;
1356 int ac_cwmax = conf->wmm_ac_params[queue].cwmax;
1357
1358 if (tx_cwmin > tx_cwmax) {
1359 wpa_printf(MSG_ERROR,
1360 "Invalid TX queue cwMin/cwMax values. cwMin(%d) greater than cwMax(%d)",
1361 tx_cwmin, tx_cwmax);
1362 return -1;
1363 }
1364 if (ac_cwmin > ac_cwmax) {
1365 wpa_printf(MSG_ERROR,
1366 "Invalid WMM AC cwMin/cwMax values. cwMin(%d) greater than cwMax(%d)",
1367 ac_cwmin, ac_cwmax);
1368 return -1;
1369 }
1370 return 0;
1371}
1372
1373
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001374int hostapd_config_check(struct hostapd_config *conf, int full_config)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001375{
1376 size_t i;
1377
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001378 if (full_config && conf->ieee80211d &&
1379 (!conf->country[0] || !conf->country[1])) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001380 wpa_printf(MSG_ERROR, "Cannot enable IEEE 802.11d without "
1381 "setting the country_code");
1382 return -1;
1383 }
1384
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001385 if (full_config && conf->ieee80211h && !conf->ieee80211d) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001386 wpa_printf(MSG_ERROR, "Cannot enable IEEE 802.11h without "
1387 "IEEE 802.11d enabled");
1388 return -1;
1389 }
1390
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001391 if (full_config && conf->local_pwr_constraint != -1 &&
1392 !conf->ieee80211d) {
1393 wpa_printf(MSG_ERROR, "Cannot add Power Constraint element without Country element");
1394 return -1;
1395 }
1396
1397 if (full_config && conf->spectrum_mgmt_required &&
1398 conf->local_pwr_constraint == -1) {
1399 wpa_printf(MSG_ERROR, "Cannot set Spectrum Management bit without Country and Power Constraint elements");
1400 return -1;
1401 }
1402
Hai Shalom81f62d82019-07-22 12:10:00 -07001403#ifdef CONFIG_AIRTIME_POLICY
1404 if (full_config && conf->airtime_mode > AIRTIME_MODE_STATIC &&
1405 !conf->airtime_update_interval) {
1406 wpa_printf(MSG_ERROR, "Airtime update interval cannot be zero");
1407 return -1;
1408 }
1409#endif /* CONFIG_AIRTIME_POLICY */
Dmitry Shmidt05df46a2015-05-19 11:02:01 -07001410 for (i = 0; i < NUM_TX_QUEUES; i++) {
1411 if (hostapd_config_check_cw(conf, i))
1412 return -1;
1413 }
1414
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001415 for (i = 0; i < conf->num_bss; i++) {
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001416 if (hostapd_config_check_bss(conf->bss[i], conf, full_config))
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001417 return -1;
1418 }
1419
1420 return 0;
1421}
1422
1423
Dmitry Shmidt71757432014-06-02 13:50:35 -07001424void hostapd_set_security_params(struct hostapd_bss_config *bss,
1425 int full_config)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001426{
Hai Shalomfdcde762020-04-02 11:19:20 -07001427#ifdef CONFIG_WEP
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001428 if (bss->individual_wep_key_len == 0) {
1429 /* individual keys are not use; can use key idx0 for
1430 * broadcast keys */
1431 bss->broadcast_key_idx_min = 0;
1432 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001433#endif /* CONFIG_WEP */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001434
1435 if ((bss->wpa & 2) && bss->rsn_pairwise == 0)
1436 bss->rsn_pairwise = bss->wpa_pairwise;
Roshan Pius3a1667e2018-07-03 15:17:14 -07001437 if (bss->group_cipher)
1438 bss->wpa_group = bss->group_cipher;
1439 else
1440 bss->wpa_group = wpa_select_ap_group_cipher(bss->wpa,
1441 bss->wpa_pairwise,
1442 bss->rsn_pairwise);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001443 if (!bss->wpa_group_rekey_set)
1444 bss->wpa_group_rekey = bss->wpa_group == WPA_CIPHER_TKIP ?
1445 600 : 86400;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001446
Dmitry Shmidt71757432014-06-02 13:50:35 -07001447 if (full_config) {
1448 bss->radius->auth_server = bss->radius->auth_servers;
1449 bss->radius->acct_server = bss->radius->acct_servers;
1450 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001451
1452 if (bss->wpa && bss->ieee802_1x) {
1453 bss->ssid.security_policy = SECURITY_WPA;
1454 } else if (bss->wpa) {
1455 bss->ssid.security_policy = SECURITY_WPA_PSK;
1456 } else if (bss->ieee802_1x) {
1457 int cipher = WPA_CIPHER_NONE;
1458 bss->ssid.security_policy = SECURITY_IEEE_802_1X;
Hai Shalomfdcde762020-04-02 11:19:20 -07001459#ifdef CONFIG_WEP
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001460 bss->ssid.wep.default_len = bss->default_wep_key_len;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001461 if (full_config && bss->default_wep_key_len) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001462 cipher = bss->default_wep_key_len >= 13 ?
1463 WPA_CIPHER_WEP104 : WPA_CIPHER_WEP40;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001464 } else if (full_config && bss->ssid.wep.keys_set) {
1465 if (bss->ssid.wep.len[0] >= 13)
1466 cipher = WPA_CIPHER_WEP104;
1467 else
1468 cipher = WPA_CIPHER_WEP40;
1469 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001470#endif /* CONFIG_WEP */
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001471 bss->wpa_group = cipher;
1472 bss->wpa_pairwise = cipher;
1473 bss->rsn_pairwise = cipher;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001474 if (full_config)
1475 bss->wpa_key_mgmt = WPA_KEY_MGMT_IEEE8021X_NO_WPA;
Hai Shalomfdcde762020-04-02 11:19:20 -07001476#ifdef CONFIG_WEP
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001477 } else if (bss->ssid.wep.keys_set) {
1478 int cipher = WPA_CIPHER_WEP40;
1479 if (bss->ssid.wep.len[0] >= 13)
1480 cipher = WPA_CIPHER_WEP104;
1481 bss->ssid.security_policy = SECURITY_STATIC_WEP;
1482 bss->wpa_group = cipher;
1483 bss->wpa_pairwise = cipher;
1484 bss->rsn_pairwise = cipher;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001485 if (full_config)
1486 bss->wpa_key_mgmt = WPA_KEY_MGMT_NONE;
Hai Shalomfdcde762020-04-02 11:19:20 -07001487#endif /* CONFIG_WEP */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001488 } else if (bss->osen) {
1489 bss->ssid.security_policy = SECURITY_OSEN;
1490 bss->wpa_group = WPA_CIPHER_CCMP;
1491 bss->wpa_pairwise = 0;
1492 bss->rsn_pairwise = WPA_CIPHER_CCMP;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001493 } else {
1494 bss->ssid.security_policy = SECURITY_PLAINTEXT;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001495 if (full_config) {
1496 bss->wpa_group = WPA_CIPHER_NONE;
1497 bss->wpa_pairwise = WPA_CIPHER_NONE;
1498 bss->rsn_pairwise = WPA_CIPHER_NONE;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001499 bss->wpa_key_mgmt = WPA_KEY_MGMT_NONE;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001500 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001501 }
1502}
Hai Shalom74f70d42019-02-11 14:42:39 -08001503
1504
1505int hostapd_sae_pw_id_in_use(struct hostapd_bss_config *conf)
1506{
1507 int with_id = 0, without_id = 0;
1508 struct sae_password_entry *pw;
1509
1510 if (conf->ssid.wpa_passphrase)
1511 without_id = 1;
1512
1513 for (pw = conf->sae_passwords; pw; pw = pw->next) {
1514 if (pw->identifier)
1515 with_id = 1;
1516 else
1517 without_id = 1;
1518 if (with_id && without_id)
1519 break;
1520 }
1521
1522 if (with_id && !without_id)
1523 return 2;
1524 return with_id;
1525}
Hai Shalom899fcc72020-10-19 14:38:18 -07001526
1527
1528bool hostapd_sae_pk_in_use(struct hostapd_bss_config *conf)
1529{
1530#ifdef CONFIG_SAE_PK
1531 struct sae_password_entry *pw;
1532
1533 for (pw = conf->sae_passwords; pw; pw = pw->next) {
1534 if (pw->pk)
1535 return true;
1536 }
1537#endif /* CONFIG_SAE_PK */
1538
1539 return false;
1540}
1541
1542
1543#ifdef CONFIG_SAE_PK
1544bool hostapd_sae_pk_exclusively(struct hostapd_bss_config *conf)
1545{
1546 bool with_pk = false;
1547 struct sae_password_entry *pw;
1548
1549 if (conf->ssid.wpa_passphrase)
1550 return false;
1551
1552 for (pw = conf->sae_passwords; pw; pw = pw->next) {
1553 if (!pw->pk)
1554 return false;
1555 with_pk = true;
1556 }
1557
1558 return with_pk;
1559}
1560#endif /* CONFIG_SAE_PK */