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