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