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