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