Line data Source code
1 : /*
2 : * hostapd / Configuration helper functions
3 : * Copyright (c) 2003-2014, Jouni Malinen <j@w1.fi>
4 : *
5 : * This software may be distributed under the terms of the BSD license.
6 : * See README for more details.
7 : */
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 :
23 2148 : static void hostapd_config_free_vlan(struct hostapd_bss_config *bss)
24 : {
25 : struct hostapd_vlan *vlan, *prev;
26 :
27 2148 : vlan = bss->vlan;
28 2148 : prev = NULL;
29 4308 : while (vlan) {
30 12 : prev = vlan;
31 12 : vlan = vlan->next;
32 12 : os_free(prev);
33 : }
34 :
35 2148 : bss->vlan = NULL;
36 2148 : }
37 :
38 :
39 2148 : void hostapd_config_defaults_bss(struct hostapd_bss_config *bss)
40 : {
41 2148 : bss->logger_syslog_level = HOSTAPD_LEVEL_INFO;
42 2148 : bss->logger_stdout_level = HOSTAPD_LEVEL_INFO;
43 2148 : bss->logger_syslog = (unsigned int) -1;
44 2148 : bss->logger_stdout = (unsigned int) -1;
45 :
46 2148 : bss->auth_algs = WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED;
47 :
48 2148 : bss->wep_rekeying_period = 300;
49 : /* use key0 in individual key and key1 in broadcast key */
50 2148 : bss->broadcast_key_idx_min = 1;
51 2148 : bss->broadcast_key_idx_max = 2;
52 2148 : bss->eap_reauth_period = 3600;
53 :
54 2148 : bss->wpa_group_rekey = 600;
55 2148 : bss->wpa_gmk_rekey = 86400;
56 2148 : bss->wpa_key_mgmt = WPA_KEY_MGMT_PSK;
57 2148 : bss->wpa_pairwise = WPA_CIPHER_TKIP;
58 2148 : bss->wpa_group = WPA_CIPHER_TKIP;
59 2148 : bss->rsn_pairwise = 0;
60 :
61 2148 : bss->max_num_sta = MAX_STA_COUNT;
62 :
63 2148 : bss->dtim_period = 2;
64 :
65 2148 : bss->radius_server_auth_port = 1812;
66 2148 : bss->ap_max_inactivity = AP_MAX_INACTIVITY;
67 2148 : bss->eapol_version = EAPOL_VERSION;
68 :
69 2148 : bss->max_listen_interval = 65535;
70 :
71 2148 : bss->pwd_group = 19; /* ECC: GF(p=256) */
72 :
73 : #ifdef CONFIG_IEEE80211W
74 2148 : bss->assoc_sa_query_max_timeout = 1000;
75 2148 : bss->assoc_sa_query_retry_timeout = 201;
76 2148 : bss->group_mgmt_cipher = WPA_CIPHER_AES_128_CMAC;
77 : #endif /* CONFIG_IEEE80211W */
78 : #ifdef EAP_SERVER_FAST
79 : /* both anonymous and authenticated provisioning */
80 1775 : bss->eap_fast_prov = 3;
81 1775 : bss->pac_key_lifetime = 7 * 24 * 60 * 60;
82 1775 : bss->pac_key_refresh_time = 1 * 24 * 60 * 60;
83 : #endif /* EAP_SERVER_FAST */
84 :
85 : /* Set to -1 as defaults depends on HT in setup */
86 2148 : bss->wmm_enabled = -1;
87 :
88 : #ifdef CONFIG_IEEE80211R
89 2148 : bss->ft_over_ds = 1;
90 : #endif /* CONFIG_IEEE80211R */
91 :
92 2148 : bss->radius_das_time_window = 300;
93 :
94 2148 : bss->sae_anti_clogging_threshold = 5;
95 2148 : }
96 :
97 :
98 2155 : struct hostapd_config * hostapd_config_defaults(void)
99 : {
100 : #define ecw2cw(ecw) ((1 << (ecw)) - 1)
101 :
102 : struct hostapd_config *conf;
103 : struct hostapd_bss_config *bss;
104 2155 : const int aCWmin = 4, aCWmax = 10;
105 2155 : const struct hostapd_wmm_ac_params ac_bk =
106 : { aCWmin, aCWmax, 7, 0, 0 }; /* background traffic */
107 2155 : const struct hostapd_wmm_ac_params ac_be =
108 : { aCWmin, aCWmax, 3, 0, 0 }; /* best effort traffic */
109 2155 : const struct hostapd_wmm_ac_params ac_vi = /* video traffic */
110 2155 : { aCWmin - 1, aCWmin, 2, 3008 / 32, 0 };
111 4310 : const struct hostapd_wmm_ac_params ac_vo = /* voice traffic */
112 4310 : { aCWmin - 2, aCWmin - 1, 2, 1504 / 32, 0 };
113 6465 : const struct hostapd_tx_queue_params txq_bk =
114 4310 : { 7, ecw2cw(aCWmin), ecw2cw(aCWmax), 0 };
115 6465 : const struct hostapd_tx_queue_params txq_be =
116 4310 : { 3, ecw2cw(aCWmin), 4 * (ecw2cw(aCWmin) + 1) - 1, 0};
117 6465 : const struct hostapd_tx_queue_params txq_vi =
118 4310 : { 1, (ecw2cw(aCWmin) + 1) / 2 - 1, ecw2cw(aCWmin), 30};
119 6465 : const struct hostapd_tx_queue_params txq_vo =
120 2155 : { 1, (ecw2cw(aCWmin) + 1) / 4 - 1,
121 2155 : (ecw2cw(aCWmin) + 1) / 2 - 1, 15};
122 :
123 : #undef ecw2cw
124 :
125 2155 : conf = os_zalloc(sizeof(*conf));
126 2155 : bss = os_zalloc(sizeof(*bss));
127 2155 : if (conf == NULL || bss == NULL) {
128 10 : wpa_printf(MSG_ERROR, "Failed to allocate memory for "
129 : "configuration data.");
130 10 : os_free(conf);
131 10 : os_free(bss);
132 10 : return NULL;
133 : }
134 2145 : conf->bss = os_calloc(1, sizeof(struct hostapd_bss_config *));
135 2145 : if (conf->bss == NULL) {
136 4 : os_free(conf);
137 4 : os_free(bss);
138 4 : return NULL;
139 : }
140 2141 : conf->bss[0] = bss;
141 :
142 2141 : bss->radius = os_zalloc(sizeof(*bss->radius));
143 2141 : if (bss->radius == NULL) {
144 4 : os_free(conf->bss);
145 4 : os_free(conf);
146 4 : os_free(bss);
147 4 : return NULL;
148 : }
149 :
150 2137 : hostapd_config_defaults_bss(bss);
151 :
152 2137 : conf->num_bss = 1;
153 :
154 2137 : conf->beacon_int = 100;
155 2137 : conf->rts_threshold = -1; /* use driver default: 2347 */
156 2137 : conf->fragm_threshold = -1; /* user driver default: 2346 */
157 2137 : conf->send_probe_response = 1;
158 : /* Set to invalid value means do not add Power Constraint IE */
159 2137 : conf->local_pwr_constraint = -1;
160 :
161 2137 : conf->wmm_ac_params[0] = ac_be;
162 2137 : conf->wmm_ac_params[1] = ac_bk;
163 2137 : conf->wmm_ac_params[2] = ac_vi;
164 2137 : conf->wmm_ac_params[3] = ac_vo;
165 :
166 2137 : conf->tx_queue[0] = txq_vo;
167 2137 : conf->tx_queue[1] = txq_vi;
168 2137 : conf->tx_queue[2] = txq_be;
169 2137 : conf->tx_queue[3] = txq_bk;
170 :
171 2137 : conf->ht_capab = HT_CAP_INFO_SMPS_DISABLED;
172 :
173 2137 : conf->ap_table_max_size = 255;
174 2137 : conf->ap_table_expiration_time = 60;
175 2137 : conf->track_sta_max_age = 180;
176 :
177 : #ifdef CONFIG_TESTING_OPTIONS
178 2137 : conf->ignore_probe_probability = 0.0;
179 2137 : conf->ignore_auth_probability = 0.0;
180 2137 : conf->ignore_assoc_probability = 0.0;
181 2137 : conf->ignore_reassoc_probability = 0.0;
182 2137 : conf->corrupt_gtk_rekey_mic_probability = 0.0;
183 : #endif /* CONFIG_TESTING_OPTIONS */
184 :
185 2137 : conf->acs = 0;
186 2137 : conf->acs_ch_list.num = 0;
187 : #ifdef CONFIG_ACS
188 1764 : conf->acs_num_scans = 5;
189 : #endif /* CONFIG_ACS */
190 :
191 2137 : return conf;
192 : }
193 :
194 :
195 71 : int hostapd_mac_comp(const void *a, const void *b)
196 : {
197 71 : return os_memcmp(a, b, sizeof(macaddr));
198 : }
199 :
200 :
201 5826 : int hostapd_mac_comp_empty(const void *a)
202 : {
203 5826 : macaddr empty = { 0 };
204 5826 : return os_memcmp(a, empty, sizeof(macaddr));
205 : }
206 :
207 :
208 22 : static int hostapd_config_read_wpa_psk(const char *fname,
209 : struct hostapd_ssid *ssid)
210 : {
211 : FILE *f;
212 : char buf[128], *pos;
213 22 : int line = 0, ret = 0, len, ok;
214 : u8 addr[ETH_ALEN];
215 : struct hostapd_wpa_psk *psk;
216 :
217 22 : if (!fname)
218 0 : return 0;
219 :
220 22 : f = fopen(fname, "r");
221 22 : if (!f) {
222 1 : wpa_printf(MSG_ERROR, "WPA PSK file '%s' not found.", fname);
223 1 : return -1;
224 : }
225 :
226 120 : while (fgets(buf, sizeof(buf), f)) {
227 81 : line++;
228 :
229 81 : if (buf[0] == '#')
230 3 : continue;
231 78 : pos = buf;
232 3598 : while (*pos != '\0') {
233 3520 : if (*pos == '\n') {
234 78 : *pos = '\0';
235 78 : break;
236 : }
237 3442 : pos++;
238 : }
239 78 : if (buf[0] == '\0')
240 1 : continue;
241 :
242 77 : if (hwaddr_aton(buf, addr)) {
243 1 : wpa_printf(MSG_ERROR, "Invalid MAC address '%s' on "
244 : "line %d in '%s'", buf, line, fname);
245 1 : ret = -1;
246 1 : break;
247 : }
248 :
249 76 : psk = os_zalloc(sizeof(*psk));
250 76 : if (psk == NULL) {
251 0 : wpa_printf(MSG_ERROR, "WPA PSK allocation failed");
252 0 : ret = -1;
253 0 : break;
254 : }
255 76 : if (is_zero_ether_addr(addr))
256 28 : psk->group = 1;
257 : else
258 48 : os_memcpy(psk->addr, addr, ETH_ALEN);
259 :
260 76 : pos = buf + 17;
261 76 : if (*pos == '\0') {
262 1 : wpa_printf(MSG_ERROR, "No PSK on line %d in '%s'",
263 : line, fname);
264 1 : os_free(psk);
265 1 : ret = -1;
266 1 : break;
267 : }
268 75 : pos++;
269 :
270 75 : ok = 0;
271 75 : len = os_strlen(pos);
272 75 : if (len == 64 && hexstr2bin(pos, psk->psk, PMK_LEN) == 0)
273 15 : ok = 1;
274 60 : else if (len >= 8 && len < 64) {
275 59 : pbkdf2_sha1(pos, ssid->ssid, ssid->ssid_len,
276 59 : 4096, psk->psk, PMK_LEN);
277 59 : ok = 1;
278 : }
279 75 : if (!ok) {
280 1 : wpa_printf(MSG_ERROR, "Invalid PSK '%s' on line %d in "
281 : "'%s'", pos, line, fname);
282 1 : os_free(psk);
283 1 : ret = -1;
284 1 : break;
285 : }
286 :
287 74 : psk->next = ssid->wpa_psk;
288 74 : ssid->wpa_psk = psk;
289 : }
290 :
291 21 : fclose(f);
292 :
293 21 : return ret;
294 : }
295 :
296 :
297 445 : static int hostapd_derive_psk(struct hostapd_ssid *ssid)
298 : {
299 445 : ssid->wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
300 445 : if (ssid->wpa_psk == NULL) {
301 0 : wpa_printf(MSG_ERROR, "Unable to alloc space for PSK");
302 0 : return -1;
303 : }
304 890 : wpa_hexdump_ascii(MSG_DEBUG, "SSID",
305 445 : (u8 *) ssid->ssid, ssid->ssid_len);
306 890 : wpa_hexdump_ascii_key(MSG_DEBUG, "PSK (ASCII passphrase)",
307 445 : (u8 *) ssid->wpa_passphrase,
308 445 : os_strlen(ssid->wpa_passphrase));
309 890 : pbkdf2_sha1(ssid->wpa_passphrase,
310 445 : ssid->ssid, ssid->ssid_len,
311 445 : 4096, ssid->wpa_psk->psk, PMK_LEN);
312 445 : wpa_hexdump_key(MSG_DEBUG, "PSK (from passphrase)",
313 445 : ssid->wpa_psk->psk, PMK_LEN);
314 445 : return 0;
315 : }
316 :
317 :
318 2077 : int hostapd_setup_wpa_psk(struct hostapd_bss_config *conf)
319 : {
320 2077 : struct hostapd_ssid *ssid = &conf->ssid;
321 :
322 2077 : if (ssid->wpa_passphrase != NULL) {
323 463 : if (ssid->wpa_psk != NULL) {
324 18 : wpa_printf(MSG_DEBUG, "Using pre-configured WPA PSK "
325 : "instead of passphrase");
326 : } else {
327 445 : wpa_printf(MSG_DEBUG, "Deriving WPA PSK based on "
328 : "passphrase");
329 445 : if (hostapd_derive_psk(ssid) < 0)
330 0 : return -1;
331 : }
332 463 : ssid->wpa_psk->group = 1;
333 : }
334 :
335 2077 : if (ssid->wpa_psk_file) {
336 22 : if (hostapd_config_read_wpa_psk(ssid->wpa_psk_file,
337 : &conf->ssid))
338 4 : return -1;
339 : }
340 :
341 2073 : return 0;
342 : }
343 :
344 :
345 4296 : static void hostapd_config_free_radius(struct hostapd_radius_server *servers,
346 : int num_servers)
347 : {
348 : int i;
349 :
350 4774 : for (i = 0; i < num_servers; i++) {
351 478 : os_free(servers[i].shared_secret);
352 : }
353 4296 : os_free(servers);
354 4296 : }
355 :
356 :
357 : struct hostapd_radius_attr *
358 47560 : hostapd_config_get_radius_attr(struct hostapd_radius_attr *attr, u8 type)
359 : {
360 47899 : for (; attr; attr = attr->next) {
361 354 : if (attr->type == type)
362 15 : return attr;
363 : }
364 47545 : return NULL;
365 : }
366 :
367 :
368 10576 : static void hostapd_config_free_radius_attr(struct hostapd_radius_attr *attr)
369 : {
370 : struct hostapd_radius_attr *prev;
371 :
372 22538 : while (attr) {
373 1386 : prev = attr;
374 1386 : attr = attr->next;
375 1386 : wpabuf_free(prev->val);
376 1386 : os_free(prev);
377 : }
378 10576 : }
379 :
380 :
381 6280 : void hostapd_config_free_eap_user(struct hostapd_eap_user *user)
382 : {
383 6280 : hostapd_config_free_radius_attr(user->accept_attr);
384 6280 : os_free(user->identity);
385 6280 : bin_clear_free(user->password, user->password_len);
386 6280 : os_free(user);
387 6280 : }
388 :
389 :
390 2148 : static void hostapd_config_free_wep(struct hostapd_wep_keys *keys)
391 : {
392 : int i;
393 10740 : for (i = 0; i < NUM_WEP_KEYS; i++) {
394 8592 : bin_clear_free(keys->key[i], keys->len[i]);
395 8592 : keys->key[i] = NULL;
396 : }
397 2148 : }
398 :
399 :
400 2664 : void hostapd_config_clear_wpa_psk(struct hostapd_wpa_psk **l)
401 : {
402 : struct hostapd_wpa_psk *psk, *tmp;
403 :
404 6225 : for (psk = *l; psk;) {
405 897 : tmp = psk;
406 897 : psk = psk->next;
407 897 : bin_clear_free(tmp, sizeof(*tmp));
408 : }
409 2664 : *l = NULL;
410 2664 : }
411 :
412 :
413 2148 : void hostapd_config_free_bss(struct hostapd_bss_config *conf)
414 : {
415 : struct hostapd_eap_user *user, *prev_user;
416 :
417 2148 : if (conf == NULL)
418 2148 : return;
419 :
420 2148 : hostapd_config_clear_wpa_psk(&conf->ssid.wpa_psk);
421 :
422 2148 : str_clear_free(conf->ssid.wpa_passphrase);
423 2148 : os_free(conf->ssid.wpa_psk_file);
424 2148 : hostapd_config_free_wep(&conf->ssid.wep);
425 : #ifdef CONFIG_FULL_DYNAMIC_VLAN
426 1775 : os_free(conf->ssid.vlan_tagged_interface);
427 : #endif /* CONFIG_FULL_DYNAMIC_VLAN */
428 :
429 2148 : user = conf->eap_user;
430 10429 : while (user) {
431 6133 : prev_user = user;
432 6133 : user = user->next;
433 6133 : hostapd_config_free_eap_user(prev_user);
434 : }
435 2148 : os_free(conf->eap_user_sqlite);
436 :
437 2148 : os_free(conf->eap_req_id_text);
438 2148 : os_free(conf->erp_domain);
439 2148 : os_free(conf->accept_mac);
440 2148 : os_free(conf->deny_mac);
441 2148 : os_free(conf->nas_identifier);
442 2148 : if (conf->radius) {
443 2148 : hostapd_config_free_radius(conf->radius->auth_servers,
444 2148 : conf->radius->num_auth_servers);
445 2148 : hostapd_config_free_radius(conf->radius->acct_servers,
446 2148 : conf->radius->num_acct_servers);
447 : }
448 2148 : hostapd_config_free_radius_attr(conf->radius_auth_req_attr);
449 2148 : hostapd_config_free_radius_attr(conf->radius_acct_req_attr);
450 2148 : os_free(conf->rsn_preauth_interfaces);
451 2148 : os_free(conf->ctrl_interface);
452 2148 : os_free(conf->ca_cert);
453 2148 : os_free(conf->server_cert);
454 2148 : os_free(conf->private_key);
455 2148 : os_free(conf->private_key_passwd);
456 2148 : os_free(conf->ocsp_stapling_response);
457 2148 : os_free(conf->dh_file);
458 2148 : os_free(conf->openssl_ciphers);
459 2148 : os_free(conf->pac_opaque_encr_key);
460 2148 : os_free(conf->eap_fast_a_id);
461 2148 : os_free(conf->eap_fast_a_id_info);
462 2148 : os_free(conf->eap_sim_db);
463 2148 : os_free(conf->radius_server_clients);
464 2148 : os_free(conf->radius);
465 2148 : os_free(conf->radius_das_shared_secret);
466 2148 : hostapd_config_free_vlan(conf);
467 2148 : os_free(conf->time_zone);
468 :
469 : #ifdef CONFIG_IEEE80211R
470 : {
471 : struct ft_remote_r0kh *r0kh, *r0kh_prev;
472 : struct ft_remote_r1kh *r1kh, *r1kh_prev;
473 :
474 2148 : r0kh = conf->r0kh_list;
475 2148 : conf->r0kh_list = NULL;
476 4398 : while (r0kh) {
477 102 : r0kh_prev = r0kh;
478 102 : r0kh = r0kh->next;
479 102 : os_free(r0kh_prev);
480 : }
481 :
482 2148 : r1kh = conf->r1kh_list;
483 2148 : conf->r1kh_list = NULL;
484 4347 : while (r1kh) {
485 51 : r1kh_prev = r1kh;
486 51 : r1kh = r1kh->next;
487 51 : os_free(r1kh_prev);
488 : }
489 : }
490 : #endif /* CONFIG_IEEE80211R */
491 :
492 : #ifdef CONFIG_WPS
493 2148 : os_free(conf->wps_pin_requests);
494 2148 : os_free(conf->device_name);
495 2148 : os_free(conf->manufacturer);
496 2148 : os_free(conf->model_name);
497 2148 : os_free(conf->model_number);
498 2148 : os_free(conf->serial_number);
499 2148 : os_free(conf->config_methods);
500 2148 : os_free(conf->ap_pin);
501 2148 : os_free(conf->extra_cred);
502 2148 : os_free(conf->ap_settings);
503 2148 : os_free(conf->upnp_iface);
504 2148 : os_free(conf->friendly_name);
505 2148 : os_free(conf->manufacturer_url);
506 2148 : os_free(conf->model_description);
507 2148 : os_free(conf->model_url);
508 2148 : os_free(conf->upc);
509 : {
510 : unsigned int i;
511 :
512 23628 : for (i = 0; i < MAX_WPS_VENDOR_EXTENSIONS; i++)
513 21480 : wpabuf_free(conf->wps_vendor_ext[i]);
514 : }
515 2148 : wpabuf_free(conf->wps_nfc_dh_pubkey);
516 2148 : wpabuf_free(conf->wps_nfc_dh_privkey);
517 2148 : wpabuf_free(conf->wps_nfc_dev_pw);
518 : #endif /* CONFIG_WPS */
519 :
520 2148 : os_free(conf->roaming_consortium);
521 2148 : os_free(conf->venue_name);
522 2148 : os_free(conf->nai_realm_data);
523 2148 : os_free(conf->network_auth_type);
524 2148 : os_free(conf->anqp_3gpp_cell_net);
525 2148 : os_free(conf->domain_name);
526 :
527 : #ifdef CONFIG_RADIUS_TEST
528 : os_free(conf->dump_msk_file);
529 : #endif /* CONFIG_RADIUS_TEST */
530 :
531 : #ifdef CONFIG_HS20
532 2148 : os_free(conf->hs20_oper_friendly_name);
533 2148 : os_free(conf->hs20_wan_metrics);
534 2148 : os_free(conf->hs20_connection_capability);
535 2148 : os_free(conf->hs20_operating_class);
536 2148 : os_free(conf->hs20_icons);
537 2148 : if (conf->hs20_osu_providers) {
538 : size_t i;
539 8 : for (i = 0; i < conf->hs20_osu_providers_count; i++) {
540 : struct hs20_osu_provider *p;
541 : size_t j;
542 4 : p = &conf->hs20_osu_providers[i];
543 4 : os_free(p->friendly_name);
544 4 : os_free(p->server_uri);
545 4 : os_free(p->method_list);
546 7 : for (j = 0; j < p->icons_count; j++)
547 3 : os_free(p->icons[j]);
548 4 : os_free(p->icons);
549 4 : os_free(p->osu_nai);
550 4 : os_free(p->service_desc);
551 : }
552 4 : os_free(conf->hs20_osu_providers);
553 : }
554 2148 : os_free(conf->subscr_remediation_url);
555 : #endif /* CONFIG_HS20 */
556 :
557 2148 : wpabuf_free(conf->vendor_elements);
558 :
559 2148 : os_free(conf->sae_groups);
560 :
561 2148 : os_free(conf->wowlan_triggers);
562 :
563 2148 : os_free(conf->server_id);
564 :
565 : #ifdef CONFIG_TESTING_OPTIONS
566 2148 : wpabuf_free(conf->own_ie_override);
567 : #endif /* CONFIG_TESTING_OPTIONS */
568 :
569 2148 : os_free(conf->no_probe_resp_if_seen_on);
570 2148 : os_free(conf->no_auth_if_seen_on);
571 :
572 2148 : os_free(conf);
573 : }
574 :
575 :
576 : /**
577 : * hostapd_config_free - Free hostapd configuration
578 : * @conf: Configuration data from hostapd_config_read().
579 : */
580 2164 : void hostapd_config_free(struct hostapd_config *conf)
581 : {
582 : size_t i;
583 :
584 2164 : if (conf == NULL)
585 2191 : return;
586 :
587 4244 : for (i = 0; i < conf->num_bss; i++)
588 2107 : hostapd_config_free_bss(conf->bss[i]);
589 2137 : os_free(conf->bss);
590 2137 : os_free(conf->supported_rates);
591 2137 : os_free(conf->basic_rates);
592 2137 : os_free(conf->acs_ch_list.range);
593 2137 : os_free(conf->driver_params);
594 : #ifdef CONFIG_ACS
595 1764 : os_free(conf->acs_chan_bias);
596 : #endif /* CONFIG_ACS */
597 :
598 2137 : os_free(conf);
599 : }
600 :
601 :
602 : /**
603 : * hostapd_maclist_found - Find a MAC address from a list
604 : * @list: MAC address list
605 : * @num_entries: Number of addresses in the list
606 : * @addr: Address to search for
607 : * @vlan_id: Buffer for returning VLAN ID or %NULL if not needed
608 : * Returns: 1 if address is in the list or 0 if not.
609 : *
610 : * Perform a binary search for given MAC address from a pre-sorted list.
611 : */
612 7142 : int hostapd_maclist_found(struct mac_acl_entry *list, int num_entries,
613 : const u8 *addr, int *vlan_id)
614 : {
615 : int start, end, middle, res;
616 :
617 7142 : start = 0;
618 7142 : end = num_entries - 1;
619 :
620 14305 : while (start <= end) {
621 148 : middle = (start + end) / 2;
622 148 : res = os_memcmp(list[middle].addr, addr, ETH_ALEN);
623 148 : if (res == 0) {
624 127 : if (vlan_id)
625 127 : *vlan_id = list[middle].vlan_id;
626 127 : return 1;
627 : }
628 21 : if (res < 0)
629 21 : start = middle + 1;
630 : else
631 0 : end = middle - 1;
632 : }
633 :
634 7015 : return 0;
635 : }
636 :
637 :
638 25616 : int hostapd_rate_found(int *list, int rate)
639 : {
640 : int i;
641 :
642 25616 : if (list == NULL)
643 0 : return 0;
644 :
645 110372 : for (i = 0; list[i] >= 0; i++)
646 94827 : if (list[i] == rate)
647 10071 : return 1;
648 :
649 15545 : return 0;
650 : }
651 :
652 :
653 22 : int hostapd_vlan_id_valid(struct hostapd_vlan *vlan, int vlan_id)
654 : {
655 22 : struct hostapd_vlan *v = vlan;
656 52 : while (v) {
657 30 : if (v->vlan_id == vlan_id || v->vlan_id == VLAN_ID_WILDCARD)
658 22 : return 1;
659 8 : v = v->next;
660 : }
661 0 : return 0;
662 : }
663 :
664 :
665 23 : const char * hostapd_get_vlan_id_ifname(struct hostapd_vlan *vlan, int vlan_id)
666 : {
667 23 : struct hostapd_vlan *v = vlan;
668 46 : while (v) {
669 23 : if (v->vlan_id == vlan_id)
670 23 : return v->ifname;
671 0 : v = v->next;
672 : }
673 0 : return NULL;
674 : }
675 :
676 :
677 2303 : const u8 * hostapd_get_psk(const struct hostapd_bss_config *conf,
678 : const u8 *addr, const u8 *p2p_dev_addr,
679 : const u8 *prev_psk)
680 : {
681 : struct hostapd_wpa_psk *psk;
682 2303 : int next_ok = prev_psk == NULL;
683 :
684 2303 : if (p2p_dev_addr && !is_zero_ether_addr(p2p_dev_addr)) {
685 7824 : wpa_printf(MSG_DEBUG, "Searching a PSK for " MACSTR
686 : " p2p_dev_addr=" MACSTR " prev_psk=%p",
687 7824 : MAC2STR(addr), MAC2STR(p2p_dev_addr), prev_psk);
688 652 : addr = NULL; /* Use P2P Device Address for matching */
689 : } else {
690 9906 : wpa_printf(MSG_DEBUG, "Searching a PSK for " MACSTR
691 : " prev_psk=%p",
692 9906 : MAC2STR(addr), prev_psk);
693 : }
694 :
695 2348 : for (psk = conf->ssid.wpa_psk; psk != NULL; psk = psk->next) {
696 4629 : if (next_ok &&
697 2394 : (psk->group ||
698 42 : (addr && os_memcmp(psk->addr, addr, ETH_ALEN) == 0) ||
699 96 : (!addr && p2p_dev_addr &&
700 48 : os_memcmp(psk->p2p_dev_addr, p2p_dev_addr, ETH_ALEN) ==
701 : 0)))
702 2280 : return psk->psk;
703 :
704 45 : if (psk->psk == prev_psk)
705 17 : next_ok = 1;
706 : }
707 :
708 23 : return NULL;
709 : }
710 :
711 :
712 25576 : static int hostapd_config_check_bss(struct hostapd_bss_config *bss,
713 : struct hostapd_config *conf,
714 : int full_config)
715 : {
716 25984 : if (full_config && bss->ieee802_1x && !bss->eap_server &&
717 408 : !bss->radius->auth_servers) {
718 1 : wpa_printf(MSG_ERROR, "Invalid IEEE 802.1X configuration (no "
719 : "EAP authenticator configured).");
720 1 : return -1;
721 : }
722 :
723 25575 : if (bss->wpa) {
724 : int wep, i;
725 :
726 19820 : wep = bss->default_wep_key_len > 0 ||
727 9910 : bss->individual_wep_key_len > 0;
728 49546 : for (i = 0; i < NUM_WEP_KEYS; i++) {
729 39637 : if (bss->ssid.wep.keys_set) {
730 1 : wep = 1;
731 1 : break;
732 : }
733 : }
734 :
735 9910 : if (wep) {
736 1 : wpa_printf(MSG_ERROR, "WEP configuration in a WPA network is not supported");
737 1 : return -1;
738 : }
739 : }
740 :
741 26527 : if (full_config && bss->wpa &&
742 955 : bss->wpa_psk_radius != PSK_RADIUS_IGNORED &&
743 2 : bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH) {
744 1 : wpa_printf(MSG_ERROR, "WPA-PSK using RADIUS enabled, but no "
745 : "RADIUS checking (macaddr_acl=2) enabled.");
746 1 : return -1;
747 : }
748 :
749 25982 : if (full_config && bss->wpa && (bss->wpa_key_mgmt & WPA_KEY_MGMT_PSK) &&
750 782 : bss->ssid.wpa_psk == NULL && bss->ssid.wpa_passphrase == NULL &&
751 11 : bss->ssid.wpa_psk_file == NULL &&
752 2 : (bss->wpa_psk_radius != PSK_RADIUS_REQUIRED ||
753 1 : bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH)) {
754 0 : wpa_printf(MSG_ERROR, "WPA-PSK enabled, but PSK or passphrase "
755 : "is not configured.");
756 0 : return -1;
757 : }
758 :
759 25573 : if (full_config && hostapd_mac_comp_empty(bss->bssid) != 0) {
760 : size_t i;
761 :
762 230 : for (i = 0; i < conf->num_bss; i++) {
763 157 : if (conf->bss[i] != bss &&
764 28 : (hostapd_mac_comp(conf->bss[i]->bssid,
765 28 : bss->bssid) == 0)) {
766 0 : wpa_printf(MSG_ERROR, "Duplicate BSSID " MACSTR
767 : " on interface '%s' and '%s'.",
768 0 : MAC2STR(bss->bssid),
769 0 : conf->bss[i]->iface, bss->iface);
770 0 : return -1;
771 : }
772 : }
773 : }
774 :
775 : #ifdef CONFIG_IEEE80211R
776 25634 : if (full_config && wpa_key_mgmt_ft(bss->wpa_key_mgmt) &&
777 121 : (bss->nas_identifier == NULL ||
778 120 : os_strlen(bss->nas_identifier) < 1 ||
779 60 : os_strlen(bss->nas_identifier) > FT_R0KH_ID_MAX_LEN)) {
780 1 : wpa_printf(MSG_ERROR, "FT (IEEE 802.11r) requires "
781 : "nas_identifier to be configured as a 1..48 octet "
782 : "string");
783 1 : return -1;
784 : }
785 : #endif /* CONFIG_IEEE80211R */
786 :
787 : #ifdef CONFIG_IEEE80211N
788 27304 : if (full_config && conf->ieee80211n &&
789 1732 : conf->hw_mode == HOSTAPD_MODE_IEEE80211B) {
790 17 : bss->disable_11n = 1;
791 17 : wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) in 11b mode is not "
792 : "allowed, disabling HT capabilities");
793 : }
794 :
795 27304 : if (full_config && conf->ieee80211n &&
796 1732 : bss->ssid.security_policy == SECURITY_STATIC_WEP) {
797 11 : bss->disable_11n = 1;
798 11 : wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) with WEP is not "
799 : "allowed, disabling HT capabilities");
800 : }
801 :
802 26523 : if (full_config && conf->ieee80211n && bss->wpa &&
803 1900 : !(bss->wpa_pairwise & WPA_CIPHER_CCMP) &&
804 949 : !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
805 : WPA_CIPHER_CCMP_256 | WPA_CIPHER_GCMP_256)))
806 : {
807 15 : bss->disable_11n = 1;
808 15 : wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) with WPA/WPA2 "
809 : "requires CCMP/GCMP to be enabled, disabling HT "
810 : "capabilities");
811 : }
812 : #endif /* CONFIG_IEEE80211N */
813 :
814 : #ifdef CONFIG_WPS
815 25572 : if (full_config && bss->wps_state && bss->ignore_broadcast_ssid) {
816 0 : wpa_printf(MSG_INFO, "WPS: ignore_broadcast_ssid "
817 : "configuration forced WPS to be disabled");
818 0 : bss->wps_state = 0;
819 : }
820 :
821 25828 : if (full_config && bss->wps_state &&
822 256 : bss->ssid.wep.keys_set && bss->wpa == 0) {
823 0 : wpa_printf(MSG_INFO, "WPS: WEP configuration forced WPS to be "
824 : "disabled");
825 0 : bss->wps_state = 0;
826 : }
827 :
828 25794 : if (full_config && bss->wps_state && bss->wpa &&
829 444 : (!(bss->wpa & 2) ||
830 222 : !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP)))) {
831 0 : wpa_printf(MSG_INFO, "WPS: WPA/TKIP configuration without "
832 : "WPA2/CCMP/GCMP forced WPS to be disabled");
833 0 : bss->wps_state = 0;
834 : }
835 : #endif /* CONFIG_WPS */
836 :
837 : #ifdef CONFIG_HS20
838 25700 : if (full_config && bss->hs20 &&
839 255 : (!(bss->wpa & 2) ||
840 127 : !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
841 : WPA_CIPHER_CCMP_256 |
842 : WPA_CIPHER_GCMP_256)))) {
843 1 : wpa_printf(MSG_ERROR, "HS 2.0: WPA2-Enterprise/CCMP "
844 : "configuration is required for Hotspot 2.0 "
845 : "functionality");
846 1 : return -1;
847 : }
848 : #endif /* CONFIG_HS20 */
849 :
850 25571 : return 0;
851 : }
852 :
853 :
854 102196 : static int hostapd_config_check_cw(struct hostapd_config *conf, int queue)
855 : {
856 102196 : int tx_cwmin = conf->tx_queue[queue].cwmin;
857 102196 : int tx_cwmax = conf->tx_queue[queue].cwmax;
858 102196 : int ac_cwmin = conf->wmm_ac_params[queue].cwmin;
859 102196 : int ac_cwmax = conf->wmm_ac_params[queue].cwmax;
860 :
861 102196 : if (tx_cwmin > tx_cwmax) {
862 0 : wpa_printf(MSG_ERROR,
863 : "Invalid TX queue cwMin/cwMax values. cwMin(%d) greater than cwMax(%d)",
864 : tx_cwmin, tx_cwmax);
865 0 : return -1;
866 : }
867 102196 : if (ac_cwmin > ac_cwmax) {
868 0 : wpa_printf(MSG_ERROR,
869 : "Invalid WMM AC cwMin/cwMax values. cwMin(%d) greater than cwMax(%d)",
870 : ac_cwmin, ac_cwmax);
871 0 : return -1;
872 : }
873 102196 : return 0;
874 : }
875 :
876 :
877 25553 : int hostapd_config_check(struct hostapd_config *conf, int full_config)
878 : {
879 : size_t i;
880 :
881 25574 : if (full_config && conf->ieee80211d &&
882 41 : (!conf->country[0] || !conf->country[1])) {
883 1 : wpa_printf(MSG_ERROR, "Cannot enable IEEE 802.11d without "
884 : "setting the country_code");
885 1 : return -1;
886 : }
887 :
888 25552 : if (full_config && conf->ieee80211h && !conf->ieee80211d) {
889 1 : wpa_printf(MSG_ERROR, "Cannot enable IEEE 802.11h without "
890 : "IEEE 802.11d enabled");
891 1 : return -1;
892 : }
893 :
894 25553 : if (full_config && conf->local_pwr_constraint != -1 &&
895 2 : !conf->ieee80211d) {
896 1 : wpa_printf(MSG_ERROR, "Cannot add Power Constraint element without Country element");
897 1 : return -1;
898 : }
899 :
900 25552 : if (full_config && conf->spectrum_mgmt_required &&
901 2 : conf->local_pwr_constraint == -1) {
902 1 : wpa_printf(MSG_ERROR, "Cannot set Spectrum Management bit without Country and Power Constraint elements");
903 1 : return -1;
904 : }
905 :
906 127745 : for (i = 0; i < NUM_TX_QUEUES; i++) {
907 102196 : if (hostapd_config_check_cw(conf, i))
908 0 : return -1;
909 : }
910 :
911 51120 : for (i = 0; i < conf->num_bss; i++) {
912 25576 : if (hostapd_config_check_bss(conf->bss[i], conf, full_config))
913 5 : return -1;
914 : }
915 :
916 25544 : return 0;
917 : }
918 :
919 :
920 25576 : void hostapd_set_security_params(struct hostapd_bss_config *bss,
921 : int full_config)
922 : {
923 25576 : if (bss->individual_wep_key_len == 0) {
924 : /* individual keys are not use; can use key idx0 for
925 : * broadcast keys */
926 25567 : bss->broadcast_key_idx_min = 0;
927 : }
928 :
929 25576 : if ((bss->wpa & 2) && bss->rsn_pairwise == 0)
930 912 : bss->rsn_pairwise = bss->wpa_pairwise;
931 25576 : bss->wpa_group = wpa_select_ap_group_cipher(bss->wpa, bss->wpa_pairwise,
932 : bss->rsn_pairwise);
933 :
934 25576 : if (full_config) {
935 1753 : bss->radius->auth_server = bss->radius->auth_servers;
936 1753 : bss->radius->acct_server = bss->radius->acct_servers;
937 : }
938 :
939 25576 : if (bss->wpa && bss->ieee802_1x) {
940 3019 : bss->ssid.security_policy = SECURITY_WPA;
941 22557 : } else if (bss->wpa) {
942 6891 : bss->ssid.security_policy = SECURITY_WPA_PSK;
943 15666 : } else if (bss->ieee802_1x) {
944 57 : int cipher = WPA_CIPHER_NONE;
945 57 : bss->ssid.security_policy = SECURITY_IEEE_802_1X;
946 57 : bss->ssid.wep.default_len = bss->default_wep_key_len;
947 57 : if (full_config && bss->default_wep_key_len) {
948 3 : cipher = bss->default_wep_key_len >= 13 ?
949 : WPA_CIPHER_WEP104 : WPA_CIPHER_WEP40;
950 54 : } else if (full_config && bss->ssid.wep.keys_set) {
951 1 : if (bss->ssid.wep.len[0] >= 13)
952 0 : cipher = WPA_CIPHER_WEP104;
953 : else
954 1 : cipher = WPA_CIPHER_WEP40;
955 : }
956 57 : bss->wpa_group = cipher;
957 57 : bss->wpa_pairwise = cipher;
958 57 : bss->rsn_pairwise = cipher;
959 57 : if (full_config)
960 13 : bss->wpa_key_mgmt = WPA_KEY_MGMT_IEEE8021X_NO_WPA;
961 15609 : } else if (bss->ssid.wep.keys_set) {
962 24 : int cipher = WPA_CIPHER_WEP40;
963 24 : if (bss->ssid.wep.len[0] >= 13)
964 12 : cipher = WPA_CIPHER_WEP104;
965 24 : bss->ssid.security_policy = SECURITY_STATIC_WEP;
966 24 : bss->wpa_group = cipher;
967 24 : bss->wpa_pairwise = cipher;
968 24 : bss->rsn_pairwise = cipher;
969 24 : if (full_config)
970 11 : bss->wpa_key_mgmt = WPA_KEY_MGMT_NONE;
971 15585 : } else if (bss->osen) {
972 2 : bss->ssid.security_policy = SECURITY_OSEN;
973 2 : bss->wpa_group = WPA_CIPHER_CCMP;
974 2 : bss->wpa_pairwise = 0;
975 2 : bss->rsn_pairwise = WPA_CIPHER_CCMP;
976 : } else {
977 15583 : bss->ssid.security_policy = SECURITY_PLAINTEXT;
978 15583 : if (full_config) {
979 775 : bss->wpa_group = WPA_CIPHER_NONE;
980 775 : bss->wpa_pairwise = WPA_CIPHER_NONE;
981 775 : bss->rsn_pairwise = WPA_CIPHER_NONE;
982 775 : bss->wpa_key_mgmt = WPA_KEY_MGMT_NONE;
983 : }
984 : }
985 25576 : }
|