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/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"
24 #include "airtime_policy.h"
25 #include "ap_config.h"
28 static void hostapd_config_free_vlan(struct hostapd_bss_config
*bss
)
30 struct hostapd_vlan
*vlan
, *prev
;
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 */
48 void hostapd_config_defaults_bss(struct hostapd_bss_config
*bss
)
50 dl_list_init(&bss
->anqp_elem
);
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;
58 bss
->auth_algs
= WPA_AUTH_ALG_OPEN
| WPA_AUTH_ALG_SHARED
;
60 bss
->wep_rekeying_period
= 300;
61 /* use key0 in individual key and key1 in broadcast key */
62 bss
->broadcast_key_idx_min
= 1;
63 bss
->broadcast_key_idx_max
= 2;
64 #else /* CONFIG_WEP */
65 bss
->auth_algs
= WPA_AUTH_ALG_OPEN
;
66 #endif /* CONFIG_WEP */
67 bss
->eap_reauth_period
= 3600;
69 bss
->wpa_group_rekey
= 600;
70 bss
->wpa_gmk_rekey
= 86400;
71 bss
->wpa_deny_ptk0_rekey
= PTK0_REKEY_ALLOW_ALWAYS
;
72 bss
->wpa_group_update_count
= 4;
73 bss
->wpa_pairwise_update_count
= 4;
74 bss
->wpa_disable_eapol_key_retries
=
75 DEFAULT_WPA_DISABLE_EAPOL_KEY_RETRIES
;
76 bss
->wpa_key_mgmt
= WPA_KEY_MGMT_PSK
;
77 bss
->wpa_pairwise
= WPA_CIPHER_TKIP
;
78 bss
->wpa_group
= WPA_CIPHER_TKIP
;
79 bss
->rsn_pairwise
= 0;
81 bss
->max_num_sta
= MAX_STA_COUNT
;
85 bss
->radius_server_auth_port
= 1812;
86 bss
->eap_sim_db_timeout
= 1;
88 bss
->ap_max_inactivity
= AP_MAX_INACTIVITY
;
89 bss
->eapol_version
= EAPOL_VERSION
;
91 bss
->max_listen_interval
= 65535;
93 bss
->pwd_group
= 19; /* ECC: GF(p=256) */
95 bss
->assoc_sa_query_max_timeout
= 1000;
96 bss
->assoc_sa_query_retry_timeout
= 201;
97 bss
->group_mgmt_cipher
= WPA_CIPHER_AES_128_CMAC
;
98 #ifdef EAP_SERVER_FAST
99 /* both anonymous and authenticated provisioning */
100 bss
->eap_fast_prov
= 3;
101 bss
->pac_key_lifetime
= 7 * 24 * 60 * 60;
102 bss
->pac_key_refresh_time
= 1 * 24 * 60 * 60;
103 #endif /* EAP_SERVER_FAST */
105 /* Set to -1 as defaults depends on HT in setup */
106 bss
->wmm_enabled
= -1;
108 #ifdef CONFIG_IEEE80211R_AP
110 bss
->rkh_pos_timeout
= 86400;
111 bss
->rkh_neg_timeout
= 60;
112 bss
->rkh_pull_timeout
= 1000;
113 bss
->rkh_pull_retries
= 4;
114 bss
->r0_key_lifetime
= 1209600;
115 #endif /* CONFIG_IEEE80211R_AP */
117 bss
->radius_das_time_window
= 300;
119 bss
->sae_anti_clogging_threshold
= 5;
122 bss
->gas_frag_limit
= 1400;
125 dl_list_init(&bss
->fils_realms
);
126 bss
->fils_hlp_wait_time
= 30;
127 bss
->dhcp_server_port
= DHCP_SERVER_PORT
;
128 bss
->dhcp_relay_port
= DHCP_SERVER_PORT
;
129 #endif /* CONFIG_FILS */
131 bss
->broadcast_deauth
= 1;
134 bss
->mbo_cell_data_conn_pref
= -1;
135 #endif /* CONFIG_MBO */
137 /* Disable TLS v1.3 by default for now to avoid interoperability issue.
138 * This can be enabled by default once the implementation has been fully
139 * completed and tested with other implementations. */
140 bss
->tls_flags
= TLS_CONN_DISABLE_TLSv1_3
;
142 bss
->max_auth_rounds
= 100;
143 bss
->max_auth_rounds_short
= 50;
145 bss
->send_probe_response
= 1;
148 bss
->hs20_release
= (HS20_VERSION
>> 4) + 1;
149 #endif /* CONFIG_HS20 */
152 bss
->mka_priority
= DEFAULT_PRIO_NOT_KEY_SERVER
;
153 bss
->macsec_port
= 1;
154 #endif /* CONFIG_MACSEC */
156 /* Default to strict CRL checking. */
157 bss
->check_crl_strict
= 1;
161 struct hostapd_config
* hostapd_config_defaults(void)
163 #define ecw2cw(ecw) ((1 << (ecw)) - 1)
165 struct hostapd_config
*conf
;
166 struct hostapd_bss_config
*bss
;
167 const int aCWmin
= 4, aCWmax
= 10;
168 const struct hostapd_wmm_ac_params ac_bk
=
169 { aCWmin
, aCWmax
, 7, 0, 0 }; /* background traffic */
170 const struct hostapd_wmm_ac_params ac_be
=
171 { aCWmin
, aCWmax
, 3, 0, 0 }; /* best effort traffic */
172 const struct hostapd_wmm_ac_params ac_vi
= /* video traffic */
173 { aCWmin
- 1, aCWmin
, 2, 3008 / 32, 0 };
174 const struct hostapd_wmm_ac_params ac_vo
= /* voice traffic */
175 { aCWmin
- 2, aCWmin
- 1, 2, 1504 / 32, 0 };
176 const struct hostapd_tx_queue_params txq_bk
=
177 { 7, ecw2cw(aCWmin
), ecw2cw(aCWmax
), 0 };
178 const struct hostapd_tx_queue_params txq_be
=
179 { 3, ecw2cw(aCWmin
), 4 * (ecw2cw(aCWmin
) + 1) - 1, 0};
180 const struct hostapd_tx_queue_params txq_vi
=
181 { 1, (ecw2cw(aCWmin
) + 1) / 2 - 1, ecw2cw(aCWmin
), 30};
182 const struct hostapd_tx_queue_params txq_vo
=
183 { 1, (ecw2cw(aCWmin
) + 1) / 4 - 1,
184 (ecw2cw(aCWmin
) + 1) / 2 - 1, 15};
188 conf
= os_zalloc(sizeof(*conf
));
189 bss
= os_zalloc(sizeof(*bss
));
190 if (conf
== NULL
|| bss
== NULL
) {
191 wpa_printf(MSG_ERROR
, "Failed to allocate memory for "
192 "configuration data.");
197 conf
->bss
= os_calloc(1, sizeof(struct hostapd_bss_config
*));
198 if (conf
->bss
== NULL
) {
205 bss
->radius
= os_zalloc(sizeof(*bss
->radius
));
206 if (bss
->radius
== NULL
) {
213 hostapd_config_defaults_bss(bss
);
217 conf
->beacon_int
= 100;
218 conf
->rts_threshold
= -2; /* use driver default: 2347 */
219 conf
->fragm_threshold
= -2; /* user driver default: 2346 */
220 /* Set to invalid value means do not add Power Constraint IE */
221 conf
->local_pwr_constraint
= -1;
223 conf
->wmm_ac_params
[0] = ac_be
;
224 conf
->wmm_ac_params
[1] = ac_bk
;
225 conf
->wmm_ac_params
[2] = ac_vi
;
226 conf
->wmm_ac_params
[3] = ac_vo
;
228 conf
->tx_queue
[0] = txq_vo
;
229 conf
->tx_queue
[1] = txq_vi
;
230 conf
->tx_queue
[2] = txq_be
;
231 conf
->tx_queue
[3] = txq_bk
;
233 conf
->ht_capab
= HT_CAP_INFO_SMPS_DISABLED
;
235 conf
->ap_table_max_size
= 255;
236 conf
->ap_table_expiration_time
= 60;
237 conf
->track_sta_max_age
= 180;
239 #ifdef CONFIG_TESTING_OPTIONS
240 conf
->ignore_probe_probability
= 0.0;
241 conf
->ignore_auth_probability
= 0.0;
242 conf
->ignore_assoc_probability
= 0.0;
243 conf
->ignore_reassoc_probability
= 0.0;
244 conf
->corrupt_gtk_rekey_mic_probability
= 0.0;
245 conf
->ecsa_ie_only
= 0;
246 #endif /* CONFIG_TESTING_OPTIONS */
249 conf
->acs_ch_list
.num
= 0;
251 conf
->acs_num_scans
= 5;
252 #endif /* CONFIG_ACS */
254 #ifdef CONFIG_IEEE80211AX
255 conf
->he_op
.he_rts_threshold
= HE_OPERATION_RTS_THRESHOLD_MASK
>>
256 HE_OPERATION_RTS_THRESHOLD_OFFSET
;
257 /* Set default basic MCS/NSS set to single stream MCS 0-7 */
258 conf
->he_op
.he_basic_mcs_nss_set
= 0xfffc;
259 conf
->he_op
.he_bss_color_disabled
= 1;
260 conf
->he_op
.he_bss_color_partial
= 0;
261 conf
->he_op
.he_bss_color
= 1;
262 #endif /* CONFIG_IEEE80211AX */
264 /* The third octet of the country string uses an ASCII space character
265 * by default to indicate that the regulations encompass all
266 * environments for the current frequency band in the country. */
267 conf
->country
[2] = ' ';
269 conf
->rssi_reject_assoc_rssi
= 0;
270 conf
->rssi_reject_assoc_timeout
= 30;
272 #ifdef CONFIG_AIRTIME_POLICY
273 conf
->airtime_update_interval
= AIRTIME_DEFAULT_UPDATE_INTERVAL
;
274 #endif /* CONFIG_AIRTIME_POLICY */
280 int hostapd_mac_comp(const void *a
, const void *b
)
282 return os_memcmp(a
, b
, sizeof(macaddr
));
286 static int hostapd_config_read_wpa_psk(const char *fname
,
287 struct hostapd_ssid
*ssid
)
297 int line
= 0, ret
= 0, len
, ok
;
299 struct hostapd_wpa_psk
*psk
;
304 f
= fopen(fname
, "r");
306 wpa_printf(MSG_ERROR
, "WPA PSK file '%s' not found.", fname
);
310 while (fgets(buf
, sizeof(buf
), f
)) {
319 while (*pos
!= '\0') {
331 while ((token
= str_token(buf
, " ", &context
))) {
332 if (!os_strchr(token
, '='))
335 name
= str_token(token
, "=", &context2
);
338 value
= str_token(token
, "", &context2
);
341 if (!os_strcmp(name
, "keyid")) {
343 } else if (!os_strcmp(name
, "wps")) {
345 } else if (!os_strcmp(name
, "vlanid")) {
346 vlan_id
= atoi(value
);
348 wpa_printf(MSG_ERROR
,
349 "Unrecognized '%s=%s' on line %d in '%s'",
350 name
, value
, line
, fname
);
361 if (hwaddr_aton(token
, addr
)) {
362 wpa_printf(MSG_ERROR
,
363 "Invalid MAC address '%s' on line %d in '%s'",
369 psk
= os_zalloc(sizeof(*psk
));
371 wpa_printf(MSG_ERROR
, "WPA PSK allocation failed");
375 psk
->vlan_id
= vlan_id
;
376 if (is_zero_ether_addr(addr
))
379 os_memcpy(psk
->addr
, addr
, ETH_ALEN
);
381 pos
= str_token(buf
, "", &context
);
383 wpa_printf(MSG_ERROR
, "No PSK on line %d in '%s'",
391 len
= os_strlen(pos
);
392 if (len
== 2 * PMK_LEN
&&
393 hexstr2bin(pos
, psk
->psk
, PMK_LEN
) == 0)
395 else if (len
>= 8 && len
< 64 &&
396 pbkdf2_sha1(pos
, ssid
->ssid
, ssid
->ssid_len
,
397 4096, psk
->psk
, PMK_LEN
) == 0)
400 wpa_printf(MSG_ERROR
,
401 "Invalid PSK '%s' on line %d in '%s'",
409 len
= os_strlcpy(psk
->keyid
, keyid
, sizeof(psk
->keyid
));
410 if ((size_t) len
>= sizeof(psk
->keyid
)) {
411 wpa_printf(MSG_ERROR
,
412 "PSK keyid too long on line %d in '%s'",
422 psk
->next
= ssid
->wpa_psk
;
432 static int hostapd_derive_psk(struct hostapd_ssid
*ssid
)
434 ssid
->wpa_psk
= os_zalloc(sizeof(struct hostapd_wpa_psk
));
435 if (ssid
->wpa_psk
== NULL
) {
436 wpa_printf(MSG_ERROR
, "Unable to alloc space for PSK");
439 wpa_hexdump_ascii(MSG_DEBUG
, "SSID",
440 (u8
*) ssid
->ssid
, ssid
->ssid_len
);
441 wpa_hexdump_ascii_key(MSG_DEBUG
, "PSK (ASCII passphrase)",
442 (u8
*) ssid
->wpa_passphrase
,
443 os_strlen(ssid
->wpa_passphrase
));
444 pbkdf2_sha1(ssid
->wpa_passphrase
,
445 ssid
->ssid
, ssid
->ssid_len
,
446 4096, ssid
->wpa_psk
->psk
, PMK_LEN
);
447 wpa_hexdump_key(MSG_DEBUG
, "PSK (from passphrase)",
448 ssid
->wpa_psk
->psk
, PMK_LEN
);
453 int hostapd_setup_sae_pt(struct hostapd_bss_config
*conf
)
456 struct hostapd_ssid
*ssid
= &conf
->ssid
;
457 struct sae_password_entry
*pw
;
459 if ((conf
->sae_pwe
== 0 && !hostapd_sae_pw_id_in_use(conf
)) ||
460 conf
->sae_pwe
== 3 ||
461 !wpa_key_mgmt_sae(conf
->wpa_key_mgmt
))
462 return 0; /* PT not needed */
464 sae_deinit_pt(ssid
->pt
);
466 if (ssid
->wpa_passphrase
) {
467 ssid
->pt
= sae_derive_pt(conf
->sae_groups
, ssid
->ssid
,
469 (const u8
*) ssid
->wpa_passphrase
,
470 os_strlen(ssid
->wpa_passphrase
),
476 for (pw
= conf
->sae_passwords
; pw
; pw
= pw
->next
) {
477 sae_deinit_pt(pw
->pt
);
478 pw
->pt
= sae_derive_pt(conf
->sae_groups
, ssid
->ssid
,
480 (const u8
*) pw
->password
,
481 os_strlen(pw
->password
),
486 #endif /* CONFIG_SAE */
492 int hostapd_setup_wpa_psk(struct hostapd_bss_config
*conf
)
494 struct hostapd_ssid
*ssid
= &conf
->ssid
;
496 if (hostapd_setup_sae_pt(conf
) < 0)
499 if (ssid
->wpa_passphrase
!= NULL
) {
500 if (ssid
->wpa_psk
!= NULL
) {
501 wpa_printf(MSG_DEBUG
, "Using pre-configured WPA PSK "
502 "instead of passphrase");
504 wpa_printf(MSG_DEBUG
, "Deriving WPA PSK based on "
506 if (hostapd_derive_psk(ssid
) < 0)
509 ssid
->wpa_psk
->group
= 1;
512 return hostapd_config_read_wpa_psk(ssid
->wpa_psk_file
, &conf
->ssid
);
516 static void hostapd_config_free_radius(struct hostapd_radius_server
*servers
,
521 for (i
= 0; i
< num_servers
; i
++) {
522 os_free(servers
[i
].shared_secret
);
528 struct hostapd_radius_attr
*
529 hostapd_config_get_radius_attr(struct hostapd_radius_attr
*attr
, u8 type
)
531 for (; attr
; attr
= attr
->next
) {
532 if (attr
->type
== type
)
539 struct hostapd_radius_attr
* hostapd_parse_radius_attr(const char *value
)
543 struct hostapd_radius_attr
*attr
;
546 attr
= os_zalloc(sizeof(*attr
));
550 attr
->type
= atoi(value
);
552 pos
= os_strchr(value
, ':');
554 attr
->val
= wpabuf_alloc(1);
559 wpabuf_put_u8(attr
->val
, 0);
564 if (pos
[0] == '\0' || pos
[1] != ':') {
573 attr
->val
= wpabuf_alloc_copy(pos
, os_strlen(pos
));
576 len
= os_strlen(pos
);
580 attr
->val
= wpabuf_alloc(len
);
583 if (hexstr2bin(pos
, wpabuf_put(attr
->val
, len
), len
) < 0) {
584 wpabuf_free(attr
->val
);
590 attr
->val
= wpabuf_alloc(4);
592 wpabuf_put_be32(attr
->val
, atoi(pos
));
608 void hostapd_config_free_radius_attr(struct hostapd_radius_attr
*attr
)
610 struct hostapd_radius_attr
*prev
;
615 wpabuf_free(prev
->val
);
621 void hostapd_config_free_eap_user(struct hostapd_eap_user
*user
)
623 hostapd_config_free_radius_attr(user
->accept_attr
);
624 os_free(user
->identity
);
625 bin_clear_free(user
->password
, user
->password_len
);
626 bin_clear_free(user
->salt
, user
->salt_len
);
631 void hostapd_config_free_eap_users(struct hostapd_eap_user
*user
)
633 struct hostapd_eap_user
*prev_user
;
638 hostapd_config_free_eap_user(prev_user
);
644 static void hostapd_config_free_wep(struct hostapd_wep_keys
*keys
)
647 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
648 bin_clear_free(keys
->key
[i
], keys
->len
[i
]);
652 #endif /* CONFIG_WEP */
655 void hostapd_config_clear_wpa_psk(struct hostapd_wpa_psk
**l
)
657 struct hostapd_wpa_psk
*psk
, *tmp
;
659 for (psk
= *l
; psk
;) {
662 bin_clear_free(tmp
, sizeof(*tmp
));
668 static void hostapd_config_free_anqp_elem(struct hostapd_bss_config
*conf
)
670 struct anqp_element
*elem
;
672 while ((elem
= dl_list_first(&conf
->anqp_elem
, struct anqp_element
,
674 dl_list_del(&elem
->list
);
675 wpabuf_free(elem
->payload
);
681 static void hostapd_config_free_fils_realms(struct hostapd_bss_config
*conf
)
684 struct fils_realm
*realm
;
686 while ((realm
= dl_list_first(&conf
->fils_realms
, struct fils_realm
,
688 dl_list_del(&realm
->list
);
691 #endif /* CONFIG_FILS */
695 static void hostapd_config_free_sae_passwords(struct hostapd_bss_config
*conf
)
697 struct sae_password_entry
*pw
, *tmp
;
699 pw
= conf
->sae_passwords
;
700 conf
->sae_passwords
= NULL
;
704 str_clear_free(tmp
->password
);
705 os_free(tmp
->identifier
);
707 sae_deinit_pt(tmp
->pt
);
708 #endif /* CONFIG_SAE */
715 static void hostapd_dpp_controller_conf_free(struct dpp_controller_conf
*conf
)
717 struct dpp_controller_conf
*prev
;
725 #endif /* CONFIG_DPP2 */
728 void hostapd_config_free_bss(struct hostapd_bss_config
*conf
)
730 #if defined(CONFIG_WPS) || defined(CONFIG_HS20)
737 hostapd_config_clear_wpa_psk(&conf
->ssid
.wpa_psk
);
739 str_clear_free(conf
->ssid
.wpa_passphrase
);
740 os_free(conf
->ssid
.wpa_psk_file
);
742 hostapd_config_free_wep(&conf
->ssid
.wep
);
743 #endif /* CONFIG_WEP */
744 #ifdef CONFIG_FULL_DYNAMIC_VLAN
745 os_free(conf
->ssid
.vlan_tagged_interface
);
746 #endif /* CONFIG_FULL_DYNAMIC_VLAN */
748 sae_deinit_pt(conf
->ssid
.pt
);
749 #endif /* CONFIG_SAE */
751 hostapd_config_free_eap_users(conf
->eap_user
);
752 os_free(conf
->eap_user_sqlite
);
754 os_free(conf
->eap_req_id_text
);
755 os_free(conf
->erp_domain
);
756 os_free(conf
->accept_mac
);
757 os_free(conf
->deny_mac
);
758 os_free(conf
->nas_identifier
);
760 hostapd_config_free_radius(conf
->radius
->auth_servers
,
761 conf
->radius
->num_auth_servers
);
762 hostapd_config_free_radius(conf
->radius
->acct_servers
,
763 conf
->radius
->num_acct_servers
);
765 hostapd_config_free_radius_attr(conf
->radius_auth_req_attr
);
766 hostapd_config_free_radius_attr(conf
->radius_acct_req_attr
);
767 os_free(conf
->radius_req_attr_sqlite
);
768 os_free(conf
->rsn_preauth_interfaces
);
769 os_free(conf
->ctrl_interface
);
770 os_free(conf
->ca_cert
);
771 os_free(conf
->server_cert
);
772 os_free(conf
->server_cert2
);
773 os_free(conf
->private_key
);
774 os_free(conf
->private_key2
);
775 os_free(conf
->private_key_passwd
);
776 os_free(conf
->private_key_passwd2
);
777 os_free(conf
->check_cert_subject
);
778 os_free(conf
->ocsp_stapling_response
);
779 os_free(conf
->ocsp_stapling_response_multi
);
780 os_free(conf
->dh_file
);
781 os_free(conf
->openssl_ciphers
);
782 os_free(conf
->openssl_ecdh_curves
);
783 os_free(conf
->pac_opaque_encr_key
);
784 os_free(conf
->eap_fast_a_id
);
785 os_free(conf
->eap_fast_a_id_info
);
786 os_free(conf
->eap_sim_db
);
787 os_free(conf
->radius_server_clients
);
788 os_free(conf
->radius
);
789 os_free(conf
->radius_das_shared_secret
);
790 hostapd_config_free_vlan(conf
);
791 os_free(conf
->time_zone
);
793 #ifdef CONFIG_IEEE80211R_AP
795 struct ft_remote_r0kh
*r0kh
, *r0kh_prev
;
796 struct ft_remote_r1kh
*r1kh
, *r1kh_prev
;
798 r0kh
= conf
->r0kh_list
;
799 conf
->r0kh_list
= NULL
;
806 r1kh
= conf
->r1kh_list
;
807 conf
->r1kh_list
= NULL
;
814 #endif /* CONFIG_IEEE80211R_AP */
817 os_free(conf
->wps_pin_requests
);
818 os_free(conf
->device_name
);
819 os_free(conf
->manufacturer
);
820 os_free(conf
->model_name
);
821 os_free(conf
->model_number
);
822 os_free(conf
->serial_number
);
823 os_free(conf
->config_methods
);
824 os_free(conf
->ap_pin
);
825 os_free(conf
->extra_cred
);
826 os_free(conf
->ap_settings
);
827 hostapd_config_clear_wpa_psk(&conf
->multi_ap_backhaul_ssid
.wpa_psk
);
828 str_clear_free(conf
->multi_ap_backhaul_ssid
.wpa_passphrase
);
829 os_free(conf
->upnp_iface
);
830 os_free(conf
->friendly_name
);
831 os_free(conf
->manufacturer_url
);
832 os_free(conf
->model_description
);
833 os_free(conf
->model_url
);
835 for (i
= 0; i
< MAX_WPS_VENDOR_EXTENSIONS
; i
++)
836 wpabuf_free(conf
->wps_vendor_ext
[i
]);
837 wpabuf_free(conf
->wps_application_ext
);
838 wpabuf_free(conf
->wps_nfc_dh_pubkey
);
839 wpabuf_free(conf
->wps_nfc_dh_privkey
);
840 wpabuf_free(conf
->wps_nfc_dev_pw
);
841 #endif /* CONFIG_WPS */
843 os_free(conf
->roaming_consortium
);
844 os_free(conf
->venue_name
);
845 os_free(conf
->venue_url
);
846 os_free(conf
->nai_realm_data
);
847 os_free(conf
->network_auth_type
);
848 os_free(conf
->anqp_3gpp_cell_net
);
849 os_free(conf
->domain_name
);
850 hostapd_config_free_anqp_elem(conf
);
852 #ifdef CONFIG_RADIUS_TEST
853 os_free(conf
->dump_msk_file
);
854 #endif /* CONFIG_RADIUS_TEST */
857 os_free(conf
->hs20_oper_friendly_name
);
858 os_free(conf
->hs20_wan_metrics
);
859 os_free(conf
->hs20_connection_capability
);
860 os_free(conf
->hs20_operating_class
);
861 os_free(conf
->hs20_icons
);
862 if (conf
->hs20_osu_providers
) {
863 for (i
= 0; i
< conf
->hs20_osu_providers_count
; i
++) {
864 struct hs20_osu_provider
*p
;
866 p
= &conf
->hs20_osu_providers
[i
];
867 os_free(p
->friendly_name
);
868 os_free(p
->server_uri
);
869 os_free(p
->method_list
);
870 for (j
= 0; j
< p
->icons_count
; j
++)
871 os_free(p
->icons
[j
]);
874 os_free(p
->osu_nai2
);
875 os_free(p
->service_desc
);
877 os_free(conf
->hs20_osu_providers
);
879 if (conf
->hs20_operator_icon
) {
880 for (i
= 0; i
< conf
->hs20_operator_icon_count
; i
++)
881 os_free(conf
->hs20_operator_icon
[i
]);
882 os_free(conf
->hs20_operator_icon
);
884 os_free(conf
->subscr_remediation_url
);
885 os_free(conf
->hs20_sim_provisioning_url
);
886 os_free(conf
->t_c_filename
);
887 os_free(conf
->t_c_server_url
);
888 #endif /* CONFIG_HS20 */
890 wpabuf_free(conf
->vendor_elements
);
891 wpabuf_free(conf
->assocresp_elements
);
893 os_free(conf
->sae_groups
);
895 os_free(conf
->owe_groups
);
896 #endif /* CONFIG_OWE */
898 os_free(conf
->wowlan_triggers
);
900 os_free(conf
->server_id
);
902 #ifdef CONFIG_TESTING_OPTIONS
903 wpabuf_free(conf
->own_ie_override
);
904 wpabuf_free(conf
->sae_commit_override
);
905 wpabuf_free(conf
->rsne_override_eapol
);
906 wpabuf_free(conf
->rsnxe_override_eapol
);
907 wpabuf_free(conf
->rsne_override_ft
);
908 wpabuf_free(conf
->rsnxe_override_ft
);
909 wpabuf_free(conf
->gtk_rsc_override
);
910 wpabuf_free(conf
->igtk_rsc_override
);
911 #endif /* CONFIG_TESTING_OPTIONS */
913 os_free(conf
->no_probe_resp_if_seen_on
);
914 os_free(conf
->no_auth_if_seen_on
);
916 hostapd_config_free_fils_realms(conf
);
919 os_free(conf
->dpp_name
);
920 os_free(conf
->dpp_mud_url
);
921 os_free(conf
->dpp_connector
);
922 wpabuf_free(conf
->dpp_netaccesskey
);
923 wpabuf_free(conf
->dpp_csign
);
925 hostapd_dpp_controller_conf_free(conf
->dpp_controller
);
926 #endif /* CONFIG_DPP2 */
927 #endif /* CONFIG_DPP */
929 hostapd_config_free_sae_passwords(conf
);
931 #ifdef CONFIG_AIRTIME_POLICY
933 struct airtime_sta_weight
*wt
, *wt_prev
;
935 wt
= conf
->airtime_weight_list
;
936 conf
->airtime_weight_list
= NULL
;
943 #endif /* CONFIG_AIRTIME_POLICY */
950 * hostapd_config_free - Free hostapd configuration
951 * @conf: Configuration data from hostapd_config_read().
953 void hostapd_config_free(struct hostapd_config
*conf
)
960 for (i
= 0; i
< conf
->num_bss
; i
++)
961 hostapd_config_free_bss(conf
->bss
[i
]);
963 os_free(conf
->supported_rates
);
964 os_free(conf
->basic_rates
);
965 os_free(conf
->acs_ch_list
.range
);
966 os_free(conf
->acs_freq_list
.range
);
967 os_free(conf
->driver_params
);
969 os_free(conf
->acs_chan_bias
);
970 #endif /* CONFIG_ACS */
971 wpabuf_free(conf
->lci
);
972 wpabuf_free(conf
->civic
);
979 * hostapd_maclist_found - Find a MAC address from a list
980 * @list: MAC address list
981 * @num_entries: Number of addresses in the list
982 * @addr: Address to search for
983 * @vlan_id: Buffer for returning VLAN ID or %NULL if not needed
984 * Returns: 1 if address is in the list or 0 if not.
986 * Perform a binary search for given MAC address from a pre-sorted list.
988 int hostapd_maclist_found(struct mac_acl_entry
*list
, int num_entries
,
989 const u8
*addr
, struct vlan_description
*vlan_id
)
991 int start
, end
, middle
, res
;
994 end
= num_entries
- 1;
996 while (start
<= end
) {
997 middle
= (start
+ end
) / 2;
998 res
= os_memcmp(list
[middle
].addr
, addr
, ETH_ALEN
);
1001 *vlan_id
= list
[middle
].vlan_id
;
1014 int hostapd_rate_found(int *list
, int rate
)
1021 for (i
= 0; list
[i
] >= 0; i
++)
1022 if (list
[i
] == rate
)
1029 int hostapd_vlan_valid(struct hostapd_vlan
*vlan
,
1030 struct vlan_description
*vlan_desc
)
1032 struct hostapd_vlan
*v
= vlan
;
1035 if (!vlan_desc
->notempty
|| vlan_desc
->untagged
< 0 ||
1036 vlan_desc
->untagged
> MAX_VLAN_ID
)
1038 for (i
= 0; i
< MAX_NUM_TAGGED_VLAN
; i
++) {
1039 if (vlan_desc
->tagged
[i
] < 0 ||
1040 vlan_desc
->tagged
[i
] > MAX_VLAN_ID
)
1043 if (!vlan_desc
->untagged
&& !vlan_desc
->tagged
[0])
1047 if (!vlan_compare(&v
->vlan_desc
, vlan_desc
) ||
1048 v
->vlan_id
== VLAN_ID_WILDCARD
)
1056 const char * hostapd_get_vlan_id_ifname(struct hostapd_vlan
*vlan
, int vlan_id
)
1058 struct hostapd_vlan
*v
= vlan
;
1060 if (v
->vlan_id
== vlan_id
)
1068 const u8
* hostapd_get_psk(const struct hostapd_bss_config
*conf
,
1069 const u8
*addr
, const u8
*p2p_dev_addr
,
1070 const u8
*prev_psk
, int *vlan_id
)
1072 struct hostapd_wpa_psk
*psk
;
1073 int next_ok
= prev_psk
== NULL
;
1078 if (p2p_dev_addr
&& !is_zero_ether_addr(p2p_dev_addr
)) {
1079 wpa_printf(MSG_DEBUG
, "Searching a PSK for " MACSTR
1080 " p2p_dev_addr=" MACSTR
" prev_psk=%p",
1081 MAC2STR(addr
), MAC2STR(p2p_dev_addr
), prev_psk
);
1082 addr
= NULL
; /* Use P2P Device Address for matching */
1084 wpa_printf(MSG_DEBUG
, "Searching a PSK for " MACSTR
1086 MAC2STR(addr
), prev_psk
);
1089 for (psk
= conf
->ssid
.wpa_psk
; psk
!= NULL
; psk
= psk
->next
) {
1092 (addr
&& os_memcmp(psk
->addr
, addr
, ETH_ALEN
) == 0) ||
1093 (!addr
&& p2p_dev_addr
&&
1094 os_memcmp(psk
->p2p_dev_addr
, p2p_dev_addr
, ETH_ALEN
) ==
1097 *vlan_id
= psk
->vlan_id
;
1101 if (psk
->psk
== prev_psk
)
1109 static int hostapd_config_check_bss(struct hostapd_bss_config
*bss
,
1110 struct hostapd_config
*conf
,
1113 if (full_config
&& bss
->ieee802_1x
&& !bss
->eap_server
&&
1114 !bss
->radius
->auth_servers
) {
1115 wpa_printf(MSG_ERROR
, "Invalid IEEE 802.1X configuration (no "
1116 "EAP authenticator configured).");
1124 wep
= bss
->default_wep_key_len
> 0 ||
1125 bss
->individual_wep_key_len
> 0;
1126 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
1127 if (bss
->ssid
.wep
.keys_set
) {
1134 wpa_printf(MSG_ERROR
, "WEP configuration in a WPA network is not supported");
1138 #endif /* CONFIG_WEP */
1140 if (full_config
&& bss
->wpa
&&
1141 bss
->wpa_psk_radius
!= PSK_RADIUS_IGNORED
&&
1142 bss
->macaddr_acl
!= USE_EXTERNAL_RADIUS_AUTH
) {
1143 wpa_printf(MSG_ERROR
, "WPA-PSK using RADIUS enabled, but no "
1144 "RADIUS checking (macaddr_acl=2) enabled.");
1148 if (full_config
&& bss
->wpa
&& (bss
->wpa_key_mgmt
& WPA_KEY_MGMT_PSK
) &&
1149 bss
->ssid
.wpa_psk
== NULL
&& bss
->ssid
.wpa_passphrase
== NULL
&&
1150 bss
->ssid
.wpa_psk_file
== NULL
&&
1151 (bss
->wpa_psk_radius
!= PSK_RADIUS_REQUIRED
||
1152 bss
->macaddr_acl
!= USE_EXTERNAL_RADIUS_AUTH
)) {
1153 wpa_printf(MSG_ERROR
, "WPA-PSK enabled, but PSK or passphrase "
1154 "is not configured.");
1158 if (full_config
&& !is_zero_ether_addr(bss
->bssid
)) {
1161 for (i
= 0; i
< conf
->num_bss
; i
++) {
1162 if (conf
->bss
[i
] != bss
&&
1163 (hostapd_mac_comp(conf
->bss
[i
]->bssid
,
1164 bss
->bssid
) == 0)) {
1165 wpa_printf(MSG_ERROR
, "Duplicate BSSID " MACSTR
1166 " on interface '%s' and '%s'.",
1167 MAC2STR(bss
->bssid
),
1168 conf
->bss
[i
]->iface
, bss
->iface
);
1174 #ifdef CONFIG_IEEE80211R_AP
1175 if (full_config
&& wpa_key_mgmt_ft(bss
->wpa_key_mgmt
) &&
1176 (bss
->nas_identifier
== NULL
||
1177 os_strlen(bss
->nas_identifier
) < 1 ||
1178 os_strlen(bss
->nas_identifier
) > FT_R0KH_ID_MAX_LEN
)) {
1179 wpa_printf(MSG_ERROR
, "FT (IEEE 802.11r) requires "
1180 "nas_identifier to be configured as a 1..48 octet "
1184 #endif /* CONFIG_IEEE80211R_AP */
1186 if (full_config
&& conf
->ieee80211n
&&
1187 conf
->hw_mode
== HOSTAPD_MODE_IEEE80211B
) {
1188 bss
->disable_11n
= 1;
1189 wpa_printf(MSG_ERROR
, "HT (IEEE 802.11n) in 11b mode is not "
1190 "allowed, disabling HT capabilities");
1194 if (full_config
&& conf
->ieee80211n
&&
1195 bss
->ssid
.security_policy
== SECURITY_STATIC_WEP
) {
1196 bss
->disable_11n
= 1;
1197 wpa_printf(MSG_ERROR
, "HT (IEEE 802.11n) with WEP is not "
1198 "allowed, disabling HT capabilities");
1200 #endif /* CONFIG_WEP */
1202 if (full_config
&& conf
->ieee80211n
&& bss
->wpa
&&
1203 !(bss
->wpa_pairwise
& WPA_CIPHER_CCMP
) &&
1204 !(bss
->rsn_pairwise
& (WPA_CIPHER_CCMP
| WPA_CIPHER_GCMP
|
1205 WPA_CIPHER_CCMP_256
| WPA_CIPHER_GCMP_256
)))
1207 bss
->disable_11n
= 1;
1208 wpa_printf(MSG_ERROR
, "HT (IEEE 802.11n) with WPA/WPA2 "
1209 "requires CCMP/GCMP to be enabled, disabling HT "
1213 #ifdef CONFIG_IEEE80211AC
1215 if (full_config
&& conf
->ieee80211ac
&&
1216 bss
->ssid
.security_policy
== SECURITY_STATIC_WEP
) {
1217 bss
->disable_11ac
= 1;
1218 wpa_printf(MSG_ERROR
,
1219 "VHT (IEEE 802.11ac) with WEP is not allowed, disabling VHT capabilities");
1221 #endif /* CONFIG_WEP */
1223 if (full_config
&& conf
->ieee80211ac
&& bss
->wpa
&&
1224 !(bss
->wpa_pairwise
& WPA_CIPHER_CCMP
) &&
1225 !(bss
->rsn_pairwise
& (WPA_CIPHER_CCMP
| WPA_CIPHER_GCMP
|
1226 WPA_CIPHER_CCMP_256
| WPA_CIPHER_GCMP_256
)))
1228 bss
->disable_11ac
= 1;
1229 wpa_printf(MSG_ERROR
,
1230 "VHT (IEEE 802.11ac) with WPA/WPA2 requires CCMP/GCMP to be enabled, disabling VHT capabilities");
1232 #endif /* CONFIG_IEEE80211AC */
1235 if (full_config
&& bss
->wps_state
&& bss
->ignore_broadcast_ssid
) {
1236 wpa_printf(MSG_INFO
, "WPS: ignore_broadcast_ssid "
1237 "configuration forced WPS to be disabled");
1242 if (full_config
&& bss
->wps_state
&&
1243 bss
->ssid
.wep
.keys_set
&& bss
->wpa
== 0) {
1244 wpa_printf(MSG_INFO
, "WPS: WEP configuration forced WPS to be "
1248 #endif /* CONFIG_WEP */
1250 if (full_config
&& bss
->wps_state
&& bss
->wpa
&&
1252 !(bss
->rsn_pairwise
& (WPA_CIPHER_CCMP
| WPA_CIPHER_GCMP
|
1253 WPA_CIPHER_CCMP_256
|
1254 WPA_CIPHER_GCMP_256
)))) {
1255 wpa_printf(MSG_INFO
, "WPS: WPA/TKIP configuration without "
1256 "WPA2/CCMP/GCMP forced WPS to be disabled");
1259 #endif /* CONFIG_WPS */
1262 if (full_config
&& bss
->hs20
&&
1264 !(bss
->rsn_pairwise
& (WPA_CIPHER_CCMP
| WPA_CIPHER_GCMP
|
1265 WPA_CIPHER_CCMP_256
|
1266 WPA_CIPHER_GCMP_256
)))) {
1267 wpa_printf(MSG_ERROR
, "HS 2.0: WPA2-Enterprise/CCMP "
1268 "configuration is required for Hotspot 2.0 "
1272 #endif /* CONFIG_HS20 */
1275 if (full_config
&& bss
->mbo_enabled
&& (bss
->wpa
& 2) &&
1276 bss
->ieee80211w
== NO_MGMT_FRAME_PROTECTION
) {
1277 wpa_printf(MSG_ERROR
,
1278 "MBO: PMF needs to be enabled whenever using WPA2 with MBO");
1281 #endif /* CONFIG_MBO */
1284 if (full_config
&& bss
->ieee80211w
== NO_MGMT_FRAME_PROTECTION
&&
1286 wpa_printf(MSG_ERROR
,
1287 "OCV: PMF needs to be enabled whenever using OCV");
1290 #endif /* CONFIG_OCV */
1296 static int hostapd_config_check_cw(struct hostapd_config
*conf
, int queue
)
1298 int tx_cwmin
= conf
->tx_queue
[queue
].cwmin
;
1299 int tx_cwmax
= conf
->tx_queue
[queue
].cwmax
;
1300 int ac_cwmin
= conf
->wmm_ac_params
[queue
].cwmin
;
1301 int ac_cwmax
= conf
->wmm_ac_params
[queue
].cwmax
;
1303 if (tx_cwmin
> tx_cwmax
) {
1304 wpa_printf(MSG_ERROR
,
1305 "Invalid TX queue cwMin/cwMax values. cwMin(%d) greater than cwMax(%d)",
1306 tx_cwmin
, tx_cwmax
);
1309 if (ac_cwmin
> ac_cwmax
) {
1310 wpa_printf(MSG_ERROR
,
1311 "Invalid WMM AC cwMin/cwMax values. cwMin(%d) greater than cwMax(%d)",
1312 ac_cwmin
, ac_cwmax
);
1319 int hostapd_config_check(struct hostapd_config
*conf
, int full_config
)
1323 if (full_config
&& conf
->ieee80211d
&&
1324 (!conf
->country
[0] || !conf
->country
[1])) {
1325 wpa_printf(MSG_ERROR
, "Cannot enable IEEE 802.11d without "
1326 "setting the country_code");
1330 if (full_config
&& conf
->ieee80211h
&& !conf
->ieee80211d
) {
1331 wpa_printf(MSG_ERROR
, "Cannot enable IEEE 802.11h without "
1332 "IEEE 802.11d enabled");
1336 if (full_config
&& conf
->local_pwr_constraint
!= -1 &&
1337 !conf
->ieee80211d
) {
1338 wpa_printf(MSG_ERROR
, "Cannot add Power Constraint element without Country element");
1342 if (full_config
&& conf
->spectrum_mgmt_required
&&
1343 conf
->local_pwr_constraint
== -1) {
1344 wpa_printf(MSG_ERROR
, "Cannot set Spectrum Management bit without Country and Power Constraint elements");
1348 #ifdef CONFIG_AIRTIME_POLICY
1349 if (full_config
&& conf
->airtime_mode
> AIRTIME_MODE_STATIC
&&
1350 !conf
->airtime_update_interval
) {
1351 wpa_printf(MSG_ERROR
, "Airtime update interval cannot be zero");
1354 #endif /* CONFIG_AIRTIME_POLICY */
1355 for (i
= 0; i
< NUM_TX_QUEUES
; i
++) {
1356 if (hostapd_config_check_cw(conf
, i
))
1360 for (i
= 0; i
< conf
->num_bss
; i
++) {
1361 if (hostapd_config_check_bss(conf
->bss
[i
], conf
, full_config
))
1369 void hostapd_set_security_params(struct hostapd_bss_config
*bss
,
1373 if (bss
->individual_wep_key_len
== 0) {
1374 /* individual keys are not use; can use key idx0 for
1376 bss
->broadcast_key_idx_min
= 0;
1378 #endif /* CONFIG_WEP */
1380 if ((bss
->wpa
& 2) && bss
->rsn_pairwise
== 0)
1381 bss
->rsn_pairwise
= bss
->wpa_pairwise
;
1382 if (bss
->group_cipher
)
1383 bss
->wpa_group
= bss
->group_cipher
;
1385 bss
->wpa_group
= wpa_select_ap_group_cipher(bss
->wpa
,
1388 if (!bss
->wpa_group_rekey_set
)
1389 bss
->wpa_group_rekey
= bss
->wpa_group
== WPA_CIPHER_TKIP
?
1393 bss
->radius
->auth_server
= bss
->radius
->auth_servers
;
1394 bss
->radius
->acct_server
= bss
->radius
->acct_servers
;
1397 if (bss
->wpa
&& bss
->ieee802_1x
) {
1398 bss
->ssid
.security_policy
= SECURITY_WPA
;
1399 } else if (bss
->wpa
) {
1400 bss
->ssid
.security_policy
= SECURITY_WPA_PSK
;
1401 } else if (bss
->ieee802_1x
) {
1402 int cipher
= WPA_CIPHER_NONE
;
1403 bss
->ssid
.security_policy
= SECURITY_IEEE_802_1X
;
1405 bss
->ssid
.wep
.default_len
= bss
->default_wep_key_len
;
1406 if (full_config
&& bss
->default_wep_key_len
) {
1407 cipher
= bss
->default_wep_key_len
>= 13 ?
1408 WPA_CIPHER_WEP104
: WPA_CIPHER_WEP40
;
1409 } else if (full_config
&& bss
->ssid
.wep
.keys_set
) {
1410 if (bss
->ssid
.wep
.len
[0] >= 13)
1411 cipher
= WPA_CIPHER_WEP104
;
1413 cipher
= WPA_CIPHER_WEP40
;
1415 #endif /* CONFIG_WEP */
1416 bss
->wpa_group
= cipher
;
1417 bss
->wpa_pairwise
= cipher
;
1418 bss
->rsn_pairwise
= cipher
;
1420 bss
->wpa_key_mgmt
= WPA_KEY_MGMT_IEEE8021X_NO_WPA
;
1422 } else if (bss
->ssid
.wep
.keys_set
) {
1423 int cipher
= WPA_CIPHER_WEP40
;
1424 if (bss
->ssid
.wep
.len
[0] >= 13)
1425 cipher
= WPA_CIPHER_WEP104
;
1426 bss
->ssid
.security_policy
= SECURITY_STATIC_WEP
;
1427 bss
->wpa_group
= cipher
;
1428 bss
->wpa_pairwise
= cipher
;
1429 bss
->rsn_pairwise
= cipher
;
1431 bss
->wpa_key_mgmt
= WPA_KEY_MGMT_NONE
;
1432 #endif /* CONFIG_WEP */
1433 } else if (bss
->osen
) {
1434 bss
->ssid
.security_policy
= SECURITY_OSEN
;
1435 bss
->wpa_group
= WPA_CIPHER_CCMP
;
1436 bss
->wpa_pairwise
= 0;
1437 bss
->rsn_pairwise
= WPA_CIPHER_CCMP
;
1439 bss
->ssid
.security_policy
= SECURITY_PLAINTEXT
;
1441 bss
->wpa_group
= WPA_CIPHER_NONE
;
1442 bss
->wpa_pairwise
= WPA_CIPHER_NONE
;
1443 bss
->rsn_pairwise
= WPA_CIPHER_NONE
;
1444 bss
->wpa_key_mgmt
= WPA_KEY_MGMT_NONE
;
1450 int hostapd_sae_pw_id_in_use(struct hostapd_bss_config
*conf
)
1452 int with_id
= 0, without_id
= 0;
1453 struct sae_password_entry
*pw
;
1455 if (conf
->ssid
.wpa_passphrase
)
1458 for (pw
= conf
->sae_passwords
; pw
; pw
= pw
->next
) {
1463 if (with_id
&& without_id
)
1467 if (with_id
&& !without_id
)