]> git.ipfire.org Git - thirdparty/hostap.git/blame - src/ap/ap_config.c
HE: Make the basic NSS/MCS configurable
[thirdparty/hostap.git] / src / ap / ap_config.c
CommitLineData
6fc6879b 1/*
41d719d6 2 * hostapd / Configuration helper functions
08081ad8 3 * Copyright (c) 2003-2014, Jouni Malinen <j@w1.fi>
6fc6879b 4 *
0f3d578e
JM
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
6fc6879b
JM
7 */
8
6226e38d 9#include "utils/includes.h"
6fc6879b 10
6226e38d 11#include "utils/common.h"
03da66bd 12#include "crypto/sha1.h"
d501c27c 13#include "crypto/tls.h"
6fc6879b 14#include "radius/radius_client.h"
df84268a 15#include "common/ieee802_11_defs.h"
41d719d6 16#include "common/eapol_common.h"
91d91abf 17#include "common/dhcp.h"
03da66bd
JM
18#include "eap_common/eap_wsc_common.h"
19#include "eap_server/eap.h"
6226e38d 20#include "wpa_auth.h"
97234b50 21#include "sta_info.h"
ef721751 22#include "airtime_policy.h"
6226e38d 23#include "ap_config.h"
6fc6879b
JM
24
25
6fc6879b
JM
26static void hostapd_config_free_vlan(struct hostapd_bss_config *bss)
27{
28 struct hostapd_vlan *vlan, *prev;
29
30 vlan = bss->vlan;
31 prev = NULL;
32 while (vlan) {
33 prev = vlan;
34 vlan = vlan->next;
35 os_free(prev);
36 }
37
38 bss->vlan = NULL;
39}
40
41
6f234c1e
JM
42#ifndef DEFAULT_WPA_DISABLE_EAPOL_KEY_RETRIES
43#define DEFAULT_WPA_DISABLE_EAPOL_KEY_RETRIES 0
44#endif /* DEFAULT_WPA_DISABLE_EAPOL_KEY_RETRIES */
45
41d719d6 46void hostapd_config_defaults_bss(struct hostapd_bss_config *bss)
6fc6879b 47{
695dbbea
JM
48 dl_list_init(&bss->anqp_elem);
49
6fc6879b
JM
50 bss->logger_syslog_level = HOSTAPD_LEVEL_INFO;
51 bss->logger_stdout_level = HOSTAPD_LEVEL_INFO;
52 bss->logger_syslog = (unsigned int) -1;
53 bss->logger_stdout = (unsigned int) -1;
54
55 bss->auth_algs = WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED;
56
57 bss->wep_rekeying_period = 300;
58 /* use key0 in individual key and key1 in broadcast key */
59 bss->broadcast_key_idx_min = 1;
60 bss->broadcast_key_idx_max = 2;
61 bss->eap_reauth_period = 3600;
62
63 bss->wpa_group_rekey = 600;
64 bss->wpa_gmk_rekey = 86400;
41f140d3
GK
65 bss->wpa_group_update_count = 4;
66 bss->wpa_pairwise_update_count = 4;
6f234c1e
JM
67 bss->wpa_disable_eapol_key_retries =
68 DEFAULT_WPA_DISABLE_EAPOL_KEY_RETRIES;
6fc6879b
JM
69 bss->wpa_key_mgmt = WPA_KEY_MGMT_PSK;
70 bss->wpa_pairwise = WPA_CIPHER_TKIP;
71 bss->wpa_group = WPA_CIPHER_TKIP;
72 bss->rsn_pairwise = 0;
73
74 bss->max_num_sta = MAX_STA_COUNT;
75
76 bss->dtim_period = 2;
77
78 bss->radius_server_auth_port = 1812;
7b0f5500 79 bss->eap_sim_db_timeout = 1;
6fc6879b
JM
80 bss->ap_max_inactivity = AP_MAX_INACTIVITY;
81 bss->eapol_version = EAPOL_VERSION;
b0194fe0
JM
82
83 bss->max_listen_interval = 65535;
5d22a1d5 84
df684d82
DH
85 bss->pwd_group = 19; /* ECC: GF(p=256) */
86
5d22a1d5 87#ifdef CONFIG_IEEE80211W
45c94154
JM
88 bss->assoc_sa_query_max_timeout = 1000;
89 bss->assoc_sa_query_retry_timeout = 201;
8dd9f9cd 90 bss->group_mgmt_cipher = WPA_CIPHER_AES_128_CMAC;
5d22a1d5 91#endif /* CONFIG_IEEE80211W */
1e5839e0 92#ifdef EAP_SERVER_FAST
378eae5e
JM
93 /* both anonymous and authenticated provisioning */
94 bss->eap_fast_prov = 3;
a11c90a6
JM
95 bss->pac_key_lifetime = 7 * 24 * 60 * 60;
96 bss->pac_key_refresh_time = 1 * 24 * 60 * 60;
1e5839e0 97#endif /* EAP_SERVER_FAST */
d2da2249
JB
98
99 /* Set to -1 as defaults depends on HT in setup */
100 bss->wmm_enabled = -1;
d7956add 101
4ec1fd8e 102#ifdef CONFIG_IEEE80211R_AP
d7956add 103 bss->ft_over_ds = 1;
3a46cf93
MB
104 bss->rkh_pos_timeout = 86400;
105 bss->rkh_neg_timeout = 60;
106 bss->rkh_pull_timeout = 1000;
107 bss->rkh_pull_retries = 4;
83fe4bd3 108 bss->r0_key_lifetime = 1209600;
4ec1fd8e 109#endif /* CONFIG_IEEE80211R_AP */
bde7ba6c
JM
110
111 bss->radius_das_time_window = 300;
d136c376
JM
112
113 bss->sae_anti_clogging_threshold = 5;
d8b841eb 114 bss->sae_sync = 5;
26bf70e3 115
2977f519
JM
116 bss->gas_frag_limit = 1400;
117
26bf70e3
JM
118#ifdef CONFIG_FILS
119 dl_list_init(&bss->fils_realms);
91d91abf
JM
120 bss->fils_hlp_wait_time = 30;
121 bss->dhcp_server_port = DHCP_SERVER_PORT;
122 bss->dhcp_relay_port = DHCP_SERVER_PORT;
26bf70e3 123#endif /* CONFIG_FILS */
57a2aaca
JM
124
125 bss->broadcast_deauth = 1;
941caed9
JM
126
127#ifdef CONFIG_MBO
128 bss->mbo_cell_data_conn_pref = -1;
129#endif /* CONFIG_MBO */
d501c27c
JM
130
131 /* Disable TLS v1.3 by default for now to avoid interoperability issue.
132 * This can be enabled by default once the implementation has been fully
133 * completed and tested with other implementations. */
134 bss->tls_flags = TLS_CONN_DISABLE_TLSv1_3;
678d8410
JM
135
136 bss->send_probe_response = 1;
6ae04d7b
JM
137
138#ifdef CONFIG_HS20
139 bss->hs20_release = (HS20_VERSION >> 4) + 1;
140#endif /* CONFIG_HS20 */
dd5d325b
SV
141
142 /* Default to strict CRL checking. */
143 bss->check_crl_strict = 1;
6fc6879b
JM
144}
145
146
89111f3b 147struct hostapd_config * hostapd_config_defaults(void)
6fc6879b 148{
d2da2249
JB
149#define ecw2cw(ecw) ((1 << (ecw)) - 1)
150
6fc6879b
JM
151 struct hostapd_config *conf;
152 struct hostapd_bss_config *bss;
594cf8b9 153 const int aCWmin = 4, aCWmax = 10;
3ae0800c 154 const struct hostapd_wmm_ac_params ac_bk =
6fc6879b 155 { aCWmin, aCWmax, 7, 0, 0 }; /* background traffic */
3ae0800c 156 const struct hostapd_wmm_ac_params ac_be =
6fc6879b 157 { aCWmin, aCWmax, 3, 0, 0 }; /* best effort traffic */
3ae0800c 158 const struct hostapd_wmm_ac_params ac_vi = /* video traffic */
f4e3860f 159 { aCWmin - 1, aCWmin, 2, 3008 / 32, 0 };
3ae0800c 160 const struct hostapd_wmm_ac_params ac_vo = /* voice traffic */
f4e3860f 161 { aCWmin - 2, aCWmin - 1, 2, 1504 / 32, 0 };
d2da2249
JB
162 const struct hostapd_tx_queue_params txq_bk =
163 { 7, ecw2cw(aCWmin), ecw2cw(aCWmax), 0 };
164 const struct hostapd_tx_queue_params txq_be =
165 { 3, ecw2cw(aCWmin), 4 * (ecw2cw(aCWmin) + 1) - 1, 0};
166 const struct hostapd_tx_queue_params txq_vi =
167 { 1, (ecw2cw(aCWmin) + 1) / 2 - 1, ecw2cw(aCWmin), 30};
168 const struct hostapd_tx_queue_params txq_vo =
169 { 1, (ecw2cw(aCWmin) + 1) / 4 - 1,
170 (ecw2cw(aCWmin) + 1) / 2 - 1, 15};
171
172#undef ecw2cw
6fc6879b
JM
173
174 conf = os_zalloc(sizeof(*conf));
175 bss = os_zalloc(sizeof(*bss));
176 if (conf == NULL || bss == NULL) {
10656fc2
JM
177 wpa_printf(MSG_ERROR, "Failed to allocate memory for "
178 "configuration data.");
6fc6879b
JM
179 os_free(conf);
180 os_free(bss);
181 return NULL;
182 }
ebd79f07
JM
183 conf->bss = os_calloc(1, sizeof(struct hostapd_bss_config *));
184 if (conf->bss == NULL) {
185 os_free(conf);
186 os_free(bss);
187 return NULL;
188 }
189 conf->bss[0] = bss;
6fc6879b 190
6fc6879b
JM
191 bss->radius = os_zalloc(sizeof(*bss->radius));
192 if (bss->radius == NULL) {
04c366cb 193 os_free(conf->bss);
6fc6879b
JM
194 os_free(conf);
195 os_free(bss);
196 return NULL;
197 }
198
199 hostapd_config_defaults_bss(bss);
200
201 conf->num_bss = 1;
6fc6879b
JM
202
203 conf->beacon_int = 100;
bf0021ed
JM
204 conf->rts_threshold = -2; /* use driver default: 2347 */
205 conf->fragm_threshold = -2; /* user driver default: 2346 */
e0392f82
S
206 /* Set to invalid value means do not add Power Constraint IE */
207 conf->local_pwr_constraint = -1;
6fc6879b 208
3ae0800c
JM
209 conf->wmm_ac_params[0] = ac_be;
210 conf->wmm_ac_params[1] = ac_bk;
211 conf->wmm_ac_params[2] = ac_vi;
212 conf->wmm_ac_params[3] = ac_vo;
6fc6879b 213
d2da2249
JB
214 conf->tx_queue[0] = txq_vo;
215 conf->tx_queue[1] = txq_vi;
216 conf->tx_queue[2] = txq_be;
217 conf->tx_queue[3] = txq_bk;
218
fc14f567 219 conf->ht_capab = HT_CAP_INFO_SMPS_DISABLED;
de9289c8 220
f1b44874
SE
221 conf->ap_table_max_size = 255;
222 conf->ap_table_expiration_time = 60;
a65a9b8d 223 conf->track_sta_max_age = 180;
f1b44874 224
c2aff6b1 225#ifdef CONFIG_TESTING_OPTIONS
06df2aa6
JM
226 conf->ignore_probe_probability = 0.0;
227 conf->ignore_auth_probability = 0.0;
228 conf->ignore_assoc_probability = 0.0;
229 conf->ignore_reassoc_probability = 0.0;
230 conf->corrupt_gtk_rekey_mic_probability = 0.0;
2b6e1216 231 conf->ecsa_ie_only = 0;
c2aff6b1
JB
232#endif /* CONFIG_TESTING_OPTIONS */
233
857d9422
MM
234 conf->acs = 0;
235 conf->acs_ch_list.num = 0;
50f4f2a0
MK
236#ifdef CONFIG_ACS
237 conf->acs_num_scans = 5;
238#endif /* CONFIG_ACS */
239
83f30fab
JC
240#ifdef CONFIG_IEEE80211AX
241 conf->he_op.he_rts_threshold = HE_OPERATION_RTS_THRESHOLD_MASK >>
242 HE_OPERATION_RTS_THRESHOLD_OFFSET;
4f3f3380
JC
243 /* Set default basic MCS/NSS set to single stream MCS 0-7 */
244 conf->he_op.he_basic_mcs_nss_set = 0xfffc;
83f30fab
JC
245#endif /* CONFIG_IEEE80211AX */
246
ff936bc7
JM
247 /* The third octet of the country string uses an ASCII space character
248 * by default to indicate that the regulations encompass all
249 * environments for the current frequency band in the country. */
250 conf->country[2] = ' ';
251
076f1ea1
BL
252 conf->rssi_reject_assoc_rssi = 0;
253 conf->rssi_reject_assoc_timeout = 30;
254
ef721751
THJ
255#ifdef CONFIG_AIRTIME_POLICY
256 conf->airtime_update_interval = AIRTIME_DEFAULT_UPDATE_INTERVAL;
257#endif /* CONFIG_AIRTIME_POLICY */
258
6fc6879b
JM
259 return conf;
260}
261
262
263int hostapd_mac_comp(const void *a, const void *b)
264{
265 return os_memcmp(a, b, sizeof(macaddr));
266}
267
268
6fc6879b
JM
269static int hostapd_config_read_wpa_psk(const char *fname,
270 struct hostapd_ssid *ssid)
271{
272 FILE *f;
273 char buf[128], *pos;
ec5c39a5
MK
274 const char *keyid;
275 char *context;
276 char *context2;
277 char *token;
278 char *name;
279 char *value;
6fc6879b
JM
280 int line = 0, ret = 0, len, ok;
281 u8 addr[ETH_ALEN];
282 struct hostapd_wpa_psk *psk;
283
284 if (!fname)
285 return 0;
286
287 f = fopen(fname, "r");
288 if (!f) {
10656fc2 289 wpa_printf(MSG_ERROR, "WPA PSK file '%s' not found.", fname);
6fc6879b
JM
290 return -1;
291 }
292
293 while (fgets(buf, sizeof(buf), f)) {
dbfa691d
JM
294 int vlan_id = 0;
295
6fc6879b
JM
296 line++;
297
298 if (buf[0] == '#')
299 continue;
300 pos = buf;
301 while (*pos != '\0') {
302 if (*pos == '\n') {
303 *pos = '\0';
304 break;
305 }
306 pos++;
307 }
308 if (buf[0] == '\0')
309 continue;
310
ec5c39a5
MK
311 context = NULL;
312 keyid = NULL;
313 while ((token = str_token(buf, " ", &context))) {
314 if (!os_strchr(token, '='))
315 break;
316 context2 = NULL;
317 name = str_token(token, "=", &context2);
2fae58fd
JM
318 if (!name)
319 break;
ec5c39a5
MK
320 value = str_token(token, "", &context2);
321 if (!value)
322 value = "";
323 if (!os_strcmp(name, "keyid")) {
324 keyid = value;
dbfa691d
JM
325 } else if (!os_strcmp(name, "vlanid")) {
326 vlan_id = atoi(value);
ec5c39a5
MK
327 } else {
328 wpa_printf(MSG_ERROR,
329 "Unrecognized '%s=%s' on line %d in '%s'",
330 name, value, line, fname);
331 ret = -1;
332 break;
333 }
334 }
335
336 if (ret == -1)
337 break;
338
339 if (!token)
340 token = "";
341 if (hwaddr_aton(token, addr)) {
10656fc2 342 wpa_printf(MSG_ERROR, "Invalid MAC address '%s' on "
ec5c39a5 343 "line %d in '%s'", token, line, fname);
6fc6879b
JM
344 ret = -1;
345 break;
346 }
347
348 psk = os_zalloc(sizeof(*psk));
349 if (psk == NULL) {
10656fc2 350 wpa_printf(MSG_ERROR, "WPA PSK allocation failed");
6fc6879b
JM
351 ret = -1;
352 break;
353 }
dbfa691d 354 psk->vlan_id = vlan_id;
a8e16edc 355 if (is_zero_ether_addr(addr))
6fc6879b
JM
356 psk->group = 1;
357 else
358 os_memcpy(psk->addr, addr, ETH_ALEN);
359
ec5c39a5
MK
360 pos = str_token(buf, "", &context);
361 if (!pos) {
10656fc2
JM
362 wpa_printf(MSG_ERROR, "No PSK on line %d in '%s'",
363 line, fname);
6fc6879b
JM
364 os_free(psk);
365 ret = -1;
366 break;
367 }
6fc6879b
JM
368
369 ok = 0;
370 len = os_strlen(pos);
371 if (len == 64 && hexstr2bin(pos, psk->psk, PMK_LEN) == 0)
372 ok = 1;
373 else if (len >= 8 && len < 64) {
374 pbkdf2_sha1(pos, ssid->ssid, ssid->ssid_len,
375 4096, psk->psk, PMK_LEN);
376 ok = 1;
377 }
378 if (!ok) {
10656fc2
JM
379 wpa_printf(MSG_ERROR, "Invalid PSK '%s' on line %d in "
380 "'%s'", pos, line, fname);
6fc6879b
JM
381 os_free(psk);
382 ret = -1;
383 break;
384 }
385
ec5c39a5
MK
386 if (keyid) {
387 len = os_strlcpy(psk->keyid, keyid, sizeof(psk->keyid));
388 if ((size_t) len >= sizeof(psk->keyid)) {
389 wpa_printf(MSG_ERROR,
390 "PSK keyid too long on line %d in '%s'",
391 line, fname);
392 os_free(psk);
393 ret = -1;
394 break;
395 }
396 }
397
6fc6879b
JM
398 psk->next = ssid->wpa_psk;
399 ssid->wpa_psk = psk;
400 }
401
402 fclose(f);
403
404 return ret;
405}
406
407
0ae687bd
JM
408static int hostapd_derive_psk(struct hostapd_ssid *ssid)
409{
410 ssid->wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
411 if (ssid->wpa_psk == NULL) {
412 wpa_printf(MSG_ERROR, "Unable to alloc space for PSK");
413 return -1;
414 }
415 wpa_hexdump_ascii(MSG_DEBUG, "SSID",
416 (u8 *) ssid->ssid, ssid->ssid_len);
417 wpa_hexdump_ascii_key(MSG_DEBUG, "PSK (ASCII passphrase)",
418 (u8 *) ssid->wpa_passphrase,
419 os_strlen(ssid->wpa_passphrase));
420 pbkdf2_sha1(ssid->wpa_passphrase,
421 ssid->ssid, ssid->ssid_len,
422 4096, ssid->wpa_psk->psk, PMK_LEN);
423 wpa_hexdump_key(MSG_DEBUG, "PSK (from passphrase)",
424 ssid->wpa_psk->psk, PMK_LEN);
425 return 0;
426}
427
428
6fc6879b
JM
429int hostapd_setup_wpa_psk(struct hostapd_bss_config *conf)
430{
431 struct hostapd_ssid *ssid = &conf->ssid;
432
433 if (ssid->wpa_passphrase != NULL) {
434 if (ssid->wpa_psk != NULL) {
0ae687bd
JM
435 wpa_printf(MSG_DEBUG, "Using pre-configured WPA PSK "
436 "instead of passphrase");
437 } else {
438 wpa_printf(MSG_DEBUG, "Deriving WPA PSK based on "
439 "passphrase");
440 if (hostapd_derive_psk(ssid) < 0)
441 return -1;
6fc6879b 442 }
6fc6879b 443 ssid->wpa_psk->group = 1;
6fc6879b
JM
444 }
445
34e29dfd 446 return hostapd_config_read_wpa_psk(ssid->wpa_psk_file, &conf->ssid);
6fc6879b
JM
447}
448
449
6fc6879b
JM
450static void hostapd_config_free_radius(struct hostapd_radius_server *servers,
451 int num_servers)
452{
453 int i;
454
455 for (i = 0; i < num_servers; i++) {
456 os_free(servers[i].shared_secret);
457 }
458 os_free(servers);
459}
460
461
af35e7af
JM
462struct hostapd_radius_attr *
463hostapd_config_get_radius_attr(struct hostapd_radius_attr *attr, u8 type)
464{
465 for (; attr; attr = attr->next) {
466 if (attr->type == type)
467 return attr;
468 }
469 return NULL;
470}
471
472
473static void hostapd_config_free_radius_attr(struct hostapd_radius_attr *attr)
474{
475 struct hostapd_radius_attr *prev;
476
477 while (attr) {
478 prev = attr;
479 attr = attr->next;
480 wpabuf_free(prev->val);
481 os_free(prev);
482 }
483}
484
485
d0ee16ed 486void hostapd_config_free_eap_user(struct hostapd_eap_user *user)
6fc6879b 487{
d0ee16ed 488 hostapd_config_free_radius_attr(user->accept_attr);
6fc6879b 489 os_free(user->identity);
b7175b4d 490 bin_clear_free(user->password, user->password_len);
d52ead3d 491 bin_clear_free(user->salt, user->salt_len);
6fc6879b
JM
492 os_free(user);
493}
494
495
78022c83
JM
496void hostapd_config_free_eap_users(struct hostapd_eap_user *user)
497{
498 struct hostapd_eap_user *prev_user;
499
500 while (user) {
501 prev_user = user;
502 user = user->next;
503 hostapd_config_free_eap_user(prev_user);
504 }
505}
506
507
6fc6879b
JM
508static void hostapd_config_free_wep(struct hostapd_wep_keys *keys)
509{
510 int i;
511 for (i = 0; i < NUM_WEP_KEYS; i++) {
b7175b4d 512 bin_clear_free(keys->key[i], keys->len[i]);
6fc6879b
JM
513 keys->key[i] = NULL;
514 }
515}
516
517
891dfb33
ST
518void hostapd_config_clear_wpa_psk(struct hostapd_wpa_psk **l)
519{
520 struct hostapd_wpa_psk *psk, *tmp;
521
522 for (psk = *l; psk;) {
523 tmp = psk;
524 psk = psk->next;
525 bin_clear_free(tmp, sizeof(*tmp));
526 }
527 *l = NULL;
528}
529
530
695dbbea
JM
531static void hostapd_config_free_anqp_elem(struct hostapd_bss_config *conf)
532{
533 struct anqp_element *elem;
534
535 while ((elem = dl_list_first(&conf->anqp_elem, struct anqp_element,
536 list))) {
537 dl_list_del(&elem->list);
538 wpabuf_free(elem->payload);
539 os_free(elem);
540 }
541}
542
543
26bf70e3
JM
544static void hostapd_config_free_fils_realms(struct hostapd_bss_config *conf)
545{
546#ifdef CONFIG_FILS
547 struct fils_realm *realm;
548
549 while ((realm = dl_list_first(&conf->fils_realms, struct fils_realm,
550 list))) {
551 dl_list_del(&realm->list);
552 os_free(realm);
553 }
554#endif /* CONFIG_FILS */
555}
556
557
9be19d0b
JM
558static void hostapd_config_free_sae_passwords(struct hostapd_bss_config *conf)
559{
560 struct sae_password_entry *pw, *tmp;
561
562 pw = conf->sae_passwords;
563 conf->sae_passwords = NULL;
564 while (pw) {
565 tmp = pw;
566 pw = pw->next;
567 str_clear_free(tmp->password);
568 os_free(tmp->identifier);
569 os_free(tmp);
570 }
571}
572
573
e00f780e
JM
574#ifdef CONFIG_DPP2
575static void hostapd_dpp_controller_conf_free(struct dpp_controller_conf *conf)
576{
577 struct dpp_controller_conf *prev;
578
579 while (conf) {
580 prev = conf;
581 conf = conf->next;
582 os_free(prev);
583 }
584}
585#endif /* CONFIG_DPP2 */
586
587
55920658 588void hostapd_config_free_bss(struct hostapd_bss_config *conf)
6fc6879b 589{
6fc6879b
JM
590 if (conf == NULL)
591 return;
592
891dfb33 593 hostapd_config_clear_wpa_psk(&conf->ssid.wpa_psk);
6fc6879b 594
b7175b4d 595 str_clear_free(conf->ssid.wpa_passphrase);
6fc6879b 596 os_free(conf->ssid.wpa_psk_file);
43dd46b3 597 hostapd_config_free_wep(&conf->ssid.wep);
6fc6879b
JM
598#ifdef CONFIG_FULL_DYNAMIC_VLAN
599 os_free(conf->ssid.vlan_tagged_interface);
600#endif /* CONFIG_FULL_DYNAMIC_VLAN */
601
78022c83 602 hostapd_config_free_eap_users(conf->eap_user);
ee431d77 603 os_free(conf->eap_user_sqlite);
6fc6879b 604
6fc6879b 605 os_free(conf->eap_req_id_text);
2a5156a6 606 os_free(conf->erp_domain);
6fc6879b
JM
607 os_free(conf->accept_mac);
608 os_free(conf->deny_mac);
609 os_free(conf->nas_identifier);
5afaa067
JM
610 if (conf->radius) {
611 hostapd_config_free_radius(conf->radius->auth_servers,
612 conf->radius->num_auth_servers);
613 hostapd_config_free_radius(conf->radius->acct_servers,
614 conf->radius->num_acct_servers);
615 }
af35e7af
JM
616 hostapd_config_free_radius_attr(conf->radius_auth_req_attr);
617 hostapd_config_free_radius_attr(conf->radius_acct_req_attr);
6fc6879b
JM
618 os_free(conf->rsn_preauth_interfaces);
619 os_free(conf->ctrl_interface);
620 os_free(conf->ca_cert);
621 os_free(conf->server_cert);
622 os_free(conf->private_key);
623 os_free(conf->private_key_passwd);
841205a1 624 os_free(conf->check_cert_subject);
080585c0 625 os_free(conf->ocsp_stapling_response);
5addb0df 626 os_free(conf->ocsp_stapling_response_multi);
6fc6879b 627 os_free(conf->dh_file);
f8995f8f 628 os_free(conf->openssl_ciphers);
d01203ca 629 os_free(conf->openssl_ecdh_curves);
6fc6879b
JM
630 os_free(conf->pac_opaque_encr_key);
631 os_free(conf->eap_fast_a_id);
2d867244 632 os_free(conf->eap_fast_a_id_info);
6fc6879b
JM
633 os_free(conf->eap_sim_db);
634 os_free(conf->radius_server_clients);
6fc6879b 635 os_free(conf->radius);
b031338c 636 os_free(conf->radius_das_shared_secret);
6fc6879b 637 hostapd_config_free_vlan(conf);
39b97072
JM
638 os_free(conf->time_zone);
639
4ec1fd8e 640#ifdef CONFIG_IEEE80211R_AP
6fc6879b
JM
641 {
642 struct ft_remote_r0kh *r0kh, *r0kh_prev;
643 struct ft_remote_r1kh *r1kh, *r1kh_prev;
644
645 r0kh = conf->r0kh_list;
646 conf->r0kh_list = NULL;
647 while (r0kh) {
648 r0kh_prev = r0kh;
649 r0kh = r0kh->next;
650 os_free(r0kh_prev);
651 }
652
653 r1kh = conf->r1kh_list;
654 conf->r1kh_list = NULL;
655 while (r1kh) {
656 r1kh_prev = r1kh;
657 r1kh = r1kh->next;
658 os_free(r1kh_prev);
659 }
660 }
4ec1fd8e 661#endif /* CONFIG_IEEE80211R_AP */
ad08c363
JM
662
663#ifdef CONFIG_WPS
664 os_free(conf->wps_pin_requests);
665 os_free(conf->device_name);
666 os_free(conf->manufacturer);
667 os_free(conf->model_name);
668 os_free(conf->model_number);
669 os_free(conf->serial_number);
ad08c363
JM
670 os_free(conf->config_methods);
671 os_free(conf->ap_pin);
62966253 672 os_free(conf->extra_cred);
4c29cae9 673 os_free(conf->ap_settings);
66819b07
DL
674 hostapd_config_clear_wpa_psk(&conf->multi_ap_backhaul_ssid.wpa_psk);
675 str_clear_free(conf->multi_ap_backhaul_ssid.wpa_passphrase);
f620268f
JM
676 os_free(conf->upnp_iface);
677 os_free(conf->friendly_name);
678 os_free(conf->manufacturer_url);
679 os_free(conf->model_description);
680 os_free(conf->model_url);
681 os_free(conf->upc);
8509fb5c
JM
682 {
683 unsigned int i;
684
685 for (i = 0; i < MAX_WPS_VENDOR_EXTENSIONS; i++)
686 wpabuf_free(conf->wps_vendor_ext[i]);
687 }
ffdaa05a
JM
688 wpabuf_free(conf->wps_nfc_dh_pubkey);
689 wpabuf_free(conf->wps_nfc_dh_privkey);
690 wpabuf_free(conf->wps_nfc_dev_pw);
ad08c363 691#endif /* CONFIG_WPS */
4b2a77ab
JM
692
693 os_free(conf->roaming_consortium);
648cc711 694 os_free(conf->venue_name);
7e1d3ee9 695 os_free(conf->venue_url);
8047b186 696 os_free(conf->nai_realm_data);
550a3958 697 os_free(conf->network_auth_type);
7515adb2 698 os_free(conf->anqp_3gpp_cell_net);
26fac8b6 699 os_free(conf->domain_name);
695dbbea 700 hostapd_config_free_anqp_elem(conf);
505a3694
JM
701
702#ifdef CONFIG_RADIUS_TEST
703 os_free(conf->dump_msk_file);
704#endif /* CONFIG_RADIUS_TEST */
df5934f1
JK
705
706#ifdef CONFIG_HS20
a9277e85 707 os_free(conf->hs20_oper_friendly_name);
4065a309 708 os_free(conf->hs20_wan_metrics);
5ccc54aa 709 os_free(conf->hs20_connection_capability);
df5934f1 710 os_free(conf->hs20_operating_class);
f7bd7a01 711 os_free(conf->hs20_icons);
ae6d15c7
JM
712 if (conf->hs20_osu_providers) {
713 size_t i;
714 for (i = 0; i < conf->hs20_osu_providers_count; i++) {
715 struct hs20_osu_provider *p;
716 size_t j;
717 p = &conf->hs20_osu_providers[i];
718 os_free(p->friendly_name);
719 os_free(p->server_uri);
720 os_free(p->method_list);
721 for (j = 0; j < p->icons_count; j++)
722 os_free(p->icons[j]);
723 os_free(p->icons);
724 os_free(p->osu_nai);
cad810a9 725 os_free(p->osu_nai2);
ae6d15c7
JM
726 os_free(p->service_desc);
727 }
728 os_free(conf->hs20_osu_providers);
729 }
0e450db2
JM
730 if (conf->hs20_operator_icon) {
731 size_t i;
732
733 for (i = 0; i < conf->hs20_operator_icon_count; i++)
734 os_free(conf->hs20_operator_icon[i]);
735 os_free(conf->hs20_operator_icon);
736 }
8d2a9921 737 os_free(conf->subscr_remediation_url);
7bd8c76a 738 os_free(conf->hs20_sim_provisioning_url);
6cb8f4f3 739 os_free(conf->t_c_filename);
8760b984 740 os_free(conf->t_c_server_url);
df5934f1 741#endif /* CONFIG_HS20 */
b52f084c
JM
742
743 wpabuf_free(conf->vendor_elements);
a9112270 744 wpabuf_free(conf->assocresp_elements);
625f202a
JM
745
746 os_free(conf->sae_groups);
91cc34bf
JM
747#ifdef CONFIG_OWE
748 os_free(conf->owe_groups);
749#endif /* CONFIG_OWE */
67fe933d 750
88cb27c7
DS
751 os_free(conf->wowlan_triggers);
752
67fe933d 753 os_free(conf->server_id);
ebd79f07 754
bc02843e
JM
755#ifdef CONFIG_TESTING_OPTIONS
756 wpabuf_free(conf->own_ie_override);
3648d8a1 757 wpabuf_free(conf->sae_commit_override);
bc02843e
JM
758#endif /* CONFIG_TESTING_OPTIONS */
759
964f64e2 760 os_free(conf->no_probe_resp_if_seen_on);
0e2412d0 761 os_free(conf->no_auth_if_seen_on);
964f64e2 762
26bf70e3
JM
763 hostapd_config_free_fils_realms(conf);
764
56c75495
JM
765#ifdef CONFIG_DPP
766 os_free(conf->dpp_connector);
767 wpabuf_free(conf->dpp_netaccesskey);
768 wpabuf_free(conf->dpp_csign);
e00f780e
JM
769#ifdef CONFIG_DPP2
770 hostapd_dpp_controller_conf_free(conf->dpp_controller);
771#endif /* CONFIG_DPP2 */
56c75495
JM
772#endif /* CONFIG_DPP */
773
9be19d0b 774 hostapd_config_free_sae_passwords(conf);
2377c1ca 775
ef721751
THJ
776#ifdef CONFIG_AIRTIME_POLICY
777 {
778 struct airtime_sta_weight *wt, *wt_prev;
779
780 wt = conf->airtime_weight_list;
781 conf->airtime_weight_list = NULL;
782 while (wt) {
783 wt_prev = wt;
784 wt = wt->next;
785 os_free(wt_prev);
786 }
787 }
788#endif /* CONFIG_AIRTIME_POLICY */
789
ebd79f07 790 os_free(conf);
6fc6879b
JM
791}
792
793
1c6e69cc
JM
794/**
795 * hostapd_config_free - Free hostapd configuration
796 * @conf: Configuration data from hostapd_config_read().
797 */
6fc6879b
JM
798void hostapd_config_free(struct hostapd_config *conf)
799{
800 size_t i;
801
802 if (conf == NULL)
803 return;
804
805 for (i = 0; i < conf->num_bss; i++)
ebd79f07 806 hostapd_config_free_bss(conf->bss[i]);
6fc6879b 807 os_free(conf->bss);
79d6c85f
JM
808 os_free(conf->supported_rates);
809 os_free(conf->basic_rates);
857d9422 810 os_free(conf->acs_ch_list.range);
0ecff8d7 811 os_free(conf->driver_params);
68fa00c3
JM
812#ifdef CONFIG_ACS
813 os_free(conf->acs_chan_bias);
814#endif /* CONFIG_ACS */
74e982d8
DS
815 wpabuf_free(conf->lci);
816 wpabuf_free(conf->civic);
6fc6879b
JM
817
818 os_free(conf);
819}
820
821
1c6e69cc
JM
822/**
823 * hostapd_maclist_found - Find a MAC address from a list
824 * @list: MAC address list
825 * @num_entries: Number of addresses in the list
826 * @addr: Address to search for
827 * @vlan_id: Buffer for returning VLAN ID or %NULL if not needed
828 * Returns: 1 if address is in the list or 0 if not.
829 *
830 * Perform a binary search for given MAC address from a pre-sorted list.
831 */
271d2830 832int hostapd_maclist_found(struct mac_acl_entry *list, int num_entries,
1889af2e 833 const u8 *addr, struct vlan_description *vlan_id)
6fc6879b
JM
834{
835 int start, end, middle, res;
836
837 start = 0;
838 end = num_entries - 1;
839
840 while (start <= end) {
841 middle = (start + end) / 2;
271d2830
JM
842 res = os_memcmp(list[middle].addr, addr, ETH_ALEN);
843 if (res == 0) {
844 if (vlan_id)
845 *vlan_id = list[middle].vlan_id;
6fc6879b 846 return 1;
271d2830 847 }
6fc6879b
JM
848 if (res < 0)
849 start = middle + 1;
850 else
851 end = middle - 1;
852 }
853
854 return 0;
855}
856
857
858int hostapd_rate_found(int *list, int rate)
859{
860 int i;
861
862 if (list == NULL)
863 return 0;
864
865 for (i = 0; list[i] >= 0; i++)
866 if (list[i] == rate)
867 return 1;
868
869 return 0;
870}
871
872
1889af2e
MB
873int hostapd_vlan_valid(struct hostapd_vlan *vlan,
874 struct vlan_description *vlan_desc)
6fc6879b
JM
875{
876 struct hostapd_vlan *v = vlan;
8e44c192 877 int i;
1889af2e 878
8e44c192 879 if (!vlan_desc->notempty || vlan_desc->untagged < 0 ||
1889af2e
MB
880 vlan_desc->untagged > MAX_VLAN_ID)
881 return 0;
8e44c192
MB
882 for (i = 0; i < MAX_NUM_TAGGED_VLAN; i++) {
883 if (vlan_desc->tagged[i] < 0 ||
884 vlan_desc->tagged[i] > MAX_VLAN_ID)
885 return 0;
886 }
887 if (!vlan_desc->untagged && !vlan_desc->tagged[0])
888 return 0;
1889af2e 889
6fc6879b 890 while (v) {
1889af2e
MB
891 if (!vlan_compare(&v->vlan_desc, vlan_desc) ||
892 v->vlan_id == VLAN_ID_WILDCARD)
80ebfd95
MB
893 return 1;
894 v = v->next;
895 }
896 return 0;
897}
898
899
900const char * hostapd_get_vlan_id_ifname(struct hostapd_vlan *vlan, int vlan_id)
901{
902 struct hostapd_vlan *v = vlan;
903 while (v) {
904 if (v->vlan_id == vlan_id)
6fc6879b
JM
905 return v->ifname;
906 v = v->next;
907 }
908 return NULL;
909}
910
911
912const u8 * hostapd_get_psk(const struct hostapd_bss_config *conf,
759fd76b 913 const u8 *addr, const u8 *p2p_dev_addr,
dbfa691d 914 const u8 *prev_psk, int *vlan_id)
6fc6879b
JM
915{
916 struct hostapd_wpa_psk *psk;
917 int next_ok = prev_psk == NULL;
918
dbfa691d
JM
919 if (vlan_id)
920 *vlan_id = 0;
921
dc87541e 922 if (p2p_dev_addr && !is_zero_ether_addr(p2p_dev_addr)) {
759fd76b
JM
923 wpa_printf(MSG_DEBUG, "Searching a PSK for " MACSTR
924 " p2p_dev_addr=" MACSTR " prev_psk=%p",
925 MAC2STR(addr), MAC2STR(p2p_dev_addr), prev_psk);
dc87541e 926 addr = NULL; /* Use P2P Device Address for matching */
759fd76b
JM
927 } else {
928 wpa_printf(MSG_DEBUG, "Searching a PSK for " MACSTR
929 " prev_psk=%p",
930 MAC2STR(addr), prev_psk);
931 }
932
6fc6879b
JM
933 for (psk = conf->ssid.wpa_psk; psk != NULL; psk = psk->next) {
934 if (next_ok &&
759fd76b
JM
935 (psk->group ||
936 (addr && os_memcmp(psk->addr, addr, ETH_ALEN) == 0) ||
937 (!addr && p2p_dev_addr &&
938 os_memcmp(psk->p2p_dev_addr, p2p_dev_addr, ETH_ALEN) ==
dbfa691d
JM
939 0))) {
940 if (vlan_id)
941 *vlan_id = psk->vlan_id;
6fc6879b 942 return psk->psk;
dbfa691d 943 }
6fc6879b
JM
944
945 if (psk->psk == prev_psk)
946 next_ok = 1;
947 }
948
949 return NULL;
950}
eff0fd1e
JM
951
952
953static int hostapd_config_check_bss(struct hostapd_bss_config *bss,
08081ad8
JM
954 struct hostapd_config *conf,
955 int full_config)
eff0fd1e 956{
08081ad8 957 if (full_config && bss->ieee802_1x && !bss->eap_server &&
eff0fd1e
JM
958 !bss->radius->auth_servers) {
959 wpa_printf(MSG_ERROR, "Invalid IEEE 802.1X configuration (no "
960 "EAP authenticator configured).");
961 return -1;
962 }
963
964 if (bss->wpa) {
965 int wep, i;
966
967 wep = bss->default_wep_key_len > 0 ||
968 bss->individual_wep_key_len > 0;
969 for (i = 0; i < NUM_WEP_KEYS; i++) {
970 if (bss->ssid.wep.keys_set) {
971 wep = 1;
972 break;
973 }
974 }
975
976 if (wep) {
977 wpa_printf(MSG_ERROR, "WEP configuration in a WPA network is not supported");
978 return -1;
979 }
980 }
981
08081ad8
JM
982 if (full_config && bss->wpa &&
983 bss->wpa_psk_radius != PSK_RADIUS_IGNORED &&
eff0fd1e
JM
984 bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH) {
985 wpa_printf(MSG_ERROR, "WPA-PSK using RADIUS enabled, but no "
986 "RADIUS checking (macaddr_acl=2) enabled.");
987 return -1;
988 }
989
08081ad8 990 if (full_config && bss->wpa && (bss->wpa_key_mgmt & WPA_KEY_MGMT_PSK) &&
eff0fd1e
JM
991 bss->ssid.wpa_psk == NULL && bss->ssid.wpa_passphrase == NULL &&
992 bss->ssid.wpa_psk_file == NULL &&
993 (bss->wpa_psk_radius != PSK_RADIUS_REQUIRED ||
994 bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH)) {
995 wpa_printf(MSG_ERROR, "WPA-PSK enabled, but PSK or passphrase "
996 "is not configured.");
997 return -1;
998 }
999
902c07a7 1000 if (full_config && !is_zero_ether_addr(bss->bssid)) {
eff0fd1e
JM
1001 size_t i;
1002
1003 for (i = 0; i < conf->num_bss; i++) {
1004 if (conf->bss[i] != bss &&
1005 (hostapd_mac_comp(conf->bss[i]->bssid,
1006 bss->bssid) == 0)) {
1007 wpa_printf(MSG_ERROR, "Duplicate BSSID " MACSTR
1008 " on interface '%s' and '%s'.",
1009 MAC2STR(bss->bssid),
1010 conf->bss[i]->iface, bss->iface);
1011 return -1;
1012 }
1013 }
1014 }
1015
4ec1fd8e 1016#ifdef CONFIG_IEEE80211R_AP
08081ad8 1017 if (full_config && wpa_key_mgmt_ft(bss->wpa_key_mgmt) &&
eff0fd1e
JM
1018 (bss->nas_identifier == NULL ||
1019 os_strlen(bss->nas_identifier) < 1 ||
1020 os_strlen(bss->nas_identifier) > FT_R0KH_ID_MAX_LEN)) {
1021 wpa_printf(MSG_ERROR, "FT (IEEE 802.11r) requires "
1022 "nas_identifier to be configured as a 1..48 octet "
1023 "string");
1024 return -1;
1025 }
4ec1fd8e 1026#endif /* CONFIG_IEEE80211R_AP */
eff0fd1e
JM
1027
1028#ifdef CONFIG_IEEE80211N
08081ad8
JM
1029 if (full_config && conf->ieee80211n &&
1030 conf->hw_mode == HOSTAPD_MODE_IEEE80211B) {
eff0fd1e
JM
1031 bss->disable_11n = 1;
1032 wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) in 11b mode is not "
8c6f4a5a 1033 "allowed, disabling HT capabilities");
eff0fd1e
JM
1034 }
1035
08081ad8 1036 if (full_config && conf->ieee80211n &&
eff0fd1e
JM
1037 bss->ssid.security_policy == SECURITY_STATIC_WEP) {
1038 bss->disable_11n = 1;
1039 wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) with WEP is not "
1040 "allowed, disabling HT capabilities");
1041 }
1042
08081ad8 1043 if (full_config && conf->ieee80211n && bss->wpa &&
eff0fd1e 1044 !(bss->wpa_pairwise & WPA_CIPHER_CCMP) &&
30675c34
JM
1045 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
1046 WPA_CIPHER_CCMP_256 | WPA_CIPHER_GCMP_256)))
1047 {
eff0fd1e
JM
1048 bss->disable_11n = 1;
1049 wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) with WPA/WPA2 "
1050 "requires CCMP/GCMP to be enabled, disabling HT "
1051 "capabilities");
1052 }
1053#endif /* CONFIG_IEEE80211N */
1054
551817a5
WG
1055#ifdef CONFIG_IEEE80211AC
1056 if (full_config && conf->ieee80211ac &&
1057 bss->ssid.security_policy == SECURITY_STATIC_WEP) {
1058 bss->disable_11ac = 1;
1059 wpa_printf(MSG_ERROR,
1060 "VHT (IEEE 802.11ac) with WEP is not allowed, disabling VHT capabilities");
1061 }
59d7cff7
FM
1062
1063 if (full_config && conf->ieee80211ac && bss->wpa &&
1064 !(bss->wpa_pairwise & WPA_CIPHER_CCMP) &&
1065 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
1066 WPA_CIPHER_CCMP_256 | WPA_CIPHER_GCMP_256)))
1067 {
1068 bss->disable_11ac = 1;
1069 wpa_printf(MSG_ERROR,
1070 "VHT (IEEE 802.11ac) with WPA/WPA2 requires CCMP/GCMP to be enabled, disabling VHT capabilities");
1071 }
551817a5
WG
1072#endif /* CONFIG_IEEE80211AC */
1073
c201f93a 1074#ifdef CONFIG_WPS
08081ad8 1075 if (full_config && bss->wps_state && bss->ignore_broadcast_ssid) {
eff0fd1e
JM
1076 wpa_printf(MSG_INFO, "WPS: ignore_broadcast_ssid "
1077 "configuration forced WPS to be disabled");
1078 bss->wps_state = 0;
1079 }
1080
08081ad8
JM
1081 if (full_config && bss->wps_state &&
1082 bss->ssid.wep.keys_set && bss->wpa == 0) {
eff0fd1e
JM
1083 wpa_printf(MSG_INFO, "WPS: WEP configuration forced WPS to be "
1084 "disabled");
1085 bss->wps_state = 0;
1086 }
1087
08081ad8 1088 if (full_config && bss->wps_state && bss->wpa &&
eff0fd1e 1089 (!(bss->wpa & 2) ||
a2660890
SSG
1090 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
1091 WPA_CIPHER_CCMP_256 |
1092 WPA_CIPHER_GCMP_256)))) {
eff0fd1e 1093 wpa_printf(MSG_INFO, "WPS: WPA/TKIP configuration without "
01a02593 1094 "WPA2/CCMP/GCMP forced WPS to be disabled");
eff0fd1e
JM
1095 bss->wps_state = 0;
1096 }
c201f93a 1097#endif /* CONFIG_WPS */
eff0fd1e
JM
1098
1099#ifdef CONFIG_HS20
08081ad8 1100 if (full_config && bss->hs20 &&
eff0fd1e 1101 (!(bss->wpa & 2) ||
30675c34
JM
1102 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
1103 WPA_CIPHER_CCMP_256 |
1104 WPA_CIPHER_GCMP_256)))) {
eff0fd1e
JM
1105 wpa_printf(MSG_ERROR, "HS 2.0: WPA2-Enterprise/CCMP "
1106 "configuration is required for Hotspot 2.0 "
1107 "functionality");
1108 return -1;
1109 }
1110#endif /* CONFIG_HS20 */
1111
4c572281
JM
1112#ifdef CONFIG_MBO
1113 if (full_config && bss->mbo_enabled && (bss->wpa & 2) &&
1114 bss->ieee80211w == NO_MGMT_FRAME_PROTECTION) {
1115 wpa_printf(MSG_ERROR,
1116 "MBO: PMF needs to be enabled whenever using WPA2 with MBO");
1117 return -1;
1118 }
1119#endif /* CONFIG_MBO */
1120
9c55fdb0
MV
1121#ifdef CONFIG_OCV
1122 if (full_config && bss->ieee80211w == NO_MGMT_FRAME_PROTECTION &&
1123 bss->ocv) {
1124 wpa_printf(MSG_ERROR,
1125 "OCV: PMF needs to be enabled whenever using OCV");
1126 return -1;
1127 }
1128#endif /* CONFIG_OCV */
1129
eff0fd1e
JM
1130 return 0;
1131}
1132
1133
8884ce03
MM
1134static int hostapd_config_check_cw(struct hostapd_config *conf, int queue)
1135{
1136 int tx_cwmin = conf->tx_queue[queue].cwmin;
1137 int tx_cwmax = conf->tx_queue[queue].cwmax;
1138 int ac_cwmin = conf->wmm_ac_params[queue].cwmin;
1139 int ac_cwmax = conf->wmm_ac_params[queue].cwmax;
1140
1141 if (tx_cwmin > tx_cwmax) {
1142 wpa_printf(MSG_ERROR,
1143 "Invalid TX queue cwMin/cwMax values. cwMin(%d) greater than cwMax(%d)",
1144 tx_cwmin, tx_cwmax);
1145 return -1;
1146 }
1147 if (ac_cwmin > ac_cwmax) {
1148 wpa_printf(MSG_ERROR,
1149 "Invalid WMM AC cwMin/cwMax values. cwMin(%d) greater than cwMax(%d)",
1150 ac_cwmin, ac_cwmax);
1151 return -1;
1152 }
1153 return 0;
1154}
1155
1156
08081ad8 1157int hostapd_config_check(struct hostapd_config *conf, int full_config)
eff0fd1e
JM
1158{
1159 size_t i;
1160
08081ad8
JM
1161 if (full_config && conf->ieee80211d &&
1162 (!conf->country[0] || !conf->country[1])) {
eff0fd1e
JM
1163 wpa_printf(MSG_ERROR, "Cannot enable IEEE 802.11d without "
1164 "setting the country_code");
1165 return -1;
1166 }
1167
08081ad8 1168 if (full_config && conf->ieee80211h && !conf->ieee80211d) {
eff0fd1e
JM
1169 wpa_printf(MSG_ERROR, "Cannot enable IEEE 802.11h without "
1170 "IEEE 802.11d enabled");
1171 return -1;
1172 }
1173
e0392f82
S
1174 if (full_config && conf->local_pwr_constraint != -1 &&
1175 !conf->ieee80211d) {
1176 wpa_printf(MSG_ERROR, "Cannot add Power Constraint element without Country element");
1177 return -1;
1178 }
1179
3d7ad2f6
C
1180 if (full_config && conf->spectrum_mgmt_required &&
1181 conf->local_pwr_constraint == -1) {
1182 wpa_printf(MSG_ERROR, "Cannot set Spectrum Management bit without Country and Power Constraint elements");
1183 return -1;
1184 }
1185
ef721751
THJ
1186#ifdef CONFIG_AIRTIME_POLICY
1187 if (full_config && conf->airtime_mode > AIRTIME_MODE_STATIC &&
1188 !conf->airtime_update_interval) {
1189 wpa_printf(MSG_ERROR, "Airtime update interval cannot be zero");
1190 return -1;
1191 }
1192#endif /* CONFIG_AIRTIME_POLICY */
8884ce03
MM
1193 for (i = 0; i < NUM_TX_QUEUES; i++) {
1194 if (hostapd_config_check_cw(conf, i))
1195 return -1;
1196 }
1197
eff0fd1e 1198 for (i = 0; i < conf->num_bss; i++) {
08081ad8 1199 if (hostapd_config_check_bss(conf->bss[i], conf, full_config))
eff0fd1e
JM
1200 return -1;
1201 }
1202
1203 return 0;
1204}
1205
1206
5d67bf15
JM
1207void hostapd_set_security_params(struct hostapd_bss_config *bss,
1208 int full_config)
eff0fd1e
JM
1209{
1210 if (bss->individual_wep_key_len == 0) {
1211 /* individual keys are not use; can use key idx0 for
1212 * broadcast keys */
1213 bss->broadcast_key_idx_min = 0;
1214 }
1215
1216 if ((bss->wpa & 2) && bss->rsn_pairwise == 0)
1217 bss->rsn_pairwise = bss->wpa_pairwise;
27781c0a
JM
1218 if (bss->group_cipher)
1219 bss->wpa_group = bss->group_cipher;
1220 else
1221 bss->wpa_group = wpa_select_ap_group_cipher(bss->wpa,
1222 bss->wpa_pairwise,
1223 bss->rsn_pairwise);
90f837b0
JM
1224 if (!bss->wpa_group_rekey_set)
1225 bss->wpa_group_rekey = bss->wpa_group == WPA_CIPHER_TKIP ?
1226 600 : 86400;
eff0fd1e 1227
5d67bf15
JM
1228 if (full_config) {
1229 bss->radius->auth_server = bss->radius->auth_servers;
1230 bss->radius->acct_server = bss->radius->acct_servers;
1231 }
eff0fd1e
JM
1232
1233 if (bss->wpa && bss->ieee802_1x) {
1234 bss->ssid.security_policy = SECURITY_WPA;
1235 } else if (bss->wpa) {
1236 bss->ssid.security_policy = SECURITY_WPA_PSK;
1237 } else if (bss->ieee802_1x) {
1238 int cipher = WPA_CIPHER_NONE;
1239 bss->ssid.security_policy = SECURITY_IEEE_802_1X;
1240 bss->ssid.wep.default_len = bss->default_wep_key_len;
13a3a20d 1241 if (full_config && bss->default_wep_key_len) {
eff0fd1e
JM
1242 cipher = bss->default_wep_key_len >= 13 ?
1243 WPA_CIPHER_WEP104 : WPA_CIPHER_WEP40;
13a3a20d
JM
1244 } else if (full_config && bss->ssid.wep.keys_set) {
1245 if (bss->ssid.wep.len[0] >= 13)
1246 cipher = WPA_CIPHER_WEP104;
1247 else
1248 cipher = WPA_CIPHER_WEP40;
1249 }
eff0fd1e
JM
1250 bss->wpa_group = cipher;
1251 bss->wpa_pairwise = cipher;
1252 bss->rsn_pairwise = cipher;
13a3a20d
JM
1253 if (full_config)
1254 bss->wpa_key_mgmt = WPA_KEY_MGMT_IEEE8021X_NO_WPA;
eff0fd1e
JM
1255 } else if (bss->ssid.wep.keys_set) {
1256 int cipher = WPA_CIPHER_WEP40;
1257 if (bss->ssid.wep.len[0] >= 13)
1258 cipher = WPA_CIPHER_WEP104;
1259 bss->ssid.security_policy = SECURITY_STATIC_WEP;
1260 bss->wpa_group = cipher;
1261 bss->wpa_pairwise = cipher;
1262 bss->rsn_pairwise = cipher;
13a3a20d
JM
1263 if (full_config)
1264 bss->wpa_key_mgmt = WPA_KEY_MGMT_NONE;
a14896e8
JM
1265 } else if (bss->osen) {
1266 bss->ssid.security_policy = SECURITY_OSEN;
1267 bss->wpa_group = WPA_CIPHER_CCMP;
1268 bss->wpa_pairwise = 0;
1269 bss->rsn_pairwise = WPA_CIPHER_CCMP;
eff0fd1e
JM
1270 } else {
1271 bss->ssid.security_policy = SECURITY_PLAINTEXT;
29767152
JM
1272 if (full_config) {
1273 bss->wpa_group = WPA_CIPHER_NONE;
1274 bss->wpa_pairwise = WPA_CIPHER_NONE;
1275 bss->rsn_pairwise = WPA_CIPHER_NONE;
13a3a20d 1276 bss->wpa_key_mgmt = WPA_KEY_MGMT_NONE;
29767152 1277 }
eff0fd1e
JM
1278 }
1279}
42d30863
JM
1280
1281
1282int hostapd_sae_pw_id_in_use(struct hostapd_bss_config *conf)
1283{
1284 int with_id = 0, without_id = 0;
1285 struct sae_password_entry *pw;
1286
1287 if (conf->ssid.wpa_passphrase)
1288 without_id = 1;
1289
1290 for (pw = conf->sae_passwords; pw; pw = pw->next) {
1291 if (pw->identifier)
1292 with_id = 1;
1293 else
1294 without_id = 1;
1295 if (with_id && without_id)
1296 break;
1297 }
1298
1299 if (with_id && !without_id)
1300 return 2;
1301 return with_id;
1302}