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