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 | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 15 | #include "radius/radius_client.h" |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 16 | #include "radius/radius_das.h" |
Dmitry Shmidt | 50b691d | 2014-05-21 14:01:45 -0700 | [diff] [blame^] | 17 | #include "eap_server/tncs.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 18 | #include "hostapd.h" |
| 19 | #include "authsrv.h" |
| 20 | #include "sta_info.h" |
| 21 | #include "accounting.h" |
| 22 | #include "ap_list.h" |
| 23 | #include "beacon.h" |
| 24 | #include "iapp.h" |
| 25 | #include "ieee802_1x.h" |
| 26 | #include "ieee802_11_auth.h" |
| 27 | #include "vlan_init.h" |
| 28 | #include "wpa_auth.h" |
| 29 | #include "wps_hostapd.h" |
| 30 | #include "hw_features.h" |
| 31 | #include "wpa_auth_glue.h" |
| 32 | #include "ap_drv_ops.h" |
| 33 | #include "ap_config.h" |
| 34 | #include "p2p_hostapd.h" |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 35 | #include "gas_serv.h" |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 36 | #include "dfs.h" |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 37 | #include "ieee802_11.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 38 | |
| 39 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 40 | static int hostapd_flush_old_stations(struct hostapd_data *hapd, u16 reason); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 41 | static int hostapd_setup_encryption(char *iface, struct hostapd_data *hapd); |
Dmitry Shmidt | c55524a | 2011-07-07 11:18:38 -0700 | [diff] [blame] | 42 | static int hostapd_broadcast_wep_clear(struct hostapd_data *hapd); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 43 | static int setup_interface2(struct hostapd_iface *iface); |
| 44 | static void channel_list_update_timeout(void *eloop_ctx, void *timeout_ctx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 45 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 46 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 47 | int hostapd_for_each_interface(struct hapd_interfaces *interfaces, |
| 48 | int (*cb)(struct hostapd_iface *iface, |
| 49 | void *ctx), void *ctx) |
| 50 | { |
| 51 | size_t i; |
| 52 | int ret; |
| 53 | |
| 54 | for (i = 0; i < interfaces->count; i++) { |
| 55 | ret = cb(interfaces->iface[i], ctx); |
| 56 | if (ret) |
| 57 | return ret; |
| 58 | } |
| 59 | |
| 60 | return 0; |
| 61 | } |
| 62 | |
| 63 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 64 | static void hostapd_reload_bss(struct hostapd_data *hapd) |
| 65 | { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 66 | struct hostapd_ssid *ssid; |
| 67 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 68 | #ifndef CONFIG_NO_RADIUS |
| 69 | radius_client_reconfig(hapd->radius, hapd->conf->radius); |
| 70 | #endif /* CONFIG_NO_RADIUS */ |
| 71 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 72 | ssid = &hapd->conf->ssid; |
| 73 | if (!ssid->wpa_psk_set && ssid->wpa_psk && !ssid->wpa_psk->next && |
| 74 | ssid->wpa_passphrase_set && ssid->wpa_passphrase) { |
| 75 | /* |
| 76 | * Force PSK to be derived again since SSID or passphrase may |
| 77 | * have changed. |
| 78 | */ |
| 79 | os_free(ssid->wpa_psk); |
| 80 | ssid->wpa_psk = NULL; |
| 81 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 82 | if (hostapd_setup_wpa_psk(hapd->conf)) { |
| 83 | wpa_printf(MSG_ERROR, "Failed to re-configure WPA PSK " |
| 84 | "after reloading configuration"); |
| 85 | } |
| 86 | |
| 87 | if (hapd->conf->ieee802_1x || hapd->conf->wpa) |
| 88 | hostapd_set_drv_ieee8021x(hapd, hapd->conf->iface, 1); |
| 89 | else |
| 90 | hostapd_set_drv_ieee8021x(hapd, hapd->conf->iface, 0); |
| 91 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 92 | if ((hapd->conf->wpa || hapd->conf->osen) && hapd->wpa_auth == NULL) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 93 | hostapd_setup_wpa(hapd); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 94 | if (hapd->wpa_auth) |
| 95 | wpa_init_keys(hapd->wpa_auth); |
| 96 | } else if (hapd->conf->wpa) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 97 | const u8 *wpa_ie; |
| 98 | size_t wpa_ie_len; |
| 99 | hostapd_reconfig_wpa(hapd); |
| 100 | wpa_ie = wpa_auth_get_wpa_ie(hapd->wpa_auth, &wpa_ie_len); |
| 101 | if (hostapd_set_generic_elem(hapd, wpa_ie, wpa_ie_len)) |
| 102 | wpa_printf(MSG_ERROR, "Failed to configure WPA IE for " |
| 103 | "the kernel driver."); |
| 104 | } else if (hapd->wpa_auth) { |
| 105 | wpa_deinit(hapd->wpa_auth); |
| 106 | hapd->wpa_auth = NULL; |
| 107 | hostapd_set_privacy(hapd, 0); |
| 108 | hostapd_setup_encryption(hapd->conf->iface, hapd); |
| 109 | hostapd_set_generic_elem(hapd, (u8 *) "", 0); |
| 110 | } |
| 111 | |
| 112 | ieee802_11_set_beacon(hapd); |
| 113 | hostapd_update_wps(hapd); |
| 114 | |
| 115 | if (hapd->conf->ssid.ssid_set && |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 116 | hostapd_set_ssid(hapd, hapd->conf->ssid.ssid, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 117 | hapd->conf->ssid.ssid_len)) { |
| 118 | wpa_printf(MSG_ERROR, "Could not set SSID for kernel driver"); |
| 119 | /* try to continue */ |
| 120 | } |
| 121 | wpa_printf(MSG_DEBUG, "Reconfigured interface %s", hapd->conf->iface); |
| 122 | } |
| 123 | |
| 124 | |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 125 | static void hostapd_clear_old(struct hostapd_iface *iface) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 126 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 127 | size_t j; |
| 128 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 129 | /* |
| 130 | * Deauthenticate all stations since the new configuration may not |
| 131 | * allow them to use the BSS anymore. |
| 132 | */ |
| 133 | for (j = 0; j < iface->num_bss; j++) { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 134 | hostapd_flush_old_stations(iface->bss[j], |
| 135 | WLAN_REASON_PREV_AUTH_NOT_VALID); |
Dmitry Shmidt | c55524a | 2011-07-07 11:18:38 -0700 | [diff] [blame] | 136 | hostapd_broadcast_wep_clear(iface->bss[j]); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 137 | |
| 138 | #ifndef CONFIG_NO_RADIUS |
| 139 | /* TODO: update dynamic data based on changed configuration |
| 140 | * items (e.g., open/close sockets, etc.) */ |
| 141 | radius_client_flush(iface->bss[j]->radius, 0); |
| 142 | #endif /* CONFIG_NO_RADIUS */ |
| 143 | } |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | |
| 147 | int hostapd_reload_config(struct hostapd_iface *iface) |
| 148 | { |
| 149 | struct hostapd_data *hapd = iface->bss[0]; |
| 150 | struct hostapd_config *newconf, *oldconf; |
| 151 | size_t j; |
| 152 | |
| 153 | if (iface->config_fname == NULL) { |
| 154 | /* Only in-memory config in use - assume it has been updated */ |
| 155 | hostapd_clear_old(iface); |
| 156 | for (j = 0; j < iface->num_bss; j++) |
| 157 | hostapd_reload_bss(iface->bss[j]); |
| 158 | return 0; |
| 159 | } |
| 160 | |
| 161 | if (iface->interfaces == NULL || |
| 162 | iface->interfaces->config_read_cb == NULL) |
| 163 | return -1; |
| 164 | newconf = iface->interfaces->config_read_cb(iface->config_fname); |
| 165 | if (newconf == NULL) |
| 166 | return -1; |
| 167 | |
| 168 | hostapd_clear_old(iface); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 169 | |
| 170 | oldconf = hapd->iconf; |
| 171 | iface->conf = newconf; |
| 172 | |
| 173 | for (j = 0; j < iface->num_bss; j++) { |
| 174 | hapd = iface->bss[j]; |
| 175 | hapd->iconf = newconf; |
Dmitry Shmidt | d11f019 | 2014-03-24 12:09:47 -0700 | [diff] [blame] | 176 | hapd->iconf->channel = oldconf->channel; |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 177 | hapd->iconf->secondary_channel = oldconf->secondary_channel; |
Dmitry Shmidt | d11f019 | 2014-03-24 12:09:47 -0700 | [diff] [blame] | 178 | hapd->iconf->ieee80211n = oldconf->ieee80211n; |
| 179 | hapd->iconf->ieee80211ac = oldconf->ieee80211ac; |
| 180 | hapd->iconf->ht_capab = oldconf->ht_capab; |
| 181 | hapd->iconf->vht_capab = oldconf->vht_capab; |
| 182 | hapd->iconf->vht_oper_chwidth = oldconf->vht_oper_chwidth; |
| 183 | hapd->iconf->vht_oper_centr_freq_seg0_idx = |
| 184 | oldconf->vht_oper_centr_freq_seg0_idx; |
| 185 | hapd->iconf->vht_oper_centr_freq_seg1_idx = |
| 186 | oldconf->vht_oper_centr_freq_seg1_idx; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 187 | hapd->conf = newconf->bss[j]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 188 | hostapd_reload_bss(hapd); |
| 189 | } |
| 190 | |
| 191 | hostapd_config_free(oldconf); |
| 192 | |
| 193 | |
| 194 | return 0; |
| 195 | } |
| 196 | |
| 197 | |
| 198 | static void hostapd_broadcast_key_clear_iface(struct hostapd_data *hapd, |
| 199 | char *ifname) |
| 200 | { |
| 201 | int i; |
| 202 | |
| 203 | for (i = 0; i < NUM_WEP_KEYS; i++) { |
| 204 | if (hostapd_drv_set_key(ifname, hapd, WPA_ALG_NONE, NULL, i, |
| 205 | 0, NULL, 0, NULL, 0)) { |
| 206 | wpa_printf(MSG_DEBUG, "Failed to clear default " |
| 207 | "encryption keys (ifname=%s keyidx=%d)", |
| 208 | ifname, i); |
| 209 | } |
| 210 | } |
| 211 | #ifdef CONFIG_IEEE80211W |
| 212 | if (hapd->conf->ieee80211w) { |
| 213 | for (i = NUM_WEP_KEYS; i < NUM_WEP_KEYS + 2; i++) { |
| 214 | if (hostapd_drv_set_key(ifname, hapd, WPA_ALG_NONE, |
| 215 | NULL, i, 0, NULL, |
| 216 | 0, NULL, 0)) { |
| 217 | wpa_printf(MSG_DEBUG, "Failed to clear " |
| 218 | "default mgmt encryption keys " |
| 219 | "(ifname=%s keyidx=%d)", ifname, i); |
| 220 | } |
| 221 | } |
| 222 | } |
| 223 | #endif /* CONFIG_IEEE80211W */ |
| 224 | } |
| 225 | |
| 226 | |
| 227 | static int hostapd_broadcast_wep_clear(struct hostapd_data *hapd) |
| 228 | { |
| 229 | hostapd_broadcast_key_clear_iface(hapd, hapd->conf->iface); |
| 230 | return 0; |
| 231 | } |
| 232 | |
| 233 | |
| 234 | static int hostapd_broadcast_wep_set(struct hostapd_data *hapd) |
| 235 | { |
| 236 | int errors = 0, idx; |
| 237 | struct hostapd_ssid *ssid = &hapd->conf->ssid; |
| 238 | |
| 239 | idx = ssid->wep.idx; |
| 240 | if (ssid->wep.default_len && |
| 241 | hostapd_drv_set_key(hapd->conf->iface, |
| 242 | hapd, WPA_ALG_WEP, broadcast_ether_addr, idx, |
| 243 | 1, NULL, 0, ssid->wep.key[idx], |
| 244 | ssid->wep.len[idx])) { |
| 245 | wpa_printf(MSG_WARNING, "Could not set WEP encryption."); |
| 246 | errors++; |
| 247 | } |
| 248 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 249 | return errors; |
| 250 | } |
| 251 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 252 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 253 | static void hostapd_free_hapd_data(struct hostapd_data *hapd) |
| 254 | { |
Dmitry Shmidt | fa3fc4a | 2013-11-21 13:34:38 -0800 | [diff] [blame] | 255 | if (!hapd->started) { |
| 256 | wpa_printf(MSG_ERROR, "%s: Interface %s wasn't started", |
| 257 | __func__, hapd->conf->iface); |
| 258 | return; |
| 259 | } |
| 260 | hapd->started = 0; |
| 261 | |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 262 | wpa_printf(MSG_DEBUG, "%s(%s)", __func__, hapd->conf->iface); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 263 | iapp_deinit(hapd->iapp); |
| 264 | hapd->iapp = NULL; |
| 265 | accounting_deinit(hapd); |
| 266 | hostapd_deinit_wpa(hapd); |
| 267 | vlan_deinit(hapd); |
| 268 | hostapd_acl_deinit(hapd); |
| 269 | #ifndef CONFIG_NO_RADIUS |
| 270 | radius_client_deinit(hapd->radius); |
| 271 | hapd->radius = NULL; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 272 | radius_das_deinit(hapd->radius_das); |
| 273 | hapd->radius_das = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 274 | #endif /* CONFIG_NO_RADIUS */ |
| 275 | |
| 276 | hostapd_deinit_wps(hapd); |
| 277 | |
| 278 | authsrv_deinit(hapd); |
| 279 | |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 280 | if (hapd->interface_added && |
| 281 | hostapd_if_remove(hapd, WPA_IF_AP_BSS, hapd->conf->iface)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 282 | wpa_printf(MSG_WARNING, "Failed to remove BSS interface %s", |
| 283 | hapd->conf->iface); |
| 284 | } |
| 285 | |
| 286 | os_free(hapd->probereq_cb); |
| 287 | hapd->probereq_cb = NULL; |
| 288 | |
| 289 | #ifdef CONFIG_P2P |
| 290 | wpabuf_free(hapd->p2p_beacon_ie); |
| 291 | hapd->p2p_beacon_ie = NULL; |
| 292 | wpabuf_free(hapd->p2p_probe_resp_ie); |
| 293 | hapd->p2p_probe_resp_ie = NULL; |
| 294 | #endif /* CONFIG_P2P */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 295 | |
| 296 | wpabuf_free(hapd->time_adv); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 297 | |
| 298 | #ifdef CONFIG_INTERWORKING |
| 299 | gas_serv_deinit(hapd); |
| 300 | #endif /* CONFIG_INTERWORKING */ |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 301 | |
| 302 | #ifdef CONFIG_SQLITE |
| 303 | os_free(hapd->tmp_eap_user.identity); |
| 304 | os_free(hapd->tmp_eap_user.password); |
| 305 | #endif /* CONFIG_SQLITE */ |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | |
| 309 | /** |
| 310 | * hostapd_cleanup - Per-BSS cleanup (deinitialization) |
| 311 | * @hapd: Pointer to BSS data |
| 312 | * |
| 313 | * 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] | 314 | * Most of the modules that are initialized in hostapd_setup_bss() are |
| 315 | * deinitialized here. |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 316 | */ |
| 317 | static void hostapd_cleanup(struct hostapd_data *hapd) |
| 318 | { |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 319 | wpa_printf(MSG_DEBUG, "%s(hapd=%p (%s))", __func__, hapd, |
| 320 | hapd->conf->iface); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 321 | if (hapd->iface->interfaces && |
| 322 | hapd->iface->interfaces->ctrl_iface_deinit) |
| 323 | hapd->iface->interfaces->ctrl_iface_deinit(hapd); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 324 | hostapd_free_hapd_data(hapd); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 328 | static void hostapd_cleanup_iface_partial(struct hostapd_iface *iface) |
| 329 | { |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 330 | wpa_printf(MSG_DEBUG, "%s(%p)", __func__, iface); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 331 | hostapd_free_hw_features(iface->hw_features, iface->num_hw_features); |
| 332 | iface->hw_features = NULL; |
| 333 | os_free(iface->current_rates); |
| 334 | iface->current_rates = NULL; |
| 335 | os_free(iface->basic_rates); |
| 336 | iface->basic_rates = NULL; |
| 337 | ap_list_deinit(iface); |
| 338 | } |
| 339 | |
| 340 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 341 | /** |
| 342 | * hostapd_cleanup_iface - Complete per-interface cleanup |
| 343 | * @iface: Pointer to interface data |
| 344 | * |
| 345 | * This function is called after per-BSS data structures are deinitialized |
| 346 | * with hostapd_cleanup(). |
| 347 | */ |
| 348 | static void hostapd_cleanup_iface(struct hostapd_iface *iface) |
| 349 | { |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 350 | wpa_printf(MSG_DEBUG, "%s(%p)", __func__, iface); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 351 | eloop_cancel_timeout(channel_list_update_timeout, iface, NULL); |
| 352 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 353 | hostapd_cleanup_iface_partial(iface); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 354 | hostapd_config_free(iface->conf); |
| 355 | iface->conf = NULL; |
| 356 | |
| 357 | os_free(iface->config_fname); |
| 358 | os_free(iface->bss); |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 359 | wpa_printf(MSG_DEBUG, "%s: free iface=%p", __func__, iface); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 360 | os_free(iface); |
| 361 | } |
| 362 | |
| 363 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 364 | static void hostapd_clear_wep(struct hostapd_data *hapd) |
| 365 | { |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 366 | if (hapd->drv_priv && !hapd->iface->driver_ap_teardown) { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 367 | hostapd_set_privacy(hapd, 0); |
| 368 | hostapd_broadcast_wep_clear(hapd); |
| 369 | } |
| 370 | } |
| 371 | |
| 372 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 373 | static int hostapd_setup_encryption(char *iface, struct hostapd_data *hapd) |
| 374 | { |
| 375 | int i; |
| 376 | |
| 377 | hostapd_broadcast_wep_set(hapd); |
| 378 | |
| 379 | if (hapd->conf->ssid.wep.default_len) { |
| 380 | hostapd_set_privacy(hapd, 1); |
| 381 | return 0; |
| 382 | } |
| 383 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 384 | /* |
| 385 | * When IEEE 802.1X is not enabled, the driver may need to know how to |
| 386 | * set authentication algorithms for static WEP. |
| 387 | */ |
| 388 | hostapd_drv_set_authmode(hapd, hapd->conf->auth_algs); |
| 389 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 390 | for (i = 0; i < 4; i++) { |
| 391 | if (hapd->conf->ssid.wep.key[i] && |
| 392 | hostapd_drv_set_key(iface, hapd, WPA_ALG_WEP, NULL, i, |
| 393 | i == hapd->conf->ssid.wep.idx, NULL, 0, |
| 394 | hapd->conf->ssid.wep.key[i], |
| 395 | hapd->conf->ssid.wep.len[i])) { |
| 396 | wpa_printf(MSG_WARNING, "Could not set WEP " |
| 397 | "encryption."); |
| 398 | return -1; |
| 399 | } |
| 400 | if (hapd->conf->ssid.wep.key[i] && |
| 401 | i == hapd->conf->ssid.wep.idx) |
| 402 | hostapd_set_privacy(hapd, 1); |
| 403 | } |
| 404 | |
| 405 | return 0; |
| 406 | } |
| 407 | |
| 408 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 409 | static int hostapd_flush_old_stations(struct hostapd_data *hapd, u16 reason) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 410 | { |
| 411 | int ret = 0; |
| 412 | u8 addr[ETH_ALEN]; |
| 413 | |
| 414 | if (hostapd_drv_none(hapd) || hapd->drv_priv == NULL) |
| 415 | return 0; |
| 416 | |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 417 | if (!hapd->iface->driver_ap_teardown) { |
| 418 | wpa_dbg(hapd->msg_ctx, MSG_DEBUG, |
| 419 | "Flushing old station entries"); |
| 420 | |
| 421 | if (hostapd_flush(hapd)) { |
| 422 | wpa_msg(hapd->msg_ctx, MSG_WARNING, |
| 423 | "Could not connect to kernel driver"); |
| 424 | ret = -1; |
| 425 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 426 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 427 | wpa_dbg(hapd->msg_ctx, MSG_DEBUG, "Deauthenticate all stations"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 428 | os_memset(addr, 0xff, ETH_ALEN); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 429 | hostapd_drv_sta_deauth(hapd, addr, reason); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 430 | hostapd_free_stas(hapd); |
| 431 | |
| 432 | return ret; |
| 433 | } |
| 434 | |
| 435 | |
| 436 | /** |
| 437 | * hostapd_validate_bssid_configuration - Validate BSSID configuration |
| 438 | * @iface: Pointer to interface data |
| 439 | * Returns: 0 on success, -1 on failure |
| 440 | * |
| 441 | * This function is used to validate that the configured BSSIDs are valid. |
| 442 | */ |
| 443 | static int hostapd_validate_bssid_configuration(struct hostapd_iface *iface) |
| 444 | { |
| 445 | u8 mask[ETH_ALEN] = { 0 }; |
| 446 | struct hostapd_data *hapd = iface->bss[0]; |
| 447 | unsigned int i = iface->conf->num_bss, bits = 0, j; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 448 | int auto_addr = 0; |
| 449 | |
| 450 | if (hostapd_drv_none(hapd)) |
| 451 | return 0; |
| 452 | |
| 453 | /* Generate BSSID mask that is large enough to cover the BSSIDs. */ |
| 454 | |
| 455 | /* Determine the bits necessary to cover the number of BSSIDs. */ |
| 456 | for (i--; i; i >>= 1) |
| 457 | bits++; |
| 458 | |
| 459 | /* Determine the bits necessary to any configured BSSIDs, |
| 460 | if they are higher than the number of BSSIDs. */ |
| 461 | for (j = 0; j < iface->conf->num_bss; j++) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 462 | if (hostapd_mac_comp_empty(iface->conf->bss[j]->bssid) == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 463 | if (j) |
| 464 | auto_addr++; |
| 465 | continue; |
| 466 | } |
| 467 | |
| 468 | for (i = 0; i < ETH_ALEN; i++) { |
| 469 | mask[i] |= |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 470 | iface->conf->bss[j]->bssid[i] ^ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 471 | hapd->own_addr[i]; |
| 472 | } |
| 473 | } |
| 474 | |
| 475 | if (!auto_addr) |
| 476 | goto skip_mask_ext; |
| 477 | |
| 478 | for (i = 0; i < ETH_ALEN && mask[i] == 0; i++) |
| 479 | ; |
| 480 | j = 0; |
| 481 | if (i < ETH_ALEN) { |
| 482 | j = (5 - i) * 8; |
| 483 | |
| 484 | while (mask[i] != 0) { |
| 485 | mask[i] >>= 1; |
| 486 | j++; |
| 487 | } |
| 488 | } |
| 489 | |
| 490 | if (bits < j) |
| 491 | bits = j; |
| 492 | |
| 493 | if (bits > 40) { |
| 494 | wpa_printf(MSG_ERROR, "Too many bits in the BSSID mask (%u)", |
| 495 | bits); |
| 496 | return -1; |
| 497 | } |
| 498 | |
| 499 | os_memset(mask, 0xff, ETH_ALEN); |
| 500 | j = bits / 8; |
| 501 | for (i = 5; i > 5 - j; i--) |
| 502 | mask[i] = 0; |
| 503 | j = bits % 8; |
| 504 | while (j--) |
| 505 | mask[i] <<= 1; |
| 506 | |
| 507 | skip_mask_ext: |
| 508 | wpa_printf(MSG_DEBUG, "BSS count %lu, BSSID mask " MACSTR " (%d bits)", |
| 509 | (unsigned long) iface->conf->num_bss, MAC2STR(mask), bits); |
| 510 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 511 | if (!auto_addr) |
| 512 | return 0; |
| 513 | |
| 514 | for (i = 0; i < ETH_ALEN; i++) { |
| 515 | if ((hapd->own_addr[i] & mask[i]) != hapd->own_addr[i]) { |
| 516 | wpa_printf(MSG_ERROR, "Invalid BSSID mask " MACSTR |
| 517 | " for start address " MACSTR ".", |
| 518 | MAC2STR(mask), MAC2STR(hapd->own_addr)); |
| 519 | wpa_printf(MSG_ERROR, "Start address must be the " |
| 520 | "first address in the block (i.e., addr " |
| 521 | "AND mask == addr)."); |
| 522 | return -1; |
| 523 | } |
| 524 | } |
| 525 | |
| 526 | return 0; |
| 527 | } |
| 528 | |
| 529 | |
| 530 | static int mac_in_conf(struct hostapd_config *conf, const void *a) |
| 531 | { |
| 532 | size_t i; |
| 533 | |
| 534 | for (i = 0; i < conf->num_bss; i++) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 535 | if (hostapd_mac_comp(conf->bss[i]->bssid, a) == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 536 | return 1; |
| 537 | } |
| 538 | } |
| 539 | |
| 540 | return 0; |
| 541 | } |
| 542 | |
| 543 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 544 | #ifndef CONFIG_NO_RADIUS |
| 545 | |
| 546 | static int hostapd_das_nas_mismatch(struct hostapd_data *hapd, |
| 547 | struct radius_das_attrs *attr) |
| 548 | { |
Dmitry Shmidt | 13ca8d8 | 2014-02-20 10:18:40 -0800 | [diff] [blame] | 549 | if (attr->nas_identifier && |
| 550 | (!hapd->conf->nas_identifier || |
| 551 | os_strlen(hapd->conf->nas_identifier) != |
| 552 | attr->nas_identifier_len || |
| 553 | os_memcmp(hapd->conf->nas_identifier, attr->nas_identifier, |
| 554 | attr->nas_identifier_len) != 0)) { |
| 555 | wpa_printf(MSG_DEBUG, "RADIUS DAS: NAS-Identifier mismatch"); |
| 556 | return 1; |
| 557 | } |
| 558 | |
| 559 | if (attr->nas_ip_addr && |
| 560 | (hapd->conf->own_ip_addr.af != AF_INET || |
| 561 | os_memcmp(&hapd->conf->own_ip_addr.u.v4, attr->nas_ip_addr, 4) != |
| 562 | 0)) { |
| 563 | wpa_printf(MSG_DEBUG, "RADIUS DAS: NAS-IP-Address mismatch"); |
| 564 | return 1; |
| 565 | } |
| 566 | |
| 567 | #ifdef CONFIG_IPV6 |
| 568 | if (attr->nas_ipv6_addr && |
| 569 | (hapd->conf->own_ip_addr.af != AF_INET6 || |
| 570 | os_memcmp(&hapd->conf->own_ip_addr.u.v6, attr->nas_ipv6_addr, 16) |
| 571 | != 0)) { |
| 572 | wpa_printf(MSG_DEBUG, "RADIUS DAS: NAS-IPv6-Address mismatch"); |
| 573 | return 1; |
| 574 | } |
| 575 | #endif /* CONFIG_IPV6 */ |
| 576 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 577 | return 0; |
| 578 | } |
| 579 | |
| 580 | |
| 581 | static struct sta_info * hostapd_das_find_sta(struct hostapd_data *hapd, |
| 582 | struct radius_das_attrs *attr) |
| 583 | { |
| 584 | struct sta_info *sta = NULL; |
| 585 | char buf[128]; |
| 586 | |
| 587 | if (attr->sta_addr) |
| 588 | sta = ap_get_sta(hapd, attr->sta_addr); |
| 589 | |
| 590 | if (sta == NULL && attr->acct_session_id && |
| 591 | attr->acct_session_id_len == 17) { |
| 592 | for (sta = hapd->sta_list; sta; sta = sta->next) { |
| 593 | os_snprintf(buf, sizeof(buf), "%08X-%08X", |
| 594 | sta->acct_session_id_hi, |
| 595 | sta->acct_session_id_lo); |
| 596 | if (os_memcmp(attr->acct_session_id, buf, 17) == 0) |
| 597 | break; |
| 598 | } |
| 599 | } |
| 600 | |
| 601 | if (sta == NULL && attr->cui) { |
| 602 | for (sta = hapd->sta_list; sta; sta = sta->next) { |
| 603 | struct wpabuf *cui; |
| 604 | cui = ieee802_1x_get_radius_cui(sta->eapol_sm); |
| 605 | if (cui && wpabuf_len(cui) == attr->cui_len && |
| 606 | os_memcmp(wpabuf_head(cui), attr->cui, |
| 607 | attr->cui_len) == 0) |
| 608 | break; |
| 609 | } |
| 610 | } |
| 611 | |
| 612 | if (sta == NULL && attr->user_name) { |
| 613 | for (sta = hapd->sta_list; sta; sta = sta->next) { |
| 614 | u8 *identity; |
| 615 | size_t identity_len; |
| 616 | identity = ieee802_1x_get_identity(sta->eapol_sm, |
| 617 | &identity_len); |
| 618 | if (identity && |
| 619 | identity_len == attr->user_name_len && |
| 620 | os_memcmp(identity, attr->user_name, identity_len) |
| 621 | == 0) |
| 622 | break; |
| 623 | } |
| 624 | } |
| 625 | |
| 626 | return sta; |
| 627 | } |
| 628 | |
| 629 | |
| 630 | static enum radius_das_res |
| 631 | hostapd_das_disconnect(void *ctx, struct radius_das_attrs *attr) |
| 632 | { |
| 633 | struct hostapd_data *hapd = ctx; |
| 634 | struct sta_info *sta; |
| 635 | |
| 636 | if (hostapd_das_nas_mismatch(hapd, attr)) |
| 637 | return RADIUS_DAS_NAS_MISMATCH; |
| 638 | |
| 639 | sta = hostapd_das_find_sta(hapd, attr); |
| 640 | if (sta == NULL) |
| 641 | return RADIUS_DAS_SESSION_NOT_FOUND; |
| 642 | |
Dmitry Shmidt | 13ca8d8 | 2014-02-20 10:18:40 -0800 | [diff] [blame] | 643 | wpa_auth_pmksa_remove(hapd->wpa_auth, sta->addr); |
| 644 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 645 | hostapd_drv_sta_deauth(hapd, sta->addr, |
| 646 | WLAN_REASON_PREV_AUTH_NOT_VALID); |
| 647 | ap_sta_deauthenticate(hapd, sta, WLAN_REASON_PREV_AUTH_NOT_VALID); |
| 648 | |
| 649 | return RADIUS_DAS_SUCCESS; |
| 650 | } |
| 651 | |
| 652 | #endif /* CONFIG_NO_RADIUS */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 653 | |
| 654 | |
| 655 | /** |
| 656 | * hostapd_setup_bss - Per-BSS setup (initialization) |
| 657 | * @hapd: Pointer to BSS data |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 658 | * @first: Whether this BSS is the first BSS of an interface; -1 = not first, |
| 659 | * but interface may exist |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 660 | * |
| 661 | * This function is used to initialize all per-BSS data structures and |
| 662 | * resources. This gets called in a loop for each BSS when an interface is |
| 663 | * initialized. Most of the modules that are initialized here will be |
| 664 | * deinitialized in hostapd_cleanup(). |
| 665 | */ |
| 666 | static int hostapd_setup_bss(struct hostapd_data *hapd, int first) |
| 667 | { |
| 668 | struct hostapd_bss_config *conf = hapd->conf; |
| 669 | u8 ssid[HOSTAPD_MAX_SSID_LEN + 1]; |
| 670 | int ssid_len, set_ssid; |
| 671 | char force_ifname[IFNAMSIZ]; |
| 672 | u8 if_addr[ETH_ALEN]; |
| 673 | |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 674 | wpa_printf(MSG_DEBUG, "%s(hapd=%p (%s), first=%d)", |
| 675 | __func__, hapd, hapd->conf->iface, first); |
| 676 | |
Dmitry Shmidt | 50b691d | 2014-05-21 14:01:45 -0700 | [diff] [blame^] | 677 | #ifdef EAP_SERVER_TNC |
| 678 | if (hapd->conf->tnc && tncs_global_init() < 0) { |
| 679 | wpa_printf(MSG_ERROR, "Failed to initialize TNCS"); |
| 680 | return -1; |
| 681 | } |
| 682 | #endif /* EAP_SERVER_TNC */ |
| 683 | |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 684 | if (hapd->started) { |
| 685 | wpa_printf(MSG_ERROR, "%s: Interface %s was already started", |
| 686 | __func__, hapd->conf->iface); |
| 687 | return -1; |
| 688 | } |
| 689 | hapd->started = 1; |
| 690 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 691 | if (!first || first == -1) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 692 | if (hostapd_mac_comp_empty(hapd->conf->bssid) == 0) { |
| 693 | /* Allocate the next available BSSID. */ |
| 694 | do { |
| 695 | inc_byte_array(hapd->own_addr, ETH_ALEN); |
| 696 | } while (mac_in_conf(hapd->iconf, hapd->own_addr)); |
| 697 | } else { |
| 698 | /* Allocate the configured BSSID. */ |
| 699 | os_memcpy(hapd->own_addr, hapd->conf->bssid, ETH_ALEN); |
| 700 | |
| 701 | if (hostapd_mac_comp(hapd->own_addr, |
| 702 | hapd->iface->bss[0]->own_addr) == |
| 703 | 0) { |
| 704 | wpa_printf(MSG_ERROR, "BSS '%s' may not have " |
| 705 | "BSSID set to the MAC address of " |
| 706 | "the radio", hapd->conf->iface); |
| 707 | return -1; |
| 708 | } |
| 709 | } |
| 710 | |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 711 | hapd->interface_added = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 712 | if (hostapd_if_add(hapd->iface->bss[0], WPA_IF_AP_BSS, |
| 713 | hapd->conf->iface, hapd->own_addr, hapd, |
| 714 | &hapd->drv_priv, force_ifname, if_addr, |
| 715 | hapd->conf->bridge[0] ? hapd->conf->bridge : |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 716 | NULL, first == -1)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 717 | wpa_printf(MSG_ERROR, "Failed to add BSS (BSSID=" |
| 718 | MACSTR ")", MAC2STR(hapd->own_addr)); |
Dmitry Shmidt | 3cf6f79 | 2013-12-18 13:12:19 -0800 | [diff] [blame] | 719 | hapd->interface_added = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 720 | return -1; |
| 721 | } |
| 722 | } |
| 723 | |
| 724 | if (conf->wmm_enabled < 0) |
| 725 | conf->wmm_enabled = hapd->iconf->ieee80211n; |
| 726 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 727 | hostapd_flush_old_stations(hapd, WLAN_REASON_PREV_AUTH_NOT_VALID); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 728 | hostapd_set_privacy(hapd, 0); |
| 729 | |
| 730 | hostapd_broadcast_wep_clear(hapd); |
| 731 | if (hostapd_setup_encryption(hapd->conf->iface, hapd)) |
| 732 | return -1; |
| 733 | |
| 734 | /* |
| 735 | * Fetch the SSID from the system and use it or, |
| 736 | * if one was specified in the config file, verify they |
| 737 | * match. |
| 738 | */ |
| 739 | ssid_len = hostapd_get_ssid(hapd, ssid, sizeof(ssid)); |
| 740 | if (ssid_len < 0) { |
| 741 | wpa_printf(MSG_ERROR, "Could not read SSID from system"); |
| 742 | return -1; |
| 743 | } |
| 744 | if (conf->ssid.ssid_set) { |
| 745 | /* |
| 746 | * If SSID is specified in the config file and it differs |
| 747 | * from what is being used then force installation of the |
| 748 | * new SSID. |
| 749 | */ |
| 750 | set_ssid = (conf->ssid.ssid_len != (size_t) ssid_len || |
| 751 | os_memcmp(conf->ssid.ssid, ssid, ssid_len) != 0); |
| 752 | } else { |
| 753 | /* |
| 754 | * No SSID in the config file; just use the one we got |
| 755 | * from the system. |
| 756 | */ |
| 757 | set_ssid = 0; |
| 758 | conf->ssid.ssid_len = ssid_len; |
| 759 | os_memcpy(conf->ssid.ssid, ssid, conf->ssid.ssid_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 760 | } |
| 761 | |
| 762 | if (!hostapd_drv_none(hapd)) { |
| 763 | wpa_printf(MSG_ERROR, "Using interface %s with hwaddr " MACSTR |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 764 | " and ssid \"%s\"", |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 765 | hapd->conf->iface, MAC2STR(hapd->own_addr), |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 766 | wpa_ssid_txt(hapd->conf->ssid.ssid, |
| 767 | hapd->conf->ssid.ssid_len)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 768 | } |
| 769 | |
| 770 | if (hostapd_setup_wpa_psk(conf)) { |
| 771 | wpa_printf(MSG_ERROR, "WPA-PSK setup failed."); |
| 772 | return -1; |
| 773 | } |
| 774 | |
| 775 | /* Set SSID for the kernel driver (to be used in beacon and probe |
| 776 | * response frames) */ |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 777 | if (set_ssid && hostapd_set_ssid(hapd, conf->ssid.ssid, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 778 | conf->ssid.ssid_len)) { |
| 779 | wpa_printf(MSG_ERROR, "Could not set SSID for kernel driver"); |
| 780 | return -1; |
| 781 | } |
| 782 | |
Dmitry Shmidt | 818ea48 | 2014-03-10 13:15:21 -0700 | [diff] [blame] | 783 | if (wpa_debug_level <= MSG_MSGDUMP) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 784 | conf->radius->msg_dumps = 1; |
| 785 | #ifndef CONFIG_NO_RADIUS |
| 786 | hapd->radius = radius_client_init(hapd, conf->radius); |
| 787 | if (hapd->radius == NULL) { |
| 788 | wpa_printf(MSG_ERROR, "RADIUS client initialization failed."); |
| 789 | return -1; |
| 790 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 791 | |
| 792 | if (hapd->conf->radius_das_port) { |
| 793 | struct radius_das_conf das_conf; |
| 794 | os_memset(&das_conf, 0, sizeof(das_conf)); |
| 795 | das_conf.port = hapd->conf->radius_das_port; |
| 796 | das_conf.shared_secret = hapd->conf->radius_das_shared_secret; |
| 797 | das_conf.shared_secret_len = |
| 798 | hapd->conf->radius_das_shared_secret_len; |
| 799 | das_conf.client_addr = &hapd->conf->radius_das_client_addr; |
| 800 | das_conf.time_window = hapd->conf->radius_das_time_window; |
| 801 | das_conf.require_event_timestamp = |
| 802 | hapd->conf->radius_das_require_event_timestamp; |
| 803 | das_conf.ctx = hapd; |
| 804 | das_conf.disconnect = hostapd_das_disconnect; |
| 805 | hapd->radius_das = radius_das_init(&das_conf); |
| 806 | if (hapd->radius_das == NULL) { |
| 807 | wpa_printf(MSG_ERROR, "RADIUS DAS initialization " |
| 808 | "failed."); |
| 809 | return -1; |
| 810 | } |
| 811 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 812 | #endif /* CONFIG_NO_RADIUS */ |
| 813 | |
| 814 | if (hostapd_acl_init(hapd)) { |
| 815 | wpa_printf(MSG_ERROR, "ACL initialization failed."); |
| 816 | return -1; |
| 817 | } |
| 818 | if (hostapd_init_wps(hapd, conf)) |
| 819 | return -1; |
| 820 | |
| 821 | if (authsrv_init(hapd) < 0) |
| 822 | return -1; |
| 823 | |
| 824 | if (ieee802_1x_init(hapd)) { |
| 825 | wpa_printf(MSG_ERROR, "IEEE 802.1X initialization failed."); |
| 826 | return -1; |
| 827 | } |
| 828 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 829 | if ((hapd->conf->wpa || hapd->conf->osen) && hostapd_setup_wpa(hapd)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 830 | return -1; |
| 831 | |
| 832 | if (accounting_init(hapd)) { |
| 833 | wpa_printf(MSG_ERROR, "Accounting initialization failed."); |
| 834 | return -1; |
| 835 | } |
| 836 | |
| 837 | if (hapd->conf->ieee802_11f && |
| 838 | (hapd->iapp = iapp_init(hapd, hapd->conf->iapp_iface)) == NULL) { |
| 839 | wpa_printf(MSG_ERROR, "IEEE 802.11F (IAPP) initialization " |
| 840 | "failed."); |
| 841 | return -1; |
| 842 | } |
| 843 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 844 | #ifdef CONFIG_INTERWORKING |
| 845 | if (gas_serv_init(hapd)) { |
| 846 | wpa_printf(MSG_ERROR, "GAS server initialization failed"); |
| 847 | return -1; |
| 848 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 849 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 850 | if (conf->qos_map_set_len && |
| 851 | hostapd_drv_set_qos_map(hapd, conf->qos_map_set, |
| 852 | conf->qos_map_set_len)) { |
| 853 | wpa_printf(MSG_ERROR, "Failed to initialize QoS Map"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 854 | return -1; |
| 855 | } |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 856 | #endif /* CONFIG_INTERWORKING */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 857 | |
| 858 | if (!hostapd_drv_none(hapd) && vlan_init(hapd)) { |
| 859 | wpa_printf(MSG_ERROR, "VLAN initialization failed."); |
| 860 | return -1; |
| 861 | } |
| 862 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 863 | if (!hapd->conf->start_disabled && ieee802_11_set_beacon(hapd) < 0) |
| 864 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 865 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 866 | if (hapd->wpa_auth && wpa_init_keys(hapd->wpa_auth) < 0) |
| 867 | return -1; |
| 868 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 869 | if (hapd->driver && hapd->driver->set_operstate) |
| 870 | hapd->driver->set_operstate(hapd->drv_priv, 1); |
| 871 | |
| 872 | return 0; |
| 873 | } |
| 874 | |
| 875 | |
| 876 | static void hostapd_tx_queue_params(struct hostapd_iface *iface) |
| 877 | { |
| 878 | struct hostapd_data *hapd = iface->bss[0]; |
| 879 | int i; |
| 880 | struct hostapd_tx_queue_params *p; |
| 881 | |
| 882 | for (i = 0; i < NUM_TX_QUEUES; i++) { |
| 883 | p = &iface->conf->tx_queue[i]; |
| 884 | |
| 885 | if (hostapd_set_tx_queue_params(hapd, i, p->aifs, p->cwmin, |
| 886 | p->cwmax, p->burst)) { |
| 887 | wpa_printf(MSG_DEBUG, "Failed to set TX queue " |
| 888 | "parameters for queue %d.", i); |
| 889 | /* Continue anyway */ |
| 890 | } |
| 891 | } |
| 892 | } |
| 893 | |
| 894 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 895 | static int hostapd_set_acl_list(struct hostapd_data *hapd, |
| 896 | struct mac_acl_entry *mac_acl, |
| 897 | int n_entries, u8 accept_acl) |
| 898 | { |
| 899 | struct hostapd_acl_params *acl_params; |
| 900 | int i, err; |
| 901 | |
| 902 | acl_params = os_zalloc(sizeof(*acl_params) + |
| 903 | (n_entries * sizeof(acl_params->mac_acl[0]))); |
| 904 | if (!acl_params) |
| 905 | return -ENOMEM; |
| 906 | |
| 907 | for (i = 0; i < n_entries; i++) |
| 908 | os_memcpy(acl_params->mac_acl[i].addr, mac_acl[i].addr, |
| 909 | ETH_ALEN); |
| 910 | |
| 911 | acl_params->acl_policy = accept_acl; |
| 912 | acl_params->num_mac_acl = n_entries; |
| 913 | |
| 914 | err = hostapd_drv_set_acl(hapd, acl_params); |
| 915 | |
| 916 | os_free(acl_params); |
| 917 | |
| 918 | return err; |
| 919 | } |
| 920 | |
| 921 | |
| 922 | static void hostapd_set_acl(struct hostapd_data *hapd) |
| 923 | { |
| 924 | struct hostapd_config *conf = hapd->iconf; |
| 925 | int err; |
| 926 | u8 accept_acl; |
| 927 | |
| 928 | if (hapd->iface->drv_max_acl_mac_addrs == 0) |
| 929 | return; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 930 | if (!(conf->bss[0]->num_accept_mac || conf->bss[0]->num_deny_mac)) |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 931 | return; |
| 932 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 933 | if (conf->bss[0]->macaddr_acl == DENY_UNLESS_ACCEPTED) { |
| 934 | if (conf->bss[0]->num_accept_mac) { |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 935 | accept_acl = 1; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 936 | err = hostapd_set_acl_list(hapd, |
| 937 | conf->bss[0]->accept_mac, |
| 938 | conf->bss[0]->num_accept_mac, |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 939 | accept_acl); |
| 940 | if (err) { |
| 941 | wpa_printf(MSG_DEBUG, "Failed to set accept acl"); |
| 942 | return; |
| 943 | } |
| 944 | } else { |
| 945 | wpa_printf(MSG_DEBUG, "Mismatch between ACL Policy & Accept/deny lists file"); |
| 946 | } |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 947 | } else if (conf->bss[0]->macaddr_acl == ACCEPT_UNLESS_DENIED) { |
| 948 | if (conf->bss[0]->num_deny_mac) { |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 949 | accept_acl = 0; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 950 | err = hostapd_set_acl_list(hapd, conf->bss[0]->deny_mac, |
| 951 | conf->bss[0]->num_deny_mac, |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 952 | accept_acl); |
| 953 | if (err) { |
| 954 | wpa_printf(MSG_DEBUG, "Failed to set deny acl"); |
| 955 | return; |
| 956 | } |
| 957 | } else { |
| 958 | wpa_printf(MSG_DEBUG, "Mismatch between ACL Policy & Accept/deny lists file"); |
| 959 | } |
| 960 | } |
| 961 | } |
| 962 | |
| 963 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 964 | static int start_ctrl_iface_bss(struct hostapd_data *hapd) |
| 965 | { |
| 966 | if (!hapd->iface->interfaces || |
| 967 | !hapd->iface->interfaces->ctrl_iface_init) |
| 968 | return 0; |
| 969 | |
| 970 | if (hapd->iface->interfaces->ctrl_iface_init(hapd)) { |
| 971 | wpa_printf(MSG_ERROR, |
| 972 | "Failed to setup control interface for %s", |
| 973 | hapd->conf->iface); |
| 974 | return -1; |
| 975 | } |
| 976 | |
| 977 | return 0; |
| 978 | } |
| 979 | |
| 980 | |
| 981 | static int start_ctrl_iface(struct hostapd_iface *iface) |
| 982 | { |
| 983 | size_t i; |
| 984 | |
| 985 | if (!iface->interfaces || !iface->interfaces->ctrl_iface_init) |
| 986 | return 0; |
| 987 | |
| 988 | for (i = 0; i < iface->num_bss; i++) { |
| 989 | struct hostapd_data *hapd = iface->bss[i]; |
| 990 | if (iface->interfaces->ctrl_iface_init(hapd)) { |
| 991 | wpa_printf(MSG_ERROR, |
| 992 | "Failed to setup control interface for %s", |
| 993 | hapd->conf->iface); |
| 994 | return -1; |
| 995 | } |
| 996 | } |
| 997 | |
| 998 | return 0; |
| 999 | } |
| 1000 | |
| 1001 | |
| 1002 | static void channel_list_update_timeout(void *eloop_ctx, void *timeout_ctx) |
| 1003 | { |
| 1004 | struct hostapd_iface *iface = eloop_ctx; |
| 1005 | |
| 1006 | if (!iface->wait_channel_update) { |
| 1007 | wpa_printf(MSG_INFO, "Channel list update timeout, but interface was not waiting for it"); |
| 1008 | return; |
| 1009 | } |
| 1010 | |
| 1011 | /* |
| 1012 | * It is possible that the existing channel list is acceptable, so try |
| 1013 | * to proceed. |
| 1014 | */ |
| 1015 | wpa_printf(MSG_DEBUG, "Channel list update timeout - try to continue anyway"); |
| 1016 | setup_interface2(iface); |
| 1017 | } |
| 1018 | |
| 1019 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1020 | void hostapd_channel_list_updated(struct hostapd_iface *iface, int initiator) |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1021 | { |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1022 | if (!iface->wait_channel_update || initiator != REGDOM_SET_BY_USER) |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1023 | return; |
| 1024 | |
| 1025 | wpa_printf(MSG_DEBUG, "Channel list updated - continue setup"); |
| 1026 | eloop_cancel_timeout(channel_list_update_timeout, iface, NULL); |
| 1027 | setup_interface2(iface); |
| 1028 | } |
| 1029 | |
| 1030 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1031 | static int setup_interface(struct hostapd_iface *iface) |
| 1032 | { |
| 1033 | struct hostapd_data *hapd = iface->bss[0]; |
| 1034 | size_t i; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1035 | |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 1036 | /* |
| 1037 | * It is possible that setup_interface() is called after the interface |
| 1038 | * was disabled etc., in which case driver_ap_teardown is possibly set |
| 1039 | * to 1. Clear it here so any other key/station deletion, which is not |
| 1040 | * part of a teardown flow, would also call the relevant driver |
| 1041 | * callbacks. |
| 1042 | */ |
| 1043 | iface->driver_ap_teardown = 0; |
| 1044 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1045 | if (!iface->phy[0]) { |
| 1046 | const char *phy = hostapd_drv_get_radio_name(hapd); |
| 1047 | if (phy) { |
| 1048 | wpa_printf(MSG_DEBUG, "phy: %s", phy); |
| 1049 | os_strlcpy(iface->phy, phy, sizeof(iface->phy)); |
| 1050 | } |
| 1051 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1052 | |
| 1053 | /* |
| 1054 | * Make sure that all BSSes get configured with a pointer to the same |
| 1055 | * driver interface. |
| 1056 | */ |
| 1057 | for (i = 1; i < iface->num_bss; i++) { |
| 1058 | iface->bss[i]->driver = hapd->driver; |
| 1059 | iface->bss[i]->drv_priv = hapd->drv_priv; |
| 1060 | } |
| 1061 | |
| 1062 | if (hostapd_validate_bssid_configuration(iface)) |
| 1063 | return -1; |
| 1064 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1065 | /* |
| 1066 | * Initialize control interfaces early to allow external monitoring of |
| 1067 | * channel setup operations that may take considerable amount of time |
| 1068 | * especially for DFS cases. |
| 1069 | */ |
| 1070 | if (start_ctrl_iface(iface)) |
| 1071 | return -1; |
| 1072 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1073 | if (hapd->iconf->country[0] && hapd->iconf->country[1]) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1074 | char country[4], previous_country[4]; |
| 1075 | |
| 1076 | hostapd_set_state(iface, HAPD_IFACE_COUNTRY_UPDATE); |
| 1077 | if (hostapd_get_country(hapd, previous_country) < 0) |
| 1078 | previous_country[0] = '\0'; |
| 1079 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1080 | os_memcpy(country, hapd->iconf->country, 3); |
| 1081 | country[3] = '\0'; |
| 1082 | if (hostapd_set_country(hapd, country) < 0) { |
| 1083 | wpa_printf(MSG_ERROR, "Failed to set country code"); |
| 1084 | return -1; |
| 1085 | } |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1086 | |
| 1087 | wpa_printf(MSG_DEBUG, "Previous country code %s, new country code %s", |
| 1088 | previous_country, country); |
| 1089 | |
| 1090 | if (os_strncmp(previous_country, country, 2) != 0) { |
| 1091 | wpa_printf(MSG_DEBUG, "Continue interface setup after channel list update"); |
| 1092 | iface->wait_channel_update = 1; |
Dmitry Shmidt | 9767226 | 2014-02-03 13:02:54 -0800 | [diff] [blame] | 1093 | eloop_register_timeout(5, 0, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1094 | channel_list_update_timeout, |
| 1095 | iface, NULL); |
| 1096 | return 0; |
| 1097 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1098 | } |
| 1099 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1100 | return setup_interface2(iface); |
| 1101 | } |
| 1102 | |
| 1103 | |
| 1104 | static int setup_interface2(struct hostapd_iface *iface) |
| 1105 | { |
| 1106 | iface->wait_channel_update = 0; |
| 1107 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1108 | if (hostapd_get_hw_features(iface)) { |
| 1109 | /* Not all drivers support this yet, so continue without hw |
| 1110 | * feature data. */ |
| 1111 | } else { |
| 1112 | int ret = hostapd_select_hw_mode(iface); |
| 1113 | if (ret < 0) { |
| 1114 | wpa_printf(MSG_ERROR, "Could not select hw_mode and " |
| 1115 | "channel. (%d)", ret); |
Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 1116 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1117 | } |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 1118 | if (ret == 1) { |
| 1119 | wpa_printf(MSG_DEBUG, "Interface initialization will be completed in a callback (ACS)"); |
| 1120 | return 0; |
| 1121 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1122 | ret = hostapd_check_ht_capab(iface); |
| 1123 | if (ret < 0) |
Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 1124 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1125 | if (ret == 1) { |
| 1126 | wpa_printf(MSG_DEBUG, "Interface initialization will " |
| 1127 | "be completed in a callback"); |
| 1128 | return 0; |
| 1129 | } |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 1130 | |
| 1131 | if (iface->conf->ieee80211h) |
| 1132 | wpa_printf(MSG_DEBUG, "DFS support is enabled"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1133 | } |
| 1134 | return hostapd_setup_interface_complete(iface, 0); |
Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 1135 | |
| 1136 | fail: |
| 1137 | hostapd_set_state(iface, HAPD_IFACE_DISABLED); |
| 1138 | wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO, AP_EVENT_DISABLED); |
| 1139 | if (iface->interfaces && iface->interfaces->terminate_on_error) |
| 1140 | eloop_terminate(); |
| 1141 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1142 | } |
| 1143 | |
| 1144 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1145 | /** |
| 1146 | * hostapd_setup_interface_complete - Complete interface setup |
| 1147 | * |
| 1148 | * This function is called when previous steps in the interface setup has been |
| 1149 | * completed. This can also start operations, e.g., DFS, that will require |
| 1150 | * additional processing before interface is ready to be enabled. Such |
| 1151 | * operations will call this function from eloop callbacks when finished. |
| 1152 | */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1153 | int hostapd_setup_interface_complete(struct hostapd_iface *iface, int err) |
| 1154 | { |
| 1155 | struct hostapd_data *hapd = iface->bss[0]; |
| 1156 | size_t j; |
| 1157 | u8 *prev_addr; |
| 1158 | |
Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 1159 | if (err) |
| 1160 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1161 | |
| 1162 | wpa_printf(MSG_DEBUG, "Completing interface initialization"); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1163 | if (iface->conf->channel) { |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 1164 | #ifdef NEED_AP_MLME |
| 1165 | int res; |
| 1166 | #endif /* NEED_AP_MLME */ |
| 1167 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1168 | iface->freq = hostapd_hw_get_freq(hapd, iface->conf->channel); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1169 | wpa_printf(MSG_DEBUG, "Mode: %s Channel: %d " |
| 1170 | "Frequency: %d MHz", |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1171 | hostapd_hw_mode_txt(iface->conf->hw_mode), |
| 1172 | iface->conf->channel, iface->freq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1173 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 1174 | #ifdef NEED_AP_MLME |
| 1175 | /* Check DFS */ |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1176 | res = hostapd_handle_dfs(iface); |
Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 1177 | if (res <= 0) { |
| 1178 | if (res < 0) |
| 1179 | goto fail; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 1180 | return res; |
Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 1181 | } |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 1182 | #endif /* NEED_AP_MLME */ |
| 1183 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1184 | if (hostapd_set_freq(hapd, hapd->iconf->hw_mode, iface->freq, |
| 1185 | hapd->iconf->channel, |
| 1186 | hapd->iconf->ieee80211n, |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1187 | hapd->iconf->ieee80211ac, |
| 1188 | hapd->iconf->secondary_channel, |
| 1189 | hapd->iconf->vht_oper_chwidth, |
| 1190 | hapd->iconf->vht_oper_centr_freq_seg0_idx, |
| 1191 | hapd->iconf->vht_oper_centr_freq_seg1_idx)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1192 | wpa_printf(MSG_ERROR, "Could not set channel for " |
| 1193 | "kernel driver"); |
Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 1194 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1195 | } |
| 1196 | } |
| 1197 | |
| 1198 | if (iface->current_mode) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1199 | if (hostapd_prepare_rates(iface, iface->current_mode)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1200 | wpa_printf(MSG_ERROR, "Failed to prepare rates " |
| 1201 | "table."); |
| 1202 | hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211, |
| 1203 | HOSTAPD_LEVEL_WARNING, |
| 1204 | "Failed to prepare rates table."); |
Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 1205 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1206 | } |
| 1207 | } |
| 1208 | |
| 1209 | if (hapd->iconf->rts_threshold > -1 && |
| 1210 | hostapd_set_rts(hapd, hapd->iconf->rts_threshold)) { |
| 1211 | wpa_printf(MSG_ERROR, "Could not set RTS threshold for " |
| 1212 | "kernel driver"); |
Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 1213 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1214 | } |
| 1215 | |
| 1216 | if (hapd->iconf->fragm_threshold > -1 && |
| 1217 | hostapd_set_frag(hapd, hapd->iconf->fragm_threshold)) { |
| 1218 | wpa_printf(MSG_ERROR, "Could not set fragmentation threshold " |
| 1219 | "for kernel driver"); |
Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 1220 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1221 | } |
| 1222 | |
| 1223 | prev_addr = hapd->own_addr; |
| 1224 | |
| 1225 | for (j = 0; j < iface->num_bss; j++) { |
| 1226 | hapd = iface->bss[j]; |
| 1227 | if (j) |
| 1228 | os_memcpy(hapd->own_addr, prev_addr, ETH_ALEN); |
| 1229 | if (hostapd_setup_bss(hapd, j == 0)) |
Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 1230 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1231 | if (hostapd_mac_comp_empty(hapd->conf->bssid) == 0) |
| 1232 | prev_addr = hapd->own_addr; |
| 1233 | } |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1234 | hapd = iface->bss[0]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1235 | |
| 1236 | hostapd_tx_queue_params(iface); |
| 1237 | |
| 1238 | ap_list_init(iface); |
| 1239 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 1240 | hostapd_set_acl(hapd); |
| 1241 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1242 | if (hostapd_driver_commit(hapd) < 0) { |
| 1243 | wpa_printf(MSG_ERROR, "%s: Failed to commit driver " |
| 1244 | "configuration", __func__); |
Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 1245 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1246 | } |
| 1247 | |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1248 | /* |
| 1249 | * WPS UPnP module can be initialized only when the "upnp_iface" is up. |
| 1250 | * If "interface" and "upnp_iface" are the same (e.g., non-bridge |
| 1251 | * mode), the interface is up only after driver_commit, so initialize |
| 1252 | * WPS after driver_commit. |
| 1253 | */ |
| 1254 | for (j = 0; j < iface->num_bss; j++) { |
| 1255 | if (hostapd_init_wps_complete(iface->bss[j])) |
Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 1256 | goto fail; |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1257 | } |
| 1258 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1259 | hostapd_set_state(iface, HAPD_IFACE_ENABLED); |
| 1260 | wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO, AP_EVENT_ENABLED); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1261 | if (hapd->setup_complete_cb) |
| 1262 | hapd->setup_complete_cb(hapd->setup_complete_cb_ctx); |
| 1263 | |
| 1264 | wpa_printf(MSG_DEBUG, "%s: Setup of interface done.", |
| 1265 | iface->bss[0]->conf->iface); |
Dmitry Shmidt | b96dad4 | 2013-11-05 10:07:29 -0800 | [diff] [blame] | 1266 | if (iface->interfaces && iface->interfaces->terminate_on_error > 0) |
| 1267 | iface->interfaces->terminate_on_error--; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1268 | |
| 1269 | return 0; |
Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 1270 | |
| 1271 | fail: |
| 1272 | wpa_printf(MSG_ERROR, "Interface initialization failed"); |
| 1273 | hostapd_set_state(iface, HAPD_IFACE_DISABLED); |
| 1274 | wpa_msg(hapd->msg_ctx, MSG_INFO, AP_EVENT_DISABLED); |
| 1275 | if (iface->interfaces && iface->interfaces->terminate_on_error) |
| 1276 | eloop_terminate(); |
| 1277 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1278 | } |
| 1279 | |
| 1280 | |
| 1281 | /** |
| 1282 | * hostapd_setup_interface - Setup of an interface |
| 1283 | * @iface: Pointer to interface data. |
| 1284 | * Returns: 0 on success, -1 on failure |
| 1285 | * |
| 1286 | * Initializes the driver interface, validates the configuration, |
| 1287 | * and sets driver parameters based on the configuration. |
| 1288 | * Flushes old stations, sets the channel, encryption, |
| 1289 | * beacons, and WDS links based on the configuration. |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1290 | * |
| 1291 | * If interface setup requires more time, e.g., to perform HT co-ex scans, ACS, |
| 1292 | * or DFS operations, this function returns 0 before such operations have been |
| 1293 | * completed. The pending operations are registered into eloop and will be |
| 1294 | * completed from eloop callbacks. Those callbacks end up calling |
| 1295 | * hostapd_setup_interface_complete() once setup has been completed. |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1296 | */ |
| 1297 | int hostapd_setup_interface(struct hostapd_iface *iface) |
| 1298 | { |
| 1299 | int ret; |
| 1300 | |
| 1301 | ret = setup_interface(iface); |
| 1302 | if (ret) { |
| 1303 | wpa_printf(MSG_ERROR, "%s: Unable to setup interface.", |
| 1304 | iface->bss[0]->conf->iface); |
| 1305 | return -1; |
| 1306 | } |
| 1307 | |
| 1308 | return 0; |
| 1309 | } |
| 1310 | |
| 1311 | |
| 1312 | /** |
| 1313 | * hostapd_alloc_bss_data - Allocate and initialize per-BSS data |
| 1314 | * @hapd_iface: Pointer to interface data |
| 1315 | * @conf: Pointer to per-interface configuration |
| 1316 | * @bss: Pointer to per-BSS configuration for this BSS |
| 1317 | * Returns: Pointer to allocated BSS data |
| 1318 | * |
| 1319 | * This function is used to allocate per-BSS data structure. This data will be |
| 1320 | * freed after hostapd_cleanup() is called for it during interface |
| 1321 | * deinitialization. |
| 1322 | */ |
| 1323 | struct hostapd_data * |
| 1324 | hostapd_alloc_bss_data(struct hostapd_iface *hapd_iface, |
| 1325 | struct hostapd_config *conf, |
| 1326 | struct hostapd_bss_config *bss) |
| 1327 | { |
| 1328 | struct hostapd_data *hapd; |
| 1329 | |
| 1330 | hapd = os_zalloc(sizeof(*hapd)); |
| 1331 | if (hapd == NULL) |
| 1332 | return NULL; |
| 1333 | |
| 1334 | hapd->new_assoc_sta_cb = hostapd_new_assoc_sta; |
| 1335 | hapd->iconf = conf; |
| 1336 | hapd->conf = bss; |
| 1337 | hapd->iface = hapd_iface; |
| 1338 | hapd->driver = hapd->iconf->driver; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1339 | hapd->ctrl_sock = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1340 | |
| 1341 | return hapd; |
| 1342 | } |
| 1343 | |
| 1344 | |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 1345 | static void hostapd_bss_deinit(struct hostapd_data *hapd) |
| 1346 | { |
| 1347 | wpa_printf(MSG_DEBUG, "%s: deinit bss %s", __func__, |
| 1348 | hapd->conf->iface); |
| 1349 | hostapd_free_stas(hapd); |
| 1350 | hostapd_flush_old_stations(hapd, WLAN_REASON_DEAUTH_LEAVING); |
| 1351 | hostapd_clear_wep(hapd); |
| 1352 | hostapd_cleanup(hapd); |
| 1353 | } |
| 1354 | |
| 1355 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1356 | void hostapd_interface_deinit(struct hostapd_iface *iface) |
| 1357 | { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1358 | int j; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1359 | |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 1360 | wpa_printf(MSG_DEBUG, "%s(%p)", __func__, iface); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1361 | if (iface == NULL) |
| 1362 | return; |
| 1363 | |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 1364 | #ifdef CONFIG_IEEE80211N |
| 1365 | #ifdef NEED_AP_MLME |
| 1366 | hostapd_stop_setup_timers(iface); |
| 1367 | eloop_cancel_timeout(ap_ht2040_timeout, iface, NULL); |
| 1368 | #endif /* NEED_AP_MLME */ |
| 1369 | #endif /* CONFIG_IEEE80211N */ |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1370 | eloop_cancel_timeout(channel_list_update_timeout, iface, NULL); |
| 1371 | iface->wait_channel_update = 0; |
| 1372 | |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 1373 | for (j = iface->num_bss - 1; j >= 0; j--) |
| 1374 | hostapd_bss_deinit(iface->bss[j]); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1375 | } |
| 1376 | |
| 1377 | |
| 1378 | void hostapd_interface_free(struct hostapd_iface *iface) |
| 1379 | { |
| 1380 | size_t j; |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 1381 | wpa_printf(MSG_DEBUG, "%s(%p)", __func__, iface); |
| 1382 | for (j = 0; j < iface->num_bss; j++) { |
| 1383 | wpa_printf(MSG_DEBUG, "%s: free hapd %p", |
| 1384 | __func__, iface->bss[j]); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1385 | os_free(iface->bss[j]); |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 1386 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1387 | hostapd_cleanup_iface(iface); |
| 1388 | } |
| 1389 | |
| 1390 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1391 | /** |
| 1392 | * hostapd_init - Allocate and initialize per-interface data |
| 1393 | * @config_file: Path to the configuration file |
| 1394 | * Returns: Pointer to the allocated interface data or %NULL on failure |
| 1395 | * |
| 1396 | * This function is used to allocate main data structures for per-interface |
| 1397 | * data. The allocated data buffer will be freed by calling |
| 1398 | * hostapd_cleanup_iface(). |
| 1399 | */ |
| 1400 | struct hostapd_iface * hostapd_init(struct hapd_interfaces *interfaces, |
| 1401 | const char *config_file) |
| 1402 | { |
| 1403 | struct hostapd_iface *hapd_iface = NULL; |
| 1404 | struct hostapd_config *conf = NULL; |
| 1405 | struct hostapd_data *hapd; |
| 1406 | size_t i; |
| 1407 | |
| 1408 | hapd_iface = os_zalloc(sizeof(*hapd_iface)); |
| 1409 | if (hapd_iface == NULL) |
| 1410 | goto fail; |
| 1411 | |
| 1412 | hapd_iface->config_fname = os_strdup(config_file); |
| 1413 | if (hapd_iface->config_fname == NULL) |
| 1414 | goto fail; |
| 1415 | |
| 1416 | conf = interfaces->config_read_cb(hapd_iface->config_fname); |
| 1417 | if (conf == NULL) |
| 1418 | goto fail; |
| 1419 | hapd_iface->conf = conf; |
| 1420 | |
| 1421 | hapd_iface->num_bss = conf->num_bss; |
| 1422 | hapd_iface->bss = os_calloc(conf->num_bss, |
| 1423 | sizeof(struct hostapd_data *)); |
| 1424 | if (hapd_iface->bss == NULL) |
| 1425 | goto fail; |
| 1426 | |
| 1427 | for (i = 0; i < conf->num_bss; i++) { |
| 1428 | hapd = hapd_iface->bss[i] = |
| 1429 | hostapd_alloc_bss_data(hapd_iface, conf, |
| 1430 | conf->bss[i]); |
| 1431 | if (hapd == NULL) |
| 1432 | goto fail; |
| 1433 | hapd->msg_ctx = hapd; |
| 1434 | } |
| 1435 | |
| 1436 | return hapd_iface; |
| 1437 | |
| 1438 | fail: |
| 1439 | wpa_printf(MSG_ERROR, "Failed to set up interface with %s", |
| 1440 | config_file); |
| 1441 | if (conf) |
| 1442 | hostapd_config_free(conf); |
| 1443 | if (hapd_iface) { |
| 1444 | os_free(hapd_iface->config_fname); |
| 1445 | os_free(hapd_iface->bss); |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 1446 | wpa_printf(MSG_DEBUG, "%s: free iface %p", |
| 1447 | __func__, hapd_iface); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1448 | os_free(hapd_iface); |
| 1449 | } |
| 1450 | return NULL; |
| 1451 | } |
| 1452 | |
| 1453 | |
| 1454 | static int ifname_in_use(struct hapd_interfaces *interfaces, const char *ifname) |
| 1455 | { |
| 1456 | size_t i, j; |
| 1457 | |
| 1458 | for (i = 0; i < interfaces->count; i++) { |
| 1459 | struct hostapd_iface *iface = interfaces->iface[i]; |
| 1460 | for (j = 0; j < iface->num_bss; j++) { |
| 1461 | struct hostapd_data *hapd = iface->bss[j]; |
| 1462 | if (os_strcmp(ifname, hapd->conf->iface) == 0) |
| 1463 | return 1; |
| 1464 | } |
| 1465 | } |
| 1466 | |
| 1467 | return 0; |
| 1468 | } |
| 1469 | |
| 1470 | |
| 1471 | /** |
| 1472 | * hostapd_interface_init_bss - Read configuration file and init BSS data |
| 1473 | * |
| 1474 | * This function is used to parse configuration file for a BSS. This BSS is |
| 1475 | * added to an existing interface sharing the same radio (if any) or a new |
| 1476 | * interface is created if this is the first interface on a radio. This |
| 1477 | * allocate memory for the BSS. No actual driver operations are started. |
| 1478 | * |
| 1479 | * This is similar to hostapd_interface_init(), but for a case where the |
| 1480 | * configuration is used to add a single BSS instead of all BSSes for a radio. |
| 1481 | */ |
| 1482 | struct hostapd_iface * |
| 1483 | hostapd_interface_init_bss(struct hapd_interfaces *interfaces, const char *phy, |
| 1484 | const char *config_fname, int debug) |
| 1485 | { |
| 1486 | struct hostapd_iface *new_iface = NULL, *iface = NULL; |
| 1487 | struct hostapd_data *hapd; |
| 1488 | int k; |
| 1489 | size_t i, bss_idx; |
| 1490 | |
| 1491 | if (!phy || !*phy) |
| 1492 | return NULL; |
| 1493 | |
| 1494 | for (i = 0; i < interfaces->count; i++) { |
| 1495 | if (os_strcmp(interfaces->iface[i]->phy, phy) == 0) { |
| 1496 | iface = interfaces->iface[i]; |
| 1497 | break; |
| 1498 | } |
| 1499 | } |
| 1500 | |
| 1501 | wpa_printf(MSG_INFO, "Configuration file: %s (phy %s)%s", |
| 1502 | config_fname, phy, iface ? "" : " --> new PHY"); |
| 1503 | if (iface) { |
| 1504 | struct hostapd_config *conf; |
| 1505 | struct hostapd_bss_config **tmp_conf; |
| 1506 | struct hostapd_data **tmp_bss; |
| 1507 | struct hostapd_bss_config *bss; |
| 1508 | const char *ifname; |
| 1509 | |
| 1510 | /* Add new BSS to existing iface */ |
| 1511 | conf = interfaces->config_read_cb(config_fname); |
| 1512 | if (conf == NULL) |
| 1513 | return NULL; |
| 1514 | if (conf->num_bss > 1) { |
| 1515 | wpa_printf(MSG_ERROR, "Multiple BSSes specified in BSS-config"); |
| 1516 | hostapd_config_free(conf); |
| 1517 | return NULL; |
| 1518 | } |
| 1519 | |
| 1520 | ifname = conf->bss[0]->iface; |
| 1521 | if (ifname[0] != '\0' && ifname_in_use(interfaces, ifname)) { |
| 1522 | wpa_printf(MSG_ERROR, |
| 1523 | "Interface name %s already in use", ifname); |
| 1524 | hostapd_config_free(conf); |
| 1525 | return NULL; |
| 1526 | } |
| 1527 | |
| 1528 | tmp_conf = os_realloc_array( |
| 1529 | iface->conf->bss, iface->conf->num_bss + 1, |
| 1530 | sizeof(struct hostapd_bss_config *)); |
| 1531 | tmp_bss = os_realloc_array(iface->bss, iface->num_bss + 1, |
| 1532 | sizeof(struct hostapd_data *)); |
| 1533 | if (tmp_bss) |
| 1534 | iface->bss = tmp_bss; |
| 1535 | if (tmp_conf) { |
| 1536 | iface->conf->bss = tmp_conf; |
| 1537 | iface->conf->last_bss = tmp_conf[0]; |
| 1538 | } |
| 1539 | if (tmp_bss == NULL || tmp_conf == NULL) { |
| 1540 | hostapd_config_free(conf); |
| 1541 | return NULL; |
| 1542 | } |
| 1543 | bss = iface->conf->bss[iface->conf->num_bss] = conf->bss[0]; |
| 1544 | iface->conf->num_bss++; |
| 1545 | |
| 1546 | hapd = hostapd_alloc_bss_data(iface, iface->conf, bss); |
| 1547 | if (hapd == NULL) { |
| 1548 | iface->conf->num_bss--; |
| 1549 | hostapd_config_free(conf); |
| 1550 | return NULL; |
| 1551 | } |
| 1552 | iface->conf->last_bss = bss; |
| 1553 | iface->bss[iface->num_bss] = hapd; |
| 1554 | hapd->msg_ctx = hapd; |
| 1555 | |
| 1556 | bss_idx = iface->num_bss++; |
| 1557 | conf->num_bss--; |
| 1558 | conf->bss[0] = NULL; |
| 1559 | hostapd_config_free(conf); |
| 1560 | } else { |
| 1561 | /* Add a new iface with the first BSS */ |
| 1562 | new_iface = iface = hostapd_init(interfaces, config_fname); |
| 1563 | if (!iface) |
| 1564 | return NULL; |
| 1565 | os_strlcpy(iface->phy, phy, sizeof(iface->phy)); |
| 1566 | iface->interfaces = interfaces; |
| 1567 | bss_idx = 0; |
| 1568 | } |
| 1569 | |
| 1570 | for (k = 0; k < debug; k++) { |
| 1571 | if (iface->bss[bss_idx]->conf->logger_stdout_level > 0) |
| 1572 | iface->bss[bss_idx]->conf->logger_stdout_level--; |
| 1573 | } |
| 1574 | |
| 1575 | if (iface->conf->bss[bss_idx]->iface[0] == '\0' && |
| 1576 | !hostapd_drv_none(iface->bss[bss_idx])) { |
| 1577 | wpa_printf(MSG_ERROR, "Interface name not specified in %s", |
| 1578 | config_fname); |
| 1579 | if (new_iface) |
| 1580 | hostapd_interface_deinit_free(new_iface); |
| 1581 | return NULL; |
| 1582 | } |
| 1583 | |
| 1584 | return iface; |
| 1585 | } |
| 1586 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1587 | |
| 1588 | void hostapd_interface_deinit_free(struct hostapd_iface *iface) |
| 1589 | { |
| 1590 | const struct wpa_driver_ops *driver; |
| 1591 | void *drv_priv; |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 1592 | |
| 1593 | wpa_printf(MSG_DEBUG, "%s(%p)", __func__, iface); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1594 | if (iface == NULL) |
| 1595 | return; |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 1596 | wpa_printf(MSG_DEBUG, "%s: num_bss=%u conf->num_bss=%u", |
| 1597 | __func__, (unsigned int) iface->num_bss, |
| 1598 | (unsigned int) iface->conf->num_bss); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1599 | driver = iface->bss[0]->driver; |
| 1600 | drv_priv = iface->bss[0]->drv_priv; |
| 1601 | hostapd_interface_deinit(iface); |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 1602 | wpa_printf(MSG_DEBUG, "%s: driver=%p drv_priv=%p -> hapd_deinit", |
| 1603 | __func__, driver, drv_priv); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1604 | if (driver && driver->hapd_deinit && drv_priv) |
| 1605 | driver->hapd_deinit(drv_priv); |
| 1606 | hostapd_interface_free(iface); |
| 1607 | } |
| 1608 | |
| 1609 | |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 1610 | static void hostapd_deinit_driver(const struct wpa_driver_ops *driver, |
| 1611 | void *drv_priv, |
| 1612 | struct hostapd_iface *hapd_iface) |
| 1613 | { |
| 1614 | size_t j; |
| 1615 | |
| 1616 | wpa_printf(MSG_DEBUG, "%s: driver=%p drv_priv=%p -> hapd_deinit", |
| 1617 | __func__, driver, drv_priv); |
| 1618 | if (driver && driver->hapd_deinit && drv_priv) { |
| 1619 | driver->hapd_deinit(drv_priv); |
| 1620 | for (j = 0; j < hapd_iface->num_bss; j++) { |
| 1621 | wpa_printf(MSG_DEBUG, "%s:bss[%d]->drv_priv=%p", |
| 1622 | __func__, (int) j, |
| 1623 | hapd_iface->bss[j]->drv_priv); |
| 1624 | if (hapd_iface->bss[j]->drv_priv == drv_priv) |
| 1625 | hapd_iface->bss[j]->drv_priv = NULL; |
| 1626 | } |
| 1627 | } |
| 1628 | } |
| 1629 | |
| 1630 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1631 | int hostapd_enable_iface(struct hostapd_iface *hapd_iface) |
| 1632 | { |
| 1633 | if (hapd_iface->bss[0]->drv_priv != NULL) { |
| 1634 | wpa_printf(MSG_ERROR, "Interface %s already enabled", |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1635 | hapd_iface->conf->bss[0]->iface); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1636 | return -1; |
| 1637 | } |
| 1638 | |
| 1639 | wpa_printf(MSG_DEBUG, "Enable interface %s", |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1640 | hapd_iface->conf->bss[0]->iface); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1641 | |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 1642 | if (hostapd_config_check(hapd_iface->conf, 1) < 0) { |
| 1643 | wpa_printf(MSG_INFO, "Invalid configuration - cannot enable"); |
| 1644 | return -1; |
| 1645 | } |
| 1646 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1647 | if (hapd_iface->interfaces == NULL || |
| 1648 | hapd_iface->interfaces->driver_init == NULL || |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1649 | hapd_iface->interfaces->driver_init(hapd_iface)) |
| 1650 | return -1; |
| 1651 | |
| 1652 | if (hostapd_setup_interface(hapd_iface)) { |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 1653 | hostapd_deinit_driver(hapd_iface->bss[0]->driver, |
| 1654 | hapd_iface->bss[0]->drv_priv, |
| 1655 | hapd_iface); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1656 | return -1; |
| 1657 | } |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1658 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1659 | return 0; |
| 1660 | } |
| 1661 | |
| 1662 | |
| 1663 | int hostapd_reload_iface(struct hostapd_iface *hapd_iface) |
| 1664 | { |
| 1665 | size_t j; |
| 1666 | |
| 1667 | wpa_printf(MSG_DEBUG, "Reload interface %s", |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1668 | hapd_iface->conf->bss[0]->iface); |
| 1669 | for (j = 0; j < hapd_iface->num_bss; j++) |
| 1670 | hostapd_set_security_params(hapd_iface->conf->bss[j]); |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 1671 | if (hostapd_config_check(hapd_iface->conf, 1) < 0) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1672 | wpa_printf(MSG_ERROR, "Updated configuration is invalid"); |
| 1673 | return -1; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1674 | } |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1675 | hostapd_clear_old(hapd_iface); |
| 1676 | for (j = 0; j < hapd_iface->num_bss; j++) |
| 1677 | hostapd_reload_bss(hapd_iface->bss[j]); |
| 1678 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1679 | return 0; |
| 1680 | } |
| 1681 | |
| 1682 | |
| 1683 | int hostapd_disable_iface(struct hostapd_iface *hapd_iface) |
| 1684 | { |
| 1685 | size_t j; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1686 | const struct wpa_driver_ops *driver; |
| 1687 | void *drv_priv; |
| 1688 | |
| 1689 | if (hapd_iface == NULL) |
| 1690 | return -1; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1691 | 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] | 1692 | driver = hapd_iface->bss[0]->driver; |
| 1693 | drv_priv = hapd_iface->bss[0]->drv_priv; |
| 1694 | |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 1695 | hapd_iface->driver_ap_teardown = |
| 1696 | !!(hapd_iface->drv_flags & |
| 1697 | WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT); |
| 1698 | |
| 1699 | /* same as hostapd_interface_deinit without deinitializing ctrl-iface */ |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1700 | for (j = 0; j < hapd_iface->num_bss; j++) { |
| 1701 | struct hostapd_data *hapd = hapd_iface->bss[j]; |
| 1702 | hostapd_free_stas(hapd); |
| 1703 | hostapd_flush_old_stations(hapd, WLAN_REASON_DEAUTH_LEAVING); |
| 1704 | hostapd_clear_wep(hapd); |
| 1705 | hostapd_free_hapd_data(hapd); |
| 1706 | } |
| 1707 | |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 1708 | hostapd_deinit_driver(driver, drv_priv, hapd_iface); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1709 | |
| 1710 | /* From hostapd_cleanup_iface: These were initialized in |
| 1711 | * hostapd_setup_interface and hostapd_setup_interface_complete |
| 1712 | */ |
| 1713 | hostapd_cleanup_iface_partial(hapd_iface); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1714 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 1715 | wpa_printf(MSG_DEBUG, "Interface %s disabled", |
| 1716 | hapd_iface->bss[0]->conf->iface); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1717 | hostapd_set_state(hapd_iface, HAPD_IFACE_DISABLED); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1718 | return 0; |
| 1719 | } |
| 1720 | |
| 1721 | |
| 1722 | static struct hostapd_iface * |
| 1723 | hostapd_iface_alloc(struct hapd_interfaces *interfaces) |
| 1724 | { |
| 1725 | struct hostapd_iface **iface, *hapd_iface; |
| 1726 | |
| 1727 | iface = os_realloc_array(interfaces->iface, interfaces->count + 1, |
| 1728 | sizeof(struct hostapd_iface *)); |
| 1729 | if (iface == NULL) |
| 1730 | return NULL; |
| 1731 | interfaces->iface = iface; |
| 1732 | hapd_iface = interfaces->iface[interfaces->count] = |
| 1733 | os_zalloc(sizeof(*hapd_iface)); |
| 1734 | if (hapd_iface == NULL) { |
| 1735 | wpa_printf(MSG_ERROR, "%s: Failed to allocate memory for " |
| 1736 | "the interface", __func__); |
| 1737 | return NULL; |
| 1738 | } |
| 1739 | interfaces->count++; |
| 1740 | hapd_iface->interfaces = interfaces; |
| 1741 | |
| 1742 | return hapd_iface; |
| 1743 | } |
| 1744 | |
| 1745 | |
| 1746 | static struct hostapd_config * |
| 1747 | hostapd_config_alloc(struct hapd_interfaces *interfaces, const char *ifname, |
| 1748 | const char *ctrl_iface) |
| 1749 | { |
| 1750 | struct hostapd_bss_config *bss; |
| 1751 | struct hostapd_config *conf; |
| 1752 | |
| 1753 | /* Allocates memory for bss and conf */ |
| 1754 | conf = hostapd_config_defaults(); |
| 1755 | if (conf == NULL) { |
| 1756 | wpa_printf(MSG_ERROR, "%s: Failed to allocate memory for " |
| 1757 | "configuration", __func__); |
| 1758 | return NULL; |
| 1759 | } |
| 1760 | |
| 1761 | conf->driver = wpa_drivers[0]; |
| 1762 | if (conf->driver == NULL) { |
| 1763 | wpa_printf(MSG_ERROR, "No driver wrappers registered!"); |
| 1764 | hostapd_config_free(conf); |
| 1765 | return NULL; |
| 1766 | } |
| 1767 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1768 | bss = conf->last_bss = conf->bss[0]; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1769 | |
| 1770 | os_strlcpy(bss->iface, ifname, sizeof(bss->iface)); |
| 1771 | bss->ctrl_interface = os_strdup(ctrl_iface); |
| 1772 | if (bss->ctrl_interface == NULL) { |
| 1773 | hostapd_config_free(conf); |
| 1774 | return NULL; |
| 1775 | } |
| 1776 | |
| 1777 | /* Reading configuration file skipped, will be done in SET! |
| 1778 | * From reading the configuration till the end has to be done in |
| 1779 | * SET |
| 1780 | */ |
| 1781 | return conf; |
| 1782 | } |
| 1783 | |
| 1784 | |
| 1785 | static struct hostapd_iface * hostapd_data_alloc( |
| 1786 | struct hapd_interfaces *interfaces, struct hostapd_config *conf) |
| 1787 | { |
| 1788 | size_t i; |
| 1789 | struct hostapd_iface *hapd_iface = |
| 1790 | interfaces->iface[interfaces->count - 1]; |
| 1791 | struct hostapd_data *hapd; |
| 1792 | |
| 1793 | hapd_iface->conf = conf; |
| 1794 | hapd_iface->num_bss = conf->num_bss; |
| 1795 | |
| 1796 | hapd_iface->bss = os_zalloc(conf->num_bss * |
| 1797 | sizeof(struct hostapd_data *)); |
| 1798 | if (hapd_iface->bss == NULL) |
| 1799 | return NULL; |
| 1800 | |
| 1801 | for (i = 0; i < conf->num_bss; i++) { |
| 1802 | hapd = hapd_iface->bss[i] = |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1803 | hostapd_alloc_bss_data(hapd_iface, conf, conf->bss[i]); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1804 | if (hapd == NULL) |
| 1805 | return NULL; |
| 1806 | hapd->msg_ctx = hapd; |
| 1807 | } |
| 1808 | |
| 1809 | hapd_iface->interfaces = interfaces; |
| 1810 | |
| 1811 | return hapd_iface; |
| 1812 | } |
| 1813 | |
| 1814 | |
| 1815 | int hostapd_add_iface(struct hapd_interfaces *interfaces, char *buf) |
| 1816 | { |
| 1817 | struct hostapd_config *conf = NULL; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1818 | struct hostapd_iface *hapd_iface = NULL, *new_iface = NULL; |
| 1819 | struct hostapd_data *hapd; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1820 | char *ptr; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1821 | size_t i, j; |
| 1822 | const char *conf_file = NULL, *phy_name = NULL; |
| 1823 | |
| 1824 | if (os_strncmp(buf, "bss_config=", 11) == 0) { |
| 1825 | char *pos; |
| 1826 | phy_name = buf + 11; |
| 1827 | pos = os_strchr(phy_name, ':'); |
| 1828 | if (!pos) |
| 1829 | return -1; |
| 1830 | *pos++ = '\0'; |
| 1831 | conf_file = pos; |
| 1832 | if (!os_strlen(conf_file)) |
| 1833 | return -1; |
| 1834 | |
| 1835 | hapd_iface = hostapd_interface_init_bss(interfaces, phy_name, |
| 1836 | conf_file, 0); |
| 1837 | if (!hapd_iface) |
| 1838 | return -1; |
| 1839 | for (j = 0; j < interfaces->count; j++) { |
| 1840 | if (interfaces->iface[j] == hapd_iface) |
| 1841 | break; |
| 1842 | } |
| 1843 | if (j == interfaces->count) { |
| 1844 | struct hostapd_iface **tmp; |
| 1845 | tmp = os_realloc_array(interfaces->iface, |
| 1846 | interfaces->count + 1, |
| 1847 | sizeof(struct hostapd_iface *)); |
| 1848 | if (!tmp) { |
| 1849 | hostapd_interface_deinit_free(hapd_iface); |
| 1850 | return -1; |
| 1851 | } |
| 1852 | interfaces->iface = tmp; |
| 1853 | interfaces->iface[interfaces->count++] = hapd_iface; |
| 1854 | new_iface = hapd_iface; |
| 1855 | } |
| 1856 | |
| 1857 | if (new_iface) { |
| 1858 | if (interfaces->driver_init(hapd_iface) || |
| 1859 | hostapd_setup_interface(hapd_iface)) { |
| 1860 | interfaces->count--; |
| 1861 | goto fail; |
| 1862 | } |
| 1863 | } else { |
| 1864 | /* Assign new BSS with bss[0]'s driver info */ |
| 1865 | hapd = hapd_iface->bss[hapd_iface->num_bss - 1]; |
| 1866 | hapd->driver = hapd_iface->bss[0]->driver; |
| 1867 | hapd->drv_priv = hapd_iface->bss[0]->drv_priv; |
| 1868 | os_memcpy(hapd->own_addr, hapd_iface->bss[0]->own_addr, |
| 1869 | ETH_ALEN); |
| 1870 | |
| 1871 | if (start_ctrl_iface_bss(hapd) < 0 || |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 1872 | (hapd_iface->state == HAPD_IFACE_ENABLED && |
| 1873 | hostapd_setup_bss(hapd, -1))) { |
Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 1874 | hostapd_cleanup(hapd); |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 1875 | hapd_iface->bss[hapd_iface->num_bss - 1] = NULL; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1876 | hapd_iface->conf->num_bss--; |
| 1877 | hapd_iface->num_bss--; |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 1878 | wpa_printf(MSG_DEBUG, "%s: free hapd %p %s", |
| 1879 | __func__, hapd, hapd->conf->iface); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1880 | os_free(hapd); |
| 1881 | return -1; |
| 1882 | } |
| 1883 | } |
| 1884 | return 0; |
| 1885 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1886 | |
| 1887 | ptr = os_strchr(buf, ' '); |
| 1888 | if (ptr == NULL) |
| 1889 | return -1; |
| 1890 | *ptr++ = '\0'; |
| 1891 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 1892 | if (os_strncmp(ptr, "config=", 7) == 0) |
| 1893 | conf_file = ptr + 7; |
| 1894 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1895 | for (i = 0; i < interfaces->count; i++) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1896 | if (!os_strcmp(interfaces->iface[i]->conf->bss[0]->iface, |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1897 | buf)) { |
| 1898 | wpa_printf(MSG_INFO, "Cannot add interface - it " |
| 1899 | "already exists"); |
| 1900 | return -1; |
| 1901 | } |
| 1902 | } |
| 1903 | |
| 1904 | hapd_iface = hostapd_iface_alloc(interfaces); |
| 1905 | if (hapd_iface == NULL) { |
| 1906 | wpa_printf(MSG_ERROR, "%s: Failed to allocate memory " |
| 1907 | "for interface", __func__); |
| 1908 | goto fail; |
| 1909 | } |
| 1910 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 1911 | if (conf_file && interfaces->config_read_cb) { |
| 1912 | conf = interfaces->config_read_cb(conf_file); |
| 1913 | if (conf && conf->bss) |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1914 | os_strlcpy(conf->bss[0]->iface, buf, |
| 1915 | sizeof(conf->bss[0]->iface)); |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 1916 | } else |
| 1917 | conf = hostapd_config_alloc(interfaces, buf, ptr); |
| 1918 | if (conf == NULL || conf->bss == NULL) { |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1919 | wpa_printf(MSG_ERROR, "%s: Failed to allocate memory " |
| 1920 | "for configuration", __func__); |
| 1921 | goto fail; |
| 1922 | } |
| 1923 | |
| 1924 | hapd_iface = hostapd_data_alloc(interfaces, conf); |
| 1925 | if (hapd_iface == NULL) { |
| 1926 | wpa_printf(MSG_ERROR, "%s: Failed to allocate memory " |
| 1927 | "for hostapd", __func__); |
| 1928 | goto fail; |
| 1929 | } |
| 1930 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1931 | if (start_ctrl_iface(hapd_iface) < 0) |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1932 | goto fail; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1933 | |
| 1934 | wpa_printf(MSG_INFO, "Add interface '%s'", conf->bss[0]->iface); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1935 | |
| 1936 | return 0; |
| 1937 | |
| 1938 | fail: |
| 1939 | if (conf) |
| 1940 | hostapd_config_free(conf); |
| 1941 | if (hapd_iface) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1942 | if (hapd_iface->bss) { |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 1943 | for (i = 0; i < hapd_iface->num_bss; i++) { |
| 1944 | hapd = hapd_iface->bss[i]; |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 1945 | if (!hapd) |
| 1946 | continue; |
| 1947 | if (hapd_iface->interfaces && |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 1948 | hapd_iface->interfaces->ctrl_iface_deinit) |
| 1949 | hapd_iface->interfaces-> |
| 1950 | ctrl_iface_deinit(hapd); |
| 1951 | wpa_printf(MSG_DEBUG, "%s: free hapd %p (%s)", |
| 1952 | __func__, hapd_iface->bss[i], |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 1953 | hapd->conf->iface); |
| 1954 | os_free(hapd); |
| 1955 | hapd_iface->bss[i] = NULL; |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 1956 | } |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1957 | os_free(hapd_iface->bss); |
| 1958 | } |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 1959 | wpa_printf(MSG_DEBUG, "%s: free iface %p", |
| 1960 | __func__, hapd_iface); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1961 | os_free(hapd_iface); |
| 1962 | } |
| 1963 | return -1; |
| 1964 | } |
| 1965 | |
| 1966 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1967 | static int hostapd_remove_bss(struct hostapd_iface *iface, unsigned int idx) |
| 1968 | { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1969 | size_t i; |
| 1970 | |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 1971 | wpa_printf(MSG_INFO, "Remove BSS '%s'", iface->conf->bss[idx]->iface); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1972 | |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 1973 | /* Remove hostapd_data only if it has already been initialized */ |
| 1974 | if (idx < iface->num_bss) { |
| 1975 | struct hostapd_data *hapd = iface->bss[idx]; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1976 | |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 1977 | hostapd_bss_deinit(hapd); |
| 1978 | wpa_printf(MSG_DEBUG, "%s: free hapd %p (%s)", |
| 1979 | __func__, hapd, hapd->conf->iface); |
| 1980 | hostapd_config_free_bss(hapd->conf); |
| 1981 | os_free(hapd); |
| 1982 | |
| 1983 | iface->num_bss--; |
| 1984 | |
| 1985 | for (i = idx; i < iface->num_bss; i++) |
| 1986 | iface->bss[i] = iface->bss[i + 1]; |
| 1987 | } else { |
| 1988 | hostapd_config_free_bss(iface->conf->bss[idx]); |
| 1989 | iface->conf->bss[idx] = NULL; |
| 1990 | } |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1991 | |
| 1992 | iface->conf->num_bss--; |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 1993 | for (i = idx; i < iface->conf->num_bss; i++) |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1994 | iface->conf->bss[i] = iface->conf->bss[i + 1]; |
| 1995 | |
| 1996 | return 0; |
| 1997 | } |
| 1998 | |
| 1999 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2000 | int hostapd_remove_iface(struct hapd_interfaces *interfaces, char *buf) |
| 2001 | { |
| 2002 | struct hostapd_iface *hapd_iface; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2003 | size_t i, j, k = 0; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2004 | |
| 2005 | for (i = 0; i < interfaces->count; i++) { |
| 2006 | hapd_iface = interfaces->iface[i]; |
| 2007 | if (hapd_iface == NULL) |
| 2008 | return -1; |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 2009 | if (!os_strcmp(hapd_iface->conf->bss[0]->iface, buf)) { |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2010 | wpa_printf(MSG_INFO, "Remove interface '%s'", buf); |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 2011 | hapd_iface->driver_ap_teardown = |
| 2012 | !!(hapd_iface->drv_flags & |
| 2013 | WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT); |
| 2014 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2015 | hostapd_interface_deinit_free(hapd_iface); |
| 2016 | k = i; |
| 2017 | while (k < (interfaces->count - 1)) { |
| 2018 | interfaces->iface[k] = |
| 2019 | interfaces->iface[k + 1]; |
| 2020 | k++; |
| 2021 | } |
| 2022 | interfaces->count--; |
| 2023 | return 0; |
| 2024 | } |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2025 | |
| 2026 | for (j = 0; j < hapd_iface->conf->num_bss; j++) { |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 2027 | if (!os_strcmp(hapd_iface->conf->bss[j]->iface, buf)) { |
| 2028 | hapd_iface->driver_ap_teardown = |
| 2029 | !(hapd_iface->drv_flags & |
| 2030 | WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2031 | return hostapd_remove_bss(hapd_iface, j); |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 2032 | } |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2033 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2034 | } |
| 2035 | return -1; |
| 2036 | } |
| 2037 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2038 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2039 | /** |
| 2040 | * hostapd_new_assoc_sta - Notify that a new station associated with the AP |
| 2041 | * @hapd: Pointer to BSS data |
| 2042 | * @sta: Pointer to the associated STA data |
| 2043 | * @reassoc: 1 to indicate this was a re-association; 0 = first association |
| 2044 | * |
| 2045 | * This function will be called whenever a station associates with the AP. It |
| 2046 | * can be called from ieee802_11.c for drivers that export MLME to hostapd and |
| 2047 | * from drv_callbacks.c based on driver events for drivers that take care of |
| 2048 | * management frames (IEEE 802.11 authentication and association) internally. |
| 2049 | */ |
| 2050 | void hostapd_new_assoc_sta(struct hostapd_data *hapd, struct sta_info *sta, |
| 2051 | int reassoc) |
| 2052 | { |
| 2053 | if (hapd->tkip_countermeasures) { |
| 2054 | hostapd_drv_sta_deauth(hapd, sta->addr, |
| 2055 | WLAN_REASON_MICHAEL_MIC_FAILURE); |
| 2056 | return; |
| 2057 | } |
| 2058 | |
| 2059 | hostapd_prune_associations(hapd, sta->addr); |
| 2060 | |
| 2061 | /* IEEE 802.11F (IAPP) */ |
| 2062 | if (hapd->conf->ieee802_11f) |
| 2063 | iapp_new_station(hapd->iapp, sta); |
| 2064 | |
| 2065 | #ifdef CONFIG_P2P |
| 2066 | if (sta->p2p_ie == NULL && !sta->no_p2p_set) { |
| 2067 | sta->no_p2p_set = 1; |
| 2068 | hapd->num_sta_no_p2p++; |
| 2069 | if (hapd->num_sta_no_p2p == 1) |
| 2070 | hostapd_p2p_non_p2p_sta_connected(hapd); |
| 2071 | } |
| 2072 | #endif /* CONFIG_P2P */ |
| 2073 | |
| 2074 | /* Start accounting here, if IEEE 802.1X and WPA are not used. |
| 2075 | * IEEE 802.1X/WPA code will start accounting after the station has |
| 2076 | * been authorized. */ |
Dmitry Shmidt | 2ac5f60 | 2014-03-07 10:08:21 -0800 | [diff] [blame] | 2077 | if (!hapd->conf->ieee802_1x && !hapd->conf->wpa && !hapd->conf->osen) { |
| 2078 | ap_sta_set_authorized(hapd, sta, 1); |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 2079 | os_get_reltime(&sta->connected_time); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2080 | accounting_sta_start(hapd, sta); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2081 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2082 | |
| 2083 | /* Start IEEE 802.1X authentication process for new stations */ |
| 2084 | ieee802_1x_new_station(hapd, sta); |
| 2085 | if (reassoc) { |
| 2086 | if (sta->auth_alg != WLAN_AUTH_FT && |
| 2087 | !(sta->flags & (WLAN_STA_WPS | WLAN_STA_MAYBE_WPS))) |
| 2088 | wpa_auth_sm_event(sta->wpa_sm, WPA_REAUTH); |
| 2089 | } else |
| 2090 | wpa_auth_sta_associated(hapd->wpa_auth, sta->wpa_sm); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2091 | |
Dmitry Shmidt | 01904cf | 2013-12-05 11:08:35 -0800 | [diff] [blame] | 2092 | if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_INACTIVITY_TIMER)) { |
| 2093 | wpa_printf(MSG_DEBUG, "%s: reschedule ap_handle_timer timeout " |
| 2094 | "for " MACSTR " (%d seconds - ap_max_inactivity)", |
| 2095 | __func__, MAC2STR(sta->addr), |
| 2096 | hapd->conf->ap_max_inactivity); |
| 2097 | eloop_cancel_timeout(ap_handle_timer, hapd, sta); |
| 2098 | eloop_register_timeout(hapd->conf->ap_max_inactivity, 0, |
| 2099 | ap_handle_timer, hapd, sta); |
| 2100 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2101 | } |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2102 | |
| 2103 | |
| 2104 | const char * hostapd_state_text(enum hostapd_iface_state s) |
| 2105 | { |
| 2106 | switch (s) { |
| 2107 | case HAPD_IFACE_UNINITIALIZED: |
| 2108 | return "UNINITIALIZED"; |
| 2109 | case HAPD_IFACE_DISABLED: |
| 2110 | return "DISABLED"; |
| 2111 | case HAPD_IFACE_COUNTRY_UPDATE: |
| 2112 | return "COUNTRY_UPDATE"; |
| 2113 | case HAPD_IFACE_ACS: |
| 2114 | return "ACS"; |
| 2115 | case HAPD_IFACE_HT_SCAN: |
| 2116 | return "HT_SCAN"; |
| 2117 | case HAPD_IFACE_DFS: |
| 2118 | return "DFS"; |
| 2119 | case HAPD_IFACE_ENABLED: |
| 2120 | return "ENABLED"; |
| 2121 | } |
| 2122 | |
| 2123 | return "UNKNOWN"; |
| 2124 | } |
| 2125 | |
| 2126 | |
| 2127 | void hostapd_set_state(struct hostapd_iface *iface, enum hostapd_iface_state s) |
| 2128 | { |
| 2129 | wpa_printf(MSG_INFO, "%s: interface state %s->%s", |
| 2130 | iface->conf->bss[0]->iface, hostapd_state_text(iface->state), |
| 2131 | hostapd_state_text(s)); |
| 2132 | iface->state = s; |
| 2133 | } |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2134 | |
| 2135 | |
| 2136 | #ifdef NEED_AP_MLME |
| 2137 | |
| 2138 | static void free_beacon_data(struct beacon_data *beacon) |
| 2139 | { |
| 2140 | os_free(beacon->head); |
| 2141 | beacon->head = NULL; |
| 2142 | os_free(beacon->tail); |
| 2143 | beacon->tail = NULL; |
| 2144 | os_free(beacon->probe_resp); |
| 2145 | beacon->probe_resp = NULL; |
| 2146 | os_free(beacon->beacon_ies); |
| 2147 | beacon->beacon_ies = NULL; |
| 2148 | os_free(beacon->proberesp_ies); |
| 2149 | beacon->proberesp_ies = NULL; |
| 2150 | os_free(beacon->assocresp_ies); |
| 2151 | beacon->assocresp_ies = NULL; |
| 2152 | } |
| 2153 | |
| 2154 | |
| 2155 | static int hostapd_build_beacon_data(struct hostapd_iface *iface, |
| 2156 | struct beacon_data *beacon) |
| 2157 | { |
| 2158 | struct wpabuf *beacon_extra, *proberesp_extra, *assocresp_extra; |
| 2159 | struct wpa_driver_ap_params params; |
| 2160 | int ret; |
| 2161 | struct hostapd_data *hapd = iface->bss[0]; |
| 2162 | |
Dmitry Shmidt | 01904cf | 2013-12-05 11:08:35 -0800 | [diff] [blame] | 2163 | os_memset(beacon, 0, sizeof(*beacon)); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2164 | ret = ieee802_11_build_ap_params(hapd, ¶ms); |
| 2165 | if (ret < 0) |
| 2166 | return ret; |
| 2167 | |
| 2168 | ret = hostapd_build_ap_extra_ies(hapd, &beacon_extra, |
| 2169 | &proberesp_extra, |
| 2170 | &assocresp_extra); |
| 2171 | if (ret) |
| 2172 | goto free_ap_params; |
| 2173 | |
| 2174 | ret = -1; |
| 2175 | beacon->head = os_malloc(params.head_len); |
| 2176 | if (!beacon->head) |
| 2177 | goto free_ap_extra_ies; |
| 2178 | |
| 2179 | os_memcpy(beacon->head, params.head, params.head_len); |
| 2180 | beacon->head_len = params.head_len; |
| 2181 | |
| 2182 | beacon->tail = os_malloc(params.tail_len); |
| 2183 | if (!beacon->tail) |
| 2184 | goto free_beacon; |
| 2185 | |
| 2186 | os_memcpy(beacon->tail, params.tail, params.tail_len); |
| 2187 | beacon->tail_len = params.tail_len; |
| 2188 | |
| 2189 | if (params.proberesp != NULL) { |
| 2190 | beacon->probe_resp = os_malloc(params.proberesp_len); |
| 2191 | if (!beacon->probe_resp) |
| 2192 | goto free_beacon; |
| 2193 | |
| 2194 | os_memcpy(beacon->probe_resp, params.proberesp, |
| 2195 | params.proberesp_len); |
| 2196 | beacon->probe_resp_len = params.proberesp_len; |
| 2197 | } |
| 2198 | |
| 2199 | /* copy the extra ies */ |
| 2200 | if (beacon_extra) { |
| 2201 | beacon->beacon_ies = os_malloc(wpabuf_len(beacon_extra)); |
| 2202 | if (!beacon->beacon_ies) |
| 2203 | goto free_beacon; |
| 2204 | |
| 2205 | os_memcpy(beacon->beacon_ies, |
| 2206 | beacon_extra->buf, wpabuf_len(beacon_extra)); |
| 2207 | beacon->beacon_ies_len = wpabuf_len(beacon_extra); |
| 2208 | } |
| 2209 | |
| 2210 | if (proberesp_extra) { |
| 2211 | beacon->proberesp_ies = |
| 2212 | os_malloc(wpabuf_len(proberesp_extra)); |
| 2213 | if (!beacon->proberesp_ies) |
| 2214 | goto free_beacon; |
| 2215 | |
| 2216 | os_memcpy(beacon->proberesp_ies, proberesp_extra->buf, |
| 2217 | wpabuf_len(proberesp_extra)); |
| 2218 | beacon->proberesp_ies_len = wpabuf_len(proberesp_extra); |
| 2219 | } |
| 2220 | |
| 2221 | if (assocresp_extra) { |
| 2222 | beacon->assocresp_ies = |
| 2223 | os_malloc(wpabuf_len(assocresp_extra)); |
| 2224 | if (!beacon->assocresp_ies) |
| 2225 | goto free_beacon; |
| 2226 | |
| 2227 | os_memcpy(beacon->assocresp_ies, assocresp_extra->buf, |
| 2228 | wpabuf_len(assocresp_extra)); |
| 2229 | beacon->assocresp_ies_len = wpabuf_len(assocresp_extra); |
| 2230 | } |
| 2231 | |
| 2232 | ret = 0; |
| 2233 | free_beacon: |
| 2234 | /* if the function fails, the caller should not free beacon data */ |
| 2235 | if (ret) |
| 2236 | free_beacon_data(beacon); |
| 2237 | |
| 2238 | free_ap_extra_ies: |
| 2239 | hostapd_free_ap_extra_ies(hapd, beacon_extra, proberesp_extra, |
| 2240 | assocresp_extra); |
| 2241 | free_ap_params: |
| 2242 | ieee802_11_free_ap_params(¶ms); |
| 2243 | return ret; |
| 2244 | } |
| 2245 | |
| 2246 | |
| 2247 | /* |
| 2248 | * TODO: This flow currently supports only changing frequency within the |
| 2249 | * same hw_mode. Any other changes to MAC parameters or provided settings (even |
| 2250 | * width) are not supported. |
| 2251 | */ |
| 2252 | static int hostapd_change_config_freq(struct hostapd_data *hapd, |
| 2253 | struct hostapd_config *conf, |
| 2254 | struct hostapd_freq_params *params, |
| 2255 | struct hostapd_freq_params *old_params) |
| 2256 | { |
| 2257 | int channel; |
| 2258 | |
| 2259 | if (!params->channel) { |
| 2260 | /* check if the new channel is supported by hw */ |
| 2261 | channel = hostapd_hw_get_channel(hapd, params->freq); |
| 2262 | if (!channel) |
| 2263 | return -1; |
| 2264 | } else { |
| 2265 | channel = params->channel; |
| 2266 | } |
| 2267 | |
| 2268 | /* if a pointer to old_params is provided we save previous state */ |
| 2269 | if (old_params) { |
| 2270 | old_params->channel = conf->channel; |
| 2271 | old_params->ht_enabled = conf->ieee80211n; |
| 2272 | old_params->sec_channel_offset = conf->secondary_channel; |
| 2273 | } |
| 2274 | |
| 2275 | conf->channel = channel; |
| 2276 | conf->ieee80211n = params->ht_enabled; |
| 2277 | conf->secondary_channel = params->sec_channel_offset; |
| 2278 | |
| 2279 | /* TODO: maybe call here hostapd_config_check here? */ |
| 2280 | |
| 2281 | return 0; |
| 2282 | } |
| 2283 | |
| 2284 | |
| 2285 | static int hostapd_fill_csa_settings(struct hostapd_iface *iface, |
| 2286 | struct csa_settings *settings) |
| 2287 | { |
| 2288 | struct hostapd_freq_params old_freq; |
| 2289 | int ret; |
| 2290 | |
| 2291 | os_memset(&old_freq, 0, sizeof(old_freq)); |
| 2292 | if (!iface || !iface->freq || iface->csa_in_progress) |
| 2293 | return -1; |
| 2294 | |
| 2295 | ret = hostapd_change_config_freq(iface->bss[0], iface->conf, |
| 2296 | &settings->freq_params, |
| 2297 | &old_freq); |
| 2298 | if (ret) |
| 2299 | return ret; |
| 2300 | |
| 2301 | ret = hostapd_build_beacon_data(iface, &settings->beacon_after); |
| 2302 | |
| 2303 | /* change back the configuration */ |
| 2304 | hostapd_change_config_freq(iface->bss[0], iface->conf, |
| 2305 | &old_freq, NULL); |
| 2306 | |
| 2307 | if (ret) |
| 2308 | return ret; |
| 2309 | |
| 2310 | /* set channel switch parameters for csa ie */ |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2311 | iface->cs_freq_params = settings->freq_params; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2312 | iface->cs_count = settings->cs_count; |
| 2313 | iface->cs_block_tx = settings->block_tx; |
| 2314 | |
| 2315 | ret = hostapd_build_beacon_data(iface, &settings->beacon_csa); |
| 2316 | if (ret) { |
| 2317 | free_beacon_data(&settings->beacon_after); |
| 2318 | return ret; |
| 2319 | } |
| 2320 | |
| 2321 | settings->counter_offset_beacon = iface->cs_c_off_beacon; |
| 2322 | settings->counter_offset_presp = iface->cs_c_off_proberesp; |
| 2323 | |
| 2324 | return 0; |
| 2325 | } |
| 2326 | |
| 2327 | |
| 2328 | void hostapd_cleanup_cs_params(struct hostapd_data *hapd) |
| 2329 | { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2330 | os_memset(&hapd->iface->cs_freq_params, 0, |
| 2331 | sizeof(hapd->iface->cs_freq_params)); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2332 | hapd->iface->cs_count = 0; |
| 2333 | hapd->iface->cs_block_tx = 0; |
| 2334 | hapd->iface->cs_c_off_beacon = 0; |
| 2335 | hapd->iface->cs_c_off_proberesp = 0; |
| 2336 | hapd->iface->csa_in_progress = 0; |
| 2337 | } |
| 2338 | |
| 2339 | |
| 2340 | int hostapd_switch_channel(struct hostapd_data *hapd, |
| 2341 | struct csa_settings *settings) |
| 2342 | { |
| 2343 | int ret; |
| 2344 | ret = hostapd_fill_csa_settings(hapd->iface, settings); |
| 2345 | if (ret) |
| 2346 | return ret; |
| 2347 | |
| 2348 | ret = hostapd_drv_switch_channel(hapd, settings); |
| 2349 | free_beacon_data(&settings->beacon_csa); |
| 2350 | free_beacon_data(&settings->beacon_after); |
| 2351 | |
| 2352 | if (ret) { |
| 2353 | /* if we failed, clean cs parameters */ |
| 2354 | hostapd_cleanup_cs_params(hapd); |
| 2355 | return ret; |
| 2356 | } |
| 2357 | |
| 2358 | hapd->iface->csa_in_progress = 1; |
| 2359 | return 0; |
| 2360 | } |
| 2361 | |
| 2362 | #endif /* NEED_AP_MLME */ |