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