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