Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * hostapd / Initialization and configuration |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3 | * Copyright (c) 2002-2021, 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" |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 10 | #ifdef CONFIG_SQLITE |
| 11 | #include <sqlite3.h> |
| 12 | #endif /* CONFIG_SQLITE */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 13 | |
| 14 | #include "utils/common.h" |
| 15 | #include "utils/eloop.h" |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 16 | #include "utils/crc32.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 17 | #include "common/ieee802_11_defs.h" |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 18 | #include "common/wpa_ctrl.h" |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 19 | #include "common/hw_features_common.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 20 | #include "radius/radius_client.h" |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 21 | #include "radius/radius_das.h" |
Dmitry Shmidt | 50b691d | 2014-05-21 14:01:45 -0700 | [diff] [blame] | 22 | #include "eap_server/tncs.h" |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 23 | #include "eapol_auth/eapol_auth_sm.h" |
| 24 | #include "eapol_auth/eapol_auth_sm_i.h" |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 25 | #include "fst/fst.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 26 | #include "hostapd.h" |
| 27 | #include "authsrv.h" |
| 28 | #include "sta_info.h" |
| 29 | #include "accounting.h" |
| 30 | #include "ap_list.h" |
| 31 | #include "beacon.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 32 | #include "ieee802_1x.h" |
| 33 | #include "ieee802_11_auth.h" |
| 34 | #include "vlan_init.h" |
| 35 | #include "wpa_auth.h" |
| 36 | #include "wps_hostapd.h" |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 37 | #include "dpp_hostapd.h" |
Sunil Ravi | 72e0122 | 2024-03-09 01:25:43 +0000 | [diff] [blame] | 38 | #include "nan_usd_ap.h" |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 39 | #include "gas_query_ap.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 40 | #include "hw_features.h" |
| 41 | #include "wpa_auth_glue.h" |
| 42 | #include "ap_drv_ops.h" |
| 43 | #include "ap_config.h" |
| 44 | #include "p2p_hostapd.h" |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 45 | #include "gas_serv.h" |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 46 | #include "dfs.h" |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 47 | #include "ieee802_11.h" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 48 | #include "bss_load.h" |
| 49 | #include "x_snoop.h" |
| 50 | #include "dhcp_snoop.h" |
| 51 | #include "ndisc_snoop.h" |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 52 | #include "neighbor_db.h" |
| 53 | #include "rrm.h" |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 54 | #include "fils_hlp.h" |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 55 | #include "acs.h" |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 56 | #include "hs20.h" |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 57 | #include "airtime_policy.h" |
| 58 | #include "wpa_auth_kay.h" |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 59 | #include "hw_features.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 60 | |
| 61 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 62 | static int hostapd_flush_old_stations(struct hostapd_data *hapd, u16 reason); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 63 | #ifdef CONFIG_WEP |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 64 | static int hostapd_setup_encryption(char *iface, struct hostapd_data *hapd); |
Dmitry Shmidt | c55524a | 2011-07-07 11:18:38 -0700 | [diff] [blame] | 65 | static int hostapd_broadcast_wep_clear(struct hostapd_data *hapd); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 66 | #endif /* CONFIG_WEP */ |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 67 | static int setup_interface2(struct hostapd_iface *iface); |
| 68 | static void channel_list_update_timeout(void *eloop_ctx, void *timeout_ctx); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 69 | static void hostapd_interface_setup_failure_handler(void *eloop_ctx, |
| 70 | void *timeout_ctx); |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 71 | #ifdef CONFIG_IEEE80211AX |
| 72 | static void hostapd_switch_color_timeout_handler(void *eloop_data, |
| 73 | void *user_ctx); |
| 74 | #endif /* CONFIG_IEEE80211AX */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 75 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 76 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 77 | int hostapd_for_each_interface(struct hapd_interfaces *interfaces, |
| 78 | int (*cb)(struct hostapd_iface *iface, |
| 79 | void *ctx), void *ctx) |
| 80 | { |
| 81 | size_t i; |
| 82 | int ret; |
| 83 | |
| 84 | for (i = 0; i < interfaces->count; i++) { |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 85 | if (!interfaces->iface[i]) |
| 86 | continue; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 87 | ret = cb(interfaces->iface[i], ctx); |
| 88 | if (ret) |
| 89 | return ret; |
| 90 | } |
| 91 | |
| 92 | return 0; |
| 93 | } |
| 94 | |
| 95 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 96 | struct hostapd_data * hostapd_mbssid_get_tx_bss(struct hostapd_data *hapd) |
| 97 | { |
| 98 | if (hapd->iconf->mbssid) |
| 99 | return hapd->iface->bss[0]; |
| 100 | |
| 101 | return hapd; |
| 102 | } |
| 103 | |
| 104 | |
| 105 | int hostapd_mbssid_get_bss_index(struct hostapd_data *hapd) |
| 106 | { |
| 107 | if (hapd->iconf->mbssid) { |
| 108 | size_t i; |
| 109 | |
| 110 | for (i = 1; i < hapd->iface->num_bss; i++) |
| 111 | if (hapd->iface->bss[i] == hapd) |
| 112 | return i; |
| 113 | } |
| 114 | |
| 115 | return 0; |
| 116 | } |
| 117 | |
| 118 | |
Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 119 | void hostapd_reconfig_encryption(struct hostapd_data *hapd) |
| 120 | { |
| 121 | if (hapd->wpa_auth) |
| 122 | return; |
| 123 | |
| 124 | hostapd_set_privacy(hapd, 0); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 125 | #ifdef CONFIG_WEP |
Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 126 | hostapd_setup_encryption(hapd->conf->iface, hapd); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 127 | #endif /* CONFIG_WEP */ |
Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 131 | static void hostapd_reload_bss(struct hostapd_data *hapd) |
| 132 | { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 133 | struct hostapd_ssid *ssid; |
| 134 | |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 135 | if (!hapd->started) |
| 136 | return; |
| 137 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 138 | if (hapd->conf->wmm_enabled < 0) |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 139 | hapd->conf->wmm_enabled = hapd->iconf->ieee80211n | |
| 140 | hapd->iconf->ieee80211ax; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 141 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 142 | #ifndef CONFIG_NO_RADIUS |
| 143 | radius_client_reconfig(hapd->radius, hapd->conf->radius); |
| 144 | #endif /* CONFIG_NO_RADIUS */ |
| 145 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 146 | ssid = &hapd->conf->ssid; |
| 147 | if (!ssid->wpa_psk_set && ssid->wpa_psk && !ssid->wpa_psk->next && |
| 148 | ssid->wpa_passphrase_set && ssid->wpa_passphrase) { |
| 149 | /* |
| 150 | * Force PSK to be derived again since SSID or passphrase may |
| 151 | * have changed. |
| 152 | */ |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 153 | hostapd_config_clear_wpa_psk(&hapd->conf->ssid.wpa_psk); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 154 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 155 | if (hostapd_setup_wpa_psk(hapd->conf)) { |
| 156 | wpa_printf(MSG_ERROR, "Failed to re-configure WPA PSK " |
| 157 | "after reloading configuration"); |
| 158 | } |
| 159 | |
| 160 | if (hapd->conf->ieee802_1x || hapd->conf->wpa) |
| 161 | hostapd_set_drv_ieee8021x(hapd, hapd->conf->iface, 1); |
| 162 | else |
| 163 | hostapd_set_drv_ieee8021x(hapd, hapd->conf->iface, 0); |
| 164 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 165 | if ((hapd->conf->wpa || hapd->conf->osen) && hapd->wpa_auth == NULL) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 166 | hostapd_setup_wpa(hapd); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 167 | if (hapd->wpa_auth) |
| 168 | wpa_init_keys(hapd->wpa_auth); |
| 169 | } else if (hapd->conf->wpa) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 170 | const u8 *wpa_ie; |
| 171 | size_t wpa_ie_len; |
| 172 | hostapd_reconfig_wpa(hapd); |
| 173 | wpa_ie = wpa_auth_get_wpa_ie(hapd->wpa_auth, &wpa_ie_len); |
| 174 | if (hostapd_set_generic_elem(hapd, wpa_ie, wpa_ie_len)) |
| 175 | wpa_printf(MSG_ERROR, "Failed to configure WPA IE for " |
| 176 | "the kernel driver."); |
| 177 | } else if (hapd->wpa_auth) { |
| 178 | wpa_deinit(hapd->wpa_auth); |
| 179 | hapd->wpa_auth = NULL; |
| 180 | hostapd_set_privacy(hapd, 0); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 181 | #ifdef CONFIG_WEP |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 182 | hostapd_setup_encryption(hapd->conf->iface, hapd); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 183 | #endif /* CONFIG_WEP */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 184 | hostapd_set_generic_elem(hapd, (u8 *) "", 0); |
| 185 | } |
| 186 | |
Sunil Ravi | af399a8 | 2024-05-05 20:56:55 +0000 | [diff] [blame^] | 187 | hostapd_neighbor_sync_own_report(hapd); |
| 188 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 189 | ieee802_11_set_beacon(hapd); |
| 190 | hostapd_update_wps(hapd); |
| 191 | |
| 192 | if (hapd->conf->ssid.ssid_set && |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 193 | hostapd_set_ssid(hapd, hapd->conf->ssid.ssid, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 194 | hapd->conf->ssid.ssid_len)) { |
| 195 | wpa_printf(MSG_ERROR, "Could not set SSID for kernel driver"); |
| 196 | /* try to continue */ |
| 197 | } |
| 198 | wpa_printf(MSG_DEBUG, "Reconfigured interface %s", hapd->conf->iface); |
| 199 | } |
| 200 | |
| 201 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 202 | static void hostapd_clear_old_bss(struct hostapd_data *bss) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 203 | { |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 204 | wpa_printf(MSG_DEBUG, "BSS %s changed - clear old state", |
| 205 | bss->conf->iface); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 206 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 207 | /* |
| 208 | * Deauthenticate all stations since the new configuration may not |
| 209 | * allow them to use the BSS anymore. |
| 210 | */ |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 211 | hostapd_flush_old_stations(bss, WLAN_REASON_PREV_AUTH_NOT_VALID); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 212 | #ifdef CONFIG_WEP |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 213 | hostapd_broadcast_wep_clear(bss); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 214 | #endif /* CONFIG_WEP */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 215 | |
| 216 | #ifndef CONFIG_NO_RADIUS |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 217 | /* TODO: update dynamic data based on changed configuration |
| 218 | * items (e.g., open/close sockets, etc.) */ |
| 219 | radius_client_flush(bss->radius, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 220 | #endif /* CONFIG_NO_RADIUS */ |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | |
| 224 | static void hostapd_clear_old(struct hostapd_iface *iface) |
| 225 | { |
| 226 | size_t j; |
| 227 | |
| 228 | for (j = 0; j < iface->num_bss; j++) |
| 229 | hostapd_clear_old_bss(iface->bss[j]); |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 233 | static int hostapd_iface_conf_changed(struct hostapd_config *newconf, |
| 234 | struct hostapd_config *oldconf) |
| 235 | { |
| 236 | size_t i; |
| 237 | |
| 238 | if (newconf->num_bss != oldconf->num_bss) |
| 239 | return 1; |
| 240 | |
| 241 | for (i = 0; i < newconf->num_bss; i++) { |
| 242 | if (os_strcmp(newconf->bss[i]->iface, |
| 243 | oldconf->bss[i]->iface) != 0) |
| 244 | return 1; |
| 245 | } |
| 246 | |
| 247 | return 0; |
| 248 | } |
| 249 | |
| 250 | |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 251 | int hostapd_reload_config(struct hostapd_iface *iface) |
| 252 | { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 253 | struct hapd_interfaces *interfaces = iface->interfaces; |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 254 | struct hostapd_data *hapd = iface->bss[0]; |
| 255 | struct hostapd_config *newconf, *oldconf; |
| 256 | size_t j; |
| 257 | |
| 258 | if (iface->config_fname == NULL) { |
| 259 | /* Only in-memory config in use - assume it has been updated */ |
| 260 | hostapd_clear_old(iface); |
| 261 | for (j = 0; j < iface->num_bss; j++) |
| 262 | hostapd_reload_bss(iface->bss[j]); |
| 263 | return 0; |
| 264 | } |
| 265 | |
| 266 | if (iface->interfaces == NULL || |
| 267 | iface->interfaces->config_read_cb == NULL) |
| 268 | return -1; |
| 269 | newconf = iface->interfaces->config_read_cb(iface->config_fname); |
| 270 | if (newconf == NULL) |
| 271 | return -1; |
| 272 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 273 | oldconf = hapd->iconf; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 274 | if (hostapd_iface_conf_changed(newconf, oldconf)) { |
| 275 | char *fname; |
| 276 | int res; |
| 277 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 278 | hostapd_clear_old(iface); |
| 279 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 280 | wpa_printf(MSG_DEBUG, |
| 281 | "Configuration changes include interface/BSS modification - force full disable+enable sequence"); |
| 282 | fname = os_strdup(iface->config_fname); |
| 283 | if (!fname) { |
| 284 | hostapd_config_free(newconf); |
| 285 | return -1; |
| 286 | } |
| 287 | hostapd_remove_iface(interfaces, hapd->conf->iface); |
| 288 | iface = hostapd_init(interfaces, fname); |
| 289 | os_free(fname); |
| 290 | hostapd_config_free(newconf); |
| 291 | if (!iface) { |
| 292 | wpa_printf(MSG_ERROR, |
| 293 | "Failed to initialize interface on config reload"); |
| 294 | return -1; |
| 295 | } |
| 296 | iface->interfaces = interfaces; |
| 297 | interfaces->iface[interfaces->count] = iface; |
| 298 | interfaces->count++; |
| 299 | res = hostapd_enable_iface(iface); |
| 300 | if (res < 0) |
| 301 | wpa_printf(MSG_ERROR, |
| 302 | "Failed to enable interface on config reload"); |
| 303 | return res; |
| 304 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 305 | iface->conf = newconf; |
| 306 | |
| 307 | for (j = 0; j < iface->num_bss; j++) { |
| 308 | hapd = iface->bss[j]; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 309 | if (!hapd->conf->config_id || !newconf->bss[j]->config_id || |
| 310 | os_strcmp(hapd->conf->config_id, |
| 311 | newconf->bss[j]->config_id) != 0) |
| 312 | hostapd_clear_old_bss(hapd); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 313 | hapd->iconf = newconf; |
Dmitry Shmidt | d11f019 | 2014-03-24 12:09:47 -0700 | [diff] [blame] | 314 | hapd->iconf->channel = oldconf->channel; |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 315 | hapd->iconf->acs = oldconf->acs; |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 316 | hapd->iconf->secondary_channel = oldconf->secondary_channel; |
Dmitry Shmidt | d11f019 | 2014-03-24 12:09:47 -0700 | [diff] [blame] | 317 | hapd->iconf->ieee80211n = oldconf->ieee80211n; |
| 318 | hapd->iconf->ieee80211ac = oldconf->ieee80211ac; |
| 319 | hapd->iconf->ht_capab = oldconf->ht_capab; |
| 320 | hapd->iconf->vht_capab = oldconf->vht_capab; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 321 | hostapd_set_oper_chwidth(hapd->iconf, |
| 322 | hostapd_get_oper_chwidth(oldconf)); |
| 323 | hostapd_set_oper_centr_freq_seg0_idx( |
| 324 | hapd->iconf, |
| 325 | hostapd_get_oper_centr_freq_seg0_idx(oldconf)); |
| 326 | hostapd_set_oper_centr_freq_seg1_idx( |
| 327 | hapd->iconf, |
| 328 | hostapd_get_oper_centr_freq_seg1_idx(oldconf)); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 329 | hapd->conf = newconf->bss[j]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 330 | hostapd_reload_bss(hapd); |
| 331 | } |
| 332 | |
| 333 | hostapd_config_free(oldconf); |
| 334 | |
| 335 | |
| 336 | return 0; |
| 337 | } |
| 338 | |
| 339 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 340 | #ifdef CONFIG_WEP |
| 341 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 342 | static void hostapd_broadcast_key_clear_iface(struct hostapd_data *hapd, |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 343 | const char *ifname) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 344 | { |
| 345 | int i; |
| 346 | |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 347 | if (!ifname || !hapd->drv_priv) |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 348 | return; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 349 | for (i = 0; i < NUM_WEP_KEYS; i++) { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 350 | if (hostapd_drv_set_key(ifname, hapd, WPA_ALG_NONE, NULL, i, 0, |
| 351 | 0, NULL, 0, NULL, 0, KEY_FLAG_GROUP)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 352 | wpa_printf(MSG_DEBUG, "Failed to clear default " |
| 353 | "encryption keys (ifname=%s keyidx=%d)", |
| 354 | ifname, i); |
| 355 | } |
| 356 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 357 | if (hapd->conf->ieee80211w) { |
| 358 | for (i = NUM_WEP_KEYS; i < NUM_WEP_KEYS + 2; i++) { |
| 359 | if (hostapd_drv_set_key(ifname, hapd, WPA_ALG_NONE, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 360 | NULL, i, 0, 0, NULL, |
| 361 | 0, NULL, 0, KEY_FLAG_GROUP)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 362 | wpa_printf(MSG_DEBUG, "Failed to clear " |
| 363 | "default mgmt encryption keys " |
| 364 | "(ifname=%s keyidx=%d)", ifname, i); |
| 365 | } |
| 366 | } |
| 367 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | |
| 371 | static int hostapd_broadcast_wep_clear(struct hostapd_data *hapd) |
| 372 | { |
| 373 | hostapd_broadcast_key_clear_iface(hapd, hapd->conf->iface); |
| 374 | return 0; |
| 375 | } |
| 376 | |
| 377 | |
| 378 | static int hostapd_broadcast_wep_set(struct hostapd_data *hapd) |
| 379 | { |
| 380 | int errors = 0, idx; |
| 381 | struct hostapd_ssid *ssid = &hapd->conf->ssid; |
| 382 | |
| 383 | idx = ssid->wep.idx; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 384 | if (ssid->wep.default_len && ssid->wep.key[idx] && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 385 | hostapd_drv_set_key(hapd->conf->iface, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 386 | hapd, WPA_ALG_WEP, broadcast_ether_addr, idx, 0, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 387 | 1, NULL, 0, ssid->wep.key[idx], |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 388 | ssid->wep.len[idx], |
| 389 | KEY_FLAG_GROUP_RX_TX_DEFAULT)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 390 | wpa_printf(MSG_WARNING, "Could not set WEP encryption."); |
| 391 | errors++; |
| 392 | } |
| 393 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 394 | return errors; |
| 395 | } |
| 396 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 397 | #endif /* CONFIG_WEP */ |
| 398 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 399 | |
Sunil Ravi | 72e0122 | 2024-03-09 01:25:43 +0000 | [diff] [blame] | 400 | #ifdef CONFIG_IEEE80211BE |
| 401 | #ifdef CONFIG_TESTING_OPTIONS |
| 402 | |
| 403 | #define TU_TO_USEC(_val) ((_val) * 1024) |
| 404 | |
| 405 | static void hostapd_link_remove_timeout_handler(void *eloop_data, |
| 406 | void *user_ctx) |
| 407 | { |
| 408 | struct hostapd_data *hapd = (struct hostapd_data *) eloop_data; |
| 409 | |
| 410 | if (hapd->eht_mld_link_removal_count == 0) |
| 411 | return; |
| 412 | hapd->eht_mld_link_removal_count--; |
| 413 | |
| 414 | wpa_printf(MSG_DEBUG, "MLD: Remove link_id=%u in %u beacons", |
| 415 | hapd->mld_link_id, |
| 416 | hapd->eht_mld_link_removal_count); |
| 417 | |
| 418 | ieee802_11_set_beacon(hapd); |
| 419 | |
| 420 | if (!hapd->eht_mld_link_removal_count) { |
Sunil Ravi | af399a8 | 2024-05-05 20:56:55 +0000 | [diff] [blame^] | 421 | hostapd_free_link_stas(hapd); |
Sunil Ravi | 72e0122 | 2024-03-09 01:25:43 +0000 | [diff] [blame] | 422 | hostapd_disable_iface(hapd->iface); |
| 423 | return; |
| 424 | } |
| 425 | |
| 426 | eloop_register_timeout(0, TU_TO_USEC(hapd->iconf->beacon_int), |
| 427 | hostapd_link_remove_timeout_handler, |
| 428 | hapd, NULL); |
| 429 | } |
| 430 | |
| 431 | |
| 432 | int hostapd_link_remove(struct hostapd_data *hapd, u32 count) |
| 433 | { |
| 434 | if (!hapd->conf->mld_ap) |
| 435 | return -1; |
| 436 | |
| 437 | wpa_printf(MSG_DEBUG, |
| 438 | "MLD: Remove link_id=%u in %u beacons", |
| 439 | hapd->mld_link_id, count); |
| 440 | |
| 441 | hapd->eht_mld_link_removal_count = count; |
| 442 | hapd->eht_mld_bss_param_change++; |
| 443 | |
| 444 | eloop_register_timeout(0, TU_TO_USEC(hapd->iconf->beacon_int), |
| 445 | hostapd_link_remove_timeout_handler, |
| 446 | hapd, NULL); |
| 447 | |
| 448 | ieee802_11_set_beacon(hapd); |
| 449 | return 0; |
| 450 | } |
| 451 | |
| 452 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 453 | #endif /* CONFIG_IEEE80211BE */ |
| 454 | |
| 455 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 456 | void hostapd_free_hapd_data(struct hostapd_data *hapd) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 457 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 458 | os_free(hapd->probereq_cb); |
| 459 | hapd->probereq_cb = NULL; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 460 | hapd->num_probereq_cb = 0; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 461 | |
| 462 | #ifdef CONFIG_P2P |
| 463 | wpabuf_free(hapd->p2p_beacon_ie); |
| 464 | hapd->p2p_beacon_ie = NULL; |
| 465 | wpabuf_free(hapd->p2p_probe_resp_ie); |
| 466 | hapd->p2p_probe_resp_ie = NULL; |
| 467 | #endif /* CONFIG_P2P */ |
| 468 | |
Dmitry Shmidt | fa3fc4a | 2013-11-21 13:34:38 -0800 | [diff] [blame] | 469 | if (!hapd->started) { |
| 470 | wpa_printf(MSG_ERROR, "%s: Interface %s wasn't started", |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 471 | __func__, hapd->conf ? hapd->conf->iface : "N/A"); |
Dmitry Shmidt | fa3fc4a | 2013-11-21 13:34:38 -0800 | [diff] [blame] | 472 | return; |
| 473 | } |
| 474 | hapd->started = 0; |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 475 | hapd->beacon_set_done = 0; |
Dmitry Shmidt | fa3fc4a | 2013-11-21 13:34:38 -0800 | [diff] [blame] | 476 | |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 477 | wpa_printf(MSG_DEBUG, "%s(%s)", __func__, hapd->conf->iface); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 478 | accounting_deinit(hapd); |
| 479 | hostapd_deinit_wpa(hapd); |
| 480 | vlan_deinit(hapd); |
| 481 | hostapd_acl_deinit(hapd); |
| 482 | #ifndef CONFIG_NO_RADIUS |
Sunil Ravi | af399a8 | 2024-05-05 20:56:55 +0000 | [diff] [blame^] | 483 | if (hostapd_mld_is_first_bss(hapd)) { |
| 484 | #ifdef CONFIG_IEEE80211BE |
Sunil Ravi | 72e0122 | 2024-03-09 01:25:43 +0000 | [diff] [blame] | 485 | struct hapd_interfaces *ifaces = hapd->iface->interfaces; |
| 486 | size_t i; |
| 487 | |
| 488 | for (i = 0; i < ifaces->count; i++) { |
| 489 | struct hostapd_iface *iface = ifaces->iface[i]; |
| 490 | size_t j; |
| 491 | |
| 492 | for (j = 0; iface && j < iface->num_bss; j++) { |
| 493 | struct hostapd_data *h = iface->bss[j]; |
| 494 | |
| 495 | if (hapd == h) |
| 496 | continue; |
| 497 | if (h->radius == hapd->radius) |
| 498 | h->radius = NULL; |
| 499 | if (h->radius_das == hapd->radius_das) |
| 500 | h->radius_das = NULL; |
| 501 | } |
| 502 | } |
Sunil Ravi | af399a8 | 2024-05-05 20:56:55 +0000 | [diff] [blame^] | 503 | #endif /* CONFIG_IEEE80211BE */ |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 504 | radius_client_deinit(hapd->radius); |
| 505 | radius_das_deinit(hapd->radius_das); |
| 506 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 507 | hapd->radius = NULL; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 508 | hapd->radius_das = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 509 | #endif /* CONFIG_NO_RADIUS */ |
| 510 | |
| 511 | hostapd_deinit_wps(hapd); |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 512 | ieee802_1x_dealloc_kay_sm_hapd(hapd); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 513 | #ifdef CONFIG_DPP |
| 514 | hostapd_dpp_deinit(hapd); |
| 515 | gas_query_ap_deinit(hapd->gas); |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 516 | hapd->gas = NULL; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 517 | #endif /* CONFIG_DPP */ |
Sunil Ravi | 72e0122 | 2024-03-09 01:25:43 +0000 | [diff] [blame] | 518 | #ifdef CONFIG_NAN_USD |
| 519 | hostapd_nan_usd_deinit(hapd); |
| 520 | #endif /* CONFIG_NAN_USD */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 521 | |
| 522 | authsrv_deinit(hapd); |
| 523 | |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 524 | if (hapd->interface_added) { |
| 525 | hapd->interface_added = 0; |
| 526 | if (hostapd_if_remove(hapd, WPA_IF_AP_BSS, hapd->conf->iface)) { |
| 527 | wpa_printf(MSG_WARNING, |
| 528 | "Failed to remove BSS interface %s", |
| 529 | hapd->conf->iface); |
| 530 | hapd->interface_added = 1; |
| 531 | } else { |
| 532 | /* |
| 533 | * Since this was a dynamically added interface, the |
| 534 | * driver wrapper may have removed its internal instance |
| 535 | * and hapd->drv_priv is not valid anymore. |
| 536 | */ |
Sunil Ravi | af399a8 | 2024-05-05 20:56:55 +0000 | [diff] [blame^] | 537 | hapd->drv_priv = NULL; |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 538 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 539 | } |
| 540 | |
Sunil Ravi | af399a8 | 2024-05-05 20:56:55 +0000 | [diff] [blame^] | 541 | #ifdef CONFIG_IEEE80211BE |
| 542 | /* If the interface was not added as well as it is not the first BSS, |
| 543 | * at least the link should be removed here since deinit will take care |
| 544 | * of only the first BSS. */ |
| 545 | if (hapd->conf->mld_ap && !hapd->interface_added && |
| 546 | hapd->iface->bss[0] != hapd) |
| 547 | hostapd_if_link_remove(hapd, WPA_IF_AP_BSS, hapd->conf->iface, |
| 548 | hapd->mld_link_id); |
| 549 | #endif /* CONFIG_IEEE80211BE */ |
| 550 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 551 | wpabuf_free(hapd->time_adv); |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 552 | hapd->time_adv = NULL; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 553 | |
| 554 | #ifdef CONFIG_INTERWORKING |
| 555 | gas_serv_deinit(hapd); |
| 556 | #endif /* CONFIG_INTERWORKING */ |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 557 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 558 | bss_load_update_deinit(hapd); |
| 559 | ndisc_snoop_deinit(hapd); |
| 560 | dhcp_snoop_deinit(hapd); |
| 561 | x_snoop_deinit(hapd); |
| 562 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 563 | #ifdef CONFIG_SQLITE |
Dmitry Shmidt | c281702 | 2014-07-02 10:32:10 -0700 | [diff] [blame] | 564 | bin_clear_free(hapd->tmp_eap_user.identity, |
| 565 | hapd->tmp_eap_user.identity_len); |
| 566 | bin_clear_free(hapd->tmp_eap_user.password, |
| 567 | hapd->tmp_eap_user.password_len); |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 568 | os_memset(&hapd->tmp_eap_user, 0, sizeof(hapd->tmp_eap_user)); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 569 | #endif /* CONFIG_SQLITE */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 570 | |
| 571 | #ifdef CONFIG_MESH |
| 572 | wpabuf_free(hapd->mesh_pending_auth); |
| 573 | hapd->mesh_pending_auth = NULL; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 574 | /* handling setup failure is already done */ |
| 575 | hapd->setup_complete_cb = NULL; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 576 | #endif /* CONFIG_MESH */ |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 577 | |
Sunil Ravi | 72e0122 | 2024-03-09 01:25:43 +0000 | [diff] [blame] | 578 | #ifndef CONFIG_NO_RRM |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 579 | hostapd_clean_rrm(hapd); |
Sunil Ravi | 72e0122 | 2024-03-09 01:25:43 +0000 | [diff] [blame] | 580 | #endif /* CONFIG_NO_RRM */ |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 581 | fils_hlp_deinit(hapd); |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 582 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 583 | #ifdef CONFIG_OCV |
| 584 | eloop_cancel_timeout(hostapd_ocv_check_csa_sa_query, hapd, NULL); |
| 585 | #endif /* CONFIG_OCV */ |
| 586 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 587 | #ifdef CONFIG_SAE |
| 588 | { |
| 589 | struct hostapd_sae_commit_queue *q; |
| 590 | |
| 591 | while ((q = dl_list_first(&hapd->sae_commit_queue, |
| 592 | struct hostapd_sae_commit_queue, |
| 593 | list))) { |
| 594 | dl_list_del(&q->list); |
| 595 | os_free(q); |
| 596 | } |
| 597 | } |
| 598 | eloop_cancel_timeout(auth_sae_process_commit, hapd, NULL); |
| 599 | #endif /* CONFIG_SAE */ |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 600 | |
| 601 | #ifdef CONFIG_IEEE80211AX |
| 602 | eloop_cancel_timeout(hostapd_switch_color_timeout_handler, hapd, NULL); |
Sunil Ravi | 72e0122 | 2024-03-09 01:25:43 +0000 | [diff] [blame] | 603 | #ifdef CONFIG_TESTING_OPTIONS |
| 604 | #ifdef CONFIG_IEEE80211BE |
| 605 | eloop_cancel_timeout(hostapd_link_remove_timeout_handler, hapd, NULL); |
| 606 | #endif /* CONFIG_IEEE80211BE */ |
| 607 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 608 | |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 609 | #endif /* CONFIG_IEEE80211AX */ |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 610 | } |
| 611 | |
| 612 | |
Sunil Ravi | af399a8 | 2024-05-05 20:56:55 +0000 | [diff] [blame^] | 613 | /* hostapd_bss_link_deinit - Per-BSS ML cleanup (deinitialization) |
| 614 | * @hapd: Pointer to BSS data |
| 615 | * |
| 616 | * This function is used to unlink the BSS from the AP MLD. |
| 617 | * If the BSS being removed is the first link, the next link becomes the first |
| 618 | * link. |
| 619 | */ |
| 620 | static void hostapd_bss_link_deinit(struct hostapd_data *hapd) |
| 621 | { |
| 622 | #ifdef CONFIG_IEEE80211BE |
| 623 | if (!hapd->conf || !hapd->conf->mld_ap) |
| 624 | return; |
| 625 | |
| 626 | if (!hapd->mld->num_links) |
| 627 | return; |
| 628 | |
| 629 | /* If not started, not yet linked to the MLD. However, the first |
| 630 | * BSS is always linked since it is linked during driver_init(), and |
| 631 | * hence, need to remove it from the AP MLD. |
| 632 | */ |
| 633 | if (!hapd->started && hapd->iface->bss[0] != hapd) |
| 634 | return; |
| 635 | |
| 636 | /* The first BSS can also be only linked when at least driver_init() is |
| 637 | * executed. But if previous interface fails, it is not, and hence, |
| 638 | * safe to skip. |
| 639 | */ |
| 640 | if (hapd->iface->bss[0] == hapd && !hapd->drv_priv) |
| 641 | return; |
| 642 | |
| 643 | hostapd_mld_remove_link(hapd); |
| 644 | #endif /* CONFIG_IEEE80211BE */ |
| 645 | } |
| 646 | |
| 647 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 648 | /** |
| 649 | * hostapd_cleanup - Per-BSS cleanup (deinitialization) |
| 650 | * @hapd: Pointer to BSS data |
| 651 | * |
| 652 | * This function is used to free all per-BSS data structures and resources. |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 653 | * Most of the modules that are initialized in hostapd_setup_bss() are |
| 654 | * deinitialized here. |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 655 | */ |
| 656 | static void hostapd_cleanup(struct hostapd_data *hapd) |
| 657 | { |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 658 | wpa_printf(MSG_DEBUG, "%s(hapd=%p (%s))", __func__, hapd, |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 659 | hapd->conf ? hapd->conf->iface : "N/A"); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 660 | if (hapd->iface->interfaces && |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 661 | hapd->iface->interfaces->ctrl_iface_deinit) { |
| 662 | wpa_msg(hapd->msg_ctx, MSG_INFO, WPA_EVENT_TERMINATING); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 663 | hapd->iface->interfaces->ctrl_iface_deinit(hapd); |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 664 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 665 | hostapd_free_hapd_data(hapd); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 666 | } |
| 667 | |
| 668 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 669 | static void sta_track_deinit(struct hostapd_iface *iface) |
| 670 | { |
| 671 | struct hostapd_sta_info *info; |
| 672 | |
| 673 | if (!iface->num_sta_seen) |
| 674 | return; |
| 675 | |
| 676 | while ((info = dl_list_first(&iface->sta_seen, struct hostapd_sta_info, |
| 677 | list))) { |
| 678 | dl_list_del(&info->list); |
| 679 | iface->num_sta_seen--; |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 680 | sta_track_del(info); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 681 | } |
| 682 | } |
| 683 | |
| 684 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 685 | void hostapd_cleanup_iface_partial(struct hostapd_iface *iface) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 686 | { |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 687 | wpa_printf(MSG_DEBUG, "%s(%p)", __func__, iface); |
Sunil Ravi | af399a8 | 2024-05-05 20:56:55 +0000 | [diff] [blame^] | 688 | eloop_cancel_timeout(channel_list_update_timeout, iface, NULL); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 689 | #ifdef NEED_AP_MLME |
| 690 | hostapd_stop_setup_timers(iface); |
| 691 | #endif /* NEED_AP_MLME */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 692 | if (iface->current_mode) |
| 693 | acs_cleanup(iface); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 694 | hostapd_free_hw_features(iface->hw_features, iface->num_hw_features); |
| 695 | iface->hw_features = NULL; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 696 | iface->current_mode = NULL; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 697 | os_free(iface->current_rates); |
| 698 | iface->current_rates = NULL; |
| 699 | os_free(iface->basic_rates); |
| 700 | iface->basic_rates = NULL; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 701 | iface->cac_started = 0; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 702 | ap_list_deinit(iface); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 703 | sta_track_deinit(iface); |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 704 | airtime_policy_update_deinit(iface); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 705 | } |
| 706 | |
| 707 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 708 | /** |
| 709 | * hostapd_cleanup_iface - Complete per-interface cleanup |
| 710 | * @iface: Pointer to interface data |
| 711 | * |
| 712 | * This function is called after per-BSS data structures are deinitialized |
| 713 | * with hostapd_cleanup(). |
| 714 | */ |
| 715 | static void hostapd_cleanup_iface(struct hostapd_iface *iface) |
| 716 | { |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 717 | wpa_printf(MSG_DEBUG, "%s(%p)", __func__, iface); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 718 | eloop_cancel_timeout(hostapd_interface_setup_failure_handler, iface, |
| 719 | NULL); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 720 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 721 | hostapd_cleanup_iface_partial(iface); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 722 | hostapd_config_free(iface->conf); |
| 723 | iface->conf = NULL; |
| 724 | |
| 725 | os_free(iface->config_fname); |
| 726 | os_free(iface->bss); |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 727 | wpa_printf(MSG_DEBUG, "%s: free iface=%p", __func__, iface); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 728 | os_free(iface); |
| 729 | } |
| 730 | |
| 731 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 732 | #ifdef CONFIG_WEP |
| 733 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 734 | static void hostapd_clear_wep(struct hostapd_data *hapd) |
| 735 | { |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 736 | if (hapd->drv_priv && !hapd->iface->driver_ap_teardown && hapd->conf) { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 737 | hostapd_set_privacy(hapd, 0); |
| 738 | hostapd_broadcast_wep_clear(hapd); |
| 739 | } |
| 740 | } |
| 741 | |
| 742 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 743 | static int hostapd_setup_encryption(char *iface, struct hostapd_data *hapd) |
| 744 | { |
| 745 | int i; |
| 746 | |
| 747 | hostapd_broadcast_wep_set(hapd); |
| 748 | |
| 749 | if (hapd->conf->ssid.wep.default_len) { |
| 750 | hostapd_set_privacy(hapd, 1); |
| 751 | return 0; |
| 752 | } |
| 753 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 754 | /* |
| 755 | * When IEEE 802.1X is not enabled, the driver may need to know how to |
| 756 | * set authentication algorithms for static WEP. |
| 757 | */ |
| 758 | hostapd_drv_set_authmode(hapd, hapd->conf->auth_algs); |
| 759 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 760 | for (i = 0; i < 4; i++) { |
| 761 | if (hapd->conf->ssid.wep.key[i] && |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 762 | hostapd_drv_set_key(iface, hapd, WPA_ALG_WEP, NULL, i, 0, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 763 | i == hapd->conf->ssid.wep.idx, NULL, 0, |
| 764 | hapd->conf->ssid.wep.key[i], |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 765 | hapd->conf->ssid.wep.len[i], |
| 766 | i == hapd->conf->ssid.wep.idx ? |
| 767 | KEY_FLAG_GROUP_RX_TX_DEFAULT : |
| 768 | KEY_FLAG_GROUP_RX_TX)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 769 | wpa_printf(MSG_WARNING, "Could not set WEP " |
| 770 | "encryption."); |
| 771 | return -1; |
| 772 | } |
| 773 | if (hapd->conf->ssid.wep.key[i] && |
| 774 | i == hapd->conf->ssid.wep.idx) |
| 775 | hostapd_set_privacy(hapd, 1); |
| 776 | } |
| 777 | |
| 778 | return 0; |
| 779 | } |
| 780 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 781 | #endif /* CONFIG_WEP */ |
| 782 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 783 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 784 | static int hostapd_flush_old_stations(struct hostapd_data *hapd, u16 reason) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 785 | { |
| 786 | int ret = 0; |
| 787 | u8 addr[ETH_ALEN]; |
| 788 | |
| 789 | if (hostapd_drv_none(hapd) || hapd->drv_priv == NULL) |
| 790 | return 0; |
| 791 | |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 792 | if (!hapd->iface->driver_ap_teardown) { |
| 793 | wpa_dbg(hapd->msg_ctx, MSG_DEBUG, |
| 794 | "Flushing old station entries"); |
| 795 | |
| 796 | if (hostapd_flush(hapd)) { |
| 797 | wpa_msg(hapd->msg_ctx, MSG_WARNING, |
| 798 | "Could not connect to kernel driver"); |
| 799 | ret = -1; |
| 800 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 801 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 802 | if (hapd->conf && hapd->conf->broadcast_deauth) { |
| 803 | wpa_dbg(hapd->msg_ctx, MSG_DEBUG, |
| 804 | "Deauthenticate all stations"); |
| 805 | os_memset(addr, 0xff, ETH_ALEN); |
| 806 | hostapd_drv_sta_deauth(hapd, addr, reason); |
| 807 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 808 | hostapd_free_stas(hapd); |
| 809 | |
| 810 | return ret; |
| 811 | } |
| 812 | |
| 813 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 814 | void hostapd_bss_deinit_no_free(struct hostapd_data *hapd) |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 815 | { |
| 816 | hostapd_free_stas(hapd); |
| 817 | hostapd_flush_old_stations(hapd, WLAN_REASON_DEAUTH_LEAVING); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 818 | #ifdef CONFIG_WEP |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 819 | hostapd_clear_wep(hapd); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 820 | #endif /* CONFIG_WEP */ |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 821 | } |
| 822 | |
| 823 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 824 | /** |
| 825 | * hostapd_validate_bssid_configuration - Validate BSSID configuration |
| 826 | * @iface: Pointer to interface data |
| 827 | * Returns: 0 on success, -1 on failure |
| 828 | * |
| 829 | * This function is used to validate that the configured BSSIDs are valid. |
| 830 | */ |
| 831 | static int hostapd_validate_bssid_configuration(struct hostapd_iface *iface) |
| 832 | { |
| 833 | u8 mask[ETH_ALEN] = { 0 }; |
| 834 | struct hostapd_data *hapd = iface->bss[0]; |
| 835 | unsigned int i = iface->conf->num_bss, bits = 0, j; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 836 | int auto_addr = 0; |
| 837 | |
| 838 | if (hostapd_drv_none(hapd)) |
| 839 | return 0; |
| 840 | |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 841 | if (iface->conf->use_driver_iface_addr) |
| 842 | return 0; |
| 843 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 844 | /* Generate BSSID mask that is large enough to cover the BSSIDs. */ |
| 845 | |
| 846 | /* Determine the bits necessary to cover the number of BSSIDs. */ |
| 847 | for (i--; i; i >>= 1) |
| 848 | bits++; |
| 849 | |
| 850 | /* Determine the bits necessary to any configured BSSIDs, |
| 851 | if they are higher than the number of BSSIDs. */ |
| 852 | for (j = 0; j < iface->conf->num_bss; j++) { |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 853 | if (is_zero_ether_addr(iface->conf->bss[j]->bssid)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 854 | if (j) |
| 855 | auto_addr++; |
| 856 | continue; |
| 857 | } |
| 858 | |
| 859 | for (i = 0; i < ETH_ALEN; i++) { |
| 860 | mask[i] |= |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 861 | iface->conf->bss[j]->bssid[i] ^ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 862 | hapd->own_addr[i]; |
| 863 | } |
| 864 | } |
| 865 | |
| 866 | if (!auto_addr) |
| 867 | goto skip_mask_ext; |
| 868 | |
| 869 | for (i = 0; i < ETH_ALEN && mask[i] == 0; i++) |
| 870 | ; |
| 871 | j = 0; |
| 872 | if (i < ETH_ALEN) { |
| 873 | j = (5 - i) * 8; |
| 874 | |
| 875 | while (mask[i] != 0) { |
| 876 | mask[i] >>= 1; |
| 877 | j++; |
| 878 | } |
| 879 | } |
| 880 | |
| 881 | if (bits < j) |
| 882 | bits = j; |
| 883 | |
| 884 | if (bits > 40) { |
| 885 | wpa_printf(MSG_ERROR, "Too many bits in the BSSID mask (%u)", |
| 886 | bits); |
| 887 | return -1; |
| 888 | } |
| 889 | |
| 890 | os_memset(mask, 0xff, ETH_ALEN); |
| 891 | j = bits / 8; |
| 892 | for (i = 5; i > 5 - j; i--) |
| 893 | mask[i] = 0; |
| 894 | j = bits % 8; |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 895 | while (j) { |
| 896 | j--; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 897 | mask[i] <<= 1; |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 898 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 899 | |
| 900 | skip_mask_ext: |
| 901 | wpa_printf(MSG_DEBUG, "BSS count %lu, BSSID mask " MACSTR " (%d bits)", |
| 902 | (unsigned long) iface->conf->num_bss, MAC2STR(mask), bits); |
| 903 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 904 | if (!auto_addr) |
| 905 | return 0; |
| 906 | |
| 907 | for (i = 0; i < ETH_ALEN; i++) { |
| 908 | if ((hapd->own_addr[i] & mask[i]) != hapd->own_addr[i]) { |
| 909 | wpa_printf(MSG_ERROR, "Invalid BSSID mask " MACSTR |
| 910 | " for start address " MACSTR ".", |
| 911 | MAC2STR(mask), MAC2STR(hapd->own_addr)); |
| 912 | wpa_printf(MSG_ERROR, "Start address must be the " |
| 913 | "first address in the block (i.e., addr " |
| 914 | "AND mask == addr)."); |
| 915 | return -1; |
| 916 | } |
| 917 | } |
| 918 | |
| 919 | return 0; |
| 920 | } |
| 921 | |
| 922 | |
| 923 | static int mac_in_conf(struct hostapd_config *conf, const void *a) |
| 924 | { |
| 925 | size_t i; |
| 926 | |
| 927 | for (i = 0; i < conf->num_bss; i++) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 928 | if (hostapd_mac_comp(conf->bss[i]->bssid, a) == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 929 | return 1; |
| 930 | } |
| 931 | } |
| 932 | |
| 933 | return 0; |
| 934 | } |
| 935 | |
| 936 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 937 | #ifndef CONFIG_NO_RADIUS |
| 938 | |
| 939 | static int hostapd_das_nas_mismatch(struct hostapd_data *hapd, |
| 940 | struct radius_das_attrs *attr) |
| 941 | { |
Dmitry Shmidt | 13ca8d8 | 2014-02-20 10:18:40 -0800 | [diff] [blame] | 942 | if (attr->nas_identifier && |
| 943 | (!hapd->conf->nas_identifier || |
| 944 | os_strlen(hapd->conf->nas_identifier) != |
| 945 | attr->nas_identifier_len || |
| 946 | os_memcmp(hapd->conf->nas_identifier, attr->nas_identifier, |
| 947 | attr->nas_identifier_len) != 0)) { |
| 948 | wpa_printf(MSG_DEBUG, "RADIUS DAS: NAS-Identifier mismatch"); |
| 949 | return 1; |
| 950 | } |
| 951 | |
| 952 | if (attr->nas_ip_addr && |
| 953 | (hapd->conf->own_ip_addr.af != AF_INET || |
| 954 | os_memcmp(&hapd->conf->own_ip_addr.u.v4, attr->nas_ip_addr, 4) != |
| 955 | 0)) { |
| 956 | wpa_printf(MSG_DEBUG, "RADIUS DAS: NAS-IP-Address mismatch"); |
| 957 | return 1; |
| 958 | } |
| 959 | |
| 960 | #ifdef CONFIG_IPV6 |
| 961 | if (attr->nas_ipv6_addr && |
| 962 | (hapd->conf->own_ip_addr.af != AF_INET6 || |
| 963 | os_memcmp(&hapd->conf->own_ip_addr.u.v6, attr->nas_ipv6_addr, 16) |
| 964 | != 0)) { |
| 965 | wpa_printf(MSG_DEBUG, "RADIUS DAS: NAS-IPv6-Address mismatch"); |
| 966 | return 1; |
| 967 | } |
| 968 | #endif /* CONFIG_IPV6 */ |
| 969 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 970 | return 0; |
| 971 | } |
| 972 | |
| 973 | |
| 974 | static struct sta_info * hostapd_das_find_sta(struct hostapd_data *hapd, |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 975 | struct radius_das_attrs *attr, |
| 976 | int *multi) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 977 | { |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 978 | struct sta_info *selected, *sta; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 979 | char buf[128]; |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 980 | int num_attr = 0; |
| 981 | int count; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 982 | |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 983 | *multi = 0; |
| 984 | |
| 985 | for (sta = hapd->sta_list; sta; sta = sta->next) |
| 986 | sta->radius_das_match = 1; |
| 987 | |
| 988 | if (attr->sta_addr) { |
| 989 | num_attr++; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 990 | sta = ap_get_sta(hapd, attr->sta_addr); |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 991 | if (!sta) { |
| 992 | wpa_printf(MSG_DEBUG, |
| 993 | "RADIUS DAS: No Calling-Station-Id match"); |
| 994 | return NULL; |
| 995 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 996 | |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 997 | selected = sta; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 998 | for (sta = hapd->sta_list; sta; sta = sta->next) { |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 999 | if (sta != selected) |
| 1000 | sta->radius_das_match = 0; |
| 1001 | } |
| 1002 | wpa_printf(MSG_DEBUG, "RADIUS DAS: Calling-Station-Id match"); |
| 1003 | } |
| 1004 | |
| 1005 | if (attr->acct_session_id) { |
| 1006 | num_attr++; |
Dmitry Shmidt | b97e428 | 2016-02-08 10:16:07 -0800 | [diff] [blame] | 1007 | if (attr->acct_session_id_len != 16) { |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 1008 | wpa_printf(MSG_DEBUG, |
| 1009 | "RADIUS DAS: Acct-Session-Id cannot match"); |
| 1010 | return NULL; |
| 1011 | } |
| 1012 | count = 0; |
| 1013 | |
| 1014 | for (sta = hapd->sta_list; sta; sta = sta->next) { |
| 1015 | if (!sta->radius_das_match) |
| 1016 | continue; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1017 | os_snprintf(buf, sizeof(buf), "%016llX", |
| 1018 | (unsigned long long) sta->acct_session_id); |
Dmitry Shmidt | b97e428 | 2016-02-08 10:16:07 -0800 | [diff] [blame] | 1019 | if (os_memcmp(attr->acct_session_id, buf, 16) != 0) |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 1020 | sta->radius_das_match = 0; |
| 1021 | else |
| 1022 | count++; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1023 | } |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 1024 | |
| 1025 | if (count == 0) { |
| 1026 | wpa_printf(MSG_DEBUG, |
| 1027 | "RADIUS DAS: No matches remaining after Acct-Session-Id check"); |
| 1028 | return NULL; |
| 1029 | } |
| 1030 | wpa_printf(MSG_DEBUG, "RADIUS DAS: Acct-Session-Id match"); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1031 | } |
| 1032 | |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 1033 | if (attr->acct_multi_session_id) { |
| 1034 | num_attr++; |
Dmitry Shmidt | b97e428 | 2016-02-08 10:16:07 -0800 | [diff] [blame] | 1035 | if (attr->acct_multi_session_id_len != 16) { |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 1036 | wpa_printf(MSG_DEBUG, |
| 1037 | "RADIUS DAS: Acct-Multi-Session-Id cannot match"); |
| 1038 | return NULL; |
| 1039 | } |
| 1040 | count = 0; |
| 1041 | |
| 1042 | for (sta = hapd->sta_list; sta; sta = sta->next) { |
| 1043 | if (!sta->radius_das_match) |
| 1044 | continue; |
| 1045 | if (!sta->eapol_sm || |
Dmitry Shmidt | b97e428 | 2016-02-08 10:16:07 -0800 | [diff] [blame] | 1046 | !sta->eapol_sm->acct_multi_session_id) { |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 1047 | sta->radius_das_match = 0; |
| 1048 | continue; |
| 1049 | } |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1050 | os_snprintf(buf, sizeof(buf), "%016llX", |
| 1051 | (unsigned long long) |
Dmitry Shmidt | b97e428 | 2016-02-08 10:16:07 -0800 | [diff] [blame] | 1052 | sta->eapol_sm->acct_multi_session_id); |
| 1053 | if (os_memcmp(attr->acct_multi_session_id, buf, 16) != |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 1054 | 0) |
| 1055 | sta->radius_das_match = 0; |
| 1056 | else |
| 1057 | count++; |
| 1058 | } |
| 1059 | |
| 1060 | if (count == 0) { |
| 1061 | wpa_printf(MSG_DEBUG, |
| 1062 | "RADIUS DAS: No matches remaining after Acct-Multi-Session-Id check"); |
| 1063 | return NULL; |
| 1064 | } |
| 1065 | wpa_printf(MSG_DEBUG, |
| 1066 | "RADIUS DAS: Acct-Multi-Session-Id match"); |
| 1067 | } |
| 1068 | |
| 1069 | if (attr->cui) { |
| 1070 | num_attr++; |
| 1071 | count = 0; |
| 1072 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1073 | for (sta = hapd->sta_list; sta; sta = sta->next) { |
| 1074 | struct wpabuf *cui; |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 1075 | |
| 1076 | if (!sta->radius_das_match) |
| 1077 | continue; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1078 | cui = ieee802_1x_get_radius_cui(sta->eapol_sm); |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 1079 | if (!cui || wpabuf_len(cui) != attr->cui_len || |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1080 | os_memcmp(wpabuf_head(cui), attr->cui, |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 1081 | attr->cui_len) != 0) |
| 1082 | sta->radius_das_match = 0; |
| 1083 | else |
| 1084 | count++; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1085 | } |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 1086 | |
| 1087 | if (count == 0) { |
| 1088 | wpa_printf(MSG_DEBUG, |
| 1089 | "RADIUS DAS: No matches remaining after Chargeable-User-Identity check"); |
| 1090 | return NULL; |
| 1091 | } |
| 1092 | wpa_printf(MSG_DEBUG, |
| 1093 | "RADIUS DAS: Chargeable-User-Identity match"); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1094 | } |
| 1095 | |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 1096 | if (attr->user_name) { |
| 1097 | num_attr++; |
| 1098 | count = 0; |
| 1099 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1100 | for (sta = hapd->sta_list; sta; sta = sta->next) { |
| 1101 | u8 *identity; |
| 1102 | size_t identity_len; |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 1103 | |
| 1104 | if (!sta->radius_das_match) |
| 1105 | continue; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1106 | identity = ieee802_1x_get_identity(sta->eapol_sm, |
| 1107 | &identity_len); |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 1108 | if (!identity || |
| 1109 | identity_len != attr->user_name_len || |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1110 | os_memcmp(identity, attr->user_name, identity_len) |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 1111 | != 0) |
| 1112 | sta->radius_das_match = 0; |
| 1113 | else |
| 1114 | count++; |
| 1115 | } |
| 1116 | |
| 1117 | if (count == 0) { |
| 1118 | wpa_printf(MSG_DEBUG, |
| 1119 | "RADIUS DAS: No matches remaining after User-Name check"); |
| 1120 | return NULL; |
| 1121 | } |
| 1122 | wpa_printf(MSG_DEBUG, |
| 1123 | "RADIUS DAS: User-Name match"); |
| 1124 | } |
| 1125 | |
| 1126 | if (num_attr == 0) { |
| 1127 | /* |
| 1128 | * In theory, we could match all current associations, but it |
| 1129 | * seems safer to just reject requests that do not include any |
| 1130 | * session identification attributes. |
| 1131 | */ |
| 1132 | wpa_printf(MSG_DEBUG, |
| 1133 | "RADIUS DAS: No session identification attributes included"); |
| 1134 | return NULL; |
| 1135 | } |
| 1136 | |
| 1137 | selected = NULL; |
| 1138 | for (sta = hapd->sta_list; sta; sta = sta->next) { |
| 1139 | if (sta->radius_das_match) { |
| 1140 | if (selected) { |
| 1141 | *multi = 1; |
| 1142 | return NULL; |
| 1143 | } |
| 1144 | selected = sta; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1145 | } |
| 1146 | } |
| 1147 | |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 1148 | return selected; |
| 1149 | } |
| 1150 | |
| 1151 | |
| 1152 | static int hostapd_das_disconnect_pmksa(struct hostapd_data *hapd, |
| 1153 | struct radius_das_attrs *attr) |
| 1154 | { |
| 1155 | if (!hapd->wpa_auth) |
| 1156 | return -1; |
| 1157 | return wpa_auth_radius_das_disconnect_pmksa(hapd->wpa_auth, attr); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1158 | } |
| 1159 | |
| 1160 | |
| 1161 | static enum radius_das_res |
| 1162 | hostapd_das_disconnect(void *ctx, struct radius_das_attrs *attr) |
| 1163 | { |
| 1164 | struct hostapd_data *hapd = ctx; |
| 1165 | struct sta_info *sta; |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 1166 | int multi; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1167 | |
| 1168 | if (hostapd_das_nas_mismatch(hapd, attr)) |
| 1169 | return RADIUS_DAS_NAS_MISMATCH; |
| 1170 | |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 1171 | sta = hostapd_das_find_sta(hapd, attr, &multi); |
| 1172 | if (sta == NULL) { |
| 1173 | if (multi) { |
| 1174 | wpa_printf(MSG_DEBUG, |
| 1175 | "RADIUS DAS: Multiple sessions match - not supported"); |
| 1176 | return RADIUS_DAS_MULTI_SESSION_MATCH; |
| 1177 | } |
| 1178 | if (hostapd_das_disconnect_pmksa(hapd, attr) == 0) { |
| 1179 | wpa_printf(MSG_DEBUG, |
| 1180 | "RADIUS DAS: PMKSA cache entry matched"); |
| 1181 | return RADIUS_DAS_SUCCESS; |
| 1182 | } |
| 1183 | wpa_printf(MSG_DEBUG, "RADIUS DAS: No matching session found"); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1184 | return RADIUS_DAS_SESSION_NOT_FOUND; |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 1185 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1186 | |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 1187 | wpa_printf(MSG_DEBUG, "RADIUS DAS: Found a matching session " MACSTR |
| 1188 | " - disconnecting", MAC2STR(sta->addr)); |
Dmitry Shmidt | 13ca8d8 | 2014-02-20 10:18:40 -0800 | [diff] [blame] | 1189 | wpa_auth_pmksa_remove(hapd->wpa_auth, sta->addr); |
| 1190 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1191 | hostapd_drv_sta_deauth(hapd, sta->addr, |
| 1192 | WLAN_REASON_PREV_AUTH_NOT_VALID); |
| 1193 | ap_sta_deauthenticate(hapd, sta, WLAN_REASON_PREV_AUTH_NOT_VALID); |
| 1194 | |
| 1195 | return RADIUS_DAS_SUCCESS; |
| 1196 | } |
| 1197 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1198 | |
| 1199 | #ifdef CONFIG_HS20 |
| 1200 | static enum radius_das_res |
| 1201 | hostapd_das_coa(void *ctx, struct radius_das_attrs *attr) |
| 1202 | { |
| 1203 | struct hostapd_data *hapd = ctx; |
| 1204 | struct sta_info *sta; |
| 1205 | int multi; |
| 1206 | |
| 1207 | if (hostapd_das_nas_mismatch(hapd, attr)) |
| 1208 | return RADIUS_DAS_NAS_MISMATCH; |
| 1209 | |
| 1210 | sta = hostapd_das_find_sta(hapd, attr, &multi); |
| 1211 | if (!sta) { |
| 1212 | if (multi) { |
| 1213 | wpa_printf(MSG_DEBUG, |
| 1214 | "RADIUS DAS: Multiple sessions match - not supported"); |
| 1215 | return RADIUS_DAS_MULTI_SESSION_MATCH; |
| 1216 | } |
| 1217 | wpa_printf(MSG_DEBUG, "RADIUS DAS: No matching session found"); |
| 1218 | return RADIUS_DAS_SESSION_NOT_FOUND; |
| 1219 | } |
| 1220 | |
| 1221 | wpa_printf(MSG_DEBUG, "RADIUS DAS: Found a matching session " MACSTR |
| 1222 | " - CoA", MAC2STR(sta->addr)); |
| 1223 | |
| 1224 | if (attr->hs20_t_c_filtering) { |
| 1225 | if (attr->hs20_t_c_filtering[0] & BIT(0)) { |
| 1226 | wpa_printf(MSG_DEBUG, |
| 1227 | "HS 2.0: Unexpected Terms and Conditions filtering required in CoA-Request"); |
| 1228 | return RADIUS_DAS_COA_FAILED; |
| 1229 | } |
| 1230 | |
| 1231 | hs20_t_c_filtering(hapd, sta, 0); |
| 1232 | } |
| 1233 | |
| 1234 | return RADIUS_DAS_SUCCESS; |
| 1235 | } |
| 1236 | #else /* CONFIG_HS20 */ |
| 1237 | #define hostapd_das_coa NULL |
| 1238 | #endif /* CONFIG_HS20 */ |
| 1239 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1240 | |
| 1241 | #ifdef CONFIG_SQLITE |
| 1242 | |
| 1243 | static int db_table_exists(sqlite3 *db, const char *name) |
| 1244 | { |
| 1245 | char cmd[128]; |
| 1246 | |
| 1247 | os_snprintf(cmd, sizeof(cmd), "SELECT 1 FROM %s;", name); |
| 1248 | return sqlite3_exec(db, cmd, NULL, NULL, NULL) == SQLITE_OK; |
| 1249 | } |
| 1250 | |
| 1251 | |
| 1252 | static int db_table_create_radius_attributes(sqlite3 *db) |
| 1253 | { |
| 1254 | char *err = NULL; |
| 1255 | const char *sql = |
| 1256 | "CREATE TABLE radius_attributes(" |
| 1257 | " id INTEGER PRIMARY KEY," |
| 1258 | " sta TEXT," |
| 1259 | " reqtype TEXT," |
| 1260 | " attr TEXT" |
| 1261 | ");" |
| 1262 | "CREATE INDEX idx_sta_reqtype ON radius_attributes(sta,reqtype);"; |
| 1263 | |
| 1264 | wpa_printf(MSG_DEBUG, |
| 1265 | "Adding database table for RADIUS attribute information"); |
| 1266 | if (sqlite3_exec(db, sql, NULL, NULL, &err) != SQLITE_OK) { |
| 1267 | wpa_printf(MSG_ERROR, "SQLite error: %s", err); |
| 1268 | sqlite3_free(err); |
| 1269 | return -1; |
| 1270 | } |
| 1271 | |
| 1272 | return 0; |
| 1273 | } |
| 1274 | |
| 1275 | #endif /* CONFIG_SQLITE */ |
| 1276 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1277 | #endif /* CONFIG_NO_RADIUS */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1278 | |
| 1279 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 1280 | static int hostapd_start_beacon(struct hostapd_data *hapd, |
| 1281 | bool flush_old_stations) |
| 1282 | { |
| 1283 | struct hostapd_bss_config *conf = hapd->conf; |
| 1284 | |
| 1285 | if (!conf->start_disabled && ieee802_11_set_beacon(hapd) < 0) |
| 1286 | return -1; |
| 1287 | |
| 1288 | if (flush_old_stations && !conf->start_disabled && |
| 1289 | conf->broadcast_deauth) { |
| 1290 | u8 addr[ETH_ALEN]; |
| 1291 | |
| 1292 | /* Should any previously associated STA not have noticed that |
| 1293 | * the AP had stopped and restarted, send one more |
| 1294 | * deauthentication notification now that the AP is ready to |
| 1295 | * operate. */ |
| 1296 | wpa_dbg(hapd->msg_ctx, MSG_DEBUG, |
| 1297 | "Deauthenticate all stations at BSS start"); |
| 1298 | os_memset(addr, 0xff, ETH_ALEN); |
| 1299 | hostapd_drv_sta_deauth(hapd, addr, |
| 1300 | WLAN_REASON_PREV_AUTH_NOT_VALID); |
| 1301 | } |
| 1302 | |
| 1303 | if (hapd->driver && hapd->driver->set_operstate) |
| 1304 | hapd->driver->set_operstate(hapd->drv_priv, 1); |
| 1305 | |
| 1306 | return 0; |
| 1307 | } |
| 1308 | |
| 1309 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1310 | /** |
| 1311 | * hostapd_setup_bss - Per-BSS setup (initialization) |
| 1312 | * @hapd: Pointer to BSS data |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1313 | * @first: Whether this BSS is the first BSS of an interface; -1 = not first, |
| 1314 | * but interface may exist |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 1315 | * @start_beacon: Whether Beacon frame template should be configured and |
| 1316 | * transmission of Beaconf rames started at this time. This is used when |
| 1317 | * MBSSID element is enabled where the information regarding all BSSes |
| 1318 | * should be retrieved before configuring the Beacon frame template. The |
| 1319 | * calling functions are responsible for configuring the Beacon frame |
| 1320 | * explicitly if this is set to false. |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1321 | * |
| 1322 | * This function is used to initialize all per-BSS data structures and |
| 1323 | * resources. This gets called in a loop for each BSS when an interface is |
| 1324 | * initialized. Most of the modules that are initialized here will be |
| 1325 | * deinitialized in hostapd_cleanup(). |
| 1326 | */ |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 1327 | static int hostapd_setup_bss(struct hostapd_data *hapd, int first, |
| 1328 | bool start_beacon) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1329 | { |
| 1330 | struct hostapd_bss_config *conf = hapd->conf; |
Dmitry Shmidt | 9d9e602 | 2015-04-23 10:34:55 -0700 | [diff] [blame] | 1331 | u8 ssid[SSID_MAX_LEN + 1]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1332 | int ssid_len, set_ssid; |
| 1333 | char force_ifname[IFNAMSIZ]; |
| 1334 | u8 if_addr[ETH_ALEN]; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1335 | int flush_old_stations = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1336 | |
Sunil Ravi | af399a8 | 2024-05-05 20:56:55 +0000 | [diff] [blame^] | 1337 | if (!hostapd_mld_is_first_bss(hapd)) |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1338 | wpa_printf(MSG_DEBUG, |
| 1339 | "MLD: %s: Setting non-first BSS", __func__); |
| 1340 | |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 1341 | wpa_printf(MSG_DEBUG, "%s(hapd=%p (%s), first=%d)", |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1342 | __func__, hapd, conf->iface, first); |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 1343 | |
Dmitry Shmidt | 50b691d | 2014-05-21 14:01:45 -0700 | [diff] [blame] | 1344 | #ifdef EAP_SERVER_TNC |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1345 | if (conf->tnc && tncs_global_init() < 0) { |
Dmitry Shmidt | 50b691d | 2014-05-21 14:01:45 -0700 | [diff] [blame] | 1346 | wpa_printf(MSG_ERROR, "Failed to initialize TNCS"); |
| 1347 | return -1; |
| 1348 | } |
| 1349 | #endif /* EAP_SERVER_TNC */ |
| 1350 | |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 1351 | if (hapd->started) { |
| 1352 | wpa_printf(MSG_ERROR, "%s: Interface %s was already started", |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1353 | __func__, conf->iface); |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 1354 | return -1; |
| 1355 | } |
| 1356 | hapd->started = 1; |
| 1357 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1358 | if (!first || first == -1) { |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 1359 | u8 *addr = hapd->own_addr; |
| 1360 | |
| 1361 | if (!is_zero_ether_addr(conf->bssid)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1362 | /* Allocate the configured BSSID. */ |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1363 | os_memcpy(hapd->own_addr, conf->bssid, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1364 | |
| 1365 | if (hostapd_mac_comp(hapd->own_addr, |
| 1366 | hapd->iface->bss[0]->own_addr) == |
| 1367 | 0) { |
| 1368 | wpa_printf(MSG_ERROR, "BSS '%s' may not have " |
| 1369 | "BSSID set to the MAC address of " |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1370 | "the radio", conf->iface); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1371 | return -1; |
| 1372 | } |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 1373 | } else if (hapd->iconf->use_driver_iface_addr) { |
| 1374 | addr = NULL; |
| 1375 | } else { |
| 1376 | /* Allocate the next available BSSID. */ |
| 1377 | do { |
| 1378 | inc_byte_array(hapd->own_addr, ETH_ALEN); |
| 1379 | } while (mac_in_conf(hapd->iconf, hapd->own_addr)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1380 | } |
| 1381 | |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 1382 | hapd->interface_added = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1383 | if (hostapd_if_add(hapd->iface->bss[0], WPA_IF_AP_BSS, |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 1384 | conf->iface, addr, hapd, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1385 | &hapd->drv_priv, force_ifname, if_addr, |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1386 | conf->bridge[0] ? conf->bridge : NULL, |
| 1387 | first == -1)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1388 | wpa_printf(MSG_ERROR, "Failed to add BSS (BSSID=" |
| 1389 | MACSTR ")", MAC2STR(hapd->own_addr)); |
Dmitry Shmidt | 3cf6f79 | 2013-12-18 13:12:19 -0800 | [diff] [blame] | 1390 | hapd->interface_added = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1391 | return -1; |
| 1392 | } |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 1393 | |
| 1394 | if (!addr) |
| 1395 | os_memcpy(hapd->own_addr, if_addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1396 | } |
| 1397 | |
| 1398 | if (conf->wmm_enabled < 0) |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 1399 | conf->wmm_enabled = hapd->iconf->ieee80211n | |
| 1400 | hapd->iconf->ieee80211ax; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1401 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1402 | #ifdef CONFIG_IEEE80211R_AP |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1403 | if (is_zero_ether_addr(conf->r1_key_holder)) |
| 1404 | os_memcpy(conf->r1_key_holder, hapd->own_addr, ETH_ALEN); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1405 | #endif /* CONFIG_IEEE80211R_AP */ |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1406 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1407 | #ifdef CONFIG_MESH |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1408 | if ((hapd->conf->mesh & MESH_ENABLED) && hapd->iface->mconf == NULL) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1409 | flush_old_stations = 0; |
| 1410 | #endif /* CONFIG_MESH */ |
| 1411 | |
| 1412 | if (flush_old_stations) |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 1413 | hostapd_flush(hapd); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1414 | hostapd_set_privacy(hapd, 0); |
| 1415 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1416 | #ifdef CONFIG_WEP |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 1417 | if (!hostapd_drv_nl80211(hapd)) |
| 1418 | hostapd_broadcast_wep_clear(hapd); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1419 | if (hostapd_setup_encryption(conf->iface, hapd)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1420 | return -1; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1421 | #endif /* CONFIG_WEP */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1422 | |
| 1423 | /* |
| 1424 | * Fetch the SSID from the system and use it or, |
| 1425 | * if one was specified in the config file, verify they |
| 1426 | * match. |
| 1427 | */ |
| 1428 | ssid_len = hostapd_get_ssid(hapd, ssid, sizeof(ssid)); |
| 1429 | if (ssid_len < 0) { |
| 1430 | wpa_printf(MSG_ERROR, "Could not read SSID from system"); |
| 1431 | return -1; |
| 1432 | } |
| 1433 | if (conf->ssid.ssid_set) { |
| 1434 | /* |
| 1435 | * If SSID is specified in the config file and it differs |
| 1436 | * from what is being used then force installation of the |
| 1437 | * new SSID. |
| 1438 | */ |
| 1439 | set_ssid = (conf->ssid.ssid_len != (size_t) ssid_len || |
| 1440 | os_memcmp(conf->ssid.ssid, ssid, ssid_len) != 0); |
| 1441 | } else { |
| 1442 | /* |
| 1443 | * No SSID in the config file; just use the one we got |
| 1444 | * from the system. |
| 1445 | */ |
| 1446 | set_ssid = 0; |
| 1447 | conf->ssid.ssid_len = ssid_len; |
| 1448 | os_memcpy(conf->ssid.ssid, ssid, conf->ssid.ssid_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1449 | } |
| 1450 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1451 | /* |
| 1452 | * Short SSID calculation is identical to FCS and it is defined in |
| 1453 | * IEEE P802.11-REVmd/D3.0, 9.4.2.170.3 (Calculating the Short-SSID). |
| 1454 | */ |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 1455 | conf->ssid.short_ssid = ieee80211_crc32(conf->ssid.ssid, |
| 1456 | conf->ssid.ssid_len); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1457 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1458 | if (!hostapd_drv_none(hapd)) { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1459 | wpa_printf(MSG_DEBUG, "Using interface %s with hwaddr " MACSTR |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1460 | " and ssid \"%s\"", |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1461 | conf->iface, MAC2STR(hapd->own_addr), |
| 1462 | wpa_ssid_txt(conf->ssid.ssid, conf->ssid.ssid_len)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1463 | } |
| 1464 | |
| 1465 | if (hostapd_setup_wpa_psk(conf)) { |
| 1466 | wpa_printf(MSG_ERROR, "WPA-PSK setup failed."); |
| 1467 | return -1; |
| 1468 | } |
| 1469 | |
| 1470 | /* Set SSID for the kernel driver (to be used in beacon and probe |
| 1471 | * response frames) */ |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1472 | if (set_ssid && hostapd_set_ssid(hapd, conf->ssid.ssid, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1473 | conf->ssid.ssid_len)) { |
| 1474 | wpa_printf(MSG_ERROR, "Could not set SSID for kernel driver"); |
| 1475 | return -1; |
| 1476 | } |
| 1477 | |
Dmitry Shmidt | 818ea48 | 2014-03-10 13:15:21 -0700 | [diff] [blame] | 1478 | if (wpa_debug_level <= MSG_MSGDUMP) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1479 | conf->radius->msg_dumps = 1; |
| 1480 | #ifndef CONFIG_NO_RADIUS |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1481 | |
| 1482 | #ifdef CONFIG_SQLITE |
| 1483 | if (conf->radius_req_attr_sqlite) { |
| 1484 | if (sqlite3_open(conf->radius_req_attr_sqlite, |
| 1485 | &hapd->rad_attr_db)) { |
| 1486 | wpa_printf(MSG_ERROR, "Could not open SQLite file '%s'", |
| 1487 | conf->radius_req_attr_sqlite); |
| 1488 | return -1; |
| 1489 | } |
| 1490 | |
| 1491 | wpa_printf(MSG_DEBUG, "Opening RADIUS attribute database: %s", |
| 1492 | conf->radius_req_attr_sqlite); |
| 1493 | if (!db_table_exists(hapd->rad_attr_db, "radius_attributes") && |
| 1494 | db_table_create_radius_attributes(hapd->rad_attr_db) < 0) |
| 1495 | return -1; |
| 1496 | } |
| 1497 | #endif /* CONFIG_SQLITE */ |
| 1498 | |
Sunil Ravi | af399a8 | 2024-05-05 20:56:55 +0000 | [diff] [blame^] | 1499 | if (hostapd_mld_is_first_bss(hapd)) { |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1500 | hapd->radius = radius_client_init(hapd, conf->radius); |
| 1501 | if (!hapd->radius) { |
| 1502 | wpa_printf(MSG_ERROR, |
| 1503 | "RADIUS client initialization failed."); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1504 | return -1; |
| 1505 | } |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1506 | |
| 1507 | if (conf->radius_das_port) { |
| 1508 | struct radius_das_conf das_conf; |
| 1509 | |
| 1510 | os_memset(&das_conf, 0, sizeof(das_conf)); |
| 1511 | das_conf.port = conf->radius_das_port; |
| 1512 | das_conf.shared_secret = conf->radius_das_shared_secret; |
| 1513 | das_conf.shared_secret_len = |
| 1514 | conf->radius_das_shared_secret_len; |
| 1515 | das_conf.client_addr = &conf->radius_das_client_addr; |
| 1516 | das_conf.time_window = conf->radius_das_time_window; |
| 1517 | das_conf.require_event_timestamp = |
| 1518 | conf->radius_das_require_event_timestamp; |
| 1519 | das_conf.require_message_authenticator = |
| 1520 | conf->radius_das_require_message_authenticator; |
| 1521 | das_conf.ctx = hapd; |
| 1522 | das_conf.disconnect = hostapd_das_disconnect; |
| 1523 | das_conf.coa = hostapd_das_coa; |
| 1524 | hapd->radius_das = radius_das_init(&das_conf); |
| 1525 | if (!hapd->radius_das) { |
| 1526 | wpa_printf(MSG_ERROR, |
| 1527 | "RADIUS DAS initialization failed."); |
| 1528 | return -1; |
| 1529 | } |
| 1530 | } |
| 1531 | } else { |
Sunil Ravi | af399a8 | 2024-05-05 20:56:55 +0000 | [diff] [blame^] | 1532 | #ifdef CONFIG_IEEE80211BE |
| 1533 | struct hostapd_data *f_bss; |
| 1534 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1535 | wpa_printf(MSG_DEBUG, |
| 1536 | "MLD: Using RADIUS client of the first BSS"); |
Sunil Ravi | af399a8 | 2024-05-05 20:56:55 +0000 | [diff] [blame^] | 1537 | f_bss = hostapd_mld_get_first_bss(hapd); |
| 1538 | if (!f_bss) |
| 1539 | return -1; |
| 1540 | hapd->radius = f_bss->radius; |
| 1541 | hapd->radius_das = f_bss->radius_das; |
| 1542 | #endif /* CONFIG_IEEE80211BE */ |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1543 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1544 | #endif /* CONFIG_NO_RADIUS */ |
| 1545 | |
| 1546 | if (hostapd_acl_init(hapd)) { |
| 1547 | wpa_printf(MSG_ERROR, "ACL initialization failed."); |
| 1548 | return -1; |
| 1549 | } |
| 1550 | if (hostapd_init_wps(hapd, conf)) |
| 1551 | return -1; |
| 1552 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1553 | #ifdef CONFIG_DPP |
| 1554 | hapd->gas = gas_query_ap_init(hapd, hapd->msg_ctx); |
| 1555 | if (!hapd->gas) |
| 1556 | return -1; |
| 1557 | if (hostapd_dpp_init(hapd)) |
| 1558 | return -1; |
| 1559 | #endif /* CONFIG_DPP */ |
| 1560 | |
Sunil Ravi | 72e0122 | 2024-03-09 01:25:43 +0000 | [diff] [blame] | 1561 | #ifdef CONFIG_NAN_USD |
| 1562 | if (hostapd_nan_usd_init(hapd) < 0) |
| 1563 | return -1; |
| 1564 | #endif /* CONFIG_NAN_USD */ |
| 1565 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1566 | if (authsrv_init(hapd) < 0) |
| 1567 | return -1; |
| 1568 | |
| 1569 | if (ieee802_1x_init(hapd)) { |
| 1570 | wpa_printf(MSG_ERROR, "IEEE 802.1X initialization failed."); |
| 1571 | return -1; |
| 1572 | } |
| 1573 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1574 | if ((conf->wpa || conf->osen) && hostapd_setup_wpa(hapd)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1575 | return -1; |
| 1576 | |
| 1577 | if (accounting_init(hapd)) { |
| 1578 | wpa_printf(MSG_ERROR, "Accounting initialization failed."); |
| 1579 | return -1; |
| 1580 | } |
| 1581 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1582 | #ifdef CONFIG_INTERWORKING |
| 1583 | if (gas_serv_init(hapd)) { |
| 1584 | wpa_printf(MSG_ERROR, "GAS server initialization failed"); |
| 1585 | return -1; |
| 1586 | } |
Sunil Ravi | af399a8 | 2024-05-05 20:56:55 +0000 | [diff] [blame^] | 1587 | #endif /* CONFIG_INTERWORKING */ |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1588 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1589 | if (conf->qos_map_set_len && |
| 1590 | hostapd_drv_set_qos_map(hapd, conf->qos_map_set, |
| 1591 | conf->qos_map_set_len)) { |
| 1592 | wpa_printf(MSG_ERROR, "Failed to initialize QoS Map"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1593 | return -1; |
| 1594 | } |
| 1595 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1596 | if (conf->bss_load_update_period && bss_load_update_init(hapd)) { |
| 1597 | wpa_printf(MSG_ERROR, "BSS Load initialization failed"); |
| 1598 | return -1; |
| 1599 | } |
| 1600 | |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 1601 | if (conf->bridge[0]) { |
| 1602 | /* Set explicitly configured bridge parameters that might have |
| 1603 | * been lost if the interface has been removed out of the |
| 1604 | * bridge. */ |
| 1605 | |
| 1606 | /* multicast to unicast on bridge ports */ |
| 1607 | if (conf->bridge_multicast_to_unicast) |
| 1608 | hostapd_drv_br_port_set_attr( |
| 1609 | hapd, DRV_BR_PORT_ATTR_MCAST2UCAST, 1); |
| 1610 | |
| 1611 | /* hairpin mode */ |
| 1612 | if (conf->bridge_hairpin) |
| 1613 | hostapd_drv_br_port_set_attr( |
| 1614 | hapd, DRV_BR_PORT_ATTR_HAIRPIN_MODE, 1); |
| 1615 | } |
| 1616 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1617 | if (conf->proxy_arp) { |
| 1618 | if (x_snoop_init(hapd)) { |
| 1619 | wpa_printf(MSG_ERROR, |
| 1620 | "Generic snooping infrastructure initialization failed"); |
| 1621 | return -1; |
| 1622 | } |
| 1623 | |
| 1624 | if (dhcp_snoop_init(hapd)) { |
| 1625 | wpa_printf(MSG_ERROR, |
| 1626 | "DHCP snooping initialization failed"); |
| 1627 | return -1; |
| 1628 | } |
| 1629 | |
| 1630 | if (ndisc_snoop_init(hapd)) { |
| 1631 | wpa_printf(MSG_ERROR, |
| 1632 | "Neighbor Discovery snooping initialization failed"); |
| 1633 | return -1; |
| 1634 | } |
| 1635 | } |
| 1636 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1637 | if (!hostapd_drv_none(hapd) && vlan_init(hapd)) { |
| 1638 | wpa_printf(MSG_ERROR, "VLAN initialization failed."); |
| 1639 | return -1; |
| 1640 | } |
| 1641 | |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame] | 1642 | if (start_beacon && hostapd_start_beacon(hapd, flush_old_stations) < 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1643 | return -1; |
| 1644 | |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame] | 1645 | if (hapd->wpa_auth && wpa_init_keys(hapd->wpa_auth) < 0) |
| 1646 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1647 | |
| 1648 | return 0; |
| 1649 | } |
| 1650 | |
| 1651 | |
| 1652 | static void hostapd_tx_queue_params(struct hostapd_iface *iface) |
| 1653 | { |
| 1654 | struct hostapd_data *hapd = iface->bss[0]; |
| 1655 | int i; |
| 1656 | struct hostapd_tx_queue_params *p; |
| 1657 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1658 | #ifdef CONFIG_MESH |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1659 | if ((hapd->conf->mesh & MESH_ENABLED) && iface->mconf == NULL) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1660 | return; |
| 1661 | #endif /* CONFIG_MESH */ |
| 1662 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1663 | for (i = 0; i < NUM_TX_QUEUES; i++) { |
| 1664 | p = &iface->conf->tx_queue[i]; |
| 1665 | |
| 1666 | if (hostapd_set_tx_queue_params(hapd, i, p->aifs, p->cwmin, |
| 1667 | p->cwmax, p->burst)) { |
| 1668 | wpa_printf(MSG_DEBUG, "Failed to set TX queue " |
| 1669 | "parameters for queue %d.", i); |
| 1670 | /* Continue anyway */ |
| 1671 | } |
| 1672 | } |
| 1673 | } |
| 1674 | |
| 1675 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 1676 | static int hostapd_set_acl_list(struct hostapd_data *hapd, |
| 1677 | struct mac_acl_entry *mac_acl, |
| 1678 | int n_entries, u8 accept_acl) |
| 1679 | { |
| 1680 | struct hostapd_acl_params *acl_params; |
| 1681 | int i, err; |
| 1682 | |
| 1683 | acl_params = os_zalloc(sizeof(*acl_params) + |
| 1684 | (n_entries * sizeof(acl_params->mac_acl[0]))); |
| 1685 | if (!acl_params) |
| 1686 | return -ENOMEM; |
| 1687 | |
| 1688 | for (i = 0; i < n_entries; i++) |
| 1689 | os_memcpy(acl_params->mac_acl[i].addr, mac_acl[i].addr, |
| 1690 | ETH_ALEN); |
| 1691 | |
| 1692 | acl_params->acl_policy = accept_acl; |
| 1693 | acl_params->num_mac_acl = n_entries; |
| 1694 | |
| 1695 | err = hostapd_drv_set_acl(hapd, acl_params); |
| 1696 | |
| 1697 | os_free(acl_params); |
| 1698 | |
| 1699 | return err; |
| 1700 | } |
| 1701 | |
| 1702 | |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 1703 | int hostapd_set_acl(struct hostapd_data *hapd) |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 1704 | { |
| 1705 | struct hostapd_config *conf = hapd->iconf; |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 1706 | int err = 0; |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 1707 | u8 accept_acl; |
| 1708 | |
| 1709 | if (hapd->iface->drv_max_acl_mac_addrs == 0) |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 1710 | return 0; |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 1711 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1712 | if (conf->bss[0]->macaddr_acl == DENY_UNLESS_ACCEPTED) { |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 1713 | accept_acl = 1; |
| 1714 | err = hostapd_set_acl_list(hapd, conf->bss[0]->accept_mac, |
| 1715 | conf->bss[0]->num_accept_mac, |
| 1716 | accept_acl); |
| 1717 | if (err) { |
| 1718 | wpa_printf(MSG_DEBUG, "Failed to set accept acl"); |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 1719 | return -1; |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 1720 | } |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1721 | } else if (conf->bss[0]->macaddr_acl == ACCEPT_UNLESS_DENIED) { |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 1722 | accept_acl = 0; |
| 1723 | err = hostapd_set_acl_list(hapd, conf->bss[0]->deny_mac, |
| 1724 | conf->bss[0]->num_deny_mac, |
| 1725 | accept_acl); |
| 1726 | if (err) { |
| 1727 | wpa_printf(MSG_DEBUG, "Failed to set deny acl"); |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 1728 | return -1; |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 1729 | } |
| 1730 | } |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 1731 | return err; |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 1732 | } |
| 1733 | |
| 1734 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1735 | static int start_ctrl_iface_bss(struct hostapd_data *hapd) |
| 1736 | { |
| 1737 | if (!hapd->iface->interfaces || |
| 1738 | !hapd->iface->interfaces->ctrl_iface_init) |
| 1739 | return 0; |
| 1740 | |
| 1741 | if (hapd->iface->interfaces->ctrl_iface_init(hapd)) { |
| 1742 | wpa_printf(MSG_ERROR, |
| 1743 | "Failed to setup control interface for %s", |
| 1744 | hapd->conf->iface); |
| 1745 | return -1; |
| 1746 | } |
| 1747 | |
| 1748 | return 0; |
| 1749 | } |
| 1750 | |
| 1751 | |
| 1752 | static int start_ctrl_iface(struct hostapd_iface *iface) |
| 1753 | { |
| 1754 | size_t i; |
| 1755 | |
| 1756 | if (!iface->interfaces || !iface->interfaces->ctrl_iface_init) |
| 1757 | return 0; |
| 1758 | |
| 1759 | for (i = 0; i < iface->num_bss; i++) { |
| 1760 | struct hostapd_data *hapd = iface->bss[i]; |
| 1761 | if (iface->interfaces->ctrl_iface_init(hapd)) { |
| 1762 | wpa_printf(MSG_ERROR, |
| 1763 | "Failed to setup control interface for %s", |
| 1764 | hapd->conf->iface); |
| 1765 | return -1; |
| 1766 | } |
| 1767 | } |
| 1768 | |
| 1769 | return 0; |
| 1770 | } |
| 1771 | |
| 1772 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1773 | /* When NO_IR flag is set and AP is stopped, clean up BSS parameters without |
| 1774 | * deinitializing the driver and the control interfaces. A subsequent |
| 1775 | * REG_CHANGE event can bring the AP back up. |
| 1776 | */ |
| 1777 | static void hostapd_no_ir_cleanup(struct hostapd_data *bss) |
| 1778 | { |
| 1779 | hostapd_bss_deinit_no_free(bss); |
Sunil Ravi | af399a8 | 2024-05-05 20:56:55 +0000 | [diff] [blame^] | 1780 | hostapd_bss_link_deinit(bss); |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1781 | hostapd_free_hapd_data(bss); |
| 1782 | hostapd_cleanup_iface_partial(bss->iface); |
| 1783 | } |
| 1784 | |
| 1785 | |
| 1786 | static int hostapd_no_ir_channel_list_updated(struct hostapd_iface *iface, |
| 1787 | void *ctx) |
| 1788 | { |
| 1789 | bool all_no_ir, is_6ghz; |
| 1790 | int i, j; |
| 1791 | struct hostapd_hw_modes *mode = NULL; |
| 1792 | |
| 1793 | if (hostapd_get_hw_features(iface)) |
| 1794 | return 0; |
| 1795 | |
| 1796 | all_no_ir = true; |
| 1797 | is_6ghz = false; |
| 1798 | |
| 1799 | for (i = 0; i < iface->num_hw_features; i++) { |
| 1800 | mode = &iface->hw_features[i]; |
| 1801 | |
| 1802 | if (mode->mode == iface->conf->hw_mode) { |
| 1803 | if (iface->freq > 0 && |
| 1804 | !hw_mode_get_channel(mode, iface->freq, NULL)) { |
| 1805 | mode = NULL; |
| 1806 | continue; |
| 1807 | } |
| 1808 | |
| 1809 | for (j = 0; j < mode->num_channels; j++) { |
| 1810 | if (!(mode->channels[j].flag & |
| 1811 | HOSTAPD_CHAN_NO_IR)) |
| 1812 | all_no_ir = false; |
| 1813 | |
| 1814 | if (is_6ghz_freq(mode->channels[j].freq)) |
| 1815 | is_6ghz = true; |
| 1816 | } |
| 1817 | break; |
| 1818 | } |
| 1819 | } |
| 1820 | |
| 1821 | if (!mode || !is_6ghz) |
| 1822 | return 0; |
| 1823 | iface->current_mode = mode; |
| 1824 | |
| 1825 | if (iface->state == HAPD_IFACE_ENABLED) { |
| 1826 | if (!all_no_ir) { |
| 1827 | struct hostapd_channel_data *chan; |
| 1828 | |
| 1829 | chan = hw_get_channel_freq(iface->current_mode->mode, |
| 1830 | iface->freq, NULL, |
| 1831 | iface->hw_features, |
| 1832 | iface->num_hw_features); |
| 1833 | |
| 1834 | if (!chan) { |
| 1835 | wpa_printf(MSG_ERROR, |
| 1836 | "NO_IR: Could not derive chan from freq"); |
| 1837 | return 0; |
| 1838 | } |
| 1839 | |
| 1840 | if (!(chan->flag & HOSTAPD_CHAN_NO_IR)) |
| 1841 | return 0; |
| 1842 | wpa_printf(MSG_DEBUG, |
| 1843 | "NO_IR: The current channel has NO_IR flag now, stop AP."); |
| 1844 | } else { |
| 1845 | wpa_printf(MSG_DEBUG, |
| 1846 | "NO_IR: All chan in new chanlist are NO_IR, stop AP."); |
| 1847 | } |
| 1848 | |
| 1849 | hostapd_set_state(iface, HAPD_IFACE_NO_IR); |
| 1850 | iface->is_no_ir = true; |
| 1851 | hostapd_drv_stop_ap(iface->bss[0]); |
| 1852 | hostapd_no_ir_cleanup(iface->bss[0]); |
| 1853 | wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO, AP_EVENT_NO_IR); |
| 1854 | } else if (iface->state == HAPD_IFACE_NO_IR) { |
| 1855 | if (all_no_ir) { |
| 1856 | wpa_printf(MSG_DEBUG, |
| 1857 | "NO_IR: AP in NO_IR and all chan in the new chanlist are NO_IR. Ignore"); |
| 1858 | return 0; |
| 1859 | } |
| 1860 | |
| 1861 | if (!iface->conf->acs) { |
| 1862 | struct hostapd_channel_data *chan; |
| 1863 | |
| 1864 | chan = hw_get_channel_freq(iface->current_mode->mode, |
| 1865 | iface->freq, NULL, |
| 1866 | iface->hw_features, |
| 1867 | iface->num_hw_features); |
| 1868 | if (!chan) { |
| 1869 | wpa_printf(MSG_ERROR, |
| 1870 | "NO_IR: Could not derive chan from freq"); |
| 1871 | return 0; |
| 1872 | } |
| 1873 | |
| 1874 | /* If the last operating channel is NO_IR, trigger ACS. |
| 1875 | */ |
| 1876 | if (chan->flag & HOSTAPD_CHAN_NO_IR) { |
| 1877 | iface->freq = 0; |
| 1878 | iface->conf->channel = 0; |
| 1879 | if (acs_init(iface) != HOSTAPD_CHAN_ACS) |
| 1880 | wpa_printf(MSG_ERROR, |
| 1881 | "NO_IR: Could not start ACS"); |
| 1882 | return 0; |
| 1883 | } |
| 1884 | } |
| 1885 | |
| 1886 | setup_interface2(iface); |
| 1887 | } |
| 1888 | |
| 1889 | return 0; |
| 1890 | } |
| 1891 | |
| 1892 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1893 | static void channel_list_update_timeout(void *eloop_ctx, void *timeout_ctx) |
| 1894 | { |
| 1895 | struct hostapd_iface *iface = eloop_ctx; |
| 1896 | |
| 1897 | if (!iface->wait_channel_update) { |
| 1898 | wpa_printf(MSG_INFO, "Channel list update timeout, but interface was not waiting for it"); |
| 1899 | return; |
| 1900 | } |
| 1901 | |
| 1902 | /* |
| 1903 | * It is possible that the existing channel list is acceptable, so try |
| 1904 | * to proceed. |
| 1905 | */ |
| 1906 | wpa_printf(MSG_DEBUG, "Channel list update timeout - try to continue anyway"); |
| 1907 | setup_interface2(iface); |
| 1908 | } |
| 1909 | |
| 1910 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1911 | void hostapd_channel_list_updated(struct hostapd_iface *iface, int initiator) |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1912 | { |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1913 | if (initiator == REGDOM_SET_BY_DRIVER) { |
| 1914 | hostapd_for_each_interface(iface->interfaces, |
| 1915 | hostapd_no_ir_channel_list_updated, |
| 1916 | NULL); |
| 1917 | return; |
| 1918 | } |
| 1919 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1920 | if (!iface->wait_channel_update || initiator != REGDOM_SET_BY_USER) |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1921 | return; |
| 1922 | |
| 1923 | wpa_printf(MSG_DEBUG, "Channel list updated - continue setup"); |
| 1924 | eloop_cancel_timeout(channel_list_update_timeout, iface, NULL); |
| 1925 | setup_interface2(iface); |
| 1926 | } |
| 1927 | |
| 1928 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1929 | static int setup_interface(struct hostapd_iface *iface) |
| 1930 | { |
| 1931 | struct hostapd_data *hapd = iface->bss[0]; |
| 1932 | size_t i; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1933 | |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 1934 | /* |
| 1935 | * It is possible that setup_interface() is called after the interface |
| 1936 | * was disabled etc., in which case driver_ap_teardown is possibly set |
| 1937 | * to 1. Clear it here so any other key/station deletion, which is not |
| 1938 | * part of a teardown flow, would also call the relevant driver |
| 1939 | * callbacks. |
| 1940 | */ |
| 1941 | iface->driver_ap_teardown = 0; |
| 1942 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1943 | if (!iface->phy[0]) { |
| 1944 | const char *phy = hostapd_drv_get_radio_name(hapd); |
| 1945 | if (phy) { |
| 1946 | wpa_printf(MSG_DEBUG, "phy: %s", phy); |
| 1947 | os_strlcpy(iface->phy, phy, sizeof(iface->phy)); |
| 1948 | } |
| 1949 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1950 | |
| 1951 | /* |
| 1952 | * Make sure that all BSSes get configured with a pointer to the same |
| 1953 | * driver interface. |
| 1954 | */ |
| 1955 | for (i = 1; i < iface->num_bss; i++) { |
| 1956 | iface->bss[i]->driver = hapd->driver; |
| 1957 | iface->bss[i]->drv_priv = hapd->drv_priv; |
| 1958 | } |
| 1959 | |
| 1960 | if (hostapd_validate_bssid_configuration(iface)) |
| 1961 | return -1; |
| 1962 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1963 | /* |
| 1964 | * Initialize control interfaces early to allow external monitoring of |
| 1965 | * channel setup operations that may take considerable amount of time |
| 1966 | * especially for DFS cases. |
| 1967 | */ |
| 1968 | if (start_ctrl_iface(iface)) |
| 1969 | return -1; |
| 1970 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1971 | if (hapd->iconf->country[0] && hapd->iconf->country[1]) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1972 | char country[4], previous_country[4]; |
| 1973 | |
| 1974 | hostapd_set_state(iface, HAPD_IFACE_COUNTRY_UPDATE); |
| 1975 | if (hostapd_get_country(hapd, previous_country) < 0) |
| 1976 | previous_country[0] = '\0'; |
| 1977 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1978 | os_memcpy(country, hapd->iconf->country, 3); |
| 1979 | country[3] = '\0'; |
| 1980 | if (hostapd_set_country(hapd, country) < 0) { |
| 1981 | wpa_printf(MSG_ERROR, "Failed to set country code"); |
| 1982 | return -1; |
| 1983 | } |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1984 | |
| 1985 | wpa_printf(MSG_DEBUG, "Previous country code %s, new country code %s", |
| 1986 | previous_country, country); |
| 1987 | |
| 1988 | if (os_strncmp(previous_country, country, 2) != 0) { |
| 1989 | wpa_printf(MSG_DEBUG, "Continue interface setup after channel list update"); |
| 1990 | iface->wait_channel_update = 1; |
Dmitry Shmidt | 9767226 | 2014-02-03 13:02:54 -0800 | [diff] [blame] | 1991 | eloop_register_timeout(5, 0, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1992 | channel_list_update_timeout, |
| 1993 | iface, NULL); |
| 1994 | return 0; |
| 1995 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1996 | } |
| 1997 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1998 | return setup_interface2(iface); |
| 1999 | } |
| 2000 | |
| 2001 | |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 2002 | static int configured_fixed_chan_to_freq(struct hostapd_iface *iface) |
| 2003 | { |
| 2004 | int freq, i, j; |
| 2005 | |
| 2006 | if (!iface->conf->channel) |
| 2007 | return 0; |
| 2008 | if (iface->conf->op_class) { |
| 2009 | freq = ieee80211_chan_to_freq(NULL, iface->conf->op_class, |
| 2010 | iface->conf->channel); |
| 2011 | if (freq < 0) { |
| 2012 | wpa_printf(MSG_INFO, |
| 2013 | "Could not convert op_class %u channel %u to operating frequency", |
| 2014 | iface->conf->op_class, iface->conf->channel); |
| 2015 | return -1; |
| 2016 | } |
| 2017 | iface->freq = freq; |
| 2018 | return 0; |
| 2019 | } |
| 2020 | |
| 2021 | /* Old configurations using only 2.4/5/60 GHz bands may not specify the |
| 2022 | * op_class parameter. Select a matching channel from the configured |
| 2023 | * mode using the channel parameter for these cases. |
| 2024 | */ |
| 2025 | for (j = 0; j < iface->num_hw_features; j++) { |
| 2026 | struct hostapd_hw_modes *mode = &iface->hw_features[j]; |
| 2027 | |
| 2028 | if (iface->conf->hw_mode != HOSTAPD_MODE_IEEE80211ANY && |
| 2029 | iface->conf->hw_mode != mode->mode) |
| 2030 | continue; |
| 2031 | for (i = 0; i < mode->num_channels; i++) { |
| 2032 | struct hostapd_channel_data *chan = &mode->channels[i]; |
| 2033 | |
| 2034 | if (chan->chan == iface->conf->channel && |
| 2035 | !is_6ghz_freq(chan->freq)) { |
| 2036 | iface->freq = chan->freq; |
| 2037 | return 0; |
| 2038 | } |
| 2039 | } |
| 2040 | } |
| 2041 | |
| 2042 | wpa_printf(MSG_INFO, "Could not determine operating frequency"); |
| 2043 | return -1; |
| 2044 | } |
| 2045 | |
| 2046 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2047 | static void hostapd_set_6ghz_sec_chan(struct hostapd_iface *iface) |
| 2048 | { |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame] | 2049 | int bw; |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2050 | |
| 2051 | if (!is_6ghz_op_class(iface->conf->op_class)) |
| 2052 | return; |
| 2053 | |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame] | 2054 | bw = op_class_to_bandwidth(iface->conf->op_class); |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2055 | /* Assign the secondary channel if absent in config for |
| 2056 | * bandwidths > 20 MHz */ |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame] | 2057 | if (bw >= 40 && !iface->conf->secondary_channel) { |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2058 | if (((iface->conf->channel - 1) / 4) % 2) |
| 2059 | iface->conf->secondary_channel = -1; |
| 2060 | else |
| 2061 | iface->conf->secondary_channel = 1; |
| 2062 | } |
| 2063 | } |
| 2064 | |
| 2065 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2066 | static int setup_interface2(struct hostapd_iface *iface) |
| 2067 | { |
| 2068 | iface->wait_channel_update = 0; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 2069 | iface->is_no_ir = false; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2070 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2071 | if (hostapd_get_hw_features(iface)) { |
| 2072 | /* Not all drivers support this yet, so continue without hw |
| 2073 | * feature data. */ |
| 2074 | } else { |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 2075 | int ret; |
| 2076 | |
Sunil Ravi | af399a8 | 2024-05-05 20:56:55 +0000 | [diff] [blame^] | 2077 | if (iface->conf->acs && !iface->is_ch_switch_dfs) { |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 2078 | iface->freq = 0; |
| 2079 | iface->conf->channel = 0; |
| 2080 | } |
Sunil Ravi | af399a8 | 2024-05-05 20:56:55 +0000 | [diff] [blame^] | 2081 | iface->is_ch_switch_dfs = false; |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 2082 | |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 2083 | ret = configured_fixed_chan_to_freq(iface); |
| 2084 | if (ret < 0) |
| 2085 | goto fail; |
| 2086 | |
| 2087 | if (iface->conf->op_class) { |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 2088 | enum oper_chan_width ch_width; |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 2089 | |
| 2090 | ch_width = op_class_to_ch_width(iface->conf->op_class); |
| 2091 | hostapd_set_oper_chwidth(iface->conf, ch_width); |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2092 | hostapd_set_6ghz_sec_chan(iface); |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 2093 | } |
| 2094 | |
| 2095 | ret = hostapd_select_hw_mode(iface); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2096 | if (ret < 0) { |
| 2097 | wpa_printf(MSG_ERROR, "Could not select hw_mode and " |
| 2098 | "channel. (%d)", ret); |
Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 2099 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2100 | } |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 2101 | if (ret == 1) { |
| 2102 | wpa_printf(MSG_DEBUG, "Interface initialization will be completed in a callback (ACS)"); |
| 2103 | return 0; |
| 2104 | } |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 2105 | ret = hostapd_check_edmg_capab(iface); |
| 2106 | if (ret < 0) |
| 2107 | goto fail; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2108 | ret = hostapd_check_he_6ghz_capab(iface); |
| 2109 | if (ret < 0) |
| 2110 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2111 | ret = hostapd_check_ht_capab(iface); |
| 2112 | if (ret < 0) |
Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 2113 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2114 | if (ret == 1) { |
| 2115 | wpa_printf(MSG_DEBUG, "Interface initialization will " |
| 2116 | "be completed in a callback"); |
| 2117 | return 0; |
| 2118 | } |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 2119 | |
| 2120 | if (iface->conf->ieee80211h) |
| 2121 | wpa_printf(MSG_DEBUG, "DFS support is enabled"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2122 | } |
| 2123 | return hostapd_setup_interface_complete(iface, 0); |
Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 2124 | |
| 2125 | fail: |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 2126 | if (iface->is_no_ir) { |
| 2127 | /* If AP is in NO_IR state, it can be reenabled by the driver |
| 2128 | * regulatory update and EVENT_CHANNEL_LIST_CHANGED. */ |
| 2129 | hostapd_set_state(iface, HAPD_IFACE_NO_IR); |
| 2130 | wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO, AP_EVENT_NO_IR); |
| 2131 | return 0; |
| 2132 | } |
| 2133 | |
Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 2134 | hostapd_set_state(iface, HAPD_IFACE_DISABLED); |
| 2135 | wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO, AP_EVENT_DISABLED); |
| 2136 | if (iface->interfaces && iface->interfaces->terminate_on_error) |
| 2137 | eloop_terminate(); |
| 2138 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2139 | } |
| 2140 | |
| 2141 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2142 | #ifdef CONFIG_FST |
| 2143 | |
| 2144 | static const u8 * fst_hostapd_get_bssid_cb(void *ctx) |
| 2145 | { |
| 2146 | struct hostapd_data *hapd = ctx; |
| 2147 | |
| 2148 | return hapd->own_addr; |
| 2149 | } |
| 2150 | |
| 2151 | |
| 2152 | static void fst_hostapd_get_channel_info_cb(void *ctx, |
| 2153 | enum hostapd_hw_mode *hw_mode, |
| 2154 | u8 *channel) |
| 2155 | { |
| 2156 | struct hostapd_data *hapd = ctx; |
| 2157 | |
| 2158 | *hw_mode = ieee80211_freq_to_chan(hapd->iface->freq, channel); |
| 2159 | } |
| 2160 | |
| 2161 | |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 2162 | static int fst_hostapd_get_hw_modes_cb(void *ctx, |
| 2163 | struct hostapd_hw_modes **modes) |
| 2164 | { |
| 2165 | struct hostapd_data *hapd = ctx; |
| 2166 | |
| 2167 | *modes = hapd->iface->hw_features; |
| 2168 | return hapd->iface->num_hw_features; |
| 2169 | } |
| 2170 | |
| 2171 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2172 | static void fst_hostapd_set_ies_cb(void *ctx, const struct wpabuf *fst_ies) |
| 2173 | { |
| 2174 | struct hostapd_data *hapd = ctx; |
| 2175 | |
| 2176 | if (hapd->iface->fst_ies != fst_ies) { |
| 2177 | hapd->iface->fst_ies = fst_ies; |
| 2178 | if (ieee802_11_set_beacon(hapd)) |
| 2179 | wpa_printf(MSG_WARNING, "FST: Cannot set beacon"); |
| 2180 | } |
| 2181 | } |
| 2182 | |
| 2183 | |
| 2184 | static int fst_hostapd_send_action_cb(void *ctx, const u8 *da, |
| 2185 | struct wpabuf *buf) |
| 2186 | { |
| 2187 | struct hostapd_data *hapd = ctx; |
| 2188 | |
| 2189 | return hostapd_drv_send_action(hapd, hapd->iface->freq, 0, da, |
| 2190 | wpabuf_head(buf), wpabuf_len(buf)); |
| 2191 | } |
| 2192 | |
| 2193 | |
| 2194 | static const struct wpabuf * fst_hostapd_get_mb_ie_cb(void *ctx, const u8 *addr) |
| 2195 | { |
| 2196 | struct hostapd_data *hapd = ctx; |
| 2197 | struct sta_info *sta = ap_get_sta(hapd, addr); |
| 2198 | |
| 2199 | return sta ? sta->mb_ies : NULL; |
| 2200 | } |
| 2201 | |
| 2202 | |
| 2203 | static void fst_hostapd_update_mb_ie_cb(void *ctx, const u8 *addr, |
| 2204 | const u8 *buf, size_t size) |
| 2205 | { |
| 2206 | struct hostapd_data *hapd = ctx; |
| 2207 | struct sta_info *sta = ap_get_sta(hapd, addr); |
| 2208 | |
| 2209 | if (sta) { |
| 2210 | struct mb_ies_info info; |
| 2211 | |
| 2212 | if (!mb_ies_info_by_ies(&info, buf, size)) { |
| 2213 | wpabuf_free(sta->mb_ies); |
| 2214 | sta->mb_ies = mb_ies_by_info(&info); |
| 2215 | } |
| 2216 | } |
| 2217 | } |
| 2218 | |
| 2219 | |
| 2220 | static const u8 * fst_hostapd_get_sta(struct fst_get_peer_ctx **get_ctx, |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 2221 | bool mb_only) |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2222 | { |
| 2223 | struct sta_info *s = (struct sta_info *) *get_ctx; |
| 2224 | |
| 2225 | if (mb_only) { |
| 2226 | for (; s && !s->mb_ies; s = s->next) |
| 2227 | ; |
| 2228 | } |
| 2229 | |
| 2230 | if (s) { |
| 2231 | *get_ctx = (struct fst_get_peer_ctx *) s->next; |
| 2232 | |
| 2233 | return s->addr; |
| 2234 | } |
| 2235 | |
| 2236 | *get_ctx = NULL; |
| 2237 | return NULL; |
| 2238 | } |
| 2239 | |
| 2240 | |
| 2241 | static const u8 * fst_hostapd_get_peer_first(void *ctx, |
| 2242 | struct fst_get_peer_ctx **get_ctx, |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 2243 | bool mb_only) |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2244 | { |
| 2245 | struct hostapd_data *hapd = ctx; |
| 2246 | |
| 2247 | *get_ctx = (struct fst_get_peer_ctx *) hapd->sta_list; |
| 2248 | |
| 2249 | return fst_hostapd_get_sta(get_ctx, mb_only); |
| 2250 | } |
| 2251 | |
| 2252 | |
| 2253 | static const u8 * fst_hostapd_get_peer_next(void *ctx, |
| 2254 | struct fst_get_peer_ctx **get_ctx, |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 2255 | bool mb_only) |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2256 | { |
| 2257 | return fst_hostapd_get_sta(get_ctx, mb_only); |
| 2258 | } |
| 2259 | |
| 2260 | |
| 2261 | void fst_hostapd_fill_iface_obj(struct hostapd_data *hapd, |
| 2262 | struct fst_wpa_obj *iface_obj) |
| 2263 | { |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 2264 | os_memset(iface_obj, 0, sizeof(*iface_obj)); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2265 | iface_obj->ctx = hapd; |
| 2266 | iface_obj->get_bssid = fst_hostapd_get_bssid_cb; |
| 2267 | iface_obj->get_channel_info = fst_hostapd_get_channel_info_cb; |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 2268 | iface_obj->get_hw_modes = fst_hostapd_get_hw_modes_cb; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2269 | iface_obj->set_ies = fst_hostapd_set_ies_cb; |
| 2270 | iface_obj->send_action = fst_hostapd_send_action_cb; |
| 2271 | iface_obj->get_mb_ie = fst_hostapd_get_mb_ie_cb; |
| 2272 | iface_obj->update_mb_ie = fst_hostapd_update_mb_ie_cb; |
| 2273 | iface_obj->get_peer_first = fst_hostapd_get_peer_first; |
| 2274 | iface_obj->get_peer_next = fst_hostapd_get_peer_next; |
| 2275 | } |
| 2276 | |
| 2277 | #endif /* CONFIG_FST */ |
| 2278 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2279 | #ifdef CONFIG_OWE |
| 2280 | |
| 2281 | static int hostapd_owe_iface_iter(struct hostapd_iface *iface, void *ctx) |
| 2282 | { |
| 2283 | struct hostapd_data *hapd = ctx; |
| 2284 | size_t i; |
| 2285 | |
| 2286 | for (i = 0; i < iface->num_bss; i++) { |
| 2287 | struct hostapd_data *bss = iface->bss[i]; |
| 2288 | |
| 2289 | if (os_strcmp(hapd->conf->owe_transition_ifname, |
| 2290 | bss->conf->iface) != 0) |
| 2291 | continue; |
| 2292 | |
| 2293 | wpa_printf(MSG_DEBUG, |
| 2294 | "OWE: ifname=%s found transition mode ifname=%s BSSID " |
| 2295 | MACSTR " SSID %s", |
| 2296 | hapd->conf->iface, bss->conf->iface, |
| 2297 | MAC2STR(bss->own_addr), |
| 2298 | wpa_ssid_txt(bss->conf->ssid.ssid, |
| 2299 | bss->conf->ssid.ssid_len)); |
| 2300 | if (!bss->conf->ssid.ssid_set || !bss->conf->ssid.ssid_len || |
| 2301 | is_zero_ether_addr(bss->own_addr)) |
| 2302 | continue; |
| 2303 | |
| 2304 | os_memcpy(hapd->conf->owe_transition_bssid, bss->own_addr, |
| 2305 | ETH_ALEN); |
| 2306 | os_memcpy(hapd->conf->owe_transition_ssid, |
| 2307 | bss->conf->ssid.ssid, bss->conf->ssid.ssid_len); |
| 2308 | hapd->conf->owe_transition_ssid_len = bss->conf->ssid.ssid_len; |
| 2309 | wpa_printf(MSG_DEBUG, |
| 2310 | "OWE: Copied transition mode information"); |
| 2311 | return 1; |
| 2312 | } |
| 2313 | |
| 2314 | return 0; |
| 2315 | } |
| 2316 | |
| 2317 | |
| 2318 | int hostapd_owe_trans_get_info(struct hostapd_data *hapd) |
| 2319 | { |
| 2320 | if (hapd->conf->owe_transition_ssid_len > 0 && |
| 2321 | !is_zero_ether_addr(hapd->conf->owe_transition_bssid)) |
| 2322 | return 0; |
| 2323 | |
| 2324 | /* Find transition mode SSID/BSSID information from a BSS operated by |
| 2325 | * this hostapd instance. */ |
| 2326 | if (!hapd->iface->interfaces || |
| 2327 | !hapd->iface->interfaces->for_each_interface) |
| 2328 | return hostapd_owe_iface_iter(hapd->iface, hapd); |
| 2329 | else |
| 2330 | return hapd->iface->interfaces->for_each_interface( |
| 2331 | hapd->iface->interfaces, hostapd_owe_iface_iter, hapd); |
| 2332 | } |
| 2333 | |
| 2334 | |
| 2335 | static int hostapd_owe_iface_iter2(struct hostapd_iface *iface, void *ctx) |
| 2336 | { |
| 2337 | size_t i; |
| 2338 | |
| 2339 | for (i = 0; i < iface->num_bss; i++) { |
| 2340 | struct hostapd_data *bss = iface->bss[i]; |
| 2341 | int res; |
| 2342 | |
| 2343 | if (!bss->conf->owe_transition_ifname[0]) |
| 2344 | continue; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2345 | if (bss->iface->state != HAPD_IFACE_ENABLED) { |
| 2346 | wpa_printf(MSG_DEBUG, |
| 2347 | "OWE: Interface %s state %s - defer beacon update", |
| 2348 | bss->conf->iface, |
| 2349 | hostapd_state_text(bss->iface->state)); |
| 2350 | continue; |
| 2351 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2352 | res = hostapd_owe_trans_get_info(bss); |
| 2353 | if (res == 0) |
| 2354 | continue; |
| 2355 | wpa_printf(MSG_DEBUG, |
| 2356 | "OWE: Matching transition mode interface enabled - update beacon data for %s", |
| 2357 | bss->conf->iface); |
| 2358 | ieee802_11_set_beacon(bss); |
| 2359 | } |
| 2360 | |
| 2361 | return 0; |
| 2362 | } |
| 2363 | |
| 2364 | #endif /* CONFIG_OWE */ |
| 2365 | |
| 2366 | |
| 2367 | static void hostapd_owe_update_trans(struct hostapd_iface *iface) |
| 2368 | { |
| 2369 | #ifdef CONFIG_OWE |
| 2370 | /* Check whether the enabled BSS can complete OWE transition mode |
| 2371 | * configuration for any pending interface. */ |
| 2372 | if (!iface->interfaces || |
| 2373 | !iface->interfaces->for_each_interface) |
| 2374 | hostapd_owe_iface_iter2(iface, NULL); |
| 2375 | else |
| 2376 | iface->interfaces->for_each_interface( |
| 2377 | iface->interfaces, hostapd_owe_iface_iter2, NULL); |
| 2378 | #endif /* CONFIG_OWE */ |
| 2379 | } |
| 2380 | |
| 2381 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2382 | static void hostapd_interface_setup_failure_handler(void *eloop_ctx, |
| 2383 | void *timeout_ctx) |
| 2384 | { |
| 2385 | struct hostapd_iface *iface = eloop_ctx; |
| 2386 | struct hostapd_data *hapd; |
| 2387 | |
| 2388 | if (iface->num_bss < 1 || !iface->bss || !iface->bss[0]) |
| 2389 | return; |
| 2390 | hapd = iface->bss[0]; |
| 2391 | if (hapd->setup_complete_cb) |
| 2392 | hapd->setup_complete_cb(hapd->setup_complete_cb_ctx); |
| 2393 | } |
| 2394 | |
| 2395 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2396 | static int hostapd_setup_interface_complete_sync(struct hostapd_iface *iface, |
| 2397 | int err) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2398 | { |
| 2399 | struct hostapd_data *hapd = iface->bss[0]; |
| 2400 | size_t j; |
| 2401 | u8 *prev_addr; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2402 | int delay_apply_cfg = 0; |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 2403 | int res_dfs_offload = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2404 | |
Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 2405 | if (err) |
| 2406 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2407 | |
| 2408 | wpa_printf(MSG_DEBUG, "Completing interface initialization"); |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 2409 | if (iface->freq) { |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 2410 | #ifdef NEED_AP_MLME |
| 2411 | int res; |
| 2412 | #endif /* NEED_AP_MLME */ |
| 2413 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2414 | wpa_printf(MSG_DEBUG, "Mode: %s Channel: %d " |
| 2415 | "Frequency: %d MHz", |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2416 | hostapd_hw_mode_txt(iface->conf->hw_mode), |
| 2417 | iface->conf->channel, iface->freq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2418 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 2419 | #ifdef NEED_AP_MLME |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 2420 | /* Handle DFS only if it is not offloaded to the driver */ |
| 2421 | if (!(iface->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD)) { |
| 2422 | /* Check DFS */ |
| 2423 | res = hostapd_handle_dfs(iface); |
| 2424 | if (res <= 0) { |
| 2425 | if (res < 0) |
| 2426 | goto fail; |
| 2427 | return res; |
| 2428 | } |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 2429 | } else { |
| 2430 | /* If DFS is offloaded to the driver */ |
| 2431 | res_dfs_offload = hostapd_handle_dfs_offload(iface); |
| 2432 | if (res_dfs_offload <= 0) { |
| 2433 | if (res_dfs_offload < 0) |
| 2434 | goto fail; |
| 2435 | } else { |
| 2436 | wpa_printf(MSG_DEBUG, |
| 2437 | "Proceed with AP/channel setup"); |
| 2438 | /* |
| 2439 | * If this is a DFS channel, move to completing |
| 2440 | * AP setup. |
| 2441 | */ |
| 2442 | if (res_dfs_offload == 1) |
| 2443 | goto dfs_offload; |
| 2444 | /* Otherwise fall through. */ |
| 2445 | } |
Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 2446 | } |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 2447 | #endif /* NEED_AP_MLME */ |
| 2448 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2449 | #ifdef CONFIG_MESH |
| 2450 | if (iface->mconf != NULL) { |
| 2451 | wpa_printf(MSG_DEBUG, |
| 2452 | "%s: Mesh configuration will be applied while joining the mesh network", |
| 2453 | iface->bss[0]->conf->iface); |
| 2454 | delay_apply_cfg = 1; |
| 2455 | } |
| 2456 | #endif /* CONFIG_MESH */ |
| 2457 | |
| 2458 | if (!delay_apply_cfg && |
| 2459 | hostapd_set_freq(hapd, hapd->iconf->hw_mode, iface->freq, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2460 | hapd->iconf->channel, |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 2461 | hapd->iconf->enable_edmg, |
| 2462 | hapd->iconf->edmg_channel, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2463 | hapd->iconf->ieee80211n, |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2464 | hapd->iconf->ieee80211ac, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 2465 | hapd->iconf->ieee80211ax, |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 2466 | hapd->iconf->ieee80211be, |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2467 | hapd->iconf->secondary_channel, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 2468 | hostapd_get_oper_chwidth(hapd->iconf), |
| 2469 | hostapd_get_oper_centr_freq_seg0_idx( |
| 2470 | hapd->iconf), |
| 2471 | hostapd_get_oper_centr_freq_seg1_idx( |
| 2472 | hapd->iconf))) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2473 | wpa_printf(MSG_ERROR, "Could not set channel for " |
| 2474 | "kernel driver"); |
Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 2475 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2476 | } |
| 2477 | } |
| 2478 | |
| 2479 | if (iface->current_mode) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2480 | if (hostapd_prepare_rates(iface, iface->current_mode)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2481 | wpa_printf(MSG_ERROR, "Failed to prepare rates " |
| 2482 | "table."); |
| 2483 | hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211, |
| 2484 | HOSTAPD_LEVEL_WARNING, |
| 2485 | "Failed to prepare rates table."); |
Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 2486 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2487 | } |
| 2488 | } |
| 2489 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 2490 | if (hapd->iconf->rts_threshold >= -1 && |
| 2491 | hostapd_set_rts(hapd, hapd->iconf->rts_threshold) && |
| 2492 | hapd->iconf->rts_threshold >= -1) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2493 | wpa_printf(MSG_ERROR, "Could not set RTS threshold for " |
| 2494 | "kernel driver"); |
Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 2495 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2496 | } |
| 2497 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 2498 | if (hapd->iconf->fragm_threshold >= -1 && |
| 2499 | hostapd_set_frag(hapd, hapd->iconf->fragm_threshold) && |
| 2500 | hapd->iconf->fragm_threshold != -1) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2501 | wpa_printf(MSG_ERROR, "Could not set fragmentation threshold " |
| 2502 | "for kernel driver"); |
Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 2503 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2504 | } |
| 2505 | |
| 2506 | prev_addr = hapd->own_addr; |
| 2507 | |
| 2508 | for (j = 0; j < iface->num_bss; j++) { |
| 2509 | hapd = iface->bss[j]; |
| 2510 | if (j) |
| 2511 | os_memcpy(hapd->own_addr, prev_addr, ETH_ALEN); |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 2512 | if (hostapd_setup_bss(hapd, j == 0, !iface->conf->mbssid)) { |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 2513 | for (;;) { |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 2514 | hapd = iface->bss[j]; |
| 2515 | hostapd_bss_deinit_no_free(hapd); |
| 2516 | hostapd_free_hapd_data(hapd); |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 2517 | if (j == 0) |
| 2518 | break; |
| 2519 | j--; |
| 2520 | } |
Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 2521 | goto fail; |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 2522 | } |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2523 | if (is_zero_ether_addr(hapd->conf->bssid)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2524 | prev_addr = hapd->own_addr; |
| 2525 | } |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 2526 | |
| 2527 | if (hapd->iconf->mbssid) { |
| 2528 | for (j = 0; hapd->iconf->mbssid && j < iface->num_bss; j++) { |
| 2529 | hapd = iface->bss[j]; |
| 2530 | if (hostapd_start_beacon(hapd, true)) { |
| 2531 | for (;;) { |
| 2532 | hapd = iface->bss[j]; |
| 2533 | hostapd_bss_deinit_no_free(hapd); |
| 2534 | hostapd_free_hapd_data(hapd); |
| 2535 | if (j == 0) |
| 2536 | break; |
| 2537 | j--; |
| 2538 | } |
| 2539 | goto fail; |
| 2540 | } |
| 2541 | } |
| 2542 | } |
| 2543 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2544 | hapd = iface->bss[0]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2545 | |
| 2546 | hostapd_tx_queue_params(iface); |
| 2547 | |
| 2548 | ap_list_init(iface); |
| 2549 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 2550 | hostapd_set_acl(hapd); |
| 2551 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2552 | if (hostapd_driver_commit(hapd) < 0) { |
| 2553 | wpa_printf(MSG_ERROR, "%s: Failed to commit driver " |
| 2554 | "configuration", __func__); |
Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 2555 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2556 | } |
| 2557 | |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 2558 | /* |
| 2559 | * WPS UPnP module can be initialized only when the "upnp_iface" is up. |
| 2560 | * If "interface" and "upnp_iface" are the same (e.g., non-bridge |
| 2561 | * mode), the interface is up only after driver_commit, so initialize |
| 2562 | * WPS after driver_commit. |
| 2563 | */ |
| 2564 | for (j = 0; j < iface->num_bss; j++) { |
| 2565 | if (hostapd_init_wps_complete(iface->bss[j])) |
Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 2566 | goto fail; |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 2567 | } |
| 2568 | |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 2569 | if ((iface->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD) && |
| 2570 | !res_dfs_offload) { |
| 2571 | /* |
| 2572 | * If freq is DFS, and DFS is offloaded to the driver, then wait |
| 2573 | * for CAC to complete. |
| 2574 | */ |
| 2575 | wpa_printf(MSG_DEBUG, "%s: Wait for CAC to complete", __func__); |
| 2576 | return res_dfs_offload; |
| 2577 | } |
| 2578 | |
| 2579 | #ifdef NEED_AP_MLME |
| 2580 | dfs_offload: |
| 2581 | #endif /* NEED_AP_MLME */ |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2582 | |
| 2583 | #ifdef CONFIG_FST |
| 2584 | if (hapd->iconf->fst_cfg.group_id[0]) { |
| 2585 | struct fst_wpa_obj iface_obj; |
| 2586 | |
| 2587 | fst_hostapd_fill_iface_obj(hapd, &iface_obj); |
| 2588 | iface->fst = fst_attach(hapd->conf->iface, hapd->own_addr, |
| 2589 | &iface_obj, &hapd->iconf->fst_cfg); |
| 2590 | if (!iface->fst) { |
| 2591 | wpa_printf(MSG_ERROR, "Could not attach to FST %s", |
| 2592 | hapd->iconf->fst_cfg.group_id); |
| 2593 | goto fail; |
| 2594 | } |
| 2595 | } |
| 2596 | #endif /* CONFIG_FST */ |
| 2597 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2598 | hostapd_set_state(iface, HAPD_IFACE_ENABLED); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2599 | hostapd_owe_update_trans(iface); |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 2600 | airtime_policy_update_init(iface); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2601 | wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO, AP_EVENT_ENABLED); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2602 | if (hapd->setup_complete_cb) |
| 2603 | hapd->setup_complete_cb(hapd->setup_complete_cb_ctx); |
| 2604 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2605 | #ifdef CONFIG_MESH |
| 2606 | if (delay_apply_cfg && !iface->mconf) { |
| 2607 | wpa_printf(MSG_ERROR, "Error while completing mesh init"); |
| 2608 | goto fail; |
| 2609 | } |
| 2610 | #endif /* CONFIG_MESH */ |
| 2611 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2612 | wpa_printf(MSG_DEBUG, "%s: Setup of interface done.", |
| 2613 | iface->bss[0]->conf->iface); |
Dmitry Shmidt | b96dad4 | 2013-11-05 10:07:29 -0800 | [diff] [blame] | 2614 | if (iface->interfaces && iface->interfaces->terminate_on_error > 0) |
| 2615 | iface->interfaces->terminate_on_error--; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2616 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2617 | for (j = 0; j < iface->num_bss; j++) |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2618 | hostapd_neighbor_set_own_report(iface->bss[j]); |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2619 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 2620 | if (iface->interfaces && iface->interfaces->count > 1) |
| 2621 | ieee802_11_set_beacons(iface); |
| 2622 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2623 | return 0; |
Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 2624 | |
| 2625 | fail: |
| 2626 | wpa_printf(MSG_ERROR, "Interface initialization failed"); |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 2627 | |
| 2628 | if (iface->is_no_ir) { |
| 2629 | hostapd_set_state(iface, HAPD_IFACE_NO_IR); |
| 2630 | wpa_msg(hapd->msg_ctx, MSG_INFO, AP_EVENT_NO_IR); |
| 2631 | return 0; |
| 2632 | } |
| 2633 | |
Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 2634 | hostapd_set_state(iface, HAPD_IFACE_DISABLED); |
| 2635 | wpa_msg(hapd->msg_ctx, MSG_INFO, AP_EVENT_DISABLED); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2636 | #ifdef CONFIG_FST |
| 2637 | if (iface->fst) { |
| 2638 | fst_detach(iface->fst); |
| 2639 | iface->fst = NULL; |
| 2640 | } |
| 2641 | #endif /* CONFIG_FST */ |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2642 | |
| 2643 | if (iface->interfaces && iface->interfaces->terminate_on_error) { |
Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 2644 | eloop_terminate(); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2645 | } else if (hapd->setup_complete_cb) { |
| 2646 | /* |
| 2647 | * Calling hapd->setup_complete_cb directly may cause iface |
| 2648 | * deinitialization which may be accessed later by the caller. |
| 2649 | */ |
| 2650 | eloop_register_timeout(0, 0, |
| 2651 | hostapd_interface_setup_failure_handler, |
| 2652 | iface, NULL); |
| 2653 | } |
| 2654 | |
Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 2655 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2656 | } |
| 2657 | |
| 2658 | |
| 2659 | /** |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2660 | * hostapd_setup_interface_complete - Complete interface setup |
| 2661 | * |
| 2662 | * This function is called when previous steps in the interface setup has been |
| 2663 | * completed. This can also start operations, e.g., DFS, that will require |
| 2664 | * additional processing before interface is ready to be enabled. Such |
| 2665 | * operations will call this function from eloop callbacks when finished. |
| 2666 | */ |
| 2667 | int hostapd_setup_interface_complete(struct hostapd_iface *iface, int err) |
| 2668 | { |
| 2669 | struct hapd_interfaces *interfaces = iface->interfaces; |
| 2670 | struct hostapd_data *hapd = iface->bss[0]; |
| 2671 | unsigned int i; |
| 2672 | int not_ready_in_sync_ifaces = 0; |
| 2673 | |
| 2674 | if (!iface->need_to_start_in_sync) |
| 2675 | return hostapd_setup_interface_complete_sync(iface, err); |
| 2676 | |
| 2677 | if (err) { |
| 2678 | wpa_printf(MSG_ERROR, "Interface initialization failed"); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2679 | iface->need_to_start_in_sync = 0; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 2680 | |
| 2681 | if (iface->is_no_ir) { |
| 2682 | hostapd_set_state(iface, HAPD_IFACE_NO_IR); |
| 2683 | wpa_msg(hapd->msg_ctx, MSG_INFO, AP_EVENT_NO_IR); |
| 2684 | return 0; |
| 2685 | } |
| 2686 | |
| 2687 | hostapd_set_state(iface, HAPD_IFACE_DISABLED); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2688 | wpa_msg(hapd->msg_ctx, MSG_INFO, AP_EVENT_DISABLED); |
| 2689 | if (interfaces && interfaces->terminate_on_error) |
| 2690 | eloop_terminate(); |
| 2691 | return -1; |
| 2692 | } |
| 2693 | |
| 2694 | if (iface->ready_to_start_in_sync) { |
| 2695 | /* Already in ready and waiting. should never happpen */ |
| 2696 | return 0; |
| 2697 | } |
| 2698 | |
| 2699 | for (i = 0; i < interfaces->count; i++) { |
| 2700 | if (interfaces->iface[i]->need_to_start_in_sync && |
| 2701 | !interfaces->iface[i]->ready_to_start_in_sync) |
| 2702 | not_ready_in_sync_ifaces++; |
| 2703 | } |
| 2704 | |
| 2705 | /* |
| 2706 | * Check if this is the last interface, if yes then start all the other |
| 2707 | * waiting interfaces. If not, add this interface to the waiting list. |
| 2708 | */ |
| 2709 | if (not_ready_in_sync_ifaces > 1 && iface->state == HAPD_IFACE_DFS) { |
| 2710 | /* |
| 2711 | * If this interface went through CAC, do not synchronize, just |
| 2712 | * start immediately. |
| 2713 | */ |
| 2714 | iface->need_to_start_in_sync = 0; |
| 2715 | wpa_printf(MSG_INFO, |
| 2716 | "%s: Finished CAC - bypass sync and start interface", |
| 2717 | iface->bss[0]->conf->iface); |
| 2718 | return hostapd_setup_interface_complete_sync(iface, err); |
| 2719 | } |
| 2720 | |
| 2721 | if (not_ready_in_sync_ifaces > 1) { |
| 2722 | /* need to wait as there are other interfaces still coming up */ |
| 2723 | iface->ready_to_start_in_sync = 1; |
| 2724 | wpa_printf(MSG_INFO, |
| 2725 | "%s: Interface waiting to sync with other interfaces", |
| 2726 | iface->bss[0]->conf->iface); |
| 2727 | return 0; |
| 2728 | } |
| 2729 | |
| 2730 | wpa_printf(MSG_INFO, |
| 2731 | "%s: Last interface to sync - starting all interfaces", |
| 2732 | iface->bss[0]->conf->iface); |
| 2733 | iface->need_to_start_in_sync = 0; |
| 2734 | hostapd_setup_interface_complete_sync(iface, err); |
| 2735 | for (i = 0; i < interfaces->count; i++) { |
| 2736 | if (interfaces->iface[i]->need_to_start_in_sync && |
| 2737 | interfaces->iface[i]->ready_to_start_in_sync) { |
| 2738 | hostapd_setup_interface_complete_sync( |
| 2739 | interfaces->iface[i], 0); |
| 2740 | /* Only once the interfaces are sync started */ |
| 2741 | interfaces->iface[i]->need_to_start_in_sync = 0; |
| 2742 | } |
| 2743 | } |
| 2744 | |
| 2745 | return 0; |
| 2746 | } |
| 2747 | |
| 2748 | |
| 2749 | /** |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2750 | * hostapd_setup_interface - Setup of an interface |
| 2751 | * @iface: Pointer to interface data. |
| 2752 | * Returns: 0 on success, -1 on failure |
| 2753 | * |
| 2754 | * Initializes the driver interface, validates the configuration, |
| 2755 | * and sets driver parameters based on the configuration. |
| 2756 | * Flushes old stations, sets the channel, encryption, |
| 2757 | * beacons, and WDS links based on the configuration. |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2758 | * |
| 2759 | * If interface setup requires more time, e.g., to perform HT co-ex scans, ACS, |
| 2760 | * or DFS operations, this function returns 0 before such operations have been |
| 2761 | * completed. The pending operations are registered into eloop and will be |
| 2762 | * completed from eloop callbacks. Those callbacks end up calling |
| 2763 | * hostapd_setup_interface_complete() once setup has been completed. |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2764 | */ |
| 2765 | int hostapd_setup_interface(struct hostapd_iface *iface) |
| 2766 | { |
| 2767 | int ret; |
| 2768 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2769 | if (!iface->conf) |
| 2770 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2771 | ret = setup_interface(iface); |
| 2772 | if (ret) { |
| 2773 | wpa_printf(MSG_ERROR, "%s: Unable to setup interface.", |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2774 | iface->conf->bss[0]->iface); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2775 | return -1; |
| 2776 | } |
| 2777 | |
| 2778 | return 0; |
| 2779 | } |
| 2780 | |
| 2781 | |
| 2782 | /** |
| 2783 | * hostapd_alloc_bss_data - Allocate and initialize per-BSS data |
| 2784 | * @hapd_iface: Pointer to interface data |
| 2785 | * @conf: Pointer to per-interface configuration |
| 2786 | * @bss: Pointer to per-BSS configuration for this BSS |
| 2787 | * Returns: Pointer to allocated BSS data |
| 2788 | * |
| 2789 | * This function is used to allocate per-BSS data structure. This data will be |
| 2790 | * freed after hostapd_cleanup() is called for it during interface |
| 2791 | * deinitialization. |
| 2792 | */ |
| 2793 | struct hostapd_data * |
| 2794 | hostapd_alloc_bss_data(struct hostapd_iface *hapd_iface, |
| 2795 | struct hostapd_config *conf, |
| 2796 | struct hostapd_bss_config *bss) |
| 2797 | { |
| 2798 | struct hostapd_data *hapd; |
| 2799 | |
| 2800 | hapd = os_zalloc(sizeof(*hapd)); |
| 2801 | if (hapd == NULL) |
| 2802 | return NULL; |
| 2803 | |
| 2804 | hapd->new_assoc_sta_cb = hostapd_new_assoc_sta; |
| 2805 | hapd->iconf = conf; |
| 2806 | hapd->conf = bss; |
| 2807 | hapd->iface = hapd_iface; |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 2808 | if (conf) |
| 2809 | hapd->driver = conf->driver; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2810 | hapd->ctrl_sock = -1; |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 2811 | dl_list_init(&hapd->ctrl_dst); |
Dmitry Shmidt | 7d17530 | 2016-09-06 13:11:34 -0700 | [diff] [blame] | 2812 | dl_list_init(&hapd->nr_db); |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 2813 | hapd->dhcp_sock = -1; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2814 | #ifdef CONFIG_IEEE80211R_AP |
| 2815 | dl_list_init(&hapd->l2_queue); |
| 2816 | dl_list_init(&hapd->l2_oui_queue); |
| 2817 | #endif /* CONFIG_IEEE80211R_AP */ |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 2818 | #ifdef CONFIG_SAE |
| 2819 | dl_list_init(&hapd->sae_commit_queue); |
| 2820 | #endif /* CONFIG_SAE */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2821 | |
| 2822 | return hapd; |
| 2823 | } |
| 2824 | |
| 2825 | |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 2826 | static void hostapd_bss_deinit(struct hostapd_data *hapd) |
| 2827 | { |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 2828 | if (!hapd) |
| 2829 | return; |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 2830 | wpa_printf(MSG_DEBUG, "%s: deinit bss %s", __func__, |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 2831 | hapd->conf ? hapd->conf->iface : "N/A"); |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 2832 | hostapd_bss_deinit_no_free(hapd); |
Dmitry Shmidt | f73259c | 2015-03-17 11:00:54 -0700 | [diff] [blame] | 2833 | wpa_msg(hapd->msg_ctx, MSG_INFO, AP_EVENT_DISABLED); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 2834 | #ifdef CONFIG_SQLITE |
| 2835 | if (hapd->rad_attr_db) { |
| 2836 | sqlite3_close(hapd->rad_attr_db); |
| 2837 | hapd->rad_attr_db = NULL; |
| 2838 | } |
| 2839 | #endif /* CONFIG_SQLITE */ |
Sunil Ravi | af399a8 | 2024-05-05 20:56:55 +0000 | [diff] [blame^] | 2840 | |
| 2841 | hostapd_bss_link_deinit(hapd); |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 2842 | hostapd_cleanup(hapd); |
| 2843 | } |
| 2844 | |
| 2845 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2846 | void hostapd_interface_deinit(struct hostapd_iface *iface) |
| 2847 | { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2848 | int j; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2849 | |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 2850 | wpa_printf(MSG_DEBUG, "%s(%p)", __func__, iface); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2851 | if (iface == NULL) |
| 2852 | return; |
| 2853 | |
Dmitry Shmidt | f73259c | 2015-03-17 11:00:54 -0700 | [diff] [blame] | 2854 | hostapd_set_state(iface, HAPD_IFACE_DISABLED); |
| 2855 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2856 | eloop_cancel_timeout(channel_list_update_timeout, iface, NULL); |
| 2857 | iface->wait_channel_update = 0; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 2858 | iface->is_no_ir = false; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2859 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2860 | #ifdef CONFIG_FST |
| 2861 | if (iface->fst) { |
| 2862 | fst_detach(iface->fst); |
| 2863 | iface->fst = NULL; |
| 2864 | } |
| 2865 | #endif /* CONFIG_FST */ |
| 2866 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 2867 | for (j = (int) iface->num_bss - 1; j >= 0; j--) { |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 2868 | if (!iface->bss) |
| 2869 | break; |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 2870 | hostapd_bss_deinit(iface->bss[j]); |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 2871 | } |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2872 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2873 | #ifdef NEED_AP_MLME |
| 2874 | hostapd_stop_setup_timers(iface); |
| 2875 | eloop_cancel_timeout(ap_ht2040_timeout, iface, NULL); |
| 2876 | #endif /* NEED_AP_MLME */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2877 | } |
| 2878 | |
| 2879 | |
Sunil Ravi | af399a8 | 2024-05-05 20:56:55 +0000 | [diff] [blame^] | 2880 | #ifdef CONFIG_IEEE80211BE |
| 2881 | |
| 2882 | static void hostapd_mld_ref_inc(struct hostapd_mld *mld) |
| 2883 | { |
| 2884 | if (!mld) |
| 2885 | return; |
| 2886 | |
| 2887 | if (mld->refcount == HOSTAPD_MLD_MAX_REF_COUNT) { |
| 2888 | wpa_printf(MSG_ERROR, "AP MLD %s: Ref count overflow", |
| 2889 | mld->name); |
| 2890 | return; |
| 2891 | } |
| 2892 | |
| 2893 | mld->refcount++; |
| 2894 | } |
| 2895 | |
| 2896 | |
| 2897 | static void hostapd_mld_ref_dec(struct hostapd_mld *mld) |
| 2898 | { |
| 2899 | if (!mld) |
| 2900 | return; |
| 2901 | |
| 2902 | if (!mld->refcount) { |
| 2903 | wpa_printf(MSG_ERROR, "AP MLD %s: Ref count underflow", |
| 2904 | mld->name); |
| 2905 | return; |
| 2906 | } |
| 2907 | |
| 2908 | mld->refcount--; |
| 2909 | } |
| 2910 | |
| 2911 | #endif /* CONFIG_IEEE80211BE */ |
| 2912 | |
| 2913 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2914 | void hostapd_interface_free(struct hostapd_iface *iface) |
| 2915 | { |
| 2916 | size_t j; |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 2917 | wpa_printf(MSG_DEBUG, "%s(%p)", __func__, iface); |
| 2918 | for (j = 0; j < iface->num_bss; j++) { |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 2919 | if (!iface->bss) |
| 2920 | break; |
Sunil Ravi | af399a8 | 2024-05-05 20:56:55 +0000 | [diff] [blame^] | 2921 | #ifdef CONFIG_IEEE80211BE |
| 2922 | if (iface->bss[j]) |
| 2923 | hostapd_mld_ref_dec(iface->bss[j]->mld); |
| 2924 | #endif /* CONFIG_IEEE80211BE */ |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 2925 | wpa_printf(MSG_DEBUG, "%s: free hapd %p", |
| 2926 | __func__, iface->bss[j]); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2927 | os_free(iface->bss[j]); |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 2928 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2929 | hostapd_cleanup_iface(iface); |
| 2930 | } |
| 2931 | |
| 2932 | |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 2933 | struct hostapd_iface * hostapd_alloc_iface(void) |
| 2934 | { |
| 2935 | struct hostapd_iface *hapd_iface; |
| 2936 | |
| 2937 | hapd_iface = os_zalloc(sizeof(*hapd_iface)); |
| 2938 | if (!hapd_iface) |
| 2939 | return NULL; |
| 2940 | |
| 2941 | dl_list_init(&hapd_iface->sta_seen); |
| 2942 | |
| 2943 | return hapd_iface; |
| 2944 | } |
| 2945 | |
| 2946 | |
Sunil Ravi | af399a8 | 2024-05-05 20:56:55 +0000 | [diff] [blame^] | 2947 | #ifdef CONFIG_IEEE80211BE |
| 2948 | static void hostapd_bss_alloc_link_id(struct hostapd_data *hapd) |
| 2949 | { |
| 2950 | hapd->mld_link_id = hapd->mld->next_link_id++; |
| 2951 | wpa_printf(MSG_DEBUG, "AP MLD: %s: Link ID %d assigned.", |
| 2952 | hapd->mld->name, hapd->mld_link_id); |
| 2953 | } |
| 2954 | #endif /* CONFIG_IEEE80211BE */ |
| 2955 | |
| 2956 | |
| 2957 | static void hostapd_bss_setup_multi_link(struct hostapd_data *hapd, |
| 2958 | struct hapd_interfaces *interfaces) |
| 2959 | { |
| 2960 | #ifdef CONFIG_IEEE80211BE |
| 2961 | struct hostapd_mld *mld, **all_mld; |
| 2962 | struct hostapd_bss_config *conf; |
| 2963 | size_t i; |
| 2964 | |
| 2965 | conf = hapd->conf; |
| 2966 | |
| 2967 | if (!hapd->iconf || !hapd->iconf->ieee80211be || !conf->mld_ap || |
| 2968 | conf->disable_11be) |
| 2969 | return; |
| 2970 | |
| 2971 | for (i = 0; i < interfaces->mld_count; i++) { |
| 2972 | mld = interfaces->mld[i]; |
| 2973 | |
| 2974 | if (!mld || os_strcmp(conf->iface, mld->name) != 0) |
| 2975 | continue; |
| 2976 | |
| 2977 | hapd->mld = mld; |
| 2978 | hostapd_mld_ref_inc(mld); |
| 2979 | hostapd_bss_alloc_link_id(hapd); |
| 2980 | break; |
| 2981 | } |
| 2982 | |
| 2983 | if (hapd->mld) |
| 2984 | return; |
| 2985 | |
| 2986 | mld = os_zalloc(sizeof(struct hostapd_mld)); |
| 2987 | if (!mld) |
| 2988 | goto fail; |
| 2989 | |
| 2990 | os_strlcpy(mld->name, conf->iface, sizeof(conf->iface)); |
| 2991 | dl_list_init(&mld->links); |
| 2992 | |
| 2993 | wpa_printf(MSG_DEBUG, "AP MLD %s created", mld->name); |
| 2994 | |
| 2995 | hapd->mld = mld; |
| 2996 | hostapd_mld_ref_inc(mld); |
| 2997 | hostapd_bss_alloc_link_id(hapd); |
| 2998 | |
| 2999 | all_mld = os_realloc_array(interfaces->mld, interfaces->mld_count + 1, |
| 3000 | sizeof(struct hostapd_mld *)); |
| 3001 | if (!all_mld) |
| 3002 | goto fail; |
| 3003 | |
| 3004 | interfaces->mld = all_mld; |
| 3005 | interfaces->mld[interfaces->mld_count] = mld; |
| 3006 | interfaces->mld_count++; |
| 3007 | |
| 3008 | return; |
| 3009 | fail: |
| 3010 | if (!mld) |
| 3011 | return; |
| 3012 | |
| 3013 | wpa_printf(MSG_DEBUG, "AP MLD %s: free mld %p", mld->name, mld); |
| 3014 | os_free(mld); |
| 3015 | hapd->mld = NULL; |
| 3016 | #endif /* CONFIG_IEEE80211BE */ |
| 3017 | } |
| 3018 | |
| 3019 | |
| 3020 | static void hostapd_cleanup_unused_mlds(struct hapd_interfaces *interfaces) |
| 3021 | { |
| 3022 | #ifdef CONFIG_IEEE80211BE |
| 3023 | struct hostapd_mld *mld, **all_mld; |
| 3024 | size_t i, j, num_mlds; |
| 3025 | bool forced_remove, remove; |
| 3026 | |
| 3027 | if (!interfaces->mld) |
| 3028 | return; |
| 3029 | |
| 3030 | num_mlds = interfaces->mld_count; |
| 3031 | |
| 3032 | for (i = 0; i < interfaces->mld_count; i++) { |
| 3033 | mld = interfaces->mld[i]; |
| 3034 | if (!mld) |
| 3035 | continue; |
| 3036 | |
| 3037 | remove = false; |
| 3038 | forced_remove = false; |
| 3039 | |
| 3040 | if (!mld->refcount) |
| 3041 | remove = true; |
| 3042 | |
| 3043 | /* If MLD is still being referenced but the number of interfaces |
| 3044 | * is zero, it is safe to force its deletion. Normally, this |
| 3045 | * should not happen but even if it does, let us free the |
| 3046 | * memory. |
| 3047 | */ |
| 3048 | if (!remove && !interfaces->count) |
| 3049 | forced_remove = true; |
| 3050 | |
| 3051 | if (!remove && !forced_remove) |
| 3052 | continue; |
| 3053 | |
| 3054 | wpa_printf(MSG_DEBUG, "AP MLD %s: Freed%s", mld->name, |
| 3055 | forced_remove ? " (forced)" : ""); |
| 3056 | os_free(mld); |
| 3057 | interfaces->mld[i] = NULL; |
| 3058 | num_mlds--; |
| 3059 | } |
| 3060 | |
| 3061 | if (!num_mlds) { |
| 3062 | interfaces->mld_count = 0; |
| 3063 | os_free(interfaces->mld); |
| 3064 | interfaces->mld = NULL; |
| 3065 | return; |
| 3066 | } |
| 3067 | |
| 3068 | all_mld = os_zalloc(num_mlds * sizeof(struct hostapd_mld *)); |
| 3069 | if (!all_mld) { |
| 3070 | wpa_printf(MSG_ERROR, |
| 3071 | "AP MLD: Failed to re-allocate the MLDs. Expect issues"); |
| 3072 | return; |
| 3073 | } |
| 3074 | |
| 3075 | for (i = 0, j = 0; i < interfaces->mld_count; i++) { |
| 3076 | mld = interfaces->mld[i]; |
| 3077 | if (!mld) |
| 3078 | continue; |
| 3079 | |
| 3080 | all_mld[j++] = mld; |
| 3081 | } |
| 3082 | |
| 3083 | /* This should not happen */ |
| 3084 | if (j != num_mlds) { |
| 3085 | wpa_printf(MSG_DEBUG, |
| 3086 | "AP MLD: Some error occurred while reallocating MLDs. Expect issues."); |
| 3087 | os_free(all_mld); |
| 3088 | return; |
| 3089 | } |
| 3090 | |
| 3091 | os_free(interfaces->mld); |
| 3092 | interfaces->mld = all_mld; |
| 3093 | interfaces->mld_count = num_mlds; |
| 3094 | #endif /* CONFIG_IEEE80211BE */ |
| 3095 | } |
| 3096 | |
| 3097 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3098 | /** |
| 3099 | * hostapd_init - Allocate and initialize per-interface data |
| 3100 | * @config_file: Path to the configuration file |
| 3101 | * Returns: Pointer to the allocated interface data or %NULL on failure |
| 3102 | * |
| 3103 | * This function is used to allocate main data structures for per-interface |
| 3104 | * data. The allocated data buffer will be freed by calling |
| 3105 | * hostapd_cleanup_iface(). |
| 3106 | */ |
| 3107 | struct hostapd_iface * hostapd_init(struct hapd_interfaces *interfaces, |
| 3108 | const char *config_file) |
| 3109 | { |
| 3110 | struct hostapd_iface *hapd_iface = NULL; |
| 3111 | struct hostapd_config *conf = NULL; |
| 3112 | struct hostapd_data *hapd; |
| 3113 | size_t i; |
| 3114 | |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 3115 | hapd_iface = hostapd_alloc_iface(); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3116 | if (hapd_iface == NULL) |
| 3117 | goto fail; |
| 3118 | |
| 3119 | hapd_iface->config_fname = os_strdup(config_file); |
| 3120 | if (hapd_iface->config_fname == NULL) |
| 3121 | goto fail; |
| 3122 | |
| 3123 | conf = interfaces->config_read_cb(hapd_iface->config_fname); |
| 3124 | if (conf == NULL) |
| 3125 | goto fail; |
| 3126 | hapd_iface->conf = conf; |
| 3127 | |
| 3128 | hapd_iface->num_bss = conf->num_bss; |
| 3129 | hapd_iface->bss = os_calloc(conf->num_bss, |
| 3130 | sizeof(struct hostapd_data *)); |
| 3131 | if (hapd_iface->bss == NULL) |
| 3132 | goto fail; |
| 3133 | |
| 3134 | for (i = 0; i < conf->num_bss; i++) { |
| 3135 | hapd = hapd_iface->bss[i] = |
| 3136 | hostapd_alloc_bss_data(hapd_iface, conf, |
| 3137 | conf->bss[i]); |
| 3138 | if (hapd == NULL) |
| 3139 | goto fail; |
| 3140 | hapd->msg_ctx = hapd; |
Sunil Ravi | af399a8 | 2024-05-05 20:56:55 +0000 | [diff] [blame^] | 3141 | hostapd_bss_setup_multi_link(hapd, interfaces); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3142 | } |
| 3143 | |
Sunil Ravi | af399a8 | 2024-05-05 20:56:55 +0000 | [diff] [blame^] | 3144 | hapd_iface->is_ch_switch_dfs = false; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3145 | return hapd_iface; |
| 3146 | |
| 3147 | fail: |
| 3148 | wpa_printf(MSG_ERROR, "Failed to set up interface with %s", |
| 3149 | config_file); |
| 3150 | if (conf) |
| 3151 | hostapd_config_free(conf); |
| 3152 | if (hapd_iface) { |
| 3153 | os_free(hapd_iface->config_fname); |
| 3154 | os_free(hapd_iface->bss); |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 3155 | wpa_printf(MSG_DEBUG, "%s: free iface %p", |
| 3156 | __func__, hapd_iface); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3157 | os_free(hapd_iface); |
| 3158 | } |
| 3159 | return NULL; |
| 3160 | } |
| 3161 | |
| 3162 | |
| 3163 | static int ifname_in_use(struct hapd_interfaces *interfaces, const char *ifname) |
| 3164 | { |
| 3165 | size_t i, j; |
| 3166 | |
| 3167 | for (i = 0; i < interfaces->count; i++) { |
| 3168 | struct hostapd_iface *iface = interfaces->iface[i]; |
| 3169 | for (j = 0; j < iface->num_bss; j++) { |
| 3170 | struct hostapd_data *hapd = iface->bss[j]; |
| 3171 | if (os_strcmp(ifname, hapd->conf->iface) == 0) |
| 3172 | return 1; |
| 3173 | } |
| 3174 | } |
| 3175 | |
| 3176 | return 0; |
| 3177 | } |
| 3178 | |
| 3179 | |
| 3180 | /** |
| 3181 | * hostapd_interface_init_bss - Read configuration file and init BSS data |
| 3182 | * |
| 3183 | * This function is used to parse configuration file for a BSS. This BSS is |
| 3184 | * added to an existing interface sharing the same radio (if any) or a new |
| 3185 | * interface is created if this is the first interface on a radio. This |
| 3186 | * allocate memory for the BSS. No actual driver operations are started. |
| 3187 | * |
| 3188 | * This is similar to hostapd_interface_init(), but for a case where the |
| 3189 | * configuration is used to add a single BSS instead of all BSSes for a radio. |
| 3190 | */ |
| 3191 | struct hostapd_iface * |
| 3192 | hostapd_interface_init_bss(struct hapd_interfaces *interfaces, const char *phy, |
| 3193 | const char *config_fname, int debug) |
| 3194 | { |
| 3195 | struct hostapd_iface *new_iface = NULL, *iface = NULL; |
| 3196 | struct hostapd_data *hapd; |
| 3197 | int k; |
| 3198 | size_t i, bss_idx; |
| 3199 | |
| 3200 | if (!phy || !*phy) |
| 3201 | return NULL; |
| 3202 | |
| 3203 | for (i = 0; i < interfaces->count; i++) { |
| 3204 | if (os_strcmp(interfaces->iface[i]->phy, phy) == 0) { |
| 3205 | iface = interfaces->iface[i]; |
| 3206 | break; |
| 3207 | } |
| 3208 | } |
| 3209 | |
| 3210 | wpa_printf(MSG_INFO, "Configuration file: %s (phy %s)%s", |
| 3211 | config_fname, phy, iface ? "" : " --> new PHY"); |
| 3212 | if (iface) { |
| 3213 | struct hostapd_config *conf; |
| 3214 | struct hostapd_bss_config **tmp_conf; |
| 3215 | struct hostapd_data **tmp_bss; |
| 3216 | struct hostapd_bss_config *bss; |
| 3217 | const char *ifname; |
| 3218 | |
| 3219 | /* Add new BSS to existing iface */ |
| 3220 | conf = interfaces->config_read_cb(config_fname); |
| 3221 | if (conf == NULL) |
| 3222 | return NULL; |
| 3223 | if (conf->num_bss > 1) { |
| 3224 | wpa_printf(MSG_ERROR, "Multiple BSSes specified in BSS-config"); |
| 3225 | hostapd_config_free(conf); |
| 3226 | return NULL; |
| 3227 | } |
| 3228 | |
| 3229 | ifname = conf->bss[0]->iface; |
| 3230 | if (ifname[0] != '\0' && ifname_in_use(interfaces, ifname)) { |
| 3231 | wpa_printf(MSG_ERROR, |
| 3232 | "Interface name %s already in use", ifname); |
| 3233 | hostapd_config_free(conf); |
| 3234 | return NULL; |
| 3235 | } |
| 3236 | |
| 3237 | tmp_conf = os_realloc_array( |
| 3238 | iface->conf->bss, iface->conf->num_bss + 1, |
| 3239 | sizeof(struct hostapd_bss_config *)); |
| 3240 | tmp_bss = os_realloc_array(iface->bss, iface->num_bss + 1, |
| 3241 | sizeof(struct hostapd_data *)); |
| 3242 | if (tmp_bss) |
| 3243 | iface->bss = tmp_bss; |
| 3244 | if (tmp_conf) { |
| 3245 | iface->conf->bss = tmp_conf; |
| 3246 | iface->conf->last_bss = tmp_conf[0]; |
| 3247 | } |
| 3248 | if (tmp_bss == NULL || tmp_conf == NULL) { |
| 3249 | hostapd_config_free(conf); |
| 3250 | return NULL; |
| 3251 | } |
| 3252 | bss = iface->conf->bss[iface->conf->num_bss] = conf->bss[0]; |
| 3253 | iface->conf->num_bss++; |
| 3254 | |
| 3255 | hapd = hostapd_alloc_bss_data(iface, iface->conf, bss); |
| 3256 | if (hapd == NULL) { |
| 3257 | iface->conf->num_bss--; |
| 3258 | hostapd_config_free(conf); |
| 3259 | return NULL; |
| 3260 | } |
| 3261 | iface->conf->last_bss = bss; |
| 3262 | iface->bss[iface->num_bss] = hapd; |
| 3263 | hapd->msg_ctx = hapd; |
Sunil Ravi | af399a8 | 2024-05-05 20:56:55 +0000 | [diff] [blame^] | 3264 | hostapd_bss_setup_multi_link(hapd, interfaces); |
| 3265 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3266 | |
| 3267 | bss_idx = iface->num_bss++; |
| 3268 | conf->num_bss--; |
| 3269 | conf->bss[0] = NULL; |
| 3270 | hostapd_config_free(conf); |
| 3271 | } else { |
| 3272 | /* Add a new iface with the first BSS */ |
| 3273 | new_iface = iface = hostapd_init(interfaces, config_fname); |
| 3274 | if (!iface) |
| 3275 | return NULL; |
| 3276 | os_strlcpy(iface->phy, phy, sizeof(iface->phy)); |
| 3277 | iface->interfaces = interfaces; |
| 3278 | bss_idx = 0; |
| 3279 | } |
| 3280 | |
| 3281 | for (k = 0; k < debug; k++) { |
| 3282 | if (iface->bss[bss_idx]->conf->logger_stdout_level > 0) |
| 3283 | iface->bss[bss_idx]->conf->logger_stdout_level--; |
| 3284 | } |
| 3285 | |
| 3286 | if (iface->conf->bss[bss_idx]->iface[0] == '\0' && |
| 3287 | !hostapd_drv_none(iface->bss[bss_idx])) { |
| 3288 | wpa_printf(MSG_ERROR, "Interface name not specified in %s", |
| 3289 | config_fname); |
| 3290 | if (new_iface) |
| 3291 | hostapd_interface_deinit_free(new_iface); |
| 3292 | return NULL; |
| 3293 | } |
| 3294 | |
| 3295 | return iface; |
| 3296 | } |
| 3297 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3298 | |
Sunil Ravi | af399a8 | 2024-05-05 20:56:55 +0000 | [diff] [blame^] | 3299 | static void hostapd_cleanup_driver(const struct wpa_driver_ops *driver, |
| 3300 | void *drv_priv, struct hostapd_iface *iface) |
| 3301 | { |
| 3302 | #ifdef CONFIG_IEEE80211BE |
| 3303 | if (!driver || !driver->hapd_deinit || !drv_priv) |
| 3304 | return; |
| 3305 | |
| 3306 | /* In case of non-ML operation, de-init. But if ML operation exist, |
| 3307 | * even if that's the last BSS in the interface, the driver (drv) could |
| 3308 | * be in use for a different AP MLD. Hence, need to check if drv is |
| 3309 | * still being used by some other BSS before de-initiallizing. */ |
| 3310 | if (!iface->bss[0]->conf->mld_ap) { |
| 3311 | driver->hapd_deinit(drv_priv); |
| 3312 | } else if (hostapd_mld_is_first_bss(iface->bss[0]) && |
| 3313 | driver->is_drv_shared && |
| 3314 | !driver->is_drv_shared(drv_priv, iface->bss[0])) { |
| 3315 | driver->hapd_deinit(drv_priv); |
| 3316 | } else if (hostapd_if_link_remove(iface->bss[0], |
| 3317 | WPA_IF_AP_BSS, |
| 3318 | iface->bss[0]->conf->iface, |
| 3319 | iface->bss[0]->mld_link_id)) { |
| 3320 | wpa_printf(MSG_WARNING, "Failed to remove BSS interface %s", |
| 3321 | iface->bss[0]->conf->iface); |
| 3322 | } |
| 3323 | #else /* CONFIG_IEEE80211BE */ |
| 3324 | driver->hapd_deinit(drv_priv); |
| 3325 | #endif /* CONFIG_IEEE80211BE */ |
| 3326 | iface->bss[0]->drv_priv = NULL; |
| 3327 | } |
| 3328 | |
| 3329 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3330 | void hostapd_interface_deinit_free(struct hostapd_iface *iface) |
| 3331 | { |
| 3332 | const struct wpa_driver_ops *driver; |
| 3333 | void *drv_priv; |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 3334 | |
| 3335 | wpa_printf(MSG_DEBUG, "%s(%p)", __func__, iface); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3336 | if (iface == NULL) |
| 3337 | return; |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 3338 | wpa_printf(MSG_DEBUG, "%s: num_bss=%u conf->num_bss=%u", |
| 3339 | __func__, (unsigned int) iface->num_bss, |
| 3340 | (unsigned int) iface->conf->num_bss); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3341 | driver = iface->bss[0]->driver; |
| 3342 | drv_priv = iface->bss[0]->drv_priv; |
| 3343 | hostapd_interface_deinit(iface); |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 3344 | wpa_printf(MSG_DEBUG, "%s: driver=%p drv_priv=%p -> hapd_deinit", |
| 3345 | __func__, driver, drv_priv); |
Sunil Ravi | af399a8 | 2024-05-05 20:56:55 +0000 | [diff] [blame^] | 3346 | hostapd_cleanup_driver(driver, drv_priv, iface); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3347 | hostapd_interface_free(iface); |
| 3348 | } |
| 3349 | |
| 3350 | |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 3351 | static void hostapd_deinit_driver(const struct wpa_driver_ops *driver, |
| 3352 | void *drv_priv, |
| 3353 | struct hostapd_iface *hapd_iface) |
| 3354 | { |
| 3355 | size_t j; |
| 3356 | |
| 3357 | wpa_printf(MSG_DEBUG, "%s: driver=%p drv_priv=%p -> hapd_deinit", |
| 3358 | __func__, driver, drv_priv); |
Sunil Ravi | af399a8 | 2024-05-05 20:56:55 +0000 | [diff] [blame^] | 3359 | |
| 3360 | hostapd_cleanup_driver(driver, drv_priv, hapd_iface); |
| 3361 | |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 3362 | if (driver && driver->hapd_deinit && drv_priv) { |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 3363 | for (j = 0; j < hapd_iface->num_bss; j++) { |
| 3364 | wpa_printf(MSG_DEBUG, "%s:bss[%d]->drv_priv=%p", |
| 3365 | __func__, (int) j, |
| 3366 | hapd_iface->bss[j]->drv_priv); |
Hai Shalom | 1dc4d20 | 2019-04-29 16:22:27 -0700 | [diff] [blame] | 3367 | if (hapd_iface->bss[j]->drv_priv == drv_priv) { |
Sunil Ravi | af399a8 | 2024-05-05 20:56:55 +0000 | [diff] [blame^] | 3368 | hapd_iface->bss[j]->drv_priv = NULL; |
Hai Shalom | 1dc4d20 | 2019-04-29 16:22:27 -0700 | [diff] [blame] | 3369 | hapd_iface->extended_capa = NULL; |
| 3370 | hapd_iface->extended_capa_mask = NULL; |
| 3371 | hapd_iface->extended_capa_len = 0; |
| 3372 | } |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 3373 | } |
| 3374 | } |
| 3375 | } |
| 3376 | |
| 3377 | |
Sunil Ravi | af399a8 | 2024-05-05 20:56:55 +0000 | [diff] [blame^] | 3378 | static void hostapd_refresh_all_iface_beacons(struct hostapd_iface *hapd_iface) |
| 3379 | { |
| 3380 | size_t j; |
| 3381 | |
| 3382 | if (!hapd_iface->interfaces || hapd_iface->interfaces->count <= 1) |
| 3383 | return; |
| 3384 | |
| 3385 | for (j = 0; j < hapd_iface->interfaces->count; j++) { |
| 3386 | if (hapd_iface->interfaces->iface[j] == hapd_iface) |
| 3387 | continue; |
| 3388 | |
| 3389 | ieee802_11_update_beacons(hapd_iface->interfaces->iface[j]); |
| 3390 | } |
| 3391 | } |
| 3392 | |
| 3393 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3394 | int hostapd_enable_iface(struct hostapd_iface *hapd_iface) |
| 3395 | { |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 3396 | size_t j; |
| 3397 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 3398 | if (!hapd_iface) |
| 3399 | return -1; |
| 3400 | |
| 3401 | if (hapd_iface->enable_iface_cb) |
| 3402 | return hapd_iface->enable_iface_cb(hapd_iface); |
| 3403 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3404 | if (hapd_iface->bss[0]->drv_priv != NULL) { |
| 3405 | wpa_printf(MSG_ERROR, "Interface %s already enabled", |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3406 | hapd_iface->conf->bss[0]->iface); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3407 | return -1; |
| 3408 | } |
| 3409 | |
| 3410 | wpa_printf(MSG_DEBUG, "Enable interface %s", |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3411 | hapd_iface->conf->bss[0]->iface); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3412 | |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 3413 | for (j = 0; j < hapd_iface->num_bss; j++) |
| 3414 | hostapd_set_security_params(hapd_iface->conf->bss[j], 1); |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 3415 | if (hostapd_config_check(hapd_iface->conf, 1) < 0) { |
| 3416 | wpa_printf(MSG_INFO, "Invalid configuration - cannot enable"); |
| 3417 | return -1; |
| 3418 | } |
| 3419 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3420 | if (hapd_iface->interfaces == NULL || |
| 3421 | hapd_iface->interfaces->driver_init == NULL || |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3422 | hapd_iface->interfaces->driver_init(hapd_iface)) |
| 3423 | return -1; |
| 3424 | |
| 3425 | if (hostapd_setup_interface(hapd_iface)) { |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 3426 | hostapd_deinit_driver(hapd_iface->bss[0]->driver, |
| 3427 | hapd_iface->bss[0]->drv_priv, |
| 3428 | hapd_iface); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3429 | return -1; |
| 3430 | } |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3431 | |
Sunil Ravi | af399a8 | 2024-05-05 20:56:55 +0000 | [diff] [blame^] | 3432 | hostapd_refresh_all_iface_beacons(hapd_iface); |
| 3433 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3434 | return 0; |
| 3435 | } |
| 3436 | |
| 3437 | |
| 3438 | int hostapd_reload_iface(struct hostapd_iface *hapd_iface) |
| 3439 | { |
| 3440 | size_t j; |
| 3441 | |
| 3442 | wpa_printf(MSG_DEBUG, "Reload interface %s", |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3443 | hapd_iface->conf->bss[0]->iface); |
| 3444 | for (j = 0; j < hapd_iface->num_bss; j++) |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 3445 | hostapd_set_security_params(hapd_iface->conf->bss[j], 1); |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 3446 | if (hostapd_config_check(hapd_iface->conf, 1) < 0) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3447 | wpa_printf(MSG_ERROR, "Updated configuration is invalid"); |
| 3448 | return -1; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3449 | } |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3450 | hostapd_clear_old(hapd_iface); |
| 3451 | for (j = 0; j < hapd_iface->num_bss; j++) |
| 3452 | hostapd_reload_bss(hapd_iface->bss[j]); |
| 3453 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3454 | return 0; |
| 3455 | } |
| 3456 | |
| 3457 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 3458 | int hostapd_reload_bss_only(struct hostapd_data *bss) |
| 3459 | { |
| 3460 | |
| 3461 | wpa_printf(MSG_DEBUG, "Reload BSS %s", bss->conf->iface); |
| 3462 | hostapd_set_security_params(bss->conf, 1); |
| 3463 | if (hostapd_config_check(bss->iconf, 1) < 0) { |
| 3464 | wpa_printf(MSG_ERROR, "Updated BSS configuration is invalid"); |
| 3465 | return -1; |
| 3466 | } |
| 3467 | hostapd_clear_old_bss(bss); |
| 3468 | hostapd_reload_bss(bss); |
| 3469 | return 0; |
| 3470 | } |
| 3471 | |
| 3472 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3473 | int hostapd_disable_iface(struct hostapd_iface *hapd_iface) |
| 3474 | { |
| 3475 | size_t j; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3476 | const struct wpa_driver_ops *driver; |
| 3477 | void *drv_priv; |
| 3478 | |
| 3479 | if (hapd_iface == NULL) |
| 3480 | return -1; |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 3481 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 3482 | if (hapd_iface->disable_iface_cb) |
| 3483 | return hapd_iface->disable_iface_cb(hapd_iface); |
| 3484 | |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 3485 | if (hapd_iface->bss[0]->drv_priv == NULL) { |
| 3486 | wpa_printf(MSG_INFO, "Interface %s already disabled", |
| 3487 | hapd_iface->conf->bss[0]->iface); |
| 3488 | return -1; |
| 3489 | } |
| 3490 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3491 | wpa_msg(hapd_iface->bss[0]->msg_ctx, MSG_INFO, AP_EVENT_DISABLED); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3492 | driver = hapd_iface->bss[0]->driver; |
| 3493 | drv_priv = hapd_iface->bss[0]->drv_priv; |
| 3494 | |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 3495 | hapd_iface->driver_ap_teardown = |
| 3496 | !!(hapd_iface->drv_flags & |
| 3497 | WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT); |
| 3498 | |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 3499 | #ifdef NEED_AP_MLME |
| 3500 | for (j = 0; j < hapd_iface->num_bss; j++) |
| 3501 | hostapd_cleanup_cs_params(hapd_iface->bss[j]); |
| 3502 | #endif /* NEED_AP_MLME */ |
| 3503 | |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 3504 | /* same as hostapd_interface_deinit without deinitializing ctrl-iface */ |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3505 | for (j = 0; j < hapd_iface->num_bss; j++) { |
| 3506 | struct hostapd_data *hapd = hapd_iface->bss[j]; |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 3507 | hostapd_bss_deinit_no_free(hapd); |
Sunil Ravi | af399a8 | 2024-05-05 20:56:55 +0000 | [diff] [blame^] | 3508 | hostapd_bss_link_deinit(hapd); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3509 | hostapd_free_hapd_data(hapd); |
| 3510 | } |
| 3511 | |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 3512 | hostapd_deinit_driver(driver, drv_priv, hapd_iface); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3513 | |
| 3514 | /* From hostapd_cleanup_iface: These were initialized in |
| 3515 | * hostapd_setup_interface and hostapd_setup_interface_complete |
| 3516 | */ |
| 3517 | hostapd_cleanup_iface_partial(hapd_iface); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3518 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3519 | wpa_printf(MSG_DEBUG, "Interface %s disabled", |
| 3520 | hapd_iface->bss[0]->conf->iface); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3521 | hostapd_set_state(hapd_iface, HAPD_IFACE_DISABLED); |
Sunil Ravi | af399a8 | 2024-05-05 20:56:55 +0000 | [diff] [blame^] | 3522 | hostapd_refresh_all_iface_beacons(hapd_iface); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3523 | return 0; |
| 3524 | } |
| 3525 | |
| 3526 | |
| 3527 | static struct hostapd_iface * |
| 3528 | hostapd_iface_alloc(struct hapd_interfaces *interfaces) |
| 3529 | { |
| 3530 | struct hostapd_iface **iface, *hapd_iface; |
| 3531 | |
| 3532 | iface = os_realloc_array(interfaces->iface, interfaces->count + 1, |
| 3533 | sizeof(struct hostapd_iface *)); |
| 3534 | if (iface == NULL) |
| 3535 | return NULL; |
| 3536 | interfaces->iface = iface; |
| 3537 | hapd_iface = interfaces->iface[interfaces->count] = |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 3538 | hostapd_alloc_iface(); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3539 | if (hapd_iface == NULL) { |
| 3540 | wpa_printf(MSG_ERROR, "%s: Failed to allocate memory for " |
| 3541 | "the interface", __func__); |
| 3542 | return NULL; |
| 3543 | } |
| 3544 | interfaces->count++; |
| 3545 | hapd_iface->interfaces = interfaces; |
| 3546 | |
| 3547 | return hapd_iface; |
| 3548 | } |
| 3549 | |
| 3550 | |
| 3551 | static struct hostapd_config * |
| 3552 | hostapd_config_alloc(struct hapd_interfaces *interfaces, const char *ifname, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3553 | const char *ctrl_iface, const char *driver) |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3554 | { |
| 3555 | struct hostapd_bss_config *bss; |
| 3556 | struct hostapd_config *conf; |
| 3557 | |
| 3558 | /* Allocates memory for bss and conf */ |
| 3559 | conf = hostapd_config_defaults(); |
| 3560 | if (conf == NULL) { |
| 3561 | wpa_printf(MSG_ERROR, "%s: Failed to allocate memory for " |
| 3562 | "configuration", __func__); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3563 | return NULL; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3564 | } |
| 3565 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3566 | if (driver) { |
| 3567 | int j; |
| 3568 | |
| 3569 | for (j = 0; wpa_drivers[j]; j++) { |
| 3570 | if (os_strcmp(driver, wpa_drivers[j]->name) == 0) { |
| 3571 | conf->driver = wpa_drivers[j]; |
| 3572 | goto skip; |
| 3573 | } |
| 3574 | } |
| 3575 | |
| 3576 | wpa_printf(MSG_ERROR, |
| 3577 | "Invalid/unknown driver '%s' - registering the default driver", |
| 3578 | driver); |
| 3579 | } |
| 3580 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3581 | conf->driver = wpa_drivers[0]; |
| 3582 | if (conf->driver == NULL) { |
| 3583 | wpa_printf(MSG_ERROR, "No driver wrappers registered!"); |
| 3584 | hostapd_config_free(conf); |
| 3585 | return NULL; |
| 3586 | } |
| 3587 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3588 | skip: |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3589 | bss = conf->last_bss = conf->bss[0]; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3590 | |
| 3591 | os_strlcpy(bss->iface, ifname, sizeof(bss->iface)); |
| 3592 | bss->ctrl_interface = os_strdup(ctrl_iface); |
| 3593 | if (bss->ctrl_interface == NULL) { |
| 3594 | hostapd_config_free(conf); |
| 3595 | return NULL; |
| 3596 | } |
| 3597 | |
| 3598 | /* Reading configuration file skipped, will be done in SET! |
| 3599 | * From reading the configuration till the end has to be done in |
| 3600 | * SET |
| 3601 | */ |
| 3602 | return conf; |
| 3603 | } |
| 3604 | |
| 3605 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3606 | static int hostapd_data_alloc(struct hostapd_iface *hapd_iface, |
| 3607 | struct hostapd_config *conf) |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3608 | { |
| 3609 | size_t i; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3610 | struct hostapd_data *hapd; |
| 3611 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3612 | hapd_iface->bss = os_calloc(conf->num_bss, |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3613 | sizeof(struct hostapd_data *)); |
| 3614 | if (hapd_iface->bss == NULL) |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3615 | return -1; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3616 | |
| 3617 | for (i = 0; i < conf->num_bss; i++) { |
| 3618 | hapd = hapd_iface->bss[i] = |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3619 | hostapd_alloc_bss_data(hapd_iface, conf, conf->bss[i]); |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3620 | if (hapd == NULL) { |
| 3621 | while (i > 0) { |
| 3622 | i--; |
| 3623 | os_free(hapd_iface->bss[i]); |
| 3624 | hapd_iface->bss[i] = NULL; |
| 3625 | } |
| 3626 | os_free(hapd_iface->bss); |
| 3627 | hapd_iface->bss = NULL; |
| 3628 | return -1; |
| 3629 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3630 | hapd->msg_ctx = hapd; |
Sunil Ravi | af399a8 | 2024-05-05 20:56:55 +0000 | [diff] [blame^] | 3631 | hostapd_bss_setup_multi_link(hapd, hapd_iface->interfaces); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3632 | } |
| 3633 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3634 | hapd_iface->conf = conf; |
| 3635 | hapd_iface->num_bss = conf->num_bss; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3636 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3637 | return 0; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3638 | } |
| 3639 | |
| 3640 | |
| 3641 | int hostapd_add_iface(struct hapd_interfaces *interfaces, char *buf) |
| 3642 | { |
| 3643 | struct hostapd_config *conf = NULL; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3644 | struct hostapd_iface *hapd_iface = NULL, *new_iface = NULL; |
| 3645 | struct hostapd_data *hapd; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3646 | char *ptr; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3647 | size_t i, j; |
| 3648 | const char *conf_file = NULL, *phy_name = NULL; |
| 3649 | |
| 3650 | if (os_strncmp(buf, "bss_config=", 11) == 0) { |
| 3651 | char *pos; |
| 3652 | phy_name = buf + 11; |
| 3653 | pos = os_strchr(phy_name, ':'); |
| 3654 | if (!pos) |
| 3655 | return -1; |
| 3656 | *pos++ = '\0'; |
| 3657 | conf_file = pos; |
| 3658 | if (!os_strlen(conf_file)) |
| 3659 | return -1; |
| 3660 | |
| 3661 | hapd_iface = hostapd_interface_init_bss(interfaces, phy_name, |
| 3662 | conf_file, 0); |
| 3663 | if (!hapd_iface) |
| 3664 | return -1; |
| 3665 | for (j = 0; j < interfaces->count; j++) { |
| 3666 | if (interfaces->iface[j] == hapd_iface) |
| 3667 | break; |
| 3668 | } |
| 3669 | if (j == interfaces->count) { |
| 3670 | struct hostapd_iface **tmp; |
| 3671 | tmp = os_realloc_array(interfaces->iface, |
| 3672 | interfaces->count + 1, |
| 3673 | sizeof(struct hostapd_iface *)); |
| 3674 | if (!tmp) { |
| 3675 | hostapd_interface_deinit_free(hapd_iface); |
| 3676 | return -1; |
| 3677 | } |
| 3678 | interfaces->iface = tmp; |
| 3679 | interfaces->iface[interfaces->count++] = hapd_iface; |
| 3680 | new_iface = hapd_iface; |
| 3681 | } |
| 3682 | |
| 3683 | if (new_iface) { |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3684 | if (interfaces->driver_init(hapd_iface)) |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3685 | goto fail; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3686 | |
| 3687 | if (hostapd_setup_interface(hapd_iface)) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3688 | hostapd_deinit_driver( |
| 3689 | hapd_iface->bss[0]->driver, |
| 3690 | hapd_iface->bss[0]->drv_priv, |
| 3691 | hapd_iface); |
| 3692 | goto fail; |
| 3693 | } |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3694 | } else { |
| 3695 | /* Assign new BSS with bss[0]'s driver info */ |
| 3696 | hapd = hapd_iface->bss[hapd_iface->num_bss - 1]; |
| 3697 | hapd->driver = hapd_iface->bss[0]->driver; |
| 3698 | hapd->drv_priv = hapd_iface->bss[0]->drv_priv; |
| 3699 | os_memcpy(hapd->own_addr, hapd_iface->bss[0]->own_addr, |
| 3700 | ETH_ALEN); |
| 3701 | |
| 3702 | if (start_ctrl_iface_bss(hapd) < 0 || |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 3703 | (hapd_iface->state == HAPD_IFACE_ENABLED && |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 3704 | hostapd_setup_bss(hapd, -1, true))) { |
Sunil Ravi | af399a8 | 2024-05-05 20:56:55 +0000 | [diff] [blame^] | 3705 | hostapd_bss_link_deinit(hapd); |
Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 3706 | hostapd_cleanup(hapd); |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 3707 | hapd_iface->bss[hapd_iface->num_bss - 1] = NULL; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3708 | hapd_iface->conf->num_bss--; |
| 3709 | hapd_iface->num_bss--; |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 3710 | wpa_printf(MSG_DEBUG, "%s: free hapd %p %s", |
| 3711 | __func__, hapd, hapd->conf->iface); |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3712 | hostapd_config_free_bss(hapd->conf); |
| 3713 | hapd->conf = NULL; |
Sunil Ravi | af399a8 | 2024-05-05 20:56:55 +0000 | [diff] [blame^] | 3714 | #ifdef CONFIG_IEEE80211BE |
| 3715 | hostapd_mld_ref_dec(hapd->mld); |
| 3716 | #endif /* CONFIG_IEEE80211BE */ |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3717 | os_free(hapd); |
| 3718 | return -1; |
| 3719 | } |
| 3720 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3721 | hostapd_owe_update_trans(hapd_iface); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3722 | return 0; |
| 3723 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3724 | |
| 3725 | ptr = os_strchr(buf, ' '); |
| 3726 | if (ptr == NULL) |
| 3727 | return -1; |
| 3728 | *ptr++ = '\0'; |
| 3729 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3730 | if (os_strncmp(ptr, "config=", 7) == 0) |
| 3731 | conf_file = ptr + 7; |
| 3732 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3733 | for (i = 0; i < interfaces->count; i++) { |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 3734 | bool mld_ap = false; |
| 3735 | |
| 3736 | #ifdef CONFIG_IEEE80211BE |
| 3737 | mld_ap = interfaces->iface[i]->conf->bss[0]->mld_ap; |
| 3738 | #endif /* CONFIG_IEEE80211BE */ |
| 3739 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3740 | if (!os_strcmp(interfaces->iface[i]->conf->bss[0]->iface, |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 3741 | buf) && !mld_ap) { |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3742 | wpa_printf(MSG_INFO, "Cannot add interface - it " |
| 3743 | "already exists"); |
| 3744 | return -1; |
| 3745 | } |
| 3746 | } |
| 3747 | |
| 3748 | hapd_iface = hostapd_iface_alloc(interfaces); |
| 3749 | if (hapd_iface == NULL) { |
| 3750 | wpa_printf(MSG_ERROR, "%s: Failed to allocate memory " |
| 3751 | "for interface", __func__); |
| 3752 | goto fail; |
| 3753 | } |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3754 | new_iface = hapd_iface; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3755 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3756 | if (conf_file && interfaces->config_read_cb) { |
| 3757 | conf = interfaces->config_read_cb(conf_file); |
| 3758 | if (conf && conf->bss) |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3759 | os_strlcpy(conf->bss[0]->iface, buf, |
| 3760 | sizeof(conf->bss[0]->iface)); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3761 | } else { |
| 3762 | char *driver = os_strchr(ptr, ' '); |
| 3763 | |
| 3764 | if (driver) |
| 3765 | *driver++ = '\0'; |
| 3766 | conf = hostapd_config_alloc(interfaces, buf, ptr, driver); |
| 3767 | } |
| 3768 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3769 | if (conf == NULL || conf->bss == NULL) { |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3770 | wpa_printf(MSG_ERROR, "%s: Failed to allocate memory " |
| 3771 | "for configuration", __func__); |
| 3772 | goto fail; |
| 3773 | } |
| 3774 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3775 | if (hostapd_data_alloc(hapd_iface, conf) < 0) { |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3776 | wpa_printf(MSG_ERROR, "%s: Failed to allocate memory " |
| 3777 | "for hostapd", __func__); |
| 3778 | goto fail; |
| 3779 | } |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3780 | conf = NULL; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3781 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3782 | if (start_ctrl_iface(hapd_iface) < 0) |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3783 | goto fail; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3784 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3785 | wpa_printf(MSG_INFO, "Add interface '%s'", |
| 3786 | hapd_iface->conf->bss[0]->iface); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3787 | |
| 3788 | return 0; |
| 3789 | |
| 3790 | fail: |
| 3791 | if (conf) |
| 3792 | hostapd_config_free(conf); |
| 3793 | if (hapd_iface) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3794 | if (hapd_iface->bss) { |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 3795 | for (i = 0; i < hapd_iface->num_bss; i++) { |
| 3796 | hapd = hapd_iface->bss[i]; |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 3797 | if (!hapd) |
| 3798 | continue; |
| 3799 | if (hapd_iface->interfaces && |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 3800 | hapd_iface->interfaces->ctrl_iface_deinit) |
| 3801 | hapd_iface->interfaces-> |
| 3802 | ctrl_iface_deinit(hapd); |
| 3803 | wpa_printf(MSG_DEBUG, "%s: free hapd %p (%s)", |
| 3804 | __func__, hapd_iface->bss[i], |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 3805 | hapd->conf->iface); |
Sunil Ravi | af399a8 | 2024-05-05 20:56:55 +0000 | [diff] [blame^] | 3806 | hostapd_bss_link_deinit(hapd); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3807 | hostapd_cleanup(hapd); |
Sunil Ravi | af399a8 | 2024-05-05 20:56:55 +0000 | [diff] [blame^] | 3808 | #ifdef CONFIG_IEEE80211BE |
| 3809 | hostapd_mld_ref_dec(hapd->mld); |
| 3810 | #endif /* CONFIG_IEEE80211BE */ |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 3811 | os_free(hapd); |
| 3812 | hapd_iface->bss[i] = NULL; |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 3813 | } |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3814 | os_free(hapd_iface->bss); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3815 | hapd_iface->bss = NULL; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3816 | } |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3817 | if (new_iface) { |
| 3818 | interfaces->count--; |
| 3819 | interfaces->iface[interfaces->count] = NULL; |
Sunil Ravi | af399a8 | 2024-05-05 20:56:55 +0000 | [diff] [blame^] | 3820 | hostapd_cleanup_unused_mlds(interfaces); |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3821 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3822 | hostapd_cleanup_iface(hapd_iface); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3823 | } |
| 3824 | return -1; |
| 3825 | } |
| 3826 | |
| 3827 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3828 | static int hostapd_remove_bss(struct hostapd_iface *iface, unsigned int idx) |
| 3829 | { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3830 | size_t i; |
| 3831 | |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 3832 | wpa_printf(MSG_INFO, "Remove BSS '%s'", iface->conf->bss[idx]->iface); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3833 | |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 3834 | /* Remove hostapd_data only if it has already been initialized */ |
| 3835 | if (idx < iface->num_bss) { |
| 3836 | struct hostapd_data *hapd = iface->bss[idx]; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3837 | |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 3838 | hostapd_bss_deinit(hapd); |
| 3839 | wpa_printf(MSG_DEBUG, "%s: free hapd %p (%s)", |
| 3840 | __func__, hapd, hapd->conf->iface); |
| 3841 | hostapd_config_free_bss(hapd->conf); |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3842 | hapd->conf = NULL; |
Sunil Ravi | af399a8 | 2024-05-05 20:56:55 +0000 | [diff] [blame^] | 3843 | #ifdef CONFIG_IEEE80211BE |
| 3844 | hostapd_mld_ref_dec(hapd->mld); |
| 3845 | #endif /* CONFIG_IEEE80211BE */ |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 3846 | os_free(hapd); |
| 3847 | |
| 3848 | iface->num_bss--; |
| 3849 | |
| 3850 | for (i = idx; i < iface->num_bss; i++) |
| 3851 | iface->bss[i] = iface->bss[i + 1]; |
| 3852 | } else { |
| 3853 | hostapd_config_free_bss(iface->conf->bss[idx]); |
| 3854 | iface->conf->bss[idx] = NULL; |
| 3855 | } |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3856 | |
| 3857 | iface->conf->num_bss--; |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 3858 | for (i = idx; i < iface->conf->num_bss; i++) |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3859 | iface->conf->bss[i] = iface->conf->bss[i + 1]; |
| 3860 | |
| 3861 | return 0; |
| 3862 | } |
| 3863 | |
| 3864 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3865 | int hostapd_remove_iface(struct hapd_interfaces *interfaces, char *buf) |
| 3866 | { |
| 3867 | struct hostapd_iface *hapd_iface; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3868 | size_t i, j, k = 0; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3869 | |
| 3870 | for (i = 0; i < interfaces->count; i++) { |
| 3871 | hapd_iface = interfaces->iface[i]; |
| 3872 | if (hapd_iface == NULL) |
| 3873 | return -1; |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 3874 | if (!os_strcmp(hapd_iface->conf->bss[0]->iface, buf)) { |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3875 | wpa_printf(MSG_INFO, "Remove interface '%s'", buf); |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 3876 | hapd_iface->driver_ap_teardown = |
| 3877 | !!(hapd_iface->drv_flags & |
| 3878 | WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT); |
| 3879 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3880 | hostapd_interface_deinit_free(hapd_iface); |
| 3881 | k = i; |
| 3882 | while (k < (interfaces->count - 1)) { |
| 3883 | interfaces->iface[k] = |
| 3884 | interfaces->iface[k + 1]; |
| 3885 | k++; |
| 3886 | } |
| 3887 | interfaces->count--; |
Sunil Ravi | af399a8 | 2024-05-05 20:56:55 +0000 | [diff] [blame^] | 3888 | hostapd_cleanup_unused_mlds(interfaces); |
| 3889 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3890 | return 0; |
| 3891 | } |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3892 | |
| 3893 | for (j = 0; j < hapd_iface->conf->num_bss; j++) { |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 3894 | if (!os_strcmp(hapd_iface->conf->bss[j]->iface, buf)) { |
| 3895 | hapd_iface->driver_ap_teardown = |
| 3896 | !(hapd_iface->drv_flags & |
| 3897 | WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3898 | return hostapd_remove_bss(hapd_iface, j); |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 3899 | } |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3900 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3901 | } |
| 3902 | return -1; |
| 3903 | } |
| 3904 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3905 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3906 | /** |
| 3907 | * hostapd_new_assoc_sta - Notify that a new station associated with the AP |
| 3908 | * @hapd: Pointer to BSS data |
| 3909 | * @sta: Pointer to the associated STA data |
| 3910 | * @reassoc: 1 to indicate this was a re-association; 0 = first association |
| 3911 | * |
| 3912 | * This function will be called whenever a station associates with the AP. It |
| 3913 | * can be called from ieee802_11.c for drivers that export MLME to hostapd and |
| 3914 | * from drv_callbacks.c based on driver events for drivers that take care of |
| 3915 | * management frames (IEEE 802.11 authentication and association) internally. |
| 3916 | */ |
| 3917 | void hostapd_new_assoc_sta(struct hostapd_data *hapd, struct sta_info *sta, |
| 3918 | int reassoc) |
| 3919 | { |
| 3920 | if (hapd->tkip_countermeasures) { |
| 3921 | hostapd_drv_sta_deauth(hapd, sta->addr, |
| 3922 | WLAN_REASON_MICHAEL_MIC_FAILURE); |
| 3923 | return; |
| 3924 | } |
| 3925 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 3926 | #ifdef CONFIG_IEEE80211BE |
Sunil Ravi | 72e0122 | 2024-03-09 01:25:43 +0000 | [diff] [blame] | 3927 | if (ap_sta_is_mld(hapd, sta) && |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 3928 | sta->mld_assoc_link_id != hapd->mld_link_id) |
| 3929 | return; |
| 3930 | #endif /* CONFIG_IEEE80211BE */ |
| 3931 | |
Dmitry Shmidt | 1d6bf42 | 2016-01-19 15:51:35 -0800 | [diff] [blame] | 3932 | ap_sta_clear_disconnect_timeouts(hapd, sta); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 3933 | sta->post_csa_sa_query = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3934 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3935 | #ifdef CONFIG_P2P |
| 3936 | if (sta->p2p_ie == NULL && !sta->no_p2p_set) { |
| 3937 | sta->no_p2p_set = 1; |
| 3938 | hapd->num_sta_no_p2p++; |
| 3939 | if (hapd->num_sta_no_p2p == 1) |
| 3940 | hostapd_p2p_non_p2p_sta_connected(hapd); |
| 3941 | } |
| 3942 | #endif /* CONFIG_P2P */ |
| 3943 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 3944 | airtime_policy_new_sta(hapd, sta); |
| 3945 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3946 | /* Start accounting here, if IEEE 802.1X and WPA are not used. |
| 3947 | * IEEE 802.1X/WPA code will start accounting after the station has |
| 3948 | * been authorized. */ |
Dmitry Shmidt | 2ac5f60 | 2014-03-07 10:08:21 -0800 | [diff] [blame] | 3949 | if (!hapd->conf->ieee802_1x && !hapd->conf->wpa && !hapd->conf->osen) { |
| 3950 | ap_sta_set_authorized(hapd, sta, 1); |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 3951 | os_get_reltime(&sta->connected_time); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3952 | accounting_sta_start(hapd, sta); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3953 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3954 | |
| 3955 | /* Start IEEE 802.1X authentication process for new stations */ |
| 3956 | ieee802_1x_new_station(hapd, sta); |
| 3957 | if (reassoc) { |
| 3958 | if (sta->auth_alg != WLAN_AUTH_FT && |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3959 | sta->auth_alg != WLAN_AUTH_FILS_SK && |
| 3960 | sta->auth_alg != WLAN_AUTH_FILS_SK_PFS && |
| 3961 | sta->auth_alg != WLAN_AUTH_FILS_PK && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3962 | !(sta->flags & (WLAN_STA_WPS | WLAN_STA_MAYBE_WPS))) |
| 3963 | wpa_auth_sm_event(sta->wpa_sm, WPA_REAUTH); |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 3964 | } else if (!(hapd->iface->drv_flags2 & |
| 3965 | WPA_DRIVER_FLAGS2_4WAY_HANDSHAKE_AP_PSK)) { |
| 3966 | /* The 4-way handshake offloaded case will have this handled |
| 3967 | * based on the port authorized event. */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3968 | wpa_auth_sta_associated(hapd->wpa_auth, sta->wpa_sm); |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 3969 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3970 | |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 3971 | if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_WIRED) { |
| 3972 | if (eloop_cancel_timeout(ap_handle_timer, hapd, sta) > 0) { |
| 3973 | wpa_printf(MSG_DEBUG, |
| 3974 | "%s: %s: canceled wired ap_handle_timer timeout for " |
| 3975 | MACSTR, |
| 3976 | hapd->conf->iface, __func__, |
| 3977 | MAC2STR(sta->addr)); |
| 3978 | } |
| 3979 | } else if (!(hapd->iface->drv_flags & |
| 3980 | WPA_DRIVER_FLAGS_INACTIVITY_TIMER)) { |
Dmitry Shmidt | 1d6bf42 | 2016-01-19 15:51:35 -0800 | [diff] [blame] | 3981 | wpa_printf(MSG_DEBUG, |
| 3982 | "%s: %s: reschedule ap_handle_timer timeout for " |
| 3983 | MACSTR " (%d seconds - ap_max_inactivity)", |
| 3984 | hapd->conf->iface, __func__, MAC2STR(sta->addr), |
Dmitry Shmidt | 01904cf | 2013-12-05 11:08:35 -0800 | [diff] [blame] | 3985 | hapd->conf->ap_max_inactivity); |
| 3986 | eloop_cancel_timeout(ap_handle_timer, hapd, sta); |
| 3987 | eloop_register_timeout(hapd->conf->ap_max_inactivity, 0, |
| 3988 | ap_handle_timer, hapd, sta); |
| 3989 | } |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 3990 | |
| 3991 | #ifdef CONFIG_MACSEC |
| 3992 | if (hapd->conf->wpa_key_mgmt == WPA_KEY_MGMT_NONE && |
| 3993 | hapd->conf->mka_psk_set) |
| 3994 | ieee802_1x_create_preshared_mka_hapd(hapd, sta); |
| 3995 | else |
| 3996 | ieee802_1x_alloc_kay_sm_hapd(hapd, sta); |
| 3997 | #endif /* CONFIG_MACSEC */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3998 | } |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3999 | |
| 4000 | |
| 4001 | const char * hostapd_state_text(enum hostapd_iface_state s) |
| 4002 | { |
| 4003 | switch (s) { |
| 4004 | case HAPD_IFACE_UNINITIALIZED: |
| 4005 | return "UNINITIALIZED"; |
| 4006 | case HAPD_IFACE_DISABLED: |
| 4007 | return "DISABLED"; |
| 4008 | case HAPD_IFACE_COUNTRY_UPDATE: |
| 4009 | return "COUNTRY_UPDATE"; |
| 4010 | case HAPD_IFACE_ACS: |
| 4011 | return "ACS"; |
| 4012 | case HAPD_IFACE_HT_SCAN: |
| 4013 | return "HT_SCAN"; |
| 4014 | case HAPD_IFACE_DFS: |
| 4015 | return "DFS"; |
| 4016 | case HAPD_IFACE_ENABLED: |
| 4017 | return "ENABLED"; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 4018 | case HAPD_IFACE_NO_IR: |
| 4019 | return "NO_IR"; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4020 | } |
| 4021 | |
| 4022 | return "UNKNOWN"; |
| 4023 | } |
| 4024 | |
| 4025 | |
| 4026 | void hostapd_set_state(struct hostapd_iface *iface, enum hostapd_iface_state s) |
| 4027 | { |
| 4028 | wpa_printf(MSG_INFO, "%s: interface state %s->%s", |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 4029 | iface->conf ? iface->conf->bss[0]->iface : "N/A", |
| 4030 | hostapd_state_text(iface->state), hostapd_state_text(s)); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4031 | iface->state = s; |
| 4032 | } |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4033 | |
| 4034 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4035 | int hostapd_csa_in_progress(struct hostapd_iface *iface) |
| 4036 | { |
| 4037 | unsigned int i; |
| 4038 | |
| 4039 | for (i = 0; i < iface->num_bss; i++) |
| 4040 | if (iface->bss[i]->csa_in_progress) |
| 4041 | return 1; |
| 4042 | return 0; |
| 4043 | } |
| 4044 | |
| 4045 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4046 | #ifdef NEED_AP_MLME |
| 4047 | |
| 4048 | static void free_beacon_data(struct beacon_data *beacon) |
| 4049 | { |
| 4050 | os_free(beacon->head); |
| 4051 | beacon->head = NULL; |
| 4052 | os_free(beacon->tail); |
| 4053 | beacon->tail = NULL; |
| 4054 | os_free(beacon->probe_resp); |
| 4055 | beacon->probe_resp = NULL; |
| 4056 | os_free(beacon->beacon_ies); |
| 4057 | beacon->beacon_ies = NULL; |
| 4058 | os_free(beacon->proberesp_ies); |
| 4059 | beacon->proberesp_ies = NULL; |
| 4060 | os_free(beacon->assocresp_ies); |
| 4061 | beacon->assocresp_ies = NULL; |
| 4062 | } |
| 4063 | |
| 4064 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4065 | static int hostapd_build_beacon_data(struct hostapd_data *hapd, |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4066 | struct beacon_data *beacon) |
| 4067 | { |
| 4068 | struct wpabuf *beacon_extra, *proberesp_extra, *assocresp_extra; |
| 4069 | struct wpa_driver_ap_params params; |
| 4070 | int ret; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4071 | |
Dmitry Shmidt | 01904cf | 2013-12-05 11:08:35 -0800 | [diff] [blame] | 4072 | os_memset(beacon, 0, sizeof(*beacon)); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4073 | ret = ieee802_11_build_ap_params(hapd, ¶ms); |
| 4074 | if (ret < 0) |
| 4075 | return ret; |
| 4076 | |
| 4077 | ret = hostapd_build_ap_extra_ies(hapd, &beacon_extra, |
| 4078 | &proberesp_extra, |
| 4079 | &assocresp_extra); |
| 4080 | if (ret) |
| 4081 | goto free_ap_params; |
| 4082 | |
| 4083 | ret = -1; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4084 | beacon->head = os_memdup(params.head, params.head_len); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4085 | if (!beacon->head) |
| 4086 | goto free_ap_extra_ies; |
| 4087 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4088 | beacon->head_len = params.head_len; |
| 4089 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4090 | beacon->tail = os_memdup(params.tail, params.tail_len); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4091 | if (!beacon->tail) |
| 4092 | goto free_beacon; |
| 4093 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4094 | beacon->tail_len = params.tail_len; |
| 4095 | |
| 4096 | if (params.proberesp != NULL) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4097 | beacon->probe_resp = os_memdup(params.proberesp, |
| 4098 | params.proberesp_len); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4099 | if (!beacon->probe_resp) |
| 4100 | goto free_beacon; |
| 4101 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4102 | beacon->probe_resp_len = params.proberesp_len; |
| 4103 | } |
| 4104 | |
| 4105 | /* copy the extra ies */ |
| 4106 | if (beacon_extra) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4107 | beacon->beacon_ies = os_memdup(beacon_extra->buf, |
| 4108 | wpabuf_len(beacon_extra)); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4109 | if (!beacon->beacon_ies) |
| 4110 | goto free_beacon; |
| 4111 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4112 | beacon->beacon_ies_len = wpabuf_len(beacon_extra); |
| 4113 | } |
| 4114 | |
| 4115 | if (proberesp_extra) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4116 | beacon->proberesp_ies = os_memdup(proberesp_extra->buf, |
| 4117 | wpabuf_len(proberesp_extra)); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4118 | if (!beacon->proberesp_ies) |
| 4119 | goto free_beacon; |
| 4120 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4121 | beacon->proberesp_ies_len = wpabuf_len(proberesp_extra); |
| 4122 | } |
| 4123 | |
| 4124 | if (assocresp_extra) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4125 | beacon->assocresp_ies = os_memdup(assocresp_extra->buf, |
| 4126 | wpabuf_len(assocresp_extra)); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4127 | if (!beacon->assocresp_ies) |
| 4128 | goto free_beacon; |
| 4129 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4130 | beacon->assocresp_ies_len = wpabuf_len(assocresp_extra); |
| 4131 | } |
| 4132 | |
| 4133 | ret = 0; |
| 4134 | free_beacon: |
| 4135 | /* if the function fails, the caller should not free beacon data */ |
| 4136 | if (ret) |
| 4137 | free_beacon_data(beacon); |
| 4138 | |
| 4139 | free_ap_extra_ies: |
| 4140 | hostapd_free_ap_extra_ies(hapd, beacon_extra, proberesp_extra, |
| 4141 | assocresp_extra); |
| 4142 | free_ap_params: |
| 4143 | ieee802_11_free_ap_params(¶ms); |
| 4144 | return ret; |
| 4145 | } |
| 4146 | |
| 4147 | |
| 4148 | /* |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4149 | * TODO: This flow currently supports only changing channel and width within |
| 4150 | * the same hw_mode. Any other changes to MAC parameters or provided settings |
| 4151 | * are not supported. |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4152 | */ |
| 4153 | static int hostapd_change_config_freq(struct hostapd_data *hapd, |
| 4154 | struct hostapd_config *conf, |
| 4155 | struct hostapd_freq_params *params, |
| 4156 | struct hostapd_freq_params *old_params) |
| 4157 | { |
| 4158 | int channel; |
Sunil Ravi | 72e0122 | 2024-03-09 01:25:43 +0000 | [diff] [blame] | 4159 | u8 seg0 = 0, seg1 = 0; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 4160 | struct hostapd_hw_modes *mode; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4161 | |
| 4162 | if (!params->channel) { |
| 4163 | /* check if the new channel is supported by hw */ |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4164 | params->channel = hostapd_hw_get_channel(hapd, params->freq); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4165 | } |
| 4166 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4167 | channel = params->channel; |
| 4168 | if (!channel) |
| 4169 | return -1; |
| 4170 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 4171 | hostapd_determine_mode(hapd->iface); |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 4172 | mode = hapd->iface->current_mode; |
| 4173 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4174 | /* if a pointer to old_params is provided we save previous state */ |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4175 | if (old_params && |
| 4176 | hostapd_set_freq_params(old_params, conf->hw_mode, |
| 4177 | hostapd_hw_get_freq(hapd, conf->channel), |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 4178 | conf->channel, conf->enable_edmg, |
| 4179 | conf->edmg_channel, conf->ieee80211n, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 4180 | conf->ieee80211ac, conf->ieee80211ax, |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 4181 | conf->ieee80211be, conf->secondary_channel, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 4182 | hostapd_get_oper_chwidth(conf), |
| 4183 | hostapd_get_oper_centr_freq_seg0_idx(conf), |
| 4184 | hostapd_get_oper_centr_freq_seg1_idx(conf), |
| 4185 | conf->vht_capab, |
| 4186 | mode ? &mode->he_capab[IEEE80211_MODE_AP] : |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 4187 | NULL, |
| 4188 | mode ? &mode->eht_capab[IEEE80211_MODE_AP] : |
Sunil Ravi | af399a8 | 2024-05-05 20:56:55 +0000 | [diff] [blame^] | 4189 | NULL, |
| 4190 | hostapd_get_punct_bitmap(hapd))) |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4191 | return -1; |
| 4192 | |
| 4193 | switch (params->bandwidth) { |
| 4194 | case 0: |
| 4195 | case 20: |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4196 | conf->ht_capab &= ~HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET; |
| 4197 | break; |
| 4198 | case 40: |
| 4199 | case 80: |
| 4200 | case 160: |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame] | 4201 | case 320: |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4202 | conf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET; |
| 4203 | break; |
| 4204 | default: |
| 4205 | return -1; |
| 4206 | } |
| 4207 | |
| 4208 | switch (params->bandwidth) { |
| 4209 | case 0: |
| 4210 | case 20: |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4211 | case 40: |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 4212 | hostapd_set_oper_chwidth(conf, CONF_OPER_CHWIDTH_USE_HT); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4213 | break; |
| 4214 | case 80: |
| 4215 | if (params->center_freq2) |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 4216 | hostapd_set_oper_chwidth(conf, |
| 4217 | CONF_OPER_CHWIDTH_80P80MHZ); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4218 | else |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 4219 | hostapd_set_oper_chwidth(conf, |
| 4220 | CONF_OPER_CHWIDTH_80MHZ); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4221 | break; |
| 4222 | case 160: |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 4223 | hostapd_set_oper_chwidth(conf, CONF_OPER_CHWIDTH_160MHZ); |
| 4224 | break; |
| 4225 | case 320: |
| 4226 | hostapd_set_oper_chwidth(conf, CONF_OPER_CHWIDTH_320MHZ); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4227 | break; |
| 4228 | default: |
| 4229 | return -1; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4230 | } |
| 4231 | |
| 4232 | conf->channel = channel; |
| 4233 | conf->ieee80211n = params->ht_enabled; |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4234 | conf->ieee80211ac = params->vht_enabled; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4235 | conf->secondary_channel = params->sec_channel_offset; |
Sunil Ravi | 72e0122 | 2024-03-09 01:25:43 +0000 | [diff] [blame] | 4236 | if (params->center_freq1 && |
| 4237 | ieee80211_freq_to_chan(params->center_freq1, &seg0) == |
| 4238 | NUM_HOSTAPD_MODES) |
| 4239 | return -1; |
| 4240 | if (params->center_freq2 && |
| 4241 | ieee80211_freq_to_chan(params->center_freq2, |
| 4242 | &seg1) == NUM_HOSTAPD_MODES) |
| 4243 | return -1; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 4244 | hostapd_set_oper_centr_freq_seg0_idx(conf, seg0); |
| 4245 | hostapd_set_oper_centr_freq_seg1_idx(conf, seg1); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4246 | |
| 4247 | /* TODO: maybe call here hostapd_config_check here? */ |
| 4248 | |
| 4249 | return 0; |
| 4250 | } |
| 4251 | |
| 4252 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4253 | static int hostapd_fill_csa_settings(struct hostapd_data *hapd, |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4254 | struct csa_settings *settings) |
| 4255 | { |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4256 | struct hostapd_iface *iface = hapd->iface; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4257 | struct hostapd_freq_params old_freq; |
| 4258 | int ret; |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 4259 | #ifdef CONFIG_IEEE80211BE |
| 4260 | u16 old_punct_bitmap; |
| 4261 | #endif /* CONFIG_IEEE80211BE */ |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 4262 | u8 chan, bandwidth; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4263 | |
| 4264 | os_memset(&old_freq, 0, sizeof(old_freq)); |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4265 | if (!iface || !iface->freq || hapd->csa_in_progress) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4266 | return -1; |
| 4267 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4268 | switch (settings->freq_params.bandwidth) { |
| 4269 | case 80: |
| 4270 | if (settings->freq_params.center_freq2) |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 4271 | bandwidth = CONF_OPER_CHWIDTH_80P80MHZ; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4272 | else |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 4273 | bandwidth = CONF_OPER_CHWIDTH_80MHZ; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4274 | break; |
| 4275 | case 160: |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 4276 | bandwidth = CONF_OPER_CHWIDTH_160MHZ; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4277 | break; |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame] | 4278 | case 320: |
| 4279 | bandwidth = CONF_OPER_CHWIDTH_320MHZ; |
| 4280 | break; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4281 | default: |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 4282 | bandwidth = CONF_OPER_CHWIDTH_USE_HT; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4283 | break; |
| 4284 | } |
| 4285 | |
| 4286 | if (ieee80211_freq_to_channel_ext( |
| 4287 | settings->freq_params.freq, |
| 4288 | settings->freq_params.sec_channel_offset, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 4289 | bandwidth, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4290 | &hapd->iface->cs_oper_class, |
| 4291 | &chan) == NUM_HOSTAPD_MODES) { |
| 4292 | wpa_printf(MSG_DEBUG, |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 4293 | "invalid frequency for channel switch (freq=%d, sec_channel_offset=%d, vht_enabled=%d, he_enabled=%d, eht_enabled=%d)", |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4294 | settings->freq_params.freq, |
| 4295 | settings->freq_params.sec_channel_offset, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 4296 | settings->freq_params.vht_enabled, |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 4297 | settings->freq_params.he_enabled, |
| 4298 | settings->freq_params.eht_enabled); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4299 | return -1; |
| 4300 | } |
| 4301 | |
| 4302 | settings->freq_params.channel = chan; |
| 4303 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4304 | ret = hostapd_change_config_freq(iface->bss[0], iface->conf, |
| 4305 | &settings->freq_params, |
| 4306 | &old_freq); |
| 4307 | if (ret) |
| 4308 | return ret; |
| 4309 | |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 4310 | #ifdef CONFIG_IEEE80211BE |
| 4311 | old_punct_bitmap = iface->conf->punct_bitmap; |
| 4312 | iface->conf->punct_bitmap = settings->punct_bitmap; |
| 4313 | #endif /* CONFIG_IEEE80211BE */ |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4314 | ret = hostapd_build_beacon_data(hapd, &settings->beacon_after); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4315 | |
| 4316 | /* change back the configuration */ |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 4317 | #ifdef CONFIG_IEEE80211BE |
| 4318 | iface->conf->punct_bitmap = old_punct_bitmap; |
| 4319 | #endif /* CONFIG_IEEE80211BE */ |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4320 | hostapd_change_config_freq(iface->bss[0], iface->conf, |
| 4321 | &old_freq, NULL); |
| 4322 | |
| 4323 | if (ret) |
| 4324 | return ret; |
| 4325 | |
| 4326 | /* set channel switch parameters for csa ie */ |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4327 | hapd->cs_freq_params = settings->freq_params; |
| 4328 | hapd->cs_count = settings->cs_count; |
| 4329 | hapd->cs_block_tx = settings->block_tx; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4330 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4331 | ret = hostapd_build_beacon_data(hapd, &settings->beacon_csa); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4332 | if (ret) { |
| 4333 | free_beacon_data(&settings->beacon_after); |
| 4334 | return ret; |
| 4335 | } |
| 4336 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4337 | settings->counter_offset_beacon[0] = hapd->cs_c_off_beacon; |
| 4338 | settings->counter_offset_presp[0] = hapd->cs_c_off_proberesp; |
| 4339 | settings->counter_offset_beacon[1] = hapd->cs_c_off_ecsa_beacon; |
| 4340 | settings->counter_offset_presp[1] = hapd->cs_c_off_ecsa_proberesp; |
Sunil Ravi | 72e0122 | 2024-03-09 01:25:43 +0000 | [diff] [blame] | 4341 | settings->link_id = -1; |
| 4342 | #ifdef CONFIG_IEEE80211BE |
| 4343 | if (hapd->conf->mld_ap) |
| 4344 | settings->link_id = hapd->mld_link_id; |
| 4345 | #endif /* CONFIG_IEEE80211BE */ |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4346 | |
| 4347 | return 0; |
| 4348 | } |
| 4349 | |
| 4350 | |
| 4351 | void hostapd_cleanup_cs_params(struct hostapd_data *hapd) |
| 4352 | { |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4353 | os_memset(&hapd->cs_freq_params, 0, sizeof(hapd->cs_freq_params)); |
| 4354 | hapd->cs_count = 0; |
| 4355 | hapd->cs_block_tx = 0; |
| 4356 | hapd->cs_c_off_beacon = 0; |
| 4357 | hapd->cs_c_off_proberesp = 0; |
| 4358 | hapd->csa_in_progress = 0; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4359 | hapd->cs_c_off_ecsa_beacon = 0; |
| 4360 | hapd->cs_c_off_ecsa_proberesp = 0; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4361 | } |
| 4362 | |
| 4363 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4364 | void hostapd_chan_switch_config(struct hostapd_data *hapd, |
| 4365 | struct hostapd_freq_params *freq_params) |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 4366 | { |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 4367 | if (freq_params->eht_enabled) |
| 4368 | hapd->iconf->ch_switch_eht_config |= CH_SWITCH_EHT_ENABLED; |
| 4369 | else |
| 4370 | hapd->iconf->ch_switch_eht_config |= CH_SWITCH_EHT_DISABLED; |
| 4371 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4372 | if (freq_params->he_enabled) |
| 4373 | hapd->iconf->ch_switch_he_config |= CH_SWITCH_HE_ENABLED; |
| 4374 | else |
| 4375 | hapd->iconf->ch_switch_he_config |= CH_SWITCH_HE_DISABLED; |
| 4376 | |
| 4377 | if (freq_params->vht_enabled) |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 4378 | hapd->iconf->ch_switch_vht_config |= CH_SWITCH_VHT_ENABLED; |
| 4379 | else |
| 4380 | hapd->iconf->ch_switch_vht_config |= CH_SWITCH_VHT_DISABLED; |
| 4381 | |
| 4382 | hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211, |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4383 | HOSTAPD_LEVEL_INFO, |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 4384 | "CHAN_SWITCH EHT config 0x%x HE config 0x%x VHT config 0x%x", |
| 4385 | hapd->iconf->ch_switch_eht_config, |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4386 | hapd->iconf->ch_switch_he_config, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 4387 | hapd->iconf->ch_switch_vht_config); |
| 4388 | } |
| 4389 | |
| 4390 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4391 | int hostapd_switch_channel(struct hostapd_data *hapd, |
| 4392 | struct csa_settings *settings) |
| 4393 | { |
| 4394 | int ret; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4395 | |
| 4396 | if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_AP_CSA)) { |
| 4397 | wpa_printf(MSG_INFO, "CSA is not supported"); |
| 4398 | return -1; |
| 4399 | } |
| 4400 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4401 | ret = hostapd_fill_csa_settings(hapd, settings); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4402 | if (ret) |
| 4403 | return ret; |
| 4404 | |
| 4405 | ret = hostapd_drv_switch_channel(hapd, settings); |
| 4406 | free_beacon_data(&settings->beacon_csa); |
| 4407 | free_beacon_data(&settings->beacon_after); |
| 4408 | |
| 4409 | if (ret) { |
| 4410 | /* if we failed, clean cs parameters */ |
| 4411 | hostapd_cleanup_cs_params(hapd); |
| 4412 | return ret; |
| 4413 | } |
| 4414 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4415 | hapd->csa_in_progress = 1; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4416 | return 0; |
| 4417 | } |
| 4418 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4419 | |
| 4420 | void |
| 4421 | hostapd_switch_channel_fallback(struct hostapd_iface *iface, |
| 4422 | const struct hostapd_freq_params *freq_params) |
| 4423 | { |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 4424 | int seg0_idx = 0, seg1_idx = 0; |
| 4425 | enum oper_chan_width bw = CONF_OPER_CHWIDTH_USE_HT; |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4426 | |
| 4427 | wpa_printf(MSG_DEBUG, "Restarting all CSA-related BSSes"); |
| 4428 | |
| 4429 | if (freq_params->center_freq1) |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 4430 | seg0_idx = 36 + (freq_params->center_freq1 - 5180) / 5; |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4431 | if (freq_params->center_freq2) |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 4432 | seg1_idx = 36 + (freq_params->center_freq2 - 5180) / 5; |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4433 | |
| 4434 | switch (freq_params->bandwidth) { |
| 4435 | case 0: |
| 4436 | case 20: |
| 4437 | case 40: |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 4438 | bw = CONF_OPER_CHWIDTH_USE_HT; |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4439 | break; |
| 4440 | case 80: |
Sunil Ravi | 72e0122 | 2024-03-09 01:25:43 +0000 | [diff] [blame] | 4441 | if (freq_params->center_freq2) { |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 4442 | bw = CONF_OPER_CHWIDTH_80P80MHZ; |
Sunil Ravi | 72e0122 | 2024-03-09 01:25:43 +0000 | [diff] [blame] | 4443 | iface->conf->vht_capab |= |
| 4444 | VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ; |
| 4445 | } else { |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 4446 | bw = CONF_OPER_CHWIDTH_80MHZ; |
Sunil Ravi | 72e0122 | 2024-03-09 01:25:43 +0000 | [diff] [blame] | 4447 | } |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4448 | break; |
| 4449 | case 160: |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 4450 | bw = CONF_OPER_CHWIDTH_160MHZ; |
Sunil Ravi | 72e0122 | 2024-03-09 01:25:43 +0000 | [diff] [blame] | 4451 | iface->conf->vht_capab |= VHT_CAP_SUPP_CHAN_WIDTH_160MHZ; |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 4452 | break; |
| 4453 | case 320: |
| 4454 | bw = CONF_OPER_CHWIDTH_320MHZ; |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4455 | break; |
| 4456 | default: |
| 4457 | wpa_printf(MSG_WARNING, "Unknown CSA bandwidth: %d", |
| 4458 | freq_params->bandwidth); |
| 4459 | break; |
| 4460 | } |
| 4461 | |
| 4462 | iface->freq = freq_params->freq; |
| 4463 | iface->conf->channel = freq_params->channel; |
| 4464 | iface->conf->secondary_channel = freq_params->sec_channel_offset; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 4465 | hostapd_set_oper_centr_freq_seg0_idx(iface->conf, seg0_idx); |
| 4466 | hostapd_set_oper_centr_freq_seg1_idx(iface->conf, seg1_idx); |
| 4467 | hostapd_set_oper_chwidth(iface->conf, bw); |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4468 | iface->conf->ieee80211n = freq_params->ht_enabled; |
| 4469 | iface->conf->ieee80211ac = freq_params->vht_enabled; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 4470 | iface->conf->ieee80211ax = freq_params->he_enabled; |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 4471 | iface->conf->ieee80211be = freq_params->eht_enabled; |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4472 | |
| 4473 | /* |
| 4474 | * cs_params must not be cleared earlier because the freq_params |
| 4475 | * argument may actually point to one of these. |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 4476 | * These params will be cleared during interface disable below. |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4477 | */ |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4478 | hostapd_disable_iface(iface); |
| 4479 | hostapd_enable_iface(iface); |
| 4480 | } |
| 4481 | |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 4482 | |
| 4483 | #ifdef CONFIG_IEEE80211AX |
| 4484 | |
| 4485 | void hostapd_cleanup_cca_params(struct hostapd_data *hapd) |
| 4486 | { |
| 4487 | hapd->cca_count = 0; |
| 4488 | hapd->cca_color = 0; |
| 4489 | hapd->cca_c_off_beacon = 0; |
| 4490 | hapd->cca_c_off_proberesp = 0; |
| 4491 | hapd->cca_in_progress = false; |
| 4492 | } |
| 4493 | |
| 4494 | |
| 4495 | static int hostapd_fill_cca_settings(struct hostapd_data *hapd, |
| 4496 | struct cca_settings *settings) |
| 4497 | { |
| 4498 | struct hostapd_iface *iface = hapd->iface; |
| 4499 | u8 old_color; |
| 4500 | int ret; |
| 4501 | |
| 4502 | if (!iface || iface->conf->he_op.he_bss_color_disabled) |
| 4503 | return -1; |
| 4504 | |
| 4505 | old_color = iface->conf->he_op.he_bss_color; |
| 4506 | iface->conf->he_op.he_bss_color = hapd->cca_color; |
| 4507 | ret = hostapd_build_beacon_data(hapd, &settings->beacon_after); |
| 4508 | if (ret) |
| 4509 | return ret; |
| 4510 | |
| 4511 | iface->conf->he_op.he_bss_color = old_color; |
| 4512 | |
| 4513 | settings->cca_count = hapd->cca_count; |
| 4514 | settings->cca_color = hapd->cca_color, |
| 4515 | hapd->cca_in_progress = true; |
| 4516 | |
| 4517 | ret = hostapd_build_beacon_data(hapd, &settings->beacon_cca); |
| 4518 | if (ret) { |
| 4519 | free_beacon_data(&settings->beacon_after); |
| 4520 | return ret; |
| 4521 | } |
| 4522 | |
| 4523 | settings->counter_offset_beacon = hapd->cca_c_off_beacon; |
| 4524 | settings->counter_offset_presp = hapd->cca_c_off_proberesp; |
| 4525 | |
| 4526 | return 0; |
| 4527 | } |
| 4528 | |
| 4529 | |
| 4530 | static void hostapd_switch_color_timeout_handler(void *eloop_data, |
| 4531 | void *user_ctx) |
| 4532 | { |
| 4533 | struct hostapd_data *hapd = (struct hostapd_data *) eloop_data; |
| 4534 | os_time_t delta_t; |
| 4535 | unsigned int b; |
| 4536 | int i, r; |
| 4537 | |
| 4538 | /* CCA can be triggered once the handler constantly receives |
| 4539 | * color collision events to for at least |
| 4540 | * DOT11BSS_COLOR_COLLISION_AP_PERIOD (50 s by default). */ |
| 4541 | delta_t = hapd->last_color_collision.sec - |
| 4542 | hapd->first_color_collision.sec; |
| 4543 | if (delta_t < DOT11BSS_COLOR_COLLISION_AP_PERIOD) |
| 4544 | return; |
| 4545 | |
| 4546 | r = os_random() % HE_OPERATION_BSS_COLOR_MAX; |
| 4547 | for (i = 0; i < HE_OPERATION_BSS_COLOR_MAX; i++) { |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 4548 | if (r && !(hapd->color_collision_bitmap & (1ULL << r))) |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 4549 | break; |
| 4550 | |
| 4551 | r = (r + 1) % HE_OPERATION_BSS_COLOR_MAX; |
| 4552 | } |
| 4553 | |
| 4554 | if (i == HE_OPERATION_BSS_COLOR_MAX) { |
| 4555 | /* There are no free colors so turn BSS coloring off */ |
| 4556 | wpa_printf(MSG_INFO, |
| 4557 | "No free colors left, turning off BSS coloring"); |
| 4558 | hapd->iface->conf->he_op.he_bss_color_disabled = 1; |
| 4559 | hapd->iface->conf->he_op.he_bss_color = os_random() % 63 + 1; |
| 4560 | for (b = 0; b < hapd->iface->num_bss; b++) |
| 4561 | ieee802_11_set_beacon(hapd->iface->bss[b]); |
| 4562 | return; |
| 4563 | } |
| 4564 | |
| 4565 | for (b = 0; b < hapd->iface->num_bss; b++) { |
| 4566 | struct hostapd_data *bss = hapd->iface->bss[b]; |
| 4567 | struct cca_settings settings; |
| 4568 | int ret; |
| 4569 | |
| 4570 | hostapd_cleanup_cca_params(bss); |
| 4571 | bss->cca_color = r; |
| 4572 | bss->cca_count = 10; |
| 4573 | |
| 4574 | if (hostapd_fill_cca_settings(bss, &settings)) { |
| 4575 | hostapd_cleanup_cca_params(bss); |
| 4576 | continue; |
| 4577 | } |
| 4578 | |
| 4579 | ret = hostapd_drv_switch_color(bss, &settings); |
| 4580 | if (ret) |
| 4581 | hostapd_cleanup_cca_params(bss); |
| 4582 | |
| 4583 | free_beacon_data(&settings.beacon_cca); |
| 4584 | free_beacon_data(&settings.beacon_after); |
| 4585 | } |
| 4586 | } |
| 4587 | |
| 4588 | |
| 4589 | void hostapd_switch_color(struct hostapd_data *hapd, u64 bitmap) |
| 4590 | { |
| 4591 | struct os_reltime now; |
| 4592 | |
| 4593 | if (hapd->cca_in_progress) |
| 4594 | return; |
| 4595 | |
| 4596 | if (os_get_reltime(&now)) |
| 4597 | return; |
| 4598 | |
| 4599 | hapd->color_collision_bitmap = bitmap; |
| 4600 | hapd->last_color_collision = now; |
| 4601 | |
| 4602 | if (eloop_is_timeout_registered(hostapd_switch_color_timeout_handler, |
| 4603 | hapd, NULL)) |
| 4604 | return; |
| 4605 | |
| 4606 | hapd->first_color_collision = now; |
| 4607 | /* 10 s window as margin for persistent color collision reporting */ |
| 4608 | eloop_register_timeout(DOT11BSS_COLOR_COLLISION_AP_PERIOD + 10, 0, |
| 4609 | hostapd_switch_color_timeout_handler, |
| 4610 | hapd, NULL); |
| 4611 | } |
| 4612 | |
| 4613 | #endif /* CONFIG_IEEE80211AX */ |
| 4614 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 4615 | #endif /* NEED_AP_MLME */ |
| 4616 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4617 | |
| 4618 | struct hostapd_data * hostapd_get_iface(struct hapd_interfaces *interfaces, |
| 4619 | const char *ifname) |
| 4620 | { |
| 4621 | size_t i, j; |
| 4622 | |
| 4623 | for (i = 0; i < interfaces->count; i++) { |
| 4624 | struct hostapd_iface *iface = interfaces->iface[i]; |
| 4625 | |
| 4626 | for (j = 0; j < iface->num_bss; j++) { |
| 4627 | struct hostapd_data *hapd = iface->bss[j]; |
| 4628 | |
| 4629 | if (os_strcmp(ifname, hapd->conf->iface) == 0) |
| 4630 | return hapd; |
| 4631 | } |
| 4632 | } |
| 4633 | |
| 4634 | return NULL; |
| 4635 | } |
| 4636 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4637 | |
| 4638 | void hostapd_periodic_iface(struct hostapd_iface *iface) |
| 4639 | { |
| 4640 | size_t i; |
| 4641 | |
| 4642 | ap_list_timer(iface); |
| 4643 | |
| 4644 | for (i = 0; i < iface->num_bss; i++) { |
| 4645 | struct hostapd_data *hapd = iface->bss[i]; |
| 4646 | |
| 4647 | if (!hapd->started) |
| 4648 | continue; |
| 4649 | |
| 4650 | #ifndef CONFIG_NO_RADIUS |
| 4651 | hostapd_acl_expire(hapd); |
| 4652 | #endif /* CONFIG_NO_RADIUS */ |
| 4653 | } |
| 4654 | } |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 4655 | |
| 4656 | |
| 4657 | #ifdef CONFIG_OCV |
| 4658 | void hostapd_ocv_check_csa_sa_query(void *eloop_ctx, void *timeout_ctx) |
| 4659 | { |
| 4660 | struct hostapd_data *hapd = eloop_ctx; |
| 4661 | struct sta_info *sta; |
| 4662 | |
| 4663 | wpa_printf(MSG_DEBUG, "OCV: Post-CSA SA Query initiation check"); |
| 4664 | |
| 4665 | for (sta = hapd->sta_list; sta; sta = sta->next) { |
| 4666 | if (!sta->post_csa_sa_query) |
| 4667 | continue; |
| 4668 | |
| 4669 | wpa_printf(MSG_DEBUG, "OCV: OCVC STA " MACSTR |
| 4670 | " did not start SA Query after CSA - disconnect", |
| 4671 | MAC2STR(sta->addr)); |
| 4672 | ap_sta_disconnect(hapd, sta, sta->addr, |
| 4673 | WLAN_REASON_PREV_AUTH_NOT_VALID); |
| 4674 | } |
| 4675 | } |
| 4676 | #endif /* CONFIG_OCV */ |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 4677 | |
| 4678 | |
| 4679 | #ifdef CONFIG_IEEE80211BE |
Sunil Ravi | af399a8 | 2024-05-05 20:56:55 +0000 | [diff] [blame^] | 4680 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 4681 | struct hostapd_data * hostapd_mld_get_link_bss(struct hostapd_data *hapd, |
| 4682 | u8 link_id) |
| 4683 | { |
| 4684 | unsigned int i; |
| 4685 | |
| 4686 | for (i = 0; i < hapd->iface->interfaces->count; i++) { |
| 4687 | struct hostapd_iface *h = hapd->iface->interfaces->iface[i]; |
| 4688 | struct hostapd_data *h_hapd = h->bss[0]; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 4689 | |
Sunil Ravi | af399a8 | 2024-05-05 20:56:55 +0000 | [diff] [blame^] | 4690 | if (!hostapd_is_ml_partner(hapd, h_hapd)) |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 4691 | continue; |
| 4692 | |
| 4693 | if (h_hapd->mld_link_id == link_id) |
| 4694 | return h_hapd; |
| 4695 | } |
| 4696 | |
| 4697 | return NULL; |
| 4698 | } |
Sunil Ravi | af399a8 | 2024-05-05 20:56:55 +0000 | [diff] [blame^] | 4699 | |
| 4700 | |
| 4701 | bool hostapd_is_ml_partner(struct hostapd_data *hapd1, |
| 4702 | struct hostapd_data *hapd2) |
| 4703 | { |
| 4704 | if (!hapd1->conf->mld_ap || !hapd2->conf->mld_ap) |
| 4705 | return false; |
| 4706 | |
| 4707 | return !os_strcmp(hapd1->conf->iface, hapd2->conf->iface); |
| 4708 | } |
| 4709 | |
| 4710 | |
| 4711 | u8 hostapd_get_mld_id(struct hostapd_data *hapd) |
| 4712 | { |
| 4713 | if (!hapd->conf->mld_ap) |
| 4714 | return 255; |
| 4715 | |
| 4716 | /* MLD ID 0 represents self */ |
| 4717 | return 0; |
| 4718 | |
| 4719 | /* TODO: MLD ID for Multiple BSS cases */ |
| 4720 | } |
| 4721 | |
| 4722 | |
| 4723 | int hostapd_mld_add_link(struct hostapd_data *hapd) |
| 4724 | { |
| 4725 | struct hostapd_mld *mld = hapd->mld; |
| 4726 | |
| 4727 | if (!hapd->conf->mld_ap) |
| 4728 | return 0; |
| 4729 | |
| 4730 | /* Should not happen */ |
| 4731 | if (!mld) |
| 4732 | return -1; |
| 4733 | |
| 4734 | dl_list_add_tail(&mld->links, &hapd->link); |
| 4735 | mld->num_links++; |
| 4736 | |
| 4737 | wpa_printf(MSG_DEBUG, "AP MLD %s: Link ID %d added. num_links: %d", |
| 4738 | mld->name, hapd->mld_link_id, mld->num_links); |
| 4739 | |
| 4740 | if (mld->fbss) |
| 4741 | return 0; |
| 4742 | |
| 4743 | mld->fbss = hapd; |
| 4744 | wpa_printf(MSG_DEBUG, "AP MLD %s: First link BSS set to %p", |
| 4745 | mld->name, mld->fbss); |
| 4746 | return 0; |
| 4747 | } |
| 4748 | |
| 4749 | |
| 4750 | int hostapd_mld_remove_link(struct hostapd_data *hapd) |
| 4751 | { |
| 4752 | struct hostapd_mld *mld = hapd->mld; |
| 4753 | struct hostapd_data *next_fbss; |
| 4754 | |
| 4755 | if (!hapd->conf->mld_ap) |
| 4756 | return 0; |
| 4757 | |
| 4758 | /* Should not happen */ |
| 4759 | if (!mld) |
| 4760 | return -1; |
| 4761 | |
| 4762 | dl_list_del(&hapd->link); |
| 4763 | mld->num_links--; |
| 4764 | |
| 4765 | wpa_printf(MSG_DEBUG, "AP MLD %s: Link ID %d removed. num_links: %d", |
| 4766 | mld->name, hapd->mld_link_id, mld->num_links); |
| 4767 | |
| 4768 | if (mld->fbss != hapd) |
| 4769 | return 0; |
| 4770 | |
| 4771 | /* If the list is empty, all links are removed */ |
| 4772 | if (dl_list_empty(&mld->links)) { |
| 4773 | mld->fbss = NULL; |
| 4774 | } else { |
| 4775 | next_fbss = dl_list_entry(mld->links.next, struct hostapd_data, |
| 4776 | link); |
| 4777 | mld->fbss = next_fbss; |
| 4778 | } |
| 4779 | |
| 4780 | wpa_printf(MSG_DEBUG, "AP MLD %s: First link BSS set to %p", |
| 4781 | mld->name, mld->fbss); |
| 4782 | return 0; |
| 4783 | } |
| 4784 | |
| 4785 | |
| 4786 | bool hostapd_mld_is_first_bss(struct hostapd_data *hapd) |
| 4787 | { |
| 4788 | struct hostapd_mld *mld = hapd->mld; |
| 4789 | |
| 4790 | if (!hapd->conf->mld_ap) |
| 4791 | return true; |
| 4792 | |
| 4793 | /* Should not happen */ |
| 4794 | if (!mld) |
| 4795 | return false; |
| 4796 | |
| 4797 | /* If fbss is not set, it is safe to assume the caller is the first BSS. |
| 4798 | */ |
| 4799 | if (!mld->fbss) |
| 4800 | return true; |
| 4801 | |
| 4802 | return hapd == mld->fbss; |
| 4803 | } |
| 4804 | |
| 4805 | |
| 4806 | struct hostapd_data * hostapd_mld_get_first_bss(struct hostapd_data *hapd) |
| 4807 | { |
| 4808 | struct hostapd_mld *mld = hapd->mld; |
| 4809 | |
| 4810 | if (!hapd->conf->mld_ap) |
| 4811 | return NULL; |
| 4812 | |
| 4813 | /* Should not happen */ |
| 4814 | if (!mld) |
| 4815 | return NULL; |
| 4816 | |
| 4817 | return mld->fbss; |
| 4818 | } |
| 4819 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 4820 | #endif /* CONFIG_IEEE80211BE */ |
Sunil Ravi | af399a8 | 2024-05-05 20:56:55 +0000 | [diff] [blame^] | 4821 | |
| 4822 | |
| 4823 | u16 hostapd_get_punct_bitmap(struct hostapd_data *hapd) |
| 4824 | { |
| 4825 | u16 punct_bitmap = 0; |
| 4826 | |
| 4827 | #ifdef CONFIG_IEEE80211BE |
| 4828 | punct_bitmap = hapd->iconf->punct_bitmap; |
| 4829 | #ifdef CONFIG_TESTING_OPTIONS |
| 4830 | if (!punct_bitmap) |
| 4831 | punct_bitmap = hapd->conf->eht_oper_puncturing_override; |
| 4832 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 4833 | #endif /* CONFIG_IEEE80211BE */ |
| 4834 | |
| 4835 | return punct_bitmap; |
| 4836 | } |