Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * hostapd / Configuration file parser |
Dmitry Shmidt | bd14a57 | 2014-02-18 10:33:49 -0800 | [diff] [blame] | 3 | * Copyright (c) 2003-2014, Jouni Malinen <j@w1.fi> |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4 | * |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 5 | * This software may be distributed under the terms of the BSD license. |
| 6 | * See README for more details. |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include "utils/includes.h" |
| 10 | #ifndef CONFIG_NATIVE_WINDOWS |
| 11 | #include <grp.h> |
| 12 | #endif /* CONFIG_NATIVE_WINDOWS */ |
| 13 | |
| 14 | #include "utils/common.h" |
| 15 | #include "utils/uuid.h" |
| 16 | #include "common/ieee802_11_defs.h" |
| 17 | #include "drivers/driver.h" |
| 18 | #include "eap_server/eap.h" |
| 19 | #include "radius/radius_client.h" |
| 20 | #include "ap/wpa_auth.h" |
| 21 | #include "ap/ap_config.h" |
| 22 | #include "config_file.h" |
| 23 | |
| 24 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 25 | #ifndef CONFIG_NO_VLAN |
| 26 | static int hostapd_config_read_vlan_file(struct hostapd_bss_config *bss, |
| 27 | const char *fname) |
| 28 | { |
| 29 | FILE *f; |
| 30 | char buf[128], *pos, *pos2; |
| 31 | int line = 0, vlan_id; |
| 32 | struct hostapd_vlan *vlan; |
| 33 | |
| 34 | f = fopen(fname, "r"); |
| 35 | if (!f) { |
| 36 | wpa_printf(MSG_ERROR, "VLAN file '%s' not readable.", fname); |
| 37 | return -1; |
| 38 | } |
| 39 | |
| 40 | while (fgets(buf, sizeof(buf), f)) { |
| 41 | line++; |
| 42 | |
| 43 | if (buf[0] == '#') |
| 44 | continue; |
| 45 | pos = buf; |
| 46 | while (*pos != '\0') { |
| 47 | if (*pos == '\n') { |
| 48 | *pos = '\0'; |
| 49 | break; |
| 50 | } |
| 51 | pos++; |
| 52 | } |
| 53 | if (buf[0] == '\0') |
| 54 | continue; |
| 55 | |
| 56 | if (buf[0] == '*') { |
| 57 | vlan_id = VLAN_ID_WILDCARD; |
| 58 | pos = buf + 1; |
| 59 | } else { |
| 60 | vlan_id = strtol(buf, &pos, 10); |
| 61 | if (buf == pos || vlan_id < 1 || |
| 62 | vlan_id > MAX_VLAN_ID) { |
| 63 | wpa_printf(MSG_ERROR, "Invalid VLAN ID at " |
| 64 | "line %d in '%s'", line, fname); |
| 65 | fclose(f); |
| 66 | return -1; |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | while (*pos == ' ' || *pos == '\t') |
| 71 | pos++; |
| 72 | pos2 = pos; |
| 73 | while (*pos2 != ' ' && *pos2 != '\t' && *pos2 != '\0') |
| 74 | pos2++; |
| 75 | *pos2 = '\0'; |
| 76 | if (*pos == '\0' || os_strlen(pos) > IFNAMSIZ) { |
| 77 | wpa_printf(MSG_ERROR, "Invalid VLAN ifname at line %d " |
| 78 | "in '%s'", line, fname); |
| 79 | fclose(f); |
| 80 | return -1; |
| 81 | } |
| 82 | |
Dmitry Shmidt | 4b06059 | 2013-04-29 16:42:49 -0700 | [diff] [blame] | 83 | vlan = os_zalloc(sizeof(*vlan)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 84 | if (vlan == NULL) { |
| 85 | wpa_printf(MSG_ERROR, "Out of memory while reading " |
| 86 | "VLAN interfaces from '%s'", fname); |
| 87 | fclose(f); |
| 88 | return -1; |
| 89 | } |
| 90 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 91 | vlan->vlan_id = vlan_id; |
| 92 | os_strlcpy(vlan->ifname, pos, sizeof(vlan->ifname)); |
Dmitry Shmidt | d5c075b | 2013-08-05 14:36:10 -0700 | [diff] [blame] | 93 | vlan->next = bss->vlan; |
| 94 | bss->vlan = vlan; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | fclose(f); |
| 98 | |
| 99 | return 0; |
| 100 | } |
| 101 | #endif /* CONFIG_NO_VLAN */ |
| 102 | |
| 103 | |
| 104 | static int hostapd_acl_comp(const void *a, const void *b) |
| 105 | { |
| 106 | const struct mac_acl_entry *aa = a; |
| 107 | const struct mac_acl_entry *bb = b; |
| 108 | return os_memcmp(aa->addr, bb->addr, sizeof(macaddr)); |
| 109 | } |
| 110 | |
| 111 | |
| 112 | static int hostapd_config_read_maclist(const char *fname, |
| 113 | struct mac_acl_entry **acl, int *num) |
| 114 | { |
| 115 | FILE *f; |
| 116 | char buf[128], *pos; |
| 117 | int line = 0; |
| 118 | u8 addr[ETH_ALEN]; |
| 119 | struct mac_acl_entry *newacl; |
| 120 | int vlan_id; |
| 121 | |
| 122 | if (!fname) |
| 123 | return 0; |
| 124 | |
| 125 | f = fopen(fname, "r"); |
| 126 | if (!f) { |
| 127 | wpa_printf(MSG_ERROR, "MAC list file '%s' not found.", fname); |
| 128 | return -1; |
| 129 | } |
| 130 | |
| 131 | while (fgets(buf, sizeof(buf), f)) { |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame^] | 132 | int i, rem = 0; |
| 133 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 134 | line++; |
| 135 | |
| 136 | if (buf[0] == '#') |
| 137 | continue; |
| 138 | pos = buf; |
| 139 | while (*pos != '\0') { |
| 140 | if (*pos == '\n') { |
| 141 | *pos = '\0'; |
| 142 | break; |
| 143 | } |
| 144 | pos++; |
| 145 | } |
| 146 | if (buf[0] == '\0') |
| 147 | continue; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame^] | 148 | pos = buf; |
| 149 | if (buf[0] == '-') { |
| 150 | rem = 1; |
| 151 | pos++; |
| 152 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 153 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame^] | 154 | if (hwaddr_aton(pos, addr)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 155 | wpa_printf(MSG_ERROR, "Invalid MAC address '%s' at " |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame^] | 156 | "line %d in '%s'", pos, line, fname); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 157 | fclose(f); |
| 158 | return -1; |
| 159 | } |
| 160 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame^] | 161 | if (rem) { |
| 162 | i = 0; |
| 163 | while (i < *num) { |
| 164 | if (os_memcmp((*acl)[i].addr, addr, ETH_ALEN) == |
| 165 | 0) { |
| 166 | os_remove_in_array(*acl, *num, |
| 167 | sizeof(**acl), i); |
| 168 | (*num)--; |
| 169 | } else |
| 170 | i++; |
| 171 | } |
| 172 | continue; |
| 173 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 174 | vlan_id = 0; |
| 175 | pos = buf; |
| 176 | while (*pos != '\0' && *pos != ' ' && *pos != '\t') |
| 177 | pos++; |
| 178 | while (*pos == ' ' || *pos == '\t') |
| 179 | pos++; |
| 180 | if (*pos != '\0') |
| 181 | vlan_id = atoi(pos); |
| 182 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 183 | newacl = os_realloc_array(*acl, *num + 1, sizeof(**acl)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 184 | if (newacl == NULL) { |
| 185 | wpa_printf(MSG_ERROR, "MAC list reallocation failed"); |
| 186 | fclose(f); |
| 187 | return -1; |
| 188 | } |
| 189 | |
| 190 | *acl = newacl; |
| 191 | os_memcpy((*acl)[*num].addr, addr, ETH_ALEN); |
| 192 | (*acl)[*num].vlan_id = vlan_id; |
| 193 | (*num)++; |
| 194 | } |
| 195 | |
| 196 | fclose(f); |
| 197 | |
| 198 | qsort(*acl, *num, sizeof(**acl), hostapd_acl_comp); |
| 199 | |
| 200 | return 0; |
| 201 | } |
| 202 | |
| 203 | |
| 204 | #ifdef EAP_SERVER |
| 205 | static int hostapd_config_read_eap_user(const char *fname, |
| 206 | struct hostapd_bss_config *conf) |
| 207 | { |
| 208 | FILE *f; |
| 209 | char buf[512], *pos, *start, *pos2; |
| 210 | int line = 0, ret = 0, num_methods; |
| 211 | struct hostapd_eap_user *user, *tail = NULL; |
| 212 | |
| 213 | if (!fname) |
| 214 | return 0; |
| 215 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 216 | if (os_strncmp(fname, "sqlite:", 7) == 0) { |
| 217 | os_free(conf->eap_user_sqlite); |
| 218 | conf->eap_user_sqlite = os_strdup(fname + 7); |
| 219 | return 0; |
| 220 | } |
| 221 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 222 | f = fopen(fname, "r"); |
| 223 | if (!f) { |
| 224 | wpa_printf(MSG_ERROR, "EAP user file '%s' not found.", fname); |
| 225 | return -1; |
| 226 | } |
| 227 | |
| 228 | /* Lines: "user" METHOD,METHOD2 "password" (password optional) */ |
| 229 | while (fgets(buf, sizeof(buf), f)) { |
| 230 | line++; |
| 231 | |
| 232 | if (buf[0] == '#') |
| 233 | continue; |
| 234 | pos = buf; |
| 235 | while (*pos != '\0') { |
| 236 | if (*pos == '\n') { |
| 237 | *pos = '\0'; |
| 238 | break; |
| 239 | } |
| 240 | pos++; |
| 241 | } |
| 242 | if (buf[0] == '\0') |
| 243 | continue; |
| 244 | |
| 245 | user = NULL; |
| 246 | |
| 247 | if (buf[0] != '"' && buf[0] != '*') { |
| 248 | wpa_printf(MSG_ERROR, "Invalid EAP identity (no \" in " |
| 249 | "start) on line %d in '%s'", line, fname); |
| 250 | goto failed; |
| 251 | } |
| 252 | |
| 253 | user = os_zalloc(sizeof(*user)); |
| 254 | if (user == NULL) { |
| 255 | wpa_printf(MSG_ERROR, "EAP user allocation failed"); |
| 256 | goto failed; |
| 257 | } |
| 258 | user->force_version = -1; |
| 259 | |
| 260 | if (buf[0] == '*') { |
| 261 | pos = buf; |
| 262 | } else { |
| 263 | pos = buf + 1; |
| 264 | start = pos; |
| 265 | while (*pos != '"' && *pos != '\0') |
| 266 | pos++; |
| 267 | if (*pos == '\0') { |
| 268 | wpa_printf(MSG_ERROR, "Invalid EAP identity " |
| 269 | "(no \" in end) on line %d in '%s'", |
| 270 | line, fname); |
| 271 | goto failed; |
| 272 | } |
| 273 | |
| 274 | user->identity = os_malloc(pos - start); |
| 275 | if (user->identity == NULL) { |
| 276 | wpa_printf(MSG_ERROR, "Failed to allocate " |
| 277 | "memory for EAP identity"); |
| 278 | goto failed; |
| 279 | } |
| 280 | os_memcpy(user->identity, start, pos - start); |
| 281 | user->identity_len = pos - start; |
| 282 | |
| 283 | if (pos[0] == '"' && pos[1] == '*') { |
| 284 | user->wildcard_prefix = 1; |
| 285 | pos++; |
| 286 | } |
| 287 | } |
| 288 | pos++; |
| 289 | while (*pos == ' ' || *pos == '\t') |
| 290 | pos++; |
| 291 | |
| 292 | if (*pos == '\0') { |
| 293 | wpa_printf(MSG_ERROR, "No EAP method on line %d in " |
| 294 | "'%s'", line, fname); |
| 295 | goto failed; |
| 296 | } |
| 297 | |
| 298 | start = pos; |
| 299 | while (*pos != ' ' && *pos != '\t' && *pos != '\0') |
| 300 | pos++; |
| 301 | if (*pos == '\0') { |
| 302 | pos = NULL; |
| 303 | } else { |
| 304 | *pos = '\0'; |
| 305 | pos++; |
| 306 | } |
| 307 | num_methods = 0; |
| 308 | while (*start) { |
| 309 | char *pos3 = os_strchr(start, ','); |
| 310 | if (pos3) { |
| 311 | *pos3++ = '\0'; |
| 312 | } |
| 313 | user->methods[num_methods].method = |
| 314 | eap_server_get_type( |
| 315 | start, |
| 316 | &user->methods[num_methods].vendor); |
| 317 | if (user->methods[num_methods].vendor == |
| 318 | EAP_VENDOR_IETF && |
| 319 | user->methods[num_methods].method == EAP_TYPE_NONE) |
| 320 | { |
| 321 | if (os_strcmp(start, "TTLS-PAP") == 0) { |
| 322 | user->ttls_auth |= EAP_TTLS_AUTH_PAP; |
| 323 | goto skip_eap; |
| 324 | } |
| 325 | if (os_strcmp(start, "TTLS-CHAP") == 0) { |
| 326 | user->ttls_auth |= EAP_TTLS_AUTH_CHAP; |
| 327 | goto skip_eap; |
| 328 | } |
| 329 | if (os_strcmp(start, "TTLS-MSCHAP") == 0) { |
| 330 | user->ttls_auth |= |
| 331 | EAP_TTLS_AUTH_MSCHAP; |
| 332 | goto skip_eap; |
| 333 | } |
| 334 | if (os_strcmp(start, "TTLS-MSCHAPV2") == 0) { |
| 335 | user->ttls_auth |= |
| 336 | EAP_TTLS_AUTH_MSCHAPV2; |
| 337 | goto skip_eap; |
| 338 | } |
| 339 | wpa_printf(MSG_ERROR, "Unsupported EAP type " |
| 340 | "'%s' on line %d in '%s'", |
| 341 | start, line, fname); |
| 342 | goto failed; |
| 343 | } |
| 344 | |
| 345 | num_methods++; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 346 | if (num_methods >= EAP_MAX_METHODS) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 347 | break; |
| 348 | skip_eap: |
| 349 | if (pos3 == NULL) |
| 350 | break; |
| 351 | start = pos3; |
| 352 | } |
| 353 | if (num_methods == 0 && user->ttls_auth == 0) { |
| 354 | wpa_printf(MSG_ERROR, "No EAP types configured on " |
| 355 | "line %d in '%s'", line, fname); |
| 356 | goto failed; |
| 357 | } |
| 358 | |
| 359 | if (pos == NULL) |
| 360 | goto done; |
| 361 | |
| 362 | while (*pos == ' ' || *pos == '\t') |
| 363 | pos++; |
| 364 | if (*pos == '\0') |
| 365 | goto done; |
| 366 | |
| 367 | if (os_strncmp(pos, "[ver=0]", 7) == 0) { |
| 368 | user->force_version = 0; |
| 369 | goto done; |
| 370 | } |
| 371 | |
| 372 | if (os_strncmp(pos, "[ver=1]", 7) == 0) { |
| 373 | user->force_version = 1; |
| 374 | goto done; |
| 375 | } |
| 376 | |
| 377 | if (os_strncmp(pos, "[2]", 3) == 0) { |
| 378 | user->phase2 = 1; |
| 379 | goto done; |
| 380 | } |
| 381 | |
| 382 | if (*pos == '"') { |
| 383 | pos++; |
| 384 | start = pos; |
| 385 | while (*pos != '"' && *pos != '\0') |
| 386 | pos++; |
| 387 | if (*pos == '\0') { |
| 388 | wpa_printf(MSG_ERROR, "Invalid EAP password " |
| 389 | "(no \" in end) on line %d in '%s'", |
| 390 | line, fname); |
| 391 | goto failed; |
| 392 | } |
| 393 | |
| 394 | user->password = os_malloc(pos - start); |
| 395 | if (user->password == NULL) { |
| 396 | wpa_printf(MSG_ERROR, "Failed to allocate " |
| 397 | "memory for EAP password"); |
| 398 | goto failed; |
| 399 | } |
| 400 | os_memcpy(user->password, start, pos - start); |
| 401 | user->password_len = pos - start; |
| 402 | |
| 403 | pos++; |
| 404 | } else if (os_strncmp(pos, "hash:", 5) == 0) { |
| 405 | pos += 5; |
| 406 | pos2 = pos; |
| 407 | while (*pos2 != '\0' && *pos2 != ' ' && |
| 408 | *pos2 != '\t' && *pos2 != '#') |
| 409 | pos2++; |
| 410 | if (pos2 - pos != 32) { |
| 411 | wpa_printf(MSG_ERROR, "Invalid password hash " |
| 412 | "on line %d in '%s'", line, fname); |
| 413 | goto failed; |
| 414 | } |
| 415 | user->password = os_malloc(16); |
| 416 | if (user->password == NULL) { |
| 417 | wpa_printf(MSG_ERROR, "Failed to allocate " |
| 418 | "memory for EAP password hash"); |
| 419 | goto failed; |
| 420 | } |
| 421 | if (hexstr2bin(pos, user->password, 16) < 0) { |
| 422 | wpa_printf(MSG_ERROR, "Invalid hash password " |
| 423 | "on line %d in '%s'", line, fname); |
| 424 | goto failed; |
| 425 | } |
| 426 | user->password_len = 16; |
| 427 | user->password_hash = 1; |
| 428 | pos = pos2; |
| 429 | } else { |
| 430 | pos2 = pos; |
| 431 | while (*pos2 != '\0' && *pos2 != ' ' && |
| 432 | *pos2 != '\t' && *pos2 != '#') |
| 433 | pos2++; |
| 434 | if ((pos2 - pos) & 1) { |
| 435 | wpa_printf(MSG_ERROR, "Invalid hex password " |
| 436 | "on line %d in '%s'", line, fname); |
| 437 | goto failed; |
| 438 | } |
| 439 | user->password = os_malloc((pos2 - pos) / 2); |
| 440 | if (user->password == NULL) { |
| 441 | wpa_printf(MSG_ERROR, "Failed to allocate " |
| 442 | "memory for EAP password"); |
| 443 | goto failed; |
| 444 | } |
| 445 | if (hexstr2bin(pos, user->password, |
| 446 | (pos2 - pos) / 2) < 0) { |
| 447 | wpa_printf(MSG_ERROR, "Invalid hex password " |
| 448 | "on line %d in '%s'", line, fname); |
| 449 | goto failed; |
| 450 | } |
| 451 | user->password_len = (pos2 - pos) / 2; |
| 452 | pos = pos2; |
| 453 | } |
| 454 | |
| 455 | while (*pos == ' ' || *pos == '\t') |
| 456 | pos++; |
| 457 | if (os_strncmp(pos, "[2]", 3) == 0) { |
| 458 | user->phase2 = 1; |
| 459 | } |
| 460 | |
| 461 | done: |
| 462 | if (tail == NULL) { |
| 463 | tail = conf->eap_user = user; |
| 464 | } else { |
| 465 | tail->next = user; |
| 466 | tail = user; |
| 467 | } |
| 468 | continue; |
| 469 | |
| 470 | failed: |
| 471 | if (user) { |
| 472 | os_free(user->password); |
| 473 | os_free(user->identity); |
| 474 | os_free(user); |
| 475 | } |
| 476 | ret = -1; |
| 477 | break; |
| 478 | } |
| 479 | |
| 480 | fclose(f); |
| 481 | |
| 482 | return ret; |
| 483 | } |
| 484 | #endif /* EAP_SERVER */ |
| 485 | |
| 486 | |
| 487 | #ifndef CONFIG_NO_RADIUS |
| 488 | static int |
| 489 | hostapd_config_read_radius_addr(struct hostapd_radius_server **server, |
| 490 | int *num_server, const char *val, int def_port, |
| 491 | struct hostapd_radius_server **curr_serv) |
| 492 | { |
| 493 | struct hostapd_radius_server *nserv; |
| 494 | int ret; |
| 495 | static int server_index = 1; |
| 496 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 497 | nserv = os_realloc_array(*server, *num_server + 1, sizeof(*nserv)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 498 | if (nserv == NULL) |
| 499 | return -1; |
| 500 | |
| 501 | *server = nserv; |
| 502 | nserv = &nserv[*num_server]; |
| 503 | (*num_server)++; |
| 504 | (*curr_serv) = nserv; |
| 505 | |
| 506 | os_memset(nserv, 0, sizeof(*nserv)); |
| 507 | nserv->port = def_port; |
| 508 | ret = hostapd_parse_ip_addr(val, &nserv->addr); |
| 509 | nserv->index = server_index++; |
| 510 | |
| 511 | return ret; |
| 512 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 513 | |
| 514 | |
| 515 | static struct hostapd_radius_attr * |
| 516 | hostapd_parse_radius_attr(const char *value) |
| 517 | { |
| 518 | const char *pos; |
| 519 | char syntax; |
| 520 | struct hostapd_radius_attr *attr; |
| 521 | size_t len; |
| 522 | |
| 523 | attr = os_zalloc(sizeof(*attr)); |
| 524 | if (attr == NULL) |
| 525 | return NULL; |
| 526 | |
| 527 | attr->type = atoi(value); |
| 528 | |
| 529 | pos = os_strchr(value, ':'); |
| 530 | if (pos == NULL) { |
| 531 | attr->val = wpabuf_alloc(1); |
| 532 | if (attr->val == NULL) { |
| 533 | os_free(attr); |
| 534 | return NULL; |
| 535 | } |
| 536 | wpabuf_put_u8(attr->val, 0); |
| 537 | return attr; |
| 538 | } |
| 539 | |
| 540 | pos++; |
| 541 | if (pos[0] == '\0' || pos[1] != ':') { |
| 542 | os_free(attr); |
| 543 | return NULL; |
| 544 | } |
| 545 | syntax = *pos++; |
| 546 | pos++; |
| 547 | |
| 548 | switch (syntax) { |
| 549 | case 's': |
| 550 | attr->val = wpabuf_alloc_copy(pos, os_strlen(pos)); |
| 551 | break; |
| 552 | case 'x': |
| 553 | len = os_strlen(pos); |
| 554 | if (len & 1) |
| 555 | break; |
| 556 | len /= 2; |
| 557 | attr->val = wpabuf_alloc(len); |
| 558 | if (attr->val == NULL) |
| 559 | break; |
| 560 | if (hexstr2bin(pos, wpabuf_put(attr->val, len), len) < 0) { |
| 561 | wpabuf_free(attr->val); |
| 562 | os_free(attr); |
| 563 | return NULL; |
| 564 | } |
| 565 | break; |
| 566 | case 'd': |
| 567 | attr->val = wpabuf_alloc(4); |
| 568 | if (attr->val) |
| 569 | wpabuf_put_be32(attr->val, atoi(pos)); |
| 570 | break; |
| 571 | default: |
| 572 | os_free(attr); |
| 573 | return NULL; |
| 574 | } |
| 575 | |
| 576 | if (attr->val == NULL) { |
| 577 | os_free(attr); |
| 578 | return NULL; |
| 579 | } |
| 580 | |
| 581 | return attr; |
| 582 | } |
| 583 | |
| 584 | |
| 585 | static int hostapd_parse_das_client(struct hostapd_bss_config *bss, |
| 586 | const char *val) |
| 587 | { |
| 588 | char *secret; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 589 | |
| 590 | secret = os_strchr(val, ' '); |
| 591 | if (secret == NULL) |
| 592 | return -1; |
| 593 | |
| 594 | secret++; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 595 | |
| 596 | if (hostapd_parse_ip_addr(val, &bss->radius_das_client_addr)) |
| 597 | return -1; |
| 598 | |
| 599 | os_free(bss->radius_das_shared_secret); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 600 | bss->radius_das_shared_secret = (u8 *) os_strdup(secret); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 601 | if (bss->radius_das_shared_secret == NULL) |
| 602 | return -1; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 603 | bss->radius_das_shared_secret_len = os_strlen(secret); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 604 | |
| 605 | return 0; |
| 606 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 607 | #endif /* CONFIG_NO_RADIUS */ |
| 608 | |
| 609 | |
| 610 | static int hostapd_config_parse_key_mgmt(int line, const char *value) |
| 611 | { |
| 612 | int val = 0, last; |
| 613 | char *start, *end, *buf; |
| 614 | |
| 615 | buf = os_strdup(value); |
| 616 | if (buf == NULL) |
| 617 | return -1; |
| 618 | start = buf; |
| 619 | |
| 620 | while (*start != '\0') { |
| 621 | while (*start == ' ' || *start == '\t') |
| 622 | start++; |
| 623 | if (*start == '\0') |
| 624 | break; |
| 625 | end = start; |
| 626 | while (*end != ' ' && *end != '\t' && *end != '\0') |
| 627 | end++; |
| 628 | last = *end == '\0'; |
| 629 | *end = '\0'; |
| 630 | if (os_strcmp(start, "WPA-PSK") == 0) |
| 631 | val |= WPA_KEY_MGMT_PSK; |
| 632 | else if (os_strcmp(start, "WPA-EAP") == 0) |
| 633 | val |= WPA_KEY_MGMT_IEEE8021X; |
| 634 | #ifdef CONFIG_IEEE80211R |
| 635 | else if (os_strcmp(start, "FT-PSK") == 0) |
| 636 | val |= WPA_KEY_MGMT_FT_PSK; |
| 637 | else if (os_strcmp(start, "FT-EAP") == 0) |
| 638 | val |= WPA_KEY_MGMT_FT_IEEE8021X; |
| 639 | #endif /* CONFIG_IEEE80211R */ |
| 640 | #ifdef CONFIG_IEEE80211W |
| 641 | else if (os_strcmp(start, "WPA-PSK-SHA256") == 0) |
| 642 | val |= WPA_KEY_MGMT_PSK_SHA256; |
| 643 | else if (os_strcmp(start, "WPA-EAP-SHA256") == 0) |
| 644 | val |= WPA_KEY_MGMT_IEEE8021X_SHA256; |
| 645 | #endif /* CONFIG_IEEE80211W */ |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 646 | #ifdef CONFIG_SAE |
| 647 | else if (os_strcmp(start, "SAE") == 0) |
| 648 | val |= WPA_KEY_MGMT_SAE; |
| 649 | else if (os_strcmp(start, "FT-SAE") == 0) |
| 650 | val |= WPA_KEY_MGMT_FT_SAE; |
| 651 | #endif /* CONFIG_SAE */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 652 | else { |
| 653 | wpa_printf(MSG_ERROR, "Line %d: invalid key_mgmt '%s'", |
| 654 | line, start); |
| 655 | os_free(buf); |
| 656 | return -1; |
| 657 | } |
| 658 | |
| 659 | if (last) |
| 660 | break; |
| 661 | start = end + 1; |
| 662 | } |
| 663 | |
| 664 | os_free(buf); |
| 665 | if (val == 0) { |
| 666 | wpa_printf(MSG_ERROR, "Line %d: no key_mgmt values " |
| 667 | "configured.", line); |
| 668 | return -1; |
| 669 | } |
| 670 | |
| 671 | return val; |
| 672 | } |
| 673 | |
| 674 | |
| 675 | static int hostapd_config_parse_cipher(int line, const char *value) |
| 676 | { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 677 | int val = wpa_parse_cipher(value); |
| 678 | if (val < 0) { |
| 679 | wpa_printf(MSG_ERROR, "Line %d: invalid cipher '%s'.", |
| 680 | line, value); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 681 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 682 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 683 | if (val == 0) { |
| 684 | wpa_printf(MSG_ERROR, "Line %d: no cipher values configured.", |
| 685 | line); |
| 686 | return -1; |
| 687 | } |
| 688 | return val; |
| 689 | } |
| 690 | |
| 691 | |
| 692 | static int hostapd_config_read_wep(struct hostapd_wep_keys *wep, int keyidx, |
| 693 | char *val) |
| 694 | { |
| 695 | size_t len = os_strlen(val); |
| 696 | |
| 697 | if (keyidx < 0 || keyidx > 3 || wep->key[keyidx] != NULL) |
| 698 | return -1; |
| 699 | |
| 700 | if (val[0] == '"') { |
| 701 | if (len < 2 || val[len - 1] != '"') |
| 702 | return -1; |
| 703 | len -= 2; |
| 704 | wep->key[keyidx] = os_malloc(len); |
| 705 | if (wep->key[keyidx] == NULL) |
| 706 | return -1; |
| 707 | os_memcpy(wep->key[keyidx], val + 1, len); |
| 708 | wep->len[keyidx] = len; |
| 709 | } else { |
| 710 | if (len & 1) |
| 711 | return -1; |
| 712 | len /= 2; |
| 713 | wep->key[keyidx] = os_malloc(len); |
| 714 | if (wep->key[keyidx] == NULL) |
| 715 | return -1; |
| 716 | wep->len[keyidx] = len; |
| 717 | if (hexstr2bin(val, wep->key[keyidx], len) < 0) |
| 718 | return -1; |
| 719 | } |
| 720 | |
| 721 | wep->keys_set++; |
| 722 | |
| 723 | return 0; |
| 724 | } |
| 725 | |
| 726 | |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 727 | static int hostapd_parse_intlist(int **int_list, char *val) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 728 | { |
| 729 | int *list; |
| 730 | int count; |
| 731 | char *pos, *end; |
| 732 | |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 733 | os_free(*int_list); |
| 734 | *int_list = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 735 | |
| 736 | pos = val; |
| 737 | count = 0; |
| 738 | while (*pos != '\0') { |
| 739 | if (*pos == ' ') |
| 740 | count++; |
| 741 | pos++; |
| 742 | } |
| 743 | |
| 744 | list = os_malloc(sizeof(int) * (count + 2)); |
| 745 | if (list == NULL) |
| 746 | return -1; |
| 747 | pos = val; |
| 748 | count = 0; |
| 749 | while (*pos != '\0') { |
| 750 | end = os_strchr(pos, ' '); |
| 751 | if (end) |
| 752 | *end = '\0'; |
| 753 | |
| 754 | list[count++] = atoi(pos); |
| 755 | if (!end) |
| 756 | break; |
| 757 | pos = end + 1; |
| 758 | } |
| 759 | list[count] = -1; |
| 760 | |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 761 | *int_list = list; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 762 | return 0; |
| 763 | } |
| 764 | |
| 765 | |
| 766 | static int hostapd_config_bss(struct hostapd_config *conf, const char *ifname) |
| 767 | { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 768 | struct hostapd_bss_config **all, *bss; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 769 | |
| 770 | if (*ifname == '\0') |
| 771 | return -1; |
| 772 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 773 | all = os_realloc_array(conf->bss, conf->num_bss + 1, |
| 774 | sizeof(struct hostapd_bss_config *)); |
| 775 | if (all == NULL) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 776 | wpa_printf(MSG_ERROR, "Failed to allocate memory for " |
| 777 | "multi-BSS entry"); |
| 778 | return -1; |
| 779 | } |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 780 | conf->bss = all; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 781 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 782 | bss = os_zalloc(sizeof(*bss)); |
| 783 | if (bss == NULL) |
| 784 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 785 | bss->radius = os_zalloc(sizeof(*bss->radius)); |
| 786 | if (bss->radius == NULL) { |
| 787 | wpa_printf(MSG_ERROR, "Failed to allocate memory for " |
| 788 | "multi-BSS RADIUS data"); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 789 | os_free(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 790 | return -1; |
| 791 | } |
| 792 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 793 | conf->bss[conf->num_bss++] = bss; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 794 | conf->last_bss = bss; |
| 795 | |
| 796 | hostapd_config_defaults_bss(bss); |
| 797 | os_strlcpy(bss->iface, ifname, sizeof(bss->iface)); |
| 798 | os_memcpy(bss->ssid.vlan, bss->iface, IFNAMSIZ + 1); |
| 799 | |
| 800 | return 0; |
| 801 | } |
| 802 | |
| 803 | |
| 804 | /* convert floats with one decimal place to value*10 int, i.e., |
| 805 | * "1.5" will return 15 */ |
| 806 | static int hostapd_config_read_int10(const char *value) |
| 807 | { |
| 808 | int i, d; |
| 809 | char *pos; |
| 810 | |
| 811 | i = atoi(value); |
| 812 | pos = os_strchr(value, '.'); |
| 813 | d = 0; |
| 814 | if (pos) { |
| 815 | pos++; |
| 816 | if (*pos >= '0' && *pos <= '9') |
| 817 | d = *pos - '0'; |
| 818 | } |
| 819 | |
| 820 | return i * 10 + d; |
| 821 | } |
| 822 | |
| 823 | |
| 824 | static int valid_cw(int cw) |
| 825 | { |
| 826 | return (cw == 1 || cw == 3 || cw == 7 || cw == 15 || cw == 31 || |
| 827 | cw == 63 || cw == 127 || cw == 255 || cw == 511 || cw == 1023); |
| 828 | } |
| 829 | |
| 830 | |
| 831 | enum { |
| 832 | IEEE80211_TX_QUEUE_DATA0 = 0, /* used for EDCA AC_VO data */ |
| 833 | IEEE80211_TX_QUEUE_DATA1 = 1, /* used for EDCA AC_VI data */ |
| 834 | IEEE80211_TX_QUEUE_DATA2 = 2, /* used for EDCA AC_BE data */ |
| 835 | IEEE80211_TX_QUEUE_DATA3 = 3 /* used for EDCA AC_BK data */ |
| 836 | }; |
| 837 | |
| 838 | static int hostapd_config_tx_queue(struct hostapd_config *conf, char *name, |
| 839 | char *val) |
| 840 | { |
| 841 | int num; |
| 842 | char *pos; |
| 843 | struct hostapd_tx_queue_params *queue; |
| 844 | |
| 845 | /* skip 'tx_queue_' prefix */ |
| 846 | pos = name + 9; |
| 847 | if (os_strncmp(pos, "data", 4) == 0 && |
| 848 | pos[4] >= '0' && pos[4] <= '9' && pos[5] == '_') { |
| 849 | num = pos[4] - '0'; |
| 850 | pos += 6; |
| 851 | } else if (os_strncmp(pos, "after_beacon_", 13) == 0 || |
| 852 | os_strncmp(pos, "beacon_", 7) == 0) { |
| 853 | wpa_printf(MSG_INFO, "DEPRECATED: '%s' not used", name); |
| 854 | return 0; |
| 855 | } else { |
| 856 | wpa_printf(MSG_ERROR, "Unknown tx_queue name '%s'", pos); |
| 857 | return -1; |
| 858 | } |
| 859 | |
| 860 | if (num >= NUM_TX_QUEUES) { |
| 861 | /* for backwards compatibility, do not trigger failure */ |
| 862 | wpa_printf(MSG_INFO, "DEPRECATED: '%s' not used", name); |
| 863 | return 0; |
| 864 | } |
| 865 | |
| 866 | queue = &conf->tx_queue[num]; |
| 867 | |
| 868 | if (os_strcmp(pos, "aifs") == 0) { |
| 869 | queue->aifs = atoi(val); |
| 870 | if (queue->aifs < 0 || queue->aifs > 255) { |
| 871 | wpa_printf(MSG_ERROR, "Invalid AIFS value %d", |
| 872 | queue->aifs); |
| 873 | return -1; |
| 874 | } |
| 875 | } else if (os_strcmp(pos, "cwmin") == 0) { |
| 876 | queue->cwmin = atoi(val); |
| 877 | if (!valid_cw(queue->cwmin)) { |
| 878 | wpa_printf(MSG_ERROR, "Invalid cwMin value %d", |
| 879 | queue->cwmin); |
| 880 | return -1; |
| 881 | } |
| 882 | } else if (os_strcmp(pos, "cwmax") == 0) { |
| 883 | queue->cwmax = atoi(val); |
| 884 | if (!valid_cw(queue->cwmax)) { |
| 885 | wpa_printf(MSG_ERROR, "Invalid cwMax value %d", |
| 886 | queue->cwmax); |
| 887 | return -1; |
| 888 | } |
| 889 | } else if (os_strcmp(pos, "burst") == 0) { |
| 890 | queue->burst = hostapd_config_read_int10(val); |
| 891 | } else { |
| 892 | wpa_printf(MSG_ERROR, "Unknown tx_queue field '%s'", pos); |
| 893 | return -1; |
| 894 | } |
| 895 | |
| 896 | return 0; |
| 897 | } |
| 898 | |
| 899 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 900 | #ifdef CONFIG_IEEE80211R |
| 901 | static int add_r0kh(struct hostapd_bss_config *bss, char *value) |
| 902 | { |
| 903 | struct ft_remote_r0kh *r0kh; |
| 904 | char *pos, *next; |
| 905 | |
| 906 | r0kh = os_zalloc(sizeof(*r0kh)); |
| 907 | if (r0kh == NULL) |
| 908 | return -1; |
| 909 | |
| 910 | /* 02:01:02:03:04:05 a.example.com 000102030405060708090a0b0c0d0e0f */ |
| 911 | pos = value; |
| 912 | next = os_strchr(pos, ' '); |
| 913 | if (next) |
| 914 | *next++ = '\0'; |
| 915 | if (next == NULL || hwaddr_aton(pos, r0kh->addr)) { |
| 916 | wpa_printf(MSG_ERROR, "Invalid R0KH MAC address: '%s'", pos); |
| 917 | os_free(r0kh); |
| 918 | return -1; |
| 919 | } |
| 920 | |
| 921 | pos = next; |
| 922 | next = os_strchr(pos, ' '); |
| 923 | if (next) |
| 924 | *next++ = '\0'; |
| 925 | if (next == NULL || next - pos > FT_R0KH_ID_MAX_LEN) { |
| 926 | wpa_printf(MSG_ERROR, "Invalid R0KH-ID: '%s'", pos); |
| 927 | os_free(r0kh); |
| 928 | return -1; |
| 929 | } |
| 930 | r0kh->id_len = next - pos - 1; |
| 931 | os_memcpy(r0kh->id, pos, r0kh->id_len); |
| 932 | |
| 933 | pos = next; |
| 934 | if (hexstr2bin(pos, r0kh->key, sizeof(r0kh->key))) { |
| 935 | wpa_printf(MSG_ERROR, "Invalid R0KH key: '%s'", pos); |
| 936 | os_free(r0kh); |
| 937 | return -1; |
| 938 | } |
| 939 | |
| 940 | r0kh->next = bss->r0kh_list; |
| 941 | bss->r0kh_list = r0kh; |
| 942 | |
| 943 | return 0; |
| 944 | } |
| 945 | |
| 946 | |
| 947 | static int add_r1kh(struct hostapd_bss_config *bss, char *value) |
| 948 | { |
| 949 | struct ft_remote_r1kh *r1kh; |
| 950 | char *pos, *next; |
| 951 | |
| 952 | r1kh = os_zalloc(sizeof(*r1kh)); |
| 953 | if (r1kh == NULL) |
| 954 | return -1; |
| 955 | |
| 956 | /* 02:01:02:03:04:05 02:01:02:03:04:05 |
| 957 | * 000102030405060708090a0b0c0d0e0f */ |
| 958 | pos = value; |
| 959 | next = os_strchr(pos, ' '); |
| 960 | if (next) |
| 961 | *next++ = '\0'; |
| 962 | if (next == NULL || hwaddr_aton(pos, r1kh->addr)) { |
| 963 | wpa_printf(MSG_ERROR, "Invalid R1KH MAC address: '%s'", pos); |
| 964 | os_free(r1kh); |
| 965 | return -1; |
| 966 | } |
| 967 | |
| 968 | pos = next; |
| 969 | next = os_strchr(pos, ' '); |
| 970 | if (next) |
| 971 | *next++ = '\0'; |
| 972 | if (next == NULL || hwaddr_aton(pos, r1kh->id)) { |
| 973 | wpa_printf(MSG_ERROR, "Invalid R1KH-ID: '%s'", pos); |
| 974 | os_free(r1kh); |
| 975 | return -1; |
| 976 | } |
| 977 | |
| 978 | pos = next; |
| 979 | if (hexstr2bin(pos, r1kh->key, sizeof(r1kh->key))) { |
| 980 | wpa_printf(MSG_ERROR, "Invalid R1KH key: '%s'", pos); |
| 981 | os_free(r1kh); |
| 982 | return -1; |
| 983 | } |
| 984 | |
| 985 | r1kh->next = bss->r1kh_list; |
| 986 | bss->r1kh_list = r1kh; |
| 987 | |
| 988 | return 0; |
| 989 | } |
| 990 | #endif /* CONFIG_IEEE80211R */ |
| 991 | |
| 992 | |
| 993 | #ifdef CONFIG_IEEE80211N |
| 994 | static int hostapd_config_ht_capab(struct hostapd_config *conf, |
| 995 | const char *capab) |
| 996 | { |
| 997 | if (os_strstr(capab, "[LDPC]")) |
| 998 | conf->ht_capab |= HT_CAP_INFO_LDPC_CODING_CAP; |
| 999 | if (os_strstr(capab, "[HT40-]")) { |
| 1000 | conf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET; |
| 1001 | conf->secondary_channel = -1; |
| 1002 | } |
| 1003 | if (os_strstr(capab, "[HT40+]")) { |
| 1004 | conf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET; |
| 1005 | conf->secondary_channel = 1; |
| 1006 | } |
| 1007 | if (os_strstr(capab, "[SMPS-STATIC]")) { |
| 1008 | conf->ht_capab &= ~HT_CAP_INFO_SMPS_MASK; |
| 1009 | conf->ht_capab |= HT_CAP_INFO_SMPS_STATIC; |
| 1010 | } |
| 1011 | if (os_strstr(capab, "[SMPS-DYNAMIC]")) { |
| 1012 | conf->ht_capab &= ~HT_CAP_INFO_SMPS_MASK; |
| 1013 | conf->ht_capab |= HT_CAP_INFO_SMPS_DYNAMIC; |
| 1014 | } |
| 1015 | if (os_strstr(capab, "[GF]")) |
| 1016 | conf->ht_capab |= HT_CAP_INFO_GREEN_FIELD; |
| 1017 | if (os_strstr(capab, "[SHORT-GI-20]")) |
| 1018 | conf->ht_capab |= HT_CAP_INFO_SHORT_GI20MHZ; |
| 1019 | if (os_strstr(capab, "[SHORT-GI-40]")) |
| 1020 | conf->ht_capab |= HT_CAP_INFO_SHORT_GI40MHZ; |
| 1021 | if (os_strstr(capab, "[TX-STBC]")) |
| 1022 | conf->ht_capab |= HT_CAP_INFO_TX_STBC; |
| 1023 | if (os_strstr(capab, "[RX-STBC1]")) { |
| 1024 | conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK; |
| 1025 | conf->ht_capab |= HT_CAP_INFO_RX_STBC_1; |
| 1026 | } |
| 1027 | if (os_strstr(capab, "[RX-STBC12]")) { |
| 1028 | conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK; |
| 1029 | conf->ht_capab |= HT_CAP_INFO_RX_STBC_12; |
| 1030 | } |
| 1031 | if (os_strstr(capab, "[RX-STBC123]")) { |
| 1032 | conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK; |
| 1033 | conf->ht_capab |= HT_CAP_INFO_RX_STBC_123; |
| 1034 | } |
| 1035 | if (os_strstr(capab, "[DELAYED-BA]")) |
| 1036 | conf->ht_capab |= HT_CAP_INFO_DELAYED_BA; |
| 1037 | if (os_strstr(capab, "[MAX-AMSDU-7935]")) |
| 1038 | conf->ht_capab |= HT_CAP_INFO_MAX_AMSDU_SIZE; |
| 1039 | if (os_strstr(capab, "[DSSS_CCK-40]")) |
| 1040 | conf->ht_capab |= HT_CAP_INFO_DSSS_CCK40MHZ; |
| 1041 | if (os_strstr(capab, "[PSMP]")) |
| 1042 | conf->ht_capab |= HT_CAP_INFO_PSMP_SUPP; |
| 1043 | if (os_strstr(capab, "[LSIG-TXOP-PROT]")) |
| 1044 | conf->ht_capab |= HT_CAP_INFO_LSIG_TXOP_PROTECT_SUPPORT; |
| 1045 | |
| 1046 | return 0; |
| 1047 | } |
| 1048 | #endif /* CONFIG_IEEE80211N */ |
| 1049 | |
| 1050 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1051 | #ifdef CONFIG_IEEE80211AC |
| 1052 | static int hostapd_config_vht_capab(struct hostapd_config *conf, |
| 1053 | const char *capab) |
| 1054 | { |
| 1055 | if (os_strstr(capab, "[MAX-MPDU-7991]")) |
| 1056 | conf->vht_capab |= VHT_CAP_MAX_MPDU_LENGTH_7991; |
| 1057 | if (os_strstr(capab, "[MAX-MPDU-11454]")) |
| 1058 | conf->vht_capab |= VHT_CAP_MAX_MPDU_LENGTH_11454; |
| 1059 | if (os_strstr(capab, "[VHT160]")) |
| 1060 | conf->vht_capab |= VHT_CAP_SUPP_CHAN_WIDTH_160MHZ; |
| 1061 | if (os_strstr(capab, "[VHT160-80PLUS80]")) |
| 1062 | conf->vht_capab |= VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ; |
| 1063 | if (os_strstr(capab, "[VHT160-80PLUS80]")) |
| 1064 | conf->vht_capab |= VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ; |
| 1065 | if (os_strstr(capab, "[RXLDPC]")) |
| 1066 | conf->vht_capab |= VHT_CAP_RXLDPC; |
| 1067 | if (os_strstr(capab, "[SHORT-GI-80]")) |
| 1068 | conf->vht_capab |= VHT_CAP_SHORT_GI_80; |
| 1069 | if (os_strstr(capab, "[SHORT-GI-160]")) |
| 1070 | conf->vht_capab |= VHT_CAP_SHORT_GI_160; |
| 1071 | if (os_strstr(capab, "[TX-STBC-2BY1]")) |
| 1072 | conf->vht_capab |= VHT_CAP_TXSTBC; |
| 1073 | if (os_strstr(capab, "[RX-STBC-1]")) |
| 1074 | conf->vht_capab |= VHT_CAP_RXSTBC_1; |
| 1075 | if (os_strstr(capab, "[RX-STBC-12]")) |
| 1076 | conf->vht_capab |= VHT_CAP_RXSTBC_2; |
| 1077 | if (os_strstr(capab, "[RX-STBC-123]")) |
| 1078 | conf->vht_capab |= VHT_CAP_RXSTBC_3; |
| 1079 | if (os_strstr(capab, "[RX-STBC-1234]")) |
| 1080 | conf->vht_capab |= VHT_CAP_RXSTBC_4; |
| 1081 | if (os_strstr(capab, "[SU-BEAMFORMER]")) |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1082 | conf->vht_capab |= VHT_CAP_SU_BEAMFORMER_CAPABLE; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1083 | if (os_strstr(capab, "[SU-BEAMFORMEE]")) |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1084 | conf->vht_capab |= VHT_CAP_SU_BEAMFORMEE_CAPABLE; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1085 | if (os_strstr(capab, "[BF-ANTENNA-2]") && |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1086 | (conf->vht_capab & VHT_CAP_SU_BEAMFORMEE_CAPABLE)) |
| 1087 | conf->vht_capab |= (1 << VHT_CAP_BEAMFORMEE_STS_OFFSET); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1088 | if (os_strstr(capab, "[SOUNDING-DIMENSION-2]") && |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1089 | (conf->vht_capab & VHT_CAP_SU_BEAMFORMER_CAPABLE)) |
| 1090 | conf->vht_capab |= (1 << VHT_CAP_SOUNDING_DIMENSION_OFFSET); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1091 | if (os_strstr(capab, "[MU-BEAMFORMER]")) |
| 1092 | conf->vht_capab |= VHT_CAP_MU_BEAMFORMER_CAPABLE; |
| 1093 | if (os_strstr(capab, "[MU-BEAMFORMEE]")) |
| 1094 | conf->vht_capab |= VHT_CAP_MU_BEAMFORMEE_CAPABLE; |
| 1095 | if (os_strstr(capab, "[VHT-TXOP-PS]")) |
| 1096 | conf->vht_capab |= VHT_CAP_VHT_TXOP_PS; |
| 1097 | if (os_strstr(capab, "[HTC-VHT]")) |
| 1098 | conf->vht_capab |= VHT_CAP_HTC_VHT; |
| 1099 | if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP0]")) |
| 1100 | conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT; |
| 1101 | if (os_strstr(capab, "[VHT-LINK-ADAPT2]") && |
| 1102 | (conf->vht_capab & VHT_CAP_HTC_VHT)) |
| 1103 | conf->vht_capab |= VHT_CAP_VHT_LINK_ADAPTATION_VHT_UNSOL_MFB; |
| 1104 | if (os_strstr(capab, "[VHT-LINK-ADAPT3]") && |
| 1105 | (conf->vht_capab & VHT_CAP_HTC_VHT)) |
| 1106 | conf->vht_capab |= VHT_CAP_VHT_LINK_ADAPTATION_VHT_MRQ_MFB; |
| 1107 | if (os_strstr(capab, "[RX-ANTENNA-PATTERN]")) |
| 1108 | conf->vht_capab |= VHT_CAP_RX_ANTENNA_PATTERN; |
| 1109 | if (os_strstr(capab, "[TX-ANTENNA-PATTERN]")) |
| 1110 | conf->vht_capab |= VHT_CAP_TX_ANTENNA_PATTERN; |
| 1111 | return 0; |
| 1112 | } |
| 1113 | #endif /* CONFIG_IEEE80211AC */ |
| 1114 | |
| 1115 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1116 | #ifdef CONFIG_INTERWORKING |
| 1117 | static int parse_roaming_consortium(struct hostapd_bss_config *bss, char *pos, |
| 1118 | int line) |
| 1119 | { |
| 1120 | size_t len = os_strlen(pos); |
| 1121 | u8 oi[MAX_ROAMING_CONSORTIUM_LEN]; |
| 1122 | |
| 1123 | struct hostapd_roaming_consortium *rc; |
| 1124 | |
| 1125 | if ((len & 1) || len < 2 * 3 || len / 2 > MAX_ROAMING_CONSORTIUM_LEN || |
| 1126 | hexstr2bin(pos, oi, len / 2)) { |
| 1127 | wpa_printf(MSG_ERROR, "Line %d: invalid roaming_consortium " |
| 1128 | "'%s'", line, pos); |
| 1129 | return -1; |
| 1130 | } |
| 1131 | len /= 2; |
| 1132 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1133 | rc = os_realloc_array(bss->roaming_consortium, |
| 1134 | bss->roaming_consortium_count + 1, |
| 1135 | sizeof(struct hostapd_roaming_consortium)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1136 | if (rc == NULL) |
| 1137 | return -1; |
| 1138 | |
| 1139 | os_memcpy(rc[bss->roaming_consortium_count].oi, oi, len); |
| 1140 | rc[bss->roaming_consortium_count].len = len; |
| 1141 | |
| 1142 | bss->roaming_consortium = rc; |
| 1143 | bss->roaming_consortium_count++; |
| 1144 | |
| 1145 | return 0; |
| 1146 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1147 | |
| 1148 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1149 | static int parse_lang_string(struct hostapd_lang_string **array, |
| 1150 | unsigned int *count, char *pos) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1151 | { |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 1152 | char *sep, *str = NULL; |
| 1153 | size_t clen, nlen, slen; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1154 | struct hostapd_lang_string *ls; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 1155 | int ret = -1; |
| 1156 | |
| 1157 | if (*pos == '"' || (*pos == 'P' && pos[1] == '"')) { |
| 1158 | str = wpa_config_parse_string(pos, &slen); |
| 1159 | if (!str) |
| 1160 | return -1; |
| 1161 | pos = str; |
| 1162 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1163 | |
| 1164 | sep = os_strchr(pos, ':'); |
| 1165 | if (sep == NULL) |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 1166 | goto fail; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1167 | *sep++ = '\0'; |
| 1168 | |
| 1169 | clen = os_strlen(pos); |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 1170 | if (clen < 2 || clen > sizeof(ls->lang)) |
| 1171 | goto fail; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1172 | nlen = os_strlen(sep); |
| 1173 | if (nlen > 252) |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 1174 | goto fail; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1175 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1176 | ls = os_realloc_array(*array, *count + 1, |
| 1177 | sizeof(struct hostapd_lang_string)); |
| 1178 | if (ls == NULL) |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 1179 | goto fail; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1180 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1181 | *array = ls; |
| 1182 | ls = &(*array)[*count]; |
| 1183 | (*count)++; |
| 1184 | |
| 1185 | os_memset(ls->lang, 0, sizeof(ls->lang)); |
| 1186 | os_memcpy(ls->lang, pos, clen); |
| 1187 | ls->name_len = nlen; |
| 1188 | os_memcpy(ls->name, sep, nlen); |
| 1189 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 1190 | ret = 0; |
| 1191 | fail: |
| 1192 | os_free(str); |
| 1193 | return ret; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1194 | } |
| 1195 | |
| 1196 | |
| 1197 | static int parse_venue_name(struct hostapd_bss_config *bss, char *pos, |
| 1198 | int line) |
| 1199 | { |
| 1200 | if (parse_lang_string(&bss->venue_name, &bss->venue_name_count, pos)) { |
| 1201 | wpa_printf(MSG_ERROR, "Line %d: Invalid venue_name '%s'", |
| 1202 | line, pos); |
| 1203 | return -1; |
| 1204 | } |
| 1205 | return 0; |
| 1206 | } |
| 1207 | |
| 1208 | |
| 1209 | static int parse_3gpp_cell_net(struct hostapd_bss_config *bss, char *buf, |
| 1210 | int line) |
| 1211 | { |
| 1212 | size_t count; |
| 1213 | char *pos; |
| 1214 | u8 *info = NULL, *ipos; |
| 1215 | |
| 1216 | /* format: <MCC1,MNC1>[;<MCC2,MNC2>][;...] */ |
| 1217 | |
| 1218 | count = 1; |
| 1219 | for (pos = buf; *pos; pos++) { |
| 1220 | if ((*pos < '0' && *pos > '9') && *pos != ';' && *pos != ',') |
| 1221 | goto fail; |
| 1222 | if (*pos == ';') |
| 1223 | count++; |
| 1224 | } |
| 1225 | if (1 + count * 3 > 0x7f) |
| 1226 | goto fail; |
| 1227 | |
| 1228 | info = os_zalloc(2 + 3 + count * 3); |
| 1229 | if (info == NULL) |
| 1230 | return -1; |
| 1231 | |
| 1232 | ipos = info; |
| 1233 | *ipos++ = 0; /* GUD - Version 1 */ |
| 1234 | *ipos++ = 3 + count * 3; /* User Data Header Length (UDHL) */ |
| 1235 | *ipos++ = 0; /* PLMN List IEI */ |
| 1236 | /* ext(b8) | Length of PLMN List value contents(b7..1) */ |
| 1237 | *ipos++ = 1 + count * 3; |
| 1238 | *ipos++ = count; /* Number of PLMNs */ |
| 1239 | |
| 1240 | pos = buf; |
| 1241 | while (pos && *pos) { |
| 1242 | char *mcc, *mnc; |
| 1243 | size_t mnc_len; |
| 1244 | |
| 1245 | mcc = pos; |
| 1246 | mnc = os_strchr(pos, ','); |
| 1247 | if (mnc == NULL) |
| 1248 | goto fail; |
| 1249 | *mnc++ = '\0'; |
| 1250 | pos = os_strchr(mnc, ';'); |
| 1251 | if (pos) |
| 1252 | *pos++ = '\0'; |
| 1253 | |
| 1254 | mnc_len = os_strlen(mnc); |
| 1255 | if (os_strlen(mcc) != 3 || (mnc_len != 2 && mnc_len != 3)) |
| 1256 | goto fail; |
| 1257 | |
| 1258 | /* BC coded MCC,MNC */ |
| 1259 | /* MCC digit 2 | MCC digit 1 */ |
| 1260 | *ipos++ = ((mcc[1] - '0') << 4) | (mcc[0] - '0'); |
| 1261 | /* MNC digit 3 | MCC digit 3 */ |
| 1262 | *ipos++ = (((mnc_len == 2) ? 0xf0 : ((mnc[2] - '0') << 4))) | |
| 1263 | (mcc[2] - '0'); |
| 1264 | /* MNC digit 2 | MNC digit 1 */ |
| 1265 | *ipos++ = ((mnc[1] - '0') << 4) | (mnc[0] - '0'); |
| 1266 | } |
| 1267 | |
| 1268 | os_free(bss->anqp_3gpp_cell_net); |
| 1269 | bss->anqp_3gpp_cell_net = info; |
| 1270 | bss->anqp_3gpp_cell_net_len = 2 + 3 + 3 * count; |
| 1271 | wpa_hexdump(MSG_MSGDUMP, "3GPP Cellular Network information", |
| 1272 | bss->anqp_3gpp_cell_net, bss->anqp_3gpp_cell_net_len); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1273 | |
| 1274 | return 0; |
| 1275 | |
| 1276 | fail: |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1277 | wpa_printf(MSG_ERROR, "Line %d: Invalid anqp_3gpp_cell_net: %s", |
| 1278 | line, buf); |
| 1279 | os_free(info); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1280 | return -1; |
| 1281 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1282 | |
| 1283 | |
| 1284 | static int parse_nai_realm(struct hostapd_bss_config *bss, char *buf, int line) |
| 1285 | { |
| 1286 | struct hostapd_nai_realm_data *realm; |
| 1287 | size_t i, j, len; |
| 1288 | int *offsets; |
| 1289 | char *pos, *end, *rpos; |
| 1290 | |
| 1291 | offsets = os_calloc(bss->nai_realm_count * MAX_NAI_REALMS, |
| 1292 | sizeof(int)); |
| 1293 | if (offsets == NULL) |
| 1294 | return -1; |
| 1295 | |
| 1296 | for (i = 0; i < bss->nai_realm_count; i++) { |
| 1297 | realm = &bss->nai_realm_data[i]; |
| 1298 | for (j = 0; j < MAX_NAI_REALMS; j++) { |
| 1299 | offsets[i * MAX_NAI_REALMS + j] = |
| 1300 | realm->realm[j] ? |
| 1301 | realm->realm[j] - realm->realm_buf : -1; |
| 1302 | } |
| 1303 | } |
| 1304 | |
| 1305 | realm = os_realloc_array(bss->nai_realm_data, bss->nai_realm_count + 1, |
| 1306 | sizeof(struct hostapd_nai_realm_data)); |
| 1307 | if (realm == NULL) { |
| 1308 | os_free(offsets); |
| 1309 | return -1; |
| 1310 | } |
| 1311 | bss->nai_realm_data = realm; |
| 1312 | |
| 1313 | /* patch the pointers after realloc */ |
| 1314 | for (i = 0; i < bss->nai_realm_count; i++) { |
| 1315 | realm = &bss->nai_realm_data[i]; |
| 1316 | for (j = 0; j < MAX_NAI_REALMS; j++) { |
| 1317 | int offs = offsets[i * MAX_NAI_REALMS + j]; |
| 1318 | if (offs >= 0) |
| 1319 | realm->realm[j] = realm->realm_buf + offs; |
| 1320 | else |
| 1321 | realm->realm[j] = NULL; |
| 1322 | } |
| 1323 | } |
| 1324 | os_free(offsets); |
| 1325 | |
| 1326 | realm = &bss->nai_realm_data[bss->nai_realm_count]; |
| 1327 | os_memset(realm, 0, sizeof(*realm)); |
| 1328 | |
| 1329 | pos = buf; |
| 1330 | realm->encoding = atoi(pos); |
| 1331 | pos = os_strchr(pos, ','); |
| 1332 | if (pos == NULL) |
| 1333 | goto fail; |
| 1334 | pos++; |
| 1335 | |
| 1336 | end = os_strchr(pos, ','); |
| 1337 | if (end) { |
| 1338 | len = end - pos; |
| 1339 | *end = '\0'; |
| 1340 | } else { |
| 1341 | len = os_strlen(pos); |
| 1342 | } |
| 1343 | |
| 1344 | if (len > MAX_NAI_REALMLEN) { |
| 1345 | wpa_printf(MSG_ERROR, "Too long a realm string (%d > max %d " |
| 1346 | "characters)", (int) len, MAX_NAI_REALMLEN); |
| 1347 | goto fail; |
| 1348 | } |
| 1349 | os_memcpy(realm->realm_buf, pos, len); |
| 1350 | |
| 1351 | if (end) |
| 1352 | pos = end + 1; |
| 1353 | else |
| 1354 | pos = NULL; |
| 1355 | |
| 1356 | while (pos && *pos) { |
| 1357 | struct hostapd_nai_realm_eap *eap; |
| 1358 | |
| 1359 | if (realm->eap_method_count >= MAX_NAI_EAP_METHODS) { |
| 1360 | wpa_printf(MSG_ERROR, "Too many EAP methods"); |
| 1361 | goto fail; |
| 1362 | } |
| 1363 | |
| 1364 | eap = &realm->eap_method[realm->eap_method_count]; |
| 1365 | realm->eap_method_count++; |
| 1366 | |
| 1367 | end = os_strchr(pos, ','); |
| 1368 | if (end == NULL) |
| 1369 | end = pos + os_strlen(pos); |
| 1370 | |
| 1371 | eap->eap_method = atoi(pos); |
| 1372 | for (;;) { |
| 1373 | pos = os_strchr(pos, '['); |
| 1374 | if (pos == NULL || pos > end) |
| 1375 | break; |
| 1376 | pos++; |
| 1377 | if (eap->num_auths >= MAX_NAI_AUTH_TYPES) { |
| 1378 | wpa_printf(MSG_ERROR, "Too many auth params"); |
| 1379 | goto fail; |
| 1380 | } |
| 1381 | eap->auth_id[eap->num_auths] = atoi(pos); |
| 1382 | pos = os_strchr(pos, ':'); |
| 1383 | if (pos == NULL || pos > end) |
| 1384 | goto fail; |
| 1385 | pos++; |
| 1386 | eap->auth_val[eap->num_auths] = atoi(pos); |
| 1387 | pos = os_strchr(pos, ']'); |
| 1388 | if (pos == NULL || pos > end) |
| 1389 | goto fail; |
| 1390 | pos++; |
| 1391 | eap->num_auths++; |
| 1392 | } |
| 1393 | |
| 1394 | if (*end != ',') |
| 1395 | break; |
| 1396 | |
| 1397 | pos = end + 1; |
| 1398 | } |
| 1399 | |
| 1400 | /* Split realm list into null terminated realms */ |
| 1401 | rpos = realm->realm_buf; |
| 1402 | i = 0; |
| 1403 | while (*rpos) { |
| 1404 | if (i >= MAX_NAI_REALMS) { |
| 1405 | wpa_printf(MSG_ERROR, "Too many realms"); |
| 1406 | goto fail; |
| 1407 | } |
| 1408 | realm->realm[i++] = rpos; |
| 1409 | rpos = os_strchr(rpos, ';'); |
| 1410 | if (rpos == NULL) |
| 1411 | break; |
| 1412 | *rpos++ = '\0'; |
| 1413 | } |
| 1414 | |
| 1415 | bss->nai_realm_count++; |
| 1416 | |
| 1417 | return 0; |
| 1418 | |
| 1419 | fail: |
| 1420 | wpa_printf(MSG_ERROR, "Line %d: invalid nai_realm '%s'", line, buf); |
| 1421 | return -1; |
| 1422 | } |
| 1423 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 1424 | |
| 1425 | static int parse_qos_map_set(struct hostapd_bss_config *bss, |
| 1426 | char *buf, int line) |
| 1427 | { |
| 1428 | u8 qos_map_set[16 + 2 * 21], count = 0; |
| 1429 | char *pos = buf; |
| 1430 | int val; |
| 1431 | |
| 1432 | for (;;) { |
| 1433 | if (count == sizeof(qos_map_set)) { |
| 1434 | wpa_printf(MSG_ERROR, "Line %d: Too many qos_map_set " |
| 1435 | "parameters '%s'", line, buf); |
| 1436 | return -1; |
| 1437 | } |
| 1438 | |
| 1439 | val = atoi(pos); |
| 1440 | if (val > 255 || val < 0) { |
| 1441 | wpa_printf(MSG_ERROR, "Line %d: Invalid qos_map_set " |
| 1442 | "'%s'", line, buf); |
| 1443 | return -1; |
| 1444 | } |
| 1445 | |
| 1446 | qos_map_set[count++] = val; |
| 1447 | pos = os_strchr(pos, ','); |
| 1448 | if (!pos) |
| 1449 | break; |
| 1450 | pos++; |
| 1451 | } |
| 1452 | |
| 1453 | if (count < 16 || count & 1) { |
| 1454 | wpa_printf(MSG_ERROR, "Line %d: Invalid qos_map_set '%s'", |
| 1455 | line, buf); |
| 1456 | return -1; |
| 1457 | } |
| 1458 | |
| 1459 | os_memcpy(bss->qos_map_set, qos_map_set, count); |
| 1460 | bss->qos_map_set_len = count; |
| 1461 | |
| 1462 | return 0; |
| 1463 | } |
| 1464 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1465 | #endif /* CONFIG_INTERWORKING */ |
| 1466 | |
| 1467 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1468 | #ifdef CONFIG_HS20 |
| 1469 | static int hs20_parse_conn_capab(struct hostapd_bss_config *bss, char *buf, |
| 1470 | int line) |
| 1471 | { |
| 1472 | u8 *conn_cap; |
| 1473 | char *pos; |
| 1474 | |
| 1475 | if (bss->hs20_connection_capability_len >= 0xfff0) |
| 1476 | return -1; |
| 1477 | |
| 1478 | conn_cap = os_realloc(bss->hs20_connection_capability, |
| 1479 | bss->hs20_connection_capability_len + 4); |
| 1480 | if (conn_cap == NULL) |
| 1481 | return -1; |
| 1482 | |
| 1483 | bss->hs20_connection_capability = conn_cap; |
| 1484 | conn_cap += bss->hs20_connection_capability_len; |
| 1485 | pos = buf; |
| 1486 | conn_cap[0] = atoi(pos); |
| 1487 | pos = os_strchr(pos, ':'); |
| 1488 | if (pos == NULL) |
| 1489 | return -1; |
| 1490 | pos++; |
| 1491 | WPA_PUT_LE16(conn_cap + 1, atoi(pos)); |
| 1492 | pos = os_strchr(pos, ':'); |
| 1493 | if (pos == NULL) |
| 1494 | return -1; |
| 1495 | pos++; |
| 1496 | conn_cap[3] = atoi(pos); |
| 1497 | bss->hs20_connection_capability_len += 4; |
| 1498 | |
| 1499 | return 0; |
| 1500 | } |
| 1501 | |
| 1502 | |
| 1503 | static int hs20_parse_wan_metrics(struct hostapd_bss_config *bss, char *buf, |
| 1504 | int line) |
| 1505 | { |
| 1506 | u8 *wan_metrics; |
| 1507 | char *pos; |
| 1508 | |
| 1509 | /* <WAN Info>:<DL Speed>:<UL Speed>:<DL Load>:<UL Load>:<LMD> */ |
| 1510 | |
| 1511 | wan_metrics = os_zalloc(13); |
| 1512 | if (wan_metrics == NULL) |
| 1513 | return -1; |
| 1514 | |
| 1515 | pos = buf; |
| 1516 | /* WAN Info */ |
| 1517 | if (hexstr2bin(pos, wan_metrics, 1) < 0) |
| 1518 | goto fail; |
| 1519 | pos += 2; |
| 1520 | if (*pos != ':') |
| 1521 | goto fail; |
| 1522 | pos++; |
| 1523 | |
| 1524 | /* Downlink Speed */ |
| 1525 | WPA_PUT_LE32(wan_metrics + 1, atoi(pos)); |
| 1526 | pos = os_strchr(pos, ':'); |
| 1527 | if (pos == NULL) |
| 1528 | goto fail; |
| 1529 | pos++; |
| 1530 | |
| 1531 | /* Uplink Speed */ |
| 1532 | WPA_PUT_LE32(wan_metrics + 5, atoi(pos)); |
| 1533 | pos = os_strchr(pos, ':'); |
| 1534 | if (pos == NULL) |
| 1535 | goto fail; |
| 1536 | pos++; |
| 1537 | |
| 1538 | /* Downlink Load */ |
| 1539 | wan_metrics[9] = atoi(pos); |
| 1540 | pos = os_strchr(pos, ':'); |
| 1541 | if (pos == NULL) |
| 1542 | goto fail; |
| 1543 | pos++; |
| 1544 | |
| 1545 | /* Uplink Load */ |
| 1546 | wan_metrics[10] = atoi(pos); |
| 1547 | pos = os_strchr(pos, ':'); |
| 1548 | if (pos == NULL) |
| 1549 | goto fail; |
| 1550 | pos++; |
| 1551 | |
| 1552 | /* LMD */ |
| 1553 | WPA_PUT_LE16(wan_metrics + 11, atoi(pos)); |
| 1554 | |
| 1555 | os_free(bss->hs20_wan_metrics); |
| 1556 | bss->hs20_wan_metrics = wan_metrics; |
| 1557 | |
| 1558 | return 0; |
| 1559 | |
| 1560 | fail: |
| 1561 | wpa_printf(MSG_ERROR, "Line %d: Invalid hs20_wan_metrics '%s'", |
| 1562 | line, pos); |
| 1563 | os_free(wan_metrics); |
| 1564 | return -1; |
| 1565 | } |
| 1566 | |
| 1567 | |
| 1568 | static int hs20_parse_oper_friendly_name(struct hostapd_bss_config *bss, |
| 1569 | char *pos, int line) |
| 1570 | { |
| 1571 | if (parse_lang_string(&bss->hs20_oper_friendly_name, |
| 1572 | &bss->hs20_oper_friendly_name_count, pos)) { |
| 1573 | wpa_printf(MSG_ERROR, "Line %d: Invalid " |
| 1574 | "hs20_oper_friendly_name '%s'", line, pos); |
| 1575 | return -1; |
| 1576 | } |
| 1577 | return 0; |
| 1578 | } |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame^] | 1579 | |
| 1580 | |
| 1581 | static int hs20_parse_icon(struct hostapd_bss_config *bss, char *pos) |
| 1582 | { |
| 1583 | struct hs20_icon *icon; |
| 1584 | char *end; |
| 1585 | |
| 1586 | icon = os_realloc_array(bss->hs20_icons, bss->hs20_icons_count + 1, |
| 1587 | sizeof(struct hs20_icon)); |
| 1588 | if (icon == NULL) |
| 1589 | return -1; |
| 1590 | bss->hs20_icons = icon; |
| 1591 | icon = &bss->hs20_icons[bss->hs20_icons_count]; |
| 1592 | os_memset(icon, 0, sizeof(*icon)); |
| 1593 | |
| 1594 | icon->width = atoi(pos); |
| 1595 | pos = os_strchr(pos, ':'); |
| 1596 | if (pos == NULL) |
| 1597 | return -1; |
| 1598 | pos++; |
| 1599 | |
| 1600 | icon->height = atoi(pos); |
| 1601 | pos = os_strchr(pos, ':'); |
| 1602 | if (pos == NULL) |
| 1603 | return -1; |
| 1604 | pos++; |
| 1605 | |
| 1606 | end = os_strchr(pos, ':'); |
| 1607 | if (end == NULL || end - pos > 3) |
| 1608 | return -1; |
| 1609 | os_memcpy(icon->language, pos, end - pos); |
| 1610 | pos = end + 1; |
| 1611 | |
| 1612 | end = os_strchr(pos, ':'); |
| 1613 | if (end == NULL || end - pos > 255) |
| 1614 | return -1; |
| 1615 | os_memcpy(icon->type, pos, end - pos); |
| 1616 | pos = end + 1; |
| 1617 | |
| 1618 | end = os_strchr(pos, ':'); |
| 1619 | if (end == NULL || end - pos > 255) |
| 1620 | return -1; |
| 1621 | os_memcpy(icon->name, pos, end - pos); |
| 1622 | pos = end + 1; |
| 1623 | |
| 1624 | if (os_strlen(pos) > 255) |
| 1625 | return -1; |
| 1626 | os_memcpy(icon->file, pos, os_strlen(pos)); |
| 1627 | |
| 1628 | bss->hs20_icons_count++; |
| 1629 | |
| 1630 | return 0; |
| 1631 | } |
| 1632 | |
| 1633 | |
| 1634 | static int hs20_parse_osu_ssid(struct hostapd_bss_config *bss, |
| 1635 | char *pos, int line) |
| 1636 | { |
| 1637 | size_t slen; |
| 1638 | char *str; |
| 1639 | |
| 1640 | str = wpa_config_parse_string(pos, &slen); |
| 1641 | if (str == NULL || slen < 1 || slen > HOSTAPD_MAX_SSID_LEN) { |
| 1642 | wpa_printf(MSG_ERROR, "Line %d: Invalid SSID '%s'", line, pos); |
| 1643 | return -1; |
| 1644 | } |
| 1645 | |
| 1646 | os_memcpy(bss->osu_ssid, str, slen); |
| 1647 | bss->osu_ssid_len = slen; |
| 1648 | os_free(str); |
| 1649 | |
| 1650 | return 0; |
| 1651 | } |
| 1652 | |
| 1653 | |
| 1654 | static int hs20_parse_osu_server_uri(struct hostapd_bss_config *bss, |
| 1655 | char *pos, int line) |
| 1656 | { |
| 1657 | struct hs20_osu_provider *p; |
| 1658 | |
| 1659 | p = os_realloc_array(bss->hs20_osu_providers, |
| 1660 | bss->hs20_osu_providers_count + 1, sizeof(*p)); |
| 1661 | if (p == NULL) |
| 1662 | return -1; |
| 1663 | |
| 1664 | bss->hs20_osu_providers = p; |
| 1665 | bss->last_osu = &bss->hs20_osu_providers[bss->hs20_osu_providers_count]; |
| 1666 | bss->hs20_osu_providers_count++; |
| 1667 | os_memset(bss->last_osu, 0, sizeof(*p)); |
| 1668 | bss->last_osu->server_uri = os_strdup(pos); |
| 1669 | |
| 1670 | return 0; |
| 1671 | } |
| 1672 | |
| 1673 | |
| 1674 | static int hs20_parse_osu_friendly_name(struct hostapd_bss_config *bss, |
| 1675 | char *pos, int line) |
| 1676 | { |
| 1677 | if (bss->last_osu == NULL) { |
| 1678 | wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line); |
| 1679 | return -1; |
| 1680 | } |
| 1681 | |
| 1682 | if (parse_lang_string(&bss->last_osu->friendly_name, |
| 1683 | &bss->last_osu->friendly_name_count, pos)) { |
| 1684 | wpa_printf(MSG_ERROR, "Line %d: Invalid osu_friendly_name '%s'", |
| 1685 | line, pos); |
| 1686 | return -1; |
| 1687 | } |
| 1688 | |
| 1689 | return 0; |
| 1690 | } |
| 1691 | |
| 1692 | |
| 1693 | static int hs20_parse_osu_nai(struct hostapd_bss_config *bss, |
| 1694 | char *pos, int line) |
| 1695 | { |
| 1696 | if (bss->last_osu == NULL) { |
| 1697 | wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line); |
| 1698 | return -1; |
| 1699 | } |
| 1700 | |
| 1701 | os_free(bss->last_osu->osu_nai); |
| 1702 | bss->last_osu->osu_nai = os_strdup(pos); |
| 1703 | if (bss->last_osu->osu_nai == NULL) |
| 1704 | return -1; |
| 1705 | |
| 1706 | return 0; |
| 1707 | } |
| 1708 | |
| 1709 | |
| 1710 | static int hs20_parse_osu_method_list(struct hostapd_bss_config *bss, char *pos, |
| 1711 | int line) |
| 1712 | { |
| 1713 | if (bss->last_osu == NULL) { |
| 1714 | wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line); |
| 1715 | return -1; |
| 1716 | } |
| 1717 | |
| 1718 | if (hostapd_parse_intlist(&bss->last_osu->method_list, pos)) { |
| 1719 | wpa_printf(MSG_ERROR, "Line %d: Invalid osu_method_list", line); |
| 1720 | return -1; |
| 1721 | } |
| 1722 | |
| 1723 | return 0; |
| 1724 | } |
| 1725 | |
| 1726 | |
| 1727 | static int hs20_parse_osu_icon(struct hostapd_bss_config *bss, char *pos, |
| 1728 | int line) |
| 1729 | { |
| 1730 | char **n; |
| 1731 | struct hs20_osu_provider *p = bss->last_osu; |
| 1732 | |
| 1733 | if (p == NULL) { |
| 1734 | wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line); |
| 1735 | return -1; |
| 1736 | } |
| 1737 | |
| 1738 | n = os_realloc_array(p->icons, p->icons_count + 1, sizeof(char *)); |
| 1739 | if (n == NULL) |
| 1740 | return -1; |
| 1741 | p->icons = n; |
| 1742 | p->icons[p->icons_count] = os_strdup(pos); |
| 1743 | if (p->icons[p->icons_count] == NULL) |
| 1744 | return -1; |
| 1745 | p->icons_count++; |
| 1746 | |
| 1747 | return 0; |
| 1748 | } |
| 1749 | |
| 1750 | |
| 1751 | static int hs20_parse_osu_service_desc(struct hostapd_bss_config *bss, |
| 1752 | char *pos, int line) |
| 1753 | { |
| 1754 | if (bss->last_osu == NULL) { |
| 1755 | wpa_printf(MSG_ERROR, "Line %d: Unexpected OSU field", line); |
| 1756 | return -1; |
| 1757 | } |
| 1758 | |
| 1759 | if (parse_lang_string(&bss->last_osu->service_desc, |
| 1760 | &bss->last_osu->service_desc_count, pos)) { |
| 1761 | wpa_printf(MSG_ERROR, "Line %d: Invalid osu_service_desc '%s'", |
| 1762 | line, pos); |
| 1763 | return -1; |
| 1764 | } |
| 1765 | |
| 1766 | return 0; |
| 1767 | } |
| 1768 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1769 | #endif /* CONFIG_HS20 */ |
| 1770 | |
| 1771 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1772 | #ifdef CONFIG_WPS_NFC |
| 1773 | static struct wpabuf * hostapd_parse_bin(const char *buf) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1774 | { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1775 | size_t len; |
| 1776 | struct wpabuf *ret; |
| 1777 | |
| 1778 | len = os_strlen(buf); |
| 1779 | if (len & 0x01) |
| 1780 | return NULL; |
| 1781 | len /= 2; |
| 1782 | |
| 1783 | ret = wpabuf_alloc(len); |
| 1784 | if (ret == NULL) |
| 1785 | return NULL; |
| 1786 | |
| 1787 | if (hexstr2bin(buf, wpabuf_put(ret, len), len)) { |
| 1788 | wpabuf_free(ret); |
| 1789 | return NULL; |
| 1790 | } |
| 1791 | |
| 1792 | return ret; |
| 1793 | } |
| 1794 | #endif /* CONFIG_WPS_NFC */ |
| 1795 | |
| 1796 | |
| 1797 | static int hostapd_config_fill(struct hostapd_config *conf, |
| 1798 | struct hostapd_bss_config *bss, |
| 1799 | char *buf, char *pos, int line) |
| 1800 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1801 | int errors = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1802 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1803 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1804 | if (os_strcmp(buf, "interface") == 0) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1805 | os_strlcpy(conf->bss[0]->iface, pos, |
| 1806 | sizeof(conf->bss[0]->iface)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1807 | } else if (os_strcmp(buf, "bridge") == 0) { |
| 1808 | os_strlcpy(bss->bridge, pos, sizeof(bss->bridge)); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 1809 | } else if (os_strcmp(buf, "vlan_bridge") == 0) { |
| 1810 | os_strlcpy(bss->vlan_bridge, pos, |
| 1811 | sizeof(bss->vlan_bridge)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1812 | } else if (os_strcmp(buf, "wds_bridge") == 0) { |
| 1813 | os_strlcpy(bss->wds_bridge, pos, |
| 1814 | sizeof(bss->wds_bridge)); |
| 1815 | } else if (os_strcmp(buf, "driver") == 0) { |
| 1816 | int j; |
| 1817 | /* clear to get error below if setting is invalid */ |
| 1818 | conf->driver = NULL; |
| 1819 | for (j = 0; wpa_drivers[j]; j++) { |
| 1820 | if (os_strcmp(pos, wpa_drivers[j]->name) == 0) |
| 1821 | { |
| 1822 | conf->driver = wpa_drivers[j]; |
| 1823 | break; |
| 1824 | } |
| 1825 | } |
| 1826 | if (conf->driver == NULL) { |
| 1827 | wpa_printf(MSG_ERROR, "Line %d: invalid/" |
| 1828 | "unknown driver '%s'", line, pos); |
| 1829 | errors++; |
| 1830 | } |
| 1831 | } else if (os_strcmp(buf, "debug") == 0) { |
| 1832 | wpa_printf(MSG_DEBUG, "Line %d: DEPRECATED: 'debug' " |
| 1833 | "configuration variable is not used " |
| 1834 | "anymore", line); |
| 1835 | } else if (os_strcmp(buf, "logger_syslog_level") == 0) { |
| 1836 | bss->logger_syslog_level = atoi(pos); |
| 1837 | } else if (os_strcmp(buf, "logger_stdout_level") == 0) { |
| 1838 | bss->logger_stdout_level = atoi(pos); |
| 1839 | } else if (os_strcmp(buf, "logger_syslog") == 0) { |
| 1840 | bss->logger_syslog = atoi(pos); |
| 1841 | } else if (os_strcmp(buf, "logger_stdout") == 0) { |
| 1842 | bss->logger_stdout = atoi(pos); |
| 1843 | } else if (os_strcmp(buf, "dump_file") == 0) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1844 | wpa_printf(MSG_INFO, "Line %d: DEPRECATED: 'dump_file' configuration variable is not used anymore", |
| 1845 | line); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1846 | } else if (os_strcmp(buf, "ssid") == 0) { |
| 1847 | bss->ssid.ssid_len = os_strlen(pos); |
| 1848 | if (bss->ssid.ssid_len > HOSTAPD_MAX_SSID_LEN || |
| 1849 | bss->ssid.ssid_len < 1) { |
| 1850 | wpa_printf(MSG_ERROR, "Line %d: invalid SSID " |
| 1851 | "'%s'", line, pos); |
| 1852 | errors++; |
| 1853 | } else { |
| 1854 | os_memcpy(bss->ssid.ssid, pos, |
| 1855 | bss->ssid.ssid_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1856 | bss->ssid.ssid_set = 1; |
| 1857 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1858 | } else if (os_strcmp(buf, "ssid2") == 0) { |
| 1859 | size_t slen; |
| 1860 | char *str = wpa_config_parse_string(pos, &slen); |
| 1861 | if (str == NULL || slen < 1 || |
| 1862 | slen > HOSTAPD_MAX_SSID_LEN) { |
| 1863 | wpa_printf(MSG_ERROR, "Line %d: invalid SSID " |
| 1864 | "'%s'", line, pos); |
| 1865 | errors++; |
| 1866 | } else { |
| 1867 | os_memcpy(bss->ssid.ssid, str, slen); |
| 1868 | bss->ssid.ssid_len = slen; |
| 1869 | bss->ssid.ssid_set = 1; |
| 1870 | } |
| 1871 | os_free(str); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1872 | } else if (os_strcmp(buf, "utf8_ssid") == 0) { |
| 1873 | bss->ssid.utf8_ssid = atoi(pos) > 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1874 | } else if (os_strcmp(buf, "macaddr_acl") == 0) { |
| 1875 | bss->macaddr_acl = atoi(pos); |
| 1876 | if (bss->macaddr_acl != ACCEPT_UNLESS_DENIED && |
| 1877 | bss->macaddr_acl != DENY_UNLESS_ACCEPTED && |
| 1878 | bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH) { |
| 1879 | wpa_printf(MSG_ERROR, "Line %d: unknown " |
| 1880 | "macaddr_acl %d", |
| 1881 | line, bss->macaddr_acl); |
| 1882 | } |
| 1883 | } else if (os_strcmp(buf, "accept_mac_file") == 0) { |
| 1884 | if (hostapd_config_read_maclist(pos, &bss->accept_mac, |
| 1885 | &bss->num_accept_mac)) |
| 1886 | { |
| 1887 | wpa_printf(MSG_ERROR, "Line %d: Failed to " |
| 1888 | "read accept_mac_file '%s'", |
| 1889 | line, pos); |
| 1890 | errors++; |
| 1891 | } |
| 1892 | } else if (os_strcmp(buf, "deny_mac_file") == 0) { |
| 1893 | if (hostapd_config_read_maclist(pos, &bss->deny_mac, |
| 1894 | &bss->num_deny_mac)) { |
| 1895 | wpa_printf(MSG_ERROR, "Line %d: Failed to " |
| 1896 | "read deny_mac_file '%s'", |
| 1897 | line, pos); |
| 1898 | errors++; |
| 1899 | } |
| 1900 | } else if (os_strcmp(buf, "wds_sta") == 0) { |
| 1901 | bss->wds_sta = atoi(pos); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 1902 | } else if (os_strcmp(buf, "start_disabled") == 0) { |
| 1903 | bss->start_disabled = atoi(pos); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1904 | } else if (os_strcmp(buf, "ap_isolate") == 0) { |
| 1905 | bss->isolate = atoi(pos); |
| 1906 | } else if (os_strcmp(buf, "ap_max_inactivity") == 0) { |
| 1907 | bss->ap_max_inactivity = atoi(pos); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1908 | } else if (os_strcmp(buf, "skip_inactivity_poll") == 0) { |
| 1909 | bss->skip_inactivity_poll = atoi(pos); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1910 | } else if (os_strcmp(buf, "country_code") == 0) { |
| 1911 | os_memcpy(conf->country, pos, 2); |
| 1912 | /* FIX: make this configurable */ |
| 1913 | conf->country[2] = ' '; |
| 1914 | } else if (os_strcmp(buf, "ieee80211d") == 0) { |
| 1915 | conf->ieee80211d = atoi(pos); |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 1916 | } else if (os_strcmp(buf, "ieee80211h") == 0) { |
| 1917 | conf->ieee80211h = atoi(pos); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1918 | } else if (os_strcmp(buf, "ieee8021x") == 0) { |
| 1919 | bss->ieee802_1x = atoi(pos); |
| 1920 | } else if (os_strcmp(buf, "eapol_version") == 0) { |
| 1921 | bss->eapol_version = atoi(pos); |
| 1922 | if (bss->eapol_version < 1 || |
| 1923 | bss->eapol_version > 2) { |
| 1924 | wpa_printf(MSG_ERROR, "Line %d: invalid EAPOL " |
| 1925 | "version (%d): '%s'.", |
| 1926 | line, bss->eapol_version, pos); |
| 1927 | errors++; |
| 1928 | } else |
| 1929 | wpa_printf(MSG_DEBUG, "eapol_version=%d", |
| 1930 | bss->eapol_version); |
| 1931 | #ifdef EAP_SERVER |
| 1932 | } else if (os_strcmp(buf, "eap_authenticator") == 0) { |
| 1933 | bss->eap_server = atoi(pos); |
| 1934 | wpa_printf(MSG_ERROR, "Line %d: obsolete " |
| 1935 | "eap_authenticator used; this has been " |
| 1936 | "renamed to eap_server", line); |
| 1937 | } else if (os_strcmp(buf, "eap_server") == 0) { |
| 1938 | bss->eap_server = atoi(pos); |
| 1939 | } else if (os_strcmp(buf, "eap_user_file") == 0) { |
| 1940 | if (hostapd_config_read_eap_user(pos, bss)) |
| 1941 | errors++; |
| 1942 | } else if (os_strcmp(buf, "ca_cert") == 0) { |
| 1943 | os_free(bss->ca_cert); |
| 1944 | bss->ca_cert = os_strdup(pos); |
| 1945 | } else if (os_strcmp(buf, "server_cert") == 0) { |
| 1946 | os_free(bss->server_cert); |
| 1947 | bss->server_cert = os_strdup(pos); |
| 1948 | } else if (os_strcmp(buf, "private_key") == 0) { |
| 1949 | os_free(bss->private_key); |
| 1950 | bss->private_key = os_strdup(pos); |
| 1951 | } else if (os_strcmp(buf, "private_key_passwd") == 0) { |
| 1952 | os_free(bss->private_key_passwd); |
| 1953 | bss->private_key_passwd = os_strdup(pos); |
| 1954 | } else if (os_strcmp(buf, "check_crl") == 0) { |
| 1955 | bss->check_crl = atoi(pos); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 1956 | } else if (os_strcmp(buf, "ocsp_stapling_response") == 0) { |
| 1957 | os_free(bss->ocsp_stapling_response); |
| 1958 | bss->ocsp_stapling_response = os_strdup(pos); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1959 | } else if (os_strcmp(buf, "dh_file") == 0) { |
| 1960 | os_free(bss->dh_file); |
| 1961 | bss->dh_file = os_strdup(pos); |
| 1962 | } else if (os_strcmp(buf, "fragment_size") == 0) { |
| 1963 | bss->fragment_size = atoi(pos); |
| 1964 | #ifdef EAP_SERVER_FAST |
| 1965 | } else if (os_strcmp(buf, "pac_opaque_encr_key") == 0) { |
| 1966 | os_free(bss->pac_opaque_encr_key); |
| 1967 | bss->pac_opaque_encr_key = os_malloc(16); |
| 1968 | if (bss->pac_opaque_encr_key == NULL) { |
| 1969 | wpa_printf(MSG_ERROR, "Line %d: No memory for " |
| 1970 | "pac_opaque_encr_key", line); |
| 1971 | errors++; |
| 1972 | } else if (hexstr2bin(pos, bss->pac_opaque_encr_key, |
| 1973 | 16)) { |
| 1974 | wpa_printf(MSG_ERROR, "Line %d: Invalid " |
| 1975 | "pac_opaque_encr_key", line); |
| 1976 | errors++; |
| 1977 | } |
| 1978 | } else if (os_strcmp(buf, "eap_fast_a_id") == 0) { |
| 1979 | size_t idlen = os_strlen(pos); |
| 1980 | if (idlen & 1) { |
| 1981 | wpa_printf(MSG_ERROR, "Line %d: Invalid " |
| 1982 | "eap_fast_a_id", line); |
| 1983 | errors++; |
| 1984 | } else { |
| 1985 | os_free(bss->eap_fast_a_id); |
| 1986 | bss->eap_fast_a_id = os_malloc(idlen / 2); |
| 1987 | if (bss->eap_fast_a_id == NULL || |
| 1988 | hexstr2bin(pos, bss->eap_fast_a_id, |
| 1989 | idlen / 2)) { |
| 1990 | wpa_printf(MSG_ERROR, "Line %d: " |
| 1991 | "Failed to parse " |
| 1992 | "eap_fast_a_id", line); |
| 1993 | errors++; |
| 1994 | } else |
| 1995 | bss->eap_fast_a_id_len = idlen / 2; |
| 1996 | } |
| 1997 | } else if (os_strcmp(buf, "eap_fast_a_id_info") == 0) { |
| 1998 | os_free(bss->eap_fast_a_id_info); |
| 1999 | bss->eap_fast_a_id_info = os_strdup(pos); |
| 2000 | } else if (os_strcmp(buf, "eap_fast_prov") == 0) { |
| 2001 | bss->eap_fast_prov = atoi(pos); |
| 2002 | } else if (os_strcmp(buf, "pac_key_lifetime") == 0) { |
| 2003 | bss->pac_key_lifetime = atoi(pos); |
| 2004 | } else if (os_strcmp(buf, "pac_key_refresh_time") == 0) { |
| 2005 | bss->pac_key_refresh_time = atoi(pos); |
| 2006 | #endif /* EAP_SERVER_FAST */ |
| 2007 | #ifdef EAP_SERVER_SIM |
| 2008 | } else if (os_strcmp(buf, "eap_sim_db") == 0) { |
| 2009 | os_free(bss->eap_sim_db); |
| 2010 | bss->eap_sim_db = os_strdup(pos); |
| 2011 | } else if (os_strcmp(buf, "eap_sim_aka_result_ind") == 0) { |
| 2012 | bss->eap_sim_aka_result_ind = atoi(pos); |
| 2013 | #endif /* EAP_SERVER_SIM */ |
| 2014 | #ifdef EAP_SERVER_TNC |
| 2015 | } else if (os_strcmp(buf, "tnc") == 0) { |
| 2016 | bss->tnc = atoi(pos); |
| 2017 | #endif /* EAP_SERVER_TNC */ |
| 2018 | #ifdef EAP_SERVER_PWD |
| 2019 | } else if (os_strcmp(buf, "pwd_group") == 0) { |
| 2020 | bss->pwd_group = atoi(pos); |
| 2021 | #endif /* EAP_SERVER_PWD */ |
| 2022 | #endif /* EAP_SERVER */ |
| 2023 | } else if (os_strcmp(buf, "eap_message") == 0) { |
| 2024 | char *term; |
| 2025 | bss->eap_req_id_text = os_strdup(pos); |
| 2026 | if (bss->eap_req_id_text == NULL) { |
| 2027 | wpa_printf(MSG_ERROR, "Line %d: Failed to " |
| 2028 | "allocate memory for " |
| 2029 | "eap_req_id_text", line); |
| 2030 | errors++; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2031 | return errors; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2032 | } |
| 2033 | bss->eap_req_id_text_len = |
| 2034 | os_strlen(bss->eap_req_id_text); |
| 2035 | term = os_strstr(bss->eap_req_id_text, "\\0"); |
| 2036 | if (term) { |
| 2037 | *term++ = '\0'; |
| 2038 | os_memmove(term, term + 1, |
| 2039 | bss->eap_req_id_text_len - |
| 2040 | (term - bss->eap_req_id_text) - 1); |
| 2041 | bss->eap_req_id_text_len--; |
| 2042 | } |
| 2043 | } else if (os_strcmp(buf, "wep_key_len_broadcast") == 0) { |
| 2044 | bss->default_wep_key_len = atoi(pos); |
| 2045 | if (bss->default_wep_key_len > 13) { |
| 2046 | wpa_printf(MSG_ERROR, "Line %d: invalid WEP " |
| 2047 | "key len %lu (= %lu bits)", line, |
| 2048 | (unsigned long) |
| 2049 | bss->default_wep_key_len, |
| 2050 | (unsigned long) |
| 2051 | bss->default_wep_key_len * 8); |
| 2052 | errors++; |
| 2053 | } |
| 2054 | } else if (os_strcmp(buf, "wep_key_len_unicast") == 0) { |
| 2055 | bss->individual_wep_key_len = atoi(pos); |
| 2056 | if (bss->individual_wep_key_len < 0 || |
| 2057 | bss->individual_wep_key_len > 13) { |
| 2058 | wpa_printf(MSG_ERROR, "Line %d: invalid WEP " |
| 2059 | "key len %d (= %d bits)", line, |
| 2060 | bss->individual_wep_key_len, |
| 2061 | bss->individual_wep_key_len * 8); |
| 2062 | errors++; |
| 2063 | } |
| 2064 | } else if (os_strcmp(buf, "wep_rekey_period") == 0) { |
| 2065 | bss->wep_rekeying_period = atoi(pos); |
| 2066 | if (bss->wep_rekeying_period < 0) { |
| 2067 | wpa_printf(MSG_ERROR, "Line %d: invalid " |
| 2068 | "period %d", |
| 2069 | line, bss->wep_rekeying_period); |
| 2070 | errors++; |
| 2071 | } |
| 2072 | } else if (os_strcmp(buf, "eap_reauth_period") == 0) { |
| 2073 | bss->eap_reauth_period = atoi(pos); |
| 2074 | if (bss->eap_reauth_period < 0) { |
| 2075 | wpa_printf(MSG_ERROR, "Line %d: invalid " |
| 2076 | "period %d", |
| 2077 | line, bss->eap_reauth_period); |
| 2078 | errors++; |
| 2079 | } |
| 2080 | } else if (os_strcmp(buf, "eapol_key_index_workaround") == 0) { |
| 2081 | bss->eapol_key_index_workaround = atoi(pos); |
| 2082 | #ifdef CONFIG_IAPP |
| 2083 | } else if (os_strcmp(buf, "iapp_interface") == 0) { |
| 2084 | bss->ieee802_11f = 1; |
| 2085 | os_strlcpy(bss->iapp_iface, pos, |
| 2086 | sizeof(bss->iapp_iface)); |
| 2087 | #endif /* CONFIG_IAPP */ |
| 2088 | } else if (os_strcmp(buf, "own_ip_addr") == 0) { |
| 2089 | if (hostapd_parse_ip_addr(pos, &bss->own_ip_addr)) { |
| 2090 | wpa_printf(MSG_ERROR, "Line %d: invalid IP " |
| 2091 | "address '%s'", line, pos); |
| 2092 | errors++; |
| 2093 | } |
| 2094 | } else if (os_strcmp(buf, "nas_identifier") == 0) { |
| 2095 | bss->nas_identifier = os_strdup(pos); |
| 2096 | #ifndef CONFIG_NO_RADIUS |
| 2097 | } else if (os_strcmp(buf, "auth_server_addr") == 0) { |
| 2098 | if (hostapd_config_read_radius_addr( |
| 2099 | &bss->radius->auth_servers, |
| 2100 | &bss->radius->num_auth_servers, pos, 1812, |
| 2101 | &bss->radius->auth_server)) { |
| 2102 | wpa_printf(MSG_ERROR, "Line %d: invalid IP " |
| 2103 | "address '%s'", line, pos); |
| 2104 | errors++; |
| 2105 | } |
| 2106 | } else if (bss->radius->auth_server && |
| 2107 | os_strcmp(buf, "auth_server_port") == 0) { |
| 2108 | bss->radius->auth_server->port = atoi(pos); |
| 2109 | } else if (bss->radius->auth_server && |
| 2110 | os_strcmp(buf, "auth_server_shared_secret") == 0) { |
| 2111 | int len = os_strlen(pos); |
| 2112 | if (len == 0) { |
| 2113 | /* RFC 2865, Ch. 3 */ |
| 2114 | wpa_printf(MSG_ERROR, "Line %d: empty shared " |
| 2115 | "secret is not allowed.", line); |
| 2116 | errors++; |
| 2117 | } |
| 2118 | bss->radius->auth_server->shared_secret = |
| 2119 | (u8 *) os_strdup(pos); |
| 2120 | bss->radius->auth_server->shared_secret_len = len; |
| 2121 | } else if (os_strcmp(buf, "acct_server_addr") == 0) { |
| 2122 | if (hostapd_config_read_radius_addr( |
| 2123 | &bss->radius->acct_servers, |
| 2124 | &bss->radius->num_acct_servers, pos, 1813, |
| 2125 | &bss->radius->acct_server)) { |
| 2126 | wpa_printf(MSG_ERROR, "Line %d: invalid IP " |
| 2127 | "address '%s'", line, pos); |
| 2128 | errors++; |
| 2129 | } |
| 2130 | } else if (bss->radius->acct_server && |
| 2131 | os_strcmp(buf, "acct_server_port") == 0) { |
| 2132 | bss->radius->acct_server->port = atoi(pos); |
| 2133 | } else if (bss->radius->acct_server && |
| 2134 | os_strcmp(buf, "acct_server_shared_secret") == 0) { |
| 2135 | int len = os_strlen(pos); |
| 2136 | if (len == 0) { |
| 2137 | /* RFC 2865, Ch. 3 */ |
| 2138 | wpa_printf(MSG_ERROR, "Line %d: empty shared " |
| 2139 | "secret is not allowed.", line); |
| 2140 | errors++; |
| 2141 | } |
| 2142 | bss->radius->acct_server->shared_secret = |
| 2143 | (u8 *) os_strdup(pos); |
| 2144 | bss->radius->acct_server->shared_secret_len = len; |
| 2145 | } else if (os_strcmp(buf, "radius_retry_primary_interval") == |
| 2146 | 0) { |
| 2147 | bss->radius->retry_primary_interval = atoi(pos); |
| 2148 | } else if (os_strcmp(buf, "radius_acct_interim_interval") == 0) |
| 2149 | { |
| 2150 | bss->acct_interim_interval = atoi(pos); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2151 | } else if (os_strcmp(buf, "radius_request_cui") == 0) { |
| 2152 | bss->radius_request_cui = atoi(pos); |
| 2153 | } else if (os_strcmp(buf, "radius_auth_req_attr") == 0) { |
| 2154 | struct hostapd_radius_attr *attr, *a; |
| 2155 | attr = hostapd_parse_radius_attr(pos); |
| 2156 | if (attr == NULL) { |
| 2157 | wpa_printf(MSG_ERROR, "Line %d: invalid " |
| 2158 | "radius_auth_req_attr", line); |
| 2159 | errors++; |
| 2160 | } else if (bss->radius_auth_req_attr == NULL) { |
| 2161 | bss->radius_auth_req_attr = attr; |
| 2162 | } else { |
| 2163 | a = bss->radius_auth_req_attr; |
| 2164 | while (a->next) |
| 2165 | a = a->next; |
| 2166 | a->next = attr; |
| 2167 | } |
| 2168 | } else if (os_strcmp(buf, "radius_acct_req_attr") == 0) { |
| 2169 | struct hostapd_radius_attr *attr, *a; |
| 2170 | attr = hostapd_parse_radius_attr(pos); |
| 2171 | if (attr == NULL) { |
| 2172 | wpa_printf(MSG_ERROR, "Line %d: invalid " |
| 2173 | "radius_acct_req_attr", line); |
| 2174 | errors++; |
| 2175 | } else if (bss->radius_acct_req_attr == NULL) { |
| 2176 | bss->radius_acct_req_attr = attr; |
| 2177 | } else { |
| 2178 | a = bss->radius_acct_req_attr; |
| 2179 | while (a->next) |
| 2180 | a = a->next; |
| 2181 | a->next = attr; |
| 2182 | } |
| 2183 | } else if (os_strcmp(buf, "radius_das_port") == 0) { |
| 2184 | bss->radius_das_port = atoi(pos); |
| 2185 | } else if (os_strcmp(buf, "radius_das_client") == 0) { |
| 2186 | if (hostapd_parse_das_client(bss, pos) < 0) { |
| 2187 | wpa_printf(MSG_ERROR, "Line %d: invalid " |
| 2188 | "DAS client", line); |
| 2189 | errors++; |
| 2190 | } |
| 2191 | } else if (os_strcmp(buf, "radius_das_time_window") == 0) { |
| 2192 | bss->radius_das_time_window = atoi(pos); |
| 2193 | } else if (os_strcmp(buf, "radius_das_require_event_timestamp") |
| 2194 | == 0) { |
| 2195 | bss->radius_das_require_event_timestamp = atoi(pos); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2196 | #endif /* CONFIG_NO_RADIUS */ |
| 2197 | } else if (os_strcmp(buf, "auth_algs") == 0) { |
| 2198 | bss->auth_algs = atoi(pos); |
| 2199 | if (bss->auth_algs == 0) { |
| 2200 | wpa_printf(MSG_ERROR, "Line %d: no " |
| 2201 | "authentication algorithms allowed", |
| 2202 | line); |
| 2203 | errors++; |
| 2204 | } |
| 2205 | } else if (os_strcmp(buf, "max_num_sta") == 0) { |
| 2206 | bss->max_num_sta = atoi(pos); |
| 2207 | if (bss->max_num_sta < 0 || |
| 2208 | bss->max_num_sta > MAX_STA_COUNT) { |
| 2209 | wpa_printf(MSG_ERROR, "Line %d: Invalid " |
| 2210 | "max_num_sta=%d; allowed range " |
| 2211 | "0..%d", line, bss->max_num_sta, |
| 2212 | MAX_STA_COUNT); |
| 2213 | errors++; |
| 2214 | } |
| 2215 | } else if (os_strcmp(buf, "wpa") == 0) { |
| 2216 | bss->wpa = atoi(pos); |
| 2217 | } else if (os_strcmp(buf, "wpa_group_rekey") == 0) { |
| 2218 | bss->wpa_group_rekey = atoi(pos); |
| 2219 | } else if (os_strcmp(buf, "wpa_strict_rekey") == 0) { |
| 2220 | bss->wpa_strict_rekey = atoi(pos); |
| 2221 | } else if (os_strcmp(buf, "wpa_gmk_rekey") == 0) { |
| 2222 | bss->wpa_gmk_rekey = atoi(pos); |
| 2223 | } else if (os_strcmp(buf, "wpa_ptk_rekey") == 0) { |
| 2224 | bss->wpa_ptk_rekey = atoi(pos); |
| 2225 | } else if (os_strcmp(buf, "wpa_passphrase") == 0) { |
| 2226 | int len = os_strlen(pos); |
| 2227 | if (len < 8 || len > 63) { |
| 2228 | wpa_printf(MSG_ERROR, "Line %d: invalid WPA " |
| 2229 | "passphrase length %d (expected " |
| 2230 | "8..63)", line, len); |
| 2231 | errors++; |
| 2232 | } else { |
| 2233 | os_free(bss->ssid.wpa_passphrase); |
| 2234 | bss->ssid.wpa_passphrase = os_strdup(pos); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2235 | if (bss->ssid.wpa_passphrase) { |
| 2236 | os_free(bss->ssid.wpa_psk); |
| 2237 | bss->ssid.wpa_psk = NULL; |
| 2238 | bss->ssid.wpa_passphrase_set = 1; |
| 2239 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2240 | } |
| 2241 | } else if (os_strcmp(buf, "wpa_psk") == 0) { |
| 2242 | os_free(bss->ssid.wpa_psk); |
| 2243 | bss->ssid.wpa_psk = |
| 2244 | os_zalloc(sizeof(struct hostapd_wpa_psk)); |
| 2245 | if (bss->ssid.wpa_psk == NULL) |
| 2246 | errors++; |
| 2247 | else if (hexstr2bin(pos, bss->ssid.wpa_psk->psk, |
| 2248 | PMK_LEN) || |
| 2249 | pos[PMK_LEN * 2] != '\0') { |
| 2250 | wpa_printf(MSG_ERROR, "Line %d: Invalid PSK " |
| 2251 | "'%s'.", line, pos); |
| 2252 | errors++; |
| 2253 | } else { |
| 2254 | bss->ssid.wpa_psk->group = 1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2255 | os_free(bss->ssid.wpa_passphrase); |
| 2256 | bss->ssid.wpa_passphrase = NULL; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2257 | bss->ssid.wpa_psk_set = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2258 | } |
| 2259 | } else if (os_strcmp(buf, "wpa_psk_file") == 0) { |
| 2260 | os_free(bss->ssid.wpa_psk_file); |
| 2261 | bss->ssid.wpa_psk_file = os_strdup(pos); |
| 2262 | if (!bss->ssid.wpa_psk_file) { |
| 2263 | wpa_printf(MSG_ERROR, "Line %d: allocation " |
| 2264 | "failed", line); |
| 2265 | errors++; |
| 2266 | } |
| 2267 | } else if (os_strcmp(buf, "wpa_key_mgmt") == 0) { |
| 2268 | bss->wpa_key_mgmt = |
| 2269 | hostapd_config_parse_key_mgmt(line, pos); |
| 2270 | if (bss->wpa_key_mgmt == -1) |
| 2271 | errors++; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2272 | } else if (os_strcmp(buf, "wpa_psk_radius") == 0) { |
| 2273 | bss->wpa_psk_radius = atoi(pos); |
| 2274 | if (bss->wpa_psk_radius != PSK_RADIUS_IGNORED && |
| 2275 | bss->wpa_psk_radius != PSK_RADIUS_ACCEPTED && |
| 2276 | bss->wpa_psk_radius != PSK_RADIUS_REQUIRED) { |
| 2277 | wpa_printf(MSG_ERROR, "Line %d: unknown " |
| 2278 | "wpa_psk_radius %d", |
| 2279 | line, bss->wpa_psk_radius); |
| 2280 | errors++; |
| 2281 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2282 | } else if (os_strcmp(buf, "wpa_pairwise") == 0) { |
| 2283 | bss->wpa_pairwise = |
| 2284 | hostapd_config_parse_cipher(line, pos); |
| 2285 | if (bss->wpa_pairwise == -1 || |
| 2286 | bss->wpa_pairwise == 0) |
| 2287 | errors++; |
| 2288 | else if (bss->wpa_pairwise & |
| 2289 | (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 | |
| 2290 | WPA_CIPHER_WEP104)) { |
| 2291 | wpa_printf(MSG_ERROR, "Line %d: unsupported " |
| 2292 | "pairwise cipher suite '%s'", |
| 2293 | bss->wpa_pairwise, pos); |
| 2294 | errors++; |
| 2295 | } |
| 2296 | } else if (os_strcmp(buf, "rsn_pairwise") == 0) { |
| 2297 | bss->rsn_pairwise = |
| 2298 | hostapd_config_parse_cipher(line, pos); |
| 2299 | if (bss->rsn_pairwise == -1 || |
| 2300 | bss->rsn_pairwise == 0) |
| 2301 | errors++; |
| 2302 | else if (bss->rsn_pairwise & |
| 2303 | (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 | |
| 2304 | WPA_CIPHER_WEP104)) { |
| 2305 | wpa_printf(MSG_ERROR, "Line %d: unsupported " |
| 2306 | "pairwise cipher suite '%s'", |
| 2307 | bss->rsn_pairwise, pos); |
| 2308 | errors++; |
| 2309 | } |
| 2310 | #ifdef CONFIG_RSN_PREAUTH |
| 2311 | } else if (os_strcmp(buf, "rsn_preauth") == 0) { |
| 2312 | bss->rsn_preauth = atoi(pos); |
| 2313 | } else if (os_strcmp(buf, "rsn_preauth_interfaces") == 0) { |
| 2314 | bss->rsn_preauth_interfaces = os_strdup(pos); |
| 2315 | #endif /* CONFIG_RSN_PREAUTH */ |
| 2316 | #ifdef CONFIG_PEERKEY |
| 2317 | } else if (os_strcmp(buf, "peerkey") == 0) { |
| 2318 | bss->peerkey = atoi(pos); |
| 2319 | #endif /* CONFIG_PEERKEY */ |
| 2320 | #ifdef CONFIG_IEEE80211R |
| 2321 | } else if (os_strcmp(buf, "mobility_domain") == 0) { |
| 2322 | if (os_strlen(pos) != 2 * MOBILITY_DOMAIN_ID_LEN || |
| 2323 | hexstr2bin(pos, bss->mobility_domain, |
| 2324 | MOBILITY_DOMAIN_ID_LEN) != 0) { |
| 2325 | wpa_printf(MSG_DEBUG, "Line %d: Invalid " |
| 2326 | "mobility_domain '%s'", line, pos); |
| 2327 | errors++; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2328 | return errors; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2329 | } |
| 2330 | } else if (os_strcmp(buf, "r1_key_holder") == 0) { |
| 2331 | if (os_strlen(pos) != 2 * FT_R1KH_ID_LEN || |
| 2332 | hexstr2bin(pos, bss->r1_key_holder, |
| 2333 | FT_R1KH_ID_LEN) != 0) { |
| 2334 | wpa_printf(MSG_DEBUG, "Line %d: Invalid " |
| 2335 | "r1_key_holder '%s'", line, pos); |
| 2336 | errors++; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2337 | return errors; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2338 | } |
| 2339 | } else if (os_strcmp(buf, "r0_key_lifetime") == 0) { |
| 2340 | bss->r0_key_lifetime = atoi(pos); |
| 2341 | } else if (os_strcmp(buf, "reassociation_deadline") == 0) { |
| 2342 | bss->reassociation_deadline = atoi(pos); |
| 2343 | } else if (os_strcmp(buf, "r0kh") == 0) { |
| 2344 | if (add_r0kh(bss, pos) < 0) { |
| 2345 | wpa_printf(MSG_DEBUG, "Line %d: Invalid " |
| 2346 | "r0kh '%s'", line, pos); |
| 2347 | errors++; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2348 | return errors; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2349 | } |
| 2350 | } else if (os_strcmp(buf, "r1kh") == 0) { |
| 2351 | if (add_r1kh(bss, pos) < 0) { |
| 2352 | wpa_printf(MSG_DEBUG, "Line %d: Invalid " |
| 2353 | "r1kh '%s'", line, pos); |
| 2354 | errors++; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2355 | return errors; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2356 | } |
| 2357 | } else if (os_strcmp(buf, "pmk_r1_push") == 0) { |
| 2358 | bss->pmk_r1_push = atoi(pos); |
| 2359 | } else if (os_strcmp(buf, "ft_over_ds") == 0) { |
| 2360 | bss->ft_over_ds = atoi(pos); |
| 2361 | #endif /* CONFIG_IEEE80211R */ |
| 2362 | #ifndef CONFIG_NO_CTRL_IFACE |
| 2363 | } else if (os_strcmp(buf, "ctrl_interface") == 0) { |
| 2364 | os_free(bss->ctrl_interface); |
| 2365 | bss->ctrl_interface = os_strdup(pos); |
| 2366 | } else if (os_strcmp(buf, "ctrl_interface_group") == 0) { |
| 2367 | #ifndef CONFIG_NATIVE_WINDOWS |
| 2368 | struct group *grp; |
| 2369 | char *endp; |
| 2370 | const char *group = pos; |
| 2371 | |
| 2372 | grp = getgrnam(group); |
| 2373 | if (grp) { |
| 2374 | bss->ctrl_interface_gid = grp->gr_gid; |
| 2375 | bss->ctrl_interface_gid_set = 1; |
| 2376 | wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d" |
| 2377 | " (from group name '%s')", |
| 2378 | bss->ctrl_interface_gid, group); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2379 | return errors; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2380 | } |
| 2381 | |
| 2382 | /* Group name not found - try to parse this as gid */ |
| 2383 | bss->ctrl_interface_gid = strtol(group, &endp, 10); |
| 2384 | if (*group == '\0' || *endp != '\0') { |
| 2385 | wpa_printf(MSG_DEBUG, "Line %d: Invalid group " |
| 2386 | "'%s'", line, group); |
| 2387 | errors++; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2388 | return errors; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2389 | } |
| 2390 | bss->ctrl_interface_gid_set = 1; |
| 2391 | wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d", |
| 2392 | bss->ctrl_interface_gid); |
| 2393 | #endif /* CONFIG_NATIVE_WINDOWS */ |
| 2394 | #endif /* CONFIG_NO_CTRL_IFACE */ |
| 2395 | #ifdef RADIUS_SERVER |
| 2396 | } else if (os_strcmp(buf, "radius_server_clients") == 0) { |
| 2397 | os_free(bss->radius_server_clients); |
| 2398 | bss->radius_server_clients = os_strdup(pos); |
| 2399 | } else if (os_strcmp(buf, "radius_server_auth_port") == 0) { |
| 2400 | bss->radius_server_auth_port = atoi(pos); |
Dmitry Shmidt | bd14a57 | 2014-02-18 10:33:49 -0800 | [diff] [blame] | 2401 | } else if (os_strcmp(buf, "radius_server_acct_port") == 0) { |
| 2402 | bss->radius_server_acct_port = atoi(pos); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2403 | } else if (os_strcmp(buf, "radius_server_ipv6") == 0) { |
| 2404 | bss->radius_server_ipv6 = atoi(pos); |
| 2405 | #endif /* RADIUS_SERVER */ |
| 2406 | } else if (os_strcmp(buf, "test_socket") == 0) { |
| 2407 | os_free(bss->test_socket); |
| 2408 | bss->test_socket = os_strdup(pos); |
| 2409 | } else if (os_strcmp(buf, "use_pae_group_addr") == 0) { |
| 2410 | bss->use_pae_group_addr = atoi(pos); |
| 2411 | } else if (os_strcmp(buf, "hw_mode") == 0) { |
| 2412 | if (os_strcmp(pos, "a") == 0) |
| 2413 | conf->hw_mode = HOSTAPD_MODE_IEEE80211A; |
| 2414 | else if (os_strcmp(pos, "b") == 0) |
| 2415 | conf->hw_mode = HOSTAPD_MODE_IEEE80211B; |
| 2416 | else if (os_strcmp(pos, "g") == 0) |
| 2417 | conf->hw_mode = HOSTAPD_MODE_IEEE80211G; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2418 | else if (os_strcmp(pos, "ad") == 0) |
| 2419 | conf->hw_mode = HOSTAPD_MODE_IEEE80211AD; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2420 | else { |
| 2421 | wpa_printf(MSG_ERROR, "Line %d: unknown " |
| 2422 | "hw_mode '%s'", line, pos); |
| 2423 | errors++; |
| 2424 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2425 | } else if (os_strcmp(buf, "wps_rf_bands") == 0) { |
| 2426 | if (os_strcmp(pos, "a") == 0) |
| 2427 | bss->wps_rf_bands = WPS_RF_50GHZ; |
| 2428 | else if (os_strcmp(pos, "g") == 0 || |
| 2429 | os_strcmp(pos, "b") == 0) |
| 2430 | bss->wps_rf_bands = WPS_RF_24GHZ; |
| 2431 | else if (os_strcmp(pos, "ag") == 0 || |
| 2432 | os_strcmp(pos, "ga") == 0) |
| 2433 | bss->wps_rf_bands = |
| 2434 | WPS_RF_24GHZ | WPS_RF_50GHZ; |
| 2435 | else { |
| 2436 | wpa_printf(MSG_ERROR, "Line %d: unknown " |
| 2437 | "wps_rf_band '%s'", line, pos); |
| 2438 | errors++; |
| 2439 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2440 | } else if (os_strcmp(buf, "channel") == 0) { |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 2441 | if (os_strcmp(pos, "acs_survey") == 0) { |
| 2442 | #ifndef CONFIG_ACS |
| 2443 | wpa_printf(MSG_ERROR, "Line %d: tries to enable ACS but CONFIG_ACS disabled", |
| 2444 | line); |
| 2445 | errors++; |
| 2446 | #endif /* CONFIG_ACS */ |
| 2447 | conf->channel = 0; |
| 2448 | } else |
| 2449 | conf->channel = atoi(pos); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2450 | } else if (os_strcmp(buf, "beacon_int") == 0) { |
| 2451 | int val = atoi(pos); |
| 2452 | /* MIB defines range as 1..65535, but very small values |
| 2453 | * cause problems with the current implementation. |
| 2454 | * Since it is unlikely that this small numbers are |
| 2455 | * useful in real life scenarios, do not allow beacon |
| 2456 | * period to be set below 15 TU. */ |
| 2457 | if (val < 15 || val > 65535) { |
| 2458 | wpa_printf(MSG_ERROR, "Line %d: invalid " |
| 2459 | "beacon_int %d (expected " |
| 2460 | "15..65535)", line, val); |
| 2461 | errors++; |
| 2462 | } else |
| 2463 | conf->beacon_int = val; |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 2464 | #ifdef CONFIG_ACS |
| 2465 | } else if (os_strcmp(buf, "acs_num_scans") == 0) { |
| 2466 | int val = atoi(pos); |
| 2467 | if (val <= 0 || val > 100) { |
| 2468 | wpa_printf(MSG_ERROR, "Line %d: invalid acs_num_scans %d (expected 1..100)", |
| 2469 | line, val); |
| 2470 | errors++; |
| 2471 | } else |
| 2472 | conf->acs_num_scans = val; |
| 2473 | #endif /* CONFIG_ACS */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2474 | } else if (os_strcmp(buf, "dtim_period") == 0) { |
| 2475 | bss->dtim_period = atoi(pos); |
| 2476 | if (bss->dtim_period < 1 || bss->dtim_period > 255) { |
| 2477 | wpa_printf(MSG_ERROR, "Line %d: invalid " |
| 2478 | "dtim_period %d", |
| 2479 | line, bss->dtim_period); |
| 2480 | errors++; |
| 2481 | } |
| 2482 | } else if (os_strcmp(buf, "rts_threshold") == 0) { |
| 2483 | conf->rts_threshold = atoi(pos); |
| 2484 | if (conf->rts_threshold < 0 || |
| 2485 | conf->rts_threshold > 2347) { |
| 2486 | wpa_printf(MSG_ERROR, "Line %d: invalid " |
| 2487 | "rts_threshold %d", |
| 2488 | line, conf->rts_threshold); |
| 2489 | errors++; |
| 2490 | } |
| 2491 | } else if (os_strcmp(buf, "fragm_threshold") == 0) { |
| 2492 | conf->fragm_threshold = atoi(pos); |
| 2493 | if (conf->fragm_threshold < 256 || |
| 2494 | conf->fragm_threshold > 2346) { |
| 2495 | wpa_printf(MSG_ERROR, "Line %d: invalid " |
| 2496 | "fragm_threshold %d", |
| 2497 | line, conf->fragm_threshold); |
| 2498 | errors++; |
| 2499 | } |
| 2500 | } else if (os_strcmp(buf, "send_probe_response") == 0) { |
| 2501 | int val = atoi(pos); |
| 2502 | if (val != 0 && val != 1) { |
| 2503 | wpa_printf(MSG_ERROR, "Line %d: invalid " |
| 2504 | "send_probe_response %d (expected " |
| 2505 | "0 or 1)", line, val); |
| 2506 | } else |
| 2507 | conf->send_probe_response = val; |
| 2508 | } else if (os_strcmp(buf, "supported_rates") == 0) { |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 2509 | if (hostapd_parse_intlist(&conf->supported_rates, pos)) |
| 2510 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2511 | wpa_printf(MSG_ERROR, "Line %d: invalid rate " |
| 2512 | "list", line); |
| 2513 | errors++; |
| 2514 | } |
| 2515 | } else if (os_strcmp(buf, "basic_rates") == 0) { |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 2516 | if (hostapd_parse_intlist(&conf->basic_rates, pos)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2517 | wpa_printf(MSG_ERROR, "Line %d: invalid rate " |
| 2518 | "list", line); |
| 2519 | errors++; |
| 2520 | } |
| 2521 | } else if (os_strcmp(buf, "preamble") == 0) { |
| 2522 | if (atoi(pos)) |
| 2523 | conf->preamble = SHORT_PREAMBLE; |
| 2524 | else |
| 2525 | conf->preamble = LONG_PREAMBLE; |
| 2526 | } else if (os_strcmp(buf, "ignore_broadcast_ssid") == 0) { |
| 2527 | bss->ignore_broadcast_ssid = atoi(pos); |
| 2528 | } else if (os_strcmp(buf, "wep_default_key") == 0) { |
| 2529 | bss->ssid.wep.idx = atoi(pos); |
| 2530 | if (bss->ssid.wep.idx > 3) { |
| 2531 | wpa_printf(MSG_ERROR, "Invalid " |
| 2532 | "wep_default_key index %d", |
| 2533 | bss->ssid.wep.idx); |
| 2534 | errors++; |
| 2535 | } |
| 2536 | } else if (os_strcmp(buf, "wep_key0") == 0 || |
| 2537 | os_strcmp(buf, "wep_key1") == 0 || |
| 2538 | os_strcmp(buf, "wep_key2") == 0 || |
| 2539 | os_strcmp(buf, "wep_key3") == 0) { |
| 2540 | if (hostapd_config_read_wep(&bss->ssid.wep, |
| 2541 | buf[7] - '0', pos)) { |
| 2542 | wpa_printf(MSG_ERROR, "Line %d: invalid WEP " |
| 2543 | "key '%s'", line, buf); |
| 2544 | errors++; |
| 2545 | } |
| 2546 | #ifndef CONFIG_NO_VLAN |
| 2547 | } else if (os_strcmp(buf, "dynamic_vlan") == 0) { |
| 2548 | bss->ssid.dynamic_vlan = atoi(pos); |
| 2549 | } else if (os_strcmp(buf, "vlan_file") == 0) { |
| 2550 | if (hostapd_config_read_vlan_file(bss, pos)) { |
| 2551 | wpa_printf(MSG_ERROR, "Line %d: failed to " |
| 2552 | "read VLAN file '%s'", line, pos); |
| 2553 | errors++; |
| 2554 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2555 | } else if (os_strcmp(buf, "vlan_naming") == 0) { |
| 2556 | bss->ssid.vlan_naming = atoi(pos); |
| 2557 | if (bss->ssid.vlan_naming >= DYNAMIC_VLAN_NAMING_END || |
| 2558 | bss->ssid.vlan_naming < 0) { |
| 2559 | wpa_printf(MSG_ERROR, "Line %d: invalid " |
| 2560 | "naming scheme %d", line, |
| 2561 | bss->ssid.vlan_naming); |
| 2562 | errors++; |
| 2563 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2564 | #ifdef CONFIG_FULL_DYNAMIC_VLAN |
| 2565 | } else if (os_strcmp(buf, "vlan_tagged_interface") == 0) { |
| 2566 | bss->ssid.vlan_tagged_interface = os_strdup(pos); |
| 2567 | #endif /* CONFIG_FULL_DYNAMIC_VLAN */ |
| 2568 | #endif /* CONFIG_NO_VLAN */ |
| 2569 | } else if (os_strcmp(buf, "ap_table_max_size") == 0) { |
| 2570 | conf->ap_table_max_size = atoi(pos); |
| 2571 | } else if (os_strcmp(buf, "ap_table_expiration_time") == 0) { |
| 2572 | conf->ap_table_expiration_time = atoi(pos); |
| 2573 | } else if (os_strncmp(buf, "tx_queue_", 9) == 0) { |
| 2574 | if (hostapd_config_tx_queue(conf, buf, pos)) { |
| 2575 | wpa_printf(MSG_ERROR, "Line %d: invalid TX " |
| 2576 | "queue item", line); |
| 2577 | errors++; |
| 2578 | } |
| 2579 | } else if (os_strcmp(buf, "wme_enabled") == 0 || |
| 2580 | os_strcmp(buf, "wmm_enabled") == 0) { |
| 2581 | bss->wmm_enabled = atoi(pos); |
| 2582 | } else if (os_strcmp(buf, "uapsd_advertisement_enabled") == 0) { |
| 2583 | bss->wmm_uapsd = atoi(pos); |
| 2584 | } else if (os_strncmp(buf, "wme_ac_", 7) == 0 || |
| 2585 | os_strncmp(buf, "wmm_ac_", 7) == 0) { |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2586 | if (hostapd_config_wmm_ac(conf->wmm_ac_params, buf, |
| 2587 | pos)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2588 | wpa_printf(MSG_ERROR, "Line %d: invalid WMM " |
| 2589 | "ac item", line); |
| 2590 | errors++; |
| 2591 | } |
| 2592 | } else if (os_strcmp(buf, "bss") == 0) { |
| 2593 | if (hostapd_config_bss(conf, pos)) { |
| 2594 | wpa_printf(MSG_ERROR, "Line %d: invalid bss " |
| 2595 | "item", line); |
| 2596 | errors++; |
| 2597 | } |
| 2598 | } else if (os_strcmp(buf, "bssid") == 0) { |
| 2599 | if (hwaddr_aton(pos, bss->bssid)) { |
| 2600 | wpa_printf(MSG_ERROR, "Line %d: invalid bssid " |
| 2601 | "item", line); |
| 2602 | errors++; |
| 2603 | } |
| 2604 | #ifdef CONFIG_IEEE80211W |
| 2605 | } else if (os_strcmp(buf, "ieee80211w") == 0) { |
| 2606 | bss->ieee80211w = atoi(pos); |
| 2607 | } else if (os_strcmp(buf, "assoc_sa_query_max_timeout") == 0) { |
| 2608 | bss->assoc_sa_query_max_timeout = atoi(pos); |
| 2609 | if (bss->assoc_sa_query_max_timeout == 0) { |
| 2610 | wpa_printf(MSG_ERROR, "Line %d: invalid " |
| 2611 | "assoc_sa_query_max_timeout", line); |
| 2612 | errors++; |
| 2613 | } |
| 2614 | } else if (os_strcmp(buf, "assoc_sa_query_retry_timeout") == 0) |
| 2615 | { |
| 2616 | bss->assoc_sa_query_retry_timeout = atoi(pos); |
| 2617 | if (bss->assoc_sa_query_retry_timeout == 0) { |
| 2618 | wpa_printf(MSG_ERROR, "Line %d: invalid " |
| 2619 | "assoc_sa_query_retry_timeout", |
| 2620 | line); |
| 2621 | errors++; |
| 2622 | } |
| 2623 | #endif /* CONFIG_IEEE80211W */ |
| 2624 | #ifdef CONFIG_IEEE80211N |
| 2625 | } else if (os_strcmp(buf, "ieee80211n") == 0) { |
| 2626 | conf->ieee80211n = atoi(pos); |
| 2627 | } else if (os_strcmp(buf, "ht_capab") == 0) { |
| 2628 | if (hostapd_config_ht_capab(conf, pos) < 0) { |
| 2629 | wpa_printf(MSG_ERROR, "Line %d: invalid " |
| 2630 | "ht_capab", line); |
| 2631 | errors++; |
| 2632 | } |
| 2633 | } else if (os_strcmp(buf, "require_ht") == 0) { |
| 2634 | conf->require_ht = atoi(pos); |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 2635 | } else if (os_strcmp(buf, "obss_interval") == 0) { |
| 2636 | conf->obss_interval = atoi(pos); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2637 | #endif /* CONFIG_IEEE80211N */ |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2638 | #ifdef CONFIG_IEEE80211AC |
| 2639 | } else if (os_strcmp(buf, "ieee80211ac") == 0) { |
| 2640 | conf->ieee80211ac = atoi(pos); |
| 2641 | } else if (os_strcmp(buf, "vht_capab") == 0) { |
| 2642 | if (hostapd_config_vht_capab(conf, pos) < 0) { |
| 2643 | wpa_printf(MSG_ERROR, "Line %d: invalid " |
| 2644 | "vht_capab", line); |
| 2645 | errors++; |
| 2646 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2647 | } else if (os_strcmp(buf, "require_vht") == 0) { |
| 2648 | conf->require_vht = atoi(pos); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2649 | } else if (os_strcmp(buf, "vht_oper_chwidth") == 0) { |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2650 | conf->vht_oper_chwidth = atoi(pos); |
| 2651 | } else if (os_strcmp(buf, "vht_oper_centr_freq_seg0_idx") == 0) |
| 2652 | { |
| 2653 | conf->vht_oper_centr_freq_seg0_idx = atoi(pos); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2654 | } else if (os_strcmp(buf, "vht_oper_centr_freq_seg1_idx") == 0) |
| 2655 | { |
| 2656 | conf->vht_oper_centr_freq_seg1_idx = atoi(pos); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2657 | #endif /* CONFIG_IEEE80211AC */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2658 | } else if (os_strcmp(buf, "max_listen_interval") == 0) { |
| 2659 | bss->max_listen_interval = atoi(pos); |
Dmitry Shmidt | c55524a | 2011-07-07 11:18:38 -0700 | [diff] [blame] | 2660 | } else if (os_strcmp(buf, "disable_pmksa_caching") == 0) { |
| 2661 | bss->disable_pmksa_caching = atoi(pos); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2662 | } else if (os_strcmp(buf, "okc") == 0) { |
| 2663 | bss->okc = atoi(pos); |
| 2664 | #ifdef CONFIG_WPS |
| 2665 | } else if (os_strcmp(buf, "wps_state") == 0) { |
| 2666 | bss->wps_state = atoi(pos); |
| 2667 | if (bss->wps_state < 0 || bss->wps_state > 2) { |
| 2668 | wpa_printf(MSG_ERROR, "Line %d: invalid " |
| 2669 | "wps_state", line); |
| 2670 | errors++; |
| 2671 | } |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 2672 | } else if (os_strcmp(buf, "wps_independent") == 0) { |
| 2673 | bss->wps_independent = atoi(pos); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2674 | } else if (os_strcmp(buf, "ap_setup_locked") == 0) { |
| 2675 | bss->ap_setup_locked = atoi(pos); |
| 2676 | } else if (os_strcmp(buf, "uuid") == 0) { |
| 2677 | if (uuid_str2bin(pos, bss->uuid)) { |
| 2678 | wpa_printf(MSG_ERROR, "Line %d: invalid UUID", |
| 2679 | line); |
| 2680 | errors++; |
| 2681 | } |
| 2682 | } else if (os_strcmp(buf, "wps_pin_requests") == 0) { |
| 2683 | os_free(bss->wps_pin_requests); |
| 2684 | bss->wps_pin_requests = os_strdup(pos); |
| 2685 | } else if (os_strcmp(buf, "device_name") == 0) { |
| 2686 | if (os_strlen(pos) > 32) { |
| 2687 | wpa_printf(MSG_ERROR, "Line %d: Too long " |
| 2688 | "device_name", line); |
| 2689 | errors++; |
| 2690 | } |
| 2691 | os_free(bss->device_name); |
| 2692 | bss->device_name = os_strdup(pos); |
| 2693 | } else if (os_strcmp(buf, "manufacturer") == 0) { |
| 2694 | if (os_strlen(pos) > 64) { |
| 2695 | wpa_printf(MSG_ERROR, "Line %d: Too long " |
| 2696 | "manufacturer", line); |
| 2697 | errors++; |
| 2698 | } |
| 2699 | os_free(bss->manufacturer); |
| 2700 | bss->manufacturer = os_strdup(pos); |
| 2701 | } else if (os_strcmp(buf, "model_name") == 0) { |
| 2702 | if (os_strlen(pos) > 32) { |
| 2703 | wpa_printf(MSG_ERROR, "Line %d: Too long " |
| 2704 | "model_name", line); |
| 2705 | errors++; |
| 2706 | } |
| 2707 | os_free(bss->model_name); |
| 2708 | bss->model_name = os_strdup(pos); |
| 2709 | } else if (os_strcmp(buf, "model_number") == 0) { |
| 2710 | if (os_strlen(pos) > 32) { |
| 2711 | wpa_printf(MSG_ERROR, "Line %d: Too long " |
| 2712 | "model_number", line); |
| 2713 | errors++; |
| 2714 | } |
| 2715 | os_free(bss->model_number); |
| 2716 | bss->model_number = os_strdup(pos); |
| 2717 | } else if (os_strcmp(buf, "serial_number") == 0) { |
| 2718 | if (os_strlen(pos) > 32) { |
| 2719 | wpa_printf(MSG_ERROR, "Line %d: Too long " |
| 2720 | "serial_number", line); |
| 2721 | errors++; |
| 2722 | } |
| 2723 | os_free(bss->serial_number); |
| 2724 | bss->serial_number = os_strdup(pos); |
| 2725 | } else if (os_strcmp(buf, "device_type") == 0) { |
| 2726 | if (wps_dev_type_str2bin(pos, bss->device_type)) |
| 2727 | errors++; |
| 2728 | } else if (os_strcmp(buf, "config_methods") == 0) { |
| 2729 | os_free(bss->config_methods); |
| 2730 | bss->config_methods = os_strdup(pos); |
| 2731 | } else if (os_strcmp(buf, "os_version") == 0) { |
| 2732 | if (hexstr2bin(pos, bss->os_version, 4)) { |
| 2733 | wpa_printf(MSG_ERROR, "Line %d: invalid " |
| 2734 | "os_version", line); |
| 2735 | errors++; |
| 2736 | } |
| 2737 | } else if (os_strcmp(buf, "ap_pin") == 0) { |
| 2738 | os_free(bss->ap_pin); |
| 2739 | bss->ap_pin = os_strdup(pos); |
| 2740 | } else if (os_strcmp(buf, "skip_cred_build") == 0) { |
| 2741 | bss->skip_cred_build = atoi(pos); |
| 2742 | } else if (os_strcmp(buf, "extra_cred") == 0) { |
| 2743 | os_free(bss->extra_cred); |
| 2744 | bss->extra_cred = |
| 2745 | (u8 *) os_readfile(pos, &bss->extra_cred_len); |
| 2746 | if (bss->extra_cred == NULL) { |
| 2747 | wpa_printf(MSG_ERROR, "Line %d: could not " |
| 2748 | "read Credentials from '%s'", |
| 2749 | line, pos); |
| 2750 | errors++; |
| 2751 | } |
| 2752 | } else if (os_strcmp(buf, "wps_cred_processing") == 0) { |
| 2753 | bss->wps_cred_processing = atoi(pos); |
| 2754 | } else if (os_strcmp(buf, "ap_settings") == 0) { |
| 2755 | os_free(bss->ap_settings); |
| 2756 | bss->ap_settings = |
| 2757 | (u8 *) os_readfile(pos, &bss->ap_settings_len); |
| 2758 | if (bss->ap_settings == NULL) { |
| 2759 | wpa_printf(MSG_ERROR, "Line %d: could not " |
| 2760 | "read AP Settings from '%s'", |
| 2761 | line, pos); |
| 2762 | errors++; |
| 2763 | } |
| 2764 | } else if (os_strcmp(buf, "upnp_iface") == 0) { |
| 2765 | bss->upnp_iface = os_strdup(pos); |
| 2766 | } else if (os_strcmp(buf, "friendly_name") == 0) { |
| 2767 | os_free(bss->friendly_name); |
| 2768 | bss->friendly_name = os_strdup(pos); |
| 2769 | } else if (os_strcmp(buf, "manufacturer_url") == 0) { |
| 2770 | os_free(bss->manufacturer_url); |
| 2771 | bss->manufacturer_url = os_strdup(pos); |
| 2772 | } else if (os_strcmp(buf, "model_description") == 0) { |
| 2773 | os_free(bss->model_description); |
| 2774 | bss->model_description = os_strdup(pos); |
| 2775 | } else if (os_strcmp(buf, "model_url") == 0) { |
| 2776 | os_free(bss->model_url); |
| 2777 | bss->model_url = os_strdup(pos); |
| 2778 | } else if (os_strcmp(buf, "upc") == 0) { |
| 2779 | os_free(bss->upc); |
| 2780 | bss->upc = os_strdup(pos); |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 2781 | } else if (os_strcmp(buf, "pbc_in_m1") == 0) { |
| 2782 | bss->pbc_in_m1 = atoi(pos); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2783 | } else if (os_strcmp(buf, "server_id") == 0) { |
| 2784 | os_free(bss->server_id); |
| 2785 | bss->server_id = os_strdup(pos); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2786 | #ifdef CONFIG_WPS_NFC |
| 2787 | } else if (os_strcmp(buf, "wps_nfc_dev_pw_id") == 0) { |
| 2788 | bss->wps_nfc_dev_pw_id = atoi(pos); |
| 2789 | if (bss->wps_nfc_dev_pw_id < 0x10 || |
| 2790 | bss->wps_nfc_dev_pw_id > 0xffff) { |
| 2791 | wpa_printf(MSG_ERROR, "Line %d: Invalid " |
| 2792 | "wps_nfc_dev_pw_id value", line); |
| 2793 | errors++; |
| 2794 | } |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 2795 | bss->wps_nfc_pw_from_config = 1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2796 | } else if (os_strcmp(buf, "wps_nfc_dh_pubkey") == 0) { |
| 2797 | wpabuf_free(bss->wps_nfc_dh_pubkey); |
| 2798 | bss->wps_nfc_dh_pubkey = hostapd_parse_bin(pos); |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 2799 | bss->wps_nfc_pw_from_config = 1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2800 | } else if (os_strcmp(buf, "wps_nfc_dh_privkey") == 0) { |
| 2801 | wpabuf_free(bss->wps_nfc_dh_privkey); |
| 2802 | bss->wps_nfc_dh_privkey = hostapd_parse_bin(pos); |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 2803 | bss->wps_nfc_pw_from_config = 1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2804 | } else if (os_strcmp(buf, "wps_nfc_dev_pw") == 0) { |
| 2805 | wpabuf_free(bss->wps_nfc_dev_pw); |
| 2806 | bss->wps_nfc_dev_pw = hostapd_parse_bin(pos); |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 2807 | bss->wps_nfc_pw_from_config = 1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2808 | #endif /* CONFIG_WPS_NFC */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2809 | #endif /* CONFIG_WPS */ |
| 2810 | #ifdef CONFIG_P2P_MANAGER |
| 2811 | } else if (os_strcmp(buf, "manage_p2p") == 0) { |
| 2812 | int manage = atoi(pos); |
| 2813 | if (manage) |
| 2814 | bss->p2p |= P2P_MANAGE; |
| 2815 | else |
| 2816 | bss->p2p &= ~P2P_MANAGE; |
| 2817 | } else if (os_strcmp(buf, "allow_cross_connection") == 0) { |
| 2818 | if (atoi(pos)) |
| 2819 | bss->p2p |= P2P_ALLOW_CROSS_CONNECTION; |
| 2820 | else |
| 2821 | bss->p2p &= ~P2P_ALLOW_CROSS_CONNECTION; |
| 2822 | #endif /* CONFIG_P2P_MANAGER */ |
| 2823 | } else if (os_strcmp(buf, "disassoc_low_ack") == 0) { |
| 2824 | bss->disassoc_low_ack = atoi(pos); |
| 2825 | } else if (os_strcmp(buf, "tdls_prohibit") == 0) { |
| 2826 | int val = atoi(pos); |
| 2827 | if (val) |
| 2828 | bss->tdls |= TDLS_PROHIBIT; |
| 2829 | else |
| 2830 | bss->tdls &= ~TDLS_PROHIBIT; |
| 2831 | } else if (os_strcmp(buf, "tdls_prohibit_chan_switch") == 0) { |
| 2832 | int val = atoi(pos); |
| 2833 | if (val) |
| 2834 | bss->tdls |= TDLS_PROHIBIT_CHAN_SWITCH; |
| 2835 | else |
| 2836 | bss->tdls &= ~TDLS_PROHIBIT_CHAN_SWITCH; |
| 2837 | #ifdef CONFIG_RSN_TESTING |
| 2838 | } else if (os_strcmp(buf, "rsn_testing") == 0) { |
| 2839 | extern int rsn_testing; |
| 2840 | rsn_testing = atoi(pos); |
| 2841 | #endif /* CONFIG_RSN_TESTING */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2842 | } else if (os_strcmp(buf, "time_advertisement") == 0) { |
| 2843 | bss->time_advertisement = atoi(pos); |
| 2844 | } else if (os_strcmp(buf, "time_zone") == 0) { |
| 2845 | size_t tz_len = os_strlen(pos); |
| 2846 | if (tz_len < 4 || tz_len > 255) { |
| 2847 | wpa_printf(MSG_DEBUG, "Line %d: invalid " |
| 2848 | "time_zone", line); |
| 2849 | errors++; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2850 | return errors; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2851 | } |
| 2852 | os_free(bss->time_zone); |
| 2853 | bss->time_zone = os_strdup(pos); |
| 2854 | if (bss->time_zone == NULL) |
| 2855 | errors++; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2856 | #ifdef CONFIG_WNM |
| 2857 | } else if (os_strcmp(buf, "wnm_sleep_mode") == 0) { |
| 2858 | bss->wnm_sleep_mode = atoi(pos); |
| 2859 | } else if (os_strcmp(buf, "bss_transition") == 0) { |
| 2860 | bss->bss_transition = atoi(pos); |
| 2861 | #endif /* CONFIG_WNM */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2862 | #ifdef CONFIG_INTERWORKING |
| 2863 | } else if (os_strcmp(buf, "interworking") == 0) { |
| 2864 | bss->interworking = atoi(pos); |
| 2865 | } else if (os_strcmp(buf, "access_network_type") == 0) { |
| 2866 | bss->access_network_type = atoi(pos); |
| 2867 | if (bss->access_network_type < 0 || |
| 2868 | bss->access_network_type > 15) { |
| 2869 | wpa_printf(MSG_ERROR, "Line %d: invalid " |
| 2870 | "access_network_type", line); |
| 2871 | errors++; |
| 2872 | } |
| 2873 | } else if (os_strcmp(buf, "internet") == 0) { |
| 2874 | bss->internet = atoi(pos); |
| 2875 | } else if (os_strcmp(buf, "asra") == 0) { |
| 2876 | bss->asra = atoi(pos); |
| 2877 | } else if (os_strcmp(buf, "esr") == 0) { |
| 2878 | bss->esr = atoi(pos); |
| 2879 | } else if (os_strcmp(buf, "uesa") == 0) { |
| 2880 | bss->uesa = atoi(pos); |
| 2881 | } else if (os_strcmp(buf, "venue_group") == 0) { |
| 2882 | bss->venue_group = atoi(pos); |
| 2883 | bss->venue_info_set = 1; |
| 2884 | } else if (os_strcmp(buf, "venue_type") == 0) { |
| 2885 | bss->venue_type = atoi(pos); |
| 2886 | bss->venue_info_set = 1; |
| 2887 | } else if (os_strcmp(buf, "hessid") == 0) { |
| 2888 | if (hwaddr_aton(pos, bss->hessid)) { |
| 2889 | wpa_printf(MSG_ERROR, "Line %d: invalid " |
| 2890 | "hessid", line); |
| 2891 | errors++; |
| 2892 | } |
| 2893 | } else if (os_strcmp(buf, "roaming_consortium") == 0) { |
| 2894 | if (parse_roaming_consortium(bss, pos, line) < 0) |
| 2895 | errors++; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2896 | } else if (os_strcmp(buf, "venue_name") == 0) { |
| 2897 | if (parse_venue_name(bss, pos, line) < 0) |
| 2898 | errors++; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2899 | } else if (os_strcmp(buf, "network_auth_type") == 0) { |
| 2900 | u8 auth_type; |
| 2901 | u16 redirect_url_len; |
| 2902 | if (hexstr2bin(pos, &auth_type, 1)) { |
| 2903 | wpa_printf(MSG_ERROR, "Line %d: Invalid " |
| 2904 | "network_auth_type '%s'", |
| 2905 | line, pos); |
| 2906 | errors++; |
| 2907 | return errors; |
| 2908 | } |
| 2909 | if (auth_type == 0 || auth_type == 2) |
| 2910 | redirect_url_len = os_strlen(pos + 2); |
| 2911 | else |
| 2912 | redirect_url_len = 0; |
| 2913 | os_free(bss->network_auth_type); |
| 2914 | bss->network_auth_type = |
| 2915 | os_malloc(redirect_url_len + 3 + 1); |
| 2916 | if (bss->network_auth_type == NULL) { |
| 2917 | errors++; |
| 2918 | return errors; |
| 2919 | } |
| 2920 | *bss->network_auth_type = auth_type; |
| 2921 | WPA_PUT_LE16(bss->network_auth_type + 1, |
| 2922 | redirect_url_len); |
| 2923 | if (redirect_url_len) |
| 2924 | os_memcpy(bss->network_auth_type + 3, |
| 2925 | pos + 2, redirect_url_len); |
| 2926 | bss->network_auth_type_len = 3 + redirect_url_len; |
| 2927 | } else if (os_strcmp(buf, "ipaddr_type_availability") == 0) { |
| 2928 | if (hexstr2bin(pos, &bss->ipaddr_type_availability, 1)) |
| 2929 | { |
| 2930 | wpa_printf(MSG_ERROR, "Line %d: Invalid " |
| 2931 | "ipaddr_type_availability '%s'", |
| 2932 | line, pos); |
| 2933 | bss->ipaddr_type_configured = 0; |
| 2934 | errors++; |
| 2935 | return errors; |
| 2936 | } |
| 2937 | bss->ipaddr_type_configured = 1; |
| 2938 | } else if (os_strcmp(buf, "domain_name") == 0) { |
| 2939 | int j, num_domains, domain_len, domain_list_len = 0; |
| 2940 | char *tok_start, *tok_prev; |
| 2941 | u8 *domain_list, *domain_ptr; |
| 2942 | |
| 2943 | domain_list_len = os_strlen(pos) + 1; |
| 2944 | domain_list = os_malloc(domain_list_len); |
| 2945 | if (domain_list == NULL) { |
| 2946 | errors++; |
| 2947 | return errors; |
| 2948 | } |
| 2949 | |
| 2950 | domain_ptr = domain_list; |
| 2951 | tok_prev = pos; |
| 2952 | num_domains = 1; |
| 2953 | while ((tok_prev = os_strchr(tok_prev, ','))) { |
| 2954 | num_domains++; |
| 2955 | tok_prev++; |
| 2956 | } |
| 2957 | tok_prev = pos; |
| 2958 | for (j = 0; j < num_domains; j++) { |
| 2959 | tok_start = os_strchr(tok_prev, ','); |
| 2960 | if (tok_start) { |
| 2961 | domain_len = tok_start - tok_prev; |
| 2962 | *domain_ptr = domain_len; |
| 2963 | os_memcpy(domain_ptr + 1, tok_prev, |
| 2964 | domain_len); |
| 2965 | domain_ptr += domain_len + 1; |
| 2966 | tok_prev = ++tok_start; |
| 2967 | } else { |
| 2968 | domain_len = os_strlen(tok_prev); |
| 2969 | *domain_ptr = domain_len; |
| 2970 | os_memcpy(domain_ptr + 1, tok_prev, |
| 2971 | domain_len); |
| 2972 | domain_ptr += domain_len + 1; |
| 2973 | } |
| 2974 | } |
| 2975 | |
| 2976 | os_free(bss->domain_name); |
| 2977 | bss->domain_name = domain_list; |
| 2978 | bss->domain_name_len = domain_list_len; |
| 2979 | } else if (os_strcmp(buf, "anqp_3gpp_cell_net") == 0) { |
| 2980 | if (parse_3gpp_cell_net(bss, pos, line) < 0) |
| 2981 | errors++; |
| 2982 | } else if (os_strcmp(buf, "nai_realm") == 0) { |
| 2983 | if (parse_nai_realm(bss, pos, line) < 0) |
| 2984 | errors++; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2985 | } else if (os_strcmp(buf, "gas_frag_limit") == 0) { |
| 2986 | bss->gas_frag_limit = atoi(pos); |
| 2987 | } else if (os_strcmp(buf, "gas_comeback_delay") == 0) { |
| 2988 | bss->gas_comeback_delay = atoi(pos); |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 2989 | } else if (os_strcmp(buf, "qos_map_set") == 0) { |
| 2990 | if (parse_qos_map_set(bss, pos, line) < 0) |
| 2991 | errors++; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2992 | #endif /* CONFIG_INTERWORKING */ |
| 2993 | #ifdef CONFIG_RADIUS_TEST |
| 2994 | } else if (os_strcmp(buf, "dump_msk_file") == 0) { |
| 2995 | os_free(bss->dump_msk_file); |
| 2996 | bss->dump_msk_file = os_strdup(pos); |
| 2997 | #endif /* CONFIG_RADIUS_TEST */ |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2998 | #ifdef CONFIG_HS20 |
| 2999 | } else if (os_strcmp(buf, "hs20") == 0) { |
| 3000 | bss->hs20 = atoi(pos); |
| 3001 | } else if (os_strcmp(buf, "disable_dgaf") == 0) { |
| 3002 | bss->disable_dgaf = atoi(pos); |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame^] | 3003 | } else if (os_strcmp(buf, "osen") == 0) { |
| 3004 | bss->osen = atoi(pos); |
| 3005 | } else if (os_strcmp(buf, "anqp_domain_id") == 0) { |
| 3006 | bss->anqp_domain_id = atoi(pos); |
| 3007 | } else if (os_strcmp(buf, "hs20_deauth_req_timeout") == 0) { |
| 3008 | bss->hs20_deauth_req_timeout = atoi(pos); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3009 | } else if (os_strcmp(buf, "hs20_oper_friendly_name") == 0) { |
| 3010 | if (hs20_parse_oper_friendly_name(bss, pos, line) < 0) |
| 3011 | errors++; |
| 3012 | } else if (os_strcmp(buf, "hs20_wan_metrics") == 0) { |
| 3013 | if (hs20_parse_wan_metrics(bss, pos, line) < 0) { |
| 3014 | errors++; |
| 3015 | return errors; |
| 3016 | } |
| 3017 | } else if (os_strcmp(buf, "hs20_conn_capab") == 0) { |
| 3018 | if (hs20_parse_conn_capab(bss, pos, line) < 0) { |
| 3019 | errors++; |
| 3020 | return errors; |
| 3021 | } |
| 3022 | } else if (os_strcmp(buf, "hs20_operating_class") == 0) { |
| 3023 | u8 *oper_class; |
| 3024 | size_t oper_class_len; |
| 3025 | oper_class_len = os_strlen(pos); |
| 3026 | if (oper_class_len < 2 || (oper_class_len & 0x01)) { |
| 3027 | wpa_printf(MSG_ERROR, "Line %d: Invalid " |
| 3028 | "hs20_operating_class '%s'", |
| 3029 | line, pos); |
| 3030 | errors++; |
| 3031 | return errors; |
| 3032 | } |
| 3033 | oper_class_len /= 2; |
| 3034 | oper_class = os_malloc(oper_class_len); |
| 3035 | if (oper_class == NULL) { |
| 3036 | errors++; |
| 3037 | return errors; |
| 3038 | } |
| 3039 | if (hexstr2bin(pos, oper_class, oper_class_len)) { |
| 3040 | wpa_printf(MSG_ERROR, "Line %d: Invalid " |
| 3041 | "hs20_operating_class '%s'", |
| 3042 | line, pos); |
| 3043 | os_free(oper_class); |
| 3044 | errors++; |
| 3045 | return errors; |
| 3046 | } |
| 3047 | os_free(bss->hs20_operating_class); |
| 3048 | bss->hs20_operating_class = oper_class; |
| 3049 | bss->hs20_operating_class_len = oper_class_len; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame^] | 3050 | } else if (os_strcmp(buf, "hs20_icon") == 0) { |
| 3051 | if (hs20_parse_icon(bss, pos) < 0) { |
| 3052 | wpa_printf(MSG_ERROR, "Line %d: Invalid " |
| 3053 | "hs20_icon '%s'", line, pos); |
| 3054 | errors++; |
| 3055 | return errors; |
| 3056 | } |
| 3057 | } else if (os_strcmp(buf, "osu_ssid") == 0) { |
| 3058 | if (hs20_parse_osu_ssid(bss, pos, line) < 0) |
| 3059 | errors++; |
| 3060 | } else if (os_strcmp(buf, "osu_server_uri") == 0) { |
| 3061 | if (hs20_parse_osu_server_uri(bss, pos, line) < 0) |
| 3062 | errors++; |
| 3063 | } else if (os_strcmp(buf, "osu_friendly_name") == 0) { |
| 3064 | if (hs20_parse_osu_friendly_name(bss, pos, line) < 0) |
| 3065 | errors++; |
| 3066 | } else if (os_strcmp(buf, "osu_nai") == 0) { |
| 3067 | if (hs20_parse_osu_nai(bss, pos, line) < 0) |
| 3068 | errors++; |
| 3069 | } else if (os_strcmp(buf, "osu_method_list") == 0) { |
| 3070 | if (hs20_parse_osu_method_list(bss, pos, line) < 0) |
| 3071 | errors++; |
| 3072 | } else if (os_strcmp(buf, "osu_icon") == 0) { |
| 3073 | if (hs20_parse_osu_icon(bss, pos, line) < 0) |
| 3074 | errors++; |
| 3075 | } else if (os_strcmp(buf, "osu_service_desc") == 0) { |
| 3076 | if (hs20_parse_osu_service_desc(bss, pos, line) < 0) |
| 3077 | errors++; |
| 3078 | } else if (os_strcmp(buf, "subscr_remediation_url") == 0) { |
| 3079 | os_free(bss->subscr_remediation_url); |
| 3080 | bss->subscr_remediation_url = os_strdup(pos); |
| 3081 | } else if (os_strcmp(buf, "subscr_remediation_method") == 0) { |
| 3082 | bss->subscr_remediation_method = atoi(pos); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3083 | #endif /* CONFIG_HS20 */ |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 3084 | #ifdef CONFIG_TESTING_OPTIONS |
| 3085 | #define PARSE_TEST_PROBABILITY(_val) \ |
| 3086 | } else if (os_strcmp(buf, #_val) == 0) { \ |
| 3087 | char *end; \ |
| 3088 | \ |
| 3089 | conf->_val = strtod(pos, &end); \ |
| 3090 | if (*end || conf->_val < 0.0d || \ |
| 3091 | conf->_val > 1.0d) { \ |
| 3092 | wpa_printf(MSG_ERROR, \ |
| 3093 | "Line %d: Invalid value '%s'", \ |
| 3094 | line, pos); \ |
| 3095 | errors++; \ |
| 3096 | return errors; \ |
| 3097 | } |
| 3098 | PARSE_TEST_PROBABILITY(ignore_probe_probability) |
| 3099 | PARSE_TEST_PROBABILITY(ignore_auth_probability) |
| 3100 | PARSE_TEST_PROBABILITY(ignore_assoc_probability) |
| 3101 | PARSE_TEST_PROBABILITY(ignore_reassoc_probability) |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 3102 | PARSE_TEST_PROBABILITY(corrupt_gtk_rekey_mic_probability) |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 3103 | } else if (os_strcmp(buf, "bss_load_test") == 0) { |
| 3104 | WPA_PUT_LE16(bss->bss_load_test, atoi(pos)); |
| 3105 | pos = os_strchr(pos, ':'); |
| 3106 | if (pos == NULL) { |
| 3107 | wpa_printf(MSG_ERROR, "Line %d: Invalid " |
| 3108 | "bss_load_test", line); |
| 3109 | return 1; |
| 3110 | } |
| 3111 | pos++; |
| 3112 | bss->bss_load_test[2] = atoi(pos); |
| 3113 | pos = os_strchr(pos, ':'); |
| 3114 | if (pos == NULL) { |
| 3115 | wpa_printf(MSG_ERROR, "Line %d: Invalid " |
| 3116 | "bss_load_test", line); |
| 3117 | return 1; |
| 3118 | } |
| 3119 | pos++; |
| 3120 | WPA_PUT_LE16(&bss->bss_load_test[3], atoi(pos)); |
| 3121 | bss->bss_load_test_set = 1; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 3122 | #endif /* CONFIG_TESTING_OPTIONS */ |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3123 | } else if (os_strcmp(buf, "vendor_elements") == 0) { |
| 3124 | struct wpabuf *elems; |
| 3125 | size_t len = os_strlen(pos); |
| 3126 | if (len & 0x01) { |
| 3127 | wpa_printf(MSG_ERROR, "Line %d: Invalid " |
| 3128 | "vendor_elements '%s'", line, pos); |
| 3129 | return 1; |
| 3130 | } |
| 3131 | len /= 2; |
| 3132 | if (len == 0) { |
| 3133 | wpabuf_free(bss->vendor_elements); |
| 3134 | bss->vendor_elements = NULL; |
| 3135 | return 0; |
| 3136 | } |
| 3137 | |
| 3138 | elems = wpabuf_alloc(len); |
| 3139 | if (elems == NULL) |
| 3140 | return 1; |
| 3141 | |
| 3142 | if (hexstr2bin(pos, wpabuf_put(elems, len), len)) { |
| 3143 | wpabuf_free(elems); |
| 3144 | wpa_printf(MSG_ERROR, "Line %d: Invalid " |
| 3145 | "vendor_elements '%s'", line, pos); |
| 3146 | return 1; |
| 3147 | } |
| 3148 | |
| 3149 | wpabuf_free(bss->vendor_elements); |
| 3150 | bss->vendor_elements = elems; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3151 | } else if (os_strcmp(buf, "sae_anti_clogging_threshold") == 0) { |
| 3152 | bss->sae_anti_clogging_threshold = atoi(pos); |
| 3153 | } else if (os_strcmp(buf, "sae_groups") == 0) { |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 3154 | if (hostapd_parse_intlist(&bss->sae_groups, pos)) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3155 | wpa_printf(MSG_ERROR, "Line %d: Invalid " |
| 3156 | "sae_groups value '%s'", line, pos); |
| 3157 | return 1; |
| 3158 | } |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame^] | 3159 | } else if (os_strcmp(buf, "local_pwr_constraint") == 0) { |
| 3160 | int val = atoi(pos); |
| 3161 | if (val < 0 || val > 255) { |
| 3162 | wpa_printf(MSG_ERROR, "Line %d: Invalid local_pwr_constraint %d (expected 0..255)", |
| 3163 | line, val); |
| 3164 | return 1; |
| 3165 | } |
| 3166 | conf->local_pwr_constraint = val; |
| 3167 | } else if (os_strcmp(buf, "spectrum_mgmt_required") == 0) { |
| 3168 | conf->spectrum_mgmt_required = atoi(pos); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3169 | } else { |
| 3170 | wpa_printf(MSG_ERROR, "Line %d: unknown configuration " |
| 3171 | "item '%s'", line, buf); |
| 3172 | errors++; |
| 3173 | } |
| 3174 | } |
| 3175 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3176 | return errors; |
| 3177 | } |
| 3178 | |
| 3179 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3180 | /** |
| 3181 | * hostapd_config_read - Read and parse a configuration file |
| 3182 | * @fname: Configuration file name (including path, if needed) |
| 3183 | * Returns: Allocated configuration data structure |
| 3184 | */ |
| 3185 | struct hostapd_config * hostapd_config_read(const char *fname) |
| 3186 | { |
| 3187 | struct hostapd_config *conf; |
| 3188 | struct hostapd_bss_config *bss; |
| 3189 | FILE *f; |
| 3190 | char buf[512], *pos; |
| 3191 | int line = 0; |
| 3192 | int errors = 0; |
| 3193 | size_t i; |
| 3194 | |
| 3195 | f = fopen(fname, "r"); |
| 3196 | if (f == NULL) { |
| 3197 | wpa_printf(MSG_ERROR, "Could not open configuration file '%s' " |
| 3198 | "for reading.", fname); |
| 3199 | return NULL; |
| 3200 | } |
| 3201 | |
| 3202 | conf = hostapd_config_defaults(); |
| 3203 | if (conf == NULL) { |
| 3204 | fclose(f); |
| 3205 | return NULL; |
| 3206 | } |
| 3207 | |
| 3208 | /* set default driver based on configuration */ |
| 3209 | conf->driver = wpa_drivers[0]; |
| 3210 | if (conf->driver == NULL) { |
| 3211 | wpa_printf(MSG_ERROR, "No driver wrappers registered!"); |
| 3212 | hostapd_config_free(conf); |
| 3213 | fclose(f); |
| 3214 | return NULL; |
| 3215 | } |
| 3216 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3217 | bss = conf->last_bss = conf->bss[0]; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3218 | |
| 3219 | while (fgets(buf, sizeof(buf), f)) { |
| 3220 | bss = conf->last_bss; |
| 3221 | line++; |
| 3222 | |
| 3223 | if (buf[0] == '#') |
| 3224 | continue; |
| 3225 | pos = buf; |
| 3226 | while (*pos != '\0') { |
| 3227 | if (*pos == '\n') { |
| 3228 | *pos = '\0'; |
| 3229 | break; |
| 3230 | } |
| 3231 | pos++; |
| 3232 | } |
| 3233 | if (buf[0] == '\0') |
| 3234 | continue; |
| 3235 | |
| 3236 | pos = os_strchr(buf, '='); |
| 3237 | if (pos == NULL) { |
| 3238 | wpa_printf(MSG_ERROR, "Line %d: invalid line '%s'", |
| 3239 | line, buf); |
| 3240 | errors++; |
| 3241 | continue; |
| 3242 | } |
| 3243 | *pos = '\0'; |
| 3244 | pos++; |
| 3245 | errors += hostapd_config_fill(conf, bss, buf, pos, line); |
| 3246 | } |
| 3247 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3248 | fclose(f); |
| 3249 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3250 | for (i = 0; i < conf->num_bss; i++) |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3251 | hostapd_set_security_params(conf->bss[i]); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3252 | |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 3253 | if (hostapd_config_check(conf, 1)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3254 | errors++; |
| 3255 | |
| 3256 | #ifndef WPA_IGNORE_CONFIG_ERRORS |
| 3257 | if (errors) { |
| 3258 | wpa_printf(MSG_ERROR, "%d errors found in configuration file " |
| 3259 | "'%s'", errors, fname); |
| 3260 | hostapd_config_free(conf); |
| 3261 | conf = NULL; |
| 3262 | } |
| 3263 | #endif /* WPA_IGNORE_CONFIG_ERRORS */ |
| 3264 | |
| 3265 | return conf; |
| 3266 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3267 | |
| 3268 | |
| 3269 | int hostapd_set_iface(struct hostapd_config *conf, |
| 3270 | struct hostapd_bss_config *bss, char *field, char *value) |
| 3271 | { |
| 3272 | int errors; |
| 3273 | size_t i; |
| 3274 | |
| 3275 | errors = hostapd_config_fill(conf, bss, field, value, 0); |
| 3276 | if (errors) { |
| 3277 | wpa_printf(MSG_INFO, "Failed to set configuration field '%s' " |
| 3278 | "to value '%s'", field, value); |
| 3279 | return -1; |
| 3280 | } |
| 3281 | |
| 3282 | for (i = 0; i < conf->num_bss; i++) |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3283 | hostapd_set_security_params(conf->bss[i]); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3284 | |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 3285 | if (hostapd_config_check(conf, 0)) { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3286 | wpa_printf(MSG_ERROR, "Configuration check failed"); |
| 3287 | return -1; |
| 3288 | } |
| 3289 | |
| 3290 | return 0; |
| 3291 | } |