]>
Commit | Line | Data |
---|---|---|
6fc6879b JM |
1 | /* |
2 | * hostapd / Configuration file | |
5d22a1d5 | 3 | * Copyright (c) 2003-2008, Jouni Malinen <j@w1.fi> |
71b6ae14 | 4 | * Copyright (c) 2007-2008, Intel Corporation |
6fc6879b JM |
5 | * |
6 | * This program is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License version 2 as | |
8 | * published by the Free Software Foundation. | |
9 | * | |
10 | * Alternatively, this software may be distributed under the terms of BSD | |
11 | * license. | |
12 | * | |
13 | * See README and COPYING for more details. | |
14 | */ | |
15 | ||
16 | #include "includes.h" | |
17 | #ifndef CONFIG_NATIVE_WINDOWS | |
18 | #include <grp.h> | |
19 | #endif /* CONFIG_NATIVE_WINDOWS */ | |
20 | ||
21 | #include "hostapd.h" | |
22 | #include "driver.h" | |
23 | #include "sha1.h" | |
24 | #include "eap_server/eap.h" | |
25 | #include "radius/radius_client.h" | |
26 | #include "wpa_common.h" | |
27 | #include "wpa.h" | |
28 | #include "uuid.h" | |
ad08c363 | 29 | #include "eap_common/eap_wsc_common.h" |
6fc6879b JM |
30 | |
31 | ||
32 | #define MAX_STA_COUNT 2007 | |
33 | ||
34 | extern struct wpa_driver_ops *hostapd_drivers[]; | |
35 | ||
36 | ||
37 | static int hostapd_config_read_vlan_file(struct hostapd_bss_config *bss, | |
38 | const char *fname) | |
39 | { | |
40 | FILE *f; | |
41 | char buf[128], *pos, *pos2; | |
42 | int line = 0, vlan_id; | |
43 | struct hostapd_vlan *vlan; | |
44 | ||
45 | f = fopen(fname, "r"); | |
46 | if (!f) { | |
10656fc2 | 47 | wpa_printf(MSG_ERROR, "VLAN file '%s' not readable.", fname); |
6fc6879b JM |
48 | return -1; |
49 | } | |
50 | ||
51 | while (fgets(buf, sizeof(buf), f)) { | |
52 | line++; | |
53 | ||
54 | if (buf[0] == '#') | |
55 | continue; | |
56 | pos = buf; | |
57 | while (*pos != '\0') { | |
58 | if (*pos == '\n') { | |
59 | *pos = '\0'; | |
60 | break; | |
61 | } | |
62 | pos++; | |
63 | } | |
64 | if (buf[0] == '\0') | |
65 | continue; | |
66 | ||
67 | if (buf[0] == '*') { | |
68 | vlan_id = VLAN_ID_WILDCARD; | |
69 | pos = buf + 1; | |
70 | } else { | |
71 | vlan_id = strtol(buf, &pos, 10); | |
72 | if (buf == pos || vlan_id < 1 || | |
73 | vlan_id > MAX_VLAN_ID) { | |
10656fc2 JM |
74 | wpa_printf(MSG_ERROR, "Invalid VLAN ID at " |
75 | "line %d in '%s'", line, fname); | |
6fc6879b JM |
76 | fclose(f); |
77 | return -1; | |
78 | } | |
79 | } | |
80 | ||
81 | while (*pos == ' ' || *pos == '\t') | |
82 | pos++; | |
83 | pos2 = pos; | |
84 | while (*pos2 != ' ' && *pos2 != '\t' && *pos2 != '\0') | |
85 | pos2++; | |
86 | *pos2 = '\0'; | |
87 | if (*pos == '\0' || os_strlen(pos) > IFNAMSIZ) { | |
10656fc2 JM |
88 | wpa_printf(MSG_ERROR, "Invalid VLAN ifname at line %d " |
89 | "in '%s'", line, fname); | |
6fc6879b JM |
90 | fclose(f); |
91 | return -1; | |
92 | } | |
93 | ||
94 | vlan = os_malloc(sizeof(*vlan)); | |
95 | if (vlan == NULL) { | |
10656fc2 JM |
96 | wpa_printf(MSG_ERROR, "Out of memory while reading " |
97 | "VLAN interfaces from '%s'", fname); | |
6fc6879b JM |
98 | fclose(f); |
99 | return -1; | |
100 | } | |
101 | ||
102 | os_memset(vlan, 0, sizeof(*vlan)); | |
103 | vlan->vlan_id = vlan_id; | |
104 | os_strlcpy(vlan->ifname, pos, sizeof(vlan->ifname)); | |
105 | if (bss->vlan_tail) | |
106 | bss->vlan_tail->next = vlan; | |
107 | else | |
108 | bss->vlan = vlan; | |
109 | bss->vlan_tail = vlan; | |
110 | } | |
111 | ||
112 | fclose(f); | |
113 | ||
114 | return 0; | |
115 | } | |
116 | ||
117 | ||
118 | static void hostapd_config_free_vlan(struct hostapd_bss_config *bss) | |
119 | { | |
120 | struct hostapd_vlan *vlan, *prev; | |
121 | ||
122 | vlan = bss->vlan; | |
123 | prev = NULL; | |
124 | while (vlan) { | |
125 | prev = vlan; | |
126 | vlan = vlan->next; | |
127 | os_free(prev); | |
128 | } | |
129 | ||
130 | bss->vlan = NULL; | |
131 | } | |
132 | ||
133 | ||
134 | /* convert floats with one decimal place to value*10 int, i.e., | |
135 | * "1.5" will return 15 */ | |
136 | static int hostapd_config_read_int10(const char *value) | |
137 | { | |
138 | int i, d; | |
139 | char *pos; | |
140 | ||
141 | i = atoi(value); | |
142 | pos = os_strchr(value, '.'); | |
143 | d = 0; | |
144 | if (pos) { | |
145 | pos++; | |
146 | if (*pos >= '0' && *pos <= '9') | |
147 | d = *pos - '0'; | |
148 | } | |
149 | ||
150 | return i * 10 + d; | |
151 | } | |
152 | ||
153 | ||
154 | static void hostapd_config_defaults_bss(struct hostapd_bss_config *bss) | |
155 | { | |
156 | bss->logger_syslog_level = HOSTAPD_LEVEL_INFO; | |
157 | bss->logger_stdout_level = HOSTAPD_LEVEL_INFO; | |
158 | bss->logger_syslog = (unsigned int) -1; | |
159 | bss->logger_stdout = (unsigned int) -1; | |
160 | ||
161 | bss->auth_algs = WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED; | |
162 | ||
163 | bss->wep_rekeying_period = 300; | |
164 | /* use key0 in individual key and key1 in broadcast key */ | |
165 | bss->broadcast_key_idx_min = 1; | |
166 | bss->broadcast_key_idx_max = 2; | |
167 | bss->eap_reauth_period = 3600; | |
168 | ||
169 | bss->wpa_group_rekey = 600; | |
170 | bss->wpa_gmk_rekey = 86400; | |
171 | bss->wpa_key_mgmt = WPA_KEY_MGMT_PSK; | |
172 | bss->wpa_pairwise = WPA_CIPHER_TKIP; | |
173 | bss->wpa_group = WPA_CIPHER_TKIP; | |
174 | bss->rsn_pairwise = 0; | |
175 | ||
176 | bss->max_num_sta = MAX_STA_COUNT; | |
177 | ||
178 | bss->dtim_period = 2; | |
179 | ||
180 | bss->radius_server_auth_port = 1812; | |
181 | bss->ap_max_inactivity = AP_MAX_INACTIVITY; | |
182 | bss->eapol_version = EAPOL_VERSION; | |
b0194fe0 JM |
183 | |
184 | bss->max_listen_interval = 65535; | |
5d22a1d5 JM |
185 | |
186 | #ifdef CONFIG_IEEE80211W | |
45c94154 JM |
187 | bss->assoc_sa_query_max_timeout = 1000; |
188 | bss->assoc_sa_query_retry_timeout = 201; | |
5d22a1d5 | 189 | #endif /* CONFIG_IEEE80211W */ |
378eae5e JM |
190 | #ifdef EAP_FAST |
191 | /* both anonymous and authenticated provisioning */ | |
192 | bss->eap_fast_prov = 3; | |
a11c90a6 JM |
193 | bss->pac_key_lifetime = 7 * 24 * 60 * 60; |
194 | bss->pac_key_refresh_time = 1 * 24 * 60 * 60; | |
378eae5e | 195 | #endif /* EAP_FAST */ |
6fc6879b JM |
196 | } |
197 | ||
198 | ||
199 | static struct hostapd_config * hostapd_config_defaults(void) | |
200 | { | |
201 | struct hostapd_config *conf; | |
202 | struct hostapd_bss_config *bss; | |
203 | int i; | |
204 | const int aCWmin = 15, aCWmax = 1024; | |
205 | const struct hostapd_wme_ac_params ac_bk = | |
206 | { aCWmin, aCWmax, 7, 0, 0 }; /* background traffic */ | |
207 | const struct hostapd_wme_ac_params ac_be = | |
208 | { aCWmin, aCWmax, 3, 0, 0 }; /* best effort traffic */ | |
209 | const struct hostapd_wme_ac_params ac_vi = /* video traffic */ | |
210 | { aCWmin >> 1, aCWmin, 2, 3000 / 32, 1 }; | |
211 | const struct hostapd_wme_ac_params ac_vo = /* voice traffic */ | |
212 | { aCWmin >> 2, aCWmin >> 1, 2, 1500 / 32, 1 }; | |
213 | ||
214 | conf = os_zalloc(sizeof(*conf)); | |
215 | bss = os_zalloc(sizeof(*bss)); | |
216 | if (conf == NULL || bss == NULL) { | |
10656fc2 JM |
217 | wpa_printf(MSG_ERROR, "Failed to allocate memory for " |
218 | "configuration data."); | |
6fc6879b JM |
219 | os_free(conf); |
220 | os_free(bss); | |
221 | return NULL; | |
222 | } | |
223 | ||
224 | /* set default driver based on configuration */ | |
225 | conf->driver = hostapd_drivers[0]; | |
226 | if (conf->driver == NULL) { | |
10656fc2 | 227 | wpa_printf(MSG_ERROR, "No driver wrappers registered!"); |
6fc6879b JM |
228 | os_free(conf); |
229 | os_free(bss); | |
230 | return NULL; | |
231 | } | |
232 | ||
233 | bss->radius = os_zalloc(sizeof(*bss->radius)); | |
234 | if (bss->radius == NULL) { | |
235 | os_free(conf); | |
236 | os_free(bss); | |
237 | return NULL; | |
238 | } | |
239 | ||
240 | hostapd_config_defaults_bss(bss); | |
241 | ||
242 | conf->num_bss = 1; | |
243 | conf->bss = bss; | |
244 | ||
245 | conf->beacon_int = 100; | |
246 | conf->rts_threshold = -1; /* use driver default: 2347 */ | |
247 | conf->fragm_threshold = -1; /* user driver default: 2346 */ | |
248 | conf->send_probe_response = 1; | |
249 | conf->bridge_packets = INTERNAL_BRIDGE_DO_NOT_CONTROL; | |
250 | ||
251 | os_memcpy(conf->country, "US ", 3); | |
252 | ||
253 | for (i = 0; i < NUM_TX_QUEUES; i++) | |
254 | conf->tx_queue[i].aifs = -1; /* use hw default */ | |
255 | ||
256 | conf->wme_ac_params[0] = ac_be; | |
257 | conf->wme_ac_params[1] = ac_bk; | |
258 | conf->wme_ac_params[2] = ac_vi; | |
259 | conf->wme_ac_params[3] = ac_vo; | |
260 | ||
de9289c8 | 261 | #ifdef CONFIG_IEEE80211N |
fc14f567 | 262 | conf->ht_capab = HT_CAP_INFO_SMPS_DISABLED; |
de9289c8 JM |
263 | #endif /* CONFIG_IEEE80211N */ |
264 | ||
6fc6879b JM |
265 | return conf; |
266 | } | |
267 | ||
268 | ||
269 | int hostapd_mac_comp(const void *a, const void *b) | |
270 | { | |
271 | return os_memcmp(a, b, sizeof(macaddr)); | |
272 | } | |
273 | ||
274 | ||
275 | int hostapd_mac_comp_empty(const void *a) | |
276 | { | |
277 | macaddr empty = { 0 }; | |
278 | return os_memcmp(a, empty, sizeof(macaddr)); | |
279 | } | |
280 | ||
281 | ||
271d2830 JM |
282 | static int hostapd_acl_comp(const void *a, const void *b) |
283 | { | |
284 | const struct mac_acl_entry *aa = a; | |
285 | const struct mac_acl_entry *bb = b; | |
286 | return os_memcmp(aa->addr, bb->addr, sizeof(macaddr)); | |
287 | } | |
288 | ||
289 | ||
290 | static int hostapd_config_read_maclist(const char *fname, | |
291 | struct mac_acl_entry **acl, int *num) | |
6fc6879b JM |
292 | { |
293 | FILE *f; | |
294 | char buf[128], *pos; | |
295 | int line = 0; | |
296 | u8 addr[ETH_ALEN]; | |
271d2830 JM |
297 | struct mac_acl_entry *newacl; |
298 | int vlan_id; | |
6fc6879b JM |
299 | |
300 | if (!fname) | |
301 | return 0; | |
302 | ||
303 | f = fopen(fname, "r"); | |
304 | if (!f) { | |
10656fc2 | 305 | wpa_printf(MSG_ERROR, "MAC list file '%s' not found.", fname); |
6fc6879b JM |
306 | return -1; |
307 | } | |
308 | ||
309 | while (fgets(buf, sizeof(buf), f)) { | |
310 | line++; | |
311 | ||
312 | if (buf[0] == '#') | |
313 | continue; | |
314 | pos = buf; | |
315 | while (*pos != '\0') { | |
316 | if (*pos == '\n') { | |
317 | *pos = '\0'; | |
318 | break; | |
319 | } | |
320 | pos++; | |
321 | } | |
322 | if (buf[0] == '\0') | |
323 | continue; | |
324 | ||
325 | if (hwaddr_aton(buf, addr)) { | |
10656fc2 JM |
326 | wpa_printf(MSG_ERROR, "Invalid MAC address '%s' at " |
327 | "line %d in '%s'", buf, line, fname); | |
6fc6879b JM |
328 | fclose(f); |
329 | return -1; | |
330 | } | |
331 | ||
271d2830 JM |
332 | vlan_id = 0; |
333 | pos = buf; | |
334 | while (*pos != '\0' && *pos != ' ' && *pos != '\t') | |
335 | pos++; | |
336 | while (*pos == ' ' || *pos == '\t') | |
337 | pos++; | |
338 | if (*pos != '\0') | |
339 | vlan_id = atoi(pos); | |
340 | ||
341 | newacl = os_realloc(*acl, (*num + 1) * sizeof(**acl)); | |
6fc6879b | 342 | if (newacl == NULL) { |
10656fc2 | 343 | wpa_printf(MSG_ERROR, "MAC list reallocation failed"); |
6fc6879b JM |
344 | fclose(f); |
345 | return -1; | |
346 | } | |
347 | ||
348 | *acl = newacl; | |
271d2830 JM |
349 | os_memcpy((*acl)[*num].addr, addr, ETH_ALEN); |
350 | (*acl)[*num].vlan_id = vlan_id; | |
6fc6879b JM |
351 | (*num)++; |
352 | } | |
353 | ||
354 | fclose(f); | |
355 | ||
271d2830 | 356 | qsort(*acl, *num, sizeof(**acl), hostapd_acl_comp); |
6fc6879b JM |
357 | |
358 | return 0; | |
359 | } | |
360 | ||
361 | ||
362 | static int hostapd_config_read_wpa_psk(const char *fname, | |
363 | struct hostapd_ssid *ssid) | |
364 | { | |
365 | FILE *f; | |
366 | char buf[128], *pos; | |
367 | int line = 0, ret = 0, len, ok; | |
368 | u8 addr[ETH_ALEN]; | |
369 | struct hostapd_wpa_psk *psk; | |
370 | ||
371 | if (!fname) | |
372 | return 0; | |
373 | ||
374 | f = fopen(fname, "r"); | |
375 | if (!f) { | |
10656fc2 | 376 | wpa_printf(MSG_ERROR, "WPA PSK file '%s' not found.", fname); |
6fc6879b JM |
377 | return -1; |
378 | } | |
379 | ||
380 | while (fgets(buf, sizeof(buf), f)) { | |
381 | line++; | |
382 | ||
383 | if (buf[0] == '#') | |
384 | continue; | |
385 | pos = buf; | |
386 | while (*pos != '\0') { | |
387 | if (*pos == '\n') { | |
388 | *pos = '\0'; | |
389 | break; | |
390 | } | |
391 | pos++; | |
392 | } | |
393 | if (buf[0] == '\0') | |
394 | continue; | |
395 | ||
396 | if (hwaddr_aton(buf, addr)) { | |
10656fc2 JM |
397 | wpa_printf(MSG_ERROR, "Invalid MAC address '%s' on " |
398 | "line %d in '%s'", buf, line, fname); | |
6fc6879b JM |
399 | ret = -1; |
400 | break; | |
401 | } | |
402 | ||
403 | psk = os_zalloc(sizeof(*psk)); | |
404 | if (psk == NULL) { | |
10656fc2 | 405 | wpa_printf(MSG_ERROR, "WPA PSK allocation failed"); |
6fc6879b JM |
406 | ret = -1; |
407 | break; | |
408 | } | |
a8e16edc | 409 | if (is_zero_ether_addr(addr)) |
6fc6879b JM |
410 | psk->group = 1; |
411 | else | |
412 | os_memcpy(psk->addr, addr, ETH_ALEN); | |
413 | ||
414 | pos = buf + 17; | |
5306f43f | 415 | if (*pos == '\0') { |
10656fc2 JM |
416 | wpa_printf(MSG_ERROR, "No PSK on line %d in '%s'", |
417 | line, fname); | |
6fc6879b JM |
418 | os_free(psk); |
419 | ret = -1; | |
420 | break; | |
421 | } | |
422 | pos++; | |
423 | ||
424 | ok = 0; | |
425 | len = os_strlen(pos); | |
426 | if (len == 64 && hexstr2bin(pos, psk->psk, PMK_LEN) == 0) | |
427 | ok = 1; | |
428 | else if (len >= 8 && len < 64) { | |
429 | pbkdf2_sha1(pos, ssid->ssid, ssid->ssid_len, | |
430 | 4096, psk->psk, PMK_LEN); | |
431 | ok = 1; | |
432 | } | |
433 | if (!ok) { | |
10656fc2 JM |
434 | wpa_printf(MSG_ERROR, "Invalid PSK '%s' on line %d in " |
435 | "'%s'", pos, line, fname); | |
6fc6879b JM |
436 | os_free(psk); |
437 | ret = -1; | |
438 | break; | |
439 | } | |
440 | ||
441 | psk->next = ssid->wpa_psk; | |
442 | ssid->wpa_psk = psk; | |
443 | } | |
444 | ||
445 | fclose(f); | |
446 | ||
447 | return ret; | |
448 | } | |
449 | ||
450 | ||
451 | int hostapd_setup_wpa_psk(struct hostapd_bss_config *conf) | |
452 | { | |
453 | struct hostapd_ssid *ssid = &conf->ssid; | |
454 | ||
455 | if (ssid->wpa_passphrase != NULL) { | |
456 | if (ssid->wpa_psk != NULL) { | |
10656fc2 JM |
457 | wpa_printf(MSG_ERROR, "Warning: both WPA PSK and " |
458 | "passphrase set. Using passphrase."); | |
6fc6879b JM |
459 | os_free(ssid->wpa_psk); |
460 | } | |
461 | ssid->wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk)); | |
462 | if (ssid->wpa_psk == NULL) { | |
10656fc2 | 463 | wpa_printf(MSG_ERROR, "Unable to alloc space for PSK"); |
6fc6879b JM |
464 | return -1; |
465 | } | |
466 | wpa_hexdump_ascii(MSG_DEBUG, "SSID", | |
467 | (u8 *) ssid->ssid, ssid->ssid_len); | |
468 | wpa_hexdump_ascii(MSG_DEBUG, "PSK (ASCII passphrase)", | |
469 | (u8 *) ssid->wpa_passphrase, | |
470 | os_strlen(ssid->wpa_passphrase)); | |
471 | pbkdf2_sha1(ssid->wpa_passphrase, | |
472 | ssid->ssid, ssid->ssid_len, | |
473 | 4096, ssid->wpa_psk->psk, PMK_LEN); | |
474 | wpa_hexdump(MSG_DEBUG, "PSK (from passphrase)", | |
475 | ssid->wpa_psk->psk, PMK_LEN); | |
476 | ssid->wpa_psk->group = 1; | |
477 | ||
478 | os_memset(ssid->wpa_passphrase, 0, | |
479 | os_strlen(ssid->wpa_passphrase)); | |
480 | os_free(ssid->wpa_passphrase); | |
481 | ssid->wpa_passphrase = NULL; | |
482 | } | |
483 | ||
484 | if (ssid->wpa_psk_file) { | |
485 | if (hostapd_config_read_wpa_psk(ssid->wpa_psk_file, | |
486 | &conf->ssid)) | |
487 | return -1; | |
488 | } | |
489 | ||
490 | return 0; | |
491 | } | |
492 | ||
493 | ||
494 | #ifdef EAP_SERVER | |
495 | static int hostapd_config_read_eap_user(const char *fname, | |
496 | struct hostapd_bss_config *conf) | |
497 | { | |
498 | FILE *f; | |
499 | char buf[512], *pos, *start, *pos2; | |
500 | int line = 0, ret = 0, num_methods; | |
501 | struct hostapd_eap_user *user, *tail = NULL; | |
502 | ||
503 | if (!fname) | |
504 | return 0; | |
505 | ||
506 | f = fopen(fname, "r"); | |
507 | if (!f) { | |
10656fc2 | 508 | wpa_printf(MSG_ERROR, "EAP user file '%s' not found.", fname); |
6fc6879b JM |
509 | return -1; |
510 | } | |
511 | ||
512 | /* Lines: "user" METHOD,METHOD2 "password" (password optional) */ | |
513 | while (fgets(buf, sizeof(buf), f)) { | |
514 | line++; | |
515 | ||
516 | if (buf[0] == '#') | |
517 | continue; | |
518 | pos = buf; | |
519 | while (*pos != '\0') { | |
520 | if (*pos == '\n') { | |
521 | *pos = '\0'; | |
522 | break; | |
523 | } | |
524 | pos++; | |
525 | } | |
526 | if (buf[0] == '\0') | |
527 | continue; | |
528 | ||
529 | user = NULL; | |
530 | ||
531 | if (buf[0] != '"' && buf[0] != '*') { | |
10656fc2 JM |
532 | wpa_printf(MSG_ERROR, "Invalid EAP identity (no \" in " |
533 | "start) on line %d in '%s'", line, fname); | |
6fc6879b JM |
534 | goto failed; |
535 | } | |
536 | ||
537 | user = os_zalloc(sizeof(*user)); | |
538 | if (user == NULL) { | |
10656fc2 | 539 | wpa_printf(MSG_ERROR, "EAP user allocation failed"); |
6fc6879b JM |
540 | goto failed; |
541 | } | |
542 | user->force_version = -1; | |
543 | ||
544 | if (buf[0] == '*') { | |
545 | pos = buf; | |
546 | } else { | |
547 | pos = buf + 1; | |
548 | start = pos; | |
549 | while (*pos != '"' && *pos != '\0') | |
550 | pos++; | |
551 | if (*pos == '\0') { | |
10656fc2 JM |
552 | wpa_printf(MSG_ERROR, "Invalid EAP identity " |
553 | "(no \" in end) on line %d in '%s'", | |
554 | line, fname); | |
6fc6879b JM |
555 | goto failed; |
556 | } | |
557 | ||
558 | user->identity = os_malloc(pos - start); | |
559 | if (user->identity == NULL) { | |
10656fc2 JM |
560 | wpa_printf(MSG_ERROR, "Failed to allocate " |
561 | "memory for EAP identity"); | |
6fc6879b JM |
562 | goto failed; |
563 | } | |
564 | os_memcpy(user->identity, start, pos - start); | |
565 | user->identity_len = pos - start; | |
566 | ||
567 | if (pos[0] == '"' && pos[1] == '*') { | |
568 | user->wildcard_prefix = 1; | |
569 | pos++; | |
570 | } | |
571 | } | |
572 | pos++; | |
573 | while (*pos == ' ' || *pos == '\t') | |
574 | pos++; | |
575 | ||
576 | if (*pos == '\0') { | |
10656fc2 JM |
577 | wpa_printf(MSG_ERROR, "No EAP method on line %d in " |
578 | "'%s'", line, fname); | |
6fc6879b JM |
579 | goto failed; |
580 | } | |
581 | ||
582 | start = pos; | |
583 | while (*pos != ' ' && *pos != '\t' && *pos != '\0') | |
584 | pos++; | |
585 | if (*pos == '\0') { | |
586 | pos = NULL; | |
587 | } else { | |
588 | *pos = '\0'; | |
589 | pos++; | |
590 | } | |
591 | num_methods = 0; | |
592 | while (*start) { | |
593 | char *pos3 = os_strchr(start, ','); | |
594 | if (pos3) { | |
595 | *pos3++ = '\0'; | |
596 | } | |
597 | user->methods[num_methods].method = | |
598 | eap_server_get_type( | |
599 | start, | |
600 | &user->methods[num_methods].vendor); | |
601 | if (user->methods[num_methods].vendor == | |
602 | EAP_VENDOR_IETF && | |
603 | user->methods[num_methods].method == EAP_TYPE_NONE) | |
604 | { | |
605 | if (os_strcmp(start, "TTLS-PAP") == 0) { | |
606 | user->ttls_auth |= EAP_TTLS_AUTH_PAP; | |
607 | goto skip_eap; | |
608 | } | |
609 | if (os_strcmp(start, "TTLS-CHAP") == 0) { | |
610 | user->ttls_auth |= EAP_TTLS_AUTH_CHAP; | |
611 | goto skip_eap; | |
612 | } | |
613 | if (os_strcmp(start, "TTLS-MSCHAP") == 0) { | |
614 | user->ttls_auth |= | |
615 | EAP_TTLS_AUTH_MSCHAP; | |
616 | goto skip_eap; | |
617 | } | |
618 | if (os_strcmp(start, "TTLS-MSCHAPV2") == 0) { | |
619 | user->ttls_auth |= | |
620 | EAP_TTLS_AUTH_MSCHAPV2; | |
621 | goto skip_eap; | |
622 | } | |
10656fc2 JM |
623 | wpa_printf(MSG_ERROR, "Unsupported EAP type " |
624 | "'%s' on line %d in '%s'", | |
625 | start, line, fname); | |
6fc6879b JM |
626 | goto failed; |
627 | } | |
628 | ||
629 | num_methods++; | |
630 | if (num_methods >= EAP_USER_MAX_METHODS) | |
631 | break; | |
632 | skip_eap: | |
633 | if (pos3 == NULL) | |
634 | break; | |
635 | start = pos3; | |
636 | } | |
637 | if (num_methods == 0 && user->ttls_auth == 0) { | |
10656fc2 JM |
638 | wpa_printf(MSG_ERROR, "No EAP types configured on " |
639 | "line %d in '%s'", line, fname); | |
6fc6879b JM |
640 | goto failed; |
641 | } | |
642 | ||
643 | if (pos == NULL) | |
644 | goto done; | |
645 | ||
646 | while (*pos == ' ' || *pos == '\t') | |
647 | pos++; | |
648 | if (*pos == '\0') | |
649 | goto done; | |
650 | ||
651 | if (os_strncmp(pos, "[ver=0]", 7) == 0) { | |
652 | user->force_version = 0; | |
653 | goto done; | |
654 | } | |
655 | ||
656 | if (os_strncmp(pos, "[ver=1]", 7) == 0) { | |
657 | user->force_version = 1; | |
658 | goto done; | |
659 | } | |
660 | ||
661 | if (os_strncmp(pos, "[2]", 3) == 0) { | |
662 | user->phase2 = 1; | |
663 | goto done; | |
664 | } | |
665 | ||
666 | if (*pos == '"') { | |
667 | pos++; | |
668 | start = pos; | |
669 | while (*pos != '"' && *pos != '\0') | |
670 | pos++; | |
671 | if (*pos == '\0') { | |
10656fc2 JM |
672 | wpa_printf(MSG_ERROR, "Invalid EAP password " |
673 | "(no \" in end) on line %d in '%s'", | |
674 | line, fname); | |
6fc6879b JM |
675 | goto failed; |
676 | } | |
677 | ||
678 | user->password = os_malloc(pos - start); | |
679 | if (user->password == NULL) { | |
10656fc2 JM |
680 | wpa_printf(MSG_ERROR, "Failed to allocate " |
681 | "memory for EAP password"); | |
6fc6879b JM |
682 | goto failed; |
683 | } | |
684 | os_memcpy(user->password, start, pos - start); | |
685 | user->password_len = pos - start; | |
686 | ||
687 | pos++; | |
688 | } else if (os_strncmp(pos, "hash:", 5) == 0) { | |
689 | pos += 5; | |
690 | pos2 = pos; | |
691 | while (*pos2 != '\0' && *pos2 != ' ' && | |
692 | *pos2 != '\t' && *pos2 != '#') | |
693 | pos2++; | |
694 | if (pos2 - pos != 32) { | |
10656fc2 JM |
695 | wpa_printf(MSG_ERROR, "Invalid password hash " |
696 | "on line %d in '%s'", line, fname); | |
6fc6879b JM |
697 | goto failed; |
698 | } | |
699 | user->password = os_malloc(16); | |
700 | if (user->password == NULL) { | |
10656fc2 JM |
701 | wpa_printf(MSG_ERROR, "Failed to allocate " |
702 | "memory for EAP password hash"); | |
6fc6879b JM |
703 | goto failed; |
704 | } | |
705 | if (hexstr2bin(pos, user->password, 16) < 0) { | |
10656fc2 JM |
706 | wpa_printf(MSG_ERROR, "Invalid hash password " |
707 | "on line %d in '%s'", line, fname); | |
6fc6879b JM |
708 | goto failed; |
709 | } | |
710 | user->password_len = 16; | |
711 | user->password_hash = 1; | |
712 | pos = pos2; | |
713 | } else { | |
714 | pos2 = pos; | |
715 | while (*pos2 != '\0' && *pos2 != ' ' && | |
716 | *pos2 != '\t' && *pos2 != '#') | |
717 | pos2++; | |
718 | if ((pos2 - pos) & 1) { | |
10656fc2 JM |
719 | wpa_printf(MSG_ERROR, "Invalid hex password " |
720 | "on line %d in '%s'", line, fname); | |
6fc6879b JM |
721 | goto failed; |
722 | } | |
723 | user->password = os_malloc((pos2 - pos) / 2); | |
724 | if (user->password == NULL) { | |
10656fc2 JM |
725 | wpa_printf(MSG_ERROR, "Failed to allocate " |
726 | "memory for EAP password"); | |
6fc6879b JM |
727 | goto failed; |
728 | } | |
729 | if (hexstr2bin(pos, user->password, | |
730 | (pos2 - pos) / 2) < 0) { | |
10656fc2 JM |
731 | wpa_printf(MSG_ERROR, "Invalid hex password " |
732 | "on line %d in '%s'", line, fname); | |
6fc6879b JM |
733 | goto failed; |
734 | } | |
735 | user->password_len = (pos2 - pos) / 2; | |
736 | pos = pos2; | |
737 | } | |
738 | ||
739 | while (*pos == ' ' || *pos == '\t') | |
740 | pos++; | |
741 | if (os_strncmp(pos, "[2]", 3) == 0) { | |
742 | user->phase2 = 1; | |
743 | } | |
744 | ||
745 | done: | |
746 | if (tail == NULL) { | |
747 | tail = conf->eap_user = user; | |
748 | } else { | |
749 | tail->next = user; | |
750 | tail = user; | |
751 | } | |
752 | continue; | |
753 | ||
754 | failed: | |
755 | if (user) { | |
756 | os_free(user->password); | |
757 | os_free(user->identity); | |
758 | os_free(user); | |
759 | } | |
760 | ret = -1; | |
761 | break; | |
762 | } | |
763 | ||
764 | fclose(f); | |
765 | ||
766 | return ret; | |
767 | } | |
768 | #endif /* EAP_SERVER */ | |
769 | ||
770 | ||
771 | static int | |
772 | hostapd_config_read_radius_addr(struct hostapd_radius_server **server, | |
773 | int *num_server, const char *val, int def_port, | |
774 | struct hostapd_radius_server **curr_serv) | |
775 | { | |
776 | struct hostapd_radius_server *nserv; | |
777 | int ret; | |
778 | static int server_index = 1; | |
779 | ||
780 | nserv = os_realloc(*server, (*num_server + 1) * sizeof(*nserv)); | |
781 | if (nserv == NULL) | |
782 | return -1; | |
783 | ||
784 | *server = nserv; | |
785 | nserv = &nserv[*num_server]; | |
786 | (*num_server)++; | |
787 | (*curr_serv) = nserv; | |
788 | ||
789 | os_memset(nserv, 0, sizeof(*nserv)); | |
790 | nserv->port = def_port; | |
791 | ret = hostapd_parse_ip_addr(val, &nserv->addr); | |
792 | nserv->index = server_index++; | |
793 | ||
794 | return ret; | |
795 | } | |
796 | ||
797 | ||
798 | static int hostapd_config_parse_key_mgmt(int line, const char *value) | |
799 | { | |
800 | int val = 0, last; | |
801 | char *start, *end, *buf; | |
802 | ||
803 | buf = os_strdup(value); | |
804 | if (buf == NULL) | |
805 | return -1; | |
806 | start = buf; | |
807 | ||
5306f43f | 808 | while (*start != '\0') { |
6fc6879b JM |
809 | while (*start == ' ' || *start == '\t') |
810 | start++; | |
811 | if (*start == '\0') | |
812 | break; | |
813 | end = start; | |
814 | while (*end != ' ' && *end != '\t' && *end != '\0') | |
815 | end++; | |
816 | last = *end == '\0'; | |
817 | *end = '\0'; | |
818 | if (os_strcmp(start, "WPA-PSK") == 0) | |
819 | val |= WPA_KEY_MGMT_PSK; | |
820 | else if (os_strcmp(start, "WPA-EAP") == 0) | |
821 | val |= WPA_KEY_MGMT_IEEE8021X; | |
822 | #ifdef CONFIG_IEEE80211R | |
823 | else if (os_strcmp(start, "FT-PSK") == 0) | |
824 | val |= WPA_KEY_MGMT_FT_PSK; | |
825 | else if (os_strcmp(start, "FT-EAP") == 0) | |
826 | val |= WPA_KEY_MGMT_FT_IEEE8021X; | |
827 | #endif /* CONFIG_IEEE80211R */ | |
56586197 JM |
828 | #ifdef CONFIG_IEEE80211W |
829 | else if (os_strcmp(start, "WPA-PSK-SHA256") == 0) | |
830 | val |= WPA_KEY_MGMT_PSK_SHA256; | |
831 | else if (os_strcmp(start, "WPA-EAP-SHA256") == 0) | |
832 | val |= WPA_KEY_MGMT_IEEE8021X_SHA256; | |
833 | #endif /* CONFIG_IEEE80211W */ | |
6fc6879b | 834 | else { |
10656fc2 JM |
835 | wpa_printf(MSG_ERROR, "Line %d: invalid key_mgmt '%s'", |
836 | line, start); | |
6fc6879b JM |
837 | os_free(buf); |
838 | return -1; | |
839 | } | |
840 | ||
841 | if (last) | |
842 | break; | |
843 | start = end + 1; | |
844 | } | |
845 | ||
846 | os_free(buf); | |
847 | if (val == 0) { | |
10656fc2 JM |
848 | wpa_printf(MSG_ERROR, "Line %d: no key_mgmt values " |
849 | "configured.", line); | |
6fc6879b JM |
850 | return -1; |
851 | } | |
852 | ||
853 | return val; | |
854 | } | |
855 | ||
856 | ||
857 | static int hostapd_config_parse_cipher(int line, const char *value) | |
858 | { | |
859 | int val = 0, last; | |
860 | char *start, *end, *buf; | |
861 | ||
862 | buf = os_strdup(value); | |
863 | if (buf == NULL) | |
864 | return -1; | |
865 | start = buf; | |
866 | ||
5306f43f | 867 | while (*start != '\0') { |
6fc6879b JM |
868 | while (*start == ' ' || *start == '\t') |
869 | start++; | |
870 | if (*start == '\0') | |
871 | break; | |
872 | end = start; | |
873 | while (*end != ' ' && *end != '\t' && *end != '\0') | |
874 | end++; | |
875 | last = *end == '\0'; | |
876 | *end = '\0'; | |
877 | if (os_strcmp(start, "CCMP") == 0) | |
878 | val |= WPA_CIPHER_CCMP; | |
879 | else if (os_strcmp(start, "TKIP") == 0) | |
880 | val |= WPA_CIPHER_TKIP; | |
881 | else if (os_strcmp(start, "WEP104") == 0) | |
882 | val |= WPA_CIPHER_WEP104; | |
883 | else if (os_strcmp(start, "WEP40") == 0) | |
884 | val |= WPA_CIPHER_WEP40; | |
885 | else if (os_strcmp(start, "NONE") == 0) | |
886 | val |= WPA_CIPHER_NONE; | |
887 | else { | |
10656fc2 JM |
888 | wpa_printf(MSG_ERROR, "Line %d: invalid cipher '%s'.", |
889 | line, start); | |
6fc6879b JM |
890 | os_free(buf); |
891 | return -1; | |
892 | } | |
893 | ||
894 | if (last) | |
895 | break; | |
896 | start = end + 1; | |
897 | } | |
898 | os_free(buf); | |
899 | ||
900 | if (val == 0) { | |
10656fc2 JM |
901 | wpa_printf(MSG_ERROR, "Line %d: no cipher values configured.", |
902 | line); | |
6fc6879b JM |
903 | return -1; |
904 | } | |
905 | return val; | |
906 | } | |
907 | ||
908 | ||
909 | static int hostapd_config_check_bss(struct hostapd_bss_config *bss, | |
910 | struct hostapd_config *conf) | |
911 | { | |
912 | if (bss->ieee802_1x && !bss->eap_server && | |
913 | !bss->radius->auth_servers) { | |
10656fc2 JM |
914 | wpa_printf(MSG_ERROR, "Invalid IEEE 802.1X configuration (no " |
915 | "EAP authenticator configured)."); | |
6fc6879b JM |
916 | return -1; |
917 | } | |
918 | ||
919 | if (bss->wpa && (bss->wpa_key_mgmt & WPA_KEY_MGMT_PSK) && | |
920 | bss->ssid.wpa_psk == NULL && bss->ssid.wpa_passphrase == NULL && | |
921 | bss->ssid.wpa_psk_file == NULL) { | |
10656fc2 JM |
922 | wpa_printf(MSG_ERROR, "WPA-PSK enabled, but PSK or passphrase " |
923 | "is not configured."); | |
6fc6879b JM |
924 | return -1; |
925 | } | |
926 | ||
927 | if (hostapd_mac_comp_empty(bss->bssid) != 0) { | |
928 | size_t i; | |
929 | ||
930 | for (i = 0; i < conf->num_bss; i++) { | |
931 | if ((&conf->bss[i] != bss) && | |
932 | (hostapd_mac_comp(conf->bss[i].bssid, | |
933 | bss->bssid) == 0)) { | |
10656fc2 JM |
934 | wpa_printf(MSG_ERROR, "Duplicate BSSID " MACSTR |
935 | " on interface '%s' and '%s'.", | |
936 | MAC2STR(bss->bssid), | |
937 | conf->bss[i].iface, bss->iface); | |
6fc6879b JM |
938 | return -1; |
939 | } | |
940 | } | |
941 | } | |
942 | ||
943 | #ifdef CONFIG_IEEE80211R | |
944 | if ((bss->wpa_key_mgmt & | |
945 | (WPA_KEY_MGMT_FT_PSK | WPA_KEY_MGMT_FT_IEEE8021X)) && | |
946 | (bss->nas_identifier == NULL || | |
947 | os_strlen(bss->nas_identifier) < 1 || | |
948 | os_strlen(bss->nas_identifier) > FT_R0KH_ID_MAX_LEN)) { | |
10656fc2 JM |
949 | wpa_printf(MSG_ERROR, "FT (IEEE 802.11r) requires " |
950 | "nas_identifier to be configured as a 1..48 octet " | |
951 | "string"); | |
6fc6879b JM |
952 | return -1; |
953 | } | |
954 | #endif /* CONFIG_IEEE80211R */ | |
955 | ||
47f72245 JM |
956 | #ifdef CONFIG_IEEE80211N |
957 | if (conf->ieee80211n && bss->wpa && | |
958 | !(bss->wpa_pairwise & WPA_CIPHER_CCMP) && | |
959 | !(bss->rsn_pairwise & WPA_CIPHER_CCMP)) { | |
10656fc2 JM |
960 | wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) with WPA/WPA2 " |
961 | "requires CCMP to be enabled"); | |
47f72245 JM |
962 | return -1; |
963 | } | |
964 | #endif /* CONFIG_IEEE80211N */ | |
965 | ||
6fc6879b JM |
966 | return 0; |
967 | } | |
968 | ||
969 | ||
970 | static int hostapd_config_check(struct hostapd_config *conf) | |
971 | { | |
972 | size_t i; | |
973 | ||
974 | for (i = 0; i < conf->num_bss; i++) { | |
975 | if (hostapd_config_check_bss(&conf->bss[i], conf)) | |
976 | return -1; | |
977 | } | |
978 | ||
979 | return 0; | |
980 | } | |
981 | ||
982 | ||
983 | static int hostapd_config_read_wep(struct hostapd_wep_keys *wep, int keyidx, | |
984 | char *val) | |
985 | { | |
986 | size_t len = os_strlen(val); | |
987 | ||
988 | if (keyidx < 0 || keyidx > 3 || wep->key[keyidx] != NULL) | |
989 | return -1; | |
990 | ||
991 | if (val[0] == '"') { | |
992 | if (len < 2 || val[len - 1] != '"') | |
993 | return -1; | |
994 | len -= 2; | |
995 | wep->key[keyidx] = os_malloc(len); | |
996 | if (wep->key[keyidx] == NULL) | |
997 | return -1; | |
998 | os_memcpy(wep->key[keyidx], val + 1, len); | |
999 | wep->len[keyidx] = len; | |
1000 | } else { | |
1001 | if (len & 1) | |
1002 | return -1; | |
1003 | len /= 2; | |
1004 | wep->key[keyidx] = os_malloc(len); | |
1005 | if (wep->key[keyidx] == NULL) | |
1006 | return -1; | |
1007 | wep->len[keyidx] = len; | |
1008 | if (hexstr2bin(val, wep->key[keyidx], len) < 0) | |
1009 | return -1; | |
1010 | } | |
1011 | ||
1012 | wep->keys_set++; | |
1013 | ||
1014 | return 0; | |
1015 | } | |
1016 | ||
1017 | ||
1018 | static int hostapd_parse_rates(int **rate_list, char *val) | |
1019 | { | |
1020 | int *list; | |
1021 | int count; | |
1022 | char *pos, *end; | |
1023 | ||
1024 | os_free(*rate_list); | |
1025 | *rate_list = NULL; | |
1026 | ||
1027 | pos = val; | |
1028 | count = 0; | |
1029 | while (*pos != '\0') { | |
1030 | if (*pos == ' ') | |
1031 | count++; | |
1032 | pos++; | |
1033 | } | |
1034 | ||
1035 | list = os_malloc(sizeof(int) * (count + 2)); | |
1036 | if (list == NULL) | |
1037 | return -1; | |
1038 | pos = val; | |
1039 | count = 0; | |
1040 | while (*pos != '\0') { | |
1041 | end = os_strchr(pos, ' '); | |
1042 | if (end) | |
1043 | *end = '\0'; | |
1044 | ||
1045 | list[count++] = atoi(pos); | |
1046 | if (!end) | |
1047 | break; | |
1048 | pos = end + 1; | |
1049 | } | |
1050 | list[count] = -1; | |
1051 | ||
1052 | *rate_list = list; | |
1053 | return 0; | |
1054 | } | |
1055 | ||
1056 | ||
1057 | static int hostapd_config_bss(struct hostapd_config *conf, const char *ifname) | |
1058 | { | |
1059 | struct hostapd_bss_config *bss; | |
1060 | ||
1061 | if (*ifname == '\0') | |
1062 | return -1; | |
1063 | ||
1064 | bss = os_realloc(conf->bss, (conf->num_bss + 1) * | |
1065 | sizeof(struct hostapd_bss_config)); | |
1066 | if (bss == NULL) { | |
10656fc2 JM |
1067 | wpa_printf(MSG_ERROR, "Failed to allocate memory for " |
1068 | "multi-BSS entry"); | |
6fc6879b JM |
1069 | return -1; |
1070 | } | |
1071 | conf->bss = bss; | |
1072 | ||
1073 | bss = &(conf->bss[conf->num_bss]); | |
1074 | os_memset(bss, 0, sizeof(*bss)); | |
1075 | bss->radius = os_zalloc(sizeof(*bss->radius)); | |
1076 | if (bss->radius == NULL) { | |
10656fc2 JM |
1077 | wpa_printf(MSG_ERROR, "Failed to allocate memory for " |
1078 | "multi-BSS RADIUS data"); | |
6fc6879b JM |
1079 | return -1; |
1080 | } | |
1081 | ||
1082 | conf->num_bss++; | |
1083 | conf->last_bss = bss; | |
1084 | ||
1085 | hostapd_config_defaults_bss(bss); | |
1086 | os_strlcpy(bss->iface, ifname, sizeof(bss->iface)); | |
1087 | os_memcpy(bss->ssid.vlan, bss->iface, IFNAMSIZ + 1); | |
1088 | ||
1089 | return 0; | |
1090 | } | |
1091 | ||
1092 | ||
1093 | static int valid_cw(int cw) | |
1094 | { | |
1095 | return (cw == 1 || cw == 3 || cw == 7 || cw == 15 || cw == 31 || | |
1096 | cw == 63 || cw == 127 || cw == 255 || cw == 511 || cw == 1023); | |
1097 | } | |
1098 | ||
1099 | ||
1100 | enum { | |
1101 | IEEE80211_TX_QUEUE_DATA0 = 0, /* used for EDCA AC_VO data */ | |
1102 | IEEE80211_TX_QUEUE_DATA1 = 1, /* used for EDCA AC_VI data */ | |
1103 | IEEE80211_TX_QUEUE_DATA2 = 2, /* used for EDCA AC_BE data */ | |
1104 | IEEE80211_TX_QUEUE_DATA3 = 3, /* used for EDCA AC_BK data */ | |
1105 | IEEE80211_TX_QUEUE_DATA4 = 4, | |
1106 | IEEE80211_TX_QUEUE_AFTER_BEACON = 6, | |
1107 | IEEE80211_TX_QUEUE_BEACON = 7 | |
1108 | }; | |
1109 | ||
1110 | static int hostapd_config_tx_queue(struct hostapd_config *conf, char *name, | |
1111 | char *val) | |
1112 | { | |
1113 | int num; | |
1114 | char *pos; | |
1115 | struct hostapd_tx_queue_params *queue; | |
1116 | ||
1117 | /* skip 'tx_queue_' prefix */ | |
1118 | pos = name + 9; | |
1119 | if (os_strncmp(pos, "data", 4) == 0 && | |
1120 | pos[4] >= '0' && pos[4] <= '9' && pos[5] == '_') { | |
1121 | num = pos[4] - '0'; | |
1122 | pos += 6; | |
1123 | } else if (os_strncmp(pos, "after_beacon_", 13) == 0) { | |
1124 | num = IEEE80211_TX_QUEUE_AFTER_BEACON; | |
1125 | pos += 13; | |
1126 | } else if (os_strncmp(pos, "beacon_", 7) == 0) { | |
1127 | num = IEEE80211_TX_QUEUE_BEACON; | |
1128 | pos += 7; | |
1129 | } else { | |
10656fc2 | 1130 | wpa_printf(MSG_ERROR, "Unknown tx_queue name '%s'", pos); |
6fc6879b JM |
1131 | return -1; |
1132 | } | |
1133 | ||
1134 | queue = &conf->tx_queue[num]; | |
1135 | ||
1136 | if (os_strcmp(pos, "aifs") == 0) { | |
1137 | queue->aifs = atoi(val); | |
1138 | if (queue->aifs < 0 || queue->aifs > 255) { | |
10656fc2 JM |
1139 | wpa_printf(MSG_ERROR, "Invalid AIFS value %d", |
1140 | queue->aifs); | |
6fc6879b JM |
1141 | return -1; |
1142 | } | |
1143 | } else if (os_strcmp(pos, "cwmin") == 0) { | |
1144 | queue->cwmin = atoi(val); | |
1145 | if (!valid_cw(queue->cwmin)) { | |
10656fc2 JM |
1146 | wpa_printf(MSG_ERROR, "Invalid cwMin value %d", |
1147 | queue->cwmin); | |
6fc6879b JM |
1148 | return -1; |
1149 | } | |
1150 | } else if (os_strcmp(pos, "cwmax") == 0) { | |
1151 | queue->cwmax = atoi(val); | |
1152 | if (!valid_cw(queue->cwmax)) { | |
10656fc2 JM |
1153 | wpa_printf(MSG_ERROR, "Invalid cwMax value %d", |
1154 | queue->cwmax); | |
6fc6879b JM |
1155 | return -1; |
1156 | } | |
1157 | } else if (os_strcmp(pos, "burst") == 0) { | |
1158 | queue->burst = hostapd_config_read_int10(val); | |
1159 | } else { | |
10656fc2 | 1160 | wpa_printf(MSG_ERROR, "Unknown tx_queue field '%s'", pos); |
6fc6879b JM |
1161 | return -1; |
1162 | } | |
1163 | ||
1164 | queue->configured = 1; | |
1165 | ||
1166 | return 0; | |
1167 | } | |
1168 | ||
1169 | ||
1170 | static int hostapd_config_wme_ac(struct hostapd_config *conf, char *name, | |
1171 | char *val) | |
1172 | { | |
1173 | int num, v; | |
1174 | char *pos; | |
1175 | struct hostapd_wme_ac_params *ac; | |
1176 | ||
1177 | /* skip 'wme_ac_' prefix */ | |
1178 | pos = name + 7; | |
1179 | if (os_strncmp(pos, "be_", 3) == 0) { | |
1180 | num = 0; | |
1181 | pos += 3; | |
1182 | } else if (os_strncmp(pos, "bk_", 3) == 0) { | |
1183 | num = 1; | |
1184 | pos += 3; | |
1185 | } else if (os_strncmp(pos, "vi_", 3) == 0) { | |
1186 | num = 2; | |
1187 | pos += 3; | |
1188 | } else if (os_strncmp(pos, "vo_", 3) == 0) { | |
1189 | num = 3; | |
1190 | pos += 3; | |
1191 | } else { | |
10656fc2 | 1192 | wpa_printf(MSG_ERROR, "Unknown wme name '%s'", pos); |
6fc6879b JM |
1193 | return -1; |
1194 | } | |
1195 | ||
1196 | ac = &conf->wme_ac_params[num]; | |
1197 | ||
1198 | if (os_strcmp(pos, "aifs") == 0) { | |
1199 | v = atoi(val); | |
1200 | if (v < 1 || v > 255) { | |
10656fc2 | 1201 | wpa_printf(MSG_ERROR, "Invalid AIFS value %d", v); |
6fc6879b JM |
1202 | return -1; |
1203 | } | |
1204 | ac->aifs = v; | |
1205 | } else if (os_strcmp(pos, "cwmin") == 0) { | |
1206 | v = atoi(val); | |
1207 | if (v < 0 || v > 12) { | |
10656fc2 | 1208 | wpa_printf(MSG_ERROR, "Invalid cwMin value %d", v); |
6fc6879b JM |
1209 | return -1; |
1210 | } | |
1211 | ac->cwmin = v; | |
1212 | } else if (os_strcmp(pos, "cwmax") == 0) { | |
1213 | v = atoi(val); | |
1214 | if (v < 0 || v > 12) { | |
10656fc2 | 1215 | wpa_printf(MSG_ERROR, "Invalid cwMax value %d", v); |
6fc6879b JM |
1216 | return -1; |
1217 | } | |
1218 | ac->cwmax = v; | |
1219 | } else if (os_strcmp(pos, "txop_limit") == 0) { | |
1220 | v = atoi(val); | |
1221 | if (v < 0 || v > 0xffff) { | |
10656fc2 | 1222 | wpa_printf(MSG_ERROR, "Invalid txop value %d", v); |
6fc6879b JM |
1223 | return -1; |
1224 | } | |
1225 | ac->txopLimit = v; | |
1226 | } else if (os_strcmp(pos, "acm") == 0) { | |
1227 | v = atoi(val); | |
1228 | if (v < 0 || v > 1) { | |
10656fc2 | 1229 | wpa_printf(MSG_ERROR, "Invalid acm value %d", v); |
6fc6879b JM |
1230 | return -1; |
1231 | } | |
1232 | ac->admission_control_mandatory = v; | |
1233 | } else { | |
10656fc2 | 1234 | wpa_printf(MSG_ERROR, "Unknown wme_ac_ field '%s'", pos); |
6fc6879b JM |
1235 | return -1; |
1236 | } | |
1237 | ||
1238 | return 0; | |
1239 | } | |
1240 | ||
1241 | ||
1242 | #ifdef CONFIG_IEEE80211R | |
1243 | static int add_r0kh(struct hostapd_bss_config *bss, char *value) | |
1244 | { | |
1245 | struct ft_remote_r0kh *r0kh; | |
1246 | char *pos, *next; | |
1247 | ||
1248 | r0kh = os_zalloc(sizeof(*r0kh)); | |
1249 | if (r0kh == NULL) | |
1250 | return -1; | |
1251 | ||
1252 | /* 02:01:02:03:04:05 a.example.com 000102030405060708090a0b0c0d0e0f */ | |
1253 | pos = value; | |
1254 | next = os_strchr(pos, ' '); | |
1255 | if (next) | |
1256 | *next++ = '\0'; | |
1257 | if (next == NULL || hwaddr_aton(pos, r0kh->addr)) { | |
10656fc2 | 1258 | wpa_printf(MSG_ERROR, "Invalid R0KH MAC address: '%s'", pos); |
6fc6879b JM |
1259 | os_free(r0kh); |
1260 | return -1; | |
1261 | } | |
1262 | ||
1263 | pos = next; | |
1264 | next = os_strchr(pos, ' '); | |
1265 | if (next) | |
1266 | *next++ = '\0'; | |
1267 | if (next == NULL || next - pos > FT_R0KH_ID_MAX_LEN) { | |
10656fc2 | 1268 | wpa_printf(MSG_ERROR, "Invalid R0KH-ID: '%s'", pos); |
6fc6879b JM |
1269 | os_free(r0kh); |
1270 | return -1; | |
1271 | } | |
1272 | r0kh->id_len = next - pos - 1; | |
1273 | os_memcpy(r0kh->id, pos, r0kh->id_len); | |
1274 | ||
1275 | pos = next; | |
1276 | if (hexstr2bin(pos, r0kh->key, sizeof(r0kh->key))) { | |
10656fc2 | 1277 | wpa_printf(MSG_ERROR, "Invalid R0KH key: '%s'", pos); |
6fc6879b JM |
1278 | os_free(r0kh); |
1279 | return -1; | |
1280 | } | |
1281 | ||
1282 | r0kh->next = bss->r0kh_list; | |
1283 | bss->r0kh_list = r0kh; | |
1284 | ||
1285 | return 0; | |
1286 | } | |
1287 | ||
1288 | ||
1289 | static int add_r1kh(struct hostapd_bss_config *bss, char *value) | |
1290 | { | |
1291 | struct ft_remote_r1kh *r1kh; | |
1292 | char *pos, *next; | |
1293 | ||
1294 | r1kh = os_zalloc(sizeof(*r1kh)); | |
1295 | if (r1kh == NULL) | |
1296 | return -1; | |
1297 | ||
1298 | /* 02:01:02:03:04:05 02:01:02:03:04:05 | |
1299 | * 000102030405060708090a0b0c0d0e0f */ | |
1300 | pos = value; | |
1301 | next = os_strchr(pos, ' '); | |
1302 | if (next) | |
1303 | *next++ = '\0'; | |
1304 | if (next == NULL || hwaddr_aton(pos, r1kh->addr)) { | |
10656fc2 | 1305 | wpa_printf(MSG_ERROR, "Invalid R1KH MAC address: '%s'", pos); |
6fc6879b JM |
1306 | os_free(r1kh); |
1307 | return -1; | |
1308 | } | |
1309 | ||
1310 | pos = next; | |
1311 | next = os_strchr(pos, ' '); | |
1312 | if (next) | |
1313 | *next++ = '\0'; | |
1314 | if (next == NULL || hwaddr_aton(pos, r1kh->id)) { | |
10656fc2 | 1315 | wpa_printf(MSG_ERROR, "Invalid R1KH-ID: '%s'", pos); |
6fc6879b JM |
1316 | os_free(r1kh); |
1317 | return -1; | |
1318 | } | |
1319 | ||
1320 | pos = next; | |
1321 | if (hexstr2bin(pos, r1kh->key, sizeof(r1kh->key))) { | |
10656fc2 | 1322 | wpa_printf(MSG_ERROR, "Invalid R1KH key: '%s'", pos); |
6fc6879b JM |
1323 | os_free(r1kh); |
1324 | return -1; | |
1325 | } | |
1326 | ||
1327 | r1kh->next = bss->r1kh_list; | |
1328 | bss->r1kh_list = r1kh; | |
1329 | ||
1330 | return 0; | |
1331 | } | |
1332 | #endif /* CONFIG_IEEE80211R */ | |
1333 | ||
1334 | ||
fc14f567 JM |
1335 | #ifdef CONFIG_IEEE80211N |
1336 | static int hostapd_config_ht_capab(struct hostapd_config *conf, | |
1337 | const char *capab) | |
1338 | { | |
1339 | if (os_strstr(capab, "[LDPC]")) | |
1340 | conf->ht_capab |= HT_CAP_INFO_LDPC_CODING_CAP; | |
a8d8410e | 1341 | if (os_strstr(capab, "[HT40-]")) { |
fc14f567 | 1342 | conf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET; |
a8d8410e JM |
1343 | conf->secondary_channel = -1; |
1344 | } | |
1345 | if (os_strstr(capab, "[HT40+]")) { | |
1346 | conf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET; | |
1347 | conf->secondary_channel = 1; | |
1348 | } | |
fc14f567 JM |
1349 | if (os_strstr(capab, "[SMPS-STATIC]")) { |
1350 | conf->ht_capab &= ~HT_CAP_INFO_SMPS_MASK; | |
1351 | conf->ht_capab |= HT_CAP_INFO_SMPS_STATIC; | |
1352 | } | |
1353 | if (os_strstr(capab, "[SMPS-DYNAMIC]")) { | |
1354 | conf->ht_capab &= ~HT_CAP_INFO_SMPS_MASK; | |
1355 | conf->ht_capab |= HT_CAP_INFO_SMPS_DYNAMIC; | |
1356 | } | |
1357 | if (os_strstr(capab, "[GF]")) | |
1358 | conf->ht_capab |= HT_CAP_INFO_GREEN_FIELD; | |
1359 | if (os_strstr(capab, "[SHORT-GI-20]")) | |
1360 | conf->ht_capab |= HT_CAP_INFO_SHORT_GI20MHZ; | |
1361 | if (os_strstr(capab, "[SHORT-GI-40]")) | |
1362 | conf->ht_capab |= HT_CAP_INFO_SHORT_GI40MHZ; | |
1363 | if (os_strstr(capab, "[TX-STBC]")) | |
1364 | conf->ht_capab |= HT_CAP_INFO_TX_STBC; | |
1365 | if (os_strstr(capab, "[RX-STBC1]")) { | |
1366 | conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK; | |
1367 | conf->ht_capab |= HT_CAP_INFO_RX_STBC_1; | |
1368 | } | |
1369 | if (os_strstr(capab, "[RX-STBC12]")) { | |
1370 | conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK; | |
1371 | conf->ht_capab |= HT_CAP_INFO_RX_STBC_12; | |
1372 | } | |
1373 | if (os_strstr(capab, "[RX-STBC123]")) { | |
1374 | conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK; | |
1375 | conf->ht_capab |= HT_CAP_INFO_RX_STBC_123; | |
1376 | } | |
1377 | if (os_strstr(capab, "[DELAYED-BA]")) | |
1378 | conf->ht_capab |= HT_CAP_INFO_DELAYED_BA; | |
1379 | if (os_strstr(capab, "[MAX-AMSDU-7935]")) | |
1380 | conf->ht_capab |= HT_CAP_INFO_MAX_AMSDU_SIZE; | |
1381 | if (os_strstr(capab, "[DSSS_CCK-40]")) | |
1382 | conf->ht_capab |= HT_CAP_INFO_DSSS_CCK40MHZ; | |
1383 | if (os_strstr(capab, "[PSMP]")) | |
1384 | conf->ht_capab |= HT_CAP_INFO_PSMP_SUPP; | |
1385 | if (os_strstr(capab, "[LSIG-TXOP-PROT]")) | |
1386 | conf->ht_capab |= HT_CAP_INFO_LSIG_TXOP_PROTECT_SUPPORT; | |
1387 | ||
1388 | return 0; | |
1389 | } | |
1390 | #endif /* CONFIG_IEEE80211N */ | |
1391 | ||
1392 | ||
1c6e69cc JM |
1393 | /** |
1394 | * hostapd_config_read - Read and parse a configuration file | |
1395 | * @fname: Configuration file name (including path, if needed) | |
1396 | * Returns: Allocated configuration data structure | |
1397 | */ | |
6fc6879b JM |
1398 | struct hostapd_config * hostapd_config_read(const char *fname) |
1399 | { | |
1400 | struct hostapd_config *conf; | |
1401 | struct hostapd_bss_config *bss; | |
1402 | FILE *f; | |
1403 | char buf[256], *pos; | |
1404 | int line = 0; | |
1405 | int errors = 0; | |
1406 | int pairwise; | |
1407 | size_t i; | |
1408 | ||
1409 | f = fopen(fname, "r"); | |
1410 | if (f == NULL) { | |
10656fc2 JM |
1411 | wpa_printf(MSG_ERROR, "Could not open configuration file '%s' " |
1412 | "for reading.", fname); | |
6fc6879b JM |
1413 | return NULL; |
1414 | } | |
1415 | ||
1416 | conf = hostapd_config_defaults(); | |
1417 | if (conf == NULL) { | |
1418 | fclose(f); | |
1419 | return NULL; | |
1420 | } | |
1421 | bss = conf->last_bss = conf->bss; | |
1422 | ||
1423 | while (fgets(buf, sizeof(buf), f)) { | |
1424 | bss = conf->last_bss; | |
1425 | line++; | |
1426 | ||
1427 | if (buf[0] == '#') | |
1428 | continue; | |
1429 | pos = buf; | |
1430 | while (*pos != '\0') { | |
1431 | if (*pos == '\n') { | |
1432 | *pos = '\0'; | |
1433 | break; | |
1434 | } | |
1435 | pos++; | |
1436 | } | |
1437 | if (buf[0] == '\0') | |
1438 | continue; | |
1439 | ||
1440 | pos = os_strchr(buf, '='); | |
1441 | if (pos == NULL) { | |
10656fc2 JM |
1442 | wpa_printf(MSG_ERROR, "Line %d: invalid line '%s'", |
1443 | line, buf); | |
6fc6879b JM |
1444 | errors++; |
1445 | continue; | |
1446 | } | |
1447 | *pos = '\0'; | |
1448 | pos++; | |
1449 | ||
1450 | if (os_strcmp(buf, "interface") == 0) { | |
1451 | os_strlcpy(conf->bss[0].iface, pos, | |
1452 | sizeof(conf->bss[0].iface)); | |
1453 | } else if (os_strcmp(buf, "bridge") == 0) { | |
1454 | os_strlcpy(bss->bridge, pos, sizeof(bss->bridge)); | |
1455 | } else if (os_strcmp(buf, "driver") == 0) { | |
1456 | int i; | |
1457 | /* clear to get error below if setting is invalid */ | |
1458 | conf->driver = NULL; | |
1459 | for (i = 0; hostapd_drivers[i]; i++) { | |
1460 | if (os_strcmp(pos, hostapd_drivers[i]->name) == | |
1461 | 0) { | |
1462 | conf->driver = hostapd_drivers[i]; | |
1463 | break; | |
1464 | } | |
1465 | } | |
1466 | if (conf->driver == NULL) { | |
10656fc2 JM |
1467 | wpa_printf(MSG_ERROR, "Line %d: invalid/" |
1468 | "unknown driver '%s'", line, pos); | |
6fc6879b JM |
1469 | errors++; |
1470 | } | |
1471 | } else if (os_strcmp(buf, "debug") == 0) { | |
1472 | wpa_printf(MSG_DEBUG, "Line %d: DEPRECATED: 'debug' " | |
1473 | "configuration variable is not used " | |
1474 | "anymore", line); | |
1475 | } else if (os_strcmp(buf, "logger_syslog_level") == 0) { | |
1476 | bss->logger_syslog_level = atoi(pos); | |
1477 | } else if (os_strcmp(buf, "logger_stdout_level") == 0) { | |
1478 | bss->logger_stdout_level = atoi(pos); | |
1479 | } else if (os_strcmp(buf, "logger_syslog") == 0) { | |
1480 | bss->logger_syslog = atoi(pos); | |
1481 | } else if (os_strcmp(buf, "logger_stdout") == 0) { | |
1482 | bss->logger_stdout = atoi(pos); | |
1483 | } else if (os_strcmp(buf, "dump_file") == 0) { | |
1484 | bss->dump_log_name = os_strdup(pos); | |
1485 | } else if (os_strcmp(buf, "ssid") == 0) { | |
1486 | bss->ssid.ssid_len = os_strlen(pos); | |
1487 | if (bss->ssid.ssid_len > HOSTAPD_MAX_SSID_LEN || | |
1488 | bss->ssid.ssid_len < 1) { | |
10656fc2 JM |
1489 | wpa_printf(MSG_ERROR, "Line %d: invalid SSID " |
1490 | "'%s'", line, pos); | |
6fc6879b JM |
1491 | errors++; |
1492 | } else { | |
1493 | os_memcpy(bss->ssid.ssid, pos, | |
1494 | bss->ssid.ssid_len); | |
1495 | bss->ssid.ssid[bss->ssid.ssid_len] = '\0'; | |
1496 | bss->ssid.ssid_set = 1; | |
1497 | } | |
1498 | } else if (os_strcmp(buf, "macaddr_acl") == 0) { | |
1499 | bss->macaddr_acl = atoi(pos); | |
1500 | if (bss->macaddr_acl != ACCEPT_UNLESS_DENIED && | |
1501 | bss->macaddr_acl != DENY_UNLESS_ACCEPTED && | |
1502 | bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH) { | |
10656fc2 JM |
1503 | wpa_printf(MSG_ERROR, "Line %d: unknown " |
1504 | "macaddr_acl %d", | |
1505 | line, bss->macaddr_acl); | |
6fc6879b JM |
1506 | } |
1507 | } else if (os_strcmp(buf, "accept_mac_file") == 0) { | |
1508 | if (hostapd_config_read_maclist(pos, &bss->accept_mac, | |
1509 | &bss->num_accept_mac)) | |
1510 | { | |
10656fc2 JM |
1511 | wpa_printf(MSG_ERROR, "Line %d: Failed to " |
1512 | "read accept_mac_file '%s'", | |
1513 | line, pos); | |
6fc6879b JM |
1514 | errors++; |
1515 | } | |
1516 | } else if (os_strcmp(buf, "deny_mac_file") == 0) { | |
1517 | if (hostapd_config_read_maclist(pos, &bss->deny_mac, | |
10656fc2 JM |
1518 | &bss->num_deny_mac)) { |
1519 | wpa_printf(MSG_ERROR "Line %d: Failed to read " | |
1520 | "deny_mac_file '%s'", line, pos); | |
6fc6879b JM |
1521 | errors++; |
1522 | } | |
1523 | } else if (os_strcmp(buf, "ap_max_inactivity") == 0) { | |
1524 | bss->ap_max_inactivity = atoi(pos); | |
1525 | } else if (os_strcmp(buf, "country_code") == 0) { | |
1526 | os_memcpy(conf->country, pos, 2); | |
1527 | /* FIX: make this configurable */ | |
1528 | conf->country[2] = ' '; | |
1529 | } else if (os_strcmp(buf, "ieee80211d") == 0) { | |
1530 | conf->ieee80211d = atoi(pos); | |
6fc6879b JM |
1531 | } else if (os_strcmp(buf, "ieee8021x") == 0) { |
1532 | bss->ieee802_1x = atoi(pos); | |
1533 | } else if (os_strcmp(buf, "eapol_version") == 0) { | |
1534 | bss->eapol_version = atoi(pos); | |
1535 | if (bss->eapol_version < 1 || | |
1536 | bss->eapol_version > 2) { | |
10656fc2 JM |
1537 | wpa_printf(MSG_ERROR, "Line %d: invalid EAPOL " |
1538 | "version (%d): '%s'.", | |
1539 | line, bss->eapol_version, pos); | |
6fc6879b JM |
1540 | errors++; |
1541 | } else | |
1542 | wpa_printf(MSG_DEBUG, "eapol_version=%d", | |
1543 | bss->eapol_version); | |
1544 | #ifdef EAP_SERVER | |
1545 | } else if (os_strcmp(buf, "eap_authenticator") == 0) { | |
1546 | bss->eap_server = atoi(pos); | |
10656fc2 JM |
1547 | wpa_printf(MSG_ERROR, "Line %d: obsolete " |
1548 | "eap_authenticator used; this has been " | |
1549 | "renamed to eap_server", line); | |
6fc6879b JM |
1550 | } else if (os_strcmp(buf, "eap_server") == 0) { |
1551 | bss->eap_server = atoi(pos); | |
1552 | } else if (os_strcmp(buf, "eap_user_file") == 0) { | |
1553 | if (hostapd_config_read_eap_user(pos, bss)) | |
1554 | errors++; | |
1555 | } else if (os_strcmp(buf, "ca_cert") == 0) { | |
1556 | os_free(bss->ca_cert); | |
1557 | bss->ca_cert = os_strdup(pos); | |
1558 | } else if (os_strcmp(buf, "server_cert") == 0) { | |
1559 | os_free(bss->server_cert); | |
1560 | bss->server_cert = os_strdup(pos); | |
1561 | } else if (os_strcmp(buf, "private_key") == 0) { | |
1562 | os_free(bss->private_key); | |
1563 | bss->private_key = os_strdup(pos); | |
1564 | } else if (os_strcmp(buf, "private_key_passwd") == 0) { | |
1565 | os_free(bss->private_key_passwd); | |
1566 | bss->private_key_passwd = os_strdup(pos); | |
1567 | } else if (os_strcmp(buf, "check_crl") == 0) { | |
1568 | bss->check_crl = atoi(pos); | |
1569 | } else if (os_strcmp(buf, "dh_file") == 0) { | |
1570 | os_free(bss->dh_file); | |
1571 | bss->dh_file = os_strdup(pos); | |
1572 | #ifdef EAP_FAST | |
1573 | } else if (os_strcmp(buf, "pac_opaque_encr_key") == 0) { | |
1574 | os_free(bss->pac_opaque_encr_key); | |
1575 | bss->pac_opaque_encr_key = os_malloc(16); | |
1576 | if (bss->pac_opaque_encr_key == NULL) { | |
10656fc2 JM |
1577 | wpa_printf(MSG_ERROR, "Line %d: No memory for " |
1578 | "pac_opaque_encr_key", line); | |
6fc6879b JM |
1579 | errors++; |
1580 | } else if (hexstr2bin(pos, bss->pac_opaque_encr_key, | |
1581 | 16)) { | |
10656fc2 JM |
1582 | wpa_printf(MSG_ERROR, "Line %d: Invalid " |
1583 | "pac_opaque_encr_key", line); | |
6fc6879b JM |
1584 | errors++; |
1585 | } | |
1586 | } else if (os_strcmp(buf, "eap_fast_a_id") == 0) { | |
2d867244 JM |
1587 | size_t idlen = os_strlen(pos); |
1588 | if (idlen & 1) { | |
10656fc2 JM |
1589 | wpa_printf(MSG_ERROR, "Line %d: Invalid " |
1590 | "eap_fast_a_id", line); | |
2d867244 JM |
1591 | errors++; |
1592 | } else { | |
1593 | os_free(bss->eap_fast_a_id); | |
1594 | bss->eap_fast_a_id = os_malloc(idlen / 2); | |
1595 | if (bss->eap_fast_a_id == NULL || | |
1596 | hexstr2bin(pos, bss->eap_fast_a_id, | |
1597 | idlen / 2)) { | |
10656fc2 JM |
1598 | wpa_printf(MSG_ERROR, "Line %d: " |
1599 | "Failed to parse " | |
1600 | "eap_fast_a_id", line); | |
2d867244 JM |
1601 | errors++; |
1602 | } else | |
1603 | bss->eap_fast_a_id_len = idlen / 2; | |
1604 | } | |
1605 | } else if (os_strcmp(buf, "eap_fast_a_id_info") == 0) { | |
1606 | os_free(bss->eap_fast_a_id_info); | |
1607 | bss->eap_fast_a_id_info = os_strdup(pos); | |
378eae5e JM |
1608 | } else if (os_strcmp(buf, "eap_fast_prov") == 0) { |
1609 | bss->eap_fast_prov = atoi(pos); | |
a11c90a6 JM |
1610 | } else if (os_strcmp(buf, "pac_key_lifetime") == 0) { |
1611 | bss->pac_key_lifetime = atoi(pos); | |
1612 | } else if (os_strcmp(buf, "pac_key_refresh_time") == 0) { | |
1613 | bss->pac_key_refresh_time = atoi(pos); | |
6fc6879b JM |
1614 | #endif /* EAP_FAST */ |
1615 | #ifdef EAP_SIM | |
1616 | } else if (os_strcmp(buf, "eap_sim_db") == 0) { | |
1617 | os_free(bss->eap_sim_db); | |
1618 | bss->eap_sim_db = os_strdup(pos); | |
1619 | } else if (os_strcmp(buf, "eap_sim_aka_result_ind") == 0) { | |
1620 | bss->eap_sim_aka_result_ind = atoi(pos); | |
1621 | #endif /* EAP_SIM */ | |
da08a7c7 JM |
1622 | #ifdef EAP_TNC |
1623 | } else if (os_strcmp(buf, "tnc") == 0) { | |
1624 | bss->tnc = atoi(pos); | |
1625 | #endif /* EAP_TNC */ | |
6fc6879b JM |
1626 | #endif /* EAP_SERVER */ |
1627 | } else if (os_strcmp(buf, "eap_message") == 0) { | |
1628 | char *term; | |
1629 | bss->eap_req_id_text = os_strdup(pos); | |
1630 | if (bss->eap_req_id_text == NULL) { | |
10656fc2 JM |
1631 | wpa_printf(MSG_ERROR, "Line %d: Failed to " |
1632 | "allocate memory for " | |
1633 | "eap_req_id_text", line); | |
6fc6879b JM |
1634 | errors++; |
1635 | continue; | |
1636 | } | |
1637 | bss->eap_req_id_text_len = | |
1638 | os_strlen(bss->eap_req_id_text); | |
1639 | term = os_strstr(bss->eap_req_id_text, "\\0"); | |
1640 | if (term) { | |
1641 | *term++ = '\0'; | |
1642 | os_memmove(term, term + 1, | |
1643 | bss->eap_req_id_text_len - | |
1644 | (term - bss->eap_req_id_text) - 1); | |
1645 | bss->eap_req_id_text_len--; | |
1646 | } | |
1647 | } else if (os_strcmp(buf, "wep_key_len_broadcast") == 0) { | |
1648 | bss->default_wep_key_len = atoi(pos); | |
1649 | if (bss->default_wep_key_len > 13) { | |
10656fc2 JM |
1650 | wpa_printf(MSG_ERROR, "Line %d: invalid WEP " |
1651 | "key len %lu (= %lu bits)", line, | |
1652 | (unsigned long) | |
1653 | bss->default_wep_key_len, | |
1654 | (unsigned long) | |
1655 | bss->default_wep_key_len * 8); | |
6fc6879b JM |
1656 | errors++; |
1657 | } | |
1658 | } else if (os_strcmp(buf, "wep_key_len_unicast") == 0) { | |
1659 | bss->individual_wep_key_len = atoi(pos); | |
1660 | if (bss->individual_wep_key_len < 0 || | |
1661 | bss->individual_wep_key_len > 13) { | |
10656fc2 JM |
1662 | wpa_printf(MSG_ERROR, "Line %d: invalid WEP " |
1663 | "key len %d (= %d bits)", line, | |
1664 | bss->individual_wep_key_len, | |
1665 | bss->individual_wep_key_len * 8); | |
6fc6879b JM |
1666 | errors++; |
1667 | } | |
1668 | } else if (os_strcmp(buf, "wep_rekey_period") == 0) { | |
1669 | bss->wep_rekeying_period = atoi(pos); | |
1670 | if (bss->wep_rekeying_period < 0) { | |
10656fc2 JM |
1671 | wpa_printf(MSG_ERROR, "Line %d: invalid " |
1672 | "period %d", | |
1673 | line, bss->wep_rekeying_period); | |
6fc6879b JM |
1674 | errors++; |
1675 | } | |
1676 | } else if (os_strcmp(buf, "eap_reauth_period") == 0) { | |
1677 | bss->eap_reauth_period = atoi(pos); | |
1678 | if (bss->eap_reauth_period < 0) { | |
10656fc2 JM |
1679 | wpa_printf(MSG_ERROR, "Line %d: invalid " |
1680 | "period %d", | |
1681 | line, bss->eap_reauth_period); | |
6fc6879b JM |
1682 | errors++; |
1683 | } | |
1684 | } else if (os_strcmp(buf, "eapol_key_index_workaround") == 0) { | |
1685 | bss->eapol_key_index_workaround = atoi(pos); | |
1686 | #ifdef CONFIG_IAPP | |
1687 | } else if (os_strcmp(buf, "iapp_interface") == 0) { | |
1688 | bss->ieee802_11f = 1; | |
1689 | os_strlcpy(bss->iapp_iface, pos, | |
1690 | sizeof(bss->iapp_iface)); | |
1691 | #endif /* CONFIG_IAPP */ | |
1692 | } else if (os_strcmp(buf, "own_ip_addr") == 0) { | |
1693 | if (hostapd_parse_ip_addr(pos, &bss->own_ip_addr)) { | |
10656fc2 JM |
1694 | wpa_printf(MSG_ERROR, "Line %d: invalid IP " |
1695 | "address '%s'", line, pos); | |
6fc6879b JM |
1696 | errors++; |
1697 | } | |
1698 | } else if (os_strcmp(buf, "nas_identifier") == 0) { | |
1699 | bss->nas_identifier = os_strdup(pos); | |
1700 | } else if (os_strcmp(buf, "auth_server_addr") == 0) { | |
1701 | if (hostapd_config_read_radius_addr( | |
1702 | &bss->radius->auth_servers, | |
1703 | &bss->radius->num_auth_servers, pos, 1812, | |
1704 | &bss->radius->auth_server)) { | |
10656fc2 JM |
1705 | wpa_printf(MSG_ERROR, "Line %d: invalid IP " |
1706 | "address '%s'", line, pos); | |
6fc6879b JM |
1707 | errors++; |
1708 | } | |
1709 | } else if (bss->radius->auth_server && | |
1710 | os_strcmp(buf, "auth_server_port") == 0) { | |
1711 | bss->radius->auth_server->port = atoi(pos); | |
1712 | } else if (bss->radius->auth_server && | |
1713 | os_strcmp(buf, "auth_server_shared_secret") == 0) { | |
1714 | int len = os_strlen(pos); | |
1715 | if (len == 0) { | |
1716 | /* RFC 2865, Ch. 3 */ | |
10656fc2 JM |
1717 | wpa_printf(MSG_ERROR, "Line %d: empty shared " |
1718 | "secret is not allowed.", line); | |
6fc6879b JM |
1719 | errors++; |
1720 | } | |
1721 | bss->radius->auth_server->shared_secret = | |
1722 | (u8 *) os_strdup(pos); | |
1723 | bss->radius->auth_server->shared_secret_len = len; | |
1724 | } else if (os_strcmp(buf, "acct_server_addr") == 0) { | |
1725 | if (hostapd_config_read_radius_addr( | |
1726 | &bss->radius->acct_servers, | |
1727 | &bss->radius->num_acct_servers, pos, 1813, | |
1728 | &bss->radius->acct_server)) { | |
10656fc2 JM |
1729 | wpa_printf(MSG_ERROR, "Line %d: invalid IP " |
1730 | "address '%s'", line, pos); | |
6fc6879b JM |
1731 | errors++; |
1732 | } | |
1733 | } else if (bss->radius->acct_server && | |
1734 | os_strcmp(buf, "acct_server_port") == 0) { | |
1735 | bss->radius->acct_server->port = atoi(pos); | |
1736 | } else if (bss->radius->acct_server && | |
1737 | os_strcmp(buf, "acct_server_shared_secret") == 0) { | |
1738 | int len = os_strlen(pos); | |
1739 | if (len == 0) { | |
1740 | /* RFC 2865, Ch. 3 */ | |
10656fc2 JM |
1741 | wpa_printf(MSG_ERROR, "Line %d: empty shared " |
1742 | "secret is not allowed.", line); | |
6fc6879b JM |
1743 | errors++; |
1744 | } | |
1745 | bss->radius->acct_server->shared_secret = | |
1746 | (u8 *) os_strdup(pos); | |
1747 | bss->radius->acct_server->shared_secret_len = len; | |
1748 | } else if (os_strcmp(buf, "radius_retry_primary_interval") == | |
1749 | 0) { | |
1750 | bss->radius->retry_primary_interval = atoi(pos); | |
1751 | } else if (os_strcmp(buf, "radius_acct_interim_interval") == 0) | |
1752 | { | |
1753 | bss->radius->acct_interim_interval = atoi(pos); | |
1754 | } else if (os_strcmp(buf, "auth_algs") == 0) { | |
1755 | bss->auth_algs = atoi(pos); | |
1756 | if (bss->auth_algs == 0) { | |
10656fc2 JM |
1757 | wpa_printf(MSG_ERROR, "Line %d: no " |
1758 | "authentication algorithms allowed", | |
1759 | line); | |
6fc6879b JM |
1760 | errors++; |
1761 | } | |
1762 | } else if (os_strcmp(buf, "max_num_sta") == 0) { | |
1763 | bss->max_num_sta = atoi(pos); | |
1764 | if (bss->max_num_sta < 0 || | |
1765 | bss->max_num_sta > MAX_STA_COUNT) { | |
10656fc2 JM |
1766 | wpa_printf(MSG_ERROR, "Line %d: Invalid " |
1767 | "max_num_sta=%d; allowed range " | |
1768 | "0..%d", line, bss->max_num_sta, | |
1769 | MAX_STA_COUNT); | |
6fc6879b JM |
1770 | errors++; |
1771 | } | |
1772 | } else if (os_strcmp(buf, "wpa") == 0) { | |
1773 | bss->wpa = atoi(pos); | |
1774 | } else if (os_strcmp(buf, "wpa_group_rekey") == 0) { | |
1775 | bss->wpa_group_rekey = atoi(pos); | |
1776 | } else if (os_strcmp(buf, "wpa_strict_rekey") == 0) { | |
1777 | bss->wpa_strict_rekey = atoi(pos); | |
1778 | } else if (os_strcmp(buf, "wpa_gmk_rekey") == 0) { | |
1779 | bss->wpa_gmk_rekey = atoi(pos); | |
581a8cde JM |
1780 | } else if (os_strcmp(buf, "wpa_ptk_rekey") == 0) { |
1781 | bss->wpa_ptk_rekey = atoi(pos); | |
6fc6879b JM |
1782 | } else if (os_strcmp(buf, "wpa_passphrase") == 0) { |
1783 | int len = os_strlen(pos); | |
1784 | if (len < 8 || len > 63) { | |
10656fc2 JM |
1785 | wpa_printf(MSG_ERROR, "Line %d: invalid WPA " |
1786 | "passphrase length %d (expected " | |
1787 | "8..63)", line, len); | |
6fc6879b JM |
1788 | errors++; |
1789 | } else { | |
1790 | os_free(bss->ssid.wpa_passphrase); | |
1791 | bss->ssid.wpa_passphrase = os_strdup(pos); | |
1792 | } | |
1793 | } else if (os_strcmp(buf, "wpa_psk") == 0) { | |
1794 | os_free(bss->ssid.wpa_psk); | |
1795 | bss->ssid.wpa_psk = | |
1796 | os_zalloc(sizeof(struct hostapd_wpa_psk)); | |
1797 | if (bss->ssid.wpa_psk == NULL) | |
1798 | errors++; | |
1799 | else if (hexstr2bin(pos, bss->ssid.wpa_psk->psk, | |
1800 | PMK_LEN) || | |
1801 | pos[PMK_LEN * 2] != '\0') { | |
10656fc2 JM |
1802 | wpa_printf(MSG_ERROR, "Line %d: Invalid PSK " |
1803 | "'%s'.", line, pos); | |
6fc6879b JM |
1804 | errors++; |
1805 | } else { | |
1806 | bss->ssid.wpa_psk->group = 1; | |
1807 | } | |
1808 | } else if (os_strcmp(buf, "wpa_psk_file") == 0) { | |
1809 | os_free(bss->ssid.wpa_psk_file); | |
1810 | bss->ssid.wpa_psk_file = os_strdup(pos); | |
1811 | if (!bss->ssid.wpa_psk_file) { | |
10656fc2 JM |
1812 | wpa_printf(MSG_ERROR, "Line %d: allocation " |
1813 | "failed", line); | |
6fc6879b JM |
1814 | errors++; |
1815 | } | |
1816 | } else if (os_strcmp(buf, "wpa_key_mgmt") == 0) { | |
1817 | bss->wpa_key_mgmt = | |
1818 | hostapd_config_parse_key_mgmt(line, pos); | |
1819 | if (bss->wpa_key_mgmt == -1) | |
1820 | errors++; | |
1821 | } else if (os_strcmp(buf, "wpa_pairwise") == 0) { | |
1822 | bss->wpa_pairwise = | |
1823 | hostapd_config_parse_cipher(line, pos); | |
1824 | if (bss->wpa_pairwise == -1 || | |
1825 | bss->wpa_pairwise == 0) | |
1826 | errors++; | |
1827 | else if (bss->wpa_pairwise & | |
1828 | (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 | | |
1829 | WPA_CIPHER_WEP104)) { | |
10656fc2 JM |
1830 | wpa_printf(MSG_ERROR, "Line %d: unsupported " |
1831 | "pairwise cipher suite '%s'", | |
1832 | bss->wpa_pairwise, pos); | |
6fc6879b JM |
1833 | errors++; |
1834 | } | |
1835 | } else if (os_strcmp(buf, "rsn_pairwise") == 0) { | |
1836 | bss->rsn_pairwise = | |
1837 | hostapd_config_parse_cipher(line, pos); | |
1838 | if (bss->rsn_pairwise == -1 || | |
1839 | bss->rsn_pairwise == 0) | |
1840 | errors++; | |
1841 | else if (bss->rsn_pairwise & | |
1842 | (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 | | |
1843 | WPA_CIPHER_WEP104)) { | |
10656fc2 JM |
1844 | wpa_printf(MSG_ERROR, "Line %d: unsupported " |
1845 | "pairwise cipher suite '%s'", | |
1846 | bss->rsn_pairwise, pos); | |
6fc6879b JM |
1847 | errors++; |
1848 | } | |
1849 | #ifdef CONFIG_RSN_PREAUTH | |
1850 | } else if (os_strcmp(buf, "rsn_preauth") == 0) { | |
1851 | bss->rsn_preauth = atoi(pos); | |
1852 | } else if (os_strcmp(buf, "rsn_preauth_interfaces") == 0) { | |
1853 | bss->rsn_preauth_interfaces = os_strdup(pos); | |
1854 | #endif /* CONFIG_RSN_PREAUTH */ | |
1855 | #ifdef CONFIG_PEERKEY | |
1856 | } else if (os_strcmp(buf, "peerkey") == 0) { | |
1857 | bss->peerkey = atoi(pos); | |
1858 | #endif /* CONFIG_PEERKEY */ | |
1859 | #ifdef CONFIG_IEEE80211R | |
1860 | } else if (os_strcmp(buf, "mobility_domain") == 0) { | |
1861 | if (os_strlen(pos) != 2 * MOBILITY_DOMAIN_ID_LEN || | |
1862 | hexstr2bin(pos, bss->mobility_domain, | |
1863 | MOBILITY_DOMAIN_ID_LEN) != 0) { | |
1864 | wpa_printf(MSG_DEBUG, "Line %d: Invalid " | |
1865 | "mobility_domain '%s'", line, pos); | |
1866 | errors++; | |
1867 | continue; | |
1868 | } | |
1869 | } else if (os_strcmp(buf, "r1_key_holder") == 0) { | |
1870 | if (os_strlen(pos) != 2 * FT_R1KH_ID_LEN || | |
1871 | hexstr2bin(pos, bss->r1_key_holder, | |
1872 | FT_R1KH_ID_LEN) != 0) { | |
1873 | wpa_printf(MSG_DEBUG, "Line %d: Invalid " | |
1874 | "r1_key_holder '%s'", line, pos); | |
1875 | errors++; | |
1876 | continue; | |
1877 | } | |
1878 | } else if (os_strcmp(buf, "r0_key_lifetime") == 0) { | |
1879 | bss->r0_key_lifetime = atoi(pos); | |
1880 | } else if (os_strcmp(buf, "reassociation_deadline") == 0) { | |
1881 | bss->reassociation_deadline = atoi(pos); | |
1882 | } else if (os_strcmp(buf, "r0kh") == 0) { | |
1883 | if (add_r0kh(bss, pos) < 0) { | |
1884 | wpa_printf(MSG_DEBUG, "Line %d: Invalid " | |
1885 | "r0kh '%s'", line, pos); | |
1886 | errors++; | |
1887 | continue; | |
1888 | } | |
1889 | } else if (os_strcmp(buf, "r1kh") == 0) { | |
1890 | if (add_r1kh(bss, pos) < 0) { | |
1891 | wpa_printf(MSG_DEBUG, "Line %d: Invalid " | |
1892 | "r1kh '%s'", line, pos); | |
1893 | errors++; | |
1894 | continue; | |
1895 | } | |
1896 | } else if (os_strcmp(buf, "pmk_r1_push") == 0) { | |
1897 | bss->pmk_r1_push = atoi(pos); | |
1898 | #endif /* CONFIG_IEEE80211R */ | |
1899 | } else if (os_strcmp(buf, "ctrl_interface") == 0) { | |
1900 | os_free(bss->ctrl_interface); | |
1901 | bss->ctrl_interface = os_strdup(pos); | |
1902 | } else if (os_strcmp(buf, "ctrl_interface_group") == 0) { | |
1903 | #ifndef CONFIG_NATIVE_WINDOWS | |
1904 | struct group *grp; | |
1905 | char *endp; | |
1906 | const char *group = pos; | |
1907 | ||
1908 | grp = getgrnam(group); | |
1909 | if (grp) { | |
1910 | bss->ctrl_interface_gid = grp->gr_gid; | |
1911 | bss->ctrl_interface_gid_set = 1; | |
1912 | wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d" | |
1913 | " (from group name '%s')", | |
1914 | bss->ctrl_interface_gid, group); | |
1915 | continue; | |
1916 | } | |
1917 | ||
1918 | /* Group name not found - try to parse this as gid */ | |
1919 | bss->ctrl_interface_gid = strtol(group, &endp, 10); | |
1920 | if (*group == '\0' || *endp != '\0') { | |
1921 | wpa_printf(MSG_DEBUG, "Line %d: Invalid group " | |
1922 | "'%s'", line, group); | |
1923 | errors++; | |
1924 | continue; | |
1925 | } | |
1926 | bss->ctrl_interface_gid_set = 1; | |
1927 | wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d", | |
1928 | bss->ctrl_interface_gid); | |
1929 | #endif /* CONFIG_NATIVE_WINDOWS */ | |
1930 | #ifdef RADIUS_SERVER | |
1931 | } else if (os_strcmp(buf, "radius_server_clients") == 0) { | |
1932 | os_free(bss->radius_server_clients); | |
1933 | bss->radius_server_clients = os_strdup(pos); | |
1934 | } else if (os_strcmp(buf, "radius_server_auth_port") == 0) { | |
1935 | bss->radius_server_auth_port = atoi(pos); | |
1936 | } else if (os_strcmp(buf, "radius_server_ipv6") == 0) { | |
1937 | bss->radius_server_ipv6 = atoi(pos); | |
1938 | #endif /* RADIUS_SERVER */ | |
1939 | } else if (os_strcmp(buf, "test_socket") == 0) { | |
1940 | os_free(bss->test_socket); | |
1941 | bss->test_socket = os_strdup(pos); | |
1942 | } else if (os_strcmp(buf, "use_pae_group_addr") == 0) { | |
1943 | bss->use_pae_group_addr = atoi(pos); | |
1944 | } else if (os_strcmp(buf, "hw_mode") == 0) { | |
1945 | if (os_strcmp(pos, "a") == 0) | |
1946 | conf->hw_mode = HOSTAPD_MODE_IEEE80211A; | |
1947 | else if (os_strcmp(pos, "b") == 0) | |
1948 | conf->hw_mode = HOSTAPD_MODE_IEEE80211B; | |
1949 | else if (os_strcmp(pos, "g") == 0) | |
1950 | conf->hw_mode = HOSTAPD_MODE_IEEE80211G; | |
1951 | else { | |
10656fc2 JM |
1952 | wpa_printf(MSG_ERROR, "Line %d: unknown " |
1953 | "hw_mode '%s'", line, pos); | |
6fc6879b JM |
1954 | errors++; |
1955 | } | |
1956 | } else if (os_strcmp(buf, "channel") == 0) { | |
1957 | conf->channel = atoi(pos); | |
1958 | } else if (os_strcmp(buf, "beacon_int") == 0) { | |
1959 | int val = atoi(pos); | |
1960 | /* MIB defines range as 1..65535, but very small values | |
1961 | * cause problems with the current implementation. | |
1962 | * Since it is unlikely that this small numbers are | |
1963 | * useful in real life scenarios, do not allow beacon | |
1964 | * period to be set below 15 TU. */ | |
1965 | if (val < 15 || val > 65535) { | |
10656fc2 JM |
1966 | wpa_printf(MSG_ERROR, "Line %d: invalid " |
1967 | "beacon_int %d (expected " | |
1968 | "15..65535)", line, val); | |
6fc6879b JM |
1969 | errors++; |
1970 | } else | |
1971 | conf->beacon_int = val; | |
1972 | } else if (os_strcmp(buf, "dtim_period") == 0) { | |
1973 | bss->dtim_period = atoi(pos); | |
1974 | if (bss->dtim_period < 1 || bss->dtim_period > 255) { | |
10656fc2 JM |
1975 | wpa_printf(MSG_ERROR, "Line %d: invalid " |
1976 | "dtim_period %d", | |
1977 | line, bss->dtim_period); | |
6fc6879b JM |
1978 | errors++; |
1979 | } | |
1980 | } else if (os_strcmp(buf, "rts_threshold") == 0) { | |
1981 | conf->rts_threshold = atoi(pos); | |
1982 | if (conf->rts_threshold < 0 || | |
1983 | conf->rts_threshold > 2347) { | |
10656fc2 JM |
1984 | wpa_printf(MSG_ERROR, "Line %d: invalid " |
1985 | "rts_threshold %d", | |
1986 | line, conf->rts_threshold); | |
6fc6879b JM |
1987 | errors++; |
1988 | } | |
1989 | } else if (os_strcmp(buf, "fragm_threshold") == 0) { | |
1990 | conf->fragm_threshold = atoi(pos); | |
1991 | if (conf->fragm_threshold < 256 || | |
1992 | conf->fragm_threshold > 2346) { | |
10656fc2 JM |
1993 | wpa_printf(MSG_ERROR, "Line %d: invalid " |
1994 | "fragm_threshold %d", | |
1995 | line, conf->fragm_threshold); | |
6fc6879b JM |
1996 | errors++; |
1997 | } | |
1998 | } else if (os_strcmp(buf, "send_probe_response") == 0) { | |
1999 | int val = atoi(pos); | |
2000 | if (val != 0 && val != 1) { | |
10656fc2 JM |
2001 | wpa_printf(MSG_ERROR, "Line %d: invalid " |
2002 | "send_probe_response %d (expected " | |
2003 | "0 or 1)", line, val); | |
6fc6879b JM |
2004 | } else |
2005 | conf->send_probe_response = val; | |
2006 | } else if (os_strcmp(buf, "supported_rates") == 0) { | |
2007 | if (hostapd_parse_rates(&conf->supported_rates, pos)) { | |
10656fc2 JM |
2008 | wpa_printf(MSG_ERROR, "Line %d: invalid rate " |
2009 | "list", line); | |
6fc6879b JM |
2010 | errors++; |
2011 | } | |
2012 | } else if (os_strcmp(buf, "basic_rates") == 0) { | |
2013 | if (hostapd_parse_rates(&conf->basic_rates, pos)) { | |
10656fc2 JM |
2014 | wpa_printf(MSG_ERROR, "Line %d: invalid rate " |
2015 | "list", line); | |
6fc6879b JM |
2016 | errors++; |
2017 | } | |
839faf04 JM |
2018 | } else if (os_strcmp(buf, "preamble") == 0) { |
2019 | if (atoi(pos)) | |
2020 | conf->preamble = SHORT_PREAMBLE; | |
2021 | else | |
2022 | conf->preamble = LONG_PREAMBLE; | |
6fc6879b JM |
2023 | } else if (os_strcmp(buf, "ignore_broadcast_ssid") == 0) { |
2024 | bss->ignore_broadcast_ssid = atoi(pos); | |
2025 | } else if (os_strcmp(buf, "bridge_packets") == 0) { | |
2026 | conf->bridge_packets = atoi(pos); | |
2027 | } else if (os_strcmp(buf, "wep_default_key") == 0) { | |
2028 | bss->ssid.wep.idx = atoi(pos); | |
2029 | if (bss->ssid.wep.idx > 3) { | |
10656fc2 JM |
2030 | wpa_printf(MSG_ERROR, "Invalid " |
2031 | "wep_default_key index %d", | |
2032 | bss->ssid.wep.idx); | |
6fc6879b JM |
2033 | errors++; |
2034 | } | |
2035 | } else if (os_strcmp(buf, "wep_key0") == 0 || | |
2036 | os_strcmp(buf, "wep_key1") == 0 || | |
2037 | os_strcmp(buf, "wep_key2") == 0 || | |
2038 | os_strcmp(buf, "wep_key3") == 0) { | |
2039 | if (hostapd_config_read_wep(&bss->ssid.wep, | |
2040 | buf[7] - '0', pos)) { | |
10656fc2 JM |
2041 | wpa_printf(MSG_ERROR, "Line %d: invalid WEP " |
2042 | "key '%s'", line, buf); | |
6fc6879b JM |
2043 | errors++; |
2044 | } | |
2045 | } else if (os_strcmp(buf, "dynamic_vlan") == 0) { | |
2046 | bss->ssid.dynamic_vlan = atoi(pos); | |
2047 | } else if (os_strcmp(buf, "vlan_file") == 0) { | |
2048 | if (hostapd_config_read_vlan_file(bss, pos)) { | |
10656fc2 JM |
2049 | wpa_printf(MSG_ERROR, "Line %d: failed to " |
2050 | "read VLAN file '%s'", line, pos); | |
6fc6879b JM |
2051 | errors++; |
2052 | } | |
2053 | #ifdef CONFIG_FULL_DYNAMIC_VLAN | |
2054 | } else if (os_strcmp(buf, "vlan_tagged_interface") == 0) { | |
2055 | bss->ssid.vlan_tagged_interface = os_strdup(pos); | |
2056 | #endif /* CONFIG_FULL_DYNAMIC_VLAN */ | |
2057 | } else if (os_strcmp(buf, "passive_scan_interval") == 0) { | |
2058 | conf->passive_scan_interval = atoi(pos); | |
2059 | } else if (os_strcmp(buf, "passive_scan_listen") == 0) { | |
2060 | conf->passive_scan_listen = atoi(pos); | |
2061 | } else if (os_strcmp(buf, "passive_scan_mode") == 0) { | |
2062 | conf->passive_scan_mode = atoi(pos); | |
2063 | } else if (os_strcmp(buf, "ap_table_max_size") == 0) { | |
2064 | conf->ap_table_max_size = atoi(pos); | |
2065 | } else if (os_strcmp(buf, "ap_table_expiration_time") == 0) { | |
2066 | conf->ap_table_expiration_time = atoi(pos); | |
2067 | } else if (os_strncmp(buf, "tx_queue_", 9) == 0) { | |
2068 | if (hostapd_config_tx_queue(conf, buf, pos)) { | |
10656fc2 JM |
2069 | wpa_printf(MSG_ERROR, "Line %d: invalid TX " |
2070 | "queue item", line); | |
6fc6879b JM |
2071 | errors++; |
2072 | } | |
2073 | } else if (os_strcmp(buf, "wme_enabled") == 0) { | |
2074 | bss->wme_enabled = atoi(pos); | |
2075 | } else if (os_strncmp(buf, "wme_ac_", 7) == 0) { | |
2076 | if (hostapd_config_wme_ac(conf, buf, pos)) { | |
10656fc2 JM |
2077 | wpa_printf(MSG_ERROR, "Line %d: invalid wme " |
2078 | "ac item", line); | |
6fc6879b JM |
2079 | errors++; |
2080 | } | |
2081 | } else if (os_strcmp(buf, "bss") == 0) { | |
2082 | if (hostapd_config_bss(conf, pos)) { | |
10656fc2 JM |
2083 | wpa_printf(MSG_ERROR, "Line %d: invalid bss " |
2084 | "item", line); | |
6fc6879b JM |
2085 | errors++; |
2086 | } | |
2087 | } else if (os_strcmp(buf, "bssid") == 0) { | |
2088 | if (bss == conf->bss && | |
2089 | (!conf->driver || !conf->driver->init_bssid)) { | |
10656fc2 JM |
2090 | wpa_printf(MSG_ERROR, "Line %d: bssid item " |
2091 | "not allowed for the default " | |
2092 | "interface and this driver", line); | |
6fc6879b JM |
2093 | errors++; |
2094 | } else if (hwaddr_aton(pos, bss->bssid)) { | |
10656fc2 JM |
2095 | wpa_printf(MSG_ERROR, "Line %d: invalid bssid " |
2096 | "item", line); | |
6fc6879b JM |
2097 | errors++; |
2098 | } | |
2099 | #ifdef CONFIG_IEEE80211W | |
2100 | } else if (os_strcmp(buf, "ieee80211w") == 0) { | |
2101 | bss->ieee80211w = atoi(pos); | |
45c94154 JM |
2102 | } else if (os_strcmp(buf, "assoc_sa_query_max_timeout") == 0) { |
2103 | bss->assoc_sa_query_max_timeout = atoi(pos); | |
2104 | if (bss->assoc_sa_query_max_timeout == 0) { | |
10656fc2 JM |
2105 | wpa_printf(MSG_ERROR, "Line %d: invalid " |
2106 | "assoc_sa_query_max_timeout", line); | |
5d22a1d5 JM |
2107 | errors++; |
2108 | } | |
45c94154 JM |
2109 | } else if (os_strcmp(buf, "assoc_sa_query_retry_timeout") == 0) |
2110 | { | |
2111 | bss->assoc_sa_query_retry_timeout = atoi(pos); | |
2112 | if (bss->assoc_sa_query_retry_timeout == 0) { | |
10656fc2 JM |
2113 | wpa_printf(MSG_ERROR, "Line %d: invalid " |
2114 | "assoc_sa_query_retry_timeout", | |
2115 | line); | |
5d22a1d5 JM |
2116 | errors++; |
2117 | } | |
6fc6879b | 2118 | #endif /* CONFIG_IEEE80211W */ |
de9289c8 JM |
2119 | #ifdef CONFIG_IEEE80211N |
2120 | } else if (os_strcmp(buf, "ieee80211n") == 0) { | |
9d2a76a2 | 2121 | conf->ieee80211n = atoi(pos); |
fc14f567 JM |
2122 | } else if (os_strcmp(buf, "ht_capab") == 0) { |
2123 | if (hostapd_config_ht_capab(conf, pos) < 0) { | |
10656fc2 JM |
2124 | wpa_printf(MSG_ERROR, "Line %d: invalid " |
2125 | "ht_capab", line); | |
fc14f567 JM |
2126 | errors++; |
2127 | } | |
de9289c8 | 2128 | #endif /* CONFIG_IEEE80211N */ |
b0194fe0 JM |
2129 | } else if (os_strcmp(buf, "max_listen_interval") == 0) { |
2130 | bss->max_listen_interval = atoi(pos); | |
bf98f7f3 JM |
2131 | } else if (os_strcmp(buf, "okc") == 0) { |
2132 | bss->okc = atoi(pos); | |
ad08c363 JM |
2133 | #ifdef CONFIG_WPS |
2134 | } else if (os_strcmp(buf, "wps_state") == 0) { | |
2135 | bss->wps_state = atoi(pos); | |
2136 | if (bss->wps_state < 0 || bss->wps_state > 2) { | |
10656fc2 JM |
2137 | wpa_printf(MSG_ERROR, "Line %d: invalid " |
2138 | "wps_state", line); | |
ad08c363 JM |
2139 | errors++; |
2140 | } | |
2141 | } else if (os_strcmp(buf, "ap_setup_locked") == 0) { | |
2142 | bss->ap_setup_locked = atoi(pos); | |
2143 | } else if (os_strcmp(buf, "uuid") == 0) { | |
2144 | if (uuid_str2bin(pos, bss->uuid)) { | |
10656fc2 JM |
2145 | wpa_printf(MSG_ERROR, "Line %d: invalid UUID", |
2146 | line); | |
ad08c363 JM |
2147 | errors++; |
2148 | } | |
2149 | } else if (os_strcmp(buf, "wps_pin_requests") == 0) { | |
2150 | bss->wps_pin_requests = os_strdup(pos); | |
2151 | } else if (os_strcmp(buf, "device_name") == 0) { | |
8874b727 | 2152 | if (os_strlen(pos) > 32) { |
10656fc2 JM |
2153 | wpa_printf(MSG_ERROR, "Line %d: Too long " |
2154 | "device_name", line); | |
8874b727 JM |
2155 | errors++; |
2156 | } | |
ad08c363 JM |
2157 | bss->device_name = os_strdup(pos); |
2158 | } else if (os_strcmp(buf, "manufacturer") == 0) { | |
8874b727 | 2159 | if (os_strlen(pos) > 64) { |
10656fc2 JM |
2160 | wpa_printf(MSG_ERROR, "Line %d: Too long " |
2161 | "manufacturer", line); | |
8874b727 JM |
2162 | errors++; |
2163 | } | |
ad08c363 JM |
2164 | bss->manufacturer = os_strdup(pos); |
2165 | } else if (os_strcmp(buf, "model_name") == 0) { | |
8874b727 | 2166 | if (os_strlen(pos) > 32) { |
10656fc2 JM |
2167 | wpa_printf(MSG_ERROR, "Line %d: Too long " |
2168 | "model_name", line); | |
8874b727 JM |
2169 | errors++; |
2170 | } | |
ad08c363 JM |
2171 | bss->model_name = os_strdup(pos); |
2172 | } else if (os_strcmp(buf, "model_number") == 0) { | |
8874b727 | 2173 | if (os_strlen(pos) > 32) { |
10656fc2 JM |
2174 | wpa_printf(MSG_ERROR, "Line %d: Too long " |
2175 | "model_number", line); | |
8874b727 JM |
2176 | errors++; |
2177 | } | |
ad08c363 JM |
2178 | bss->model_number = os_strdup(pos); |
2179 | } else if (os_strcmp(buf, "serial_number") == 0) { | |
8874b727 | 2180 | if (os_strlen(pos) > 32) { |
10656fc2 JM |
2181 | wpa_printf(MSG_ERROR, "Line %d: Too long " |
2182 | "serial_number", line); | |
8874b727 JM |
2183 | errors++; |
2184 | } | |
ad08c363 JM |
2185 | bss->serial_number = os_strdup(pos); |
2186 | } else if (os_strcmp(buf, "device_type") == 0) { | |
2187 | bss->device_type = os_strdup(pos); | |
2188 | } else if (os_strcmp(buf, "config_methods") == 0) { | |
2189 | bss->config_methods = os_strdup(pos); | |
2190 | } else if (os_strcmp(buf, "os_version") == 0) { | |
2191 | if (hexstr2bin(pos, bss->os_version, 4)) { | |
10656fc2 JM |
2192 | wpa_printf(MSG_ERROR, "Line %d: invalid " |
2193 | "os_version", line); | |
ad08c363 JM |
2194 | errors++; |
2195 | } | |
2196 | } else if (os_strcmp(buf, "ap_pin") == 0) { | |
2197 | bss->ap_pin = os_strdup(pos); | |
2198 | #endif /* CONFIG_WPS */ | |
6fc6879b | 2199 | } else { |
10656fc2 JM |
2200 | wpa_printf(MSG_ERROR, "Line %d: unknown configuration " |
2201 | "item '%s'", line, buf); | |
6fc6879b JM |
2202 | errors++; |
2203 | } | |
2204 | } | |
2205 | ||
2206 | fclose(f); | |
2207 | ||
2208 | if (bss->individual_wep_key_len == 0) { | |
2209 | /* individual keys are not use; can use key idx0 for broadcast | |
2210 | * keys */ | |
2211 | bss->broadcast_key_idx_min = 0; | |
2212 | } | |
2213 | ||
2214 | /* Select group cipher based on the enabled pairwise cipher suites */ | |
2215 | pairwise = 0; | |
2216 | if (bss->wpa & 1) | |
2217 | pairwise |= bss->wpa_pairwise; | |
2218 | if (bss->wpa & 2) { | |
2219 | if (bss->rsn_pairwise == 0) | |
2220 | bss->rsn_pairwise = bss->wpa_pairwise; | |
2221 | pairwise |= bss->rsn_pairwise; | |
2222 | } | |
2223 | if (pairwise & WPA_CIPHER_TKIP) | |
2224 | bss->wpa_group = WPA_CIPHER_TKIP; | |
2225 | else | |
2226 | bss->wpa_group = WPA_CIPHER_CCMP; | |
2227 | ||
2228 | for (i = 0; i < conf->num_bss; i++) { | |
2229 | bss = &conf->bss[i]; | |
2230 | ||
2231 | bss->radius->auth_server = bss->radius->auth_servers; | |
2232 | bss->radius->acct_server = bss->radius->acct_servers; | |
2233 | ||
2234 | if (bss->wpa && bss->ieee802_1x) { | |
2235 | bss->ssid.security_policy = SECURITY_WPA; | |
2236 | } else if (bss->wpa) { | |
2237 | bss->ssid.security_policy = SECURITY_WPA_PSK; | |
2238 | } else if (bss->ieee802_1x) { | |
2239 | bss->ssid.security_policy = SECURITY_IEEE_802_1X; | |
2240 | bss->ssid.wep.default_len = bss->default_wep_key_len; | |
2241 | } else if (bss->ssid.wep.keys_set) | |
2242 | bss->ssid.security_policy = SECURITY_STATIC_WEP; | |
2243 | else | |
2244 | bss->ssid.security_policy = SECURITY_PLAINTEXT; | |
2245 | } | |
2246 | ||
2247 | if (hostapd_config_check(conf)) | |
2248 | errors++; | |
2249 | ||
2250 | if (errors) { | |
10656fc2 JM |
2251 | wpa_printf(MSG_ERROR, "%d errors found in configuration file " |
2252 | "'%s'", errors, fname); | |
6fc6879b JM |
2253 | hostapd_config_free(conf); |
2254 | conf = NULL; | |
2255 | } | |
2256 | ||
2257 | return conf; | |
2258 | } | |
2259 | ||
2260 | ||
2261 | int hostapd_wep_key_cmp(struct hostapd_wep_keys *a, struct hostapd_wep_keys *b) | |
2262 | { | |
2263 | int i; | |
2264 | ||
2265 | if (a->idx != b->idx || a->default_len != b->default_len) | |
2266 | return 1; | |
2267 | for (i = 0; i < NUM_WEP_KEYS; i++) | |
2268 | if (a->len[i] != b->len[i] || | |
2269 | os_memcmp(a->key[i], b->key[i], a->len[i]) != 0) | |
2270 | return 1; | |
2271 | return 0; | |
2272 | } | |
2273 | ||
2274 | ||
2275 | static void hostapd_config_free_radius(struct hostapd_radius_server *servers, | |
2276 | int num_servers) | |
2277 | { | |
2278 | int i; | |
2279 | ||
2280 | for (i = 0; i < num_servers; i++) { | |
2281 | os_free(servers[i].shared_secret); | |
2282 | } | |
2283 | os_free(servers); | |
2284 | } | |
2285 | ||
2286 | ||
2287 | static void hostapd_config_free_eap_user(struct hostapd_eap_user *user) | |
2288 | { | |
2289 | os_free(user->identity); | |
2290 | os_free(user->password); | |
2291 | os_free(user); | |
2292 | } | |
2293 | ||
2294 | ||
2295 | static void hostapd_config_free_wep(struct hostapd_wep_keys *keys) | |
2296 | { | |
2297 | int i; | |
2298 | for (i = 0; i < NUM_WEP_KEYS; i++) { | |
2299 | os_free(keys->key[i]); | |
2300 | keys->key[i] = NULL; | |
2301 | } | |
2302 | } | |
2303 | ||
2304 | ||
2305 | static void hostapd_config_free_bss(struct hostapd_bss_config *conf) | |
2306 | { | |
2307 | struct hostapd_wpa_psk *psk, *prev; | |
2308 | struct hostapd_eap_user *user, *prev_user; | |
2309 | ||
2310 | if (conf == NULL) | |
2311 | return; | |
2312 | ||
2313 | psk = conf->ssid.wpa_psk; | |
2314 | while (psk) { | |
2315 | prev = psk; | |
2316 | psk = psk->next; | |
2317 | os_free(prev); | |
2318 | } | |
2319 | ||
2320 | os_free(conf->ssid.wpa_passphrase); | |
2321 | os_free(conf->ssid.wpa_psk_file); | |
2322 | #ifdef CONFIG_FULL_DYNAMIC_VLAN | |
2323 | os_free(conf->ssid.vlan_tagged_interface); | |
2324 | #endif /* CONFIG_FULL_DYNAMIC_VLAN */ | |
2325 | ||
2326 | user = conf->eap_user; | |
2327 | while (user) { | |
2328 | prev_user = user; | |
2329 | user = user->next; | |
2330 | hostapd_config_free_eap_user(prev_user); | |
2331 | } | |
2332 | ||
2333 | os_free(conf->dump_log_name); | |
2334 | os_free(conf->eap_req_id_text); | |
2335 | os_free(conf->accept_mac); | |
2336 | os_free(conf->deny_mac); | |
2337 | os_free(conf->nas_identifier); | |
2338 | hostapd_config_free_radius(conf->radius->auth_servers, | |
2339 | conf->radius->num_auth_servers); | |
2340 | hostapd_config_free_radius(conf->radius->acct_servers, | |
2341 | conf->radius->num_acct_servers); | |
2342 | os_free(conf->rsn_preauth_interfaces); | |
2343 | os_free(conf->ctrl_interface); | |
2344 | os_free(conf->ca_cert); | |
2345 | os_free(conf->server_cert); | |
2346 | os_free(conf->private_key); | |
2347 | os_free(conf->private_key_passwd); | |
2348 | os_free(conf->dh_file); | |
2349 | os_free(conf->pac_opaque_encr_key); | |
2350 | os_free(conf->eap_fast_a_id); | |
2d867244 | 2351 | os_free(conf->eap_fast_a_id_info); |
6fc6879b JM |
2352 | os_free(conf->eap_sim_db); |
2353 | os_free(conf->radius_server_clients); | |
2354 | os_free(conf->test_socket); | |
2355 | os_free(conf->radius); | |
2356 | hostapd_config_free_vlan(conf); | |
2357 | if (conf->ssid.dyn_vlan_keys) { | |
2358 | struct hostapd_ssid *ssid = &conf->ssid; | |
2359 | size_t i; | |
2360 | for (i = 0; i <= ssid->max_dyn_vlan_keys; i++) { | |
2361 | if (ssid->dyn_vlan_keys[i] == NULL) | |
2362 | continue; | |
2363 | hostapd_config_free_wep(ssid->dyn_vlan_keys[i]); | |
2364 | os_free(ssid->dyn_vlan_keys[i]); | |
2365 | } | |
2366 | os_free(ssid->dyn_vlan_keys); | |
2367 | ssid->dyn_vlan_keys = NULL; | |
2368 | } | |
2369 | ||
2370 | #ifdef CONFIG_IEEE80211R | |
2371 | { | |
2372 | struct ft_remote_r0kh *r0kh, *r0kh_prev; | |
2373 | struct ft_remote_r1kh *r1kh, *r1kh_prev; | |
2374 | ||
2375 | r0kh = conf->r0kh_list; | |
2376 | conf->r0kh_list = NULL; | |
2377 | while (r0kh) { | |
2378 | r0kh_prev = r0kh; | |
2379 | r0kh = r0kh->next; | |
2380 | os_free(r0kh_prev); | |
2381 | } | |
2382 | ||
2383 | r1kh = conf->r1kh_list; | |
2384 | conf->r1kh_list = NULL; | |
2385 | while (r1kh) { | |
2386 | r1kh_prev = r1kh; | |
2387 | r1kh = r1kh->next; | |
2388 | os_free(r1kh_prev); | |
2389 | } | |
2390 | } | |
2391 | #endif /* CONFIG_IEEE80211R */ | |
ad08c363 JM |
2392 | |
2393 | #ifdef CONFIG_WPS | |
2394 | os_free(conf->wps_pin_requests); | |
2395 | os_free(conf->device_name); | |
2396 | os_free(conf->manufacturer); | |
2397 | os_free(conf->model_name); | |
2398 | os_free(conf->model_number); | |
2399 | os_free(conf->serial_number); | |
2400 | os_free(conf->device_type); | |
2401 | os_free(conf->config_methods); | |
2402 | os_free(conf->ap_pin); | |
2403 | #endif /* CONFIG_WPS */ | |
6fc6879b JM |
2404 | } |
2405 | ||
2406 | ||
1c6e69cc JM |
2407 | /** |
2408 | * hostapd_config_free - Free hostapd configuration | |
2409 | * @conf: Configuration data from hostapd_config_read(). | |
2410 | */ | |
6fc6879b JM |
2411 | void hostapd_config_free(struct hostapd_config *conf) |
2412 | { | |
2413 | size_t i; | |
2414 | ||
2415 | if (conf == NULL) | |
2416 | return; | |
2417 | ||
2418 | for (i = 0; i < conf->num_bss; i++) | |
2419 | hostapd_config_free_bss(&conf->bss[i]); | |
2420 | os_free(conf->bss); | |
2421 | ||
2422 | os_free(conf); | |
2423 | } | |
2424 | ||
2425 | ||
1c6e69cc JM |
2426 | /** |
2427 | * hostapd_maclist_found - Find a MAC address from a list | |
2428 | * @list: MAC address list | |
2429 | * @num_entries: Number of addresses in the list | |
2430 | * @addr: Address to search for | |
2431 | * @vlan_id: Buffer for returning VLAN ID or %NULL if not needed | |
2432 | * Returns: 1 if address is in the list or 0 if not. | |
2433 | * | |
2434 | * Perform a binary search for given MAC address from a pre-sorted list. | |
2435 | */ | |
271d2830 JM |
2436 | int hostapd_maclist_found(struct mac_acl_entry *list, int num_entries, |
2437 | const u8 *addr, int *vlan_id) | |
6fc6879b JM |
2438 | { |
2439 | int start, end, middle, res; | |
2440 | ||
2441 | start = 0; | |
2442 | end = num_entries - 1; | |
2443 | ||
2444 | while (start <= end) { | |
2445 | middle = (start + end) / 2; | |
271d2830 JM |
2446 | res = os_memcmp(list[middle].addr, addr, ETH_ALEN); |
2447 | if (res == 0) { | |
2448 | if (vlan_id) | |
2449 | *vlan_id = list[middle].vlan_id; | |
6fc6879b | 2450 | return 1; |
271d2830 | 2451 | } |
6fc6879b JM |
2452 | if (res < 0) |
2453 | start = middle + 1; | |
2454 | else | |
2455 | end = middle - 1; | |
2456 | } | |
2457 | ||
2458 | return 0; | |
2459 | } | |
2460 | ||
2461 | ||
2462 | int hostapd_rate_found(int *list, int rate) | |
2463 | { | |
2464 | int i; | |
2465 | ||
2466 | if (list == NULL) | |
2467 | return 0; | |
2468 | ||
2469 | for (i = 0; list[i] >= 0; i++) | |
2470 | if (list[i] == rate) | |
2471 | return 1; | |
2472 | ||
2473 | return 0; | |
2474 | } | |
2475 | ||
2476 | ||
2477 | const char * hostapd_get_vlan_id_ifname(struct hostapd_vlan *vlan, int vlan_id) | |
2478 | { | |
2479 | struct hostapd_vlan *v = vlan; | |
2480 | while (v) { | |
2481 | if (v->vlan_id == vlan_id || v->vlan_id == VLAN_ID_WILDCARD) | |
2482 | return v->ifname; | |
2483 | v = v->next; | |
2484 | } | |
2485 | return NULL; | |
2486 | } | |
2487 | ||
2488 | ||
2489 | const u8 * hostapd_get_psk(const struct hostapd_bss_config *conf, | |
2490 | const u8 *addr, const u8 *prev_psk) | |
2491 | { | |
2492 | struct hostapd_wpa_psk *psk; | |
2493 | int next_ok = prev_psk == NULL; | |
2494 | ||
2495 | for (psk = conf->ssid.wpa_psk; psk != NULL; psk = psk->next) { | |
2496 | if (next_ok && | |
2497 | (psk->group || os_memcmp(psk->addr, addr, ETH_ALEN) == 0)) | |
2498 | return psk->psk; | |
2499 | ||
2500 | if (psk->psk == prev_psk) | |
2501 | next_ok = 1; | |
2502 | } | |
2503 | ||
2504 | return NULL; | |
2505 | } | |
2506 | ||
2507 | ||
2508 | const struct hostapd_eap_user * | |
2509 | hostapd_get_eap_user(const struct hostapd_bss_config *conf, const u8 *identity, | |
2510 | size_t identity_len, int phase2) | |
2511 | { | |
2512 | struct hostapd_eap_user *user = conf->eap_user; | |
2513 | ||
ad08c363 JM |
2514 | #ifdef CONFIG_WPS |
2515 | if (conf->wps_state && identity_len == WSC_ID_ENROLLEE_LEN && | |
2516 | os_memcmp(identity, WSC_ID_ENROLLEE, WSC_ID_ENROLLEE_LEN) == 0) { | |
2517 | static struct hostapd_eap_user wsc_enrollee; | |
2518 | os_memset(&wsc_enrollee, 0, sizeof(wsc_enrollee)); | |
2519 | wsc_enrollee.methods[0].method = eap_server_get_type( | |
2520 | "WSC", &wsc_enrollee.methods[0].vendor); | |
2521 | return &wsc_enrollee; | |
2522 | } | |
2523 | ||
2524 | if (conf->wps_state && conf->ap_pin && | |
2525 | identity_len == WSC_ID_REGISTRAR_LEN && | |
2526 | os_memcmp(identity, WSC_ID_REGISTRAR, WSC_ID_REGISTRAR_LEN) == 0) { | |
2527 | static struct hostapd_eap_user wsc_registrar; | |
2528 | os_memset(&wsc_registrar, 0, sizeof(wsc_registrar)); | |
2529 | wsc_registrar.methods[0].method = eap_server_get_type( | |
2530 | "WSC", &wsc_registrar.methods[0].vendor); | |
2531 | wsc_registrar.password = (u8 *) conf->ap_pin; | |
2532 | wsc_registrar.password_len = os_strlen(conf->ap_pin); | |
2533 | return &wsc_registrar; | |
2534 | } | |
2535 | #endif /* CONFIG_WPS */ | |
2536 | ||
6fc6879b JM |
2537 | while (user) { |
2538 | if (!phase2 && user->identity == NULL) { | |
2539 | /* Wildcard match */ | |
2540 | break; | |
2541 | } | |
2542 | ||
2543 | if (user->phase2 == !!phase2 && user->wildcard_prefix && | |
2544 | identity_len >= user->identity_len && | |
2545 | os_memcmp(user->identity, identity, user->identity_len) == | |
2546 | 0) { | |
2547 | /* Wildcard prefix match */ | |
2548 | break; | |
2549 | } | |
2550 | ||
2551 | if (user->phase2 == !!phase2 && | |
2552 | user->identity_len == identity_len && | |
2553 | os_memcmp(user->identity, identity, identity_len) == 0) | |
2554 | break; | |
2555 | user = user->next; | |
2556 | } | |
2557 | ||
2558 | return user; | |
2559 | } |