main.c 18 KB

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