]> git.ipfire.org Git - thirdparty/hostap.git/blame - src/ap/ap_config.c
MBO: Add MBO ANQP-element processing on AP
[thirdparty/hostap.git] / src / ap / ap_config.c
CommitLineData
6fc6879b 1/*
41d719d6 2 * hostapd / Configuration helper functions
08081ad8 3 * Copyright (c) 2003-2014, Jouni Malinen <j@w1.fi>
6fc6879b 4 *
0f3d578e
JM
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
6fc6879b
JM
7 */
8
6226e38d 9#include "utils/includes.h"
6fc6879b 10
6226e38d 11#include "utils/common.h"
03da66bd 12#include "crypto/sha1.h"
6fc6879b 13#include "radius/radius_client.h"
df84268a 14#include "common/ieee802_11_defs.h"
41d719d6 15#include "common/eapol_common.h"
91d91abf 16#include "common/dhcp.h"
03da66bd
JM
17#include "eap_common/eap_wsc_common.h"
18#include "eap_server/eap.h"
6226e38d 19#include "wpa_auth.h"
97234b50 20#include "sta_info.h"
6226e38d 21#include "ap_config.h"
6fc6879b
JM
22
23
6fc6879b
JM
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
41d719d6 40void hostapd_config_defaults_bss(struct hostapd_bss_config *bss)
6fc6879b 41{
695dbbea
JM
42 dl_list_init(&bss->anqp_elem);
43
6fc6879b
JM
44 bss->logger_syslog_level = HOSTAPD_LEVEL_INFO;
45 bss->logger_stdout_level = HOSTAPD_LEVEL_INFO;
46 bss->logger_syslog = (unsigned int) -1;
47 bss->logger_stdout = (unsigned int) -1;
48
49 bss->auth_algs = WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED;
50
51 bss->wep_rekeying_period = 300;
52 /* use key0 in individual key and key1 in broadcast key */
53 bss->broadcast_key_idx_min = 1;
54 bss->broadcast_key_idx_max = 2;
55 bss->eap_reauth_period = 3600;
56
57 bss->wpa_group_rekey = 600;
58 bss->wpa_gmk_rekey = 86400;
41f140d3
GK
59 bss->wpa_group_update_count = 4;
60 bss->wpa_pairwise_update_count = 4;
6fc6879b
JM
61 bss->wpa_key_mgmt = WPA_KEY_MGMT_PSK;
62 bss->wpa_pairwise = WPA_CIPHER_TKIP;
63 bss->wpa_group = WPA_CIPHER_TKIP;
64 bss->rsn_pairwise = 0;
65
66 bss->max_num_sta = MAX_STA_COUNT;
67
68 bss->dtim_period = 2;
69
70 bss->radius_server_auth_port = 1812;
7b0f5500 71 bss->eap_sim_db_timeout = 1;
6fc6879b
JM
72 bss->ap_max_inactivity = AP_MAX_INACTIVITY;
73 bss->eapol_version = EAPOL_VERSION;
b0194fe0
JM
74
75 bss->max_listen_interval = 65535;
5d22a1d5 76
df684d82
DH
77 bss->pwd_group = 19; /* ECC: GF(p=256) */
78
5d22a1d5 79#ifdef CONFIG_IEEE80211W
45c94154
JM
80 bss->assoc_sa_query_max_timeout = 1000;
81 bss->assoc_sa_query_retry_timeout = 201;
8dd9f9cd 82 bss->group_mgmt_cipher = WPA_CIPHER_AES_128_CMAC;
5d22a1d5 83#endif /* CONFIG_IEEE80211W */
1e5839e0 84#ifdef EAP_SERVER_FAST
378eae5e
JM
85 /* both anonymous and authenticated provisioning */
86 bss->eap_fast_prov = 3;
a11c90a6
JM
87 bss->pac_key_lifetime = 7 * 24 * 60 * 60;
88 bss->pac_key_refresh_time = 1 * 24 * 60 * 60;
1e5839e0 89#endif /* EAP_SERVER_FAST */
d2da2249
JB
90
91 /* Set to -1 as defaults depends on HT in setup */
92 bss->wmm_enabled = -1;
d7956add 93
4ec1fd8e 94#ifdef CONFIG_IEEE80211R_AP
d7956add 95 bss->ft_over_ds = 1;
4ec1fd8e 96#endif /* CONFIG_IEEE80211R_AP */
bde7ba6c
JM
97
98 bss->radius_das_time_window = 300;
d136c376
JM
99
100 bss->sae_anti_clogging_threshold = 5;
26bf70e3 101
2977f519
JM
102 bss->gas_frag_limit = 1400;
103
26bf70e3
JM
104#ifdef CONFIG_FILS
105 dl_list_init(&bss->fils_realms);
91d91abf
JM
106 bss->fils_hlp_wait_time = 30;
107 bss->dhcp_server_port = DHCP_SERVER_PORT;
108 bss->dhcp_relay_port = DHCP_SERVER_PORT;
26bf70e3 109#endif /* CONFIG_FILS */
57a2aaca
JM
110
111 bss->broadcast_deauth = 1;
941caed9
JM
112
113#ifdef CONFIG_MBO
114 bss->mbo_cell_data_conn_pref = -1;
115#endif /* CONFIG_MBO */
6fc6879b
JM
116}
117
118
89111f3b 119struct hostapd_config * hostapd_config_defaults(void)
6fc6879b 120{
d2da2249
JB
121#define ecw2cw(ecw) ((1 << (ecw)) - 1)
122
6fc6879b
JM
123 struct hostapd_config *conf;
124 struct hostapd_bss_config *bss;
594cf8b9 125 const int aCWmin = 4, aCWmax = 10;
3ae0800c 126 const struct hostapd_wmm_ac_params ac_bk =
6fc6879b 127 { aCWmin, aCWmax, 7, 0, 0 }; /* background traffic */
3ae0800c 128 const struct hostapd_wmm_ac_params ac_be =
6fc6879b 129 { aCWmin, aCWmax, 3, 0, 0 }; /* best effort traffic */
3ae0800c 130 const struct hostapd_wmm_ac_params ac_vi = /* video traffic */
f4e3860f 131 { aCWmin - 1, aCWmin, 2, 3008 / 32, 0 };
3ae0800c 132 const struct hostapd_wmm_ac_params ac_vo = /* voice traffic */
f4e3860f 133 { aCWmin - 2, aCWmin - 1, 2, 1504 / 32, 0 };
d2da2249
JB
134 const struct hostapd_tx_queue_params txq_bk =
135 { 7, ecw2cw(aCWmin), ecw2cw(aCWmax), 0 };
136 const struct hostapd_tx_queue_params txq_be =
137 { 3, ecw2cw(aCWmin), 4 * (ecw2cw(aCWmin) + 1) - 1, 0};
138 const struct hostapd_tx_queue_params txq_vi =
139 { 1, (ecw2cw(aCWmin) + 1) / 2 - 1, ecw2cw(aCWmin), 30};
140 const struct hostapd_tx_queue_params txq_vo =
141 { 1, (ecw2cw(aCWmin) + 1) / 4 - 1,
142 (ecw2cw(aCWmin) + 1) / 2 - 1, 15};
143
144#undef ecw2cw
6fc6879b
JM
145
146 conf = os_zalloc(sizeof(*conf));
147 bss = os_zalloc(sizeof(*bss));
148 if (conf == NULL || bss == NULL) {
10656fc2
JM
149 wpa_printf(MSG_ERROR, "Failed to allocate memory for "
150 "configuration data.");
6fc6879b
JM
151 os_free(conf);
152 os_free(bss);
153 return NULL;
154 }
ebd79f07
JM
155 conf->bss = os_calloc(1, sizeof(struct hostapd_bss_config *));
156 if (conf->bss == NULL) {
157 os_free(conf);
158 os_free(bss);
159 return NULL;
160 }
161 conf->bss[0] = bss;
6fc6879b 162
6fc6879b
JM
163 bss->radius = os_zalloc(sizeof(*bss->radius));
164 if (bss->radius == NULL) {
04c366cb 165 os_free(conf->bss);
6fc6879b
JM
166 os_free(conf);
167 os_free(bss);
168 return NULL;
169 }
170
171 hostapd_config_defaults_bss(bss);
172
173 conf->num_bss = 1;
6fc6879b
JM
174
175 conf->beacon_int = 100;
176 conf->rts_threshold = -1; /* use driver default: 2347 */
177 conf->fragm_threshold = -1; /* user driver default: 2346 */
178 conf->send_probe_response = 1;
e0392f82
S
179 /* Set to invalid value means do not add Power Constraint IE */
180 conf->local_pwr_constraint = -1;
6fc6879b 181
3ae0800c
JM
182 conf->wmm_ac_params[0] = ac_be;
183 conf->wmm_ac_params[1] = ac_bk;
184 conf->wmm_ac_params[2] = ac_vi;
185 conf->wmm_ac_params[3] = ac_vo;
6fc6879b 186
d2da2249
JB
187 conf->tx_queue[0] = txq_vo;
188 conf->tx_queue[1] = txq_vi;
189 conf->tx_queue[2] = txq_be;
190 conf->tx_queue[3] = txq_bk;
191
fc14f567 192 conf->ht_capab = HT_CAP_INFO_SMPS_DISABLED;
de9289c8 193
f1b44874
SE
194 conf->ap_table_max_size = 255;
195 conf->ap_table_expiration_time = 60;
a65a9b8d 196 conf->track_sta_max_age = 180;
f1b44874 197
c2aff6b1 198#ifdef CONFIG_TESTING_OPTIONS
06df2aa6
JM
199 conf->ignore_probe_probability = 0.0;
200 conf->ignore_auth_probability = 0.0;
201 conf->ignore_assoc_probability = 0.0;
202 conf->ignore_reassoc_probability = 0.0;
203 conf->corrupt_gtk_rekey_mic_probability = 0.0;
2b6e1216 204 conf->ecsa_ie_only = 0;
c2aff6b1
JB
205#endif /* CONFIG_TESTING_OPTIONS */
206
857d9422
MM
207 conf->acs = 0;
208 conf->acs_ch_list.num = 0;
50f4f2a0
MK
209#ifdef CONFIG_ACS
210 conf->acs_num_scans = 5;
211#endif /* CONFIG_ACS */
212
ff936bc7
JM
213 /* The third octet of the country string uses an ASCII space character
214 * by default to indicate that the regulations encompass all
215 * environments for the current frequency band in the country. */
216 conf->country[2] = ' ';
217
6fc6879b
JM
218 return conf;
219}
220
221
222int hostapd_mac_comp(const void *a, const void *b)
223{
224 return os_memcmp(a, b, sizeof(macaddr));
225}
226
227
6fc6879b
JM
228static int hostapd_config_read_wpa_psk(const char *fname,
229 struct hostapd_ssid *ssid)
230{
231 FILE *f;
232 char buf[128], *pos;
233 int line = 0, ret = 0, len, ok;
234 u8 addr[ETH_ALEN];
235 struct hostapd_wpa_psk *psk;
236
237 if (!fname)
238 return 0;
239
240 f = fopen(fname, "r");
241 if (!f) {
10656fc2 242 wpa_printf(MSG_ERROR, "WPA PSK file '%s' not found.", fname);
6fc6879b
JM
243 return -1;
244 }
245
246 while (fgets(buf, sizeof(buf), f)) {
247 line++;
248
249 if (buf[0] == '#')
250 continue;
251 pos = buf;
252 while (*pos != '\0') {
253 if (*pos == '\n') {
254 *pos = '\0';
255 break;
256 }
257 pos++;
258 }
259 if (buf[0] == '\0')
260 continue;
261
262 if (hwaddr_aton(buf, addr)) {
10656fc2
JM
263 wpa_printf(MSG_ERROR, "Invalid MAC address '%s' on "
264 "line %d in '%s'", buf, line, fname);
6fc6879b
JM
265 ret = -1;
266 break;
267 }
268
269 psk = os_zalloc(sizeof(*psk));
270 if (psk == NULL) {
10656fc2 271 wpa_printf(MSG_ERROR, "WPA PSK allocation failed");
6fc6879b
JM
272 ret = -1;
273 break;
274 }
a8e16edc 275 if (is_zero_ether_addr(addr))
6fc6879b
JM
276 psk->group = 1;
277 else
278 os_memcpy(psk->addr, addr, ETH_ALEN);
279
280 pos = buf + 17;
5306f43f 281 if (*pos == '\0') {
10656fc2
JM
282 wpa_printf(MSG_ERROR, "No PSK on line %d in '%s'",
283 line, fname);
6fc6879b
JM
284 os_free(psk);
285 ret = -1;
286 break;
287 }
288 pos++;
289
290 ok = 0;
291 len = os_strlen(pos);
292 if (len == 64 && hexstr2bin(pos, psk->psk, PMK_LEN) == 0)
293 ok = 1;
294 else if (len >= 8 && len < 64) {
295 pbkdf2_sha1(pos, ssid->ssid, ssid->ssid_len,
296 4096, psk->psk, PMK_LEN);
297 ok = 1;
298 }
299 if (!ok) {
10656fc2
JM
300 wpa_printf(MSG_ERROR, "Invalid PSK '%s' on line %d in "
301 "'%s'", pos, line, fname);
6fc6879b
JM
302 os_free(psk);
303 ret = -1;
304 break;
305 }
306
307 psk->next = ssid->wpa_psk;
308 ssid->wpa_psk = psk;
309 }
310
311 fclose(f);
312
313 return ret;
314}
315
316
0ae687bd
JM
317static int hostapd_derive_psk(struct hostapd_ssid *ssid)
318{
319 ssid->wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
320 if (ssid->wpa_psk == NULL) {
321 wpa_printf(MSG_ERROR, "Unable to alloc space for PSK");
322 return -1;
323 }
324 wpa_hexdump_ascii(MSG_DEBUG, "SSID",
325 (u8 *) ssid->ssid, ssid->ssid_len);
326 wpa_hexdump_ascii_key(MSG_DEBUG, "PSK (ASCII passphrase)",
327 (u8 *) ssid->wpa_passphrase,
328 os_strlen(ssid->wpa_passphrase));
329 pbkdf2_sha1(ssid->wpa_passphrase,
330 ssid->ssid, ssid->ssid_len,
331 4096, ssid->wpa_psk->psk, PMK_LEN);
332 wpa_hexdump_key(MSG_DEBUG, "PSK (from passphrase)",
333 ssid->wpa_psk->psk, PMK_LEN);
334 return 0;
335}
336
337
6fc6879b
JM
338int hostapd_setup_wpa_psk(struct hostapd_bss_config *conf)
339{
340 struct hostapd_ssid *ssid = &conf->ssid;
341
342 if (ssid->wpa_passphrase != NULL) {
343 if (ssid->wpa_psk != NULL) {
0ae687bd
JM
344 wpa_printf(MSG_DEBUG, "Using pre-configured WPA PSK "
345 "instead of passphrase");
346 } else {
347 wpa_printf(MSG_DEBUG, "Deriving WPA PSK based on "
348 "passphrase");
349 if (hostapd_derive_psk(ssid) < 0)
350 return -1;
6fc6879b 351 }
6fc6879b 352 ssid->wpa_psk->group = 1;
6fc6879b
JM
353 }
354
34e29dfd 355 return hostapd_config_read_wpa_psk(ssid->wpa_psk_file, &conf->ssid);
6fc6879b
JM
356}
357
358
6fc6879b
JM
359static void hostapd_config_free_radius(struct hostapd_radius_server *servers,
360 int num_servers)
361{
362 int i;
363
364 for (i = 0; i < num_servers; i++) {
365 os_free(servers[i].shared_secret);
366 }
367 os_free(servers);
368}
369
370
af35e7af
JM
371struct hostapd_radius_attr *
372hostapd_config_get_radius_attr(struct hostapd_radius_attr *attr, u8 type)
373{
374 for (; attr; attr = attr->next) {
375 if (attr->type == type)
376 return attr;
377 }
378 return NULL;
379}
380
381
382static void hostapd_config_free_radius_attr(struct hostapd_radius_attr *attr)
383{
384 struct hostapd_radius_attr *prev;
385
386 while (attr) {
387 prev = attr;
388 attr = attr->next;
389 wpabuf_free(prev->val);
390 os_free(prev);
391 }
392}
393
394
d0ee16ed 395void hostapd_config_free_eap_user(struct hostapd_eap_user *user)
6fc6879b 396{
d0ee16ed 397 hostapd_config_free_radius_attr(user->accept_attr);
6fc6879b 398 os_free(user->identity);
b7175b4d 399 bin_clear_free(user->password, user->password_len);
6fc6879b
JM
400 os_free(user);
401}
402
403
78022c83
JM
404void hostapd_config_free_eap_users(struct hostapd_eap_user *user)
405{
406 struct hostapd_eap_user *prev_user;
407
408 while (user) {
409 prev_user = user;
410 user = user->next;
411 hostapd_config_free_eap_user(prev_user);
412 }
413}
414
415
6fc6879b
JM
416static void hostapd_config_free_wep(struct hostapd_wep_keys *keys)
417{
418 int i;
419 for (i = 0; i < NUM_WEP_KEYS; i++) {
b7175b4d 420 bin_clear_free(keys->key[i], keys->len[i]);
6fc6879b
JM
421 keys->key[i] = NULL;
422 }
423}
424
425
891dfb33
ST
426void hostapd_config_clear_wpa_psk(struct hostapd_wpa_psk **l)
427{
428 struct hostapd_wpa_psk *psk, *tmp;
429
430 for (psk = *l; psk;) {
431 tmp = psk;
432 psk = psk->next;
433 bin_clear_free(tmp, sizeof(*tmp));
434 }
435 *l = NULL;
436}
437
438
695dbbea
JM
439static void hostapd_config_free_anqp_elem(struct hostapd_bss_config *conf)
440{
441 struct anqp_element *elem;
442
443 while ((elem = dl_list_first(&conf->anqp_elem, struct anqp_element,
444 list))) {
445 dl_list_del(&elem->list);
446 wpabuf_free(elem->payload);
447 os_free(elem);
448 }
449}
450
451
26bf70e3
JM
452static void hostapd_config_free_fils_realms(struct hostapd_bss_config *conf)
453{
454#ifdef CONFIG_FILS
455 struct fils_realm *realm;
456
457 while ((realm = dl_list_first(&conf->fils_realms, struct fils_realm,
458 list))) {
459 dl_list_del(&realm->list);
460 os_free(realm);
461 }
462#endif /* CONFIG_FILS */
463}
464
465
55920658 466void hostapd_config_free_bss(struct hostapd_bss_config *conf)
6fc6879b 467{
6fc6879b
JM
468 if (conf == NULL)
469 return;
470
891dfb33 471 hostapd_config_clear_wpa_psk(&conf->ssid.wpa_psk);
6fc6879b 472
b7175b4d 473 str_clear_free(conf->ssid.wpa_passphrase);
6fc6879b 474 os_free(conf->ssid.wpa_psk_file);
43dd46b3 475 hostapd_config_free_wep(&conf->ssid.wep);
6fc6879b
JM
476#ifdef CONFIG_FULL_DYNAMIC_VLAN
477 os_free(conf->ssid.vlan_tagged_interface);
478#endif /* CONFIG_FULL_DYNAMIC_VLAN */
479
78022c83 480 hostapd_config_free_eap_users(conf->eap_user);
ee431d77 481 os_free(conf->eap_user_sqlite);
6fc6879b 482
6fc6879b 483 os_free(conf->eap_req_id_text);
2a5156a6 484 os_free(conf->erp_domain);
6fc6879b
JM
485 os_free(conf->accept_mac);
486 os_free(conf->deny_mac);
487 os_free(conf->nas_identifier);
5afaa067
JM
488 if (conf->radius) {
489 hostapd_config_free_radius(conf->radius->auth_servers,
490 conf->radius->num_auth_servers);
491 hostapd_config_free_radius(conf->radius->acct_servers,
492 conf->radius->num_acct_servers);
493 }
af35e7af
JM
494 hostapd_config_free_radius_attr(conf->radius_auth_req_attr);
495 hostapd_config_free_radius_attr(conf->radius_acct_req_attr);
6fc6879b
JM
496 os_free(conf->rsn_preauth_interfaces);
497 os_free(conf->ctrl_interface);
498 os_free(conf->ca_cert);
499 os_free(conf->server_cert);
500 os_free(conf->private_key);
501 os_free(conf->private_key_passwd);
080585c0 502 os_free(conf->ocsp_stapling_response);
5addb0df 503 os_free(conf->ocsp_stapling_response_multi);
6fc6879b 504 os_free(conf->dh_file);
f8995f8f 505 os_free(conf->openssl_ciphers);
6fc6879b
JM
506 os_free(conf->pac_opaque_encr_key);
507 os_free(conf->eap_fast_a_id);
2d867244 508 os_free(conf->eap_fast_a_id_info);
6fc6879b
JM
509 os_free(conf->eap_sim_db);
510 os_free(conf->radius_server_clients);
6fc6879b 511 os_free(conf->radius);
b031338c 512 os_free(conf->radius_das_shared_secret);
6fc6879b 513 hostapd_config_free_vlan(conf);
39b97072
JM
514 os_free(conf->time_zone);
515
4ec1fd8e 516#ifdef CONFIG_IEEE80211R_AP
6fc6879b
JM
517 {
518 struct ft_remote_r0kh *r0kh, *r0kh_prev;
519 struct ft_remote_r1kh *r1kh, *r1kh_prev;
520
521 r0kh = conf->r0kh_list;
522 conf->r0kh_list = NULL;
523 while (r0kh) {
524 r0kh_prev = r0kh;
525 r0kh = r0kh->next;
526 os_free(r0kh_prev);
527 }
528
529 r1kh = conf->r1kh_list;
530 conf->r1kh_list = NULL;
531 while (r1kh) {
532 r1kh_prev = r1kh;
533 r1kh = r1kh->next;
534 os_free(r1kh_prev);
535 }
536 }
4ec1fd8e 537#endif /* CONFIG_IEEE80211R_AP */
ad08c363
JM
538
539#ifdef CONFIG_WPS
540 os_free(conf->wps_pin_requests);
541 os_free(conf->device_name);
542 os_free(conf->manufacturer);
543 os_free(conf->model_name);
544 os_free(conf->model_number);
545 os_free(conf->serial_number);
ad08c363
JM
546 os_free(conf->config_methods);
547 os_free(conf->ap_pin);
62966253 548 os_free(conf->extra_cred);
4c29cae9 549 os_free(conf->ap_settings);
f620268f
JM
550 os_free(conf->upnp_iface);
551 os_free(conf->friendly_name);
552 os_free(conf->manufacturer_url);
553 os_free(conf->model_description);
554 os_free(conf->model_url);
555 os_free(conf->upc);
8509fb5c
JM
556 {
557 unsigned int i;
558
559 for (i = 0; i < MAX_WPS_VENDOR_EXTENSIONS; i++)
560 wpabuf_free(conf->wps_vendor_ext[i]);
561 }
ffdaa05a
JM
562 wpabuf_free(conf->wps_nfc_dh_pubkey);
563 wpabuf_free(conf->wps_nfc_dh_privkey);
564 wpabuf_free(conf->wps_nfc_dev_pw);
ad08c363 565#endif /* CONFIG_WPS */
4b2a77ab
JM
566
567 os_free(conf->roaming_consortium);
648cc711 568 os_free(conf->venue_name);
8047b186 569 os_free(conf->nai_realm_data);
550a3958 570 os_free(conf->network_auth_type);
7515adb2 571 os_free(conf->anqp_3gpp_cell_net);
26fac8b6 572 os_free(conf->domain_name);
695dbbea 573 hostapd_config_free_anqp_elem(conf);
505a3694
JM
574
575#ifdef CONFIG_RADIUS_TEST
576 os_free(conf->dump_msk_file);
577#endif /* CONFIG_RADIUS_TEST */
df5934f1
JK
578
579#ifdef CONFIG_HS20
a9277e85 580 os_free(conf->hs20_oper_friendly_name);
4065a309 581 os_free(conf->hs20_wan_metrics);
5ccc54aa 582 os_free(conf->hs20_connection_capability);
df5934f1 583 os_free(conf->hs20_operating_class);
f7bd7a01 584 os_free(conf->hs20_icons);
ae6d15c7
JM
585 if (conf->hs20_osu_providers) {
586 size_t i;
587 for (i = 0; i < conf->hs20_osu_providers_count; i++) {
588 struct hs20_osu_provider *p;
589 size_t j;
590 p = &conf->hs20_osu_providers[i];
591 os_free(p->friendly_name);
592 os_free(p->server_uri);
593 os_free(p->method_list);
594 for (j = 0; j < p->icons_count; j++)
595 os_free(p->icons[j]);
596 os_free(p->icons);
597 os_free(p->osu_nai);
598 os_free(p->service_desc);
599 }
600 os_free(conf->hs20_osu_providers);
601 }
8d2a9921 602 os_free(conf->subscr_remediation_url);
df5934f1 603#endif /* CONFIG_HS20 */
b52f084c
JM
604
605 wpabuf_free(conf->vendor_elements);
a9112270 606 wpabuf_free(conf->assocresp_elements);
625f202a
JM
607
608 os_free(conf->sae_groups);
67fe933d 609
88cb27c7
DS
610 os_free(conf->wowlan_triggers);
611
67fe933d 612 os_free(conf->server_id);
ebd79f07 613
bc02843e
JM
614#ifdef CONFIG_TESTING_OPTIONS
615 wpabuf_free(conf->own_ie_override);
616#endif /* CONFIG_TESTING_OPTIONS */
617
964f64e2 618 os_free(conf->no_probe_resp_if_seen_on);
0e2412d0 619 os_free(conf->no_auth_if_seen_on);
964f64e2 620
26bf70e3
JM
621 hostapd_config_free_fils_realms(conf);
622
ebd79f07 623 os_free(conf);
6fc6879b
JM
624}
625
626
1c6e69cc
JM
627/**
628 * hostapd_config_free - Free hostapd configuration
629 * @conf: Configuration data from hostapd_config_read().
630 */
6fc6879b
JM
631void hostapd_config_free(struct hostapd_config *conf)
632{
633 size_t i;
634
635 if (conf == NULL)
636 return;
637
638 for (i = 0; i < conf->num_bss; i++)
ebd79f07 639 hostapd_config_free_bss(conf->bss[i]);
6fc6879b 640 os_free(conf->bss);
79d6c85f
JM
641 os_free(conf->supported_rates);
642 os_free(conf->basic_rates);
857d9422 643 os_free(conf->acs_ch_list.range);
0ecff8d7 644 os_free(conf->driver_params);
68fa00c3
JM
645#ifdef CONFIG_ACS
646 os_free(conf->acs_chan_bias);
647#endif /* CONFIG_ACS */
74e982d8
DS
648 wpabuf_free(conf->lci);
649 wpabuf_free(conf->civic);
6fc6879b
JM
650
651 os_free(conf);
652}
653
654
1c6e69cc
JM
655/**
656 * hostapd_maclist_found - Find a MAC address from a list
657 * @list: MAC address list
658 * @num_entries: Number of addresses in the list
659 * @addr: Address to search for
660 * @vlan_id: Buffer for returning VLAN ID or %NULL if not needed
661 * Returns: 1 if address is in the list or 0 if not.
662 *
663 * Perform a binary search for given MAC address from a pre-sorted list.
664 */
271d2830 665int hostapd_maclist_found(struct mac_acl_entry *list, int num_entries,
1889af2e 666 const u8 *addr, struct vlan_description *vlan_id)
6fc6879b
JM
667{
668 int start, end, middle, res;
669
670 start = 0;
671 end = num_entries - 1;
672
673 while (start <= end) {
674 middle = (start + end) / 2;
271d2830
JM
675 res = os_memcmp(list[middle].addr, addr, ETH_ALEN);
676 if (res == 0) {
677 if (vlan_id)
678 *vlan_id = list[middle].vlan_id;
6fc6879b 679 return 1;
271d2830 680 }
6fc6879b
JM
681 if (res < 0)
682 start = middle + 1;
683 else
684 end = middle - 1;
685 }
686
687 return 0;
688}
689
690
691int hostapd_rate_found(int *list, int rate)
692{
693 int i;
694
695 if (list == NULL)
696 return 0;
697
698 for (i = 0; list[i] >= 0; i++)
699 if (list[i] == rate)
700 return 1;
701
702 return 0;
703}
704
705
1889af2e
MB
706int hostapd_vlan_valid(struct hostapd_vlan *vlan,
707 struct vlan_description *vlan_desc)
6fc6879b
JM
708{
709 struct hostapd_vlan *v = vlan;
8e44c192 710 int i;
1889af2e 711
8e44c192 712 if (!vlan_desc->notempty || vlan_desc->untagged < 0 ||
1889af2e
MB
713 vlan_desc->untagged > MAX_VLAN_ID)
714 return 0;
8e44c192
MB
715 for (i = 0; i < MAX_NUM_TAGGED_VLAN; i++) {
716 if (vlan_desc->tagged[i] < 0 ||
717 vlan_desc->tagged[i] > MAX_VLAN_ID)
718 return 0;
719 }
720 if (!vlan_desc->untagged && !vlan_desc->tagged[0])
721 return 0;
1889af2e 722
6fc6879b 723 while (v) {
1889af2e
MB
724 if (!vlan_compare(&v->vlan_desc, vlan_desc) ||
725 v->vlan_id == VLAN_ID_WILDCARD)
80ebfd95
MB
726 return 1;
727 v = v->next;
728 }
729 return 0;
730}
731
732
733const char * hostapd_get_vlan_id_ifname(struct hostapd_vlan *vlan, int vlan_id)
734{
735 struct hostapd_vlan *v = vlan;
736 while (v) {
737 if (v->vlan_id == vlan_id)
6fc6879b
JM
738 return v->ifname;
739 v = v->next;
740 }
741 return NULL;
742}
743
744
745const u8 * hostapd_get_psk(const struct hostapd_bss_config *conf,
759fd76b
JM
746 const u8 *addr, const u8 *p2p_dev_addr,
747 const u8 *prev_psk)
6fc6879b
JM
748{
749 struct hostapd_wpa_psk *psk;
750 int next_ok = prev_psk == NULL;
751
dc87541e 752 if (p2p_dev_addr && !is_zero_ether_addr(p2p_dev_addr)) {
759fd76b
JM
753 wpa_printf(MSG_DEBUG, "Searching a PSK for " MACSTR
754 " p2p_dev_addr=" MACSTR " prev_psk=%p",
755 MAC2STR(addr), MAC2STR(p2p_dev_addr), prev_psk);
dc87541e 756 addr = NULL; /* Use P2P Device Address for matching */
759fd76b
JM
757 } else {
758 wpa_printf(MSG_DEBUG, "Searching a PSK for " MACSTR
759 " prev_psk=%p",
760 MAC2STR(addr), prev_psk);
761 }
762
6fc6879b
JM
763 for (psk = conf->ssid.wpa_psk; psk != NULL; psk = psk->next) {
764 if (next_ok &&
759fd76b
JM
765 (psk->group ||
766 (addr && os_memcmp(psk->addr, addr, ETH_ALEN) == 0) ||
767 (!addr && p2p_dev_addr &&
768 os_memcmp(psk->p2p_dev_addr, p2p_dev_addr, ETH_ALEN) ==
769 0)))
6fc6879b
JM
770 return psk->psk;
771
772 if (psk->psk == prev_psk)
773 next_ok = 1;
774 }
775
776 return NULL;
777}
eff0fd1e
JM
778
779
780static int hostapd_config_check_bss(struct hostapd_bss_config *bss,
08081ad8
JM
781 struct hostapd_config *conf,
782 int full_config)
eff0fd1e 783{
08081ad8 784 if (full_config && bss->ieee802_1x && !bss->eap_server &&
eff0fd1e
JM
785 !bss->radius->auth_servers) {
786 wpa_printf(MSG_ERROR, "Invalid IEEE 802.1X configuration (no "
787 "EAP authenticator configured).");
788 return -1;
789 }
790
791 if (bss->wpa) {
792 int wep, i;
793
794 wep = bss->default_wep_key_len > 0 ||
795 bss->individual_wep_key_len > 0;
796 for (i = 0; i < NUM_WEP_KEYS; i++) {
797 if (bss->ssid.wep.keys_set) {
798 wep = 1;
799 break;
800 }
801 }
802
803 if (wep) {
804 wpa_printf(MSG_ERROR, "WEP configuration in a WPA network is not supported");
805 return -1;
806 }
807 }
808
08081ad8
JM
809 if (full_config && bss->wpa &&
810 bss->wpa_psk_radius != PSK_RADIUS_IGNORED &&
eff0fd1e
JM
811 bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH) {
812 wpa_printf(MSG_ERROR, "WPA-PSK using RADIUS enabled, but no "
813 "RADIUS checking (macaddr_acl=2) enabled.");
814 return -1;
815 }
816
08081ad8 817 if (full_config && bss->wpa && (bss->wpa_key_mgmt & WPA_KEY_MGMT_PSK) &&
eff0fd1e
JM
818 bss->ssid.wpa_psk == NULL && bss->ssid.wpa_passphrase == NULL &&
819 bss->ssid.wpa_psk_file == NULL &&
820 (bss->wpa_psk_radius != PSK_RADIUS_REQUIRED ||
821 bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH)) {
822 wpa_printf(MSG_ERROR, "WPA-PSK enabled, but PSK or passphrase "
823 "is not configured.");
824 return -1;
825 }
826
902c07a7 827 if (full_config && !is_zero_ether_addr(bss->bssid)) {
eff0fd1e
JM
828 size_t i;
829
830 for (i = 0; i < conf->num_bss; i++) {
831 if (conf->bss[i] != bss &&
832 (hostapd_mac_comp(conf->bss[i]->bssid,
833 bss->bssid) == 0)) {
834 wpa_printf(MSG_ERROR, "Duplicate BSSID " MACSTR
835 " on interface '%s' and '%s'.",
836 MAC2STR(bss->bssid),
837 conf->bss[i]->iface, bss->iface);
838 return -1;
839 }
840 }
841 }
842
4ec1fd8e 843#ifdef CONFIG_IEEE80211R_AP
08081ad8 844 if (full_config && wpa_key_mgmt_ft(bss->wpa_key_mgmt) &&
eff0fd1e
JM
845 (bss->nas_identifier == NULL ||
846 os_strlen(bss->nas_identifier) < 1 ||
847 os_strlen(bss->nas_identifier) > FT_R0KH_ID_MAX_LEN)) {
848 wpa_printf(MSG_ERROR, "FT (IEEE 802.11r) requires "
849 "nas_identifier to be configured as a 1..48 octet "
850 "string");
851 return -1;
852 }
4ec1fd8e 853#endif /* CONFIG_IEEE80211R_AP */
eff0fd1e
JM
854
855#ifdef CONFIG_IEEE80211N
08081ad8
JM
856 if (full_config && conf->ieee80211n &&
857 conf->hw_mode == HOSTAPD_MODE_IEEE80211B) {
eff0fd1e
JM
858 bss->disable_11n = 1;
859 wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) in 11b mode is not "
8c6f4a5a 860 "allowed, disabling HT capabilities");
eff0fd1e
JM
861 }
862
08081ad8 863 if (full_config && conf->ieee80211n &&
eff0fd1e
JM
864 bss->ssid.security_policy == SECURITY_STATIC_WEP) {
865 bss->disable_11n = 1;
866 wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) with WEP is not "
867 "allowed, disabling HT capabilities");
868 }
869
08081ad8 870 if (full_config && conf->ieee80211n && bss->wpa &&
eff0fd1e 871 !(bss->wpa_pairwise & WPA_CIPHER_CCMP) &&
30675c34
JM
872 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
873 WPA_CIPHER_CCMP_256 | WPA_CIPHER_GCMP_256)))
874 {
eff0fd1e
JM
875 bss->disable_11n = 1;
876 wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) with WPA/WPA2 "
877 "requires CCMP/GCMP to be enabled, disabling HT "
878 "capabilities");
879 }
880#endif /* CONFIG_IEEE80211N */
881
551817a5
WG
882#ifdef CONFIG_IEEE80211AC
883 if (full_config && conf->ieee80211ac &&
884 bss->ssid.security_policy == SECURITY_STATIC_WEP) {
885 bss->disable_11ac = 1;
886 wpa_printf(MSG_ERROR,
887 "VHT (IEEE 802.11ac) with WEP is not allowed, disabling VHT capabilities");
888 }
59d7cff7
FM
889
890 if (full_config && conf->ieee80211ac && bss->wpa &&
891 !(bss->wpa_pairwise & WPA_CIPHER_CCMP) &&
892 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
893 WPA_CIPHER_CCMP_256 | WPA_CIPHER_GCMP_256)))
894 {
895 bss->disable_11ac = 1;
896 wpa_printf(MSG_ERROR,
897 "VHT (IEEE 802.11ac) with WPA/WPA2 requires CCMP/GCMP to be enabled, disabling VHT capabilities");
898 }
551817a5
WG
899#endif /* CONFIG_IEEE80211AC */
900
c201f93a 901#ifdef CONFIG_WPS
08081ad8 902 if (full_config && bss->wps_state && bss->ignore_broadcast_ssid) {
eff0fd1e
JM
903 wpa_printf(MSG_INFO, "WPS: ignore_broadcast_ssid "
904 "configuration forced WPS to be disabled");
905 bss->wps_state = 0;
906 }
907
08081ad8
JM
908 if (full_config && bss->wps_state &&
909 bss->ssid.wep.keys_set && bss->wpa == 0) {
eff0fd1e
JM
910 wpa_printf(MSG_INFO, "WPS: WEP configuration forced WPS to be "
911 "disabled");
912 bss->wps_state = 0;
913 }
914
08081ad8 915 if (full_config && bss->wps_state && bss->wpa &&
eff0fd1e 916 (!(bss->wpa & 2) ||
01a02593 917 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP)))) {
eff0fd1e 918 wpa_printf(MSG_INFO, "WPS: WPA/TKIP configuration without "
01a02593 919 "WPA2/CCMP/GCMP forced WPS to be disabled");
eff0fd1e
JM
920 bss->wps_state = 0;
921 }
c201f93a 922#endif /* CONFIG_WPS */
eff0fd1e
JM
923
924#ifdef CONFIG_HS20
08081ad8 925 if (full_config && bss->hs20 &&
eff0fd1e 926 (!(bss->wpa & 2) ||
30675c34
JM
927 !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
928 WPA_CIPHER_CCMP_256 |
929 WPA_CIPHER_GCMP_256)))) {
eff0fd1e
JM
930 wpa_printf(MSG_ERROR, "HS 2.0: WPA2-Enterprise/CCMP "
931 "configuration is required for Hotspot 2.0 "
932 "functionality");
933 return -1;
934 }
935#endif /* CONFIG_HS20 */
936
4c572281
JM
937#ifdef CONFIG_MBO
938 if (full_config && bss->mbo_enabled && (bss->wpa & 2) &&
939 bss->ieee80211w == NO_MGMT_FRAME_PROTECTION) {
940 wpa_printf(MSG_ERROR,
941 "MBO: PMF needs to be enabled whenever using WPA2 with MBO");
942 return -1;
943 }
944#endif /* CONFIG_MBO */
945
eff0fd1e
JM
946 return 0;
947}
948
949
8884ce03
MM
950static int hostapd_config_check_cw(struct hostapd_config *conf, int queue)
951{
952 int tx_cwmin = conf->tx_queue[queue].cwmin;
953 int tx_cwmax = conf->tx_queue[queue].cwmax;
954 int ac_cwmin = conf->wmm_ac_params[queue].cwmin;
955 int ac_cwmax = conf->wmm_ac_params[queue].cwmax;
956
957 if (tx_cwmin > tx_cwmax) {
958 wpa_printf(MSG_ERROR,
959 "Invalid TX queue cwMin/cwMax values. cwMin(%d) greater than cwMax(%d)",
960 tx_cwmin, tx_cwmax);
961 return -1;
962 }
963 if (ac_cwmin > ac_cwmax) {
964 wpa_printf(MSG_ERROR,
965 "Invalid WMM AC cwMin/cwMax values. cwMin(%d) greater than cwMax(%d)",
966 ac_cwmin, ac_cwmax);
967 return -1;
968 }
969 return 0;
970}
971
972
08081ad8 973int hostapd_config_check(struct hostapd_config *conf, int full_config)
eff0fd1e
JM
974{
975 size_t i;
976
08081ad8
JM
977 if (full_config && conf->ieee80211d &&
978 (!conf->country[0] || !conf->country[1])) {
eff0fd1e
JM
979 wpa_printf(MSG_ERROR, "Cannot enable IEEE 802.11d without "
980 "setting the country_code");
981 return -1;
982 }
983
08081ad8 984 if (full_config && conf->ieee80211h && !conf->ieee80211d) {
eff0fd1e
JM
985 wpa_printf(MSG_ERROR, "Cannot enable IEEE 802.11h without "
986 "IEEE 802.11d enabled");
987 return -1;
988 }
989
e0392f82
S
990 if (full_config && conf->local_pwr_constraint != -1 &&
991 !conf->ieee80211d) {
992 wpa_printf(MSG_ERROR, "Cannot add Power Constraint element without Country element");
993 return -1;
994 }
995
3d7ad2f6
C
996 if (full_config && conf->spectrum_mgmt_required &&
997 conf->local_pwr_constraint == -1) {
998 wpa_printf(MSG_ERROR, "Cannot set Spectrum Management bit without Country and Power Constraint elements");
999 return -1;
1000 }
1001
8884ce03
MM
1002 for (i = 0; i < NUM_TX_QUEUES; i++) {
1003 if (hostapd_config_check_cw(conf, i))
1004 return -1;
1005 }
1006
eff0fd1e 1007 for (i = 0; i < conf->num_bss; i++) {
08081ad8 1008 if (hostapd_config_check_bss(conf->bss[i], conf, full_config))
eff0fd1e
JM
1009 return -1;
1010 }
1011
1012 return 0;
1013}
1014
1015
5d67bf15
JM
1016void hostapd_set_security_params(struct hostapd_bss_config *bss,
1017 int full_config)
eff0fd1e
JM
1018{
1019 if (bss->individual_wep_key_len == 0) {
1020 /* individual keys are not use; can use key idx0 for
1021 * broadcast keys */
1022 bss->broadcast_key_idx_min = 0;
1023 }
1024
1025 if ((bss->wpa & 2) && bss->rsn_pairwise == 0)
1026 bss->rsn_pairwise = bss->wpa_pairwise;
1027 bss->wpa_group = wpa_select_ap_group_cipher(bss->wpa, bss->wpa_pairwise,
1028 bss->rsn_pairwise);
1029
5d67bf15
JM
1030 if (full_config) {
1031 bss->radius->auth_server = bss->radius->auth_servers;
1032 bss->radius->acct_server = bss->radius->acct_servers;
1033 }
eff0fd1e
JM
1034
1035 if (bss->wpa && bss->ieee802_1x) {
1036 bss->ssid.security_policy = SECURITY_WPA;
1037 } else if (bss->wpa) {
1038 bss->ssid.security_policy = SECURITY_WPA_PSK;
1039 } else if (bss->ieee802_1x) {
1040 int cipher = WPA_CIPHER_NONE;
1041 bss->ssid.security_policy = SECURITY_IEEE_802_1X;
1042 bss->ssid.wep.default_len = bss->default_wep_key_len;
13a3a20d 1043 if (full_config && bss->default_wep_key_len) {
eff0fd1e
JM
1044 cipher = bss->default_wep_key_len >= 13 ?
1045 WPA_CIPHER_WEP104 : WPA_CIPHER_WEP40;
13a3a20d
JM
1046 } else if (full_config && bss->ssid.wep.keys_set) {
1047 if (bss->ssid.wep.len[0] >= 13)
1048 cipher = WPA_CIPHER_WEP104;
1049 else
1050 cipher = WPA_CIPHER_WEP40;
1051 }
eff0fd1e
JM
1052 bss->wpa_group = cipher;
1053 bss->wpa_pairwise = cipher;
1054 bss->rsn_pairwise = cipher;
13a3a20d
JM
1055 if (full_config)
1056 bss->wpa_key_mgmt = WPA_KEY_MGMT_IEEE8021X_NO_WPA;
eff0fd1e
JM
1057 } else if (bss->ssid.wep.keys_set) {
1058 int cipher = WPA_CIPHER_WEP40;
1059 if (bss->ssid.wep.len[0] >= 13)
1060 cipher = WPA_CIPHER_WEP104;
1061 bss->ssid.security_policy = SECURITY_STATIC_WEP;
1062 bss->wpa_group = cipher;
1063 bss->wpa_pairwise = cipher;
1064 bss->rsn_pairwise = cipher;
13a3a20d
JM
1065 if (full_config)
1066 bss->wpa_key_mgmt = WPA_KEY_MGMT_NONE;
a14896e8
JM
1067 } else if (bss->osen) {
1068 bss->ssid.security_policy = SECURITY_OSEN;
1069 bss->wpa_group = WPA_CIPHER_CCMP;
1070 bss->wpa_pairwise = 0;
1071 bss->rsn_pairwise = WPA_CIPHER_CCMP;
eff0fd1e
JM
1072 } else {
1073 bss->ssid.security_policy = SECURITY_PLAINTEXT;
29767152
JM
1074 if (full_config) {
1075 bss->wpa_group = WPA_CIPHER_NONE;
1076 bss->wpa_pairwise = WPA_CIPHER_NONE;
1077 bss->rsn_pairwise = WPA_CIPHER_NONE;
13a3a20d 1078 bss->wpa_key_mgmt = WPA_KEY_MGMT_NONE;
29767152 1079 }
eff0fd1e
JM
1080 }
1081}