blob: 60058e45c31c143524829b8d102dd547d83be11a [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * hostapd / Station table
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07003 * Copyright (c) 2002-2013, Jouni Malinen <j@w1.fi>
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004 *
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007 */
8
9#include "utils/includes.h"
10
11#include "utils/common.h"
12#include "utils/eloop.h"
13#include "common/ieee802_11_defs.h"
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080014#include "common/wpa_ctrl.h"
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080015#include "common/sae.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070016#include "radius/radius.h"
17#include "radius/radius_client.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070018#include "p2p/p2p.h"
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080019#include "fst/fst.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070020#include "hostapd.h"
21#include "accounting.h"
22#include "ieee802_1x.h"
23#include "ieee802_11.h"
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080024#include "ieee802_11_auth.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070025#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"
Dmitry Shmidt04949592012-07-19 12:16:46 -070033#include "gas_serv.h"
Dmitry Shmidtf21452a2014-02-26 10:55:25 -080034#include "wnm_ap.h"
Dmitry Shmidt57c2d392016-02-23 13:40:19 -080035#include "mbo_ap.h"
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -080036#include "ndisc_snoop.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070037#include "sta_info.h"
Dmitry Shmidt57c2d392016-02-23 13:40:19 -080038#include "vlan.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070039
40static void ap_sta_remove_in_other_bss(struct hostapd_data *hapd,
41 struct sta_info *sta);
42static void ap_handle_session_timer(void *eloop_ctx, void *timeout_ctx);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -080043static void ap_handle_session_warning_timer(void *eloop_ctx, void *timeout_ctx);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080044static void ap_sta_deauth_cb_timeout(void *eloop_ctx, void *timeout_ctx);
45static void ap_sta_disassoc_cb_timeout(void *eloop_ctx, void *timeout_ctx);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070046#ifdef CONFIG_IEEE80211W
47static void ap_sa_query_timer(void *eloop_ctx, void *timeout_ctx);
48#endif /* CONFIG_IEEE80211W */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080049static int ap_sta_remove(struct hostapd_data *hapd, struct sta_info *sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070050
51int ap_for_each_sta(struct hostapd_data *hapd,
52 int (*cb)(struct hostapd_data *hapd, struct sta_info *sta,
53 void *ctx),
54 void *ctx)
55{
56 struct sta_info *sta;
57
58 for (sta = hapd->sta_list; sta; sta = sta->next) {
59 if (cb(hapd, sta, ctx))
60 return 1;
61 }
62
63 return 0;
64}
65
66
67struct sta_info * ap_get_sta(struct hostapd_data *hapd, const u8 *sta)
68{
69 struct sta_info *s;
70
71 s = hapd->sta_hash[STA_HASH(sta)];
72 while (s != NULL && os_memcmp(s->addr, sta, 6) != 0)
73 s = s->hnext;
74 return s;
75}
76
77
Dmitry Shmidt391c59f2013-09-03 12:16:28 -070078#ifdef CONFIG_P2P
79struct sta_info * ap_get_sta_p2p(struct hostapd_data *hapd, const u8 *addr)
80{
81 struct sta_info *sta;
82
83 for (sta = hapd->sta_list; sta; sta = sta->next) {
84 const u8 *p2p_dev_addr;
85
86 if (sta->p2p_ie == NULL)
87 continue;
88
89 p2p_dev_addr = p2p_get_go_dev_addr(sta->p2p_ie);
90 if (p2p_dev_addr == NULL)
91 continue;
92
93 if (os_memcmp(p2p_dev_addr, addr, ETH_ALEN) == 0)
94 return sta;
95 }
96
97 return NULL;
98}
99#endif /* CONFIG_P2P */
100
101
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700102static void ap_sta_list_del(struct hostapd_data *hapd, struct sta_info *sta)
103{
104 struct sta_info *tmp;
105
106 if (hapd->sta_list == sta) {
107 hapd->sta_list = sta->next;
108 return;
109 }
110
111 tmp = hapd->sta_list;
112 while (tmp != NULL && tmp->next != sta)
113 tmp = tmp->next;
114 if (tmp == NULL) {
115 wpa_printf(MSG_DEBUG, "Could not remove STA " MACSTR " from "
116 "list.", MAC2STR(sta->addr));
117 } else
118 tmp->next = sta->next;
119}
120
121
122void ap_sta_hash_add(struct hostapd_data *hapd, struct sta_info *sta)
123{
124 sta->hnext = hapd->sta_hash[STA_HASH(sta->addr)];
125 hapd->sta_hash[STA_HASH(sta->addr)] = sta;
126}
127
128
129static void ap_sta_hash_del(struct hostapd_data *hapd, struct sta_info *sta)
130{
131 struct sta_info *s;
132
133 s = hapd->sta_hash[STA_HASH(sta->addr)];
134 if (s == NULL) return;
135 if (os_memcmp(s->addr, sta->addr, 6) == 0) {
136 hapd->sta_hash[STA_HASH(sta->addr)] = s->hnext;
137 return;
138 }
139
140 while (s->hnext != NULL &&
141 os_memcmp(s->hnext->addr, sta->addr, ETH_ALEN) != 0)
142 s = s->hnext;
143 if (s->hnext != NULL)
144 s->hnext = s->hnext->hnext;
145 else
146 wpa_printf(MSG_DEBUG, "AP: could not remove STA " MACSTR
147 " from hash table", MAC2STR(sta->addr));
148}
149
150
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800151void ap_sta_ip6addr_del(struct hostapd_data *hapd, struct sta_info *sta)
152{
153 sta_ip6addr_del(hapd, sta);
154}
155
156
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700157void ap_free_sta(struct hostapd_data *hapd, struct sta_info *sta)
158{
159 int set_beacon = 0;
160
161 accounting_sta_stop(hapd, sta);
162
163 /* just in case */
164 ap_sta_set_authorized(hapd, sta, 0);
165
166 if (sta->flags & WLAN_STA_WDS)
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -0700167 hostapd_set_wds_sta(hapd, NULL, sta->addr, sta->aid, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700168
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800169 if (sta->ipaddr)
170 hostapd_drv_br_delete_ip_neigh(hapd, 4, (u8 *) &sta->ipaddr);
171 ap_sta_ip6addr_del(hapd, sta);
172
Dmitry Shmidta38abf92014-03-06 13:38:44 -0800173 if (!hapd->iface->driver_ap_teardown &&
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800174 !(sta->flags & WLAN_STA_PREAUTH)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700175 hostapd_drv_sta_remove(hapd, sta->addr);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800176 sta->added_unassoc = 0;
177 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700178
179 ap_sta_hash_del(hapd, sta);
180 ap_sta_list_del(hapd, sta);
181
182 if (sta->aid > 0)
183 hapd->sta_aid[(sta->aid - 1) / 32] &=
184 ~BIT((sta->aid - 1) % 32);
185
186 hapd->num_sta--;
187 if (sta->nonerp_set) {
188 sta->nonerp_set = 0;
189 hapd->iface->num_sta_non_erp--;
190 if (hapd->iface->num_sta_non_erp == 0)
191 set_beacon++;
192 }
193
194 if (sta->no_short_slot_time_set) {
195 sta->no_short_slot_time_set = 0;
196 hapd->iface->num_sta_no_short_slot_time--;
197 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G
198 && hapd->iface->num_sta_no_short_slot_time == 0)
199 set_beacon++;
200 }
201
202 if (sta->no_short_preamble_set) {
203 sta->no_short_preamble_set = 0;
204 hapd->iface->num_sta_no_short_preamble--;
205 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G
206 && hapd->iface->num_sta_no_short_preamble == 0)
207 set_beacon++;
208 }
209
210 if (sta->no_ht_gf_set) {
211 sta->no_ht_gf_set = 0;
212 hapd->iface->num_sta_ht_no_gf--;
213 }
214
215 if (sta->no_ht_set) {
216 sta->no_ht_set = 0;
217 hapd->iface->num_sta_no_ht--;
218 }
219
220 if (sta->ht_20mhz_set) {
221 sta->ht_20mhz_set = 0;
222 hapd->iface->num_sta_ht_20mhz--;
223 }
224
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700225#ifdef CONFIG_IEEE80211N
226 ht40_intolerant_remove(hapd->iface, sta);
227#endif /* CONFIG_IEEE80211N */
228
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700229#ifdef CONFIG_P2P
230 if (sta->no_p2p_set) {
231 sta->no_p2p_set = 0;
232 hapd->num_sta_no_p2p--;
233 if (hapd->num_sta_no_p2p == 0)
234 hostapd_p2p_non_p2p_sta_disconnected(hapd);
235 }
236#endif /* CONFIG_P2P */
237
238#if defined(NEED_AP_MLME) && defined(CONFIG_IEEE80211N)
239 if (hostapd_ht_operation_update(hapd->iface) > 0)
240 set_beacon++;
241#endif /* NEED_AP_MLME && CONFIG_IEEE80211N */
242
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800243#ifdef CONFIG_MESH
244 if (hapd->mesh_sta_free_cb)
Dmitry Shmidtb97e4282016-02-08 10:16:07 -0800245 hapd->mesh_sta_free_cb(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800246#endif /* CONFIG_MESH */
247
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700248 if (set_beacon)
249 ieee802_11_set_beacons(hapd->iface);
250
Dmitry Shmidt04949592012-07-19 12:16:46 -0700251 wpa_printf(MSG_DEBUG, "%s: cancel ap_handle_timer for " MACSTR,
252 __func__, MAC2STR(sta->addr));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700253 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
254 eloop_cancel_timeout(ap_handle_session_timer, hapd, sta);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800255 eloop_cancel_timeout(ap_handle_session_warning_timer, hapd, sta);
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -0800256 ap_sta_clear_disconnect_timeouts(hapd, sta);
Dmitry Shmidtff787d52015-01-12 13:01:47 -0800257 sae_clear_retransmit_timer(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700258
Dmitry Shmidtde47be72016-01-07 12:52:55 -0800259 ieee802_1x_free_station(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700260 wpa_auth_sta_deinit(sta->wpa_sm);
261 rsn_preauth_free_station(hapd, sta);
262#ifndef CONFIG_NO_RADIUS
Dmitry Shmidt96571392013-10-14 12:54:46 -0700263 if (hapd->radius)
264 radius_client_flush_auth(hapd->radius, sta->addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700265#endif /* CONFIG_NO_RADIUS */
266
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800267#ifndef CONFIG_NO_VLAN
268 /*
269 * sta->wpa_sm->group needs to be released before so that
270 * vlan_remove_dynamic() can check that no stations are left on the
271 * AP_VLAN netdev.
272 */
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800273 if (sta->vlan_id)
274 vlan_remove_dynamic(hapd, sta->vlan_id);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800275 if (sta->vlan_id_bound) {
276 /*
277 * Need to remove the STA entry before potentially removing the
278 * VLAN.
279 */
280 if (hapd->iface->driver_ap_teardown &&
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800281 !(sta->flags & WLAN_STA_PREAUTH)) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800282 hostapd_drv_sta_remove(hapd, sta->addr);
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800283 sta->added_unassoc = 0;
284 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800285 vlan_remove_dynamic(hapd, sta->vlan_id_bound);
286 }
287#endif /* CONFIG_NO_VLAN */
288
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700289 os_free(sta->challenge);
290
291#ifdef CONFIG_IEEE80211W
292 os_free(sta->sa_query_trans_id);
293 eloop_cancel_timeout(ap_sa_query_timer, hapd, sta);
294#endif /* CONFIG_IEEE80211W */
295
296#ifdef CONFIG_P2P
297 p2p_group_notif_disassoc(hapd->p2p_group, sta->addr);
298#endif /* CONFIG_P2P */
299
Dmitry Shmidt04949592012-07-19 12:16:46 -0700300#ifdef CONFIG_INTERWORKING
301 if (sta->gas_dialog) {
302 int i;
303 for (i = 0; i < GAS_DIALOG_MAX; i++)
304 gas_serv_dialog_clear(&sta->gas_dialog[i]);
305 os_free(sta->gas_dialog);
306 }
307#endif /* CONFIG_INTERWORKING */
308
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700309 wpabuf_free(sta->wps_ie);
310 wpabuf_free(sta->p2p_ie);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800311 wpabuf_free(sta->hs20_ie);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800312#ifdef CONFIG_FST
313 wpabuf_free(sta->mb_ies);
314#endif /* CONFIG_FST */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700315
316 os_free(sta->ht_capabilities);
Dmitry Shmidt292b0c32013-11-22 12:54:42 -0800317 os_free(sta->vht_capabilities);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800318 hostapd_free_psk_list(sta->psk);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700319 os_free(sta->identity);
320 os_free(sta->radius_cui);
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800321 os_free(sta->remediation_url);
322 wpabuf_free(sta->hs20_deauth_req);
323 os_free(sta->hs20_session_info_url);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700324
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800325#ifdef CONFIG_SAE
326 sae_clear_data(sta->sae);
327 os_free(sta->sae);
328#endif /* CONFIG_SAE */
329
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800330 mbo_ap_sta_free(sta);
331
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700332 os_free(sta);
333}
334
335
336void hostapd_free_stas(struct hostapd_data *hapd)
337{
338 struct sta_info *sta, *prev;
339
340 sta = hapd->sta_list;
341
342 while (sta) {
343 prev = sta;
344 if (sta->flags & WLAN_STA_AUTH) {
345 mlme_deauthenticate_indication(
346 hapd, sta, WLAN_REASON_UNSPECIFIED);
347 }
348 sta = sta->next;
349 wpa_printf(MSG_DEBUG, "Removing station " MACSTR,
350 MAC2STR(prev->addr));
351 ap_free_sta(hapd, prev);
352 }
353}
354
355
356/**
357 * ap_handle_timer - Per STA timer handler
358 * @eloop_ctx: struct hostapd_data *
359 * @timeout_ctx: struct sta_info *
360 *
361 * This function is called to check station activity and to remove inactive
362 * stations.
363 */
364void ap_handle_timer(void *eloop_ctx, void *timeout_ctx)
365{
366 struct hostapd_data *hapd = eloop_ctx;
367 struct sta_info *sta = timeout_ctx;
368 unsigned long next_time = 0;
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700369 int reason;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700370
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -0800371 wpa_printf(MSG_DEBUG, "%s: %s: " MACSTR " flags=0x%x timeout_next=%d",
372 hapd->conf->iface, __func__, MAC2STR(sta->addr), sta->flags,
Dmitry Shmidt04949592012-07-19 12:16:46 -0700373 sta->timeout_next);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700374 if (sta->timeout_next == STA_REMOVE) {
375 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
376 HOSTAPD_LEVEL_INFO, "deauthenticated due to "
377 "local deauth request");
378 ap_free_sta(hapd, sta);
379 return;
380 }
381
382 if ((sta->flags & WLAN_STA_ASSOC) &&
383 (sta->timeout_next == STA_NULLFUNC ||
384 sta->timeout_next == STA_DISASSOC)) {
385 int inactive_sec;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700386 /*
387 * Add random value to timeout so that we don't end up bouncing
388 * all stations at the same time if we have lots of associated
389 * stations that are idle (but keep re-associating).
390 */
391 int fuzz = os_random() % 20;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700392 inactive_sec = hostapd_drv_get_inact_sec(hapd, sta->addr);
393 if (inactive_sec == -1) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800394 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
395 "Check inactivity: Could not "
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800396 "get station info from kernel driver for "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700397 MACSTR, MAC2STR(sta->addr));
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -0800398 /*
399 * The driver may not support this functionality.
400 * Anyway, try again after the next inactivity timeout,
401 * but do not disconnect the station now.
402 */
Dmitry Shmidt04949592012-07-19 12:16:46 -0700403 next_time = hapd->conf->ap_max_inactivity + fuzz;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800404 } else if (inactive_sec == -ENOENT) {
405 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
406 "Station " MACSTR " has lost its driver entry",
407 MAC2STR(sta->addr));
408
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800409 /* Avoid sending client probe on removed client */
410 sta->timeout_next = STA_DISASSOC;
411 goto skip_poll;
Dmitry Shmidt2f74e362015-01-21 13:19:05 -0800412 } else if (inactive_sec < hapd->conf->ap_max_inactivity) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700413 /* station activity detected; reset timeout state */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800414 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
415 "Station " MACSTR " has been active %is ago",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700416 MAC2STR(sta->addr), inactive_sec);
417 sta->timeout_next = STA_NULLFUNC;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700418 next_time = hapd->conf->ap_max_inactivity + fuzz -
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700419 inactive_sec;
420 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800421 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
422 "Station " MACSTR " has been "
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700423 "inactive too long: %d sec, max allowed: %d",
424 MAC2STR(sta->addr), inactive_sec,
425 hapd->conf->ap_max_inactivity);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800426
427 if (hapd->conf->skip_inactivity_poll)
428 sta->timeout_next = STA_DISASSOC;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700429 }
430 }
431
432 if ((sta->flags & WLAN_STA_ASSOC) &&
433 sta->timeout_next == STA_DISASSOC &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800434 !(sta->flags & WLAN_STA_PENDING_POLL) &&
435 !hapd->conf->skip_inactivity_poll) {
436 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR
437 " has ACKed data poll", MAC2STR(sta->addr));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700438 /* data nullfunc frame poll did not produce TX errors; assume
439 * station ACKed it */
440 sta->timeout_next = STA_NULLFUNC;
441 next_time = hapd->conf->ap_max_inactivity;
442 }
443
Dmitry Shmidt7f656022015-02-25 14:36:37 -0800444skip_poll:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700445 if (next_time) {
Dmitry Shmidt04949592012-07-19 12:16:46 -0700446 wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout "
447 "for " MACSTR " (%lu seconds)",
448 __func__, MAC2STR(sta->addr), next_time);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700449 eloop_register_timeout(next_time, 0, ap_handle_timer, hapd,
450 sta);
451 return;
452 }
453
454 if (sta->timeout_next == STA_NULLFUNC &&
455 (sta->flags & WLAN_STA_ASSOC)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800456 wpa_printf(MSG_DEBUG, " Polling STA");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700457 sta->flags |= WLAN_STA_PENDING_POLL;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800458 hostapd_drv_poll_client(hapd, hapd->own_addr, sta->addr,
459 sta->flags & WLAN_STA_WMM);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700460 } else if (sta->timeout_next != STA_REMOVE) {
461 int deauth = sta->timeout_next == STA_DEAUTH;
462
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800463 wpa_dbg(hapd->msg_ctx, MSG_DEBUG,
464 "Timeout, sending %s info to STA " MACSTR,
465 deauth ? "deauthentication" : "disassociation",
466 MAC2STR(sta->addr));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700467
468 if (deauth) {
469 hostapd_drv_sta_deauth(
470 hapd, sta->addr,
471 WLAN_REASON_PREV_AUTH_NOT_VALID);
472 } else {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700473 reason = (sta->timeout_next == STA_DISASSOC) ?
474 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY :
475 WLAN_REASON_PREV_AUTH_NOT_VALID;
476
477 hostapd_drv_sta_disassoc(hapd, sta->addr, reason);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700478 }
479 }
480
481 switch (sta->timeout_next) {
482 case STA_NULLFUNC:
483 sta->timeout_next = STA_DISASSOC;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700484 wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout "
485 "for " MACSTR " (%d seconds - AP_DISASSOC_DELAY)",
486 __func__, MAC2STR(sta->addr), AP_DISASSOC_DELAY);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700487 eloop_register_timeout(AP_DISASSOC_DELAY, 0, ap_handle_timer,
488 hapd, sta);
489 break;
490 case STA_DISASSOC:
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700491 case STA_DISASSOC_FROM_CLI:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800492 ap_sta_set_authorized(hapd, sta, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700493 sta->flags &= ~WLAN_STA_ASSOC;
494 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
495 if (!sta->acct_terminate_cause)
496 sta->acct_terminate_cause =
497 RADIUS_ACCT_TERMINATE_CAUSE_IDLE_TIMEOUT;
498 accounting_sta_stop(hapd, sta);
Dmitry Shmidtde47be72016-01-07 12:52:55 -0800499 ieee802_1x_free_station(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700500 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
501 HOSTAPD_LEVEL_INFO, "disassociated due to "
502 "inactivity");
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700503 reason = (sta->timeout_next == STA_DISASSOC) ?
504 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY :
505 WLAN_REASON_PREV_AUTH_NOT_VALID;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700506 sta->timeout_next = STA_DEAUTH;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700507 wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout "
508 "for " MACSTR " (%d seconds - AP_DEAUTH_DELAY)",
509 __func__, MAC2STR(sta->addr), AP_DEAUTH_DELAY);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700510 eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer,
511 hapd, sta);
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -0700512 mlme_disassociate_indication(hapd, sta, reason);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700513 break;
514 case STA_DEAUTH:
515 case STA_REMOVE:
516 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
517 HOSTAPD_LEVEL_INFO, "deauthenticated due to "
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800518 "inactivity (timer DEAUTH/REMOVE)");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700519 if (!sta->acct_terminate_cause)
520 sta->acct_terminate_cause =
521 RADIUS_ACCT_TERMINATE_CAUSE_IDLE_TIMEOUT;
522 mlme_deauthenticate_indication(
523 hapd, sta,
524 WLAN_REASON_PREV_AUTH_NOT_VALID);
525 ap_free_sta(hapd, sta);
526 break;
527 }
528}
529
530
531static void ap_handle_session_timer(void *eloop_ctx, void *timeout_ctx)
532{
533 struct hostapd_data *hapd = eloop_ctx;
534 struct sta_info *sta = timeout_ctx;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700535
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -0800536 wpa_printf(MSG_DEBUG, "%s: Session timer for STA " MACSTR,
537 hapd->conf->iface, MAC2STR(sta->addr));
Dmitry Shmidt04949592012-07-19 12:16:46 -0700538 if (!(sta->flags & WLAN_STA_AUTH)) {
539 if (sta->flags & WLAN_STA_GAS) {
540 wpa_printf(MSG_DEBUG, "GAS: Remove temporary STA "
541 "entry " MACSTR, MAC2STR(sta->addr));
542 ap_free_sta(hapd, sta);
543 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700544 return;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700545 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700546
Dmitry Shmidt818ea482014-03-10 13:15:21 -0700547 hostapd_drv_sta_deauth(hapd, sta->addr,
548 WLAN_REASON_PREV_AUTH_NOT_VALID);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700549 mlme_deauthenticate_indication(hapd, sta,
550 WLAN_REASON_PREV_AUTH_NOT_VALID);
551 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
552 HOSTAPD_LEVEL_INFO, "deauthenticated due to "
553 "session timeout");
554 sta->acct_terminate_cause =
555 RADIUS_ACCT_TERMINATE_CAUSE_SESSION_TIMEOUT;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700556 ap_free_sta(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700557}
558
559
Dmitry Shmidt54605472013-11-08 11:10:19 -0800560void ap_sta_replenish_timeout(struct hostapd_data *hapd, struct sta_info *sta,
561 u32 session_timeout)
562{
563 if (eloop_replenish_timeout(session_timeout, 0,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800564 ap_handle_session_timer, hapd, sta) == 1) {
Dmitry Shmidt54605472013-11-08 11:10:19 -0800565 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
566 HOSTAPD_LEVEL_DEBUG, "setting session timeout "
567 "to %d seconds", session_timeout);
568 }
569}
570
571
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700572void ap_sta_session_timeout(struct hostapd_data *hapd, struct sta_info *sta,
573 u32 session_timeout)
574{
575 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
576 HOSTAPD_LEVEL_DEBUG, "setting session timeout to %d "
577 "seconds", session_timeout);
578 eloop_cancel_timeout(ap_handle_session_timer, hapd, sta);
579 eloop_register_timeout(session_timeout, 0, ap_handle_session_timer,
580 hapd, sta);
581}
582
583
584void ap_sta_no_session_timeout(struct hostapd_data *hapd, struct sta_info *sta)
585{
586 eloop_cancel_timeout(ap_handle_session_timer, hapd, sta);
587}
588
589
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800590static void ap_handle_session_warning_timer(void *eloop_ctx, void *timeout_ctx)
591{
592#ifdef CONFIG_WNM
593 struct hostapd_data *hapd = eloop_ctx;
594 struct sta_info *sta = timeout_ctx;
595
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -0800596 wpa_printf(MSG_DEBUG, "%s: WNM: Session warning time reached for "
597 MACSTR, hapd->conf->iface, MAC2STR(sta->addr));
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800598 if (sta->hs20_session_info_url == NULL)
599 return;
600
601 wnm_send_ess_disassoc_imminent(hapd, sta, sta->hs20_session_info_url,
602 sta->hs20_disassoc_timer);
603#endif /* CONFIG_WNM */
604}
605
606
607void ap_sta_session_warning_timeout(struct hostapd_data *hapd,
608 struct sta_info *sta, int warning_time)
609{
610 eloop_cancel_timeout(ap_handle_session_warning_timer, hapd, sta);
611 eloop_register_timeout(warning_time, 0, ap_handle_session_warning_timer,
612 hapd, sta);
613}
614
615
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700616struct sta_info * ap_sta_add(struct hostapd_data *hapd, const u8 *addr)
617{
618 struct sta_info *sta;
619
620 sta = ap_get_sta(hapd, addr);
621 if (sta)
622 return sta;
623
624 wpa_printf(MSG_DEBUG, " New STA");
625 if (hapd->num_sta >= hapd->conf->max_num_sta) {
626 /* FIX: might try to remove some old STAs first? */
627 wpa_printf(MSG_DEBUG, "no more room for new STAs (%d/%d)",
628 hapd->num_sta, hapd->conf->max_num_sta);
629 return NULL;
630 }
631
632 sta = os_zalloc(sizeof(struct sta_info));
633 if (sta == NULL) {
634 wpa_printf(MSG_ERROR, "malloc failed");
635 return NULL;
636 }
637 sta->acct_interim_interval = hapd->conf->acct_interim_interval;
Dmitry Shmidtb97e4282016-02-08 10:16:07 -0800638 if (accounting_sta_get_id(hapd, sta) < 0) {
639 os_free(sta);
640 return NULL;
641 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700642
Dmitry Shmidt01904cf2013-12-05 11:08:35 -0800643 if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_INACTIVITY_TIMER)) {
644 wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout "
645 "for " MACSTR " (%d seconds - ap_max_inactivity)",
646 __func__, MAC2STR(addr),
647 hapd->conf->ap_max_inactivity);
648 eloop_register_timeout(hapd->conf->ap_max_inactivity, 0,
649 ap_handle_timer, hapd, sta);
650 }
651
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700652 /* initialize STA info data */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700653 os_memcpy(sta->addr, addr, ETH_ALEN);
654 sta->next = hapd->sta_list;
655 hapd->sta_list = sta;
656 hapd->num_sta++;
657 ap_sta_hash_add(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700658 ap_sta_remove_in_other_bss(hapd, sta);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800659 sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ;
660 dl_list_init(&sta->ip6addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700661
662 return sta;
663}
664
665
666static int ap_sta_remove(struct hostapd_data *hapd, struct sta_info *sta)
667{
668 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
669
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800670 if (sta->ipaddr)
671 hostapd_drv_br_delete_ip_neigh(hapd, 4, (u8 *) &sta->ipaddr);
672 ap_sta_ip6addr_del(hapd, sta);
673
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -0800674 wpa_printf(MSG_DEBUG, "%s: Removing STA " MACSTR " from kernel driver",
675 hapd->conf->iface, MAC2STR(sta->addr));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700676 if (hostapd_drv_sta_remove(hapd, sta->addr) &&
677 sta->flags & WLAN_STA_ASSOC) {
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -0800678 wpa_printf(MSG_DEBUG, "%s: Could not remove station " MACSTR
679 " from kernel driver",
680 hapd->conf->iface, MAC2STR(sta->addr));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700681 return -1;
682 }
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800683 sta->added_unassoc = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700684 return 0;
685}
686
687
688static void ap_sta_remove_in_other_bss(struct hostapd_data *hapd,
689 struct sta_info *sta)
690{
691 struct hostapd_iface *iface = hapd->iface;
692 size_t i;
693
694 for (i = 0; i < iface->num_bss; i++) {
695 struct hostapd_data *bss = iface->bss[i];
696 struct sta_info *sta2;
697 /* bss should always be set during operation, but it may be
698 * NULL during reconfiguration. Assume the STA is not
699 * associated to another BSS in that case to avoid NULL pointer
700 * dereferences. */
701 if (bss == hapd || bss == NULL)
702 continue;
703 sta2 = ap_get_sta(bss, sta->addr);
704 if (!sta2)
705 continue;
706
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -0800707 wpa_printf(MSG_DEBUG, "%s: disconnect old STA " MACSTR
708 " association from another BSS %s",
709 hapd->conf->iface, MAC2STR(sta2->addr),
710 bss->conf->iface);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700711 ap_sta_disconnect(bss, sta2, sta2->addr,
712 WLAN_REASON_PREV_AUTH_NOT_VALID);
713 }
714}
715
716
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800717static void ap_sta_disassoc_cb_timeout(void *eloop_ctx, void *timeout_ctx)
718{
719 struct hostapd_data *hapd = eloop_ctx;
720 struct sta_info *sta = timeout_ctx;
721
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -0800722 wpa_printf(MSG_DEBUG, "%s: Disassociation callback for STA " MACSTR,
723 hapd->conf->iface, MAC2STR(sta->addr));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800724 ap_sta_remove(hapd, sta);
725 mlme_disassociate_indication(hapd, sta, sta->disassoc_reason);
726}
727
728
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700729void ap_sta_disassociate(struct hostapd_data *hapd, struct sta_info *sta,
730 u16 reason)
731{
732 wpa_printf(MSG_DEBUG, "%s: disassociate STA " MACSTR,
733 hapd->conf->iface, MAC2STR(sta->addr));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800734 sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ;
Dmitry Shmidt700a1372013-03-15 14:14:44 -0700735 sta->flags &= ~(WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800736 ap_sta_set_authorized(hapd, sta, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700737 sta->timeout_next = STA_DEAUTH;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700738 wpa_printf(MSG_DEBUG, "%s: reschedule ap_handle_timer timeout "
739 "for " MACSTR " (%d seconds - "
740 "AP_MAX_INACTIVITY_AFTER_DISASSOC)",
741 __func__, MAC2STR(sta->addr),
742 AP_MAX_INACTIVITY_AFTER_DISASSOC);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700743 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
744 eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DISASSOC, 0,
745 ap_handle_timer, hapd, sta);
746 accounting_sta_stop(hapd, sta);
Dmitry Shmidtde47be72016-01-07 12:52:55 -0800747 ieee802_1x_free_station(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700748
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800749 sta->disassoc_reason = reason;
750 sta->flags |= WLAN_STA_PENDING_DISASSOC_CB;
751 eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta);
752 eloop_register_timeout(hapd->iface->drv_flags &
753 WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0,
754 ap_sta_disassoc_cb_timeout, hapd, sta);
755}
756
757
758static void ap_sta_deauth_cb_timeout(void *eloop_ctx, void *timeout_ctx)
759{
760 struct hostapd_data *hapd = eloop_ctx;
761 struct sta_info *sta = timeout_ctx;
762
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -0800763 wpa_printf(MSG_DEBUG, "%s: Deauthentication callback for STA " MACSTR,
764 hapd->conf->iface, MAC2STR(sta->addr));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800765 ap_sta_remove(hapd, sta);
766 mlme_deauthenticate_indication(hapd, sta, sta->deauth_reason);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700767}
768
769
770void ap_sta_deauthenticate(struct hostapd_data *hapd, struct sta_info *sta,
771 u16 reason)
772{
773 wpa_printf(MSG_DEBUG, "%s: deauthenticate STA " MACSTR,
774 hapd->conf->iface, MAC2STR(sta->addr));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800775 sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ;
776 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800777 ap_sta_set_authorized(hapd, sta, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700778 sta->timeout_next = STA_REMOVE;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700779 wpa_printf(MSG_DEBUG, "%s: reschedule ap_handle_timer timeout "
780 "for " MACSTR " (%d seconds - "
781 "AP_MAX_INACTIVITY_AFTER_DEAUTH)",
782 __func__, MAC2STR(sta->addr),
783 AP_MAX_INACTIVITY_AFTER_DEAUTH);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700784 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
785 eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DEAUTH, 0,
786 ap_handle_timer, hapd, sta);
787 accounting_sta_stop(hapd, sta);
Dmitry Shmidtde47be72016-01-07 12:52:55 -0800788 ieee802_1x_free_station(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700789
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800790 sta->deauth_reason = reason;
791 sta->flags |= WLAN_STA_PENDING_DEAUTH_CB;
792 eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
793 eloop_register_timeout(hapd->iface->drv_flags &
794 WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0,
795 ap_sta_deauth_cb_timeout, hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700796}
797
798
Dmitry Shmidt04949592012-07-19 12:16:46 -0700799#ifdef CONFIG_WPS
800int ap_sta_wps_cancel(struct hostapd_data *hapd,
801 struct sta_info *sta, void *ctx)
802{
803 if (sta && (sta->flags & WLAN_STA_WPS)) {
804 ap_sta_deauthenticate(hapd, sta,
805 WLAN_REASON_PREV_AUTH_NOT_VALID);
806 wpa_printf(MSG_DEBUG, "WPS: %s: Deauth sta=" MACSTR,
807 __func__, MAC2STR(sta->addr));
808 return 1;
809 }
810
811 return 0;
812}
813#endif /* CONFIG_WPS */
814
815
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800816static int ap_sta_get_free_vlan_id(struct hostapd_data *hapd)
817{
818 struct hostapd_vlan *vlan;
819 int vlan_id = MAX_VLAN_ID + 2;
820
821retry:
822 for (vlan = hapd->conf->vlan; vlan; vlan = vlan->next) {
823 if (vlan->vlan_id == vlan_id) {
824 vlan_id++;
825 goto retry;
826 }
827 }
828 return vlan_id;
829}
830
831
832int ap_sta_set_vlan(struct hostapd_data *hapd, struct sta_info *sta,
833 struct vlan_description *vlan_desc)
834{
835 struct hostapd_vlan *vlan = NULL, *wildcard_vlan = NULL;
836 int old_vlan_id, vlan_id = 0, ret = 0;
837
838 if (hapd->conf->ssid.dynamic_vlan == DYNAMIC_VLAN_DISABLED)
839 vlan_desc = NULL;
840
841 /* Check if there is something to do */
842 if (hapd->conf->ssid.per_sta_vif && !sta->vlan_id) {
843 /* This sta is lacking its own vif */
844 } else if (hapd->conf->ssid.dynamic_vlan == DYNAMIC_VLAN_DISABLED &&
845 !hapd->conf->ssid.per_sta_vif && sta->vlan_id) {
846 /* sta->vlan_id needs to be reset */
847 } else if (!vlan_compare(vlan_desc, sta->vlan_desc)) {
848 return 0; /* nothing to change */
849 }
850
851 /* Now the real VLAN changed or the STA just needs its own vif */
852 if (hapd->conf->ssid.per_sta_vif) {
853 /* Assign a new vif, always */
854 /* find a free vlan_id sufficiently big */
855 vlan_id = ap_sta_get_free_vlan_id(hapd);
856 /* Get wildcard VLAN */
857 for (vlan = hapd->conf->vlan; vlan; vlan = vlan->next) {
858 if (vlan->vlan_id == VLAN_ID_WILDCARD)
859 break;
860 }
861 if (!vlan) {
862 hostapd_logger(hapd, sta->addr,
863 HOSTAPD_MODULE_IEEE80211,
864 HOSTAPD_LEVEL_DEBUG,
865 "per_sta_vif missing wildcard");
866 vlan_id = 0;
867 ret = -1;
868 goto done;
869 }
870 } else if (vlan_desc && vlan_desc->notempty) {
871 for (vlan = hapd->conf->vlan; vlan; vlan = vlan->next) {
872 if (!vlan_compare(&vlan->vlan_desc, vlan_desc))
873 break;
874 if (vlan->vlan_id == VLAN_ID_WILDCARD)
875 wildcard_vlan = vlan;
876 }
877 if (vlan) {
878 vlan_id = vlan->vlan_id;
879 } else if (wildcard_vlan) {
880 vlan = wildcard_vlan;
881 vlan_id = vlan_desc->untagged;
882 if (vlan_desc->tagged[0]) {
883 /* Tagged VLAN configuration */
884 vlan_id = ap_sta_get_free_vlan_id(hapd);
885 }
886 } else {
887 hostapd_logger(hapd, sta->addr,
888 HOSTAPD_MODULE_IEEE80211,
889 HOSTAPD_LEVEL_DEBUG,
890 "missing vlan and wildcard for vlan=%d%s",
891 vlan_desc->untagged,
892 vlan_desc->tagged[0] ? "+" : "");
893 vlan_id = 0;
894 ret = -1;
895 goto done;
896 }
897 }
898
899 if (vlan && vlan->vlan_id == VLAN_ID_WILDCARD) {
900 vlan = vlan_add_dynamic(hapd, vlan, vlan_id, vlan_desc);
901 if (vlan == NULL) {
902 hostapd_logger(hapd, sta->addr,
903 HOSTAPD_MODULE_IEEE80211,
904 HOSTAPD_LEVEL_DEBUG,
905 "could not add dynamic VLAN interface for vlan=%d%s",
906 vlan_desc ? vlan_desc->untagged : -1,
907 (vlan_desc && vlan_desc->tagged[0]) ?
908 "+" : "");
909 vlan_id = 0;
910 ret = -1;
911 goto done;
912 }
913
914 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
915 HOSTAPD_LEVEL_DEBUG,
916 "added new dynamic VLAN interface '%s'",
917 vlan->ifname);
918 } else if (vlan && vlan->dynamic_vlan > 0) {
919 vlan->dynamic_vlan++;
920 hostapd_logger(hapd, sta->addr,
921 HOSTAPD_MODULE_IEEE80211,
922 HOSTAPD_LEVEL_DEBUG,
923 "updated existing dynamic VLAN interface '%s'",
924 vlan->ifname);
925 }
926done:
927 old_vlan_id = sta->vlan_id;
928 sta->vlan_id = vlan_id;
929 sta->vlan_desc = vlan ? &vlan->vlan_desc : NULL;
930
931 if (vlan_id != old_vlan_id && old_vlan_id)
932 vlan_remove_dynamic(hapd, old_vlan_id);
933
934 return ret;
935}
936
937
Dmitry Shmidt83474442015-04-15 13:47:09 -0700938int ap_sta_bind_vlan(struct hostapd_data *hapd, struct sta_info *sta)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700939{
940#ifndef CONFIG_NO_VLAN
941 const char *iface;
942 struct hostapd_vlan *vlan = NULL;
943 int ret;
Dmitry Shmidt83474442015-04-15 13:47:09 -0700944 int old_vlanid = sta->vlan_id_bound;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700945
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700946 iface = hapd->conf->iface;
Dmitry Shmidt9d9e6022015-04-23 10:34:55 -0700947 if (hapd->conf->ssid.vlan[0])
948 iface = hapd->conf->ssid.vlan;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700949
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800950 if (sta->vlan_id > 0) {
951 for (vlan = hapd->conf->vlan; vlan; vlan = vlan->next) {
Dmitry Shmidtd5c075b2013-08-05 14:36:10 -0700952 if (vlan->vlan_id == sta->vlan_id)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700953 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700954 }
Dmitry Shmidtd5c075b2013-08-05 14:36:10 -0700955 if (vlan)
956 iface = vlan->ifname;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700957 }
958
Dmitry Shmidt83474442015-04-15 13:47:09 -0700959 /*
960 * Do not increment ref counters if the VLAN ID remains same, but do
961 * not skip hostapd_drv_set_sta_vlan() as hostapd_drv_sta_remove() might
962 * have been called before.
963 */
964 if (sta->vlan_id == old_vlanid)
965 goto skip_counting;
966
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700967 if (sta->vlan_id > 0 && vlan == NULL) {
968 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
969 HOSTAPD_LEVEL_DEBUG, "could not find VLAN for "
970 "binding station to (vlan_id=%d)",
971 sta->vlan_id);
Dmitry Shmidt216983b2015-02-06 10:50:36 -0800972 ret = -1;
973 goto done;
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800974 } else if (vlan && vlan->dynamic_vlan > 0) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800975 vlan->dynamic_vlan++;
976 hostapd_logger(hapd, sta->addr,
977 HOSTAPD_MODULE_IEEE80211,
978 HOSTAPD_LEVEL_DEBUG,
979 "updated existing dynamic VLAN interface '%s'",
980 iface);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700981 }
982
Dmitry Shmidt83474442015-04-15 13:47:09 -0700983 /* ref counters have been increased, so mark the station */
984 sta->vlan_id_bound = sta->vlan_id;
985
986skip_counting:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700987 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
988 HOSTAPD_LEVEL_DEBUG, "binding station to interface "
989 "'%s'", iface);
990
991 if (wpa_auth_sta_set_vlan(sta->wpa_sm, sta->vlan_id) < 0)
992 wpa_printf(MSG_INFO, "Failed to update VLAN-ID for WPA");
993
994 ret = hostapd_drv_set_sta_vlan(iface, hapd, sta->addr, sta->vlan_id);
995 if (ret < 0) {
996 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
997 HOSTAPD_LEVEL_DEBUG, "could not bind the STA "
998 "entry to vlan_id=%d", sta->vlan_id);
999 }
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001000
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001001 /* During 1x reauth, if the vlan id changes, then remove the old id. */
Dmitry Shmidt83474442015-04-15 13:47:09 -07001002 if (old_vlanid > 0 && old_vlanid != sta->vlan_id)
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001003 vlan_remove_dynamic(hapd, old_vlanid);
Dmitry Shmidt83474442015-04-15 13:47:09 -07001004done:
Dmitry Shmidt216983b2015-02-06 10:50:36 -08001005
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001006 return ret;
1007#else /* CONFIG_NO_VLAN */
1008 return 0;
1009#endif /* CONFIG_NO_VLAN */
1010}
1011
1012
1013#ifdef CONFIG_IEEE80211W
1014
1015int ap_check_sa_query_timeout(struct hostapd_data *hapd, struct sta_info *sta)
1016{
1017 u32 tu;
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08001018 struct os_reltime now, passed;
1019 os_get_reltime(&now);
1020 os_reltime_sub(&now, &sta->sa_query_start, &passed);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001021 tu = (passed.sec * 1000000 + passed.usec) / 1024;
1022 if (hapd->conf->assoc_sa_query_max_timeout < tu) {
1023 hostapd_logger(hapd, sta->addr,
1024 HOSTAPD_MODULE_IEEE80211,
1025 HOSTAPD_LEVEL_DEBUG,
1026 "association SA Query timed out");
1027 sta->sa_query_timed_out = 1;
1028 os_free(sta->sa_query_trans_id);
1029 sta->sa_query_trans_id = NULL;
1030 sta->sa_query_count = 0;
1031 eloop_cancel_timeout(ap_sa_query_timer, hapd, sta);
1032 return 1;
1033 }
1034
1035 return 0;
1036}
1037
1038
1039static void ap_sa_query_timer(void *eloop_ctx, void *timeout_ctx)
1040{
1041 struct hostapd_data *hapd = eloop_ctx;
1042 struct sta_info *sta = timeout_ctx;
1043 unsigned int timeout, sec, usec;
1044 u8 *trans_id, *nbuf;
1045
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -08001046 wpa_printf(MSG_DEBUG, "%s: SA Query timer for STA " MACSTR
1047 " (count=%d)",
1048 hapd->conf->iface, MAC2STR(sta->addr), sta->sa_query_count);
1049
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001050 if (sta->sa_query_count > 0 &&
1051 ap_check_sa_query_timeout(hapd, sta))
1052 return;
1053
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001054 nbuf = os_realloc_array(sta->sa_query_trans_id,
1055 sta->sa_query_count + 1,
1056 WLAN_SA_QUERY_TR_ID_LEN);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001057 if (nbuf == NULL)
1058 return;
1059 if (sta->sa_query_count == 0) {
1060 /* Starting a new SA Query procedure */
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08001061 os_get_reltime(&sta->sa_query_start);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001062 }
1063 trans_id = nbuf + sta->sa_query_count * WLAN_SA_QUERY_TR_ID_LEN;
1064 sta->sa_query_trans_id = nbuf;
1065 sta->sa_query_count++;
1066
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001067 if (os_get_random(trans_id, WLAN_SA_QUERY_TR_ID_LEN) < 0) {
1068 /*
1069 * We don't really care which ID is used here, so simply
1070 * hardcode this if the mostly theoretical os_get_random()
1071 * failure happens.
1072 */
1073 trans_id[0] = 0x12;
1074 trans_id[1] = 0x34;
1075 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001076
1077 timeout = hapd->conf->assoc_sa_query_retry_timeout;
1078 sec = ((timeout / 1000) * 1024) / 1000;
1079 usec = (timeout % 1000) * 1024;
1080 eloop_register_timeout(sec, usec, ap_sa_query_timer, hapd, sta);
1081
1082 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1083 HOSTAPD_LEVEL_DEBUG,
1084 "association SA Query attempt %d", sta->sa_query_count);
1085
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001086 ieee802_11_send_sa_query_req(hapd, sta->addr, trans_id);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001087}
1088
1089
1090void ap_sta_start_sa_query(struct hostapd_data *hapd, struct sta_info *sta)
1091{
1092 ap_sa_query_timer(hapd, sta);
1093}
1094
1095
1096void ap_sta_stop_sa_query(struct hostapd_data *hapd, struct sta_info *sta)
1097{
1098 eloop_cancel_timeout(ap_sa_query_timer, hapd, sta);
1099 os_free(sta->sa_query_trans_id);
1100 sta->sa_query_trans_id = NULL;
1101 sta->sa_query_count = 0;
1102}
1103
1104#endif /* CONFIG_IEEE80211W */
1105
1106
1107void ap_sta_set_authorized(struct hostapd_data *hapd, struct sta_info *sta,
1108 int authorized)
1109{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001110 const u8 *dev_addr = NULL;
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07001111 char buf[100];
Dmitry Shmidt04949592012-07-19 12:16:46 -07001112#ifdef CONFIG_P2P
1113 u8 addr[ETH_ALEN];
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001114 u8 ip_addr_buf[4];
Dmitry Shmidt04949592012-07-19 12:16:46 -07001115#endif /* CONFIG_P2P */
1116
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001117 if (!!authorized == !!(sta->flags & WLAN_STA_AUTHORIZED))
1118 return;
1119
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001120 if (authorized)
1121 sta->flags |= WLAN_STA_AUTHORIZED;
1122 else
1123 sta->flags &= ~WLAN_STA_AUTHORIZED;
1124
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001125#ifdef CONFIG_P2P
Dmitry Shmidt04949592012-07-19 12:16:46 -07001126 if (hapd->p2p_group == NULL) {
1127 if (sta->p2p_ie != NULL &&
1128 p2p_parse_dev_addr_in_p2p_ie(sta->p2p_ie, addr) == 0)
1129 dev_addr = addr;
1130 } else
1131 dev_addr = p2p_group_get_dev_addr(hapd->p2p_group, sta->addr);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001132
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07001133 if (dev_addr)
1134 os_snprintf(buf, sizeof(buf), MACSTR " p2p_dev_addr=" MACSTR,
1135 MAC2STR(sta->addr), MAC2STR(dev_addr));
1136 else
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001137#endif /* CONFIG_P2P */
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07001138 os_snprintf(buf, sizeof(buf), MACSTR, MAC2STR(sta->addr));
1139
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001140 if (hapd->sta_authorized_cb)
1141 hapd->sta_authorized_cb(hapd->sta_authorized_cb_ctx,
1142 sta->addr, authorized, dev_addr);
1143
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001144 if (authorized) {
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001145 char ip_addr[100];
1146 ip_addr[0] = '\0';
1147#ifdef CONFIG_P2P
1148 if (wpa_auth_get_ip_addr(sta->wpa_sm, ip_addr_buf) == 0) {
1149 os_snprintf(ip_addr, sizeof(ip_addr),
1150 " ip_addr=%u.%u.%u.%u",
1151 ip_addr_buf[0], ip_addr_buf[1],
1152 ip_addr_buf[2], ip_addr_buf[3]);
1153 }
1154#endif /* CONFIG_P2P */
1155
1156 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_CONNECTED "%s%s",
1157 buf, ip_addr);
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07001158
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001159 if (hapd->msg_ctx_parent &&
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07001160 hapd->msg_ctx_parent != hapd->msg_ctx)
1161 wpa_msg_no_global(hapd->msg_ctx_parent, MSG_INFO,
Dmitry Shmidtcf32e602014-01-28 10:57:39 -08001162 AP_STA_CONNECTED "%s%s",
1163 buf, ip_addr);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001164 } else {
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07001165 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_DISCONNECTED "%s", buf);
1166
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001167 if (hapd->msg_ctx_parent &&
Dmitry Shmidtb6e9aaf2013-05-20 14:49:44 -07001168 hapd->msg_ctx_parent != hapd->msg_ctx)
1169 wpa_msg_no_global(hapd->msg_ctx_parent, MSG_INFO,
1170 AP_STA_DISCONNECTED "%s", buf);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001171 }
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001172
1173#ifdef CONFIG_FST
1174 if (hapd->iface->fst) {
1175 if (authorized)
1176 fst_notify_peer_connected(hapd->iface->fst, sta->addr);
1177 else
1178 fst_notify_peer_disconnected(hapd->iface->fst,
1179 sta->addr);
1180 }
1181#endif /* CONFIG_FST */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001182}
1183
1184
1185void ap_sta_disconnect(struct hostapd_data *hapd, struct sta_info *sta,
1186 const u8 *addr, u16 reason)
1187{
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -08001188 if (sta)
1189 wpa_printf(MSG_DEBUG, "%s: %s STA " MACSTR " reason=%u",
1190 hapd->conf->iface, __func__, MAC2STR(sta->addr),
1191 reason);
1192 else if (addr)
1193 wpa_printf(MSG_DEBUG, "%s: %s addr " MACSTR " reason=%u",
1194 hapd->conf->iface, __func__, MAC2STR(addr),
1195 reason);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001196
1197 if (sta == NULL && addr)
1198 sta = ap_get_sta(hapd, addr);
1199
1200 if (addr)
1201 hostapd_drv_sta_deauth(hapd, addr, reason);
1202
1203 if (sta == NULL)
1204 return;
1205 ap_sta_set_authorized(hapd, sta, 0);
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08001206 wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH);
1207 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001208 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -08001209 wpa_printf(MSG_DEBUG, "%s: %s: reschedule ap_handle_timer timeout "
Dmitry Shmidt04949592012-07-19 12:16:46 -07001210 "for " MACSTR " (%d seconds - "
1211 "AP_MAX_INACTIVITY_AFTER_DEAUTH)",
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -08001212 hapd->conf->iface, __func__, MAC2STR(sta->addr),
Dmitry Shmidt04949592012-07-19 12:16:46 -07001213 AP_MAX_INACTIVITY_AFTER_DEAUTH);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001214 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001215 eloop_register_timeout(AP_MAX_INACTIVITY_AFTER_DEAUTH, 0,
1216 ap_handle_timer, hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001217 sta->timeout_next = STA_REMOVE;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001218
1219 sta->deauth_reason = reason;
1220 sta->flags |= WLAN_STA_PENDING_DEAUTH_CB;
1221 eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
1222 eloop_register_timeout(hapd->iface->drv_flags &
1223 WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS ? 2 : 0, 0,
1224 ap_sta_deauth_cb_timeout, hapd, sta);
1225}
1226
1227
1228void ap_sta_deauth_cb(struct hostapd_data *hapd, struct sta_info *sta)
1229{
1230 if (!(sta->flags & WLAN_STA_PENDING_DEAUTH_CB)) {
1231 wpa_printf(MSG_DEBUG, "Ignore deauth cb for test frame");
1232 return;
1233 }
1234 sta->flags &= ~WLAN_STA_PENDING_DEAUTH_CB;
1235 eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta);
1236 ap_sta_deauth_cb_timeout(hapd, sta);
1237}
1238
1239
1240void ap_sta_disassoc_cb(struct hostapd_data *hapd, struct sta_info *sta)
1241{
1242 if (!(sta->flags & WLAN_STA_PENDING_DISASSOC_CB)) {
1243 wpa_printf(MSG_DEBUG, "Ignore disassoc cb for test frame");
1244 return;
1245 }
1246 sta->flags &= ~WLAN_STA_PENDING_DISASSOC_CB;
1247 eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta);
1248 ap_sta_disassoc_cb_timeout(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001249}
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001250
1251
Dmitry Shmidt1d6bf422016-01-19 15:51:35 -08001252void ap_sta_clear_disconnect_timeouts(struct hostapd_data *hapd,
1253 struct sta_info *sta)
1254{
1255 if (eloop_cancel_timeout(ap_sta_deauth_cb_timeout, hapd, sta) > 0)
1256 wpa_printf(MSG_DEBUG,
1257 "%s: Removed ap_sta_deauth_cb_timeout timeout for "
1258 MACSTR,
1259 hapd->conf->iface, MAC2STR(sta->addr));
1260 if (eloop_cancel_timeout(ap_sta_disassoc_cb_timeout, hapd, sta) > 0)
1261 wpa_printf(MSG_DEBUG,
1262 "%s: Removed ap_sta_disassoc_cb_timeout timeout for "
1263 MACSTR,
1264 hapd->conf->iface, MAC2STR(sta->addr));
1265}
1266
1267
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001268int ap_sta_flags_txt(u32 flags, char *buf, size_t buflen)
1269{
1270 int res;
1271
1272 buf[0] = '\0';
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001273 res = os_snprintf(buf, buflen, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001274 (flags & WLAN_STA_AUTH ? "[AUTH]" : ""),
1275 (flags & WLAN_STA_ASSOC ? "[ASSOC]" : ""),
1276 (flags & WLAN_STA_AUTHORIZED ? "[AUTHORIZED]" : ""),
1277 (flags & WLAN_STA_PENDING_POLL ? "[PENDING_POLL" :
1278 ""),
1279 (flags & WLAN_STA_SHORT_PREAMBLE ?
1280 "[SHORT_PREAMBLE]" : ""),
1281 (flags & WLAN_STA_PREAUTH ? "[PREAUTH]" : ""),
1282 (flags & WLAN_STA_WMM ? "[WMM]" : ""),
1283 (flags & WLAN_STA_MFP ? "[MFP]" : ""),
1284 (flags & WLAN_STA_WPS ? "[WPS]" : ""),
1285 (flags & WLAN_STA_MAYBE_WPS ? "[MAYBE_WPS]" : ""),
1286 (flags & WLAN_STA_WDS ? "[WDS]" : ""),
1287 (flags & WLAN_STA_NONERP ? "[NonERP]" : ""),
1288 (flags & WLAN_STA_WPS2 ? "[WPS2]" : ""),
1289 (flags & WLAN_STA_GAS ? "[GAS]" : ""),
1290 (flags & WLAN_STA_VHT ? "[VHT]" : ""),
Dmitry Shmidt2f74e362015-01-21 13:19:05 -08001291 (flags & WLAN_STA_VENDOR_VHT ? "[VENDOR_VHT]" : ""),
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001292 (flags & WLAN_STA_WNM_SLEEP_MODE ?
1293 "[WNM_SLEEP_MODE]" : ""));
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001294 if (os_snprintf_error(buflen, res))
1295 res = -1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001296
1297 return res;
1298}