main.c 17 KB

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