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