Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * hostapd / main() |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 3 | * Copyright (c) 2002-2017, 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" |
Roshan Pius | cc81756 | 2017-12-22 14:45:05 -0800 | [diff] [blame^] | 31 | #ifdef CONFIG_CTRL_IFACE_HIDL |
| 32 | #include "hidl.h" |
| 33 | #endif /* CONFIG_CTRL_IFACE_HIDL */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 34 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 35 | struct hapd_global { |
| 36 | void **drv_priv; |
| 37 | size_t drv_count; |
| 38 | }; |
| 39 | |
| 40 | static struct hapd_global global; |
| 41 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 42 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 43 | #ifndef CONFIG_NO_HOSTAPD_LOGGER |
| 44 | static void hostapd_logger_cb(void *ctx, const u8 *addr, unsigned int module, |
| 45 | int level, const char *txt, size_t len) |
| 46 | { |
| 47 | struct hostapd_data *hapd = ctx; |
| 48 | char *format, *module_str; |
| 49 | int maxlen; |
| 50 | int conf_syslog_level, conf_stdout_level; |
| 51 | unsigned int conf_syslog, conf_stdout; |
| 52 | |
| 53 | maxlen = len + 100; |
| 54 | format = os_malloc(maxlen); |
| 55 | if (!format) |
| 56 | return; |
| 57 | |
| 58 | if (hapd && hapd->conf) { |
| 59 | conf_syslog_level = hapd->conf->logger_syslog_level; |
| 60 | conf_stdout_level = hapd->conf->logger_stdout_level; |
| 61 | conf_syslog = hapd->conf->logger_syslog; |
| 62 | conf_stdout = hapd->conf->logger_stdout; |
| 63 | } else { |
| 64 | conf_syslog_level = conf_stdout_level = 0; |
| 65 | conf_syslog = conf_stdout = (unsigned int) -1; |
| 66 | } |
| 67 | |
| 68 | switch (module) { |
| 69 | case HOSTAPD_MODULE_IEEE80211: |
| 70 | module_str = "IEEE 802.11"; |
| 71 | break; |
| 72 | case HOSTAPD_MODULE_IEEE8021X: |
| 73 | module_str = "IEEE 802.1X"; |
| 74 | break; |
| 75 | case HOSTAPD_MODULE_RADIUS: |
| 76 | module_str = "RADIUS"; |
| 77 | break; |
| 78 | case HOSTAPD_MODULE_WPA: |
| 79 | module_str = "WPA"; |
| 80 | break; |
| 81 | case HOSTAPD_MODULE_DRIVER: |
| 82 | module_str = "DRIVER"; |
| 83 | break; |
| 84 | case HOSTAPD_MODULE_IAPP: |
| 85 | module_str = "IAPP"; |
| 86 | break; |
| 87 | case HOSTAPD_MODULE_MLME: |
| 88 | module_str = "MLME"; |
| 89 | break; |
| 90 | default: |
| 91 | module_str = NULL; |
| 92 | break; |
| 93 | } |
| 94 | |
| 95 | if (hapd && hapd->conf && addr) |
| 96 | os_snprintf(format, maxlen, "%s: STA " MACSTR "%s%s: %s", |
| 97 | hapd->conf->iface, MAC2STR(addr), |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 98 | module_str ? " " : "", module_str ? module_str : "", |
| 99 | txt); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 100 | else if (hapd && hapd->conf) |
| 101 | os_snprintf(format, maxlen, "%s:%s%s %s", |
| 102 | hapd->conf->iface, module_str ? " " : "", |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 103 | module_str ? module_str : "", txt); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 104 | else if (addr) |
| 105 | os_snprintf(format, maxlen, "STA " MACSTR "%s%s: %s", |
| 106 | MAC2STR(addr), module_str ? " " : "", |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 107 | module_str ? module_str : "", txt); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 108 | else |
| 109 | os_snprintf(format, maxlen, "%s%s%s", |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 110 | module_str ? module_str : "", |
| 111 | module_str ? ": " : "", txt); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 112 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 113 | #ifdef CONFIG_DEBUG_SYSLOG |
| 114 | if (wpa_debug_syslog) |
| 115 | conf_stdout = 0; |
| 116 | #endif /* CONFIG_DEBUG_SYSLOG */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 117 | if ((conf_stdout & module) && level >= conf_stdout_level) { |
| 118 | wpa_debug_print_timestamp(); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 119 | wpa_printf(MSG_INFO, "%s", format); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | #ifndef CONFIG_NATIVE_WINDOWS |
| 123 | if ((conf_syslog & module) && level >= conf_syslog_level) { |
| 124 | int priority; |
| 125 | switch (level) { |
| 126 | case HOSTAPD_LEVEL_DEBUG_VERBOSE: |
| 127 | case HOSTAPD_LEVEL_DEBUG: |
| 128 | priority = LOG_DEBUG; |
| 129 | break; |
| 130 | case HOSTAPD_LEVEL_INFO: |
| 131 | priority = LOG_INFO; |
| 132 | break; |
| 133 | case HOSTAPD_LEVEL_NOTICE: |
| 134 | priority = LOG_NOTICE; |
| 135 | break; |
| 136 | case HOSTAPD_LEVEL_WARNING: |
| 137 | priority = LOG_WARNING; |
| 138 | break; |
| 139 | default: |
| 140 | priority = LOG_INFO; |
| 141 | break; |
| 142 | } |
| 143 | syslog(priority, "%s", format); |
| 144 | } |
| 145 | #endif /* CONFIG_NATIVE_WINDOWS */ |
| 146 | |
| 147 | os_free(format); |
| 148 | } |
| 149 | #endif /* CONFIG_NO_HOSTAPD_LOGGER */ |
| 150 | |
| 151 | |
| 152 | /** |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 153 | * hostapd_driver_init - Preparate driver interface |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 154 | */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 155 | static int hostapd_driver_init(struct hostapd_iface *iface) |
| 156 | { |
| 157 | struct wpa_init_params params; |
| 158 | size_t i; |
| 159 | struct hostapd_data *hapd = iface->bss[0]; |
| 160 | struct hostapd_bss_config *conf = hapd->conf; |
| 161 | u8 *b = conf->bssid; |
| 162 | struct wpa_driver_capa capa; |
| 163 | |
| 164 | if (hapd->driver == NULL || hapd->driver->hapd_init == NULL) { |
| 165 | wpa_printf(MSG_ERROR, "No hostapd driver wrapper available"); |
| 166 | return -1; |
| 167 | } |
| 168 | |
| 169 | /* Initialize the driver interface */ |
| 170 | if (!(b[0] | b[1] | b[2] | b[3] | b[4] | b[5])) |
| 171 | b = NULL; |
| 172 | |
| 173 | os_memset(¶ms, 0, sizeof(params)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 174 | for (i = 0; wpa_drivers[i]; i++) { |
| 175 | if (wpa_drivers[i] != hapd->driver) |
| 176 | continue; |
| 177 | |
| 178 | if (global.drv_priv[i] == NULL && |
| 179 | wpa_drivers[i]->global_init) { |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 180 | global.drv_priv[i] = |
| 181 | wpa_drivers[i]->global_init(iface->interfaces); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 182 | if (global.drv_priv[i] == NULL) { |
| 183 | wpa_printf(MSG_ERROR, "Failed to initialize " |
| 184 | "driver '%s'", |
| 185 | wpa_drivers[i]->name); |
| 186 | return -1; |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | params.global_priv = global.drv_priv[i]; |
| 191 | break; |
| 192 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 193 | params.bssid = b; |
| 194 | params.ifname = hapd->conf->iface; |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 195 | params.driver_params = hapd->iconf->driver_params; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 196 | params.use_pae_group_addr = hapd->conf->use_pae_group_addr; |
| 197 | |
| 198 | params.num_bridge = hapd->iface->num_bss; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 199 | params.bridge = os_calloc(hapd->iface->num_bss, sizeof(char *)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 200 | if (params.bridge == NULL) |
| 201 | return -1; |
| 202 | for (i = 0; i < hapd->iface->num_bss; i++) { |
| 203 | struct hostapd_data *bss = hapd->iface->bss[i]; |
| 204 | if (bss->conf->bridge[0]) |
| 205 | params.bridge[i] = bss->conf->bridge; |
| 206 | } |
| 207 | |
| 208 | params.own_addr = hapd->own_addr; |
| 209 | |
| 210 | hapd->drv_priv = hapd->driver->hapd_init(hapd, ¶ms); |
| 211 | os_free(params.bridge); |
| 212 | if (hapd->drv_priv == NULL) { |
| 213 | wpa_printf(MSG_ERROR, "%s driver initialization failed.", |
| 214 | hapd->driver->name); |
| 215 | hapd->driver = NULL; |
| 216 | return -1; |
| 217 | } |
| 218 | |
| 219 | if (hapd->driver->get_capa && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 220 | hapd->driver->get_capa(hapd->drv_priv, &capa) == 0) { |
Dmitry Shmidt | 0207e23 | 2014-09-03 14:58:37 -0700 | [diff] [blame] | 221 | struct wowlan_triggers *triggs; |
| 222 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 223 | iface->drv_flags = capa.flags; |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 224 | iface->smps_modes = capa.smps_modes; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 225 | iface->probe_resp_offloads = capa.probe_resp_offloads; |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 226 | /* |
| 227 | * Use default extended capa values from per-radio information |
| 228 | */ |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 229 | iface->extended_capa = capa.extended_capa; |
| 230 | iface->extended_capa_mask = capa.extended_capa_mask; |
| 231 | iface->extended_capa_len = capa.extended_capa_len; |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 232 | iface->drv_max_acl_mac_addrs = capa.max_acl_mac_addrs; |
Dmitry Shmidt | 0207e23 | 2014-09-03 14:58:37 -0700 | [diff] [blame] | 233 | |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 234 | /* |
| 235 | * Override extended capa with per-interface type (AP), if |
| 236 | * available from the driver. |
| 237 | */ |
| 238 | hostapd_get_ext_capa(iface); |
| 239 | |
Dmitry Shmidt | 0207e23 | 2014-09-03 14:58:37 -0700 | [diff] [blame] | 240 | triggs = wpa_get_wowlan_triggers(conf->wowlan_triggers, &capa); |
| 241 | if (triggs && hapd->driver->set_wowlan) { |
| 242 | if (hapd->driver->set_wowlan(hapd->drv_priv, triggs)) |
| 243 | wpa_printf(MSG_ERROR, "set_wowlan failed"); |
| 244 | } |
| 245 | os_free(triggs); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 246 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 247 | |
| 248 | return 0; |
| 249 | } |
| 250 | |
| 251 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 252 | /** |
| 253 | * hostapd_interface_init - Read configuration file and init BSS data |
| 254 | * |
| 255 | * This function is used to parse configuration file for a full interface (one |
| 256 | * or more BSSes sharing the same radio) and allocate memory for the BSS |
| 257 | * interfaces. No actiual driver operations are started. |
| 258 | */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 259 | static struct hostapd_iface * |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 260 | hostapd_interface_init(struct hapd_interfaces *interfaces, const char *if_name, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 261 | const char *config_fname, int debug) |
| 262 | { |
| 263 | struct hostapd_iface *iface; |
| 264 | int k; |
| 265 | |
| 266 | wpa_printf(MSG_ERROR, "Configuration file: %s", config_fname); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 267 | iface = hostapd_init(interfaces, config_fname); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 268 | if (!iface) |
| 269 | return NULL; |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 270 | |
| 271 | if (if_name) { |
| 272 | os_strlcpy(iface->conf->bss[0]->iface, if_name, |
| 273 | sizeof(iface->conf->bss[0]->iface)); |
| 274 | } |
| 275 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 276 | iface->interfaces = interfaces; |
| 277 | |
| 278 | for (k = 0; k < debug; k++) { |
| 279 | if (iface->bss[0]->conf->logger_stdout_level > 0) |
| 280 | iface->bss[0]->conf->logger_stdout_level--; |
| 281 | } |
| 282 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 283 | if (iface->conf->bss[0]->iface[0] == '\0' && |
Dmitry Shmidt | 4b06059 | 2013-04-29 16:42:49 -0700 | [diff] [blame] | 284 | !hostapd_drv_none(iface->bss[0])) { |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 285 | wpa_printf(MSG_ERROR, |
| 286 | "Interface name not specified in %s, nor by '-i' parameter", |
Dmitry Shmidt | 4b06059 | 2013-04-29 16:42:49 -0700 | [diff] [blame] | 287 | config_fname); |
| 288 | hostapd_interface_deinit_free(iface); |
| 289 | return NULL; |
| 290 | } |
| 291 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 292 | return iface; |
| 293 | } |
| 294 | |
| 295 | |
| 296 | /** |
| 297 | * handle_term - SIGINT and SIGTERM handler to terminate hostapd process |
| 298 | */ |
| 299 | static void handle_term(int sig, void *signal_ctx) |
| 300 | { |
| 301 | wpa_printf(MSG_DEBUG, "Signal %d received - terminating", sig); |
| 302 | eloop_terminate(); |
| 303 | } |
| 304 | |
| 305 | |
| 306 | #ifndef CONFIG_NATIVE_WINDOWS |
| 307 | |
| 308 | static int handle_reload_iface(struct hostapd_iface *iface, void *ctx) |
| 309 | { |
| 310 | if (hostapd_reload_config(iface) < 0) { |
| 311 | wpa_printf(MSG_WARNING, "Failed to read new configuration " |
| 312 | "file - continuing with old."); |
| 313 | } |
| 314 | return 0; |
| 315 | } |
| 316 | |
| 317 | |
| 318 | /** |
| 319 | * handle_reload - SIGHUP handler to reload configuration |
| 320 | */ |
| 321 | static void handle_reload(int sig, void *signal_ctx) |
| 322 | { |
| 323 | struct hapd_interfaces *interfaces = signal_ctx; |
| 324 | wpa_printf(MSG_DEBUG, "Signal %d received - reloading configuration", |
| 325 | sig); |
| 326 | hostapd_for_each_interface(interfaces, handle_reload_iface, NULL); |
| 327 | } |
| 328 | |
| 329 | |
| 330 | static void handle_dump_state(int sig, void *signal_ctx) |
| 331 | { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 332 | /* Not used anymore - ignore signal */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 333 | } |
| 334 | #endif /* CONFIG_NATIVE_WINDOWS */ |
| 335 | |
| 336 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 337 | static int hostapd_global_init(struct hapd_interfaces *interfaces, |
| 338 | const char *entropy_file) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 339 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 340 | int i; |
| 341 | |
| 342 | os_memset(&global, 0, sizeof(global)); |
| 343 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 344 | hostapd_logger_register_cb(hostapd_logger_cb); |
| 345 | |
| 346 | if (eap_server_register_methods()) { |
| 347 | wpa_printf(MSG_ERROR, "Failed to register EAP methods"); |
| 348 | return -1; |
| 349 | } |
| 350 | |
| 351 | if (eloop_init()) { |
| 352 | wpa_printf(MSG_ERROR, "Failed to initialize event loop"); |
| 353 | return -1; |
| 354 | } |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 355 | interfaces->eloop_initialized = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 356 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 357 | random_init(entropy_file); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 358 | |
| 359 | #ifndef CONFIG_NATIVE_WINDOWS |
| 360 | eloop_register_signal(SIGHUP, handle_reload, interfaces); |
| 361 | eloop_register_signal(SIGUSR1, handle_dump_state, interfaces); |
| 362 | #endif /* CONFIG_NATIVE_WINDOWS */ |
| 363 | eloop_register_signal_terminate(handle_term, interfaces); |
| 364 | |
| 365 | #ifndef CONFIG_NATIVE_WINDOWS |
| 366 | openlog("hostapd", 0, LOG_DAEMON); |
| 367 | #endif /* CONFIG_NATIVE_WINDOWS */ |
| 368 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 369 | for (i = 0; wpa_drivers[i]; i++) |
| 370 | global.drv_count++; |
| 371 | if (global.drv_count == 0) { |
| 372 | wpa_printf(MSG_ERROR, "No drivers enabled"); |
| 373 | return -1; |
| 374 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 375 | global.drv_priv = os_calloc(global.drv_count, sizeof(void *)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 376 | if (global.drv_priv == NULL) |
| 377 | return -1; |
| 378 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 379 | return 0; |
| 380 | } |
| 381 | |
| 382 | |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 383 | static void hostapd_global_deinit(const char *pid_file, int eloop_initialized) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 384 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 385 | int i; |
| 386 | |
| 387 | for (i = 0; wpa_drivers[i] && global.drv_priv; i++) { |
| 388 | if (!global.drv_priv[i]) |
| 389 | continue; |
| 390 | wpa_drivers[i]->global_deinit(global.drv_priv[i]); |
| 391 | } |
| 392 | os_free(global.drv_priv); |
| 393 | global.drv_priv = NULL; |
| 394 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 395 | #ifdef EAP_SERVER_TNC |
| 396 | tncs_global_deinit(); |
| 397 | #endif /* EAP_SERVER_TNC */ |
| 398 | |
| 399 | random_deinit(); |
| 400 | |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 401 | if (eloop_initialized) |
| 402 | eloop_destroy(); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 403 | |
| 404 | #ifndef CONFIG_NATIVE_WINDOWS |
| 405 | closelog(); |
| 406 | #endif /* CONFIG_NATIVE_WINDOWS */ |
| 407 | |
| 408 | eap_server_unregister_methods(); |
| 409 | |
| 410 | os_daemonize_terminate(pid_file); |
| 411 | } |
| 412 | |
| 413 | |
| 414 | static int hostapd_global_run(struct hapd_interfaces *ifaces, int daemonize, |
| 415 | const char *pid_file) |
| 416 | { |
| 417 | #ifdef EAP_SERVER_TNC |
| 418 | int tnc = 0; |
| 419 | size_t i, k; |
| 420 | |
| 421 | for (i = 0; !tnc && i < ifaces->count; i++) { |
| 422 | for (k = 0; k < ifaces->iface[i]->num_bss; k++) { |
| 423 | if (ifaces->iface[i]->bss[0]->conf->tnc) { |
| 424 | tnc++; |
| 425 | break; |
| 426 | } |
| 427 | } |
| 428 | } |
| 429 | |
| 430 | if (tnc && tncs_global_init() < 0) { |
| 431 | wpa_printf(MSG_ERROR, "Failed to initialize TNCS"); |
| 432 | return -1; |
| 433 | } |
| 434 | #endif /* EAP_SERVER_TNC */ |
| 435 | |
Dmitry Shmidt | b97e428 | 2016-02-08 10:16:07 -0800 | [diff] [blame] | 436 | if (daemonize) { |
| 437 | if (os_daemonize(pid_file)) { |
| 438 | wpa_printf(MSG_ERROR, "daemon: %s", strerror(errno)); |
| 439 | return -1; |
| 440 | } |
| 441 | if (eloop_sock_requeue()) { |
| 442 | wpa_printf(MSG_ERROR, "eloop_sock_requeue: %s", |
| 443 | strerror(errno)); |
| 444 | return -1; |
| 445 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 446 | } |
| 447 | |
| 448 | eloop_run(); |
| 449 | |
| 450 | return 0; |
| 451 | } |
| 452 | |
| 453 | |
| 454 | static void show_version(void) |
| 455 | { |
| 456 | fprintf(stderr, |
| 457 | "hostapd v" VERSION_STR "\n" |
| 458 | "User space daemon for IEEE 802.11 AP management,\n" |
| 459 | "IEEE 802.1X/WPA/WPA2/EAP/RADIUS Authenticator\n" |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 460 | "Copyright (c) 2002-2017, Jouni Malinen <j@w1.fi> " |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 461 | "and contributors\n"); |
| 462 | } |
| 463 | |
| 464 | |
| 465 | static void usage(void) |
| 466 | { |
| 467 | show_version(); |
| 468 | fprintf(stderr, |
| 469 | "\n" |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 470 | "usage: hostapd [-hdBKtv] [-P <PID file>] [-e <entropy file>] " |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 471 | "\\\n" |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 472 | " [-g <global ctrl_iface>] [-G <group>]\\\n" |
| 473 | " [-i <comma-separated list of interface names>]\\\n" |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 474 | " <configuration file(s)>\n" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 475 | "\n" |
| 476 | "options:\n" |
| 477 | " -h show this usage\n" |
| 478 | " -d show more debug messages (-dd for even more)\n" |
| 479 | " -B run daemon in the background\n" |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 480 | " -e entropy file\n" |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 481 | " -g global control interface path\n" |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 482 | " -G group for control interfaces\n" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 483 | " -P PID file\n" |
| 484 | " -K include key data in debug messages\n" |
| 485 | #ifdef CONFIG_DEBUG_FILE |
| 486 | " -f log output to debug file instead of stdout\n" |
| 487 | #endif /* CONFIG_DEBUG_FILE */ |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 488 | #ifdef CONFIG_DEBUG_LINUX_TRACING |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 489 | " -T record to Linux tracing in addition to logging\n" |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 490 | " (records all messages regardless of debug verbosity)\n" |
| 491 | #endif /* CONFIG_DEBUG_LINUX_TRACING */ |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 492 | " -i list of interface names to use\n" |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 493 | #ifdef CONFIG_DEBUG_SYSLOG |
| 494 | " -s log output to syslog instead of stdout\n" |
| 495 | #endif /* CONFIG_DEBUG_SYSLOG */ |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 496 | " -S start all the interfaces synchronously\n" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 497 | " -t include timestamps in some debug messages\n" |
| 498 | " -v show hostapd version\n"); |
| 499 | |
| 500 | exit(1); |
| 501 | } |
| 502 | |
| 503 | |
| 504 | static const char * hostapd_msg_ifname_cb(void *ctx) |
| 505 | { |
| 506 | struct hostapd_data *hapd = ctx; |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 507 | if (hapd && hapd->conf) |
| 508 | return hapd->conf->iface; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 509 | return NULL; |
| 510 | } |
| 511 | |
| 512 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 513 | static int hostapd_get_global_ctrl_iface(struct hapd_interfaces *interfaces, |
| 514 | const char *path) |
| 515 | { |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 516 | #ifndef CONFIG_CTRL_IFACE_UDP |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 517 | char *pos; |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 518 | #endif /* !CONFIG_CTRL_IFACE_UDP */ |
| 519 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 520 | os_free(interfaces->global_iface_path); |
| 521 | interfaces->global_iface_path = os_strdup(path); |
| 522 | if (interfaces->global_iface_path == NULL) |
| 523 | return -1; |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 524 | |
| 525 | #ifndef CONFIG_CTRL_IFACE_UDP |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 526 | pos = os_strrchr(interfaces->global_iface_path, '/'); |
| 527 | if (pos == NULL) { |
Dmitry Shmidt | 1e78e76 | 2013-04-02 11:05:36 -0700 | [diff] [blame] | 528 | wpa_printf(MSG_ERROR, "No '/' in the global control interface " |
| 529 | "file"); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 530 | os_free(interfaces->global_iface_path); |
| 531 | interfaces->global_iface_path = NULL; |
| 532 | return -1; |
| 533 | } |
| 534 | |
| 535 | *pos = '\0'; |
| 536 | interfaces->global_iface_name = pos + 1; |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 537 | #endif /* !CONFIG_CTRL_IFACE_UDP */ |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 538 | |
| 539 | return 0; |
| 540 | } |
| 541 | |
| 542 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 543 | static int hostapd_get_ctrl_iface_group(struct hapd_interfaces *interfaces, |
| 544 | const char *group) |
| 545 | { |
| 546 | #ifndef CONFIG_NATIVE_WINDOWS |
| 547 | struct group *grp; |
| 548 | grp = getgrnam(group); |
| 549 | if (grp == NULL) { |
| 550 | wpa_printf(MSG_ERROR, "Unknown group '%s'", group); |
| 551 | return -1; |
| 552 | } |
| 553 | interfaces->ctrl_iface_group = grp->gr_gid; |
| 554 | #endif /* CONFIG_NATIVE_WINDOWS */ |
| 555 | return 0; |
| 556 | } |
| 557 | |
| 558 | |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 559 | static int hostapd_get_interface_names(char ***if_names, |
| 560 | size_t *if_names_size, |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 561 | char *arg) |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 562 | { |
| 563 | char *if_name, *tmp, **nnames; |
| 564 | size_t i; |
| 565 | |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 566 | if (!arg) |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 567 | return -1; |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 568 | if_name = strtok_r(arg, ",", &tmp); |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 569 | |
| 570 | while (if_name) { |
| 571 | nnames = os_realloc_array(*if_names, 1 + *if_names_size, |
| 572 | sizeof(char *)); |
| 573 | if (!nnames) |
| 574 | goto fail; |
| 575 | *if_names = nnames; |
| 576 | |
| 577 | (*if_names)[*if_names_size] = os_strdup(if_name); |
| 578 | if (!(*if_names)[*if_names_size]) |
| 579 | goto fail; |
| 580 | (*if_names_size)++; |
| 581 | if_name = strtok_r(NULL, ",", &tmp); |
| 582 | } |
| 583 | |
| 584 | return 0; |
| 585 | |
| 586 | fail: |
| 587 | for (i = 0; i < *if_names_size; i++) |
| 588 | os_free((*if_names)[i]); |
| 589 | os_free(*if_names); |
| 590 | *if_names = NULL; |
| 591 | *if_names_size = 0; |
| 592 | return -1; |
| 593 | } |
| 594 | |
| 595 | |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 596 | #ifdef CONFIG_WPS |
| 597 | static int gen_uuid(const char *txt_addr) |
| 598 | { |
| 599 | u8 addr[ETH_ALEN]; |
| 600 | u8 uuid[UUID_LEN]; |
| 601 | char buf[100]; |
| 602 | |
| 603 | if (hwaddr_aton(txt_addr, addr) < 0) |
| 604 | return -1; |
| 605 | |
| 606 | uuid_gen_mac_addr(addr, uuid); |
| 607 | if (uuid_bin2str(uuid, buf, sizeof(buf)) < 0) |
| 608 | return -1; |
| 609 | |
| 610 | printf("%s\n", buf); |
| 611 | |
| 612 | return 0; |
| 613 | } |
| 614 | #endif /* CONFIG_WPS */ |
| 615 | |
| 616 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 617 | #ifndef HOSTAPD_CLEANUP_INTERVAL |
| 618 | #define HOSTAPD_CLEANUP_INTERVAL 10 |
| 619 | #endif /* HOSTAPD_CLEANUP_INTERVAL */ |
| 620 | |
| 621 | static int hostapd_periodic_call(struct hostapd_iface *iface, void *ctx) |
| 622 | { |
| 623 | hostapd_periodic_iface(iface); |
| 624 | return 0; |
| 625 | } |
| 626 | |
| 627 | |
| 628 | /* Periodic cleanup tasks */ |
| 629 | static void hostapd_periodic(void *eloop_ctx, void *timeout_ctx) |
| 630 | { |
| 631 | struct hapd_interfaces *interfaces = eloop_ctx; |
| 632 | |
| 633 | eloop_register_timeout(HOSTAPD_CLEANUP_INTERVAL, 0, |
| 634 | hostapd_periodic, interfaces, NULL); |
| 635 | hostapd_for_each_interface(interfaces, hostapd_periodic_call, NULL); |
| 636 | } |
| 637 | |
| 638 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 639 | int main(int argc, char *argv[]) |
| 640 | { |
| 641 | struct hapd_interfaces interfaces; |
| 642 | int ret = 1; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 643 | size_t i, j; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 644 | int c, debug = 0, daemonize = 0; |
| 645 | char *pid_file = NULL; |
| 646 | const char *log_file = NULL; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 647 | const char *entropy_file = NULL; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 648 | char **bss_config = NULL, **tmp_bss; |
| 649 | size_t num_bss_configs = 0; |
| 650 | #ifdef CONFIG_DEBUG_LINUX_TRACING |
| 651 | int enable_trace_dbg = 0; |
| 652 | #endif /* CONFIG_DEBUG_LINUX_TRACING */ |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 653 | int start_ifaces_in_sync = 0; |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 654 | char **if_names = NULL; |
| 655 | size_t if_names_size = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 656 | |
| 657 | if (os_program_init()) |
| 658 | return -1; |
| 659 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 660 | os_memset(&interfaces, 0, sizeof(interfaces)); |
| 661 | interfaces.reload_config = hostapd_reload_config; |
| 662 | interfaces.config_read_cb = hostapd_config_read; |
| 663 | interfaces.for_each_interface = hostapd_for_each_interface; |
Roshan Pius | cc81756 | 2017-12-22 14:45:05 -0800 | [diff] [blame^] | 664 | #ifdef CONFIG_CTRL_IFACE_HIDL |
| 665 | // No per-netdev setup for HIDL control interface. |
| 666 | interfaces.ctrl_iface_init = NULL; |
| 667 | interfaces.ctrl_iface_deinit = NULL; |
| 668 | #else /* CONFIG_CTRL_IFACE_HIDL */ |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 669 | interfaces.ctrl_iface_init = hostapd_ctrl_iface_init; |
| 670 | interfaces.ctrl_iface_deinit = hostapd_ctrl_iface_deinit; |
Roshan Pius | cc81756 | 2017-12-22 14:45:05 -0800 | [diff] [blame^] | 671 | #endif /* CONFIG_CTRL_IFACE_HIDL */ |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 672 | interfaces.driver_init = hostapd_driver_init; |
| 673 | interfaces.global_iface_path = NULL; |
| 674 | interfaces.global_iface_name = NULL; |
| 675 | interfaces.global_ctrl_sock = -1; |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 676 | dl_list_init(&interfaces.global_ctrl_dst); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 677 | #ifdef CONFIG_ETH_P_OUI |
| 678 | dl_list_init(&interfaces.eth_p_oui); |
| 679 | #endif /* CONFIG_ETH_P_OUI */ |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 680 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 681 | for (;;) { |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 682 | c = getopt(argc, argv, "b:Bde:f:hi:KP:sSTtu:vg:G:"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 683 | if (c < 0) |
| 684 | break; |
| 685 | switch (c) { |
| 686 | case 'h': |
| 687 | usage(); |
| 688 | break; |
| 689 | case 'd': |
| 690 | debug++; |
| 691 | if (wpa_debug_level > 0) |
| 692 | wpa_debug_level--; |
| 693 | break; |
| 694 | case 'B': |
| 695 | daemonize++; |
| 696 | break; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 697 | case 'e': |
| 698 | entropy_file = optarg; |
| 699 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 700 | case 'f': |
| 701 | log_file = optarg; |
| 702 | break; |
| 703 | case 'K': |
| 704 | wpa_debug_show_keys++; |
| 705 | break; |
| 706 | case 'P': |
| 707 | os_free(pid_file); |
| 708 | pid_file = os_rel2abs_path(optarg); |
| 709 | break; |
| 710 | case 't': |
| 711 | wpa_debug_timestamp++; |
| 712 | break; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 713 | #ifdef CONFIG_DEBUG_LINUX_TRACING |
| 714 | case 'T': |
| 715 | enable_trace_dbg = 1; |
| 716 | break; |
| 717 | #endif /* CONFIG_DEBUG_LINUX_TRACING */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 718 | case 'v': |
| 719 | show_version(); |
| 720 | exit(1); |
| 721 | break; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 722 | case 'g': |
Dmitry Shmidt | 1e78e76 | 2013-04-02 11:05:36 -0700 | [diff] [blame] | 723 | if (hostapd_get_global_ctrl_iface(&interfaces, optarg)) |
| 724 | return -1; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 725 | break; |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 726 | case 'G': |
Dmitry Shmidt | 1e78e76 | 2013-04-02 11:05:36 -0700 | [diff] [blame] | 727 | if (hostapd_get_ctrl_iface_group(&interfaces, optarg)) |
| 728 | return -1; |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 729 | break; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 730 | case 'b': |
| 731 | tmp_bss = os_realloc_array(bss_config, |
| 732 | num_bss_configs + 1, |
| 733 | sizeof(char *)); |
| 734 | if (tmp_bss == NULL) |
| 735 | goto out; |
| 736 | bss_config = tmp_bss; |
| 737 | bss_config[num_bss_configs++] = optarg; |
| 738 | break; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 739 | #ifdef CONFIG_DEBUG_SYSLOG |
| 740 | case 's': |
| 741 | wpa_debug_syslog = 1; |
| 742 | break; |
| 743 | #endif /* CONFIG_DEBUG_SYSLOG */ |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 744 | case 'S': |
| 745 | start_ifaces_in_sync = 1; |
| 746 | break; |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 747 | #ifdef CONFIG_WPS |
| 748 | case 'u': |
| 749 | return gen_uuid(optarg); |
| 750 | #endif /* CONFIG_WPS */ |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 751 | case 'i': |
| 752 | if (hostapd_get_interface_names(&if_names, |
| 753 | &if_names_size, optarg)) |
| 754 | goto out; |
| 755 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 756 | default: |
| 757 | usage(); |
| 758 | break; |
| 759 | } |
| 760 | } |
| 761 | |
Roshan Pius | cc81756 | 2017-12-22 14:45:05 -0800 | [diff] [blame^] | 762 | #ifndef CONFIG_CTRL_IFACE_HIDL |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 763 | if (optind == argc && interfaces.global_iface_path == NULL && |
| 764 | num_bss_configs == 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 765 | usage(); |
Roshan Pius | cc81756 | 2017-12-22 14:45:05 -0800 | [diff] [blame^] | 766 | #endif |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 767 | |
| 768 | wpa_msg_register_ifname_cb(hostapd_msg_ifname_cb); |
| 769 | |
| 770 | if (log_file) |
| 771 | wpa_debug_open_file(log_file); |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 772 | else |
| 773 | wpa_debug_setup_stdout(); |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 774 | #ifdef CONFIG_DEBUG_SYSLOG |
| 775 | if (wpa_debug_syslog) |
| 776 | wpa_debug_open_syslog(); |
| 777 | #endif /* CONFIG_DEBUG_SYSLOG */ |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 778 | #ifdef CONFIG_DEBUG_LINUX_TRACING |
| 779 | if (enable_trace_dbg) { |
| 780 | int tret = wpa_debug_open_linux_tracing(); |
| 781 | if (tret) { |
| 782 | wpa_printf(MSG_ERROR, "Failed to enable trace logging"); |
| 783 | return -1; |
| 784 | } |
| 785 | } |
| 786 | #endif /* CONFIG_DEBUG_LINUX_TRACING */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 787 | |
| 788 | interfaces.count = argc - optind; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 789 | if (interfaces.count || num_bss_configs) { |
| 790 | interfaces.iface = os_calloc(interfaces.count + num_bss_configs, |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 791 | sizeof(struct hostapd_iface *)); |
| 792 | if (interfaces.iface == NULL) { |
| 793 | wpa_printf(MSG_ERROR, "malloc failed"); |
| 794 | return -1; |
| 795 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 796 | } |
| 797 | |
Dmitry Shmidt | 4b06059 | 2013-04-29 16:42:49 -0700 | [diff] [blame] | 798 | if (hostapd_global_init(&interfaces, entropy_file)) { |
Dmitry Shmidt | 7a53dbb | 2015-06-11 13:13:53 -0700 | [diff] [blame] | 799 | wpa_printf(MSG_ERROR, "Failed to initialize global context"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 800 | return -1; |
Dmitry Shmidt | 4b06059 | 2013-04-29 16:42:49 -0700 | [diff] [blame] | 801 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 802 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 803 | eloop_register_timeout(HOSTAPD_CLEANUP_INTERVAL, 0, |
| 804 | hostapd_periodic, &interfaces, NULL); |
| 805 | |
| 806 | if (fst_global_init()) { |
| 807 | wpa_printf(MSG_ERROR, |
| 808 | "Failed to initialize global FST context"); |
| 809 | goto out; |
| 810 | } |
| 811 | |
| 812 | #if defined(CONFIG_FST) && defined(CONFIG_CTRL_IFACE) |
| 813 | if (!fst_global_add_ctrl(fst_ctrl_cli)) |
| 814 | wpa_printf(MSG_WARNING, "Failed to add CLI FST ctrl"); |
| 815 | #endif /* CONFIG_FST && CONFIG_CTRL_IFACE */ |
| 816 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 817 | /* Allocate and parse configuration for full interface files */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 818 | for (i = 0; i < interfaces.count; i++) { |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 819 | char *if_name = NULL; |
| 820 | |
| 821 | if (i < if_names_size) |
| 822 | if_name = if_names[i]; |
| 823 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 824 | interfaces.iface[i] = hostapd_interface_init(&interfaces, |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 825 | if_name, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 826 | argv[optind + i], |
| 827 | debug); |
Dmitry Shmidt | 4b06059 | 2013-04-29 16:42:49 -0700 | [diff] [blame] | 828 | if (!interfaces.iface[i]) { |
| 829 | wpa_printf(MSG_ERROR, "Failed to initialize interface"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 830 | goto out; |
Dmitry Shmidt | 4b06059 | 2013-04-29 16:42:49 -0700 | [diff] [blame] | 831 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 832 | if (start_ifaces_in_sync) |
| 833 | interfaces.iface[i]->need_to_start_in_sync = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 834 | } |
| 835 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 836 | /* Allocate and parse configuration for per-BSS files */ |
| 837 | for (i = 0; i < num_bss_configs; i++) { |
| 838 | struct hostapd_iface *iface; |
| 839 | char *fname; |
| 840 | |
| 841 | wpa_printf(MSG_INFO, "BSS config: %s", bss_config[i]); |
| 842 | fname = os_strchr(bss_config[i], ':'); |
| 843 | if (fname == NULL) { |
| 844 | wpa_printf(MSG_ERROR, |
| 845 | "Invalid BSS config identifier '%s'", |
| 846 | bss_config[i]); |
| 847 | goto out; |
| 848 | } |
| 849 | *fname++ = '\0'; |
| 850 | iface = hostapd_interface_init_bss(&interfaces, bss_config[i], |
| 851 | fname, debug); |
| 852 | if (iface == NULL) |
| 853 | goto out; |
| 854 | for (j = 0; j < interfaces.count; j++) { |
| 855 | if (interfaces.iface[j] == iface) |
| 856 | break; |
| 857 | } |
| 858 | if (j == interfaces.count) { |
| 859 | struct hostapd_iface **tmp; |
| 860 | tmp = os_realloc_array(interfaces.iface, |
| 861 | interfaces.count + 1, |
| 862 | sizeof(struct hostapd_iface *)); |
| 863 | if (tmp == NULL) { |
| 864 | hostapd_interface_deinit_free(iface); |
| 865 | goto out; |
| 866 | } |
| 867 | interfaces.iface = tmp; |
| 868 | interfaces.iface[interfaces.count++] = iface; |
| 869 | } |
| 870 | } |
| 871 | |
| 872 | /* |
| 873 | * Enable configured interfaces. Depending on channel configuration, |
| 874 | * this may complete full initialization before returning or use a |
| 875 | * callback mechanism to complete setup in case of operations like HT |
| 876 | * co-ex scans, ACS, or DFS are needed to determine channel parameters. |
| 877 | * In such case, the interface will be enabled from eloop context within |
| 878 | * hostapd_global_run(). |
| 879 | */ |
Dmitry Shmidt | b96dad4 | 2013-11-05 10:07:29 -0800 | [diff] [blame] | 880 | interfaces.terminate_on_error = interfaces.count; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 881 | for (i = 0; i < interfaces.count; i++) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 882 | if (hostapd_driver_init(interfaces.iface[i])) |
| 883 | goto out; |
| 884 | #ifdef CONFIG_MBO |
| 885 | for (j = 0; j < interfaces.iface[i]->num_bss; j++) { |
| 886 | struct hostapd_data *hapd = interfaces.iface[i]->bss[j]; |
| 887 | |
| 888 | if (hapd && (hapd->conf->oce & OCE_STA_CFON) && |
| 889 | (interfaces.iface[i]->drv_flags & |
| 890 | WPA_DRIVER_FLAGS_OCE_STA_CFON)) |
| 891 | hapd->enable_oce = OCE_STA_CFON; |
| 892 | |
| 893 | if (hapd && (hapd->conf->oce & OCE_AP) && |
| 894 | (interfaces.iface[i]->drv_flags & |
| 895 | WPA_DRIVER_FLAGS_OCE_STA_CFON)) { |
| 896 | /* TODO: Need to add OCE-AP support */ |
| 897 | wpa_printf(MSG_ERROR, |
| 898 | "OCE-AP feature is not yet supported"); |
| 899 | } |
| 900 | } |
| 901 | #endif /* CONFIG_MBO */ |
| 902 | if (hostapd_setup_interface(interfaces.iface[i])) |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 903 | goto out; |
| 904 | } |
| 905 | |
Roshan Pius | cc81756 | 2017-12-22 14:45:05 -0800 | [diff] [blame^] | 906 | #ifdef CONFIG_CTRL_IFACE_HIDL |
| 907 | if (hostapd_hidl_init(&interfaces)) { |
| 908 | wpa_printf(MSG_ERROR, "Failed to initialize HIDL interface"); |
| 909 | goto out; |
| 910 | } |
| 911 | #else /* CONFIG_CTRL_IFACE_HIDL */ |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 912 | hostapd_global_ctrl_iface_init(&interfaces); |
Roshan Pius | cc81756 | 2017-12-22 14:45:05 -0800 | [diff] [blame^] | 913 | #endif /* CONFIG_CTRL_IFACE_HIDL */ |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 914 | |
Dmitry Shmidt | 4b06059 | 2013-04-29 16:42:49 -0700 | [diff] [blame] | 915 | if (hostapd_global_run(&interfaces, daemonize, pid_file)) { |
| 916 | wpa_printf(MSG_ERROR, "Failed to start eloop"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 917 | goto out; |
Dmitry Shmidt | 4b06059 | 2013-04-29 16:42:49 -0700 | [diff] [blame] | 918 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 919 | |
| 920 | ret = 0; |
| 921 | |
| 922 | out: |
Roshan Pius | cc81756 | 2017-12-22 14:45:05 -0800 | [diff] [blame^] | 923 | #ifdef CONFIG_CTRL_IFACE_HIDL |
| 924 | hostapd_hidl_deinit(&interfaces); |
| 925 | #else /* CONFIG_CTRL_IFACE_HIDL */ |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 926 | hostapd_global_ctrl_iface_deinit(&interfaces); |
Roshan Pius | cc81756 | 2017-12-22 14:45:05 -0800 | [diff] [blame^] | 927 | #endif /* CONFIG_CTRL_IFACE_HIDL */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 928 | /* Deinitialize all interfaces */ |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 929 | for (i = 0; i < interfaces.count; i++) { |
Dmitry Shmidt | 818ea48 | 2014-03-10 13:15:21 -0700 | [diff] [blame] | 930 | if (!interfaces.iface[i]) |
| 931 | continue; |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 932 | interfaces.iface[i]->driver_ap_teardown = |
| 933 | !!(interfaces.iface[i]->drv_flags & |
| 934 | WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 935 | hostapd_interface_deinit_free(interfaces.iface[i]); |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 936 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 937 | os_free(interfaces.iface); |
| 938 | |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 939 | if (interfaces.eloop_initialized) |
| 940 | eloop_cancel_timeout(hostapd_periodic, &interfaces, NULL); |
| 941 | hostapd_global_deinit(pid_file, interfaces.eloop_initialized); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 942 | os_free(pid_file); |
| 943 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 944 | wpa_debug_close_syslog(); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 945 | if (log_file) |
| 946 | wpa_debug_close_file(); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 947 | wpa_debug_close_linux_tracing(); |
| 948 | |
| 949 | os_free(bss_config); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 950 | |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 951 | for (i = 0; i < if_names_size; i++) |
| 952 | os_free(if_names[i]); |
| 953 | os_free(if_names); |
| 954 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 955 | fst_global_deinit(); |
| 956 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 957 | os_program_deinit(); |
| 958 | |
| 959 | return ret; |
| 960 | } |