]>
Commit | Line | Data |
---|---|---|
6fc6879b JM |
1 | /* |
2 | * hostapd / Station table | |
4dc03726 | 3 | * Copyright (c) 2002-2011, Jouni Malinen <j@w1.fi> |
6fc6879b | 4 | * |
0f3d578e JM |
5 | * This software may be distributed under the terms of the BSD license. |
6 | * See README for more details. | |
6fc6879b JM |
7 | */ |
8 | ||
6226e38d | 9 | #include "utils/includes.h" |
6fc6879b | 10 | |
6226e38d JM |
11 | #include "utils/common.h" |
12 | #include "utils/eloop.h" | |
81f4f619 | 13 | #include "common/ieee802_11_defs.h" |
6caaae1e | 14 | #include "common/wpa_ctrl.h" |
a46d72d7 | 15 | #include "common/sae.h" |
bdee6fce JM |
16 | #include "radius/radius.h" |
17 | #include "radius/radius_client.h" | |
18 | #include "drivers/driver.h" | |
8ccbe415 | 19 | #include "p2p/p2p.h" |
6fc6879b | 20 | #include "hostapd.h" |
6fc6879b JM |
21 | #include "accounting.h" |
22 | #include "ieee802_1x.h" | |
23 | #include "ieee802_11.h" | |
f2a14be7 | 24 | #include "ieee802_11_auth.h" |
6226e38d JM |
25 | #include "wpa_auth.h" |
26 | #include "preauth_auth.h" | |
27 | #include "ap_config.h" | |
6fc6879b | 28 | #include "beacon.h" |
6226e38d | 29 | #include "ap_mlme.h" |
6fc6879b | 30 | #include "vlan_init.h" |
aefb53bd | 31 | #include "p2p_hostapd.h" |
cee7d66b | 32 | #include "ap_drv_ops.h" |
dca30c3f | 33 | #include "gas_serv.h" |
6226e38d | 34 | #include "sta_info.h" |
6fc6879b | 35 | |
53f3d6f3 FF |
36 | static void ap_sta_remove_in_other_bss(struct hostapd_data *hapd, |
37 | struct sta_info *sta); | |
6fc6879b | 38 | static void ap_handle_session_timer(void *eloop_ctx, void *timeout_ctx); |
4dc03726 JM |
39 | static void ap_sta_deauth_cb_timeout(void *eloop_ctx, void *timeout_ctx); |
40 | static void ap_sta_disassoc_cb_timeout(void *eloop_ctx, void *timeout_ctx); | |
5d22a1d5 | 41 | #ifdef CONFIG_IEEE80211W |
93b76319 | 42 | static void ap_sa_query_timer(void *eloop_ctx, void *timeout_ctx); |
5d22a1d5 | 43 | #endif /* CONFIG_IEEE80211W */ |
4dc03726 | 44 | static int ap_sta_remove(struct hostapd_data *hapd, struct sta_info *sta); |
6fc6879b JM |
45 | |
46 | int ap_for_each_sta(struct hostapd_data *hapd, | |
47 | int (*cb)(struct hostapd_data *hapd, struct sta_info *sta, | |
48 | void *ctx), | |
49 | void *ctx) | |
50 | { | |
51 | struct sta_info *sta; | |
52 | ||
53 | for (sta = hapd->sta_list; sta; sta = sta->next) { | |
54 | if (cb(hapd, sta, ctx)) | |
55 | return 1; | |
56 | } | |
57 | ||
58 | return 0; | |
59 | } | |
60 | ||
61 | ||
62 | struct sta_info * ap_get_sta(struct hostapd_data *hapd, const u8 *sta) | |
63 | { | |
64 | struct sta_info *s; | |
65 | ||
66 | s = hapd->sta_hash[STA_HASH(sta)]; | |
67 | while (s != NULL && os_memcmp(s->addr, sta, 6) != 0) | |
68 | s = s->hnext; | |
69 | return s; | |
70 | } | |
71 | ||
72 | ||
73 | static void ap_sta_list_del(struct hostapd_data *hapd, struct sta_info *sta) | |
74 | { | |
75 | struct sta_info *tmp; | |
76 | ||
77 | if (hapd->sta_list == sta) { | |
78 | hapd->sta_list = sta->next; | |
79 | return; | |
80 | } | |
81 | ||
82 | tmp = hapd->sta_list; | |
83 | while (tmp != NULL && tmp->next != sta) | |
84 | tmp = tmp->next; | |
85 | if (tmp == NULL) { | |
86 | wpa_printf(MSG_DEBUG, "Could not remove STA " MACSTR " from " | |
87 | "list.", MAC2STR(sta->addr)); | |
88 | } else | |
89 | tmp->next = sta->next; | |
90 | } | |
91 | ||
92 | ||
93 | void ap_sta_hash_add(struct hostapd_data *hapd, struct sta_info *sta) | |
94 | { | |
95 | sta->hnext = hapd->sta_hash[STA_HASH(sta->addr)]; | |
96 | hapd->sta_hash[STA_HASH(sta->addr)] = sta; | |
97 | } | |
98 | ||
99 | ||
100 | static void ap_sta_hash_del(struct hostapd_data *hapd, struct sta_info *sta) | |
101 | { | |
102 | struct sta_info *s; | |
103 | ||
104 | s = hapd->sta_hash[STA_HASH(sta->addr)]; | |
105 | if (s == NULL) return; | |
106 | if (os_memcmp(s->addr, sta->addr, 6) == 0) { | |
107 | hapd->sta_hash[STA_HASH(sta->addr)] = s->hnext; | |
108 | return; | |
109 | } | |
110 | ||
111 | while (s->hnext != NULL && | |
112 | os_memcmp(s->hnext->addr, sta->addr, ETH_ALEN) != 0) | |
113 | s = s->hnext; | |
114 | if (s->hnext != NULL) | |
115 | s->hnext = s->hnext->hnext; | |
116 | else | |
117 | wpa_printf(MSG_DEBUG, "AP: could not remove STA " MACSTR | |
118 | " from hash table", MAC2STR(sta->addr)); | |
119 | } | |
120 | ||
121 | ||
122 | void ap_free_sta(struct hostapd_data *hapd, struct sta_info *sta) | |
123 | { | |
124 | int set_beacon = 0; | |
125 | ||
126 | accounting_sta_stop(hapd, sta); | |
127 | ||
6905dcb1 JB |
128 | /* just in case */ |
129 | ap_sta_set_authorized(hapd, sta, 0); | |
130 | ||
39f42d11 | 131 | if (sta->flags & WLAN_STA_WDS) |
0e8a96a9 | 132 | hostapd_set_wds_sta(hapd, sta->addr, sta->aid, 0); |
53f3d6f3 FF |
133 | |
134 | if (!(sta->flags & WLAN_STA_PREAUTH)) | |
51e2a27a | 135 | hostapd_drv_sta_remove(hapd, sta->addr); |
6fc6879b JM |
136 | |
137 | ap_sta_hash_del(hapd, sta); | |
138 | ap_sta_list_del(hapd, sta); | |
139 | ||
140 | if (sta->aid > 0) | |
2991469c JM |
141 | hapd->sta_aid[(sta->aid - 1) / 32] &= |
142 | ~BIT((sta->aid - 1) % 32); | |
6fc6879b JM |
143 | |
144 | hapd->num_sta--; | |
145 | if (sta->nonerp_set) { | |
146 | sta->nonerp_set = 0; | |
147 | hapd->iface->num_sta_non_erp--; | |
148 | if (hapd->iface->num_sta_non_erp == 0) | |
149 | set_beacon++; | |
150 | } | |
151 | ||
152 | if (sta->no_short_slot_time_set) { | |
153 | sta->no_short_slot_time_set = 0; | |
154 | hapd->iface->num_sta_no_short_slot_time--; | |
155 | if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G | |
156 | && hapd->iface->num_sta_no_short_slot_time == 0) | |
157 | set_beacon++; | |
158 | } | |
159 | ||
160 | if (sta->no_short_preamble_set) { | |
161 | sta->no_short_preamble_set = 0; | |
162 | hapd->iface->num_sta_no_short_preamble--; | |
163 | if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G | |
164 | && hapd->iface->num_sta_no_short_preamble == 0) | |
165 | set_beacon++; | |
166 | } | |
167 | ||
e8ff1e59 JM |
168 | if (sta->no_ht_gf_set) { |
169 | sta->no_ht_gf_set = 0; | |
170 | hapd->iface->num_sta_ht_no_gf--; | |
171 | } | |
172 | ||
173 | if (sta->no_ht_set) { | |
174 | sta->no_ht_set = 0; | |
de9289c8 | 175 | hapd->iface->num_sta_no_ht--; |
e8ff1e59 JM |
176 | } |
177 | ||
178 | if (sta->ht_20mhz_set) { | |
179 | sta->ht_20mhz_set = 0; | |
180 | hapd->iface->num_sta_ht_20mhz--; | |
181 | } | |
de9289c8 | 182 | |
aefb53bd JM |
183 | #ifdef CONFIG_P2P |
184 | if (sta->no_p2p_set) { | |
185 | sta->no_p2p_set = 0; | |
186 | hapd->num_sta_no_p2p--; | |
187 | if (hapd->num_sta_no_p2p == 0) | |
188 | hostapd_p2p_non_p2p_sta_disconnected(hapd); | |
189 | } | |
190 | #endif /* CONFIG_P2P */ | |
191 | ||
d45354be | 192 | #if defined(NEED_AP_MLME) && defined(CONFIG_IEEE80211N) |
de9289c8 JM |
193 | if (hostapd_ht_operation_update(hapd->iface) > 0) |
194 | set_beacon++; | |
d45354be | 195 | #endif /* NEED_AP_MLME && CONFIG_IEEE80211N */ |
de9289c8 | 196 | |
6fc6879b JM |
197 | if (set_beacon) |
198 | ieee802_11_set_beacons(hapd->iface); | |
199 | ||
42ca9845 JM |
200 | wpa_printf(MSG_DEBUG, "%s: cancel ap_handle_timer for " MACSTR, |
201 | __func__, MAC2STR(sta->addr)); | |
6fc6879b JM |
202 | eloop_cancel_timeout(ap_handle_timer, hapd, sta); |
203 | eloop_cancel_timeout(ap_handle_session_timer, hapd, sta); | |
4dc03726 JM |
204 | eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta); |
205 | eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta); | |
6fc6879b JM |
206 | |
207 | ieee802_1x_free_station(sta); | |
208 | wpa_auth_sta_deinit(sta->wpa_sm); | |
209 | rsn_preauth_free_station(hapd, sta); | |
74784010 | 210 | #ifndef CONFIG_NO_RADIUS |
6fc6879b | 211 | radius_client_flush_auth(hapd->radius, sta->addr); |
74784010 | 212 | #endif /* CONFIG_NO_RADIUS */ |
6fc6879b JM |
213 | |
214 | os_free(sta->last_assoc_req); | |
215 | os_free(sta->challenge); | |
5d22a1d5 JM |
216 | |
217 | #ifdef CONFIG_IEEE80211W | |
93b76319 JM |
218 | os_free(sta->sa_query_trans_id); |
219 | eloop_cancel_timeout(ap_sa_query_timer, hapd, sta); | |
5d22a1d5 JM |
220 | #endif /* CONFIG_IEEE80211W */ |
221 | ||
8ccbe415 JM |
222 | #ifdef CONFIG_P2P |
223 | p2p_group_notif_disassoc(hapd->p2p_group, sta->addr); | |
224 | #endif /* CONFIG_P2P */ | |
225 | ||
dca30c3f JK |
226 | #ifdef CONFIG_INTERWORKING |
227 | if (sta->gas_dialog) { | |
228 | int i; | |
229 | for (i = 0; i < GAS_DIALOG_MAX; i++) | |
230 | gas_serv_dialog_clear(&sta->gas_dialog[i]); | |
231 | os_free(sta->gas_dialog); | |
232 | } | |
233 | #endif /* CONFIG_INTERWORKING */ | |
234 | ||
eb76b7e3 | 235 | wpabuf_free(sta->wps_ie); |
b305c684 | 236 | wpabuf_free(sta->p2p_ie); |
f403dcd6 | 237 | wpabuf_free(sta->hs20_ie); |
eb76b7e3 | 238 | |
df84268a | 239 | os_free(sta->ht_capabilities); |
f2a14be7 | 240 | hostapd_free_psk_list(sta->psk); |
2092597f MB |
241 | os_free(sta->identity); |
242 | os_free(sta->radius_cui); | |
df84268a | 243 | |
98efcc41 | 244 | #ifdef CONFIG_SAE |
a46d72d7 | 245 | sae_clear_data(sta->sae); |
98efcc41 JM |
246 | os_free(sta->sae); |
247 | #endif /* CONFIG_SAE */ | |
248 | ||
6fc6879b JM |
249 | os_free(sta); |
250 | } | |
251 | ||
252 | ||
253 | void hostapd_free_stas(struct hostapd_data *hapd) | |
254 | { | |
255 | struct sta_info *sta, *prev; | |
256 | ||
257 | sta = hapd->sta_list; | |
258 | ||
259 | while (sta) { | |
260 | prev = sta; | |
261 | if (sta->flags & WLAN_STA_AUTH) { | |
262 | mlme_deauthenticate_indication( | |
263 | hapd, sta, WLAN_REASON_UNSPECIFIED); | |
264 | } | |
265 | sta = sta->next; | |
266 | wpa_printf(MSG_DEBUG, "Removing station " MACSTR, | |
267 | MAC2STR(prev->addr)); | |
268 | ap_free_sta(hapd, prev); | |
269 | } | |
270 | } | |
271 | ||
272 | ||
1c6e69cc JM |
273 | /** |
274 | * ap_handle_timer - Per STA timer handler | |
275 | * @eloop_ctx: struct hostapd_data * | |
276 | * @timeout_ctx: struct sta_info * | |
277 | * | |
278 | * This function is called to check station activity and to remove inactive | |
279 | * stations. | |
280 | */ | |
6fc6879b JM |
281 | void ap_handle_timer(void *eloop_ctx, void *timeout_ctx) |
282 | { | |
283 | struct hostapd_data *hapd = eloop_ctx; | |
284 | struct sta_info *sta = timeout_ctx; | |
285 | unsigned long next_time = 0; | |
286 | ||
42ca9845 JM |
287 | wpa_printf(MSG_DEBUG, "%s: " MACSTR " flags=0x%x timeout_next=%d", |
288 | __func__, MAC2STR(sta->addr), sta->flags, | |
289 | sta->timeout_next); | |
6fc6879b JM |
290 | if (sta->timeout_next == STA_REMOVE) { |
291 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, | |
292 | HOSTAPD_LEVEL_INFO, "deauthenticated due to " | |
293 | "local deauth request"); | |
294 | ap_free_sta(hapd, sta); | |
295 | return; | |
296 | } | |
297 | ||
298 | if ((sta->flags & WLAN_STA_ASSOC) && | |
299 | (sta->timeout_next == STA_NULLFUNC || | |
300 | sta->timeout_next == STA_DISASSOC)) { | |
301 | int inactive_sec; | |
ce28e279 BG |
302 | /* |
303 | * Add random value to timeout so that we don't end up bouncing | |
304 | * all stations at the same time if we have lots of associated | |
305 | * stations that are idle (but keep re-associating). | |
306 | */ | |
307 | int fuzz = os_random() % 20; | |
51e2a27a | 308 | inactive_sec = hostapd_drv_get_inact_sec(hapd, sta->addr); |
6fc6879b | 309 | if (inactive_sec == -1) { |
3ec1e902 JM |
310 | wpa_msg(hapd->msg_ctx, MSG_DEBUG, |
311 | "Check inactivity: Could not " | |
d5674791 | 312 | "get station info from kernel driver for " |
24d75245 | 313 | MACSTR, MAC2STR(sta->addr)); |
d5674791 JM |
314 | /* |
315 | * The driver may not support this functionality. | |
316 | * Anyway, try again after the next inactivity timeout, | |
317 | * but do not disconnect the station now. | |
318 | */ | |
ce28e279 | 319 | next_time = hapd->conf->ap_max_inactivity + fuzz; |
6fc6879b JM |
320 | } else if (inactive_sec < hapd->conf->ap_max_inactivity && |
321 | sta->flags & WLAN_STA_ASSOC) { | |
322 | /* station activity detected; reset timeout state */ | |
3ec1e902 JM |
323 | wpa_msg(hapd->msg_ctx, MSG_DEBUG, |
324 | "Station " MACSTR " has been active %is ago", | |
24d75245 | 325 | MAC2STR(sta->addr), inactive_sec); |
6fc6879b | 326 | sta->timeout_next = STA_NULLFUNC; |
ce28e279 | 327 | next_time = hapd->conf->ap_max_inactivity + fuzz - |
6fc6879b | 328 | inactive_sec; |
24d75245 | 329 | } else { |
3ec1e902 JM |
330 | wpa_msg(hapd->msg_ctx, MSG_DEBUG, |
331 | "Station " MACSTR " has been " | |
24d75245 BG |
332 | "inactive too long: %d sec, max allowed: %d", |
333 | MAC2STR(sta->addr), inactive_sec, | |
334 | hapd->conf->ap_max_inactivity); | |
ef01fa7b YAP |
335 | |
336 | if (hapd->conf->skip_inactivity_poll) | |
337 | sta->timeout_next = STA_DISASSOC; | |
6fc6879b JM |
338 | } |
339 | } | |
340 | ||
341 | if ((sta->flags & WLAN_STA_ASSOC) && | |
342 | sta->timeout_next == STA_DISASSOC && | |
ef01fa7b YAP |
343 | !(sta->flags & WLAN_STA_PENDING_POLL) && |
344 | !hapd->conf->skip_inactivity_poll) { | |
3ec1e902 JM |
345 | wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR |
346 | " has ACKed data poll", MAC2STR(sta->addr)); | |
6fc6879b JM |
347 | /* data nullfunc frame poll did not produce TX errors; assume |
348 | * station ACKed it */ | |
349 | sta->timeout_next = STA_NULLFUNC; | |
350 | next_time = hapd->conf->ap_max_inactivity; | |
351 | } | |
352 | ||
353 | if (next_time) { | |
42ca9845 JM |
354 | wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout " |
355 | "for " MACSTR " (%lu seconds)", | |
356 | __func__, MAC2STR(sta->addr), next_time); | |
6fc6879b JM |
357 | eloop_register_timeout(next_time, 0, ap_handle_timer, hapd, |
358 | sta); | |
359 | return; | |
360 | } | |
361 | ||
362 | if (sta->timeout_next == STA_NULLFUNC && | |
363 | (sta->flags & WLAN_STA_ASSOC)) { | |
bcf24348 | 364 | wpa_printf(MSG_DEBUG, " Polling STA"); |
6fc6879b | 365 | sta->flags |= WLAN_STA_PENDING_POLL; |
bcf24348 JB |
366 | hostapd_drv_poll_client(hapd, hapd->own_addr, sta->addr, |
367 | sta->flags & WLAN_STA_WMM); | |
6fc6879b JM |
368 | } else if (sta->timeout_next != STA_REMOVE) { |
369 | int deauth = sta->timeout_next == STA_DEAUTH; | |
370 | ||
afcc9ea1 BG |
371 | wpa_dbg(hapd->msg_ctx, MSG_DEBUG, |
372 | "Timeout, sending %s info to STA " MACSTR, | |
373 | deauth ? "deauthentication" : "disassociation", | |
374 | MAC2STR(sta->addr)); | |
6fc6879b JM |
375 | |
376 | if (deauth) { | |
51e2a27a JM |
377 | hostapd_drv_sta_deauth( |
378 | hapd, sta->addr, | |
379 | WLAN_REASON_PREV_AUTH_NOT_VALID); | |
6fc6879b | 380 | } else { |
51e2a27a | 381 | hostapd_drv_sta_disassoc( |
6fc6879b JM |
382 | hapd, sta->addr, |
383 | WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY); | |
384 | } | |
385 | } | |
386 | ||
387 | switch (sta->timeout_next) { | |
388 | case STA_NULLFUNC: | |
389 | sta->timeout_next = STA_DISASSOC; | |
42ca9845 JM |
390 | wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout " |
391 | "for " MACSTR " (%d seconds - AP_DISASSOC_DELAY)", | |
392 | __func__, MAC2STR(sta->addr), AP_DISASSOC_DELAY); | |
6fc6879b JM |
393 | eloop_register_timeout(AP_DISASSOC_DELAY, 0, ap_handle_timer, |
394 | hapd, sta); | |
395 | break; | |
396 | case STA_DISASSOC: | |
ae055af4 | 397 | ap_sta_set_authorized(hapd, sta, 0); |
6fc6879b JM |
398 | sta->flags &= ~WLAN_STA_ASSOC; |
399 | ieee802_1x_notify_port_enabled(sta->eapol_sm, 0); | |
400 | if (!sta->acct_terminate_cause) | |
401 | sta->acct_terminate_cause = | |
402 | RADIUS_ACCT_TERMINATE_CAUSE_IDLE_TIMEOUT; | |
403 | accounting_sta_stop(hapd, sta); | |
404 | ieee802_1x_free_station(sta); | |
405 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, | |
406 | HOSTAPD_LEVEL_INFO, "disassociated due to " | |
407 | "inactivity"); | |
408 | sta->timeout_next = STA_DEAUTH; | |
42ca9845 JM |
409 | wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout " |
410 | "for " MACSTR " (%d seconds - AP_DEAUTH_DELAY)", | |
411 | __func__, MAC2STR(sta->addr), AP_DEAUTH_DELAY); | |
6fc6879b JM |
412 | eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer, |
413 | hapd, sta); | |
414 | mlme_disassociate_indication( | |
415 | hapd, sta, WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY); | |
416 | break; | |
417 | case STA_DEAUTH: | |
418 | case STA_REMOVE: | |
419 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, | |
420 | HOSTAPD_LEVEL_INFO, "deauthenticated due to " | |
afcc9ea1 | 421 | "inactivity (timer DEAUTH/REMOVE)"); |
6fc6879b JM |
422 | if (!sta->acct_terminate_cause) |
423 | sta->acct_terminate_cause = | |
424 | RADIUS_ACCT_TERMINATE_CAUSE_IDLE_TIMEOUT; | |
425 | mlme_deauthenticate_indication( | |
426 | hapd, sta, | |
427 | WLAN_REASON_PREV_AUTH_NOT_VALID); | |
428 | ap_free_sta(hapd, sta); | |
429 | break; | |
430 | } | |
431 | } | |
432 | ||
433 | ||
434 | static void ap_handle_session_timer(void *eloop_ctx, void *timeout_ctx) | |
435 | { | |
436 | struct hostapd_data *hapd = eloop_ctx; | |
437 | struct sta_info *sta = timeout_ctx; | |
438 | u8 addr[ETH_ALEN]; | |
439 | ||
dca30c3f JK |
440 | if (!(sta->flags & WLAN_STA_AUTH)) { |
441 | if (sta->flags & WLAN_STA_GAS) { | |
442 | wpa_printf(MSG_DEBUG, "GAS: Remove temporary STA " | |
443 | "entry " MACSTR, MAC2STR(sta->addr)); | |
444 | ap_free_sta(hapd, sta); | |
445 | } | |
6fc6879b | 446 | return; |
dca30c3f | 447 | } |
6fc6879b JM |
448 | |
449 | mlme_deauthenticate_indication(hapd, sta, | |
450 | WLAN_REASON_PREV_AUTH_NOT_VALID); | |
451 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, | |
452 | HOSTAPD_LEVEL_INFO, "deauthenticated due to " | |
453 | "session timeout"); | |
454 | sta->acct_terminate_cause = | |
455 | RADIUS_ACCT_TERMINATE_CAUSE_SESSION_TIMEOUT; | |
456 | os_memcpy(addr, sta->addr, ETH_ALEN); | |
457 | ap_free_sta(hapd, sta); | |
51e2a27a | 458 | hostapd_drv_sta_deauth(hapd, addr, WLAN_REASON_PREV_AUTH_NOT_VALID); |
6fc6879b JM |
459 | } |
460 | ||
461 | ||
462 | void ap_sta_session_timeout(struct hostapd_data *hapd, struct sta_info *sta, | |
463 | u32 session_timeout) | |
464 | { | |
465 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, | |
466 | HOSTAPD_LEVEL_DEBUG, "setting session timeout to %d " | |
467 | "seconds", session_timeout); | |
468 | eloop_cancel_timeout(ap_handle_session_timer, hapd, sta); | |
469 | eloop_register_timeout(session_timeout, 0, ap_handle_session_timer, | |
470 | hapd, sta); | |
471 | } | |
472 | ||
473 | ||
474 | void ap_sta_no_session_timeout(struct hostapd_data *hapd, struct sta_info *sta) | |
475 | { | |
476 | eloop_cancel_timeout(ap_handle_session_timer, hapd, sta); | |
477 | } | |
478 | ||
479 | ||
480 | struct sta_info * ap_sta_add(struct hostapd_data *hapd, const u8 *addr) | |
481 | { | |
482 | struct sta_info *sta; | |
483 | ||
484 | sta = ap_get_sta(hapd, addr); | |
485 | if (sta) | |
486 | return sta; | |
487 | ||
488 | wpa_printf(MSG_DEBUG, " New STA"); | |
489 | if (hapd->num_sta >= hapd->conf->max_num_sta) { | |
490 | /* FIX: might try to remove some old STAs first? */ | |
491 | wpa_printf(MSG_DEBUG, "no more room for new STAs (%d/%d)", | |
492 | hapd->num_sta, hapd->conf->max_num_sta); | |
493 | return NULL; | |
494 | } | |
495 | ||
496 | sta = os_zalloc(sizeof(struct sta_info)); | |
497 | if (sta == NULL) { | |
498 | wpa_printf(MSG_ERROR, "malloc failed"); | |
499 | return NULL; | |
500 | } | |
5843e1c9 | 501 | sta->acct_interim_interval = hapd->conf->acct_interim_interval; |
8b248611 | 502 | accounting_sta_get_id(hapd, sta); |
6fc6879b JM |
503 | |
504 | /* initialize STA info data */ | |
42ca9845 JM |
505 | wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout " |
506 | "for " MACSTR " (%d seconds - ap_max_inactivity)", | |
507 | __func__, MAC2STR(addr), | |
508 | hapd->conf->ap_max_inactivity); | |
6fc6879b JM |
509 | eloop_register_timeout(hapd->conf->ap_max_inactivity, 0, |
510 | ap_handle_timer, hapd, sta); | |
511 | os_memcpy(sta->addr, addr, ETH_ALEN); | |
512 | sta->next = hapd->sta_list; | |
513 | hapd->sta_list = sta; | |
514 | hapd->num_sta++; | |
515 | ap_sta_hash_add(hapd, sta); | |
516 | sta->ssid = &hapd->conf->ssid; | |
53f3d6f3 | 517 | ap_sta_remove_in_other_bss(hapd, sta); |
6fc6879b JM |
518 | |
519 | return sta; | |
520 | } | |
521 | ||
522 | ||
523 | static int ap_sta_remove(struct hostapd_data *hapd, struct sta_info *sta) | |
524 | { | |
525 | ieee802_1x_notify_port_enabled(sta->eapol_sm, 0); | |
526 | ||
527 | wpa_printf(MSG_DEBUG, "Removing STA " MACSTR " from kernel driver", | |
528 | MAC2STR(sta->addr)); | |
51e2a27a | 529 | if (hostapd_drv_sta_remove(hapd, sta->addr) && |
6fc6879b JM |
530 | sta->flags & WLAN_STA_ASSOC) { |
531 | wpa_printf(MSG_DEBUG, "Could not remove station " MACSTR | |
532 | " from kernel driver.", MAC2STR(sta->addr)); | |
533 | return -1; | |
534 | } | |
535 | return 0; | |
536 | } | |
537 | ||
538 | ||
53f3d6f3 FF |
539 | static void ap_sta_remove_in_other_bss(struct hostapd_data *hapd, |
540 | struct sta_info *sta) | |
6fc6879b JM |
541 | { |
542 | struct hostapd_iface *iface = hapd->iface; | |
543 | size_t i; | |
544 | ||
545 | for (i = 0; i < iface->num_bss; i++) { | |
546 | struct hostapd_data *bss = iface->bss[i]; | |
547 | struct sta_info *sta2; | |
548 | /* bss should always be set during operation, but it may be | |
549 | * NULL during reconfiguration. Assume the STA is not | |
550 | * associated to another BSS in that case to avoid NULL pointer | |
551 | * dereferences. */ | |
552 | if (bss == hapd || bss == NULL) | |
553 | continue; | |
554 | sta2 = ap_get_sta(bss, sta->addr); | |
53f3d6f3 FF |
555 | if (!sta2) |
556 | continue; | |
6fc6879b | 557 | |
53f3d6f3 FF |
558 | ap_sta_disconnect(bss, sta2, sta2->addr, |
559 | WLAN_REASON_PREV_AUTH_NOT_VALID); | |
560 | } | |
6fc6879b JM |
561 | } |
562 | ||
563 | ||
4dc03726 JM |
564 | static void ap_sta_disassoc_cb_timeout(void *eloop_ctx, void *timeout_ctx) |
565 | { | |
566 | struct hostapd_data *hapd = eloop_ctx; | |
567 | struct sta_info *sta = timeout_ctx; | |
568 | ||
569 | ap_sta_remove(hapd, sta); | |
570 | mlme_disassociate_indication(hapd, sta, sta->disassoc_reason); | |
571 | } | |
572 | ||
573 | ||
6fc6879b JM |
574 | void ap_sta_disassociate(struct hostapd_data *hapd, struct sta_info *sta, |
575 | u16 reason) | |
576 | { | |
577 | wpa_printf(MSG_DEBUG, "%s: disassociate STA " MACSTR, | |
578 | hapd->conf->iface, MAC2STR(sta->addr)); | |
ba873c12 | 579 | sta->flags &= ~(WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK); |
4dc03726 | 580 | ap_sta_set_authorized(hapd, sta, 0); |
6fc6879b | 581 | sta->timeout_next = STA_DEAUTH; |
42ca9845 JM |
582 | wpa_printf(MSG_DEBUG, "%s: reschedule ap_handle_timer timeout " |
583 | "for " MACSTR " (%d seconds - " | |
584 | "AP_MAX_INACTIVITY_AFTER_DISASSOC)", | |
585 | __func__, MAC2STR(sta->addr), | |
586 | AP_MAX_INACTIVITY_AFTER_DISASSOC); | |
6fc6879b JM |
587 | eloop_cancel_timeout(ap_handle_timer, hapd, sta); |
588 | eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DISASSOC, 0, | |
589 | ap_handle_timer, hapd, sta); | |
590 | accounting_sta_stop(hapd, sta); | |
591 | ieee802_1x_free_station(sta); | |
592 | ||
4dc03726 | 593 | sta->disassoc_reason = reason; |
cc28ad8c | 594 | sta->flags |= WLAN_STA_PENDING_DISASSOC_CB; |
4dc03726 JM |
595 | eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta); |
596 | eloop_register_timeout(hapd->iface->drv_flags & | |
597 | WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0, | |
598 | ap_sta_disassoc_cb_timeout, hapd, sta); | |
599 | } | |
600 | ||
601 | ||
602 | static void ap_sta_deauth_cb_timeout(void *eloop_ctx, void *timeout_ctx) | |
603 | { | |
604 | struct hostapd_data *hapd = eloop_ctx; | |
605 | struct sta_info *sta = timeout_ctx; | |
606 | ||
607 | ap_sta_remove(hapd, sta); | |
608 | mlme_deauthenticate_indication(hapd, sta, sta->deauth_reason); | |
6fc6879b JM |
609 | } |
610 | ||
611 | ||
612 | void ap_sta_deauthenticate(struct hostapd_data *hapd, struct sta_info *sta, | |
613 | u16 reason) | |
614 | { | |
615 | wpa_printf(MSG_DEBUG, "%s: deauthenticate STA " MACSTR, | |
616 | hapd->conf->iface, MAC2STR(sta->addr)); | |
617 | sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC); | |
4dc03726 | 618 | ap_sta_set_authorized(hapd, sta, 0); |
6fc6879b | 619 | sta->timeout_next = STA_REMOVE; |
42ca9845 JM |
620 | wpa_printf(MSG_DEBUG, "%s: reschedule ap_handle_timer timeout " |
621 | "for " MACSTR " (%d seconds - " | |
622 | "AP_MAX_INACTIVITY_AFTER_DEAUTH)", | |
623 | __func__, MAC2STR(sta->addr), | |
624 | AP_MAX_INACTIVITY_AFTER_DEAUTH); | |
6fc6879b JM |
625 | eloop_cancel_timeout(ap_handle_timer, hapd, sta); |
626 | eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DEAUTH, 0, | |
627 | ap_handle_timer, hapd, sta); | |
628 | accounting_sta_stop(hapd, sta); | |
629 | ieee802_1x_free_station(sta); | |
630 | ||
4dc03726 | 631 | sta->deauth_reason = reason; |
cc28ad8c | 632 | sta->flags |= WLAN_STA_PENDING_DEAUTH_CB; |
4dc03726 JM |
633 | eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta); |
634 | eloop_register_timeout(hapd->iface->drv_flags & | |
635 | WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0, | |
636 | ap_sta_deauth_cb_timeout, hapd, sta); | |
6fc6879b JM |
637 | } |
638 | ||
639 | ||
4c374cde AS |
640 | #ifdef CONFIG_WPS |
641 | int ap_sta_wps_cancel(struct hostapd_data *hapd, | |
642 | struct sta_info *sta, void *ctx) | |
643 | { | |
644 | if (sta && (sta->flags & WLAN_STA_WPS)) { | |
645 | ap_sta_deauthenticate(hapd, sta, | |
646 | WLAN_REASON_PREV_AUTH_NOT_VALID); | |
647 | wpa_printf(MSG_DEBUG, "WPS: %s: Deauth sta=" MACSTR, | |
648 | __func__, MAC2STR(sta->addr)); | |
649 | return 1; | |
650 | } | |
651 | ||
652 | return 0; | |
653 | } | |
654 | #endif /* CONFIG_WPS */ | |
655 | ||
656 | ||
6fc6879b JM |
657 | int ap_sta_bind_vlan(struct hostapd_data *hapd, struct sta_info *sta, |
658 | int old_vlanid) | |
659 | { | |
30b32314 | 660 | #ifndef CONFIG_NO_VLAN |
6fc6879b JM |
661 | const char *iface; |
662 | struct hostapd_vlan *vlan = NULL; | |
4254100d | 663 | int ret; |
6fc6879b JM |
664 | |
665 | /* | |
666 | * Do not proceed furthur if the vlan id remains same. We do not want | |
667 | * duplicate dynamic vlan entries. | |
668 | */ | |
669 | if (sta->vlan_id == old_vlanid) | |
670 | return 0; | |
671 | ||
672 | /* | |
673 | * During 1x reauth, if the vlan id changes, then remove the old id and | |
674 | * proceed furthur to add the new one. | |
675 | */ | |
676 | if (old_vlanid > 0) | |
677 | vlan_remove_dynamic(hapd, old_vlanid); | |
678 | ||
679 | iface = hapd->conf->iface; | |
680 | if (sta->ssid->vlan[0]) | |
681 | iface = sta->ssid->vlan; | |
682 | ||
683 | if (sta->ssid->dynamic_vlan == DYNAMIC_VLAN_DISABLED) | |
684 | sta->vlan_id = 0; | |
685 | else if (sta->vlan_id > 0) { | |
686 | vlan = hapd->conf->vlan; | |
687 | while (vlan) { | |
688 | if (vlan->vlan_id == sta->vlan_id || | |
689 | vlan->vlan_id == VLAN_ID_WILDCARD) { | |
690 | iface = vlan->ifname; | |
691 | break; | |
692 | } | |
693 | vlan = vlan->next; | |
694 | } | |
695 | } | |
696 | ||
697 | if (sta->vlan_id > 0 && vlan == NULL) { | |
698 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, | |
699 | HOSTAPD_LEVEL_DEBUG, "could not find VLAN for " | |
700 | "binding station to (vlan_id=%d)", | |
701 | sta->vlan_id); | |
702 | return -1; | |
703 | } else if (sta->vlan_id > 0 && vlan->vlan_id == VLAN_ID_WILDCARD) { | |
704 | vlan = vlan_add_dynamic(hapd, vlan, sta->vlan_id); | |
705 | if (vlan == NULL) { | |
706 | hostapd_logger(hapd, sta->addr, | |
707 | HOSTAPD_MODULE_IEEE80211, | |
708 | HOSTAPD_LEVEL_DEBUG, "could not add " | |
709 | "dynamic VLAN interface for vlan_id=%d", | |
710 | sta->vlan_id); | |
711 | return -1; | |
712 | } | |
713 | ||
714 | iface = vlan->ifname; | |
715 | if (vlan_setup_encryption_dyn(hapd, sta->ssid, iface) != 0) { | |
716 | hostapd_logger(hapd, sta->addr, | |
717 | HOSTAPD_MODULE_IEEE80211, | |
718 | HOSTAPD_LEVEL_DEBUG, "could not " | |
719 | "configure encryption for dynamic VLAN " | |
720 | "interface for vlan_id=%d", | |
721 | sta->vlan_id); | |
722 | } | |
723 | ||
724 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, | |
725 | HOSTAPD_LEVEL_DEBUG, "added new dynamic VLAN " | |
726 | "interface '%s'", iface); | |
727 | } else if (vlan && vlan->vlan_id == sta->vlan_id) { | |
728 | if (sta->vlan_id > 0) { | |
729 | vlan->dynamic_vlan++; | |
730 | hostapd_logger(hapd, sta->addr, | |
731 | HOSTAPD_MODULE_IEEE80211, | |
732 | HOSTAPD_LEVEL_DEBUG, "updated existing " | |
733 | "dynamic VLAN interface '%s'", iface); | |
734 | } | |
735 | ||
736 | /* | |
737 | * Update encryption configuration for statically generated | |
738 | * VLAN interface. This is only used for static WEP | |
739 | * configuration for the case where hostapd did not yet know | |
740 | * which keys are to be used when the interface was added. | |
741 | */ | |
742 | if (vlan_setup_encryption_dyn(hapd, sta->ssid, iface) != 0) { | |
743 | hostapd_logger(hapd, sta->addr, | |
744 | HOSTAPD_MODULE_IEEE80211, | |
745 | HOSTAPD_LEVEL_DEBUG, "could not " | |
746 | "configure encryption for VLAN " | |
747 | "interface for vlan_id=%d", | |
748 | sta->vlan_id); | |
749 | } | |
750 | } | |
751 | ||
752 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, | |
753 | HOSTAPD_LEVEL_DEBUG, "binding station to interface " | |
754 | "'%s'", iface); | |
755 | ||
756 | if (wpa_auth_sta_set_vlan(sta->wpa_sm, sta->vlan_id) < 0) | |
757 | wpa_printf(MSG_INFO, "Failed to update VLAN-ID for WPA"); | |
758 | ||
51e2a27a | 759 | ret = hostapd_drv_set_sta_vlan(iface, hapd, sta->addr, sta->vlan_id); |
4254100d JM |
760 | if (ret < 0) { |
761 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, | |
762 | HOSTAPD_LEVEL_DEBUG, "could not bind the STA " | |
763 | "entry to vlan_id=%d", sta->vlan_id); | |
764 | } | |
765 | return ret; | |
30b32314 JM |
766 | #else /* CONFIG_NO_VLAN */ |
767 | return 0; | |
768 | #endif /* CONFIG_NO_VLAN */ | |
6fc6879b | 769 | } |
5d22a1d5 JM |
770 | |
771 | ||
772 | #ifdef CONFIG_IEEE80211W | |
773 | ||
45c94154 | 774 | int ap_check_sa_query_timeout(struct hostapd_data *hapd, struct sta_info *sta) |
5d22a1d5 | 775 | { |
45c94154 JM |
776 | u32 tu; |
777 | struct os_time now, passed; | |
778 | os_get_time(&now); | |
779 | os_time_sub(&now, &sta->sa_query_start, &passed); | |
780 | tu = (passed.sec * 1000000 + passed.usec) / 1024; | |
781 | if (hapd->conf->assoc_sa_query_max_timeout < tu) { | |
782 | hostapd_logger(hapd, sta->addr, | |
783 | HOSTAPD_MODULE_IEEE80211, | |
5d22a1d5 | 784 | HOSTAPD_LEVEL_DEBUG, |
93b76319 JM |
785 | "association SA Query timed out"); |
786 | sta->sa_query_timed_out = 1; | |
787 | os_free(sta->sa_query_trans_id); | |
788 | sta->sa_query_trans_id = NULL; | |
789 | sta->sa_query_count = 0; | |
45c94154 JM |
790 | eloop_cancel_timeout(ap_sa_query_timer, hapd, sta); |
791 | return 1; | |
5d22a1d5 JM |
792 | } |
793 | ||
45c94154 JM |
794 | return 0; |
795 | } | |
796 | ||
797 | ||
798 | static void ap_sa_query_timer(void *eloop_ctx, void *timeout_ctx) | |
799 | { | |
800 | struct hostapd_data *hapd = eloop_ctx; | |
801 | struct sta_info *sta = timeout_ctx; | |
802 | unsigned int timeout, sec, usec; | |
803 | u8 *trans_id, *nbuf; | |
804 | ||
805 | if (sta->sa_query_count > 0 && | |
806 | ap_check_sa_query_timeout(hapd, sta)) | |
807 | return; | |
808 | ||
067ffa26 JM |
809 | nbuf = os_realloc_array(sta->sa_query_trans_id, |
810 | sta->sa_query_count + 1, | |
811 | WLAN_SA_QUERY_TR_ID_LEN); | |
5d22a1d5 JM |
812 | if (nbuf == NULL) |
813 | return; | |
45c94154 JM |
814 | if (sta->sa_query_count == 0) { |
815 | /* Starting a new SA Query procedure */ | |
816 | os_get_time(&sta->sa_query_start); | |
817 | } | |
93b76319 JM |
818 | trans_id = nbuf + sta->sa_query_count * WLAN_SA_QUERY_TR_ID_LEN; |
819 | sta->sa_query_trans_id = nbuf; | |
820 | sta->sa_query_count++; | |
5d22a1d5 | 821 | |
93b76319 | 822 | os_get_random(trans_id, WLAN_SA_QUERY_TR_ID_LEN); |
5d22a1d5 | 823 | |
45c94154 JM |
824 | timeout = hapd->conf->assoc_sa_query_retry_timeout; |
825 | sec = ((timeout / 1000) * 1024) / 1000; | |
826 | usec = (timeout % 1000) * 1024; | |
827 | eloop_register_timeout(sec, usec, ap_sa_query_timer, hapd, sta); | |
828 | ||
5d22a1d5 JM |
829 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
830 | HOSTAPD_LEVEL_DEBUG, | |
93b76319 | 831 | "association SA Query attempt %d", sta->sa_query_count); |
5d22a1d5 | 832 | |
93b76319 | 833 | ieee802_11_send_sa_query_req(hapd, sta->addr, trans_id); |
5d22a1d5 JM |
834 | } |
835 | ||
836 | ||
93b76319 | 837 | void ap_sta_start_sa_query(struct hostapd_data *hapd, struct sta_info *sta) |
5d22a1d5 | 838 | { |
93b76319 | 839 | ap_sa_query_timer(hapd, sta); |
5d22a1d5 JM |
840 | } |
841 | ||
842 | ||
93b76319 | 843 | void ap_sta_stop_sa_query(struct hostapd_data *hapd, struct sta_info *sta) |
5d22a1d5 | 844 | { |
93b76319 JM |
845 | eloop_cancel_timeout(ap_sa_query_timer, hapd, sta); |
846 | os_free(sta->sa_query_trans_id); | |
847 | sta->sa_query_trans_id = NULL; | |
848 | sta->sa_query_count = 0; | |
5d22a1d5 JM |
849 | } |
850 | ||
851 | #endif /* CONFIG_IEEE80211W */ | |
45cefa0b JM |
852 | |
853 | ||
6905dcb1 JB |
854 | void ap_sta_set_authorized(struct hostapd_data *hapd, struct sta_info *sta, |
855 | int authorized) | |
856 | { | |
10cc6c88 | 857 | const u8 *dev_addr = NULL; |
7793c959 | 858 | char buf[100]; |
c2d76aa6 MH |
859 | #ifdef CONFIG_P2P |
860 | u8 addr[ETH_ALEN]; | |
861 | #endif /* CONFIG_P2P */ | |
862 | ||
6905dcb1 JB |
863 | if (!!authorized == !!(sta->flags & WLAN_STA_AUTHORIZED)) |
864 | return; | |
865 | ||
ae055af4 | 866 | #ifdef CONFIG_P2P |
c2d76aa6 MH |
867 | if (hapd->p2p_group == NULL) { |
868 | if (sta->p2p_ie != NULL && | |
869 | p2p_parse_dev_addr_in_p2p_ie(sta->p2p_ie, addr) == 0) | |
870 | dev_addr = addr; | |
871 | } else | |
872 | dev_addr = p2p_group_get_dev_addr(hapd->p2p_group, sta->addr); | |
ae055af4 | 873 | #endif /* CONFIG_P2P */ |
10cc6c88 | 874 | |
7793c959 JM |
875 | if (dev_addr) |
876 | os_snprintf(buf, sizeof(buf), MACSTR " p2p_dev_addr=" MACSTR, | |
877 | MAC2STR(sta->addr), MAC2STR(dev_addr)); | |
878 | else | |
879 | os_snprintf(buf, sizeof(buf), MACSTR, MAC2STR(sta->addr)); | |
880 | ||
10cc6c88 | 881 | if (authorized) { |
7793c959 JM |
882 | wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_CONNECTED "%s", buf); |
883 | ||
8a5e75f6 | 884 | if (hapd->msg_ctx_parent && |
7793c959 | 885 | hapd->msg_ctx_parent != hapd->msg_ctx) |
8a5e75f6 | 886 | wpa_msg(hapd->msg_ctx_parent, MSG_INFO, |
7793c959 | 887 | AP_STA_CONNECTED "%s", buf); |
ae055af4 | 888 | |
6905dcb1 | 889 | sta->flags |= WLAN_STA_AUTHORIZED; |
ae055af4 | 890 | } else { |
7793c959 JM |
891 | wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_DISCONNECTED "%s", buf); |
892 | ||
8a5e75f6 | 893 | if (hapd->msg_ctx_parent && |
7793c959 | 894 | hapd->msg_ctx_parent != hapd->msg_ctx) |
10cc6c88 | 895 | wpa_msg(hapd->msg_ctx_parent, MSG_INFO, |
7793c959 JM |
896 | AP_STA_DISCONNECTED "%s", buf); |
897 | ||
6905dcb1 | 898 | sta->flags &= ~WLAN_STA_AUTHORIZED; |
ae055af4 | 899 | } |
0661eed2 JB |
900 | |
901 | if (hapd->sta_authorized_cb) | |
902 | hapd->sta_authorized_cb(hapd->sta_authorized_cb_ctx, | |
fbdcfd57 | 903 | sta->addr, authorized, dev_addr); |
6905dcb1 JB |
904 | } |
905 | ||
906 | ||
45cefa0b JM |
907 | void ap_sta_disconnect(struct hostapd_data *hapd, struct sta_info *sta, |
908 | const u8 *addr, u16 reason) | |
909 | { | |
910 | ||
911 | if (sta == NULL && addr) | |
912 | sta = ap_get_sta(hapd, addr); | |
913 | ||
914 | if (addr) | |
51e2a27a | 915 | hostapd_drv_sta_deauth(hapd, addr, reason); |
45cefa0b JM |
916 | |
917 | if (sta == NULL) | |
918 | return; | |
6905dcb1 | 919 | ap_sta_set_authorized(hapd, sta, 0); |
ceb997f3 JM |
920 | wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH); |
921 | ieee802_1x_notify_port_enabled(sta->eapol_sm, 0); | |
6905dcb1 | 922 | sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC); |
42ca9845 JM |
923 | wpa_printf(MSG_DEBUG, "%s: reschedule ap_handle_timer timeout " |
924 | "for " MACSTR " (%d seconds - " | |
925 | "AP_MAX_INACTIVITY_AFTER_DEAUTH)", | |
926 | __func__, MAC2STR(sta->addr), | |
927 | AP_MAX_INACTIVITY_AFTER_DEAUTH); | |
45cefa0b | 928 | eloop_cancel_timeout(ap_handle_timer, hapd, sta); |
4dc03726 JM |
929 | eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DEAUTH, 0, |
930 | ap_handle_timer, hapd, sta); | |
45cefa0b | 931 | sta->timeout_next = STA_REMOVE; |
4dc03726 JM |
932 | |
933 | sta->deauth_reason = reason; | |
cc28ad8c | 934 | sta->flags |= WLAN_STA_PENDING_DEAUTH_CB; |
4dc03726 JM |
935 | eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta); |
936 | eloop_register_timeout(hapd->iface->drv_flags & | |
937 | WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0, | |
938 | ap_sta_deauth_cb_timeout, hapd, sta); | |
939 | } | |
940 | ||
941 | ||
942 | void ap_sta_deauth_cb(struct hostapd_data *hapd, struct sta_info *sta) | |
943 | { | |
cc28ad8c JM |
944 | if (!(sta->flags & WLAN_STA_PENDING_DEAUTH_CB)) { |
945 | wpa_printf(MSG_DEBUG, "Ignore deauth cb for test frame"); | |
946 | return; | |
947 | } | |
948 | sta->flags &= ~WLAN_STA_PENDING_DEAUTH_CB; | |
4dc03726 JM |
949 | eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta); |
950 | ap_sta_deauth_cb_timeout(hapd, sta); | |
951 | } | |
952 | ||
953 | ||
954 | void ap_sta_disassoc_cb(struct hostapd_data *hapd, struct sta_info *sta) | |
955 | { | |
cc28ad8c JM |
956 | if (!(sta->flags & WLAN_STA_PENDING_DISASSOC_CB)) { |
957 | wpa_printf(MSG_DEBUG, "Ignore disassoc cb for test frame"); | |
958 | return; | |
959 | } | |
960 | sta->flags &= ~WLAN_STA_PENDING_DISASSOC_CB; | |
961 | eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta); | |
962 | ap_sta_disassoc_cb_timeout(hapd, sta); | |
45cefa0b | 963 | } |