Added support for configuring secondary channel offset for HT40
[wpasupplicant] / hostapd / ieee802_11.c
1 /*
2  * hostapd / IEEE 802.11 Management
3  * Copyright (c) 2002-2008, Jouni Malinen <j@w1.fi>
4  * Copyright (c) 2007-2008, Intel Corporation
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * Alternatively, this software may be distributed under the terms of BSD
11  * license.
12  *
13  * See README and COPYING for more details.
14  */
15
16 #include "includes.h"
17
18 #ifndef CONFIG_NATIVE_WINDOWS
19
20 #include <net/if.h>
21
22 #include "eloop.h"
23 #include "hostapd.h"
24 #include "ieee802_11.h"
25 #include "beacon.h"
26 #include "hw_features.h"
27 #include "radius/radius.h"
28 #include "radius/radius_client.h"
29 #include "ieee802_11_auth.h"
30 #include "sta_info.h"
31 #include "rc4.h"
32 #include "ieee802_1x.h"
33 #include "wpa.h"
34 #include "wme.h"
35 #include "ap_list.h"
36 #include "accounting.h"
37 #include "driver.h"
38 #include "mlme.h"
39
40
41 u8 * hostapd_eid_supp_rates(struct hostapd_data *hapd, u8 *eid)
42 {
43         u8 *pos = eid;
44         int i, num, count;
45
46         if (hapd->iface->current_rates == NULL)
47                 return eid;
48
49         *pos++ = WLAN_EID_SUPP_RATES;
50         num = hapd->iface->num_rates;
51         if (num > 8) {
52                 /* rest of the rates are encoded in Extended supported
53                  * rates element */
54                 num = 8;
55         }
56
57         *pos++ = num;
58         count = 0;
59         for (i = 0, count = 0; i < hapd->iface->num_rates && count < num;
60              i++) {
61                 count++;
62                 *pos = hapd->iface->current_rates[i].rate / 5;
63                 if (hapd->iface->current_rates[i].flags & HOSTAPD_RATE_BASIC)
64                         *pos |= 0x80;
65                 pos++;
66         }
67
68         return pos;
69 }
70
71
72 u8 * hostapd_eid_ext_supp_rates(struct hostapd_data *hapd, u8 *eid)
73 {
74         u8 *pos = eid;
75         int i, num, count;
76
77         if (hapd->iface->current_rates == NULL)
78                 return eid;
79
80         num = hapd->iface->num_rates;
81         if (num <= 8)
82                 return eid;
83         num -= 8;
84
85         *pos++ = WLAN_EID_EXT_SUPP_RATES;
86         *pos++ = num;
87         count = 0;
88         for (i = 0, count = 0; i < hapd->iface->num_rates && count < num + 8;
89              i++) {
90                 count++;
91                 if (count <= 8)
92                         continue; /* already in SuppRates IE */
93                 *pos = hapd->iface->current_rates[i].rate / 5;
94                 if (hapd->iface->current_rates[i].flags & HOSTAPD_RATE_BASIC)
95                         *pos |= 0x80;
96                 pos++;
97         }
98
99         return pos;
100 }
101
102
103 u8 * hostapd_eid_ht_capabilities_info(struct hostapd_data *hapd, u8 *eid)
104 {
105 #ifdef CONFIG_IEEE80211N
106         struct ieee80211_ht_capability *cap;
107         u8 *pos = eid;
108
109         if (!hapd->iconf->ieee80211n)
110                 return eid;
111
112         *pos++ = WLAN_EID_HT_CAP;
113         *pos++ = sizeof(*cap);
114
115         cap = (struct ieee80211_ht_capability *) pos;
116         os_memset(cap, 0, sizeof(*cap));
117         SET_2BIT_U8(&cap->mac_ht_params_info,
118                     MAC_HT_PARAM_INFO_MAX_RX_AMPDU_FACTOR_OFFSET,
119                     MAX_RX_AMPDU_FACTOR_64KB);
120
121         cap->capabilities_info = host_to_le16(hapd->iconf->ht_capab);
122
123         cap->supported_mcs_set[0] = 0xff;
124         cap->supported_mcs_set[1] = 0xff;
125
126         pos += sizeof(*cap);
127
128         return pos;
129 #else /* CONFIG_IEEE80211N */
130         return eid;
131 #endif /* CONFIG_IEEE80211N */
132 }
133
134
135 u8 * hostapd_eid_ht_operation(struct hostapd_data *hapd, u8 *eid)
136 {
137 #ifdef CONFIG_IEEE80211N
138         struct ieee80211_ht_operation *oper;
139         u8 *pos = eid;
140
141         if (!hapd->iconf->ieee80211n)
142                 return eid;
143
144         *pos++ = WLAN_EID_HT_OPERATION;
145         *pos++ = sizeof(*oper);
146
147         oper = (struct ieee80211_ht_operation *) pos;
148         os_memset(oper, 0, sizeof(*oper));
149
150         oper->control_chan = hapd->iconf->channel;
151         oper->operation_mode = host_to_le16(hapd->iface->ht_op_mode);
152         if (hapd->iconf->secondary_channel == 1)
153                 oper->ht_param |= HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE;
154         if (hapd->iconf->secondary_channel == -1)
155                 oper->ht_param |= HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW;
156
157         pos += sizeof(*oper);
158
159         return pos;
160 #else /* CONFIG_IEEE80211N */
161         return eid;
162 #endif /* CONFIG_IEEE80211N */
163 }
164
165
166 #ifdef CONFIG_IEEE80211N
167
168 /*
169 op_mode
170 Set to 0 (HT pure) under the followign conditions
171         - all STAs in the BSS are 20/40 MHz HT in 20/40 MHz BSS or
172         - all STAs in the BSS are 20 MHz HT in 20 MHz BSS
173 Set to 1 (HT non-member protection) if there may be non-HT STAs
174         in both the primary and the secondary channel
175 Set to 2 if only HT STAs are associated in BSS,
176         however and at least one 20 MHz HT STA is associated
177 Set to 3 (HT mixed mode) when one or more non-HT STAs are associated
178         (currently non-GF HT station is considered as non-HT STA also)
179 */
180 int hostapd_ht_operation_update(struct hostapd_iface *iface)
181 {
182         u16 cur_op_mode, new_op_mode;
183         int op_mode_changes = 0;
184
185         if (!iface->conf->ieee80211n || iface->conf->ht_op_mode_fixed)
186                 return 0;
187
188         wpa_printf(MSG_DEBUG, "%s current operation mode=0x%X",
189                    __func__, iface->ht_op_mode);
190
191         if (!(iface->ht_op_mode & HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT)
192             && iface->num_sta_ht_no_gf) {
193                 iface->ht_op_mode |=
194                         HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT;
195                 op_mode_changes++;
196         } else if ((iface->ht_op_mode &
197                     HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT) &&
198                    iface->num_sta_ht_no_gf == 0) {
199                 iface->ht_op_mode &=
200                         ~HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT;
201                 op_mode_changes++;
202         }
203
204         if (!(iface->ht_op_mode & HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT) &&
205             (iface->num_sta_no_ht || iface->olbc_ht)) {
206                 iface->ht_op_mode |= HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT;
207                 op_mode_changes++;
208         } else if ((iface->ht_op_mode &
209                     HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT) &&
210                    (iface->num_sta_no_ht == 0 && !iface->olbc_ht)) {
211                 iface->ht_op_mode &=
212                         ~HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT;
213                 op_mode_changes++;
214         }
215
216         /* Note: currently we switch to the MIXED op mode if HT non-greenfield
217          * station is associated. Probably it's a theoretical case, since
218          * it looks like all known HT STAs support greenfield.
219          */
220         new_op_mode = 0;
221         if (iface->num_sta_no_ht ||
222             (iface->ht_op_mode & HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT))
223                 new_op_mode = OP_MODE_MIXED;
224         else if ((iface->conf->ht_capab & HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)
225                  && iface->num_sta_ht_20mhz)
226                 new_op_mode = OP_MODE_20MHZ_HT_STA_ASSOCED;
227         else if (iface->olbc_ht)
228                 new_op_mode = OP_MODE_MAY_BE_LEGACY_STAS;
229         else
230                 new_op_mode = OP_MODE_PURE;
231
232         cur_op_mode = iface->ht_op_mode & HT_INFO_OPERATION_MODE_OP_MODE_MASK;
233         if (cur_op_mode != new_op_mode) {
234                 iface->ht_op_mode &= ~HT_INFO_OPERATION_MODE_OP_MODE_MASK;
235                 iface->ht_op_mode |= new_op_mode;
236                 op_mode_changes++;
237         }
238
239         wpa_printf(MSG_DEBUG, "%s new operation mode=0x%X changes=%d",
240                    __func__, iface->ht_op_mode, op_mode_changes);
241
242         return op_mode_changes;
243 }
244
245 #endif /* CONFIG_IEEE80211N */
246
247
248 u16 hostapd_own_capab_info(struct hostapd_data *hapd, struct sta_info *sta,
249                            int probe)
250 {
251         int capab = WLAN_CAPABILITY_ESS;
252         int privacy;
253
254         if (hapd->iface->num_sta_no_short_preamble == 0 &&
255             hapd->iconf->preamble == SHORT_PREAMBLE)
256                 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
257
258         privacy = hapd->conf->ssid.wep.keys_set;
259
260         if (hapd->conf->ieee802_1x &&
261             (hapd->conf->default_wep_key_len ||
262              hapd->conf->individual_wep_key_len))
263                 privacy = 1;
264
265         if (hapd->conf->wpa)
266                 privacy = 1;
267
268         if (sta) {
269                 int policy, def_klen;
270                 if (probe && sta->ssid_probe) {
271                         policy = sta->ssid_probe->security_policy;
272                         def_klen = sta->ssid_probe->wep.default_len;
273                 } else {
274                         policy = sta->ssid->security_policy;
275                         def_klen = sta->ssid->wep.default_len;
276                 }
277                 privacy = policy != SECURITY_PLAINTEXT;
278                 if (policy == SECURITY_IEEE_802_1X && def_klen == 0)
279                         privacy = 0;
280         }
281
282         if (privacy)
283                 capab |= WLAN_CAPABILITY_PRIVACY;
284
285         if (hapd->iface->current_mode &&
286             hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G &&
287             hapd->iface->num_sta_no_short_slot_time == 0)
288                 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
289
290         return capab;
291 }
292
293
294 #ifdef CONFIG_IEEE80211W
295 static u8 * hostapd_eid_assoc_comeback_time(struct hostapd_data *hapd,
296                                             struct sta_info *sta, u8 *eid)
297 {
298         u8 *pos = eid;
299         u32 timeout;
300
301         *pos++ = WLAN_EID_ASSOC_COMEBACK_TIME;
302         *pos++ = 4;
303         timeout = (hapd->conf->assoc_ping_attempts - sta->ping_count + 1) *
304                 hapd->conf->assoc_ping_timeout;
305         WPA_PUT_LE32(pos, timeout);
306         pos += 4;
307
308         return pos;
309 }
310 #endif /* CONFIG_IEEE80211W */
311
312
313 void ieee802_11_print_ssid(char *buf, const u8 *ssid, u8 len)
314 {
315         int i;
316         if (len > HOSTAPD_MAX_SSID_LEN)
317                 len = HOSTAPD_MAX_SSID_LEN;
318         for (i = 0; i < len; i++) {
319                 if (ssid[i] >= 32 && ssid[i] < 127)
320                         buf[i] = ssid[i];
321                 else
322                         buf[i] = '.';
323         }
324         buf[len] = '\0';
325 }
326
327
328 void ieee802_11_send_deauth(struct hostapd_data *hapd, u8 *addr, u16 reason)
329 {
330         struct ieee80211_mgmt mgmt;
331
332         hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
333                        HOSTAPD_LEVEL_DEBUG,
334                        "deauthenticate - reason %d", reason);
335         os_memset(&mgmt, 0, sizeof(mgmt));
336         mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
337                                           WLAN_FC_STYPE_DEAUTH);
338         os_memcpy(mgmt.da, addr, ETH_ALEN);
339         os_memcpy(mgmt.sa, hapd->own_addr, ETH_ALEN);
340         os_memcpy(mgmt.bssid, hapd->own_addr, ETH_ALEN);
341         mgmt.u.deauth.reason_code = host_to_le16(reason);
342         if (hostapd_send_mgmt_frame(hapd, &mgmt, IEEE80211_HDRLEN +
343                                     sizeof(mgmt.u.deauth), 0) < 0)
344                 perror("ieee802_11_send_deauth: send");
345 }
346
347
348 static u16 auth_shared_key(struct hostapd_data *hapd, struct sta_info *sta,
349                            u16 auth_transaction, u8 *challenge, int iswep)
350 {
351         hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
352                        HOSTAPD_LEVEL_DEBUG,
353                        "authentication (shared key, transaction %d)",
354                        auth_transaction);
355
356         if (auth_transaction == 1) {
357                 if (!sta->challenge) {
358                         /* Generate a pseudo-random challenge */
359                         u8 key[8];
360                         time_t now;
361                         int r;
362                         sta->challenge = os_zalloc(WLAN_AUTH_CHALLENGE_LEN);
363                         if (sta->challenge == NULL)
364                                 return WLAN_STATUS_UNSPECIFIED_FAILURE;
365
366                         now = time(NULL);
367                         r = random();
368                         os_memcpy(key, &now, 4);
369                         os_memcpy(key + 4, &r, 4);
370                         rc4(sta->challenge, WLAN_AUTH_CHALLENGE_LEN,
371                             key, sizeof(key));
372                 }
373                 return 0;
374         }
375
376         if (auth_transaction != 3)
377                 return WLAN_STATUS_UNSPECIFIED_FAILURE;
378
379         /* Transaction 3 */
380         if (!iswep || !sta->challenge || !challenge ||
381             os_memcmp(sta->challenge, challenge, WLAN_AUTH_CHALLENGE_LEN)) {
382                 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
383                                HOSTAPD_LEVEL_INFO,
384                                "shared key authentication - invalid "
385                                "challenge-response");
386                 return WLAN_STATUS_CHALLENGE_FAIL;
387         }
388
389         hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
390                        HOSTAPD_LEVEL_DEBUG,
391                        "authentication OK (shared key)");
392 #ifdef IEEE80211_REQUIRE_AUTH_ACK
393         /* Station will be marked authenticated if it ACKs the
394          * authentication reply. */
395 #else
396         sta->flags |= WLAN_STA_AUTH;
397         wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
398 #endif
399         os_free(sta->challenge);
400         sta->challenge = NULL;
401
402         return 0;
403 }
404
405
406 static void send_auth_reply(struct hostapd_data *hapd,
407                             const u8 *dst, const u8 *bssid,
408                             u16 auth_alg, u16 auth_transaction, u16 resp,
409                             const u8 *ies, size_t ies_len)
410 {
411         struct ieee80211_mgmt *reply;
412         u8 *buf;
413         size_t rlen;
414
415         rlen = IEEE80211_HDRLEN + sizeof(reply->u.auth) + ies_len;
416         buf = os_zalloc(rlen);
417         if (buf == NULL)
418                 return;
419
420         reply = (struct ieee80211_mgmt *) buf;
421         reply->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
422                                             WLAN_FC_STYPE_AUTH);
423         os_memcpy(reply->da, dst, ETH_ALEN);
424         os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN);
425         os_memcpy(reply->bssid, bssid, ETH_ALEN);
426
427         reply->u.auth.auth_alg = host_to_le16(auth_alg);
428         reply->u.auth.auth_transaction = host_to_le16(auth_transaction);
429         reply->u.auth.status_code = host_to_le16(resp);
430
431         if (ies && ies_len)
432                 os_memcpy(reply->u.auth.variable, ies, ies_len);
433
434         wpa_printf(MSG_DEBUG, "authentication reply: STA=" MACSTR
435                    " auth_alg=%d auth_transaction=%d resp=%d (IE len=%lu)",
436                    MAC2STR(dst), auth_alg, auth_transaction,
437                    resp, (unsigned long) ies_len);
438         if (hostapd_send_mgmt_frame(hapd, reply, rlen, 0) < 0)
439                 perror("send_auth_reply: send");
440
441         os_free(buf);
442 }
443
444
445 #ifdef CONFIG_IEEE80211R
446 static void handle_auth_ft_finish(void *ctx, const u8 *dst, const u8 *bssid,
447                                   u16 auth_transaction, u16 status,
448                                   const u8 *ies, size_t ies_len)
449 {
450         struct hostapd_data *hapd = ctx;
451         struct sta_info *sta;
452
453         send_auth_reply(hapd, dst, bssid, WLAN_AUTH_FT, auth_transaction,
454                         status, ies, ies_len);
455
456         if (status != WLAN_STATUS_SUCCESS)
457                 return;
458
459         sta = ap_get_sta(hapd, dst);
460         if (sta == NULL)
461                 return;
462
463         hostapd_logger(hapd, dst, HOSTAPD_MODULE_IEEE80211,
464                        HOSTAPD_LEVEL_DEBUG, "authentication OK (FT)");
465         sta->flags |= WLAN_STA_AUTH;
466         mlme_authenticate_indication(hapd, sta);
467 }
468 #endif /* CONFIG_IEEE80211R */
469
470
471 static void handle_auth(struct hostapd_data *hapd, struct ieee80211_mgmt *mgmt,
472                         size_t len)
473 {
474         u16 auth_alg, auth_transaction, status_code;
475         u16 resp = WLAN_STATUS_SUCCESS;
476         struct sta_info *sta = NULL;
477         int res;
478         u16 fc;
479         u8 *challenge = NULL;
480         u32 session_timeout, acct_interim_interval;
481         int vlan_id = 0;
482         u8 resp_ies[2 + WLAN_AUTH_CHALLENGE_LEN];
483         size_t resp_ies_len = 0;
484
485         if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
486                 printf("handle_auth - too short payload (len=%lu)\n",
487                        (unsigned long) len);
488                 return;
489         }
490
491         auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
492         auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
493         status_code = le_to_host16(mgmt->u.auth.status_code);
494         fc = le_to_host16(mgmt->frame_control);
495
496         if (len >= IEEE80211_HDRLEN + sizeof(mgmt->u.auth) +
497             2 + WLAN_AUTH_CHALLENGE_LEN &&
498             mgmt->u.auth.variable[0] == WLAN_EID_CHALLENGE &&
499             mgmt->u.auth.variable[1] == WLAN_AUTH_CHALLENGE_LEN)
500                 challenge = &mgmt->u.auth.variable[2];
501
502         wpa_printf(MSG_DEBUG, "authentication: STA=" MACSTR " auth_alg=%d "
503                    "auth_transaction=%d status_code=%d wep=%d%s",
504                    MAC2STR(mgmt->sa), auth_alg, auth_transaction,
505                    status_code, !!(fc & WLAN_FC_ISWEP),
506                    challenge ? " challenge" : "");
507
508         if (hapd->tkip_countermeasures) {
509                 resp = WLAN_REASON_MICHAEL_MIC_FAILURE;
510                 goto fail;
511         }
512
513         if (!(((hapd->conf->auth_algs & WPA_AUTH_ALG_OPEN) &&
514                auth_alg == WLAN_AUTH_OPEN) ||
515 #ifdef CONFIG_IEEE80211R
516               (hapd->conf->wpa &&
517                (hapd->conf->wpa_key_mgmt &
518                 (WPA_KEY_MGMT_FT_IEEE8021X | WPA_KEY_MGMT_FT_PSK)) &&
519                auth_alg == WLAN_AUTH_FT) ||
520 #endif /* CONFIG_IEEE80211R */
521               ((hapd->conf->auth_algs & WPA_AUTH_ALG_SHARED) &&
522                auth_alg == WLAN_AUTH_SHARED_KEY))) {
523                 printf("Unsupported authentication algorithm (%d)\n",
524                        auth_alg);
525                 resp = WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
526                 goto fail;
527         }
528
529         if (!(auth_transaction == 1 ||
530               (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 3))) {
531                 printf("Unknown authentication transaction number (%d)\n",
532                        auth_transaction);
533                 resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
534                 goto fail;
535         }
536
537         if (os_memcmp(mgmt->sa, hapd->own_addr, ETH_ALEN) == 0) {
538                 printf("Station " MACSTR " not allowed to authenticate.\n",
539                        MAC2STR(mgmt->sa));
540                 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
541                 goto fail;
542         }
543
544         res = hostapd_allowed_address(hapd, mgmt->sa, (u8 *) mgmt, len,
545                                       &session_timeout,
546                                       &acct_interim_interval, &vlan_id);
547         if (res == HOSTAPD_ACL_REJECT) {
548                 printf("Station " MACSTR " not allowed to authenticate.\n",
549                        MAC2STR(mgmt->sa));
550                 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
551                 goto fail;
552         }
553         if (res == HOSTAPD_ACL_PENDING) {
554                 wpa_printf(MSG_DEBUG, "Authentication frame from " MACSTR
555                            " waiting for an external authentication",
556                            MAC2STR(mgmt->sa));
557                 /* Authentication code will re-send the authentication frame
558                  * after it has received (and cached) information from the
559                  * external source. */
560                 return;
561         }
562
563         sta = ap_sta_add(hapd, mgmt->sa);
564         if (!sta) {
565                 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
566                 goto fail;
567         }
568
569         if (vlan_id > 0) {
570                 if (hostapd_get_vlan_id_ifname(hapd->conf->vlan,
571                                                sta->vlan_id) == NULL) {
572                         hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
573                                        HOSTAPD_LEVEL_INFO, "Invalid VLAN ID "
574                                        "%d received from RADIUS server",
575                                        vlan_id);
576                         resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
577                         goto fail;
578                 }
579                 sta->vlan_id = vlan_id;
580                 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
581                                HOSTAPD_LEVEL_INFO, "VLAN ID %d", sta->vlan_id);
582         }
583
584         sta->flags &= ~WLAN_STA_PREAUTH;
585         ieee802_1x_notify_pre_auth(sta->eapol_sm, 0);
586
587         if (hapd->conf->radius->acct_interim_interval == 0 &&
588             acct_interim_interval)
589                 sta->acct_interim_interval = acct_interim_interval;
590         if (res == HOSTAPD_ACL_ACCEPT_TIMEOUT)
591                 ap_sta_session_timeout(hapd, sta, session_timeout);
592         else
593                 ap_sta_no_session_timeout(hapd, sta);
594
595         switch (auth_alg) {
596         case WLAN_AUTH_OPEN:
597                 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
598                                HOSTAPD_LEVEL_DEBUG,
599                                "authentication OK (open system)");
600 #ifdef IEEE80211_REQUIRE_AUTH_ACK
601                 /* Station will be marked authenticated if it ACKs the
602                  * authentication reply. */
603 #else
604                 sta->flags |= WLAN_STA_AUTH;
605                 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
606                 sta->auth_alg = WLAN_AUTH_OPEN;
607                 mlme_authenticate_indication(hapd, sta);
608 #endif
609                 break;
610         case WLAN_AUTH_SHARED_KEY:
611                 resp = auth_shared_key(hapd, sta, auth_transaction, challenge,
612                                        fc & WLAN_FC_ISWEP);
613                 sta->auth_alg = WLAN_AUTH_SHARED_KEY;
614                 mlme_authenticate_indication(hapd, sta);
615                 if (sta->challenge && auth_transaction == 1) {
616                         resp_ies[0] = WLAN_EID_CHALLENGE;
617                         resp_ies[1] = WLAN_AUTH_CHALLENGE_LEN;
618                         os_memcpy(resp_ies + 2, sta->challenge,
619                                   WLAN_AUTH_CHALLENGE_LEN);
620                         resp_ies_len = 2 + WLAN_AUTH_CHALLENGE_LEN;
621                 }
622                 break;
623 #ifdef CONFIG_IEEE80211R
624         case WLAN_AUTH_FT:
625                 sta->auth_alg = WLAN_AUTH_FT;
626                 if (sta->wpa_sm == NULL)
627                         sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
628                                                         sta->addr);
629                 if (sta->wpa_sm == NULL) {
630                         wpa_printf(MSG_DEBUG, "FT: Failed to initialize WPA "
631                                    "state machine");
632                         resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
633                         goto fail;
634                 }
635                 wpa_ft_process_auth(sta->wpa_sm, mgmt->bssid,
636                                     auth_transaction, mgmt->u.auth.variable,
637                                     len - IEEE80211_HDRLEN -
638                                     sizeof(mgmt->u.auth),
639                                     handle_auth_ft_finish, hapd);
640                 /* handle_auth_ft_finish() callback will complete auth. */
641                 return;
642 #endif /* CONFIG_IEEE80211R */
643         }
644
645  fail:
646         send_auth_reply(hapd, mgmt->sa, mgmt->bssid, auth_alg,
647                         auth_transaction + 1, resp, resp_ies, resp_ies_len);
648 }
649
650
651 static void handle_assoc(struct hostapd_data *hapd,
652                          struct ieee80211_mgmt *mgmt, size_t len, int reassoc)
653 {
654         u16 capab_info, listen_interval;
655         u16 resp = WLAN_STATUS_SUCCESS;
656         u8 *pos, *wpa_ie;
657         size_t wpa_ie_len;
658         int send_deauth = 0, send_len, left, i;
659         struct sta_info *sta;
660         struct ieee802_11_elems elems;
661         u8 buf[sizeof(struct ieee80211_mgmt) + 512];
662         struct ieee80211_mgmt *reply;
663
664         if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_req) :
665                                       sizeof(mgmt->u.assoc_req))) {
666                 printf("handle_assoc(reassoc=%d) - too short payload (len=%lu)"
667                        "\n", reassoc, (unsigned long) len);
668                 return;
669         }
670
671         if (reassoc) {
672                 capab_info = le_to_host16(mgmt->u.reassoc_req.capab_info);
673                 listen_interval = le_to_host16(
674                         mgmt->u.reassoc_req.listen_interval);
675                 wpa_printf(MSG_DEBUG, "reassociation request: STA=" MACSTR
676                            " capab_info=0x%02x listen_interval=%d current_ap="
677                            MACSTR,
678                            MAC2STR(mgmt->sa), capab_info, listen_interval,
679                            MAC2STR(mgmt->u.reassoc_req.current_ap));
680                 left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.reassoc_req));
681                 pos = mgmt->u.reassoc_req.variable;
682         } else {
683                 capab_info = le_to_host16(mgmt->u.assoc_req.capab_info);
684                 listen_interval = le_to_host16(
685                         mgmt->u.assoc_req.listen_interval);
686                 wpa_printf(MSG_DEBUG, "association request: STA=" MACSTR
687                            " capab_info=0x%02x listen_interval=%d",
688                            MAC2STR(mgmt->sa), capab_info, listen_interval);
689                 left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.assoc_req));
690                 pos = mgmt->u.assoc_req.variable;
691         }
692
693         sta = ap_get_sta(hapd, mgmt->sa);
694 #ifdef CONFIG_IEEE80211R
695         if (sta && sta->auth_alg == WLAN_AUTH_FT &&
696             (sta->flags & WLAN_STA_AUTH) == 0) {
697                 wpa_printf(MSG_DEBUG, "FT: Allow STA " MACSTR " to associate "
698                            "prior to authentication since it is using "
699                            "over-the-DS FT", MAC2STR(mgmt->sa));
700         } else
701 #endif /* CONFIG_IEEE80211R */
702         if (sta == NULL || (sta->flags & WLAN_STA_AUTH) == 0) {
703                 printf("STA " MACSTR " trying to associate before "
704                        "authentication\n", MAC2STR(mgmt->sa));
705                 if (sta) {
706                         printf("  sta: addr=" MACSTR " aid=%d flags=0x%04x\n",
707                                MAC2STR(sta->addr), sta->aid, sta->flags);
708                 }
709                 send_deauth = 1;
710                 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
711                 goto fail;
712         }
713
714         if (hapd->tkip_countermeasures) {
715                 resp = WLAN_REASON_MICHAEL_MIC_FAILURE;
716                 goto fail;
717         }
718
719         if (listen_interval > hapd->conf->max_listen_interval) {
720                 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
721                                HOSTAPD_LEVEL_DEBUG,
722                                "Too large Listen Interval (%d)",
723                                listen_interval);
724                 resp = WLAN_STATUS_ASSOC_DENIED_LISTEN_INT_TOO_LARGE;
725                 goto fail;
726         }
727
728         sta->capability = capab_info;
729         sta->listen_interval = listen_interval;
730
731         /* followed by SSID and Supported rates; and HT capabilities if 802.11n
732          * is used */
733         if (ieee802_11_parse_elems(pos, left, &elems, 1) == ParseFailed ||
734             !elems.ssid) {
735                 printf("STA " MACSTR " sent invalid association request\n",
736                        MAC2STR(sta->addr));
737                 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
738                 goto fail;
739         }
740
741         if (elems.ssid_len != hapd->conf->ssid.ssid_len ||
742             os_memcmp(elems.ssid, hapd->conf->ssid.ssid, elems.ssid_len) != 0)
743         {
744                 char ssid_txt[33];
745                 ieee802_11_print_ssid(ssid_txt, elems.ssid, elems.ssid_len);
746                 printf("Station " MACSTR " tried to associate with "
747                        "unknown SSID '%s'\n", MAC2STR(sta->addr), ssid_txt);
748                 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
749                 goto fail;
750         }
751
752         sta->flags &= ~WLAN_STA_WME;
753         if (elems.wme && hapd->conf->wme_enabled) {
754                 if (hostapd_eid_wme_valid(hapd, elems.wme, elems.wme_len))
755                         hostapd_logger(hapd, sta->addr,
756                                        HOSTAPD_MODULE_WPA,
757                                        HOSTAPD_LEVEL_DEBUG,
758                                        "invalid WME element in association "
759                                        "request");
760                 else
761                         sta->flags |= WLAN_STA_WME;
762         }
763
764         if (!elems.supp_rates) {
765                 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
766                                HOSTAPD_LEVEL_DEBUG,
767                                "No supported rates element in AssocReq");
768                 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
769                 goto fail;
770         }
771
772         if (elems.supp_rates_len > sizeof(sta->supported_rates)) {
773                 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
774                                HOSTAPD_LEVEL_DEBUG,
775                                "Invalid supported rates element length %d",
776                                elems.supp_rates_len);
777                 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
778                 goto fail;
779         }
780
781         os_memset(sta->supported_rates, 0, sizeof(sta->supported_rates));
782         os_memcpy(sta->supported_rates, elems.supp_rates,
783                   elems.supp_rates_len);
784         sta->supported_rates_len = elems.supp_rates_len;
785
786         if (elems.ext_supp_rates) {
787                 if (elems.supp_rates_len + elems.ext_supp_rates_len >
788                     sizeof(sta->supported_rates)) {
789                         hostapd_logger(hapd, mgmt->sa,
790                                        HOSTAPD_MODULE_IEEE80211,
791                                        HOSTAPD_LEVEL_DEBUG,
792                                        "Invalid supported rates element length"
793                                        " %d+%d", elems.supp_rates_len,
794                                        elems.ext_supp_rates_len);
795                         resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
796                         goto fail;
797                 }
798
799                 os_memcpy(sta->supported_rates + elems.supp_rates_len,
800                           elems.ext_supp_rates, elems.ext_supp_rates_len);
801                 sta->supported_rates_len += elems.ext_supp_rates_len;
802         }
803
804 #ifdef CONFIG_IEEE80211N
805         /* save HT capabilities in the sta object */
806         os_memset(&sta->ht_capabilities, 0, sizeof(sta->ht_capabilities));
807         if (elems.ht_capabilities &&
808             elems.ht_capabilities_len >= sizeof(struct ieee80211_ht_capability)
809             && (sta->flags & WLAN_STA_WME)) {
810                 /* note: without WMM capability, treat the sta as non-HT */
811                 sta->flags |= WLAN_STA_HT;
812                 sta->ht_capabilities.id = WLAN_EID_HT_CAP;
813                 sta->ht_capabilities.length =
814                         sizeof(struct ieee80211_ht_capability);
815                 os_memcpy(&sta->ht_capabilities.data,
816                           elems.ht_capabilities,
817                           sizeof(struct ieee80211_ht_capability));
818         } else
819                 sta->flags &= ~WLAN_STA_HT;
820 #endif /* CONFIG_IEEE80211N */
821
822         if ((hapd->conf->wpa & WPA_PROTO_RSN) && elems.rsn_ie) {
823                 wpa_ie = elems.rsn_ie;
824                 wpa_ie_len = elems.rsn_ie_len;
825         } else if ((hapd->conf->wpa & WPA_PROTO_WPA) &&
826                    elems.wpa_ie) {
827                 wpa_ie = elems.wpa_ie;
828                 wpa_ie_len = elems.wpa_ie_len;
829         } else {
830                 wpa_ie = NULL;
831                 wpa_ie_len = 0;
832         }
833 #ifdef CONFIG_WPS
834         if (hapd->conf->wps_state && wpa_ie == NULL) {
835                 if (elems.wps_ie) {
836                         wpa_printf(MSG_DEBUG, "STA included WPS IE in "
837                                    "(Re)Association Request - assume WPS is "
838                                    "used");
839                         sta->flags |= WLAN_STA_WPS;
840                 } else {
841                         wpa_printf(MSG_DEBUG, "STA did not include WPA/RSN IE "
842                                    "in (Re)Association Request - possible WPS "
843                                    "use");
844                         sta->flags |= WLAN_STA_MAYBE_WPS;
845                 }
846         } else
847 #endif /* CONFIG_WPS */
848         if (hapd->conf->wpa && wpa_ie == NULL) {
849                 printf("STA " MACSTR ": No WPA/RSN IE in association "
850                        "request\n", MAC2STR(sta->addr));
851                 resp = WLAN_STATUS_INVALID_IE;
852                 goto fail;
853         }
854
855         if (hapd->conf->wpa && wpa_ie) {
856                 int res;
857                 wpa_ie -= 2;
858                 wpa_ie_len += 2;
859                 if (sta->wpa_sm == NULL)
860                         sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
861                                                         sta->addr);
862                 if (sta->wpa_sm == NULL) {
863                         printf("Failed to initialize WPA state machine\n");
864                         resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
865                         goto fail;
866                 }
867                 res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,
868                                           wpa_ie, wpa_ie_len,
869                                           elems.mdie, elems.mdie_len);
870                 if (res == WPA_INVALID_GROUP)
871                         resp = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
872                 else if (res == WPA_INVALID_PAIRWISE)
873                         resp = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
874                 else if (res == WPA_INVALID_AKMP)
875                         resp = WLAN_STATUS_AKMP_NOT_VALID;
876                 else if (res == WPA_ALLOC_FAIL)
877                         resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
878 #ifdef CONFIG_IEEE80211W
879                 else if (res == WPA_MGMT_FRAME_PROTECTION_VIOLATION)
880                         resp = WLAN_STATUS_UNSPECIFIED_FAILURE; /* FIX */
881                 else if (res == WPA_INVALID_MGMT_GROUP_CIPHER)
882                         resp = WLAN_STATUS_UNSPECIFIED_FAILURE; /* FIX */
883 #endif /* CONFIG_IEEE80211W */
884                 else if (res == WPA_INVALID_MDIE)
885                         resp = WLAN_STATUS_INVALID_MDIE;
886                 else if (res != WPA_IE_OK)
887                         resp = WLAN_STATUS_INVALID_IE;
888                 if (resp != WLAN_STATUS_SUCCESS)
889                         goto fail;
890 #ifdef CONFIG_IEEE80211W
891                 if ((sta->flags & WLAN_STA_MFP) && !sta->ping_timed_out) {
892                         /*
893                          * STA has already been associated with MFP and ping
894                          * timeout has not been reached. Reject the
895                          * association attempt temporarily and start ping, if
896                          * one is not pending.
897                          */
898
899                         if (sta->ping_count == 0)
900                                 ap_sta_start_ping(hapd, sta);
901
902                         resp = WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY;
903                         goto fail;
904                 }
905
906                 if (wpa_auth_uses_mfp(sta->wpa_sm))
907                         sta->flags |= WLAN_STA_MFP;
908                 else
909                         sta->flags &= ~WLAN_STA_MFP;
910 #endif /* CONFIG_IEEE80211W */
911
912 #ifdef CONFIG_IEEE80211R
913                 if (sta->auth_alg == WLAN_AUTH_FT) {
914                         if (!reassoc) {
915                                 wpa_printf(MSG_DEBUG, "FT: " MACSTR " tried "
916                                            "to use association (not "
917                                            "re-association) with FT auth_alg",
918                                            MAC2STR(sta->addr));
919                                 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
920                                 goto fail;
921                         }
922
923                         resp = wpa_ft_validate_reassoc(sta->wpa_sm, pos, left);
924                         if (resp != WLAN_STATUS_SUCCESS)
925                                 goto fail;
926                 }
927 #endif /* CONFIG_IEEE80211R */
928         }
929
930         if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
931                 sta->flags |= WLAN_STA_NONERP;
932         for (i = 0; i < sta->supported_rates_len; i++) {
933                 if ((sta->supported_rates[i] & 0x7f) > 22) {
934                         sta->flags &= ~WLAN_STA_NONERP;
935                         break;
936                 }
937         }
938         if (sta->flags & WLAN_STA_NONERP && !sta->nonerp_set) {
939                 sta->nonerp_set = 1;
940                 hapd->iface->num_sta_non_erp++;
941                 if (hapd->iface->num_sta_non_erp == 1)
942                         ieee802_11_set_beacons(hapd->iface);
943         }
944
945         if (!(sta->capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) &&
946             !sta->no_short_slot_time_set) {
947                 sta->no_short_slot_time_set = 1;
948                 hapd->iface->num_sta_no_short_slot_time++;
949                 if (hapd->iface->current_mode->mode ==
950                     HOSTAPD_MODE_IEEE80211G &&
951                     hapd->iface->num_sta_no_short_slot_time == 1)
952                         ieee802_11_set_beacons(hapd->iface);
953         }
954
955         if (sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
956                 sta->flags |= WLAN_STA_SHORT_PREAMBLE;
957         else
958                 sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
959
960         if (!(sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) &&
961             !sta->no_short_preamble_set) {
962                 sta->no_short_preamble_set = 1;
963                 hapd->iface->num_sta_no_short_preamble++;
964                 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G
965                     && hapd->iface->num_sta_no_short_preamble == 1)
966                         ieee802_11_set_beacons(hapd->iface);
967         }
968
969 #ifdef CONFIG_IEEE80211N
970         if (sta->flags & WLAN_STA_HT) {
971                 u16 ht_capab = le_to_host16(
972                         sta->ht_capabilities.data.capabilities_info);
973                 wpa_printf(MSG_DEBUG, "HT: STA " MACSTR " HT Capabilities "
974                            "Info: 0x%04x", MAC2STR(sta->addr), ht_capab);
975                 if ((ht_capab & HT_CAP_INFO_GREEN_FIELD) == 0) {
976                         hapd->iface->num_sta_ht_no_gf++;
977                         wpa_printf(MSG_DEBUG, "%s STA " MACSTR " - no "
978                                    "greenfield, num of non-gf stations %d",
979                                    __func__, MAC2STR(sta->addr),
980                                    hapd->iface->num_sta_ht_no_gf);
981                 }
982                 if ((ht_capab & HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET) == 0) {
983                         hapd->iface->num_sta_ht_20mhz++;
984                         wpa_printf(MSG_DEBUG, "%s STA " MACSTR " - 20 MHz HT, "
985                                    "num of 20MHz HT STAs %d",
986                                    __func__, MAC2STR(sta->addr),
987                                    hapd->iface->num_sta_ht_20mhz);
988                 }
989         } else {
990                 hapd->iface->num_sta_no_ht++;
991                 if (hapd->iconf->ieee80211n) {
992                         wpa_printf(MSG_DEBUG, "%s STA " MACSTR
993                                    " - no HT, num of non-HT stations %d",
994                                    __func__, MAC2STR(sta->addr),
995                                    hapd->iface->num_sta_no_ht);
996                 }
997         }
998
999         if (hostapd_ht_operation_update(hapd->iface) > 0)
1000                 ieee802_11_set_beacons(hapd->iface);
1001 #endif /* CONFIG_IEEE80211N */
1002
1003         /* get a unique AID */
1004         if (sta->aid > 0) {
1005                 wpa_printf(MSG_DEBUG, "  old AID %d", sta->aid);
1006         } else {
1007                 for (sta->aid = 1; sta->aid <= MAX_AID_TABLE_SIZE; sta->aid++)
1008                         if (hapd->sta_aid[sta->aid - 1] == NULL)
1009                                 break;
1010                 if (sta->aid > MAX_AID_TABLE_SIZE) {
1011                         sta->aid = 0;
1012                         resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
1013                         wpa_printf(MSG_ERROR, "  no room for more AIDs");
1014                         goto fail;
1015                 } else {
1016                         hapd->sta_aid[sta->aid - 1] = sta;
1017                         wpa_printf(MSG_DEBUG, "  new AID %d", sta->aid);
1018                 }
1019         }
1020
1021         hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1022                        HOSTAPD_LEVEL_DEBUG,
1023                        "association OK (aid %d)", sta->aid);
1024         /* Station will be marked associated, after it acknowledges AssocResp
1025          */
1026
1027         if (reassoc) {
1028                 os_memcpy(sta->previous_ap, mgmt->u.reassoc_req.current_ap,
1029                           ETH_ALEN);
1030         }
1031
1032         if (sta->last_assoc_req)
1033                 os_free(sta->last_assoc_req);
1034         sta->last_assoc_req = os_malloc(len);
1035         if (sta->last_assoc_req)
1036                 os_memcpy(sta->last_assoc_req, mgmt, len);
1037
1038         /* Make sure that the previously registered inactivity timer will not
1039          * remove the STA immediately. */
1040         sta->timeout_next = STA_NULLFUNC;
1041
1042  fail:
1043         os_memset(buf, 0, sizeof(buf));
1044         reply = (struct ieee80211_mgmt *) buf;
1045         reply->frame_control =
1046                 IEEE80211_FC(WLAN_FC_TYPE_MGMT,
1047                              (send_deauth ? WLAN_FC_STYPE_DEAUTH :
1048                               (reassoc ? WLAN_FC_STYPE_REASSOC_RESP :
1049                                WLAN_FC_STYPE_ASSOC_RESP)));
1050         os_memcpy(reply->da, mgmt->sa, ETH_ALEN);
1051         os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN);
1052         os_memcpy(reply->bssid, mgmt->bssid, ETH_ALEN);
1053
1054         send_len = IEEE80211_HDRLEN;
1055         if (send_deauth) {
1056                 send_len += sizeof(reply->u.deauth);
1057                 reply->u.deauth.reason_code = host_to_le16(resp);
1058         } else {
1059                 u8 *p;
1060                 send_len += sizeof(reply->u.assoc_resp);
1061                 reply->u.assoc_resp.capab_info =
1062                         host_to_le16(hostapd_own_capab_info(hapd, sta, 0));
1063                 reply->u.assoc_resp.status_code = host_to_le16(resp);
1064                 reply->u.assoc_resp.aid = host_to_le16((sta ? sta->aid : 0)
1065                                                        | BIT(14) | BIT(15));
1066                 /* Supported rates */
1067                 p = hostapd_eid_supp_rates(hapd, reply->u.assoc_resp.variable);
1068                 /* Extended supported rates */
1069                 p = hostapd_eid_ext_supp_rates(hapd, p);
1070                 if (sta->flags & WLAN_STA_WME)
1071                         p = hostapd_eid_wme(hapd, p);
1072
1073                 p = hostapd_eid_ht_capabilities_info(hapd, p);
1074                 p = hostapd_eid_ht_operation(hapd, p);
1075
1076 #ifdef CONFIG_IEEE80211R
1077                 if (resp == WLAN_STATUS_SUCCESS) {
1078                         /* IEEE 802.11r: Mobility Domain Information, Fast BSS
1079                          * Transition Information, RSN */
1080                         p = wpa_sm_write_assoc_resp_ies(sta->wpa_sm, p,
1081                                                         buf + sizeof(buf) - p,
1082                                                         sta->auth_alg);
1083                 }
1084 #endif /* CONFIG_IEEE80211R */
1085
1086 #ifdef CONFIG_IEEE80211W
1087                 if (resp == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY)
1088                         p = hostapd_eid_assoc_comeback_time(hapd, sta, p);
1089 #endif /* CONFIG_IEEE80211W */
1090
1091                 send_len += p - reply->u.assoc_resp.variable;
1092         }
1093
1094         if (hostapd_send_mgmt_frame(hapd, reply, send_len, 0) < 0)
1095                 perror("handle_assoc: send");
1096 }
1097
1098
1099 static void handle_disassoc(struct hostapd_data *hapd,
1100                             struct ieee80211_mgmt *mgmt, size_t len)
1101 {
1102         struct sta_info *sta;
1103
1104         if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.disassoc)) {
1105                 printf("handle_disassoc - too short payload (len=%lu)\n",
1106                        (unsigned long) len);
1107                 return;
1108         }
1109
1110         wpa_printf(MSG_DEBUG, "disassocation: STA=" MACSTR " reason_code=%d",
1111                    MAC2STR(mgmt->sa),
1112                    le_to_host16(mgmt->u.disassoc.reason_code));
1113
1114         sta = ap_get_sta(hapd, mgmt->sa);
1115         if (sta == NULL) {
1116                 printf("Station " MACSTR " trying to disassociate, but it "
1117                        "is not associated.\n", MAC2STR(mgmt->sa));
1118                 return;
1119         }
1120
1121         sta->flags &= ~WLAN_STA_ASSOC;
1122         wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC);
1123         hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1124                        HOSTAPD_LEVEL_INFO, "disassociated");
1125         sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
1126         ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
1127         /* Stop Accounting and IEEE 802.1X sessions, but leave the STA
1128          * authenticated. */
1129         accounting_sta_stop(hapd, sta);
1130         ieee802_1x_free_station(sta);
1131         hostapd_sta_remove(hapd, sta->addr);
1132
1133         if (sta->timeout_next == STA_NULLFUNC ||
1134             sta->timeout_next == STA_DISASSOC) {
1135                 sta->timeout_next = STA_DEAUTH;
1136                 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
1137                 eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer,
1138                                        hapd, sta);
1139         }
1140
1141         mlme_disassociate_indication(
1142                 hapd, sta, le_to_host16(mgmt->u.disassoc.reason_code));
1143 }
1144
1145
1146 static void handle_deauth(struct hostapd_data *hapd,
1147                           struct ieee80211_mgmt *mgmt, size_t len)
1148 {
1149         struct sta_info *sta;
1150
1151         if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.deauth)) {
1152                 printf("handle_deauth - too short payload (len=%lu)\n",
1153                        (unsigned long) len);
1154                 return;
1155         }
1156
1157         wpa_printf(MSG_DEBUG, "deauthentication: STA=" MACSTR
1158                    " reason_code=%d",
1159                    MAC2STR(mgmt->sa),
1160                    le_to_host16(mgmt->u.deauth.reason_code));
1161
1162         sta = ap_get_sta(hapd, mgmt->sa);
1163         if (sta == NULL) {
1164                 printf("Station " MACSTR " trying to deauthenticate, but it "
1165                        "is not authenticated.\n", MAC2STR(mgmt->sa));
1166                 return;
1167         }
1168
1169         sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
1170         wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH);
1171         hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1172                        HOSTAPD_LEVEL_DEBUG, "deauthenticated");
1173         mlme_deauthenticate_indication(
1174                 hapd, sta, le_to_host16(mgmt->u.deauth.reason_code));
1175         sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
1176         ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
1177         ap_free_sta(hapd, sta);
1178 }
1179
1180
1181 static void handle_beacon(struct hostapd_data *hapd,
1182                           struct ieee80211_mgmt *mgmt, size_t len,
1183                           struct hostapd_frame_info *fi)
1184 {
1185         struct ieee802_11_elems elems;
1186
1187         if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.beacon)) {
1188                 printf("handle_beacon - too short payload (len=%lu)\n",
1189                        (unsigned long) len);
1190                 return;
1191         }
1192
1193         (void) ieee802_11_parse_elems(mgmt->u.beacon.variable,
1194                                       len - (IEEE80211_HDRLEN +
1195                                              sizeof(mgmt->u.beacon)), &elems,
1196                                       0);
1197
1198         ap_list_process_beacon(hapd->iface, mgmt, &elems, fi);
1199 }
1200
1201
1202 #ifdef CONFIG_IEEE80211W
1203 static void hostapd_ping_action(struct hostapd_data *hapd,
1204                                 struct ieee80211_mgmt *mgmt, size_t len)
1205 {
1206         struct sta_info *sta;
1207         u8 *end;
1208         int i;
1209
1210         end = mgmt->u.action.u.ping_resp.trans_id + WLAN_PING_TRANS_ID_LEN;
1211         if (((u8 *) mgmt) + len < end) {
1212                 wpa_printf(MSG_DEBUG, "IEEE 802.11: Too short Ping Action "
1213                            "frame (len=%lu)", (unsigned long) len);
1214                 return;
1215         }
1216
1217         if (mgmt->u.action.u.ping_resp.action != WLAN_PING_RESPONSE) {
1218                 wpa_printf(MSG_DEBUG, "IEEE 802.11: Unexpected Ping Action %d",
1219                            mgmt->u.action.u.ping_resp.action);
1220                 return;
1221         }
1222
1223         /* MLME-PING.confirm */
1224
1225         sta = ap_get_sta(hapd, mgmt->sa);
1226         if (sta == NULL || sta->ping_trans_id == NULL) {
1227                 wpa_printf(MSG_DEBUG, "IEEE 802.11: No matching STA with "
1228                            "pending ping request found");
1229                 return;
1230         }
1231
1232         for (i = 0; i < sta->ping_count; i++) {
1233                 if (os_memcmp(sta->ping_trans_id + i * WLAN_PING_TRANS_ID_LEN,
1234                               mgmt->u.action.u.ping_resp.trans_id,
1235                               WLAN_PING_TRANS_ID_LEN) == 0)
1236                         break;
1237         }
1238
1239         if (i >= sta->ping_count) {
1240                 wpa_printf(MSG_DEBUG, "IEEE 802.11: No matching ping "
1241                            "transaction identifier found");
1242                 return;
1243         }
1244
1245         hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1246                        HOSTAPD_LEVEL_DEBUG, "Reply to pending ping received");
1247         ap_sta_stop_ping(hapd, sta);
1248 }
1249 #endif /* CONFIG_IEEE80211W */
1250
1251
1252 static void handle_action(struct hostapd_data *hapd,
1253                           struct ieee80211_mgmt *mgmt, size_t len)
1254 {
1255         if (len < IEEE80211_HDRLEN + 1) {
1256                 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1257                                HOSTAPD_LEVEL_DEBUG,
1258                                "handle_action - too short payload (len=%lu)",
1259                                (unsigned long) len);
1260                 return;
1261         }
1262
1263         switch (mgmt->u.action.category) {
1264 #ifdef CONFIG_IEEE80211R
1265         case WLAN_ACTION_FT:
1266         {
1267                 struct sta_info *sta;
1268
1269                 sta = ap_get_sta(hapd, mgmt->sa);
1270                 if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC)) {
1271                         wpa_printf(MSG_DEBUG, "IEEE 802.11: Ignored FT Action "
1272                                    "frame from unassociated STA " MACSTR,
1273                                    MAC2STR(mgmt->sa));
1274                         return;
1275                 }
1276
1277                 if (wpa_ft_action_rx(sta->wpa_sm, (u8 *) &mgmt->u.action,
1278                                      len - IEEE80211_HDRLEN))
1279                         break;
1280
1281                 return;
1282         }
1283 #endif /* CONFIG_IEEE80211R */
1284         case WLAN_ACTION_WMM:
1285                 hostapd_wme_action(hapd, mgmt, len);
1286                 return;
1287 #ifdef CONFIG_IEEE80211W
1288         case WLAN_ACTION_PING:
1289                 hostapd_ping_action(hapd, mgmt, len);
1290                 return;
1291 #endif /* CONFIG_IEEE80211W */
1292         }
1293
1294         hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1295                        HOSTAPD_LEVEL_DEBUG,
1296                        "handle_action - unknown action category %d or invalid "
1297                        "frame",
1298                        mgmt->u.action.category);
1299         if (!(mgmt->da[0] & 0x01) && !(mgmt->u.action.category & 0x80) &&
1300             !(mgmt->sa[0] & 0x01)) {
1301                 /*
1302                  * IEEE 802.11-REVma/D9.0 - 7.3.1.11
1303                  * Return the Action frame to the source without change
1304                  * except that MSB of the Category set to 1.
1305                  */
1306                 wpa_printf(MSG_DEBUG, "IEEE 802.11: Return unknown Action "
1307                            "frame back to sender");
1308                 os_memcpy(mgmt->da, mgmt->sa, ETH_ALEN);
1309                 os_memcpy(mgmt->sa, hapd->own_addr, ETH_ALEN);
1310                 os_memcpy(mgmt->bssid, hapd->own_addr, ETH_ALEN);
1311                 mgmt->u.action.category |= 0x80;
1312
1313                 hostapd_send_mgmt_frame(hapd, mgmt, len, 0);
1314         }
1315 }
1316
1317
1318 /**
1319  * ieee802_11_mgmt - process incoming IEEE 802.11 management frames
1320  * @hapd: hostapd BSS data structure (the BSS to which the management frame was
1321  * sent to)
1322  * @buf: management frame data (starting from IEEE 802.11 header)
1323  * @len: length of frame data in octets
1324  * @stype: management frame subtype from frame control field
1325  *
1326  * Process all incoming IEEE 802.11 management frames. This will be called for
1327  * each frame received from the kernel driver through wlan#ap interface. In
1328  * addition, it can be called to re-inserted pending frames (e.g., when using
1329  * external RADIUS server as an MAC ACL).
1330  */
1331 void ieee802_11_mgmt(struct hostapd_data *hapd, u8 *buf, size_t len, u16 stype,
1332                      struct hostapd_frame_info *fi)
1333 {
1334         struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) buf;
1335         int broadcast;
1336
1337         if (stype == WLAN_FC_STYPE_BEACON) {
1338                 handle_beacon(hapd, mgmt, len, fi);
1339                 return;
1340         }
1341
1342         if (fi && fi->passive_scan)
1343                 return;
1344
1345         broadcast = mgmt->bssid[0] == 0xff && mgmt->bssid[1] == 0xff &&
1346                 mgmt->bssid[2] == 0xff && mgmt->bssid[3] == 0xff &&
1347                 mgmt->bssid[4] == 0xff && mgmt->bssid[5] == 0xff;
1348
1349         if (!broadcast &&
1350             os_memcmp(mgmt->bssid, hapd->own_addr, ETH_ALEN) != 0) {
1351                 printf("MGMT: BSSID=" MACSTR " not our address\n",
1352                        MAC2STR(mgmt->bssid));
1353                 return;
1354         }
1355
1356
1357         if (stype == WLAN_FC_STYPE_PROBE_REQ) {
1358                 handle_probe_req(hapd, mgmt, len);
1359                 return;
1360         }
1361
1362         if (os_memcmp(mgmt->da, hapd->own_addr, ETH_ALEN) != 0) {
1363                 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1364                                HOSTAPD_LEVEL_DEBUG,
1365                                "MGMT: DA=" MACSTR " not our address",
1366                                MAC2STR(mgmt->da));
1367                 return;
1368         }
1369
1370         switch (stype) {
1371         case WLAN_FC_STYPE_AUTH:
1372                 wpa_printf(MSG_DEBUG, "mgmt::auth");
1373                 handle_auth(hapd, mgmt, len);
1374                 break;
1375         case WLAN_FC_STYPE_ASSOC_REQ:
1376                 wpa_printf(MSG_DEBUG, "mgmt::assoc_req");
1377                 handle_assoc(hapd, mgmt, len, 0);
1378                 break;
1379         case WLAN_FC_STYPE_REASSOC_REQ:
1380                 wpa_printf(MSG_DEBUG, "mgmt::reassoc_req");
1381                 handle_assoc(hapd, mgmt, len, 1);
1382                 break;
1383         case WLAN_FC_STYPE_DISASSOC:
1384                 wpa_printf(MSG_DEBUG, "mgmt::disassoc");
1385                 handle_disassoc(hapd, mgmt, len);
1386                 break;
1387         case WLAN_FC_STYPE_DEAUTH:
1388                 wpa_printf(MSG_DEBUG, "mgmt::deauth");
1389                 handle_deauth(hapd, mgmt, len);
1390                 break;
1391         case WLAN_FC_STYPE_ACTION:
1392                 wpa_printf(MSG_DEBUG, "mgmt::action");
1393                 handle_action(hapd, mgmt, len);
1394                 break;
1395         default:
1396                 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1397                                HOSTAPD_LEVEL_DEBUG,
1398                                "unknown mgmt frame subtype %d", stype);
1399                 break;
1400         }
1401 }
1402
1403
1404 static void handle_auth_cb(struct hostapd_data *hapd,
1405                            struct ieee80211_mgmt *mgmt,
1406                            size_t len, int ok)
1407 {
1408         u16 auth_alg, auth_transaction, status_code;
1409         struct sta_info *sta;
1410
1411         if (!ok) {
1412                 hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
1413                                HOSTAPD_LEVEL_NOTICE,
1414                                "did not acknowledge authentication response");
1415                 return;
1416         }
1417
1418         if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
1419                 printf("handle_auth_cb - too short payload (len=%lu)\n",
1420                        (unsigned long) len);
1421                 return;
1422         }
1423
1424         auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
1425         auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
1426         status_code = le_to_host16(mgmt->u.auth.status_code);
1427
1428         sta = ap_get_sta(hapd, mgmt->da);
1429         if (!sta) {
1430                 printf("handle_auth_cb: STA " MACSTR " not found\n",
1431                        MAC2STR(mgmt->da));
1432                 return;
1433         }
1434
1435         if (status_code == WLAN_STATUS_SUCCESS &&
1436             ((auth_alg == WLAN_AUTH_OPEN && auth_transaction == 2) ||
1437              (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 4))) {
1438                 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1439                                HOSTAPD_LEVEL_INFO, "authenticated");
1440                 sta->flags |= WLAN_STA_AUTH;
1441         }
1442 }
1443
1444
1445 static void handle_assoc_cb(struct hostapd_data *hapd,
1446                             struct ieee80211_mgmt *mgmt,
1447                             size_t len, int reassoc, int ok)
1448 {
1449         u16 status;
1450         struct sta_info *sta;
1451         int new_assoc = 1;
1452         struct ht_cap_ie *ht_cap = NULL;
1453
1454         if (!ok) {
1455                 hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
1456                                HOSTAPD_LEVEL_DEBUG,
1457                                "did not acknowledge association response");
1458                 return;
1459         }
1460
1461         if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_resp) :
1462                                       sizeof(mgmt->u.assoc_resp))) {
1463                 printf("handle_assoc_cb(reassoc=%d) - too short payload "
1464                        "(len=%lu)\n", reassoc, (unsigned long) len);
1465                 return;
1466         }
1467
1468         if (reassoc)
1469                 status = le_to_host16(mgmt->u.reassoc_resp.status_code);
1470         else
1471                 status = le_to_host16(mgmt->u.assoc_resp.status_code);
1472
1473         sta = ap_get_sta(hapd, mgmt->da);
1474         if (!sta) {
1475                 printf("handle_assoc_cb: STA " MACSTR " not found\n",
1476                        MAC2STR(mgmt->da));
1477                 return;
1478         }
1479
1480         if (status != WLAN_STATUS_SUCCESS)
1481                 goto fail;
1482
1483         /* Stop previous accounting session, if one is started, and allocate
1484          * new session id for the new session. */
1485         accounting_sta_stop(hapd, sta);
1486
1487         hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1488                        HOSTAPD_LEVEL_INFO,
1489                        "associated (aid %d)",
1490                        sta->aid);
1491
1492         if (sta->flags & WLAN_STA_ASSOC)
1493                 new_assoc = 0;
1494         sta->flags |= WLAN_STA_ASSOC;
1495
1496         if (reassoc)
1497                 mlme_reassociate_indication(hapd, sta);
1498         else
1499                 mlme_associate_indication(hapd, sta);
1500
1501 #ifdef CONFIG_IEEE80211N
1502         if (sta->flags & WLAN_STA_HT)
1503                 ht_cap = &sta->ht_capabilities;
1504 #endif /* CONFIG_IEEE80211N */
1505
1506 #ifdef CONFIG_IEEE80211W
1507         sta->ping_timed_out = 0;
1508 #endif /* CONFIG_IEEE80211W */
1509
1510         if (hostapd_sta_add(hapd->conf->iface, hapd, sta->addr, sta->aid,
1511                             sta->capability, sta->supported_rates,
1512                             sta->supported_rates_len, 0, sta->listen_interval,
1513                             ht_cap))
1514         {
1515                 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1516                                HOSTAPD_LEVEL_NOTICE,
1517                                "Could not add STA to kernel driver");
1518         }
1519
1520         if (sta->eapol_sm == NULL) {
1521                 /*
1522                  * This STA does not use RADIUS server for EAP authentication,
1523                  * so bind it to the selected VLAN interface now, since the
1524                  * interface selection is not going to change anymore.
1525                  */
1526                 ap_sta_bind_vlan(hapd, sta, 0);
1527         } else if (sta->vlan_id) {
1528                 /* VLAN ID already set (e.g., by PMKSA caching), so bind STA */
1529                 ap_sta_bind_vlan(hapd, sta, 0);
1530         }
1531         if (sta->flags & WLAN_STA_SHORT_PREAMBLE) {
1532                 hostapd_sta_set_flags(hapd, sta->addr, sta->flags,
1533                                       WLAN_STA_SHORT_PREAMBLE, ~0);
1534         } else {
1535                 hostapd_sta_set_flags(hapd, sta->addr, sta->flags,
1536                                       0, ~WLAN_STA_SHORT_PREAMBLE);
1537         }
1538
1539         if (sta->auth_alg == WLAN_AUTH_FT)
1540                 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FT);
1541         else
1542                 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC);
1543         hostapd_new_assoc_sta(hapd, sta, !new_assoc);
1544
1545         ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
1546
1547  fail:
1548         /* Copy of the association request is not needed anymore */
1549         if (sta->last_assoc_req) {
1550                 os_free(sta->last_assoc_req);
1551                 sta->last_assoc_req = NULL;
1552         }
1553 }
1554
1555
1556 void ieee802_11_mgmt_cb(struct hostapd_data *hapd, u8 *buf, size_t len,
1557                         u16 stype, int ok)
1558 {
1559         struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) buf;
1560
1561         switch (stype) {
1562         case WLAN_FC_STYPE_AUTH:
1563                 wpa_printf(MSG_DEBUG, "mgmt::auth cb");
1564                 handle_auth_cb(hapd, mgmt, len, ok);
1565                 break;
1566         case WLAN_FC_STYPE_ASSOC_RESP:
1567                 wpa_printf(MSG_DEBUG, "mgmt::assoc_resp cb");
1568                 handle_assoc_cb(hapd, mgmt, len, 0, ok);
1569                 break;
1570         case WLAN_FC_STYPE_REASSOC_RESP:
1571                 wpa_printf(MSG_DEBUG, "mgmt::reassoc_resp cb");
1572                 handle_assoc_cb(hapd, mgmt, len, 1, ok);
1573                 break;
1574         case WLAN_FC_STYPE_PROBE_RESP:
1575                 wpa_printf(MSG_DEBUG, "mgmt::proberesp cb");
1576                 break;
1577         case WLAN_FC_STYPE_DEAUTH:
1578                 /* ignore */
1579                 break;
1580         case WLAN_FC_STYPE_ACTION:
1581                 wpa_printf(MSG_DEBUG, "mgmt::action cb");
1582                 break;
1583         default:
1584                 printf("unknown mgmt cb frame subtype %d\n", stype);
1585                 break;
1586         }
1587 }
1588
1589
1590 static void ieee80211_tkip_countermeasures_stop(void *eloop_ctx,
1591                                                 void *timeout_ctx)
1592 {
1593         struct hostapd_data *hapd = eloop_ctx;
1594         hapd->tkip_countermeasures = 0;
1595         hostapd_set_countermeasures(hapd, 0);
1596         hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
1597                        HOSTAPD_LEVEL_INFO, "TKIP countermeasures ended");
1598 }
1599
1600
1601 static void ieee80211_tkip_countermeasures_start(struct hostapd_data *hapd)
1602 {
1603         struct sta_info *sta;
1604
1605         hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
1606                        HOSTAPD_LEVEL_INFO, "TKIP countermeasures initiated");
1607
1608         wpa_auth_countermeasures_start(hapd->wpa_auth);
1609         hapd->tkip_countermeasures = 1;
1610         hostapd_set_countermeasures(hapd, 1);
1611         wpa_gtk_rekey(hapd->wpa_auth);
1612         eloop_cancel_timeout(ieee80211_tkip_countermeasures_stop, hapd, NULL);
1613         eloop_register_timeout(60, 0, ieee80211_tkip_countermeasures_stop,
1614                                hapd, NULL);
1615         for (sta = hapd->sta_list; sta != NULL; sta = sta->next) {
1616                 hostapd_sta_deauth(hapd, sta->addr,
1617                                    WLAN_REASON_MICHAEL_MIC_FAILURE);
1618                 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC |
1619                                 WLAN_STA_AUTHORIZED);
1620                 hostapd_sta_remove(hapd, sta->addr);
1621         }
1622 }
1623
1624
1625 void ieee80211_michael_mic_failure(struct hostapd_data *hapd, const u8 *addr,
1626                                    int local)
1627 {
1628         time_t now;
1629
1630         if (addr && local) {
1631                 struct sta_info *sta = ap_get_sta(hapd, addr);
1632                 if (sta != NULL) {
1633                         wpa_auth_sta_local_mic_failure_report(sta->wpa_sm);
1634                         hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
1635                                        HOSTAPD_LEVEL_INFO,
1636                                        "Michael MIC failure detected in "
1637                                        "received frame");
1638                         mlme_michaelmicfailure_indication(hapd, addr);
1639                 } else {
1640                         wpa_printf(MSG_DEBUG,
1641                                    "MLME-MICHAELMICFAILURE.indication "
1642                                    "for not associated STA (" MACSTR
1643                                    ") ignored", MAC2STR(addr));
1644                         return;
1645                 }
1646         }
1647
1648         time(&now);
1649         if (now > hapd->michael_mic_failure + 60) {
1650                 hapd->michael_mic_failures = 1;
1651         } else {
1652                 hapd->michael_mic_failures++;
1653                 if (hapd->michael_mic_failures > 1)
1654                         ieee80211_tkip_countermeasures_start(hapd);
1655         }
1656         hapd->michael_mic_failure = now;
1657 }
1658
1659
1660 int ieee802_11_get_mib(struct hostapd_data *hapd, char *buf, size_t buflen)
1661 {
1662         /* TODO */
1663         return 0;
1664 }
1665
1666
1667 int ieee802_11_get_mib_sta(struct hostapd_data *hapd, struct sta_info *sta,
1668                            char *buf, size_t buflen)
1669 {
1670         /* TODO */
1671         return 0;
1672 }
1673
1674 #endif /* CONFIG_NATIVE_WINDOWS */