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