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