2 * hostapd / Station table
3 * Copyright (c) 2002-2011, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
9 #include "utils/includes.h"
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 "radius/radius.h"
16 #include "radius/radius_client.h"
17 #include "drivers/driver.h"
20 #include "accounting.h"
21 #include "ieee802_1x.h"
22 #include "ieee802_11.h"
24 #include "preauth_auth.h"
25 #include "ap_config.h"
28 #include "vlan_init.h"
29 #include "p2p_hostapd.h"
30 #include "ap_drv_ops.h"
34 static void ap_sta_remove_in_other_bss(struct hostapd_data
*hapd
,
35 struct sta_info
*sta
);
36 static void ap_handle_session_timer(void *eloop_ctx
, void *timeout_ctx
);
37 static void ap_sta_deauth_cb_timeout(void *eloop_ctx
, void *timeout_ctx
);
38 static void ap_sta_disassoc_cb_timeout(void *eloop_ctx
, void *timeout_ctx
);
39 #ifdef CONFIG_IEEE80211W
40 static void ap_sa_query_timer(void *eloop_ctx
, void *timeout_ctx
);
41 #endif /* CONFIG_IEEE80211W */
42 static int ap_sta_remove(struct hostapd_data
*hapd
, struct sta_info
*sta
);
44 int ap_for_each_sta(struct hostapd_data
*hapd
,
45 int (*cb
)(struct hostapd_data
*hapd
, struct sta_info
*sta
,
51 for (sta
= hapd
->sta_list
; sta
; sta
= sta
->next
) {
52 if (cb(hapd
, sta
, ctx
))
60 struct sta_info
* ap_get_sta(struct hostapd_data
*hapd
, const u8
*sta
)
64 s
= hapd
->sta_hash
[STA_HASH(sta
)];
65 while (s
!= NULL
&& os_memcmp(s
->addr
, sta
, 6) != 0)
71 static void ap_sta_list_del(struct hostapd_data
*hapd
, struct sta_info
*sta
)
75 if (hapd
->sta_list
== sta
) {
76 hapd
->sta_list
= sta
->next
;
81 while (tmp
!= NULL
&& tmp
->next
!= sta
)
84 wpa_printf(MSG_DEBUG
, "Could not remove STA " MACSTR
" from "
85 "list.", MAC2STR(sta
->addr
));
87 tmp
->next
= sta
->next
;
91 void ap_sta_hash_add(struct hostapd_data
*hapd
, struct sta_info
*sta
)
93 sta
->hnext
= hapd
->sta_hash
[STA_HASH(sta
->addr
)];
94 hapd
->sta_hash
[STA_HASH(sta
->addr
)] = sta
;
98 static void ap_sta_hash_del(struct hostapd_data
*hapd
, struct sta_info
*sta
)
102 s
= hapd
->sta_hash
[STA_HASH(sta
->addr
)];
103 if (s
== NULL
) return;
104 if (os_memcmp(s
->addr
, sta
->addr
, 6) == 0) {
105 hapd
->sta_hash
[STA_HASH(sta
->addr
)] = s
->hnext
;
109 while (s
->hnext
!= NULL
&&
110 os_memcmp(s
->hnext
->addr
, sta
->addr
, ETH_ALEN
) != 0)
112 if (s
->hnext
!= NULL
)
113 s
->hnext
= s
->hnext
->hnext
;
115 wpa_printf(MSG_DEBUG
, "AP: could not remove STA " MACSTR
116 " from hash table", MAC2STR(sta
->addr
));
120 void ap_free_sta(struct hostapd_data
*hapd
, struct sta_info
*sta
)
124 accounting_sta_stop(hapd
, sta
);
127 ap_sta_set_authorized(hapd
, sta
, 0);
129 if (sta
->flags
& WLAN_STA_WDS
)
130 hostapd_set_wds_sta(hapd
, sta
->addr
, sta
->aid
, 0);
132 if (!(sta
->flags
& WLAN_STA_PREAUTH
))
133 hostapd_drv_sta_remove(hapd
, sta
->addr
);
135 ap_sta_hash_del(hapd
, sta
);
136 ap_sta_list_del(hapd
, sta
);
139 hapd
->sta_aid
[(sta
->aid
- 1) / 32] &=
140 ~BIT((sta
->aid
- 1) % 32);
143 if (sta
->nonerp_set
) {
145 hapd
->iface
->num_sta_non_erp
--;
146 if (hapd
->iface
->num_sta_non_erp
== 0)
150 if (sta
->no_short_slot_time_set
) {
151 sta
->no_short_slot_time_set
= 0;
152 hapd
->iface
->num_sta_no_short_slot_time
--;
153 if (hapd
->iface
->current_mode
->mode
== HOSTAPD_MODE_IEEE80211G
154 && hapd
->iface
->num_sta_no_short_slot_time
== 0)
158 if (sta
->no_short_preamble_set
) {
159 sta
->no_short_preamble_set
= 0;
160 hapd
->iface
->num_sta_no_short_preamble
--;
161 if (hapd
->iface
->current_mode
->mode
== HOSTAPD_MODE_IEEE80211G
162 && hapd
->iface
->num_sta_no_short_preamble
== 0)
166 if (sta
->no_ht_gf_set
) {
167 sta
->no_ht_gf_set
= 0;
168 hapd
->iface
->num_sta_ht_no_gf
--;
171 if (sta
->no_ht_set
) {
173 hapd
->iface
->num_sta_no_ht
--;
176 if (sta
->ht_20mhz_set
) {
177 sta
->ht_20mhz_set
= 0;
178 hapd
->iface
->num_sta_ht_20mhz
--;
182 if (sta
->no_p2p_set
) {
184 hapd
->num_sta_no_p2p
--;
185 if (hapd
->num_sta_no_p2p
== 0)
186 hostapd_p2p_non_p2p_sta_disconnected(hapd
);
188 #endif /* CONFIG_P2P */
190 #if defined(NEED_AP_MLME) && defined(CONFIG_IEEE80211N)
191 if (hostapd_ht_operation_update(hapd
->iface
) > 0)
193 #endif /* NEED_AP_MLME && CONFIG_IEEE80211N */
196 ieee802_11_set_beacons(hapd
->iface
);
198 wpa_printf(MSG_DEBUG
, "%s: cancel ap_handle_timer for " MACSTR
,
199 __func__
, MAC2STR(sta
->addr
));
200 eloop_cancel_timeout(ap_handle_timer
, hapd
, sta
);
201 eloop_cancel_timeout(ap_handle_session_timer
, hapd
, sta
);
202 eloop_cancel_timeout(ap_sta_deauth_cb_timeout
, hapd
, sta
);
203 eloop_cancel_timeout(ap_sta_disassoc_cb_timeout
, hapd
, sta
);
205 ieee802_1x_free_station(sta
);
206 wpa_auth_sta_deinit(sta
->wpa_sm
);
207 rsn_preauth_free_station(hapd
, sta
);
208 #ifndef CONFIG_NO_RADIUS
209 radius_client_flush_auth(hapd
->radius
, sta
->addr
);
210 #endif /* CONFIG_NO_RADIUS */
212 os_free(sta
->last_assoc_req
);
213 os_free(sta
->challenge
);
215 #ifdef CONFIG_IEEE80211W
216 os_free(sta
->sa_query_trans_id
);
217 eloop_cancel_timeout(ap_sa_query_timer
, hapd
, sta
);
218 #endif /* CONFIG_IEEE80211W */
221 p2p_group_notif_disassoc(hapd
->p2p_group
, sta
->addr
);
222 #endif /* CONFIG_P2P */
224 #ifdef CONFIG_INTERWORKING
225 if (sta
->gas_dialog
) {
227 for (i
= 0; i
< GAS_DIALOG_MAX
; i
++)
228 gas_serv_dialog_clear(&sta
->gas_dialog
[i
]);
229 os_free(sta
->gas_dialog
);
231 #endif /* CONFIG_INTERWORKING */
233 wpabuf_free(sta
->wps_ie
);
234 wpabuf_free(sta
->p2p_ie
);
235 wpabuf_free(sta
->hs20_ie
);
237 os_free(sta
->ht_capabilities
);
239 struct hostapd_sta_wpa_psk_short
*prev
= sta
->psk
;
240 sta
->psk
= sta
->psk
->next
;
243 os_free(sta
->identity
);
244 os_free(sta
->radius_cui
);
250 void hostapd_free_stas(struct hostapd_data
*hapd
)
252 struct sta_info
*sta
, *prev
;
254 sta
= hapd
->sta_list
;
258 if (sta
->flags
& WLAN_STA_AUTH
) {
259 mlme_deauthenticate_indication(
260 hapd
, sta
, WLAN_REASON_UNSPECIFIED
);
263 wpa_printf(MSG_DEBUG
, "Removing station " MACSTR
,
264 MAC2STR(prev
->addr
));
265 ap_free_sta(hapd
, prev
);
271 * ap_handle_timer - Per STA timer handler
272 * @eloop_ctx: struct hostapd_data *
273 * @timeout_ctx: struct sta_info *
275 * This function is called to check station activity and to remove inactive
278 void ap_handle_timer(void *eloop_ctx
, void *timeout_ctx
)
280 struct hostapd_data
*hapd
= eloop_ctx
;
281 struct sta_info
*sta
= timeout_ctx
;
282 unsigned long next_time
= 0;
284 wpa_printf(MSG_DEBUG
, "%s: " MACSTR
" flags=0x%x timeout_next=%d",
285 __func__
, MAC2STR(sta
->addr
), sta
->flags
,
287 if (sta
->timeout_next
== STA_REMOVE
) {
288 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
289 HOSTAPD_LEVEL_INFO
, "deauthenticated due to "
290 "local deauth request");
291 ap_free_sta(hapd
, sta
);
295 if ((sta
->flags
& WLAN_STA_ASSOC
) &&
296 (sta
->timeout_next
== STA_NULLFUNC
||
297 sta
->timeout_next
== STA_DISASSOC
)) {
300 * Add random value to timeout so that we don't end up bouncing
301 * all stations at the same time if we have lots of associated
302 * stations that are idle (but keep re-associating).
304 int fuzz
= os_random() % 20;
305 inactive_sec
= hostapd_drv_get_inact_sec(hapd
, sta
->addr
);
306 if (inactive_sec
== -1) {
307 wpa_msg(hapd
->msg_ctx
, MSG_DEBUG
,
308 "Check inactivity: Could not "
309 "get station info from kernel driver for "
310 MACSTR
, MAC2STR(sta
->addr
));
312 * The driver may not support this functionality.
313 * Anyway, try again after the next inactivity timeout,
314 * but do not disconnect the station now.
316 next_time
= hapd
->conf
->ap_max_inactivity
+ fuzz
;
317 } else if (inactive_sec
< hapd
->conf
->ap_max_inactivity
&&
318 sta
->flags
& WLAN_STA_ASSOC
) {
319 /* station activity detected; reset timeout state */
320 wpa_msg(hapd
->msg_ctx
, MSG_DEBUG
,
321 "Station " MACSTR
" has been active %is ago",
322 MAC2STR(sta
->addr
), inactive_sec
);
323 sta
->timeout_next
= STA_NULLFUNC
;
324 next_time
= hapd
->conf
->ap_max_inactivity
+ fuzz
-
327 wpa_msg(hapd
->msg_ctx
, MSG_DEBUG
,
328 "Station " MACSTR
" has been "
329 "inactive too long: %d sec, max allowed: %d",
330 MAC2STR(sta
->addr
), inactive_sec
,
331 hapd
->conf
->ap_max_inactivity
);
333 if (hapd
->conf
->skip_inactivity_poll
)
334 sta
->timeout_next
= STA_DISASSOC
;
338 if ((sta
->flags
& WLAN_STA_ASSOC
) &&
339 sta
->timeout_next
== STA_DISASSOC
&&
340 !(sta
->flags
& WLAN_STA_PENDING_POLL
) &&
341 !hapd
->conf
->skip_inactivity_poll
) {
342 wpa_msg(hapd
->msg_ctx
, MSG_DEBUG
, "Station " MACSTR
343 " has ACKed data poll", MAC2STR(sta
->addr
));
344 /* data nullfunc frame poll did not produce TX errors; assume
345 * station ACKed it */
346 sta
->timeout_next
= STA_NULLFUNC
;
347 next_time
= hapd
->conf
->ap_max_inactivity
;
351 wpa_printf(MSG_DEBUG
, "%s: register ap_handle_timer timeout "
352 "for " MACSTR
" (%lu seconds)",
353 __func__
, MAC2STR(sta
->addr
), next_time
);
354 eloop_register_timeout(next_time
, 0, ap_handle_timer
, hapd
,
359 if (sta
->timeout_next
== STA_NULLFUNC
&&
360 (sta
->flags
& WLAN_STA_ASSOC
)) {
361 wpa_printf(MSG_DEBUG
, " Polling STA");
362 sta
->flags
|= WLAN_STA_PENDING_POLL
;
363 hostapd_drv_poll_client(hapd
, hapd
->own_addr
, sta
->addr
,
364 sta
->flags
& WLAN_STA_WMM
);
365 } else if (sta
->timeout_next
!= STA_REMOVE
) {
366 int deauth
= sta
->timeout_next
== STA_DEAUTH
;
368 wpa_dbg(hapd
->msg_ctx
, MSG_DEBUG
,
369 "Timeout, sending %s info to STA " MACSTR
,
370 deauth
? "deauthentication" : "disassociation",
374 hostapd_drv_sta_deauth(
376 WLAN_REASON_PREV_AUTH_NOT_VALID
);
378 hostapd_drv_sta_disassoc(
380 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY
);
384 switch (sta
->timeout_next
) {
386 sta
->timeout_next
= STA_DISASSOC
;
387 wpa_printf(MSG_DEBUG
, "%s: register ap_handle_timer timeout "
388 "for " MACSTR
" (%d seconds - AP_DISASSOC_DELAY)",
389 __func__
, MAC2STR(sta
->addr
), AP_DISASSOC_DELAY
);
390 eloop_register_timeout(AP_DISASSOC_DELAY
, 0, ap_handle_timer
,
394 ap_sta_set_authorized(hapd
, sta
, 0);
395 sta
->flags
&= ~WLAN_STA_ASSOC
;
396 ieee802_1x_notify_port_enabled(sta
->eapol_sm
, 0);
397 if (!sta
->acct_terminate_cause
)
398 sta
->acct_terminate_cause
=
399 RADIUS_ACCT_TERMINATE_CAUSE_IDLE_TIMEOUT
;
400 accounting_sta_stop(hapd
, sta
);
401 ieee802_1x_free_station(sta
);
402 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
403 HOSTAPD_LEVEL_INFO
, "disassociated due to "
405 sta
->timeout_next
= STA_DEAUTH
;
406 wpa_printf(MSG_DEBUG
, "%s: register ap_handle_timer timeout "
407 "for " MACSTR
" (%d seconds - AP_DEAUTH_DELAY)",
408 __func__
, MAC2STR(sta
->addr
), AP_DEAUTH_DELAY
);
409 eloop_register_timeout(AP_DEAUTH_DELAY
, 0, ap_handle_timer
,
411 mlme_disassociate_indication(
412 hapd
, sta
, WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY
);
416 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
417 HOSTAPD_LEVEL_INFO
, "deauthenticated due to "
418 "inactivity (timer DEAUTH/REMOVE)");
419 if (!sta
->acct_terminate_cause
)
420 sta
->acct_terminate_cause
=
421 RADIUS_ACCT_TERMINATE_CAUSE_IDLE_TIMEOUT
;
422 mlme_deauthenticate_indication(
424 WLAN_REASON_PREV_AUTH_NOT_VALID
);
425 ap_free_sta(hapd
, sta
);
431 static void ap_handle_session_timer(void *eloop_ctx
, void *timeout_ctx
)
433 struct hostapd_data
*hapd
= eloop_ctx
;
434 struct sta_info
*sta
= timeout_ctx
;
437 if (!(sta
->flags
& WLAN_STA_AUTH
)) {
438 if (sta
->flags
& WLAN_STA_GAS
) {
439 wpa_printf(MSG_DEBUG
, "GAS: Remove temporary STA "
440 "entry " MACSTR
, MAC2STR(sta
->addr
));
441 ap_free_sta(hapd
, sta
);
446 mlme_deauthenticate_indication(hapd
, sta
,
447 WLAN_REASON_PREV_AUTH_NOT_VALID
);
448 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
449 HOSTAPD_LEVEL_INFO
, "deauthenticated due to "
451 sta
->acct_terminate_cause
=
452 RADIUS_ACCT_TERMINATE_CAUSE_SESSION_TIMEOUT
;
453 os_memcpy(addr
, sta
->addr
, ETH_ALEN
);
454 ap_free_sta(hapd
, sta
);
455 hostapd_drv_sta_deauth(hapd
, addr
, WLAN_REASON_PREV_AUTH_NOT_VALID
);
459 void ap_sta_session_timeout(struct hostapd_data
*hapd
, struct sta_info
*sta
,
462 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
463 HOSTAPD_LEVEL_DEBUG
, "setting session timeout to %d "
464 "seconds", session_timeout
);
465 eloop_cancel_timeout(ap_handle_session_timer
, hapd
, sta
);
466 eloop_register_timeout(session_timeout
, 0, ap_handle_session_timer
,
471 void ap_sta_no_session_timeout(struct hostapd_data
*hapd
, struct sta_info
*sta
)
473 eloop_cancel_timeout(ap_handle_session_timer
, hapd
, sta
);
477 struct sta_info
* ap_sta_add(struct hostapd_data
*hapd
, const u8
*addr
)
479 struct sta_info
*sta
;
481 sta
= ap_get_sta(hapd
, addr
);
485 wpa_printf(MSG_DEBUG
, " New STA");
486 if (hapd
->num_sta
>= hapd
->conf
->max_num_sta
) {
487 /* FIX: might try to remove some old STAs first? */
488 wpa_printf(MSG_DEBUG
, "no more room for new STAs (%d/%d)",
489 hapd
->num_sta
, hapd
->conf
->max_num_sta
);
493 sta
= os_zalloc(sizeof(struct sta_info
));
495 wpa_printf(MSG_ERROR
, "malloc failed");
498 sta
->acct_interim_interval
= hapd
->conf
->acct_interim_interval
;
500 /* initialize STA info data */
501 wpa_printf(MSG_DEBUG
, "%s: register ap_handle_timer timeout "
502 "for " MACSTR
" (%d seconds - ap_max_inactivity)",
503 __func__
, MAC2STR(addr
),
504 hapd
->conf
->ap_max_inactivity
);
505 eloop_register_timeout(hapd
->conf
->ap_max_inactivity
, 0,
506 ap_handle_timer
, hapd
, sta
);
507 os_memcpy(sta
->addr
, addr
, ETH_ALEN
);
508 sta
->next
= hapd
->sta_list
;
509 hapd
->sta_list
= sta
;
511 ap_sta_hash_add(hapd
, sta
);
512 sta
->ssid
= &hapd
->conf
->ssid
;
513 ap_sta_remove_in_other_bss(hapd
, sta
);
519 static int ap_sta_remove(struct hostapd_data
*hapd
, struct sta_info
*sta
)
521 ieee802_1x_notify_port_enabled(sta
->eapol_sm
, 0);
523 wpa_printf(MSG_DEBUG
, "Removing STA " MACSTR
" from kernel driver",
525 if (hostapd_drv_sta_remove(hapd
, sta
->addr
) &&
526 sta
->flags
& WLAN_STA_ASSOC
) {
527 wpa_printf(MSG_DEBUG
, "Could not remove station " MACSTR
528 " from kernel driver.", MAC2STR(sta
->addr
));
535 static void ap_sta_remove_in_other_bss(struct hostapd_data
*hapd
,
536 struct sta_info
*sta
)
538 struct hostapd_iface
*iface
= hapd
->iface
;
541 for (i
= 0; i
< iface
->num_bss
; i
++) {
542 struct hostapd_data
*bss
= iface
->bss
[i
];
543 struct sta_info
*sta2
;
544 /* bss should always be set during operation, but it may be
545 * NULL during reconfiguration. Assume the STA is not
546 * associated to another BSS in that case to avoid NULL pointer
548 if (bss
== hapd
|| bss
== NULL
)
550 sta2
= ap_get_sta(bss
, sta
->addr
);
554 ap_sta_disconnect(bss
, sta2
, sta2
->addr
,
555 WLAN_REASON_PREV_AUTH_NOT_VALID
);
560 static void ap_sta_disassoc_cb_timeout(void *eloop_ctx
, void *timeout_ctx
)
562 struct hostapd_data
*hapd
= eloop_ctx
;
563 struct sta_info
*sta
= timeout_ctx
;
565 ap_sta_remove(hapd
, sta
);
566 mlme_disassociate_indication(hapd
, sta
, sta
->disassoc_reason
);
570 void ap_sta_disassociate(struct hostapd_data
*hapd
, struct sta_info
*sta
,
573 wpa_printf(MSG_DEBUG
, "%s: disassociate STA " MACSTR
,
574 hapd
->conf
->iface
, MAC2STR(sta
->addr
));
575 sta
->flags
&= ~WLAN_STA_ASSOC
;
576 ap_sta_set_authorized(hapd
, sta
, 0);
577 sta
->timeout_next
= STA_DEAUTH
;
578 wpa_printf(MSG_DEBUG
, "%s: reschedule ap_handle_timer timeout "
579 "for " MACSTR
" (%d seconds - "
580 "AP_MAX_INACTIVITY_AFTER_DISASSOC)",
581 __func__
, MAC2STR(sta
->addr
),
582 AP_MAX_INACTIVITY_AFTER_DISASSOC
);
583 eloop_cancel_timeout(ap_handle_timer
, hapd
, sta
);
584 eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DISASSOC
, 0,
585 ap_handle_timer
, hapd
, sta
);
586 accounting_sta_stop(hapd
, sta
);
587 ieee802_1x_free_station(sta
);
589 sta
->disassoc_reason
= reason
;
590 sta
->flags
|= WLAN_STA_PENDING_DISASSOC_CB
;
591 eloop_cancel_timeout(ap_sta_disassoc_cb_timeout
, hapd
, sta
);
592 eloop_register_timeout(hapd
->iface
->drv_flags
&
593 WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS
? 2 : 0, 0,
594 ap_sta_disassoc_cb_timeout
, hapd
, sta
);
598 static void ap_sta_deauth_cb_timeout(void *eloop_ctx
, void *timeout_ctx
)
600 struct hostapd_data
*hapd
= eloop_ctx
;
601 struct sta_info
*sta
= timeout_ctx
;
603 ap_sta_remove(hapd
, sta
);
604 mlme_deauthenticate_indication(hapd
, sta
, sta
->deauth_reason
);
608 void ap_sta_deauthenticate(struct hostapd_data
*hapd
, struct sta_info
*sta
,
611 wpa_printf(MSG_DEBUG
, "%s: deauthenticate STA " MACSTR
,
612 hapd
->conf
->iface
, MAC2STR(sta
->addr
));
613 sta
->flags
&= ~(WLAN_STA_AUTH
| WLAN_STA_ASSOC
);
614 ap_sta_set_authorized(hapd
, sta
, 0);
615 sta
->timeout_next
= STA_REMOVE
;
616 wpa_printf(MSG_DEBUG
, "%s: reschedule ap_handle_timer timeout "
617 "for " MACSTR
" (%d seconds - "
618 "AP_MAX_INACTIVITY_AFTER_DEAUTH)",
619 __func__
, MAC2STR(sta
->addr
),
620 AP_MAX_INACTIVITY_AFTER_DEAUTH
);
621 eloop_cancel_timeout(ap_handle_timer
, hapd
, sta
);
622 eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DEAUTH
, 0,
623 ap_handle_timer
, hapd
, sta
);
624 accounting_sta_stop(hapd
, sta
);
625 ieee802_1x_free_station(sta
);
627 sta
->deauth_reason
= reason
;
628 sta
->flags
|= WLAN_STA_PENDING_DEAUTH_CB
;
629 eloop_cancel_timeout(ap_sta_deauth_cb_timeout
, hapd
, sta
);
630 eloop_register_timeout(hapd
->iface
->drv_flags
&
631 WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS
? 2 : 0, 0,
632 ap_sta_deauth_cb_timeout
, hapd
, sta
);
637 int ap_sta_wps_cancel(struct hostapd_data
*hapd
,
638 struct sta_info
*sta
, void *ctx
)
640 if (sta
&& (sta
->flags
& WLAN_STA_WPS
)) {
641 ap_sta_deauthenticate(hapd
, sta
,
642 WLAN_REASON_PREV_AUTH_NOT_VALID
);
643 wpa_printf(MSG_DEBUG
, "WPS: %s: Deauth sta=" MACSTR
,
644 __func__
, MAC2STR(sta
->addr
));
650 #endif /* CONFIG_WPS */
653 int ap_sta_bind_vlan(struct hostapd_data
*hapd
, struct sta_info
*sta
,
656 #ifndef CONFIG_NO_VLAN
658 struct hostapd_vlan
*vlan
= NULL
;
662 * Do not proceed furthur if the vlan id remains same. We do not want
663 * duplicate dynamic vlan entries.
665 if (sta
->vlan_id
== old_vlanid
)
669 * During 1x reauth, if the vlan id changes, then remove the old id and
670 * proceed furthur to add the new one.
673 vlan_remove_dynamic(hapd
, old_vlanid
);
675 iface
= hapd
->conf
->iface
;
676 if (sta
->ssid
->vlan
[0])
677 iface
= sta
->ssid
->vlan
;
679 if (sta
->ssid
->dynamic_vlan
== DYNAMIC_VLAN_DISABLED
)
681 else if (sta
->vlan_id
> 0) {
682 vlan
= hapd
->conf
->vlan
;
684 if (vlan
->vlan_id
== sta
->vlan_id
||
685 vlan
->vlan_id
== VLAN_ID_WILDCARD
) {
686 iface
= vlan
->ifname
;
693 if (sta
->vlan_id
> 0 && vlan
== NULL
) {
694 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
695 HOSTAPD_LEVEL_DEBUG
, "could not find VLAN for "
696 "binding station to (vlan_id=%d)",
699 } else if (sta
->vlan_id
> 0 && vlan
->vlan_id
== VLAN_ID_WILDCARD
) {
700 vlan
= vlan_add_dynamic(hapd
, vlan
, sta
->vlan_id
);
702 hostapd_logger(hapd
, sta
->addr
,
703 HOSTAPD_MODULE_IEEE80211
,
704 HOSTAPD_LEVEL_DEBUG
, "could not add "
705 "dynamic VLAN interface for vlan_id=%d",
710 iface
= vlan
->ifname
;
711 if (vlan_setup_encryption_dyn(hapd
, sta
->ssid
, iface
) != 0) {
712 hostapd_logger(hapd
, sta
->addr
,
713 HOSTAPD_MODULE_IEEE80211
,
714 HOSTAPD_LEVEL_DEBUG
, "could not "
715 "configure encryption for dynamic VLAN "
716 "interface for vlan_id=%d",
720 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
721 HOSTAPD_LEVEL_DEBUG
, "added new dynamic VLAN "
722 "interface '%s'", iface
);
723 } else if (vlan
&& vlan
->vlan_id
== sta
->vlan_id
) {
724 if (sta
->vlan_id
> 0) {
725 vlan
->dynamic_vlan
++;
726 hostapd_logger(hapd
, sta
->addr
,
727 HOSTAPD_MODULE_IEEE80211
,
728 HOSTAPD_LEVEL_DEBUG
, "updated existing "
729 "dynamic VLAN interface '%s'", iface
);
733 * Update encryption configuration for statically generated
734 * VLAN interface. This is only used for static WEP
735 * configuration for the case where hostapd did not yet know
736 * which keys are to be used when the interface was added.
738 if (vlan_setup_encryption_dyn(hapd
, sta
->ssid
, iface
) != 0) {
739 hostapd_logger(hapd
, sta
->addr
,
740 HOSTAPD_MODULE_IEEE80211
,
741 HOSTAPD_LEVEL_DEBUG
, "could not "
742 "configure encryption for VLAN "
743 "interface for vlan_id=%d",
748 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
749 HOSTAPD_LEVEL_DEBUG
, "binding station to interface "
752 if (wpa_auth_sta_set_vlan(sta
->wpa_sm
, sta
->vlan_id
) < 0)
753 wpa_printf(MSG_INFO
, "Failed to update VLAN-ID for WPA");
755 ret
= hostapd_drv_set_sta_vlan(iface
, hapd
, sta
->addr
, sta
->vlan_id
);
757 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
758 HOSTAPD_LEVEL_DEBUG
, "could not bind the STA "
759 "entry to vlan_id=%d", sta
->vlan_id
);
762 #else /* CONFIG_NO_VLAN */
764 #endif /* CONFIG_NO_VLAN */
768 #ifdef CONFIG_IEEE80211W
770 int ap_check_sa_query_timeout(struct hostapd_data
*hapd
, struct sta_info
*sta
)
773 struct os_time now
, passed
;
775 os_time_sub(&now
, &sta
->sa_query_start
, &passed
);
776 tu
= (passed
.sec
* 1000000 + passed
.usec
) / 1024;
777 if (hapd
->conf
->assoc_sa_query_max_timeout
< tu
) {
778 hostapd_logger(hapd
, sta
->addr
,
779 HOSTAPD_MODULE_IEEE80211
,
781 "association SA Query timed out");
782 sta
->sa_query_timed_out
= 1;
783 os_free(sta
->sa_query_trans_id
);
784 sta
->sa_query_trans_id
= NULL
;
785 sta
->sa_query_count
= 0;
786 eloop_cancel_timeout(ap_sa_query_timer
, hapd
, sta
);
794 static void ap_sa_query_timer(void *eloop_ctx
, void *timeout_ctx
)
796 struct hostapd_data
*hapd
= eloop_ctx
;
797 struct sta_info
*sta
= timeout_ctx
;
798 unsigned int timeout
, sec
, usec
;
801 if (sta
->sa_query_count
> 0 &&
802 ap_check_sa_query_timeout(hapd
, sta
))
805 nbuf
= os_realloc_array(sta
->sa_query_trans_id
,
806 sta
->sa_query_count
+ 1,
807 WLAN_SA_QUERY_TR_ID_LEN
);
810 if (sta
->sa_query_count
== 0) {
811 /* Starting a new SA Query procedure */
812 os_get_time(&sta
->sa_query_start
);
814 trans_id
= nbuf
+ sta
->sa_query_count
* WLAN_SA_QUERY_TR_ID_LEN
;
815 sta
->sa_query_trans_id
= nbuf
;
816 sta
->sa_query_count
++;
818 os_get_random(trans_id
, WLAN_SA_QUERY_TR_ID_LEN
);
820 timeout
= hapd
->conf
->assoc_sa_query_retry_timeout
;
821 sec
= ((timeout
/ 1000) * 1024) / 1000;
822 usec
= (timeout
% 1000) * 1024;
823 eloop_register_timeout(sec
, usec
, ap_sa_query_timer
, hapd
, sta
);
825 hostapd_logger(hapd
, sta
->addr
, HOSTAPD_MODULE_IEEE80211
,
827 "association SA Query attempt %d", sta
->sa_query_count
);
829 ieee802_11_send_sa_query_req(hapd
, sta
->addr
, trans_id
);
833 void ap_sta_start_sa_query(struct hostapd_data
*hapd
, struct sta_info
*sta
)
835 ap_sa_query_timer(hapd
, sta
);
839 void ap_sta_stop_sa_query(struct hostapd_data
*hapd
, struct sta_info
*sta
)
841 eloop_cancel_timeout(ap_sa_query_timer
, hapd
, sta
);
842 os_free(sta
->sa_query_trans_id
);
843 sta
->sa_query_trans_id
= NULL
;
844 sta
->sa_query_count
= 0;
847 #endif /* CONFIG_IEEE80211W */
850 void ap_sta_set_authorized(struct hostapd_data
*hapd
, struct sta_info
*sta
,
853 const u8
*dev_addr
= NULL
;
856 #endif /* CONFIG_P2P */
858 if (!!authorized
== !!(sta
->flags
& WLAN_STA_AUTHORIZED
))
862 if (hapd
->p2p_group
== NULL
) {
863 if (sta
->p2p_ie
!= NULL
&&
864 p2p_parse_dev_addr_in_p2p_ie(sta
->p2p_ie
, addr
) == 0)
867 dev_addr
= p2p_group_get_dev_addr(hapd
->p2p_group
, sta
->addr
);
868 #endif /* CONFIG_P2P */
872 wpa_msg(hapd
->msg_ctx
, MSG_INFO
, AP_STA_CONNECTED
873 MACSTR
" p2p_dev_addr=" MACSTR
,
874 MAC2STR(sta
->addr
), MAC2STR(dev_addr
));
876 wpa_msg(hapd
->msg_ctx
, MSG_INFO
, AP_STA_CONNECTED
877 MACSTR
, MAC2STR(sta
->addr
));
878 if (hapd
->msg_ctx_parent
&&
879 hapd
->msg_ctx_parent
!= hapd
->msg_ctx
&& dev_addr
)
880 wpa_msg(hapd
->msg_ctx_parent
, MSG_INFO
,
881 AP_STA_CONNECTED MACSTR
" p2p_dev_addr="
883 MAC2STR(sta
->addr
), MAC2STR(dev_addr
));
884 else if (hapd
->msg_ctx_parent
&&
885 hapd
->msg_ctx_parent
!= hapd
->msg_ctx
)
886 wpa_msg(hapd
->msg_ctx_parent
, MSG_INFO
,
887 AP_STA_CONNECTED MACSTR
, MAC2STR(sta
->addr
));
889 sta
->flags
|= WLAN_STA_AUTHORIZED
;
892 wpa_msg(hapd
->msg_ctx
, MSG_INFO
, AP_STA_DISCONNECTED
893 MACSTR
" p2p_dev_addr=" MACSTR
,
894 MAC2STR(sta
->addr
), MAC2STR(dev_addr
));
896 wpa_msg(hapd
->msg_ctx
, MSG_INFO
, AP_STA_DISCONNECTED
897 MACSTR
, MAC2STR(sta
->addr
));
898 if (hapd
->msg_ctx_parent
&&
899 hapd
->msg_ctx_parent
!= hapd
->msg_ctx
&& dev_addr
)
900 wpa_msg(hapd
->msg_ctx_parent
, MSG_INFO
,
901 AP_STA_DISCONNECTED MACSTR
" p2p_dev_addr="
902 MACSTR
, MAC2STR(sta
->addr
), MAC2STR(dev_addr
));
903 else if (hapd
->msg_ctx_parent
&&
904 hapd
->msg_ctx_parent
!= hapd
->msg_ctx
)
905 wpa_msg(hapd
->msg_ctx_parent
, MSG_INFO
,
906 AP_STA_DISCONNECTED MACSTR
,
908 sta
->flags
&= ~WLAN_STA_AUTHORIZED
;
911 if (hapd
->sta_authorized_cb
)
912 hapd
->sta_authorized_cb(hapd
->sta_authorized_cb_ctx
,
913 sta
->addr
, authorized
, dev_addr
);
917 void ap_sta_disconnect(struct hostapd_data
*hapd
, struct sta_info
*sta
,
918 const u8
*addr
, u16 reason
)
921 if (sta
== NULL
&& addr
)
922 sta
= ap_get_sta(hapd
, addr
);
925 hostapd_drv_sta_deauth(hapd
, addr
, reason
);
929 ap_sta_set_authorized(hapd
, sta
, 0);
930 wpa_auth_sm_event(sta
->wpa_sm
, WPA_DEAUTH
);
931 ieee802_1x_notify_port_enabled(sta
->eapol_sm
, 0);
932 sta
->flags
&= ~(WLAN_STA_AUTH
| WLAN_STA_ASSOC
);
933 wpa_printf(MSG_DEBUG
, "%s: reschedule ap_handle_timer timeout "
934 "for " MACSTR
" (%d seconds - "
935 "AP_MAX_INACTIVITY_AFTER_DEAUTH)",
936 __func__
, MAC2STR(sta
->addr
),
937 AP_MAX_INACTIVITY_AFTER_DEAUTH
);
938 eloop_cancel_timeout(ap_handle_timer
, hapd
, sta
);
939 eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DEAUTH
, 0,
940 ap_handle_timer
, hapd
, sta
);
941 sta
->timeout_next
= STA_REMOVE
;
943 sta
->deauth_reason
= reason
;
944 sta
->flags
|= WLAN_STA_PENDING_DEAUTH_CB
;
945 eloop_cancel_timeout(ap_sta_deauth_cb_timeout
, hapd
, sta
);
946 eloop_register_timeout(hapd
->iface
->drv_flags
&
947 WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS
? 2 : 0, 0,
948 ap_sta_deauth_cb_timeout
, hapd
, sta
);
952 void ap_sta_deauth_cb(struct hostapd_data
*hapd
, struct sta_info
*sta
)
954 if (!(sta
->flags
& WLAN_STA_PENDING_DEAUTH_CB
)) {
955 wpa_printf(MSG_DEBUG
, "Ignore deauth cb for test frame");
958 sta
->flags
&= ~WLAN_STA_PENDING_DEAUTH_CB
;
959 eloop_cancel_timeout(ap_sta_deauth_cb_timeout
, hapd
, sta
);
960 ap_sta_deauth_cb_timeout(hapd
, sta
);
964 void ap_sta_disassoc_cb(struct hostapd_data
*hapd
, struct sta_info
*sta
)
966 if (!(sta
->flags
& WLAN_STA_PENDING_DISASSOC_CB
)) {
967 wpa_printf(MSG_DEBUG
, "Ignore disassoc cb for test frame");
970 sta
->flags
&= ~WLAN_STA_PENDING_DISASSOC_CB
;
971 eloop_cancel_timeout(ap_sta_disassoc_cb_timeout
, hapd
, sta
);
972 ap_sta_disassoc_cb_timeout(hapd
, sta
);