Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * hostapd / main() |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 3 | * Copyright (c) 2002-2016, 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 <syslog.h> |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 12 | #include <grp.h> |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 13 | #endif /* CONFIG_NATIVE_WINDOWS */ |
| 14 | |
| 15 | #include "utils/common.h" |
| 16 | #include "utils/eloop.h" |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 17 | #include "utils/uuid.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 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" |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 26 | #include "ap/ap_drv_ops.h" |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 27 | #include "fst/fst.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 28 | #include "config_file.h" |
| 29 | #include "eap_register.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 30 | #include "ctrl_iface.h" |
| 31 | |
| 32 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 33 | struct hapd_global { |
| 34 | void **drv_priv; |
| 35 | size_t drv_count; |
| 36 | }; |
| 37 | |
| 38 | static struct hapd_global global; |
| 39 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 40 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 41 | #ifndef CONFIG_NO_HOSTAPD_LOGGER |
| 42 | static void hostapd_logger_cb(void *ctx, const u8 *addr, unsigned int module, |
| 43 | int level, const char *txt, size_t len) |
| 44 | { |
| 45 | struct hostapd_data *hapd = ctx; |
| 46 | char *format, *module_str; |
| 47 | int maxlen; |
| 48 | int conf_syslog_level, conf_stdout_level; |
| 49 | unsigned int conf_syslog, conf_stdout; |
| 50 | |
| 51 | maxlen = len + 100; |
| 52 | format = os_malloc(maxlen); |
| 53 | if (!format) |
| 54 | return; |
| 55 | |
| 56 | if (hapd && hapd->conf) { |
| 57 | conf_syslog_level = hapd->conf->logger_syslog_level; |
| 58 | conf_stdout_level = hapd->conf->logger_stdout_level; |
| 59 | conf_syslog = hapd->conf->logger_syslog; |
| 60 | conf_stdout = hapd->conf->logger_stdout; |
| 61 | } else { |
| 62 | conf_syslog_level = conf_stdout_level = 0; |
| 63 | conf_syslog = conf_stdout = (unsigned int) -1; |
| 64 | } |
| 65 | |
| 66 | switch (module) { |
| 67 | case HOSTAPD_MODULE_IEEE80211: |
| 68 | module_str = "IEEE 802.11"; |
| 69 | break; |
| 70 | case HOSTAPD_MODULE_IEEE8021X: |
| 71 | module_str = "IEEE 802.1X"; |
| 72 | break; |
| 73 | case HOSTAPD_MODULE_RADIUS: |
| 74 | module_str = "RADIUS"; |
| 75 | break; |
| 76 | case HOSTAPD_MODULE_WPA: |
| 77 | module_str = "WPA"; |
| 78 | break; |
| 79 | case HOSTAPD_MODULE_DRIVER: |
| 80 | module_str = "DRIVER"; |
| 81 | break; |
| 82 | case HOSTAPD_MODULE_IAPP: |
| 83 | module_str = "IAPP"; |
| 84 | break; |
| 85 | case HOSTAPD_MODULE_MLME: |
| 86 | module_str = "MLME"; |
| 87 | break; |
| 88 | default: |
| 89 | module_str = NULL; |
| 90 | break; |
| 91 | } |
| 92 | |
| 93 | if (hapd && hapd->conf && addr) |
| 94 | os_snprintf(format, maxlen, "%s: STA " MACSTR "%s%s: %s", |
| 95 | hapd->conf->iface, MAC2STR(addr), |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 96 | module_str ? " " : "", module_str ? module_str : "", |
| 97 | txt); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 98 | else if (hapd && hapd->conf) |
| 99 | os_snprintf(format, maxlen, "%s:%s%s %s", |
| 100 | hapd->conf->iface, module_str ? " " : "", |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 101 | module_str ? module_str : "", txt); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 102 | else if (addr) |
| 103 | os_snprintf(format, maxlen, "STA " MACSTR "%s%s: %s", |
| 104 | MAC2STR(addr), module_str ? " " : "", |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 105 | module_str ? module_str : "", txt); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 106 | else |
| 107 | os_snprintf(format, maxlen, "%s%s%s", |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 108 | module_str ? module_str : "", |
| 109 | module_str ? ": " : "", txt); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 110 | |
| 111 | if ((conf_stdout & module) && level >= conf_stdout_level) { |
| 112 | wpa_debug_print_timestamp(); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 113 | wpa_printf(MSG_INFO, "%s", format); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | #ifndef CONFIG_NATIVE_WINDOWS |
| 117 | if ((conf_syslog & module) && level >= conf_syslog_level) { |
| 118 | int priority; |
| 119 | switch (level) { |
| 120 | case HOSTAPD_LEVEL_DEBUG_VERBOSE: |
| 121 | case HOSTAPD_LEVEL_DEBUG: |
| 122 | priority = LOG_DEBUG; |
| 123 | break; |
| 124 | case HOSTAPD_LEVEL_INFO: |
| 125 | priority = LOG_INFO; |
| 126 | break; |
| 127 | case HOSTAPD_LEVEL_NOTICE: |
| 128 | priority = LOG_NOTICE; |
| 129 | break; |
| 130 | case HOSTAPD_LEVEL_WARNING: |
| 131 | priority = LOG_WARNING; |
| 132 | break; |
| 133 | default: |
| 134 | priority = LOG_INFO; |
| 135 | break; |
| 136 | } |
| 137 | syslog(priority, "%s", format); |
| 138 | } |
| 139 | #endif /* CONFIG_NATIVE_WINDOWS */ |
| 140 | |
| 141 | os_free(format); |
| 142 | } |
| 143 | #endif /* CONFIG_NO_HOSTAPD_LOGGER */ |
| 144 | |
| 145 | |
| 146 | /** |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 147 | * hostapd_driver_init - Preparate driver interface |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 148 | */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 149 | static int hostapd_driver_init(struct hostapd_iface *iface) |
| 150 | { |
| 151 | struct wpa_init_params params; |
| 152 | size_t i; |
| 153 | struct hostapd_data *hapd = iface->bss[0]; |
| 154 | struct hostapd_bss_config *conf = hapd->conf; |
| 155 | u8 *b = conf->bssid; |
| 156 | struct wpa_driver_capa capa; |
| 157 | |
| 158 | if (hapd->driver == NULL || hapd->driver->hapd_init == NULL) { |
| 159 | wpa_printf(MSG_ERROR, "No hostapd driver wrapper available"); |
| 160 | return -1; |
| 161 | } |
| 162 | |
| 163 | /* Initialize the driver interface */ |
| 164 | if (!(b[0] | b[1] | b[2] | b[3] | b[4] | b[5])) |
| 165 | b = NULL; |
| 166 | |
| 167 | os_memset(¶ms, 0, sizeof(params)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 168 | for (i = 0; wpa_drivers[i]; i++) { |
| 169 | if (wpa_drivers[i] != hapd->driver) |
| 170 | continue; |
| 171 | |
| 172 | if (global.drv_priv[i] == NULL && |
| 173 | wpa_drivers[i]->global_init) { |
| 174 | global.drv_priv[i] = wpa_drivers[i]->global_init(); |
| 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 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 186 | params.bssid = b; |
| 187 | params.ifname = hapd->conf->iface; |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 188 | params.driver_params = hapd->iconf->driver_params; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 189 | params.use_pae_group_addr = hapd->conf->use_pae_group_addr; |
| 190 | |
| 191 | params.num_bridge = hapd->iface->num_bss; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 192 | params.bridge = os_calloc(hapd->iface->num_bss, sizeof(char *)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 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 && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 213 | hapd->driver->get_capa(hapd->drv_priv, &capa) == 0) { |
Dmitry Shmidt | 0207e23 | 2014-09-03 14:58:37 -0700 | [diff] [blame] | 214 | struct wowlan_triggers *triggs; |
| 215 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 216 | iface->drv_flags = capa.flags; |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 217 | iface->smps_modes = capa.smps_modes; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 218 | iface->probe_resp_offloads = capa.probe_resp_offloads; |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 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; |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 222 | iface->drv_max_acl_mac_addrs = capa.max_acl_mac_addrs; |
Dmitry Shmidt | 0207e23 | 2014-09-03 14:58:37 -0700 | [diff] [blame] | 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); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 230 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 231 | |
| 232 | return 0; |
| 233 | } |
| 234 | |
| 235 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 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 | */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 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); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 251 | iface = hostapd_init(interfaces, config_fname); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 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 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 261 | if (iface->conf->bss[0]->iface[0] == '\0' && |
Dmitry Shmidt | 4b06059 | 2013-04-29 16:42:49 -0700 | [diff] [blame] | 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 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 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 | { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 309 | /* Not used anymore - ignore signal */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 310 | } |
| 311 | #endif /* CONFIG_NATIVE_WINDOWS */ |
| 312 | |
| 313 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 314 | static int hostapd_global_init(struct hapd_interfaces *interfaces, |
| 315 | const char *entropy_file) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 316 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 317 | int i; |
| 318 | |
| 319 | os_memset(&global, 0, sizeof(global)); |
| 320 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 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 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 333 | random_init(entropy_file); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 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 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 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 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 351 | global.drv_priv = os_calloc(global.drv_count, sizeof(void *)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 352 | if (global.drv_priv == NULL) |
| 353 | return -1; |
| 354 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 355 | return 0; |
| 356 | } |
| 357 | |
| 358 | |
| 359 | static void hostapd_global_deinit(const char *pid_file) |
| 360 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 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 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 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 | |
Dmitry Shmidt | b97e428 | 2016-02-08 10:16:07 -0800 | [diff] [blame^] | 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 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 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" |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 435 | "Copyright (c) 2002-2016, Jouni Malinen <j@w1.fi> " |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 436 | "and contributors\n"); |
| 437 | } |
| 438 | |
| 439 | |
| 440 | static void usage(void) |
| 441 | { |
| 442 | show_version(); |
| 443 | fprintf(stderr, |
| 444 | "\n" |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 445 | "usage: hostapd [-hdBKtv] [-P <PID file>] [-e <entropy file>] " |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 446 | "\\\n" |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 447 | " [-g <global ctrl_iface>] [-G <group>] \\\n" |
| 448 | " <configuration file(s)>\n" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 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" |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 454 | " -e entropy file\n" |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 455 | " -g global control interface path\n" |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 456 | " -G group for control interfaces\n" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 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 */ |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 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 */ |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 466 | " -S start all the interfaces synchronously\n" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 467 | " -t include timestamps in some debug messages\n" |
| 468 | " -v show hostapd version\n"); |
| 469 | |
| 470 | exit(1); |
| 471 | } |
| 472 | |
| 473 | |
| 474 | static const char * hostapd_msg_ifname_cb(void *ctx) |
| 475 | { |
| 476 | struct hostapd_data *hapd = ctx; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 477 | if (hapd && hapd->iconf && hapd->iconf->bss && |
| 478 | hapd->iconf->num_bss > 0 && hapd->iconf->bss[0]) |
| 479 | return hapd->iconf->bss[0]->iface; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 480 | return NULL; |
| 481 | } |
| 482 | |
| 483 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 484 | static int hostapd_get_global_ctrl_iface(struct hapd_interfaces *interfaces, |
| 485 | const char *path) |
| 486 | { |
| 487 | char *pos; |
| 488 | os_free(interfaces->global_iface_path); |
| 489 | interfaces->global_iface_path = os_strdup(path); |
| 490 | if (interfaces->global_iface_path == NULL) |
| 491 | return -1; |
| 492 | pos = os_strrchr(interfaces->global_iface_path, '/'); |
| 493 | if (pos == NULL) { |
Dmitry Shmidt | 1e78e76 | 2013-04-02 11:05:36 -0700 | [diff] [blame] | 494 | wpa_printf(MSG_ERROR, "No '/' in the global control interface " |
| 495 | "file"); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 496 | os_free(interfaces->global_iface_path); |
| 497 | interfaces->global_iface_path = NULL; |
| 498 | return -1; |
| 499 | } |
| 500 | |
| 501 | *pos = '\0'; |
| 502 | interfaces->global_iface_name = pos + 1; |
| 503 | |
| 504 | return 0; |
| 505 | } |
| 506 | |
| 507 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 508 | static int hostapd_get_ctrl_iface_group(struct hapd_interfaces *interfaces, |
| 509 | const char *group) |
| 510 | { |
| 511 | #ifndef CONFIG_NATIVE_WINDOWS |
| 512 | struct group *grp; |
| 513 | grp = getgrnam(group); |
| 514 | if (grp == NULL) { |
| 515 | wpa_printf(MSG_ERROR, "Unknown group '%s'", group); |
| 516 | return -1; |
| 517 | } |
| 518 | interfaces->ctrl_iface_group = grp->gr_gid; |
| 519 | #endif /* CONFIG_NATIVE_WINDOWS */ |
| 520 | return 0; |
| 521 | } |
| 522 | |
| 523 | |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 524 | #ifdef CONFIG_WPS |
| 525 | static int gen_uuid(const char *txt_addr) |
| 526 | { |
| 527 | u8 addr[ETH_ALEN]; |
| 528 | u8 uuid[UUID_LEN]; |
| 529 | char buf[100]; |
| 530 | |
| 531 | if (hwaddr_aton(txt_addr, addr) < 0) |
| 532 | return -1; |
| 533 | |
| 534 | uuid_gen_mac_addr(addr, uuid); |
| 535 | if (uuid_bin2str(uuid, buf, sizeof(buf)) < 0) |
| 536 | return -1; |
| 537 | |
| 538 | printf("%s\n", buf); |
| 539 | |
| 540 | return 0; |
| 541 | } |
| 542 | #endif /* CONFIG_WPS */ |
| 543 | |
| 544 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 545 | #ifndef HOSTAPD_CLEANUP_INTERVAL |
| 546 | #define HOSTAPD_CLEANUP_INTERVAL 10 |
| 547 | #endif /* HOSTAPD_CLEANUP_INTERVAL */ |
| 548 | |
| 549 | static int hostapd_periodic_call(struct hostapd_iface *iface, void *ctx) |
| 550 | { |
| 551 | hostapd_periodic_iface(iface); |
| 552 | return 0; |
| 553 | } |
| 554 | |
| 555 | |
| 556 | /* Periodic cleanup tasks */ |
| 557 | static void hostapd_periodic(void *eloop_ctx, void *timeout_ctx) |
| 558 | { |
| 559 | struct hapd_interfaces *interfaces = eloop_ctx; |
| 560 | |
| 561 | eloop_register_timeout(HOSTAPD_CLEANUP_INTERVAL, 0, |
| 562 | hostapd_periodic, interfaces, NULL); |
| 563 | hostapd_for_each_interface(interfaces, hostapd_periodic_call, NULL); |
| 564 | } |
| 565 | |
| 566 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 567 | int main(int argc, char *argv[]) |
| 568 | { |
| 569 | struct hapd_interfaces interfaces; |
| 570 | int ret = 1; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 571 | size_t i, j; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 572 | int c, debug = 0, daemonize = 0; |
| 573 | char *pid_file = NULL; |
| 574 | const char *log_file = NULL; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 575 | const char *entropy_file = NULL; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 576 | char **bss_config = NULL, **tmp_bss; |
| 577 | size_t num_bss_configs = 0; |
| 578 | #ifdef CONFIG_DEBUG_LINUX_TRACING |
| 579 | int enable_trace_dbg = 0; |
| 580 | #endif /* CONFIG_DEBUG_LINUX_TRACING */ |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 581 | int start_ifaces_in_sync = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 582 | |
| 583 | if (os_program_init()) |
| 584 | return -1; |
| 585 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 586 | os_memset(&interfaces, 0, sizeof(interfaces)); |
| 587 | interfaces.reload_config = hostapd_reload_config; |
| 588 | interfaces.config_read_cb = hostapd_config_read; |
| 589 | interfaces.for_each_interface = hostapd_for_each_interface; |
| 590 | interfaces.ctrl_iface_init = hostapd_ctrl_iface_init; |
| 591 | interfaces.ctrl_iface_deinit = hostapd_ctrl_iface_deinit; |
| 592 | interfaces.driver_init = hostapd_driver_init; |
| 593 | interfaces.global_iface_path = NULL; |
| 594 | interfaces.global_iface_name = NULL; |
| 595 | interfaces.global_ctrl_sock = -1; |
Anton Nayshtut | f715e8d | 2014-11-16 16:52:49 +0200 | [diff] [blame] | 596 | interfaces.global_ctrl_dst = NULL; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 597 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 598 | for (;;) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 599 | c = getopt(argc, argv, "b:Bde:f:hKP:STtu:vg:G:"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 600 | if (c < 0) |
| 601 | break; |
| 602 | switch (c) { |
| 603 | case 'h': |
| 604 | usage(); |
| 605 | break; |
| 606 | case 'd': |
| 607 | debug++; |
| 608 | if (wpa_debug_level > 0) |
| 609 | wpa_debug_level--; |
| 610 | break; |
| 611 | case 'B': |
| 612 | daemonize++; |
| 613 | break; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 614 | case 'e': |
| 615 | entropy_file = optarg; |
| 616 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 617 | case 'f': |
| 618 | log_file = optarg; |
| 619 | break; |
| 620 | case 'K': |
| 621 | wpa_debug_show_keys++; |
| 622 | break; |
| 623 | case 'P': |
| 624 | os_free(pid_file); |
| 625 | pid_file = os_rel2abs_path(optarg); |
| 626 | break; |
| 627 | case 't': |
| 628 | wpa_debug_timestamp++; |
| 629 | break; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 630 | #ifdef CONFIG_DEBUG_LINUX_TRACING |
| 631 | case 'T': |
| 632 | enable_trace_dbg = 1; |
| 633 | break; |
| 634 | #endif /* CONFIG_DEBUG_LINUX_TRACING */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 635 | case 'v': |
| 636 | show_version(); |
| 637 | exit(1); |
| 638 | break; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 639 | case 'g': |
Dmitry Shmidt | 1e78e76 | 2013-04-02 11:05:36 -0700 | [diff] [blame] | 640 | if (hostapd_get_global_ctrl_iface(&interfaces, optarg)) |
| 641 | return -1; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 642 | break; |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 643 | case 'G': |
Dmitry Shmidt | 1e78e76 | 2013-04-02 11:05:36 -0700 | [diff] [blame] | 644 | if (hostapd_get_ctrl_iface_group(&interfaces, optarg)) |
| 645 | return -1; |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 646 | break; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 647 | case 'b': |
| 648 | tmp_bss = os_realloc_array(bss_config, |
| 649 | num_bss_configs + 1, |
| 650 | sizeof(char *)); |
| 651 | if (tmp_bss == NULL) |
| 652 | goto out; |
| 653 | bss_config = tmp_bss; |
| 654 | bss_config[num_bss_configs++] = optarg; |
| 655 | break; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 656 | case 'S': |
| 657 | start_ifaces_in_sync = 1; |
| 658 | break; |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 659 | #ifdef CONFIG_WPS |
| 660 | case 'u': |
| 661 | return gen_uuid(optarg); |
| 662 | #endif /* CONFIG_WPS */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 663 | default: |
| 664 | usage(); |
| 665 | break; |
| 666 | } |
| 667 | } |
| 668 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 669 | if (optind == argc && interfaces.global_iface_path == NULL && |
| 670 | num_bss_configs == 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 671 | usage(); |
| 672 | |
| 673 | wpa_msg_register_ifname_cb(hostapd_msg_ifname_cb); |
| 674 | |
| 675 | if (log_file) |
| 676 | wpa_debug_open_file(log_file); |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 677 | else |
| 678 | wpa_debug_setup_stdout(); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 679 | #ifdef CONFIG_DEBUG_LINUX_TRACING |
| 680 | if (enable_trace_dbg) { |
| 681 | int tret = wpa_debug_open_linux_tracing(); |
| 682 | if (tret) { |
| 683 | wpa_printf(MSG_ERROR, "Failed to enable trace logging"); |
| 684 | return -1; |
| 685 | } |
| 686 | } |
| 687 | #endif /* CONFIG_DEBUG_LINUX_TRACING */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 688 | |
| 689 | interfaces.count = argc - optind; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 690 | if (interfaces.count || num_bss_configs) { |
| 691 | interfaces.iface = os_calloc(interfaces.count + num_bss_configs, |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 692 | sizeof(struct hostapd_iface *)); |
| 693 | if (interfaces.iface == NULL) { |
| 694 | wpa_printf(MSG_ERROR, "malloc failed"); |
| 695 | return -1; |
| 696 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 697 | } |
| 698 | |
Dmitry Shmidt | 4b06059 | 2013-04-29 16:42:49 -0700 | [diff] [blame] | 699 | if (hostapd_global_init(&interfaces, entropy_file)) { |
Dmitry Shmidt | 7a53dbb | 2015-06-11 13:13:53 -0700 | [diff] [blame] | 700 | wpa_printf(MSG_ERROR, "Failed to initialize global context"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 701 | return -1; |
Dmitry Shmidt | 4b06059 | 2013-04-29 16:42:49 -0700 | [diff] [blame] | 702 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 703 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 704 | eloop_register_timeout(HOSTAPD_CLEANUP_INTERVAL, 0, |
| 705 | hostapd_periodic, &interfaces, NULL); |
| 706 | |
| 707 | if (fst_global_init()) { |
| 708 | wpa_printf(MSG_ERROR, |
| 709 | "Failed to initialize global FST context"); |
| 710 | goto out; |
| 711 | } |
| 712 | |
| 713 | #if defined(CONFIG_FST) && defined(CONFIG_CTRL_IFACE) |
| 714 | if (!fst_global_add_ctrl(fst_ctrl_cli)) |
| 715 | wpa_printf(MSG_WARNING, "Failed to add CLI FST ctrl"); |
| 716 | #endif /* CONFIG_FST && CONFIG_CTRL_IFACE */ |
| 717 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 718 | /* Allocate and parse configuration for full interface files */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 719 | for (i = 0; i < interfaces.count; i++) { |
| 720 | interfaces.iface[i] = hostapd_interface_init(&interfaces, |
| 721 | argv[optind + i], |
| 722 | debug); |
Dmitry Shmidt | 4b06059 | 2013-04-29 16:42:49 -0700 | [diff] [blame] | 723 | if (!interfaces.iface[i]) { |
| 724 | wpa_printf(MSG_ERROR, "Failed to initialize interface"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 725 | goto out; |
Dmitry Shmidt | 4b06059 | 2013-04-29 16:42:49 -0700 | [diff] [blame] | 726 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 727 | if (start_ifaces_in_sync) |
| 728 | interfaces.iface[i]->need_to_start_in_sync = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 729 | } |
| 730 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 731 | /* Allocate and parse configuration for per-BSS files */ |
| 732 | for (i = 0; i < num_bss_configs; i++) { |
| 733 | struct hostapd_iface *iface; |
| 734 | char *fname; |
| 735 | |
| 736 | wpa_printf(MSG_INFO, "BSS config: %s", bss_config[i]); |
| 737 | fname = os_strchr(bss_config[i], ':'); |
| 738 | if (fname == NULL) { |
| 739 | wpa_printf(MSG_ERROR, |
| 740 | "Invalid BSS config identifier '%s'", |
| 741 | bss_config[i]); |
| 742 | goto out; |
| 743 | } |
| 744 | *fname++ = '\0'; |
| 745 | iface = hostapd_interface_init_bss(&interfaces, bss_config[i], |
| 746 | fname, debug); |
| 747 | if (iface == NULL) |
| 748 | goto out; |
| 749 | for (j = 0; j < interfaces.count; j++) { |
| 750 | if (interfaces.iface[j] == iface) |
| 751 | break; |
| 752 | } |
| 753 | if (j == interfaces.count) { |
| 754 | struct hostapd_iface **tmp; |
| 755 | tmp = os_realloc_array(interfaces.iface, |
| 756 | interfaces.count + 1, |
| 757 | sizeof(struct hostapd_iface *)); |
| 758 | if (tmp == NULL) { |
| 759 | hostapd_interface_deinit_free(iface); |
| 760 | goto out; |
| 761 | } |
| 762 | interfaces.iface = tmp; |
| 763 | interfaces.iface[interfaces.count++] = iface; |
| 764 | } |
| 765 | } |
| 766 | |
| 767 | /* |
| 768 | * Enable configured interfaces. Depending on channel configuration, |
| 769 | * this may complete full initialization before returning or use a |
| 770 | * callback mechanism to complete setup in case of operations like HT |
| 771 | * co-ex scans, ACS, or DFS are needed to determine channel parameters. |
| 772 | * In such case, the interface will be enabled from eloop context within |
| 773 | * hostapd_global_run(). |
| 774 | */ |
Dmitry Shmidt | b96dad4 | 2013-11-05 10:07:29 -0800 | [diff] [blame] | 775 | interfaces.terminate_on_error = interfaces.count; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 776 | for (i = 0; i < interfaces.count; i++) { |
| 777 | if (hostapd_driver_init(interfaces.iface[i]) || |
| 778 | hostapd_setup_interface(interfaces.iface[i])) |
| 779 | goto out; |
| 780 | } |
| 781 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 782 | hostapd_global_ctrl_iface_init(&interfaces); |
| 783 | |
Dmitry Shmidt | 4b06059 | 2013-04-29 16:42:49 -0700 | [diff] [blame] | 784 | if (hostapd_global_run(&interfaces, daemonize, pid_file)) { |
| 785 | wpa_printf(MSG_ERROR, "Failed to start eloop"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 786 | goto out; |
Dmitry Shmidt | 4b06059 | 2013-04-29 16:42:49 -0700 | [diff] [blame] | 787 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 788 | |
| 789 | ret = 0; |
| 790 | |
| 791 | out: |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 792 | hostapd_global_ctrl_iface_deinit(&interfaces); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 793 | /* Deinitialize all interfaces */ |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 794 | for (i = 0; i < interfaces.count; i++) { |
Dmitry Shmidt | 818ea48 | 2014-03-10 13:15:21 -0700 | [diff] [blame] | 795 | if (!interfaces.iface[i]) |
| 796 | continue; |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 797 | interfaces.iface[i]->driver_ap_teardown = |
| 798 | !!(interfaces.iface[i]->drv_flags & |
| 799 | WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 800 | hostapd_interface_deinit_free(interfaces.iface[i]); |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 801 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 802 | os_free(interfaces.iface); |
| 803 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 804 | eloop_cancel_timeout(hostapd_periodic, &interfaces, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 805 | hostapd_global_deinit(pid_file); |
| 806 | os_free(pid_file); |
| 807 | |
| 808 | if (log_file) |
| 809 | wpa_debug_close_file(); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 810 | wpa_debug_close_linux_tracing(); |
| 811 | |
| 812 | os_free(bss_config); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 813 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 814 | fst_global_deinit(); |
| 815 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 816 | os_program_deinit(); |
| 817 | |
| 818 | return ret; |
| 819 | } |