blob: e417a1247a2550ccfeb19f99ac1876ef1dab5713 [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * hostapd / Configuration helper functions
Dmitry Shmidt344abd32014-01-14 13:17:00 -08003 * Copyright (c) 2003-2014, Jouni Malinen <j@w1.fi>
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004 *
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007 */
8
9#include "utils/includes.h"
10
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"
18#include "wpa_auth.h"
19#include "sta_info.h"
20#include "ap_config.h"
21
22
23static void hostapd_config_free_vlan(struct hostapd_bss_config *bss)
24{
25 struct hostapd_vlan *vlan, *prev;
26
27 vlan = bss->vlan;
28 prev = NULL;
29 while (vlan) {
30 prev = vlan;
31 vlan = vlan->next;
32 os_free(prev);
33 }
34
35 bss->vlan = NULL;
36}
37
38
39void hostapd_config_defaults_bss(struct hostapd_bss_config *bss)
40{
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080041 dl_list_init(&bss->anqp_elem);
42
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070043 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;
47
48 bss->auth_algs = WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED;
49
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;
55
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;
62
63 bss->max_num_sta = MAX_STA_COUNT;
64
65 bss->dtim_period = 2;
66
67 bss->radius_server_auth_port = 1812;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080068 bss->eap_sim_db_timeout = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070069 bss->ap_max_inactivity = AP_MAX_INACTIVITY;
70 bss->eapol_version = EAPOL_VERSION;
71
72 bss->max_listen_interval = 65535;
73
74 bss->pwd_group = 19; /* ECC: GF(p=256) */
75
76#ifdef CONFIG_IEEE80211W
77 bss->assoc_sa_query_max_timeout = 1000;
78 bss->assoc_sa_query_retry_timeout = 201;
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -070079 bss->group_mgmt_cipher = WPA_CIPHER_AES_128_CMAC;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070080#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 */
87
88 /* Set to -1 as defaults depends on HT in setup */
89 bss->wmm_enabled = -1;
90
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -080091#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070092 bss->ft_over_ds = 1;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -080093#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt04949592012-07-19 12:16:46 -070094
95 bss->radius_das_time_window = 300;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080096
97 bss->sae_anti_clogging_threshold = 5;
Dmitry Shmidt29333592017-01-09 12:27:11 -080098
99 bss->gas_frag_limit = 1400;
100
101#ifdef CONFIG_FILS
102 dl_list_init(&bss->fils_realms);
103#endif /* CONFIG_FILS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700104}
105
106
107struct hostapd_config * hostapd_config_defaults(void)
108{
109#define ecw2cw(ecw) ((1 << (ecw)) - 1)
110
111 struct hostapd_config *conf;
112 struct hostapd_bss_config *bss;
113 const int aCWmin = 4, aCWmax = 10;
114 const struct hostapd_wmm_ac_params ac_bk =
115 { aCWmin, aCWmax, 7, 0, 0 }; /* background traffic */
116 const struct hostapd_wmm_ac_params ac_be =
117 { aCWmin, aCWmax, 3, 0, 0 }; /* best effort traffic */
118 const struct hostapd_wmm_ac_params ac_vi = /* video traffic */
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700119 { aCWmin - 1, aCWmin, 2, 3008 / 32, 0 };
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700120 const struct hostapd_wmm_ac_params ac_vo = /* voice traffic */
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700121 { aCWmin - 2, aCWmin - 1, 2, 1504 / 32, 0 };
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700122 const struct hostapd_tx_queue_params txq_bk =
123 { 7, ecw2cw(aCWmin), ecw2cw(aCWmax), 0 };
124 const struct hostapd_tx_queue_params txq_be =
125 { 3, ecw2cw(aCWmin), 4 * (ecw2cw(aCWmin) + 1) - 1, 0};
126 const struct hostapd_tx_queue_params txq_vi =
127 { 1, (ecw2cw(aCWmin) + 1) / 2 - 1, ecw2cw(aCWmin), 30};
128 const struct hostapd_tx_queue_params txq_vo =
129 { 1, (ecw2cw(aCWmin) + 1) / 4 - 1,
130 (ecw2cw(aCWmin) + 1) / 2 - 1, 15};
131
132#undef ecw2cw
133
134 conf = os_zalloc(sizeof(*conf));
135 bss = os_zalloc(sizeof(*bss));
136 if (conf == NULL || bss == NULL) {
137 wpa_printf(MSG_ERROR, "Failed to allocate memory for "
138 "configuration data.");
139 os_free(conf);
140 os_free(bss);
141 return NULL;
142 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800143 conf->bss = os_calloc(1, sizeof(struct hostapd_bss_config *));
144 if (conf->bss == NULL) {
145 os_free(conf);
146 os_free(bss);
147 return NULL;
148 }
149 conf->bss[0] = bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700150
151 bss->radius = os_zalloc(sizeof(*bss->radius));
152 if (bss->radius == NULL) {
Dmitry Shmidt97672262014-02-03 13:02:54 -0800153 os_free(conf->bss);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700154 os_free(conf);
155 os_free(bss);
156 return NULL;
157 }
158
159 hostapd_config_defaults_bss(bss);
160
161 conf->num_bss = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700162
163 conf->beacon_int = 100;
164 conf->rts_threshold = -1; /* use driver default: 2347 */
165 conf->fragm_threshold = -1; /* user driver default: 2346 */
166 conf->send_probe_response = 1;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800167 /* Set to invalid value means do not add Power Constraint IE */
168 conf->local_pwr_constraint = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700169
170 conf->wmm_ac_params[0] = ac_be;
171 conf->wmm_ac_params[1] = ac_bk;
172 conf->wmm_ac_params[2] = ac_vi;
173 conf->wmm_ac_params[3] = ac_vo;
174
175 conf->tx_queue[0] = txq_vo;
176 conf->tx_queue[1] = txq_vi;
177 conf->tx_queue[2] = txq_be;
178 conf->tx_queue[3] = txq_bk;
179
180 conf->ht_capab = HT_CAP_INFO_SMPS_DISABLED;
181
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800182 conf->ap_table_max_size = 255;
183 conf->ap_table_expiration_time = 60;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800184 conf->track_sta_max_age = 180;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800185
Dmitry Shmidt8da800a2013-04-24 12:57:01 -0700186#ifdef CONFIG_TESTING_OPTIONS
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700187 conf->ignore_probe_probability = 0.0;
188 conf->ignore_auth_probability = 0.0;
189 conf->ignore_assoc_probability = 0.0;
190 conf->ignore_reassoc_probability = 0.0;
191 conf->corrupt_gtk_rekey_mic_probability = 0.0;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800192 conf->ecsa_ie_only = 0;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -0700193#endif /* CONFIG_TESTING_OPTIONS */
194
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700195 conf->acs = 0;
196 conf->acs_ch_list.num = 0;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700197#ifdef CONFIG_ACS
198 conf->acs_num_scans = 5;
199#endif /* CONFIG_ACS */
200
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700201 return conf;
202}
203
204
205int hostapd_mac_comp(const void *a, const void *b)
206{
207 return os_memcmp(a, b, sizeof(macaddr));
208}
209
210
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700211static int hostapd_config_read_wpa_psk(const char *fname,
212 struct hostapd_ssid *ssid)
213{
214 FILE *f;
215 char buf[128], *pos;
216 int line = 0, ret = 0, len, ok;
217 u8 addr[ETH_ALEN];
218 struct hostapd_wpa_psk *psk;
219
220 if (!fname)
221 return 0;
222
223 f = fopen(fname, "r");
224 if (!f) {
225 wpa_printf(MSG_ERROR, "WPA PSK file '%s' not found.", fname);
226 return -1;
227 }
228
229 while (fgets(buf, sizeof(buf), f)) {
230 line++;
231
232 if (buf[0] == '#')
233 continue;
234 pos = buf;
235 while (*pos != '\0') {
236 if (*pos == '\n') {
237 *pos = '\0';
238 break;
239 }
240 pos++;
241 }
242 if (buf[0] == '\0')
243 continue;
244
245 if (hwaddr_aton(buf, addr)) {
246 wpa_printf(MSG_ERROR, "Invalid MAC address '%s' on "
247 "line %d in '%s'", buf, line, fname);
248 ret = -1;
249 break;
250 }
251
252 psk = os_zalloc(sizeof(*psk));
253 if (psk == NULL) {
254 wpa_printf(MSG_ERROR, "WPA PSK allocation failed");
255 ret = -1;
256 break;
257 }
258 if (is_zero_ether_addr(addr))
259 psk->group = 1;
260 else
261 os_memcpy(psk->addr, addr, ETH_ALEN);
262
263 pos = buf + 17;
264 if (*pos == '\0') {
265 wpa_printf(MSG_ERROR, "No PSK on line %d in '%s'",
266 line, fname);
267 os_free(psk);
268 ret = -1;
269 break;
270 }
271 pos++;
272
273 ok = 0;
274 len = os_strlen(pos);
275 if (len == 64 && hexstr2bin(pos, psk->psk, PMK_LEN) == 0)
276 ok = 1;
277 else if (len >= 8 && len < 64) {
278 pbkdf2_sha1(pos, ssid->ssid, ssid->ssid_len,
279 4096, psk->psk, PMK_LEN);
280 ok = 1;
281 }
282 if (!ok) {
283 wpa_printf(MSG_ERROR, "Invalid PSK '%s' on line %d in "
284 "'%s'", pos, line, fname);
285 os_free(psk);
286 ret = -1;
287 break;
288 }
289
290 psk->next = ssid->wpa_psk;
291 ssid->wpa_psk = psk;
292 }
293
294 fclose(f);
295
296 return ret;
297}
298
299
300static int hostapd_derive_psk(struct hostapd_ssid *ssid)
301{
302 ssid->wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
303 if (ssid->wpa_psk == NULL) {
304 wpa_printf(MSG_ERROR, "Unable to alloc space for PSK");
305 return -1;
306 }
307 wpa_hexdump_ascii(MSG_DEBUG, "SSID",
308 (u8 *) ssid->ssid, ssid->ssid_len);
309 wpa_hexdump_ascii_key(MSG_DEBUG, "PSK (ASCII passphrase)",
310 (u8 *) ssid->wpa_passphrase,
311 os_strlen(ssid->wpa_passphrase));
312 pbkdf2_sha1(ssid->wpa_passphrase,
313 ssid->ssid, ssid->ssid_len,
314 4096, ssid->wpa_psk->psk, PMK_LEN);
315 wpa_hexdump_key(MSG_DEBUG, "PSK (from passphrase)",
316 ssid->wpa_psk->psk, PMK_LEN);
317 return 0;
318}
319
320
321int hostapd_setup_wpa_psk(struct hostapd_bss_config *conf)
322{
323 struct hostapd_ssid *ssid = &conf->ssid;
324
325 if (ssid->wpa_passphrase != NULL) {
326 if (ssid->wpa_psk != NULL) {
327 wpa_printf(MSG_DEBUG, "Using pre-configured WPA PSK "
328 "instead of passphrase");
329 } else {
330 wpa_printf(MSG_DEBUG, "Deriving WPA PSK based on "
331 "passphrase");
332 if (hostapd_derive_psk(ssid) < 0)
333 return -1;
334 }
335 ssid->wpa_psk->group = 1;
336 }
337
Dmitry Shmidt29333592017-01-09 12:27:11 -0800338 return hostapd_config_read_wpa_psk(ssid->wpa_psk_file, &conf->ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700339}
340
341
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700342static 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
Dmitry Shmidt04949592012-07-19 12:16:46 -0700354struct 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
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700378void hostapd_config_free_eap_user(struct hostapd_eap_user *user)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700379{
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700380 hostapd_config_free_radius_attr(user->accept_attr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700381 os_free(user->identity);
Dmitry Shmidtc2817022014-07-02 10:32:10 -0700382 bin_clear_free(user->password, user->password_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700383 os_free(user);
384}
385
386
Dmitry Shmidt29333592017-01-09 12:27:11 -0800387void hostapd_config_free_eap_users(struct hostapd_eap_user *user)
388{
389 struct hostapd_eap_user *prev_user;
390
391 while (user) {
392 prev_user = user;
393 user = user->next;
394 hostapd_config_free_eap_user(prev_user);
395 }
396}
397
398
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700399static void hostapd_config_free_wep(struct hostapd_wep_keys *keys)
400{
401 int i;
402 for (i = 0; i < NUM_WEP_KEYS; i++) {
Dmitry Shmidtc2817022014-07-02 10:32:10 -0700403 bin_clear_free(keys->key[i], keys->len[i]);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700404 keys->key[i] = NULL;
405 }
406}
407
408
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800409void hostapd_config_clear_wpa_psk(struct hostapd_wpa_psk **l)
410{
411 struct hostapd_wpa_psk *psk, *tmp;
412
413 for (psk = *l; psk;) {
414 tmp = psk;
415 psk = psk->next;
416 bin_clear_free(tmp, sizeof(*tmp));
417 }
418 *l = NULL;
419}
420
421
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800422static void hostapd_config_free_anqp_elem(struct hostapd_bss_config *conf)
423{
424 struct anqp_element *elem;
425
426 while ((elem = dl_list_first(&conf->anqp_elem, struct anqp_element,
427 list))) {
428 dl_list_del(&elem->list);
429 wpabuf_free(elem->payload);
430 os_free(elem);
431 }
432}
433
434
Dmitry Shmidt29333592017-01-09 12:27:11 -0800435static void hostapd_config_free_fils_realms(struct hostapd_bss_config *conf)
436{
437#ifdef CONFIG_FILS
438 struct fils_realm *realm;
439
440 while ((realm = dl_list_first(&conf->fils_realms, struct fils_realm,
441 list))) {
442 dl_list_del(&realm->list);
443 os_free(realm);
444 }
445#endif /* CONFIG_FILS */
446}
447
448
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800449void hostapd_config_free_bss(struct hostapd_bss_config *conf)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700450{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700451 if (conf == NULL)
452 return;
453
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800454 hostapd_config_clear_wpa_psk(&conf->ssid.wpa_psk);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700455
Dmitry Shmidtc2817022014-07-02 10:32:10 -0700456 str_clear_free(conf->ssid.wpa_passphrase);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700457 os_free(conf->ssid.wpa_psk_file);
458 hostapd_config_free_wep(&conf->ssid.wep);
459#ifdef CONFIG_FULL_DYNAMIC_VLAN
460 os_free(conf->ssid.vlan_tagged_interface);
461#endif /* CONFIG_FULL_DYNAMIC_VLAN */
462
Dmitry Shmidt29333592017-01-09 12:27:11 -0800463 hostapd_config_free_eap_users(conf->eap_user);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800464 os_free(conf->eap_user_sqlite);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700465
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700466 os_free(conf->eap_req_id_text);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800467 os_free(conf->erp_domain);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700468 os_free(conf->accept_mac);
469 os_free(conf->deny_mac);
470 os_free(conf->nas_identifier);
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800471 if (conf->radius) {
472 hostapd_config_free_radius(conf->radius->auth_servers,
473 conf->radius->num_auth_servers);
474 hostapd_config_free_radius(conf->radius->acct_servers,
475 conf->radius->num_acct_servers);
476 }
Dmitry Shmidt04949592012-07-19 12:16:46 -0700477 hostapd_config_free_radius_attr(conf->radius_auth_req_attr);
478 hostapd_config_free_radius_attr(conf->radius_acct_req_attr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700479 os_free(conf->rsn_preauth_interfaces);
480 os_free(conf->ctrl_interface);
481 os_free(conf->ca_cert);
482 os_free(conf->server_cert);
483 os_free(conf->private_key);
484 os_free(conf->private_key_passwd);
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700485 os_free(conf->ocsp_stapling_response);
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -0800486 os_free(conf->ocsp_stapling_response_multi);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700487 os_free(conf->dh_file);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800488 os_free(conf->openssl_ciphers);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700489 os_free(conf->pac_opaque_encr_key);
490 os_free(conf->eap_fast_a_id);
491 os_free(conf->eap_fast_a_id_info);
492 os_free(conf->eap_sim_db);
493 os_free(conf->radius_server_clients);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700494 os_free(conf->radius);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700495 os_free(conf->radius_das_shared_secret);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700496 hostapd_config_free_vlan(conf);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800497 os_free(conf->time_zone);
498
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800499#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700500 {
501 struct ft_remote_r0kh *r0kh, *r0kh_prev;
502 struct ft_remote_r1kh *r1kh, *r1kh_prev;
503
504 r0kh = conf->r0kh_list;
505 conf->r0kh_list = NULL;
506 while (r0kh) {
507 r0kh_prev = r0kh;
508 r0kh = r0kh->next;
509 os_free(r0kh_prev);
510 }
511
512 r1kh = conf->r1kh_list;
513 conf->r1kh_list = NULL;
514 while (r1kh) {
515 r1kh_prev = r1kh;
516 r1kh = r1kh->next;
517 os_free(r1kh_prev);
518 }
519 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800520#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700521
522#ifdef CONFIG_WPS
523 os_free(conf->wps_pin_requests);
524 os_free(conf->device_name);
525 os_free(conf->manufacturer);
526 os_free(conf->model_name);
527 os_free(conf->model_number);
528 os_free(conf->serial_number);
529 os_free(conf->config_methods);
530 os_free(conf->ap_pin);
531 os_free(conf->extra_cred);
532 os_free(conf->ap_settings);
533 os_free(conf->upnp_iface);
534 os_free(conf->friendly_name);
535 os_free(conf->manufacturer_url);
536 os_free(conf->model_description);
537 os_free(conf->model_url);
538 os_free(conf->upc);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800539 {
540 unsigned int i;
541
542 for (i = 0; i < MAX_WPS_VENDOR_EXTENSIONS; i++)
543 wpabuf_free(conf->wps_vendor_ext[i]);
544 }
Dmitry Shmidt04949592012-07-19 12:16:46 -0700545 wpabuf_free(conf->wps_nfc_dh_pubkey);
546 wpabuf_free(conf->wps_nfc_dh_privkey);
547 wpabuf_free(conf->wps_nfc_dev_pw);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700548#endif /* CONFIG_WPS */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800549
550 os_free(conf->roaming_consortium);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700551 os_free(conf->venue_name);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700552 os_free(conf->nai_realm_data);
553 os_free(conf->network_auth_type);
554 os_free(conf->anqp_3gpp_cell_net);
555 os_free(conf->domain_name);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800556 hostapd_config_free_anqp_elem(conf);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800557
558#ifdef CONFIG_RADIUS_TEST
559 os_free(conf->dump_msk_file);
560#endif /* CONFIG_RADIUS_TEST */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700561
562#ifdef CONFIG_HS20
563 os_free(conf->hs20_oper_friendly_name);
564 os_free(conf->hs20_wan_metrics);
565 os_free(conf->hs20_connection_capability);
566 os_free(conf->hs20_operating_class);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800567 os_free(conf->hs20_icons);
568 if (conf->hs20_osu_providers) {
569 size_t i;
570 for (i = 0; i < conf->hs20_osu_providers_count; i++) {
571 struct hs20_osu_provider *p;
572 size_t j;
573 p = &conf->hs20_osu_providers[i];
574 os_free(p->friendly_name);
575 os_free(p->server_uri);
576 os_free(p->method_list);
577 for (j = 0; j < p->icons_count; j++)
578 os_free(p->icons[j]);
579 os_free(p->icons);
580 os_free(p->osu_nai);
581 os_free(p->service_desc);
582 }
583 os_free(conf->hs20_osu_providers);
584 }
585 os_free(conf->subscr_remediation_url);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700586#endif /* CONFIG_HS20 */
587
588 wpabuf_free(conf->vendor_elements);
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700589 wpabuf_free(conf->assocresp_elements);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800590
591 os_free(conf->sae_groups);
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700592
Dmitry Shmidt0207e232014-09-03 14:58:37 -0700593 os_free(conf->wowlan_triggers);
594
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700595 os_free(conf->server_id);
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800596
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800597#ifdef CONFIG_TESTING_OPTIONS
598 wpabuf_free(conf->own_ie_override);
599#endif /* CONFIG_TESTING_OPTIONS */
600
601 os_free(conf->no_probe_resp_if_seen_on);
602 os_free(conf->no_auth_if_seen_on);
603
Dmitry Shmidt29333592017-01-09 12:27:11 -0800604 hostapd_config_free_fils_realms(conf);
605
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800606 os_free(conf);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700607}
608
609
610/**
611 * hostapd_config_free - Free hostapd configuration
612 * @conf: Configuration data from hostapd_config_read().
613 */
614void hostapd_config_free(struct hostapd_config *conf)
615{
616 size_t i;
617
618 if (conf == NULL)
619 return;
620
621 for (i = 0; i < conf->num_bss; i++)
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800622 hostapd_config_free_bss(conf->bss[i]);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700623 os_free(conf->bss);
624 os_free(conf->supported_rates);
625 os_free(conf->basic_rates);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700626 os_free(conf->acs_ch_list.range);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800627 os_free(conf->driver_params);
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800628#ifdef CONFIG_ACS
629 os_free(conf->acs_chan_bias);
630#endif /* CONFIG_ACS */
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700631 wpabuf_free(conf->lci);
632 wpabuf_free(conf->civic);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700633
634 os_free(conf);
635}
636
637
638/**
639 * hostapd_maclist_found - Find a MAC address from a list
640 * @list: MAC address list
641 * @num_entries: Number of addresses in the list
642 * @addr: Address to search for
643 * @vlan_id: Buffer for returning VLAN ID or %NULL if not needed
644 * Returns: 1 if address is in the list or 0 if not.
645 *
646 * Perform a binary search for given MAC address from a pre-sorted list.
647 */
648int hostapd_maclist_found(struct mac_acl_entry *list, int num_entries,
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800649 const u8 *addr, struct vlan_description *vlan_id)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700650{
651 int start, end, middle, res;
652
653 start = 0;
654 end = num_entries - 1;
655
656 while (start <= end) {
657 middle = (start + end) / 2;
658 res = os_memcmp(list[middle].addr, addr, ETH_ALEN);
659 if (res == 0) {
660 if (vlan_id)
661 *vlan_id = list[middle].vlan_id;
662 return 1;
663 }
664 if (res < 0)
665 start = middle + 1;
666 else
667 end = middle - 1;
668 }
669
670 return 0;
671}
672
673
674int hostapd_rate_found(int *list, int rate)
675{
676 int i;
677
678 if (list == NULL)
679 return 0;
680
681 for (i = 0; list[i] >= 0; i++)
682 if (list[i] == rate)
683 return 1;
684
685 return 0;
686}
687
688
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800689int hostapd_vlan_valid(struct hostapd_vlan *vlan,
690 struct vlan_description *vlan_desc)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700691{
692 struct hostapd_vlan *v = vlan;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800693 int i;
694
695 if (!vlan_desc->notempty || vlan_desc->untagged < 0 ||
696 vlan_desc->untagged > MAX_VLAN_ID)
697 return 0;
698 for (i = 0; i < MAX_NUM_TAGGED_VLAN; i++) {
699 if (vlan_desc->tagged[i] < 0 ||
700 vlan_desc->tagged[i] > MAX_VLAN_ID)
701 return 0;
702 }
703 if (!vlan_desc->untagged && !vlan_desc->tagged[0])
704 return 0;
705
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700706 while (v) {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800707 if (!vlan_compare(&v->vlan_desc, vlan_desc) ||
708 v->vlan_id == VLAN_ID_WILDCARD)
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700709 return 1;
710 v = v->next;
711 }
712 return 0;
713}
714
715
716const char * hostapd_get_vlan_id_ifname(struct hostapd_vlan *vlan, int vlan_id)
717{
718 struct hostapd_vlan *v = vlan;
719 while (v) {
720 if (v->vlan_id == vlan_id)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700721 return v->ifname;
722 v = v->next;
723 }
724 return NULL;
725}
726
727
728const u8 * hostapd_get_psk(const struct hostapd_bss_config *conf,
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700729 const u8 *addr, const u8 *p2p_dev_addr,
730 const u8 *prev_psk)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700731{
732 struct hostapd_wpa_psk *psk;
733 int next_ok = prev_psk == NULL;
734
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -0700735 if (p2p_dev_addr && !is_zero_ether_addr(p2p_dev_addr)) {
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700736 wpa_printf(MSG_DEBUG, "Searching a PSK for " MACSTR
737 " p2p_dev_addr=" MACSTR " prev_psk=%p",
738 MAC2STR(addr), MAC2STR(p2p_dev_addr), prev_psk);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -0700739 addr = NULL; /* Use P2P Device Address for matching */
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700740 } else {
741 wpa_printf(MSG_DEBUG, "Searching a PSK for " MACSTR
742 " prev_psk=%p",
743 MAC2STR(addr), prev_psk);
744 }
745
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700746 for (psk = conf->ssid.wpa_psk; psk != NULL; psk = psk->next) {
747 if (next_ok &&
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700748 (psk->group ||
749 (addr && os_memcmp(psk->addr, addr, ETH_ALEN) == 0) ||
750 (!addr && p2p_dev_addr &&
751 os_memcmp(psk->p2p_dev_addr, p2p_dev_addr, ETH_ALEN) ==
752 0)))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700753 return psk->psk;
754
755 if (psk->psk == prev_psk)
756 next_ok = 1;
757 }
758
759 return NULL;
760}
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800761
762
763static int hostapd_config_check_bss(struct hostapd_bss_config *bss,
Dmitry Shmidt344abd32014-01-14 13:17:00 -0800764 struct hostapd_config *conf,
765 int full_config)
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800766{
Dmitry Shmidt344abd32014-01-14 13:17:00 -0800767 if (full_config && bss->ieee802_1x && !bss->eap_server &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800768 !bss->radius->auth_servers) {
769 wpa_printf(MSG_ERROR, "Invalid IEEE 802.1X configuration (no "
770 "EAP authenticator configured).");
771 return -1;
772 }
773
774 if (bss->wpa) {
775 int wep, i;
776
777 wep = bss->default_wep_key_len > 0 ||
778 bss->individual_wep_key_len > 0;
779 for (i = 0; i < NUM_WEP_KEYS; i++) {
780 if (bss->ssid.wep.keys_set) {
781 wep = 1;
782 break;
783 }
784 }
785
786 if (wep) {
787 wpa_printf(MSG_ERROR, "WEP configuration in a WPA network is not supported");
788 return -1;
789 }
790 }
791
Dmitry Shmidt344abd32014-01-14 13:17:00 -0800792 if (full_config && bss->wpa &&
793 bss->wpa_psk_radius != PSK_RADIUS_IGNORED &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800794 bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH) {
795 wpa_printf(MSG_ERROR, "WPA-PSK using RADIUS enabled, but no "
796 "RADIUS checking (macaddr_acl=2) enabled.");
797 return -1;
798 }
799
Dmitry Shmidt344abd32014-01-14 13:17:00 -0800800 if (full_config && bss->wpa && (bss->wpa_key_mgmt & WPA_KEY_MGMT_PSK) &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800801 bss->ssid.wpa_psk == NULL && bss->ssid.wpa_passphrase == NULL &&
802 bss->ssid.wpa_psk_file == NULL &&
803 (bss->wpa_psk_radius != PSK_RADIUS_REQUIRED ||
804 bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH)) {
805 wpa_printf(MSG_ERROR, "WPA-PSK enabled, but PSK or passphrase "
806 "is not configured.");
807 return -1;
808 }
809
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800810 if (full_config && !is_zero_ether_addr(bss->bssid)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800811 size_t i;
812
813 for (i = 0; i < conf->num_bss; i++) {
814 if (conf->bss[i] != bss &&
815 (hostapd_mac_comp(conf->bss[i]->bssid,
816 bss->bssid) == 0)) {
817 wpa_printf(MSG_ERROR, "Duplicate BSSID " MACSTR
818 " on interface '%s' and '%s'.",
819 MAC2STR(bss->bssid),
820 conf->bss[i]->iface, bss->iface);
821 return -1;
822 }
823 }
824 }
825
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800826#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt344abd32014-01-14 13:17:00 -0800827 if (full_config && wpa_key_mgmt_ft(bss->wpa_key_mgmt) &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800828 (bss->nas_identifier == NULL ||
829 os_strlen(bss->nas_identifier) < 1 ||
830 os_strlen(bss->nas_identifier) > FT_R0KH_ID_MAX_LEN)) {
831 wpa_printf(MSG_ERROR, "FT (IEEE 802.11r) requires "
832 "nas_identifier to be configured as a 1..48 octet "
833 "string");
834 return -1;
835 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800836#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800837
838#ifdef CONFIG_IEEE80211N
Dmitry Shmidt344abd32014-01-14 13:17:00 -0800839 if (full_config && conf->ieee80211n &&
840 conf->hw_mode == HOSTAPD_MODE_IEEE80211B) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800841 bss->disable_11n = 1;
842 wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) in 11b mode is not "
Dmitry Shmidt661b4f72014-09-29 14:58:27 -0700843 "allowed, disabling HT capabilities");
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800844 }
845
Dmitry Shmidt344abd32014-01-14 13:17:00 -0800846 if (full_config && conf->ieee80211n &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800847 bss->ssid.security_policy == SECURITY_STATIC_WEP) {
848 bss->disable_11n = 1;
849 wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) with WEP is not "
850 "allowed, disabling HT capabilities");
851 }
852
Dmitry Shmidt344abd32014-01-14 13:17:00 -0800853 if (full_config && conf->ieee80211n && bss->wpa &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800854 !(bss->wpa_pairwise & WPA_CIPHER_CCMP) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800855 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
856 WPA_CIPHER_CCMP_256 | WPA_CIPHER_GCMP_256)))
857 {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800858 bss->disable_11n = 1;
859 wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) with WPA/WPA2 "
860 "requires CCMP/GCMP to be enabled, disabling HT "
861 "capabilities");
862 }
863#endif /* CONFIG_IEEE80211N */
864
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -0700865#ifdef CONFIG_IEEE80211AC
866 if (full_config && conf->ieee80211ac &&
867 bss->ssid.security_policy == SECURITY_STATIC_WEP) {
868 bss->disable_11ac = 1;
869 wpa_printf(MSG_ERROR,
870 "VHT (IEEE 802.11ac) with WEP is not allowed, disabling VHT capabilities");
871 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800872
873 if (full_config && conf->ieee80211ac && bss->wpa &&
874 !(bss->wpa_pairwise & WPA_CIPHER_CCMP) &&
875 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
876 WPA_CIPHER_CCMP_256 | WPA_CIPHER_GCMP_256)))
877 {
878 bss->disable_11ac = 1;
879 wpa_printf(MSG_ERROR,
880 "VHT (IEEE 802.11ac) with WPA/WPA2 requires CCMP/GCMP to be enabled, disabling VHT capabilities");
881 }
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -0700882#endif /* CONFIG_IEEE80211AC */
883
Dmitry Shmidt15907092014-03-25 10:42:57 -0700884#ifdef CONFIG_WPS
Dmitry Shmidt344abd32014-01-14 13:17:00 -0800885 if (full_config && bss->wps_state && bss->ignore_broadcast_ssid) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800886 wpa_printf(MSG_INFO, "WPS: ignore_broadcast_ssid "
887 "configuration forced WPS to be disabled");
888 bss->wps_state = 0;
889 }
890
Dmitry Shmidt344abd32014-01-14 13:17:00 -0800891 if (full_config && bss->wps_state &&
892 bss->ssid.wep.keys_set && bss->wpa == 0) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800893 wpa_printf(MSG_INFO, "WPS: WEP configuration forced WPS to be "
894 "disabled");
895 bss->wps_state = 0;
896 }
897
Dmitry Shmidt344abd32014-01-14 13:17:00 -0800898 if (full_config && bss->wps_state && bss->wpa &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800899 (!(bss->wpa & 2) ||
Dmitry Shmidt1d755d02015-04-28 10:34:29 -0700900 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP)))) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800901 wpa_printf(MSG_INFO, "WPS: WPA/TKIP configuration without "
Dmitry Shmidt1d755d02015-04-28 10:34:29 -0700902 "WPA2/CCMP/GCMP forced WPS to be disabled");
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800903 bss->wps_state = 0;
904 }
Dmitry Shmidt15907092014-03-25 10:42:57 -0700905#endif /* CONFIG_WPS */
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800906
907#ifdef CONFIG_HS20
Dmitry Shmidt344abd32014-01-14 13:17:00 -0800908 if (full_config && bss->hs20 &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800909 (!(bss->wpa & 2) ||
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800910 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
911 WPA_CIPHER_CCMP_256 |
912 WPA_CIPHER_GCMP_256)))) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800913 wpa_printf(MSG_ERROR, "HS 2.0: WPA2-Enterprise/CCMP "
914 "configuration is required for Hotspot 2.0 "
915 "functionality");
916 return -1;
917 }
918#endif /* CONFIG_HS20 */
919
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800920#ifdef CONFIG_MBO
921 if (full_config && bss->mbo_enabled && (bss->wpa & 2) &&
922 bss->ieee80211w == NO_MGMT_FRAME_PROTECTION) {
923 wpa_printf(MSG_ERROR,
924 "MBO: PMF needs to be enabled whenever using WPA2 with MBO");
925 return -1;
926 }
927#endif /* CONFIG_MBO */
928
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800929 return 0;
930}
931
932
Dmitry Shmidt05df46a2015-05-19 11:02:01 -0700933static int hostapd_config_check_cw(struct hostapd_config *conf, int queue)
934{
935 int tx_cwmin = conf->tx_queue[queue].cwmin;
936 int tx_cwmax = conf->tx_queue[queue].cwmax;
937 int ac_cwmin = conf->wmm_ac_params[queue].cwmin;
938 int ac_cwmax = conf->wmm_ac_params[queue].cwmax;
939
940 if (tx_cwmin > tx_cwmax) {
941 wpa_printf(MSG_ERROR,
942 "Invalid TX queue cwMin/cwMax values. cwMin(%d) greater than cwMax(%d)",
943 tx_cwmin, tx_cwmax);
944 return -1;
945 }
946 if (ac_cwmin > ac_cwmax) {
947 wpa_printf(MSG_ERROR,
948 "Invalid WMM AC cwMin/cwMax values. cwMin(%d) greater than cwMax(%d)",
949 ac_cwmin, ac_cwmax);
950 return -1;
951 }
952 return 0;
953}
954
955
Dmitry Shmidt344abd32014-01-14 13:17:00 -0800956int hostapd_config_check(struct hostapd_config *conf, int full_config)
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800957{
958 size_t i;
959
Dmitry Shmidt344abd32014-01-14 13:17:00 -0800960 if (full_config && conf->ieee80211d &&
961 (!conf->country[0] || !conf->country[1])) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800962 wpa_printf(MSG_ERROR, "Cannot enable IEEE 802.11d without "
963 "setting the country_code");
964 return -1;
965 }
966
Dmitry Shmidt344abd32014-01-14 13:17:00 -0800967 if (full_config && conf->ieee80211h && !conf->ieee80211d) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800968 wpa_printf(MSG_ERROR, "Cannot enable IEEE 802.11h without "
969 "IEEE 802.11d enabled");
970 return -1;
971 }
972
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800973 if (full_config && conf->local_pwr_constraint != -1 &&
974 !conf->ieee80211d) {
975 wpa_printf(MSG_ERROR, "Cannot add Power Constraint element without Country element");
976 return -1;
977 }
978
979 if (full_config && conf->spectrum_mgmt_required &&
980 conf->local_pwr_constraint == -1) {
981 wpa_printf(MSG_ERROR, "Cannot set Spectrum Management bit without Country and Power Constraint elements");
982 return -1;
983 }
984
Dmitry Shmidt05df46a2015-05-19 11:02:01 -0700985 for (i = 0; i < NUM_TX_QUEUES; i++) {
986 if (hostapd_config_check_cw(conf, i))
987 return -1;
988 }
989
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800990 for (i = 0; i < conf->num_bss; i++) {
Dmitry Shmidt344abd32014-01-14 13:17:00 -0800991 if (hostapd_config_check_bss(conf->bss[i], conf, full_config))
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800992 return -1;
993 }
994
995 return 0;
996}
997
998
Dmitry Shmidt71757432014-06-02 13:50:35 -0700999void hostapd_set_security_params(struct hostapd_bss_config *bss,
1000 int full_config)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001001{
1002 if (bss->individual_wep_key_len == 0) {
1003 /* individual keys are not use; can use key idx0 for
1004 * broadcast keys */
1005 bss->broadcast_key_idx_min = 0;
1006 }
1007
1008 if ((bss->wpa & 2) && bss->rsn_pairwise == 0)
1009 bss->rsn_pairwise = bss->wpa_pairwise;
1010 bss->wpa_group = wpa_select_ap_group_cipher(bss->wpa, bss->wpa_pairwise,
1011 bss->rsn_pairwise);
1012
Dmitry Shmidt71757432014-06-02 13:50:35 -07001013 if (full_config) {
1014 bss->radius->auth_server = bss->radius->auth_servers;
1015 bss->radius->acct_server = bss->radius->acct_servers;
1016 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001017
1018 if (bss->wpa && bss->ieee802_1x) {
1019 bss->ssid.security_policy = SECURITY_WPA;
1020 } else if (bss->wpa) {
1021 bss->ssid.security_policy = SECURITY_WPA_PSK;
1022 } else if (bss->ieee802_1x) {
1023 int cipher = WPA_CIPHER_NONE;
1024 bss->ssid.security_policy = SECURITY_IEEE_802_1X;
1025 bss->ssid.wep.default_len = bss->default_wep_key_len;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001026 if (full_config && bss->default_wep_key_len) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001027 cipher = bss->default_wep_key_len >= 13 ?
1028 WPA_CIPHER_WEP104 : WPA_CIPHER_WEP40;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001029 } else if (full_config && bss->ssid.wep.keys_set) {
1030 if (bss->ssid.wep.len[0] >= 13)
1031 cipher = WPA_CIPHER_WEP104;
1032 else
1033 cipher = WPA_CIPHER_WEP40;
1034 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001035 bss->wpa_group = cipher;
1036 bss->wpa_pairwise = cipher;
1037 bss->rsn_pairwise = cipher;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001038 if (full_config)
1039 bss->wpa_key_mgmt = WPA_KEY_MGMT_IEEE8021X_NO_WPA;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001040 } else if (bss->ssid.wep.keys_set) {
1041 int cipher = WPA_CIPHER_WEP40;
1042 if (bss->ssid.wep.len[0] >= 13)
1043 cipher = WPA_CIPHER_WEP104;
1044 bss->ssid.security_policy = SECURITY_STATIC_WEP;
1045 bss->wpa_group = cipher;
1046 bss->wpa_pairwise = cipher;
1047 bss->rsn_pairwise = cipher;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001048 if (full_config)
1049 bss->wpa_key_mgmt = WPA_KEY_MGMT_NONE;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001050 } else if (bss->osen) {
1051 bss->ssid.security_policy = SECURITY_OSEN;
1052 bss->wpa_group = WPA_CIPHER_CCMP;
1053 bss->wpa_pairwise = 0;
1054 bss->rsn_pairwise = WPA_CIPHER_CCMP;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001055 } else {
1056 bss->ssid.security_policy = SECURITY_PLAINTEXT;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001057 if (full_config) {
1058 bss->wpa_group = WPA_CIPHER_NONE;
1059 bss->wpa_pairwise = WPA_CIPHER_NONE;
1060 bss->rsn_pairwise = WPA_CIPHER_NONE;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001061 bss->wpa_key_mgmt = WPA_KEY_MGMT_NONE;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001062 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001063 }
1064}