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;
57 bss
->auth_algs
= WPA_AUTH_ALG_OPEN
| WPA_AUTH_ALG_SHARED
;
59 bss
->wep_rekeying_period
= 300;
60 /* use key0 in individual key and key1 in broadcast key */
61 bss
->broadcast_key_idx_min
= 1;
62 bss
->broadcast_key_idx_max
= 2;
63 bss
->eap_reauth_period
= 3600;
65 bss
->wpa_group_rekey
= 600;
66 bss
->wpa_gmk_rekey
= 86400;
67 bss
->wpa_group_update_count
= 4;
68 bss
->wpa_pairwise_update_count
= 4;
69 bss
->wpa_disable_eapol_key_retries
=
70 DEFAULT_WPA_DISABLE_EAPOL_KEY_RETRIES
;
71 bss
->wpa_key_mgmt
= WPA_KEY_MGMT_PSK
;
72 bss
->wpa_pairwise
= WPA_CIPHER_TKIP
;
73 bss
->wpa_group
= WPA_CIPHER_TKIP
;
74 bss
->rsn_pairwise
= 0;
76 bss
->max_num_sta
= MAX_STA_COUNT
;
80 bss
->radius_server_auth_port
= 1812;
81 bss
->eap_sim_db_timeout
= 1;
83 bss
->ap_max_inactivity
= AP_MAX_INACTIVITY
;
84 bss
->eapol_version
= EAPOL_VERSION
;
86 bss
->max_listen_interval
= 65535;
88 bss
->pwd_group
= 19; /* ECC: GF(p=256) */
90 bss
->assoc_sa_query_max_timeout
= 1000;
91 bss
->assoc_sa_query_retry_timeout
= 201;
92 bss
->group_mgmt_cipher
= WPA_CIPHER_AES_128_CMAC
;
93 #ifdef EAP_SERVER_FAST
94 /* both anonymous and authenticated provisioning */
95 bss
->eap_fast_prov
= 3;
96 bss
->pac_key_lifetime
= 7 * 24 * 60 * 60;
97 bss
->pac_key_refresh_time
= 1 * 24 * 60 * 60;
98 #endif /* EAP_SERVER_FAST */
100 /* Set to -1 as defaults depends on HT in setup */
101 bss
->wmm_enabled
= -1;
103 #ifdef CONFIG_IEEE80211R_AP
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 */
112 bss
->radius_das_time_window
= 300;
114 bss
->sae_anti_clogging_threshold
= 5;
117 bss
->gas_frag_limit
= 1400;
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 */
126 bss
->broadcast_deauth
= 1;
129 bss
->mbo_cell_data_conn_pref
= -1;
130 #endif /* CONFIG_MBO */
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
;
137 bss
->max_auth_rounds
= 100;
138 bss
->max_auth_rounds_short
= 50;
140 bss
->send_probe_response
= 1;
143 bss
->hs20_release
= (HS20_VERSION
>> 4) + 1;
144 #endif /* CONFIG_HS20 */
147 bss
->mka_priority
= DEFAULT_PRIO_NOT_KEY_SERVER
;
148 bss
->macsec_port
= 1;
149 #endif /* CONFIG_MACSEC */
151 /* Default to strict CRL checking. */
152 bss
->check_crl_strict
= 1;
156 struct hostapd_config
* hostapd_config_defaults(void)
158 #define ecw2cw(ecw) ((1 << (ecw)) - 1)
160 struct hostapd_config
*conf
;
161 struct hostapd_bss_config
*bss
;
162 const int aCWmin
= 4, aCWmax
= 10;
163 const struct hostapd_wmm_ac_params ac_bk
=
164 { aCWmin
, aCWmax
, 7, 0, 0 }; /* background traffic */
165 const struct hostapd_wmm_ac_params ac_be
=
166 { aCWmin
, aCWmax
, 3, 0, 0 }; /* best effort traffic */
167 const struct hostapd_wmm_ac_params ac_vi
= /* video traffic */
168 { aCWmin
- 1, aCWmin
, 2, 3008 / 32, 0 };
169 const struct hostapd_wmm_ac_params ac_vo
= /* voice traffic */
170 { aCWmin
- 2, aCWmin
- 1, 2, 1504 / 32, 0 };
171 const struct hostapd_tx_queue_params txq_bk
=
172 { 7, ecw2cw(aCWmin
), ecw2cw(aCWmax
), 0 };
173 const struct hostapd_tx_queue_params txq_be
=
174 { 3, ecw2cw(aCWmin
), 4 * (ecw2cw(aCWmin
) + 1) - 1, 0};
175 const struct hostapd_tx_queue_params txq_vi
=
176 { 1, (ecw2cw(aCWmin
) + 1) / 2 - 1, ecw2cw(aCWmin
), 30};
177 const struct hostapd_tx_queue_params txq_vo
=
178 { 1, (ecw2cw(aCWmin
) + 1) / 4 - 1,
179 (ecw2cw(aCWmin
) + 1) / 2 - 1, 15};
183 conf
= os_zalloc(sizeof(*conf
));
184 bss
= os_zalloc(sizeof(*bss
));
185 if (conf
== NULL
|| bss
== NULL
) {
186 wpa_printf(MSG_ERROR
, "Failed to allocate memory for "
187 "configuration data.");
192 conf
->bss
= os_calloc(1, sizeof(struct hostapd_bss_config
*));
193 if (conf
->bss
== NULL
) {
200 bss
->radius
= os_zalloc(sizeof(*bss
->radius
));
201 if (bss
->radius
== NULL
) {
208 hostapd_config_defaults_bss(bss
);
212 conf
->beacon_int
= 100;
213 conf
->rts_threshold
= -2; /* use driver default: 2347 */
214 conf
->fragm_threshold
= -2; /* user driver default: 2346 */
215 /* Set to invalid value means do not add Power Constraint IE */
216 conf
->local_pwr_constraint
= -1;
218 conf
->wmm_ac_params
[0] = ac_be
;
219 conf
->wmm_ac_params
[1] = ac_bk
;
220 conf
->wmm_ac_params
[2] = ac_vi
;
221 conf
->wmm_ac_params
[3] = ac_vo
;
223 conf
->tx_queue
[0] = txq_vo
;
224 conf
->tx_queue
[1] = txq_vi
;
225 conf
->tx_queue
[2] = txq_be
;
226 conf
->tx_queue
[3] = txq_bk
;
228 conf
->ht_capab
= HT_CAP_INFO_SMPS_DISABLED
;
230 conf
->ap_table_max_size
= 255;
231 conf
->ap_table_expiration_time
= 60;
232 conf
->track_sta_max_age
= 180;
234 #ifdef CONFIG_TESTING_OPTIONS
235 conf
->ignore_probe_probability
= 0.0;
236 conf
->ignore_auth_probability
= 0.0;
237 conf
->ignore_assoc_probability
= 0.0;
238 conf
->ignore_reassoc_probability
= 0.0;
239 conf
->corrupt_gtk_rekey_mic_probability
= 0.0;
240 conf
->ecsa_ie_only
= 0;
241 #endif /* CONFIG_TESTING_OPTIONS */
244 conf
->acs_ch_list
.num
= 0;
246 conf
->acs_num_scans
= 5;
247 #endif /* CONFIG_ACS */
249 #ifdef CONFIG_IEEE80211AX
250 conf
->he_op
.he_rts_threshold
= HE_OPERATION_RTS_THRESHOLD_MASK
>>
251 HE_OPERATION_RTS_THRESHOLD_OFFSET
;
252 /* Set default basic MCS/NSS set to single stream MCS 0-7 */
253 conf
->he_op
.he_basic_mcs_nss_set
= 0xfffc;
254 #endif /* CONFIG_IEEE80211AX */
256 /* The third octet of the country string uses an ASCII space character
257 * by default to indicate that the regulations encompass all
258 * environments for the current frequency band in the country. */
259 conf
->country
[2] = ' ';
261 conf
->rssi_reject_assoc_rssi
= 0;
262 conf
->rssi_reject_assoc_timeout
= 30;
264 #ifdef CONFIG_AIRTIME_POLICY
265 conf
->airtime_update_interval
= AIRTIME_DEFAULT_UPDATE_INTERVAL
;
266 #endif /* CONFIG_AIRTIME_POLICY */
272 int hostapd_mac_comp(const void *a
, const void *b
)
274 return os_memcmp(a
, b
, sizeof(macaddr
));
278 static int hostapd_config_read_wpa_psk(const char *fname
,
279 struct hostapd_ssid
*ssid
)
289 int line
= 0, ret
= 0, len
, ok
;
291 struct hostapd_wpa_psk
*psk
;
296 f
= fopen(fname
, "r");
298 wpa_printf(MSG_ERROR
, "WPA PSK file '%s' not found.", fname
);
302 while (fgets(buf
, sizeof(buf
), f
)) {
311 while (*pos
!= '\0') {
323 while ((token
= str_token(buf
, " ", &context
))) {
324 if (!os_strchr(token
, '='))
327 name
= str_token(token
, "=", &context2
);
330 value
= str_token(token
, "", &context2
);
333 if (!os_strcmp(name
, "keyid")) {
335 } else if (!os_strcmp(name
, "wps")) {
337 } else if (!os_strcmp(name
, "vlanid")) {
338 vlan_id
= atoi(value
);
340 wpa_printf(MSG_ERROR
,
341 "Unrecognized '%s=%s' on line %d in '%s'",
342 name
, value
, line
, fname
);
353 if (hwaddr_aton(token
, addr
)) {
354 wpa_printf(MSG_ERROR
,
355 "Invalid MAC address '%s' on line %d in '%s'",
361 psk
= os_zalloc(sizeof(*psk
));
363 wpa_printf(MSG_ERROR
, "WPA PSK allocation failed");
367 psk
->vlan_id
= vlan_id
;
368 if (is_zero_ether_addr(addr
))
371 os_memcpy(psk
->addr
, addr
, ETH_ALEN
);
373 pos
= str_token(buf
, "", &context
);
375 wpa_printf(MSG_ERROR
, "No PSK on line %d in '%s'",
383 len
= os_strlen(pos
);
384 if (len
== 2 * PMK_LEN
&&
385 hexstr2bin(pos
, psk
->psk
, PMK_LEN
) == 0)
387 else if (len
>= 8 && len
< 64 &&
388 pbkdf2_sha1(pos
, ssid
->ssid
, ssid
->ssid_len
,
389 4096, psk
->psk
, PMK_LEN
) == 0)
392 wpa_printf(MSG_ERROR
,
393 "Invalid PSK '%s' on line %d in '%s'",
401 len
= os_strlcpy(psk
->keyid
, keyid
, sizeof(psk
->keyid
));
402 if ((size_t) len
>= sizeof(psk
->keyid
)) {
403 wpa_printf(MSG_ERROR
,
404 "PSK keyid too long on line %d in '%s'",
414 psk
->next
= ssid
->wpa_psk
;
424 static int hostapd_derive_psk(struct hostapd_ssid
*ssid
)
426 ssid
->wpa_psk
= os_zalloc(sizeof(struct hostapd_wpa_psk
));
427 if (ssid
->wpa_psk
== NULL
) {
428 wpa_printf(MSG_ERROR
, "Unable to alloc space for PSK");
431 wpa_hexdump_ascii(MSG_DEBUG
, "SSID",
432 (u8
*) ssid
->ssid
, ssid
->ssid_len
);
433 wpa_hexdump_ascii_key(MSG_DEBUG
, "PSK (ASCII passphrase)",
434 (u8
*) ssid
->wpa_passphrase
,
435 os_strlen(ssid
->wpa_passphrase
));
436 pbkdf2_sha1(ssid
->wpa_passphrase
,
437 ssid
->ssid
, ssid
->ssid_len
,
438 4096, ssid
->wpa_psk
->psk
, PMK_LEN
);
439 wpa_hexdump_key(MSG_DEBUG
, "PSK (from passphrase)",
440 ssid
->wpa_psk
->psk
, PMK_LEN
);
445 int hostapd_setup_sae_pt(struct hostapd_bss_config
*conf
)
448 struct hostapd_ssid
*ssid
= &conf
->ssid
;
449 struct sae_password_entry
*pw
;
451 if ((conf
->sae_pwe
== 0 && !hostapd_sae_pw_id_in_use(conf
)) ||
452 conf
->sae_pwe
== 3 ||
453 !wpa_key_mgmt_sae(conf
->wpa_key_mgmt
))
454 return 0; /* PT not needed */
456 sae_deinit_pt(ssid
->pt
);
458 if (ssid
->wpa_passphrase
) {
459 ssid
->pt
= sae_derive_pt(conf
->sae_groups
, ssid
->ssid
,
461 (const u8
*) ssid
->wpa_passphrase
,
462 os_strlen(ssid
->wpa_passphrase
),
468 for (pw
= conf
->sae_passwords
; pw
; pw
= pw
->next
) {
469 sae_deinit_pt(pw
->pt
);
470 pw
->pt
= sae_derive_pt(conf
->sae_groups
, ssid
->ssid
,
472 (const u8
*) pw
->password
,
473 os_strlen(pw
->password
),
478 #endif /* CONFIG_SAE */
484 int hostapd_setup_wpa_psk(struct hostapd_bss_config
*conf
)
486 struct hostapd_ssid
*ssid
= &conf
->ssid
;
488 if (hostapd_setup_sae_pt(conf
) < 0)
491 if (ssid
->wpa_passphrase
!= NULL
) {
492 if (ssid
->wpa_psk
!= NULL
) {
493 wpa_printf(MSG_DEBUG
, "Using pre-configured WPA PSK "
494 "instead of passphrase");
496 wpa_printf(MSG_DEBUG
, "Deriving WPA PSK based on "
498 if (hostapd_derive_psk(ssid
) < 0)
501 ssid
->wpa_psk
->group
= 1;
504 return hostapd_config_read_wpa_psk(ssid
->wpa_psk_file
, &conf
->ssid
);
508 static void hostapd_config_free_radius(struct hostapd_radius_server
*servers
,
513 for (i
= 0; i
< num_servers
; i
++) {
514 os_free(servers
[i
].shared_secret
);
520 struct hostapd_radius_attr
*
521 hostapd_config_get_radius_attr(struct hostapd_radius_attr
*attr
, u8 type
)
523 for (; attr
; attr
= attr
->next
) {
524 if (attr
->type
== type
)
531 struct hostapd_radius_attr
* hostapd_parse_radius_attr(const char *value
)
535 struct hostapd_radius_attr
*attr
;
538 attr
= os_zalloc(sizeof(*attr
));
542 attr
->type
= atoi(value
);
544 pos
= os_strchr(value
, ':');
546 attr
->val
= wpabuf_alloc(1);
551 wpabuf_put_u8(attr
->val
, 0);
556 if (pos
[0] == '\0' || pos
[1] != ':') {
565 attr
->val
= wpabuf_alloc_copy(pos
, os_strlen(pos
));
568 len
= os_strlen(pos
);
572 attr
->val
= wpabuf_alloc(len
);
575 if (hexstr2bin(pos
, wpabuf_put(attr
->val
, len
), len
) < 0) {
576 wpabuf_free(attr
->val
);
582 attr
->val
= wpabuf_alloc(4);
584 wpabuf_put_be32(attr
->val
, atoi(pos
));
600 void hostapd_config_free_radius_attr(struct hostapd_radius_attr
*attr
)
602 struct hostapd_radius_attr
*prev
;
607 wpabuf_free(prev
->val
);
613 void hostapd_config_free_eap_user(struct hostapd_eap_user
*user
)
615 hostapd_config_free_radius_attr(user
->accept_attr
);
616 os_free(user
->identity
);
617 bin_clear_free(user
->password
, user
->password_len
);
618 bin_clear_free(user
->salt
, user
->salt_len
);
623 void hostapd_config_free_eap_users(struct hostapd_eap_user
*user
)
625 struct hostapd_eap_user
*prev_user
;
630 hostapd_config_free_eap_user(prev_user
);
635 static void hostapd_config_free_wep(struct hostapd_wep_keys
*keys
)
638 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
639 bin_clear_free(keys
->key
[i
], keys
->len
[i
]);
645 void hostapd_config_clear_wpa_psk(struct hostapd_wpa_psk
**l
)
647 struct hostapd_wpa_psk
*psk
, *tmp
;
649 for (psk
= *l
; psk
;) {
652 bin_clear_free(tmp
, sizeof(*tmp
));
658 static void hostapd_config_free_anqp_elem(struct hostapd_bss_config
*conf
)
660 struct anqp_element
*elem
;
662 while ((elem
= dl_list_first(&conf
->anqp_elem
, struct anqp_element
,
664 dl_list_del(&elem
->list
);
665 wpabuf_free(elem
->payload
);
671 static void hostapd_config_free_fils_realms(struct hostapd_bss_config
*conf
)
674 struct fils_realm
*realm
;
676 while ((realm
= dl_list_first(&conf
->fils_realms
, struct fils_realm
,
678 dl_list_del(&realm
->list
);
681 #endif /* CONFIG_FILS */
685 static void hostapd_config_free_sae_passwords(struct hostapd_bss_config
*conf
)
687 struct sae_password_entry
*pw
, *tmp
;
689 pw
= conf
->sae_passwords
;
690 conf
->sae_passwords
= NULL
;
694 str_clear_free(tmp
->password
);
695 os_free(tmp
->identifier
);
697 sae_deinit_pt(tmp
->pt
);
698 #endif /* CONFIG_SAE */
705 static void hostapd_dpp_controller_conf_free(struct dpp_controller_conf
*conf
)
707 struct dpp_controller_conf
*prev
;
715 #endif /* CONFIG_DPP2 */
718 void hostapd_config_free_bss(struct hostapd_bss_config
*conf
)
720 #if defined(CONFIG_WPS) || defined(CONFIG_HS20)
727 hostapd_config_clear_wpa_psk(&conf
->ssid
.wpa_psk
);
729 str_clear_free(conf
->ssid
.wpa_passphrase
);
730 os_free(conf
->ssid
.wpa_psk_file
);
731 hostapd_config_free_wep(&conf
->ssid
.wep
);
732 #ifdef CONFIG_FULL_DYNAMIC_VLAN
733 os_free(conf
->ssid
.vlan_tagged_interface
);
734 #endif /* CONFIG_FULL_DYNAMIC_VLAN */
736 sae_deinit_pt(conf
->ssid
.pt
);
737 #endif /* CONFIG_SAE */
739 hostapd_config_free_eap_users(conf
->eap_user
);
740 os_free(conf
->eap_user_sqlite
);
742 os_free(conf
->eap_req_id_text
);
743 os_free(conf
->erp_domain
);
744 os_free(conf
->accept_mac
);
745 os_free(conf
->deny_mac
);
746 os_free(conf
->nas_identifier
);
748 hostapd_config_free_radius(conf
->radius
->auth_servers
,
749 conf
->radius
->num_auth_servers
);
750 hostapd_config_free_radius(conf
->radius
->acct_servers
,
751 conf
->radius
->num_acct_servers
);
753 hostapd_config_free_radius_attr(conf
->radius_auth_req_attr
);
754 hostapd_config_free_radius_attr(conf
->radius_acct_req_attr
);
755 os_free(conf
->radius_req_attr_sqlite
);
756 os_free(conf
->rsn_preauth_interfaces
);
757 os_free(conf
->ctrl_interface
);
758 os_free(conf
->ca_cert
);
759 os_free(conf
->server_cert
);
760 os_free(conf
->server_cert2
);
761 os_free(conf
->private_key
);
762 os_free(conf
->private_key2
);
763 os_free(conf
->private_key_passwd
);
764 os_free(conf
->private_key_passwd2
);
765 os_free(conf
->check_cert_subject
);
766 os_free(conf
->ocsp_stapling_response
);
767 os_free(conf
->ocsp_stapling_response_multi
);
768 os_free(conf
->dh_file
);
769 os_free(conf
->openssl_ciphers
);
770 os_free(conf
->openssl_ecdh_curves
);
771 os_free(conf
->pac_opaque_encr_key
);
772 os_free(conf
->eap_fast_a_id
);
773 os_free(conf
->eap_fast_a_id_info
);
774 os_free(conf
->eap_sim_db
);
775 os_free(conf
->radius_server_clients
);
776 os_free(conf
->radius
);
777 os_free(conf
->radius_das_shared_secret
);
778 hostapd_config_free_vlan(conf
);
779 os_free(conf
->time_zone
);
781 #ifdef CONFIG_IEEE80211R_AP
783 struct ft_remote_r0kh
*r0kh
, *r0kh_prev
;
784 struct ft_remote_r1kh
*r1kh
, *r1kh_prev
;
786 r0kh
= conf
->r0kh_list
;
787 conf
->r0kh_list
= NULL
;
794 r1kh
= conf
->r1kh_list
;
795 conf
->r1kh_list
= NULL
;
802 #endif /* CONFIG_IEEE80211R_AP */
805 os_free(conf
->wps_pin_requests
);
806 os_free(conf
->device_name
);
807 os_free(conf
->manufacturer
);
808 os_free(conf
->model_name
);
809 os_free(conf
->model_number
);
810 os_free(conf
->serial_number
);
811 os_free(conf
->config_methods
);
812 os_free(conf
->ap_pin
);
813 os_free(conf
->extra_cred
);
814 os_free(conf
->ap_settings
);
815 hostapd_config_clear_wpa_psk(&conf
->multi_ap_backhaul_ssid
.wpa_psk
);
816 str_clear_free(conf
->multi_ap_backhaul_ssid
.wpa_passphrase
);
817 os_free(conf
->upnp_iface
);
818 os_free(conf
->friendly_name
);
819 os_free(conf
->manufacturer_url
);
820 os_free(conf
->model_description
);
821 os_free(conf
->model_url
);
823 for (i
= 0; i
< MAX_WPS_VENDOR_EXTENSIONS
; i
++)
824 wpabuf_free(conf
->wps_vendor_ext
[i
]);
825 wpabuf_free(conf
->wps_application_ext
);
826 wpabuf_free(conf
->wps_nfc_dh_pubkey
);
827 wpabuf_free(conf
->wps_nfc_dh_privkey
);
828 wpabuf_free(conf
->wps_nfc_dev_pw
);
829 #endif /* CONFIG_WPS */
831 os_free(conf
->roaming_consortium
);
832 os_free(conf
->venue_name
);
833 os_free(conf
->venue_url
);
834 os_free(conf
->nai_realm_data
);
835 os_free(conf
->network_auth_type
);
836 os_free(conf
->anqp_3gpp_cell_net
);
837 os_free(conf
->domain_name
);
838 hostapd_config_free_anqp_elem(conf
);
840 #ifdef CONFIG_RADIUS_TEST
841 os_free(conf
->dump_msk_file
);
842 #endif /* CONFIG_RADIUS_TEST */
845 os_free(conf
->hs20_oper_friendly_name
);
846 os_free(conf
->hs20_wan_metrics
);
847 os_free(conf
->hs20_connection_capability
);
848 os_free(conf
->hs20_operating_class
);
849 os_free(conf
->hs20_icons
);
850 if (conf
->hs20_osu_providers
) {
851 for (i
= 0; i
< conf
->hs20_osu_providers_count
; i
++) {
852 struct hs20_osu_provider
*p
;
854 p
= &conf
->hs20_osu_providers
[i
];
855 os_free(p
->friendly_name
);
856 os_free(p
->server_uri
);
857 os_free(p
->method_list
);
858 for (j
= 0; j
< p
->icons_count
; j
++)
859 os_free(p
->icons
[j
]);
862 os_free(p
->osu_nai2
);
863 os_free(p
->service_desc
);
865 os_free(conf
->hs20_osu_providers
);
867 if (conf
->hs20_operator_icon
) {
868 for (i
= 0; i
< conf
->hs20_operator_icon_count
; i
++)
869 os_free(conf
->hs20_operator_icon
[i
]);
870 os_free(conf
->hs20_operator_icon
);
872 os_free(conf
->subscr_remediation_url
);
873 os_free(conf
->hs20_sim_provisioning_url
);
874 os_free(conf
->t_c_filename
);
875 os_free(conf
->t_c_server_url
);
876 #endif /* CONFIG_HS20 */
878 wpabuf_free(conf
->vendor_elements
);
879 wpabuf_free(conf
->assocresp_elements
);
881 os_free(conf
->sae_groups
);
883 os_free(conf
->owe_groups
);
884 #endif /* CONFIG_OWE */
886 os_free(conf
->wowlan_triggers
);
888 os_free(conf
->server_id
);
890 #ifdef CONFIG_TESTING_OPTIONS
891 wpabuf_free(conf
->own_ie_override
);
892 wpabuf_free(conf
->sae_commit_override
);
893 wpabuf_free(conf
->rsnxe_override_eapol
);
894 wpabuf_free(conf
->gtk_rsc_override
);
895 wpabuf_free(conf
->igtk_rsc_override
);
896 #endif /* CONFIG_TESTING_OPTIONS */
898 os_free(conf
->no_probe_resp_if_seen_on
);
899 os_free(conf
->no_auth_if_seen_on
);
901 hostapd_config_free_fils_realms(conf
);
904 os_free(conf
->dpp_name
);
905 os_free(conf
->dpp_mud_url
);
906 os_free(conf
->dpp_connector
);
907 wpabuf_free(conf
->dpp_netaccesskey
);
908 wpabuf_free(conf
->dpp_csign
);
910 hostapd_dpp_controller_conf_free(conf
->dpp_controller
);
911 #endif /* CONFIG_DPP2 */
912 #endif /* CONFIG_DPP */
914 hostapd_config_free_sae_passwords(conf
);
916 #ifdef CONFIG_AIRTIME_POLICY
918 struct airtime_sta_weight
*wt
, *wt_prev
;
920 wt
= conf
->airtime_weight_list
;
921 conf
->airtime_weight_list
= NULL
;
928 #endif /* CONFIG_AIRTIME_POLICY */
935 * hostapd_config_free - Free hostapd configuration
936 * @conf: Configuration data from hostapd_config_read().
938 void hostapd_config_free(struct hostapd_config
*conf
)
945 for (i
= 0; i
< conf
->num_bss
; i
++)
946 hostapd_config_free_bss(conf
->bss
[i
]);
948 os_free(conf
->supported_rates
);
949 os_free(conf
->basic_rates
);
950 os_free(conf
->acs_ch_list
.range
);
951 os_free(conf
->acs_freq_list
.range
);
952 os_free(conf
->driver_params
);
954 os_free(conf
->acs_chan_bias
);
955 #endif /* CONFIG_ACS */
956 wpabuf_free(conf
->lci
);
957 wpabuf_free(conf
->civic
);
964 * hostapd_maclist_found - Find a MAC address from a list
965 * @list: MAC address list
966 * @num_entries: Number of addresses in the list
967 * @addr: Address to search for
968 * @vlan_id: Buffer for returning VLAN ID or %NULL if not needed
969 * Returns: 1 if address is in the list or 0 if not.
971 * Perform a binary search for given MAC address from a pre-sorted list.
973 int hostapd_maclist_found(struct mac_acl_entry
*list
, int num_entries
,
974 const u8
*addr
, struct vlan_description
*vlan_id
)
976 int start
, end
, middle
, res
;
979 end
= num_entries
- 1;
981 while (start
<= end
) {
982 middle
= (start
+ end
) / 2;
983 res
= os_memcmp(list
[middle
].addr
, addr
, ETH_ALEN
);
986 *vlan_id
= list
[middle
].vlan_id
;
999 int hostapd_rate_found(int *list
, int rate
)
1006 for (i
= 0; list
[i
] >= 0; i
++)
1007 if (list
[i
] == rate
)
1014 int hostapd_vlan_valid(struct hostapd_vlan
*vlan
,
1015 struct vlan_description
*vlan_desc
)
1017 struct hostapd_vlan
*v
= vlan
;
1020 if (!vlan_desc
->notempty
|| vlan_desc
->untagged
< 0 ||
1021 vlan_desc
->untagged
> MAX_VLAN_ID
)
1023 for (i
= 0; i
< MAX_NUM_TAGGED_VLAN
; i
++) {
1024 if (vlan_desc
->tagged
[i
] < 0 ||
1025 vlan_desc
->tagged
[i
] > MAX_VLAN_ID
)
1028 if (!vlan_desc
->untagged
&& !vlan_desc
->tagged
[0])
1032 if (!vlan_compare(&v
->vlan_desc
, vlan_desc
) ||
1033 v
->vlan_id
== VLAN_ID_WILDCARD
)
1041 const char * hostapd_get_vlan_id_ifname(struct hostapd_vlan
*vlan
, int vlan_id
)
1043 struct hostapd_vlan
*v
= vlan
;
1045 if (v
->vlan_id
== vlan_id
)
1053 const u8
* hostapd_get_psk(const struct hostapd_bss_config
*conf
,
1054 const u8
*addr
, const u8
*p2p_dev_addr
,
1055 const u8
*prev_psk
, int *vlan_id
)
1057 struct hostapd_wpa_psk
*psk
;
1058 int next_ok
= prev_psk
== NULL
;
1063 if (p2p_dev_addr
&& !is_zero_ether_addr(p2p_dev_addr
)) {
1064 wpa_printf(MSG_DEBUG
, "Searching a PSK for " MACSTR
1065 " p2p_dev_addr=" MACSTR
" prev_psk=%p",
1066 MAC2STR(addr
), MAC2STR(p2p_dev_addr
), prev_psk
);
1067 addr
= NULL
; /* Use P2P Device Address for matching */
1069 wpa_printf(MSG_DEBUG
, "Searching a PSK for " MACSTR
1071 MAC2STR(addr
), prev_psk
);
1074 for (psk
= conf
->ssid
.wpa_psk
; psk
!= NULL
; psk
= psk
->next
) {
1077 (addr
&& os_memcmp(psk
->addr
, addr
, ETH_ALEN
) == 0) ||
1078 (!addr
&& p2p_dev_addr
&&
1079 os_memcmp(psk
->p2p_dev_addr
, p2p_dev_addr
, ETH_ALEN
) ==
1082 *vlan_id
= psk
->vlan_id
;
1086 if (psk
->psk
== prev_psk
)
1094 static int hostapd_config_check_bss(struct hostapd_bss_config
*bss
,
1095 struct hostapd_config
*conf
,
1098 if (full_config
&& bss
->ieee802_1x
&& !bss
->eap_server
&&
1099 !bss
->radius
->auth_servers
) {
1100 wpa_printf(MSG_ERROR
, "Invalid IEEE 802.1X configuration (no "
1101 "EAP authenticator configured).");
1108 wep
= bss
->default_wep_key_len
> 0 ||
1109 bss
->individual_wep_key_len
> 0;
1110 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
1111 if (bss
->ssid
.wep
.keys_set
) {
1118 wpa_printf(MSG_ERROR
, "WEP configuration in a WPA network is not supported");
1123 if (full_config
&& bss
->wpa
&&
1124 bss
->wpa_psk_radius
!= PSK_RADIUS_IGNORED
&&
1125 bss
->macaddr_acl
!= USE_EXTERNAL_RADIUS_AUTH
) {
1126 wpa_printf(MSG_ERROR
, "WPA-PSK using RADIUS enabled, but no "
1127 "RADIUS checking (macaddr_acl=2) enabled.");
1131 if (full_config
&& bss
->wpa
&& (bss
->wpa_key_mgmt
& WPA_KEY_MGMT_PSK
) &&
1132 bss
->ssid
.wpa_psk
== NULL
&& bss
->ssid
.wpa_passphrase
== NULL
&&
1133 bss
->ssid
.wpa_psk_file
== NULL
&&
1134 (bss
->wpa_psk_radius
!= PSK_RADIUS_REQUIRED
||
1135 bss
->macaddr_acl
!= USE_EXTERNAL_RADIUS_AUTH
)) {
1136 wpa_printf(MSG_ERROR
, "WPA-PSK enabled, but PSK or passphrase "
1137 "is not configured.");
1141 if (full_config
&& !is_zero_ether_addr(bss
->bssid
)) {
1144 for (i
= 0; i
< conf
->num_bss
; i
++) {
1145 if (conf
->bss
[i
] != bss
&&
1146 (hostapd_mac_comp(conf
->bss
[i
]->bssid
,
1147 bss
->bssid
) == 0)) {
1148 wpa_printf(MSG_ERROR
, "Duplicate BSSID " MACSTR
1149 " on interface '%s' and '%s'.",
1150 MAC2STR(bss
->bssid
),
1151 conf
->bss
[i
]->iface
, bss
->iface
);
1157 #ifdef CONFIG_IEEE80211R_AP
1158 if (full_config
&& wpa_key_mgmt_ft(bss
->wpa_key_mgmt
) &&
1159 (bss
->nas_identifier
== NULL
||
1160 os_strlen(bss
->nas_identifier
) < 1 ||
1161 os_strlen(bss
->nas_identifier
) > FT_R0KH_ID_MAX_LEN
)) {
1162 wpa_printf(MSG_ERROR
, "FT (IEEE 802.11r) requires "
1163 "nas_identifier to be configured as a 1..48 octet "
1167 #endif /* CONFIG_IEEE80211R_AP */
1169 #ifdef CONFIG_IEEE80211N
1170 if (full_config
&& conf
->ieee80211n
&&
1171 conf
->hw_mode
== HOSTAPD_MODE_IEEE80211B
) {
1172 bss
->disable_11n
= 1;
1173 wpa_printf(MSG_ERROR
, "HT (IEEE 802.11n) in 11b mode is not "
1174 "allowed, disabling HT capabilities");
1177 if (full_config
&& conf
->ieee80211n
&&
1178 bss
->ssid
.security_policy
== SECURITY_STATIC_WEP
) {
1179 bss
->disable_11n
= 1;
1180 wpa_printf(MSG_ERROR
, "HT (IEEE 802.11n) with WEP is not "
1181 "allowed, disabling HT capabilities");
1184 if (full_config
&& conf
->ieee80211n
&& bss
->wpa
&&
1185 !(bss
->wpa_pairwise
& WPA_CIPHER_CCMP
) &&
1186 !(bss
->rsn_pairwise
& (WPA_CIPHER_CCMP
| WPA_CIPHER_GCMP
|
1187 WPA_CIPHER_CCMP_256
| WPA_CIPHER_GCMP_256
)))
1189 bss
->disable_11n
= 1;
1190 wpa_printf(MSG_ERROR
, "HT (IEEE 802.11n) with WPA/WPA2 "
1191 "requires CCMP/GCMP to be enabled, disabling HT "
1194 #endif /* CONFIG_IEEE80211N */
1196 #ifdef CONFIG_IEEE80211AC
1197 if (full_config
&& conf
->ieee80211ac
&&
1198 bss
->ssid
.security_policy
== SECURITY_STATIC_WEP
) {
1199 bss
->disable_11ac
= 1;
1200 wpa_printf(MSG_ERROR
,
1201 "VHT (IEEE 802.11ac) with WEP is not allowed, disabling VHT capabilities");
1204 if (full_config
&& conf
->ieee80211ac
&& bss
->wpa
&&
1205 !(bss
->wpa_pairwise
& WPA_CIPHER_CCMP
) &&
1206 !(bss
->rsn_pairwise
& (WPA_CIPHER_CCMP
| WPA_CIPHER_GCMP
|
1207 WPA_CIPHER_CCMP_256
| WPA_CIPHER_GCMP_256
)))
1209 bss
->disable_11ac
= 1;
1210 wpa_printf(MSG_ERROR
,
1211 "VHT (IEEE 802.11ac) with WPA/WPA2 requires CCMP/GCMP to be enabled, disabling VHT capabilities");
1213 #endif /* CONFIG_IEEE80211AC */
1216 if (full_config
&& bss
->wps_state
&& bss
->ignore_broadcast_ssid
) {
1217 wpa_printf(MSG_INFO
, "WPS: ignore_broadcast_ssid "
1218 "configuration forced WPS to be disabled");
1222 if (full_config
&& bss
->wps_state
&&
1223 bss
->ssid
.wep
.keys_set
&& bss
->wpa
== 0) {
1224 wpa_printf(MSG_INFO
, "WPS: WEP configuration forced WPS to be "
1229 if (full_config
&& bss
->wps_state
&& bss
->wpa
&&
1231 !(bss
->rsn_pairwise
& (WPA_CIPHER_CCMP
| WPA_CIPHER_GCMP
|
1232 WPA_CIPHER_CCMP_256
|
1233 WPA_CIPHER_GCMP_256
)))) {
1234 wpa_printf(MSG_INFO
, "WPS: WPA/TKIP configuration without "
1235 "WPA2/CCMP/GCMP forced WPS to be disabled");
1238 #endif /* CONFIG_WPS */
1241 if (full_config
&& bss
->hs20
&&
1243 !(bss
->rsn_pairwise
& (WPA_CIPHER_CCMP
| WPA_CIPHER_GCMP
|
1244 WPA_CIPHER_CCMP_256
|
1245 WPA_CIPHER_GCMP_256
)))) {
1246 wpa_printf(MSG_ERROR
, "HS 2.0: WPA2-Enterprise/CCMP "
1247 "configuration is required for Hotspot 2.0 "
1251 #endif /* CONFIG_HS20 */
1254 if (full_config
&& bss
->mbo_enabled
&& (bss
->wpa
& 2) &&
1255 bss
->ieee80211w
== NO_MGMT_FRAME_PROTECTION
) {
1256 wpa_printf(MSG_ERROR
,
1257 "MBO: PMF needs to be enabled whenever using WPA2 with MBO");
1260 #endif /* CONFIG_MBO */
1263 if (full_config
&& bss
->ieee80211w
== NO_MGMT_FRAME_PROTECTION
&&
1265 wpa_printf(MSG_ERROR
,
1266 "OCV: PMF needs to be enabled whenever using OCV");
1269 #endif /* CONFIG_OCV */
1275 static int hostapd_config_check_cw(struct hostapd_config
*conf
, int queue
)
1277 int tx_cwmin
= conf
->tx_queue
[queue
].cwmin
;
1278 int tx_cwmax
= conf
->tx_queue
[queue
].cwmax
;
1279 int ac_cwmin
= conf
->wmm_ac_params
[queue
].cwmin
;
1280 int ac_cwmax
= conf
->wmm_ac_params
[queue
].cwmax
;
1282 if (tx_cwmin
> tx_cwmax
) {
1283 wpa_printf(MSG_ERROR
,
1284 "Invalid TX queue cwMin/cwMax values. cwMin(%d) greater than cwMax(%d)",
1285 tx_cwmin
, tx_cwmax
);
1288 if (ac_cwmin
> ac_cwmax
) {
1289 wpa_printf(MSG_ERROR
,
1290 "Invalid WMM AC cwMin/cwMax values. cwMin(%d) greater than cwMax(%d)",
1291 ac_cwmin
, ac_cwmax
);
1298 int hostapd_config_check(struct hostapd_config
*conf
, int full_config
)
1302 if (full_config
&& conf
->ieee80211d
&&
1303 (!conf
->country
[0] || !conf
->country
[1])) {
1304 wpa_printf(MSG_ERROR
, "Cannot enable IEEE 802.11d without "
1305 "setting the country_code");
1309 if (full_config
&& conf
->ieee80211h
&& !conf
->ieee80211d
) {
1310 wpa_printf(MSG_ERROR
, "Cannot enable IEEE 802.11h without "
1311 "IEEE 802.11d enabled");
1315 if (full_config
&& conf
->local_pwr_constraint
!= -1 &&
1316 !conf
->ieee80211d
) {
1317 wpa_printf(MSG_ERROR
, "Cannot add Power Constraint element without Country element");
1321 if (full_config
&& conf
->spectrum_mgmt_required
&&
1322 conf
->local_pwr_constraint
== -1) {
1323 wpa_printf(MSG_ERROR
, "Cannot set Spectrum Management bit without Country and Power Constraint elements");
1327 #ifdef CONFIG_AIRTIME_POLICY
1328 if (full_config
&& conf
->airtime_mode
> AIRTIME_MODE_STATIC
&&
1329 !conf
->airtime_update_interval
) {
1330 wpa_printf(MSG_ERROR
, "Airtime update interval cannot be zero");
1333 #endif /* CONFIG_AIRTIME_POLICY */
1334 for (i
= 0; i
< NUM_TX_QUEUES
; i
++) {
1335 if (hostapd_config_check_cw(conf
, i
))
1339 for (i
= 0; i
< conf
->num_bss
; i
++) {
1340 if (hostapd_config_check_bss(conf
->bss
[i
], conf
, full_config
))
1348 void hostapd_set_security_params(struct hostapd_bss_config
*bss
,
1351 if (bss
->individual_wep_key_len
== 0) {
1352 /* individual keys are not use; can use key idx0 for
1354 bss
->broadcast_key_idx_min
= 0;
1357 if ((bss
->wpa
& 2) && bss
->rsn_pairwise
== 0)
1358 bss
->rsn_pairwise
= bss
->wpa_pairwise
;
1359 if (bss
->group_cipher
)
1360 bss
->wpa_group
= bss
->group_cipher
;
1362 bss
->wpa_group
= wpa_select_ap_group_cipher(bss
->wpa
,
1365 if (!bss
->wpa_group_rekey_set
)
1366 bss
->wpa_group_rekey
= bss
->wpa_group
== WPA_CIPHER_TKIP
?
1370 bss
->radius
->auth_server
= bss
->radius
->auth_servers
;
1371 bss
->radius
->acct_server
= bss
->radius
->acct_servers
;
1374 if (bss
->wpa
&& bss
->ieee802_1x
) {
1375 bss
->ssid
.security_policy
= SECURITY_WPA
;
1376 } else if (bss
->wpa
) {
1377 bss
->ssid
.security_policy
= SECURITY_WPA_PSK
;
1378 } else if (bss
->ieee802_1x
) {
1379 int cipher
= WPA_CIPHER_NONE
;
1380 bss
->ssid
.security_policy
= SECURITY_IEEE_802_1X
;
1381 bss
->ssid
.wep
.default_len
= bss
->default_wep_key_len
;
1382 if (full_config
&& bss
->default_wep_key_len
) {
1383 cipher
= bss
->default_wep_key_len
>= 13 ?
1384 WPA_CIPHER_WEP104
: WPA_CIPHER_WEP40
;
1385 } else if (full_config
&& bss
->ssid
.wep
.keys_set
) {
1386 if (bss
->ssid
.wep
.len
[0] >= 13)
1387 cipher
= WPA_CIPHER_WEP104
;
1389 cipher
= WPA_CIPHER_WEP40
;
1391 bss
->wpa_group
= cipher
;
1392 bss
->wpa_pairwise
= cipher
;
1393 bss
->rsn_pairwise
= cipher
;
1395 bss
->wpa_key_mgmt
= WPA_KEY_MGMT_IEEE8021X_NO_WPA
;
1396 } else if (bss
->ssid
.wep
.keys_set
) {
1397 int cipher
= WPA_CIPHER_WEP40
;
1398 if (bss
->ssid
.wep
.len
[0] >= 13)
1399 cipher
= WPA_CIPHER_WEP104
;
1400 bss
->ssid
.security_policy
= SECURITY_STATIC_WEP
;
1401 bss
->wpa_group
= cipher
;
1402 bss
->wpa_pairwise
= cipher
;
1403 bss
->rsn_pairwise
= cipher
;
1405 bss
->wpa_key_mgmt
= WPA_KEY_MGMT_NONE
;
1406 } else if (bss
->osen
) {
1407 bss
->ssid
.security_policy
= SECURITY_OSEN
;
1408 bss
->wpa_group
= WPA_CIPHER_CCMP
;
1409 bss
->wpa_pairwise
= 0;
1410 bss
->rsn_pairwise
= WPA_CIPHER_CCMP
;
1412 bss
->ssid
.security_policy
= SECURITY_PLAINTEXT
;
1414 bss
->wpa_group
= WPA_CIPHER_NONE
;
1415 bss
->wpa_pairwise
= WPA_CIPHER_NONE
;
1416 bss
->rsn_pairwise
= WPA_CIPHER_NONE
;
1417 bss
->wpa_key_mgmt
= WPA_KEY_MGMT_NONE
;
1423 int hostapd_sae_pw_id_in_use(struct hostapd_bss_config
*conf
)
1425 int with_id
= 0, without_id
= 0;
1426 struct sae_password_entry
*pw
;
1428 if (conf
->ssid
.wpa_passphrase
)
1431 for (pw
= conf
->sae_passwords
; pw
; pw
= pw
->next
) {
1436 if (with_id
&& without_id
)
1440 if (with_id
&& !without_id
)