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