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