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