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