]>
Commit | Line | Data |
---|---|---|
6fc6879b | 1 | /* |
41d719d6 | 2 | * hostapd / Configuration helper functions |
af35e7af | 3 | * Copyright (c) 2003-2012, 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 | } | |
133 | ||
6fc6879b JM |
134 | bss->radius = os_zalloc(sizeof(*bss->radius)); |
135 | if (bss->radius == NULL) { | |
136 | os_free(conf); | |
137 | os_free(bss); | |
138 | return NULL; | |
139 | } | |
140 | ||
141 | hostapd_config_defaults_bss(bss); | |
142 | ||
143 | conf->num_bss = 1; | |
144 | conf->bss = bss; | |
145 | ||
146 | conf->beacon_int = 100; | |
147 | conf->rts_threshold = -1; /* use driver default: 2347 */ | |
148 | conf->fragm_threshold = -1; /* user driver default: 2346 */ | |
149 | conf->send_probe_response = 1; | |
6fc6879b | 150 | |
3ae0800c JM |
151 | conf->wmm_ac_params[0] = ac_be; |
152 | conf->wmm_ac_params[1] = ac_bk; | |
153 | conf->wmm_ac_params[2] = ac_vi; | |
154 | conf->wmm_ac_params[3] = ac_vo; | |
6fc6879b | 155 | |
d2da2249 JB |
156 | conf->tx_queue[0] = txq_vo; |
157 | conf->tx_queue[1] = txq_vi; | |
158 | conf->tx_queue[2] = txq_be; | |
159 | conf->tx_queue[3] = txq_bk; | |
160 | ||
fc14f567 | 161 | conf->ht_capab = HT_CAP_INFO_SMPS_DISABLED; |
de9289c8 | 162 | |
f1b44874 SE |
163 | conf->ap_table_max_size = 255; |
164 | conf->ap_table_expiration_time = 60; | |
165 | ||
c2aff6b1 JB |
166 | #ifdef CONFIG_TESTING_OPTIONS |
167 | conf->ignore_probe_probability = 0.0d; | |
168 | conf->ignore_auth_probability = 0.0d; | |
169 | conf->ignore_assoc_probability = 0.0d; | |
170 | conf->ignore_reassoc_probability = 0.0d; | |
7af092a0 | 171 | conf->corrupt_gtk_rekey_mic_probability = 0.0d; |
c2aff6b1 JB |
172 | #endif /* CONFIG_TESTING_OPTIONS */ |
173 | ||
50f4f2a0 MK |
174 | #ifdef CONFIG_ACS |
175 | conf->acs_num_scans = 5; | |
176 | #endif /* CONFIG_ACS */ | |
177 | ||
6fc6879b JM |
178 | return conf; |
179 | } | |
180 | ||
181 | ||
182 | int hostapd_mac_comp(const void *a, const void *b) | |
183 | { | |
184 | return os_memcmp(a, b, sizeof(macaddr)); | |
185 | } | |
186 | ||
187 | ||
188 | int hostapd_mac_comp_empty(const void *a) | |
189 | { | |
190 | macaddr empty = { 0 }; | |
191 | return os_memcmp(a, empty, sizeof(macaddr)); | |
192 | } | |
193 | ||
194 | ||
6fc6879b JM |
195 | static int hostapd_config_read_wpa_psk(const char *fname, |
196 | struct hostapd_ssid *ssid) | |
197 | { | |
198 | FILE *f; | |
199 | char buf[128], *pos; | |
200 | int line = 0, ret = 0, len, ok; | |
201 | u8 addr[ETH_ALEN]; | |
202 | struct hostapd_wpa_psk *psk; | |
203 | ||
204 | if (!fname) | |
205 | return 0; | |
206 | ||
207 | f = fopen(fname, "r"); | |
208 | if (!f) { | |
10656fc2 | 209 | wpa_printf(MSG_ERROR, "WPA PSK file '%s' not found.", fname); |
6fc6879b JM |
210 | return -1; |
211 | } | |
212 | ||
213 | while (fgets(buf, sizeof(buf), f)) { | |
214 | line++; | |
215 | ||
216 | if (buf[0] == '#') | |
217 | continue; | |
218 | pos = buf; | |
219 | while (*pos != '\0') { | |
220 | if (*pos == '\n') { | |
221 | *pos = '\0'; | |
222 | break; | |
223 | } | |
224 | pos++; | |
225 | } | |
226 | if (buf[0] == '\0') | |
227 | continue; | |
228 | ||
229 | if (hwaddr_aton(buf, addr)) { | |
10656fc2 JM |
230 | wpa_printf(MSG_ERROR, "Invalid MAC address '%s' on " |
231 | "line %d in '%s'", buf, line, fname); | |
6fc6879b JM |
232 | ret = -1; |
233 | break; | |
234 | } | |
235 | ||
236 | psk = os_zalloc(sizeof(*psk)); | |
237 | if (psk == NULL) { | |
10656fc2 | 238 | wpa_printf(MSG_ERROR, "WPA PSK allocation failed"); |
6fc6879b JM |
239 | ret = -1; |
240 | break; | |
241 | } | |
a8e16edc | 242 | if (is_zero_ether_addr(addr)) |
6fc6879b JM |
243 | psk->group = 1; |
244 | else | |
245 | os_memcpy(psk->addr, addr, ETH_ALEN); | |
246 | ||
247 | pos = buf + 17; | |
5306f43f | 248 | if (*pos == '\0') { |
10656fc2 JM |
249 | wpa_printf(MSG_ERROR, "No PSK on line %d in '%s'", |
250 | line, fname); | |
6fc6879b JM |
251 | os_free(psk); |
252 | ret = -1; | |
253 | break; | |
254 | } | |
255 | pos++; | |
256 | ||
257 | ok = 0; | |
258 | len = os_strlen(pos); | |
259 | if (len == 64 && hexstr2bin(pos, psk->psk, PMK_LEN) == 0) | |
260 | ok = 1; | |
261 | else if (len >= 8 && len < 64) { | |
262 | pbkdf2_sha1(pos, ssid->ssid, ssid->ssid_len, | |
263 | 4096, psk->psk, PMK_LEN); | |
264 | ok = 1; | |
265 | } | |
266 | if (!ok) { | |
10656fc2 JM |
267 | wpa_printf(MSG_ERROR, "Invalid PSK '%s' on line %d in " |
268 | "'%s'", pos, line, fname); | |
6fc6879b JM |
269 | os_free(psk); |
270 | ret = -1; | |
271 | break; | |
272 | } | |
273 | ||
274 | psk->next = ssid->wpa_psk; | |
275 | ssid->wpa_psk = psk; | |
276 | } | |
277 | ||
278 | fclose(f); | |
279 | ||
280 | return ret; | |
281 | } | |
282 | ||
283 | ||
0ae687bd JM |
284 | static int hostapd_derive_psk(struct hostapd_ssid *ssid) |
285 | { | |
286 | ssid->wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk)); | |
287 | if (ssid->wpa_psk == NULL) { | |
288 | wpa_printf(MSG_ERROR, "Unable to alloc space for PSK"); | |
289 | return -1; | |
290 | } | |
291 | wpa_hexdump_ascii(MSG_DEBUG, "SSID", | |
292 | (u8 *) ssid->ssid, ssid->ssid_len); | |
293 | wpa_hexdump_ascii_key(MSG_DEBUG, "PSK (ASCII passphrase)", | |
294 | (u8 *) ssid->wpa_passphrase, | |
295 | os_strlen(ssid->wpa_passphrase)); | |
296 | pbkdf2_sha1(ssid->wpa_passphrase, | |
297 | ssid->ssid, ssid->ssid_len, | |
298 | 4096, ssid->wpa_psk->psk, PMK_LEN); | |
299 | wpa_hexdump_key(MSG_DEBUG, "PSK (from passphrase)", | |
300 | ssid->wpa_psk->psk, PMK_LEN); | |
301 | return 0; | |
302 | } | |
303 | ||
304 | ||
6fc6879b JM |
305 | int hostapd_setup_wpa_psk(struct hostapd_bss_config *conf) |
306 | { | |
307 | struct hostapd_ssid *ssid = &conf->ssid; | |
308 | ||
309 | if (ssid->wpa_passphrase != NULL) { | |
310 | if (ssid->wpa_psk != NULL) { | |
0ae687bd JM |
311 | wpa_printf(MSG_DEBUG, "Using pre-configured WPA PSK " |
312 | "instead of passphrase"); | |
313 | } else { | |
314 | wpa_printf(MSG_DEBUG, "Deriving WPA PSK based on " | |
315 | "passphrase"); | |
316 | if (hostapd_derive_psk(ssid) < 0) | |
317 | return -1; | |
6fc6879b | 318 | } |
6fc6879b | 319 | ssid->wpa_psk->group = 1; |
6fc6879b JM |
320 | } |
321 | ||
322 | if (ssid->wpa_psk_file) { | |
323 | if (hostapd_config_read_wpa_psk(ssid->wpa_psk_file, | |
324 | &conf->ssid)) | |
325 | return -1; | |
326 | } | |
327 | ||
328 | return 0; | |
329 | } | |
330 | ||
331 | ||
6fc6879b JM |
332 | int hostapd_wep_key_cmp(struct hostapd_wep_keys *a, struct hostapd_wep_keys *b) |
333 | { | |
334 | int i; | |
335 | ||
336 | if (a->idx != b->idx || a->default_len != b->default_len) | |
337 | return 1; | |
338 | for (i = 0; i < NUM_WEP_KEYS; i++) | |
339 | if (a->len[i] != b->len[i] || | |
340 | os_memcmp(a->key[i], b->key[i], a->len[i]) != 0) | |
341 | return 1; | |
342 | return 0; | |
343 | } | |
344 | ||
345 | ||
346 | static void hostapd_config_free_radius(struct hostapd_radius_server *servers, | |
347 | int num_servers) | |
348 | { | |
349 | int i; | |
350 | ||
351 | for (i = 0; i < num_servers; i++) { | |
352 | os_free(servers[i].shared_secret); | |
353 | } | |
354 | os_free(servers); | |
355 | } | |
356 | ||
357 | ||
af35e7af JM |
358 | struct hostapd_radius_attr * |
359 | hostapd_config_get_radius_attr(struct hostapd_radius_attr *attr, u8 type) | |
360 | { | |
361 | for (; attr; attr = attr->next) { | |
362 | if (attr->type == type) | |
363 | return attr; | |
364 | } | |
365 | return NULL; | |
366 | } | |
367 | ||
368 | ||
369 | static void hostapd_config_free_radius_attr(struct hostapd_radius_attr *attr) | |
370 | { | |
371 | struct hostapd_radius_attr *prev; | |
372 | ||
373 | while (attr) { | |
374 | prev = attr; | |
375 | attr = attr->next; | |
376 | wpabuf_free(prev->val); | |
377 | os_free(prev); | |
378 | } | |
379 | } | |
380 | ||
381 | ||
6fc6879b JM |
382 | static void hostapd_config_free_eap_user(struct hostapd_eap_user *user) |
383 | { | |
384 | os_free(user->identity); | |
385 | os_free(user->password); | |
386 | os_free(user); | |
387 | } | |
388 | ||
389 | ||
390 | static void hostapd_config_free_wep(struct hostapd_wep_keys *keys) | |
391 | { | |
392 | int i; | |
393 | for (i = 0; i < NUM_WEP_KEYS; i++) { | |
394 | os_free(keys->key[i]); | |
395 | keys->key[i] = NULL; | |
396 | } | |
397 | } | |
398 | ||
399 | ||
400 | static void hostapd_config_free_bss(struct hostapd_bss_config *conf) | |
401 | { | |
402 | struct hostapd_wpa_psk *psk, *prev; | |
403 | struct hostapd_eap_user *user, *prev_user; | |
404 | ||
405 | if (conf == NULL) | |
406 | return; | |
407 | ||
408 | psk = conf->ssid.wpa_psk; | |
409 | while (psk) { | |
410 | prev = psk; | |
411 | psk = psk->next; | |
412 | os_free(prev); | |
413 | } | |
414 | ||
415 | os_free(conf->ssid.wpa_passphrase); | |
416 | os_free(conf->ssid.wpa_psk_file); | |
43dd46b3 | 417 | hostapd_config_free_wep(&conf->ssid.wep); |
6fc6879b JM |
418 | #ifdef CONFIG_FULL_DYNAMIC_VLAN |
419 | os_free(conf->ssid.vlan_tagged_interface); | |
420 | #endif /* CONFIG_FULL_DYNAMIC_VLAN */ | |
421 | ||
422 | user = conf->eap_user; | |
423 | while (user) { | |
424 | prev_user = user; | |
425 | user = user->next; | |
426 | hostapd_config_free_eap_user(prev_user); | |
427 | } | |
ee431d77 | 428 | os_free(conf->eap_user_sqlite); |
6fc6879b JM |
429 | |
430 | os_free(conf->dump_log_name); | |
431 | os_free(conf->eap_req_id_text); | |
432 | os_free(conf->accept_mac); | |
433 | os_free(conf->deny_mac); | |
434 | os_free(conf->nas_identifier); | |
435 | hostapd_config_free_radius(conf->radius->auth_servers, | |
436 | conf->radius->num_auth_servers); | |
437 | hostapd_config_free_radius(conf->radius->acct_servers, | |
438 | conf->radius->num_acct_servers); | |
af35e7af JM |
439 | hostapd_config_free_radius_attr(conf->radius_auth_req_attr); |
440 | hostapd_config_free_radius_attr(conf->radius_acct_req_attr); | |
6fc6879b JM |
441 | os_free(conf->rsn_preauth_interfaces); |
442 | os_free(conf->ctrl_interface); | |
443 | os_free(conf->ca_cert); | |
444 | os_free(conf->server_cert); | |
445 | os_free(conf->private_key); | |
446 | os_free(conf->private_key_passwd); | |
080585c0 | 447 | os_free(conf->ocsp_stapling_response); |
6fc6879b JM |
448 | os_free(conf->dh_file); |
449 | os_free(conf->pac_opaque_encr_key); | |
450 | os_free(conf->eap_fast_a_id); | |
2d867244 | 451 | os_free(conf->eap_fast_a_id_info); |
6fc6879b JM |
452 | os_free(conf->eap_sim_db); |
453 | os_free(conf->radius_server_clients); | |
454 | os_free(conf->test_socket); | |
455 | os_free(conf->radius); | |
b031338c | 456 | os_free(conf->radius_das_shared_secret); |
6fc6879b | 457 | hostapd_config_free_vlan(conf); |
39b97072 JM |
458 | os_free(conf->time_zone); |
459 | ||
6fc6879b JM |
460 | #ifdef CONFIG_IEEE80211R |
461 | { | |
462 | struct ft_remote_r0kh *r0kh, *r0kh_prev; | |
463 | struct ft_remote_r1kh *r1kh, *r1kh_prev; | |
464 | ||
465 | r0kh = conf->r0kh_list; | |
466 | conf->r0kh_list = NULL; | |
467 | while (r0kh) { | |
468 | r0kh_prev = r0kh; | |
469 | r0kh = r0kh->next; | |
470 | os_free(r0kh_prev); | |
471 | } | |
472 | ||
473 | r1kh = conf->r1kh_list; | |
474 | conf->r1kh_list = NULL; | |
475 | while (r1kh) { | |
476 | r1kh_prev = r1kh; | |
477 | r1kh = r1kh->next; | |
478 | os_free(r1kh_prev); | |
479 | } | |
480 | } | |
481 | #endif /* CONFIG_IEEE80211R */ | |
ad08c363 JM |
482 | |
483 | #ifdef CONFIG_WPS | |
484 | os_free(conf->wps_pin_requests); | |
485 | os_free(conf->device_name); | |
486 | os_free(conf->manufacturer); | |
487 | os_free(conf->model_name); | |
488 | os_free(conf->model_number); | |
489 | os_free(conf->serial_number); | |
ad08c363 JM |
490 | os_free(conf->config_methods); |
491 | os_free(conf->ap_pin); | |
62966253 | 492 | os_free(conf->extra_cred); |
4c29cae9 | 493 | os_free(conf->ap_settings); |
f620268f JM |
494 | os_free(conf->upnp_iface); |
495 | os_free(conf->friendly_name); | |
496 | os_free(conf->manufacturer_url); | |
497 | os_free(conf->model_description); | |
498 | os_free(conf->model_url); | |
499 | os_free(conf->upc); | |
ffdaa05a JM |
500 | wpabuf_free(conf->wps_nfc_dh_pubkey); |
501 | wpabuf_free(conf->wps_nfc_dh_privkey); | |
502 | wpabuf_free(conf->wps_nfc_dev_pw); | |
ad08c363 | 503 | #endif /* CONFIG_WPS */ |
4b2a77ab JM |
504 | |
505 | os_free(conf->roaming_consortium); | |
648cc711 | 506 | os_free(conf->venue_name); |
8047b186 | 507 | os_free(conf->nai_realm_data); |
550a3958 | 508 | os_free(conf->network_auth_type); |
7515adb2 | 509 | os_free(conf->anqp_3gpp_cell_net); |
26fac8b6 | 510 | os_free(conf->domain_name); |
505a3694 JM |
511 | |
512 | #ifdef CONFIG_RADIUS_TEST | |
513 | os_free(conf->dump_msk_file); | |
514 | #endif /* CONFIG_RADIUS_TEST */ | |
df5934f1 JK |
515 | |
516 | #ifdef CONFIG_HS20 | |
a9277e85 | 517 | os_free(conf->hs20_oper_friendly_name); |
4065a309 | 518 | os_free(conf->hs20_wan_metrics); |
5ccc54aa | 519 | os_free(conf->hs20_connection_capability); |
df5934f1 JK |
520 | os_free(conf->hs20_operating_class); |
521 | #endif /* CONFIG_HS20 */ | |
b52f084c JM |
522 | |
523 | wpabuf_free(conf->vendor_elements); | |
625f202a JM |
524 | |
525 | os_free(conf->sae_groups); | |
67fe933d JM |
526 | |
527 | os_free(conf->server_id); | |
6fc6879b JM |
528 | } |
529 | ||
530 | ||
1c6e69cc JM |
531 | /** |
532 | * hostapd_config_free - Free hostapd configuration | |
533 | * @conf: Configuration data from hostapd_config_read(). | |
534 | */ | |
6fc6879b JM |
535 | void hostapd_config_free(struct hostapd_config *conf) |
536 | { | |
537 | size_t i; | |
538 | ||
539 | if (conf == NULL) | |
540 | return; | |
541 | ||
542 | for (i = 0; i < conf->num_bss; i++) | |
543 | hostapd_config_free_bss(&conf->bss[i]); | |
544 | os_free(conf->bss); | |
79d6c85f JM |
545 | os_free(conf->supported_rates); |
546 | os_free(conf->basic_rates); | |
6fc6879b JM |
547 | |
548 | os_free(conf); | |
549 | } | |
550 | ||
551 | ||
1c6e69cc JM |
552 | /** |
553 | * hostapd_maclist_found - Find a MAC address from a list | |
554 | * @list: MAC address list | |
555 | * @num_entries: Number of addresses in the list | |
556 | * @addr: Address to search for | |
557 | * @vlan_id: Buffer for returning VLAN ID or %NULL if not needed | |
558 | * Returns: 1 if address is in the list or 0 if not. | |
559 | * | |
560 | * Perform a binary search for given MAC address from a pre-sorted list. | |
561 | */ | |
271d2830 JM |
562 | int hostapd_maclist_found(struct mac_acl_entry *list, int num_entries, |
563 | const u8 *addr, int *vlan_id) | |
6fc6879b JM |
564 | { |
565 | int start, end, middle, res; | |
566 | ||
567 | start = 0; | |
568 | end = num_entries - 1; | |
569 | ||
570 | while (start <= end) { | |
571 | middle = (start + end) / 2; | |
271d2830 JM |
572 | res = os_memcmp(list[middle].addr, addr, ETH_ALEN); |
573 | if (res == 0) { | |
574 | if (vlan_id) | |
575 | *vlan_id = list[middle].vlan_id; | |
6fc6879b | 576 | return 1; |
271d2830 | 577 | } |
6fc6879b JM |
578 | if (res < 0) |
579 | start = middle + 1; | |
580 | else | |
581 | end = middle - 1; | |
582 | } | |
583 | ||
584 | return 0; | |
585 | } | |
586 | ||
587 | ||
588 | int hostapd_rate_found(int *list, int rate) | |
589 | { | |
590 | int i; | |
591 | ||
592 | if (list == NULL) | |
593 | return 0; | |
594 | ||
595 | for (i = 0; list[i] >= 0; i++) | |
596 | if (list[i] == rate) | |
597 | return 1; | |
598 | ||
599 | return 0; | |
600 | } | |
601 | ||
602 | ||
80ebfd95 | 603 | int hostapd_vlan_id_valid(struct hostapd_vlan *vlan, int vlan_id) |
6fc6879b JM |
604 | { |
605 | struct hostapd_vlan *v = vlan; | |
606 | while (v) { | |
607 | if (v->vlan_id == vlan_id || v->vlan_id == VLAN_ID_WILDCARD) | |
80ebfd95 MB |
608 | return 1; |
609 | v = v->next; | |
610 | } | |
611 | return 0; | |
612 | } | |
613 | ||
614 | ||
615 | const char * hostapd_get_vlan_id_ifname(struct hostapd_vlan *vlan, int vlan_id) | |
616 | { | |
617 | struct hostapd_vlan *v = vlan; | |
618 | while (v) { | |
619 | if (v->vlan_id == vlan_id) | |
6fc6879b JM |
620 | return v->ifname; |
621 | v = v->next; | |
622 | } | |
623 | return NULL; | |
624 | } | |
625 | ||
626 | ||
627 | const u8 * hostapd_get_psk(const struct hostapd_bss_config *conf, | |
628 | const u8 *addr, const u8 *prev_psk) | |
629 | { | |
630 | struct hostapd_wpa_psk *psk; | |
631 | int next_ok = prev_psk == NULL; | |
632 | ||
633 | for (psk = conf->ssid.wpa_psk; psk != NULL; psk = psk->next) { | |
634 | if (next_ok && | |
635 | (psk->group || os_memcmp(psk->addr, addr, ETH_ALEN) == 0)) | |
636 | return psk->psk; | |
637 | ||
638 | if (psk->psk == prev_psk) | |
639 | next_ok = 1; | |
640 | } | |
641 | ||
642 | return NULL; | |
643 | } |