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