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