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