Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * hostapd / Station table |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 3 | * Copyright (c) 2002-2013, 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 | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 14 | #include "common/wpa_ctrl.h" |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 15 | #include "common/sae.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 16 | #include "radius/radius.h" |
| 17 | #include "radius/radius_client.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 18 | #include "p2p/p2p.h" |
| 19 | #include "hostapd.h" |
| 20 | #include "accounting.h" |
| 21 | #include "ieee802_1x.h" |
| 22 | #include "ieee802_11.h" |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 23 | #include "ieee802_11_auth.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 24 | #include "wpa_auth.h" |
| 25 | #include "preauth_auth.h" |
| 26 | #include "ap_config.h" |
| 27 | #include "beacon.h" |
| 28 | #include "ap_mlme.h" |
| 29 | #include "vlan_init.h" |
| 30 | #include "p2p_hostapd.h" |
| 31 | #include "ap_drv_ops.h" |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 32 | #include "gas_serv.h" |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 33 | #include "wnm_ap.h" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 34 | #include "ndisc_snoop.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 35 | #include "sta_info.h" |
| 36 | |
| 37 | static void ap_sta_remove_in_other_bss(struct hostapd_data *hapd, |
| 38 | struct sta_info *sta); |
| 39 | static void ap_handle_session_timer(void *eloop_ctx, void *timeout_ctx); |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 40 | static void ap_handle_session_warning_timer(void *eloop_ctx, void *timeout_ctx); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 41 | static void ap_sta_deauth_cb_timeout(void *eloop_ctx, void *timeout_ctx); |
| 42 | static void ap_sta_disassoc_cb_timeout(void *eloop_ctx, void *timeout_ctx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 43 | #ifdef CONFIG_IEEE80211W |
| 44 | static void ap_sa_query_timer(void *eloop_ctx, void *timeout_ctx); |
| 45 | #endif /* CONFIG_IEEE80211W */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 46 | static int ap_sta_remove(struct hostapd_data *hapd, struct sta_info *sta); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 47 | |
| 48 | int ap_for_each_sta(struct hostapd_data *hapd, |
| 49 | int (*cb)(struct hostapd_data *hapd, struct sta_info *sta, |
| 50 | void *ctx), |
| 51 | void *ctx) |
| 52 | { |
| 53 | struct sta_info *sta; |
| 54 | |
| 55 | for (sta = hapd->sta_list; sta; sta = sta->next) { |
| 56 | if (cb(hapd, sta, ctx)) |
| 57 | return 1; |
| 58 | } |
| 59 | |
| 60 | return 0; |
| 61 | } |
| 62 | |
| 63 | |
| 64 | struct sta_info * ap_get_sta(struct hostapd_data *hapd, const u8 *sta) |
| 65 | { |
| 66 | struct sta_info *s; |
| 67 | |
| 68 | s = hapd->sta_hash[STA_HASH(sta)]; |
| 69 | while (s != NULL && os_memcmp(s->addr, sta, 6) != 0) |
| 70 | s = s->hnext; |
| 71 | return s; |
| 72 | } |
| 73 | |
| 74 | |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 75 | #ifdef CONFIG_P2P |
| 76 | struct sta_info * ap_get_sta_p2p(struct hostapd_data *hapd, const u8 *addr) |
| 77 | { |
| 78 | struct sta_info *sta; |
| 79 | |
| 80 | for (sta = hapd->sta_list; sta; sta = sta->next) { |
| 81 | const u8 *p2p_dev_addr; |
| 82 | |
| 83 | if (sta->p2p_ie == NULL) |
| 84 | continue; |
| 85 | |
| 86 | p2p_dev_addr = p2p_get_go_dev_addr(sta->p2p_ie); |
| 87 | if (p2p_dev_addr == NULL) |
| 88 | continue; |
| 89 | |
| 90 | if (os_memcmp(p2p_dev_addr, addr, ETH_ALEN) == 0) |
| 91 | return sta; |
| 92 | } |
| 93 | |
| 94 | return NULL; |
| 95 | } |
| 96 | #endif /* CONFIG_P2P */ |
| 97 | |
| 98 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 99 | static void ap_sta_list_del(struct hostapd_data *hapd, struct sta_info *sta) |
| 100 | { |
| 101 | struct sta_info *tmp; |
| 102 | |
| 103 | if (hapd->sta_list == sta) { |
| 104 | hapd->sta_list = sta->next; |
| 105 | return; |
| 106 | } |
| 107 | |
| 108 | tmp = hapd->sta_list; |
| 109 | while (tmp != NULL && tmp->next != sta) |
| 110 | tmp = tmp->next; |
| 111 | if (tmp == NULL) { |
| 112 | wpa_printf(MSG_DEBUG, "Could not remove STA " MACSTR " from " |
| 113 | "list.", MAC2STR(sta->addr)); |
| 114 | } else |
| 115 | tmp->next = sta->next; |
| 116 | } |
| 117 | |
| 118 | |
| 119 | void ap_sta_hash_add(struct hostapd_data *hapd, struct sta_info *sta) |
| 120 | { |
| 121 | sta->hnext = hapd->sta_hash[STA_HASH(sta->addr)]; |
| 122 | hapd->sta_hash[STA_HASH(sta->addr)] = sta; |
| 123 | } |
| 124 | |
| 125 | |
| 126 | static void ap_sta_hash_del(struct hostapd_data *hapd, struct sta_info *sta) |
| 127 | { |
| 128 | struct sta_info *s; |
| 129 | |
| 130 | s = hapd->sta_hash[STA_HASH(sta->addr)]; |
| 131 | if (s == NULL) return; |
| 132 | if (os_memcmp(s->addr, sta->addr, 6) == 0) { |
| 133 | hapd->sta_hash[STA_HASH(sta->addr)] = s->hnext; |
| 134 | return; |
| 135 | } |
| 136 | |
| 137 | while (s->hnext != NULL && |
| 138 | os_memcmp(s->hnext->addr, sta->addr, ETH_ALEN) != 0) |
| 139 | s = s->hnext; |
| 140 | if (s->hnext != NULL) |
| 141 | s->hnext = s->hnext->hnext; |
| 142 | else |
| 143 | wpa_printf(MSG_DEBUG, "AP: could not remove STA " MACSTR |
| 144 | " from hash table", MAC2STR(sta->addr)); |
| 145 | } |
| 146 | |
| 147 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 148 | void ap_sta_ip6addr_del(struct hostapd_data *hapd, struct sta_info *sta) |
| 149 | { |
| 150 | sta_ip6addr_del(hapd, sta); |
| 151 | } |
| 152 | |
| 153 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 154 | void ap_free_sta(struct hostapd_data *hapd, struct sta_info *sta) |
| 155 | { |
| 156 | int set_beacon = 0; |
| 157 | |
| 158 | accounting_sta_stop(hapd, sta); |
| 159 | |
| 160 | /* just in case */ |
| 161 | ap_sta_set_authorized(hapd, sta, 0); |
| 162 | |
| 163 | if (sta->flags & WLAN_STA_WDS) |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 164 | hostapd_set_wds_sta(hapd, NULL, sta->addr, sta->aid, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 165 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 166 | if (sta->ipaddr) |
| 167 | hostapd_drv_br_delete_ip_neigh(hapd, 4, (u8 *) &sta->ipaddr); |
| 168 | ap_sta_ip6addr_del(hapd, sta); |
| 169 | |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 170 | if (!hapd->iface->driver_ap_teardown && |
| 171 | !(sta->flags & WLAN_STA_PREAUTH)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 172 | hostapd_drv_sta_remove(hapd, sta->addr); |
| 173 | |
| 174 | ap_sta_hash_del(hapd, sta); |
| 175 | ap_sta_list_del(hapd, sta); |
| 176 | |
| 177 | if (sta->aid > 0) |
| 178 | hapd->sta_aid[(sta->aid - 1) / 32] &= |
| 179 | ~BIT((sta->aid - 1) % 32); |
| 180 | |
| 181 | hapd->num_sta--; |
| 182 | if (sta->nonerp_set) { |
| 183 | sta->nonerp_set = 0; |
| 184 | hapd->iface->num_sta_non_erp--; |
| 185 | if (hapd->iface->num_sta_non_erp == 0) |
| 186 | set_beacon++; |
| 187 | } |
| 188 | |
| 189 | if (sta->no_short_slot_time_set) { |
| 190 | sta->no_short_slot_time_set = 0; |
| 191 | hapd->iface->num_sta_no_short_slot_time--; |
| 192 | if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G |
| 193 | && hapd->iface->num_sta_no_short_slot_time == 0) |
| 194 | set_beacon++; |
| 195 | } |
| 196 | |
| 197 | if (sta->no_short_preamble_set) { |
| 198 | sta->no_short_preamble_set = 0; |
| 199 | hapd->iface->num_sta_no_short_preamble--; |
| 200 | if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G |
| 201 | && hapd->iface->num_sta_no_short_preamble == 0) |
| 202 | set_beacon++; |
| 203 | } |
| 204 | |
| 205 | if (sta->no_ht_gf_set) { |
| 206 | sta->no_ht_gf_set = 0; |
| 207 | hapd->iface->num_sta_ht_no_gf--; |
| 208 | } |
| 209 | |
| 210 | if (sta->no_ht_set) { |
| 211 | sta->no_ht_set = 0; |
| 212 | hapd->iface->num_sta_no_ht--; |
| 213 | } |
| 214 | |
| 215 | if (sta->ht_20mhz_set) { |
| 216 | sta->ht_20mhz_set = 0; |
| 217 | hapd->iface->num_sta_ht_20mhz--; |
| 218 | } |
| 219 | |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 220 | #ifdef CONFIG_IEEE80211N |
| 221 | ht40_intolerant_remove(hapd->iface, sta); |
| 222 | #endif /* CONFIG_IEEE80211N */ |
| 223 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 224 | #ifdef CONFIG_P2P |
| 225 | if (sta->no_p2p_set) { |
| 226 | sta->no_p2p_set = 0; |
| 227 | hapd->num_sta_no_p2p--; |
| 228 | if (hapd->num_sta_no_p2p == 0) |
| 229 | hostapd_p2p_non_p2p_sta_disconnected(hapd); |
| 230 | } |
| 231 | #endif /* CONFIG_P2P */ |
| 232 | |
| 233 | #if defined(NEED_AP_MLME) && defined(CONFIG_IEEE80211N) |
| 234 | if (hostapd_ht_operation_update(hapd->iface) > 0) |
| 235 | set_beacon++; |
| 236 | #endif /* NEED_AP_MLME && CONFIG_IEEE80211N */ |
| 237 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 238 | #ifdef CONFIG_MESH |
| 239 | if (hapd->mesh_sta_free_cb) |
| 240 | hapd->mesh_sta_free_cb(sta); |
| 241 | #endif /* CONFIG_MESH */ |
| 242 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 243 | if (set_beacon) |
| 244 | ieee802_11_set_beacons(hapd->iface); |
| 245 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 246 | wpa_printf(MSG_DEBUG, "%s: cancel ap_handle_timer for " MACSTR, |
| 247 | __func__, MAC2STR(sta->addr)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 248 | eloop_cancel_timeout(ap_handle_timer, hapd, sta); |
| 249 | eloop_cancel_timeout(ap_handle_session_timer, hapd, sta); |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 250 | eloop_cancel_timeout(ap_handle_session_warning_timer, hapd, sta); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 251 | eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta); |
| 252 | eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta); |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 253 | sae_clear_retransmit_timer(hapd, sta); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 254 | |
| 255 | ieee802_1x_free_station(sta); |
| 256 | wpa_auth_sta_deinit(sta->wpa_sm); |
| 257 | rsn_preauth_free_station(hapd, sta); |
| 258 | #ifndef CONFIG_NO_RADIUS |
Dmitry Shmidt | 9657139 | 2013-10-14 12:54:46 -0700 | [diff] [blame] | 259 | if (hapd->radius) |
| 260 | radius_client_flush_auth(hapd->radius, sta->addr); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 261 | #endif /* CONFIG_NO_RADIUS */ |
| 262 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 263 | os_free(sta->challenge); |
| 264 | |
| 265 | #ifdef CONFIG_IEEE80211W |
| 266 | os_free(sta->sa_query_trans_id); |
| 267 | eloop_cancel_timeout(ap_sa_query_timer, hapd, sta); |
| 268 | #endif /* CONFIG_IEEE80211W */ |
| 269 | |
| 270 | #ifdef CONFIG_P2P |
| 271 | p2p_group_notif_disassoc(hapd->p2p_group, sta->addr); |
| 272 | #endif /* CONFIG_P2P */ |
| 273 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 274 | #ifdef CONFIG_INTERWORKING |
| 275 | if (sta->gas_dialog) { |
| 276 | int i; |
| 277 | for (i = 0; i < GAS_DIALOG_MAX; i++) |
| 278 | gas_serv_dialog_clear(&sta->gas_dialog[i]); |
| 279 | os_free(sta->gas_dialog); |
| 280 | } |
| 281 | #endif /* CONFIG_INTERWORKING */ |
| 282 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 283 | wpabuf_free(sta->wps_ie); |
| 284 | wpabuf_free(sta->p2p_ie); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 285 | wpabuf_free(sta->hs20_ie); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 286 | |
| 287 | os_free(sta->ht_capabilities); |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 288 | os_free(sta->vht_capabilities); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 289 | hostapd_free_psk_list(sta->psk); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 290 | os_free(sta->identity); |
| 291 | os_free(sta->radius_cui); |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 292 | os_free(sta->remediation_url); |
| 293 | wpabuf_free(sta->hs20_deauth_req); |
| 294 | os_free(sta->hs20_session_info_url); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 295 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 296 | #ifdef CONFIG_SAE |
| 297 | sae_clear_data(sta->sae); |
| 298 | os_free(sta->sae); |
| 299 | #endif /* CONFIG_SAE */ |
| 300 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 301 | os_free(sta); |
| 302 | } |
| 303 | |
| 304 | |
| 305 | void hostapd_free_stas(struct hostapd_data *hapd) |
| 306 | { |
| 307 | struct sta_info *sta, *prev; |
| 308 | |
| 309 | sta = hapd->sta_list; |
| 310 | |
| 311 | while (sta) { |
| 312 | prev = sta; |
| 313 | if (sta->flags & WLAN_STA_AUTH) { |
| 314 | mlme_deauthenticate_indication( |
| 315 | hapd, sta, WLAN_REASON_UNSPECIFIED); |
| 316 | } |
| 317 | sta = sta->next; |
| 318 | wpa_printf(MSG_DEBUG, "Removing station " MACSTR, |
| 319 | MAC2STR(prev->addr)); |
| 320 | ap_free_sta(hapd, prev); |
| 321 | } |
| 322 | } |
| 323 | |
| 324 | |
| 325 | /** |
| 326 | * ap_handle_timer - Per STA timer handler |
| 327 | * @eloop_ctx: struct hostapd_data * |
| 328 | * @timeout_ctx: struct sta_info * |
| 329 | * |
| 330 | * This function is called to check station activity and to remove inactive |
| 331 | * stations. |
| 332 | */ |
| 333 | void ap_handle_timer(void *eloop_ctx, void *timeout_ctx) |
| 334 | { |
| 335 | struct hostapd_data *hapd = eloop_ctx; |
| 336 | struct sta_info *sta = timeout_ctx; |
| 337 | unsigned long next_time = 0; |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 338 | int reason; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 339 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 340 | wpa_printf(MSG_DEBUG, "%s: " MACSTR " flags=0x%x timeout_next=%d", |
| 341 | __func__, MAC2STR(sta->addr), sta->flags, |
| 342 | sta->timeout_next); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 343 | if (sta->timeout_next == STA_REMOVE) { |
| 344 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 345 | HOSTAPD_LEVEL_INFO, "deauthenticated due to " |
| 346 | "local deauth request"); |
| 347 | ap_free_sta(hapd, sta); |
| 348 | return; |
| 349 | } |
| 350 | |
| 351 | if ((sta->flags & WLAN_STA_ASSOC) && |
| 352 | (sta->timeout_next == STA_NULLFUNC || |
| 353 | sta->timeout_next == STA_DISASSOC)) { |
| 354 | int inactive_sec; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 355 | /* |
| 356 | * Add random value to timeout so that we don't end up bouncing |
| 357 | * all stations at the same time if we have lots of associated |
| 358 | * stations that are idle (but keep re-associating). |
| 359 | */ |
| 360 | int fuzz = os_random() % 20; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 361 | inactive_sec = hostapd_drv_get_inact_sec(hapd, sta->addr); |
| 362 | if (inactive_sec == -1) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 363 | wpa_msg(hapd->msg_ctx, MSG_DEBUG, |
| 364 | "Check inactivity: Could not " |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 365 | "get station info from kernel driver for " |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 366 | MACSTR, MAC2STR(sta->addr)); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 367 | /* |
| 368 | * The driver may not support this functionality. |
| 369 | * Anyway, try again after the next inactivity timeout, |
| 370 | * but do not disconnect the station now. |
| 371 | */ |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 372 | next_time = hapd->conf->ap_max_inactivity + fuzz; |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame^] | 373 | } else if (inactive_sec == -ENOENT) { |
| 374 | wpa_msg(hapd->msg_ctx, MSG_DEBUG, |
| 375 | "Station " MACSTR " has lost its driver entry", |
| 376 | MAC2STR(sta->addr)); |
| 377 | |
| 378 | if (hapd->conf->skip_inactivity_poll) |
| 379 | sta->timeout_next = STA_DISASSOC; |
| 380 | } else if (inactive_sec < hapd->conf->ap_max_inactivity) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 381 | /* station activity detected; reset timeout state */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 382 | wpa_msg(hapd->msg_ctx, MSG_DEBUG, |
| 383 | "Station " MACSTR " has been active %is ago", |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 384 | MAC2STR(sta->addr), inactive_sec); |
| 385 | sta->timeout_next = STA_NULLFUNC; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 386 | next_time = hapd->conf->ap_max_inactivity + fuzz - |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 387 | inactive_sec; |
| 388 | } else { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 389 | wpa_msg(hapd->msg_ctx, MSG_DEBUG, |
| 390 | "Station " MACSTR " has been " |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 391 | "inactive too long: %d sec, max allowed: %d", |
| 392 | MAC2STR(sta->addr), inactive_sec, |
| 393 | hapd->conf->ap_max_inactivity); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 394 | |
| 395 | if (hapd->conf->skip_inactivity_poll) |
| 396 | sta->timeout_next = STA_DISASSOC; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 397 | } |
| 398 | } |
| 399 | |
| 400 | if ((sta->flags & WLAN_STA_ASSOC) && |
| 401 | sta->timeout_next == STA_DISASSOC && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 402 | !(sta->flags & WLAN_STA_PENDING_POLL) && |
| 403 | !hapd->conf->skip_inactivity_poll) { |
| 404 | wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR |
| 405 | " has ACKed data poll", MAC2STR(sta->addr)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 406 | /* data nullfunc frame poll did not produce TX errors; assume |
| 407 | * station ACKed it */ |
| 408 | sta->timeout_next = STA_NULLFUNC; |
| 409 | next_time = hapd->conf->ap_max_inactivity; |
| 410 | } |
| 411 | |
| 412 | if (next_time) { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 413 | wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout " |
| 414 | "for " MACSTR " (%lu seconds)", |
| 415 | __func__, MAC2STR(sta->addr), next_time); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 416 | eloop_register_timeout(next_time, 0, ap_handle_timer, hapd, |
| 417 | sta); |
| 418 | return; |
| 419 | } |
| 420 | |
| 421 | if (sta->timeout_next == STA_NULLFUNC && |
| 422 | (sta->flags & WLAN_STA_ASSOC)) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 423 | wpa_printf(MSG_DEBUG, " Polling STA"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 424 | sta->flags |= WLAN_STA_PENDING_POLL; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 425 | hostapd_drv_poll_client(hapd, hapd->own_addr, sta->addr, |
| 426 | sta->flags & WLAN_STA_WMM); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 427 | } else if (sta->timeout_next != STA_REMOVE) { |
| 428 | int deauth = sta->timeout_next == STA_DEAUTH; |
| 429 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 430 | wpa_dbg(hapd->msg_ctx, MSG_DEBUG, |
| 431 | "Timeout, sending %s info to STA " MACSTR, |
| 432 | deauth ? "deauthentication" : "disassociation", |
| 433 | MAC2STR(sta->addr)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 434 | |
| 435 | if (deauth) { |
| 436 | hostapd_drv_sta_deauth( |
| 437 | hapd, sta->addr, |
| 438 | WLAN_REASON_PREV_AUTH_NOT_VALID); |
| 439 | } else { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 440 | reason = (sta->timeout_next == STA_DISASSOC) ? |
| 441 | WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY : |
| 442 | WLAN_REASON_PREV_AUTH_NOT_VALID; |
| 443 | |
| 444 | hostapd_drv_sta_disassoc(hapd, sta->addr, reason); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 445 | } |
| 446 | } |
| 447 | |
| 448 | switch (sta->timeout_next) { |
| 449 | case STA_NULLFUNC: |
| 450 | sta->timeout_next = STA_DISASSOC; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 451 | wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout " |
| 452 | "for " MACSTR " (%d seconds - AP_DISASSOC_DELAY)", |
| 453 | __func__, MAC2STR(sta->addr), AP_DISASSOC_DELAY); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 454 | eloop_register_timeout(AP_DISASSOC_DELAY, 0, ap_handle_timer, |
| 455 | hapd, sta); |
| 456 | break; |
| 457 | case STA_DISASSOC: |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 458 | case STA_DISASSOC_FROM_CLI: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 459 | ap_sta_set_authorized(hapd, sta, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 460 | sta->flags &= ~WLAN_STA_ASSOC; |
| 461 | ieee802_1x_notify_port_enabled(sta->eapol_sm, 0); |
| 462 | if (!sta->acct_terminate_cause) |
| 463 | sta->acct_terminate_cause = |
| 464 | RADIUS_ACCT_TERMINATE_CAUSE_IDLE_TIMEOUT; |
| 465 | accounting_sta_stop(hapd, sta); |
| 466 | ieee802_1x_free_station(sta); |
| 467 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 468 | HOSTAPD_LEVEL_INFO, "disassociated due to " |
| 469 | "inactivity"); |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 470 | reason = (sta->timeout_next == STA_DISASSOC) ? |
| 471 | WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY : |
| 472 | WLAN_REASON_PREV_AUTH_NOT_VALID; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 473 | sta->timeout_next = STA_DEAUTH; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 474 | wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout " |
| 475 | "for " MACSTR " (%d seconds - AP_DEAUTH_DELAY)", |
| 476 | __func__, MAC2STR(sta->addr), AP_DEAUTH_DELAY); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 477 | eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer, |
| 478 | hapd, sta); |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 479 | mlme_disassociate_indication(hapd, sta, reason); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 480 | break; |
| 481 | case STA_DEAUTH: |
| 482 | case STA_REMOVE: |
| 483 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 484 | HOSTAPD_LEVEL_INFO, "deauthenticated due to " |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 485 | "inactivity (timer DEAUTH/REMOVE)"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 486 | if (!sta->acct_terminate_cause) |
| 487 | sta->acct_terminate_cause = |
| 488 | RADIUS_ACCT_TERMINATE_CAUSE_IDLE_TIMEOUT; |
| 489 | mlme_deauthenticate_indication( |
| 490 | hapd, sta, |
| 491 | WLAN_REASON_PREV_AUTH_NOT_VALID); |
| 492 | ap_free_sta(hapd, sta); |
| 493 | break; |
| 494 | } |
| 495 | } |
| 496 | |
| 497 | |
| 498 | static void ap_handle_session_timer(void *eloop_ctx, void *timeout_ctx) |
| 499 | { |
| 500 | struct hostapd_data *hapd = eloop_ctx; |
| 501 | struct sta_info *sta = timeout_ctx; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 502 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 503 | if (!(sta->flags & WLAN_STA_AUTH)) { |
| 504 | if (sta->flags & WLAN_STA_GAS) { |
| 505 | wpa_printf(MSG_DEBUG, "GAS: Remove temporary STA " |
| 506 | "entry " MACSTR, MAC2STR(sta->addr)); |
| 507 | ap_free_sta(hapd, sta); |
| 508 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 509 | return; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 510 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 511 | |
Dmitry Shmidt | 818ea48 | 2014-03-10 13:15:21 -0700 | [diff] [blame] | 512 | hostapd_drv_sta_deauth(hapd, sta->addr, |
| 513 | WLAN_REASON_PREV_AUTH_NOT_VALID); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 514 | mlme_deauthenticate_indication(hapd, sta, |
| 515 | WLAN_REASON_PREV_AUTH_NOT_VALID); |
| 516 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 517 | HOSTAPD_LEVEL_INFO, "deauthenticated due to " |
| 518 | "session timeout"); |
| 519 | sta->acct_terminate_cause = |
| 520 | RADIUS_ACCT_TERMINATE_CAUSE_SESSION_TIMEOUT; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 521 | ap_free_sta(hapd, sta); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 522 | } |
| 523 | |
| 524 | |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 525 | void ap_sta_replenish_timeout(struct hostapd_data *hapd, struct sta_info *sta, |
| 526 | u32 session_timeout) |
| 527 | { |
| 528 | if (eloop_replenish_timeout(session_timeout, 0, |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 529 | ap_handle_session_timer, hapd, sta) == 1) { |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 530 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 531 | HOSTAPD_LEVEL_DEBUG, "setting session timeout " |
| 532 | "to %d seconds", session_timeout); |
| 533 | } |
| 534 | } |
| 535 | |
| 536 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 537 | void ap_sta_session_timeout(struct hostapd_data *hapd, struct sta_info *sta, |
| 538 | u32 session_timeout) |
| 539 | { |
| 540 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 541 | HOSTAPD_LEVEL_DEBUG, "setting session timeout to %d " |
| 542 | "seconds", session_timeout); |
| 543 | eloop_cancel_timeout(ap_handle_session_timer, hapd, sta); |
| 544 | eloop_register_timeout(session_timeout, 0, ap_handle_session_timer, |
| 545 | hapd, sta); |
| 546 | } |
| 547 | |
| 548 | |
| 549 | void ap_sta_no_session_timeout(struct hostapd_data *hapd, struct sta_info *sta) |
| 550 | { |
| 551 | eloop_cancel_timeout(ap_handle_session_timer, hapd, sta); |
| 552 | } |
| 553 | |
| 554 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 555 | static void ap_handle_session_warning_timer(void *eloop_ctx, void *timeout_ctx) |
| 556 | { |
| 557 | #ifdef CONFIG_WNM |
| 558 | struct hostapd_data *hapd = eloop_ctx; |
| 559 | struct sta_info *sta = timeout_ctx; |
| 560 | |
| 561 | wpa_printf(MSG_DEBUG, "WNM: Session warning time reached for " MACSTR, |
| 562 | MAC2STR(sta->addr)); |
| 563 | if (sta->hs20_session_info_url == NULL) |
| 564 | return; |
| 565 | |
| 566 | wnm_send_ess_disassoc_imminent(hapd, sta, sta->hs20_session_info_url, |
| 567 | sta->hs20_disassoc_timer); |
| 568 | #endif /* CONFIG_WNM */ |
| 569 | } |
| 570 | |
| 571 | |
| 572 | void ap_sta_session_warning_timeout(struct hostapd_data *hapd, |
| 573 | struct sta_info *sta, int warning_time) |
| 574 | { |
| 575 | eloop_cancel_timeout(ap_handle_session_warning_timer, hapd, sta); |
| 576 | eloop_register_timeout(warning_time, 0, ap_handle_session_warning_timer, |
| 577 | hapd, sta); |
| 578 | } |
| 579 | |
| 580 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 581 | struct sta_info * ap_sta_add(struct hostapd_data *hapd, const u8 *addr) |
| 582 | { |
| 583 | struct sta_info *sta; |
| 584 | |
| 585 | sta = ap_get_sta(hapd, addr); |
| 586 | if (sta) |
| 587 | return sta; |
| 588 | |
| 589 | wpa_printf(MSG_DEBUG, " New STA"); |
| 590 | if (hapd->num_sta >= hapd->conf->max_num_sta) { |
| 591 | /* FIX: might try to remove some old STAs first? */ |
| 592 | wpa_printf(MSG_DEBUG, "no more room for new STAs (%d/%d)", |
| 593 | hapd->num_sta, hapd->conf->max_num_sta); |
| 594 | return NULL; |
| 595 | } |
| 596 | |
| 597 | sta = os_zalloc(sizeof(struct sta_info)); |
| 598 | if (sta == NULL) { |
| 599 | wpa_printf(MSG_ERROR, "malloc failed"); |
| 600 | return NULL; |
| 601 | } |
| 602 | sta->acct_interim_interval = hapd->conf->acct_interim_interval; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 603 | accounting_sta_get_id(hapd, sta); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 604 | |
Dmitry Shmidt | 01904cf | 2013-12-05 11:08:35 -0800 | [diff] [blame] | 605 | if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_INACTIVITY_TIMER)) { |
| 606 | wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout " |
| 607 | "for " MACSTR " (%d seconds - ap_max_inactivity)", |
| 608 | __func__, MAC2STR(addr), |
| 609 | hapd->conf->ap_max_inactivity); |
| 610 | eloop_register_timeout(hapd->conf->ap_max_inactivity, 0, |
| 611 | ap_handle_timer, hapd, sta); |
| 612 | } |
| 613 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 614 | /* initialize STA info data */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 615 | os_memcpy(sta->addr, addr, ETH_ALEN); |
| 616 | sta->next = hapd->sta_list; |
| 617 | hapd->sta_list = sta; |
| 618 | hapd->num_sta++; |
| 619 | ap_sta_hash_add(hapd, sta); |
| 620 | sta->ssid = &hapd->conf->ssid; |
| 621 | ap_sta_remove_in_other_bss(hapd, sta); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 622 | sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ; |
| 623 | dl_list_init(&sta->ip6addr); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 624 | |
| 625 | return sta; |
| 626 | } |
| 627 | |
| 628 | |
| 629 | static int ap_sta_remove(struct hostapd_data *hapd, struct sta_info *sta) |
| 630 | { |
| 631 | ieee802_1x_notify_port_enabled(sta->eapol_sm, 0); |
| 632 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 633 | if (sta->ipaddr) |
| 634 | hostapd_drv_br_delete_ip_neigh(hapd, 4, (u8 *) &sta->ipaddr); |
| 635 | ap_sta_ip6addr_del(hapd, sta); |
| 636 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 637 | wpa_printf(MSG_DEBUG, "Removing STA " MACSTR " from kernel driver", |
| 638 | MAC2STR(sta->addr)); |
| 639 | if (hostapd_drv_sta_remove(hapd, sta->addr) && |
| 640 | sta->flags & WLAN_STA_ASSOC) { |
| 641 | wpa_printf(MSG_DEBUG, "Could not remove station " MACSTR |
| 642 | " from kernel driver.", MAC2STR(sta->addr)); |
| 643 | return -1; |
| 644 | } |
| 645 | return 0; |
| 646 | } |
| 647 | |
| 648 | |
| 649 | static void ap_sta_remove_in_other_bss(struct hostapd_data *hapd, |
| 650 | struct sta_info *sta) |
| 651 | { |
| 652 | struct hostapd_iface *iface = hapd->iface; |
| 653 | size_t i; |
| 654 | |
| 655 | for (i = 0; i < iface->num_bss; i++) { |
| 656 | struct hostapd_data *bss = iface->bss[i]; |
| 657 | struct sta_info *sta2; |
| 658 | /* bss should always be set during operation, but it may be |
| 659 | * NULL during reconfiguration. Assume the STA is not |
| 660 | * associated to another BSS in that case to avoid NULL pointer |
| 661 | * dereferences. */ |
| 662 | if (bss == hapd || bss == NULL) |
| 663 | continue; |
| 664 | sta2 = ap_get_sta(bss, sta->addr); |
| 665 | if (!sta2) |
| 666 | continue; |
| 667 | |
| 668 | ap_sta_disconnect(bss, sta2, sta2->addr, |
| 669 | WLAN_REASON_PREV_AUTH_NOT_VALID); |
| 670 | } |
| 671 | } |
| 672 | |
| 673 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 674 | static void ap_sta_disassoc_cb_timeout(void *eloop_ctx, void *timeout_ctx) |
| 675 | { |
| 676 | struct hostapd_data *hapd = eloop_ctx; |
| 677 | struct sta_info *sta = timeout_ctx; |
| 678 | |
| 679 | ap_sta_remove(hapd, sta); |
| 680 | mlme_disassociate_indication(hapd, sta, sta->disassoc_reason); |
| 681 | } |
| 682 | |
| 683 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 684 | void ap_sta_disassociate(struct hostapd_data *hapd, struct sta_info *sta, |
| 685 | u16 reason) |
| 686 | { |
| 687 | wpa_printf(MSG_DEBUG, "%s: disassociate STA " MACSTR, |
| 688 | hapd->conf->iface, MAC2STR(sta->addr)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 689 | sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ; |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 690 | sta->flags &= ~(WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 691 | ap_sta_set_authorized(hapd, sta, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 692 | sta->timeout_next = STA_DEAUTH; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 693 | wpa_printf(MSG_DEBUG, "%s: reschedule ap_handle_timer timeout " |
| 694 | "for " MACSTR " (%d seconds - " |
| 695 | "AP_MAX_INACTIVITY_AFTER_DISASSOC)", |
| 696 | __func__, MAC2STR(sta->addr), |
| 697 | AP_MAX_INACTIVITY_AFTER_DISASSOC); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 698 | eloop_cancel_timeout(ap_handle_timer, hapd, sta); |
| 699 | eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DISASSOC, 0, |
| 700 | ap_handle_timer, hapd, sta); |
| 701 | accounting_sta_stop(hapd, sta); |
| 702 | ieee802_1x_free_station(sta); |
| 703 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 704 | sta->disassoc_reason = reason; |
| 705 | sta->flags |= WLAN_STA_PENDING_DISASSOC_CB; |
| 706 | eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta); |
| 707 | eloop_register_timeout(hapd->iface->drv_flags & |
| 708 | WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0, |
| 709 | ap_sta_disassoc_cb_timeout, hapd, sta); |
| 710 | } |
| 711 | |
| 712 | |
| 713 | static void ap_sta_deauth_cb_timeout(void *eloop_ctx, void *timeout_ctx) |
| 714 | { |
| 715 | struct hostapd_data *hapd = eloop_ctx; |
| 716 | struct sta_info *sta = timeout_ctx; |
| 717 | |
| 718 | ap_sta_remove(hapd, sta); |
| 719 | mlme_deauthenticate_indication(hapd, sta, sta->deauth_reason); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 720 | } |
| 721 | |
| 722 | |
| 723 | void ap_sta_deauthenticate(struct hostapd_data *hapd, struct sta_info *sta, |
| 724 | u16 reason) |
| 725 | { |
| 726 | wpa_printf(MSG_DEBUG, "%s: deauthenticate STA " MACSTR, |
| 727 | hapd->conf->iface, MAC2STR(sta->addr)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 728 | sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ; |
| 729 | sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 730 | ap_sta_set_authorized(hapd, sta, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 731 | sta->timeout_next = STA_REMOVE; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 732 | wpa_printf(MSG_DEBUG, "%s: reschedule ap_handle_timer timeout " |
| 733 | "for " MACSTR " (%d seconds - " |
| 734 | "AP_MAX_INACTIVITY_AFTER_DEAUTH)", |
| 735 | __func__, MAC2STR(sta->addr), |
| 736 | AP_MAX_INACTIVITY_AFTER_DEAUTH); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 737 | eloop_cancel_timeout(ap_handle_timer, hapd, sta); |
| 738 | eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DEAUTH, 0, |
| 739 | ap_handle_timer, hapd, sta); |
| 740 | accounting_sta_stop(hapd, sta); |
| 741 | ieee802_1x_free_station(sta); |
| 742 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 743 | sta->deauth_reason = reason; |
| 744 | sta->flags |= WLAN_STA_PENDING_DEAUTH_CB; |
| 745 | eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta); |
| 746 | eloop_register_timeout(hapd->iface->drv_flags & |
| 747 | WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0, |
| 748 | ap_sta_deauth_cb_timeout, hapd, sta); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 749 | } |
| 750 | |
| 751 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 752 | #ifdef CONFIG_WPS |
| 753 | int ap_sta_wps_cancel(struct hostapd_data *hapd, |
| 754 | struct sta_info *sta, void *ctx) |
| 755 | { |
| 756 | if (sta && (sta->flags & WLAN_STA_WPS)) { |
| 757 | ap_sta_deauthenticate(hapd, sta, |
| 758 | WLAN_REASON_PREV_AUTH_NOT_VALID); |
| 759 | wpa_printf(MSG_DEBUG, "WPS: %s: Deauth sta=" MACSTR, |
| 760 | __func__, MAC2STR(sta->addr)); |
| 761 | return 1; |
| 762 | } |
| 763 | |
| 764 | return 0; |
| 765 | } |
| 766 | #endif /* CONFIG_WPS */ |
| 767 | |
| 768 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 769 | int ap_sta_bind_vlan(struct hostapd_data *hapd, struct sta_info *sta, |
| 770 | int old_vlanid) |
| 771 | { |
| 772 | #ifndef CONFIG_NO_VLAN |
| 773 | const char *iface; |
| 774 | struct hostapd_vlan *vlan = NULL; |
| 775 | int ret; |
| 776 | |
| 777 | /* |
| 778 | * Do not proceed furthur if the vlan id remains same. We do not want |
| 779 | * duplicate dynamic vlan entries. |
| 780 | */ |
| 781 | if (sta->vlan_id == old_vlanid) |
| 782 | return 0; |
| 783 | |
| 784 | /* |
| 785 | * During 1x reauth, if the vlan id changes, then remove the old id and |
| 786 | * proceed furthur to add the new one. |
| 787 | */ |
| 788 | if (old_vlanid > 0) |
| 789 | vlan_remove_dynamic(hapd, old_vlanid); |
| 790 | |
| 791 | iface = hapd->conf->iface; |
| 792 | if (sta->ssid->vlan[0]) |
| 793 | iface = sta->ssid->vlan; |
| 794 | |
| 795 | if (sta->ssid->dynamic_vlan == DYNAMIC_VLAN_DISABLED) |
| 796 | sta->vlan_id = 0; |
| 797 | else if (sta->vlan_id > 0) { |
Dmitry Shmidt | d5c075b | 2013-08-05 14:36:10 -0700 | [diff] [blame] | 798 | struct hostapd_vlan *wildcard_vlan = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 799 | vlan = hapd->conf->vlan; |
| 800 | while (vlan) { |
Dmitry Shmidt | d5c075b | 2013-08-05 14:36:10 -0700 | [diff] [blame] | 801 | if (vlan->vlan_id == sta->vlan_id) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 802 | break; |
Dmitry Shmidt | d5c075b | 2013-08-05 14:36:10 -0700 | [diff] [blame] | 803 | if (vlan->vlan_id == VLAN_ID_WILDCARD) |
| 804 | wildcard_vlan = vlan; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 805 | vlan = vlan->next; |
| 806 | } |
Dmitry Shmidt | d5c075b | 2013-08-05 14:36:10 -0700 | [diff] [blame] | 807 | if (!vlan) |
| 808 | vlan = wildcard_vlan; |
| 809 | if (vlan) |
| 810 | iface = vlan->ifname; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 811 | } |
| 812 | |
| 813 | if (sta->vlan_id > 0 && vlan == NULL) { |
| 814 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 815 | HOSTAPD_LEVEL_DEBUG, "could not find VLAN for " |
| 816 | "binding station to (vlan_id=%d)", |
| 817 | sta->vlan_id); |
| 818 | return -1; |
| 819 | } else if (sta->vlan_id > 0 && vlan->vlan_id == VLAN_ID_WILDCARD) { |
| 820 | vlan = vlan_add_dynamic(hapd, vlan, sta->vlan_id); |
| 821 | if (vlan == NULL) { |
| 822 | hostapd_logger(hapd, sta->addr, |
| 823 | HOSTAPD_MODULE_IEEE80211, |
| 824 | HOSTAPD_LEVEL_DEBUG, "could not add " |
| 825 | "dynamic VLAN interface for vlan_id=%d", |
| 826 | sta->vlan_id); |
| 827 | return -1; |
| 828 | } |
| 829 | |
| 830 | iface = vlan->ifname; |
| 831 | if (vlan_setup_encryption_dyn(hapd, sta->ssid, iface) != 0) { |
| 832 | hostapd_logger(hapd, sta->addr, |
| 833 | HOSTAPD_MODULE_IEEE80211, |
| 834 | HOSTAPD_LEVEL_DEBUG, "could not " |
| 835 | "configure encryption for dynamic VLAN " |
| 836 | "interface for vlan_id=%d", |
| 837 | sta->vlan_id); |
| 838 | } |
| 839 | |
| 840 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 841 | HOSTAPD_LEVEL_DEBUG, "added new dynamic VLAN " |
| 842 | "interface '%s'", iface); |
| 843 | } else if (vlan && vlan->vlan_id == sta->vlan_id) { |
| 844 | if (sta->vlan_id > 0) { |
| 845 | vlan->dynamic_vlan++; |
| 846 | hostapd_logger(hapd, sta->addr, |
| 847 | HOSTAPD_MODULE_IEEE80211, |
| 848 | HOSTAPD_LEVEL_DEBUG, "updated existing " |
| 849 | "dynamic VLAN interface '%s'", iface); |
| 850 | } |
| 851 | |
| 852 | /* |
| 853 | * Update encryption configuration for statically generated |
| 854 | * VLAN interface. This is only used for static WEP |
| 855 | * configuration for the case where hostapd did not yet know |
| 856 | * which keys are to be used when the interface was added. |
| 857 | */ |
| 858 | if (vlan_setup_encryption_dyn(hapd, sta->ssid, iface) != 0) { |
| 859 | hostapd_logger(hapd, sta->addr, |
| 860 | HOSTAPD_MODULE_IEEE80211, |
| 861 | HOSTAPD_LEVEL_DEBUG, "could not " |
| 862 | "configure encryption for VLAN " |
| 863 | "interface for vlan_id=%d", |
| 864 | sta->vlan_id); |
| 865 | } |
| 866 | } |
| 867 | |
| 868 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 869 | HOSTAPD_LEVEL_DEBUG, "binding station to interface " |
| 870 | "'%s'", iface); |
| 871 | |
| 872 | if (wpa_auth_sta_set_vlan(sta->wpa_sm, sta->vlan_id) < 0) |
| 873 | wpa_printf(MSG_INFO, "Failed to update VLAN-ID for WPA"); |
| 874 | |
| 875 | ret = hostapd_drv_set_sta_vlan(iface, hapd, sta->addr, sta->vlan_id); |
| 876 | if (ret < 0) { |
| 877 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 878 | HOSTAPD_LEVEL_DEBUG, "could not bind the STA " |
| 879 | "entry to vlan_id=%d", sta->vlan_id); |
| 880 | } |
| 881 | return ret; |
| 882 | #else /* CONFIG_NO_VLAN */ |
| 883 | return 0; |
| 884 | #endif /* CONFIG_NO_VLAN */ |
| 885 | } |
| 886 | |
| 887 | |
| 888 | #ifdef CONFIG_IEEE80211W |
| 889 | |
| 890 | int ap_check_sa_query_timeout(struct hostapd_data *hapd, struct sta_info *sta) |
| 891 | { |
| 892 | u32 tu; |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 893 | struct os_reltime now, passed; |
| 894 | os_get_reltime(&now); |
| 895 | os_reltime_sub(&now, &sta->sa_query_start, &passed); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 896 | tu = (passed.sec * 1000000 + passed.usec) / 1024; |
| 897 | if (hapd->conf->assoc_sa_query_max_timeout < tu) { |
| 898 | hostapd_logger(hapd, sta->addr, |
| 899 | HOSTAPD_MODULE_IEEE80211, |
| 900 | HOSTAPD_LEVEL_DEBUG, |
| 901 | "association SA Query timed out"); |
| 902 | sta->sa_query_timed_out = 1; |
| 903 | os_free(sta->sa_query_trans_id); |
| 904 | sta->sa_query_trans_id = NULL; |
| 905 | sta->sa_query_count = 0; |
| 906 | eloop_cancel_timeout(ap_sa_query_timer, hapd, sta); |
| 907 | return 1; |
| 908 | } |
| 909 | |
| 910 | return 0; |
| 911 | } |
| 912 | |
| 913 | |
| 914 | static void ap_sa_query_timer(void *eloop_ctx, void *timeout_ctx) |
| 915 | { |
| 916 | struct hostapd_data *hapd = eloop_ctx; |
| 917 | struct sta_info *sta = timeout_ctx; |
| 918 | unsigned int timeout, sec, usec; |
| 919 | u8 *trans_id, *nbuf; |
| 920 | |
| 921 | if (sta->sa_query_count > 0 && |
| 922 | ap_check_sa_query_timeout(hapd, sta)) |
| 923 | return; |
| 924 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 925 | nbuf = os_realloc_array(sta->sa_query_trans_id, |
| 926 | sta->sa_query_count + 1, |
| 927 | WLAN_SA_QUERY_TR_ID_LEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 928 | if (nbuf == NULL) |
| 929 | return; |
| 930 | if (sta->sa_query_count == 0) { |
| 931 | /* Starting a new SA Query procedure */ |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 932 | os_get_reltime(&sta->sa_query_start); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 933 | } |
| 934 | trans_id = nbuf + sta->sa_query_count * WLAN_SA_QUERY_TR_ID_LEN; |
| 935 | sta->sa_query_trans_id = nbuf; |
| 936 | sta->sa_query_count++; |
| 937 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 938 | if (os_get_random(trans_id, WLAN_SA_QUERY_TR_ID_LEN) < 0) { |
| 939 | /* |
| 940 | * We don't really care which ID is used here, so simply |
| 941 | * hardcode this if the mostly theoretical os_get_random() |
| 942 | * failure happens. |
| 943 | */ |
| 944 | trans_id[0] = 0x12; |
| 945 | trans_id[1] = 0x34; |
| 946 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 947 | |
| 948 | timeout = hapd->conf->assoc_sa_query_retry_timeout; |
| 949 | sec = ((timeout / 1000) * 1024) / 1000; |
| 950 | usec = (timeout % 1000) * 1024; |
| 951 | eloop_register_timeout(sec, usec, ap_sa_query_timer, hapd, sta); |
| 952 | |
| 953 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 954 | HOSTAPD_LEVEL_DEBUG, |
| 955 | "association SA Query attempt %d", sta->sa_query_count); |
| 956 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 957 | ieee802_11_send_sa_query_req(hapd, sta->addr, trans_id); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 958 | } |
| 959 | |
| 960 | |
| 961 | void ap_sta_start_sa_query(struct hostapd_data *hapd, struct sta_info *sta) |
| 962 | { |
| 963 | ap_sa_query_timer(hapd, sta); |
| 964 | } |
| 965 | |
| 966 | |
| 967 | void ap_sta_stop_sa_query(struct hostapd_data *hapd, struct sta_info *sta) |
| 968 | { |
| 969 | eloop_cancel_timeout(ap_sa_query_timer, hapd, sta); |
| 970 | os_free(sta->sa_query_trans_id); |
| 971 | sta->sa_query_trans_id = NULL; |
| 972 | sta->sa_query_count = 0; |
| 973 | } |
| 974 | |
| 975 | #endif /* CONFIG_IEEE80211W */ |
| 976 | |
| 977 | |
| 978 | void ap_sta_set_authorized(struct hostapd_data *hapd, struct sta_info *sta, |
| 979 | int authorized) |
| 980 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 981 | const u8 *dev_addr = NULL; |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 982 | char buf[100]; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 983 | #ifdef CONFIG_P2P |
| 984 | u8 addr[ETH_ALEN]; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 985 | u8 ip_addr_buf[4]; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 986 | #endif /* CONFIG_P2P */ |
| 987 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 988 | if (!!authorized == !!(sta->flags & WLAN_STA_AUTHORIZED)) |
| 989 | return; |
| 990 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 991 | if (authorized) |
| 992 | sta->flags |= WLAN_STA_AUTHORIZED; |
| 993 | else |
| 994 | sta->flags &= ~WLAN_STA_AUTHORIZED; |
| 995 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 996 | #ifdef CONFIG_P2P |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 997 | if (hapd->p2p_group == NULL) { |
| 998 | if (sta->p2p_ie != NULL && |
| 999 | p2p_parse_dev_addr_in_p2p_ie(sta->p2p_ie, addr) == 0) |
| 1000 | dev_addr = addr; |
| 1001 | } else |
| 1002 | dev_addr = p2p_group_get_dev_addr(hapd->p2p_group, sta->addr); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1003 | |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 1004 | if (dev_addr) |
| 1005 | os_snprintf(buf, sizeof(buf), MACSTR " p2p_dev_addr=" MACSTR, |
| 1006 | MAC2STR(sta->addr), MAC2STR(dev_addr)); |
| 1007 | else |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1008 | #endif /* CONFIG_P2P */ |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 1009 | os_snprintf(buf, sizeof(buf), MACSTR, MAC2STR(sta->addr)); |
| 1010 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1011 | if (hapd->sta_authorized_cb) |
| 1012 | hapd->sta_authorized_cb(hapd->sta_authorized_cb_ctx, |
| 1013 | sta->addr, authorized, dev_addr); |
| 1014 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1015 | if (authorized) { |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1016 | char ip_addr[100]; |
| 1017 | ip_addr[0] = '\0'; |
| 1018 | #ifdef CONFIG_P2P |
| 1019 | if (wpa_auth_get_ip_addr(sta->wpa_sm, ip_addr_buf) == 0) { |
| 1020 | os_snprintf(ip_addr, sizeof(ip_addr), |
| 1021 | " ip_addr=%u.%u.%u.%u", |
| 1022 | ip_addr_buf[0], ip_addr_buf[1], |
| 1023 | ip_addr_buf[2], ip_addr_buf[3]); |
| 1024 | } |
| 1025 | #endif /* CONFIG_P2P */ |
| 1026 | |
| 1027 | wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_CONNECTED "%s%s", |
| 1028 | buf, ip_addr); |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 1029 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1030 | if (hapd->msg_ctx_parent && |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 1031 | hapd->msg_ctx_parent != hapd->msg_ctx) |
| 1032 | wpa_msg_no_global(hapd->msg_ctx_parent, MSG_INFO, |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1033 | AP_STA_CONNECTED "%s%s", |
| 1034 | buf, ip_addr); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1035 | } else { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 1036 | wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_DISCONNECTED "%s", buf); |
| 1037 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1038 | if (hapd->msg_ctx_parent && |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 1039 | hapd->msg_ctx_parent != hapd->msg_ctx) |
| 1040 | wpa_msg_no_global(hapd->msg_ctx_parent, MSG_INFO, |
| 1041 | AP_STA_DISCONNECTED "%s", buf); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1042 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1043 | } |
| 1044 | |
| 1045 | |
| 1046 | void ap_sta_disconnect(struct hostapd_data *hapd, struct sta_info *sta, |
| 1047 | const u8 *addr, u16 reason) |
| 1048 | { |
| 1049 | |
| 1050 | if (sta == NULL && addr) |
| 1051 | sta = ap_get_sta(hapd, addr); |
| 1052 | |
| 1053 | if (addr) |
| 1054 | hostapd_drv_sta_deauth(hapd, addr, reason); |
| 1055 | |
| 1056 | if (sta == NULL) |
| 1057 | return; |
| 1058 | ap_sta_set_authorized(hapd, sta, 0); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 1059 | wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH); |
| 1060 | ieee802_1x_notify_port_enabled(sta->eapol_sm, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1061 | sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1062 | wpa_printf(MSG_DEBUG, "%s: reschedule ap_handle_timer timeout " |
| 1063 | "for " MACSTR " (%d seconds - " |
| 1064 | "AP_MAX_INACTIVITY_AFTER_DEAUTH)", |
| 1065 | __func__, MAC2STR(sta->addr), |
| 1066 | AP_MAX_INACTIVITY_AFTER_DEAUTH); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1067 | eloop_cancel_timeout(ap_handle_timer, hapd, sta); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1068 | eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DEAUTH, 0, |
| 1069 | ap_handle_timer, hapd, sta); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1070 | sta->timeout_next = STA_REMOVE; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1071 | |
| 1072 | sta->deauth_reason = reason; |
| 1073 | sta->flags |= WLAN_STA_PENDING_DEAUTH_CB; |
| 1074 | eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta); |
| 1075 | eloop_register_timeout(hapd->iface->drv_flags & |
| 1076 | WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0, |
| 1077 | ap_sta_deauth_cb_timeout, hapd, sta); |
| 1078 | } |
| 1079 | |
| 1080 | |
| 1081 | void ap_sta_deauth_cb(struct hostapd_data *hapd, struct sta_info *sta) |
| 1082 | { |
| 1083 | if (!(sta->flags & WLAN_STA_PENDING_DEAUTH_CB)) { |
| 1084 | wpa_printf(MSG_DEBUG, "Ignore deauth cb for test frame"); |
| 1085 | return; |
| 1086 | } |
| 1087 | sta->flags &= ~WLAN_STA_PENDING_DEAUTH_CB; |
| 1088 | eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta); |
| 1089 | ap_sta_deauth_cb_timeout(hapd, sta); |
| 1090 | } |
| 1091 | |
| 1092 | |
| 1093 | void ap_sta_disassoc_cb(struct hostapd_data *hapd, struct sta_info *sta) |
| 1094 | { |
| 1095 | if (!(sta->flags & WLAN_STA_PENDING_DISASSOC_CB)) { |
| 1096 | wpa_printf(MSG_DEBUG, "Ignore disassoc cb for test frame"); |
| 1097 | return; |
| 1098 | } |
| 1099 | sta->flags &= ~WLAN_STA_PENDING_DISASSOC_CB; |
| 1100 | eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta); |
| 1101 | ap_sta_disassoc_cb_timeout(hapd, sta); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1102 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1103 | |
| 1104 | |
| 1105 | int ap_sta_flags_txt(u32 flags, char *buf, size_t buflen) |
| 1106 | { |
| 1107 | int res; |
| 1108 | |
| 1109 | buf[0] = '\0'; |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame^] | 1110 | res = os_snprintf(buf, buflen, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s", |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1111 | (flags & WLAN_STA_AUTH ? "[AUTH]" : ""), |
| 1112 | (flags & WLAN_STA_ASSOC ? "[ASSOC]" : ""), |
| 1113 | (flags & WLAN_STA_AUTHORIZED ? "[AUTHORIZED]" : ""), |
| 1114 | (flags & WLAN_STA_PENDING_POLL ? "[PENDING_POLL" : |
| 1115 | ""), |
| 1116 | (flags & WLAN_STA_SHORT_PREAMBLE ? |
| 1117 | "[SHORT_PREAMBLE]" : ""), |
| 1118 | (flags & WLAN_STA_PREAUTH ? "[PREAUTH]" : ""), |
| 1119 | (flags & WLAN_STA_WMM ? "[WMM]" : ""), |
| 1120 | (flags & WLAN_STA_MFP ? "[MFP]" : ""), |
| 1121 | (flags & WLAN_STA_WPS ? "[WPS]" : ""), |
| 1122 | (flags & WLAN_STA_MAYBE_WPS ? "[MAYBE_WPS]" : ""), |
| 1123 | (flags & WLAN_STA_WDS ? "[WDS]" : ""), |
| 1124 | (flags & WLAN_STA_NONERP ? "[NonERP]" : ""), |
| 1125 | (flags & WLAN_STA_WPS2 ? "[WPS2]" : ""), |
| 1126 | (flags & WLAN_STA_GAS ? "[GAS]" : ""), |
| 1127 | (flags & WLAN_STA_VHT ? "[VHT]" : ""), |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame^] | 1128 | (flags & WLAN_STA_VENDOR_VHT ? "[VENDOR_VHT]" : ""), |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1129 | (flags & WLAN_STA_WNM_SLEEP_MODE ? |
| 1130 | "[WNM_SLEEP_MODE]" : "")); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1131 | if (os_snprintf_error(buflen, res)) |
| 1132 | res = -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1133 | |
| 1134 | return res; |
| 1135 | } |