Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * hostapd / main() |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3 | * Copyright (c) 2002-2022, 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" |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 18 | #include "crypto/crypto.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 19 | #include "crypto/random.h" |
| 20 | #include "crypto/tls.h" |
| 21 | #include "common/version.h" |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 22 | #include "common/dpp.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 23 | #include "drivers/driver.h" |
| 24 | #include "eap_server/eap.h" |
| 25 | #include "eap_server/tncs.h" |
| 26 | #include "ap/hostapd.h" |
| 27 | #include "ap/ap_config.h" |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 28 | #include "ap/ap_drv_ops.h" |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 29 | #include "ap/dpp_hostapd.h" |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 30 | #include "fst/fst.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 31 | #include "config_file.h" |
| 32 | #include "eap_register.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 33 | #include "ctrl_iface.h" |
Gabriel Biren | 72cf9a5 | 2021-06-25 23:29:26 +0000 | [diff] [blame] | 34 | #ifdef CONFIG_CTRL_IFACE_AIDL |
| 35 | #include "aidl.h" |
| 36 | #endif /* CONFIG_CTRL_IFACE_AIDL */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 37 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 38 | struct hapd_global { |
| 39 | void **drv_priv; |
| 40 | size_t drv_count; |
| 41 | }; |
| 42 | |
| 43 | static struct hapd_global global; |
| 44 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 45 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 46 | #ifndef CONFIG_NO_HOSTAPD_LOGGER |
| 47 | static void hostapd_logger_cb(void *ctx, const u8 *addr, unsigned int module, |
| 48 | int level, const char *txt, size_t len) |
| 49 | { |
| 50 | struct hostapd_data *hapd = ctx; |
| 51 | char *format, *module_str; |
| 52 | int maxlen; |
| 53 | int conf_syslog_level, conf_stdout_level; |
| 54 | unsigned int conf_syslog, conf_stdout; |
| 55 | |
| 56 | maxlen = len + 100; |
| 57 | format = os_malloc(maxlen); |
| 58 | if (!format) |
| 59 | return; |
| 60 | |
| 61 | if (hapd && hapd->conf) { |
| 62 | conf_syslog_level = hapd->conf->logger_syslog_level; |
| 63 | conf_stdout_level = hapd->conf->logger_stdout_level; |
| 64 | conf_syslog = hapd->conf->logger_syslog; |
| 65 | conf_stdout = hapd->conf->logger_stdout; |
| 66 | } else { |
| 67 | conf_syslog_level = conf_stdout_level = 0; |
| 68 | conf_syslog = conf_stdout = (unsigned int) -1; |
| 69 | } |
| 70 | |
| 71 | switch (module) { |
| 72 | case HOSTAPD_MODULE_IEEE80211: |
| 73 | module_str = "IEEE 802.11"; |
| 74 | break; |
| 75 | case HOSTAPD_MODULE_IEEE8021X: |
| 76 | module_str = "IEEE 802.1X"; |
| 77 | break; |
| 78 | case HOSTAPD_MODULE_RADIUS: |
| 79 | module_str = "RADIUS"; |
| 80 | break; |
| 81 | case HOSTAPD_MODULE_WPA: |
| 82 | module_str = "WPA"; |
| 83 | break; |
| 84 | case HOSTAPD_MODULE_DRIVER: |
| 85 | module_str = "DRIVER"; |
| 86 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 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; |
Sunil Ravi | 7f76929 | 2024-07-23 22:21:32 +0000 | [diff] [blame] | 163 | #ifdef CONFIG_IEEE80211BE |
| 164 | struct hostapd_data *h_hapd = NULL; |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame] | 165 | void *shared_hapd = NULL; |
Sunil Ravi | 7f76929 | 2024-07-23 22:21:32 +0000 | [diff] [blame] | 166 | #endif /* CONFIG_IEEE80211BE */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 167 | |
| 168 | if (hapd->driver == NULL || hapd->driver->hapd_init == NULL) { |
| 169 | wpa_printf(MSG_ERROR, "No hostapd driver wrapper available"); |
| 170 | return -1; |
| 171 | } |
| 172 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 173 | #ifdef CONFIG_IEEE80211BE |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame] | 174 | if (conf->mld_ap) { |
| 175 | if (!hapd->mld) |
| 176 | hostapd_bss_setup_multi_link(hapd, iface->interfaces); |
Sunil Ravi | 7f76929 | 2024-07-23 22:21:32 +0000 | [diff] [blame] | 177 | h_hapd = hostapd_mld_get_first_bss(hapd); |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame] | 178 | } |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 179 | |
Sunil Ravi | 7f76929 | 2024-07-23 22:21:32 +0000 | [diff] [blame] | 180 | if (h_hapd) { |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 181 | hapd->drv_priv = h_hapd->drv_priv; |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 182 | hapd->interface_added = h_hapd->interface_added; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 183 | |
| 184 | /* |
| 185 | * All interfaces participating in the AP MLD would have |
| 186 | * the same MLD address, which is the interface hardware |
| 187 | * address, while the interface address would be |
| 188 | * derived from the original interface address if BSSID |
| 189 | * is not configured, and otherwise it would be the |
| 190 | * configured BSSID. |
| 191 | */ |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 192 | if (is_zero_ether_addr(b)) { |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 193 | os_memcpy(hapd->own_addr, h_hapd->mld->mld_addr, |
| 194 | ETH_ALEN); |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 195 | random_mac_addr_keep_oui(hapd->own_addr); |
| 196 | } else { |
| 197 | os_memcpy(hapd->own_addr, b, ETH_ALEN); |
| 198 | } |
| 199 | |
Sunil Ravi | 7f76929 | 2024-07-23 22:21:32 +0000 | [diff] [blame] | 200 | wpa_printf(MSG_DEBUG, |
| 201 | "Setup of non first link (%d) BSS of MLD %s", |
| 202 | hapd->mld_link_id, hapd->conf->iface); |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 203 | |
| 204 | goto setup_mld; |
| 205 | } |
| 206 | #endif /* CONFIG_IEEE80211BE */ |
| 207 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 208 | /* Initialize the driver interface */ |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 209 | if (is_zero_ether_addr(b)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 210 | b = NULL; |
| 211 | |
| 212 | os_memset(¶ms, 0, sizeof(params)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 213 | for (i = 0; wpa_drivers[i]; i++) { |
| 214 | if (wpa_drivers[i] != hapd->driver) |
| 215 | continue; |
| 216 | |
| 217 | if (global.drv_priv[i] == NULL && |
| 218 | wpa_drivers[i]->global_init) { |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 219 | global.drv_priv[i] = |
| 220 | wpa_drivers[i]->global_init(iface->interfaces); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 221 | if (global.drv_priv[i] == NULL) { |
| 222 | wpa_printf(MSG_ERROR, "Failed to initialize " |
| 223 | "driver '%s'", |
| 224 | wpa_drivers[i]->name); |
| 225 | return -1; |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | params.global_priv = global.drv_priv[i]; |
| 230 | break; |
| 231 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 232 | params.bssid = b; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 233 | #ifdef CONFIG_IEEE80211BE |
| 234 | /* |
| 235 | * Use the configured MLD MAC address as the interface hardware address |
| 236 | * if this AP is a part of an AP MLD. |
| 237 | */ |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 238 | if (hapd->conf->mld_ap) { |
| 239 | if (!is_zero_ether_addr(hapd->conf->mld_addr)) |
| 240 | params.bssid = hapd->conf->mld_addr; |
| 241 | else |
| 242 | params.bssid = NULL; |
| 243 | } |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 244 | #endif /* CONFIG_IEEE80211BE */ |
| 245 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 246 | params.ifname = hapd->conf->iface; |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 247 | params.driver_params = hapd->iconf->driver_params; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 248 | params.use_pae_group_addr = hapd->conf->use_pae_group_addr; |
| 249 | |
| 250 | params.num_bridge = hapd->iface->num_bss; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 251 | params.bridge = os_calloc(hapd->iface->num_bss, sizeof(char *)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 252 | if (params.bridge == NULL) |
| 253 | return -1; |
| 254 | for (i = 0; i < hapd->iface->num_bss; i++) { |
| 255 | struct hostapd_data *bss = hapd->iface->bss[i]; |
| 256 | if (bss->conf->bridge[0]) |
| 257 | params.bridge[i] = bss->conf->bridge; |
| 258 | } |
| 259 | |
| 260 | params.own_addr = hapd->own_addr; |
| 261 | |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame] | 262 | #ifdef CONFIG_IEEE80211BE |
| 263 | if (hapd->driver->can_share_drv && |
| 264 | hapd->driver->can_share_drv(hapd, ¶ms, &shared_hapd)) { |
| 265 | char force_ifname[IFNAMSIZ]; |
| 266 | const u8 *addr = params.bssid; |
| 267 | u8 if_addr[ETH_ALEN]; |
| 268 | |
| 269 | if (!shared_hapd) { |
| 270 | wpa_printf(MSG_ERROR, "Failed to get the shared drv"); |
| 271 | os_free(params.bridge); |
| 272 | return -1; |
| 273 | } |
| 274 | |
| 275 | /* Share an already initialized driver interface instance |
| 276 | * using an AP mode BSS in it instead of adding a new driver |
| 277 | * interface instance for the same driver. */ |
| 278 | if (hostapd_if_add(shared_hapd, WPA_IF_AP_BSS, |
| 279 | params.ifname, addr, hapd, |
| 280 | &hapd->drv_priv, force_ifname, if_addr, |
| 281 | params.num_bridge && params.bridge[0] ? |
| 282 | params.bridge[0] : NULL, |
| 283 | 0)) { |
| 284 | wpa_printf(MSG_ERROR, "Failed to add BSS (BSSID=" |
| 285 | MACSTR ")", MAC2STR(hapd->own_addr)); |
| 286 | os_free(params.bridge); |
| 287 | return -1; |
| 288 | } |
| 289 | os_free(params.bridge); |
| 290 | |
| 291 | hapd->interface_added = 1; |
| 292 | os_memcpy(params.own_addr, addr ? addr : if_addr, ETH_ALEN); |
| 293 | |
| 294 | goto pre_setup_mld; |
| 295 | } |
| 296 | #endif /* CONFIG_IEEE80211BE */ |
| 297 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 298 | hapd->drv_priv = hapd->driver->hapd_init(hapd, ¶ms); |
| 299 | os_free(params.bridge); |
| 300 | if (hapd->drv_priv == NULL) { |
| 301 | wpa_printf(MSG_ERROR, "%s driver initialization failed.", |
| 302 | hapd->driver->name); |
| 303 | hapd->driver = NULL; |
| 304 | return -1; |
| 305 | } |
| 306 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 307 | #ifdef CONFIG_IEEE80211BE |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame] | 308 | pre_setup_mld: |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 309 | /* |
| 310 | * This is the first interface added to the AP MLD, so have the |
| 311 | * interface hardware address be the MLD address, while the link address |
| 312 | * would be derived from the original interface address if BSSID is not |
| 313 | * configured, and otherwise it would be the configured BSSID. |
| 314 | */ |
| 315 | if (hapd->conf->mld_ap) { |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 316 | os_memcpy(hapd->mld->mld_addr, hapd->own_addr, ETH_ALEN); |
| 317 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 318 | if (!b) |
| 319 | random_mac_addr_keep_oui(hapd->own_addr); |
| 320 | else |
| 321 | os_memcpy(hapd->own_addr, b, ETH_ALEN); |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 322 | |
Sunil Ravi | 7f76929 | 2024-07-23 22:21:32 +0000 | [diff] [blame] | 323 | wpa_printf(MSG_DEBUG, "Setup of first link (%d) BSS of MLD %s", |
| 324 | hapd->mld_link_id, hapd->conf->iface); |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | setup_mld: |
| 328 | #endif /* CONFIG_IEEE80211BE */ |
| 329 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 330 | if (hapd->driver->get_capa && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 331 | hapd->driver->get_capa(hapd->drv_priv, &capa) == 0) { |
Dmitry Shmidt | 0207e23 | 2014-09-03 14:58:37 -0700 | [diff] [blame] | 332 | struct wowlan_triggers *triggs; |
| 333 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 334 | iface->drv_flags = capa.flags; |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 335 | iface->drv_flags2 = capa.flags2; |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 336 | iface->drv_rrm_flags = capa.rrm_flags; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 337 | iface->probe_resp_offloads = capa.probe_resp_offloads; |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 338 | /* |
| 339 | * Use default extended capa values from per-radio information |
| 340 | */ |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 341 | iface->extended_capa = capa.extended_capa; |
| 342 | iface->extended_capa_mask = capa.extended_capa_mask; |
| 343 | iface->extended_capa_len = capa.extended_capa_len; |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 344 | iface->drv_max_acl_mac_addrs = capa.max_acl_mac_addrs; |
Dmitry Shmidt | 0207e23 | 2014-09-03 14:58:37 -0700 | [diff] [blame] | 345 | |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 346 | /* |
| 347 | * Override extended capa with per-interface type (AP), if |
| 348 | * available from the driver. |
| 349 | */ |
| 350 | hostapd_get_ext_capa(iface); |
| 351 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 352 | hostapd_get_mld_capa(iface); |
| 353 | |
Dmitry Shmidt | 0207e23 | 2014-09-03 14:58:37 -0700 | [diff] [blame] | 354 | triggs = wpa_get_wowlan_triggers(conf->wowlan_triggers, &capa); |
| 355 | if (triggs && hapd->driver->set_wowlan) { |
| 356 | if (hapd->driver->set_wowlan(hapd->drv_priv, triggs)) |
| 357 | wpa_printf(MSG_ERROR, "set_wowlan failed"); |
| 358 | } |
| 359 | os_free(triggs); |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 360 | |
| 361 | iface->mbssid_max_interfaces = capa.mbssid_max_interfaces; |
| 362 | iface->ema_max_periodicity = capa.ema_max_periodicity; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 363 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 364 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 365 | #ifdef CONFIG_IEEE80211BE |
| 366 | if (hapd->conf->mld_ap) { |
| 367 | if (!(iface->drv_flags2 & WPA_DRIVER_FLAGS2_MLO)) { |
| 368 | wpa_printf(MSG_INFO, |
| 369 | "MLD: Not supported by the driver"); |
| 370 | return -1; |
| 371 | } |
| 372 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 373 | /* Initialize the BSS parameter change to 1 */ |
| 374 | hapd->eht_mld_bss_param_change = 1; |
| 375 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 376 | wpa_printf(MSG_DEBUG, |
| 377 | "MLD: Set link_id=%u, mld_addr=" MACSTR |
| 378 | ", own_addr=" MACSTR, |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 379 | hapd->mld_link_id, MAC2STR(hapd->mld->mld_addr), |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 380 | MAC2STR(hapd->own_addr)); |
| 381 | |
Sunil Ravi | c0f5d41 | 2024-09-11 22:12:49 +0000 | [diff] [blame] | 382 | if (hostapd_drv_link_add(hapd, hapd->mld_link_id, |
| 383 | hapd->own_addr)) { |
| 384 | wpa_printf(MSG_ERROR, |
| 385 | "MLD: Failed to add link %d in MLD %s", |
| 386 | hapd->mld_link_id, hapd->conf->iface); |
| 387 | return -1; |
| 388 | } |
| 389 | hostapd_mld_add_link(hapd); |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 390 | } |
| 391 | #endif /* CONFIG_IEEE80211BE */ |
| 392 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 393 | return 0; |
| 394 | } |
| 395 | |
| 396 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 397 | /** |
| 398 | * hostapd_interface_init - Read configuration file and init BSS data |
| 399 | * |
| 400 | * This function is used to parse configuration file for a full interface (one |
| 401 | * or more BSSes sharing the same radio) and allocate memory for the BSS |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 402 | * interfaces. No actual driver operations are started. |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 403 | */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 404 | static struct hostapd_iface * |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 405 | hostapd_interface_init(struct hapd_interfaces *interfaces, const char *if_name, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 406 | const char *config_fname, int debug) |
| 407 | { |
| 408 | struct hostapd_iface *iface; |
| 409 | int k; |
| 410 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 411 | wpa_printf(MSG_DEBUG, "Configuration file: %s", config_fname); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 412 | iface = hostapd_init(interfaces, config_fname); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 413 | if (!iface) |
| 414 | return NULL; |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 415 | |
| 416 | if (if_name) { |
| 417 | os_strlcpy(iface->conf->bss[0]->iface, if_name, |
| 418 | sizeof(iface->conf->bss[0]->iface)); |
| 419 | } |
| 420 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 421 | iface->interfaces = interfaces; |
| 422 | |
| 423 | for (k = 0; k < debug; k++) { |
| 424 | if (iface->bss[0]->conf->logger_stdout_level > 0) |
| 425 | iface->bss[0]->conf->logger_stdout_level--; |
| 426 | } |
| 427 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 428 | if (iface->conf->bss[0]->iface[0] == '\0' && |
Dmitry Shmidt | 4b06059 | 2013-04-29 16:42:49 -0700 | [diff] [blame] | 429 | !hostapd_drv_none(iface->bss[0])) { |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 430 | wpa_printf(MSG_ERROR, |
| 431 | "Interface name not specified in %s, nor by '-i' parameter", |
Dmitry Shmidt | 4b06059 | 2013-04-29 16:42:49 -0700 | [diff] [blame] | 432 | config_fname); |
| 433 | hostapd_interface_deinit_free(iface); |
| 434 | return NULL; |
| 435 | } |
| 436 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 437 | return iface; |
| 438 | } |
| 439 | |
| 440 | |
| 441 | /** |
| 442 | * handle_term - SIGINT and SIGTERM handler to terminate hostapd process |
| 443 | */ |
| 444 | static void handle_term(int sig, void *signal_ctx) |
| 445 | { |
| 446 | wpa_printf(MSG_DEBUG, "Signal %d received - terminating", sig); |
| 447 | eloop_terminate(); |
| 448 | } |
| 449 | |
| 450 | |
| 451 | #ifndef CONFIG_NATIVE_WINDOWS |
| 452 | |
| 453 | static int handle_reload_iface(struct hostapd_iface *iface, void *ctx) |
| 454 | { |
| 455 | if (hostapd_reload_config(iface) < 0) { |
| 456 | wpa_printf(MSG_WARNING, "Failed to read new configuration " |
| 457 | "file - continuing with old."); |
| 458 | } |
| 459 | return 0; |
| 460 | } |
| 461 | |
| 462 | |
| 463 | /** |
| 464 | * handle_reload - SIGHUP handler to reload configuration |
| 465 | */ |
| 466 | static void handle_reload(int sig, void *signal_ctx) |
| 467 | { |
| 468 | struct hapd_interfaces *interfaces = signal_ctx; |
| 469 | wpa_printf(MSG_DEBUG, "Signal %d received - reloading configuration", |
| 470 | sig); |
| 471 | hostapd_for_each_interface(interfaces, handle_reload_iface, NULL); |
| 472 | } |
| 473 | |
| 474 | |
| 475 | static void handle_dump_state(int sig, void *signal_ctx) |
| 476 | { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 477 | /* Not used anymore - ignore signal */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 478 | } |
| 479 | #endif /* CONFIG_NATIVE_WINDOWS */ |
| 480 | |
| 481 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 482 | static int hostapd_global_init(struct hapd_interfaces *interfaces, |
| 483 | const char *entropy_file) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 484 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 485 | int i; |
| 486 | |
| 487 | os_memset(&global, 0, sizeof(global)); |
| 488 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 489 | hostapd_logger_register_cb(hostapd_logger_cb); |
| 490 | |
| 491 | if (eap_server_register_methods()) { |
| 492 | wpa_printf(MSG_ERROR, "Failed to register EAP methods"); |
| 493 | return -1; |
| 494 | } |
| 495 | |
| 496 | if (eloop_init()) { |
| 497 | wpa_printf(MSG_ERROR, "Failed to initialize event loop"); |
| 498 | return -1; |
| 499 | } |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 500 | interfaces->eloop_initialized = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 501 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 502 | random_init(entropy_file); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 503 | |
| 504 | #ifndef CONFIG_NATIVE_WINDOWS |
| 505 | eloop_register_signal(SIGHUP, handle_reload, interfaces); |
| 506 | eloop_register_signal(SIGUSR1, handle_dump_state, interfaces); |
| 507 | #endif /* CONFIG_NATIVE_WINDOWS */ |
| 508 | eloop_register_signal_terminate(handle_term, interfaces); |
| 509 | |
| 510 | #ifndef CONFIG_NATIVE_WINDOWS |
| 511 | openlog("hostapd", 0, LOG_DAEMON); |
| 512 | #endif /* CONFIG_NATIVE_WINDOWS */ |
| 513 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 514 | for (i = 0; wpa_drivers[i]; i++) |
| 515 | global.drv_count++; |
| 516 | if (global.drv_count == 0) { |
| 517 | wpa_printf(MSG_ERROR, "No drivers enabled"); |
| 518 | return -1; |
| 519 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 520 | global.drv_priv = os_calloc(global.drv_count, sizeof(void *)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 521 | if (global.drv_priv == NULL) |
| 522 | return -1; |
| 523 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 524 | return 0; |
| 525 | } |
| 526 | |
| 527 | |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 528 | static void hostapd_global_deinit(const char *pid_file, int eloop_initialized) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 529 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 530 | int i; |
| 531 | |
| 532 | for (i = 0; wpa_drivers[i] && global.drv_priv; i++) { |
| 533 | if (!global.drv_priv[i]) |
| 534 | continue; |
| 535 | wpa_drivers[i]->global_deinit(global.drv_priv[i]); |
| 536 | } |
| 537 | os_free(global.drv_priv); |
| 538 | global.drv_priv = NULL; |
| 539 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 540 | #ifdef EAP_SERVER_TNC |
| 541 | tncs_global_deinit(); |
| 542 | #endif /* EAP_SERVER_TNC */ |
| 543 | |
| 544 | random_deinit(); |
| 545 | |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 546 | if (eloop_initialized) |
| 547 | eloop_destroy(); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 548 | |
| 549 | #ifndef CONFIG_NATIVE_WINDOWS |
| 550 | closelog(); |
| 551 | #endif /* CONFIG_NATIVE_WINDOWS */ |
| 552 | |
| 553 | eap_server_unregister_methods(); |
| 554 | |
| 555 | os_daemonize_terminate(pid_file); |
| 556 | } |
| 557 | |
| 558 | |
| 559 | static int hostapd_global_run(struct hapd_interfaces *ifaces, int daemonize, |
| 560 | const char *pid_file) |
| 561 | { |
| 562 | #ifdef EAP_SERVER_TNC |
| 563 | int tnc = 0; |
| 564 | size_t i, k; |
| 565 | |
| 566 | for (i = 0; !tnc && i < ifaces->count; i++) { |
| 567 | for (k = 0; k < ifaces->iface[i]->num_bss; k++) { |
| 568 | if (ifaces->iface[i]->bss[0]->conf->tnc) { |
| 569 | tnc++; |
| 570 | break; |
| 571 | } |
| 572 | } |
| 573 | } |
| 574 | |
| 575 | if (tnc && tncs_global_init() < 0) { |
| 576 | wpa_printf(MSG_ERROR, "Failed to initialize TNCS"); |
| 577 | return -1; |
| 578 | } |
| 579 | #endif /* EAP_SERVER_TNC */ |
| 580 | |
Dmitry Shmidt | b97e428 | 2016-02-08 10:16:07 -0800 | [diff] [blame] | 581 | if (daemonize) { |
| 582 | if (os_daemonize(pid_file)) { |
| 583 | wpa_printf(MSG_ERROR, "daemon: %s", strerror(errno)); |
| 584 | return -1; |
| 585 | } |
| 586 | if (eloop_sock_requeue()) { |
| 587 | wpa_printf(MSG_ERROR, "eloop_sock_requeue: %s", |
| 588 | strerror(errno)); |
| 589 | return -1; |
| 590 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 591 | } |
| 592 | |
Veerendranath Jakkam | 9d0d521 | 2023-02-21 19:55:58 +0530 | [diff] [blame] | 593 | #ifdef CONFIG_CTRL_IFACE_AIDL |
| 594 | if (hostapd_aidl_init(ifaces)) { |
| 595 | wpa_printf(MSG_ERROR, "Failed to initialize AIDL interface"); |
| 596 | return -1; |
| 597 | } |
| 598 | #endif /* CONFIG_CTRL_IFACE_AIDL */ |
| 599 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 600 | eloop_run(); |
| 601 | |
| 602 | return 0; |
| 603 | } |
| 604 | |
| 605 | |
| 606 | static void show_version(void) |
| 607 | { |
| 608 | fprintf(stderr, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 609 | "hostapd v%s\n" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 610 | "User space daemon for IEEE 802.11 AP management,\n" |
| 611 | "IEEE 802.1X/WPA/WPA2/EAP/RADIUS Authenticator\n" |
Sunil Ravi | 7f76929 | 2024-07-23 22:21:32 +0000 | [diff] [blame] | 612 | "Copyright (c) 2002-2024, Jouni Malinen <j@w1.fi> " |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 613 | "and contributors\n", |
| 614 | VERSION_STR); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 615 | } |
| 616 | |
| 617 | |
| 618 | static void usage(void) |
| 619 | { |
| 620 | show_version(); |
| 621 | fprintf(stderr, |
| 622 | "\n" |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 623 | "usage: hostapd [-hdBKtvq] [-P <PID file>] [-e <entropy file>] " |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 624 | "\\\n" |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 625 | " [-g <global ctrl_iface>] [-G <group>]\\\n" |
| 626 | " [-i <comma-separated list of interface names>]\\\n" |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 627 | " <configuration file(s)>\n" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 628 | "\n" |
| 629 | "options:\n" |
| 630 | " -h show this usage\n" |
| 631 | " -d show more debug messages (-dd for even more)\n" |
| 632 | " -B run daemon in the background\n" |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 633 | " -e entropy file\n" |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 634 | " -g global control interface path\n" |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 635 | " -G group for control interfaces\n" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 636 | " -P PID file\n" |
| 637 | " -K include key data in debug messages\n" |
| 638 | #ifdef CONFIG_DEBUG_FILE |
| 639 | " -f log output to debug file instead of stdout\n" |
| 640 | #endif /* CONFIG_DEBUG_FILE */ |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 641 | #ifdef CONFIG_DEBUG_LINUX_TRACING |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 642 | " -T record to Linux tracing in addition to logging\n" |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 643 | " (records all messages regardless of debug verbosity)\n" |
| 644 | #endif /* CONFIG_DEBUG_LINUX_TRACING */ |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 645 | " -i list of interface names to use\n" |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 646 | #ifdef CONFIG_DEBUG_SYSLOG |
| 647 | " -s log output to syslog instead of stdout\n" |
| 648 | #endif /* CONFIG_DEBUG_SYSLOG */ |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 649 | " -S start all the interfaces synchronously\n" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 650 | " -t include timestamps in some debug messages\n" |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 651 | " -v show hostapd version\n" |
| 652 | " -q show less debug messages (-qq for even less)\n"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 653 | |
| 654 | exit(1); |
| 655 | } |
| 656 | |
| 657 | |
| 658 | static const char * hostapd_msg_ifname_cb(void *ctx) |
| 659 | { |
| 660 | struct hostapd_data *hapd = ctx; |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 661 | if (hapd && hapd->conf) |
| 662 | return hapd->conf->iface; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 663 | return NULL; |
| 664 | } |
| 665 | |
| 666 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 667 | static int hostapd_get_global_ctrl_iface(struct hapd_interfaces *interfaces, |
| 668 | const char *path) |
| 669 | { |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 670 | #ifndef CONFIG_CTRL_IFACE_UDP |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 671 | char *pos; |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 672 | #endif /* !CONFIG_CTRL_IFACE_UDP */ |
| 673 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 674 | os_free(interfaces->global_iface_path); |
| 675 | interfaces->global_iface_path = os_strdup(path); |
| 676 | if (interfaces->global_iface_path == NULL) |
| 677 | return -1; |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 678 | |
| 679 | #ifndef CONFIG_CTRL_IFACE_UDP |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 680 | pos = os_strrchr(interfaces->global_iface_path, '/'); |
| 681 | if (pos == NULL) { |
Dmitry Shmidt | 1e78e76 | 2013-04-02 11:05:36 -0700 | [diff] [blame] | 682 | wpa_printf(MSG_ERROR, "No '/' in the global control interface " |
| 683 | "file"); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 684 | os_free(interfaces->global_iface_path); |
| 685 | interfaces->global_iface_path = NULL; |
| 686 | return -1; |
| 687 | } |
| 688 | |
| 689 | *pos = '\0'; |
| 690 | interfaces->global_iface_name = pos + 1; |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 691 | #endif /* !CONFIG_CTRL_IFACE_UDP */ |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 692 | |
| 693 | return 0; |
| 694 | } |
| 695 | |
| 696 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 697 | static int hostapd_get_ctrl_iface_group(struct hapd_interfaces *interfaces, |
| 698 | const char *group) |
| 699 | { |
| 700 | #ifndef CONFIG_NATIVE_WINDOWS |
| 701 | struct group *grp; |
| 702 | grp = getgrnam(group); |
| 703 | if (grp == NULL) { |
| 704 | wpa_printf(MSG_ERROR, "Unknown group '%s'", group); |
| 705 | return -1; |
| 706 | } |
| 707 | interfaces->ctrl_iface_group = grp->gr_gid; |
| 708 | #endif /* CONFIG_NATIVE_WINDOWS */ |
| 709 | return 0; |
| 710 | } |
| 711 | |
| 712 | |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 713 | static int hostapd_get_interface_names(char ***if_names, |
| 714 | size_t *if_names_size, |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 715 | char *arg) |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 716 | { |
| 717 | char *if_name, *tmp, **nnames; |
| 718 | size_t i; |
| 719 | |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 720 | if (!arg) |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 721 | return -1; |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 722 | if_name = strtok_r(arg, ",", &tmp); |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 723 | |
| 724 | while (if_name) { |
| 725 | nnames = os_realloc_array(*if_names, 1 + *if_names_size, |
| 726 | sizeof(char *)); |
| 727 | if (!nnames) |
| 728 | goto fail; |
| 729 | *if_names = nnames; |
| 730 | |
| 731 | (*if_names)[*if_names_size] = os_strdup(if_name); |
| 732 | if (!(*if_names)[*if_names_size]) |
| 733 | goto fail; |
| 734 | (*if_names_size)++; |
| 735 | if_name = strtok_r(NULL, ",", &tmp); |
| 736 | } |
| 737 | |
| 738 | return 0; |
| 739 | |
| 740 | fail: |
| 741 | for (i = 0; i < *if_names_size; i++) |
| 742 | os_free((*if_names)[i]); |
| 743 | os_free(*if_names); |
| 744 | *if_names = NULL; |
| 745 | *if_names_size = 0; |
| 746 | return -1; |
| 747 | } |
| 748 | |
| 749 | |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 750 | #ifdef CONFIG_WPS |
| 751 | static int gen_uuid(const char *txt_addr) |
| 752 | { |
| 753 | u8 addr[ETH_ALEN]; |
| 754 | u8 uuid[UUID_LEN]; |
| 755 | char buf[100]; |
| 756 | |
| 757 | if (hwaddr_aton(txt_addr, addr) < 0) |
| 758 | return -1; |
| 759 | |
| 760 | uuid_gen_mac_addr(addr, uuid); |
| 761 | if (uuid_bin2str(uuid, buf, sizeof(buf)) < 0) |
| 762 | return -1; |
| 763 | |
| 764 | printf("%s\n", buf); |
| 765 | |
| 766 | return 0; |
| 767 | } |
| 768 | #endif /* CONFIG_WPS */ |
| 769 | |
| 770 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 771 | #ifndef HOSTAPD_CLEANUP_INTERVAL |
| 772 | #define HOSTAPD_CLEANUP_INTERVAL 10 |
| 773 | #endif /* HOSTAPD_CLEANUP_INTERVAL */ |
| 774 | |
| 775 | static int hostapd_periodic_call(struct hostapd_iface *iface, void *ctx) |
| 776 | { |
| 777 | hostapd_periodic_iface(iface); |
| 778 | return 0; |
| 779 | } |
| 780 | |
| 781 | |
| 782 | /* Periodic cleanup tasks */ |
| 783 | static void hostapd_periodic(void *eloop_ctx, void *timeout_ctx) |
| 784 | { |
| 785 | struct hapd_interfaces *interfaces = eloop_ctx; |
| 786 | |
| 787 | eloop_register_timeout(HOSTAPD_CLEANUP_INTERVAL, 0, |
| 788 | hostapd_periodic, interfaces, NULL); |
| 789 | hostapd_for_each_interface(interfaces, hostapd_periodic_call, NULL); |
| 790 | } |
| 791 | |
| 792 | |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 793 | static void hostapd_global_cleanup_mld(struct hapd_interfaces *interfaces) |
| 794 | { |
| 795 | #ifdef CONFIG_IEEE80211BE |
| 796 | size_t i; |
| 797 | |
| 798 | if (!interfaces || !interfaces->mld) |
| 799 | return; |
| 800 | |
| 801 | for (i = 0; i < interfaces->mld_count; i++) { |
| 802 | if (!interfaces->mld[i]) |
| 803 | continue; |
| 804 | |
Sunil Ravi | c0f5d41 | 2024-09-11 22:12:49 +0000 | [diff] [blame] | 805 | interfaces->mld_ctrl_iface_deinit(interfaces->mld[i]); |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 806 | os_free(interfaces->mld[i]); |
| 807 | interfaces->mld[i] = NULL; |
| 808 | } |
| 809 | |
| 810 | os_free(interfaces->mld); |
| 811 | interfaces->mld = NULL; |
| 812 | interfaces->mld_count = 0; |
| 813 | #endif /* CONFIG_IEEE80211BE */ |
| 814 | } |
| 815 | |
| 816 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 817 | int main(int argc, char *argv[]) |
| 818 | { |
| 819 | struct hapd_interfaces interfaces; |
| 820 | int ret = 1; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 821 | size_t i, j; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 822 | int c, debug = 0, daemonize = 0; |
| 823 | char *pid_file = NULL; |
| 824 | const char *log_file = NULL; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 825 | const char *entropy_file = NULL; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 826 | char **bss_config = NULL, **tmp_bss; |
| 827 | size_t num_bss_configs = 0; |
| 828 | #ifdef CONFIG_DEBUG_LINUX_TRACING |
| 829 | int enable_trace_dbg = 0; |
| 830 | #endif /* CONFIG_DEBUG_LINUX_TRACING */ |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 831 | int start_ifaces_in_sync = 0; |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 832 | char **if_names = NULL; |
| 833 | size_t if_names_size = 0; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 834 | #ifdef CONFIG_DPP |
| 835 | struct dpp_global_config dpp_conf; |
| 836 | #endif /* CONFIG_DPP */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 837 | |
| 838 | if (os_program_init()) |
| 839 | return -1; |
| 840 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 841 | os_memset(&interfaces, 0, sizeof(interfaces)); |
| 842 | interfaces.reload_config = hostapd_reload_config; |
| 843 | interfaces.config_read_cb = hostapd_config_read; |
| 844 | interfaces.for_each_interface = hostapd_for_each_interface; |
| 845 | interfaces.ctrl_iface_init = hostapd_ctrl_iface_init; |
| 846 | interfaces.ctrl_iface_deinit = hostapd_ctrl_iface_deinit; |
| 847 | interfaces.driver_init = hostapd_driver_init; |
| 848 | interfaces.global_iface_path = NULL; |
| 849 | interfaces.global_iface_name = NULL; |
| 850 | interfaces.global_ctrl_sock = -1; |
Sunil Ravi | c0f5d41 | 2024-09-11 22:12:49 +0000 | [diff] [blame] | 851 | #ifdef CONFIG_IEEE80211BE |
| 852 | interfaces.mld_ctrl_iface_init = hostapd_mld_ctrl_iface_init; |
| 853 | interfaces.mld_ctrl_iface_deinit = hostapd_mld_ctrl_iface_deinit; |
| 854 | #endif /* CONFIG_IEEE80211BE */ |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 855 | dl_list_init(&interfaces.global_ctrl_dst); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 856 | #ifdef CONFIG_ETH_P_OUI |
| 857 | dl_list_init(&interfaces.eth_p_oui); |
| 858 | #endif /* CONFIG_ETH_P_OUI */ |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 859 | #ifdef CONFIG_DPP |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 860 | os_memset(&dpp_conf, 0, sizeof(dpp_conf)); |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 861 | dpp_conf.cb_ctx = &interfaces; |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 862 | #ifdef CONFIG_DPP2 |
| 863 | dpp_conf.remove_bi = hostapd_dpp_remove_bi; |
| 864 | #endif /* CONFIG_DPP2 */ |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 865 | interfaces.dpp = dpp_global_init(&dpp_conf); |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 866 | if (!interfaces.dpp) |
| 867 | return -1; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 868 | #endif /* CONFIG_DPP */ |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 869 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 870 | for (;;) { |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 871 | c = getopt(argc, argv, "b:Bde:f:hi:KP:sSTtu:vg:G:q"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 872 | if (c < 0) |
| 873 | break; |
| 874 | switch (c) { |
| 875 | case 'h': |
| 876 | usage(); |
| 877 | break; |
| 878 | case 'd': |
| 879 | debug++; |
| 880 | if (wpa_debug_level > 0) |
| 881 | wpa_debug_level--; |
| 882 | break; |
| 883 | case 'B': |
| 884 | daemonize++; |
| 885 | break; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 886 | case 'e': |
| 887 | entropy_file = optarg; |
| 888 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 889 | case 'f': |
| 890 | log_file = optarg; |
| 891 | break; |
| 892 | case 'K': |
| 893 | wpa_debug_show_keys++; |
| 894 | break; |
| 895 | case 'P': |
| 896 | os_free(pid_file); |
| 897 | pid_file = os_rel2abs_path(optarg); |
| 898 | break; |
| 899 | case 't': |
| 900 | wpa_debug_timestamp++; |
| 901 | break; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 902 | #ifdef CONFIG_DEBUG_LINUX_TRACING |
| 903 | case 'T': |
| 904 | enable_trace_dbg = 1; |
| 905 | break; |
| 906 | #endif /* CONFIG_DEBUG_LINUX_TRACING */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 907 | case 'v': |
| 908 | show_version(); |
| 909 | exit(1); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 910 | case 'g': |
Dmitry Shmidt | 1e78e76 | 2013-04-02 11:05:36 -0700 | [diff] [blame] | 911 | if (hostapd_get_global_ctrl_iface(&interfaces, optarg)) |
| 912 | return -1; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 913 | break; |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 914 | case 'G': |
Dmitry Shmidt | 1e78e76 | 2013-04-02 11:05:36 -0700 | [diff] [blame] | 915 | if (hostapd_get_ctrl_iface_group(&interfaces, optarg)) |
| 916 | return -1; |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 917 | break; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 918 | case 'b': |
| 919 | tmp_bss = os_realloc_array(bss_config, |
| 920 | num_bss_configs + 1, |
| 921 | sizeof(char *)); |
| 922 | if (tmp_bss == NULL) |
| 923 | goto out; |
| 924 | bss_config = tmp_bss; |
| 925 | bss_config[num_bss_configs++] = optarg; |
| 926 | break; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 927 | #ifdef CONFIG_DEBUG_SYSLOG |
| 928 | case 's': |
| 929 | wpa_debug_syslog = 1; |
| 930 | break; |
| 931 | #endif /* CONFIG_DEBUG_SYSLOG */ |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 932 | case 'S': |
| 933 | start_ifaces_in_sync = 1; |
| 934 | break; |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 935 | #ifdef CONFIG_WPS |
| 936 | case 'u': |
| 937 | return gen_uuid(optarg); |
| 938 | #endif /* CONFIG_WPS */ |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 939 | case 'i': |
| 940 | if (hostapd_get_interface_names(&if_names, |
| 941 | &if_names_size, optarg)) |
| 942 | goto out; |
| 943 | break; |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 944 | case 'q': |
| 945 | wpa_debug_level++; |
| 946 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 947 | default: |
| 948 | usage(); |
| 949 | break; |
| 950 | } |
| 951 | } |
| 952 | |
Gabriel Biren | 72cf9a5 | 2021-06-25 23:29:26 +0000 | [diff] [blame] | 953 | #ifndef CONFIG_CTRL_IFACE_AIDL |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 954 | if (optind == argc && interfaces.global_iface_path == NULL && |
| 955 | num_bss_configs == 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 956 | usage(); |
Roshan Pius | cc81756 | 2017-12-22 14:45:05 -0800 | [diff] [blame] | 957 | #endif |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 958 | |
| 959 | wpa_msg_register_ifname_cb(hostapd_msg_ifname_cb); |
| 960 | |
| 961 | if (log_file) |
| 962 | wpa_debug_open_file(log_file); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 963 | if (!log_file && !wpa_debug_syslog) |
Dmitry Shmidt | fb45fd5 | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 964 | wpa_debug_setup_stdout(); |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 965 | #ifdef CONFIG_DEBUG_SYSLOG |
| 966 | if (wpa_debug_syslog) |
| 967 | wpa_debug_open_syslog(); |
| 968 | #endif /* CONFIG_DEBUG_SYSLOG */ |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 969 | #ifdef CONFIG_DEBUG_LINUX_TRACING |
| 970 | if (enable_trace_dbg) { |
| 971 | int tret = wpa_debug_open_linux_tracing(); |
| 972 | if (tret) { |
| 973 | wpa_printf(MSG_ERROR, "Failed to enable trace logging"); |
| 974 | return -1; |
| 975 | } |
| 976 | } |
| 977 | #endif /* CONFIG_DEBUG_LINUX_TRACING */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 978 | |
| 979 | interfaces.count = argc - optind; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 980 | if (interfaces.count || num_bss_configs) { |
| 981 | interfaces.iface = os_calloc(interfaces.count + num_bss_configs, |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 982 | sizeof(struct hostapd_iface *)); |
| 983 | if (interfaces.iface == NULL) { |
| 984 | wpa_printf(MSG_ERROR, "malloc failed"); |
| 985 | return -1; |
| 986 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 987 | } |
| 988 | |
Dmitry Shmidt | 4b06059 | 2013-04-29 16:42:49 -0700 | [diff] [blame] | 989 | if (hostapd_global_init(&interfaces, entropy_file)) { |
Dmitry Shmidt | 7a53dbb | 2015-06-11 13:13:53 -0700 | [diff] [blame] | 990 | wpa_printf(MSG_ERROR, "Failed to initialize global context"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 991 | return -1; |
Dmitry Shmidt | 4b06059 | 2013-04-29 16:42:49 -0700 | [diff] [blame] | 992 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 993 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 994 | eloop_register_timeout(HOSTAPD_CLEANUP_INTERVAL, 0, |
| 995 | hostapd_periodic, &interfaces, NULL); |
| 996 | |
| 997 | if (fst_global_init()) { |
| 998 | wpa_printf(MSG_ERROR, |
| 999 | "Failed to initialize global FST context"); |
| 1000 | goto out; |
| 1001 | } |
| 1002 | |
| 1003 | #if defined(CONFIG_FST) && defined(CONFIG_CTRL_IFACE) |
| 1004 | if (!fst_global_add_ctrl(fst_ctrl_cli)) |
| 1005 | wpa_printf(MSG_WARNING, "Failed to add CLI FST ctrl"); |
| 1006 | #endif /* CONFIG_FST && CONFIG_CTRL_IFACE */ |
| 1007 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1008 | /* Allocate and parse configuration for full interface files */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1009 | for (i = 0; i < interfaces.count; i++) { |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 1010 | char *if_name = NULL; |
| 1011 | |
| 1012 | if (i < if_names_size) |
| 1013 | if_name = if_names[i]; |
| 1014 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1015 | interfaces.iface[i] = hostapd_interface_init(&interfaces, |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 1016 | if_name, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1017 | argv[optind + i], |
| 1018 | debug); |
Dmitry Shmidt | 4b06059 | 2013-04-29 16:42:49 -0700 | [diff] [blame] | 1019 | if (!interfaces.iface[i]) { |
| 1020 | wpa_printf(MSG_ERROR, "Failed to initialize interface"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1021 | goto out; |
Dmitry Shmidt | 4b06059 | 2013-04-29 16:42:49 -0700 | [diff] [blame] | 1022 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1023 | if (start_ifaces_in_sync) |
| 1024 | interfaces.iface[i]->need_to_start_in_sync = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1025 | } |
| 1026 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1027 | /* Allocate and parse configuration for per-BSS files */ |
| 1028 | for (i = 0; i < num_bss_configs; i++) { |
| 1029 | struct hostapd_iface *iface; |
| 1030 | char *fname; |
| 1031 | |
| 1032 | wpa_printf(MSG_INFO, "BSS config: %s", bss_config[i]); |
| 1033 | fname = os_strchr(bss_config[i], ':'); |
| 1034 | if (fname == NULL) { |
| 1035 | wpa_printf(MSG_ERROR, |
| 1036 | "Invalid BSS config identifier '%s'", |
| 1037 | bss_config[i]); |
| 1038 | goto out; |
| 1039 | } |
| 1040 | *fname++ = '\0'; |
| 1041 | iface = hostapd_interface_init_bss(&interfaces, bss_config[i], |
| 1042 | fname, debug); |
| 1043 | if (iface == NULL) |
| 1044 | goto out; |
| 1045 | for (j = 0; j < interfaces.count; j++) { |
| 1046 | if (interfaces.iface[j] == iface) |
| 1047 | break; |
| 1048 | } |
| 1049 | if (j == interfaces.count) { |
| 1050 | struct hostapd_iface **tmp; |
| 1051 | tmp = os_realloc_array(interfaces.iface, |
| 1052 | interfaces.count + 1, |
| 1053 | sizeof(struct hostapd_iface *)); |
| 1054 | if (tmp == NULL) { |
| 1055 | hostapd_interface_deinit_free(iface); |
| 1056 | goto out; |
| 1057 | } |
| 1058 | interfaces.iface = tmp; |
| 1059 | interfaces.iface[interfaces.count++] = iface; |
| 1060 | } |
| 1061 | } |
| 1062 | |
| 1063 | /* |
| 1064 | * Enable configured interfaces. Depending on channel configuration, |
| 1065 | * this may complete full initialization before returning or use a |
| 1066 | * callback mechanism to complete setup in case of operations like HT |
| 1067 | * co-ex scans, ACS, or DFS are needed to determine channel parameters. |
| 1068 | * In such case, the interface will be enabled from eloop context within |
| 1069 | * hostapd_global_run(). |
| 1070 | */ |
Dmitry Shmidt | b96dad4 | 2013-11-05 10:07:29 -0800 | [diff] [blame] | 1071 | interfaces.terminate_on_error = interfaces.count; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1072 | for (i = 0; i < interfaces.count; i++) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 1073 | if (hostapd_driver_init(interfaces.iface[i]) || |
| 1074 | hostapd_setup_interface(interfaces.iface[i])) |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1075 | goto out; |
| 1076 | } |
| 1077 | |
Daichi Ueura | caa74a8 | 2018-02-14 22:25:39 +0900 | [diff] [blame] | 1078 | hostapd_global_ctrl_iface_init(&interfaces); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1079 | |
Dmitry Shmidt | 4b06059 | 2013-04-29 16:42:49 -0700 | [diff] [blame] | 1080 | if (hostapd_global_run(&interfaces, daemonize, pid_file)) { |
| 1081 | wpa_printf(MSG_ERROR, "Failed to start eloop"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1082 | goto out; |
Dmitry Shmidt | 4b06059 | 2013-04-29 16:42:49 -0700 | [diff] [blame] | 1083 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1084 | |
| 1085 | ret = 0; |
| 1086 | |
| 1087 | out: |
Gabriel Biren | 72cf9a5 | 2021-06-25 23:29:26 +0000 | [diff] [blame] | 1088 | #ifdef CONFIG_CTRL_IFACE_AIDL |
| 1089 | hostapd_aidl_deinit(&interfaces); |
| 1090 | #endif /* CONFIG_CTRL_IFACE_AIDL */ |
Daichi Ueura | caa74a8 | 2018-02-14 22:25:39 +0900 | [diff] [blame] | 1091 | hostapd_global_ctrl_iface_deinit(&interfaces); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1092 | /* Deinitialize all interfaces */ |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 1093 | for (i = 0; i < interfaces.count; i++) { |
Dmitry Shmidt | 818ea48 | 2014-03-10 13:15:21 -0700 | [diff] [blame] | 1094 | if (!interfaces.iface[i]) |
| 1095 | continue; |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 1096 | interfaces.iface[i]->driver_ap_teardown = |
| 1097 | !!(interfaces.iface[i]->drv_flags & |
| 1098 | WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1099 | hostapd_interface_deinit_free(interfaces.iface[i]); |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 1100 | interfaces.iface[i] = NULL; |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 1101 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1102 | os_free(interfaces.iface); |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 1103 | interfaces.iface = NULL; |
| 1104 | interfaces.count = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1105 | |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 1106 | hostapd_global_cleanup_mld(&interfaces); |
| 1107 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1108 | #ifdef CONFIG_DPP |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1109 | dpp_global_deinit(interfaces.dpp); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1110 | #endif /* CONFIG_DPP */ |
| 1111 | |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 1112 | if (interfaces.eloop_initialized) |
| 1113 | eloop_cancel_timeout(hostapd_periodic, &interfaces, NULL); |
| 1114 | hostapd_global_deinit(pid_file, interfaces.eloop_initialized); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1115 | os_free(pid_file); |
| 1116 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 1117 | wpa_debug_close_syslog(); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1118 | if (log_file) |
| 1119 | wpa_debug_close_file(); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1120 | wpa_debug_close_linux_tracing(); |
| 1121 | |
| 1122 | os_free(bss_config); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1123 | |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 1124 | for (i = 0; i < if_names_size; i++) |
| 1125 | os_free(if_names[i]); |
| 1126 | os_free(if_names); |
| 1127 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1128 | fst_global_deinit(); |
| 1129 | |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 1130 | crypto_unload(); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1131 | os_program_deinit(); |
| 1132 | |
| 1133 | return ret; |
| 1134 | } |