2 * hostapd / Configuration helper functions
3 * Copyright (c) 2003-2014, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
9 #include "utils/includes.h"
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/eapol_common.h"
17 #include "common/dhcp.h"
18 #include "eap_common/eap_wsc_common.h"
19 #include "eap_server/eap.h"
22 #include "ap_config.h"
25 static void hostapd_config_free_vlan(struct hostapd_bss_config
*bss
)
27 struct hostapd_vlan
*vlan
, *prev
;
41 #ifndef DEFAULT_WPA_DISABLE_EAPOL_KEY_RETRIES
42 #define DEFAULT_WPA_DISABLE_EAPOL_KEY_RETRIES 0
43 #endif /* DEFAULT_WPA_DISABLE_EAPOL_KEY_RETRIES */
45 void hostapd_config_defaults_bss(struct hostapd_bss_config
*bss
)
47 dl_list_init(&bss
->anqp_elem
);
49 bss
->logger_syslog_level
= HOSTAPD_LEVEL_INFO
;
50 bss
->logger_stdout_level
= HOSTAPD_LEVEL_INFO
;
51 bss
->logger_syslog
= (unsigned int) -1;
52 bss
->logger_stdout
= (unsigned int) -1;
54 bss
->auth_algs
= WPA_AUTH_ALG_OPEN
| WPA_AUTH_ALG_SHARED
;
56 bss
->wep_rekeying_period
= 300;
57 /* use key0 in individual key and key1 in broadcast key */
58 bss
->broadcast_key_idx_min
= 1;
59 bss
->broadcast_key_idx_max
= 2;
60 bss
->eap_reauth_period
= 3600;
62 bss
->wpa_group_rekey
= 600;
63 bss
->wpa_gmk_rekey
= 86400;
64 bss
->wpa_group_update_count
= 4;
65 bss
->wpa_pairwise_update_count
= 4;
66 bss
->wpa_disable_eapol_key_retries
=
67 DEFAULT_WPA_DISABLE_EAPOL_KEY_RETRIES
;
68 bss
->wpa_key_mgmt
= WPA_KEY_MGMT_PSK
;
69 bss
->wpa_pairwise
= WPA_CIPHER_TKIP
;
70 bss
->wpa_group
= WPA_CIPHER_TKIP
;
71 bss
->rsn_pairwise
= 0;
73 bss
->max_num_sta
= MAX_STA_COUNT
;
77 bss
->radius_server_auth_port
= 1812;
78 bss
->eap_sim_db_timeout
= 1;
79 bss
->ap_max_inactivity
= AP_MAX_INACTIVITY
;
80 bss
->eapol_version
= EAPOL_VERSION
;
82 bss
->max_listen_interval
= 65535;
84 bss
->pwd_group
= 19; /* ECC: GF(p=256) */
86 #ifdef CONFIG_IEEE80211W
87 bss
->assoc_sa_query_max_timeout
= 1000;
88 bss
->assoc_sa_query_retry_timeout
= 201;
89 bss
->group_mgmt_cipher
= WPA_CIPHER_AES_128_CMAC
;
90 #endif /* CONFIG_IEEE80211W */
91 #ifdef EAP_SERVER_FAST
92 /* both anonymous and authenticated provisioning */
93 bss
->eap_fast_prov
= 3;
94 bss
->pac_key_lifetime
= 7 * 24 * 60 * 60;
95 bss
->pac_key_refresh_time
= 1 * 24 * 60 * 60;
96 #endif /* EAP_SERVER_FAST */
98 /* Set to -1 as defaults depends on HT in setup */
99 bss
->wmm_enabled
= -1;
101 #ifdef CONFIG_IEEE80211R_AP
103 bss
->rkh_pos_timeout
= 86400;
104 bss
->rkh_neg_timeout
= 60;
105 bss
->rkh_pull_timeout
= 1000;
106 bss
->rkh_pull_retries
= 4;
107 bss
->r0_key_lifetime
= 1209600;
108 #endif /* CONFIG_IEEE80211R_AP */
110 bss
->radius_das_time_window
= 300;
112 bss
->sae_anti_clogging_threshold
= 5;
115 bss
->gas_frag_limit
= 1400;
118 dl_list_init(&bss
->fils_realms
);
119 bss
->fils_hlp_wait_time
= 30;
120 bss
->dhcp_server_port
= DHCP_SERVER_PORT
;
121 bss
->dhcp_relay_port
= DHCP_SERVER_PORT
;
122 #endif /* CONFIG_FILS */
124 bss
->broadcast_deauth
= 1;
127 bss
->mbo_cell_data_conn_pref
= -1;
128 #endif /* CONFIG_MBO */
130 /* Disable TLS v1.3 by default for now to avoid interoperability issue.
131 * This can be enabled by default once the implementation has been fully
132 * completed and tested with other implementations. */
133 bss
->tls_flags
= TLS_CONN_DISABLE_TLSv1_3
;
135 bss
->send_probe_response
= 1;
138 bss
->hs20_release
= (HS20_VERSION
>> 4) + 1;
139 #endif /* CONFIG_HS20 */
141 /* Default to strict CRL checking. */
142 bss
->check_crl_strict
= 1;
146 struct hostapd_config
* hostapd_config_defaults(void)
148 #define ecw2cw(ecw) ((1 << (ecw)) - 1)
150 struct hostapd_config
*conf
;
151 struct hostapd_bss_config
*bss
;
152 const int aCWmin
= 4, aCWmax
= 10;
153 const struct hostapd_wmm_ac_params ac_bk
=
154 { aCWmin
, aCWmax
, 7, 0, 0 }; /* background traffic */
155 const struct hostapd_wmm_ac_params ac_be
=
156 { aCWmin
, aCWmax
, 3, 0, 0 }; /* best effort traffic */
157 const struct hostapd_wmm_ac_params ac_vi
= /* video traffic */
158 { aCWmin
- 1, aCWmin
, 2, 3008 / 32, 0 };
159 const struct hostapd_wmm_ac_params ac_vo
= /* voice traffic */
160 { aCWmin
- 2, aCWmin
- 1, 2, 1504 / 32, 0 };
161 const struct hostapd_tx_queue_params txq_bk
=
162 { 7, ecw2cw(aCWmin
), ecw2cw(aCWmax
), 0 };
163 const struct hostapd_tx_queue_params txq_be
=
164 { 3, ecw2cw(aCWmin
), 4 * (ecw2cw(aCWmin
) + 1) - 1, 0};
165 const struct hostapd_tx_queue_params txq_vi
=
166 { 1, (ecw2cw(aCWmin
) + 1) / 2 - 1, ecw2cw(aCWmin
), 30};
167 const struct hostapd_tx_queue_params txq_vo
=
168 { 1, (ecw2cw(aCWmin
) + 1) / 4 - 1,
169 (ecw2cw(aCWmin
) + 1) / 2 - 1, 15};
173 conf
= os_zalloc(sizeof(*conf
));
174 bss
= os_zalloc(sizeof(*bss
));
175 if (conf
== NULL
|| bss
== NULL
) {
176 wpa_printf(MSG_ERROR
, "Failed to allocate memory for "
177 "configuration data.");
182 conf
->bss
= os_calloc(1, sizeof(struct hostapd_bss_config
*));
183 if (conf
->bss
== NULL
) {
190 bss
->radius
= os_zalloc(sizeof(*bss
->radius
));
191 if (bss
->radius
== NULL
) {
198 hostapd_config_defaults_bss(bss
);
202 conf
->beacon_int
= 100;
203 conf
->rts_threshold
= -1; /* use driver default: 2347 */
204 conf
->fragm_threshold
= -1; /* user driver default: 2346 */
205 /* Set to invalid value means do not add Power Constraint IE */
206 conf
->local_pwr_constraint
= -1;
208 conf
->wmm_ac_params
[0] = ac_be
;
209 conf
->wmm_ac_params
[1] = ac_bk
;
210 conf
->wmm_ac_params
[2] = ac_vi
;
211 conf
->wmm_ac_params
[3] = ac_vo
;
213 conf
->tx_queue
[0] = txq_vo
;
214 conf
->tx_queue
[1] = txq_vi
;
215 conf
->tx_queue
[2] = txq_be
;
216 conf
->tx_queue
[3] = txq_bk
;
218 conf
->ht_capab
= HT_CAP_INFO_SMPS_DISABLED
;
220 conf
->ap_table_max_size
= 255;
221 conf
->ap_table_expiration_time
= 60;
222 conf
->track_sta_max_age
= 180;
224 #ifdef CONFIG_TESTING_OPTIONS
225 conf
->ignore_probe_probability
= 0.0;
226 conf
->ignore_auth_probability
= 0.0;
227 conf
->ignore_assoc_probability
= 0.0;
228 conf
->ignore_reassoc_probability
= 0.0;
229 conf
->corrupt_gtk_rekey_mic_probability
= 0.0;
230 conf
->ecsa_ie_only
= 0;
231 #endif /* CONFIG_TESTING_OPTIONS */
234 conf
->acs_ch_list
.num
= 0;
236 conf
->acs_num_scans
= 5;
237 #endif /* CONFIG_ACS */
239 /* The third octet of the country string uses an ASCII space character
240 * by default to indicate that the regulations encompass all
241 * environments for the current frequency band in the country. */
242 conf
->country
[2] = ' ';
244 conf
->rssi_reject_assoc_rssi
= 0;
245 conf
->rssi_reject_assoc_timeout
= 30;
251 int hostapd_mac_comp(const void *a
, const void *b
)
253 return os_memcmp(a
, b
, sizeof(macaddr
));
257 static int hostapd_config_read_wpa_psk(const char *fname
,
258 struct hostapd_ssid
*ssid
)
268 int line
= 0, ret
= 0, len
, ok
;
270 struct hostapd_wpa_psk
*psk
;
275 f
= fopen(fname
, "r");
277 wpa_printf(MSG_ERROR
, "WPA PSK file '%s' not found.", fname
);
281 while (fgets(buf
, sizeof(buf
), f
)) {
289 while (*pos
!= '\0') {
301 while ((token
= str_token(buf
, " ", &context
))) {
302 if (!os_strchr(token
, '='))
305 name
= str_token(token
, "=", &context2
);
308 value
= str_token(token
, "", &context2
);
311 if (!os_strcmp(name
, "keyid")) {
313 } else if (!os_strcmp(name
, "vlanid")) {
314 vlan_id
= atoi(value
);
316 wpa_printf(MSG_ERROR
,
317 "Unrecognized '%s=%s' on line %d in '%s'",
318 name
, value
, line
, fname
);
329 if (hwaddr_aton(token
, addr
)) {
330 wpa_printf(MSG_ERROR
, "Invalid MAC address '%s' on "
331 "line %d in '%s'", token
, line
, fname
);
336 psk
= os_zalloc(sizeof(*psk
));
338 wpa_printf(MSG_ERROR
, "WPA PSK allocation failed");
342 psk
->vlan_id
= vlan_id
;
343 if (is_zero_ether_addr(addr
))
346 os_memcpy(psk
->addr
, addr
, ETH_ALEN
);
348 pos
= str_token(buf
, "", &context
);
350 wpa_printf(MSG_ERROR
, "No PSK on line %d in '%s'",
358 len
= os_strlen(pos
);
359 if (len
== 64 && hexstr2bin(pos
, psk
->psk
, PMK_LEN
) == 0)
361 else if (len
>= 8 && len
< 64) {
362 pbkdf2_sha1(pos
, ssid
->ssid
, ssid
->ssid_len
,
363 4096, psk
->psk
, PMK_LEN
);
367 wpa_printf(MSG_ERROR
, "Invalid PSK '%s' on line %d in "
368 "'%s'", pos
, line
, fname
);
375 len
= os_strlcpy(psk
->keyid
, keyid
, sizeof(psk
->keyid
));
376 if ((size_t) len
>= sizeof(psk
->keyid
)) {
377 wpa_printf(MSG_ERROR
,
378 "PSK keyid too long on line %d in '%s'",
386 psk
->next
= ssid
->wpa_psk
;
396 static int hostapd_derive_psk(struct hostapd_ssid
*ssid
)
398 ssid
->wpa_psk
= os_zalloc(sizeof(struct hostapd_wpa_psk
));
399 if (ssid
->wpa_psk
== NULL
) {
400 wpa_printf(MSG_ERROR
, "Unable to alloc space for PSK");
403 wpa_hexdump_ascii(MSG_DEBUG
, "SSID",
404 (u8
*) ssid
->ssid
, ssid
->ssid_len
);
405 wpa_hexdump_ascii_key(MSG_DEBUG
, "PSK (ASCII passphrase)",
406 (u8
*) ssid
->wpa_passphrase
,
407 os_strlen(ssid
->wpa_passphrase
));
408 pbkdf2_sha1(ssid
->wpa_passphrase
,
409 ssid
->ssid
, ssid
->ssid_len
,
410 4096, ssid
->wpa_psk
->psk
, PMK_LEN
);
411 wpa_hexdump_key(MSG_DEBUG
, "PSK (from passphrase)",
412 ssid
->wpa_psk
->psk
, PMK_LEN
);
417 int hostapd_setup_wpa_psk(struct hostapd_bss_config
*conf
)
419 struct hostapd_ssid
*ssid
= &conf
->ssid
;
421 if (ssid
->wpa_passphrase
!= NULL
) {
422 if (ssid
->wpa_psk
!= NULL
) {
423 wpa_printf(MSG_DEBUG
, "Using pre-configured WPA PSK "
424 "instead of passphrase");
426 wpa_printf(MSG_DEBUG
, "Deriving WPA PSK based on "
428 if (hostapd_derive_psk(ssid
) < 0)
431 ssid
->wpa_psk
->group
= 1;
434 return hostapd_config_read_wpa_psk(ssid
->wpa_psk_file
, &conf
->ssid
);
438 static void hostapd_config_free_radius(struct hostapd_radius_server
*servers
,
443 for (i
= 0; i
< num_servers
; i
++) {
444 os_free(servers
[i
].shared_secret
);
450 struct hostapd_radius_attr
*
451 hostapd_config_get_radius_attr(struct hostapd_radius_attr
*attr
, u8 type
)
453 for (; attr
; attr
= attr
->next
) {
454 if (attr
->type
== type
)
461 static void hostapd_config_free_radius_attr(struct hostapd_radius_attr
*attr
)
463 struct hostapd_radius_attr
*prev
;
468 wpabuf_free(prev
->val
);
474 void hostapd_config_free_eap_user(struct hostapd_eap_user
*user
)
476 hostapd_config_free_radius_attr(user
->accept_attr
);
477 os_free(user
->identity
);
478 bin_clear_free(user
->password
, user
->password_len
);
479 bin_clear_free(user
->salt
, user
->salt_len
);
484 void hostapd_config_free_eap_users(struct hostapd_eap_user
*user
)
486 struct hostapd_eap_user
*prev_user
;
491 hostapd_config_free_eap_user(prev_user
);
496 static void hostapd_config_free_wep(struct hostapd_wep_keys
*keys
)
499 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
500 bin_clear_free(keys
->key
[i
], keys
->len
[i
]);
506 void hostapd_config_clear_wpa_psk(struct hostapd_wpa_psk
**l
)
508 struct hostapd_wpa_psk
*psk
, *tmp
;
510 for (psk
= *l
; psk
;) {
513 bin_clear_free(tmp
, sizeof(*tmp
));
519 static void hostapd_config_free_anqp_elem(struct hostapd_bss_config
*conf
)
521 struct anqp_element
*elem
;
523 while ((elem
= dl_list_first(&conf
->anqp_elem
, struct anqp_element
,
525 dl_list_del(&elem
->list
);
526 wpabuf_free(elem
->payload
);
532 static void hostapd_config_free_fils_realms(struct hostapd_bss_config
*conf
)
535 struct fils_realm
*realm
;
537 while ((realm
= dl_list_first(&conf
->fils_realms
, struct fils_realm
,
539 dl_list_del(&realm
->list
);
542 #endif /* CONFIG_FILS */
546 static void hostapd_config_free_sae_passwords(struct hostapd_bss_config
*conf
)
548 struct sae_password_entry
*pw
, *tmp
;
550 pw
= conf
->sae_passwords
;
551 conf
->sae_passwords
= NULL
;
555 str_clear_free(tmp
->password
);
556 os_free(tmp
->identifier
);
562 void hostapd_config_free_bss(struct hostapd_bss_config
*conf
)
567 hostapd_config_clear_wpa_psk(&conf
->ssid
.wpa_psk
);
569 str_clear_free(conf
->ssid
.wpa_passphrase
);
570 os_free(conf
->ssid
.wpa_psk_file
);
571 hostapd_config_free_wep(&conf
->ssid
.wep
);
572 #ifdef CONFIG_FULL_DYNAMIC_VLAN
573 os_free(conf
->ssid
.vlan_tagged_interface
);
574 #endif /* CONFIG_FULL_DYNAMIC_VLAN */
576 hostapd_config_free_eap_users(conf
->eap_user
);
577 os_free(conf
->eap_user_sqlite
);
579 os_free(conf
->eap_req_id_text
);
580 os_free(conf
->erp_domain
);
581 os_free(conf
->accept_mac
);
582 os_free(conf
->deny_mac
);
583 os_free(conf
->nas_identifier
);
585 hostapd_config_free_radius(conf
->radius
->auth_servers
,
586 conf
->radius
->num_auth_servers
);
587 hostapd_config_free_radius(conf
->radius
->acct_servers
,
588 conf
->radius
->num_acct_servers
);
590 hostapd_config_free_radius_attr(conf
->radius_auth_req_attr
);
591 hostapd_config_free_radius_attr(conf
->radius_acct_req_attr
);
592 os_free(conf
->rsn_preauth_interfaces
);
593 os_free(conf
->ctrl_interface
);
594 os_free(conf
->ca_cert
);
595 os_free(conf
->server_cert
);
596 os_free(conf
->private_key
);
597 os_free(conf
->private_key_passwd
);
598 os_free(conf
->ocsp_stapling_response
);
599 os_free(conf
->ocsp_stapling_response_multi
);
600 os_free(conf
->dh_file
);
601 os_free(conf
->openssl_ciphers
);
602 os_free(conf
->openssl_ecdh_curves
);
603 os_free(conf
->pac_opaque_encr_key
);
604 os_free(conf
->eap_fast_a_id
);
605 os_free(conf
->eap_fast_a_id_info
);
606 os_free(conf
->eap_sim_db
);
607 os_free(conf
->radius_server_clients
);
608 os_free(conf
->radius
);
609 os_free(conf
->radius_das_shared_secret
);
610 hostapd_config_free_vlan(conf
);
611 os_free(conf
->time_zone
);
613 #ifdef CONFIG_IEEE80211R_AP
615 struct ft_remote_r0kh
*r0kh
, *r0kh_prev
;
616 struct ft_remote_r1kh
*r1kh
, *r1kh_prev
;
618 r0kh
= conf
->r0kh_list
;
619 conf
->r0kh_list
= NULL
;
626 r1kh
= conf
->r1kh_list
;
627 conf
->r1kh_list
= NULL
;
634 #endif /* CONFIG_IEEE80211R_AP */
637 os_free(conf
->wps_pin_requests
);
638 os_free(conf
->device_name
);
639 os_free(conf
->manufacturer
);
640 os_free(conf
->model_name
);
641 os_free(conf
->model_number
);
642 os_free(conf
->serial_number
);
643 os_free(conf
->config_methods
);
644 os_free(conf
->ap_pin
);
645 os_free(conf
->extra_cred
);
646 os_free(conf
->ap_settings
);
647 hostapd_config_clear_wpa_psk(&conf
->multi_ap_backhaul_ssid
.wpa_psk
);
648 str_clear_free(conf
->multi_ap_backhaul_ssid
.wpa_passphrase
);
649 os_free(conf
->upnp_iface
);
650 os_free(conf
->friendly_name
);
651 os_free(conf
->manufacturer_url
);
652 os_free(conf
->model_description
);
653 os_free(conf
->model_url
);
658 for (i
= 0; i
< MAX_WPS_VENDOR_EXTENSIONS
; i
++)
659 wpabuf_free(conf
->wps_vendor_ext
[i
]);
661 wpabuf_free(conf
->wps_nfc_dh_pubkey
);
662 wpabuf_free(conf
->wps_nfc_dh_privkey
);
663 wpabuf_free(conf
->wps_nfc_dev_pw
);
664 #endif /* CONFIG_WPS */
666 os_free(conf
->roaming_consortium
);
667 os_free(conf
->venue_name
);
668 os_free(conf
->venue_url
);
669 os_free(conf
->nai_realm_data
);
670 os_free(conf
->network_auth_type
);
671 os_free(conf
->anqp_3gpp_cell_net
);
672 os_free(conf
->domain_name
);
673 hostapd_config_free_anqp_elem(conf
);
675 #ifdef CONFIG_RADIUS_TEST
676 os_free(conf
->dump_msk_file
);
677 #endif /* CONFIG_RADIUS_TEST */
680 os_free(conf
->hs20_oper_friendly_name
);
681 os_free(conf
->hs20_wan_metrics
);
682 os_free(conf
->hs20_connection_capability
);
683 os_free(conf
->hs20_operating_class
);
684 os_free(conf
->hs20_icons
);
685 if (conf
->hs20_osu_providers
) {
687 for (i
= 0; i
< conf
->hs20_osu_providers_count
; i
++) {
688 struct hs20_osu_provider
*p
;
690 p
= &conf
->hs20_osu_providers
[i
];
691 os_free(p
->friendly_name
);
692 os_free(p
->server_uri
);
693 os_free(p
->method_list
);
694 for (j
= 0; j
< p
->icons_count
; j
++)
695 os_free(p
->icons
[j
]);
698 os_free(p
->osu_nai2
);
699 os_free(p
->service_desc
);
701 os_free(conf
->hs20_osu_providers
);
703 if (conf
->hs20_operator_icon
) {
706 for (i
= 0; i
< conf
->hs20_operator_icon_count
; i
++)
707 os_free(conf
->hs20_operator_icon
[i
]);
708 os_free(conf
->hs20_operator_icon
);
710 os_free(conf
->subscr_remediation_url
);
711 os_free(conf
->hs20_sim_provisioning_url
);
712 os_free(conf
->t_c_filename
);
713 os_free(conf
->t_c_server_url
);
714 #endif /* CONFIG_HS20 */
716 wpabuf_free(conf
->vendor_elements
);
717 wpabuf_free(conf
->assocresp_elements
);
719 os_free(conf
->sae_groups
);
721 os_free(conf
->owe_groups
);
722 #endif /* CONFIG_OWE */
724 os_free(conf
->wowlan_triggers
);
726 os_free(conf
->server_id
);
728 #ifdef CONFIG_TESTING_OPTIONS
729 wpabuf_free(conf
->own_ie_override
);
730 wpabuf_free(conf
->sae_commit_override
);
731 #endif /* CONFIG_TESTING_OPTIONS */
733 os_free(conf
->no_probe_resp_if_seen_on
);
734 os_free(conf
->no_auth_if_seen_on
);
736 hostapd_config_free_fils_realms(conf
);
739 os_free(conf
->dpp_connector
);
740 wpabuf_free(conf
->dpp_netaccesskey
);
741 wpabuf_free(conf
->dpp_csign
);
742 #endif /* CONFIG_DPP */
744 hostapd_config_free_sae_passwords(conf
);
751 * hostapd_config_free - Free hostapd configuration
752 * @conf: Configuration data from hostapd_config_read().
754 void hostapd_config_free(struct hostapd_config
*conf
)
761 for (i
= 0; i
< conf
->num_bss
; i
++)
762 hostapd_config_free_bss(conf
->bss
[i
]);
764 os_free(conf
->supported_rates
);
765 os_free(conf
->basic_rates
);
766 os_free(conf
->acs_ch_list
.range
);
767 os_free(conf
->driver_params
);
769 os_free(conf
->acs_chan_bias
);
770 #endif /* CONFIG_ACS */
771 wpabuf_free(conf
->lci
);
772 wpabuf_free(conf
->civic
);
779 * hostapd_maclist_found - Find a MAC address from a list
780 * @list: MAC address list
781 * @num_entries: Number of addresses in the list
782 * @addr: Address to search for
783 * @vlan_id: Buffer for returning VLAN ID or %NULL if not needed
784 * Returns: 1 if address is in the list or 0 if not.
786 * Perform a binary search for given MAC address from a pre-sorted list.
788 int hostapd_maclist_found(struct mac_acl_entry
*list
, int num_entries
,
789 const u8
*addr
, struct vlan_description
*vlan_id
)
791 int start
, end
, middle
, res
;
794 end
= num_entries
- 1;
796 while (start
<= end
) {
797 middle
= (start
+ end
) / 2;
798 res
= os_memcmp(list
[middle
].addr
, addr
, ETH_ALEN
);
801 *vlan_id
= list
[middle
].vlan_id
;
814 int hostapd_rate_found(int *list
, int rate
)
821 for (i
= 0; list
[i
] >= 0; i
++)
829 int hostapd_vlan_valid(struct hostapd_vlan
*vlan
,
830 struct vlan_description
*vlan_desc
)
832 struct hostapd_vlan
*v
= vlan
;
835 if (!vlan_desc
->notempty
|| vlan_desc
->untagged
< 0 ||
836 vlan_desc
->untagged
> MAX_VLAN_ID
)
838 for (i
= 0; i
< MAX_NUM_TAGGED_VLAN
; i
++) {
839 if (vlan_desc
->tagged
[i
] < 0 ||
840 vlan_desc
->tagged
[i
] > MAX_VLAN_ID
)
843 if (!vlan_desc
->untagged
&& !vlan_desc
->tagged
[0])
847 if (!vlan_compare(&v
->vlan_desc
, vlan_desc
) ||
848 v
->vlan_id
== VLAN_ID_WILDCARD
)
856 const char * hostapd_get_vlan_id_ifname(struct hostapd_vlan
*vlan
, int vlan_id
)
858 struct hostapd_vlan
*v
= vlan
;
860 if (v
->vlan_id
== vlan_id
)
868 const u8
* hostapd_get_psk(const struct hostapd_bss_config
*conf
,
869 const u8
*addr
, const u8
*p2p_dev_addr
,
870 const u8
*prev_psk
, int *vlan_id
)
872 struct hostapd_wpa_psk
*psk
;
873 int next_ok
= prev_psk
== NULL
;
878 if (p2p_dev_addr
&& !is_zero_ether_addr(p2p_dev_addr
)) {
879 wpa_printf(MSG_DEBUG
, "Searching a PSK for " MACSTR
880 " p2p_dev_addr=" MACSTR
" prev_psk=%p",
881 MAC2STR(addr
), MAC2STR(p2p_dev_addr
), prev_psk
);
882 addr
= NULL
; /* Use P2P Device Address for matching */
884 wpa_printf(MSG_DEBUG
, "Searching a PSK for " MACSTR
886 MAC2STR(addr
), prev_psk
);
889 for (psk
= conf
->ssid
.wpa_psk
; psk
!= NULL
; psk
= psk
->next
) {
892 (addr
&& os_memcmp(psk
->addr
, addr
, ETH_ALEN
) == 0) ||
893 (!addr
&& p2p_dev_addr
&&
894 os_memcmp(psk
->p2p_dev_addr
, p2p_dev_addr
, ETH_ALEN
) ==
897 *vlan_id
= psk
->vlan_id
;
901 if (psk
->psk
== prev_psk
)
909 static int hostapd_config_check_bss(struct hostapd_bss_config
*bss
,
910 struct hostapd_config
*conf
,
913 if (full_config
&& bss
->ieee802_1x
&& !bss
->eap_server
&&
914 !bss
->radius
->auth_servers
) {
915 wpa_printf(MSG_ERROR
, "Invalid IEEE 802.1X configuration (no "
916 "EAP authenticator configured).");
923 wep
= bss
->default_wep_key_len
> 0 ||
924 bss
->individual_wep_key_len
> 0;
925 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
926 if (bss
->ssid
.wep
.keys_set
) {
933 wpa_printf(MSG_ERROR
, "WEP configuration in a WPA network is not supported");
938 if (full_config
&& bss
->wpa
&&
939 bss
->wpa_psk_radius
!= PSK_RADIUS_IGNORED
&&
940 bss
->macaddr_acl
!= USE_EXTERNAL_RADIUS_AUTH
) {
941 wpa_printf(MSG_ERROR
, "WPA-PSK using RADIUS enabled, but no "
942 "RADIUS checking (macaddr_acl=2) enabled.");
946 if (full_config
&& bss
->wpa
&& (bss
->wpa_key_mgmt
& WPA_KEY_MGMT_PSK
) &&
947 bss
->ssid
.wpa_psk
== NULL
&& bss
->ssid
.wpa_passphrase
== NULL
&&
948 bss
->ssid
.wpa_psk_file
== NULL
&&
949 (bss
->wpa_psk_radius
!= PSK_RADIUS_REQUIRED
||
950 bss
->macaddr_acl
!= USE_EXTERNAL_RADIUS_AUTH
)) {
951 wpa_printf(MSG_ERROR
, "WPA-PSK enabled, but PSK or passphrase "
952 "is not configured.");
956 if (full_config
&& !is_zero_ether_addr(bss
->bssid
)) {
959 for (i
= 0; i
< conf
->num_bss
; i
++) {
960 if (conf
->bss
[i
] != bss
&&
961 (hostapd_mac_comp(conf
->bss
[i
]->bssid
,
963 wpa_printf(MSG_ERROR
, "Duplicate BSSID " MACSTR
964 " on interface '%s' and '%s'.",
966 conf
->bss
[i
]->iface
, bss
->iface
);
972 #ifdef CONFIG_IEEE80211R_AP
973 if (full_config
&& wpa_key_mgmt_ft(bss
->wpa_key_mgmt
) &&
974 (bss
->nas_identifier
== NULL
||
975 os_strlen(bss
->nas_identifier
) < 1 ||
976 os_strlen(bss
->nas_identifier
) > FT_R0KH_ID_MAX_LEN
)) {
977 wpa_printf(MSG_ERROR
, "FT (IEEE 802.11r) requires "
978 "nas_identifier to be configured as a 1..48 octet "
982 #endif /* CONFIG_IEEE80211R_AP */
984 #ifdef CONFIG_IEEE80211N
985 if (full_config
&& conf
->ieee80211n
&&
986 conf
->hw_mode
== HOSTAPD_MODE_IEEE80211B
) {
987 bss
->disable_11n
= 1;
988 wpa_printf(MSG_ERROR
, "HT (IEEE 802.11n) in 11b mode is not "
989 "allowed, disabling HT capabilities");
992 if (full_config
&& conf
->ieee80211n
&&
993 bss
->ssid
.security_policy
== SECURITY_STATIC_WEP
) {
994 bss
->disable_11n
= 1;
995 wpa_printf(MSG_ERROR
, "HT (IEEE 802.11n) with WEP is not "
996 "allowed, disabling HT capabilities");
999 if (full_config
&& conf
->ieee80211n
&& bss
->wpa
&&
1000 !(bss
->wpa_pairwise
& WPA_CIPHER_CCMP
) &&
1001 !(bss
->rsn_pairwise
& (WPA_CIPHER_CCMP
| WPA_CIPHER_GCMP
|
1002 WPA_CIPHER_CCMP_256
| WPA_CIPHER_GCMP_256
)))
1004 bss
->disable_11n
= 1;
1005 wpa_printf(MSG_ERROR
, "HT (IEEE 802.11n) with WPA/WPA2 "
1006 "requires CCMP/GCMP to be enabled, disabling HT "
1009 #endif /* CONFIG_IEEE80211N */
1011 #ifdef CONFIG_IEEE80211AC
1012 if (full_config
&& conf
->ieee80211ac
&&
1013 bss
->ssid
.security_policy
== SECURITY_STATIC_WEP
) {
1014 bss
->disable_11ac
= 1;
1015 wpa_printf(MSG_ERROR
,
1016 "VHT (IEEE 802.11ac) with WEP is not allowed, disabling VHT capabilities");
1019 if (full_config
&& conf
->ieee80211ac
&& bss
->wpa
&&
1020 !(bss
->wpa_pairwise
& WPA_CIPHER_CCMP
) &&
1021 !(bss
->rsn_pairwise
& (WPA_CIPHER_CCMP
| WPA_CIPHER_GCMP
|
1022 WPA_CIPHER_CCMP_256
| WPA_CIPHER_GCMP_256
)))
1024 bss
->disable_11ac
= 1;
1025 wpa_printf(MSG_ERROR
,
1026 "VHT (IEEE 802.11ac) with WPA/WPA2 requires CCMP/GCMP to be enabled, disabling VHT capabilities");
1028 #endif /* CONFIG_IEEE80211AC */
1031 if (full_config
&& bss
->wps_state
&& bss
->ignore_broadcast_ssid
) {
1032 wpa_printf(MSG_INFO
, "WPS: ignore_broadcast_ssid "
1033 "configuration forced WPS to be disabled");
1037 if (full_config
&& bss
->wps_state
&&
1038 bss
->ssid
.wep
.keys_set
&& bss
->wpa
== 0) {
1039 wpa_printf(MSG_INFO
, "WPS: WEP configuration forced WPS to be "
1044 if (full_config
&& bss
->wps_state
&& bss
->wpa
&&
1046 !(bss
->rsn_pairwise
& (WPA_CIPHER_CCMP
| WPA_CIPHER_GCMP
|
1047 WPA_CIPHER_CCMP_256
|
1048 WPA_CIPHER_GCMP_256
)))) {
1049 wpa_printf(MSG_INFO
, "WPS: WPA/TKIP configuration without "
1050 "WPA2/CCMP/GCMP forced WPS to be disabled");
1053 #endif /* CONFIG_WPS */
1056 if (full_config
&& bss
->hs20
&&
1058 !(bss
->rsn_pairwise
& (WPA_CIPHER_CCMP
| WPA_CIPHER_GCMP
|
1059 WPA_CIPHER_CCMP_256
|
1060 WPA_CIPHER_GCMP_256
)))) {
1061 wpa_printf(MSG_ERROR
, "HS 2.0: WPA2-Enterprise/CCMP "
1062 "configuration is required for Hotspot 2.0 "
1066 #endif /* CONFIG_HS20 */
1069 if (full_config
&& bss
->mbo_enabled
&& (bss
->wpa
& 2) &&
1070 bss
->ieee80211w
== NO_MGMT_FRAME_PROTECTION
) {
1071 wpa_printf(MSG_ERROR
,
1072 "MBO: PMF needs to be enabled whenever using WPA2 with MBO");
1075 #endif /* CONFIG_MBO */
1078 if (full_config
&& bss
->ieee80211w
== NO_MGMT_FRAME_PROTECTION
&&
1080 wpa_printf(MSG_ERROR
,
1081 "OCV: PMF needs to be enabled whenever using OCV");
1084 #endif /* CONFIG_OCV */
1090 static int hostapd_config_check_cw(struct hostapd_config
*conf
, int queue
)
1092 int tx_cwmin
= conf
->tx_queue
[queue
].cwmin
;
1093 int tx_cwmax
= conf
->tx_queue
[queue
].cwmax
;
1094 int ac_cwmin
= conf
->wmm_ac_params
[queue
].cwmin
;
1095 int ac_cwmax
= conf
->wmm_ac_params
[queue
].cwmax
;
1097 if (tx_cwmin
> tx_cwmax
) {
1098 wpa_printf(MSG_ERROR
,
1099 "Invalid TX queue cwMin/cwMax values. cwMin(%d) greater than cwMax(%d)",
1100 tx_cwmin
, tx_cwmax
);
1103 if (ac_cwmin
> ac_cwmax
) {
1104 wpa_printf(MSG_ERROR
,
1105 "Invalid WMM AC cwMin/cwMax values. cwMin(%d) greater than cwMax(%d)",
1106 ac_cwmin
, ac_cwmax
);
1113 int hostapd_config_check(struct hostapd_config
*conf
, int full_config
)
1117 if (full_config
&& conf
->ieee80211d
&&
1118 (!conf
->country
[0] || !conf
->country
[1])) {
1119 wpa_printf(MSG_ERROR
, "Cannot enable IEEE 802.11d without "
1120 "setting the country_code");
1124 if (full_config
&& conf
->ieee80211h
&& !conf
->ieee80211d
) {
1125 wpa_printf(MSG_ERROR
, "Cannot enable IEEE 802.11h without "
1126 "IEEE 802.11d enabled");
1130 if (full_config
&& conf
->local_pwr_constraint
!= -1 &&
1131 !conf
->ieee80211d
) {
1132 wpa_printf(MSG_ERROR
, "Cannot add Power Constraint element without Country element");
1136 if (full_config
&& conf
->spectrum_mgmt_required
&&
1137 conf
->local_pwr_constraint
== -1) {
1138 wpa_printf(MSG_ERROR
, "Cannot set Spectrum Management bit without Country and Power Constraint elements");
1142 for (i
= 0; i
< NUM_TX_QUEUES
; i
++) {
1143 if (hostapd_config_check_cw(conf
, i
))
1147 for (i
= 0; i
< conf
->num_bss
; i
++) {
1148 if (hostapd_config_check_bss(conf
->bss
[i
], conf
, full_config
))
1156 void hostapd_set_security_params(struct hostapd_bss_config
*bss
,
1159 if (bss
->individual_wep_key_len
== 0) {
1160 /* individual keys are not use; can use key idx0 for
1162 bss
->broadcast_key_idx_min
= 0;
1165 if ((bss
->wpa
& 2) && bss
->rsn_pairwise
== 0)
1166 bss
->rsn_pairwise
= bss
->wpa_pairwise
;
1167 if (bss
->group_cipher
)
1168 bss
->wpa_group
= bss
->group_cipher
;
1170 bss
->wpa_group
= wpa_select_ap_group_cipher(bss
->wpa
,
1173 if (!bss
->wpa_group_rekey_set
)
1174 bss
->wpa_group_rekey
= bss
->wpa_group
== WPA_CIPHER_TKIP
?
1178 bss
->radius
->auth_server
= bss
->radius
->auth_servers
;
1179 bss
->radius
->acct_server
= bss
->radius
->acct_servers
;
1182 if (bss
->wpa
&& bss
->ieee802_1x
) {
1183 bss
->ssid
.security_policy
= SECURITY_WPA
;
1184 } else if (bss
->wpa
) {
1185 bss
->ssid
.security_policy
= SECURITY_WPA_PSK
;
1186 } else if (bss
->ieee802_1x
) {
1187 int cipher
= WPA_CIPHER_NONE
;
1188 bss
->ssid
.security_policy
= SECURITY_IEEE_802_1X
;
1189 bss
->ssid
.wep
.default_len
= bss
->default_wep_key_len
;
1190 if (full_config
&& bss
->default_wep_key_len
) {
1191 cipher
= bss
->default_wep_key_len
>= 13 ?
1192 WPA_CIPHER_WEP104
: WPA_CIPHER_WEP40
;
1193 } else if (full_config
&& bss
->ssid
.wep
.keys_set
) {
1194 if (bss
->ssid
.wep
.len
[0] >= 13)
1195 cipher
= WPA_CIPHER_WEP104
;
1197 cipher
= WPA_CIPHER_WEP40
;
1199 bss
->wpa_group
= cipher
;
1200 bss
->wpa_pairwise
= cipher
;
1201 bss
->rsn_pairwise
= cipher
;
1203 bss
->wpa_key_mgmt
= WPA_KEY_MGMT_IEEE8021X_NO_WPA
;
1204 } else if (bss
->ssid
.wep
.keys_set
) {
1205 int cipher
= WPA_CIPHER_WEP40
;
1206 if (bss
->ssid
.wep
.len
[0] >= 13)
1207 cipher
= WPA_CIPHER_WEP104
;
1208 bss
->ssid
.security_policy
= SECURITY_STATIC_WEP
;
1209 bss
->wpa_group
= cipher
;
1210 bss
->wpa_pairwise
= cipher
;
1211 bss
->rsn_pairwise
= cipher
;
1213 bss
->wpa_key_mgmt
= WPA_KEY_MGMT_NONE
;
1214 } else if (bss
->osen
) {
1215 bss
->ssid
.security_policy
= SECURITY_OSEN
;
1216 bss
->wpa_group
= WPA_CIPHER_CCMP
;
1217 bss
->wpa_pairwise
= 0;
1218 bss
->rsn_pairwise
= WPA_CIPHER_CCMP
;
1220 bss
->ssid
.security_policy
= SECURITY_PLAINTEXT
;
1222 bss
->wpa_group
= WPA_CIPHER_NONE
;
1223 bss
->wpa_pairwise
= WPA_CIPHER_NONE
;
1224 bss
->rsn_pairwise
= WPA_CIPHER_NONE
;
1225 bss
->wpa_key_mgmt
= WPA_KEY_MGMT_NONE
;
1231 int hostapd_sae_pw_id_in_use(struct hostapd_bss_config
*conf
)
1233 int with_id
= 0, without_id
= 0;
1234 struct sae_password_entry
*pw
;
1236 if (conf
->ssid
.wpa_passphrase
)
1239 for (pw
= conf
->sae_passwords
; pw
; pw
= pw
->next
) {
1244 if (with_id
&& without_id
)
1248 if (with_id
&& !without_id
)