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 "ap_config.h"
25 static void hostapd_config_free_vlan(struct hostapd_bss_config
*bss
)
27 struct hostapd_vlan
*vlan
, *prev
;
41 #ifndef DEFAULT_WPA_DISABLE_EAPOL_KEY_RETRIES
42 #define DEFAULT_WPA_DISABLE_EAPOL_KEY_RETRIES 0
43 #endif /* DEFAULT_WPA_DISABLE_EAPOL_KEY_RETRIES */
45 void hostapd_config_defaults_bss(struct hostapd_bss_config
*bss
)
47 dl_list_init(&bss
->anqp_elem
);
49 bss
->logger_syslog_level
= HOSTAPD_LEVEL_INFO
;
50 bss
->logger_stdout_level
= HOSTAPD_LEVEL_INFO
;
51 bss
->logger_syslog
= (unsigned int) -1;
52 bss
->logger_stdout
= (unsigned int) -1;
54 bss
->auth_algs
= WPA_AUTH_ALG_OPEN
| WPA_AUTH_ALG_SHARED
;
56 bss
->wep_rekeying_period
= 300;
57 /* use key0 in individual key and key1 in broadcast key */
58 bss
->broadcast_key_idx_min
= 1;
59 bss
->broadcast_key_idx_max
= 2;
60 bss
->eap_reauth_period
= 3600;
62 bss
->wpa_group_rekey
= 600;
63 bss
->wpa_gmk_rekey
= 86400;
64 bss
->wpa_group_update_count
= 4;
65 bss
->wpa_pairwise_update_count
= 4;
66 bss
->wpa_disable_eapol_key_retries
=
67 DEFAULT_WPA_DISABLE_EAPOL_KEY_RETRIES
;
68 bss
->wpa_key_mgmt
= WPA_KEY_MGMT_PSK
;
69 bss
->wpa_pairwise
= WPA_CIPHER_TKIP
;
70 bss
->wpa_group
= WPA_CIPHER_TKIP
;
71 bss
->rsn_pairwise
= 0;
73 bss
->max_num_sta
= MAX_STA_COUNT
;
77 bss
->radius_server_auth_port
= 1812;
78 bss
->eap_sim_db_timeout
= 1;
79 bss
->ap_max_inactivity
= AP_MAX_INACTIVITY
;
80 bss
->eapol_version
= EAPOL_VERSION
;
82 bss
->max_listen_interval
= 65535;
84 bss
->pwd_group
= 19; /* ECC: GF(p=256) */
86 #ifdef CONFIG_IEEE80211W
87 bss
->assoc_sa_query_max_timeout
= 1000;
88 bss
->assoc_sa_query_retry_timeout
= 201;
89 bss
->group_mgmt_cipher
= WPA_CIPHER_AES_128_CMAC
;
90 #endif /* CONFIG_IEEE80211W */
91 #ifdef EAP_SERVER_FAST
92 /* both anonymous and authenticated provisioning */
93 bss
->eap_fast_prov
= 3;
94 bss
->pac_key_lifetime
= 7 * 24 * 60 * 60;
95 bss
->pac_key_refresh_time
= 1 * 24 * 60 * 60;
96 #endif /* EAP_SERVER_FAST */
98 /* Set to -1 as defaults depends on HT in setup */
99 bss
->wmm_enabled
= -1;
101 #ifdef CONFIG_IEEE80211R_AP
103 bss
->rkh_pos_timeout
= 86400;
104 bss
->rkh_neg_timeout
= 60;
105 bss
->rkh_pull_timeout
= 1000;
106 bss
->rkh_pull_retries
= 4;
107 bss
->r0_key_lifetime
= 1209600;
108 #endif /* CONFIG_IEEE80211R_AP */
110 bss
->radius_das_time_window
= 300;
112 bss
->sae_anti_clogging_threshold
= 5;
115 bss
->gas_frag_limit
= 1400;
118 dl_list_init(&bss
->fils_realms
);
119 bss
->fils_hlp_wait_time
= 30;
120 bss
->dhcp_server_port
= DHCP_SERVER_PORT
;
121 bss
->dhcp_relay_port
= DHCP_SERVER_PORT
;
122 #endif /* CONFIG_FILS */
124 bss
->broadcast_deauth
= 1;
127 bss
->mbo_cell_data_conn_pref
= -1;
128 #endif /* CONFIG_MBO */
130 /* Disable TLS v1.3 by default for now to avoid interoperability issue.
131 * This can be enabled by default once the implementation has been fully
132 * completed and tested with other implementations. */
133 bss
->tls_flags
= TLS_CONN_DISABLE_TLSv1_3
;
135 bss
->send_probe_response
= 1;
138 bss
->hs20_release
= (HS20_VERSION
>> 4) + 1;
139 #endif /* CONFIG_HS20 */
141 /* Default to strict CRL checking. */
142 bss
->check_crl_strict
= 1;
146 struct hostapd_config
* hostapd_config_defaults(void)
148 #define ecw2cw(ecw) ((1 << (ecw)) - 1)
150 struct hostapd_config
*conf
;
151 struct hostapd_bss_config
*bss
;
152 const int aCWmin
= 4, aCWmax
= 10;
153 const struct hostapd_wmm_ac_params ac_bk
=
154 { aCWmin
, aCWmax
, 7, 0, 0 }; /* background traffic */
155 const struct hostapd_wmm_ac_params ac_be
=
156 { aCWmin
, aCWmax
, 3, 0, 0 }; /* best effort traffic */
157 const struct hostapd_wmm_ac_params ac_vi
= /* video traffic */
158 { aCWmin
- 1, aCWmin
, 2, 3008 / 32, 0 };
159 const struct hostapd_wmm_ac_params ac_vo
= /* voice traffic */
160 { aCWmin
- 2, aCWmin
- 1, 2, 1504 / 32, 0 };
161 const struct hostapd_tx_queue_params txq_bk
=
162 { 7, ecw2cw(aCWmin
), ecw2cw(aCWmax
), 0 };
163 const struct hostapd_tx_queue_params txq_be
=
164 { 3, ecw2cw(aCWmin
), 4 * (ecw2cw(aCWmin
) + 1) - 1, 0};
165 const struct hostapd_tx_queue_params txq_vi
=
166 { 1, (ecw2cw(aCWmin
) + 1) / 2 - 1, ecw2cw(aCWmin
), 30};
167 const struct hostapd_tx_queue_params txq_vo
=
168 { 1, (ecw2cw(aCWmin
) + 1) / 4 - 1,
169 (ecw2cw(aCWmin
) + 1) / 2 - 1, 15};
173 conf
= os_zalloc(sizeof(*conf
));
174 bss
= os_zalloc(sizeof(*bss
));
175 if (conf
== NULL
|| bss
== NULL
) {
176 wpa_printf(MSG_ERROR
, "Failed to allocate memory for "
177 "configuration data.");
182 conf
->bss
= os_calloc(1, sizeof(struct hostapd_bss_config
*));
183 if (conf
->bss
== NULL
) {
190 bss
->radius
= os_zalloc(sizeof(*bss
->radius
));
191 if (bss
->radius
== NULL
) {
198 hostapd_config_defaults_bss(bss
);
202 conf
->beacon_int
= 100;
203 conf
->rts_threshold
= -1; /* use driver default: 2347 */
204 conf
->fragm_threshold
= -1; /* user driver default: 2346 */
205 /* Set to invalid value means do not add Power Constraint IE */
206 conf
->local_pwr_constraint
= -1;
208 conf
->wmm_ac_params
[0] = ac_be
;
209 conf
->wmm_ac_params
[1] = ac_bk
;
210 conf
->wmm_ac_params
[2] = ac_vi
;
211 conf
->wmm_ac_params
[3] = ac_vo
;
213 conf
->tx_queue
[0] = txq_vo
;
214 conf
->tx_queue
[1] = txq_vi
;
215 conf
->tx_queue
[2] = txq_be
;
216 conf
->tx_queue
[3] = txq_bk
;
218 conf
->ht_capab
= HT_CAP_INFO_SMPS_DISABLED
;
220 conf
->ap_table_max_size
= 255;
221 conf
->ap_table_expiration_time
= 60;
222 conf
->track_sta_max_age
= 180;
224 #ifdef CONFIG_TESTING_OPTIONS
225 conf
->ignore_probe_probability
= 0.0;
226 conf
->ignore_auth_probability
= 0.0;
227 conf
->ignore_assoc_probability
= 0.0;
228 conf
->ignore_reassoc_probability
= 0.0;
229 conf
->corrupt_gtk_rekey_mic_probability
= 0.0;
230 conf
->ecsa_ie_only
= 0;
231 #endif /* CONFIG_TESTING_OPTIONS */
234 conf
->acs_ch_list
.num
= 0;
236 conf
->acs_num_scans
= 5;
237 #endif /* CONFIG_ACS */
239 /* The third octet of the country string uses an ASCII space character
240 * by default to indicate that the regulations encompass all
241 * environments for the current frequency band in the country. */
242 conf
->country
[2] = ' ';
244 conf
->rssi_reject_assoc_rssi
= 0;
245 conf
->rssi_reject_assoc_timeout
= 30;
251 int hostapd_mac_comp(const void *a
, const void *b
)
253 return os_memcmp(a
, b
, sizeof(macaddr
));
257 static int hostapd_config_read_wpa_psk(const char *fname
,
258 struct hostapd_ssid
*ssid
)
268 int line
= 0, ret
= 0, len
, ok
;
270 struct hostapd_wpa_psk
*psk
;
275 f
= fopen(fname
, "r");
277 wpa_printf(MSG_ERROR
, "WPA PSK file '%s' not found.", fname
);
281 while (fgets(buf
, sizeof(buf
), f
)) {
289 while (*pos
!= '\0') {
301 while ((token
= str_token(buf
, " ", &context
))) {
302 if (!os_strchr(token
, '='))
305 name
= str_token(token
, "=", &context2
);
306 value
= str_token(token
, "", &context2
);
309 if (!os_strcmp(name
, "keyid")) {
311 } else if (!os_strcmp(name
, "vlanid")) {
312 vlan_id
= atoi(value
);
314 wpa_printf(MSG_ERROR
,
315 "Unrecognized '%s=%s' on line %d in '%s'",
316 name
, value
, line
, fname
);
327 if (hwaddr_aton(token
, addr
)) {
328 wpa_printf(MSG_ERROR
, "Invalid MAC address '%s' on "
329 "line %d in '%s'", token
, line
, fname
);
334 psk
= os_zalloc(sizeof(*psk
));
336 wpa_printf(MSG_ERROR
, "WPA PSK allocation failed");
340 psk
->vlan_id
= vlan_id
;
341 if (is_zero_ether_addr(addr
))
344 os_memcpy(psk
->addr
, addr
, ETH_ALEN
);
346 pos
= str_token(buf
, "", &context
);
348 wpa_printf(MSG_ERROR
, "No PSK on line %d in '%s'",
356 len
= os_strlen(pos
);
357 if (len
== 64 && hexstr2bin(pos
, psk
->psk
, PMK_LEN
) == 0)
359 else if (len
>= 8 && len
< 64) {
360 pbkdf2_sha1(pos
, ssid
->ssid
, ssid
->ssid_len
,
361 4096, psk
->psk
, PMK_LEN
);
365 wpa_printf(MSG_ERROR
, "Invalid PSK '%s' on line %d in "
366 "'%s'", pos
, line
, fname
);
373 len
= os_strlcpy(psk
->keyid
, keyid
, sizeof(psk
->keyid
));
374 if ((size_t) len
>= sizeof(psk
->keyid
)) {
375 wpa_printf(MSG_ERROR
,
376 "PSK keyid too long on line %d in '%s'",
384 psk
->next
= ssid
->wpa_psk
;
394 static int hostapd_derive_psk(struct hostapd_ssid
*ssid
)
396 ssid
->wpa_psk
= os_zalloc(sizeof(struct hostapd_wpa_psk
));
397 if (ssid
->wpa_psk
== NULL
) {
398 wpa_printf(MSG_ERROR
, "Unable to alloc space for PSK");
401 wpa_hexdump_ascii(MSG_DEBUG
, "SSID",
402 (u8
*) ssid
->ssid
, ssid
->ssid_len
);
403 wpa_hexdump_ascii_key(MSG_DEBUG
, "PSK (ASCII passphrase)",
404 (u8
*) ssid
->wpa_passphrase
,
405 os_strlen(ssid
->wpa_passphrase
));
406 pbkdf2_sha1(ssid
->wpa_passphrase
,
407 ssid
->ssid
, ssid
->ssid_len
,
408 4096, ssid
->wpa_psk
->psk
, PMK_LEN
);
409 wpa_hexdump_key(MSG_DEBUG
, "PSK (from passphrase)",
410 ssid
->wpa_psk
->psk
, PMK_LEN
);
415 int hostapd_setup_wpa_psk(struct hostapd_bss_config
*conf
)
417 struct hostapd_ssid
*ssid
= &conf
->ssid
;
419 if (ssid
->wpa_passphrase
!= NULL
) {
420 if (ssid
->wpa_psk
!= NULL
) {
421 wpa_printf(MSG_DEBUG
, "Using pre-configured WPA PSK "
422 "instead of passphrase");
424 wpa_printf(MSG_DEBUG
, "Deriving WPA PSK based on "
426 if (hostapd_derive_psk(ssid
) < 0)
429 ssid
->wpa_psk
->group
= 1;
432 return hostapd_config_read_wpa_psk(ssid
->wpa_psk_file
, &conf
->ssid
);
436 static void hostapd_config_free_radius(struct hostapd_radius_server
*servers
,
441 for (i
= 0; i
< num_servers
; i
++) {
442 os_free(servers
[i
].shared_secret
);
448 struct hostapd_radius_attr
*
449 hostapd_config_get_radius_attr(struct hostapd_radius_attr
*attr
, u8 type
)
451 for (; attr
; attr
= attr
->next
) {
452 if (attr
->type
== type
)
459 static void hostapd_config_free_radius_attr(struct hostapd_radius_attr
*attr
)
461 struct hostapd_radius_attr
*prev
;
466 wpabuf_free(prev
->val
);
472 void hostapd_config_free_eap_user(struct hostapd_eap_user
*user
)
474 hostapd_config_free_radius_attr(user
->accept_attr
);
475 os_free(user
->identity
);
476 bin_clear_free(user
->password
, user
->password_len
);
477 bin_clear_free(user
->salt
, user
->salt_len
);
482 void hostapd_config_free_eap_users(struct hostapd_eap_user
*user
)
484 struct hostapd_eap_user
*prev_user
;
489 hostapd_config_free_eap_user(prev_user
);
494 static void hostapd_config_free_wep(struct hostapd_wep_keys
*keys
)
497 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
498 bin_clear_free(keys
->key
[i
], keys
->len
[i
]);
504 void hostapd_config_clear_wpa_psk(struct hostapd_wpa_psk
**l
)
506 struct hostapd_wpa_psk
*psk
, *tmp
;
508 for (psk
= *l
; psk
;) {
511 bin_clear_free(tmp
, sizeof(*tmp
));
517 static void hostapd_config_free_anqp_elem(struct hostapd_bss_config
*conf
)
519 struct anqp_element
*elem
;
521 while ((elem
= dl_list_first(&conf
->anqp_elem
, struct anqp_element
,
523 dl_list_del(&elem
->list
);
524 wpabuf_free(elem
->payload
);
530 static void hostapd_config_free_fils_realms(struct hostapd_bss_config
*conf
)
533 struct fils_realm
*realm
;
535 while ((realm
= dl_list_first(&conf
->fils_realms
, struct fils_realm
,
537 dl_list_del(&realm
->list
);
540 #endif /* CONFIG_FILS */
544 static void hostapd_config_free_sae_passwords(struct hostapd_bss_config
*conf
)
546 struct sae_password_entry
*pw
, *tmp
;
548 pw
= conf
->sae_passwords
;
549 conf
->sae_passwords
= NULL
;
553 str_clear_free(tmp
->password
);
554 os_free(tmp
->identifier
);
560 void hostapd_config_free_bss(struct hostapd_bss_config
*conf
)
565 hostapd_config_clear_wpa_psk(&conf
->ssid
.wpa_psk
);
567 str_clear_free(conf
->ssid
.wpa_passphrase
);
568 os_free(conf
->ssid
.wpa_psk_file
);
569 hostapd_config_free_wep(&conf
->ssid
.wep
);
570 #ifdef CONFIG_FULL_DYNAMIC_VLAN
571 os_free(conf
->ssid
.vlan_tagged_interface
);
572 #endif /* CONFIG_FULL_DYNAMIC_VLAN */
574 hostapd_config_free_eap_users(conf
->eap_user
);
575 os_free(conf
->eap_user_sqlite
);
577 os_free(conf
->eap_req_id_text
);
578 os_free(conf
->erp_domain
);
579 os_free(conf
->accept_mac
);
580 os_free(conf
->deny_mac
);
581 os_free(conf
->nas_identifier
);
583 hostapd_config_free_radius(conf
->radius
->auth_servers
,
584 conf
->radius
->num_auth_servers
);
585 hostapd_config_free_radius(conf
->radius
->acct_servers
,
586 conf
->radius
->num_acct_servers
);
588 hostapd_config_free_radius_attr(conf
->radius_auth_req_attr
);
589 hostapd_config_free_radius_attr(conf
->radius_acct_req_attr
);
590 os_free(conf
->rsn_preauth_interfaces
);
591 os_free(conf
->ctrl_interface
);
592 os_free(conf
->ca_cert
);
593 os_free(conf
->server_cert
);
594 os_free(conf
->private_key
);
595 os_free(conf
->private_key_passwd
);
596 os_free(conf
->ocsp_stapling_response
);
597 os_free(conf
->ocsp_stapling_response_multi
);
598 os_free(conf
->dh_file
);
599 os_free(conf
->openssl_ciphers
);
600 os_free(conf
->openssl_ecdh_curves
);
601 os_free(conf
->pac_opaque_encr_key
);
602 os_free(conf
->eap_fast_a_id
);
603 os_free(conf
->eap_fast_a_id_info
);
604 os_free(conf
->eap_sim_db
);
605 os_free(conf
->radius_server_clients
);
606 os_free(conf
->radius
);
607 os_free(conf
->radius_das_shared_secret
);
608 hostapd_config_free_vlan(conf
);
609 os_free(conf
->time_zone
);
611 #ifdef CONFIG_IEEE80211R_AP
613 struct ft_remote_r0kh
*r0kh
, *r0kh_prev
;
614 struct ft_remote_r1kh
*r1kh
, *r1kh_prev
;
616 r0kh
= conf
->r0kh_list
;
617 conf
->r0kh_list
= NULL
;
624 r1kh
= conf
->r1kh_list
;
625 conf
->r1kh_list
= NULL
;
632 #endif /* CONFIG_IEEE80211R_AP */
635 os_free(conf
->wps_pin_requests
);
636 os_free(conf
->device_name
);
637 os_free(conf
->manufacturer
);
638 os_free(conf
->model_name
);
639 os_free(conf
->model_number
);
640 os_free(conf
->serial_number
);
641 os_free(conf
->config_methods
);
642 os_free(conf
->ap_pin
);
643 os_free(conf
->extra_cred
);
644 os_free(conf
->ap_settings
);
645 os_free(conf
->upnp_iface
);
646 os_free(conf
->friendly_name
);
647 os_free(conf
->manufacturer_url
);
648 os_free(conf
->model_description
);
649 os_free(conf
->model_url
);
654 for (i
= 0; i
< MAX_WPS_VENDOR_EXTENSIONS
; i
++)
655 wpabuf_free(conf
->wps_vendor_ext
[i
]);
657 wpabuf_free(conf
->wps_nfc_dh_pubkey
);
658 wpabuf_free(conf
->wps_nfc_dh_privkey
);
659 wpabuf_free(conf
->wps_nfc_dev_pw
);
660 #endif /* CONFIG_WPS */
662 os_free(conf
->roaming_consortium
);
663 os_free(conf
->venue_name
);
664 os_free(conf
->venue_url
);
665 os_free(conf
->nai_realm_data
);
666 os_free(conf
->network_auth_type
);
667 os_free(conf
->anqp_3gpp_cell_net
);
668 os_free(conf
->domain_name
);
669 hostapd_config_free_anqp_elem(conf
);
671 #ifdef CONFIG_RADIUS_TEST
672 os_free(conf
->dump_msk_file
);
673 #endif /* CONFIG_RADIUS_TEST */
676 os_free(conf
->hs20_oper_friendly_name
);
677 os_free(conf
->hs20_wan_metrics
);
678 os_free(conf
->hs20_connection_capability
);
679 os_free(conf
->hs20_operating_class
);
680 os_free(conf
->hs20_icons
);
681 if (conf
->hs20_osu_providers
) {
683 for (i
= 0; i
< conf
->hs20_osu_providers_count
; i
++) {
684 struct hs20_osu_provider
*p
;
686 p
= &conf
->hs20_osu_providers
[i
];
687 os_free(p
->friendly_name
);
688 os_free(p
->server_uri
);
689 os_free(p
->method_list
);
690 for (j
= 0; j
< p
->icons_count
; j
++)
691 os_free(p
->icons
[j
]);
694 os_free(p
->osu_nai2
);
695 os_free(p
->service_desc
);
697 os_free(conf
->hs20_osu_providers
);
699 if (conf
->hs20_operator_icon
) {
702 for (i
= 0; i
< conf
->hs20_operator_icon_count
; i
++)
703 os_free(conf
->hs20_operator_icon
[i
]);
704 os_free(conf
->hs20_operator_icon
);
706 os_free(conf
->subscr_remediation_url
);
707 os_free(conf
->hs20_sim_provisioning_url
);
708 os_free(conf
->t_c_filename
);
709 os_free(conf
->t_c_server_url
);
710 #endif /* CONFIG_HS20 */
712 wpabuf_free(conf
->vendor_elements
);
713 wpabuf_free(conf
->assocresp_elements
);
715 os_free(conf
->sae_groups
);
717 os_free(conf
->owe_groups
);
718 #endif /* CONFIG_OWE */
720 os_free(conf
->wowlan_triggers
);
722 os_free(conf
->server_id
);
724 #ifdef CONFIG_TESTING_OPTIONS
725 wpabuf_free(conf
->own_ie_override
);
726 wpabuf_free(conf
->sae_commit_override
);
727 #endif /* CONFIG_TESTING_OPTIONS */
729 os_free(conf
->no_probe_resp_if_seen_on
);
730 os_free(conf
->no_auth_if_seen_on
);
732 hostapd_config_free_fils_realms(conf
);
735 os_free(conf
->dpp_connector
);
736 wpabuf_free(conf
->dpp_netaccesskey
);
737 wpabuf_free(conf
->dpp_csign
);
738 #endif /* CONFIG_DPP */
740 hostapd_config_free_sae_passwords(conf
);
747 * hostapd_config_free - Free hostapd configuration
748 * @conf: Configuration data from hostapd_config_read().
750 void hostapd_config_free(struct hostapd_config
*conf
)
757 for (i
= 0; i
< conf
->num_bss
; i
++)
758 hostapd_config_free_bss(conf
->bss
[i
]);
760 os_free(conf
->supported_rates
);
761 os_free(conf
->basic_rates
);
762 os_free(conf
->acs_ch_list
.range
);
763 os_free(conf
->driver_params
);
765 os_free(conf
->acs_chan_bias
);
766 #endif /* CONFIG_ACS */
767 wpabuf_free(conf
->lci
);
768 wpabuf_free(conf
->civic
);
775 * hostapd_maclist_found - Find a MAC address from a list
776 * @list: MAC address list
777 * @num_entries: Number of addresses in the list
778 * @addr: Address to search for
779 * @vlan_id: Buffer for returning VLAN ID or %NULL if not needed
780 * Returns: 1 if address is in the list or 0 if not.
782 * Perform a binary search for given MAC address from a pre-sorted list.
784 int hostapd_maclist_found(struct mac_acl_entry
*list
, int num_entries
,
785 const u8
*addr
, struct vlan_description
*vlan_id
)
787 int start
, end
, middle
, res
;
790 end
= num_entries
- 1;
792 while (start
<= end
) {
793 middle
= (start
+ end
) / 2;
794 res
= os_memcmp(list
[middle
].addr
, addr
, ETH_ALEN
);
797 *vlan_id
= list
[middle
].vlan_id
;
810 int hostapd_rate_found(int *list
, int rate
)
817 for (i
= 0; list
[i
] >= 0; i
++)
825 int hostapd_vlan_valid(struct hostapd_vlan
*vlan
,
826 struct vlan_description
*vlan_desc
)
828 struct hostapd_vlan
*v
= vlan
;
831 if (!vlan_desc
->notempty
|| vlan_desc
->untagged
< 0 ||
832 vlan_desc
->untagged
> MAX_VLAN_ID
)
834 for (i
= 0; i
< MAX_NUM_TAGGED_VLAN
; i
++) {
835 if (vlan_desc
->tagged
[i
] < 0 ||
836 vlan_desc
->tagged
[i
] > MAX_VLAN_ID
)
839 if (!vlan_desc
->untagged
&& !vlan_desc
->tagged
[0])
843 if (!vlan_compare(&v
->vlan_desc
, vlan_desc
) ||
844 v
->vlan_id
== VLAN_ID_WILDCARD
)
852 const char * hostapd_get_vlan_id_ifname(struct hostapd_vlan
*vlan
, int vlan_id
)
854 struct hostapd_vlan
*v
= vlan
;
856 if (v
->vlan_id
== vlan_id
)
864 const u8
* hostapd_get_psk(const struct hostapd_bss_config
*conf
,
865 const u8
*addr
, const u8
*p2p_dev_addr
,
866 const u8
*prev_psk
, int *vlan_id
)
868 struct hostapd_wpa_psk
*psk
;
869 int next_ok
= prev_psk
== NULL
;
874 if (p2p_dev_addr
&& !is_zero_ether_addr(p2p_dev_addr
)) {
875 wpa_printf(MSG_DEBUG
, "Searching a PSK for " MACSTR
876 " p2p_dev_addr=" MACSTR
" prev_psk=%p",
877 MAC2STR(addr
), MAC2STR(p2p_dev_addr
), prev_psk
);
878 addr
= NULL
; /* Use P2P Device Address for matching */
880 wpa_printf(MSG_DEBUG
, "Searching a PSK for " MACSTR
882 MAC2STR(addr
), prev_psk
);
885 for (psk
= conf
->ssid
.wpa_psk
; psk
!= NULL
; psk
= psk
->next
) {
888 (addr
&& os_memcmp(psk
->addr
, addr
, ETH_ALEN
) == 0) ||
889 (!addr
&& p2p_dev_addr
&&
890 os_memcmp(psk
->p2p_dev_addr
, p2p_dev_addr
, ETH_ALEN
) ==
893 *vlan_id
= psk
->vlan_id
;
897 if (psk
->psk
== prev_psk
)
905 static int hostapd_config_check_bss(struct hostapd_bss_config
*bss
,
906 struct hostapd_config
*conf
,
909 if (full_config
&& bss
->ieee802_1x
&& !bss
->eap_server
&&
910 !bss
->radius
->auth_servers
) {
911 wpa_printf(MSG_ERROR
, "Invalid IEEE 802.1X configuration (no "
912 "EAP authenticator configured).");
919 wep
= bss
->default_wep_key_len
> 0 ||
920 bss
->individual_wep_key_len
> 0;
921 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
922 if (bss
->ssid
.wep
.keys_set
) {
929 wpa_printf(MSG_ERROR
, "WEP configuration in a WPA network is not supported");
934 if (full_config
&& bss
->wpa
&&
935 bss
->wpa_psk_radius
!= PSK_RADIUS_IGNORED
&&
936 bss
->macaddr_acl
!= USE_EXTERNAL_RADIUS_AUTH
) {
937 wpa_printf(MSG_ERROR
, "WPA-PSK using RADIUS enabled, but no "
938 "RADIUS checking (macaddr_acl=2) enabled.");
942 if (full_config
&& bss
->wpa
&& (bss
->wpa_key_mgmt
& WPA_KEY_MGMT_PSK
) &&
943 bss
->ssid
.wpa_psk
== NULL
&& bss
->ssid
.wpa_passphrase
== NULL
&&
944 bss
->ssid
.wpa_psk_file
== NULL
&&
945 (bss
->wpa_psk_radius
!= PSK_RADIUS_REQUIRED
||
946 bss
->macaddr_acl
!= USE_EXTERNAL_RADIUS_AUTH
)) {
947 wpa_printf(MSG_ERROR
, "WPA-PSK enabled, but PSK or passphrase "
948 "is not configured.");
952 if (full_config
&& !is_zero_ether_addr(bss
->bssid
)) {
955 for (i
= 0; i
< conf
->num_bss
; i
++) {
956 if (conf
->bss
[i
] != bss
&&
957 (hostapd_mac_comp(conf
->bss
[i
]->bssid
,
959 wpa_printf(MSG_ERROR
, "Duplicate BSSID " MACSTR
960 " on interface '%s' and '%s'.",
962 conf
->bss
[i
]->iface
, bss
->iface
);
968 #ifdef CONFIG_IEEE80211R_AP
969 if (full_config
&& wpa_key_mgmt_ft(bss
->wpa_key_mgmt
) &&
970 (bss
->nas_identifier
== NULL
||
971 os_strlen(bss
->nas_identifier
) < 1 ||
972 os_strlen(bss
->nas_identifier
) > FT_R0KH_ID_MAX_LEN
)) {
973 wpa_printf(MSG_ERROR
, "FT (IEEE 802.11r) requires "
974 "nas_identifier to be configured as a 1..48 octet "
978 #endif /* CONFIG_IEEE80211R_AP */
980 #ifdef CONFIG_IEEE80211N
981 if (full_config
&& conf
->ieee80211n
&&
982 conf
->hw_mode
== HOSTAPD_MODE_IEEE80211B
) {
983 bss
->disable_11n
= 1;
984 wpa_printf(MSG_ERROR
, "HT (IEEE 802.11n) in 11b mode is not "
985 "allowed, disabling HT capabilities");
988 if (full_config
&& conf
->ieee80211n
&&
989 bss
->ssid
.security_policy
== SECURITY_STATIC_WEP
) {
990 bss
->disable_11n
= 1;
991 wpa_printf(MSG_ERROR
, "HT (IEEE 802.11n) with WEP is not "
992 "allowed, disabling HT capabilities");
995 if (full_config
&& conf
->ieee80211n
&& bss
->wpa
&&
996 !(bss
->wpa_pairwise
& WPA_CIPHER_CCMP
) &&
997 !(bss
->rsn_pairwise
& (WPA_CIPHER_CCMP
| WPA_CIPHER_GCMP
|
998 WPA_CIPHER_CCMP_256
| WPA_CIPHER_GCMP_256
)))
1000 bss
->disable_11n
= 1;
1001 wpa_printf(MSG_ERROR
, "HT (IEEE 802.11n) with WPA/WPA2 "
1002 "requires CCMP/GCMP to be enabled, disabling HT "
1005 #endif /* CONFIG_IEEE80211N */
1007 #ifdef CONFIG_IEEE80211AC
1008 if (full_config
&& conf
->ieee80211ac
&&
1009 bss
->ssid
.security_policy
== SECURITY_STATIC_WEP
) {
1010 bss
->disable_11ac
= 1;
1011 wpa_printf(MSG_ERROR
,
1012 "VHT (IEEE 802.11ac) with WEP is not allowed, disabling VHT capabilities");
1015 if (full_config
&& conf
->ieee80211ac
&& bss
->wpa
&&
1016 !(bss
->wpa_pairwise
& WPA_CIPHER_CCMP
) &&
1017 !(bss
->rsn_pairwise
& (WPA_CIPHER_CCMP
| WPA_CIPHER_GCMP
|
1018 WPA_CIPHER_CCMP_256
| WPA_CIPHER_GCMP_256
)))
1020 bss
->disable_11ac
= 1;
1021 wpa_printf(MSG_ERROR
,
1022 "VHT (IEEE 802.11ac) with WPA/WPA2 requires CCMP/GCMP to be enabled, disabling VHT capabilities");
1024 #endif /* CONFIG_IEEE80211AC */
1027 if (full_config
&& bss
->wps_state
&& bss
->ignore_broadcast_ssid
) {
1028 wpa_printf(MSG_INFO
, "WPS: ignore_broadcast_ssid "
1029 "configuration forced WPS to be disabled");
1033 if (full_config
&& bss
->wps_state
&&
1034 bss
->ssid
.wep
.keys_set
&& bss
->wpa
== 0) {
1035 wpa_printf(MSG_INFO
, "WPS: WEP configuration forced WPS to be "
1040 if (full_config
&& bss
->wps_state
&& bss
->wpa
&&
1042 !(bss
->rsn_pairwise
& (WPA_CIPHER_CCMP
| WPA_CIPHER_GCMP
|
1043 WPA_CIPHER_CCMP_256
|
1044 WPA_CIPHER_GCMP_256
)))) {
1045 wpa_printf(MSG_INFO
, "WPS: WPA/TKIP configuration without "
1046 "WPA2/CCMP/GCMP forced WPS to be disabled");
1049 #endif /* CONFIG_WPS */
1052 if (full_config
&& bss
->hs20
&&
1054 !(bss
->rsn_pairwise
& (WPA_CIPHER_CCMP
| WPA_CIPHER_GCMP
|
1055 WPA_CIPHER_CCMP_256
|
1056 WPA_CIPHER_GCMP_256
)))) {
1057 wpa_printf(MSG_ERROR
, "HS 2.0: WPA2-Enterprise/CCMP "
1058 "configuration is required for Hotspot 2.0 "
1062 #endif /* CONFIG_HS20 */
1065 if (full_config
&& bss
->mbo_enabled
&& (bss
->wpa
& 2) &&
1066 bss
->ieee80211w
== NO_MGMT_FRAME_PROTECTION
) {
1067 wpa_printf(MSG_ERROR
,
1068 "MBO: PMF needs to be enabled whenever using WPA2 with MBO");
1071 #endif /* CONFIG_MBO */
1074 if (full_config
&& bss
->ieee80211w
== NO_MGMT_FRAME_PROTECTION
&&
1076 wpa_printf(MSG_ERROR
,
1077 "OCV: PMF needs to be enabled whenever using OCV");
1080 #endif /* CONFIG_OCV */
1086 static int hostapd_config_check_cw(struct hostapd_config
*conf
, int queue
)
1088 int tx_cwmin
= conf
->tx_queue
[queue
].cwmin
;
1089 int tx_cwmax
= conf
->tx_queue
[queue
].cwmax
;
1090 int ac_cwmin
= conf
->wmm_ac_params
[queue
].cwmin
;
1091 int ac_cwmax
= conf
->wmm_ac_params
[queue
].cwmax
;
1093 if (tx_cwmin
> tx_cwmax
) {
1094 wpa_printf(MSG_ERROR
,
1095 "Invalid TX queue cwMin/cwMax values. cwMin(%d) greater than cwMax(%d)",
1096 tx_cwmin
, tx_cwmax
);
1099 if (ac_cwmin
> ac_cwmax
) {
1100 wpa_printf(MSG_ERROR
,
1101 "Invalid WMM AC cwMin/cwMax values. cwMin(%d) greater than cwMax(%d)",
1102 ac_cwmin
, ac_cwmax
);
1109 int hostapd_config_check(struct hostapd_config
*conf
, int full_config
)
1113 if (full_config
&& conf
->ieee80211d
&&
1114 (!conf
->country
[0] || !conf
->country
[1])) {
1115 wpa_printf(MSG_ERROR
, "Cannot enable IEEE 802.11d without "
1116 "setting the country_code");
1120 if (full_config
&& conf
->ieee80211h
&& !conf
->ieee80211d
) {
1121 wpa_printf(MSG_ERROR
, "Cannot enable IEEE 802.11h without "
1122 "IEEE 802.11d enabled");
1126 if (full_config
&& conf
->local_pwr_constraint
!= -1 &&
1127 !conf
->ieee80211d
) {
1128 wpa_printf(MSG_ERROR
, "Cannot add Power Constraint element without Country element");
1132 if (full_config
&& conf
->spectrum_mgmt_required
&&
1133 conf
->local_pwr_constraint
== -1) {
1134 wpa_printf(MSG_ERROR
, "Cannot set Spectrum Management bit without Country and Power Constraint elements");
1138 for (i
= 0; i
< NUM_TX_QUEUES
; i
++) {
1139 if (hostapd_config_check_cw(conf
, i
))
1143 for (i
= 0; i
< conf
->num_bss
; i
++) {
1144 if (hostapd_config_check_bss(conf
->bss
[i
], conf
, full_config
))
1152 void hostapd_set_security_params(struct hostapd_bss_config
*bss
,
1155 if (bss
->individual_wep_key_len
== 0) {
1156 /* individual keys are not use; can use key idx0 for
1158 bss
->broadcast_key_idx_min
= 0;
1161 if ((bss
->wpa
& 2) && bss
->rsn_pairwise
== 0)
1162 bss
->rsn_pairwise
= bss
->wpa_pairwise
;
1163 if (bss
->group_cipher
)
1164 bss
->wpa_group
= bss
->group_cipher
;
1166 bss
->wpa_group
= wpa_select_ap_group_cipher(bss
->wpa
,
1169 if (!bss
->wpa_group_rekey_set
)
1170 bss
->wpa_group_rekey
= bss
->wpa_group
== WPA_CIPHER_TKIP
?
1174 bss
->radius
->auth_server
= bss
->radius
->auth_servers
;
1175 bss
->radius
->acct_server
= bss
->radius
->acct_servers
;
1178 if (bss
->wpa
&& bss
->ieee802_1x
) {
1179 bss
->ssid
.security_policy
= SECURITY_WPA
;
1180 } else if (bss
->wpa
) {
1181 bss
->ssid
.security_policy
= SECURITY_WPA_PSK
;
1182 } else if (bss
->ieee802_1x
) {
1183 int cipher
= WPA_CIPHER_NONE
;
1184 bss
->ssid
.security_policy
= SECURITY_IEEE_802_1X
;
1185 bss
->ssid
.wep
.default_len
= bss
->default_wep_key_len
;
1186 if (full_config
&& bss
->default_wep_key_len
) {
1187 cipher
= bss
->default_wep_key_len
>= 13 ?
1188 WPA_CIPHER_WEP104
: WPA_CIPHER_WEP40
;
1189 } else if (full_config
&& bss
->ssid
.wep
.keys_set
) {
1190 if (bss
->ssid
.wep
.len
[0] >= 13)
1191 cipher
= WPA_CIPHER_WEP104
;
1193 cipher
= WPA_CIPHER_WEP40
;
1195 bss
->wpa_group
= cipher
;
1196 bss
->wpa_pairwise
= cipher
;
1197 bss
->rsn_pairwise
= cipher
;
1199 bss
->wpa_key_mgmt
= WPA_KEY_MGMT_IEEE8021X_NO_WPA
;
1200 } else if (bss
->ssid
.wep
.keys_set
) {
1201 int cipher
= WPA_CIPHER_WEP40
;
1202 if (bss
->ssid
.wep
.len
[0] >= 13)
1203 cipher
= WPA_CIPHER_WEP104
;
1204 bss
->ssid
.security_policy
= SECURITY_STATIC_WEP
;
1205 bss
->wpa_group
= cipher
;
1206 bss
->wpa_pairwise
= cipher
;
1207 bss
->rsn_pairwise
= cipher
;
1209 bss
->wpa_key_mgmt
= WPA_KEY_MGMT_NONE
;
1210 } else if (bss
->osen
) {
1211 bss
->ssid
.security_policy
= SECURITY_OSEN
;
1212 bss
->wpa_group
= WPA_CIPHER_CCMP
;
1213 bss
->wpa_pairwise
= 0;
1214 bss
->rsn_pairwise
= WPA_CIPHER_CCMP
;
1216 bss
->ssid
.security_policy
= SECURITY_PLAINTEXT
;
1218 bss
->wpa_group
= WPA_CIPHER_NONE
;
1219 bss
->wpa_pairwise
= WPA_CIPHER_NONE
;
1220 bss
->rsn_pairwise
= WPA_CIPHER_NONE
;
1221 bss
->wpa_key_mgmt
= WPA_KEY_MGMT_NONE
;
1227 int hostapd_sae_pw_id_in_use(struct hostapd_bss_config
*conf
)
1229 int with_id
= 0, without_id
= 0;
1230 struct sae_password_entry
*pw
;
1232 if (conf
->ssid
.wpa_passphrase
)
1235 for (pw
= conf
->sae_passwords
; pw
; pw
= pw
->next
) {
1240 if (with_id
&& without_id
)
1244 if (with_id
&& !without_id
)