blob: 07310f93c33b52e6fc781fb83bb793e7a21d4eab [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"
Dmitry Shmidtebd93af2017-02-21 13:40:44 -080016#include "common/dhcp.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070017#include "eap_common/eap_wsc_common.h"
18#include "eap_server/eap.h"
19#include "wpa_auth.h"
20#include "sta_info.h"
21#include "ap_config.h"
22
23
24static void hostapd_config_free_vlan(struct hostapd_bss_config *bss)
25{
26 struct hostapd_vlan *vlan, *prev;
27
28 vlan = bss->vlan;
29 prev = NULL;
30 while (vlan) {
31 prev = vlan;
32 vlan = vlan->next;
33 os_free(prev);
34 }
35
36 bss->vlan = NULL;
37}
38
39
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070040#ifndef DEFAULT_WPA_DISABLE_EAPOL_KEY_RETRIES
41#define DEFAULT_WPA_DISABLE_EAPOL_KEY_RETRIES 0
42#endif /* DEFAULT_WPA_DISABLE_EAPOL_KEY_RETRIES */
43
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070044void hostapd_config_defaults_bss(struct hostapd_bss_config *bss)
45{
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080046 dl_list_init(&bss->anqp_elem);
47
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070048 bss->logger_syslog_level = HOSTAPD_LEVEL_INFO;
49 bss->logger_stdout_level = HOSTAPD_LEVEL_INFO;
50 bss->logger_syslog = (unsigned int) -1;
51 bss->logger_stdout = (unsigned int) -1;
52
53 bss->auth_algs = WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED;
54
55 bss->wep_rekeying_period = 300;
56 /* use key0 in individual key and key1 in broadcast key */
57 bss->broadcast_key_idx_min = 1;
58 bss->broadcast_key_idx_max = 2;
59 bss->eap_reauth_period = 3600;
60
61 bss->wpa_group_rekey = 600;
62 bss->wpa_gmk_rekey = 86400;
Dmitry Shmidtebd93af2017-02-21 13:40:44 -080063 bss->wpa_group_update_count = 4;
64 bss->wpa_pairwise_update_count = 4;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070065 bss->wpa_disable_eapol_key_retries =
66 DEFAULT_WPA_DISABLE_EAPOL_KEY_RETRIES;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070067 bss->wpa_key_mgmt = WPA_KEY_MGMT_PSK;
68 bss->wpa_pairwise = WPA_CIPHER_TKIP;
69 bss->wpa_group = WPA_CIPHER_TKIP;
70 bss->rsn_pairwise = 0;
71
72 bss->max_num_sta = MAX_STA_COUNT;
73
74 bss->dtim_period = 2;
75
76 bss->radius_server_auth_port = 1812;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080077 bss->eap_sim_db_timeout = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070078 bss->ap_max_inactivity = AP_MAX_INACTIVITY;
79 bss->eapol_version = EAPOL_VERSION;
80
81 bss->max_listen_interval = 65535;
82
83 bss->pwd_group = 19; /* ECC: GF(p=256) */
84
85#ifdef CONFIG_IEEE80211W
86 bss->assoc_sa_query_max_timeout = 1000;
87 bss->assoc_sa_query_retry_timeout = 201;
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -070088 bss->group_mgmt_cipher = WPA_CIPHER_AES_128_CMAC;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070089#endif /* CONFIG_IEEE80211W */
90#ifdef EAP_SERVER_FAST
91 /* both anonymous and authenticated provisioning */
92 bss->eap_fast_prov = 3;
93 bss->pac_key_lifetime = 7 * 24 * 60 * 60;
94 bss->pac_key_refresh_time = 1 * 24 * 60 * 60;
95#endif /* EAP_SERVER_FAST */
96
97 /* Set to -1 as defaults depends on HT in setup */
98 bss->wmm_enabled = -1;
99
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800100#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700101 bss->ft_over_ds = 1;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700102 bss->rkh_pos_timeout = 86400;
103 bss->rkh_neg_timeout = 60;
104 bss->rkh_pull_timeout = 1000;
105 bss->rkh_pull_retries = 4;
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800106#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt04949592012-07-19 12:16:46 -0700107
108 bss->radius_das_time_window = 300;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800109
110 bss->sae_anti_clogging_threshold = 5;
Dmitry Shmidt29333592017-01-09 12:27:11 -0800111
112 bss->gas_frag_limit = 1400;
113
114#ifdef CONFIG_FILS
115 dl_list_init(&bss->fils_realms);
Dmitry Shmidtebd93af2017-02-21 13:40:44 -0800116 bss->fils_hlp_wait_time = 30;
117 bss->dhcp_server_port = DHCP_SERVER_PORT;
118 bss->dhcp_relay_port = DHCP_SERVER_PORT;
Dmitry Shmidt29333592017-01-09 12:27:11 -0800119#endif /* CONFIG_FILS */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700120
121 bss->broadcast_deauth = 1;
122
123#ifdef CONFIG_MBO
124 bss->mbo_cell_data_conn_pref = -1;
125#endif /* CONFIG_MBO */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700126}
127
128
129struct hostapd_config * hostapd_config_defaults(void)
130{
131#define ecw2cw(ecw) ((1 << (ecw)) - 1)
132
133 struct hostapd_config *conf;
134 struct hostapd_bss_config *bss;
135 const int aCWmin = 4, aCWmax = 10;
136 const struct hostapd_wmm_ac_params ac_bk =
137 { aCWmin, aCWmax, 7, 0, 0 }; /* background traffic */
138 const struct hostapd_wmm_ac_params ac_be =
139 { aCWmin, aCWmax, 3, 0, 0 }; /* best effort traffic */
140 const struct hostapd_wmm_ac_params ac_vi = /* video traffic */
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700141 { aCWmin - 1, aCWmin, 2, 3008 / 32, 0 };
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700142 const struct hostapd_wmm_ac_params ac_vo = /* voice traffic */
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -0700143 { aCWmin - 2, aCWmin - 1, 2, 1504 / 32, 0 };
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700144 const struct hostapd_tx_queue_params txq_bk =
145 { 7, ecw2cw(aCWmin), ecw2cw(aCWmax), 0 };
146 const struct hostapd_tx_queue_params txq_be =
147 { 3, ecw2cw(aCWmin), 4 * (ecw2cw(aCWmin) + 1) - 1, 0};
148 const struct hostapd_tx_queue_params txq_vi =
149 { 1, (ecw2cw(aCWmin) + 1) / 2 - 1, ecw2cw(aCWmin), 30};
150 const struct hostapd_tx_queue_params txq_vo =
151 { 1, (ecw2cw(aCWmin) + 1) / 4 - 1,
152 (ecw2cw(aCWmin) + 1) / 2 - 1, 15};
153
154#undef ecw2cw
155
156 conf = os_zalloc(sizeof(*conf));
157 bss = os_zalloc(sizeof(*bss));
158 if (conf == NULL || bss == NULL) {
159 wpa_printf(MSG_ERROR, "Failed to allocate memory for "
160 "configuration data.");
161 os_free(conf);
162 os_free(bss);
163 return NULL;
164 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800165 conf->bss = os_calloc(1, sizeof(struct hostapd_bss_config *));
166 if (conf->bss == NULL) {
167 os_free(conf);
168 os_free(bss);
169 return NULL;
170 }
171 conf->bss[0] = bss;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700172
173 bss->radius = os_zalloc(sizeof(*bss->radius));
174 if (bss->radius == NULL) {
Dmitry Shmidt97672262014-02-03 13:02:54 -0800175 os_free(conf->bss);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700176 os_free(conf);
177 os_free(bss);
178 return NULL;
179 }
180
181 hostapd_config_defaults_bss(bss);
182
183 conf->num_bss = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700184
185 conf->beacon_int = 100;
186 conf->rts_threshold = -1; /* use driver default: 2347 */
187 conf->fragm_threshold = -1; /* user driver default: 2346 */
188 conf->send_probe_response = 1;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800189 /* Set to invalid value means do not add Power Constraint IE */
190 conf->local_pwr_constraint = -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700191
192 conf->wmm_ac_params[0] = ac_be;
193 conf->wmm_ac_params[1] = ac_bk;
194 conf->wmm_ac_params[2] = ac_vi;
195 conf->wmm_ac_params[3] = ac_vo;
196
197 conf->tx_queue[0] = txq_vo;
198 conf->tx_queue[1] = txq_vi;
199 conf->tx_queue[2] = txq_be;
200 conf->tx_queue[3] = txq_bk;
201
202 conf->ht_capab = HT_CAP_INFO_SMPS_DISABLED;
203
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800204 conf->ap_table_max_size = 255;
205 conf->ap_table_expiration_time = 60;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800206 conf->track_sta_max_age = 180;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800207
Dmitry Shmidt8da800a2013-04-24 12:57:01 -0700208#ifdef CONFIG_TESTING_OPTIONS
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700209 conf->ignore_probe_probability = 0.0;
210 conf->ignore_auth_probability = 0.0;
211 conf->ignore_assoc_probability = 0.0;
212 conf->ignore_reassoc_probability = 0.0;
213 conf->corrupt_gtk_rekey_mic_probability = 0.0;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800214 conf->ecsa_ie_only = 0;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -0700215#endif /* CONFIG_TESTING_OPTIONS */
216
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700217 conf->acs = 0;
218 conf->acs_ch_list.num = 0;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700219#ifdef CONFIG_ACS
220 conf->acs_num_scans = 5;
221#endif /* CONFIG_ACS */
222
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700223 /* The third octet of the country string uses an ASCII space character
224 * by default to indicate that the regulations encompass all
225 * environments for the current frequency band in the country. */
226 conf->country[2] = ' ';
227
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700228 return conf;
229}
230
231
232int hostapd_mac_comp(const void *a, const void *b)
233{
234 return os_memcmp(a, b, sizeof(macaddr));
235}
236
237
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700238static int hostapd_config_read_wpa_psk(const char *fname,
239 struct hostapd_ssid *ssid)
240{
241 FILE *f;
242 char buf[128], *pos;
243 int line = 0, ret = 0, len, ok;
244 u8 addr[ETH_ALEN];
245 struct hostapd_wpa_psk *psk;
246
247 if (!fname)
248 return 0;
249
250 f = fopen(fname, "r");
251 if (!f) {
252 wpa_printf(MSG_ERROR, "WPA PSK file '%s' not found.", fname);
253 return -1;
254 }
255
256 while (fgets(buf, sizeof(buf), f)) {
257 line++;
258
259 if (buf[0] == '#')
260 continue;
261 pos = buf;
262 while (*pos != '\0') {
263 if (*pos == '\n') {
264 *pos = '\0';
265 break;
266 }
267 pos++;
268 }
269 if (buf[0] == '\0')
270 continue;
271
272 if (hwaddr_aton(buf, addr)) {
273 wpa_printf(MSG_ERROR, "Invalid MAC address '%s' on "
274 "line %d in '%s'", buf, line, fname);
275 ret = -1;
276 break;
277 }
278
279 psk = os_zalloc(sizeof(*psk));
280 if (psk == NULL) {
281 wpa_printf(MSG_ERROR, "WPA PSK allocation failed");
282 ret = -1;
283 break;
284 }
285 if (is_zero_ether_addr(addr))
286 psk->group = 1;
287 else
288 os_memcpy(psk->addr, addr, ETH_ALEN);
289
290 pos = buf + 17;
291 if (*pos == '\0') {
292 wpa_printf(MSG_ERROR, "No PSK on line %d in '%s'",
293 line, fname);
294 os_free(psk);
295 ret = -1;
296 break;
297 }
298 pos++;
299
300 ok = 0;
301 len = os_strlen(pos);
302 if (len == 64 && hexstr2bin(pos, psk->psk, PMK_LEN) == 0)
303 ok = 1;
304 else if (len >= 8 && len < 64) {
305 pbkdf2_sha1(pos, ssid->ssid, ssid->ssid_len,
306 4096, psk->psk, PMK_LEN);
307 ok = 1;
308 }
309 if (!ok) {
310 wpa_printf(MSG_ERROR, "Invalid PSK '%s' on line %d in "
311 "'%s'", pos, line, fname);
312 os_free(psk);
313 ret = -1;
314 break;
315 }
316
317 psk->next = ssid->wpa_psk;
318 ssid->wpa_psk = psk;
319 }
320
321 fclose(f);
322
323 return ret;
324}
325
326
327static int hostapd_derive_psk(struct hostapd_ssid *ssid)
328{
329 ssid->wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
330 if (ssid->wpa_psk == NULL) {
331 wpa_printf(MSG_ERROR, "Unable to alloc space for PSK");
332 return -1;
333 }
334 wpa_hexdump_ascii(MSG_DEBUG, "SSID",
335 (u8 *) ssid->ssid, ssid->ssid_len);
336 wpa_hexdump_ascii_key(MSG_DEBUG, "PSK (ASCII passphrase)",
337 (u8 *) ssid->wpa_passphrase,
338 os_strlen(ssid->wpa_passphrase));
339 pbkdf2_sha1(ssid->wpa_passphrase,
340 ssid->ssid, ssid->ssid_len,
341 4096, ssid->wpa_psk->psk, PMK_LEN);
342 wpa_hexdump_key(MSG_DEBUG, "PSK (from passphrase)",
343 ssid->wpa_psk->psk, PMK_LEN);
344 return 0;
345}
346
347
348int hostapd_setup_wpa_psk(struct hostapd_bss_config *conf)
349{
350 struct hostapd_ssid *ssid = &conf->ssid;
351
352 if (ssid->wpa_passphrase != NULL) {
353 if (ssid->wpa_psk != NULL) {
354 wpa_printf(MSG_DEBUG, "Using pre-configured WPA PSK "
355 "instead of passphrase");
356 } else {
357 wpa_printf(MSG_DEBUG, "Deriving WPA PSK based on "
358 "passphrase");
359 if (hostapd_derive_psk(ssid) < 0)
360 return -1;
361 }
362 ssid->wpa_psk->group = 1;
363 }
364
Dmitry Shmidt29333592017-01-09 12:27:11 -0800365 return hostapd_config_read_wpa_psk(ssid->wpa_psk_file, &conf->ssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700366}
367
368
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700369static void hostapd_config_free_radius(struct hostapd_radius_server *servers,
370 int num_servers)
371{
372 int i;
373
374 for (i = 0; i < num_servers; i++) {
375 os_free(servers[i].shared_secret);
376 }
377 os_free(servers);
378}
379
380
Dmitry Shmidt04949592012-07-19 12:16:46 -0700381struct hostapd_radius_attr *
382hostapd_config_get_radius_attr(struct hostapd_radius_attr *attr, u8 type)
383{
384 for (; attr; attr = attr->next) {
385 if (attr->type == type)
386 return attr;
387 }
388 return NULL;
389}
390
391
392static void hostapd_config_free_radius_attr(struct hostapd_radius_attr *attr)
393{
394 struct hostapd_radius_attr *prev;
395
396 while (attr) {
397 prev = attr;
398 attr = attr->next;
399 wpabuf_free(prev->val);
400 os_free(prev);
401 }
402}
403
404
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700405void hostapd_config_free_eap_user(struct hostapd_eap_user *user)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700406{
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700407 hostapd_config_free_radius_attr(user->accept_attr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700408 os_free(user->identity);
Dmitry Shmidtc2817022014-07-02 10:32:10 -0700409 bin_clear_free(user->password, user->password_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700410 os_free(user);
411}
412
413
Dmitry Shmidt29333592017-01-09 12:27:11 -0800414void hostapd_config_free_eap_users(struct hostapd_eap_user *user)
415{
416 struct hostapd_eap_user *prev_user;
417
418 while (user) {
419 prev_user = user;
420 user = user->next;
421 hostapd_config_free_eap_user(prev_user);
422 }
423}
424
425
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700426static void hostapd_config_free_wep(struct hostapd_wep_keys *keys)
427{
428 int i;
429 for (i = 0; i < NUM_WEP_KEYS; i++) {
Dmitry Shmidtc2817022014-07-02 10:32:10 -0700430 bin_clear_free(keys->key[i], keys->len[i]);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700431 keys->key[i] = NULL;
432 }
433}
434
435
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800436void hostapd_config_clear_wpa_psk(struct hostapd_wpa_psk **l)
437{
438 struct hostapd_wpa_psk *psk, *tmp;
439
440 for (psk = *l; psk;) {
441 tmp = psk;
442 psk = psk->next;
443 bin_clear_free(tmp, sizeof(*tmp));
444 }
445 *l = NULL;
446}
447
448
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800449static void hostapd_config_free_anqp_elem(struct hostapd_bss_config *conf)
450{
451 struct anqp_element *elem;
452
453 while ((elem = dl_list_first(&conf->anqp_elem, struct anqp_element,
454 list))) {
455 dl_list_del(&elem->list);
456 wpabuf_free(elem->payload);
457 os_free(elem);
458 }
459}
460
461
Dmitry Shmidt29333592017-01-09 12:27:11 -0800462static void hostapd_config_free_fils_realms(struct hostapd_bss_config *conf)
463{
464#ifdef CONFIG_FILS
465 struct fils_realm *realm;
466
467 while ((realm = dl_list_first(&conf->fils_realms, struct fils_realm,
468 list))) {
469 dl_list_del(&realm->list);
470 os_free(realm);
471 }
472#endif /* CONFIG_FILS */
473}
474
475
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800476void hostapd_config_free_bss(struct hostapd_bss_config *conf)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700477{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700478 if (conf == NULL)
479 return;
480
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800481 hostapd_config_clear_wpa_psk(&conf->ssid.wpa_psk);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700482
Dmitry Shmidtc2817022014-07-02 10:32:10 -0700483 str_clear_free(conf->ssid.wpa_passphrase);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700484 os_free(conf->ssid.wpa_psk_file);
485 hostapd_config_free_wep(&conf->ssid.wep);
486#ifdef CONFIG_FULL_DYNAMIC_VLAN
487 os_free(conf->ssid.vlan_tagged_interface);
488#endif /* CONFIG_FULL_DYNAMIC_VLAN */
489
Dmitry Shmidt29333592017-01-09 12:27:11 -0800490 hostapd_config_free_eap_users(conf->eap_user);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800491 os_free(conf->eap_user_sqlite);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700492
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700493 os_free(conf->eap_req_id_text);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800494 os_free(conf->erp_domain);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700495 os_free(conf->accept_mac);
496 os_free(conf->deny_mac);
497 os_free(conf->nas_identifier);
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800498 if (conf->radius) {
499 hostapd_config_free_radius(conf->radius->auth_servers,
500 conf->radius->num_auth_servers);
501 hostapd_config_free_radius(conf->radius->acct_servers,
502 conf->radius->num_acct_servers);
503 }
Dmitry Shmidt04949592012-07-19 12:16:46 -0700504 hostapd_config_free_radius_attr(conf->radius_auth_req_attr);
505 hostapd_config_free_radius_attr(conf->radius_acct_req_attr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700506 os_free(conf->rsn_preauth_interfaces);
507 os_free(conf->ctrl_interface);
508 os_free(conf->ca_cert);
509 os_free(conf->server_cert);
510 os_free(conf->private_key);
511 os_free(conf->private_key_passwd);
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700512 os_free(conf->ocsp_stapling_response);
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -0800513 os_free(conf->ocsp_stapling_response_multi);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700514 os_free(conf->dh_file);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800515 os_free(conf->openssl_ciphers);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700516 os_free(conf->pac_opaque_encr_key);
517 os_free(conf->eap_fast_a_id);
518 os_free(conf->eap_fast_a_id_info);
519 os_free(conf->eap_sim_db);
520 os_free(conf->radius_server_clients);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700521 os_free(conf->radius);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700522 os_free(conf->radius_das_shared_secret);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700523 hostapd_config_free_vlan(conf);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800524 os_free(conf->time_zone);
525
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800526#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700527 {
528 struct ft_remote_r0kh *r0kh, *r0kh_prev;
529 struct ft_remote_r1kh *r1kh, *r1kh_prev;
530
531 r0kh = conf->r0kh_list;
532 conf->r0kh_list = NULL;
533 while (r0kh) {
534 r0kh_prev = r0kh;
535 r0kh = r0kh->next;
536 os_free(r0kh_prev);
537 }
538
539 r1kh = conf->r1kh_list;
540 conf->r1kh_list = NULL;
541 while (r1kh) {
542 r1kh_prev = r1kh;
543 r1kh = r1kh->next;
544 os_free(r1kh_prev);
545 }
546 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800547#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700548
549#ifdef CONFIG_WPS
550 os_free(conf->wps_pin_requests);
551 os_free(conf->device_name);
552 os_free(conf->manufacturer);
553 os_free(conf->model_name);
554 os_free(conf->model_number);
555 os_free(conf->serial_number);
556 os_free(conf->config_methods);
557 os_free(conf->ap_pin);
558 os_free(conf->extra_cred);
559 os_free(conf->ap_settings);
560 os_free(conf->upnp_iface);
561 os_free(conf->friendly_name);
562 os_free(conf->manufacturer_url);
563 os_free(conf->model_description);
564 os_free(conf->model_url);
565 os_free(conf->upc);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800566 {
567 unsigned int i;
568
569 for (i = 0; i < MAX_WPS_VENDOR_EXTENSIONS; i++)
570 wpabuf_free(conf->wps_vendor_ext[i]);
571 }
Dmitry Shmidt04949592012-07-19 12:16:46 -0700572 wpabuf_free(conf->wps_nfc_dh_pubkey);
573 wpabuf_free(conf->wps_nfc_dh_privkey);
574 wpabuf_free(conf->wps_nfc_dev_pw);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700575#endif /* CONFIG_WPS */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800576
577 os_free(conf->roaming_consortium);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700578 os_free(conf->venue_name);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700579 os_free(conf->nai_realm_data);
580 os_free(conf->network_auth_type);
581 os_free(conf->anqp_3gpp_cell_net);
582 os_free(conf->domain_name);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800583 hostapd_config_free_anqp_elem(conf);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800584
585#ifdef CONFIG_RADIUS_TEST
586 os_free(conf->dump_msk_file);
587#endif /* CONFIG_RADIUS_TEST */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700588
589#ifdef CONFIG_HS20
590 os_free(conf->hs20_oper_friendly_name);
591 os_free(conf->hs20_wan_metrics);
592 os_free(conf->hs20_connection_capability);
593 os_free(conf->hs20_operating_class);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800594 os_free(conf->hs20_icons);
595 if (conf->hs20_osu_providers) {
596 size_t i;
597 for (i = 0; i < conf->hs20_osu_providers_count; i++) {
598 struct hs20_osu_provider *p;
599 size_t j;
600 p = &conf->hs20_osu_providers[i];
601 os_free(p->friendly_name);
602 os_free(p->server_uri);
603 os_free(p->method_list);
604 for (j = 0; j < p->icons_count; j++)
605 os_free(p->icons[j]);
606 os_free(p->icons);
607 os_free(p->osu_nai);
608 os_free(p->service_desc);
609 }
610 os_free(conf->hs20_osu_providers);
611 }
612 os_free(conf->subscr_remediation_url);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700613#endif /* CONFIG_HS20 */
614
615 wpabuf_free(conf->vendor_elements);
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700616 wpabuf_free(conf->assocresp_elements);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800617
618 os_free(conf->sae_groups);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700619#ifdef CONFIG_OWE
620 os_free(conf->owe_groups);
621#endif /* CONFIG_OWE */
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700622
Dmitry Shmidt0207e232014-09-03 14:58:37 -0700623 os_free(conf->wowlan_triggers);
624
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700625 os_free(conf->server_id);
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800626
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800627#ifdef CONFIG_TESTING_OPTIONS
628 wpabuf_free(conf->own_ie_override);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700629 wpabuf_free(conf->sae_commit_override);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800630#endif /* CONFIG_TESTING_OPTIONS */
631
632 os_free(conf->no_probe_resp_if_seen_on);
633 os_free(conf->no_auth_if_seen_on);
634
Dmitry Shmidt29333592017-01-09 12:27:11 -0800635 hostapd_config_free_fils_realms(conf);
636
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700637#ifdef CONFIG_DPP
638 os_free(conf->dpp_connector);
639 wpabuf_free(conf->dpp_netaccesskey);
640 wpabuf_free(conf->dpp_csign);
641#endif /* CONFIG_DPP */
642
643 os_free(conf->sae_password);
644
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800645 os_free(conf);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700646}
647
648
649/**
650 * hostapd_config_free - Free hostapd configuration
651 * @conf: Configuration data from hostapd_config_read().
652 */
653void hostapd_config_free(struct hostapd_config *conf)
654{
655 size_t i;
656
657 if (conf == NULL)
658 return;
659
660 for (i = 0; i < conf->num_bss; i++)
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800661 hostapd_config_free_bss(conf->bss[i]);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700662 os_free(conf->bss);
663 os_free(conf->supported_rates);
664 os_free(conf->basic_rates);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700665 os_free(conf->acs_ch_list.range);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800666 os_free(conf->driver_params);
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800667#ifdef CONFIG_ACS
668 os_free(conf->acs_chan_bias);
669#endif /* CONFIG_ACS */
Dmitry Shmidt849734c2016-05-27 09:59:01 -0700670 wpabuf_free(conf->lci);
671 wpabuf_free(conf->civic);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700672
673 os_free(conf);
674}
675
676
677/**
678 * hostapd_maclist_found - Find a MAC address from a list
679 * @list: MAC address list
680 * @num_entries: Number of addresses in the list
681 * @addr: Address to search for
682 * @vlan_id: Buffer for returning VLAN ID or %NULL if not needed
683 * Returns: 1 if address is in the list or 0 if not.
684 *
685 * Perform a binary search for given MAC address from a pre-sorted list.
686 */
687int hostapd_maclist_found(struct mac_acl_entry *list, int num_entries,
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800688 const u8 *addr, struct vlan_description *vlan_id)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700689{
690 int start, end, middle, res;
691
692 start = 0;
693 end = num_entries - 1;
694
695 while (start <= end) {
696 middle = (start + end) / 2;
697 res = os_memcmp(list[middle].addr, addr, ETH_ALEN);
698 if (res == 0) {
699 if (vlan_id)
700 *vlan_id = list[middle].vlan_id;
701 return 1;
702 }
703 if (res < 0)
704 start = middle + 1;
705 else
706 end = middle - 1;
707 }
708
709 return 0;
710}
711
712
713int hostapd_rate_found(int *list, int rate)
714{
715 int i;
716
717 if (list == NULL)
718 return 0;
719
720 for (i = 0; list[i] >= 0; i++)
721 if (list[i] == rate)
722 return 1;
723
724 return 0;
725}
726
727
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800728int hostapd_vlan_valid(struct hostapd_vlan *vlan,
729 struct vlan_description *vlan_desc)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700730{
731 struct hostapd_vlan *v = vlan;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800732 int i;
733
734 if (!vlan_desc->notempty || vlan_desc->untagged < 0 ||
735 vlan_desc->untagged > MAX_VLAN_ID)
736 return 0;
737 for (i = 0; i < MAX_NUM_TAGGED_VLAN; i++) {
738 if (vlan_desc->tagged[i] < 0 ||
739 vlan_desc->tagged[i] > MAX_VLAN_ID)
740 return 0;
741 }
742 if (!vlan_desc->untagged && !vlan_desc->tagged[0])
743 return 0;
744
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700745 while (v) {
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800746 if (!vlan_compare(&v->vlan_desc, vlan_desc) ||
747 v->vlan_id == VLAN_ID_WILDCARD)
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700748 return 1;
749 v = v->next;
750 }
751 return 0;
752}
753
754
755const char * hostapd_get_vlan_id_ifname(struct hostapd_vlan *vlan, int vlan_id)
756{
757 struct hostapd_vlan *v = vlan;
758 while (v) {
759 if (v->vlan_id == vlan_id)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700760 return v->ifname;
761 v = v->next;
762 }
763 return NULL;
764}
765
766
767const u8 * hostapd_get_psk(const struct hostapd_bss_config *conf,
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700768 const u8 *addr, const u8 *p2p_dev_addr,
769 const u8 *prev_psk)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700770{
771 struct hostapd_wpa_psk *psk;
772 int next_ok = prev_psk == NULL;
773
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -0700774 if (p2p_dev_addr && !is_zero_ether_addr(p2p_dev_addr)) {
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700775 wpa_printf(MSG_DEBUG, "Searching a PSK for " MACSTR
776 " p2p_dev_addr=" MACSTR " prev_psk=%p",
777 MAC2STR(addr), MAC2STR(p2p_dev_addr), prev_psk);
Dmitry Shmidtdf5a7e42014-04-02 12:59:59 -0700778 addr = NULL; /* Use P2P Device Address for matching */
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700779 } else {
780 wpa_printf(MSG_DEBUG, "Searching a PSK for " MACSTR
781 " prev_psk=%p",
782 MAC2STR(addr), prev_psk);
783 }
784
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700785 for (psk = conf->ssid.wpa_psk; psk != NULL; psk = psk->next) {
786 if (next_ok &&
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700787 (psk->group ||
788 (addr && os_memcmp(psk->addr, addr, ETH_ALEN) == 0) ||
789 (!addr && p2p_dev_addr &&
790 os_memcmp(psk->p2p_dev_addr, p2p_dev_addr, ETH_ALEN) ==
791 0)))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700792 return psk->psk;
793
794 if (psk->psk == prev_psk)
795 next_ok = 1;
796 }
797
798 return NULL;
799}
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800800
801
802static int hostapd_config_check_bss(struct hostapd_bss_config *bss,
Dmitry Shmidt344abd32014-01-14 13:17:00 -0800803 struct hostapd_config *conf,
804 int full_config)
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800805{
Dmitry Shmidt344abd32014-01-14 13:17:00 -0800806 if (full_config && bss->ieee802_1x && !bss->eap_server &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800807 !bss->radius->auth_servers) {
808 wpa_printf(MSG_ERROR, "Invalid IEEE 802.1X configuration (no "
809 "EAP authenticator configured).");
810 return -1;
811 }
812
813 if (bss->wpa) {
814 int wep, i;
815
816 wep = bss->default_wep_key_len > 0 ||
817 bss->individual_wep_key_len > 0;
818 for (i = 0; i < NUM_WEP_KEYS; i++) {
819 if (bss->ssid.wep.keys_set) {
820 wep = 1;
821 break;
822 }
823 }
824
825 if (wep) {
826 wpa_printf(MSG_ERROR, "WEP configuration in a WPA network is not supported");
827 return -1;
828 }
829 }
830
Dmitry Shmidt344abd32014-01-14 13:17:00 -0800831 if (full_config && bss->wpa &&
832 bss->wpa_psk_radius != PSK_RADIUS_IGNORED &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800833 bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH) {
834 wpa_printf(MSG_ERROR, "WPA-PSK using RADIUS enabled, but no "
835 "RADIUS checking (macaddr_acl=2) enabled.");
836 return -1;
837 }
838
Dmitry Shmidt344abd32014-01-14 13:17:00 -0800839 if (full_config && bss->wpa && (bss->wpa_key_mgmt & WPA_KEY_MGMT_PSK) &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800840 bss->ssid.wpa_psk == NULL && bss->ssid.wpa_passphrase == NULL &&
841 bss->ssid.wpa_psk_file == NULL &&
842 (bss->wpa_psk_radius != PSK_RADIUS_REQUIRED ||
843 bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH)) {
844 wpa_printf(MSG_ERROR, "WPA-PSK enabled, but PSK or passphrase "
845 "is not configured.");
846 return -1;
847 }
848
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800849 if (full_config && !is_zero_ether_addr(bss->bssid)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800850 size_t i;
851
852 for (i = 0; i < conf->num_bss; i++) {
853 if (conf->bss[i] != bss &&
854 (hostapd_mac_comp(conf->bss[i]->bssid,
855 bss->bssid) == 0)) {
856 wpa_printf(MSG_ERROR, "Duplicate BSSID " MACSTR
857 " on interface '%s' and '%s'.",
858 MAC2STR(bss->bssid),
859 conf->bss[i]->iface, bss->iface);
860 return -1;
861 }
862 }
863 }
864
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800865#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt344abd32014-01-14 13:17:00 -0800866 if (full_config && wpa_key_mgmt_ft(bss->wpa_key_mgmt) &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800867 (bss->nas_identifier == NULL ||
868 os_strlen(bss->nas_identifier) < 1 ||
869 os_strlen(bss->nas_identifier) > FT_R0KH_ID_MAX_LEN)) {
870 wpa_printf(MSG_ERROR, "FT (IEEE 802.11r) requires "
871 "nas_identifier to be configured as a 1..48 octet "
872 "string");
873 return -1;
874 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800875#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800876
877#ifdef CONFIG_IEEE80211N
Dmitry Shmidt344abd32014-01-14 13:17:00 -0800878 if (full_config && conf->ieee80211n &&
879 conf->hw_mode == HOSTAPD_MODE_IEEE80211B) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800880 bss->disable_11n = 1;
881 wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) in 11b mode is not "
Dmitry Shmidt661b4f72014-09-29 14:58:27 -0700882 "allowed, disabling HT capabilities");
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800883 }
884
Dmitry Shmidt344abd32014-01-14 13:17:00 -0800885 if (full_config && conf->ieee80211n &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800886 bss->ssid.security_policy == SECURITY_STATIC_WEP) {
887 bss->disable_11n = 1;
888 wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) with WEP is not "
889 "allowed, disabling HT capabilities");
890 }
891
Dmitry Shmidt344abd32014-01-14 13:17:00 -0800892 if (full_config && conf->ieee80211n && bss->wpa &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800893 !(bss->wpa_pairwise & WPA_CIPHER_CCMP) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800894 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
895 WPA_CIPHER_CCMP_256 | WPA_CIPHER_GCMP_256)))
896 {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800897 bss->disable_11n = 1;
898 wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) with WPA/WPA2 "
899 "requires CCMP/GCMP to be enabled, disabling HT "
900 "capabilities");
901 }
902#endif /* CONFIG_IEEE80211N */
903
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -0700904#ifdef CONFIG_IEEE80211AC
905 if (full_config && conf->ieee80211ac &&
906 bss->ssid.security_policy == SECURITY_STATIC_WEP) {
907 bss->disable_11ac = 1;
908 wpa_printf(MSG_ERROR,
909 "VHT (IEEE 802.11ac) with WEP is not allowed, disabling VHT capabilities");
910 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800911
912 if (full_config && conf->ieee80211ac && bss->wpa &&
913 !(bss->wpa_pairwise & WPA_CIPHER_CCMP) &&
914 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
915 WPA_CIPHER_CCMP_256 | WPA_CIPHER_GCMP_256)))
916 {
917 bss->disable_11ac = 1;
918 wpa_printf(MSG_ERROR,
919 "VHT (IEEE 802.11ac) with WPA/WPA2 requires CCMP/GCMP to be enabled, disabling VHT capabilities");
920 }
Dmitry Shmidt7f2c7532016-08-15 09:48:12 -0700921#endif /* CONFIG_IEEE80211AC */
922
Dmitry Shmidt15907092014-03-25 10:42:57 -0700923#ifdef CONFIG_WPS
Dmitry Shmidt344abd32014-01-14 13:17:00 -0800924 if (full_config && bss->wps_state && bss->ignore_broadcast_ssid) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800925 wpa_printf(MSG_INFO, "WPS: ignore_broadcast_ssid "
926 "configuration forced WPS to be disabled");
927 bss->wps_state = 0;
928 }
929
Dmitry Shmidt344abd32014-01-14 13:17:00 -0800930 if (full_config && bss->wps_state &&
931 bss->ssid.wep.keys_set && bss->wpa == 0) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800932 wpa_printf(MSG_INFO, "WPS: WEP configuration forced WPS to be "
933 "disabled");
934 bss->wps_state = 0;
935 }
936
Dmitry Shmidt344abd32014-01-14 13:17:00 -0800937 if (full_config && bss->wps_state && bss->wpa &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800938 (!(bss->wpa & 2) ||
Dmitry Shmidt1d755d02015-04-28 10:34:29 -0700939 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP)))) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800940 wpa_printf(MSG_INFO, "WPS: WPA/TKIP configuration without "
Dmitry Shmidt1d755d02015-04-28 10:34:29 -0700941 "WPA2/CCMP/GCMP forced WPS to be disabled");
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800942 bss->wps_state = 0;
943 }
Dmitry Shmidt15907092014-03-25 10:42:57 -0700944#endif /* CONFIG_WPS */
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800945
946#ifdef CONFIG_HS20
Dmitry Shmidt344abd32014-01-14 13:17:00 -0800947 if (full_config && bss->hs20 &&
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800948 (!(bss->wpa & 2) ||
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800949 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
950 WPA_CIPHER_CCMP_256 |
951 WPA_CIPHER_GCMP_256)))) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800952 wpa_printf(MSG_ERROR, "HS 2.0: WPA2-Enterprise/CCMP "
953 "configuration is required for Hotspot 2.0 "
954 "functionality");
955 return -1;
956 }
957#endif /* CONFIG_HS20 */
958
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800959#ifdef CONFIG_MBO
960 if (full_config && bss->mbo_enabled && (bss->wpa & 2) &&
961 bss->ieee80211w == NO_MGMT_FRAME_PROTECTION) {
962 wpa_printf(MSG_ERROR,
963 "MBO: PMF needs to be enabled whenever using WPA2 with MBO");
964 return -1;
965 }
966#endif /* CONFIG_MBO */
967
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800968 return 0;
969}
970
971
Dmitry Shmidt05df46a2015-05-19 11:02:01 -0700972static int hostapd_config_check_cw(struct hostapd_config *conf, int queue)
973{
974 int tx_cwmin = conf->tx_queue[queue].cwmin;
975 int tx_cwmax = conf->tx_queue[queue].cwmax;
976 int ac_cwmin = conf->wmm_ac_params[queue].cwmin;
977 int ac_cwmax = conf->wmm_ac_params[queue].cwmax;
978
979 if (tx_cwmin > tx_cwmax) {
980 wpa_printf(MSG_ERROR,
981 "Invalid TX queue cwMin/cwMax values. cwMin(%d) greater than cwMax(%d)",
982 tx_cwmin, tx_cwmax);
983 return -1;
984 }
985 if (ac_cwmin > ac_cwmax) {
986 wpa_printf(MSG_ERROR,
987 "Invalid WMM AC cwMin/cwMax values. cwMin(%d) greater than cwMax(%d)",
988 ac_cwmin, ac_cwmax);
989 return -1;
990 }
991 return 0;
992}
993
994
Dmitry Shmidt344abd32014-01-14 13:17:00 -0800995int hostapd_config_check(struct hostapd_config *conf, int full_config)
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800996{
997 size_t i;
998
Dmitry Shmidt344abd32014-01-14 13:17:00 -0800999 if (full_config && conf->ieee80211d &&
1000 (!conf->country[0] || !conf->country[1])) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001001 wpa_printf(MSG_ERROR, "Cannot enable IEEE 802.11d without "
1002 "setting the country_code");
1003 return -1;
1004 }
1005
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001006 if (full_config && conf->ieee80211h && !conf->ieee80211d) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001007 wpa_printf(MSG_ERROR, "Cannot enable IEEE 802.11h without "
1008 "IEEE 802.11d enabled");
1009 return -1;
1010 }
1011
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001012 if (full_config && conf->local_pwr_constraint != -1 &&
1013 !conf->ieee80211d) {
1014 wpa_printf(MSG_ERROR, "Cannot add Power Constraint element without Country element");
1015 return -1;
1016 }
1017
1018 if (full_config && conf->spectrum_mgmt_required &&
1019 conf->local_pwr_constraint == -1) {
1020 wpa_printf(MSG_ERROR, "Cannot set Spectrum Management bit without Country and Power Constraint elements");
1021 return -1;
1022 }
1023
Dmitry Shmidt05df46a2015-05-19 11:02:01 -07001024 for (i = 0; i < NUM_TX_QUEUES; i++) {
1025 if (hostapd_config_check_cw(conf, i))
1026 return -1;
1027 }
1028
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001029 for (i = 0; i < conf->num_bss; i++) {
Dmitry Shmidt344abd32014-01-14 13:17:00 -08001030 if (hostapd_config_check_bss(conf->bss[i], conf, full_config))
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001031 return -1;
1032 }
1033
1034 return 0;
1035}
1036
1037
Dmitry Shmidt71757432014-06-02 13:50:35 -07001038void hostapd_set_security_params(struct hostapd_bss_config *bss,
1039 int full_config)
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001040{
1041 if (bss->individual_wep_key_len == 0) {
1042 /* individual keys are not use; can use key idx0 for
1043 * broadcast keys */
1044 bss->broadcast_key_idx_min = 0;
1045 }
1046
1047 if ((bss->wpa & 2) && bss->rsn_pairwise == 0)
1048 bss->rsn_pairwise = bss->wpa_pairwise;
1049 bss->wpa_group = wpa_select_ap_group_cipher(bss->wpa, bss->wpa_pairwise,
1050 bss->rsn_pairwise);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001051 if (!bss->wpa_group_rekey_set)
1052 bss->wpa_group_rekey = bss->wpa_group == WPA_CIPHER_TKIP ?
1053 600 : 86400;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001054
Dmitry Shmidt71757432014-06-02 13:50:35 -07001055 if (full_config) {
1056 bss->radius->auth_server = bss->radius->auth_servers;
1057 bss->radius->acct_server = bss->radius->acct_servers;
1058 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001059
1060 if (bss->wpa && bss->ieee802_1x) {
1061 bss->ssid.security_policy = SECURITY_WPA;
1062 } else if (bss->wpa) {
1063 bss->ssid.security_policy = SECURITY_WPA_PSK;
1064 } else if (bss->ieee802_1x) {
1065 int cipher = WPA_CIPHER_NONE;
1066 bss->ssid.security_policy = SECURITY_IEEE_802_1X;
1067 bss->ssid.wep.default_len = bss->default_wep_key_len;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001068 if (full_config && bss->default_wep_key_len) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001069 cipher = bss->default_wep_key_len >= 13 ?
1070 WPA_CIPHER_WEP104 : WPA_CIPHER_WEP40;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001071 } else if (full_config && bss->ssid.wep.keys_set) {
1072 if (bss->ssid.wep.len[0] >= 13)
1073 cipher = WPA_CIPHER_WEP104;
1074 else
1075 cipher = WPA_CIPHER_WEP40;
1076 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001077 bss->wpa_group = cipher;
1078 bss->wpa_pairwise = cipher;
1079 bss->rsn_pairwise = cipher;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001080 if (full_config)
1081 bss->wpa_key_mgmt = WPA_KEY_MGMT_IEEE8021X_NO_WPA;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001082 } else if (bss->ssid.wep.keys_set) {
1083 int cipher = WPA_CIPHER_WEP40;
1084 if (bss->ssid.wep.len[0] >= 13)
1085 cipher = WPA_CIPHER_WEP104;
1086 bss->ssid.security_policy = SECURITY_STATIC_WEP;
1087 bss->wpa_group = cipher;
1088 bss->wpa_pairwise = cipher;
1089 bss->rsn_pairwise = cipher;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001090 if (full_config)
1091 bss->wpa_key_mgmt = WPA_KEY_MGMT_NONE;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001092 } else if (bss->osen) {
1093 bss->ssid.security_policy = SECURITY_OSEN;
1094 bss->wpa_group = WPA_CIPHER_CCMP;
1095 bss->wpa_pairwise = 0;
1096 bss->rsn_pairwise = WPA_CIPHER_CCMP;
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001097 } else {
1098 bss->ssid.security_policy = SECURITY_PLAINTEXT;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001099 if (full_config) {
1100 bss->wpa_group = WPA_CIPHER_NONE;
1101 bss->wpa_pairwise = WPA_CIPHER_NONE;
1102 bss->rsn_pairwise = WPA_CIPHER_NONE;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001103 bss->wpa_key_mgmt = WPA_KEY_MGMT_NONE;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001104 }
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001105 }
1106}