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 #endif /* CONFIG_IEEE80211AX */
245 /* The third octet of the country string uses an ASCII space character
246 * by default to indicate that the regulations encompass all
247 * environments for the current frequency band in the country. */
248 conf
->country
[2] = ' ';
250 conf
->rssi_reject_assoc_rssi
= 0;
251 conf
->rssi_reject_assoc_timeout
= 30;
253 #ifdef CONFIG_AIRTIME_POLICY
254 conf
->airtime_update_interval
= AIRTIME_DEFAULT_UPDATE_INTERVAL
;
255 #endif /* CONFIG_AIRTIME_POLICY */
261 int hostapd_mac_comp(const void *a
, const void *b
)
263 return os_memcmp(a
, b
, sizeof(macaddr
));
267 static int hostapd_config_read_wpa_psk(const char *fname
,
268 struct hostapd_ssid
*ssid
)
278 int line
= 0, ret
= 0, len
, ok
;
280 struct hostapd_wpa_psk
*psk
;
285 f
= fopen(fname
, "r");
287 wpa_printf(MSG_ERROR
, "WPA PSK file '%s' not found.", fname
);
291 while (fgets(buf
, sizeof(buf
), f
)) {
299 while (*pos
!= '\0') {
311 while ((token
= str_token(buf
, " ", &context
))) {
312 if (!os_strchr(token
, '='))
315 name
= str_token(token
, "=", &context2
);
318 value
= str_token(token
, "", &context2
);
321 if (!os_strcmp(name
, "keyid")) {
323 } else if (!os_strcmp(name
, "vlanid")) {
324 vlan_id
= atoi(value
);
326 wpa_printf(MSG_ERROR
,
327 "Unrecognized '%s=%s' on line %d in '%s'",
328 name
, value
, line
, fname
);
339 if (hwaddr_aton(token
, addr
)) {
340 wpa_printf(MSG_ERROR
, "Invalid MAC address '%s' on "
341 "line %d in '%s'", token
, line
, fname
);
346 psk
= os_zalloc(sizeof(*psk
));
348 wpa_printf(MSG_ERROR
, "WPA PSK allocation failed");
352 psk
->vlan_id
= vlan_id
;
353 if (is_zero_ether_addr(addr
))
356 os_memcpy(psk
->addr
, addr
, ETH_ALEN
);
358 pos
= str_token(buf
, "", &context
);
360 wpa_printf(MSG_ERROR
, "No PSK on line %d in '%s'",
368 len
= os_strlen(pos
);
369 if (len
== 64 && hexstr2bin(pos
, psk
->psk
, PMK_LEN
) == 0)
371 else if (len
>= 8 && len
< 64) {
372 pbkdf2_sha1(pos
, ssid
->ssid
, ssid
->ssid_len
,
373 4096, psk
->psk
, PMK_LEN
);
377 wpa_printf(MSG_ERROR
, "Invalid PSK '%s' on line %d in "
378 "'%s'", pos
, line
, fname
);
385 len
= os_strlcpy(psk
->keyid
, keyid
, sizeof(psk
->keyid
));
386 if ((size_t) len
>= sizeof(psk
->keyid
)) {
387 wpa_printf(MSG_ERROR
,
388 "PSK keyid too long on line %d in '%s'",
396 psk
->next
= ssid
->wpa_psk
;
406 static int hostapd_derive_psk(struct hostapd_ssid
*ssid
)
408 ssid
->wpa_psk
= os_zalloc(sizeof(struct hostapd_wpa_psk
));
409 if (ssid
->wpa_psk
== NULL
) {
410 wpa_printf(MSG_ERROR
, "Unable to alloc space for PSK");
413 wpa_hexdump_ascii(MSG_DEBUG
, "SSID",
414 (u8
*) ssid
->ssid
, ssid
->ssid_len
);
415 wpa_hexdump_ascii_key(MSG_DEBUG
, "PSK (ASCII passphrase)",
416 (u8
*) ssid
->wpa_passphrase
,
417 os_strlen(ssid
->wpa_passphrase
));
418 pbkdf2_sha1(ssid
->wpa_passphrase
,
419 ssid
->ssid
, ssid
->ssid_len
,
420 4096, ssid
->wpa_psk
->psk
, PMK_LEN
);
421 wpa_hexdump_key(MSG_DEBUG
, "PSK (from passphrase)",
422 ssid
->wpa_psk
->psk
, PMK_LEN
);
427 int hostapd_setup_wpa_psk(struct hostapd_bss_config
*conf
)
429 struct hostapd_ssid
*ssid
= &conf
->ssid
;
431 if (ssid
->wpa_passphrase
!= NULL
) {
432 if (ssid
->wpa_psk
!= NULL
) {
433 wpa_printf(MSG_DEBUG
, "Using pre-configured WPA PSK "
434 "instead of passphrase");
436 wpa_printf(MSG_DEBUG
, "Deriving WPA PSK based on "
438 if (hostapd_derive_psk(ssid
) < 0)
441 ssid
->wpa_psk
->group
= 1;
444 return hostapd_config_read_wpa_psk(ssid
->wpa_psk_file
, &conf
->ssid
);
448 static void hostapd_config_free_radius(struct hostapd_radius_server
*servers
,
453 for (i
= 0; i
< num_servers
; i
++) {
454 os_free(servers
[i
].shared_secret
);
460 struct hostapd_radius_attr
*
461 hostapd_config_get_radius_attr(struct hostapd_radius_attr
*attr
, u8 type
)
463 for (; attr
; attr
= attr
->next
) {
464 if (attr
->type
== type
)
471 static void hostapd_config_free_radius_attr(struct hostapd_radius_attr
*attr
)
473 struct hostapd_radius_attr
*prev
;
478 wpabuf_free(prev
->val
);
484 void hostapd_config_free_eap_user(struct hostapd_eap_user
*user
)
486 hostapd_config_free_radius_attr(user
->accept_attr
);
487 os_free(user
->identity
);
488 bin_clear_free(user
->password
, user
->password_len
);
489 bin_clear_free(user
->salt
, user
->salt_len
);
494 void hostapd_config_free_eap_users(struct hostapd_eap_user
*user
)
496 struct hostapd_eap_user
*prev_user
;
501 hostapd_config_free_eap_user(prev_user
);
506 static void hostapd_config_free_wep(struct hostapd_wep_keys
*keys
)
509 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
510 bin_clear_free(keys
->key
[i
], keys
->len
[i
]);
516 void hostapd_config_clear_wpa_psk(struct hostapd_wpa_psk
**l
)
518 struct hostapd_wpa_psk
*psk
, *tmp
;
520 for (psk
= *l
; psk
;) {
523 bin_clear_free(tmp
, sizeof(*tmp
));
529 static void hostapd_config_free_anqp_elem(struct hostapd_bss_config
*conf
)
531 struct anqp_element
*elem
;
533 while ((elem
= dl_list_first(&conf
->anqp_elem
, struct anqp_element
,
535 dl_list_del(&elem
->list
);
536 wpabuf_free(elem
->payload
);
542 static void hostapd_config_free_fils_realms(struct hostapd_bss_config
*conf
)
545 struct fils_realm
*realm
;
547 while ((realm
= dl_list_first(&conf
->fils_realms
, struct fils_realm
,
549 dl_list_del(&realm
->list
);
552 #endif /* CONFIG_FILS */
556 static void hostapd_config_free_sae_passwords(struct hostapd_bss_config
*conf
)
558 struct sae_password_entry
*pw
, *tmp
;
560 pw
= conf
->sae_passwords
;
561 conf
->sae_passwords
= NULL
;
565 str_clear_free(tmp
->password
);
566 os_free(tmp
->identifier
);
573 static void hostapd_dpp_controller_conf_free(struct dpp_controller_conf
*conf
)
575 struct dpp_controller_conf
*prev
;
583 #endif /* CONFIG_DPP2 */
586 void hostapd_config_free_bss(struct hostapd_bss_config
*conf
)
591 hostapd_config_clear_wpa_psk(&conf
->ssid
.wpa_psk
);
593 str_clear_free(conf
->ssid
.wpa_passphrase
);
594 os_free(conf
->ssid
.wpa_psk_file
);
595 hostapd_config_free_wep(&conf
->ssid
.wep
);
596 #ifdef CONFIG_FULL_DYNAMIC_VLAN
597 os_free(conf
->ssid
.vlan_tagged_interface
);
598 #endif /* CONFIG_FULL_DYNAMIC_VLAN */
600 hostapd_config_free_eap_users(conf
->eap_user
);
601 os_free(conf
->eap_user_sqlite
);
603 os_free(conf
->eap_req_id_text
);
604 os_free(conf
->erp_domain
);
605 os_free(conf
->accept_mac
);
606 os_free(conf
->deny_mac
);
607 os_free(conf
->nas_identifier
);
609 hostapd_config_free_radius(conf
->radius
->auth_servers
,
610 conf
->radius
->num_auth_servers
);
611 hostapd_config_free_radius(conf
->radius
->acct_servers
,
612 conf
->radius
->num_acct_servers
);
614 hostapd_config_free_radius_attr(conf
->radius_auth_req_attr
);
615 hostapd_config_free_radius_attr(conf
->radius_acct_req_attr
);
616 os_free(conf
->rsn_preauth_interfaces
);
617 os_free(conf
->ctrl_interface
);
618 os_free(conf
->ca_cert
);
619 os_free(conf
->server_cert
);
620 os_free(conf
->private_key
);
621 os_free(conf
->private_key_passwd
);
622 os_free(conf
->check_cert_subject
);
623 os_free(conf
->ocsp_stapling_response
);
624 os_free(conf
->ocsp_stapling_response_multi
);
625 os_free(conf
->dh_file
);
626 os_free(conf
->openssl_ciphers
);
627 os_free(conf
->openssl_ecdh_curves
);
628 os_free(conf
->pac_opaque_encr_key
);
629 os_free(conf
->eap_fast_a_id
);
630 os_free(conf
->eap_fast_a_id_info
);
631 os_free(conf
->eap_sim_db
);
632 os_free(conf
->radius_server_clients
);
633 os_free(conf
->radius
);
634 os_free(conf
->radius_das_shared_secret
);
635 hostapd_config_free_vlan(conf
);
636 os_free(conf
->time_zone
);
638 #ifdef CONFIG_IEEE80211R_AP
640 struct ft_remote_r0kh
*r0kh
, *r0kh_prev
;
641 struct ft_remote_r1kh
*r1kh
, *r1kh_prev
;
643 r0kh
= conf
->r0kh_list
;
644 conf
->r0kh_list
= NULL
;
651 r1kh
= conf
->r1kh_list
;
652 conf
->r1kh_list
= NULL
;
659 #endif /* CONFIG_IEEE80211R_AP */
662 os_free(conf
->wps_pin_requests
);
663 os_free(conf
->device_name
);
664 os_free(conf
->manufacturer
);
665 os_free(conf
->model_name
);
666 os_free(conf
->model_number
);
667 os_free(conf
->serial_number
);
668 os_free(conf
->config_methods
);
669 os_free(conf
->ap_pin
);
670 os_free(conf
->extra_cred
);
671 os_free(conf
->ap_settings
);
672 hostapd_config_clear_wpa_psk(&conf
->multi_ap_backhaul_ssid
.wpa_psk
);
673 str_clear_free(conf
->multi_ap_backhaul_ssid
.wpa_passphrase
);
674 os_free(conf
->upnp_iface
);
675 os_free(conf
->friendly_name
);
676 os_free(conf
->manufacturer_url
);
677 os_free(conf
->model_description
);
678 os_free(conf
->model_url
);
683 for (i
= 0; i
< MAX_WPS_VENDOR_EXTENSIONS
; i
++)
684 wpabuf_free(conf
->wps_vendor_ext
[i
]);
686 wpabuf_free(conf
->wps_nfc_dh_pubkey
);
687 wpabuf_free(conf
->wps_nfc_dh_privkey
);
688 wpabuf_free(conf
->wps_nfc_dev_pw
);
689 #endif /* CONFIG_WPS */
691 os_free(conf
->roaming_consortium
);
692 os_free(conf
->venue_name
);
693 os_free(conf
->venue_url
);
694 os_free(conf
->nai_realm_data
);
695 os_free(conf
->network_auth_type
);
696 os_free(conf
->anqp_3gpp_cell_net
);
697 os_free(conf
->domain_name
);
698 hostapd_config_free_anqp_elem(conf
);
700 #ifdef CONFIG_RADIUS_TEST
701 os_free(conf
->dump_msk_file
);
702 #endif /* CONFIG_RADIUS_TEST */
705 os_free(conf
->hs20_oper_friendly_name
);
706 os_free(conf
->hs20_wan_metrics
);
707 os_free(conf
->hs20_connection_capability
);
708 os_free(conf
->hs20_operating_class
);
709 os_free(conf
->hs20_icons
);
710 if (conf
->hs20_osu_providers
) {
712 for (i
= 0; i
< conf
->hs20_osu_providers_count
; i
++) {
713 struct hs20_osu_provider
*p
;
715 p
= &conf
->hs20_osu_providers
[i
];
716 os_free(p
->friendly_name
);
717 os_free(p
->server_uri
);
718 os_free(p
->method_list
);
719 for (j
= 0; j
< p
->icons_count
; j
++)
720 os_free(p
->icons
[j
]);
723 os_free(p
->osu_nai2
);
724 os_free(p
->service_desc
);
726 os_free(conf
->hs20_osu_providers
);
728 if (conf
->hs20_operator_icon
) {
731 for (i
= 0; i
< conf
->hs20_operator_icon_count
; i
++)
732 os_free(conf
->hs20_operator_icon
[i
]);
733 os_free(conf
->hs20_operator_icon
);
735 os_free(conf
->subscr_remediation_url
);
736 os_free(conf
->hs20_sim_provisioning_url
);
737 os_free(conf
->t_c_filename
);
738 os_free(conf
->t_c_server_url
);
739 #endif /* CONFIG_HS20 */
741 wpabuf_free(conf
->vendor_elements
);
742 wpabuf_free(conf
->assocresp_elements
);
744 os_free(conf
->sae_groups
);
746 os_free(conf
->owe_groups
);
747 #endif /* CONFIG_OWE */
749 os_free(conf
->wowlan_triggers
);
751 os_free(conf
->server_id
);
753 #ifdef CONFIG_TESTING_OPTIONS
754 wpabuf_free(conf
->own_ie_override
);
755 wpabuf_free(conf
->sae_commit_override
);
756 #endif /* CONFIG_TESTING_OPTIONS */
758 os_free(conf
->no_probe_resp_if_seen_on
);
759 os_free(conf
->no_auth_if_seen_on
);
761 hostapd_config_free_fils_realms(conf
);
764 os_free(conf
->dpp_connector
);
765 wpabuf_free(conf
->dpp_netaccesskey
);
766 wpabuf_free(conf
->dpp_csign
);
768 hostapd_dpp_controller_conf_free(conf
->dpp_controller
);
769 #endif /* CONFIG_DPP2 */
770 #endif /* CONFIG_DPP */
772 hostapd_config_free_sae_passwords(conf
);
774 #ifdef CONFIG_AIRTIME_POLICY
776 struct airtime_sta_weight
*wt
, *wt_prev
;
778 wt
= conf
->airtime_weight_list
;
779 conf
->airtime_weight_list
= NULL
;
786 #endif /* CONFIG_AIRTIME_POLICY */
793 * hostapd_config_free - Free hostapd configuration
794 * @conf: Configuration data from hostapd_config_read().
796 void hostapd_config_free(struct hostapd_config
*conf
)
803 for (i
= 0; i
< conf
->num_bss
; i
++)
804 hostapd_config_free_bss(conf
->bss
[i
]);
806 os_free(conf
->supported_rates
);
807 os_free(conf
->basic_rates
);
808 os_free(conf
->acs_ch_list
.range
);
809 os_free(conf
->driver_params
);
811 os_free(conf
->acs_chan_bias
);
812 #endif /* CONFIG_ACS */
813 wpabuf_free(conf
->lci
);
814 wpabuf_free(conf
->civic
);
821 * hostapd_maclist_found - Find a MAC address from a list
822 * @list: MAC address list
823 * @num_entries: Number of addresses in the list
824 * @addr: Address to search for
825 * @vlan_id: Buffer for returning VLAN ID or %NULL if not needed
826 * Returns: 1 if address is in the list or 0 if not.
828 * Perform a binary search for given MAC address from a pre-sorted list.
830 int hostapd_maclist_found(struct mac_acl_entry
*list
, int num_entries
,
831 const u8
*addr
, struct vlan_description
*vlan_id
)
833 int start
, end
, middle
, res
;
836 end
= num_entries
- 1;
838 while (start
<= end
) {
839 middle
= (start
+ end
) / 2;
840 res
= os_memcmp(list
[middle
].addr
, addr
, ETH_ALEN
);
843 *vlan_id
= list
[middle
].vlan_id
;
856 int hostapd_rate_found(int *list
, int rate
)
863 for (i
= 0; list
[i
] >= 0; i
++)
871 int hostapd_vlan_valid(struct hostapd_vlan
*vlan
,
872 struct vlan_description
*vlan_desc
)
874 struct hostapd_vlan
*v
= vlan
;
877 if (!vlan_desc
->notempty
|| vlan_desc
->untagged
< 0 ||
878 vlan_desc
->untagged
> MAX_VLAN_ID
)
880 for (i
= 0; i
< MAX_NUM_TAGGED_VLAN
; i
++) {
881 if (vlan_desc
->tagged
[i
] < 0 ||
882 vlan_desc
->tagged
[i
] > MAX_VLAN_ID
)
885 if (!vlan_desc
->untagged
&& !vlan_desc
->tagged
[0])
889 if (!vlan_compare(&v
->vlan_desc
, vlan_desc
) ||
890 v
->vlan_id
== VLAN_ID_WILDCARD
)
898 const char * hostapd_get_vlan_id_ifname(struct hostapd_vlan
*vlan
, int vlan_id
)
900 struct hostapd_vlan
*v
= vlan
;
902 if (v
->vlan_id
== vlan_id
)
910 const u8
* hostapd_get_psk(const struct hostapd_bss_config
*conf
,
911 const u8
*addr
, const u8
*p2p_dev_addr
,
912 const u8
*prev_psk
, int *vlan_id
)
914 struct hostapd_wpa_psk
*psk
;
915 int next_ok
= prev_psk
== NULL
;
920 if (p2p_dev_addr
&& !is_zero_ether_addr(p2p_dev_addr
)) {
921 wpa_printf(MSG_DEBUG
, "Searching a PSK for " MACSTR
922 " p2p_dev_addr=" MACSTR
" prev_psk=%p",
923 MAC2STR(addr
), MAC2STR(p2p_dev_addr
), prev_psk
);
924 addr
= NULL
; /* Use P2P Device Address for matching */
926 wpa_printf(MSG_DEBUG
, "Searching a PSK for " MACSTR
928 MAC2STR(addr
), prev_psk
);
931 for (psk
= conf
->ssid
.wpa_psk
; psk
!= NULL
; psk
= psk
->next
) {
934 (addr
&& os_memcmp(psk
->addr
, addr
, ETH_ALEN
) == 0) ||
935 (!addr
&& p2p_dev_addr
&&
936 os_memcmp(psk
->p2p_dev_addr
, p2p_dev_addr
, ETH_ALEN
) ==
939 *vlan_id
= psk
->vlan_id
;
943 if (psk
->psk
== prev_psk
)
951 static int hostapd_config_check_bss(struct hostapd_bss_config
*bss
,
952 struct hostapd_config
*conf
,
955 if (full_config
&& bss
->ieee802_1x
&& !bss
->eap_server
&&
956 !bss
->radius
->auth_servers
) {
957 wpa_printf(MSG_ERROR
, "Invalid IEEE 802.1X configuration (no "
958 "EAP authenticator configured).");
965 wep
= bss
->default_wep_key_len
> 0 ||
966 bss
->individual_wep_key_len
> 0;
967 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
968 if (bss
->ssid
.wep
.keys_set
) {
975 wpa_printf(MSG_ERROR
, "WEP configuration in a WPA network is not supported");
980 if (full_config
&& bss
->wpa
&&
981 bss
->wpa_psk_radius
!= PSK_RADIUS_IGNORED
&&
982 bss
->macaddr_acl
!= USE_EXTERNAL_RADIUS_AUTH
) {
983 wpa_printf(MSG_ERROR
, "WPA-PSK using RADIUS enabled, but no "
984 "RADIUS checking (macaddr_acl=2) enabled.");
988 if (full_config
&& bss
->wpa
&& (bss
->wpa_key_mgmt
& WPA_KEY_MGMT_PSK
) &&
989 bss
->ssid
.wpa_psk
== NULL
&& bss
->ssid
.wpa_passphrase
== NULL
&&
990 bss
->ssid
.wpa_psk_file
== NULL
&&
991 (bss
->wpa_psk_radius
!= PSK_RADIUS_REQUIRED
||
992 bss
->macaddr_acl
!= USE_EXTERNAL_RADIUS_AUTH
)) {
993 wpa_printf(MSG_ERROR
, "WPA-PSK enabled, but PSK or passphrase "
994 "is not configured.");
998 if (full_config
&& !is_zero_ether_addr(bss
->bssid
)) {
1001 for (i
= 0; i
< conf
->num_bss
; i
++) {
1002 if (conf
->bss
[i
] != bss
&&
1003 (hostapd_mac_comp(conf
->bss
[i
]->bssid
,
1004 bss
->bssid
) == 0)) {
1005 wpa_printf(MSG_ERROR
, "Duplicate BSSID " MACSTR
1006 " on interface '%s' and '%s'.",
1007 MAC2STR(bss
->bssid
),
1008 conf
->bss
[i
]->iface
, bss
->iface
);
1014 #ifdef CONFIG_IEEE80211R_AP
1015 if (full_config
&& wpa_key_mgmt_ft(bss
->wpa_key_mgmt
) &&
1016 (bss
->nas_identifier
== NULL
||
1017 os_strlen(bss
->nas_identifier
) < 1 ||
1018 os_strlen(bss
->nas_identifier
) > FT_R0KH_ID_MAX_LEN
)) {
1019 wpa_printf(MSG_ERROR
, "FT (IEEE 802.11r) requires "
1020 "nas_identifier to be configured as a 1..48 octet "
1024 #endif /* CONFIG_IEEE80211R_AP */
1026 #ifdef CONFIG_IEEE80211N
1027 if (full_config
&& conf
->ieee80211n
&&
1028 conf
->hw_mode
== HOSTAPD_MODE_IEEE80211B
) {
1029 bss
->disable_11n
= 1;
1030 wpa_printf(MSG_ERROR
, "HT (IEEE 802.11n) in 11b mode is not "
1031 "allowed, disabling HT capabilities");
1034 if (full_config
&& conf
->ieee80211n
&&
1035 bss
->ssid
.security_policy
== SECURITY_STATIC_WEP
) {
1036 bss
->disable_11n
= 1;
1037 wpa_printf(MSG_ERROR
, "HT (IEEE 802.11n) with WEP is not "
1038 "allowed, disabling HT capabilities");
1041 if (full_config
&& conf
->ieee80211n
&& bss
->wpa
&&
1042 !(bss
->wpa_pairwise
& WPA_CIPHER_CCMP
) &&
1043 !(bss
->rsn_pairwise
& (WPA_CIPHER_CCMP
| WPA_CIPHER_GCMP
|
1044 WPA_CIPHER_CCMP_256
| WPA_CIPHER_GCMP_256
)))
1046 bss
->disable_11n
= 1;
1047 wpa_printf(MSG_ERROR
, "HT (IEEE 802.11n) with WPA/WPA2 "
1048 "requires CCMP/GCMP to be enabled, disabling HT "
1051 #endif /* CONFIG_IEEE80211N */
1053 #ifdef CONFIG_IEEE80211AC
1054 if (full_config
&& conf
->ieee80211ac
&&
1055 bss
->ssid
.security_policy
== SECURITY_STATIC_WEP
) {
1056 bss
->disable_11ac
= 1;
1057 wpa_printf(MSG_ERROR
,
1058 "VHT (IEEE 802.11ac) with WEP is not allowed, disabling VHT capabilities");
1061 if (full_config
&& conf
->ieee80211ac
&& bss
->wpa
&&
1062 !(bss
->wpa_pairwise
& WPA_CIPHER_CCMP
) &&
1063 !(bss
->rsn_pairwise
& (WPA_CIPHER_CCMP
| WPA_CIPHER_GCMP
|
1064 WPA_CIPHER_CCMP_256
| WPA_CIPHER_GCMP_256
)))
1066 bss
->disable_11ac
= 1;
1067 wpa_printf(MSG_ERROR
,
1068 "VHT (IEEE 802.11ac) with WPA/WPA2 requires CCMP/GCMP to be enabled, disabling VHT capabilities");
1070 #endif /* CONFIG_IEEE80211AC */
1073 if (full_config
&& bss
->wps_state
&& bss
->ignore_broadcast_ssid
) {
1074 wpa_printf(MSG_INFO
, "WPS: ignore_broadcast_ssid "
1075 "configuration forced WPS to be disabled");
1079 if (full_config
&& bss
->wps_state
&&
1080 bss
->ssid
.wep
.keys_set
&& bss
->wpa
== 0) {
1081 wpa_printf(MSG_INFO
, "WPS: WEP configuration forced WPS to be "
1086 if (full_config
&& bss
->wps_state
&& bss
->wpa
&&
1088 !(bss
->rsn_pairwise
& (WPA_CIPHER_CCMP
| WPA_CIPHER_GCMP
|
1089 WPA_CIPHER_CCMP_256
|
1090 WPA_CIPHER_GCMP_256
)))) {
1091 wpa_printf(MSG_INFO
, "WPS: WPA/TKIP configuration without "
1092 "WPA2/CCMP/GCMP forced WPS to be disabled");
1095 #endif /* CONFIG_WPS */
1098 if (full_config
&& bss
->hs20
&&
1100 !(bss
->rsn_pairwise
& (WPA_CIPHER_CCMP
| WPA_CIPHER_GCMP
|
1101 WPA_CIPHER_CCMP_256
|
1102 WPA_CIPHER_GCMP_256
)))) {
1103 wpa_printf(MSG_ERROR
, "HS 2.0: WPA2-Enterprise/CCMP "
1104 "configuration is required for Hotspot 2.0 "
1108 #endif /* CONFIG_HS20 */
1111 if (full_config
&& bss
->mbo_enabled
&& (bss
->wpa
& 2) &&
1112 bss
->ieee80211w
== NO_MGMT_FRAME_PROTECTION
) {
1113 wpa_printf(MSG_ERROR
,
1114 "MBO: PMF needs to be enabled whenever using WPA2 with MBO");
1117 #endif /* CONFIG_MBO */
1120 if (full_config
&& bss
->ieee80211w
== NO_MGMT_FRAME_PROTECTION
&&
1122 wpa_printf(MSG_ERROR
,
1123 "OCV: PMF needs to be enabled whenever using OCV");
1126 #endif /* CONFIG_OCV */
1132 static int hostapd_config_check_cw(struct hostapd_config
*conf
, int queue
)
1134 int tx_cwmin
= conf
->tx_queue
[queue
].cwmin
;
1135 int tx_cwmax
= conf
->tx_queue
[queue
].cwmax
;
1136 int ac_cwmin
= conf
->wmm_ac_params
[queue
].cwmin
;
1137 int ac_cwmax
= conf
->wmm_ac_params
[queue
].cwmax
;
1139 if (tx_cwmin
> tx_cwmax
) {
1140 wpa_printf(MSG_ERROR
,
1141 "Invalid TX queue cwMin/cwMax values. cwMin(%d) greater than cwMax(%d)",
1142 tx_cwmin
, tx_cwmax
);
1145 if (ac_cwmin
> ac_cwmax
) {
1146 wpa_printf(MSG_ERROR
,
1147 "Invalid WMM AC cwMin/cwMax values. cwMin(%d) greater than cwMax(%d)",
1148 ac_cwmin
, ac_cwmax
);
1155 int hostapd_config_check(struct hostapd_config
*conf
, int full_config
)
1159 if (full_config
&& conf
->ieee80211d
&&
1160 (!conf
->country
[0] || !conf
->country
[1])) {
1161 wpa_printf(MSG_ERROR
, "Cannot enable IEEE 802.11d without "
1162 "setting the country_code");
1166 if (full_config
&& conf
->ieee80211h
&& !conf
->ieee80211d
) {
1167 wpa_printf(MSG_ERROR
, "Cannot enable IEEE 802.11h without "
1168 "IEEE 802.11d enabled");
1172 if (full_config
&& conf
->local_pwr_constraint
!= -1 &&
1173 !conf
->ieee80211d
) {
1174 wpa_printf(MSG_ERROR
, "Cannot add Power Constraint element without Country element");
1178 if (full_config
&& conf
->spectrum_mgmt_required
&&
1179 conf
->local_pwr_constraint
== -1) {
1180 wpa_printf(MSG_ERROR
, "Cannot set Spectrum Management bit without Country and Power Constraint elements");
1184 #ifdef CONFIG_AIRTIME_POLICY
1185 if (full_config
&& conf
->airtime_mode
> AIRTIME_MODE_STATIC
&&
1186 !conf
->airtime_update_interval
) {
1187 wpa_printf(MSG_ERROR
, "Airtime update interval cannot be zero");
1190 #endif /* CONFIG_AIRTIME_POLICY */
1191 for (i
= 0; i
< NUM_TX_QUEUES
; i
++) {
1192 if (hostapd_config_check_cw(conf
, i
))
1196 for (i
= 0; i
< conf
->num_bss
; i
++) {
1197 if (hostapd_config_check_bss(conf
->bss
[i
], conf
, full_config
))
1205 void hostapd_set_security_params(struct hostapd_bss_config
*bss
,
1208 if (bss
->individual_wep_key_len
== 0) {
1209 /* individual keys are not use; can use key idx0 for
1211 bss
->broadcast_key_idx_min
= 0;
1214 if ((bss
->wpa
& 2) && bss
->rsn_pairwise
== 0)
1215 bss
->rsn_pairwise
= bss
->wpa_pairwise
;
1216 if (bss
->group_cipher
)
1217 bss
->wpa_group
= bss
->group_cipher
;
1219 bss
->wpa_group
= wpa_select_ap_group_cipher(bss
->wpa
,
1222 if (!bss
->wpa_group_rekey_set
)
1223 bss
->wpa_group_rekey
= bss
->wpa_group
== WPA_CIPHER_TKIP
?
1227 bss
->radius
->auth_server
= bss
->radius
->auth_servers
;
1228 bss
->radius
->acct_server
= bss
->radius
->acct_servers
;
1231 if (bss
->wpa
&& bss
->ieee802_1x
) {
1232 bss
->ssid
.security_policy
= SECURITY_WPA
;
1233 } else if (bss
->wpa
) {
1234 bss
->ssid
.security_policy
= SECURITY_WPA_PSK
;
1235 } else if (bss
->ieee802_1x
) {
1236 int cipher
= WPA_CIPHER_NONE
;
1237 bss
->ssid
.security_policy
= SECURITY_IEEE_802_1X
;
1238 bss
->ssid
.wep
.default_len
= bss
->default_wep_key_len
;
1239 if (full_config
&& bss
->default_wep_key_len
) {
1240 cipher
= bss
->default_wep_key_len
>= 13 ?
1241 WPA_CIPHER_WEP104
: WPA_CIPHER_WEP40
;
1242 } else if (full_config
&& bss
->ssid
.wep
.keys_set
) {
1243 if (bss
->ssid
.wep
.len
[0] >= 13)
1244 cipher
= WPA_CIPHER_WEP104
;
1246 cipher
= WPA_CIPHER_WEP40
;
1248 bss
->wpa_group
= cipher
;
1249 bss
->wpa_pairwise
= cipher
;
1250 bss
->rsn_pairwise
= cipher
;
1252 bss
->wpa_key_mgmt
= WPA_KEY_MGMT_IEEE8021X_NO_WPA
;
1253 } else if (bss
->ssid
.wep
.keys_set
) {
1254 int cipher
= WPA_CIPHER_WEP40
;
1255 if (bss
->ssid
.wep
.len
[0] >= 13)
1256 cipher
= WPA_CIPHER_WEP104
;
1257 bss
->ssid
.security_policy
= SECURITY_STATIC_WEP
;
1258 bss
->wpa_group
= cipher
;
1259 bss
->wpa_pairwise
= cipher
;
1260 bss
->rsn_pairwise
= cipher
;
1262 bss
->wpa_key_mgmt
= WPA_KEY_MGMT_NONE
;
1263 } else if (bss
->osen
) {
1264 bss
->ssid
.security_policy
= SECURITY_OSEN
;
1265 bss
->wpa_group
= WPA_CIPHER_CCMP
;
1266 bss
->wpa_pairwise
= 0;
1267 bss
->rsn_pairwise
= WPA_CIPHER_CCMP
;
1269 bss
->ssid
.security_policy
= SECURITY_PLAINTEXT
;
1271 bss
->wpa_group
= WPA_CIPHER_NONE
;
1272 bss
->wpa_pairwise
= WPA_CIPHER_NONE
;
1273 bss
->rsn_pairwise
= WPA_CIPHER_NONE
;
1274 bss
->wpa_key_mgmt
= WPA_KEY_MGMT_NONE
;
1280 int hostapd_sae_pw_id_in_use(struct hostapd_bss_config
*conf
)
1282 int with_id
= 0, without_id
= 0;
1283 struct sae_password_entry
*pw
;
1285 if (conf
->ssid
.wpa_passphrase
)
1288 for (pw
= conf
->sae_passwords
; pw
; pw
= pw
->next
) {
1293 if (with_id
&& without_id
)
1297 if (with_id
&& !without_id
)