hostapd: Update vendor branch to 0.6.10
[dragonfly.git] / contrib / hostapd / hostapd / sta_info.c
bloba139ba9bdf94cf25b58b2adc1c7a6af070a6d940
1 /*
2 * hostapd / Station table
3 * Copyright (c) 2002-2008, Jouni Malinen <j@w1.fi>
4 * Copyright (c) 2007-2008, Intel Corporation
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
10 * Alternatively, this software may be distributed under the terms of BSD
11 * license.
13 * See README and COPYING for more details.
16 #include "includes.h"
18 #include "hostapd.h"
19 #include "sta_info.h"
20 #include "eloop.h"
21 #include "accounting.h"
22 #include "ieee802_1x.h"
23 #include "ieee802_11.h"
24 #include "radius/radius.h"
25 #include "wpa.h"
26 #include "preauth.h"
27 #include "radius/radius_client.h"
28 #include "driver.h"
29 #include "beacon.h"
30 #include "hw_features.h"
31 #include "mlme.h"
32 #include "vlan_init.h"
34 static int ap_sta_in_other_bss(struct hostapd_data *hapd,
35 struct sta_info *sta, u32 flags);
36 static void ap_handle_session_timer(void *eloop_ctx, void *timeout_ctx);
37 #ifdef CONFIG_IEEE80211W
38 static void ap_sa_query_timer(void *eloop_ctx, void *timeout_ctx);
39 #endif /* CONFIG_IEEE80211W */
41 int ap_for_each_sta(struct hostapd_data *hapd,
42 int (*cb)(struct hostapd_data *hapd, struct sta_info *sta,
43 void *ctx),
44 void *ctx)
46 struct sta_info *sta;
48 for (sta = hapd->sta_list; sta; sta = sta->next) {
49 if (cb(hapd, sta, ctx))
50 return 1;
53 return 0;
57 struct sta_info * ap_get_sta(struct hostapd_data *hapd, const u8 *sta)
59 struct sta_info *s;
61 s = hapd->sta_hash[STA_HASH(sta)];
62 while (s != NULL && os_memcmp(s->addr, sta, 6) != 0)
63 s = s->hnext;
64 return s;
68 static void ap_sta_list_del(struct hostapd_data *hapd, struct sta_info *sta)
70 struct sta_info *tmp;
72 if (hapd->sta_list == sta) {
73 hapd->sta_list = sta->next;
74 return;
77 tmp = hapd->sta_list;
78 while (tmp != NULL && tmp->next != sta)
79 tmp = tmp->next;
80 if (tmp == NULL) {
81 wpa_printf(MSG_DEBUG, "Could not remove STA " MACSTR " from "
82 "list.", MAC2STR(sta->addr));
83 } else
84 tmp->next = sta->next;
88 void ap_sta_hash_add(struct hostapd_data *hapd, struct sta_info *sta)
90 sta->hnext = hapd->sta_hash[STA_HASH(sta->addr)];
91 hapd->sta_hash[STA_HASH(sta->addr)] = sta;
95 static void ap_sta_hash_del(struct hostapd_data *hapd, struct sta_info *sta)
97 struct sta_info *s;
99 s = hapd->sta_hash[STA_HASH(sta->addr)];
100 if (s == NULL) return;
101 if (os_memcmp(s->addr, sta->addr, 6) == 0) {
102 hapd->sta_hash[STA_HASH(sta->addr)] = s->hnext;
103 return;
106 while (s->hnext != NULL &&
107 os_memcmp(s->hnext->addr, sta->addr, ETH_ALEN) != 0)
108 s = s->hnext;
109 if (s->hnext != NULL)
110 s->hnext = s->hnext->hnext;
111 else
112 wpa_printf(MSG_DEBUG, "AP: could not remove STA " MACSTR
113 " from hash table", MAC2STR(sta->addr));
117 void ap_free_sta(struct hostapd_data *hapd, struct sta_info *sta)
119 int set_beacon = 0;
121 accounting_sta_stop(hapd, sta);
123 if (!ap_sta_in_other_bss(hapd, sta, WLAN_STA_ASSOC) &&
124 !(sta->flags & WLAN_STA_PREAUTH))
125 hostapd_sta_remove(hapd, sta->addr);
127 ap_sta_hash_del(hapd, sta);
128 ap_sta_list_del(hapd, sta);
130 if (sta->aid > 0)
131 hapd->sta_aid[sta->aid - 1] = NULL;
133 hapd->num_sta--;
134 if (sta->nonerp_set) {
135 sta->nonerp_set = 0;
136 hapd->iface->num_sta_non_erp--;
137 if (hapd->iface->num_sta_non_erp == 0)
138 set_beacon++;
141 if (sta->no_short_slot_time_set) {
142 sta->no_short_slot_time_set = 0;
143 hapd->iface->num_sta_no_short_slot_time--;
144 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G
145 && hapd->iface->num_sta_no_short_slot_time == 0)
146 set_beacon++;
149 if (sta->no_short_preamble_set) {
150 sta->no_short_preamble_set = 0;
151 hapd->iface->num_sta_no_short_preamble--;
152 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G
153 && hapd->iface->num_sta_no_short_preamble == 0)
154 set_beacon++;
157 #ifdef CONFIG_IEEE80211N
158 if (sta->no_ht_gf_set) {
159 sta->no_ht_gf_set = 0;
160 hapd->iface->num_sta_ht_no_gf--;
163 if (sta->no_ht_set) {
164 sta->no_ht_set = 0;
165 hapd->iface->num_sta_no_ht--;
168 if (sta->ht_20mhz_set) {
169 sta->ht_20mhz_set = 0;
170 hapd->iface->num_sta_ht_20mhz--;
173 if (hostapd_ht_operation_update(hapd->iface) > 0)
174 set_beacon++;
175 #endif /* CONFIG_IEEE80211N */
177 if (set_beacon)
178 ieee802_11_set_beacons(hapd->iface);
180 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
181 eloop_cancel_timeout(ap_handle_session_timer, hapd, sta);
183 ieee802_1x_free_station(sta);
184 wpa_auth_sta_deinit(sta->wpa_sm);
185 rsn_preauth_free_station(hapd, sta);
186 radius_client_flush_auth(hapd->radius, sta->addr);
188 os_free(sta->last_assoc_req);
189 os_free(sta->challenge);
191 #ifdef CONFIG_IEEE80211W
192 os_free(sta->sa_query_trans_id);
193 eloop_cancel_timeout(ap_sa_query_timer, hapd, sta);
194 #endif /* CONFIG_IEEE80211W */
196 wpabuf_free(sta->wps_ie);
198 os_free(sta);
202 void hostapd_free_stas(struct hostapd_data *hapd)
204 struct sta_info *sta, *prev;
206 sta = hapd->sta_list;
208 while (sta) {
209 prev = sta;
210 if (sta->flags & WLAN_STA_AUTH) {
211 mlme_deauthenticate_indication(
212 hapd, sta, WLAN_REASON_UNSPECIFIED);
214 sta = sta->next;
215 wpa_printf(MSG_DEBUG, "Removing station " MACSTR,
216 MAC2STR(prev->addr));
217 ap_free_sta(hapd, prev);
223 * ap_handle_timer - Per STA timer handler
224 * @eloop_ctx: struct hostapd_data *
225 * @timeout_ctx: struct sta_info *
227 * This function is called to check station activity and to remove inactive
228 * stations.
230 void ap_handle_timer(void *eloop_ctx, void *timeout_ctx)
232 struct hostapd_data *hapd = eloop_ctx;
233 struct sta_info *sta = timeout_ctx;
234 unsigned long next_time = 0;
236 if (sta->timeout_next == STA_REMOVE) {
237 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
238 HOSTAPD_LEVEL_INFO, "deauthenticated due to "
239 "local deauth request");
240 ap_free_sta(hapd, sta);
241 return;
244 if ((sta->flags & WLAN_STA_ASSOC) &&
245 (sta->timeout_next == STA_NULLFUNC ||
246 sta->timeout_next == STA_DISASSOC)) {
247 int inactive_sec;
248 wpa_printf(MSG_DEBUG, "Checking STA " MACSTR " inactivity:",
249 MAC2STR(sta->addr));
250 inactive_sec = hostapd_get_inact_sec(hapd, sta->addr);
251 if (inactive_sec == -1) {
252 wpa_printf(MSG_DEBUG, "Could not get station info "
253 "from kernel driver for " MACSTR ".",
254 MAC2STR(sta->addr));
255 } else if (inactive_sec < hapd->conf->ap_max_inactivity &&
256 sta->flags & WLAN_STA_ASSOC) {
257 /* station activity detected; reset timeout state */
258 wpa_printf(MSG_DEBUG, " Station has been active");
259 sta->timeout_next = STA_NULLFUNC;
260 next_time = hapd->conf->ap_max_inactivity -
261 inactive_sec;
265 if ((sta->flags & WLAN_STA_ASSOC) &&
266 sta->timeout_next == STA_DISASSOC &&
267 !(sta->flags & WLAN_STA_PENDING_POLL)) {
268 wpa_printf(MSG_DEBUG, " Station has ACKed data poll");
269 /* data nullfunc frame poll did not produce TX errors; assume
270 * station ACKed it */
271 sta->timeout_next = STA_NULLFUNC;
272 next_time = hapd->conf->ap_max_inactivity;
275 if (next_time) {
276 eloop_register_timeout(next_time, 0, ap_handle_timer, hapd,
277 sta);
278 return;
281 if (sta->timeout_next == STA_NULLFUNC &&
282 (sta->flags & WLAN_STA_ASSOC)) {
283 /* send data frame to poll STA and check whether this frame
284 * is ACKed */
285 struct ieee80211_hdr hdr;
287 wpa_printf(MSG_DEBUG, " Polling STA with data frame");
288 sta->flags |= WLAN_STA_PENDING_POLL;
290 #ifndef CONFIG_NATIVE_WINDOWS
291 os_memset(&hdr, 0, sizeof(hdr));
292 if (hapd->driver &&
293 os_strcmp(hapd->driver->name, "hostap") == 0) {
295 * WLAN_FC_STYPE_NULLFUNC would be more appropriate,
296 * but it is apparently not retried so TX Exc events
297 * are not received for it.
299 hdr.frame_control =
300 IEEE80211_FC(WLAN_FC_TYPE_DATA,
301 WLAN_FC_STYPE_DATA);
302 } else {
303 hdr.frame_control =
304 IEEE80211_FC(WLAN_FC_TYPE_DATA,
305 WLAN_FC_STYPE_NULLFUNC);
308 hdr.frame_control |= host_to_le16(WLAN_FC_FROMDS);
309 os_memcpy(hdr.IEEE80211_DA_FROMDS, sta->addr, ETH_ALEN);
310 os_memcpy(hdr.IEEE80211_BSSID_FROMDS, hapd->own_addr,
311 ETH_ALEN);
312 os_memcpy(hdr.IEEE80211_SA_FROMDS, hapd->own_addr, ETH_ALEN);
314 if (hostapd_send_mgmt_frame(hapd, &hdr, sizeof(hdr), 0) < 0)
315 perror("ap_handle_timer: send");
316 #endif /* CONFIG_NATIVE_WINDOWS */
317 } else if (sta->timeout_next != STA_REMOVE) {
318 int deauth = sta->timeout_next == STA_DEAUTH;
320 wpa_printf(MSG_DEBUG, "Sending %s info to STA " MACSTR,
321 deauth ? "deauthentication" : "disassociation",
322 MAC2STR(sta->addr));
324 if (deauth) {
325 hostapd_sta_deauth(hapd, sta->addr,
326 WLAN_REASON_PREV_AUTH_NOT_VALID);
327 } else {
328 hostapd_sta_disassoc(
329 hapd, sta->addr,
330 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY);
334 switch (sta->timeout_next) {
335 case STA_NULLFUNC:
336 sta->timeout_next = STA_DISASSOC;
337 eloop_register_timeout(AP_DISASSOC_DELAY, 0, ap_handle_timer,
338 hapd, sta);
339 break;
340 case STA_DISASSOC:
341 sta->flags &= ~WLAN_STA_ASSOC;
342 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
343 if (!sta->acct_terminate_cause)
344 sta->acct_terminate_cause =
345 RADIUS_ACCT_TERMINATE_CAUSE_IDLE_TIMEOUT;
346 accounting_sta_stop(hapd, sta);
347 ieee802_1x_free_station(sta);
348 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
349 HOSTAPD_LEVEL_INFO, "disassociated due to "
350 "inactivity");
351 sta->timeout_next = STA_DEAUTH;
352 eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer,
353 hapd, sta);
354 mlme_disassociate_indication(
355 hapd, sta, WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY);
356 break;
357 case STA_DEAUTH:
358 case STA_REMOVE:
359 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
360 HOSTAPD_LEVEL_INFO, "deauthenticated due to "
361 "inactivity");
362 if (!sta->acct_terminate_cause)
363 sta->acct_terminate_cause =
364 RADIUS_ACCT_TERMINATE_CAUSE_IDLE_TIMEOUT;
365 mlme_deauthenticate_indication(
366 hapd, sta,
367 WLAN_REASON_PREV_AUTH_NOT_VALID);
368 ap_free_sta(hapd, sta);
369 break;
374 static void ap_handle_session_timer(void *eloop_ctx, void *timeout_ctx)
376 struct hostapd_data *hapd = eloop_ctx;
377 struct sta_info *sta = timeout_ctx;
378 u8 addr[ETH_ALEN];
380 if (!(sta->flags & WLAN_STA_AUTH))
381 return;
383 mlme_deauthenticate_indication(hapd, sta,
384 WLAN_REASON_PREV_AUTH_NOT_VALID);
385 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
386 HOSTAPD_LEVEL_INFO, "deauthenticated due to "
387 "session timeout");
388 sta->acct_terminate_cause =
389 RADIUS_ACCT_TERMINATE_CAUSE_SESSION_TIMEOUT;
390 os_memcpy(addr, sta->addr, ETH_ALEN);
391 ap_free_sta(hapd, sta);
392 hostapd_sta_deauth(hapd, addr, WLAN_REASON_PREV_AUTH_NOT_VALID);
396 void ap_sta_session_timeout(struct hostapd_data *hapd, struct sta_info *sta,
397 u32 session_timeout)
399 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
400 HOSTAPD_LEVEL_DEBUG, "setting session timeout to %d "
401 "seconds", session_timeout);
402 eloop_cancel_timeout(ap_handle_session_timer, hapd, sta);
403 eloop_register_timeout(session_timeout, 0, ap_handle_session_timer,
404 hapd, sta);
408 void ap_sta_no_session_timeout(struct hostapd_data *hapd, struct sta_info *sta)
410 eloop_cancel_timeout(ap_handle_session_timer, hapd, sta);
414 struct sta_info * ap_sta_add(struct hostapd_data *hapd, const u8 *addr)
416 struct sta_info *sta;
418 sta = ap_get_sta(hapd, addr);
419 if (sta)
420 return sta;
422 wpa_printf(MSG_DEBUG, " New STA");
423 if (hapd->num_sta >= hapd->conf->max_num_sta) {
424 /* FIX: might try to remove some old STAs first? */
425 wpa_printf(MSG_DEBUG, "no more room for new STAs (%d/%d)",
426 hapd->num_sta, hapd->conf->max_num_sta);
427 return NULL;
430 sta = os_zalloc(sizeof(struct sta_info));
431 if (sta == NULL) {
432 wpa_printf(MSG_ERROR, "malloc failed");
433 return NULL;
435 sta->acct_interim_interval = hapd->conf->radius->acct_interim_interval;
437 /* initialize STA info data */
438 eloop_register_timeout(hapd->conf->ap_max_inactivity, 0,
439 ap_handle_timer, hapd, sta);
440 os_memcpy(sta->addr, addr, ETH_ALEN);
441 sta->next = hapd->sta_list;
442 hapd->sta_list = sta;
443 hapd->num_sta++;
444 ap_sta_hash_add(hapd, sta);
445 sta->ssid = &hapd->conf->ssid;
447 return sta;
451 static int ap_sta_remove(struct hostapd_data *hapd, struct sta_info *sta)
453 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
455 wpa_printf(MSG_DEBUG, "Removing STA " MACSTR " from kernel driver",
456 MAC2STR(sta->addr));
457 if (hostapd_sta_remove(hapd, sta->addr) &&
458 sta->flags & WLAN_STA_ASSOC) {
459 wpa_printf(MSG_DEBUG, "Could not remove station " MACSTR
460 " from kernel driver.", MAC2STR(sta->addr));
461 return -1;
463 return 0;
467 static int ap_sta_in_other_bss(struct hostapd_data *hapd,
468 struct sta_info *sta, u32 flags)
470 struct hostapd_iface *iface = hapd->iface;
471 size_t i;
473 for (i = 0; i < iface->num_bss; i++) {
474 struct hostapd_data *bss = iface->bss[i];
475 struct sta_info *sta2;
476 /* bss should always be set during operation, but it may be
477 * NULL during reconfiguration. Assume the STA is not
478 * associated to another BSS in that case to avoid NULL pointer
479 * dereferences. */
480 if (bss == hapd || bss == NULL)
481 continue;
482 sta2 = ap_get_sta(bss, sta->addr);
483 if (sta2 && ((sta2->flags & flags) == flags))
484 return 1;
487 return 0;
491 void ap_sta_disassociate(struct hostapd_data *hapd, struct sta_info *sta,
492 u16 reason)
494 wpa_printf(MSG_DEBUG, "%s: disassociate STA " MACSTR,
495 hapd->conf->iface, MAC2STR(sta->addr));
496 sta->flags &= ~WLAN_STA_ASSOC;
497 if (!ap_sta_in_other_bss(hapd, sta, WLAN_STA_ASSOC))
498 ap_sta_remove(hapd, sta);
499 sta->timeout_next = STA_DEAUTH;
500 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
501 eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DISASSOC, 0,
502 ap_handle_timer, hapd, sta);
503 accounting_sta_stop(hapd, sta);
504 ieee802_1x_free_station(sta);
506 mlme_disassociate_indication(hapd, sta, reason);
510 void ap_sta_deauthenticate(struct hostapd_data *hapd, struct sta_info *sta,
511 u16 reason)
513 wpa_printf(MSG_DEBUG, "%s: deauthenticate STA " MACSTR,
514 hapd->conf->iface, MAC2STR(sta->addr));
515 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
516 if (!ap_sta_in_other_bss(hapd, sta, WLAN_STA_ASSOC))
517 ap_sta_remove(hapd, sta);
518 sta->timeout_next = STA_REMOVE;
519 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
520 eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DEAUTH, 0,
521 ap_handle_timer, hapd, sta);
522 accounting_sta_stop(hapd, sta);
523 ieee802_1x_free_station(sta);
525 mlme_deauthenticate_indication(hapd, sta, reason);
529 int ap_sta_bind_vlan(struct hostapd_data *hapd, struct sta_info *sta,
530 int old_vlanid)
532 const char *iface;
533 struct hostapd_vlan *vlan = NULL;
536 * Do not proceed furthur if the vlan id remains same. We do not want
537 * duplicate dynamic vlan entries.
539 if (sta->vlan_id == old_vlanid)
540 return 0;
543 * During 1x reauth, if the vlan id changes, then remove the old id and
544 * proceed furthur to add the new one.
546 if (old_vlanid > 0)
547 vlan_remove_dynamic(hapd, old_vlanid);
549 iface = hapd->conf->iface;
550 if (sta->ssid->vlan[0])
551 iface = sta->ssid->vlan;
553 if (sta->ssid->dynamic_vlan == DYNAMIC_VLAN_DISABLED)
554 sta->vlan_id = 0;
555 else if (sta->vlan_id > 0) {
556 vlan = hapd->conf->vlan;
557 while (vlan) {
558 if (vlan->vlan_id == sta->vlan_id ||
559 vlan->vlan_id == VLAN_ID_WILDCARD) {
560 iface = vlan->ifname;
561 break;
563 vlan = vlan->next;
567 if (sta->vlan_id > 0 && vlan == NULL) {
568 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
569 HOSTAPD_LEVEL_DEBUG, "could not find VLAN for "
570 "binding station to (vlan_id=%d)",
571 sta->vlan_id);
572 return -1;
573 } else if (sta->vlan_id > 0 && vlan->vlan_id == VLAN_ID_WILDCARD) {
574 vlan = vlan_add_dynamic(hapd, vlan, sta->vlan_id);
575 if (vlan == NULL) {
576 hostapd_logger(hapd, sta->addr,
577 HOSTAPD_MODULE_IEEE80211,
578 HOSTAPD_LEVEL_DEBUG, "could not add "
579 "dynamic VLAN interface for vlan_id=%d",
580 sta->vlan_id);
581 return -1;
584 iface = vlan->ifname;
585 if (vlan_setup_encryption_dyn(hapd, sta->ssid, iface) != 0) {
586 hostapd_logger(hapd, sta->addr,
587 HOSTAPD_MODULE_IEEE80211,
588 HOSTAPD_LEVEL_DEBUG, "could not "
589 "configure encryption for dynamic VLAN "
590 "interface for vlan_id=%d",
591 sta->vlan_id);
594 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
595 HOSTAPD_LEVEL_DEBUG, "added new dynamic VLAN "
596 "interface '%s'", iface);
597 } else if (vlan && vlan->vlan_id == sta->vlan_id) {
598 if (sta->vlan_id > 0) {
599 vlan->dynamic_vlan++;
600 hostapd_logger(hapd, sta->addr,
601 HOSTAPD_MODULE_IEEE80211,
602 HOSTAPD_LEVEL_DEBUG, "updated existing "
603 "dynamic VLAN interface '%s'", iface);
607 * Update encryption configuration for statically generated
608 * VLAN interface. This is only used for static WEP
609 * configuration for the case where hostapd did not yet know
610 * which keys are to be used when the interface was added.
612 if (vlan_setup_encryption_dyn(hapd, sta->ssid, iface) != 0) {
613 hostapd_logger(hapd, sta->addr,
614 HOSTAPD_MODULE_IEEE80211,
615 HOSTAPD_LEVEL_DEBUG, "could not "
616 "configure encryption for VLAN "
617 "interface for vlan_id=%d",
618 sta->vlan_id);
622 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
623 HOSTAPD_LEVEL_DEBUG, "binding station to interface "
624 "'%s'", iface);
626 if (wpa_auth_sta_set_vlan(sta->wpa_sm, sta->vlan_id) < 0)
627 wpa_printf(MSG_INFO, "Failed to update VLAN-ID for WPA");
629 return hostapd_set_sta_vlan(iface, hapd, sta->addr, sta->vlan_id);
633 #ifdef CONFIG_IEEE80211W
635 int ap_check_sa_query_timeout(struct hostapd_data *hapd, struct sta_info *sta)
637 u32 tu;
638 struct os_time now, passed;
639 os_get_time(&now);
640 os_time_sub(&now, &sta->sa_query_start, &passed);
641 tu = (passed.sec * 1000000 + passed.usec) / 1024;
642 if (hapd->conf->assoc_sa_query_max_timeout < tu) {
643 hostapd_logger(hapd, sta->addr,
644 HOSTAPD_MODULE_IEEE80211,
645 HOSTAPD_LEVEL_DEBUG,
646 "association SA Query timed out");
647 sta->sa_query_timed_out = 1;
648 os_free(sta->sa_query_trans_id);
649 sta->sa_query_trans_id = NULL;
650 sta->sa_query_count = 0;
651 eloop_cancel_timeout(ap_sa_query_timer, hapd, sta);
652 return 1;
655 return 0;
659 static void ap_sa_query_timer(void *eloop_ctx, void *timeout_ctx)
661 struct hostapd_data *hapd = eloop_ctx;
662 struct sta_info *sta = timeout_ctx;
663 unsigned int timeout, sec, usec;
664 u8 *trans_id, *nbuf;
666 if (sta->sa_query_count > 0 &&
667 ap_check_sa_query_timeout(hapd, sta))
668 return;
670 nbuf = os_realloc(sta->sa_query_trans_id,
671 (sta->sa_query_count + 1) * WLAN_SA_QUERY_TR_ID_LEN);
672 if (nbuf == NULL)
673 return;
674 if (sta->sa_query_count == 0) {
675 /* Starting a new SA Query procedure */
676 os_get_time(&sta->sa_query_start);
678 trans_id = nbuf + sta->sa_query_count * WLAN_SA_QUERY_TR_ID_LEN;
679 sta->sa_query_trans_id = nbuf;
680 sta->sa_query_count++;
682 os_get_random(trans_id, WLAN_SA_QUERY_TR_ID_LEN);
684 timeout = hapd->conf->assoc_sa_query_retry_timeout;
685 sec = ((timeout / 1000) * 1024) / 1000;
686 usec = (timeout % 1000) * 1024;
687 eloop_register_timeout(sec, usec, ap_sa_query_timer, hapd, sta);
689 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
690 HOSTAPD_LEVEL_DEBUG,
691 "association SA Query attempt %d", sta->sa_query_count);
693 ieee802_11_send_sa_query_req(hapd, sta->addr, trans_id);
697 void ap_sta_start_sa_query(struct hostapd_data *hapd, struct sta_info *sta)
699 ap_sa_query_timer(hapd, sta);
703 void ap_sta_stop_sa_query(struct hostapd_data *hapd, struct sta_info *sta)
705 eloop_cancel_timeout(ap_sa_query_timer, hapd, sta);
706 os_free(sta->sa_query_trans_id);
707 sta->sa_query_trans_id = NULL;
708 sta->sa_query_count = 0;
711 #endif /* CONFIG_IEEE80211W */