1 /* 2 * hostapd / main() 3 * Copyright (c) 2002-2015, Jouni Malinen <j@w1.fi> 4 * 5 * This software may be distributed under the terms of the BSD license. 6 * See README for more details. 7 */ 8 9 #include "utils/includes.h" 10 #ifndef CONFIG_NATIVE_WINDOWS 11 #include <syslog.h> 12 #include <grp.h> 13 #endif /* CONFIG_NATIVE_WINDOWS */ 14 15 #include "utils/common.h" 16 #include "utils/eloop.h" 17 #include "utils/uuid.h" 18 #include "crypto/random.h" 19 #include "crypto/tls.h" 20 #include "common/version.h" 21 #include "drivers/driver.h" 22 #include "eap_server/eap.h" 23 #include "eap_server/tncs.h" 24 #include "ap/hostapd.h" 25 #include "ap/ap_config.h" 26 #include "ap/ap_drv_ops.h" 27 #include "config_file.h" 28 #include "eap_register.h" 29 #include "ctrl_iface.h" 30 31 32 struct hapd_global { 33 void **drv_priv; 34 size_t drv_count; 35 }; 36 37 static struct hapd_global global; 38 39 40 #ifndef CONFIG_NO_HOSTAPD_LOGGER 41 static void hostapd_logger_cb(void *ctx, const u8 *addr, unsigned int module, 42 int level, const char *txt, size_t len) 43 { 44 struct hostapd_data *hapd = ctx; 45 char *format, *module_str; 46 int maxlen; 47 int conf_syslog_level, conf_stdout_level; 48 unsigned int conf_syslog, conf_stdout; 49 50 maxlen = len + 100; 51 format = os_malloc(maxlen); 52 if (!format) 53 return; 54 55 if (hapd && hapd->conf) { 56 conf_syslog_level = hapd->conf->logger_syslog_level; 57 conf_stdout_level = hapd->conf->logger_stdout_level; 58 conf_syslog = hapd->conf->logger_syslog; 59 conf_stdout = hapd->conf->logger_stdout; 60 } else { 61 conf_syslog_level = conf_stdout_level = 0; 62 conf_syslog = conf_stdout = (unsigned int) -1; 63 } 64 65 switch (module) { 66 case HOSTAPD_MODULE_IEEE80211: 67 module_str = "IEEE 802.11"; 68 break; 69 case HOSTAPD_MODULE_IEEE8021X: 70 module_str = "IEEE 802.1X"; 71 break; 72 case HOSTAPD_MODULE_RADIUS: 73 module_str = "RADIUS"; 74 break; 75 case HOSTAPD_MODULE_WPA: 76 module_str = "WPA"; 77 break; 78 case HOSTAPD_MODULE_DRIVER: 79 module_str = "DRIVER"; 80 break; 81 case HOSTAPD_MODULE_IAPP: 82 module_str = "IAPP"; 83 break; 84 case HOSTAPD_MODULE_MLME: 85 module_str = "MLME"; 86 break; 87 default: 88 module_str = NULL; 89 break; 90 } 91 92 if (hapd && hapd->conf && addr) 93 os_snprintf(format, maxlen, "%s: STA " MACSTR "%s%s: %s", 94 hapd->conf->iface, MAC2STR(addr), 95 module_str ? " " : "", module_str ? module_str : "", 96 txt); 97 else if (hapd && hapd->conf) 98 os_snprintf(format, maxlen, "%s:%s%s %s", 99 hapd->conf->iface, module_str ? " " : "", 100 module_str ? module_str : "", txt); 101 else if (addr) 102 os_snprintf(format, maxlen, "STA " MACSTR "%s%s: %s", 103 MAC2STR(addr), module_str ? " " : "", 104 module_str ? module_str : "", txt); 105 else 106 os_snprintf(format, maxlen, "%s%s%s", 107 module_str ? module_str : "", 108 module_str ? ": " : "", txt); 109 110 if ((conf_stdout & module) && level >= conf_stdout_level) { 111 wpa_debug_print_timestamp(); 112 wpa_printf(MSG_INFO, "%s", format); 113 } 114 115 #ifndef CONFIG_NATIVE_WINDOWS 116 if ((conf_syslog & module) && level >= conf_syslog_level) { 117 int priority; 118 switch (level) { 119 case HOSTAPD_LEVEL_DEBUG_VERBOSE: 120 case HOSTAPD_LEVEL_DEBUG: 121 priority = LOG_DEBUG; 122 break; 123 case HOSTAPD_LEVEL_INFO: 124 priority = LOG_INFO; 125 break; 126 case HOSTAPD_LEVEL_NOTICE: 127 priority = LOG_NOTICE; 128 break; 129 case HOSTAPD_LEVEL_WARNING: 130 priority = LOG_WARNING; 131 break; 132 default: 133 priority = LOG_INFO; 134 break; 135 } 136 syslog(priority, "%s", format); 137 } 138 #endif /* CONFIG_NATIVE_WINDOWS */ 139 140 os_free(format); 141 } 142 #endif /* CONFIG_NO_HOSTAPD_LOGGER */ 143 144 145 /** 146 * hostapd_driver_init - Preparate driver interface 147 */ 148 static int hostapd_driver_init(struct hostapd_iface *iface) 149 { 150 struct wpa_init_params params; 151 size_t i; 152 struct hostapd_data *hapd = iface->bss[0]; 153 struct hostapd_bss_config *conf = hapd->conf; 154 u8 *b = conf->bssid; 155 struct wpa_driver_capa capa; 156 157 if (hapd->driver == NULL || hapd->driver->hapd_init == NULL) { 158 wpa_printf(MSG_ERROR, "No hostapd driver wrapper available"); 159 return -1; 160 } 161 162 /* Initialize the driver interface */ 163 if (!(b[0] | b[1] | b[2] | b[3] | b[4] | b[5])) 164 b = NULL; 165 166 os_memset(¶ms, 0, sizeof(params)); 167 for (i = 0; wpa_drivers[i]; i++) { 168 if (wpa_drivers[i] != hapd->driver) 169 continue; 170 171 if (global.drv_priv[i] == NULL && 172 wpa_drivers[i]->global_init) { 173 global.drv_priv[i] = 174 wpa_drivers[i]->global_init(iface->interfaces); 175 if (global.drv_priv[i] == NULL) { 176 wpa_printf(MSG_ERROR, "Failed to initialize " 177 "driver '%s'", 178 wpa_drivers[i]->name); 179 return -1; 180 } 181 } 182 183 params.global_priv = global.drv_priv[i]; 184 break; 185 } 186 params.bssid = b; 187 params.ifname = hapd->conf->iface; 188 params.driver_params = hapd->iconf->driver_params; 189 params.use_pae_group_addr = hapd->conf->use_pae_group_addr; 190 191 params.num_bridge = hapd->iface->num_bss; 192 params.bridge = os_calloc(hapd->iface->num_bss, sizeof(char *)); 193 if (params.bridge == NULL) 194 return -1; 195 for (i = 0; i < hapd->iface->num_bss; i++) { 196 struct hostapd_data *bss = hapd->iface->bss[i]; 197 if (bss->conf->bridge[0]) 198 params.bridge[i] = bss->conf->bridge; 199 } 200 201 params.own_addr = hapd->own_addr; 202 203 hapd->drv_priv = hapd->driver->hapd_init(hapd, ¶ms); 204 os_free(params.bridge); 205 if (hapd->drv_priv == NULL) { 206 wpa_printf(MSG_ERROR, "%s driver initialization failed.", 207 hapd->driver->name); 208 hapd->driver = NULL; 209 return -1; 210 } 211 212 if (hapd->driver->get_capa && 213 hapd->driver->get_capa(hapd->drv_priv, &capa) == 0) { 214 struct wowlan_triggers *triggs; 215 216 iface->drv_flags = capa.flags; 217 iface->smps_modes = capa.smps_modes; 218 iface->probe_resp_offloads = capa.probe_resp_offloads; 219 iface->extended_capa = capa.extended_capa; 220 iface->extended_capa_mask = capa.extended_capa_mask; 221 iface->extended_capa_len = capa.extended_capa_len; 222 iface->drv_max_acl_mac_addrs = capa.max_acl_mac_addrs; 223 224 triggs = wpa_get_wowlan_triggers(conf->wowlan_triggers, &capa); 225 if (triggs && hapd->driver->set_wowlan) { 226 if (hapd->driver->set_wowlan(hapd->drv_priv, triggs)) 227 wpa_printf(MSG_ERROR, "set_wowlan failed"); 228 } 229 os_free(triggs); 230 } 231 232 return 0; 233 } 234 235 236 /** 237 * hostapd_interface_init - Read configuration file and init BSS data 238 * 239 * This function is used to parse configuration file for a full interface (one 240 * or more BSSes sharing the same radio) and allocate memory for the BSS 241 * interfaces. No actiual driver operations are started. 242 */ 243 static struct hostapd_iface * 244 hostapd_interface_init(struct hapd_interfaces *interfaces, 245 const char *config_fname, int debug) 246 { 247 struct hostapd_iface *iface; 248 int k; 249 250 wpa_printf(MSG_ERROR, "Configuration file: %s", config_fname); 251 iface = hostapd_init(interfaces, config_fname); 252 if (!iface) 253 return NULL; 254 iface->interfaces = interfaces; 255 256 for (k = 0; k < debug; k++) { 257 if (iface->bss[0]->conf->logger_stdout_level > 0) 258 iface->bss[0]->conf->logger_stdout_level--; 259 } 260 261 if (iface->conf->bss[0]->iface[0] == '\0' && 262 !hostapd_drv_none(iface->bss[0])) { 263 wpa_printf(MSG_ERROR, "Interface name not specified in %s", 264 config_fname); 265 hostapd_interface_deinit_free(iface); 266 return NULL; 267 } 268 269 return iface; 270 } 271 272 273 /** 274 * handle_term - SIGINT and SIGTERM handler to terminate hostapd process 275 */ 276 static void handle_term(int sig, void *signal_ctx) 277 { 278 wpa_printf(MSG_DEBUG, "Signal %d received - terminating", sig); 279 eloop_terminate(); 280 } 281 282 283 #ifndef CONFIG_NATIVE_WINDOWS 284 285 static int handle_reload_iface(struct hostapd_iface *iface, void *ctx) 286 { 287 if (hostapd_reload_config(iface) < 0) { 288 wpa_printf(MSG_WARNING, "Failed to read new configuration " 289 "file - continuing with old."); 290 } 291 return 0; 292 } 293 294 295 /** 296 * handle_reload - SIGHUP handler to reload configuration 297 */ 298 static void handle_reload(int sig, void *signal_ctx) 299 { 300 struct hapd_interfaces *interfaces = signal_ctx; 301 wpa_printf(MSG_DEBUG, "Signal %d received - reloading configuration", 302 sig); 303 hostapd_for_each_interface(interfaces, handle_reload_iface, NULL); 304 } 305 306 307 static void handle_dump_state(int sig, void *signal_ctx) 308 { 309 /* Not used anymore - ignore signal */ 310 } 311 #endif /* CONFIG_NATIVE_WINDOWS */ 312 313 314 static int hostapd_global_init(struct hapd_interfaces *interfaces, 315 const char *entropy_file) 316 { 317 int i; 318 319 os_memset(&global, 0, sizeof(global)); 320 321 hostapd_logger_register_cb(hostapd_logger_cb); 322 323 if (eap_server_register_methods()) { 324 wpa_printf(MSG_ERROR, "Failed to register EAP methods"); 325 return -1; 326 } 327 328 if (eloop_init()) { 329 wpa_printf(MSG_ERROR, "Failed to initialize event loop"); 330 return -1; 331 } 332 333 random_init(entropy_file); 334 335 #ifndef CONFIG_NATIVE_WINDOWS 336 eloop_register_signal(SIGHUP, handle_reload, interfaces); 337 eloop_register_signal(SIGUSR1, handle_dump_state, interfaces); 338 #endif /* CONFIG_NATIVE_WINDOWS */ 339 eloop_register_signal_terminate(handle_term, interfaces); 340 341 #ifndef CONFIG_NATIVE_WINDOWS 342 openlog("hostapd", 0, LOG_DAEMON); 343 #endif /* CONFIG_NATIVE_WINDOWS */ 344 345 for (i = 0; wpa_drivers[i]; i++) 346 global.drv_count++; 347 if (global.drv_count == 0) { 348 wpa_printf(MSG_ERROR, "No drivers enabled"); 349 return -1; 350 } 351 global.drv_priv = os_calloc(global.drv_count, sizeof(void *)); 352 if (global.drv_priv == NULL) 353 return -1; 354 355 return 0; 356 } 357 358 359 static void hostapd_global_deinit(const char *pid_file) 360 { 361 int i; 362 363 for (i = 0; wpa_drivers[i] && global.drv_priv; i++) { 364 if (!global.drv_priv[i]) 365 continue; 366 wpa_drivers[i]->global_deinit(global.drv_priv[i]); 367 } 368 os_free(global.drv_priv); 369 global.drv_priv = NULL; 370 371 #ifdef EAP_SERVER_TNC 372 tncs_global_deinit(); 373 #endif /* EAP_SERVER_TNC */ 374 375 random_deinit(); 376 377 eloop_destroy(); 378 379 #ifndef CONFIG_NATIVE_WINDOWS 380 closelog(); 381 #endif /* CONFIG_NATIVE_WINDOWS */ 382 383 eap_server_unregister_methods(); 384 385 os_daemonize_terminate(pid_file); 386 } 387 388 389 static int hostapd_global_run(struct hapd_interfaces *ifaces, int daemonize, 390 const char *pid_file) 391 { 392 #ifdef EAP_SERVER_TNC 393 int tnc = 0; 394 size_t i, k; 395 396 for (i = 0; !tnc && i < ifaces->count; i++) { 397 for (k = 0; k < ifaces->iface[i]->num_bss; k++) { 398 if (ifaces->iface[i]->bss[0]->conf->tnc) { 399 tnc++; 400 break; 401 } 402 } 403 } 404 405 if (tnc && tncs_global_init() < 0) { 406 wpa_printf(MSG_ERROR, "Failed to initialize TNCS"); 407 return -1; 408 } 409 #endif /* EAP_SERVER_TNC */ 410 411 if (daemonize) { 412 if (os_daemonize(pid_file)) { 413 wpa_printf(MSG_ERROR, "daemon: %s", strerror(errno)); 414 return -1; 415 } 416 if (eloop_sock_requeue()) { 417 wpa_printf(MSG_ERROR, "eloop_sock_requeue: %s", 418 strerror(errno)); 419 return -1; 420 } 421 } 422 423 eloop_run(); 424 425 return 0; 426 } 427 428 429 static void show_version(void) 430 { 431 fprintf(stderr, 432 "hostapd v" VERSION_STR "\n" 433 "User space daemon for IEEE 802.11 AP management,\n" 434 "IEEE 802.1X/WPA/WPA2/EAP/RADIUS Authenticator\n" 435 "Copyright (c) 2002-2015, Jouni Malinen <j@w1.fi> " 436 "and contributors\n"); 437 } 438 439 440 static void usage(void) 441 { 442 show_version(); 443 fprintf(stderr, 444 "\n" 445 "usage: hostapd [-hdBKtv] [-P <PID file>] [-e <entropy file>] " 446 "\\\n" 447 " [-g <global ctrl_iface>] [-G <group>] \\\n" 448 " <configuration file(s)>\n" 449 "\n" 450 "options:\n" 451 " -h show this usage\n" 452 " -d show more debug messages (-dd for even more)\n" 453 " -B run daemon in the background\n" 454 " -e entropy file\n" 455 " -g global control interface path\n" 456 " -G group for control interfaces\n" 457 " -P PID file\n" 458 " -K include key data in debug messages\n" 459 #ifdef CONFIG_DEBUG_FILE 460 " -f log output to debug file instead of stdout\n" 461 #endif /* CONFIG_DEBUG_FILE */ 462 #ifdef CONFIG_DEBUG_LINUX_TRACING 463 " -T = record to Linux tracing in addition to logging\n" 464 " (records all messages regardless of debug verbosity)\n" 465 #endif /* CONFIG_DEBUG_LINUX_TRACING */ 466 " -t include timestamps in some debug messages\n" 467 " -v show hostapd version\n"); 468 469 exit(1); 470 } 471 472 473 static const char * hostapd_msg_ifname_cb(void *ctx) 474 { 475 struct hostapd_data *hapd = ctx; 476 if (hapd && hapd->iconf && hapd->iconf->bss && 477 hapd->iconf->num_bss > 0 && hapd->iconf->bss[0]) 478 return hapd->iconf->bss[0]->iface; 479 return NULL; 480 } 481 482 483 static int hostapd_get_global_ctrl_iface(struct hapd_interfaces *interfaces, 484 const char *path) 485 { 486 char *pos; 487 os_free(interfaces->global_iface_path); 488 interfaces->global_iface_path = os_strdup(path); 489 if (interfaces->global_iface_path == NULL) 490 return -1; 491 pos = os_strrchr(interfaces->global_iface_path, '/'); 492 if (pos == NULL) { 493 wpa_printf(MSG_ERROR, "No '/' in the global control interface " 494 "file"); 495 os_free(interfaces->global_iface_path); 496 interfaces->global_iface_path = NULL; 497 return -1; 498 } 499 500 *pos = '\0'; 501 interfaces->global_iface_name = pos + 1; 502 503 return 0; 504 } 505 506 507 static int hostapd_get_ctrl_iface_group(struct hapd_interfaces *interfaces, 508 const char *group) 509 { 510 #ifndef CONFIG_NATIVE_WINDOWS 511 struct group *grp; 512 grp = getgrnam(group); 513 if (grp == NULL) { 514 wpa_printf(MSG_ERROR, "Unknown group '%s'", group); 515 return -1; 516 } 517 interfaces->ctrl_iface_group = grp->gr_gid; 518 #endif /* CONFIG_NATIVE_WINDOWS */ 519 return 0; 520 } 521 522 523 #ifdef CONFIG_WPS 524 static int gen_uuid(const char *txt_addr) 525 { 526 u8 addr[ETH_ALEN]; 527 u8 uuid[UUID_LEN]; 528 char buf[100]; 529 530 if (hwaddr_aton(txt_addr, addr) < 0) 531 return -1; 532 533 uuid_gen_mac_addr(addr, uuid); 534 if (uuid_bin2str(uuid, buf, sizeof(buf)) < 0) 535 return -1; 536 537 printf("%s\n", buf); 538 539 return 0; 540 } 541 #endif /* CONFIG_WPS */ 542 543 544 int main(int argc, char *argv[]) 545 { 546 struct hapd_interfaces interfaces; 547 int ret = 1; 548 size_t i, j; 549 int c, debug = 0, daemonize = 0; 550 char *pid_file = NULL; 551 const char *log_file = NULL; 552 const char *entropy_file = NULL; 553 char **bss_config = NULL, **tmp_bss; 554 size_t num_bss_configs = 0; 555 #ifdef CONFIG_DEBUG_LINUX_TRACING 556 int enable_trace_dbg = 0; 557 #endif /* CONFIG_DEBUG_LINUX_TRACING */ 558 559 if (os_program_init()) 560 return -1; 561 562 os_memset(&interfaces, 0, sizeof(interfaces)); 563 interfaces.reload_config = hostapd_reload_config; 564 interfaces.config_read_cb = hostapd_config_read; 565 interfaces.for_each_interface = hostapd_for_each_interface; 566 interfaces.ctrl_iface_init = hostapd_ctrl_iface_init; 567 interfaces.ctrl_iface_deinit = hostapd_ctrl_iface_deinit; 568 interfaces.driver_init = hostapd_driver_init; 569 interfaces.global_iface_path = NULL; 570 interfaces.global_iface_name = NULL; 571 interfaces.global_ctrl_sock = -1; 572 573 for (;;) { 574 c = getopt(argc, argv, "b:Bde:f:hKP:Ttu:vg:G:"); 575 if (c < 0) 576 break; 577 switch (c) { 578 case 'h': 579 usage(); 580 break; 581 case 'd': 582 debug++; 583 if (wpa_debug_level > 0) 584 wpa_debug_level--; 585 break; 586 case 'B': 587 daemonize++; 588 break; 589 case 'e': 590 entropy_file = optarg; 591 break; 592 case 'f': 593 log_file = optarg; 594 break; 595 case 'K': 596 wpa_debug_show_keys++; 597 break; 598 case 'P': 599 os_free(pid_file); 600 pid_file = os_rel2abs_path(optarg); 601 break; 602 case 't': 603 wpa_debug_timestamp++; 604 break; 605 #ifdef CONFIG_DEBUG_LINUX_TRACING 606 case 'T': 607 enable_trace_dbg = 1; 608 break; 609 #endif /* CONFIG_DEBUG_LINUX_TRACING */ 610 case 'v': 611 show_version(); 612 exit(1); 613 break; 614 case 'g': 615 if (hostapd_get_global_ctrl_iface(&interfaces, optarg)) 616 return -1; 617 break; 618 case 'G': 619 if (hostapd_get_ctrl_iface_group(&interfaces, optarg)) 620 return -1; 621 break; 622 case 'b': 623 tmp_bss = os_realloc_array(bss_config, 624 num_bss_configs + 1, 625 sizeof(char *)); 626 if (tmp_bss == NULL) 627 goto out; 628 bss_config = tmp_bss; 629 bss_config[num_bss_configs++] = optarg; 630 break; 631 #ifdef CONFIG_WPS 632 case 'u': 633 return gen_uuid(optarg); 634 #endif /* CONFIG_WPS */ 635 default: 636 usage(); 637 break; 638 } 639 } 640 641 if (optind == argc && interfaces.global_iface_path == NULL && 642 num_bss_configs == 0) 643 usage(); 644 645 wpa_msg_register_ifname_cb(hostapd_msg_ifname_cb); 646 647 if (log_file) 648 wpa_debug_open_file(log_file); 649 else 650 wpa_debug_setup_stdout(); 651 #ifdef CONFIG_DEBUG_LINUX_TRACING 652 if (enable_trace_dbg) { 653 int tret = wpa_debug_open_linux_tracing(); 654 if (tret) { 655 wpa_printf(MSG_ERROR, "Failed to enable trace logging"); 656 return -1; 657 } 658 } 659 #endif /* CONFIG_DEBUG_LINUX_TRACING */ 660 661 interfaces.count = argc - optind; 662 if (interfaces.count || num_bss_configs) { 663 interfaces.iface = os_calloc(interfaces.count + num_bss_configs, 664 sizeof(struct hostapd_iface *)); 665 if (interfaces.iface == NULL) { 666 wpa_printf(MSG_ERROR, "malloc failed"); 667 return -1; 668 } 669 } 670 671 if (hostapd_global_init(&interfaces, entropy_file)) { 672 wpa_printf(MSG_ERROR, "Failed to initilize global context"); 673 return -1; 674 } 675 676 /* Allocate and parse configuration for full interface files */ 677 for (i = 0; i < interfaces.count; i++) { 678 interfaces.iface[i] = hostapd_interface_init(&interfaces, 679 argv[optind + i], 680 debug); 681 if (!interfaces.iface[i]) { 682 wpa_printf(MSG_ERROR, "Failed to initialize interface"); 683 goto out; 684 } 685 } 686 687 /* Allocate and parse configuration for per-BSS files */ 688 for (i = 0; i < num_bss_configs; i++) { 689 struct hostapd_iface *iface; 690 char *fname; 691 692 wpa_printf(MSG_INFO, "BSS config: %s", bss_config[i]); 693 fname = os_strchr(bss_config[i], ':'); 694 if (fname == NULL) { 695 wpa_printf(MSG_ERROR, 696 "Invalid BSS config identifier '%s'", 697 bss_config[i]); 698 goto out; 699 } 700 *fname++ = '\0'; 701 iface = hostapd_interface_init_bss(&interfaces, bss_config[i], 702 fname, debug); 703 if (iface == NULL) 704 goto out; 705 for (j = 0; j < interfaces.count; j++) { 706 if (interfaces.iface[j] == iface) 707 break; 708 } 709 if (j == interfaces.count) { 710 struct hostapd_iface **tmp; 711 tmp = os_realloc_array(interfaces.iface, 712 interfaces.count + 1, 713 sizeof(struct hostapd_iface *)); 714 if (tmp == NULL) { 715 hostapd_interface_deinit_free(iface); 716 goto out; 717 } 718 interfaces.iface = tmp; 719 interfaces.iface[interfaces.count++] = iface; 720 } 721 } 722 723 /* 724 * Enable configured interfaces. Depending on channel configuration, 725 * this may complete full initialization before returning or use a 726 * callback mechanism to complete setup in case of operations like HT 727 * co-ex scans, ACS, or DFS are needed to determine channel parameters. 728 * In such case, the interface will be enabled from eloop context within 729 * hostapd_global_run(). 730 */ 731 interfaces.terminate_on_error = interfaces.count; 732 for (i = 0; i < interfaces.count; i++) { 733 if (hostapd_driver_init(interfaces.iface[i]) || 734 hostapd_setup_interface(interfaces.iface[i])) 735 goto out; 736 } 737 738 hostapd_global_ctrl_iface_init(&interfaces); 739 740 if (hostapd_global_run(&interfaces, daemonize, pid_file)) { 741 wpa_printf(MSG_ERROR, "Failed to start eloop"); 742 goto out; 743 } 744 745 ret = 0; 746 747 out: 748 hostapd_global_ctrl_iface_deinit(&interfaces); 749 /* Deinitialize all interfaces */ 750 for (i = 0; i < interfaces.count; i++) { 751 if (!interfaces.iface[i]) 752 continue; 753 interfaces.iface[i]->driver_ap_teardown = 754 !!(interfaces.iface[i]->drv_flags & 755 WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT); 756 hostapd_interface_deinit_free(interfaces.iface[i]); 757 } 758 os_free(interfaces.iface); 759 760 hostapd_global_deinit(pid_file); 761 os_free(pid_file); 762 763 if (log_file) 764 wpa_debug_close_file(); 765 wpa_debug_close_linux_tracing(); 766 767 os_free(bss_config); 768 769 os_program_deinit(); 770 771 return ret; 772 } 773