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
;
137 struct hostapd_config
* hostapd_config_defaults(void)
139 #define ecw2cw(ecw) ((1 << (ecw)) - 1)
141 struct hostapd_config
*conf
;
142 struct hostapd_bss_config
*bss
;
143 const int aCWmin
= 4, aCWmax
= 10;
144 const struct hostapd_wmm_ac_params ac_bk
=
145 { aCWmin
, aCWmax
, 7, 0, 0 }; /* background traffic */
146 const struct hostapd_wmm_ac_params ac_be
=
147 { aCWmin
, aCWmax
, 3, 0, 0 }; /* best effort traffic */
148 const struct hostapd_wmm_ac_params ac_vi
= /* video traffic */
149 { aCWmin
- 1, aCWmin
, 2, 3008 / 32, 0 };
150 const struct hostapd_wmm_ac_params ac_vo
= /* voice traffic */
151 { aCWmin
- 2, aCWmin
- 1, 2, 1504 / 32, 0 };
152 const struct hostapd_tx_queue_params txq_bk
=
153 { 7, ecw2cw(aCWmin
), ecw2cw(aCWmax
), 0 };
154 const struct hostapd_tx_queue_params txq_be
=
155 { 3, ecw2cw(aCWmin
), 4 * (ecw2cw(aCWmin
) + 1) - 1, 0};
156 const struct hostapd_tx_queue_params txq_vi
=
157 { 1, (ecw2cw(aCWmin
) + 1) / 2 - 1, ecw2cw(aCWmin
), 30};
158 const struct hostapd_tx_queue_params txq_vo
=
159 { 1, (ecw2cw(aCWmin
) + 1) / 4 - 1,
160 (ecw2cw(aCWmin
) + 1) / 2 - 1, 15};
164 conf
= os_zalloc(sizeof(*conf
));
165 bss
= os_zalloc(sizeof(*bss
));
166 if (conf
== NULL
|| bss
== NULL
) {
167 wpa_printf(MSG_ERROR
, "Failed to allocate memory for "
168 "configuration data.");
173 conf
->bss
= os_calloc(1, sizeof(struct hostapd_bss_config
*));
174 if (conf
->bss
== NULL
) {
181 bss
->radius
= os_zalloc(sizeof(*bss
->radius
));
182 if (bss
->radius
== NULL
) {
189 hostapd_config_defaults_bss(bss
);
193 conf
->beacon_int
= 100;
194 conf
->rts_threshold
= -1; /* use driver default: 2347 */
195 conf
->fragm_threshold
= -1; /* user driver default: 2346 */
196 conf
->send_probe_response
= 1;
197 /* Set to invalid value means do not add Power Constraint IE */
198 conf
->local_pwr_constraint
= -1;
200 conf
->wmm_ac_params
[0] = ac_be
;
201 conf
->wmm_ac_params
[1] = ac_bk
;
202 conf
->wmm_ac_params
[2] = ac_vi
;
203 conf
->wmm_ac_params
[3] = ac_vo
;
205 conf
->tx_queue
[0] = txq_vo
;
206 conf
->tx_queue
[1] = txq_vi
;
207 conf
->tx_queue
[2] = txq_be
;
208 conf
->tx_queue
[3] = txq_bk
;
210 conf
->ht_capab
= HT_CAP_INFO_SMPS_DISABLED
;
212 conf
->ap_table_max_size
= 255;
213 conf
->ap_table_expiration_time
= 60;
214 conf
->track_sta_max_age
= 180;
216 #ifdef CONFIG_TESTING_OPTIONS
217 conf
->ignore_probe_probability
= 0.0;
218 conf
->ignore_auth_probability
= 0.0;
219 conf
->ignore_assoc_probability
= 0.0;
220 conf
->ignore_reassoc_probability
= 0.0;
221 conf
->corrupt_gtk_rekey_mic_probability
= 0.0;
222 conf
->ecsa_ie_only
= 0;
223 #endif /* CONFIG_TESTING_OPTIONS */
226 conf
->acs_ch_list
.num
= 0;
228 conf
->acs_num_scans
= 5;
229 #endif /* CONFIG_ACS */
231 /* The third octet of the country string uses an ASCII space character
232 * by default to indicate that the regulations encompass all
233 * environments for the current frequency band in the country. */
234 conf
->country
[2] = ' ';
240 int hostapd_mac_comp(const void *a
, const void *b
)
242 return os_memcmp(a
, b
, sizeof(macaddr
));
246 static int hostapd_config_read_wpa_psk(const char *fname
,
247 struct hostapd_ssid
*ssid
)
251 int line
= 0, ret
= 0, len
, ok
;
253 struct hostapd_wpa_psk
*psk
;
258 f
= fopen(fname
, "r");
260 wpa_printf(MSG_ERROR
, "WPA PSK file '%s' not found.", fname
);
264 while (fgets(buf
, sizeof(buf
), f
)) {
270 while (*pos
!= '\0') {
280 if (hwaddr_aton(buf
, addr
)) {
281 wpa_printf(MSG_ERROR
, "Invalid MAC address '%s' on "
282 "line %d in '%s'", buf
, line
, fname
);
287 psk
= os_zalloc(sizeof(*psk
));
289 wpa_printf(MSG_ERROR
, "WPA PSK allocation failed");
293 if (is_zero_ether_addr(addr
))
296 os_memcpy(psk
->addr
, addr
, ETH_ALEN
);
300 wpa_printf(MSG_ERROR
, "No PSK on line %d in '%s'",
309 len
= os_strlen(pos
);
310 if (len
== 64 && hexstr2bin(pos
, psk
->psk
, PMK_LEN
) == 0)
312 else if (len
>= 8 && len
< 64) {
313 pbkdf2_sha1(pos
, ssid
->ssid
, ssid
->ssid_len
,
314 4096, psk
->psk
, PMK_LEN
);
318 wpa_printf(MSG_ERROR
, "Invalid PSK '%s' on line %d in "
319 "'%s'", pos
, line
, fname
);
325 psk
->next
= ssid
->wpa_psk
;
335 static int hostapd_derive_psk(struct hostapd_ssid
*ssid
)
337 ssid
->wpa_psk
= os_zalloc(sizeof(struct hostapd_wpa_psk
));
338 if (ssid
->wpa_psk
== NULL
) {
339 wpa_printf(MSG_ERROR
, "Unable to alloc space for PSK");
342 wpa_hexdump_ascii(MSG_DEBUG
, "SSID",
343 (u8
*) ssid
->ssid
, ssid
->ssid_len
);
344 wpa_hexdump_ascii_key(MSG_DEBUG
, "PSK (ASCII passphrase)",
345 (u8
*) ssid
->wpa_passphrase
,
346 os_strlen(ssid
->wpa_passphrase
));
347 pbkdf2_sha1(ssid
->wpa_passphrase
,
348 ssid
->ssid
, ssid
->ssid_len
,
349 4096, ssid
->wpa_psk
->psk
, PMK_LEN
);
350 wpa_hexdump_key(MSG_DEBUG
, "PSK (from passphrase)",
351 ssid
->wpa_psk
->psk
, PMK_LEN
);
356 int hostapd_setup_wpa_psk(struct hostapd_bss_config
*conf
)
358 struct hostapd_ssid
*ssid
= &conf
->ssid
;
360 if (ssid
->wpa_passphrase
!= NULL
) {
361 if (ssid
->wpa_psk
!= NULL
) {
362 wpa_printf(MSG_DEBUG
, "Using pre-configured WPA PSK "
363 "instead of passphrase");
365 wpa_printf(MSG_DEBUG
, "Deriving WPA PSK based on "
367 if (hostapd_derive_psk(ssid
) < 0)
370 ssid
->wpa_psk
->group
= 1;
373 return hostapd_config_read_wpa_psk(ssid
->wpa_psk_file
, &conf
->ssid
);
377 static void hostapd_config_free_radius(struct hostapd_radius_server
*servers
,
382 for (i
= 0; i
< num_servers
; i
++) {
383 os_free(servers
[i
].shared_secret
);
389 struct hostapd_radius_attr
*
390 hostapd_config_get_radius_attr(struct hostapd_radius_attr
*attr
, u8 type
)
392 for (; attr
; attr
= attr
->next
) {
393 if (attr
->type
== type
)
400 static void hostapd_config_free_radius_attr(struct hostapd_radius_attr
*attr
)
402 struct hostapd_radius_attr
*prev
;
407 wpabuf_free(prev
->val
);
413 void hostapd_config_free_eap_user(struct hostapd_eap_user
*user
)
415 hostapd_config_free_radius_attr(user
->accept_attr
);
416 os_free(user
->identity
);
417 bin_clear_free(user
->password
, user
->password_len
);
418 bin_clear_free(user
->salt
, user
->salt_len
);
423 void hostapd_config_free_eap_users(struct hostapd_eap_user
*user
)
425 struct hostapd_eap_user
*prev_user
;
430 hostapd_config_free_eap_user(prev_user
);
435 static void hostapd_config_free_wep(struct hostapd_wep_keys
*keys
)
438 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
439 bin_clear_free(keys
->key
[i
], keys
->len
[i
]);
445 void hostapd_config_clear_wpa_psk(struct hostapd_wpa_psk
**l
)
447 struct hostapd_wpa_psk
*psk
, *tmp
;
449 for (psk
= *l
; psk
;) {
452 bin_clear_free(tmp
, sizeof(*tmp
));
458 static void hostapd_config_free_anqp_elem(struct hostapd_bss_config
*conf
)
460 struct anqp_element
*elem
;
462 while ((elem
= dl_list_first(&conf
->anqp_elem
, struct anqp_element
,
464 dl_list_del(&elem
->list
);
465 wpabuf_free(elem
->payload
);
471 static void hostapd_config_free_fils_realms(struct hostapd_bss_config
*conf
)
474 struct fils_realm
*realm
;
476 while ((realm
= dl_list_first(&conf
->fils_realms
, struct fils_realm
,
478 dl_list_del(&realm
->list
);
481 #endif /* CONFIG_FILS */
485 static void hostapd_config_free_sae_passwords(struct hostapd_bss_config
*conf
)
487 struct sae_password_entry
*pw
, *tmp
;
489 pw
= conf
->sae_passwords
;
490 conf
->sae_passwords
= NULL
;
494 str_clear_free(tmp
->password
);
495 os_free(tmp
->identifier
);
501 void hostapd_config_free_bss(struct hostapd_bss_config
*conf
)
506 hostapd_config_clear_wpa_psk(&conf
->ssid
.wpa_psk
);
508 str_clear_free(conf
->ssid
.wpa_passphrase
);
509 os_free(conf
->ssid
.wpa_psk_file
);
510 hostapd_config_free_wep(&conf
->ssid
.wep
);
511 #ifdef CONFIG_FULL_DYNAMIC_VLAN
512 os_free(conf
->ssid
.vlan_tagged_interface
);
513 #endif /* CONFIG_FULL_DYNAMIC_VLAN */
515 hostapd_config_free_eap_users(conf
->eap_user
);
516 os_free(conf
->eap_user_sqlite
);
518 os_free(conf
->eap_req_id_text
);
519 os_free(conf
->erp_domain
);
520 os_free(conf
->accept_mac
);
521 os_free(conf
->deny_mac
);
522 os_free(conf
->nas_identifier
);
524 hostapd_config_free_radius(conf
->radius
->auth_servers
,
525 conf
->radius
->num_auth_servers
);
526 hostapd_config_free_radius(conf
->radius
->acct_servers
,
527 conf
->radius
->num_acct_servers
);
529 hostapd_config_free_radius_attr(conf
->radius_auth_req_attr
);
530 hostapd_config_free_radius_attr(conf
->radius_acct_req_attr
);
531 os_free(conf
->rsn_preauth_interfaces
);
532 os_free(conf
->ctrl_interface
);
533 os_free(conf
->ca_cert
);
534 os_free(conf
->server_cert
);
535 os_free(conf
->private_key
);
536 os_free(conf
->private_key_passwd
);
537 os_free(conf
->ocsp_stapling_response
);
538 os_free(conf
->ocsp_stapling_response_multi
);
539 os_free(conf
->dh_file
);
540 os_free(conf
->openssl_ciphers
);
541 os_free(conf
->pac_opaque_encr_key
);
542 os_free(conf
->eap_fast_a_id
);
543 os_free(conf
->eap_fast_a_id_info
);
544 os_free(conf
->eap_sim_db
);
545 os_free(conf
->radius_server_clients
);
546 os_free(conf
->radius
);
547 os_free(conf
->radius_das_shared_secret
);
548 hostapd_config_free_vlan(conf
);
549 os_free(conf
->time_zone
);
551 #ifdef CONFIG_IEEE80211R_AP
553 struct ft_remote_r0kh
*r0kh
, *r0kh_prev
;
554 struct ft_remote_r1kh
*r1kh
, *r1kh_prev
;
556 r0kh
= conf
->r0kh_list
;
557 conf
->r0kh_list
= NULL
;
564 r1kh
= conf
->r1kh_list
;
565 conf
->r1kh_list
= NULL
;
572 #endif /* CONFIG_IEEE80211R_AP */
575 os_free(conf
->wps_pin_requests
);
576 os_free(conf
->device_name
);
577 os_free(conf
->manufacturer
);
578 os_free(conf
->model_name
);
579 os_free(conf
->model_number
);
580 os_free(conf
->serial_number
);
581 os_free(conf
->config_methods
);
582 os_free(conf
->ap_pin
);
583 os_free(conf
->extra_cred
);
584 os_free(conf
->ap_settings
);
585 os_free(conf
->upnp_iface
);
586 os_free(conf
->friendly_name
);
587 os_free(conf
->manufacturer_url
);
588 os_free(conf
->model_description
);
589 os_free(conf
->model_url
);
594 for (i
= 0; i
< MAX_WPS_VENDOR_EXTENSIONS
; i
++)
595 wpabuf_free(conf
->wps_vendor_ext
[i
]);
597 wpabuf_free(conf
->wps_nfc_dh_pubkey
);
598 wpabuf_free(conf
->wps_nfc_dh_privkey
);
599 wpabuf_free(conf
->wps_nfc_dev_pw
);
600 #endif /* CONFIG_WPS */
602 os_free(conf
->roaming_consortium
);
603 os_free(conf
->venue_name
);
604 os_free(conf
->venue_url
);
605 os_free(conf
->nai_realm_data
);
606 os_free(conf
->network_auth_type
);
607 os_free(conf
->anqp_3gpp_cell_net
);
608 os_free(conf
->domain_name
);
609 hostapd_config_free_anqp_elem(conf
);
611 #ifdef CONFIG_RADIUS_TEST
612 os_free(conf
->dump_msk_file
);
613 #endif /* CONFIG_RADIUS_TEST */
616 os_free(conf
->hs20_oper_friendly_name
);
617 os_free(conf
->hs20_wan_metrics
);
618 os_free(conf
->hs20_connection_capability
);
619 os_free(conf
->hs20_operating_class
);
620 os_free(conf
->hs20_icons
);
621 if (conf
->hs20_osu_providers
) {
623 for (i
= 0; i
< conf
->hs20_osu_providers_count
; i
++) {
624 struct hs20_osu_provider
*p
;
626 p
= &conf
->hs20_osu_providers
[i
];
627 os_free(p
->friendly_name
);
628 os_free(p
->server_uri
);
629 os_free(p
->method_list
);
630 for (j
= 0; j
< p
->icons_count
; j
++)
631 os_free(p
->icons
[j
]);
634 os_free(p
->osu_nai2
);
635 os_free(p
->service_desc
);
637 os_free(conf
->hs20_osu_providers
);
639 if (conf
->hs20_operator_icon
) {
642 for (i
= 0; i
< conf
->hs20_operator_icon_count
; i
++)
643 os_free(conf
->hs20_operator_icon
[i
]);
644 os_free(conf
->hs20_operator_icon
);
646 os_free(conf
->subscr_remediation_url
);
647 os_free(conf
->t_c_filename
);
648 os_free(conf
->t_c_server_url
);
649 #endif /* CONFIG_HS20 */
651 wpabuf_free(conf
->vendor_elements
);
652 wpabuf_free(conf
->assocresp_elements
);
654 os_free(conf
->sae_groups
);
656 os_free(conf
->owe_groups
);
657 #endif /* CONFIG_OWE */
659 os_free(conf
->wowlan_triggers
);
661 os_free(conf
->server_id
);
663 #ifdef CONFIG_TESTING_OPTIONS
664 wpabuf_free(conf
->own_ie_override
);
665 wpabuf_free(conf
->sae_commit_override
);
666 #endif /* CONFIG_TESTING_OPTIONS */
668 os_free(conf
->no_probe_resp_if_seen_on
);
669 os_free(conf
->no_auth_if_seen_on
);
671 hostapd_config_free_fils_realms(conf
);
674 os_free(conf
->dpp_connector
);
675 wpabuf_free(conf
->dpp_netaccesskey
);
676 wpabuf_free(conf
->dpp_csign
);
677 #endif /* CONFIG_DPP */
679 hostapd_config_free_sae_passwords(conf
);
686 * hostapd_config_free - Free hostapd configuration
687 * @conf: Configuration data from hostapd_config_read().
689 void hostapd_config_free(struct hostapd_config
*conf
)
696 for (i
= 0; i
< conf
->num_bss
; i
++)
697 hostapd_config_free_bss(conf
->bss
[i
]);
699 os_free(conf
->supported_rates
);
700 os_free(conf
->basic_rates
);
701 os_free(conf
->acs_ch_list
.range
);
702 os_free(conf
->driver_params
);
704 os_free(conf
->acs_chan_bias
);
705 #endif /* CONFIG_ACS */
706 wpabuf_free(conf
->lci
);
707 wpabuf_free(conf
->civic
);
714 * hostapd_maclist_found - Find a MAC address from a list
715 * @list: MAC address list
716 * @num_entries: Number of addresses in the list
717 * @addr: Address to search for
718 * @vlan_id: Buffer for returning VLAN ID or %NULL if not needed
719 * Returns: 1 if address is in the list or 0 if not.
721 * Perform a binary search for given MAC address from a pre-sorted list.
723 int hostapd_maclist_found(struct mac_acl_entry
*list
, int num_entries
,
724 const u8
*addr
, struct vlan_description
*vlan_id
)
726 int start
, end
, middle
, res
;
729 end
= num_entries
- 1;
731 while (start
<= end
) {
732 middle
= (start
+ end
) / 2;
733 res
= os_memcmp(list
[middle
].addr
, addr
, ETH_ALEN
);
736 *vlan_id
= list
[middle
].vlan_id
;
749 int hostapd_rate_found(int *list
, int rate
)
756 for (i
= 0; list
[i
] >= 0; i
++)
764 int hostapd_vlan_valid(struct hostapd_vlan
*vlan
,
765 struct vlan_description
*vlan_desc
)
767 struct hostapd_vlan
*v
= vlan
;
770 if (!vlan_desc
->notempty
|| vlan_desc
->untagged
< 0 ||
771 vlan_desc
->untagged
> MAX_VLAN_ID
)
773 for (i
= 0; i
< MAX_NUM_TAGGED_VLAN
; i
++) {
774 if (vlan_desc
->tagged
[i
] < 0 ||
775 vlan_desc
->tagged
[i
] > MAX_VLAN_ID
)
778 if (!vlan_desc
->untagged
&& !vlan_desc
->tagged
[0])
782 if (!vlan_compare(&v
->vlan_desc
, vlan_desc
) ||
783 v
->vlan_id
== VLAN_ID_WILDCARD
)
791 const char * hostapd_get_vlan_id_ifname(struct hostapd_vlan
*vlan
, int vlan_id
)
793 struct hostapd_vlan
*v
= vlan
;
795 if (v
->vlan_id
== vlan_id
)
803 const u8
* hostapd_get_psk(const struct hostapd_bss_config
*conf
,
804 const u8
*addr
, const u8
*p2p_dev_addr
,
807 struct hostapd_wpa_psk
*psk
;
808 int next_ok
= prev_psk
== NULL
;
810 if (p2p_dev_addr
&& !is_zero_ether_addr(p2p_dev_addr
)) {
811 wpa_printf(MSG_DEBUG
, "Searching a PSK for " MACSTR
812 " p2p_dev_addr=" MACSTR
" prev_psk=%p",
813 MAC2STR(addr
), MAC2STR(p2p_dev_addr
), prev_psk
);
814 addr
= NULL
; /* Use P2P Device Address for matching */
816 wpa_printf(MSG_DEBUG
, "Searching a PSK for " MACSTR
818 MAC2STR(addr
), prev_psk
);
821 for (psk
= conf
->ssid
.wpa_psk
; psk
!= NULL
; psk
= psk
->next
) {
824 (addr
&& os_memcmp(psk
->addr
, addr
, ETH_ALEN
) == 0) ||
825 (!addr
&& p2p_dev_addr
&&
826 os_memcmp(psk
->p2p_dev_addr
, p2p_dev_addr
, ETH_ALEN
) ==
830 if (psk
->psk
== prev_psk
)
838 static int hostapd_config_check_bss(struct hostapd_bss_config
*bss
,
839 struct hostapd_config
*conf
,
842 if (full_config
&& bss
->ieee802_1x
&& !bss
->eap_server
&&
843 !bss
->radius
->auth_servers
) {
844 wpa_printf(MSG_ERROR
, "Invalid IEEE 802.1X configuration (no "
845 "EAP authenticator configured).");
852 wep
= bss
->default_wep_key_len
> 0 ||
853 bss
->individual_wep_key_len
> 0;
854 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
855 if (bss
->ssid
.wep
.keys_set
) {
862 wpa_printf(MSG_ERROR
, "WEP configuration in a WPA network is not supported");
867 if (full_config
&& bss
->wpa
&&
868 bss
->wpa_psk_radius
!= PSK_RADIUS_IGNORED
&&
869 bss
->macaddr_acl
!= USE_EXTERNAL_RADIUS_AUTH
) {
870 wpa_printf(MSG_ERROR
, "WPA-PSK using RADIUS enabled, but no "
871 "RADIUS checking (macaddr_acl=2) enabled.");
875 if (full_config
&& bss
->wpa
&& (bss
->wpa_key_mgmt
& WPA_KEY_MGMT_PSK
) &&
876 bss
->ssid
.wpa_psk
== NULL
&& bss
->ssid
.wpa_passphrase
== NULL
&&
877 bss
->ssid
.wpa_psk_file
== NULL
&&
878 (bss
->wpa_psk_radius
!= PSK_RADIUS_REQUIRED
||
879 bss
->macaddr_acl
!= USE_EXTERNAL_RADIUS_AUTH
)) {
880 wpa_printf(MSG_ERROR
, "WPA-PSK enabled, but PSK or passphrase "
881 "is not configured.");
885 if (full_config
&& !is_zero_ether_addr(bss
->bssid
)) {
888 for (i
= 0; i
< conf
->num_bss
; i
++) {
889 if (conf
->bss
[i
] != bss
&&
890 (hostapd_mac_comp(conf
->bss
[i
]->bssid
,
892 wpa_printf(MSG_ERROR
, "Duplicate BSSID " MACSTR
893 " on interface '%s' and '%s'.",
895 conf
->bss
[i
]->iface
, bss
->iface
);
901 #ifdef CONFIG_IEEE80211R_AP
902 if (full_config
&& wpa_key_mgmt_ft(bss
->wpa_key_mgmt
) &&
903 (bss
->nas_identifier
== NULL
||
904 os_strlen(bss
->nas_identifier
) < 1 ||
905 os_strlen(bss
->nas_identifier
) > FT_R0KH_ID_MAX_LEN
)) {
906 wpa_printf(MSG_ERROR
, "FT (IEEE 802.11r) requires "
907 "nas_identifier to be configured as a 1..48 octet "
911 #endif /* CONFIG_IEEE80211R_AP */
913 #ifdef CONFIG_IEEE80211N
914 if (full_config
&& conf
->ieee80211n
&&
915 conf
->hw_mode
== HOSTAPD_MODE_IEEE80211B
) {
916 bss
->disable_11n
= 1;
917 wpa_printf(MSG_ERROR
, "HT (IEEE 802.11n) in 11b mode is not "
918 "allowed, disabling HT capabilities");
921 if (full_config
&& conf
->ieee80211n
&&
922 bss
->ssid
.security_policy
== SECURITY_STATIC_WEP
) {
923 bss
->disable_11n
= 1;
924 wpa_printf(MSG_ERROR
, "HT (IEEE 802.11n) with WEP is not "
925 "allowed, disabling HT capabilities");
928 if (full_config
&& conf
->ieee80211n
&& bss
->wpa
&&
929 !(bss
->wpa_pairwise
& WPA_CIPHER_CCMP
) &&
930 !(bss
->rsn_pairwise
& (WPA_CIPHER_CCMP
| WPA_CIPHER_GCMP
|
931 WPA_CIPHER_CCMP_256
| WPA_CIPHER_GCMP_256
)))
933 bss
->disable_11n
= 1;
934 wpa_printf(MSG_ERROR
, "HT (IEEE 802.11n) with WPA/WPA2 "
935 "requires CCMP/GCMP to be enabled, disabling HT "
938 #endif /* CONFIG_IEEE80211N */
940 #ifdef CONFIG_IEEE80211AC
941 if (full_config
&& conf
->ieee80211ac
&&
942 bss
->ssid
.security_policy
== SECURITY_STATIC_WEP
) {
943 bss
->disable_11ac
= 1;
944 wpa_printf(MSG_ERROR
,
945 "VHT (IEEE 802.11ac) with WEP is not allowed, disabling VHT capabilities");
948 if (full_config
&& conf
->ieee80211ac
&& bss
->wpa
&&
949 !(bss
->wpa_pairwise
& WPA_CIPHER_CCMP
) &&
950 !(bss
->rsn_pairwise
& (WPA_CIPHER_CCMP
| WPA_CIPHER_GCMP
|
951 WPA_CIPHER_CCMP_256
| WPA_CIPHER_GCMP_256
)))
953 bss
->disable_11ac
= 1;
954 wpa_printf(MSG_ERROR
,
955 "VHT (IEEE 802.11ac) with WPA/WPA2 requires CCMP/GCMP to be enabled, disabling VHT capabilities");
957 #endif /* CONFIG_IEEE80211AC */
960 if (full_config
&& bss
->wps_state
&& bss
->ignore_broadcast_ssid
) {
961 wpa_printf(MSG_INFO
, "WPS: ignore_broadcast_ssid "
962 "configuration forced WPS to be disabled");
966 if (full_config
&& bss
->wps_state
&&
967 bss
->ssid
.wep
.keys_set
&& bss
->wpa
== 0) {
968 wpa_printf(MSG_INFO
, "WPS: WEP configuration forced WPS to be "
973 if (full_config
&& bss
->wps_state
&& bss
->wpa
&&
975 !(bss
->rsn_pairwise
& (WPA_CIPHER_CCMP
| WPA_CIPHER_GCMP
|
976 WPA_CIPHER_CCMP_256
|
977 WPA_CIPHER_GCMP_256
)))) {
978 wpa_printf(MSG_INFO
, "WPS: WPA/TKIP configuration without "
979 "WPA2/CCMP/GCMP forced WPS to be disabled");
982 #endif /* CONFIG_WPS */
985 if (full_config
&& bss
->hs20
&&
987 !(bss
->rsn_pairwise
& (WPA_CIPHER_CCMP
| WPA_CIPHER_GCMP
|
988 WPA_CIPHER_CCMP_256
|
989 WPA_CIPHER_GCMP_256
)))) {
990 wpa_printf(MSG_ERROR
, "HS 2.0: WPA2-Enterprise/CCMP "
991 "configuration is required for Hotspot 2.0 "
995 #endif /* CONFIG_HS20 */
998 if (full_config
&& bss
->mbo_enabled
&& (bss
->wpa
& 2) &&
999 bss
->ieee80211w
== NO_MGMT_FRAME_PROTECTION
) {
1000 wpa_printf(MSG_ERROR
,
1001 "MBO: PMF needs to be enabled whenever using WPA2 with MBO");
1004 #endif /* CONFIG_MBO */
1010 static int hostapd_config_check_cw(struct hostapd_config
*conf
, int queue
)
1012 int tx_cwmin
= conf
->tx_queue
[queue
].cwmin
;
1013 int tx_cwmax
= conf
->tx_queue
[queue
].cwmax
;
1014 int ac_cwmin
= conf
->wmm_ac_params
[queue
].cwmin
;
1015 int ac_cwmax
= conf
->wmm_ac_params
[queue
].cwmax
;
1017 if (tx_cwmin
> tx_cwmax
) {
1018 wpa_printf(MSG_ERROR
,
1019 "Invalid TX queue cwMin/cwMax values. cwMin(%d) greater than cwMax(%d)",
1020 tx_cwmin
, tx_cwmax
);
1023 if (ac_cwmin
> ac_cwmax
) {
1024 wpa_printf(MSG_ERROR
,
1025 "Invalid WMM AC cwMin/cwMax values. cwMin(%d) greater than cwMax(%d)",
1026 ac_cwmin
, ac_cwmax
);
1033 int hostapd_config_check(struct hostapd_config
*conf
, int full_config
)
1037 if (full_config
&& conf
->ieee80211d
&&
1038 (!conf
->country
[0] || !conf
->country
[1])) {
1039 wpa_printf(MSG_ERROR
, "Cannot enable IEEE 802.11d without "
1040 "setting the country_code");
1044 if (full_config
&& conf
->ieee80211h
&& !conf
->ieee80211d
) {
1045 wpa_printf(MSG_ERROR
, "Cannot enable IEEE 802.11h without "
1046 "IEEE 802.11d enabled");
1050 if (full_config
&& conf
->local_pwr_constraint
!= -1 &&
1051 !conf
->ieee80211d
) {
1052 wpa_printf(MSG_ERROR
, "Cannot add Power Constraint element without Country element");
1056 if (full_config
&& conf
->spectrum_mgmt_required
&&
1057 conf
->local_pwr_constraint
== -1) {
1058 wpa_printf(MSG_ERROR
, "Cannot set Spectrum Management bit without Country and Power Constraint elements");
1062 for (i
= 0; i
< NUM_TX_QUEUES
; i
++) {
1063 if (hostapd_config_check_cw(conf
, i
))
1067 for (i
= 0; i
< conf
->num_bss
; i
++) {
1068 if (hostapd_config_check_bss(conf
->bss
[i
], conf
, full_config
))
1076 void hostapd_set_security_params(struct hostapd_bss_config
*bss
,
1079 if (bss
->individual_wep_key_len
== 0) {
1080 /* individual keys are not use; can use key idx0 for
1082 bss
->broadcast_key_idx_min
= 0;
1085 if ((bss
->wpa
& 2) && bss
->rsn_pairwise
== 0)
1086 bss
->rsn_pairwise
= bss
->wpa_pairwise
;
1087 if (bss
->group_cipher
)
1088 bss
->wpa_group
= bss
->group_cipher
;
1090 bss
->wpa_group
= wpa_select_ap_group_cipher(bss
->wpa
,
1093 if (!bss
->wpa_group_rekey_set
)
1094 bss
->wpa_group_rekey
= bss
->wpa_group
== WPA_CIPHER_TKIP
?
1098 bss
->radius
->auth_server
= bss
->radius
->auth_servers
;
1099 bss
->radius
->acct_server
= bss
->radius
->acct_servers
;
1102 if (bss
->wpa
&& bss
->ieee802_1x
) {
1103 bss
->ssid
.security_policy
= SECURITY_WPA
;
1104 } else if (bss
->wpa
) {
1105 bss
->ssid
.security_policy
= SECURITY_WPA_PSK
;
1106 } else if (bss
->ieee802_1x
) {
1107 int cipher
= WPA_CIPHER_NONE
;
1108 bss
->ssid
.security_policy
= SECURITY_IEEE_802_1X
;
1109 bss
->ssid
.wep
.default_len
= bss
->default_wep_key_len
;
1110 if (full_config
&& bss
->default_wep_key_len
) {
1111 cipher
= bss
->default_wep_key_len
>= 13 ?
1112 WPA_CIPHER_WEP104
: WPA_CIPHER_WEP40
;
1113 } else if (full_config
&& bss
->ssid
.wep
.keys_set
) {
1114 if (bss
->ssid
.wep
.len
[0] >= 13)
1115 cipher
= WPA_CIPHER_WEP104
;
1117 cipher
= WPA_CIPHER_WEP40
;
1119 bss
->wpa_group
= cipher
;
1120 bss
->wpa_pairwise
= cipher
;
1121 bss
->rsn_pairwise
= cipher
;
1123 bss
->wpa_key_mgmt
= WPA_KEY_MGMT_IEEE8021X_NO_WPA
;
1124 } else if (bss
->ssid
.wep
.keys_set
) {
1125 int cipher
= WPA_CIPHER_WEP40
;
1126 if (bss
->ssid
.wep
.len
[0] >= 13)
1127 cipher
= WPA_CIPHER_WEP104
;
1128 bss
->ssid
.security_policy
= SECURITY_STATIC_WEP
;
1129 bss
->wpa_group
= cipher
;
1130 bss
->wpa_pairwise
= cipher
;
1131 bss
->rsn_pairwise
= cipher
;
1133 bss
->wpa_key_mgmt
= WPA_KEY_MGMT_NONE
;
1134 } else if (bss
->osen
) {
1135 bss
->ssid
.security_policy
= SECURITY_OSEN
;
1136 bss
->wpa_group
= WPA_CIPHER_CCMP
;
1137 bss
->wpa_pairwise
= 0;
1138 bss
->rsn_pairwise
= WPA_CIPHER_CCMP
;
1140 bss
->ssid
.security_policy
= SECURITY_PLAINTEXT
;
1142 bss
->wpa_group
= WPA_CIPHER_NONE
;
1143 bss
->wpa_pairwise
= WPA_CIPHER_NONE
;
1144 bss
->rsn_pairwise
= WPA_CIPHER_NONE
;
1145 bss
->wpa_key_mgmt
= WPA_KEY_MGMT_NONE
;