Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * hostapd / Initialization and configuration |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3 | * Copyright (c) 2002-2012, 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" |
| 14 | #include "radius/radius_client.h" |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 15 | #include "radius/radius_das.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 16 | #include "drivers/driver.h" |
| 17 | #include "hostapd.h" |
| 18 | #include "authsrv.h" |
| 19 | #include "sta_info.h" |
| 20 | #include "accounting.h" |
| 21 | #include "ap_list.h" |
| 22 | #include "beacon.h" |
| 23 | #include "iapp.h" |
| 24 | #include "ieee802_1x.h" |
| 25 | #include "ieee802_11_auth.h" |
| 26 | #include "vlan_init.h" |
| 27 | #include "wpa_auth.h" |
| 28 | #include "wps_hostapd.h" |
| 29 | #include "hw_features.h" |
| 30 | #include "wpa_auth_glue.h" |
| 31 | #include "ap_drv_ops.h" |
| 32 | #include "ap_config.h" |
| 33 | #include "p2p_hostapd.h" |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 34 | #include "gas_serv.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 35 | |
| 36 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 37 | static int hostapd_flush_old_stations(struct hostapd_data *hapd, u16 reason); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 38 | static int hostapd_setup_encryption(char *iface, struct hostapd_data *hapd); |
Dmitry Shmidt | c55524a | 2011-07-07 11:18:38 -0700 | [diff] [blame] | 39 | static int hostapd_broadcast_wep_clear(struct hostapd_data *hapd); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 40 | |
| 41 | extern int wpa_debug_level; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 42 | extern struct wpa_driver_ops *wpa_drivers[]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 43 | |
| 44 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 45 | int hostapd_for_each_interface(struct hapd_interfaces *interfaces, |
| 46 | int (*cb)(struct hostapd_iface *iface, |
| 47 | void *ctx), void *ctx) |
| 48 | { |
| 49 | size_t i; |
| 50 | int ret; |
| 51 | |
| 52 | for (i = 0; i < interfaces->count; i++) { |
| 53 | ret = cb(interfaces->iface[i], ctx); |
| 54 | if (ret) |
| 55 | return ret; |
| 56 | } |
| 57 | |
| 58 | return 0; |
| 59 | } |
| 60 | |
| 61 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 62 | static void hostapd_reload_bss(struct hostapd_data *hapd) |
| 63 | { |
| 64 | #ifndef CONFIG_NO_RADIUS |
| 65 | radius_client_reconfig(hapd->radius, hapd->conf->radius); |
| 66 | #endif /* CONFIG_NO_RADIUS */ |
| 67 | |
| 68 | if (hostapd_setup_wpa_psk(hapd->conf)) { |
| 69 | wpa_printf(MSG_ERROR, "Failed to re-configure WPA PSK " |
| 70 | "after reloading configuration"); |
| 71 | } |
| 72 | |
| 73 | if (hapd->conf->ieee802_1x || hapd->conf->wpa) |
| 74 | hostapd_set_drv_ieee8021x(hapd, hapd->conf->iface, 1); |
| 75 | else |
| 76 | hostapd_set_drv_ieee8021x(hapd, hapd->conf->iface, 0); |
| 77 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 78 | if (hapd->conf->wpa && hapd->wpa_auth == NULL) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 79 | hostapd_setup_wpa(hapd); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 80 | if (hapd->wpa_auth) |
| 81 | wpa_init_keys(hapd->wpa_auth); |
| 82 | } else if (hapd->conf->wpa) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 83 | const u8 *wpa_ie; |
| 84 | size_t wpa_ie_len; |
| 85 | hostapd_reconfig_wpa(hapd); |
| 86 | wpa_ie = wpa_auth_get_wpa_ie(hapd->wpa_auth, &wpa_ie_len); |
| 87 | if (hostapd_set_generic_elem(hapd, wpa_ie, wpa_ie_len)) |
| 88 | wpa_printf(MSG_ERROR, "Failed to configure WPA IE for " |
| 89 | "the kernel driver."); |
| 90 | } else if (hapd->wpa_auth) { |
| 91 | wpa_deinit(hapd->wpa_auth); |
| 92 | hapd->wpa_auth = NULL; |
| 93 | hostapd_set_privacy(hapd, 0); |
| 94 | hostapd_setup_encryption(hapd->conf->iface, hapd); |
| 95 | hostapd_set_generic_elem(hapd, (u8 *) "", 0); |
| 96 | } |
| 97 | |
| 98 | ieee802_11_set_beacon(hapd); |
| 99 | hostapd_update_wps(hapd); |
| 100 | |
| 101 | if (hapd->conf->ssid.ssid_set && |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 102 | hostapd_set_ssid(hapd, hapd->conf->ssid.ssid, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 103 | hapd->conf->ssid.ssid_len)) { |
| 104 | wpa_printf(MSG_ERROR, "Could not set SSID for kernel driver"); |
| 105 | /* try to continue */ |
| 106 | } |
| 107 | wpa_printf(MSG_DEBUG, "Reconfigured interface %s", hapd->conf->iface); |
| 108 | } |
| 109 | |
| 110 | |
| 111 | int hostapd_reload_config(struct hostapd_iface *iface) |
| 112 | { |
| 113 | struct hostapd_data *hapd = iface->bss[0]; |
| 114 | struct hostapd_config *newconf, *oldconf; |
| 115 | size_t j; |
| 116 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 117 | if (iface->interfaces == NULL || |
| 118 | iface->interfaces->config_read_cb == NULL) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 119 | return -1; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 120 | newconf = iface->interfaces->config_read_cb(iface->config_fname); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 121 | if (newconf == NULL) |
| 122 | return -1; |
| 123 | |
| 124 | /* |
| 125 | * Deauthenticate all stations since the new configuration may not |
| 126 | * allow them to use the BSS anymore. |
| 127 | */ |
| 128 | for (j = 0; j < iface->num_bss; j++) { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 129 | hostapd_flush_old_stations(iface->bss[j], |
| 130 | WLAN_REASON_PREV_AUTH_NOT_VALID); |
Dmitry Shmidt | c55524a | 2011-07-07 11:18:38 -0700 | [diff] [blame] | 131 | hostapd_broadcast_wep_clear(iface->bss[j]); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 132 | |
| 133 | #ifndef CONFIG_NO_RADIUS |
| 134 | /* TODO: update dynamic data based on changed configuration |
| 135 | * items (e.g., open/close sockets, etc.) */ |
| 136 | radius_client_flush(iface->bss[j]->radius, 0); |
| 137 | #endif /* CONFIG_NO_RADIUS */ |
| 138 | } |
| 139 | |
| 140 | oldconf = hapd->iconf; |
| 141 | iface->conf = newconf; |
| 142 | |
| 143 | for (j = 0; j < iface->num_bss; j++) { |
| 144 | hapd = iface->bss[j]; |
| 145 | hapd->iconf = newconf; |
| 146 | hapd->conf = &newconf->bss[j]; |
| 147 | hostapd_reload_bss(hapd); |
| 148 | } |
| 149 | |
| 150 | hostapd_config_free(oldconf); |
| 151 | |
| 152 | |
| 153 | return 0; |
| 154 | } |
| 155 | |
| 156 | |
| 157 | static void hostapd_broadcast_key_clear_iface(struct hostapd_data *hapd, |
| 158 | char *ifname) |
| 159 | { |
| 160 | int i; |
| 161 | |
| 162 | for (i = 0; i < NUM_WEP_KEYS; i++) { |
| 163 | if (hostapd_drv_set_key(ifname, hapd, WPA_ALG_NONE, NULL, i, |
| 164 | 0, NULL, 0, NULL, 0)) { |
| 165 | wpa_printf(MSG_DEBUG, "Failed to clear default " |
| 166 | "encryption keys (ifname=%s keyidx=%d)", |
| 167 | ifname, i); |
| 168 | } |
| 169 | } |
| 170 | #ifdef CONFIG_IEEE80211W |
| 171 | if (hapd->conf->ieee80211w) { |
| 172 | for (i = NUM_WEP_KEYS; i < NUM_WEP_KEYS + 2; i++) { |
| 173 | if (hostapd_drv_set_key(ifname, hapd, WPA_ALG_NONE, |
| 174 | NULL, i, 0, NULL, |
| 175 | 0, NULL, 0)) { |
| 176 | wpa_printf(MSG_DEBUG, "Failed to clear " |
| 177 | "default mgmt encryption keys " |
| 178 | "(ifname=%s keyidx=%d)", ifname, i); |
| 179 | } |
| 180 | } |
| 181 | } |
| 182 | #endif /* CONFIG_IEEE80211W */ |
| 183 | } |
| 184 | |
| 185 | |
| 186 | static int hostapd_broadcast_wep_clear(struct hostapd_data *hapd) |
| 187 | { |
| 188 | hostapd_broadcast_key_clear_iface(hapd, hapd->conf->iface); |
| 189 | return 0; |
| 190 | } |
| 191 | |
| 192 | |
| 193 | static int hostapd_broadcast_wep_set(struct hostapd_data *hapd) |
| 194 | { |
| 195 | int errors = 0, idx; |
| 196 | struct hostapd_ssid *ssid = &hapd->conf->ssid; |
| 197 | |
| 198 | idx = ssid->wep.idx; |
| 199 | if (ssid->wep.default_len && |
| 200 | hostapd_drv_set_key(hapd->conf->iface, |
| 201 | hapd, WPA_ALG_WEP, broadcast_ether_addr, idx, |
| 202 | 1, NULL, 0, ssid->wep.key[idx], |
| 203 | ssid->wep.len[idx])) { |
| 204 | wpa_printf(MSG_WARNING, "Could not set WEP encryption."); |
| 205 | errors++; |
| 206 | } |
| 207 | |
| 208 | if (ssid->dyn_vlan_keys) { |
| 209 | size_t i; |
| 210 | for (i = 0; i <= ssid->max_dyn_vlan_keys; i++) { |
| 211 | const char *ifname; |
| 212 | struct hostapd_wep_keys *key = ssid->dyn_vlan_keys[i]; |
| 213 | if (key == NULL) |
| 214 | continue; |
| 215 | ifname = hostapd_get_vlan_id_ifname(hapd->conf->vlan, |
| 216 | i); |
| 217 | if (ifname == NULL) |
| 218 | continue; |
| 219 | |
| 220 | idx = key->idx; |
| 221 | if (hostapd_drv_set_key(ifname, hapd, WPA_ALG_WEP, |
| 222 | broadcast_ether_addr, idx, 1, |
| 223 | NULL, 0, key->key[idx], |
| 224 | key->len[idx])) { |
| 225 | wpa_printf(MSG_WARNING, "Could not set " |
| 226 | "dynamic VLAN WEP encryption."); |
| 227 | errors++; |
| 228 | } |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | return errors; |
| 233 | } |
| 234 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 235 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 236 | static void hostapd_free_hapd_data(struct hostapd_data *hapd) |
| 237 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 238 | iapp_deinit(hapd->iapp); |
| 239 | hapd->iapp = NULL; |
| 240 | accounting_deinit(hapd); |
| 241 | hostapd_deinit_wpa(hapd); |
| 242 | vlan_deinit(hapd); |
| 243 | hostapd_acl_deinit(hapd); |
| 244 | #ifndef CONFIG_NO_RADIUS |
| 245 | radius_client_deinit(hapd->radius); |
| 246 | hapd->radius = NULL; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 247 | radius_das_deinit(hapd->radius_das); |
| 248 | hapd->radius_das = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 249 | #endif /* CONFIG_NO_RADIUS */ |
| 250 | |
| 251 | hostapd_deinit_wps(hapd); |
| 252 | |
| 253 | authsrv_deinit(hapd); |
| 254 | |
| 255 | if (hapd->interface_added && |
| 256 | hostapd_if_remove(hapd, WPA_IF_AP_BSS, hapd->conf->iface)) { |
| 257 | wpa_printf(MSG_WARNING, "Failed to remove BSS interface %s", |
| 258 | hapd->conf->iface); |
| 259 | } |
| 260 | |
| 261 | os_free(hapd->probereq_cb); |
| 262 | hapd->probereq_cb = NULL; |
| 263 | |
| 264 | #ifdef CONFIG_P2P |
| 265 | wpabuf_free(hapd->p2p_beacon_ie); |
| 266 | hapd->p2p_beacon_ie = NULL; |
| 267 | wpabuf_free(hapd->p2p_probe_resp_ie); |
| 268 | hapd->p2p_probe_resp_ie = NULL; |
| 269 | #endif /* CONFIG_P2P */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 270 | |
| 271 | wpabuf_free(hapd->time_adv); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 272 | |
| 273 | #ifdef CONFIG_INTERWORKING |
| 274 | gas_serv_deinit(hapd); |
| 275 | #endif /* CONFIG_INTERWORKING */ |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 276 | |
| 277 | #ifdef CONFIG_SQLITE |
| 278 | os_free(hapd->tmp_eap_user.identity); |
| 279 | os_free(hapd->tmp_eap_user.password); |
| 280 | #endif /* CONFIG_SQLITE */ |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | |
| 284 | /** |
| 285 | * hostapd_cleanup - Per-BSS cleanup (deinitialization) |
| 286 | * @hapd: Pointer to BSS data |
| 287 | * |
| 288 | * This function is used to free all per-BSS data structures and resources. |
| 289 | * This gets called in a loop for each BSS between calls to |
| 290 | * hostapd_cleanup_iface_pre() and hostapd_cleanup_iface() when an interface |
| 291 | * is deinitialized. Most of the modules that are initialized in |
| 292 | * hostapd_setup_bss() are deinitialized here. |
| 293 | */ |
| 294 | static void hostapd_cleanup(struct hostapd_data *hapd) |
| 295 | { |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 296 | if (hapd->iface->interfaces && |
| 297 | hapd->iface->interfaces->ctrl_iface_deinit) |
| 298 | hapd->iface->interfaces->ctrl_iface_deinit(hapd); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 299 | hostapd_free_hapd_data(hapd); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | |
| 303 | /** |
| 304 | * hostapd_cleanup_iface_pre - Preliminary per-interface cleanup |
| 305 | * @iface: Pointer to interface data |
| 306 | * |
| 307 | * This function is called before per-BSS data structures are deinitialized |
| 308 | * with hostapd_cleanup(). |
| 309 | */ |
| 310 | static void hostapd_cleanup_iface_pre(struct hostapd_iface *iface) |
| 311 | { |
| 312 | } |
| 313 | |
| 314 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 315 | static void hostapd_cleanup_iface_partial(struct hostapd_iface *iface) |
| 316 | { |
| 317 | hostapd_free_hw_features(iface->hw_features, iface->num_hw_features); |
| 318 | iface->hw_features = NULL; |
| 319 | os_free(iface->current_rates); |
| 320 | iface->current_rates = NULL; |
| 321 | os_free(iface->basic_rates); |
| 322 | iface->basic_rates = NULL; |
| 323 | ap_list_deinit(iface); |
| 324 | } |
| 325 | |
| 326 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 327 | /** |
| 328 | * hostapd_cleanup_iface - Complete per-interface cleanup |
| 329 | * @iface: Pointer to interface data |
| 330 | * |
| 331 | * This function is called after per-BSS data structures are deinitialized |
| 332 | * with hostapd_cleanup(). |
| 333 | */ |
| 334 | static void hostapd_cleanup_iface(struct hostapd_iface *iface) |
| 335 | { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 336 | hostapd_cleanup_iface_partial(iface); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 337 | hostapd_config_free(iface->conf); |
| 338 | iface->conf = NULL; |
| 339 | |
| 340 | os_free(iface->config_fname); |
| 341 | os_free(iface->bss); |
| 342 | os_free(iface); |
| 343 | } |
| 344 | |
| 345 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 346 | static void hostapd_clear_wep(struct hostapd_data *hapd) |
| 347 | { |
| 348 | if (hapd->drv_priv) { |
| 349 | hostapd_set_privacy(hapd, 0); |
| 350 | hostapd_broadcast_wep_clear(hapd); |
| 351 | } |
| 352 | } |
| 353 | |
| 354 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 355 | static int hostapd_setup_encryption(char *iface, struct hostapd_data *hapd) |
| 356 | { |
| 357 | int i; |
| 358 | |
| 359 | hostapd_broadcast_wep_set(hapd); |
| 360 | |
| 361 | if (hapd->conf->ssid.wep.default_len) { |
| 362 | hostapd_set_privacy(hapd, 1); |
| 363 | return 0; |
| 364 | } |
| 365 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 366 | /* |
| 367 | * When IEEE 802.1X is not enabled, the driver may need to know how to |
| 368 | * set authentication algorithms for static WEP. |
| 369 | */ |
| 370 | hostapd_drv_set_authmode(hapd, hapd->conf->auth_algs); |
| 371 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 372 | for (i = 0; i < 4; i++) { |
| 373 | if (hapd->conf->ssid.wep.key[i] && |
| 374 | hostapd_drv_set_key(iface, hapd, WPA_ALG_WEP, NULL, i, |
| 375 | i == hapd->conf->ssid.wep.idx, NULL, 0, |
| 376 | hapd->conf->ssid.wep.key[i], |
| 377 | hapd->conf->ssid.wep.len[i])) { |
| 378 | wpa_printf(MSG_WARNING, "Could not set WEP " |
| 379 | "encryption."); |
| 380 | return -1; |
| 381 | } |
| 382 | if (hapd->conf->ssid.wep.key[i] && |
| 383 | i == hapd->conf->ssid.wep.idx) |
| 384 | hostapd_set_privacy(hapd, 1); |
| 385 | } |
| 386 | |
| 387 | return 0; |
| 388 | } |
| 389 | |
| 390 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 391 | static int hostapd_flush_old_stations(struct hostapd_data *hapd, u16 reason) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 392 | { |
| 393 | int ret = 0; |
| 394 | u8 addr[ETH_ALEN]; |
| 395 | |
| 396 | if (hostapd_drv_none(hapd) || hapd->drv_priv == NULL) |
| 397 | return 0; |
| 398 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 399 | wpa_dbg(hapd->msg_ctx, MSG_DEBUG, "Flushing old station entries"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 400 | if (hostapd_flush(hapd)) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 401 | wpa_msg(hapd->msg_ctx, MSG_WARNING, "Could not connect to " |
| 402 | "kernel driver"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 403 | ret = -1; |
| 404 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 405 | wpa_dbg(hapd->msg_ctx, MSG_DEBUG, "Deauthenticate all stations"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 406 | os_memset(addr, 0xff, ETH_ALEN); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 407 | hostapd_drv_sta_deauth(hapd, addr, reason); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 408 | hostapd_free_stas(hapd); |
| 409 | |
| 410 | return ret; |
| 411 | } |
| 412 | |
| 413 | |
| 414 | /** |
| 415 | * hostapd_validate_bssid_configuration - Validate BSSID configuration |
| 416 | * @iface: Pointer to interface data |
| 417 | * Returns: 0 on success, -1 on failure |
| 418 | * |
| 419 | * This function is used to validate that the configured BSSIDs are valid. |
| 420 | */ |
| 421 | static int hostapd_validate_bssid_configuration(struct hostapd_iface *iface) |
| 422 | { |
| 423 | u8 mask[ETH_ALEN] = { 0 }; |
| 424 | struct hostapd_data *hapd = iface->bss[0]; |
| 425 | unsigned int i = iface->conf->num_bss, bits = 0, j; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 426 | int auto_addr = 0; |
| 427 | |
| 428 | if (hostapd_drv_none(hapd)) |
| 429 | return 0; |
| 430 | |
| 431 | /* Generate BSSID mask that is large enough to cover the BSSIDs. */ |
| 432 | |
| 433 | /* Determine the bits necessary to cover the number of BSSIDs. */ |
| 434 | for (i--; i; i >>= 1) |
| 435 | bits++; |
| 436 | |
| 437 | /* Determine the bits necessary to any configured BSSIDs, |
| 438 | if they are higher than the number of BSSIDs. */ |
| 439 | for (j = 0; j < iface->conf->num_bss; j++) { |
| 440 | if (hostapd_mac_comp_empty(iface->conf->bss[j].bssid) == 0) { |
| 441 | if (j) |
| 442 | auto_addr++; |
| 443 | continue; |
| 444 | } |
| 445 | |
| 446 | for (i = 0; i < ETH_ALEN; i++) { |
| 447 | mask[i] |= |
| 448 | iface->conf->bss[j].bssid[i] ^ |
| 449 | hapd->own_addr[i]; |
| 450 | } |
| 451 | } |
| 452 | |
| 453 | if (!auto_addr) |
| 454 | goto skip_mask_ext; |
| 455 | |
| 456 | for (i = 0; i < ETH_ALEN && mask[i] == 0; i++) |
| 457 | ; |
| 458 | j = 0; |
| 459 | if (i < ETH_ALEN) { |
| 460 | j = (5 - i) * 8; |
| 461 | |
| 462 | while (mask[i] != 0) { |
| 463 | mask[i] >>= 1; |
| 464 | j++; |
| 465 | } |
| 466 | } |
| 467 | |
| 468 | if (bits < j) |
| 469 | bits = j; |
| 470 | |
| 471 | if (bits > 40) { |
| 472 | wpa_printf(MSG_ERROR, "Too many bits in the BSSID mask (%u)", |
| 473 | bits); |
| 474 | return -1; |
| 475 | } |
| 476 | |
| 477 | os_memset(mask, 0xff, ETH_ALEN); |
| 478 | j = bits / 8; |
| 479 | for (i = 5; i > 5 - j; i--) |
| 480 | mask[i] = 0; |
| 481 | j = bits % 8; |
| 482 | while (j--) |
| 483 | mask[i] <<= 1; |
| 484 | |
| 485 | skip_mask_ext: |
| 486 | wpa_printf(MSG_DEBUG, "BSS count %lu, BSSID mask " MACSTR " (%d bits)", |
| 487 | (unsigned long) iface->conf->num_bss, MAC2STR(mask), bits); |
| 488 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 489 | if (!auto_addr) |
| 490 | return 0; |
| 491 | |
| 492 | for (i = 0; i < ETH_ALEN; i++) { |
| 493 | if ((hapd->own_addr[i] & mask[i]) != hapd->own_addr[i]) { |
| 494 | wpa_printf(MSG_ERROR, "Invalid BSSID mask " MACSTR |
| 495 | " for start address " MACSTR ".", |
| 496 | MAC2STR(mask), MAC2STR(hapd->own_addr)); |
| 497 | wpa_printf(MSG_ERROR, "Start address must be the " |
| 498 | "first address in the block (i.e., addr " |
| 499 | "AND mask == addr)."); |
| 500 | return -1; |
| 501 | } |
| 502 | } |
| 503 | |
| 504 | return 0; |
| 505 | } |
| 506 | |
| 507 | |
| 508 | static int mac_in_conf(struct hostapd_config *conf, const void *a) |
| 509 | { |
| 510 | size_t i; |
| 511 | |
| 512 | for (i = 0; i < conf->num_bss; i++) { |
| 513 | if (hostapd_mac_comp(conf->bss[i].bssid, a) == 0) { |
| 514 | return 1; |
| 515 | } |
| 516 | } |
| 517 | |
| 518 | return 0; |
| 519 | } |
| 520 | |
| 521 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 522 | #ifndef CONFIG_NO_RADIUS |
| 523 | |
| 524 | static int hostapd_das_nas_mismatch(struct hostapd_data *hapd, |
| 525 | struct radius_das_attrs *attr) |
| 526 | { |
| 527 | /* TODO */ |
| 528 | return 0; |
| 529 | } |
| 530 | |
| 531 | |
| 532 | static struct sta_info * hostapd_das_find_sta(struct hostapd_data *hapd, |
| 533 | struct radius_das_attrs *attr) |
| 534 | { |
| 535 | struct sta_info *sta = NULL; |
| 536 | char buf[128]; |
| 537 | |
| 538 | if (attr->sta_addr) |
| 539 | sta = ap_get_sta(hapd, attr->sta_addr); |
| 540 | |
| 541 | if (sta == NULL && attr->acct_session_id && |
| 542 | attr->acct_session_id_len == 17) { |
| 543 | for (sta = hapd->sta_list; sta; sta = sta->next) { |
| 544 | os_snprintf(buf, sizeof(buf), "%08X-%08X", |
| 545 | sta->acct_session_id_hi, |
| 546 | sta->acct_session_id_lo); |
| 547 | if (os_memcmp(attr->acct_session_id, buf, 17) == 0) |
| 548 | break; |
| 549 | } |
| 550 | } |
| 551 | |
| 552 | if (sta == NULL && attr->cui) { |
| 553 | for (sta = hapd->sta_list; sta; sta = sta->next) { |
| 554 | struct wpabuf *cui; |
| 555 | cui = ieee802_1x_get_radius_cui(sta->eapol_sm); |
| 556 | if (cui && wpabuf_len(cui) == attr->cui_len && |
| 557 | os_memcmp(wpabuf_head(cui), attr->cui, |
| 558 | attr->cui_len) == 0) |
| 559 | break; |
| 560 | } |
| 561 | } |
| 562 | |
| 563 | if (sta == NULL && attr->user_name) { |
| 564 | for (sta = hapd->sta_list; sta; sta = sta->next) { |
| 565 | u8 *identity; |
| 566 | size_t identity_len; |
| 567 | identity = ieee802_1x_get_identity(sta->eapol_sm, |
| 568 | &identity_len); |
| 569 | if (identity && |
| 570 | identity_len == attr->user_name_len && |
| 571 | os_memcmp(identity, attr->user_name, identity_len) |
| 572 | == 0) |
| 573 | break; |
| 574 | } |
| 575 | } |
| 576 | |
| 577 | return sta; |
| 578 | } |
| 579 | |
| 580 | |
| 581 | static enum radius_das_res |
| 582 | hostapd_das_disconnect(void *ctx, struct radius_das_attrs *attr) |
| 583 | { |
| 584 | struct hostapd_data *hapd = ctx; |
| 585 | struct sta_info *sta; |
| 586 | |
| 587 | if (hostapd_das_nas_mismatch(hapd, attr)) |
| 588 | return RADIUS_DAS_NAS_MISMATCH; |
| 589 | |
| 590 | sta = hostapd_das_find_sta(hapd, attr); |
| 591 | if (sta == NULL) |
| 592 | return RADIUS_DAS_SESSION_NOT_FOUND; |
| 593 | |
| 594 | hostapd_drv_sta_deauth(hapd, sta->addr, |
| 595 | WLAN_REASON_PREV_AUTH_NOT_VALID); |
| 596 | ap_sta_deauthenticate(hapd, sta, WLAN_REASON_PREV_AUTH_NOT_VALID); |
| 597 | |
| 598 | return RADIUS_DAS_SUCCESS; |
| 599 | } |
| 600 | |
| 601 | #endif /* CONFIG_NO_RADIUS */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 602 | |
| 603 | |
| 604 | /** |
| 605 | * hostapd_setup_bss - Per-BSS setup (initialization) |
| 606 | * @hapd: Pointer to BSS data |
| 607 | * @first: Whether this BSS is the first BSS of an interface |
| 608 | * |
| 609 | * This function is used to initialize all per-BSS data structures and |
| 610 | * resources. This gets called in a loop for each BSS when an interface is |
| 611 | * initialized. Most of the modules that are initialized here will be |
| 612 | * deinitialized in hostapd_cleanup(). |
| 613 | */ |
| 614 | static int hostapd_setup_bss(struct hostapd_data *hapd, int first) |
| 615 | { |
| 616 | struct hostapd_bss_config *conf = hapd->conf; |
| 617 | u8 ssid[HOSTAPD_MAX_SSID_LEN + 1]; |
| 618 | int ssid_len, set_ssid; |
| 619 | char force_ifname[IFNAMSIZ]; |
| 620 | u8 if_addr[ETH_ALEN]; |
| 621 | |
| 622 | if (!first) { |
| 623 | if (hostapd_mac_comp_empty(hapd->conf->bssid) == 0) { |
| 624 | /* Allocate the next available BSSID. */ |
| 625 | do { |
| 626 | inc_byte_array(hapd->own_addr, ETH_ALEN); |
| 627 | } while (mac_in_conf(hapd->iconf, hapd->own_addr)); |
| 628 | } else { |
| 629 | /* Allocate the configured BSSID. */ |
| 630 | os_memcpy(hapd->own_addr, hapd->conf->bssid, ETH_ALEN); |
| 631 | |
| 632 | if (hostapd_mac_comp(hapd->own_addr, |
| 633 | hapd->iface->bss[0]->own_addr) == |
| 634 | 0) { |
| 635 | wpa_printf(MSG_ERROR, "BSS '%s' may not have " |
| 636 | "BSSID set to the MAC address of " |
| 637 | "the radio", hapd->conf->iface); |
| 638 | return -1; |
| 639 | } |
| 640 | } |
| 641 | |
| 642 | hapd->interface_added = 1; |
| 643 | if (hostapd_if_add(hapd->iface->bss[0], WPA_IF_AP_BSS, |
| 644 | hapd->conf->iface, hapd->own_addr, hapd, |
| 645 | &hapd->drv_priv, force_ifname, if_addr, |
| 646 | hapd->conf->bridge[0] ? hapd->conf->bridge : |
| 647 | NULL)) { |
| 648 | wpa_printf(MSG_ERROR, "Failed to add BSS (BSSID=" |
| 649 | MACSTR ")", MAC2STR(hapd->own_addr)); |
| 650 | return -1; |
| 651 | } |
| 652 | } |
| 653 | |
| 654 | if (conf->wmm_enabled < 0) |
| 655 | conf->wmm_enabled = hapd->iconf->ieee80211n; |
| 656 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 657 | hostapd_flush_old_stations(hapd, WLAN_REASON_PREV_AUTH_NOT_VALID); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 658 | hostapd_set_privacy(hapd, 0); |
| 659 | |
| 660 | hostapd_broadcast_wep_clear(hapd); |
| 661 | if (hostapd_setup_encryption(hapd->conf->iface, hapd)) |
| 662 | return -1; |
| 663 | |
| 664 | /* |
| 665 | * Fetch the SSID from the system and use it or, |
| 666 | * if one was specified in the config file, verify they |
| 667 | * match. |
| 668 | */ |
| 669 | ssid_len = hostapd_get_ssid(hapd, ssid, sizeof(ssid)); |
| 670 | if (ssid_len < 0) { |
| 671 | wpa_printf(MSG_ERROR, "Could not read SSID from system"); |
| 672 | return -1; |
| 673 | } |
| 674 | if (conf->ssid.ssid_set) { |
| 675 | /* |
| 676 | * If SSID is specified in the config file and it differs |
| 677 | * from what is being used then force installation of the |
| 678 | * new SSID. |
| 679 | */ |
| 680 | set_ssid = (conf->ssid.ssid_len != (size_t) ssid_len || |
| 681 | os_memcmp(conf->ssid.ssid, ssid, ssid_len) != 0); |
| 682 | } else { |
| 683 | /* |
| 684 | * No SSID in the config file; just use the one we got |
| 685 | * from the system. |
| 686 | */ |
| 687 | set_ssid = 0; |
| 688 | conf->ssid.ssid_len = ssid_len; |
| 689 | os_memcpy(conf->ssid.ssid, ssid, conf->ssid.ssid_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 690 | } |
| 691 | |
| 692 | if (!hostapd_drv_none(hapd)) { |
| 693 | wpa_printf(MSG_ERROR, "Using interface %s with hwaddr " MACSTR |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 694 | " and ssid \"%s\"", |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 695 | hapd->conf->iface, MAC2STR(hapd->own_addr), |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 696 | wpa_ssid_txt(hapd->conf->ssid.ssid, |
| 697 | hapd->conf->ssid.ssid_len)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 698 | } |
| 699 | |
| 700 | if (hostapd_setup_wpa_psk(conf)) { |
| 701 | wpa_printf(MSG_ERROR, "WPA-PSK setup failed."); |
| 702 | return -1; |
| 703 | } |
| 704 | |
| 705 | /* Set SSID for the kernel driver (to be used in beacon and probe |
| 706 | * response frames) */ |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 707 | if (set_ssid && hostapd_set_ssid(hapd, conf->ssid.ssid, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 708 | conf->ssid.ssid_len)) { |
| 709 | wpa_printf(MSG_ERROR, "Could not set SSID for kernel driver"); |
| 710 | return -1; |
| 711 | } |
| 712 | |
| 713 | if (wpa_debug_level == MSG_MSGDUMP) |
| 714 | conf->radius->msg_dumps = 1; |
| 715 | #ifndef CONFIG_NO_RADIUS |
| 716 | hapd->radius = radius_client_init(hapd, conf->radius); |
| 717 | if (hapd->radius == NULL) { |
| 718 | wpa_printf(MSG_ERROR, "RADIUS client initialization failed."); |
| 719 | return -1; |
| 720 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 721 | |
| 722 | if (hapd->conf->radius_das_port) { |
| 723 | struct radius_das_conf das_conf; |
| 724 | os_memset(&das_conf, 0, sizeof(das_conf)); |
| 725 | das_conf.port = hapd->conf->radius_das_port; |
| 726 | das_conf.shared_secret = hapd->conf->radius_das_shared_secret; |
| 727 | das_conf.shared_secret_len = |
| 728 | hapd->conf->radius_das_shared_secret_len; |
| 729 | das_conf.client_addr = &hapd->conf->radius_das_client_addr; |
| 730 | das_conf.time_window = hapd->conf->radius_das_time_window; |
| 731 | das_conf.require_event_timestamp = |
| 732 | hapd->conf->radius_das_require_event_timestamp; |
| 733 | das_conf.ctx = hapd; |
| 734 | das_conf.disconnect = hostapd_das_disconnect; |
| 735 | hapd->radius_das = radius_das_init(&das_conf); |
| 736 | if (hapd->radius_das == NULL) { |
| 737 | wpa_printf(MSG_ERROR, "RADIUS DAS initialization " |
| 738 | "failed."); |
| 739 | return -1; |
| 740 | } |
| 741 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 742 | #endif /* CONFIG_NO_RADIUS */ |
| 743 | |
| 744 | if (hostapd_acl_init(hapd)) { |
| 745 | wpa_printf(MSG_ERROR, "ACL initialization failed."); |
| 746 | return -1; |
| 747 | } |
| 748 | if (hostapd_init_wps(hapd, conf)) |
| 749 | return -1; |
| 750 | |
| 751 | if (authsrv_init(hapd) < 0) |
| 752 | return -1; |
| 753 | |
| 754 | if (ieee802_1x_init(hapd)) { |
| 755 | wpa_printf(MSG_ERROR, "IEEE 802.1X initialization failed."); |
| 756 | return -1; |
| 757 | } |
| 758 | |
| 759 | if (hapd->conf->wpa && hostapd_setup_wpa(hapd)) |
| 760 | return -1; |
| 761 | |
| 762 | if (accounting_init(hapd)) { |
| 763 | wpa_printf(MSG_ERROR, "Accounting initialization failed."); |
| 764 | return -1; |
| 765 | } |
| 766 | |
| 767 | if (hapd->conf->ieee802_11f && |
| 768 | (hapd->iapp = iapp_init(hapd, hapd->conf->iapp_iface)) == NULL) { |
| 769 | wpa_printf(MSG_ERROR, "IEEE 802.11F (IAPP) initialization " |
| 770 | "failed."); |
| 771 | return -1; |
| 772 | } |
| 773 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 774 | #ifdef CONFIG_INTERWORKING |
| 775 | if (gas_serv_init(hapd)) { |
| 776 | wpa_printf(MSG_ERROR, "GAS server initialization failed"); |
| 777 | return -1; |
| 778 | } |
| 779 | #endif /* CONFIG_INTERWORKING */ |
| 780 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 781 | if (hapd->iface->interfaces && |
| 782 | hapd->iface->interfaces->ctrl_iface_init && |
| 783 | hapd->iface->interfaces->ctrl_iface_init(hapd)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 784 | wpa_printf(MSG_ERROR, "Failed to setup control interface"); |
| 785 | return -1; |
| 786 | } |
| 787 | |
| 788 | if (!hostapd_drv_none(hapd) && vlan_init(hapd)) { |
| 789 | wpa_printf(MSG_ERROR, "VLAN initialization failed."); |
| 790 | return -1; |
| 791 | } |
| 792 | |
| 793 | ieee802_11_set_beacon(hapd); |
| 794 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 795 | if (hapd->wpa_auth && wpa_init_keys(hapd->wpa_auth) < 0) |
| 796 | return -1; |
| 797 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 798 | if (hapd->driver && hapd->driver->set_operstate) |
| 799 | hapd->driver->set_operstate(hapd->drv_priv, 1); |
| 800 | |
| 801 | return 0; |
| 802 | } |
| 803 | |
| 804 | |
| 805 | static void hostapd_tx_queue_params(struct hostapd_iface *iface) |
| 806 | { |
| 807 | struct hostapd_data *hapd = iface->bss[0]; |
| 808 | int i; |
| 809 | struct hostapd_tx_queue_params *p; |
| 810 | |
| 811 | for (i = 0; i < NUM_TX_QUEUES; i++) { |
| 812 | p = &iface->conf->tx_queue[i]; |
| 813 | |
| 814 | if (hostapd_set_tx_queue_params(hapd, i, p->aifs, p->cwmin, |
| 815 | p->cwmax, p->burst)) { |
| 816 | wpa_printf(MSG_DEBUG, "Failed to set TX queue " |
| 817 | "parameters for queue %d.", i); |
| 818 | /* Continue anyway */ |
| 819 | } |
| 820 | } |
| 821 | } |
| 822 | |
| 823 | |
| 824 | static int setup_interface(struct hostapd_iface *iface) |
| 825 | { |
| 826 | struct hostapd_data *hapd = iface->bss[0]; |
| 827 | size_t i; |
| 828 | char country[4]; |
| 829 | |
| 830 | /* |
| 831 | * Make sure that all BSSes get configured with a pointer to the same |
| 832 | * driver interface. |
| 833 | */ |
| 834 | for (i = 1; i < iface->num_bss; i++) { |
| 835 | iface->bss[i]->driver = hapd->driver; |
| 836 | iface->bss[i]->drv_priv = hapd->drv_priv; |
| 837 | } |
| 838 | |
| 839 | if (hostapd_validate_bssid_configuration(iface)) |
| 840 | return -1; |
| 841 | |
| 842 | if (hapd->iconf->country[0] && hapd->iconf->country[1]) { |
| 843 | os_memcpy(country, hapd->iconf->country, 3); |
| 844 | country[3] = '\0'; |
| 845 | if (hostapd_set_country(hapd, country) < 0) { |
| 846 | wpa_printf(MSG_ERROR, "Failed to set country code"); |
| 847 | return -1; |
| 848 | } |
| 849 | } |
| 850 | |
| 851 | if (hostapd_get_hw_features(iface)) { |
| 852 | /* Not all drivers support this yet, so continue without hw |
| 853 | * feature data. */ |
| 854 | } else { |
| 855 | int ret = hostapd_select_hw_mode(iface); |
| 856 | if (ret < 0) { |
| 857 | wpa_printf(MSG_ERROR, "Could not select hw_mode and " |
| 858 | "channel. (%d)", ret); |
| 859 | return -1; |
| 860 | } |
| 861 | ret = hostapd_check_ht_capab(iface); |
| 862 | if (ret < 0) |
| 863 | return -1; |
| 864 | if (ret == 1) { |
| 865 | wpa_printf(MSG_DEBUG, "Interface initialization will " |
| 866 | "be completed in a callback"); |
| 867 | return 0; |
| 868 | } |
| 869 | } |
| 870 | return hostapd_setup_interface_complete(iface, 0); |
| 871 | } |
| 872 | |
| 873 | |
| 874 | int hostapd_setup_interface_complete(struct hostapd_iface *iface, int err) |
| 875 | { |
| 876 | struct hostapd_data *hapd = iface->bss[0]; |
| 877 | size_t j; |
| 878 | u8 *prev_addr; |
| 879 | |
| 880 | if (err) { |
| 881 | wpa_printf(MSG_ERROR, "Interface initialization failed"); |
| 882 | eloop_terminate(); |
| 883 | return -1; |
| 884 | } |
| 885 | |
| 886 | wpa_printf(MSG_DEBUG, "Completing interface initialization"); |
| 887 | if (hapd->iconf->channel) { |
| 888 | iface->freq = hostapd_hw_get_freq(hapd, hapd->iconf->channel); |
| 889 | wpa_printf(MSG_DEBUG, "Mode: %s Channel: %d " |
| 890 | "Frequency: %d MHz", |
| 891 | hostapd_hw_mode_txt(hapd->iconf->hw_mode), |
| 892 | hapd->iconf->channel, iface->freq); |
| 893 | |
| 894 | if (hostapd_set_freq(hapd, hapd->iconf->hw_mode, iface->freq, |
| 895 | hapd->iconf->channel, |
| 896 | hapd->iconf->ieee80211n, |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame^] | 897 | hapd->iconf->ieee80211ac, |
| 898 | hapd->iconf->secondary_channel, |
| 899 | hapd->iconf->vht_oper_chwidth, |
| 900 | hapd->iconf->vht_oper_centr_freq_seg0_idx, |
| 901 | hapd->iconf->vht_oper_centr_freq_seg1_idx)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 902 | wpa_printf(MSG_ERROR, "Could not set channel for " |
| 903 | "kernel driver"); |
| 904 | return -1; |
| 905 | } |
| 906 | } |
| 907 | |
| 908 | if (iface->current_mode) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 909 | if (hostapd_prepare_rates(iface, iface->current_mode)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 910 | wpa_printf(MSG_ERROR, "Failed to prepare rates " |
| 911 | "table."); |
| 912 | hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211, |
| 913 | HOSTAPD_LEVEL_WARNING, |
| 914 | "Failed to prepare rates table."); |
| 915 | return -1; |
| 916 | } |
| 917 | } |
| 918 | |
| 919 | if (hapd->iconf->rts_threshold > -1 && |
| 920 | hostapd_set_rts(hapd, hapd->iconf->rts_threshold)) { |
| 921 | wpa_printf(MSG_ERROR, "Could not set RTS threshold for " |
| 922 | "kernel driver"); |
| 923 | return -1; |
| 924 | } |
| 925 | |
| 926 | if (hapd->iconf->fragm_threshold > -1 && |
| 927 | hostapd_set_frag(hapd, hapd->iconf->fragm_threshold)) { |
| 928 | wpa_printf(MSG_ERROR, "Could not set fragmentation threshold " |
| 929 | "for kernel driver"); |
| 930 | return -1; |
| 931 | } |
| 932 | |
| 933 | prev_addr = hapd->own_addr; |
| 934 | |
| 935 | for (j = 0; j < iface->num_bss; j++) { |
| 936 | hapd = iface->bss[j]; |
| 937 | if (j) |
| 938 | os_memcpy(hapd->own_addr, prev_addr, ETH_ALEN); |
| 939 | if (hostapd_setup_bss(hapd, j == 0)) |
| 940 | return -1; |
| 941 | if (hostapd_mac_comp_empty(hapd->conf->bssid) == 0) |
| 942 | prev_addr = hapd->own_addr; |
| 943 | } |
| 944 | |
| 945 | hostapd_tx_queue_params(iface); |
| 946 | |
| 947 | ap_list_init(iface); |
| 948 | |
| 949 | if (hostapd_driver_commit(hapd) < 0) { |
| 950 | wpa_printf(MSG_ERROR, "%s: Failed to commit driver " |
| 951 | "configuration", __func__); |
| 952 | return -1; |
| 953 | } |
| 954 | |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 955 | /* |
| 956 | * WPS UPnP module can be initialized only when the "upnp_iface" is up. |
| 957 | * If "interface" and "upnp_iface" are the same (e.g., non-bridge |
| 958 | * mode), the interface is up only after driver_commit, so initialize |
| 959 | * WPS after driver_commit. |
| 960 | */ |
| 961 | for (j = 0; j < iface->num_bss; j++) { |
| 962 | if (hostapd_init_wps_complete(iface->bss[j])) |
| 963 | return -1; |
| 964 | } |
| 965 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 966 | if (hapd->setup_complete_cb) |
| 967 | hapd->setup_complete_cb(hapd->setup_complete_cb_ctx); |
| 968 | |
| 969 | wpa_printf(MSG_DEBUG, "%s: Setup of interface done.", |
| 970 | iface->bss[0]->conf->iface); |
| 971 | |
| 972 | return 0; |
| 973 | } |
| 974 | |
| 975 | |
| 976 | /** |
| 977 | * hostapd_setup_interface - Setup of an interface |
| 978 | * @iface: Pointer to interface data. |
| 979 | * Returns: 0 on success, -1 on failure |
| 980 | * |
| 981 | * Initializes the driver interface, validates the configuration, |
| 982 | * and sets driver parameters based on the configuration. |
| 983 | * Flushes old stations, sets the channel, encryption, |
| 984 | * beacons, and WDS links based on the configuration. |
| 985 | */ |
| 986 | int hostapd_setup_interface(struct hostapd_iface *iface) |
| 987 | { |
| 988 | int ret; |
| 989 | |
| 990 | ret = setup_interface(iface); |
| 991 | if (ret) { |
| 992 | wpa_printf(MSG_ERROR, "%s: Unable to setup interface.", |
| 993 | iface->bss[0]->conf->iface); |
| 994 | return -1; |
| 995 | } |
| 996 | |
| 997 | return 0; |
| 998 | } |
| 999 | |
| 1000 | |
| 1001 | /** |
| 1002 | * hostapd_alloc_bss_data - Allocate and initialize per-BSS data |
| 1003 | * @hapd_iface: Pointer to interface data |
| 1004 | * @conf: Pointer to per-interface configuration |
| 1005 | * @bss: Pointer to per-BSS configuration for this BSS |
| 1006 | * Returns: Pointer to allocated BSS data |
| 1007 | * |
| 1008 | * This function is used to allocate per-BSS data structure. This data will be |
| 1009 | * freed after hostapd_cleanup() is called for it during interface |
| 1010 | * deinitialization. |
| 1011 | */ |
| 1012 | struct hostapd_data * |
| 1013 | hostapd_alloc_bss_data(struct hostapd_iface *hapd_iface, |
| 1014 | struct hostapd_config *conf, |
| 1015 | struct hostapd_bss_config *bss) |
| 1016 | { |
| 1017 | struct hostapd_data *hapd; |
| 1018 | |
| 1019 | hapd = os_zalloc(sizeof(*hapd)); |
| 1020 | if (hapd == NULL) |
| 1021 | return NULL; |
| 1022 | |
| 1023 | hapd->new_assoc_sta_cb = hostapd_new_assoc_sta; |
| 1024 | hapd->iconf = conf; |
| 1025 | hapd->conf = bss; |
| 1026 | hapd->iface = hapd_iface; |
| 1027 | hapd->driver = hapd->iconf->driver; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1028 | hapd->ctrl_sock = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1029 | |
| 1030 | return hapd; |
| 1031 | } |
| 1032 | |
| 1033 | |
| 1034 | void hostapd_interface_deinit(struct hostapd_iface *iface) |
| 1035 | { |
| 1036 | size_t j; |
| 1037 | |
| 1038 | if (iface == NULL) |
| 1039 | return; |
| 1040 | |
| 1041 | hostapd_cleanup_iface_pre(iface); |
| 1042 | for (j = 0; j < iface->num_bss; j++) { |
| 1043 | struct hostapd_data *hapd = iface->bss[j]; |
| 1044 | hostapd_free_stas(hapd); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1045 | hostapd_flush_old_stations(hapd, WLAN_REASON_DEAUTH_LEAVING); |
| 1046 | hostapd_clear_wep(hapd); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1047 | hostapd_cleanup(hapd); |
| 1048 | } |
| 1049 | } |
| 1050 | |
| 1051 | |
| 1052 | void hostapd_interface_free(struct hostapd_iface *iface) |
| 1053 | { |
| 1054 | size_t j; |
| 1055 | for (j = 0; j < iface->num_bss; j++) |
| 1056 | os_free(iface->bss[j]); |
| 1057 | hostapd_cleanup_iface(iface); |
| 1058 | } |
| 1059 | |
| 1060 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1061 | #ifdef HOSTAPD |
| 1062 | |
| 1063 | void hostapd_interface_deinit_free(struct hostapd_iface *iface) |
| 1064 | { |
| 1065 | const struct wpa_driver_ops *driver; |
| 1066 | void *drv_priv; |
| 1067 | if (iface == NULL) |
| 1068 | return; |
| 1069 | driver = iface->bss[0]->driver; |
| 1070 | drv_priv = iface->bss[0]->drv_priv; |
| 1071 | hostapd_interface_deinit(iface); |
| 1072 | if (driver && driver->hapd_deinit && drv_priv) |
| 1073 | driver->hapd_deinit(drv_priv); |
| 1074 | hostapd_interface_free(iface); |
| 1075 | } |
| 1076 | |
| 1077 | |
| 1078 | int hostapd_enable_iface(struct hostapd_iface *hapd_iface) |
| 1079 | { |
| 1080 | if (hapd_iface->bss[0]->drv_priv != NULL) { |
| 1081 | wpa_printf(MSG_ERROR, "Interface %s already enabled", |
| 1082 | hapd_iface->conf->bss[0].iface); |
| 1083 | return -1; |
| 1084 | } |
| 1085 | |
| 1086 | wpa_printf(MSG_DEBUG, "Enable interface %s", |
| 1087 | hapd_iface->conf->bss[0].iface); |
| 1088 | |
| 1089 | if (hapd_iface->interfaces == NULL || |
| 1090 | hapd_iface->interfaces->driver_init == NULL || |
| 1091 | hapd_iface->interfaces->driver_init(hapd_iface) || |
| 1092 | hostapd_setup_interface(hapd_iface)) { |
| 1093 | hostapd_interface_deinit_free(hapd_iface); |
| 1094 | return -1; |
| 1095 | } |
| 1096 | return 0; |
| 1097 | } |
| 1098 | |
| 1099 | |
| 1100 | int hostapd_reload_iface(struct hostapd_iface *hapd_iface) |
| 1101 | { |
| 1102 | size_t j; |
| 1103 | |
| 1104 | wpa_printf(MSG_DEBUG, "Reload interface %s", |
| 1105 | hapd_iface->conf->bss[0].iface); |
| 1106 | for (j = 0; j < hapd_iface->num_bss; j++) { |
| 1107 | hostapd_flush_old_stations(hapd_iface->bss[j], |
| 1108 | WLAN_REASON_PREV_AUTH_NOT_VALID); |
| 1109 | |
| 1110 | #ifndef CONFIG_NO_RADIUS |
| 1111 | /* TODO: update dynamic data based on changed configuration |
| 1112 | * items (e.g., open/close sockets, etc.) */ |
| 1113 | radius_client_flush(hapd_iface->bss[j]->radius, 0); |
| 1114 | #endif /* CONFIG_NO_RADIUS */ |
| 1115 | |
| 1116 | hostapd_reload_bss(hapd_iface->bss[j]); |
| 1117 | } |
| 1118 | return 0; |
| 1119 | } |
| 1120 | |
| 1121 | |
| 1122 | int hostapd_disable_iface(struct hostapd_iface *hapd_iface) |
| 1123 | { |
| 1124 | size_t j; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1125 | struct hostapd_bss_config *bss; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1126 | const struct wpa_driver_ops *driver; |
| 1127 | void *drv_priv; |
| 1128 | |
| 1129 | if (hapd_iface == NULL) |
| 1130 | return -1; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1131 | bss = hapd_iface->bss[0]->conf; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1132 | driver = hapd_iface->bss[0]->driver; |
| 1133 | drv_priv = hapd_iface->bss[0]->drv_priv; |
| 1134 | |
| 1135 | /* whatever hostapd_interface_deinit does */ |
| 1136 | for (j = 0; j < hapd_iface->num_bss; j++) { |
| 1137 | struct hostapd_data *hapd = hapd_iface->bss[j]; |
| 1138 | hostapd_free_stas(hapd); |
| 1139 | hostapd_flush_old_stations(hapd, WLAN_REASON_DEAUTH_LEAVING); |
| 1140 | hostapd_clear_wep(hapd); |
| 1141 | hostapd_free_hapd_data(hapd); |
| 1142 | } |
| 1143 | |
| 1144 | if (driver && driver->hapd_deinit && drv_priv) { |
| 1145 | driver->hapd_deinit(drv_priv); |
| 1146 | hapd_iface->bss[0]->drv_priv = NULL; |
| 1147 | } |
| 1148 | |
| 1149 | /* From hostapd_cleanup_iface: These were initialized in |
| 1150 | * hostapd_setup_interface and hostapd_setup_interface_complete |
| 1151 | */ |
| 1152 | hostapd_cleanup_iface_partial(hapd_iface); |
| 1153 | bss->wpa = 0; |
| 1154 | bss->wpa_key_mgmt = -1; |
| 1155 | bss->wpa_pairwise = -1; |
| 1156 | |
| 1157 | wpa_printf(MSG_DEBUG, "Interface %s disabled", bss->iface); |
| 1158 | return 0; |
| 1159 | } |
| 1160 | |
| 1161 | |
| 1162 | static struct hostapd_iface * |
| 1163 | hostapd_iface_alloc(struct hapd_interfaces *interfaces) |
| 1164 | { |
| 1165 | struct hostapd_iface **iface, *hapd_iface; |
| 1166 | |
| 1167 | iface = os_realloc_array(interfaces->iface, interfaces->count + 1, |
| 1168 | sizeof(struct hostapd_iface *)); |
| 1169 | if (iface == NULL) |
| 1170 | return NULL; |
| 1171 | interfaces->iface = iface; |
| 1172 | hapd_iface = interfaces->iface[interfaces->count] = |
| 1173 | os_zalloc(sizeof(*hapd_iface)); |
| 1174 | if (hapd_iface == NULL) { |
| 1175 | wpa_printf(MSG_ERROR, "%s: Failed to allocate memory for " |
| 1176 | "the interface", __func__); |
| 1177 | return NULL; |
| 1178 | } |
| 1179 | interfaces->count++; |
| 1180 | hapd_iface->interfaces = interfaces; |
| 1181 | |
| 1182 | return hapd_iface; |
| 1183 | } |
| 1184 | |
| 1185 | |
| 1186 | static struct hostapd_config * |
| 1187 | hostapd_config_alloc(struct hapd_interfaces *interfaces, const char *ifname, |
| 1188 | const char *ctrl_iface) |
| 1189 | { |
| 1190 | struct hostapd_bss_config *bss; |
| 1191 | struct hostapd_config *conf; |
| 1192 | |
| 1193 | /* Allocates memory for bss and conf */ |
| 1194 | conf = hostapd_config_defaults(); |
| 1195 | if (conf == NULL) { |
| 1196 | wpa_printf(MSG_ERROR, "%s: Failed to allocate memory for " |
| 1197 | "configuration", __func__); |
| 1198 | return NULL; |
| 1199 | } |
| 1200 | |
| 1201 | conf->driver = wpa_drivers[0]; |
| 1202 | if (conf->driver == NULL) { |
| 1203 | wpa_printf(MSG_ERROR, "No driver wrappers registered!"); |
| 1204 | hostapd_config_free(conf); |
| 1205 | return NULL; |
| 1206 | } |
| 1207 | |
| 1208 | bss = conf->last_bss = conf->bss; |
| 1209 | |
| 1210 | os_strlcpy(bss->iface, ifname, sizeof(bss->iface)); |
| 1211 | bss->ctrl_interface = os_strdup(ctrl_iface); |
| 1212 | if (bss->ctrl_interface == NULL) { |
| 1213 | hostapd_config_free(conf); |
| 1214 | return NULL; |
| 1215 | } |
| 1216 | |
| 1217 | /* Reading configuration file skipped, will be done in SET! |
| 1218 | * From reading the configuration till the end has to be done in |
| 1219 | * SET |
| 1220 | */ |
| 1221 | return conf; |
| 1222 | } |
| 1223 | |
| 1224 | |
| 1225 | static struct hostapd_iface * hostapd_data_alloc( |
| 1226 | struct hapd_interfaces *interfaces, struct hostapd_config *conf) |
| 1227 | { |
| 1228 | size_t i; |
| 1229 | struct hostapd_iface *hapd_iface = |
| 1230 | interfaces->iface[interfaces->count - 1]; |
| 1231 | struct hostapd_data *hapd; |
| 1232 | |
| 1233 | hapd_iface->conf = conf; |
| 1234 | hapd_iface->num_bss = conf->num_bss; |
| 1235 | |
| 1236 | hapd_iface->bss = os_zalloc(conf->num_bss * |
| 1237 | sizeof(struct hostapd_data *)); |
| 1238 | if (hapd_iface->bss == NULL) |
| 1239 | return NULL; |
| 1240 | |
| 1241 | for (i = 0; i < conf->num_bss; i++) { |
| 1242 | hapd = hapd_iface->bss[i] = |
| 1243 | hostapd_alloc_bss_data(hapd_iface, conf, |
| 1244 | &conf->bss[i]); |
| 1245 | if (hapd == NULL) |
| 1246 | return NULL; |
| 1247 | hapd->msg_ctx = hapd; |
| 1248 | } |
| 1249 | |
| 1250 | hapd_iface->interfaces = interfaces; |
| 1251 | |
| 1252 | return hapd_iface; |
| 1253 | } |
| 1254 | |
| 1255 | |
| 1256 | int hostapd_add_iface(struct hapd_interfaces *interfaces, char *buf) |
| 1257 | { |
| 1258 | struct hostapd_config *conf = NULL; |
| 1259 | struct hostapd_iface *hapd_iface = NULL; |
| 1260 | char *ptr; |
| 1261 | size_t i; |
| 1262 | |
| 1263 | ptr = os_strchr(buf, ' '); |
| 1264 | if (ptr == NULL) |
| 1265 | return -1; |
| 1266 | *ptr++ = '\0'; |
| 1267 | |
| 1268 | for (i = 0; i < interfaces->count; i++) { |
| 1269 | if (!os_strcmp(interfaces->iface[i]->conf->bss[0].iface, |
| 1270 | buf)) { |
| 1271 | wpa_printf(MSG_INFO, "Cannot add interface - it " |
| 1272 | "already exists"); |
| 1273 | return -1; |
| 1274 | } |
| 1275 | } |
| 1276 | |
| 1277 | hapd_iface = hostapd_iface_alloc(interfaces); |
| 1278 | if (hapd_iface == NULL) { |
| 1279 | wpa_printf(MSG_ERROR, "%s: Failed to allocate memory " |
| 1280 | "for interface", __func__); |
| 1281 | goto fail; |
| 1282 | } |
| 1283 | |
| 1284 | conf = hostapd_config_alloc(interfaces, buf, ptr); |
| 1285 | if (conf == NULL) { |
| 1286 | wpa_printf(MSG_ERROR, "%s: Failed to allocate memory " |
| 1287 | "for configuration", __func__); |
| 1288 | goto fail; |
| 1289 | } |
| 1290 | |
| 1291 | hapd_iface = hostapd_data_alloc(interfaces, conf); |
| 1292 | if (hapd_iface == NULL) { |
| 1293 | wpa_printf(MSG_ERROR, "%s: Failed to allocate memory " |
| 1294 | "for hostapd", __func__); |
| 1295 | goto fail; |
| 1296 | } |
| 1297 | |
| 1298 | if (hapd_iface->interfaces && |
| 1299 | hapd_iface->interfaces->ctrl_iface_init && |
| 1300 | hapd_iface->interfaces->ctrl_iface_init(hapd_iface->bss[0])) { |
| 1301 | wpa_printf(MSG_ERROR, "%s: Failed to setup control " |
| 1302 | "interface", __func__); |
| 1303 | goto fail; |
| 1304 | } |
| 1305 | wpa_printf(MSG_INFO, "Add interface '%s'", conf->bss[0].iface); |
| 1306 | |
| 1307 | return 0; |
| 1308 | |
| 1309 | fail: |
| 1310 | if (conf) |
| 1311 | hostapd_config_free(conf); |
| 1312 | if (hapd_iface) { |
| 1313 | os_free(hapd_iface->bss[interfaces->count]); |
| 1314 | os_free(hapd_iface); |
| 1315 | } |
| 1316 | return -1; |
| 1317 | } |
| 1318 | |
| 1319 | |
| 1320 | int hostapd_remove_iface(struct hapd_interfaces *interfaces, char *buf) |
| 1321 | { |
| 1322 | struct hostapd_iface *hapd_iface; |
| 1323 | size_t i, k = 0; |
| 1324 | |
| 1325 | for (i = 0; i < interfaces->count; i++) { |
| 1326 | hapd_iface = interfaces->iface[i]; |
| 1327 | if (hapd_iface == NULL) |
| 1328 | return -1; |
| 1329 | if (!os_strcmp(hapd_iface->conf->bss[0].iface, buf)) { |
| 1330 | wpa_printf(MSG_INFO, "Remove interface '%s'", buf); |
| 1331 | hostapd_interface_deinit_free(hapd_iface); |
| 1332 | k = i; |
| 1333 | while (k < (interfaces->count - 1)) { |
| 1334 | interfaces->iface[k] = |
| 1335 | interfaces->iface[k + 1]; |
| 1336 | k++; |
| 1337 | } |
| 1338 | interfaces->count--; |
| 1339 | return 0; |
| 1340 | } |
| 1341 | } |
| 1342 | return -1; |
| 1343 | } |
| 1344 | |
| 1345 | #endif /* HOSTAPD */ |
| 1346 | |
| 1347 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1348 | /** |
| 1349 | * hostapd_new_assoc_sta - Notify that a new station associated with the AP |
| 1350 | * @hapd: Pointer to BSS data |
| 1351 | * @sta: Pointer to the associated STA data |
| 1352 | * @reassoc: 1 to indicate this was a re-association; 0 = first association |
| 1353 | * |
| 1354 | * This function will be called whenever a station associates with the AP. It |
| 1355 | * can be called from ieee802_11.c for drivers that export MLME to hostapd and |
| 1356 | * from drv_callbacks.c based on driver events for drivers that take care of |
| 1357 | * management frames (IEEE 802.11 authentication and association) internally. |
| 1358 | */ |
| 1359 | void hostapd_new_assoc_sta(struct hostapd_data *hapd, struct sta_info *sta, |
| 1360 | int reassoc) |
| 1361 | { |
| 1362 | if (hapd->tkip_countermeasures) { |
| 1363 | hostapd_drv_sta_deauth(hapd, sta->addr, |
| 1364 | WLAN_REASON_MICHAEL_MIC_FAILURE); |
| 1365 | return; |
| 1366 | } |
| 1367 | |
| 1368 | hostapd_prune_associations(hapd, sta->addr); |
| 1369 | |
| 1370 | /* IEEE 802.11F (IAPP) */ |
| 1371 | if (hapd->conf->ieee802_11f) |
| 1372 | iapp_new_station(hapd->iapp, sta); |
| 1373 | |
| 1374 | #ifdef CONFIG_P2P |
| 1375 | if (sta->p2p_ie == NULL && !sta->no_p2p_set) { |
| 1376 | sta->no_p2p_set = 1; |
| 1377 | hapd->num_sta_no_p2p++; |
| 1378 | if (hapd->num_sta_no_p2p == 1) |
| 1379 | hostapd_p2p_non_p2p_sta_connected(hapd); |
| 1380 | } |
| 1381 | #endif /* CONFIG_P2P */ |
| 1382 | |
| 1383 | /* Start accounting here, if IEEE 802.1X and WPA are not used. |
| 1384 | * IEEE 802.1X/WPA code will start accounting after the station has |
| 1385 | * been authorized. */ |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1386 | if (!hapd->conf->ieee802_1x && !hapd->conf->wpa) { |
| 1387 | os_get_time(&sta->connected_time); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1388 | accounting_sta_start(hapd, sta); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1389 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1390 | |
| 1391 | /* Start IEEE 802.1X authentication process for new stations */ |
| 1392 | ieee802_1x_new_station(hapd, sta); |
| 1393 | if (reassoc) { |
| 1394 | if (sta->auth_alg != WLAN_AUTH_FT && |
| 1395 | !(sta->flags & (WLAN_STA_WPS | WLAN_STA_MAYBE_WPS))) |
| 1396 | wpa_auth_sm_event(sta->wpa_sm, WPA_REAUTH); |
| 1397 | } else |
| 1398 | wpa_auth_sta_associated(hapd->wpa_auth, sta->wpa_sm); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1399 | |
| 1400 | wpa_printf(MSG_DEBUG, "%s: reschedule ap_handle_timer timeout " |
| 1401 | "for " MACSTR " (%d seconds - ap_max_inactivity)", |
| 1402 | __func__, MAC2STR(sta->addr), |
| 1403 | hapd->conf->ap_max_inactivity); |
| 1404 | eloop_cancel_timeout(ap_handle_timer, hapd, sta); |
| 1405 | eloop_register_timeout(hapd->conf->ap_max_inactivity, 0, |
| 1406 | ap_handle_timer, hapd, sta); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1407 | } |