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 "eap_common/eap_wsc_common.h"
20 #include "eap_server/eap.h"
23 #include "airtime_policy.h"
24 #include "ap_config.h"
27 static void hostapd_config_free_vlan(struct hostapd_bss_config
*bss
)
29 struct hostapd_vlan
*vlan
, *prev
;
43 #ifndef DEFAULT_WPA_DISABLE_EAPOL_KEY_RETRIES
44 #define DEFAULT_WPA_DISABLE_EAPOL_KEY_RETRIES 0
45 #endif /* DEFAULT_WPA_DISABLE_EAPOL_KEY_RETRIES */
47 void hostapd_config_defaults_bss(struct hostapd_bss_config
*bss
)
49 dl_list_init(&bss
->anqp_elem
);
51 bss
->logger_syslog_level
= HOSTAPD_LEVEL_INFO
;
52 bss
->logger_stdout_level
= HOSTAPD_LEVEL_INFO
;
53 bss
->logger_syslog
= (unsigned int) -1;
54 bss
->logger_stdout
= (unsigned int) -1;
56 bss
->auth_algs
= WPA_AUTH_ALG_OPEN
| WPA_AUTH_ALG_SHARED
;
58 bss
->wep_rekeying_period
= 300;
59 /* use key0 in individual key and key1 in broadcast key */
60 bss
->broadcast_key_idx_min
= 1;
61 bss
->broadcast_key_idx_max
= 2;
62 bss
->eap_reauth_period
= 3600;
64 bss
->wpa_group_rekey
= 600;
65 bss
->wpa_gmk_rekey
= 86400;
66 bss
->wpa_group_update_count
= 4;
67 bss
->wpa_pairwise_update_count
= 4;
68 bss
->wpa_disable_eapol_key_retries
=
69 DEFAULT_WPA_DISABLE_EAPOL_KEY_RETRIES
;
70 bss
->wpa_key_mgmt
= WPA_KEY_MGMT_PSK
;
71 bss
->wpa_pairwise
= WPA_CIPHER_TKIP
;
72 bss
->wpa_group
= WPA_CIPHER_TKIP
;
73 bss
->rsn_pairwise
= 0;
75 bss
->max_num_sta
= MAX_STA_COUNT
;
79 bss
->radius_server_auth_port
= 1812;
80 bss
->eap_sim_db_timeout
= 1;
81 bss
->ap_max_inactivity
= AP_MAX_INACTIVITY
;
82 bss
->eapol_version
= EAPOL_VERSION
;
84 bss
->max_listen_interval
= 65535;
86 bss
->pwd_group
= 19; /* ECC: GF(p=256) */
88 #ifdef CONFIG_IEEE80211W
89 bss
->assoc_sa_query_max_timeout
= 1000;
90 bss
->assoc_sa_query_retry_timeout
= 201;
91 bss
->group_mgmt_cipher
= WPA_CIPHER_AES_128_CMAC
;
92 #endif /* CONFIG_IEEE80211W */
93 #ifdef EAP_SERVER_FAST
94 /* both anonymous and authenticated provisioning */
95 bss
->eap_fast_prov
= 3;
96 bss
->pac_key_lifetime
= 7 * 24 * 60 * 60;
97 bss
->pac_key_refresh_time
= 1 * 24 * 60 * 60;
98 #endif /* EAP_SERVER_FAST */
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
->send_probe_response
= 1;
140 bss
->hs20_release
= (HS20_VERSION
>> 4) + 1;
141 #endif /* CONFIG_HS20 */
144 bss
->mka_priority
= DEFAULT_PRIO_NOT_KEY_SERVER
;
145 bss
->macsec_port
= 1;
146 #endif /* CONFIG_MACSEC */
148 /* Default to strict CRL checking. */
149 bss
->check_crl_strict
= 1;
153 struct hostapd_config
* hostapd_config_defaults(void)
155 #define ecw2cw(ecw) ((1 << (ecw)) - 1)
157 struct hostapd_config
*conf
;
158 struct hostapd_bss_config
*bss
;
159 const int aCWmin
= 4, aCWmax
= 10;
160 const struct hostapd_wmm_ac_params ac_bk
=
161 { aCWmin
, aCWmax
, 7, 0, 0 }; /* background traffic */
162 const struct hostapd_wmm_ac_params ac_be
=
163 { aCWmin
, aCWmax
, 3, 0, 0 }; /* best effort traffic */
164 const struct hostapd_wmm_ac_params ac_vi
= /* video traffic */
165 { aCWmin
- 1, aCWmin
, 2, 3008 / 32, 0 };
166 const struct hostapd_wmm_ac_params ac_vo
= /* voice traffic */
167 { aCWmin
- 2, aCWmin
- 1, 2, 1504 / 32, 0 };
168 const struct hostapd_tx_queue_params txq_bk
=
169 { 7, ecw2cw(aCWmin
), ecw2cw(aCWmax
), 0 };
170 const struct hostapd_tx_queue_params txq_be
=
171 { 3, ecw2cw(aCWmin
), 4 * (ecw2cw(aCWmin
) + 1) - 1, 0};
172 const struct hostapd_tx_queue_params txq_vi
=
173 { 1, (ecw2cw(aCWmin
) + 1) / 2 - 1, ecw2cw(aCWmin
), 30};
174 const struct hostapd_tx_queue_params txq_vo
=
175 { 1, (ecw2cw(aCWmin
) + 1) / 4 - 1,
176 (ecw2cw(aCWmin
) + 1) / 2 - 1, 15};
180 conf
= os_zalloc(sizeof(*conf
));
181 bss
= os_zalloc(sizeof(*bss
));
182 if (conf
== NULL
|| bss
== NULL
) {
183 wpa_printf(MSG_ERROR
, "Failed to allocate memory for "
184 "configuration data.");
189 conf
->bss
= os_calloc(1, sizeof(struct hostapd_bss_config
*));
190 if (conf
->bss
== NULL
) {
197 bss
->radius
= os_zalloc(sizeof(*bss
->radius
));
198 if (bss
->radius
== NULL
) {
205 hostapd_config_defaults_bss(bss
);
209 conf
->beacon_int
= 100;
210 conf
->rts_threshold
= -2; /* use driver default: 2347 */
211 conf
->fragm_threshold
= -2; /* user driver default: 2346 */
212 /* Set to invalid value means do not add Power Constraint IE */
213 conf
->local_pwr_constraint
= -1;
215 conf
->wmm_ac_params
[0] = ac_be
;
216 conf
->wmm_ac_params
[1] = ac_bk
;
217 conf
->wmm_ac_params
[2] = ac_vi
;
218 conf
->wmm_ac_params
[3] = ac_vo
;
220 conf
->tx_queue
[0] = txq_vo
;
221 conf
->tx_queue
[1] = txq_vi
;
222 conf
->tx_queue
[2] = txq_be
;
223 conf
->tx_queue
[3] = txq_bk
;
225 conf
->ht_capab
= HT_CAP_INFO_SMPS_DISABLED
;
227 conf
->ap_table_max_size
= 255;
228 conf
->ap_table_expiration_time
= 60;
229 conf
->track_sta_max_age
= 180;
231 #ifdef CONFIG_TESTING_OPTIONS
232 conf
->ignore_probe_probability
= 0.0;
233 conf
->ignore_auth_probability
= 0.0;
234 conf
->ignore_assoc_probability
= 0.0;
235 conf
->ignore_reassoc_probability
= 0.0;
236 conf
->corrupt_gtk_rekey_mic_probability
= 0.0;
237 conf
->ecsa_ie_only
= 0;
238 #endif /* CONFIG_TESTING_OPTIONS */
241 conf
->acs_ch_list
.num
= 0;
243 conf
->acs_num_scans
= 5;
244 #endif /* CONFIG_ACS */
246 #ifdef CONFIG_IEEE80211AX
247 conf
->he_op
.he_rts_threshold
= HE_OPERATION_RTS_THRESHOLD_MASK
>>
248 HE_OPERATION_RTS_THRESHOLD_OFFSET
;
249 /* Set default basic MCS/NSS set to single stream MCS 0-7 */
250 conf
->he_op
.he_basic_mcs_nss_set
= 0xfffc;
251 #endif /* CONFIG_IEEE80211AX */
253 /* The third octet of the country string uses an ASCII space character
254 * by default to indicate that the regulations encompass all
255 * environments for the current frequency band in the country. */
256 conf
->country
[2] = ' ';
258 conf
->rssi_reject_assoc_rssi
= 0;
259 conf
->rssi_reject_assoc_timeout
= 30;
261 #ifdef CONFIG_AIRTIME_POLICY
262 conf
->airtime_update_interval
= AIRTIME_DEFAULT_UPDATE_INTERVAL
;
263 #endif /* CONFIG_AIRTIME_POLICY */
269 int hostapd_mac_comp(const void *a
, const void *b
)
271 return os_memcmp(a
, b
, sizeof(macaddr
));
275 static int hostapd_config_read_wpa_psk(const char *fname
,
276 struct hostapd_ssid
*ssid
)
286 int line
= 0, ret
= 0, len
, ok
;
288 struct hostapd_wpa_psk
*psk
;
293 f
= fopen(fname
, "r");
295 wpa_printf(MSG_ERROR
, "WPA PSK file '%s' not found.", fname
);
299 while (fgets(buf
, sizeof(buf
), f
)) {
307 while (*pos
!= '\0') {
319 while ((token
= str_token(buf
, " ", &context
))) {
320 if (!os_strchr(token
, '='))
323 name
= str_token(token
, "=", &context2
);
326 value
= str_token(token
, "", &context2
);
329 if (!os_strcmp(name
, "keyid")) {
331 } else if (!os_strcmp(name
, "vlanid")) {
332 vlan_id
= atoi(value
);
334 wpa_printf(MSG_ERROR
,
335 "Unrecognized '%s=%s' on line %d in '%s'",
336 name
, value
, line
, fname
);
347 if (hwaddr_aton(token
, addr
)) {
348 wpa_printf(MSG_ERROR
, "Invalid MAC address '%s' on "
349 "line %d in '%s'", token
, line
, fname
);
354 psk
= os_zalloc(sizeof(*psk
));
356 wpa_printf(MSG_ERROR
, "WPA PSK allocation failed");
360 psk
->vlan_id
= vlan_id
;
361 if (is_zero_ether_addr(addr
))
364 os_memcpy(psk
->addr
, addr
, ETH_ALEN
);
366 pos
= str_token(buf
, "", &context
);
368 wpa_printf(MSG_ERROR
, "No PSK on line %d in '%s'",
376 len
= os_strlen(pos
);
377 if (len
== 64 && hexstr2bin(pos
, psk
->psk
, PMK_LEN
) == 0)
379 else if (len
>= 8 && len
< 64) {
380 pbkdf2_sha1(pos
, ssid
->ssid
, ssid
->ssid_len
,
381 4096, psk
->psk
, PMK_LEN
);
385 wpa_printf(MSG_ERROR
, "Invalid PSK '%s' on line %d in "
386 "'%s'", pos
, line
, fname
);
393 len
= os_strlcpy(psk
->keyid
, keyid
, sizeof(psk
->keyid
));
394 if ((size_t) len
>= sizeof(psk
->keyid
)) {
395 wpa_printf(MSG_ERROR
,
396 "PSK keyid too long on line %d in '%s'",
404 psk
->next
= ssid
->wpa_psk
;
414 static int hostapd_derive_psk(struct hostapd_ssid
*ssid
)
416 ssid
->wpa_psk
= os_zalloc(sizeof(struct hostapd_wpa_psk
));
417 if (ssid
->wpa_psk
== NULL
) {
418 wpa_printf(MSG_ERROR
, "Unable to alloc space for PSK");
421 wpa_hexdump_ascii(MSG_DEBUG
, "SSID",
422 (u8
*) ssid
->ssid
, ssid
->ssid_len
);
423 wpa_hexdump_ascii_key(MSG_DEBUG
, "PSK (ASCII passphrase)",
424 (u8
*) ssid
->wpa_passphrase
,
425 os_strlen(ssid
->wpa_passphrase
));
426 pbkdf2_sha1(ssid
->wpa_passphrase
,
427 ssid
->ssid
, ssid
->ssid_len
,
428 4096, ssid
->wpa_psk
->psk
, PMK_LEN
);
429 wpa_hexdump_key(MSG_DEBUG
, "PSK (from passphrase)",
430 ssid
->wpa_psk
->psk
, PMK_LEN
);
435 int hostapd_setup_wpa_psk(struct hostapd_bss_config
*conf
)
437 struct hostapd_ssid
*ssid
= &conf
->ssid
;
439 if (ssid
->wpa_passphrase
!= NULL
) {
440 if (ssid
->wpa_psk
!= NULL
) {
441 wpa_printf(MSG_DEBUG
, "Using pre-configured WPA PSK "
442 "instead of passphrase");
444 wpa_printf(MSG_DEBUG
, "Deriving WPA PSK based on "
446 if (hostapd_derive_psk(ssid
) < 0)
449 ssid
->wpa_psk
->group
= 1;
452 return hostapd_config_read_wpa_psk(ssid
->wpa_psk_file
, &conf
->ssid
);
456 static void hostapd_config_free_radius(struct hostapd_radius_server
*servers
,
461 for (i
= 0; i
< num_servers
; i
++) {
462 os_free(servers
[i
].shared_secret
);
468 struct hostapd_radius_attr
*
469 hostapd_config_get_radius_attr(struct hostapd_radius_attr
*attr
, u8 type
)
471 for (; attr
; attr
= attr
->next
) {
472 if (attr
->type
== type
)
479 struct hostapd_radius_attr
* hostapd_parse_radius_attr(const char *value
)
483 struct hostapd_radius_attr
*attr
;
486 attr
= os_zalloc(sizeof(*attr
));
490 attr
->type
= atoi(value
);
492 pos
= os_strchr(value
, ':');
494 attr
->val
= wpabuf_alloc(1);
499 wpabuf_put_u8(attr
->val
, 0);
504 if (pos
[0] == '\0' || pos
[1] != ':') {
513 attr
->val
= wpabuf_alloc_copy(pos
, os_strlen(pos
));
516 len
= os_strlen(pos
);
520 attr
->val
= wpabuf_alloc(len
);
523 if (hexstr2bin(pos
, wpabuf_put(attr
->val
, len
), len
) < 0) {
524 wpabuf_free(attr
->val
);
530 attr
->val
= wpabuf_alloc(4);
532 wpabuf_put_be32(attr
->val
, atoi(pos
));
548 static void hostapd_config_free_radius_attr(struct hostapd_radius_attr
*attr
)
550 struct hostapd_radius_attr
*prev
;
555 wpabuf_free(prev
->val
);
561 void hostapd_config_free_eap_user(struct hostapd_eap_user
*user
)
563 hostapd_config_free_radius_attr(user
->accept_attr
);
564 os_free(user
->identity
);
565 bin_clear_free(user
->password
, user
->password_len
);
566 bin_clear_free(user
->salt
, user
->salt_len
);
571 void hostapd_config_free_eap_users(struct hostapd_eap_user
*user
)
573 struct hostapd_eap_user
*prev_user
;
578 hostapd_config_free_eap_user(prev_user
);
583 static void hostapd_config_free_wep(struct hostapd_wep_keys
*keys
)
586 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
587 bin_clear_free(keys
->key
[i
], keys
->len
[i
]);
593 void hostapd_config_clear_wpa_psk(struct hostapd_wpa_psk
**l
)
595 struct hostapd_wpa_psk
*psk
, *tmp
;
597 for (psk
= *l
; psk
;) {
600 bin_clear_free(tmp
, sizeof(*tmp
));
606 static void hostapd_config_free_anqp_elem(struct hostapd_bss_config
*conf
)
608 struct anqp_element
*elem
;
610 while ((elem
= dl_list_first(&conf
->anqp_elem
, struct anqp_element
,
612 dl_list_del(&elem
->list
);
613 wpabuf_free(elem
->payload
);
619 static void hostapd_config_free_fils_realms(struct hostapd_bss_config
*conf
)
622 struct fils_realm
*realm
;
624 while ((realm
= dl_list_first(&conf
->fils_realms
, struct fils_realm
,
626 dl_list_del(&realm
->list
);
629 #endif /* CONFIG_FILS */
633 static void hostapd_config_free_sae_passwords(struct hostapd_bss_config
*conf
)
635 struct sae_password_entry
*pw
, *tmp
;
637 pw
= conf
->sae_passwords
;
638 conf
->sae_passwords
= NULL
;
642 str_clear_free(tmp
->password
);
643 os_free(tmp
->identifier
);
650 static void hostapd_dpp_controller_conf_free(struct dpp_controller_conf
*conf
)
652 struct dpp_controller_conf
*prev
;
660 #endif /* CONFIG_DPP2 */
663 void hostapd_config_free_bss(struct hostapd_bss_config
*conf
)
665 #if defined(CONFIG_WPS) || defined(CONFIG_HS20)
672 hostapd_config_clear_wpa_psk(&conf
->ssid
.wpa_psk
);
674 str_clear_free(conf
->ssid
.wpa_passphrase
);
675 os_free(conf
->ssid
.wpa_psk_file
);
676 hostapd_config_free_wep(&conf
->ssid
.wep
);
677 #ifdef CONFIG_FULL_DYNAMIC_VLAN
678 os_free(conf
->ssid
.vlan_tagged_interface
);
679 #endif /* CONFIG_FULL_DYNAMIC_VLAN */
681 hostapd_config_free_eap_users(conf
->eap_user
);
682 os_free(conf
->eap_user_sqlite
);
684 os_free(conf
->eap_req_id_text
);
685 os_free(conf
->erp_domain
);
686 os_free(conf
->accept_mac
);
687 os_free(conf
->deny_mac
);
688 os_free(conf
->nas_identifier
);
690 hostapd_config_free_radius(conf
->radius
->auth_servers
,
691 conf
->radius
->num_auth_servers
);
692 hostapd_config_free_radius(conf
->radius
->acct_servers
,
693 conf
->radius
->num_acct_servers
);
695 hostapd_config_free_radius_attr(conf
->radius_auth_req_attr
);
696 hostapd_config_free_radius_attr(conf
->radius_acct_req_attr
);
697 os_free(conf
->rsn_preauth_interfaces
);
698 os_free(conf
->ctrl_interface
);
699 os_free(conf
->ca_cert
);
700 os_free(conf
->server_cert
);
701 os_free(conf
->server_cert2
);
702 os_free(conf
->private_key
);
703 os_free(conf
->private_key2
);
704 os_free(conf
->private_key_passwd
);
705 os_free(conf
->private_key_passwd2
);
706 os_free(conf
->check_cert_subject
);
707 os_free(conf
->ocsp_stapling_response
);
708 os_free(conf
->ocsp_stapling_response_multi
);
709 os_free(conf
->dh_file
);
710 os_free(conf
->openssl_ciphers
);
711 os_free(conf
->openssl_ecdh_curves
);
712 os_free(conf
->pac_opaque_encr_key
);
713 os_free(conf
->eap_fast_a_id
);
714 os_free(conf
->eap_fast_a_id_info
);
715 os_free(conf
->eap_sim_db
);
716 os_free(conf
->radius_server_clients
);
717 os_free(conf
->radius
);
718 os_free(conf
->radius_das_shared_secret
);
719 hostapd_config_free_vlan(conf
);
720 os_free(conf
->time_zone
);
722 #ifdef CONFIG_IEEE80211R_AP
724 struct ft_remote_r0kh
*r0kh
, *r0kh_prev
;
725 struct ft_remote_r1kh
*r1kh
, *r1kh_prev
;
727 r0kh
= conf
->r0kh_list
;
728 conf
->r0kh_list
= NULL
;
735 r1kh
= conf
->r1kh_list
;
736 conf
->r1kh_list
= NULL
;
743 #endif /* CONFIG_IEEE80211R_AP */
746 os_free(conf
->wps_pin_requests
);
747 os_free(conf
->device_name
);
748 os_free(conf
->manufacturer
);
749 os_free(conf
->model_name
);
750 os_free(conf
->model_number
);
751 os_free(conf
->serial_number
);
752 os_free(conf
->config_methods
);
753 os_free(conf
->ap_pin
);
754 os_free(conf
->extra_cred
);
755 os_free(conf
->ap_settings
);
756 hostapd_config_clear_wpa_psk(&conf
->multi_ap_backhaul_ssid
.wpa_psk
);
757 str_clear_free(conf
->multi_ap_backhaul_ssid
.wpa_passphrase
);
758 os_free(conf
->upnp_iface
);
759 os_free(conf
->friendly_name
);
760 os_free(conf
->manufacturer_url
);
761 os_free(conf
->model_description
);
762 os_free(conf
->model_url
);
764 for (i
= 0; i
< MAX_WPS_VENDOR_EXTENSIONS
; i
++)
765 wpabuf_free(conf
->wps_vendor_ext
[i
]);
766 wpabuf_free(conf
->wps_nfc_dh_pubkey
);
767 wpabuf_free(conf
->wps_nfc_dh_privkey
);
768 wpabuf_free(conf
->wps_nfc_dev_pw
);
769 #endif /* CONFIG_WPS */
771 os_free(conf
->roaming_consortium
);
772 os_free(conf
->venue_name
);
773 os_free(conf
->venue_url
);
774 os_free(conf
->nai_realm_data
);
775 os_free(conf
->network_auth_type
);
776 os_free(conf
->anqp_3gpp_cell_net
);
777 os_free(conf
->domain_name
);
778 hostapd_config_free_anqp_elem(conf
);
780 #ifdef CONFIG_RADIUS_TEST
781 os_free(conf
->dump_msk_file
);
782 #endif /* CONFIG_RADIUS_TEST */
785 os_free(conf
->hs20_oper_friendly_name
);
786 os_free(conf
->hs20_wan_metrics
);
787 os_free(conf
->hs20_connection_capability
);
788 os_free(conf
->hs20_operating_class
);
789 os_free(conf
->hs20_icons
);
790 if (conf
->hs20_osu_providers
) {
791 for (i
= 0; i
< conf
->hs20_osu_providers_count
; i
++) {
792 struct hs20_osu_provider
*p
;
794 p
= &conf
->hs20_osu_providers
[i
];
795 os_free(p
->friendly_name
);
796 os_free(p
->server_uri
);
797 os_free(p
->method_list
);
798 for (j
= 0; j
< p
->icons_count
; j
++)
799 os_free(p
->icons
[j
]);
802 os_free(p
->osu_nai2
);
803 os_free(p
->service_desc
);
805 os_free(conf
->hs20_osu_providers
);
807 if (conf
->hs20_operator_icon
) {
808 for (i
= 0; i
< conf
->hs20_operator_icon_count
; i
++)
809 os_free(conf
->hs20_operator_icon
[i
]);
810 os_free(conf
->hs20_operator_icon
);
812 os_free(conf
->subscr_remediation_url
);
813 os_free(conf
->hs20_sim_provisioning_url
);
814 os_free(conf
->t_c_filename
);
815 os_free(conf
->t_c_server_url
);
816 #endif /* CONFIG_HS20 */
818 wpabuf_free(conf
->vendor_elements
);
819 wpabuf_free(conf
->assocresp_elements
);
821 os_free(conf
->sae_groups
);
823 os_free(conf
->owe_groups
);
824 #endif /* CONFIG_OWE */
826 os_free(conf
->wowlan_triggers
);
828 os_free(conf
->server_id
);
830 #ifdef CONFIG_TESTING_OPTIONS
831 wpabuf_free(conf
->own_ie_override
);
832 wpabuf_free(conf
->sae_commit_override
);
833 #endif /* CONFIG_TESTING_OPTIONS */
835 os_free(conf
->no_probe_resp_if_seen_on
);
836 os_free(conf
->no_auth_if_seen_on
);
838 hostapd_config_free_fils_realms(conf
);
841 os_free(conf
->dpp_connector
);
842 wpabuf_free(conf
->dpp_netaccesskey
);
843 wpabuf_free(conf
->dpp_csign
);
845 hostapd_dpp_controller_conf_free(conf
->dpp_controller
);
846 #endif /* CONFIG_DPP2 */
847 #endif /* CONFIG_DPP */
849 hostapd_config_free_sae_passwords(conf
);
851 #ifdef CONFIG_AIRTIME_POLICY
853 struct airtime_sta_weight
*wt
, *wt_prev
;
855 wt
= conf
->airtime_weight_list
;
856 conf
->airtime_weight_list
= NULL
;
863 #endif /* CONFIG_AIRTIME_POLICY */
870 * hostapd_config_free - Free hostapd configuration
871 * @conf: Configuration data from hostapd_config_read().
873 void hostapd_config_free(struct hostapd_config
*conf
)
880 for (i
= 0; i
< conf
->num_bss
; i
++)
881 hostapd_config_free_bss(conf
->bss
[i
]);
883 os_free(conf
->supported_rates
);
884 os_free(conf
->basic_rates
);
885 os_free(conf
->acs_ch_list
.range
);
886 os_free(conf
->driver_params
);
888 os_free(conf
->acs_chan_bias
);
889 #endif /* CONFIG_ACS */
890 wpabuf_free(conf
->lci
);
891 wpabuf_free(conf
->civic
);
898 * hostapd_maclist_found - Find a MAC address from a list
899 * @list: MAC address list
900 * @num_entries: Number of addresses in the list
901 * @addr: Address to search for
902 * @vlan_id: Buffer for returning VLAN ID or %NULL if not needed
903 * Returns: 1 if address is in the list or 0 if not.
905 * Perform a binary search for given MAC address from a pre-sorted list.
907 int hostapd_maclist_found(struct mac_acl_entry
*list
, int num_entries
,
908 const u8
*addr
, struct vlan_description
*vlan_id
)
910 int start
, end
, middle
, res
;
913 end
= num_entries
- 1;
915 while (start
<= end
) {
916 middle
= (start
+ end
) / 2;
917 res
= os_memcmp(list
[middle
].addr
, addr
, ETH_ALEN
);
920 *vlan_id
= list
[middle
].vlan_id
;
933 int hostapd_rate_found(int *list
, int rate
)
940 for (i
= 0; list
[i
] >= 0; i
++)
948 int hostapd_vlan_valid(struct hostapd_vlan
*vlan
,
949 struct vlan_description
*vlan_desc
)
951 struct hostapd_vlan
*v
= vlan
;
954 if (!vlan_desc
->notempty
|| vlan_desc
->untagged
< 0 ||
955 vlan_desc
->untagged
> MAX_VLAN_ID
)
957 for (i
= 0; i
< MAX_NUM_TAGGED_VLAN
; i
++) {
958 if (vlan_desc
->tagged
[i
] < 0 ||
959 vlan_desc
->tagged
[i
] > MAX_VLAN_ID
)
962 if (!vlan_desc
->untagged
&& !vlan_desc
->tagged
[0])
966 if (!vlan_compare(&v
->vlan_desc
, vlan_desc
) ||
967 v
->vlan_id
== VLAN_ID_WILDCARD
)
975 const char * hostapd_get_vlan_id_ifname(struct hostapd_vlan
*vlan
, int vlan_id
)
977 struct hostapd_vlan
*v
= vlan
;
979 if (v
->vlan_id
== vlan_id
)
987 const u8
* hostapd_get_psk(const struct hostapd_bss_config
*conf
,
988 const u8
*addr
, const u8
*p2p_dev_addr
,
989 const u8
*prev_psk
, int *vlan_id
)
991 struct hostapd_wpa_psk
*psk
;
992 int next_ok
= prev_psk
== NULL
;
997 if (p2p_dev_addr
&& !is_zero_ether_addr(p2p_dev_addr
)) {
998 wpa_printf(MSG_DEBUG
, "Searching a PSK for " MACSTR
999 " p2p_dev_addr=" MACSTR
" prev_psk=%p",
1000 MAC2STR(addr
), MAC2STR(p2p_dev_addr
), prev_psk
);
1001 addr
= NULL
; /* Use P2P Device Address for matching */
1003 wpa_printf(MSG_DEBUG
, "Searching a PSK for " MACSTR
1005 MAC2STR(addr
), prev_psk
);
1008 for (psk
= conf
->ssid
.wpa_psk
; psk
!= NULL
; psk
= psk
->next
) {
1011 (addr
&& os_memcmp(psk
->addr
, addr
, ETH_ALEN
) == 0) ||
1012 (!addr
&& p2p_dev_addr
&&
1013 os_memcmp(psk
->p2p_dev_addr
, p2p_dev_addr
, ETH_ALEN
) ==
1016 *vlan_id
= psk
->vlan_id
;
1020 if (psk
->psk
== prev_psk
)
1028 static int hostapd_config_check_bss(struct hostapd_bss_config
*bss
,
1029 struct hostapd_config
*conf
,
1032 if (full_config
&& bss
->ieee802_1x
&& !bss
->eap_server
&&
1033 !bss
->radius
->auth_servers
) {
1034 wpa_printf(MSG_ERROR
, "Invalid IEEE 802.1X configuration (no "
1035 "EAP authenticator configured).");
1042 wep
= bss
->default_wep_key_len
> 0 ||
1043 bss
->individual_wep_key_len
> 0;
1044 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
1045 if (bss
->ssid
.wep
.keys_set
) {
1052 wpa_printf(MSG_ERROR
, "WEP configuration in a WPA network is not supported");
1057 if (full_config
&& bss
->wpa
&&
1058 bss
->wpa_psk_radius
!= PSK_RADIUS_IGNORED
&&
1059 bss
->macaddr_acl
!= USE_EXTERNAL_RADIUS_AUTH
) {
1060 wpa_printf(MSG_ERROR
, "WPA-PSK using RADIUS enabled, but no "
1061 "RADIUS checking (macaddr_acl=2) enabled.");
1065 if (full_config
&& bss
->wpa
&& (bss
->wpa_key_mgmt
& WPA_KEY_MGMT_PSK
) &&
1066 bss
->ssid
.wpa_psk
== NULL
&& bss
->ssid
.wpa_passphrase
== NULL
&&
1067 bss
->ssid
.wpa_psk_file
== NULL
&&
1068 (bss
->wpa_psk_radius
!= PSK_RADIUS_REQUIRED
||
1069 bss
->macaddr_acl
!= USE_EXTERNAL_RADIUS_AUTH
)) {
1070 wpa_printf(MSG_ERROR
, "WPA-PSK enabled, but PSK or passphrase "
1071 "is not configured.");
1075 if (full_config
&& !is_zero_ether_addr(bss
->bssid
)) {
1078 for (i
= 0; i
< conf
->num_bss
; i
++) {
1079 if (conf
->bss
[i
] != bss
&&
1080 (hostapd_mac_comp(conf
->bss
[i
]->bssid
,
1081 bss
->bssid
) == 0)) {
1082 wpa_printf(MSG_ERROR
, "Duplicate BSSID " MACSTR
1083 " on interface '%s' and '%s'.",
1084 MAC2STR(bss
->bssid
),
1085 conf
->bss
[i
]->iface
, bss
->iface
);
1091 #ifdef CONFIG_IEEE80211R_AP
1092 if (full_config
&& wpa_key_mgmt_ft(bss
->wpa_key_mgmt
) &&
1093 (bss
->nas_identifier
== NULL
||
1094 os_strlen(bss
->nas_identifier
) < 1 ||
1095 os_strlen(bss
->nas_identifier
) > FT_R0KH_ID_MAX_LEN
)) {
1096 wpa_printf(MSG_ERROR
, "FT (IEEE 802.11r) requires "
1097 "nas_identifier to be configured as a 1..48 octet "
1101 #endif /* CONFIG_IEEE80211R_AP */
1103 #ifdef CONFIG_IEEE80211N
1104 if (full_config
&& conf
->ieee80211n
&&
1105 conf
->hw_mode
== HOSTAPD_MODE_IEEE80211B
) {
1106 bss
->disable_11n
= 1;
1107 wpa_printf(MSG_ERROR
, "HT (IEEE 802.11n) in 11b mode is not "
1108 "allowed, disabling HT capabilities");
1111 if (full_config
&& conf
->ieee80211n
&&
1112 bss
->ssid
.security_policy
== SECURITY_STATIC_WEP
) {
1113 bss
->disable_11n
= 1;
1114 wpa_printf(MSG_ERROR
, "HT (IEEE 802.11n) with WEP is not "
1115 "allowed, disabling HT capabilities");
1118 if (full_config
&& conf
->ieee80211n
&& bss
->wpa
&&
1119 !(bss
->wpa_pairwise
& WPA_CIPHER_CCMP
) &&
1120 !(bss
->rsn_pairwise
& (WPA_CIPHER_CCMP
| WPA_CIPHER_GCMP
|
1121 WPA_CIPHER_CCMP_256
| WPA_CIPHER_GCMP_256
)))
1123 bss
->disable_11n
= 1;
1124 wpa_printf(MSG_ERROR
, "HT (IEEE 802.11n) with WPA/WPA2 "
1125 "requires CCMP/GCMP to be enabled, disabling HT "
1128 #endif /* CONFIG_IEEE80211N */
1130 #ifdef CONFIG_IEEE80211AC
1131 if (full_config
&& conf
->ieee80211ac
&&
1132 bss
->ssid
.security_policy
== SECURITY_STATIC_WEP
) {
1133 bss
->disable_11ac
= 1;
1134 wpa_printf(MSG_ERROR
,
1135 "VHT (IEEE 802.11ac) with WEP is not allowed, disabling VHT capabilities");
1138 if (full_config
&& conf
->ieee80211ac
&& bss
->wpa
&&
1139 !(bss
->wpa_pairwise
& WPA_CIPHER_CCMP
) &&
1140 !(bss
->rsn_pairwise
& (WPA_CIPHER_CCMP
| WPA_CIPHER_GCMP
|
1141 WPA_CIPHER_CCMP_256
| WPA_CIPHER_GCMP_256
)))
1143 bss
->disable_11ac
= 1;
1144 wpa_printf(MSG_ERROR
,
1145 "VHT (IEEE 802.11ac) with WPA/WPA2 requires CCMP/GCMP to be enabled, disabling VHT capabilities");
1147 #endif /* CONFIG_IEEE80211AC */
1150 if (full_config
&& bss
->wps_state
&& bss
->ignore_broadcast_ssid
) {
1151 wpa_printf(MSG_INFO
, "WPS: ignore_broadcast_ssid "
1152 "configuration forced WPS to be disabled");
1156 if (full_config
&& bss
->wps_state
&&
1157 bss
->ssid
.wep
.keys_set
&& bss
->wpa
== 0) {
1158 wpa_printf(MSG_INFO
, "WPS: WEP configuration forced WPS to be "
1163 if (full_config
&& bss
->wps_state
&& bss
->wpa
&&
1165 !(bss
->rsn_pairwise
& (WPA_CIPHER_CCMP
| WPA_CIPHER_GCMP
|
1166 WPA_CIPHER_CCMP_256
|
1167 WPA_CIPHER_GCMP_256
)))) {
1168 wpa_printf(MSG_INFO
, "WPS: WPA/TKIP configuration without "
1169 "WPA2/CCMP/GCMP forced WPS to be disabled");
1172 #endif /* CONFIG_WPS */
1175 if (full_config
&& bss
->hs20
&&
1177 !(bss
->rsn_pairwise
& (WPA_CIPHER_CCMP
| WPA_CIPHER_GCMP
|
1178 WPA_CIPHER_CCMP_256
|
1179 WPA_CIPHER_GCMP_256
)))) {
1180 wpa_printf(MSG_ERROR
, "HS 2.0: WPA2-Enterprise/CCMP "
1181 "configuration is required for Hotspot 2.0 "
1185 #endif /* CONFIG_HS20 */
1188 if (full_config
&& bss
->mbo_enabled
&& (bss
->wpa
& 2) &&
1189 bss
->ieee80211w
== NO_MGMT_FRAME_PROTECTION
) {
1190 wpa_printf(MSG_ERROR
,
1191 "MBO: PMF needs to be enabled whenever using WPA2 with MBO");
1194 #endif /* CONFIG_MBO */
1197 if (full_config
&& bss
->ieee80211w
== NO_MGMT_FRAME_PROTECTION
&&
1199 wpa_printf(MSG_ERROR
,
1200 "OCV: PMF needs to be enabled whenever using OCV");
1203 #endif /* CONFIG_OCV */
1209 static int hostapd_config_check_cw(struct hostapd_config
*conf
, int queue
)
1211 int tx_cwmin
= conf
->tx_queue
[queue
].cwmin
;
1212 int tx_cwmax
= conf
->tx_queue
[queue
].cwmax
;
1213 int ac_cwmin
= conf
->wmm_ac_params
[queue
].cwmin
;
1214 int ac_cwmax
= conf
->wmm_ac_params
[queue
].cwmax
;
1216 if (tx_cwmin
> tx_cwmax
) {
1217 wpa_printf(MSG_ERROR
,
1218 "Invalid TX queue cwMin/cwMax values. cwMin(%d) greater than cwMax(%d)",
1219 tx_cwmin
, tx_cwmax
);
1222 if (ac_cwmin
> ac_cwmax
) {
1223 wpa_printf(MSG_ERROR
,
1224 "Invalid WMM AC cwMin/cwMax values. cwMin(%d) greater than cwMax(%d)",
1225 ac_cwmin
, ac_cwmax
);
1232 int hostapd_config_check(struct hostapd_config
*conf
, int full_config
)
1236 if (full_config
&& conf
->ieee80211d
&&
1237 (!conf
->country
[0] || !conf
->country
[1])) {
1238 wpa_printf(MSG_ERROR
, "Cannot enable IEEE 802.11d without "
1239 "setting the country_code");
1243 if (full_config
&& conf
->ieee80211h
&& !conf
->ieee80211d
) {
1244 wpa_printf(MSG_ERROR
, "Cannot enable IEEE 802.11h without "
1245 "IEEE 802.11d enabled");
1249 if (full_config
&& conf
->local_pwr_constraint
!= -1 &&
1250 !conf
->ieee80211d
) {
1251 wpa_printf(MSG_ERROR
, "Cannot add Power Constraint element without Country element");
1255 if (full_config
&& conf
->spectrum_mgmt_required
&&
1256 conf
->local_pwr_constraint
== -1) {
1257 wpa_printf(MSG_ERROR
, "Cannot set Spectrum Management bit without Country and Power Constraint elements");
1261 #ifdef CONFIG_AIRTIME_POLICY
1262 if (full_config
&& conf
->airtime_mode
> AIRTIME_MODE_STATIC
&&
1263 !conf
->airtime_update_interval
) {
1264 wpa_printf(MSG_ERROR
, "Airtime update interval cannot be zero");
1267 #endif /* CONFIG_AIRTIME_POLICY */
1268 for (i
= 0; i
< NUM_TX_QUEUES
; i
++) {
1269 if (hostapd_config_check_cw(conf
, i
))
1273 for (i
= 0; i
< conf
->num_bss
; i
++) {
1274 if (hostapd_config_check_bss(conf
->bss
[i
], conf
, full_config
))
1282 void hostapd_set_security_params(struct hostapd_bss_config
*bss
,
1285 if (bss
->individual_wep_key_len
== 0) {
1286 /* individual keys are not use; can use key idx0 for
1288 bss
->broadcast_key_idx_min
= 0;
1291 if ((bss
->wpa
& 2) && bss
->rsn_pairwise
== 0)
1292 bss
->rsn_pairwise
= bss
->wpa_pairwise
;
1293 if (bss
->group_cipher
)
1294 bss
->wpa_group
= bss
->group_cipher
;
1296 bss
->wpa_group
= wpa_select_ap_group_cipher(bss
->wpa
,
1299 if (!bss
->wpa_group_rekey_set
)
1300 bss
->wpa_group_rekey
= bss
->wpa_group
== WPA_CIPHER_TKIP
?
1304 bss
->radius
->auth_server
= bss
->radius
->auth_servers
;
1305 bss
->radius
->acct_server
= bss
->radius
->acct_servers
;
1308 if (bss
->wpa
&& bss
->ieee802_1x
) {
1309 bss
->ssid
.security_policy
= SECURITY_WPA
;
1310 } else if (bss
->wpa
) {
1311 bss
->ssid
.security_policy
= SECURITY_WPA_PSK
;
1312 } else if (bss
->ieee802_1x
) {
1313 int cipher
= WPA_CIPHER_NONE
;
1314 bss
->ssid
.security_policy
= SECURITY_IEEE_802_1X
;
1315 bss
->ssid
.wep
.default_len
= bss
->default_wep_key_len
;
1316 if (full_config
&& bss
->default_wep_key_len
) {
1317 cipher
= bss
->default_wep_key_len
>= 13 ?
1318 WPA_CIPHER_WEP104
: WPA_CIPHER_WEP40
;
1319 } else if (full_config
&& bss
->ssid
.wep
.keys_set
) {
1320 if (bss
->ssid
.wep
.len
[0] >= 13)
1321 cipher
= WPA_CIPHER_WEP104
;
1323 cipher
= WPA_CIPHER_WEP40
;
1325 bss
->wpa_group
= cipher
;
1326 bss
->wpa_pairwise
= cipher
;
1327 bss
->rsn_pairwise
= cipher
;
1329 bss
->wpa_key_mgmt
= WPA_KEY_MGMT_IEEE8021X_NO_WPA
;
1330 } else if (bss
->ssid
.wep
.keys_set
) {
1331 int cipher
= WPA_CIPHER_WEP40
;
1332 if (bss
->ssid
.wep
.len
[0] >= 13)
1333 cipher
= WPA_CIPHER_WEP104
;
1334 bss
->ssid
.security_policy
= SECURITY_STATIC_WEP
;
1335 bss
->wpa_group
= cipher
;
1336 bss
->wpa_pairwise
= cipher
;
1337 bss
->rsn_pairwise
= cipher
;
1339 bss
->wpa_key_mgmt
= WPA_KEY_MGMT_NONE
;
1340 } else if (bss
->osen
) {
1341 bss
->ssid
.security_policy
= SECURITY_OSEN
;
1342 bss
->wpa_group
= WPA_CIPHER_CCMP
;
1343 bss
->wpa_pairwise
= 0;
1344 bss
->rsn_pairwise
= WPA_CIPHER_CCMP
;
1346 bss
->ssid
.security_policy
= SECURITY_PLAINTEXT
;
1348 bss
->wpa_group
= WPA_CIPHER_NONE
;
1349 bss
->wpa_pairwise
= WPA_CIPHER_NONE
;
1350 bss
->rsn_pairwise
= WPA_CIPHER_NONE
;
1351 bss
->wpa_key_mgmt
= WPA_KEY_MGMT_NONE
;
1357 int hostapd_sae_pw_id_in_use(struct hostapd_bss_config
*conf
)
1359 int with_id
= 0, without_id
= 0;
1360 struct sae_password_entry
*pw
;
1362 if (conf
->ssid
.wpa_passphrase
)
1365 for (pw
= conf
->sae_passwords
; pw
; pw
= pw
->next
) {
1370 if (with_id
&& without_id
)
1374 if (with_id
&& !without_id
)