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