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