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 "eap_common/eap_wsc_common.h"
17 #include "eap_server/eap.h"
20 #include "ap_config.h"
23 static void hostapd_config_free_vlan(struct hostapd_bss_config
*bss
)
25 struct hostapd_vlan
*vlan
, *prev
;
39 void hostapd_config_defaults_bss(struct hostapd_bss_config
*bss
)
41 dl_list_init(&bss
->anqp_elem
);
43 bss
->logger_syslog_level
= HOSTAPD_LEVEL_INFO
;
44 bss
->logger_stdout_level
= HOSTAPD_LEVEL_INFO
;
45 bss
->logger_syslog
= (unsigned int) -1;
46 bss
->logger_stdout
= (unsigned int) -1;
48 bss
->auth_algs
= WPA_AUTH_ALG_OPEN
| WPA_AUTH_ALG_SHARED
;
50 bss
->wep_rekeying_period
= 300;
51 /* use key0 in individual key and key1 in broadcast key */
52 bss
->broadcast_key_idx_min
= 1;
53 bss
->broadcast_key_idx_max
= 2;
54 bss
->eap_reauth_period
= 3600;
56 bss
->wpa_group_rekey
= 600;
57 bss
->wpa_gmk_rekey
= 86400;
58 bss
->wpa_key_mgmt
= WPA_KEY_MGMT_PSK
;
59 bss
->wpa_pairwise
= WPA_CIPHER_TKIP
;
60 bss
->wpa_group
= WPA_CIPHER_TKIP
;
61 bss
->rsn_pairwise
= 0;
63 bss
->max_num_sta
= MAX_STA_COUNT
;
67 bss
->radius_server_auth_port
= 1812;
68 bss
->eap_sim_db_timeout
= 1;
69 bss
->ap_max_inactivity
= AP_MAX_INACTIVITY
;
70 bss
->eapol_version
= EAPOL_VERSION
;
72 bss
->max_listen_interval
= 65535;
74 bss
->pwd_group
= 19; /* ECC: GF(p=256) */
76 #ifdef CONFIG_IEEE80211W
77 bss
->assoc_sa_query_max_timeout
= 1000;
78 bss
->assoc_sa_query_retry_timeout
= 201;
79 bss
->group_mgmt_cipher
= WPA_CIPHER_AES_128_CMAC
;
80 #endif /* CONFIG_IEEE80211W */
81 #ifdef EAP_SERVER_FAST
82 /* both anonymous and authenticated provisioning */
83 bss
->eap_fast_prov
= 3;
84 bss
->pac_key_lifetime
= 7 * 24 * 60 * 60;
85 bss
->pac_key_refresh_time
= 1 * 24 * 60 * 60;
86 #endif /* EAP_SERVER_FAST */
88 /* Set to -1 as defaults depends on HT in setup */
89 bss
->wmm_enabled
= -1;
91 #ifdef CONFIG_IEEE80211R_AP
93 #endif /* CONFIG_IEEE80211R_AP */
95 bss
->radius_das_time_window
= 300;
97 bss
->sae_anti_clogging_threshold
= 5;
100 dl_list_init(&bss
->fils_realms
);
101 #endif /* CONFIG_FILS */
105 struct hostapd_config
* hostapd_config_defaults(void)
107 #define ecw2cw(ecw) ((1 << (ecw)) - 1)
109 struct hostapd_config
*conf
;
110 struct hostapd_bss_config
*bss
;
111 const int aCWmin
= 4, aCWmax
= 10;
112 const struct hostapd_wmm_ac_params ac_bk
=
113 { aCWmin
, aCWmax
, 7, 0, 0 }; /* background traffic */
114 const struct hostapd_wmm_ac_params ac_be
=
115 { aCWmin
, aCWmax
, 3, 0, 0 }; /* best effort traffic */
116 const struct hostapd_wmm_ac_params ac_vi
= /* video traffic */
117 { aCWmin
- 1, aCWmin
, 2, 3008 / 32, 0 };
118 const struct hostapd_wmm_ac_params ac_vo
= /* voice traffic */
119 { aCWmin
- 2, aCWmin
- 1, 2, 1504 / 32, 0 };
120 const struct hostapd_tx_queue_params txq_bk
=
121 { 7, ecw2cw(aCWmin
), ecw2cw(aCWmax
), 0 };
122 const struct hostapd_tx_queue_params txq_be
=
123 { 3, ecw2cw(aCWmin
), 4 * (ecw2cw(aCWmin
) + 1) - 1, 0};
124 const struct hostapd_tx_queue_params txq_vi
=
125 { 1, (ecw2cw(aCWmin
) + 1) / 2 - 1, ecw2cw(aCWmin
), 30};
126 const struct hostapd_tx_queue_params txq_vo
=
127 { 1, (ecw2cw(aCWmin
) + 1) / 4 - 1,
128 (ecw2cw(aCWmin
) + 1) / 2 - 1, 15};
132 conf
= os_zalloc(sizeof(*conf
));
133 bss
= os_zalloc(sizeof(*bss
));
134 if (conf
== NULL
|| bss
== NULL
) {
135 wpa_printf(MSG_ERROR
, "Failed to allocate memory for "
136 "configuration data.");
141 conf
->bss
= os_calloc(1, sizeof(struct hostapd_bss_config
*));
142 if (conf
->bss
== NULL
) {
149 bss
->radius
= os_zalloc(sizeof(*bss
->radius
));
150 if (bss
->radius
== NULL
) {
157 hostapd_config_defaults_bss(bss
);
161 conf
->beacon_int
= 100;
162 conf
->rts_threshold
= -1; /* use driver default: 2347 */
163 conf
->fragm_threshold
= -1; /* user driver default: 2346 */
164 conf
->send_probe_response
= 1;
165 /* Set to invalid value means do not add Power Constraint IE */
166 conf
->local_pwr_constraint
= -1;
168 conf
->wmm_ac_params
[0] = ac_be
;
169 conf
->wmm_ac_params
[1] = ac_bk
;
170 conf
->wmm_ac_params
[2] = ac_vi
;
171 conf
->wmm_ac_params
[3] = ac_vo
;
173 conf
->tx_queue
[0] = txq_vo
;
174 conf
->tx_queue
[1] = txq_vi
;
175 conf
->tx_queue
[2] = txq_be
;
176 conf
->tx_queue
[3] = txq_bk
;
178 conf
->ht_capab
= HT_CAP_INFO_SMPS_DISABLED
;
180 conf
->ap_table_max_size
= 255;
181 conf
->ap_table_expiration_time
= 60;
182 conf
->track_sta_max_age
= 180;
184 #ifdef CONFIG_TESTING_OPTIONS
185 conf
->ignore_probe_probability
= 0.0;
186 conf
->ignore_auth_probability
= 0.0;
187 conf
->ignore_assoc_probability
= 0.0;
188 conf
->ignore_reassoc_probability
= 0.0;
189 conf
->corrupt_gtk_rekey_mic_probability
= 0.0;
190 conf
->ecsa_ie_only
= 0;
191 #endif /* CONFIG_TESTING_OPTIONS */
194 conf
->acs_ch_list
.num
= 0;
196 conf
->acs_num_scans
= 5;
197 #endif /* CONFIG_ACS */
203 int hostapd_mac_comp(const void *a
, const void *b
)
205 return os_memcmp(a
, b
, sizeof(macaddr
));
209 static int hostapd_config_read_wpa_psk(const char *fname
,
210 struct hostapd_ssid
*ssid
)
214 int line
= 0, ret
= 0, len
, ok
;
216 struct hostapd_wpa_psk
*psk
;
221 f
= fopen(fname
, "r");
223 wpa_printf(MSG_ERROR
, "WPA PSK file '%s' not found.", fname
);
227 while (fgets(buf
, sizeof(buf
), f
)) {
233 while (*pos
!= '\0') {
243 if (hwaddr_aton(buf
, addr
)) {
244 wpa_printf(MSG_ERROR
, "Invalid MAC address '%s' on "
245 "line %d in '%s'", buf
, line
, fname
);
250 psk
= os_zalloc(sizeof(*psk
));
252 wpa_printf(MSG_ERROR
, "WPA PSK allocation failed");
256 if (is_zero_ether_addr(addr
))
259 os_memcpy(psk
->addr
, addr
, ETH_ALEN
);
263 wpa_printf(MSG_ERROR
, "No PSK on line %d in '%s'",
272 len
= os_strlen(pos
);
273 if (len
== 64 && hexstr2bin(pos
, psk
->psk
, PMK_LEN
) == 0)
275 else if (len
>= 8 && len
< 64) {
276 pbkdf2_sha1(pos
, ssid
->ssid
, ssid
->ssid_len
,
277 4096, psk
->psk
, PMK_LEN
);
281 wpa_printf(MSG_ERROR
, "Invalid PSK '%s' on line %d in "
282 "'%s'", pos
, line
, fname
);
288 psk
->next
= ssid
->wpa_psk
;
298 static int hostapd_derive_psk(struct hostapd_ssid
*ssid
)
300 ssid
->wpa_psk
= os_zalloc(sizeof(struct hostapd_wpa_psk
));
301 if (ssid
->wpa_psk
== NULL
) {
302 wpa_printf(MSG_ERROR
, "Unable to alloc space for PSK");
305 wpa_hexdump_ascii(MSG_DEBUG
, "SSID",
306 (u8
*) ssid
->ssid
, ssid
->ssid_len
);
307 wpa_hexdump_ascii_key(MSG_DEBUG
, "PSK (ASCII passphrase)",
308 (u8
*) ssid
->wpa_passphrase
,
309 os_strlen(ssid
->wpa_passphrase
));
310 pbkdf2_sha1(ssid
->wpa_passphrase
,
311 ssid
->ssid
, ssid
->ssid_len
,
312 4096, ssid
->wpa_psk
->psk
, PMK_LEN
);
313 wpa_hexdump_key(MSG_DEBUG
, "PSK (from passphrase)",
314 ssid
->wpa_psk
->psk
, PMK_LEN
);
319 int hostapd_setup_wpa_psk(struct hostapd_bss_config
*conf
)
321 struct hostapd_ssid
*ssid
= &conf
->ssid
;
323 if (ssid
->wpa_passphrase
!= NULL
) {
324 if (ssid
->wpa_psk
!= NULL
) {
325 wpa_printf(MSG_DEBUG
, "Using pre-configured WPA PSK "
326 "instead of passphrase");
328 wpa_printf(MSG_DEBUG
, "Deriving WPA PSK based on "
330 if (hostapd_derive_psk(ssid
) < 0)
333 ssid
->wpa_psk
->group
= 1;
336 return hostapd_config_read_wpa_psk(ssid
->wpa_psk_file
, &conf
->ssid
);
340 static void hostapd_config_free_radius(struct hostapd_radius_server
*servers
,
345 for (i
= 0; i
< num_servers
; i
++) {
346 os_free(servers
[i
].shared_secret
);
352 struct hostapd_radius_attr
*
353 hostapd_config_get_radius_attr(struct hostapd_radius_attr
*attr
, u8 type
)
355 for (; attr
; attr
= attr
->next
) {
356 if (attr
->type
== type
)
363 static void hostapd_config_free_radius_attr(struct hostapd_radius_attr
*attr
)
365 struct hostapd_radius_attr
*prev
;
370 wpabuf_free(prev
->val
);
376 void hostapd_config_free_eap_user(struct hostapd_eap_user
*user
)
378 hostapd_config_free_radius_attr(user
->accept_attr
);
379 os_free(user
->identity
);
380 bin_clear_free(user
->password
, user
->password_len
);
385 static void hostapd_config_free_wep(struct hostapd_wep_keys
*keys
)
388 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
389 bin_clear_free(keys
->key
[i
], keys
->len
[i
]);
395 void hostapd_config_clear_wpa_psk(struct hostapd_wpa_psk
**l
)
397 struct hostapd_wpa_psk
*psk
, *tmp
;
399 for (psk
= *l
; psk
;) {
402 bin_clear_free(tmp
, sizeof(*tmp
));
408 static void hostapd_config_free_anqp_elem(struct hostapd_bss_config
*conf
)
410 struct anqp_element
*elem
;
412 while ((elem
= dl_list_first(&conf
->anqp_elem
, struct anqp_element
,
414 dl_list_del(&elem
->list
);
415 wpabuf_free(elem
->payload
);
421 static void hostapd_config_free_fils_realms(struct hostapd_bss_config
*conf
)
424 struct fils_realm
*realm
;
426 while ((realm
= dl_list_first(&conf
->fils_realms
, struct fils_realm
,
428 dl_list_del(&realm
->list
);
431 #endif /* CONFIG_FILS */
435 void hostapd_config_free_bss(struct hostapd_bss_config
*conf
)
437 struct hostapd_eap_user
*user
, *prev_user
;
442 hostapd_config_clear_wpa_psk(&conf
->ssid
.wpa_psk
);
444 str_clear_free(conf
->ssid
.wpa_passphrase
);
445 os_free(conf
->ssid
.wpa_psk_file
);
446 hostapd_config_free_wep(&conf
->ssid
.wep
);
447 #ifdef CONFIG_FULL_DYNAMIC_VLAN
448 os_free(conf
->ssid
.vlan_tagged_interface
);
449 #endif /* CONFIG_FULL_DYNAMIC_VLAN */
451 user
= conf
->eap_user
;
455 hostapd_config_free_eap_user(prev_user
);
457 os_free(conf
->eap_user_sqlite
);
459 os_free(conf
->eap_req_id_text
);
460 os_free(conf
->erp_domain
);
461 os_free(conf
->accept_mac
);
462 os_free(conf
->deny_mac
);
463 os_free(conf
->nas_identifier
);
465 hostapd_config_free_radius(conf
->radius
->auth_servers
,
466 conf
->radius
->num_auth_servers
);
467 hostapd_config_free_radius(conf
->radius
->acct_servers
,
468 conf
->radius
->num_acct_servers
);
470 hostapd_config_free_radius_attr(conf
->radius_auth_req_attr
);
471 hostapd_config_free_radius_attr(conf
->radius_acct_req_attr
);
472 os_free(conf
->rsn_preauth_interfaces
);
473 os_free(conf
->ctrl_interface
);
474 os_free(conf
->ca_cert
);
475 os_free(conf
->server_cert
);
476 os_free(conf
->private_key
);
477 os_free(conf
->private_key_passwd
);
478 os_free(conf
->ocsp_stapling_response
);
479 os_free(conf
->ocsp_stapling_response_multi
);
480 os_free(conf
->dh_file
);
481 os_free(conf
->openssl_ciphers
);
482 os_free(conf
->pac_opaque_encr_key
);
483 os_free(conf
->eap_fast_a_id
);
484 os_free(conf
->eap_fast_a_id_info
);
485 os_free(conf
->eap_sim_db
);
486 os_free(conf
->radius_server_clients
);
487 os_free(conf
->radius
);
488 os_free(conf
->radius_das_shared_secret
);
489 hostapd_config_free_vlan(conf
);
490 os_free(conf
->time_zone
);
492 #ifdef CONFIG_IEEE80211R_AP
494 struct ft_remote_r0kh
*r0kh
, *r0kh_prev
;
495 struct ft_remote_r1kh
*r1kh
, *r1kh_prev
;
497 r0kh
= conf
->r0kh_list
;
498 conf
->r0kh_list
= NULL
;
505 r1kh
= conf
->r1kh_list
;
506 conf
->r1kh_list
= NULL
;
513 #endif /* CONFIG_IEEE80211R_AP */
516 os_free(conf
->wps_pin_requests
);
517 os_free(conf
->device_name
);
518 os_free(conf
->manufacturer
);
519 os_free(conf
->model_name
);
520 os_free(conf
->model_number
);
521 os_free(conf
->serial_number
);
522 os_free(conf
->config_methods
);
523 os_free(conf
->ap_pin
);
524 os_free(conf
->extra_cred
);
525 os_free(conf
->ap_settings
);
526 os_free(conf
->upnp_iface
);
527 os_free(conf
->friendly_name
);
528 os_free(conf
->manufacturer_url
);
529 os_free(conf
->model_description
);
530 os_free(conf
->model_url
);
535 for (i
= 0; i
< MAX_WPS_VENDOR_EXTENSIONS
; i
++)
536 wpabuf_free(conf
->wps_vendor_ext
[i
]);
538 wpabuf_free(conf
->wps_nfc_dh_pubkey
);
539 wpabuf_free(conf
->wps_nfc_dh_privkey
);
540 wpabuf_free(conf
->wps_nfc_dev_pw
);
541 #endif /* CONFIG_WPS */
543 os_free(conf
->roaming_consortium
);
544 os_free(conf
->venue_name
);
545 os_free(conf
->nai_realm_data
);
546 os_free(conf
->network_auth_type
);
547 os_free(conf
->anqp_3gpp_cell_net
);
548 os_free(conf
->domain_name
);
549 hostapd_config_free_anqp_elem(conf
);
551 #ifdef CONFIG_RADIUS_TEST
552 os_free(conf
->dump_msk_file
);
553 #endif /* CONFIG_RADIUS_TEST */
556 os_free(conf
->hs20_oper_friendly_name
);
557 os_free(conf
->hs20_wan_metrics
);
558 os_free(conf
->hs20_connection_capability
);
559 os_free(conf
->hs20_operating_class
);
560 os_free(conf
->hs20_icons
);
561 if (conf
->hs20_osu_providers
) {
563 for (i
= 0; i
< conf
->hs20_osu_providers_count
; i
++) {
564 struct hs20_osu_provider
*p
;
566 p
= &conf
->hs20_osu_providers
[i
];
567 os_free(p
->friendly_name
);
568 os_free(p
->server_uri
);
569 os_free(p
->method_list
);
570 for (j
= 0; j
< p
->icons_count
; j
++)
571 os_free(p
->icons
[j
]);
574 os_free(p
->service_desc
);
576 os_free(conf
->hs20_osu_providers
);
578 os_free(conf
->subscr_remediation_url
);
579 #endif /* CONFIG_HS20 */
581 wpabuf_free(conf
->vendor_elements
);
582 wpabuf_free(conf
->assocresp_elements
);
584 os_free(conf
->sae_groups
);
586 os_free(conf
->wowlan_triggers
);
588 os_free(conf
->server_id
);
590 #ifdef CONFIG_TESTING_OPTIONS
591 wpabuf_free(conf
->own_ie_override
);
592 #endif /* CONFIG_TESTING_OPTIONS */
594 os_free(conf
->no_probe_resp_if_seen_on
);
595 os_free(conf
->no_auth_if_seen_on
);
597 hostapd_config_free_fils_realms(conf
);
604 * hostapd_config_free - Free hostapd configuration
605 * @conf: Configuration data from hostapd_config_read().
607 void hostapd_config_free(struct hostapd_config
*conf
)
614 for (i
= 0; i
< conf
->num_bss
; i
++)
615 hostapd_config_free_bss(conf
->bss
[i
]);
617 os_free(conf
->supported_rates
);
618 os_free(conf
->basic_rates
);
619 os_free(conf
->acs_ch_list
.range
);
620 os_free(conf
->driver_params
);
622 os_free(conf
->acs_chan_bias
);
623 #endif /* CONFIG_ACS */
624 wpabuf_free(conf
->lci
);
625 wpabuf_free(conf
->civic
);
632 * hostapd_maclist_found - Find a MAC address from a list
633 * @list: MAC address list
634 * @num_entries: Number of addresses in the list
635 * @addr: Address to search for
636 * @vlan_id: Buffer for returning VLAN ID or %NULL if not needed
637 * Returns: 1 if address is in the list or 0 if not.
639 * Perform a binary search for given MAC address from a pre-sorted list.
641 int hostapd_maclist_found(struct mac_acl_entry
*list
, int num_entries
,
642 const u8
*addr
, struct vlan_description
*vlan_id
)
644 int start
, end
, middle
, res
;
647 end
= num_entries
- 1;
649 while (start
<= end
) {
650 middle
= (start
+ end
) / 2;
651 res
= os_memcmp(list
[middle
].addr
, addr
, ETH_ALEN
);
654 *vlan_id
= list
[middle
].vlan_id
;
667 int hostapd_rate_found(int *list
, int rate
)
674 for (i
= 0; list
[i
] >= 0; i
++)
682 int hostapd_vlan_valid(struct hostapd_vlan
*vlan
,
683 struct vlan_description
*vlan_desc
)
685 struct hostapd_vlan
*v
= vlan
;
688 if (!vlan_desc
->notempty
|| vlan_desc
->untagged
< 0 ||
689 vlan_desc
->untagged
> MAX_VLAN_ID
)
691 for (i
= 0; i
< MAX_NUM_TAGGED_VLAN
; i
++) {
692 if (vlan_desc
->tagged
[i
] < 0 ||
693 vlan_desc
->tagged
[i
] > MAX_VLAN_ID
)
696 if (!vlan_desc
->untagged
&& !vlan_desc
->tagged
[0])
700 if (!vlan_compare(&v
->vlan_desc
, vlan_desc
) ||
701 v
->vlan_id
== VLAN_ID_WILDCARD
)
709 const char * hostapd_get_vlan_id_ifname(struct hostapd_vlan
*vlan
, int vlan_id
)
711 struct hostapd_vlan
*v
= vlan
;
713 if (v
->vlan_id
== vlan_id
)
721 const u8
* hostapd_get_psk(const struct hostapd_bss_config
*conf
,
722 const u8
*addr
, const u8
*p2p_dev_addr
,
725 struct hostapd_wpa_psk
*psk
;
726 int next_ok
= prev_psk
== NULL
;
728 if (p2p_dev_addr
&& !is_zero_ether_addr(p2p_dev_addr
)) {
729 wpa_printf(MSG_DEBUG
, "Searching a PSK for " MACSTR
730 " p2p_dev_addr=" MACSTR
" prev_psk=%p",
731 MAC2STR(addr
), MAC2STR(p2p_dev_addr
), prev_psk
);
732 addr
= NULL
; /* Use P2P Device Address for matching */
734 wpa_printf(MSG_DEBUG
, "Searching a PSK for " MACSTR
736 MAC2STR(addr
), prev_psk
);
739 for (psk
= conf
->ssid
.wpa_psk
; psk
!= NULL
; psk
= psk
->next
) {
742 (addr
&& os_memcmp(psk
->addr
, addr
, ETH_ALEN
) == 0) ||
743 (!addr
&& p2p_dev_addr
&&
744 os_memcmp(psk
->p2p_dev_addr
, p2p_dev_addr
, ETH_ALEN
) ==
748 if (psk
->psk
== prev_psk
)
756 static int hostapd_config_check_bss(struct hostapd_bss_config
*bss
,
757 struct hostapd_config
*conf
,
760 if (full_config
&& bss
->ieee802_1x
&& !bss
->eap_server
&&
761 !bss
->radius
->auth_servers
) {
762 wpa_printf(MSG_ERROR
, "Invalid IEEE 802.1X configuration (no "
763 "EAP authenticator configured).");
770 wep
= bss
->default_wep_key_len
> 0 ||
771 bss
->individual_wep_key_len
> 0;
772 for (i
= 0; i
< NUM_WEP_KEYS
; i
++) {
773 if (bss
->ssid
.wep
.keys_set
) {
780 wpa_printf(MSG_ERROR
, "WEP configuration in a WPA network is not supported");
785 if (full_config
&& bss
->wpa
&&
786 bss
->wpa_psk_radius
!= PSK_RADIUS_IGNORED
&&
787 bss
->macaddr_acl
!= USE_EXTERNAL_RADIUS_AUTH
) {
788 wpa_printf(MSG_ERROR
, "WPA-PSK using RADIUS enabled, but no "
789 "RADIUS checking (macaddr_acl=2) enabled.");
793 if (full_config
&& bss
->wpa
&& (bss
->wpa_key_mgmt
& WPA_KEY_MGMT_PSK
) &&
794 bss
->ssid
.wpa_psk
== NULL
&& bss
->ssid
.wpa_passphrase
== NULL
&&
795 bss
->ssid
.wpa_psk_file
== NULL
&&
796 (bss
->wpa_psk_radius
!= PSK_RADIUS_REQUIRED
||
797 bss
->macaddr_acl
!= USE_EXTERNAL_RADIUS_AUTH
)) {
798 wpa_printf(MSG_ERROR
, "WPA-PSK enabled, but PSK or passphrase "
799 "is not configured.");
803 if (full_config
&& !is_zero_ether_addr(bss
->bssid
)) {
806 for (i
= 0; i
< conf
->num_bss
; i
++) {
807 if (conf
->bss
[i
] != bss
&&
808 (hostapd_mac_comp(conf
->bss
[i
]->bssid
,
810 wpa_printf(MSG_ERROR
, "Duplicate BSSID " MACSTR
811 " on interface '%s' and '%s'.",
813 conf
->bss
[i
]->iface
, bss
->iface
);
819 #ifdef CONFIG_IEEE80211R_AP
820 if (full_config
&& wpa_key_mgmt_ft(bss
->wpa_key_mgmt
) &&
821 (bss
->nas_identifier
== NULL
||
822 os_strlen(bss
->nas_identifier
) < 1 ||
823 os_strlen(bss
->nas_identifier
) > FT_R0KH_ID_MAX_LEN
)) {
824 wpa_printf(MSG_ERROR
, "FT (IEEE 802.11r) requires "
825 "nas_identifier to be configured as a 1..48 octet "
829 #endif /* CONFIG_IEEE80211R_AP */
831 #ifdef CONFIG_IEEE80211N
832 if (full_config
&& conf
->ieee80211n
&&
833 conf
->hw_mode
== HOSTAPD_MODE_IEEE80211B
) {
834 bss
->disable_11n
= 1;
835 wpa_printf(MSG_ERROR
, "HT (IEEE 802.11n) in 11b mode is not "
836 "allowed, disabling HT capabilities");
839 if (full_config
&& conf
->ieee80211n
&&
840 bss
->ssid
.security_policy
== SECURITY_STATIC_WEP
) {
841 bss
->disable_11n
= 1;
842 wpa_printf(MSG_ERROR
, "HT (IEEE 802.11n) with WEP is not "
843 "allowed, disabling HT capabilities");
846 if (full_config
&& conf
->ieee80211n
&& bss
->wpa
&&
847 !(bss
->wpa_pairwise
& WPA_CIPHER_CCMP
) &&
848 !(bss
->rsn_pairwise
& (WPA_CIPHER_CCMP
| WPA_CIPHER_GCMP
|
849 WPA_CIPHER_CCMP_256
| WPA_CIPHER_GCMP_256
)))
851 bss
->disable_11n
= 1;
852 wpa_printf(MSG_ERROR
, "HT (IEEE 802.11n) with WPA/WPA2 "
853 "requires CCMP/GCMP to be enabled, disabling HT "
856 #endif /* CONFIG_IEEE80211N */
858 #ifdef CONFIG_IEEE80211AC
859 if (full_config
&& conf
->ieee80211ac
&&
860 bss
->ssid
.security_policy
== SECURITY_STATIC_WEP
) {
861 bss
->disable_11ac
= 1;
862 wpa_printf(MSG_ERROR
,
863 "VHT (IEEE 802.11ac) with WEP is not allowed, disabling VHT capabilities");
866 if (full_config
&& conf
->ieee80211ac
&& bss
->wpa
&&
867 !(bss
->wpa_pairwise
& WPA_CIPHER_CCMP
) &&
868 !(bss
->rsn_pairwise
& (WPA_CIPHER_CCMP
| WPA_CIPHER_GCMP
|
869 WPA_CIPHER_CCMP_256
| WPA_CIPHER_GCMP_256
)))
871 bss
->disable_11ac
= 1;
872 wpa_printf(MSG_ERROR
,
873 "VHT (IEEE 802.11ac) with WPA/WPA2 requires CCMP/GCMP to be enabled, disabling VHT capabilities");
875 #endif /* CONFIG_IEEE80211AC */
878 if (full_config
&& bss
->wps_state
&& bss
->ignore_broadcast_ssid
) {
879 wpa_printf(MSG_INFO
, "WPS: ignore_broadcast_ssid "
880 "configuration forced WPS to be disabled");
884 if (full_config
&& bss
->wps_state
&&
885 bss
->ssid
.wep
.keys_set
&& bss
->wpa
== 0) {
886 wpa_printf(MSG_INFO
, "WPS: WEP configuration forced WPS to be "
891 if (full_config
&& bss
->wps_state
&& bss
->wpa
&&
893 !(bss
->rsn_pairwise
& (WPA_CIPHER_CCMP
| WPA_CIPHER_GCMP
)))) {
894 wpa_printf(MSG_INFO
, "WPS: WPA/TKIP configuration without "
895 "WPA2/CCMP/GCMP forced WPS to be disabled");
898 #endif /* CONFIG_WPS */
901 if (full_config
&& bss
->hs20
&&
903 !(bss
->rsn_pairwise
& (WPA_CIPHER_CCMP
| WPA_CIPHER_GCMP
|
904 WPA_CIPHER_CCMP_256
|
905 WPA_CIPHER_GCMP_256
)))) {
906 wpa_printf(MSG_ERROR
, "HS 2.0: WPA2-Enterprise/CCMP "
907 "configuration is required for Hotspot 2.0 "
911 #endif /* CONFIG_HS20 */
914 if (full_config
&& bss
->mbo_enabled
&& (bss
->wpa
& 2) &&
915 bss
->ieee80211w
== NO_MGMT_FRAME_PROTECTION
) {
916 wpa_printf(MSG_ERROR
,
917 "MBO: PMF needs to be enabled whenever using WPA2 with MBO");
920 #endif /* CONFIG_MBO */
926 static int hostapd_config_check_cw(struct hostapd_config
*conf
, int queue
)
928 int tx_cwmin
= conf
->tx_queue
[queue
].cwmin
;
929 int tx_cwmax
= conf
->tx_queue
[queue
].cwmax
;
930 int ac_cwmin
= conf
->wmm_ac_params
[queue
].cwmin
;
931 int ac_cwmax
= conf
->wmm_ac_params
[queue
].cwmax
;
933 if (tx_cwmin
> tx_cwmax
) {
934 wpa_printf(MSG_ERROR
,
935 "Invalid TX queue cwMin/cwMax values. cwMin(%d) greater than cwMax(%d)",
939 if (ac_cwmin
> ac_cwmax
) {
940 wpa_printf(MSG_ERROR
,
941 "Invalid WMM AC cwMin/cwMax values. cwMin(%d) greater than cwMax(%d)",
949 int hostapd_config_check(struct hostapd_config
*conf
, int full_config
)
953 if (full_config
&& conf
->ieee80211d
&&
954 (!conf
->country
[0] || !conf
->country
[1])) {
955 wpa_printf(MSG_ERROR
, "Cannot enable IEEE 802.11d without "
956 "setting the country_code");
960 if (full_config
&& conf
->ieee80211h
&& !conf
->ieee80211d
) {
961 wpa_printf(MSG_ERROR
, "Cannot enable IEEE 802.11h without "
962 "IEEE 802.11d enabled");
966 if (full_config
&& conf
->local_pwr_constraint
!= -1 &&
968 wpa_printf(MSG_ERROR
, "Cannot add Power Constraint element without Country element");
972 if (full_config
&& conf
->spectrum_mgmt_required
&&
973 conf
->local_pwr_constraint
== -1) {
974 wpa_printf(MSG_ERROR
, "Cannot set Spectrum Management bit without Country and Power Constraint elements");
978 for (i
= 0; i
< NUM_TX_QUEUES
; i
++) {
979 if (hostapd_config_check_cw(conf
, i
))
983 for (i
= 0; i
< conf
->num_bss
; i
++) {
984 if (hostapd_config_check_bss(conf
->bss
[i
], conf
, full_config
))
992 void hostapd_set_security_params(struct hostapd_bss_config
*bss
,
995 if (bss
->individual_wep_key_len
== 0) {
996 /* individual keys are not use; can use key idx0 for
998 bss
->broadcast_key_idx_min
= 0;
1001 if ((bss
->wpa
& 2) && bss
->rsn_pairwise
== 0)
1002 bss
->rsn_pairwise
= bss
->wpa_pairwise
;
1003 bss
->wpa_group
= wpa_select_ap_group_cipher(bss
->wpa
, bss
->wpa_pairwise
,
1007 bss
->radius
->auth_server
= bss
->radius
->auth_servers
;
1008 bss
->radius
->acct_server
= bss
->radius
->acct_servers
;
1011 if (bss
->wpa
&& bss
->ieee802_1x
) {
1012 bss
->ssid
.security_policy
= SECURITY_WPA
;
1013 } else if (bss
->wpa
) {
1014 bss
->ssid
.security_policy
= SECURITY_WPA_PSK
;
1015 } else if (bss
->ieee802_1x
) {
1016 int cipher
= WPA_CIPHER_NONE
;
1017 bss
->ssid
.security_policy
= SECURITY_IEEE_802_1X
;
1018 bss
->ssid
.wep
.default_len
= bss
->default_wep_key_len
;
1019 if (full_config
&& bss
->default_wep_key_len
) {
1020 cipher
= bss
->default_wep_key_len
>= 13 ?
1021 WPA_CIPHER_WEP104
: WPA_CIPHER_WEP40
;
1022 } else if (full_config
&& bss
->ssid
.wep
.keys_set
) {
1023 if (bss
->ssid
.wep
.len
[0] >= 13)
1024 cipher
= WPA_CIPHER_WEP104
;
1026 cipher
= WPA_CIPHER_WEP40
;
1028 bss
->wpa_group
= cipher
;
1029 bss
->wpa_pairwise
= cipher
;
1030 bss
->rsn_pairwise
= cipher
;
1032 bss
->wpa_key_mgmt
= WPA_KEY_MGMT_IEEE8021X_NO_WPA
;
1033 } else if (bss
->ssid
.wep
.keys_set
) {
1034 int cipher
= WPA_CIPHER_WEP40
;
1035 if (bss
->ssid
.wep
.len
[0] >= 13)
1036 cipher
= WPA_CIPHER_WEP104
;
1037 bss
->ssid
.security_policy
= SECURITY_STATIC_WEP
;
1038 bss
->wpa_group
= cipher
;
1039 bss
->wpa_pairwise
= cipher
;
1040 bss
->rsn_pairwise
= cipher
;
1042 bss
->wpa_key_mgmt
= WPA_KEY_MGMT_NONE
;
1043 } else if (bss
->osen
) {
1044 bss
->ssid
.security_policy
= SECURITY_OSEN
;
1045 bss
->wpa_group
= WPA_CIPHER_CCMP
;
1046 bss
->wpa_pairwise
= 0;
1047 bss
->rsn_pairwise
= WPA_CIPHER_CCMP
;
1049 bss
->ssid
.security_policy
= SECURITY_PLAINTEXT
;
1051 bss
->wpa_group
= WPA_CIPHER_NONE
;
1052 bss
->wpa_pairwise
= WPA_CIPHER_NONE
;
1053 bss
->rsn_pairwise
= WPA_CIPHER_NONE
;
1054 bss
->wpa_key_mgmt
= WPA_KEY_MGMT_NONE
;