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