ap_config.c revision c28170251eb54dbf64a9074a07fee377587425b2
15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)/*
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * hostapd / Configuration helper functions
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * Copyright (c) 2003-2014, Jouni Malinen <j@w1.fi>
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * This software may be distributed under the terms of the BSD license.
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * See README for more details.
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) */
8a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
9a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "utils/includes.h"
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "utils/common.h"
125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "crypto/sha1.h"
135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "radius/radius_client.h"
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "common/ieee802_11_defs.h"
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "common/eapol_common.h"
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "eap_common/eap_wsc_common.h"
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "eap_server/eap.h"
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "wpa_auth.h"
195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "sta_info.h"
205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ap_config.h"
215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)static void hostapd_config_free_vlan(struct hostapd_bss_config *bss)
245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles){
255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)	struct hostapd_vlan *vlan, *prev;
26a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
27a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)	vlan = bss->vlan;
285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)	prev = NULL;
295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)	while (vlan) {
305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)		prev = vlan;
315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)		vlan = vlan->next;
325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)		os_free(prev);
335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)	}
345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)	bss->vlan = NULL;
365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void hostapd_config_defaults_bss(struct hostapd_bss_config *bss)
405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles){
415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)	bss->logger_syslog_level = HOSTAPD_LEVEL_INFO;
425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)	bss->logger_stdout_level = HOSTAPD_LEVEL_INFO;
435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)	bss->logger_syslog = (unsigned int) -1;
445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)	bss->logger_stdout = (unsigned int) -1;
45a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)	bss->auth_algs = WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED;
475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)	bss->wep_rekeying_period = 300;
495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)	/* use key0 in individual key and key1 in broadcast key */
505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)	bss->broadcast_key_idx_min = 1;
515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)	bss->broadcast_key_idx_max = 2;
525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)	bss->eap_reauth_period = 3600;
535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)	bss->wpa_group_rekey = 600;
555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)	bss->wpa_gmk_rekey = 86400;
56a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)	bss->wpa_key_mgmt = WPA_KEY_MGMT_PSK;
575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)	bss->wpa_pairwise = WPA_CIPHER_TKIP;
585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)	bss->wpa_group = WPA_CIPHER_TKIP;
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	bss->rsn_pairwise = 0;
60a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)	bss->max_num_sta = MAX_STA_COUNT;
625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	bss->dtim_period = 2;
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	bss->radius_server_auth_port = 1812;
665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)	bss->ap_max_inactivity = AP_MAX_INACTIVITY;
675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)	bss->eapol_version = EAPOL_VERSION;
685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)	bss->max_listen_interval = 65535;
705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)	bss->pwd_group = 19; /* ECC: GF(p=256) */
725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#ifdef CONFIG_IEEE80211W
745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)	bss->assoc_sa_query_max_timeout = 1000;
755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)	bss->assoc_sa_query_retry_timeout = 201;
765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)	bss->group_mgmt_cipher = WPA_CIPHER_AES_128_CMAC;
775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#endif /* CONFIG_IEEE80211W */
785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#ifdef EAP_SERVER_FAST
795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)	 /* both anonymous and authenticated provisioning */
805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)	bss->eap_fast_prov = 3;
815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)	bss->pac_key_lifetime = 7 * 24 * 60 * 60;
825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)	bss->pac_key_refresh_time = 1 * 24 * 60 * 60;
835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#endif /* EAP_SERVER_FAST */
845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)	/* Set to -1 as defaults depends on HT in setup */
865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)	bss->wmm_enabled = -1;
875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifdef CONFIG_IEEE80211R
895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	bss->ft_over_ds = 1;
905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif /* CONFIG_IEEE80211R */
915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	bss->radius_das_time_window = 300;
935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	bss->sae_anti_clogging_threshold = 5;
955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
98a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)struct hostapd_config * hostapd_config_defaults(void)
995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles){
1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define ecw2cw(ecw) ((1 << (ecw)) - 1)
101424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)
102424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)	struct hostapd_config *conf;
103424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)	struct hostapd_bss_config *bss;
1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	const int aCWmin = 4, aCWmax = 10;
1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	const struct hostapd_wmm_ac_params ac_bk =
106424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)		{ aCWmin, aCWmax, 7, 0, 0 }; /* background traffic */
1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	const struct hostapd_wmm_ac_params ac_be =
1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)		{ aCWmin, aCWmax, 3, 0, 0 }; /* best effort traffic */
1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	const struct hostapd_wmm_ac_params ac_vi = /* video traffic */
1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)		{ aCWmin - 1, aCWmin, 2, 3008 / 32, 0 };
1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	const struct hostapd_wmm_ac_params ac_vo = /* voice traffic */
1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)		{ aCWmin - 2, aCWmin - 1, 2, 1504 / 32, 0 };
1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	const struct hostapd_tx_queue_params txq_bk =
1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)		{ 7, ecw2cw(aCWmin), ecw2cw(aCWmax), 0 };
115424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)	const struct hostapd_tx_queue_params txq_be =
116424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)		{ 3, ecw2cw(aCWmin), 4 * (ecw2cw(aCWmin) + 1) - 1, 0};
117a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)	const struct hostapd_tx_queue_params txq_vi =
118424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)		{ 1, (ecw2cw(aCWmin) + 1) / 2 - 1, ecw2cw(aCWmin), 30};
119424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)	const struct hostapd_tx_queue_params txq_vo =
120424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)		{ 1, (ecw2cw(aCWmin) + 1) / 4 - 1,
121424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)		  (ecw2cw(aCWmin) + 1) / 2 - 1, 15};
122424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)
123424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)#undef ecw2cw
124424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)
125424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)	conf = os_zalloc(sizeof(*conf));
126a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)	bss = os_zalloc(sizeof(*bss));
127a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)	if (conf == NULL || bss == NULL) {
128424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)		wpa_printf(MSG_ERROR, "Failed to allocate memory for "
129a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)			   "configuration data.");
130424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)		os_free(conf);
131424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)		os_free(bss);
132424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)		return NULL;
1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	}
1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	conf->bss = os_calloc(1, sizeof(struct hostapd_bss_config *));
1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	if (conf->bss == NULL) {
1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)		os_free(conf);
1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)		os_free(bss);
1382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)		return NULL;
1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	}
1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	conf->bss[0] = bss;
141a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
142a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)	bss->radius = os_zalloc(sizeof(*bss->radius));
143a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)	if (bss->radius == NULL) {
1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)		os_free(conf->bss);
1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)		os_free(conf);
1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)		os_free(bss);
1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)		return NULL;
1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	}
149a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
150a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)	hostapd_config_defaults_bss(bss);
1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
152424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)	conf->num_bss = 1;
153424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)
154424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)	conf->beacon_int = 100;
155a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)	conf->rts_threshold = -1; /* use driver default: 2347 */
156424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)	conf->fragm_threshold = -1; /* user driver default: 2346 */
157424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)	conf->send_probe_response = 1;
158a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)	/* Set to invalid value means do not add Power Constraint IE */
159424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)	conf->local_pwr_constraint = -1;
1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	conf->wmm_ac_params[0] = ac_be;
162a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)	conf->wmm_ac_params[1] = ac_bk;
1635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)	conf->wmm_ac_params[2] = ac_vi;
164a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)	conf->wmm_ac_params[3] = ac_vo;
1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	conf->tx_queue[0] = txq_vo;
167a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)	conf->tx_queue[1] = txq_vi;
1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	conf->tx_queue[2] = txq_be;
1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	conf->tx_queue[3] = txq_bk;
1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	conf->ht_capab = HT_CAP_INFO_SMPS_DISABLED;
1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	conf->ap_table_max_size = 255;
1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	conf->ap_table_expiration_time = 60;
1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifdef CONFIG_TESTING_OPTIONS
1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	conf->ignore_probe_probability = 0.0;
1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	conf->ignore_auth_probability = 0.0;
179a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)	conf->ignore_assoc_probability = 0.0;
180a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)	conf->ignore_reassoc_probability = 0.0;
1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	conf->corrupt_gtk_rekey_mic_probability = 0.0;
1825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#endif /* CONFIG_TESTING_OPTIONS */
183a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifdef CONFIG_ACS
1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	conf->acs_num_scans = 5;
1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif /* CONFIG_ACS */
1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	return conf;
1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int hostapd_mac_comp(const void *a, const void *b)
1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles){
1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	return os_memcmp(a, b, sizeof(macaddr));
1955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int hostapd_mac_comp_empty(const void *a)
1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles){
2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	macaddr empty = { 0 };
2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	return os_memcmp(a, empty, sizeof(macaddr));
202a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
203a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)static int hostapd_config_read_wpa_psk(const char *fname,
2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)				       struct hostapd_ssid *ssid)
207a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles){
2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	FILE *f;
2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	char buf[128], *pos;
210a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)	int line = 0, ret = 0, len, ok;
2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	u8 addr[ETH_ALEN];
2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	struct hostapd_wpa_psk *psk;
213a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
2145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	if (!fname)
215a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)		return 0;
2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	f = fopen(fname, "r");
218424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)	if (!f) {
219424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)		wpa_printf(MSG_ERROR, "WPA PSK file '%s' not found.", fname);
220424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)		return -1;
221424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)	}
222a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
223a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)	while (fgets(buf, sizeof(buf), f)) {
224a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)		line++;
225a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
226424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)		if (buf[0] == '#')
227424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)			continue;
228424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)		pos = buf;
2295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)		while (*pos != '\0') {
2305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)			if (*pos == '\n') {
2313240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch				*pos = '\0';
2323240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch				break;
233a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)			}
2345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)			pos++;
2355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)		}
2365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)		if (buf[0] == '\0')
2373240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch			continue;
2385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
2393240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch		if (hwaddr_aton(buf, addr)) {
2403240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch			wpa_printf(MSG_ERROR, "Invalid MAC address '%s' on "
2415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)				   "line %d in '%s'", buf, line, fname);
242			ret = -1;
243			break;
244		}
245
246		psk = os_zalloc(sizeof(*psk));
247		if (psk == NULL) {
248			wpa_printf(MSG_ERROR, "WPA PSK allocation failed");
249			ret = -1;
250			break;
251		}
252		if (is_zero_ether_addr(addr))
253			psk->group = 1;
254		else
255			os_memcpy(psk->addr, addr, ETH_ALEN);
256
257		pos = buf + 17;
258		if (*pos == '\0') {
259			wpa_printf(MSG_ERROR, "No PSK on line %d in '%s'",
260				   line, fname);
261			os_free(psk);
262			ret = -1;
263			break;
264		}
265		pos++;
266
267		ok = 0;
268		len = os_strlen(pos);
269		if (len == 64 && hexstr2bin(pos, psk->psk, PMK_LEN) == 0)
270			ok = 1;
271		else if (len >= 8 && len < 64) {
272			pbkdf2_sha1(pos, ssid->ssid, ssid->ssid_len,
273				    4096, psk->psk, PMK_LEN);
274			ok = 1;
275		}
276		if (!ok) {
277			wpa_printf(MSG_ERROR, "Invalid PSK '%s' on line %d in "
278				   "'%s'", pos, line, fname);
279			os_free(psk);
280			ret = -1;
281			break;
282		}
283
284		psk->next = ssid->wpa_psk;
285		ssid->wpa_psk = psk;
286	}
287
288	fclose(f);
289
290	return ret;
291}
292
293
294static int hostapd_derive_psk(struct hostapd_ssid *ssid)
295{
296	ssid->wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
297	if (ssid->wpa_psk == NULL) {
298		wpa_printf(MSG_ERROR, "Unable to alloc space for PSK");
299		return -1;
300	}
301	wpa_hexdump_ascii(MSG_DEBUG, "SSID",
302			  (u8 *) ssid->ssid, ssid->ssid_len);
303	wpa_hexdump_ascii_key(MSG_DEBUG, "PSK (ASCII passphrase)",
304			      (u8 *) ssid->wpa_passphrase,
305			      os_strlen(ssid->wpa_passphrase));
306	pbkdf2_sha1(ssid->wpa_passphrase,
307		    ssid->ssid, ssid->ssid_len,
308		    4096, ssid->wpa_psk->psk, PMK_LEN);
309	wpa_hexdump_key(MSG_DEBUG, "PSK (from passphrase)",
310			ssid->wpa_psk->psk, PMK_LEN);
311	return 0;
312}
313
314
315int hostapd_setup_wpa_psk(struct hostapd_bss_config *conf)
316{
317	struct hostapd_ssid *ssid = &conf->ssid;
318
319	if (ssid->wpa_passphrase != NULL) {
320		if (ssid->wpa_psk != NULL) {
321			wpa_printf(MSG_DEBUG, "Using pre-configured WPA PSK "
322				   "instead of passphrase");
323		} else {
324			wpa_printf(MSG_DEBUG, "Deriving WPA PSK based on "
325				   "passphrase");
326			if (hostapd_derive_psk(ssid) < 0)
327				return -1;
328		}
329		ssid->wpa_psk->group = 1;
330	}
331
332	if (ssid->wpa_psk_file) {
333		if (hostapd_config_read_wpa_psk(ssid->wpa_psk_file,
334						&conf->ssid))
335			return -1;
336	}
337
338	return 0;
339}
340
341
342static void hostapd_config_free_radius(struct hostapd_radius_server *servers,
343				       int num_servers)
344{
345	int i;
346
347	for (i = 0; i < num_servers; i++) {
348		os_free(servers[i].shared_secret);
349	}
350	os_free(servers);
351}
352
353
354struct hostapd_radius_attr *
355hostapd_config_get_radius_attr(struct hostapd_radius_attr *attr, u8 type)
356{
357	for (; attr; attr = attr->next) {
358		if (attr->type == type)
359			return attr;
360	}
361	return NULL;
362}
363
364
365static void hostapd_config_free_radius_attr(struct hostapd_radius_attr *attr)
366{
367	struct hostapd_radius_attr *prev;
368
369	while (attr) {
370		prev = attr;
371		attr = attr->next;
372		wpabuf_free(prev->val);
373		os_free(prev);
374	}
375}
376
377
378void hostapd_config_free_eap_user(struct hostapd_eap_user *user)
379{
380	hostapd_config_free_radius_attr(user->accept_attr);
381	os_free(user->identity);
382	bin_clear_free(user->password, user->password_len);
383	os_free(user);
384}
385
386
387static void hostapd_config_free_wep(struct hostapd_wep_keys *keys)
388{
389	int i;
390	for (i = 0; i < NUM_WEP_KEYS; i++) {
391		bin_clear_free(keys->key[i], keys->len[i]);
392		keys->key[i] = NULL;
393	}
394}
395
396
397void hostapd_config_free_bss(struct hostapd_bss_config *conf)
398{
399	struct hostapd_wpa_psk *psk, *prev;
400	struct hostapd_eap_user *user, *prev_user;
401
402	if (conf == NULL)
403		return;
404
405	psk = conf->ssid.wpa_psk;
406	while (psk) {
407		prev = psk;
408		psk = psk->next;
409		bin_clear_free(prev, sizeof(*prev));
410	}
411
412	str_clear_free(conf->ssid.wpa_passphrase);
413	os_free(conf->ssid.wpa_psk_file);
414	hostapd_config_free_wep(&conf->ssid.wep);
415#ifdef CONFIG_FULL_DYNAMIC_VLAN
416	os_free(conf->ssid.vlan_tagged_interface);
417#endif /* CONFIG_FULL_DYNAMIC_VLAN */
418
419	user = conf->eap_user;
420	while (user) {
421		prev_user = user;
422		user = user->next;
423		hostapd_config_free_eap_user(prev_user);
424	}
425	os_free(conf->eap_user_sqlite);
426
427	os_free(conf->eap_req_id_text);
428	os_free(conf->accept_mac);
429	os_free(conf->deny_mac);
430	os_free(conf->nas_identifier);
431	if (conf->radius) {
432		hostapd_config_free_radius(conf->radius->auth_servers,
433					   conf->radius->num_auth_servers);
434		hostapd_config_free_radius(conf->radius->acct_servers,
435					   conf->radius->num_acct_servers);
436	}
437	hostapd_config_free_radius_attr(conf->radius_auth_req_attr);
438	hostapd_config_free_radius_attr(conf->radius_acct_req_attr);
439	os_free(conf->rsn_preauth_interfaces);
440	os_free(conf->ctrl_interface);
441	os_free(conf->ca_cert);
442	os_free(conf->server_cert);
443	os_free(conf->private_key);
444	os_free(conf->private_key_passwd);
445	os_free(conf->ocsp_stapling_response);
446	os_free(conf->dh_file);
447	os_free(conf->pac_opaque_encr_key);
448	os_free(conf->eap_fast_a_id);
449	os_free(conf->eap_fast_a_id_info);
450	os_free(conf->eap_sim_db);
451	os_free(conf->radius_server_clients);
452	os_free(conf->test_socket);
453	os_free(conf->radius);
454	os_free(conf->radius_das_shared_secret);
455	hostapd_config_free_vlan(conf);
456	os_free(conf->time_zone);
457
458#ifdef CONFIG_IEEE80211R
459	{
460		struct ft_remote_r0kh *r0kh, *r0kh_prev;
461		struct ft_remote_r1kh *r1kh, *r1kh_prev;
462
463		r0kh = conf->r0kh_list;
464		conf->r0kh_list = NULL;
465		while (r0kh) {
466			r0kh_prev = r0kh;
467			r0kh = r0kh->next;
468			os_free(r0kh_prev);
469		}
470
471		r1kh = conf->r1kh_list;
472		conf->r1kh_list = NULL;
473		while (r1kh) {
474			r1kh_prev = r1kh;
475			r1kh = r1kh->next;
476			os_free(r1kh_prev);
477		}
478	}
479#endif /* CONFIG_IEEE80211R */
480
481#ifdef CONFIG_WPS
482	os_free(conf->wps_pin_requests);
483	os_free(conf->device_name);
484	os_free(conf->manufacturer);
485	os_free(conf->model_name);
486	os_free(conf->model_number);
487	os_free(conf->serial_number);
488	os_free(conf->config_methods);
489	os_free(conf->ap_pin);
490	os_free(conf->extra_cred);
491	os_free(conf->ap_settings);
492	os_free(conf->upnp_iface);
493	os_free(conf->friendly_name);
494	os_free(conf->manufacturer_url);
495	os_free(conf->model_description);
496	os_free(conf->model_url);
497	os_free(conf->upc);
498	wpabuf_free(conf->wps_nfc_dh_pubkey);
499	wpabuf_free(conf->wps_nfc_dh_privkey);
500	wpabuf_free(conf->wps_nfc_dev_pw);
501#endif /* CONFIG_WPS */
502
503	os_free(conf->roaming_consortium);
504	os_free(conf->venue_name);
505	os_free(conf->nai_realm_data);
506	os_free(conf->network_auth_type);
507	os_free(conf->anqp_3gpp_cell_net);
508	os_free(conf->domain_name);
509
510#ifdef CONFIG_RADIUS_TEST
511	os_free(conf->dump_msk_file);
512#endif /* CONFIG_RADIUS_TEST */
513
514#ifdef CONFIG_HS20
515	os_free(conf->hs20_oper_friendly_name);
516	os_free(conf->hs20_wan_metrics);
517	os_free(conf->hs20_connection_capability);
518	os_free(conf->hs20_operating_class);
519	os_free(conf->hs20_icons);
520	if (conf->hs20_osu_providers) {
521		size_t i;
522		for (i = 0; i < conf->hs20_osu_providers_count; i++) {
523			struct hs20_osu_provider *p;
524			size_t j;
525			p = &conf->hs20_osu_providers[i];
526			os_free(p->friendly_name);
527			os_free(p->server_uri);
528			os_free(p->method_list);
529			for (j = 0; j < p->icons_count; j++)
530				os_free(p->icons[j]);
531			os_free(p->icons);
532			os_free(p->osu_nai);
533			os_free(p->service_desc);
534		}
535		os_free(conf->hs20_osu_providers);
536	}
537	os_free(conf->subscr_remediation_url);
538#endif /* CONFIG_HS20 */
539
540	wpabuf_free(conf->vendor_elements);
541
542	os_free(conf->sae_groups);
543
544	os_free(conf->server_id);
545
546	os_free(conf);
547}
548
549
550/**
551 * hostapd_config_free - Free hostapd configuration
552 * @conf: Configuration data from hostapd_config_read().
553 */
554void hostapd_config_free(struct hostapd_config *conf)
555{
556	size_t i;
557
558	if (conf == NULL)
559		return;
560
561	for (i = 0; i < conf->num_bss; i++)
562		hostapd_config_free_bss(conf->bss[i]);
563	os_free(conf->bss);
564	os_free(conf->supported_rates);
565	os_free(conf->basic_rates);
566	os_free(conf->chanlist);
567
568	os_free(conf);
569}
570
571
572/**
573 * hostapd_maclist_found - Find a MAC address from a list
574 * @list: MAC address list
575 * @num_entries: Number of addresses in the list
576 * @addr: Address to search for
577 * @vlan_id: Buffer for returning VLAN ID or %NULL if not needed
578 * Returns: 1 if address is in the list or 0 if not.
579 *
580 * Perform a binary search for given MAC address from a pre-sorted list.
581 */
582int hostapd_maclist_found(struct mac_acl_entry *list, int num_entries,
583			  const u8 *addr, int *vlan_id)
584{
585	int start, end, middle, res;
586
587	start = 0;
588	end = num_entries - 1;
589
590	while (start <= end) {
591		middle = (start + end) / 2;
592		res = os_memcmp(list[middle].addr, addr, ETH_ALEN);
593		if (res == 0) {
594			if (vlan_id)
595				*vlan_id = list[middle].vlan_id;
596			return 1;
597		}
598		if (res < 0)
599			start = middle + 1;
600		else
601			end = middle - 1;
602	}
603
604	return 0;
605}
606
607
608int hostapd_rate_found(int *list, int rate)
609{
610	int i;
611
612	if (list == NULL)
613		return 0;
614
615	for (i = 0; list[i] >= 0; i++)
616		if (list[i] == rate)
617			return 1;
618
619	return 0;
620}
621
622
623int hostapd_vlan_id_valid(struct hostapd_vlan *vlan, int vlan_id)
624{
625	struct hostapd_vlan *v = vlan;
626	while (v) {
627		if (v->vlan_id == vlan_id || v->vlan_id == VLAN_ID_WILDCARD)
628			return 1;
629		v = v->next;
630	}
631	return 0;
632}
633
634
635const char * hostapd_get_vlan_id_ifname(struct hostapd_vlan *vlan, int vlan_id)
636{
637	struct hostapd_vlan *v = vlan;
638	while (v) {
639		if (v->vlan_id == vlan_id)
640			return v->ifname;
641		v = v->next;
642	}
643	return NULL;
644}
645
646
647const u8 * hostapd_get_psk(const struct hostapd_bss_config *conf,
648			   const u8 *addr, const u8 *p2p_dev_addr,
649			   const u8 *prev_psk)
650{
651	struct hostapd_wpa_psk *psk;
652	int next_ok = prev_psk == NULL;
653
654	if (p2p_dev_addr && !is_zero_ether_addr(p2p_dev_addr)) {
655		wpa_printf(MSG_DEBUG, "Searching a PSK for " MACSTR
656			   " p2p_dev_addr=" MACSTR " prev_psk=%p",
657			   MAC2STR(addr), MAC2STR(p2p_dev_addr), prev_psk);
658		addr = NULL; /* Use P2P Device Address for matching */
659	} else {
660		wpa_printf(MSG_DEBUG, "Searching a PSK for " MACSTR
661			   " prev_psk=%p",
662			   MAC2STR(addr), prev_psk);
663	}
664
665	for (psk = conf->ssid.wpa_psk; psk != NULL; psk = psk->next) {
666		if (next_ok &&
667		    (psk->group ||
668		     (addr && os_memcmp(psk->addr, addr, ETH_ALEN) == 0) ||
669		     (!addr && p2p_dev_addr &&
670		      os_memcmp(psk->p2p_dev_addr, p2p_dev_addr, ETH_ALEN) ==
671		      0)))
672			return psk->psk;
673
674		if (psk->psk == prev_psk)
675			next_ok = 1;
676	}
677
678	return NULL;
679}
680
681
682static int hostapd_config_check_bss(struct hostapd_bss_config *bss,
683				    struct hostapd_config *conf,
684				    int full_config)
685{
686	if (full_config && bss->ieee802_1x && !bss->eap_server &&
687	    !bss->radius->auth_servers) {
688		wpa_printf(MSG_ERROR, "Invalid IEEE 802.1X configuration (no "
689			   "EAP authenticator configured).");
690		return -1;
691	}
692
693	if (bss->wpa) {
694		int wep, i;
695
696		wep = bss->default_wep_key_len > 0 ||
697		       bss->individual_wep_key_len > 0;
698		for (i = 0; i < NUM_WEP_KEYS; i++) {
699			if (bss->ssid.wep.keys_set) {
700				wep = 1;
701				break;
702			}
703		}
704
705		if (wep) {
706			wpa_printf(MSG_ERROR, "WEP configuration in a WPA network is not supported");
707			return -1;
708		}
709	}
710
711	if (full_config && bss->wpa &&
712	    bss->wpa_psk_radius != PSK_RADIUS_IGNORED &&
713	    bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH) {
714		wpa_printf(MSG_ERROR, "WPA-PSK using RADIUS enabled, but no "
715			   "RADIUS checking (macaddr_acl=2) enabled.");
716		return -1;
717	}
718
719	if (full_config && bss->wpa && (bss->wpa_key_mgmt & WPA_KEY_MGMT_PSK) &&
720	    bss->ssid.wpa_psk == NULL && bss->ssid.wpa_passphrase == NULL &&
721	    bss->ssid.wpa_psk_file == NULL &&
722	    (bss->wpa_psk_radius != PSK_RADIUS_REQUIRED ||
723	     bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH)) {
724		wpa_printf(MSG_ERROR, "WPA-PSK enabled, but PSK or passphrase "
725			   "is not configured.");
726		return -1;
727	}
728
729	if (full_config && hostapd_mac_comp_empty(bss->bssid) != 0) {
730		size_t i;
731
732		for (i = 0; i < conf->num_bss; i++) {
733			if (conf->bss[i] != bss &&
734			    (hostapd_mac_comp(conf->bss[i]->bssid,
735					      bss->bssid) == 0)) {
736				wpa_printf(MSG_ERROR, "Duplicate BSSID " MACSTR
737					   " on interface '%s' and '%s'.",
738					   MAC2STR(bss->bssid),
739					   conf->bss[i]->iface, bss->iface);
740				return -1;
741			}
742		}
743	}
744
745#ifdef CONFIG_IEEE80211R
746	if (full_config && wpa_key_mgmt_ft(bss->wpa_key_mgmt) &&
747	    (bss->nas_identifier == NULL ||
748	     os_strlen(bss->nas_identifier) < 1 ||
749	     os_strlen(bss->nas_identifier) > FT_R0KH_ID_MAX_LEN)) {
750		wpa_printf(MSG_ERROR, "FT (IEEE 802.11r) requires "
751			   "nas_identifier to be configured as a 1..48 octet "
752			   "string");
753		return -1;
754	}
755#endif /* CONFIG_IEEE80211R */
756
757#ifdef CONFIG_IEEE80211N
758	if (full_config && conf->ieee80211n &&
759	    conf->hw_mode == HOSTAPD_MODE_IEEE80211B) {
760		bss->disable_11n = 1;
761		wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) in 11b mode is not "
762			   "allowed, disabling HT capabilites");
763	}
764
765	if (full_config && conf->ieee80211n &&
766	    bss->ssid.security_policy == SECURITY_STATIC_WEP) {
767		bss->disable_11n = 1;
768		wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) with WEP is not "
769			   "allowed, disabling HT capabilities");
770	}
771
772	if (full_config && conf->ieee80211n && bss->wpa &&
773	    !(bss->wpa_pairwise & WPA_CIPHER_CCMP) &&
774	    !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
775				   WPA_CIPHER_CCMP_256 | WPA_CIPHER_GCMP_256)))
776	{
777		bss->disable_11n = 1;
778		wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) with WPA/WPA2 "
779			   "requires CCMP/GCMP to be enabled, disabling HT "
780			   "capabilities");
781	}
782#endif /* CONFIG_IEEE80211N */
783
784#ifdef CONFIG_WPS
785	if (full_config && bss->wps_state && bss->ignore_broadcast_ssid) {
786		wpa_printf(MSG_INFO, "WPS: ignore_broadcast_ssid "
787			   "configuration forced WPS to be disabled");
788		bss->wps_state = 0;
789	}
790
791	if (full_config && bss->wps_state &&
792	    bss->ssid.wep.keys_set && bss->wpa == 0) {
793		wpa_printf(MSG_INFO, "WPS: WEP configuration forced WPS to be "
794			   "disabled");
795		bss->wps_state = 0;
796	}
797
798	if (full_config && bss->wps_state && bss->wpa &&
799	    (!(bss->wpa & 2) ||
800	     !(bss->rsn_pairwise & WPA_CIPHER_CCMP))) {
801		wpa_printf(MSG_INFO, "WPS: WPA/TKIP configuration without "
802			   "WPA2/CCMP forced WPS to be disabled");
803		bss->wps_state = 0;
804	}
805#endif /* CONFIG_WPS */
806
807#ifdef CONFIG_HS20
808	if (full_config && bss->hs20 &&
809	    (!(bss->wpa & 2) ||
810	     !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
811				    WPA_CIPHER_CCMP_256 |
812				    WPA_CIPHER_GCMP_256)))) {
813		wpa_printf(MSG_ERROR, "HS 2.0: WPA2-Enterprise/CCMP "
814			   "configuration is required for Hotspot 2.0 "
815			   "functionality");
816		return -1;
817	}
818#endif /* CONFIG_HS20 */
819
820	return 0;
821}
822
823
824int hostapd_config_check(struct hostapd_config *conf, int full_config)
825{
826	size_t i;
827
828	if (full_config && conf->ieee80211d &&
829	    (!conf->country[0] || !conf->country[1])) {
830		wpa_printf(MSG_ERROR, "Cannot enable IEEE 802.11d without "
831			   "setting the country_code");
832		return -1;
833	}
834
835	if (full_config && conf->ieee80211h && !conf->ieee80211d) {
836		wpa_printf(MSG_ERROR, "Cannot enable IEEE 802.11h without "
837			   "IEEE 802.11d enabled");
838		return -1;
839	}
840
841	if (full_config && conf->local_pwr_constraint != -1 &&
842	    !conf->ieee80211d) {
843		wpa_printf(MSG_ERROR, "Cannot add Power Constraint element without Country element");
844		return -1;
845	}
846
847	if (full_config && conf->spectrum_mgmt_required &&
848	    conf->local_pwr_constraint == -1) {
849		wpa_printf(MSG_ERROR, "Cannot set Spectrum Management bit without Country and Power Constraint elements");
850		return -1;
851	}
852
853	for (i = 0; i < conf->num_bss; i++) {
854		if (hostapd_config_check_bss(conf->bss[i], conf, full_config))
855			return -1;
856	}
857
858	return 0;
859}
860
861
862void hostapd_set_security_params(struct hostapd_bss_config *bss,
863				 int full_config)
864{
865	if (bss->individual_wep_key_len == 0) {
866		/* individual keys are not use; can use key idx0 for
867		 * broadcast keys */
868		bss->broadcast_key_idx_min = 0;
869	}
870
871	if ((bss->wpa & 2) && bss->rsn_pairwise == 0)
872		bss->rsn_pairwise = bss->wpa_pairwise;
873	bss->wpa_group = wpa_select_ap_group_cipher(bss->wpa, bss->wpa_pairwise,
874						    bss->rsn_pairwise);
875
876	if (full_config) {
877		bss->radius->auth_server = bss->radius->auth_servers;
878		bss->radius->acct_server = bss->radius->acct_servers;
879	}
880
881	if (bss->wpa && bss->ieee802_1x) {
882		bss->ssid.security_policy = SECURITY_WPA;
883	} else if (bss->wpa) {
884		bss->ssid.security_policy = SECURITY_WPA_PSK;
885	} else if (bss->ieee802_1x) {
886		int cipher = WPA_CIPHER_NONE;
887		bss->ssid.security_policy = SECURITY_IEEE_802_1X;
888		bss->ssid.wep.default_len = bss->default_wep_key_len;
889		if (bss->default_wep_key_len)
890			cipher = bss->default_wep_key_len >= 13 ?
891				WPA_CIPHER_WEP104 : WPA_CIPHER_WEP40;
892		bss->wpa_group = cipher;
893		bss->wpa_pairwise = cipher;
894		bss->rsn_pairwise = cipher;
895	} else if (bss->ssid.wep.keys_set) {
896		int cipher = WPA_CIPHER_WEP40;
897		if (bss->ssid.wep.len[0] >= 13)
898			cipher = WPA_CIPHER_WEP104;
899		bss->ssid.security_policy = SECURITY_STATIC_WEP;
900		bss->wpa_group = cipher;
901		bss->wpa_pairwise = cipher;
902		bss->rsn_pairwise = cipher;
903	} else if (bss->osen) {
904		bss->ssid.security_policy = SECURITY_OSEN;
905		bss->wpa_group = WPA_CIPHER_CCMP;
906		bss->wpa_pairwise = 0;
907		bss->rsn_pairwise = WPA_CIPHER_CCMP;
908	} else {
909		bss->ssid.security_policy = SECURITY_PLAINTEXT;
910		bss->wpa_group = WPA_CIPHER_NONE;
911		bss->wpa_pairwise = WPA_CIPHER_NONE;
912		bss->rsn_pairwise = WPA_CIPHER_NONE;
913	}
914}
915