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