2 * hostapd / Configuration helper functions
3 * Copyright (c) 2003-2014, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
9 #include "utils/includes.h"
11 #include "utils/common.h"
12 #include "crypto/sha1.h"
13 #include "crypto/tls.h"
14 #include "radius/radius_client.h"
15 #include "common/ieee802_11_defs.h"
16 #include "common/eapol_common.h"
17 #include "common/dhcp.h"
18 #include "eap_common/eap_wsc_common.h"
19 #include "eap_server/eap.h"
22 #include "airtime_policy.h"
23 #include "ap_config.h"
26 static void hostapd_config_free_vlan(struct hostapd_bss_config
*bss
)
28 struct hostapd_vlan
*vlan
, *prev
;
42 #ifndef DEFAULT_WPA_DISABLE_EAPOL_KEY_RETRIES
43 #define DEFAULT_WPA_DISABLE_EAPOL_KEY_RETRIES 0
44 #endif /* DEFAULT_WPA_DISABLE_EAPOL_KEY_RETRIES */
46 void hostapd_config_defaults_bss(struct hostapd_bss_config
*bss
)
48 dl_list_init(&bss
->anqp_elem
);
50 bss
->logger_syslog_level
= HOSTAPD_LEVEL_INFO
;
51 bss
->logger_stdout_level
= HOSTAPD_LEVEL_INFO
;
52 bss
->logger_syslog
= (unsigned int) -1;
53 bss
->logger_stdout
= (unsigned int) -1;
55 bss
->auth_algs
= WPA_AUTH_ALG_OPEN
| WPA_AUTH_ALG_SHARED
;
57 bss
->wep_rekeying_period
= 300;
58 /* use key0 in individual key and key1 in broadcast key */
59 bss
->broadcast_key_idx_min
= 1;
60 bss
->broadcast_key_idx_max
= 2;
61 bss
->eap_reauth_period
= 3600;
63 bss
->wpa_group_rekey
= 600;
64 bss
->wpa_gmk_rekey
= 86400;
65 bss
->wpa_group_update_count
= 4;
66 bss
->wpa_pairwise_update_count
= 4;
67 bss
->wpa_disable_eapol_key_retries
=
68 DEFAULT_WPA_DISABLE_EAPOL_KEY_RETRIES
;
69 bss
->wpa_key_mgmt
= WPA_KEY_MGMT_PSK
;
70 bss
->wpa_pairwise
= WPA_CIPHER_TKIP
;
71 bss
->wpa_group
= WPA_CIPHER_TKIP
;
72 bss
->rsn_pairwise
= 0;
74 bss
->max_num_sta
= MAX_STA_COUNT
;
78 bss
->radius_server_auth_port
= 1812;
79 bss
->eap_sim_db_timeout
= 1;
80 bss
->ap_max_inactivity
= AP_MAX_INACTIVITY
;
81 bss
->eapol_version
= EAPOL_VERSION
;
83 bss
->max_listen_interval
= 65535;
85 bss
->pwd_group
= 19; /* ECC: GF(p=256) */
87 #ifdef CONFIG_IEEE80211W
88 bss
->assoc_sa_query_max_timeout
= 1000;
89 bss
->assoc_sa_query_retry_timeout
= 201;
90 bss
->group_mgmt_cipher
= WPA_CIPHER_AES_128_CMAC
;
91 #endif /* CONFIG_IEEE80211W */
92 #ifdef EAP_SERVER_FAST
93 /* both anonymous and authenticated provisioning */
94 bss
->eap_fast_prov
= 3;
95 bss
->pac_key_lifetime
= 7 * 24 * 60 * 60;
96 bss
->pac_key_refresh_time
= 1 * 24 * 60 * 60;
97 #endif /* EAP_SERVER_FAST */
99 /* Set to -1 as defaults depends on HT in setup */
100 bss
->wmm_enabled
= -1;
102 #ifdef CONFIG_IEEE80211R_AP
104 bss
->rkh_pos_timeout
= 86400;
105 bss
->rkh_neg_timeout
= 60;
106 bss
->rkh_pull_timeout
= 1000;
107 bss
->rkh_pull_retries
= 4;
108 bss
->r0_key_lifetime
= 1209600;
109 #endif /* CONFIG_IEEE80211R_AP */
111 bss
->radius_das_time_window
= 300;
113 bss
->sae_anti_clogging_threshold
= 5;
116 bss
->gas_frag_limit
= 1400;
119 dl_list_init(&bss
->fils_realms
);
120 bss
->fils_hlp_wait_time
= 30;
121 bss
->dhcp_server_port
= DHCP_SERVER_PORT
;
122 bss
->dhcp_relay_port
= DHCP_SERVER_PORT
;
123 #endif /* CONFIG_FILS */
125 bss
->broadcast_deauth
= 1;
128 bss
->mbo_cell_data_conn_pref
= -1;
129 #endif /* CONFIG_MBO */
131 /* Disable TLS v1.3 by default for now to avoid interoperability issue.
132 * This can be enabled by default once the implementation has been fully
133 * completed and tested with other implementations. */
134 bss
->tls_flags
= TLS_CONN_DISABLE_TLSv1_3
;
136 bss
->send_probe_response
= 1;
139 bss
->hs20_release
= (HS20_VERSION
>> 4) + 1;
140 #endif /* CONFIG_HS20 */
142 /* Default to strict CRL checking. */
143 bss
->check_crl_strict
= 1;
147 struct hostapd_config
* hostapd_config_defaults(void)
149 #define ecw2cw(ecw) ((1 << (ecw)) - 1)
151 struct hostapd_config
*conf
;
152 struct hostapd_bss_config
*bss
;
153 const int aCWmin
= 4, aCWmax
= 10;
154 const struct hostapd_wmm_ac_params ac_bk
=
155 { aCWmin
, aCWmax
, 7, 0, 0 }; /* background traffic */
156 const struct hostapd_wmm_ac_params ac_be
=
157 { aCWmin
, aCWmax
, 3, 0, 0 }; /* best effort traffic */
158 const struct hostapd_wmm_ac_params ac_vi
= /* video traffic */
159 { aCWmin
- 1, aCWmin
, 2, 3008 / 32, 0 };
160 const struct hostapd_wmm_ac_params ac_vo
= /* voice traffic */
161 { aCWmin
- 2, aCWmin
- 1, 2, 1504 / 32, 0 };
162 const struct hostapd_tx_queue_params txq_bk
=
163 { 7, ecw2cw(aCWmin
), ecw2cw(aCWmax
), 0 };
164 const struct hostapd_tx_queue_params txq_be
=
165 { 3, ecw2cw(aCWmin
), 4 * (ecw2cw(aCWmin
) + 1) - 1, 0};
166 const struct hostapd_tx_queue_params txq_vi
=
167 { 1, (ecw2cw(aCWmin
) + 1) / 2 - 1, ecw2cw(aCWmin
), 30};
168 const struct hostapd_tx_queue_params txq_vo
=
169 { 1, (ecw2cw(aCWmin
) + 1) / 4 - 1,
170 (ecw2cw(aCWmin
) + 1) / 2 - 1, 15};
174 conf
= os_zalloc(sizeof(*conf
));
175 bss
= os_zalloc(sizeof(*bss
));
176 if (conf
== NULL
|| bss
== NULL
) {
177 wpa_printf(MSG_ERROR
, "Failed to allocate memory for "
178 "configuration data.");
183 conf
->bss
= os_calloc(1, sizeof(struct hostapd_bss_config
*));
184 if (conf
->bss
== NULL
) {
191 bss
->radius
= os_zalloc(sizeof(*bss
->radius
));
192 if (bss
->radius
== NULL
) {
199 hostapd_config_defaults_bss(bss
);
203 conf
->beacon_int
= 100;
204 conf
->rts_threshold
= -2; /* use driver default: 2347 */
205 conf
->fragm_threshold
= -2; /* user driver default: 2346 */
206 /* Set to invalid value means do not add Power Constraint IE */
207 conf
->local_pwr_constraint
= -1;
209 conf
->wmm_ac_params
[0] = ac_be
;
210 conf
->wmm_ac_params
[1] = ac_bk
;
211 conf
->wmm_ac_params
[2] = ac_vi
;
212 conf
->wmm_ac_params
[3] = ac_vo
;
214 conf
->tx_queue
[0] = txq_vo
;
215 conf
->tx_queue
[1] = txq_vi
;
216 conf
->tx_queue
[2] = txq_be
;
217 conf
->tx_queue
[3] = txq_bk
;
219 conf
->ht_capab
= HT_CAP_INFO_SMPS_DISABLED
;
221 conf
->ap_table_max_size
= 255;
222 conf
->ap_table_expiration_time
= 60;
223 conf
->track_sta_max_age
= 180;
225 #ifdef CONFIG_TESTING_OPTIONS
226 conf
->ignore_probe_probability
= 0.0;
227 conf
->ignore_auth_probability
= 0.0;
228 conf
->ignore_assoc_probability
= 0.0;
229 conf
->ignore_reassoc_probability
= 0.0;
230 conf
->corrupt_gtk_rekey_mic_probability
= 0.0;
231 conf
->ecsa_ie_only
= 0;
232 #endif /* CONFIG_TESTING_OPTIONS */
235 conf
->acs_ch_list
.num
= 0;
237 conf
->acs_num_scans
= 5;
238 #endif /* CONFIG_ACS */
240 #ifdef CONFIG_IEEE80211AX
241 conf
->he_op
.he_rts_threshold
= HE_OPERATION_RTS_THRESHOLD_MASK
>>
242 HE_OPERATION_RTS_THRESHOLD_OFFSET
;
243 /* Set default basic MCS/NSS set to single stream MCS 0-7 */
244 conf
->he_op
.he_basic_mcs_nss_set
= 0xfffc;
245 #endif /* CONFIG_IEEE80211AX */
247 /* The third octet of the country string uses an ASCII space character
248 * by default to indicate that the regulations encompass all
249 * environments for the current frequency band in the country. */
250 conf
->country
[2] = ' ';
252 conf
->rssi_reject_assoc_rssi
= 0;
253 conf
->rssi_reject_assoc_timeout
= 30;
255 #ifdef CONFIG_AIRTIME_POLICY
256 conf
->airtime_update_interval
= AIRTIME_DEFAULT_UPDATE_INTERVAL
;
257 #endif /* CONFIG_AIRTIME_POLICY */
263 int hostapd_mac_comp(const void *a
, const void *b
)
265 return os_memcmp(a
, b
, sizeof(macaddr
));
269 static int hostapd_config_read_wpa_psk(const char *fname
,
270 struct hostapd_ssid
*ssid
)
280 int line
= 0, ret
= 0, len
, ok
;
282 struct hostapd_wpa_psk
*psk
;
287 f
= fopen(fname
, "r");
289 wpa_printf(MSG_ERROR
, "WPA PSK file '%s' not found.", fname
);
293 while (fgets(buf
, sizeof(buf
), f
)) {
301 while (*pos
!= '\0') {
313 while ((token
= str_token(buf
, " ", &context
))) {
314 if (!os_strchr(token
, '='))
317 name
= str_token(token
, "=", &context2
);
320 value
= str_token(token
, "", &context2
);
323 if (!os_strcmp(name
, "keyid")) {
325 } else if (!os_strcmp(name
, "vlanid")) {
326 vlan_id
= atoi(value
);
328 wpa_printf(MSG_ERROR
,
329 "Unrecognized '%s=%s' on line %d in '%s'",
330 name
, value
, line
, fname
);
341 if (hwaddr_aton(token
, addr
)) {
342 wpa_printf(MSG_ERROR
, "Invalid MAC address '%s' on "
343 "line %d in '%s'", token
, line
, fname
);
348 psk
= os_zalloc(sizeof(*psk
));
350 wpa_printf(MSG_ERROR
, "WPA PSK allocation failed");
354 psk
->vlan_id
= vlan_id
;
355 if (is_zero_ether_addr(addr
))
358 os_memcpy(psk
->addr
, addr
, ETH_ALEN
);
360 pos
= str_token(buf
, "", &context
);
362 wpa_printf(MSG_ERROR
, "No PSK on line %d in '%s'",
370 len
= os_strlen(pos
);
371 if (len
== 64 && hexstr2bin(pos
, psk
->psk
, PMK_LEN
) == 0)
373 else if (len
>= 8 && len
< 64) {
374 pbkdf2_sha1(pos
, ssid
->ssid
, ssid
->ssid_len
,
375 4096, psk
->psk
, PMK_LEN
);
379 wpa_printf(MSG_ERROR
, "Invalid PSK '%s' on line %d in "
380 "'%s'", pos
, line
, fname
);
387 len
= os_strlcpy(psk
->keyid
, keyid
, sizeof(psk
->keyid
));
388 if ((size_t) len
>= sizeof(psk
->keyid
)) {
389 wpa_printf(MSG_ERROR
,
390 "PSK keyid too long on line %d in '%s'",
398 psk
->next
= ssid
->wpa_psk
;
408 static int hostapd_derive_psk(struct hostapd_ssid
*ssid
)
410 ssid
->wpa_psk
= os_zalloc(sizeof(struct hostapd_wpa_psk
));
411 if (ssid
->wpa_psk
== NULL
) {
412 wpa_printf(MSG_ERROR
, "Unable to alloc space for PSK");
415 wpa_hexdump_ascii(MSG_DEBUG
, "SSID",
416 (u8
*) ssid
->ssid
, ssid
->ssid_len
);
417 wpa_hexdump_ascii_key(MSG_DEBUG
, "PSK (ASCII passphrase)",
418 (u8
*) ssid
->wpa_passphrase
,
419 os_strlen(ssid
->wpa_passphrase
));
420 pbkdf2_sha1(ssid
->wpa_passphrase
,
421 ssid
->ssid
, ssid
->ssid_len
,
422 4096, ssid
->wpa_psk
->psk
, PMK_LEN
);
423 wpa_hexdump_key(MSG_DEBUG
, "PSK (from passphrase)",
424 ssid
->wpa_psk
->psk
, PMK_LEN
);
429 int hostapd_setup_wpa_psk(struct hostapd_bss_config
*conf
)
431 struct hostapd_ssid
*ssid
= &conf
->ssid
;
433 if (ssid
->wpa_passphrase
!= NULL
) {
434 if (ssid
->wpa_psk
!= NULL
) {
435 wpa_printf(MSG_DEBUG
, "Using pre-configured WPA PSK "
436 "instead of passphrase");
438 wpa_printf(MSG_DEBUG
, "Deriving WPA PSK based on "
440 if (hostapd_derive_psk(ssid
) < 0)
443 ssid
->wpa_psk
->group
= 1;
446 return hostapd_config_read_wpa_psk(ssid
->wpa_psk_file
, &conf
->ssid
);
450 static void hostapd_config_free_radius(struct hostapd_radius_server
*servers
,
455 for (i
= 0; i
< num_servers
; i
++) {
456 os_free(servers
[i
].shared_secret
);
462 struct hostapd_radius_attr
*
463 hostapd_config_get_radius_attr(struct hostapd_radius_attr
*attr
, u8 type
)
465 for (; attr
; attr
= attr
->next
) {
466 if (attr
->type
== type
)
473 static void hostapd_config_free_radius_attr(struct hostapd_radius_attr
*attr
)
475 struct hostapd_radius_attr
*prev
;
480 wpabuf_free(prev
->val
);
486 void hostapd_config_free_eap_user(struct hostapd_eap_user
*user
)
488 hostapd_config_free_radius_attr(user
->accept_attr
);
489 os_free(user
->identity
);
490 bin_clear_free(user
->password
, user
->password_len
);
491 bin_clear_free(user
->salt
, user
->salt_len
);
496 void hostapd_config_free_eap_users(struct hostapd_eap_user
*user
)
498 struct hostapd_eap_user
*prev_user
;
503 hostapd_config_free_eap_user(prev_user
);
508 static void hostapd_config_free_wep(struct hostapd_wep_keys
*keys
)
511 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
512 bin_clear_free(keys
->key
[i
], keys
->len
[i
]);
518 void hostapd_config_clear_wpa_psk(struct hostapd_wpa_psk
**l
)
520 struct hostapd_wpa_psk
*psk
, *tmp
;
522 for (psk
= *l
; psk
;) {
525 bin_clear_free(tmp
, sizeof(*tmp
));
531 static void hostapd_config_free_anqp_elem(struct hostapd_bss_config
*conf
)
533 struct anqp_element
*elem
;
535 while ((elem
= dl_list_first(&conf
->anqp_elem
, struct anqp_element
,
537 dl_list_del(&elem
->list
);
538 wpabuf_free(elem
->payload
);
544 static void hostapd_config_free_fils_realms(struct hostapd_bss_config
*conf
)
547 struct fils_realm
*realm
;
549 while ((realm
= dl_list_first(&conf
->fils_realms
, struct fils_realm
,
551 dl_list_del(&realm
->list
);
554 #endif /* CONFIG_FILS */
558 static void hostapd_config_free_sae_passwords(struct hostapd_bss_config
*conf
)
560 struct sae_password_entry
*pw
, *tmp
;
562 pw
= conf
->sae_passwords
;
563 conf
->sae_passwords
= NULL
;
567 str_clear_free(tmp
->password
);
568 os_free(tmp
->identifier
);
575 static void hostapd_dpp_controller_conf_free(struct dpp_controller_conf
*conf
)
577 struct dpp_controller_conf
*prev
;
585 #endif /* CONFIG_DPP2 */
588 void hostapd_config_free_bss(struct hostapd_bss_config
*conf
)
593 hostapd_config_clear_wpa_psk(&conf
->ssid
.wpa_psk
);
595 str_clear_free(conf
->ssid
.wpa_passphrase
);
596 os_free(conf
->ssid
.wpa_psk_file
);
597 hostapd_config_free_wep(&conf
->ssid
.wep
);
598 #ifdef CONFIG_FULL_DYNAMIC_VLAN
599 os_free(conf
->ssid
.vlan_tagged_interface
);
600 #endif /* CONFIG_FULL_DYNAMIC_VLAN */
602 hostapd_config_free_eap_users(conf
->eap_user
);
603 os_free(conf
->eap_user_sqlite
);
605 os_free(conf
->eap_req_id_text
);
606 os_free(conf
->erp_domain
);
607 os_free(conf
->accept_mac
);
608 os_free(conf
->deny_mac
);
609 os_free(conf
->nas_identifier
);
611 hostapd_config_free_radius(conf
->radius
->auth_servers
,
612 conf
->radius
->num_auth_servers
);
613 hostapd_config_free_radius(conf
->radius
->acct_servers
,
614 conf
->radius
->num_acct_servers
);
616 hostapd_config_free_radius_attr(conf
->radius_auth_req_attr
);
617 hostapd_config_free_radius_attr(conf
->radius_acct_req_attr
);
618 os_free(conf
->rsn_preauth_interfaces
);
619 os_free(conf
->ctrl_interface
);
620 os_free(conf
->ca_cert
);
621 os_free(conf
->server_cert
);
622 os_free(conf
->private_key
);
623 os_free(conf
->private_key_passwd
);
624 os_free(conf
->check_cert_subject
);
625 os_free(conf
->ocsp_stapling_response
);
626 os_free(conf
->ocsp_stapling_response_multi
);
627 os_free(conf
->dh_file
);
628 os_free(conf
->openssl_ciphers
);
629 os_free(conf
->openssl_ecdh_curves
);
630 os_free(conf
->pac_opaque_encr_key
);
631 os_free(conf
->eap_fast_a_id
);
632 os_free(conf
->eap_fast_a_id_info
);
633 os_free(conf
->eap_sim_db
);
634 os_free(conf
->radius_server_clients
);
635 os_free(conf
->radius
);
636 os_free(conf
->radius_das_shared_secret
);
637 hostapd_config_free_vlan(conf
);
638 os_free(conf
->time_zone
);
640 #ifdef CONFIG_IEEE80211R_AP
642 struct ft_remote_r0kh
*r0kh
, *r0kh_prev
;
643 struct ft_remote_r1kh
*r1kh
, *r1kh_prev
;
645 r0kh
= conf
->r0kh_list
;
646 conf
->r0kh_list
= NULL
;
653 r1kh
= conf
->r1kh_list
;
654 conf
->r1kh_list
= NULL
;
661 #endif /* CONFIG_IEEE80211R_AP */
664 os_free(conf
->wps_pin_requests
);
665 os_free(conf
->device_name
);
666 os_free(conf
->manufacturer
);
667 os_free(conf
->model_name
);
668 os_free(conf
->model_number
);
669 os_free(conf
->serial_number
);
670 os_free(conf
->config_methods
);
671 os_free(conf
->ap_pin
);
672 os_free(conf
->extra_cred
);
673 os_free(conf
->ap_settings
);
674 hostapd_config_clear_wpa_psk(&conf
->multi_ap_backhaul_ssid
.wpa_psk
);
675 str_clear_free(conf
->multi_ap_backhaul_ssid
.wpa_passphrase
);
676 os_free(conf
->upnp_iface
);
677 os_free(conf
->friendly_name
);
678 os_free(conf
->manufacturer_url
);
679 os_free(conf
->model_description
);
680 os_free(conf
->model_url
);
685 for (i
= 0; i
< MAX_WPS_VENDOR_EXTENSIONS
; i
++)
686 wpabuf_free(conf
->wps_vendor_ext
[i
]);
688 wpabuf_free(conf
->wps_nfc_dh_pubkey
);
689 wpabuf_free(conf
->wps_nfc_dh_privkey
);
690 wpabuf_free(conf
->wps_nfc_dev_pw
);
691 #endif /* CONFIG_WPS */
693 os_free(conf
->roaming_consortium
);
694 os_free(conf
->venue_name
);
695 os_free(conf
->venue_url
);
696 os_free(conf
->nai_realm_data
);
697 os_free(conf
->network_auth_type
);
698 os_free(conf
->anqp_3gpp_cell_net
);
699 os_free(conf
->domain_name
);
700 hostapd_config_free_anqp_elem(conf
);
702 #ifdef CONFIG_RADIUS_TEST
703 os_free(conf
->dump_msk_file
);
704 #endif /* CONFIG_RADIUS_TEST */
707 os_free(conf
->hs20_oper_friendly_name
);
708 os_free(conf
->hs20_wan_metrics
);
709 os_free(conf
->hs20_connection_capability
);
710 os_free(conf
->hs20_operating_class
);
711 os_free(conf
->hs20_icons
);
712 if (conf
->hs20_osu_providers
) {
714 for (i
= 0; i
< conf
->hs20_osu_providers_count
; i
++) {
715 struct hs20_osu_provider
*p
;
717 p
= &conf
->hs20_osu_providers
[i
];
718 os_free(p
->friendly_name
);
719 os_free(p
->server_uri
);
720 os_free(p
->method_list
);
721 for (j
= 0; j
< p
->icons_count
; j
++)
722 os_free(p
->icons
[j
]);
725 os_free(p
->osu_nai2
);
726 os_free(p
->service_desc
);
728 os_free(conf
->hs20_osu_providers
);
730 if (conf
->hs20_operator_icon
) {
733 for (i
= 0; i
< conf
->hs20_operator_icon_count
; i
++)
734 os_free(conf
->hs20_operator_icon
[i
]);
735 os_free(conf
->hs20_operator_icon
);
737 os_free(conf
->subscr_remediation_url
);
738 os_free(conf
->hs20_sim_provisioning_url
);
739 os_free(conf
->t_c_filename
);
740 os_free(conf
->t_c_server_url
);
741 #endif /* CONFIG_HS20 */
743 wpabuf_free(conf
->vendor_elements
);
744 wpabuf_free(conf
->assocresp_elements
);
746 os_free(conf
->sae_groups
);
748 os_free(conf
->owe_groups
);
749 #endif /* CONFIG_OWE */
751 os_free(conf
->wowlan_triggers
);
753 os_free(conf
->server_id
);
755 #ifdef CONFIG_TESTING_OPTIONS
756 wpabuf_free(conf
->own_ie_override
);
757 wpabuf_free(conf
->sae_commit_override
);
758 #endif /* CONFIG_TESTING_OPTIONS */
760 os_free(conf
->no_probe_resp_if_seen_on
);
761 os_free(conf
->no_auth_if_seen_on
);
763 hostapd_config_free_fils_realms(conf
);
766 os_free(conf
->dpp_connector
);
767 wpabuf_free(conf
->dpp_netaccesskey
);
768 wpabuf_free(conf
->dpp_csign
);
770 hostapd_dpp_controller_conf_free(conf
->dpp_controller
);
771 #endif /* CONFIG_DPP2 */
772 #endif /* CONFIG_DPP */
774 hostapd_config_free_sae_passwords(conf
);
776 #ifdef CONFIG_AIRTIME_POLICY
778 struct airtime_sta_weight
*wt
, *wt_prev
;
780 wt
= conf
->airtime_weight_list
;
781 conf
->airtime_weight_list
= NULL
;
788 #endif /* CONFIG_AIRTIME_POLICY */
795 * hostapd_config_free - Free hostapd configuration
796 * @conf: Configuration data from hostapd_config_read().
798 void hostapd_config_free(struct hostapd_config
*conf
)
805 for (i
= 0; i
< conf
->num_bss
; i
++)
806 hostapd_config_free_bss(conf
->bss
[i
]);
808 os_free(conf
->supported_rates
);
809 os_free(conf
->basic_rates
);
810 os_free(conf
->acs_ch_list
.range
);
811 os_free(conf
->driver_params
);
813 os_free(conf
->acs_chan_bias
);
814 #endif /* CONFIG_ACS */
815 wpabuf_free(conf
->lci
);
816 wpabuf_free(conf
->civic
);
823 * hostapd_maclist_found - Find a MAC address from a list
824 * @list: MAC address list
825 * @num_entries: Number of addresses in the list
826 * @addr: Address to search for
827 * @vlan_id: Buffer for returning VLAN ID or %NULL if not needed
828 * Returns: 1 if address is in the list or 0 if not.
830 * Perform a binary search for given MAC address from a pre-sorted list.
832 int hostapd_maclist_found(struct mac_acl_entry
*list
, int num_entries
,
833 const u8
*addr
, struct vlan_description
*vlan_id
)
835 int start
, end
, middle
, res
;
838 end
= num_entries
- 1;
840 while (start
<= end
) {
841 middle
= (start
+ end
) / 2;
842 res
= os_memcmp(list
[middle
].addr
, addr
, ETH_ALEN
);
845 *vlan_id
= list
[middle
].vlan_id
;
858 int hostapd_rate_found(int *list
, int rate
)
865 for (i
= 0; list
[i
] >= 0; i
++)
873 int hostapd_vlan_valid(struct hostapd_vlan
*vlan
,
874 struct vlan_description
*vlan_desc
)
876 struct hostapd_vlan
*v
= vlan
;
879 if (!vlan_desc
->notempty
|| vlan_desc
->untagged
< 0 ||
880 vlan_desc
->untagged
> MAX_VLAN_ID
)
882 for (i
= 0; i
< MAX_NUM_TAGGED_VLAN
; i
++) {
883 if (vlan_desc
->tagged
[i
] < 0 ||
884 vlan_desc
->tagged
[i
] > MAX_VLAN_ID
)
887 if (!vlan_desc
->untagged
&& !vlan_desc
->tagged
[0])
891 if (!vlan_compare(&v
->vlan_desc
, vlan_desc
) ||
892 v
->vlan_id
== VLAN_ID_WILDCARD
)
900 const char * hostapd_get_vlan_id_ifname(struct hostapd_vlan
*vlan
, int vlan_id
)
902 struct hostapd_vlan
*v
= vlan
;
904 if (v
->vlan_id
== vlan_id
)
912 const u8
* hostapd_get_psk(const struct hostapd_bss_config
*conf
,
913 const u8
*addr
, const u8
*p2p_dev_addr
,
914 const u8
*prev_psk
, int *vlan_id
)
916 struct hostapd_wpa_psk
*psk
;
917 int next_ok
= prev_psk
== NULL
;
922 if (p2p_dev_addr
&& !is_zero_ether_addr(p2p_dev_addr
)) {
923 wpa_printf(MSG_DEBUG
, "Searching a PSK for " MACSTR
924 " p2p_dev_addr=" MACSTR
" prev_psk=%p",
925 MAC2STR(addr
), MAC2STR(p2p_dev_addr
), prev_psk
);
926 addr
= NULL
; /* Use P2P Device Address for matching */
928 wpa_printf(MSG_DEBUG
, "Searching a PSK for " MACSTR
930 MAC2STR(addr
), prev_psk
);
933 for (psk
= conf
->ssid
.wpa_psk
; psk
!= NULL
; psk
= psk
->next
) {
936 (addr
&& os_memcmp(psk
->addr
, addr
, ETH_ALEN
) == 0) ||
937 (!addr
&& p2p_dev_addr
&&
938 os_memcmp(psk
->p2p_dev_addr
, p2p_dev_addr
, ETH_ALEN
) ==
941 *vlan_id
= psk
->vlan_id
;
945 if (psk
->psk
== prev_psk
)
953 static int hostapd_config_check_bss(struct hostapd_bss_config
*bss
,
954 struct hostapd_config
*conf
,
957 if (full_config
&& bss
->ieee802_1x
&& !bss
->eap_server
&&
958 !bss
->radius
->auth_servers
) {
959 wpa_printf(MSG_ERROR
, "Invalid IEEE 802.1X configuration (no "
960 "EAP authenticator configured).");
967 wep
= bss
->default_wep_key_len
> 0 ||
968 bss
->individual_wep_key_len
> 0;
969 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
970 if (bss
->ssid
.wep
.keys_set
) {
977 wpa_printf(MSG_ERROR
, "WEP configuration in a WPA network is not supported");
982 if (full_config
&& bss
->wpa
&&
983 bss
->wpa_psk_radius
!= PSK_RADIUS_IGNORED
&&
984 bss
->macaddr_acl
!= USE_EXTERNAL_RADIUS_AUTH
) {
985 wpa_printf(MSG_ERROR
, "WPA-PSK using RADIUS enabled, but no "
986 "RADIUS checking (macaddr_acl=2) enabled.");
990 if (full_config
&& bss
->wpa
&& (bss
->wpa_key_mgmt
& WPA_KEY_MGMT_PSK
) &&
991 bss
->ssid
.wpa_psk
== NULL
&& bss
->ssid
.wpa_passphrase
== NULL
&&
992 bss
->ssid
.wpa_psk_file
== NULL
&&
993 (bss
->wpa_psk_radius
!= PSK_RADIUS_REQUIRED
||
994 bss
->macaddr_acl
!= USE_EXTERNAL_RADIUS_AUTH
)) {
995 wpa_printf(MSG_ERROR
, "WPA-PSK enabled, but PSK or passphrase "
996 "is not configured.");
1000 if (full_config
&& !is_zero_ether_addr(bss
->bssid
)) {
1003 for (i
= 0; i
< conf
->num_bss
; i
++) {
1004 if (conf
->bss
[i
] != bss
&&
1005 (hostapd_mac_comp(conf
->bss
[i
]->bssid
,
1006 bss
->bssid
) == 0)) {
1007 wpa_printf(MSG_ERROR
, "Duplicate BSSID " MACSTR
1008 " on interface '%s' and '%s'.",
1009 MAC2STR(bss
->bssid
),
1010 conf
->bss
[i
]->iface
, bss
->iface
);
1016 #ifdef CONFIG_IEEE80211R_AP
1017 if (full_config
&& wpa_key_mgmt_ft(bss
->wpa_key_mgmt
) &&
1018 (bss
->nas_identifier
== NULL
||
1019 os_strlen(bss
->nas_identifier
) < 1 ||
1020 os_strlen(bss
->nas_identifier
) > FT_R0KH_ID_MAX_LEN
)) {
1021 wpa_printf(MSG_ERROR
, "FT (IEEE 802.11r) requires "
1022 "nas_identifier to be configured as a 1..48 octet "
1026 #endif /* CONFIG_IEEE80211R_AP */
1028 #ifdef CONFIG_IEEE80211N
1029 if (full_config
&& conf
->ieee80211n
&&
1030 conf
->hw_mode
== HOSTAPD_MODE_IEEE80211B
) {
1031 bss
->disable_11n
= 1;
1032 wpa_printf(MSG_ERROR
, "HT (IEEE 802.11n) in 11b mode is not "
1033 "allowed, disabling HT capabilities");
1036 if (full_config
&& conf
->ieee80211n
&&
1037 bss
->ssid
.security_policy
== SECURITY_STATIC_WEP
) {
1038 bss
->disable_11n
= 1;
1039 wpa_printf(MSG_ERROR
, "HT (IEEE 802.11n) with WEP is not "
1040 "allowed, disabling HT capabilities");
1043 if (full_config
&& conf
->ieee80211n
&& bss
->wpa
&&
1044 !(bss
->wpa_pairwise
& WPA_CIPHER_CCMP
) &&
1045 !(bss
->rsn_pairwise
& (WPA_CIPHER_CCMP
| WPA_CIPHER_GCMP
|
1046 WPA_CIPHER_CCMP_256
| WPA_CIPHER_GCMP_256
)))
1048 bss
->disable_11n
= 1;
1049 wpa_printf(MSG_ERROR
, "HT (IEEE 802.11n) with WPA/WPA2 "
1050 "requires CCMP/GCMP to be enabled, disabling HT "
1053 #endif /* CONFIG_IEEE80211N */
1055 #ifdef CONFIG_IEEE80211AC
1056 if (full_config
&& conf
->ieee80211ac
&&
1057 bss
->ssid
.security_policy
== SECURITY_STATIC_WEP
) {
1058 bss
->disable_11ac
= 1;
1059 wpa_printf(MSG_ERROR
,
1060 "VHT (IEEE 802.11ac) with WEP is not allowed, disabling VHT capabilities");
1063 if (full_config
&& conf
->ieee80211ac
&& bss
->wpa
&&
1064 !(bss
->wpa_pairwise
& WPA_CIPHER_CCMP
) &&
1065 !(bss
->rsn_pairwise
& (WPA_CIPHER_CCMP
| WPA_CIPHER_GCMP
|
1066 WPA_CIPHER_CCMP_256
| WPA_CIPHER_GCMP_256
)))
1068 bss
->disable_11ac
= 1;
1069 wpa_printf(MSG_ERROR
,
1070 "VHT (IEEE 802.11ac) with WPA/WPA2 requires CCMP/GCMP to be enabled, disabling VHT capabilities");
1072 #endif /* CONFIG_IEEE80211AC */
1075 if (full_config
&& bss
->wps_state
&& bss
->ignore_broadcast_ssid
) {
1076 wpa_printf(MSG_INFO
, "WPS: ignore_broadcast_ssid "
1077 "configuration forced WPS to be disabled");
1081 if (full_config
&& bss
->wps_state
&&
1082 bss
->ssid
.wep
.keys_set
&& bss
->wpa
== 0) {
1083 wpa_printf(MSG_INFO
, "WPS: WEP configuration forced WPS to be "
1088 if (full_config
&& bss
->wps_state
&& bss
->wpa
&&
1090 !(bss
->rsn_pairwise
& (WPA_CIPHER_CCMP
| WPA_CIPHER_GCMP
|
1091 WPA_CIPHER_CCMP_256
|
1092 WPA_CIPHER_GCMP_256
)))) {
1093 wpa_printf(MSG_INFO
, "WPS: WPA/TKIP configuration without "
1094 "WPA2/CCMP/GCMP forced WPS to be disabled");
1097 #endif /* CONFIG_WPS */
1100 if (full_config
&& bss
->hs20
&&
1102 !(bss
->rsn_pairwise
& (WPA_CIPHER_CCMP
| WPA_CIPHER_GCMP
|
1103 WPA_CIPHER_CCMP_256
|
1104 WPA_CIPHER_GCMP_256
)))) {
1105 wpa_printf(MSG_ERROR
, "HS 2.0: WPA2-Enterprise/CCMP "
1106 "configuration is required for Hotspot 2.0 "
1110 #endif /* CONFIG_HS20 */
1113 if (full_config
&& bss
->mbo_enabled
&& (bss
->wpa
& 2) &&
1114 bss
->ieee80211w
== NO_MGMT_FRAME_PROTECTION
) {
1115 wpa_printf(MSG_ERROR
,
1116 "MBO: PMF needs to be enabled whenever using WPA2 with MBO");
1119 #endif /* CONFIG_MBO */
1122 if (full_config
&& bss
->ieee80211w
== NO_MGMT_FRAME_PROTECTION
&&
1124 wpa_printf(MSG_ERROR
,
1125 "OCV: PMF needs to be enabled whenever using OCV");
1128 #endif /* CONFIG_OCV */
1134 static int hostapd_config_check_cw(struct hostapd_config
*conf
, int queue
)
1136 int tx_cwmin
= conf
->tx_queue
[queue
].cwmin
;
1137 int tx_cwmax
= conf
->tx_queue
[queue
].cwmax
;
1138 int ac_cwmin
= conf
->wmm_ac_params
[queue
].cwmin
;
1139 int ac_cwmax
= conf
->wmm_ac_params
[queue
].cwmax
;
1141 if (tx_cwmin
> tx_cwmax
) {
1142 wpa_printf(MSG_ERROR
,
1143 "Invalid TX queue cwMin/cwMax values. cwMin(%d) greater than cwMax(%d)",
1144 tx_cwmin
, tx_cwmax
);
1147 if (ac_cwmin
> ac_cwmax
) {
1148 wpa_printf(MSG_ERROR
,
1149 "Invalid WMM AC cwMin/cwMax values. cwMin(%d) greater than cwMax(%d)",
1150 ac_cwmin
, ac_cwmax
);
1157 int hostapd_config_check(struct hostapd_config
*conf
, int full_config
)
1161 if (full_config
&& conf
->ieee80211d
&&
1162 (!conf
->country
[0] || !conf
->country
[1])) {
1163 wpa_printf(MSG_ERROR
, "Cannot enable IEEE 802.11d without "
1164 "setting the country_code");
1168 if (full_config
&& conf
->ieee80211h
&& !conf
->ieee80211d
) {
1169 wpa_printf(MSG_ERROR
, "Cannot enable IEEE 802.11h without "
1170 "IEEE 802.11d enabled");
1174 if (full_config
&& conf
->local_pwr_constraint
!= -1 &&
1175 !conf
->ieee80211d
) {
1176 wpa_printf(MSG_ERROR
, "Cannot add Power Constraint element without Country element");
1180 if (full_config
&& conf
->spectrum_mgmt_required
&&
1181 conf
->local_pwr_constraint
== -1) {
1182 wpa_printf(MSG_ERROR
, "Cannot set Spectrum Management bit without Country and Power Constraint elements");
1186 #ifdef CONFIG_AIRTIME_POLICY
1187 if (full_config
&& conf
->airtime_mode
> AIRTIME_MODE_STATIC
&&
1188 !conf
->airtime_update_interval
) {
1189 wpa_printf(MSG_ERROR
, "Airtime update interval cannot be zero");
1192 #endif /* CONFIG_AIRTIME_POLICY */
1193 for (i
= 0; i
< NUM_TX_QUEUES
; i
++) {
1194 if (hostapd_config_check_cw(conf
, i
))
1198 for (i
= 0; i
< conf
->num_bss
; i
++) {
1199 if (hostapd_config_check_bss(conf
->bss
[i
], conf
, full_config
))
1207 void hostapd_set_security_params(struct hostapd_bss_config
*bss
,
1210 if (bss
->individual_wep_key_len
== 0) {
1211 /* individual keys are not use; can use key idx0 for
1213 bss
->broadcast_key_idx_min
= 0;
1216 if ((bss
->wpa
& 2) && bss
->rsn_pairwise
== 0)
1217 bss
->rsn_pairwise
= bss
->wpa_pairwise
;
1218 if (bss
->group_cipher
)
1219 bss
->wpa_group
= bss
->group_cipher
;
1221 bss
->wpa_group
= wpa_select_ap_group_cipher(bss
->wpa
,
1224 if (!bss
->wpa_group_rekey_set
)
1225 bss
->wpa_group_rekey
= bss
->wpa_group
== WPA_CIPHER_TKIP
?
1229 bss
->radius
->auth_server
= bss
->radius
->auth_servers
;
1230 bss
->radius
->acct_server
= bss
->radius
->acct_servers
;
1233 if (bss
->wpa
&& bss
->ieee802_1x
) {
1234 bss
->ssid
.security_policy
= SECURITY_WPA
;
1235 } else if (bss
->wpa
) {
1236 bss
->ssid
.security_policy
= SECURITY_WPA_PSK
;
1237 } else if (bss
->ieee802_1x
) {
1238 int cipher
= WPA_CIPHER_NONE
;
1239 bss
->ssid
.security_policy
= SECURITY_IEEE_802_1X
;
1240 bss
->ssid
.wep
.default_len
= bss
->default_wep_key_len
;
1241 if (full_config
&& bss
->default_wep_key_len
) {
1242 cipher
= bss
->default_wep_key_len
>= 13 ?
1243 WPA_CIPHER_WEP104
: WPA_CIPHER_WEP40
;
1244 } else if (full_config
&& bss
->ssid
.wep
.keys_set
) {
1245 if (bss
->ssid
.wep
.len
[0] >= 13)
1246 cipher
= WPA_CIPHER_WEP104
;
1248 cipher
= WPA_CIPHER_WEP40
;
1250 bss
->wpa_group
= cipher
;
1251 bss
->wpa_pairwise
= cipher
;
1252 bss
->rsn_pairwise
= cipher
;
1254 bss
->wpa_key_mgmt
= WPA_KEY_MGMT_IEEE8021X_NO_WPA
;
1255 } else if (bss
->ssid
.wep
.keys_set
) {
1256 int cipher
= WPA_CIPHER_WEP40
;
1257 if (bss
->ssid
.wep
.len
[0] >= 13)
1258 cipher
= WPA_CIPHER_WEP104
;
1259 bss
->ssid
.security_policy
= SECURITY_STATIC_WEP
;
1260 bss
->wpa_group
= cipher
;
1261 bss
->wpa_pairwise
= cipher
;
1262 bss
->rsn_pairwise
= cipher
;
1264 bss
->wpa_key_mgmt
= WPA_KEY_MGMT_NONE
;
1265 } else if (bss
->osen
) {
1266 bss
->ssid
.security_policy
= SECURITY_OSEN
;
1267 bss
->wpa_group
= WPA_CIPHER_CCMP
;
1268 bss
->wpa_pairwise
= 0;
1269 bss
->rsn_pairwise
= WPA_CIPHER_CCMP
;
1271 bss
->ssid
.security_policy
= SECURITY_PLAINTEXT
;
1273 bss
->wpa_group
= WPA_CIPHER_NONE
;
1274 bss
->wpa_pairwise
= WPA_CIPHER_NONE
;
1275 bss
->rsn_pairwise
= WPA_CIPHER_NONE
;
1276 bss
->wpa_key_mgmt
= WPA_KEY_MGMT_NONE
;
1282 int hostapd_sae_pw_id_in_use(struct hostapd_bss_config
*conf
)
1284 int with_id
= 0, without_id
= 0;
1285 struct sae_password_entry
*pw
;
1287 if (conf
->ssid
.wpa_passphrase
)
1290 for (pw
= conf
->sae_passwords
; pw
; pw
= pw
->next
) {
1295 if (with_id
&& without_id
)
1299 if (with_id
&& !without_id
)