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 "radius/radius_client.h"
14 #include "common/ieee802_11_defs.h"
15 #include "common/eapol_common.h"
16 #include "common/dhcp.h"
17 #include "eap_common/eap_wsc_common.h"
18 #include "eap_server/eap.h"
21 #include "ap_config.h"
24 static void hostapd_config_free_vlan(struct hostapd_bss_config
*bss
)
26 struct hostapd_vlan
*vlan
, *prev
;
40 #ifndef DEFAULT_WPA_DISABLE_EAPOL_KEY_RETRIES
41 #define DEFAULT_WPA_DISABLE_EAPOL_KEY_RETRIES 0
42 #endif /* DEFAULT_WPA_DISABLE_EAPOL_KEY_RETRIES */
44 void hostapd_config_defaults_bss(struct hostapd_bss_config
*bss
)
46 dl_list_init(&bss
->anqp_elem
);
48 bss
->logger_syslog_level
= HOSTAPD_LEVEL_INFO
;
49 bss
->logger_stdout_level
= HOSTAPD_LEVEL_INFO
;
50 bss
->logger_syslog
= (unsigned int) -1;
51 bss
->logger_stdout
= (unsigned int) -1;
53 bss
->auth_algs
= WPA_AUTH_ALG_OPEN
| WPA_AUTH_ALG_SHARED
;
55 bss
->wep_rekeying_period
= 300;
56 /* use key0 in individual key and key1 in broadcast key */
57 bss
->broadcast_key_idx_min
= 1;
58 bss
->broadcast_key_idx_max
= 2;
59 bss
->eap_reauth_period
= 3600;
61 bss
->wpa_group_rekey
= 600;
62 bss
->wpa_gmk_rekey
= 86400;
63 bss
->wpa_group_update_count
= 4;
64 bss
->wpa_pairwise_update_count
= 4;
65 bss
->wpa_disable_eapol_key_retries
=
66 DEFAULT_WPA_DISABLE_EAPOL_KEY_RETRIES
;
67 bss
->wpa_key_mgmt
= WPA_KEY_MGMT_PSK
;
68 bss
->wpa_pairwise
= WPA_CIPHER_TKIP
;
69 bss
->wpa_group
= WPA_CIPHER_TKIP
;
70 bss
->rsn_pairwise
= 0;
72 bss
->max_num_sta
= MAX_STA_COUNT
;
76 bss
->radius_server_auth_port
= 1812;
77 bss
->eap_sim_db_timeout
= 1;
78 bss
->ap_max_inactivity
= AP_MAX_INACTIVITY
;
79 bss
->eapol_version
= EAPOL_VERSION
;
81 bss
->max_listen_interval
= 65535;
83 bss
->pwd_group
= 19; /* ECC: GF(p=256) */
85 #ifdef CONFIG_IEEE80211W
86 bss
->assoc_sa_query_max_timeout
= 1000;
87 bss
->assoc_sa_query_retry_timeout
= 201;
88 bss
->group_mgmt_cipher
= WPA_CIPHER_AES_128_CMAC
;
89 #endif /* CONFIG_IEEE80211W */
90 #ifdef EAP_SERVER_FAST
91 /* both anonymous and authenticated provisioning */
92 bss
->eap_fast_prov
= 3;
93 bss
->pac_key_lifetime
= 7 * 24 * 60 * 60;
94 bss
->pac_key_refresh_time
= 1 * 24 * 60 * 60;
95 #endif /* EAP_SERVER_FAST */
97 /* Set to -1 as defaults depends on HT in setup */
98 bss
->wmm_enabled
= -1;
100 #ifdef CONFIG_IEEE80211R_AP
102 bss
->rkh_pos_timeout
= 86400;
103 bss
->rkh_neg_timeout
= 60;
104 bss
->rkh_pull_timeout
= 1000;
105 bss
->rkh_pull_retries
= 4;
106 bss
->r0_key_lifetime
= 1209600;
107 #endif /* CONFIG_IEEE80211R_AP */
109 bss
->radius_das_time_window
= 300;
111 bss
->sae_anti_clogging_threshold
= 5;
114 bss
->gas_frag_limit
= 1400;
117 dl_list_init(&bss
->fils_realms
);
118 bss
->fils_hlp_wait_time
= 30;
119 bss
->dhcp_server_port
= DHCP_SERVER_PORT
;
120 bss
->dhcp_relay_port
= DHCP_SERVER_PORT
;
121 #endif /* CONFIG_FILS */
123 bss
->broadcast_deauth
= 1;
126 bss
->mbo_cell_data_conn_pref
= -1;
127 #endif /* CONFIG_MBO */
131 struct hostapd_config
* hostapd_config_defaults(void)
133 #define ecw2cw(ecw) ((1 << (ecw)) - 1)
135 struct hostapd_config
*conf
;
136 struct hostapd_bss_config
*bss
;
137 const int aCWmin
= 4, aCWmax
= 10;
138 const struct hostapd_wmm_ac_params ac_bk
=
139 { aCWmin
, aCWmax
, 7, 0, 0 }; /* background traffic */
140 const struct hostapd_wmm_ac_params ac_be
=
141 { aCWmin
, aCWmax
, 3, 0, 0 }; /* best effort traffic */
142 const struct hostapd_wmm_ac_params ac_vi
= /* video traffic */
143 { aCWmin
- 1, aCWmin
, 2, 3008 / 32, 0 };
144 const struct hostapd_wmm_ac_params ac_vo
= /* voice traffic */
145 { aCWmin
- 2, aCWmin
- 1, 2, 1504 / 32, 0 };
146 const struct hostapd_tx_queue_params txq_bk
=
147 { 7, ecw2cw(aCWmin
), ecw2cw(aCWmax
), 0 };
148 const struct hostapd_tx_queue_params txq_be
=
149 { 3, ecw2cw(aCWmin
), 4 * (ecw2cw(aCWmin
) + 1) - 1, 0};
150 const struct hostapd_tx_queue_params txq_vi
=
151 { 1, (ecw2cw(aCWmin
) + 1) / 2 - 1, ecw2cw(aCWmin
), 30};
152 const struct hostapd_tx_queue_params txq_vo
=
153 { 1, (ecw2cw(aCWmin
) + 1) / 4 - 1,
154 (ecw2cw(aCWmin
) + 1) / 2 - 1, 15};
158 conf
= os_zalloc(sizeof(*conf
));
159 bss
= os_zalloc(sizeof(*bss
));
160 if (conf
== NULL
|| bss
== NULL
) {
161 wpa_printf(MSG_ERROR
, "Failed to allocate memory for "
162 "configuration data.");
167 conf
->bss
= os_calloc(1, sizeof(struct hostapd_bss_config
*));
168 if (conf
->bss
== NULL
) {
175 bss
->radius
= os_zalloc(sizeof(*bss
->radius
));
176 if (bss
->radius
== NULL
) {
183 hostapd_config_defaults_bss(bss
);
187 conf
->beacon_int
= 100;
188 conf
->rts_threshold
= -1; /* use driver default: 2347 */
189 conf
->fragm_threshold
= -1; /* user driver default: 2346 */
190 conf
->send_probe_response
= 1;
191 /* Set to invalid value means do not add Power Constraint IE */
192 conf
->local_pwr_constraint
= -1;
194 conf
->wmm_ac_params
[0] = ac_be
;
195 conf
->wmm_ac_params
[1] = ac_bk
;
196 conf
->wmm_ac_params
[2] = ac_vi
;
197 conf
->wmm_ac_params
[3] = ac_vo
;
199 conf
->tx_queue
[0] = txq_vo
;
200 conf
->tx_queue
[1] = txq_vi
;
201 conf
->tx_queue
[2] = txq_be
;
202 conf
->tx_queue
[3] = txq_bk
;
204 conf
->ht_capab
= HT_CAP_INFO_SMPS_DISABLED
;
206 conf
->ap_table_max_size
= 255;
207 conf
->ap_table_expiration_time
= 60;
208 conf
->track_sta_max_age
= 180;
210 #ifdef CONFIG_TESTING_OPTIONS
211 conf
->ignore_probe_probability
= 0.0;
212 conf
->ignore_auth_probability
= 0.0;
213 conf
->ignore_assoc_probability
= 0.0;
214 conf
->ignore_reassoc_probability
= 0.0;
215 conf
->corrupt_gtk_rekey_mic_probability
= 0.0;
216 conf
->ecsa_ie_only
= 0;
217 #endif /* CONFIG_TESTING_OPTIONS */
220 conf
->acs_ch_list
.num
= 0;
222 conf
->acs_num_scans
= 5;
223 #endif /* CONFIG_ACS */
225 /* The third octet of the country string uses an ASCII space character
226 * by default to indicate that the regulations encompass all
227 * environments for the current frequency band in the country. */
228 conf
->country
[2] = ' ';
234 int hostapd_mac_comp(const void *a
, const void *b
)
236 return os_memcmp(a
, b
, sizeof(macaddr
));
240 static int hostapd_config_read_wpa_psk(const char *fname
,
241 struct hostapd_ssid
*ssid
)
245 int line
= 0, ret
= 0, len
, ok
;
247 struct hostapd_wpa_psk
*psk
;
252 f
= fopen(fname
, "r");
254 wpa_printf(MSG_ERROR
, "WPA PSK file '%s' not found.", fname
);
258 while (fgets(buf
, sizeof(buf
), f
)) {
264 while (*pos
!= '\0') {
274 if (hwaddr_aton(buf
, addr
)) {
275 wpa_printf(MSG_ERROR
, "Invalid MAC address '%s' on "
276 "line %d in '%s'", buf
, line
, fname
);
281 psk
= os_zalloc(sizeof(*psk
));
283 wpa_printf(MSG_ERROR
, "WPA PSK allocation failed");
287 if (is_zero_ether_addr(addr
))
290 os_memcpy(psk
->addr
, addr
, ETH_ALEN
);
294 wpa_printf(MSG_ERROR
, "No PSK on line %d in '%s'",
303 len
= os_strlen(pos
);
304 if (len
== 64 && hexstr2bin(pos
, psk
->psk
, PMK_LEN
) == 0)
306 else if (len
>= 8 && len
< 64) {
307 pbkdf2_sha1(pos
, ssid
->ssid
, ssid
->ssid_len
,
308 4096, psk
->psk
, PMK_LEN
);
312 wpa_printf(MSG_ERROR
, "Invalid PSK '%s' on line %d in "
313 "'%s'", pos
, line
, fname
);
319 psk
->next
= ssid
->wpa_psk
;
329 static int hostapd_derive_psk(struct hostapd_ssid
*ssid
)
331 ssid
->wpa_psk
= os_zalloc(sizeof(struct hostapd_wpa_psk
));
332 if (ssid
->wpa_psk
== NULL
) {
333 wpa_printf(MSG_ERROR
, "Unable to alloc space for PSK");
336 wpa_hexdump_ascii(MSG_DEBUG
, "SSID",
337 (u8
*) ssid
->ssid
, ssid
->ssid_len
);
338 wpa_hexdump_ascii_key(MSG_DEBUG
, "PSK (ASCII passphrase)",
339 (u8
*) ssid
->wpa_passphrase
,
340 os_strlen(ssid
->wpa_passphrase
));
341 pbkdf2_sha1(ssid
->wpa_passphrase
,
342 ssid
->ssid
, ssid
->ssid_len
,
343 4096, ssid
->wpa_psk
->psk
, PMK_LEN
);
344 wpa_hexdump_key(MSG_DEBUG
, "PSK (from passphrase)",
345 ssid
->wpa_psk
->psk
, PMK_LEN
);
350 int hostapd_setup_wpa_psk(struct hostapd_bss_config
*conf
)
352 struct hostapd_ssid
*ssid
= &conf
->ssid
;
354 if (ssid
->wpa_passphrase
!= NULL
) {
355 if (ssid
->wpa_psk
!= NULL
) {
356 wpa_printf(MSG_DEBUG
, "Using pre-configured WPA PSK "
357 "instead of passphrase");
359 wpa_printf(MSG_DEBUG
, "Deriving WPA PSK based on "
361 if (hostapd_derive_psk(ssid
) < 0)
364 ssid
->wpa_psk
->group
= 1;
367 return hostapd_config_read_wpa_psk(ssid
->wpa_psk_file
, &conf
->ssid
);
371 static void hostapd_config_free_radius(struct hostapd_radius_server
*servers
,
376 for (i
= 0; i
< num_servers
; i
++) {
377 os_free(servers
[i
].shared_secret
);
383 struct hostapd_radius_attr
*
384 hostapd_config_get_radius_attr(struct hostapd_radius_attr
*attr
, u8 type
)
386 for (; attr
; attr
= attr
->next
) {
387 if (attr
->type
== type
)
394 static void hostapd_config_free_radius_attr(struct hostapd_radius_attr
*attr
)
396 struct hostapd_radius_attr
*prev
;
401 wpabuf_free(prev
->val
);
407 void hostapd_config_free_eap_user(struct hostapd_eap_user
*user
)
409 hostapd_config_free_radius_attr(user
->accept_attr
);
410 os_free(user
->identity
);
411 bin_clear_free(user
->password
, user
->password_len
);
416 void hostapd_config_free_eap_users(struct hostapd_eap_user
*user
)
418 struct hostapd_eap_user
*prev_user
;
423 hostapd_config_free_eap_user(prev_user
);
428 static void hostapd_config_free_wep(struct hostapd_wep_keys
*keys
)
431 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
432 bin_clear_free(keys
->key
[i
], keys
->len
[i
]);
438 void hostapd_config_clear_wpa_psk(struct hostapd_wpa_psk
**l
)
440 struct hostapd_wpa_psk
*psk
, *tmp
;
442 for (psk
= *l
; psk
;) {
445 bin_clear_free(tmp
, sizeof(*tmp
));
451 static void hostapd_config_free_anqp_elem(struct hostapd_bss_config
*conf
)
453 struct anqp_element
*elem
;
455 while ((elem
= dl_list_first(&conf
->anqp_elem
, struct anqp_element
,
457 dl_list_del(&elem
->list
);
458 wpabuf_free(elem
->payload
);
464 static void hostapd_config_free_fils_realms(struct hostapd_bss_config
*conf
)
467 struct fils_realm
*realm
;
469 while ((realm
= dl_list_first(&conf
->fils_realms
, struct fils_realm
,
471 dl_list_del(&realm
->list
);
474 #endif /* CONFIG_FILS */
478 void hostapd_config_free_bss(struct hostapd_bss_config
*conf
)
483 hostapd_config_clear_wpa_psk(&conf
->ssid
.wpa_psk
);
485 str_clear_free(conf
->ssid
.wpa_passphrase
);
486 os_free(conf
->ssid
.wpa_psk_file
);
487 hostapd_config_free_wep(&conf
->ssid
.wep
);
488 #ifdef CONFIG_FULL_DYNAMIC_VLAN
489 os_free(conf
->ssid
.vlan_tagged_interface
);
490 #endif /* CONFIG_FULL_DYNAMIC_VLAN */
492 hostapd_config_free_eap_users(conf
->eap_user
);
493 os_free(conf
->eap_user_sqlite
);
495 os_free(conf
->eap_req_id_text
);
496 os_free(conf
->erp_domain
);
497 os_free(conf
->accept_mac
);
498 os_free(conf
->deny_mac
);
499 os_free(conf
->nas_identifier
);
501 hostapd_config_free_radius(conf
->radius
->auth_servers
,
502 conf
->radius
->num_auth_servers
);
503 hostapd_config_free_radius(conf
->radius
->acct_servers
,
504 conf
->radius
->num_acct_servers
);
506 hostapd_config_free_radius_attr(conf
->radius_auth_req_attr
);
507 hostapd_config_free_radius_attr(conf
->radius_acct_req_attr
);
508 os_free(conf
->rsn_preauth_interfaces
);
509 os_free(conf
->ctrl_interface
);
510 os_free(conf
->ca_cert
);
511 os_free(conf
->server_cert
);
512 os_free(conf
->private_key
);
513 os_free(conf
->private_key_passwd
);
514 os_free(conf
->ocsp_stapling_response
);
515 os_free(conf
->ocsp_stapling_response_multi
);
516 os_free(conf
->dh_file
);
517 os_free(conf
->openssl_ciphers
);
518 os_free(conf
->pac_opaque_encr_key
);
519 os_free(conf
->eap_fast_a_id
);
520 os_free(conf
->eap_fast_a_id_info
);
521 os_free(conf
->eap_sim_db
);
522 os_free(conf
->radius_server_clients
);
523 os_free(conf
->radius
);
524 os_free(conf
->radius_das_shared_secret
);
525 hostapd_config_free_vlan(conf
);
526 os_free(conf
->time_zone
);
528 #ifdef CONFIG_IEEE80211R_AP
530 struct ft_remote_r0kh
*r0kh
, *r0kh_prev
;
531 struct ft_remote_r1kh
*r1kh
, *r1kh_prev
;
533 r0kh
= conf
->r0kh_list
;
534 conf
->r0kh_list
= NULL
;
541 r1kh
= conf
->r1kh_list
;
542 conf
->r1kh_list
= NULL
;
549 #endif /* CONFIG_IEEE80211R_AP */
552 os_free(conf
->wps_pin_requests
);
553 os_free(conf
->device_name
);
554 os_free(conf
->manufacturer
);
555 os_free(conf
->model_name
);
556 os_free(conf
->model_number
);
557 os_free(conf
->serial_number
);
558 os_free(conf
->config_methods
);
559 os_free(conf
->ap_pin
);
560 os_free(conf
->extra_cred
);
561 os_free(conf
->ap_settings
);
562 os_free(conf
->upnp_iface
);
563 os_free(conf
->friendly_name
);
564 os_free(conf
->manufacturer_url
);
565 os_free(conf
->model_description
);
566 os_free(conf
->model_url
);
571 for (i
= 0; i
< MAX_WPS_VENDOR_EXTENSIONS
; i
++)
572 wpabuf_free(conf
->wps_vendor_ext
[i
]);
574 wpabuf_free(conf
->wps_nfc_dh_pubkey
);
575 wpabuf_free(conf
->wps_nfc_dh_privkey
);
576 wpabuf_free(conf
->wps_nfc_dev_pw
);
577 #endif /* CONFIG_WPS */
579 os_free(conf
->roaming_consortium
);
580 os_free(conf
->venue_name
);
581 os_free(conf
->venue_url
);
582 os_free(conf
->nai_realm_data
);
583 os_free(conf
->network_auth_type
);
584 os_free(conf
->anqp_3gpp_cell_net
);
585 os_free(conf
->domain_name
);
586 hostapd_config_free_anqp_elem(conf
);
588 #ifdef CONFIG_RADIUS_TEST
589 os_free(conf
->dump_msk_file
);
590 #endif /* CONFIG_RADIUS_TEST */
593 os_free(conf
->hs20_oper_friendly_name
);
594 os_free(conf
->hs20_wan_metrics
);
595 os_free(conf
->hs20_connection_capability
);
596 os_free(conf
->hs20_operating_class
);
597 os_free(conf
->hs20_icons
);
598 if (conf
->hs20_osu_providers
) {
600 for (i
= 0; i
< conf
->hs20_osu_providers_count
; i
++) {
601 struct hs20_osu_provider
*p
;
603 p
= &conf
->hs20_osu_providers
[i
];
604 os_free(p
->friendly_name
);
605 os_free(p
->server_uri
);
606 os_free(p
->method_list
);
607 for (j
= 0; j
< p
->icons_count
; j
++)
608 os_free(p
->icons
[j
]);
611 os_free(p
->service_desc
);
613 os_free(conf
->hs20_osu_providers
);
615 if (conf
->hs20_operator_icon
) {
618 for (i
= 0; i
< conf
->hs20_operator_icon_count
; i
++)
619 os_free(conf
->hs20_operator_icon
[i
]);
620 os_free(conf
->hs20_operator_icon
);
622 os_free(conf
->subscr_remediation_url
);
623 #endif /* CONFIG_HS20 */
625 wpabuf_free(conf
->vendor_elements
);
626 wpabuf_free(conf
->assocresp_elements
);
628 os_free(conf
->sae_groups
);
630 os_free(conf
->owe_groups
);
631 #endif /* CONFIG_OWE */
633 os_free(conf
->wowlan_triggers
);
635 os_free(conf
->server_id
);
637 #ifdef CONFIG_TESTING_OPTIONS
638 wpabuf_free(conf
->own_ie_override
);
639 wpabuf_free(conf
->sae_commit_override
);
640 #endif /* CONFIG_TESTING_OPTIONS */
642 os_free(conf
->no_probe_resp_if_seen_on
);
643 os_free(conf
->no_auth_if_seen_on
);
645 hostapd_config_free_fils_realms(conf
);
648 os_free(conf
->dpp_connector
);
649 wpabuf_free(conf
->dpp_netaccesskey
);
650 wpabuf_free(conf
->dpp_csign
);
651 #endif /* CONFIG_DPP */
653 os_free(conf
->sae_password
);
660 * hostapd_config_free - Free hostapd configuration
661 * @conf: Configuration data from hostapd_config_read().
663 void hostapd_config_free(struct hostapd_config
*conf
)
670 for (i
= 0; i
< conf
->num_bss
; i
++)
671 hostapd_config_free_bss(conf
->bss
[i
]);
673 os_free(conf
->supported_rates
);
674 os_free(conf
->basic_rates
);
675 os_free(conf
->acs_ch_list
.range
);
676 os_free(conf
->driver_params
);
678 os_free(conf
->acs_chan_bias
);
679 #endif /* CONFIG_ACS */
680 wpabuf_free(conf
->lci
);
681 wpabuf_free(conf
->civic
);
688 * hostapd_maclist_found - Find a MAC address from a list
689 * @list: MAC address list
690 * @num_entries: Number of addresses in the list
691 * @addr: Address to search for
692 * @vlan_id: Buffer for returning VLAN ID or %NULL if not needed
693 * Returns: 1 if address is in the list or 0 if not.
695 * Perform a binary search for given MAC address from a pre-sorted list.
697 int hostapd_maclist_found(struct mac_acl_entry
*list
, int num_entries
,
698 const u8
*addr
, struct vlan_description
*vlan_id
)
700 int start
, end
, middle
, res
;
703 end
= num_entries
- 1;
705 while (start
<= end
) {
706 middle
= (start
+ end
) / 2;
707 res
= os_memcmp(list
[middle
].addr
, addr
, ETH_ALEN
);
710 *vlan_id
= list
[middle
].vlan_id
;
723 int hostapd_rate_found(int *list
, int rate
)
730 for (i
= 0; list
[i
] >= 0; i
++)
738 int hostapd_vlan_valid(struct hostapd_vlan
*vlan
,
739 struct vlan_description
*vlan_desc
)
741 struct hostapd_vlan
*v
= vlan
;
744 if (!vlan_desc
->notempty
|| vlan_desc
->untagged
< 0 ||
745 vlan_desc
->untagged
> MAX_VLAN_ID
)
747 for (i
= 0; i
< MAX_NUM_TAGGED_VLAN
; i
++) {
748 if (vlan_desc
->tagged
[i
] < 0 ||
749 vlan_desc
->tagged
[i
] > MAX_VLAN_ID
)
752 if (!vlan_desc
->untagged
&& !vlan_desc
->tagged
[0])
756 if (!vlan_compare(&v
->vlan_desc
, vlan_desc
) ||
757 v
->vlan_id
== VLAN_ID_WILDCARD
)
765 const char * hostapd_get_vlan_id_ifname(struct hostapd_vlan
*vlan
, int vlan_id
)
767 struct hostapd_vlan
*v
= vlan
;
769 if (v
->vlan_id
== vlan_id
)
777 const u8
* hostapd_get_psk(const struct hostapd_bss_config
*conf
,
778 const u8
*addr
, const u8
*p2p_dev_addr
,
781 struct hostapd_wpa_psk
*psk
;
782 int next_ok
= prev_psk
== NULL
;
784 if (p2p_dev_addr
&& !is_zero_ether_addr(p2p_dev_addr
)) {
785 wpa_printf(MSG_DEBUG
, "Searching a PSK for " MACSTR
786 " p2p_dev_addr=" MACSTR
" prev_psk=%p",
787 MAC2STR(addr
), MAC2STR(p2p_dev_addr
), prev_psk
);
788 addr
= NULL
; /* Use P2P Device Address for matching */
790 wpa_printf(MSG_DEBUG
, "Searching a PSK for " MACSTR
792 MAC2STR(addr
), prev_psk
);
795 for (psk
= conf
->ssid
.wpa_psk
; psk
!= NULL
; psk
= psk
->next
) {
798 (addr
&& os_memcmp(psk
->addr
, addr
, ETH_ALEN
) == 0) ||
799 (!addr
&& p2p_dev_addr
&&
800 os_memcmp(psk
->p2p_dev_addr
, p2p_dev_addr
, ETH_ALEN
) ==
804 if (psk
->psk
== prev_psk
)
812 static int hostapd_config_check_bss(struct hostapd_bss_config
*bss
,
813 struct hostapd_config
*conf
,
816 if (full_config
&& bss
->ieee802_1x
&& !bss
->eap_server
&&
817 !bss
->radius
->auth_servers
) {
818 wpa_printf(MSG_ERROR
, "Invalid IEEE 802.1X configuration (no "
819 "EAP authenticator configured).");
826 wep
= bss
->default_wep_key_len
> 0 ||
827 bss
->individual_wep_key_len
> 0;
828 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
829 if (bss
->ssid
.wep
.keys_set
) {
836 wpa_printf(MSG_ERROR
, "WEP configuration in a WPA network is not supported");
841 if (full_config
&& bss
->wpa
&&
842 bss
->wpa_psk_radius
!= PSK_RADIUS_IGNORED
&&
843 bss
->macaddr_acl
!= USE_EXTERNAL_RADIUS_AUTH
) {
844 wpa_printf(MSG_ERROR
, "WPA-PSK using RADIUS enabled, but no "
845 "RADIUS checking (macaddr_acl=2) enabled.");
849 if (full_config
&& bss
->wpa
&& (bss
->wpa_key_mgmt
& WPA_KEY_MGMT_PSK
) &&
850 bss
->ssid
.wpa_psk
== NULL
&& bss
->ssid
.wpa_passphrase
== NULL
&&
851 bss
->ssid
.wpa_psk_file
== NULL
&&
852 (bss
->wpa_psk_radius
!= PSK_RADIUS_REQUIRED
||
853 bss
->macaddr_acl
!= USE_EXTERNAL_RADIUS_AUTH
)) {
854 wpa_printf(MSG_ERROR
, "WPA-PSK enabled, but PSK or passphrase "
855 "is not configured.");
859 if (full_config
&& !is_zero_ether_addr(bss
->bssid
)) {
862 for (i
= 0; i
< conf
->num_bss
; i
++) {
863 if (conf
->bss
[i
] != bss
&&
864 (hostapd_mac_comp(conf
->bss
[i
]->bssid
,
866 wpa_printf(MSG_ERROR
, "Duplicate BSSID " MACSTR
867 " on interface '%s' and '%s'.",
869 conf
->bss
[i
]->iface
, bss
->iface
);
875 #ifdef CONFIG_IEEE80211R_AP
876 if (full_config
&& wpa_key_mgmt_ft(bss
->wpa_key_mgmt
) &&
877 (bss
->nas_identifier
== NULL
||
878 os_strlen(bss
->nas_identifier
) < 1 ||
879 os_strlen(bss
->nas_identifier
) > FT_R0KH_ID_MAX_LEN
)) {
880 wpa_printf(MSG_ERROR
, "FT (IEEE 802.11r) requires "
881 "nas_identifier to be configured as a 1..48 octet "
885 #endif /* CONFIG_IEEE80211R_AP */
887 #ifdef CONFIG_IEEE80211N
888 if (full_config
&& conf
->ieee80211n
&&
889 conf
->hw_mode
== HOSTAPD_MODE_IEEE80211B
) {
890 bss
->disable_11n
= 1;
891 wpa_printf(MSG_ERROR
, "HT (IEEE 802.11n) in 11b mode is not "
892 "allowed, disabling HT capabilities");
895 if (full_config
&& conf
->ieee80211n
&&
896 bss
->ssid
.security_policy
== SECURITY_STATIC_WEP
) {
897 bss
->disable_11n
= 1;
898 wpa_printf(MSG_ERROR
, "HT (IEEE 802.11n) with WEP is not "
899 "allowed, disabling HT capabilities");
902 if (full_config
&& conf
->ieee80211n
&& bss
->wpa
&&
903 !(bss
->wpa_pairwise
& WPA_CIPHER_CCMP
) &&
904 !(bss
->rsn_pairwise
& (WPA_CIPHER_CCMP
| WPA_CIPHER_GCMP
|
905 WPA_CIPHER_CCMP_256
| WPA_CIPHER_GCMP_256
)))
907 bss
->disable_11n
= 1;
908 wpa_printf(MSG_ERROR
, "HT (IEEE 802.11n) with WPA/WPA2 "
909 "requires CCMP/GCMP to be enabled, disabling HT "
912 #endif /* CONFIG_IEEE80211N */
914 #ifdef CONFIG_IEEE80211AC
915 if (full_config
&& conf
->ieee80211ac
&&
916 bss
->ssid
.security_policy
== SECURITY_STATIC_WEP
) {
917 bss
->disable_11ac
= 1;
918 wpa_printf(MSG_ERROR
,
919 "VHT (IEEE 802.11ac) with WEP is not allowed, disabling VHT capabilities");
922 if (full_config
&& conf
->ieee80211ac
&& bss
->wpa
&&
923 !(bss
->wpa_pairwise
& WPA_CIPHER_CCMP
) &&
924 !(bss
->rsn_pairwise
& (WPA_CIPHER_CCMP
| WPA_CIPHER_GCMP
|
925 WPA_CIPHER_CCMP_256
| WPA_CIPHER_GCMP_256
)))
927 bss
->disable_11ac
= 1;
928 wpa_printf(MSG_ERROR
,
929 "VHT (IEEE 802.11ac) with WPA/WPA2 requires CCMP/GCMP to be enabled, disabling VHT capabilities");
931 #endif /* CONFIG_IEEE80211AC */
934 if (full_config
&& bss
->wps_state
&& bss
->ignore_broadcast_ssid
) {
935 wpa_printf(MSG_INFO
, "WPS: ignore_broadcast_ssid "
936 "configuration forced WPS to be disabled");
940 if (full_config
&& bss
->wps_state
&&
941 bss
->ssid
.wep
.keys_set
&& bss
->wpa
== 0) {
942 wpa_printf(MSG_INFO
, "WPS: WEP configuration forced WPS to be "
947 if (full_config
&& bss
->wps_state
&& bss
->wpa
&&
949 !(bss
->rsn_pairwise
& (WPA_CIPHER_CCMP
| WPA_CIPHER_GCMP
|
950 WPA_CIPHER_CCMP_256
|
951 WPA_CIPHER_GCMP_256
)))) {
952 wpa_printf(MSG_INFO
, "WPS: WPA/TKIP configuration without "
953 "WPA2/CCMP/GCMP forced WPS to be disabled");
956 #endif /* CONFIG_WPS */
959 if (full_config
&& bss
->hs20
&&
961 !(bss
->rsn_pairwise
& (WPA_CIPHER_CCMP
| WPA_CIPHER_GCMP
|
962 WPA_CIPHER_CCMP_256
|
963 WPA_CIPHER_GCMP_256
)))) {
964 wpa_printf(MSG_ERROR
, "HS 2.0: WPA2-Enterprise/CCMP "
965 "configuration is required for Hotspot 2.0 "
969 #endif /* CONFIG_HS20 */
972 if (full_config
&& bss
->mbo_enabled
&& (bss
->wpa
& 2) &&
973 bss
->ieee80211w
== NO_MGMT_FRAME_PROTECTION
) {
974 wpa_printf(MSG_ERROR
,
975 "MBO: PMF needs to be enabled whenever using WPA2 with MBO");
978 #endif /* CONFIG_MBO */
984 static int hostapd_config_check_cw(struct hostapd_config
*conf
, int queue
)
986 int tx_cwmin
= conf
->tx_queue
[queue
].cwmin
;
987 int tx_cwmax
= conf
->tx_queue
[queue
].cwmax
;
988 int ac_cwmin
= conf
->wmm_ac_params
[queue
].cwmin
;
989 int ac_cwmax
= conf
->wmm_ac_params
[queue
].cwmax
;
991 if (tx_cwmin
> tx_cwmax
) {
992 wpa_printf(MSG_ERROR
,
993 "Invalid TX queue cwMin/cwMax values. cwMin(%d) greater than cwMax(%d)",
997 if (ac_cwmin
> ac_cwmax
) {
998 wpa_printf(MSG_ERROR
,
999 "Invalid WMM AC cwMin/cwMax values. cwMin(%d) greater than cwMax(%d)",
1000 ac_cwmin
, ac_cwmax
);
1007 int hostapd_config_check(struct hostapd_config
*conf
, int full_config
)
1011 if (full_config
&& conf
->ieee80211d
&&
1012 (!conf
->country
[0] || !conf
->country
[1])) {
1013 wpa_printf(MSG_ERROR
, "Cannot enable IEEE 802.11d without "
1014 "setting the country_code");
1018 if (full_config
&& conf
->ieee80211h
&& !conf
->ieee80211d
) {
1019 wpa_printf(MSG_ERROR
, "Cannot enable IEEE 802.11h without "
1020 "IEEE 802.11d enabled");
1024 if (full_config
&& conf
->local_pwr_constraint
!= -1 &&
1025 !conf
->ieee80211d
) {
1026 wpa_printf(MSG_ERROR
, "Cannot add Power Constraint element without Country element");
1030 if (full_config
&& conf
->spectrum_mgmt_required
&&
1031 conf
->local_pwr_constraint
== -1) {
1032 wpa_printf(MSG_ERROR
, "Cannot set Spectrum Management bit without Country and Power Constraint elements");
1036 for (i
= 0; i
< NUM_TX_QUEUES
; i
++) {
1037 if (hostapd_config_check_cw(conf
, i
))
1041 for (i
= 0; i
< conf
->num_bss
; i
++) {
1042 if (hostapd_config_check_bss(conf
->bss
[i
], conf
, full_config
))
1050 void hostapd_set_security_params(struct hostapd_bss_config
*bss
,
1053 if (bss
->individual_wep_key_len
== 0) {
1054 /* individual keys are not use; can use key idx0 for
1056 bss
->broadcast_key_idx_min
= 0;
1059 if ((bss
->wpa
& 2) && bss
->rsn_pairwise
== 0)
1060 bss
->rsn_pairwise
= bss
->wpa_pairwise
;
1061 if (bss
->group_cipher
)
1062 bss
->wpa_group
= bss
->group_cipher
;
1064 bss
->wpa_group
= wpa_select_ap_group_cipher(bss
->wpa
,
1067 if (!bss
->wpa_group_rekey_set
)
1068 bss
->wpa_group_rekey
= bss
->wpa_group
== WPA_CIPHER_TKIP
?
1072 bss
->radius
->auth_server
= bss
->radius
->auth_servers
;
1073 bss
->radius
->acct_server
= bss
->radius
->acct_servers
;
1076 if (bss
->wpa
&& bss
->ieee802_1x
) {
1077 bss
->ssid
.security_policy
= SECURITY_WPA
;
1078 } else if (bss
->wpa
) {
1079 bss
->ssid
.security_policy
= SECURITY_WPA_PSK
;
1080 } else if (bss
->ieee802_1x
) {
1081 int cipher
= WPA_CIPHER_NONE
;
1082 bss
->ssid
.security_policy
= SECURITY_IEEE_802_1X
;
1083 bss
->ssid
.wep
.default_len
= bss
->default_wep_key_len
;
1084 if (full_config
&& bss
->default_wep_key_len
) {
1085 cipher
= bss
->default_wep_key_len
>= 13 ?
1086 WPA_CIPHER_WEP104
: WPA_CIPHER_WEP40
;
1087 } else if (full_config
&& bss
->ssid
.wep
.keys_set
) {
1088 if (bss
->ssid
.wep
.len
[0] >= 13)
1089 cipher
= WPA_CIPHER_WEP104
;
1091 cipher
= WPA_CIPHER_WEP40
;
1093 bss
->wpa_group
= cipher
;
1094 bss
->wpa_pairwise
= cipher
;
1095 bss
->rsn_pairwise
= cipher
;
1097 bss
->wpa_key_mgmt
= WPA_KEY_MGMT_IEEE8021X_NO_WPA
;
1098 } else if (bss
->ssid
.wep
.keys_set
) {
1099 int cipher
= WPA_CIPHER_WEP40
;
1100 if (bss
->ssid
.wep
.len
[0] >= 13)
1101 cipher
= WPA_CIPHER_WEP104
;
1102 bss
->ssid
.security_policy
= SECURITY_STATIC_WEP
;
1103 bss
->wpa_group
= cipher
;
1104 bss
->wpa_pairwise
= cipher
;
1105 bss
->rsn_pairwise
= cipher
;
1107 bss
->wpa_key_mgmt
= WPA_KEY_MGMT_NONE
;
1108 } else if (bss
->osen
) {
1109 bss
->ssid
.security_policy
= SECURITY_OSEN
;
1110 bss
->wpa_group
= WPA_CIPHER_CCMP
;
1111 bss
->wpa_pairwise
= 0;
1112 bss
->rsn_pairwise
= WPA_CIPHER_CCMP
;
1114 bss
->ssid
.security_policy
= SECURITY_PLAINTEXT
;
1116 bss
->wpa_group
= WPA_CIPHER_NONE
;
1117 bss
->wpa_pairwise
= WPA_CIPHER_NONE
;
1118 bss
->rsn_pairwise
= WPA_CIPHER_NONE
;
1119 bss
->wpa_key_mgmt
= WPA_KEY_MGMT_NONE
;