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