blob: 14fb56758395c3406f7aa6fea9ef97fdee570f69 [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * hostapd / IEEE 802.11 Management
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07003 * Copyright (c) 2002-2013, Jouni Malinen <j@w1.fi>
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004 *
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007 */
8
9#include "utils/includes.h"
10
11#ifndef CONFIG_NATIVE_WINDOWS
12
13#include "utils/common.h"
14#include "utils/eloop.h"
15#include "crypto/crypto.h"
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080016#include "crypto/sha256.h"
17#include "crypto/random.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070018#include "common/ieee802_11_defs.h"
19#include "common/ieee802_11_common.h"
20#include "common/wpa_ctrl.h"
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080021#include "common/sae.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070022#include "radius/radius.h"
23#include "radius/radius_client.h"
24#include "p2p/p2p.h"
25#include "wps/wps.h"
26#include "hostapd.h"
27#include "beacon.h"
28#include "ieee802_11_auth.h"
29#include "sta_info.h"
30#include "ieee802_1x.h"
31#include "wpa_auth.h"
32#include "wmm.h"
33#include "ap_list.h"
34#include "accounting.h"
35#include "ap_config.h"
36#include "ap_mlme.h"
37#include "p2p_hostapd.h"
38#include "ap_drv_ops.h"
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -080039#include "wnm_ap.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070040#include "ieee802_11.h"
Dmitry Shmidtf21452a2014-02-26 10:55:25 -080041#include "dfs.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070042
43
44u8 * hostapd_eid_supp_rates(struct hostapd_data *hapd, u8 *eid)
45{
46 u8 *pos = eid;
47 int i, num, count;
48
49 if (hapd->iface->current_rates == NULL)
50 return eid;
51
52 *pos++ = WLAN_EID_SUPP_RATES;
53 num = hapd->iface->num_rates;
54 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht)
55 num++;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080056 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht)
57 num++;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070058 if (num > 8) {
59 /* rest of the rates are encoded in Extended supported
60 * rates element */
61 num = 8;
62 }
63
64 *pos++ = num;
65 count = 0;
66 for (i = 0, count = 0; i < hapd->iface->num_rates && count < num;
67 i++) {
68 count++;
69 *pos = hapd->iface->current_rates[i].rate / 5;
70 if (hapd->iface->current_rates[i].flags & HOSTAPD_RATE_BASIC)
71 *pos |= 0x80;
72 pos++;
73 }
74
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080075 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht && count < 8) {
76 count++;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070077 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -080078 }
79
80 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht && count < 8) {
81 count++;
82 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY;
83 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070084
85 return pos;
86}
87
88
89u8 * hostapd_eid_ext_supp_rates(struct hostapd_data *hapd, u8 *eid)
90{
91 u8 *pos = eid;
92 int i, num, count;
93
94 if (hapd->iface->current_rates == NULL)
95 return eid;
96
97 num = hapd->iface->num_rates;
98 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht)
99 num++;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800100 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht)
101 num++;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700102 if (num <= 8)
103 return eid;
104 num -= 8;
105
106 *pos++ = WLAN_EID_EXT_SUPP_RATES;
107 *pos++ = num;
108 count = 0;
109 for (i = 0, count = 0; i < hapd->iface->num_rates && count < num + 8;
110 i++) {
111 count++;
112 if (count <= 8)
113 continue; /* already in SuppRates IE */
114 *pos = hapd->iface->current_rates[i].rate / 5;
115 if (hapd->iface->current_rates[i].flags & HOSTAPD_RATE_BASIC)
116 *pos |= 0x80;
117 pos++;
118 }
119
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800120 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht) {
121 count++;
122 if (count > 8)
123 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY;
124 }
125
126 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht) {
127 count++;
128 if (count > 8)
129 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY;
130 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700131
132 return pos;
133}
134
135
136u16 hostapd_own_capab_info(struct hostapd_data *hapd, struct sta_info *sta,
137 int probe)
138{
139 int capab = WLAN_CAPABILITY_ESS;
140 int privacy;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800141 int dfs;
142
143 /* Check if any of configured channels require DFS */
144 dfs = hostapd_is_dfs_required(hapd->iface);
145 if (dfs < 0) {
146 wpa_printf(MSG_WARNING, "Failed to check if DFS is required; ret=%d",
147 dfs);
148 dfs = 0;
149 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700150
151 if (hapd->iface->num_sta_no_short_preamble == 0 &&
152 hapd->iconf->preamble == SHORT_PREAMBLE)
153 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
154
155 privacy = hapd->conf->ssid.wep.keys_set;
156
157 if (hapd->conf->ieee802_1x &&
158 (hapd->conf->default_wep_key_len ||
159 hapd->conf->individual_wep_key_len))
160 privacy = 1;
161
162 if (hapd->conf->wpa)
163 privacy = 1;
164
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800165#ifdef CONFIG_HS20
166 if (hapd->conf->osen)
167 privacy = 1;
168#endif /* CONFIG_HS20 */
169
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700170 if (sta) {
171 int policy, def_klen;
172 if (probe && sta->ssid_probe) {
173 policy = sta->ssid_probe->security_policy;
174 def_klen = sta->ssid_probe->wep.default_len;
175 } else {
176 policy = sta->ssid->security_policy;
177 def_klen = sta->ssid->wep.default_len;
178 }
179 privacy = policy != SECURITY_PLAINTEXT;
180 if (policy == SECURITY_IEEE_802_1X && def_klen == 0)
181 privacy = 0;
182 }
183
184 if (privacy)
185 capab |= WLAN_CAPABILITY_PRIVACY;
186
187 if (hapd->iface->current_mode &&
188 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G &&
189 hapd->iface->num_sta_no_short_slot_time == 0)
190 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
191
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800192 /*
193 * Currently, Spectrum Management capability bit is set when directly
194 * requested in configuration by spectrum_mgmt_required or when AP is
195 * running on DFS channel.
196 * TODO: Also consider driver support for TPC to set Spectrum Mgmt bit
197 */
198 if (hapd->iface->current_mode &&
199 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211A &&
200 (hapd->iconf->spectrum_mgmt_required || dfs))
201 capab |= WLAN_CAPABILITY_SPECTRUM_MGMT;
202
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700203 return capab;
204}
205
206
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700207static u16 auth_shared_key(struct hostapd_data *hapd, struct sta_info *sta,
208 u16 auth_transaction, const u8 *challenge,
209 int iswep)
210{
211 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
212 HOSTAPD_LEVEL_DEBUG,
213 "authentication (shared key, transaction %d)",
214 auth_transaction);
215
216 if (auth_transaction == 1) {
217 if (!sta->challenge) {
218 /* Generate a pseudo-random challenge */
219 u8 key[8];
220 struct os_time now;
221 int r;
222 sta->challenge = os_zalloc(WLAN_AUTH_CHALLENGE_LEN);
223 if (sta->challenge == NULL)
224 return WLAN_STATUS_UNSPECIFIED_FAILURE;
225
226 os_get_time(&now);
227 r = os_random();
228 os_memcpy(key, &now.sec, 4);
229 os_memcpy(key + 4, &r, 4);
230 rc4_skip(key, sizeof(key), 0,
231 sta->challenge, WLAN_AUTH_CHALLENGE_LEN);
232 }
233 return 0;
234 }
235
236 if (auth_transaction != 3)
237 return WLAN_STATUS_UNSPECIFIED_FAILURE;
238
239 /* Transaction 3 */
240 if (!iswep || !sta->challenge || !challenge ||
241 os_memcmp(sta->challenge, challenge, WLAN_AUTH_CHALLENGE_LEN)) {
242 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
243 HOSTAPD_LEVEL_INFO,
244 "shared key authentication - invalid "
245 "challenge-response");
246 return WLAN_STATUS_CHALLENGE_FAIL;
247 }
248
249 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
250 HOSTAPD_LEVEL_DEBUG,
251 "authentication OK (shared key)");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700252 sta->flags |= WLAN_STA_AUTH;
253 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700254 os_free(sta->challenge);
255 sta->challenge = NULL;
256
257 return 0;
258}
259
260
261static void send_auth_reply(struct hostapd_data *hapd,
262 const u8 *dst, const u8 *bssid,
263 u16 auth_alg, u16 auth_transaction, u16 resp,
264 const u8 *ies, size_t ies_len)
265{
266 struct ieee80211_mgmt *reply;
267 u8 *buf;
268 size_t rlen;
269
270 rlen = IEEE80211_HDRLEN + sizeof(reply->u.auth) + ies_len;
271 buf = os_zalloc(rlen);
272 if (buf == NULL)
273 return;
274
275 reply = (struct ieee80211_mgmt *) buf;
276 reply->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
277 WLAN_FC_STYPE_AUTH);
278 os_memcpy(reply->da, dst, ETH_ALEN);
279 os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN);
280 os_memcpy(reply->bssid, bssid, ETH_ALEN);
281
282 reply->u.auth.auth_alg = host_to_le16(auth_alg);
283 reply->u.auth.auth_transaction = host_to_le16(auth_transaction);
284 reply->u.auth.status_code = host_to_le16(resp);
285
286 if (ies && ies_len)
287 os_memcpy(reply->u.auth.variable, ies, ies_len);
288
289 wpa_printf(MSG_DEBUG, "authentication reply: STA=" MACSTR
290 " auth_alg=%d auth_transaction=%d resp=%d (IE len=%lu)",
291 MAC2STR(dst), auth_alg, auth_transaction,
292 resp, (unsigned long) ies_len);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800293 if (hostapd_drv_send_mlme(hapd, reply, rlen, 0) < 0)
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800294 wpa_printf(MSG_INFO, "send_auth_reply: send");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700295
296 os_free(buf);
297}
298
299
300#ifdef CONFIG_IEEE80211R
301static void handle_auth_ft_finish(void *ctx, const u8 *dst, const u8 *bssid,
302 u16 auth_transaction, u16 status,
303 const u8 *ies, size_t ies_len)
304{
305 struct hostapd_data *hapd = ctx;
306 struct sta_info *sta;
307
308 send_auth_reply(hapd, dst, bssid, WLAN_AUTH_FT, auth_transaction,
309 status, ies, ies_len);
310
311 if (status != WLAN_STATUS_SUCCESS)
312 return;
313
314 sta = ap_get_sta(hapd, dst);
315 if (sta == NULL)
316 return;
317
318 hostapd_logger(hapd, dst, HOSTAPD_MODULE_IEEE80211,
319 HOSTAPD_LEVEL_DEBUG, "authentication OK (FT)");
320 sta->flags |= WLAN_STA_AUTH;
321 mlme_authenticate_indication(hapd, sta);
322}
323#endif /* CONFIG_IEEE80211R */
324
325
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800326#ifdef CONFIG_SAE
327
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800328static struct wpabuf * auth_process_sae_commit(struct hostapd_data *hapd,
329 struct sta_info *sta)
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800330{
331 struct wpabuf *buf;
332
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800333 if (hapd->conf->ssid.wpa_passphrase == NULL) {
334 wpa_printf(MSG_DEBUG, "SAE: No password available");
335 return NULL;
336 }
337
338 if (sae_prepare_commit(hapd->own_addr, sta->addr,
339 (u8 *) hapd->conf->ssid.wpa_passphrase,
340 os_strlen(hapd->conf->ssid.wpa_passphrase),
341 sta->sae) < 0) {
342 wpa_printf(MSG_DEBUG, "SAE: Could not pick PWE");
343 return NULL;
344 }
345
346 if (sae_process_commit(sta->sae) < 0) {
347 wpa_printf(MSG_DEBUG, "SAE: Failed to process peer commit");
348 return NULL;
349 }
350
351 buf = wpabuf_alloc(SAE_COMMIT_MAX_LEN);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800352 if (buf == NULL)
353 return NULL;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800354 sae_write_commit(sta->sae, buf, NULL);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800355
356 return buf;
357}
358
359
360static struct wpabuf * auth_build_sae_confirm(struct hostapd_data *hapd,
361 struct sta_info *sta)
362{
363 struct wpabuf *buf;
364
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800365 buf = wpabuf_alloc(SAE_CONFIRM_MAX_LEN);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800366 if (buf == NULL)
367 return NULL;
368
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800369 sae_write_confirm(sta->sae, buf);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800370
371 return buf;
372}
373
374
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800375static int use_sae_anti_clogging(struct hostapd_data *hapd)
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800376{
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800377 struct sta_info *sta;
378 unsigned int open = 0;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800379
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800380 if (hapd->conf->sae_anti_clogging_threshold == 0)
381 return 1;
382
383 for (sta = hapd->sta_list; sta; sta = sta->next) {
384 if (!sta->sae)
385 continue;
386 if (sta->sae->state != SAE_COMMITTED &&
387 sta->sae->state != SAE_CONFIRMED)
388 continue;
389 open++;
390 if (open >= hapd->conf->sae_anti_clogging_threshold)
391 return 1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800392 }
393
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800394 return 0;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800395}
396
397
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800398static int check_sae_token(struct hostapd_data *hapd, const u8 *addr,
399 const u8 *token, size_t token_len)
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800400{
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800401 u8 mac[SHA256_MAC_LEN];
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800402
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800403 if (token_len != SHA256_MAC_LEN)
404 return -1;
405 if (hmac_sha256(hapd->sae_token_key, sizeof(hapd->sae_token_key),
406 addr, ETH_ALEN, mac) < 0 ||
407 os_memcmp(token, mac, SHA256_MAC_LEN) != 0)
408 return -1;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800409
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800410 return 0;
411}
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800412
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800413
414static struct wpabuf * auth_build_token_req(struct hostapd_data *hapd,
415 const u8 *addr)
416{
417 struct wpabuf *buf;
418 u8 *token;
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800419 struct os_reltime now;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800420
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800421 os_get_reltime(&now);
422 if (!os_reltime_initialized(&hapd->last_sae_token_key_update) ||
423 os_reltime_expired(&now, &hapd->last_sae_token_key_update, 60)) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800424 if (random_get_bytes(hapd->sae_token_key,
425 sizeof(hapd->sae_token_key)) < 0)
426 return NULL;
427 wpa_hexdump(MSG_DEBUG, "SAE: Updated token key",
428 hapd->sae_token_key, sizeof(hapd->sae_token_key));
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800429 hapd->last_sae_token_key_update = now;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800430 }
431
432 buf = wpabuf_alloc(SHA256_MAC_LEN);
433 if (buf == NULL)
434 return NULL;
435
436 token = wpabuf_put(buf, SHA256_MAC_LEN);
437 hmac_sha256(hapd->sae_token_key, sizeof(hapd->sae_token_key),
438 addr, ETH_ALEN, token);
439
440 return buf;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800441}
442
443
444static void handle_auth_sae(struct hostapd_data *hapd, struct sta_info *sta,
445 const struct ieee80211_mgmt *mgmt, size_t len,
446 u8 auth_transaction)
447{
448 u16 resp = WLAN_STATUS_SUCCESS;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800449 struct wpabuf *data = NULL;
450
451 if (!sta->sae) {
452 if (auth_transaction != 1)
453 return;
454 sta->sae = os_zalloc(sizeof(*sta->sae));
455 if (sta->sae == NULL)
456 return;
457 sta->sae->state = SAE_NOTHING;
458 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800459
460 if (auth_transaction == 1) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800461 const u8 *token = NULL;
462 size_t token_len = 0;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800463 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
464 HOSTAPD_LEVEL_DEBUG,
465 "start SAE authentication (RX commit)");
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800466 resp = sae_parse_commit(sta->sae, mgmt->u.auth.variable,
467 ((const u8 *) mgmt) + len -
468 mgmt->u.auth.variable, &token,
469 &token_len, hapd->conf->sae_groups);
470 if (token && check_sae_token(hapd, sta->addr, token, token_len)
471 < 0) {
472 wpa_printf(MSG_DEBUG, "SAE: Drop commit message with "
473 "incorrect token from " MACSTR,
474 MAC2STR(sta->addr));
475 return;
476 }
477
478 if (resp == WLAN_STATUS_SUCCESS) {
479 if (!token && use_sae_anti_clogging(hapd)) {
480 wpa_printf(MSG_DEBUG, "SAE: Request anti-"
481 "clogging token from " MACSTR,
482 MAC2STR(sta->addr));
483 data = auth_build_token_req(hapd, sta->addr);
484 resp = WLAN_STATUS_ANTI_CLOGGING_TOKEN_REQ;
485 } else {
486 data = auth_process_sae_commit(hapd, sta);
487 if (data == NULL)
488 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
489 else
490 sta->sae->state = SAE_COMMITTED;
491 }
492 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800493 } else if (auth_transaction == 2) {
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800494 if (sta->sae->state != SAE_COMMITTED) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800495 hostapd_logger(hapd, sta->addr,
496 HOSTAPD_MODULE_IEEE80211,
497 HOSTAPD_LEVEL_DEBUG,
498 "SAE confirm before commit");
499 resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
Dmitry Shmidt96be6222014-02-13 10:16:51 -0800500 goto failed;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800501 }
502 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
503 HOSTAPD_LEVEL_DEBUG,
504 "SAE authentication (RX confirm)");
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800505 if (sae_check_confirm(sta->sae, mgmt->u.auth.variable,
506 ((u8 *) mgmt) + len -
507 mgmt->u.auth.variable) < 0) {
508 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
509 } else {
510 resp = WLAN_STATUS_SUCCESS;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800511 sta->flags |= WLAN_STA_AUTH;
512 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
513 sta->auth_alg = WLAN_AUTH_SAE;
514 mlme_authenticate_indication(hapd, sta);
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800515
516 data = auth_build_sae_confirm(hapd, sta);
517 if (data == NULL)
518 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
519 else {
520 sta->sae->state = SAE_ACCEPTED;
521 sae_clear_temp_data(sta->sae);
522 }
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800523 }
524 } else {
525 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
526 HOSTAPD_LEVEL_DEBUG,
527 "unexpected SAE authentication transaction %u",
528 auth_transaction);
529 resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
530 }
531
Dmitry Shmidt96be6222014-02-13 10:16:51 -0800532failed:
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800533 sta->auth_alg = WLAN_AUTH_SAE;
534
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800535 send_auth_reply(hapd, mgmt->sa, mgmt->bssid, WLAN_AUTH_SAE,
536 auth_transaction, resp,
537 data ? wpabuf_head(data) : (u8 *) "",
538 data ? wpabuf_len(data) : 0);
539 wpabuf_free(data);
540}
541#endif /* CONFIG_SAE */
542
543
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700544static void handle_auth(struct hostapd_data *hapd,
545 const struct ieee80211_mgmt *mgmt, size_t len)
546{
547 u16 auth_alg, auth_transaction, status_code;
548 u16 resp = WLAN_STATUS_SUCCESS;
549 struct sta_info *sta = NULL;
550 int res;
551 u16 fc;
552 const u8 *challenge = NULL;
553 u32 session_timeout, acct_interim_interval;
554 int vlan_id = 0;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800555 struct hostapd_sta_wpa_psk_short *psk = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700556 u8 resp_ies[2 + WLAN_AUTH_CHALLENGE_LEN];
557 size_t resp_ies_len = 0;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700558 char *identity = NULL;
559 char *radius_cui = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700560
561 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800562 wpa_printf(MSG_INFO, "handle_auth - too short payload (len=%lu)",
563 (unsigned long) len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700564 return;
565 }
566
Dmitry Shmidt8da800a2013-04-24 12:57:01 -0700567#ifdef CONFIG_TESTING_OPTIONS
568 if (hapd->iconf->ignore_auth_probability > 0.0d &&
569 drand48() < hapd->iconf->ignore_auth_probability) {
570 wpa_printf(MSG_INFO,
571 "TESTING: ignoring auth frame from " MACSTR,
572 MAC2STR(mgmt->sa));
573 return;
574 }
575#endif /* CONFIG_TESTING_OPTIONS */
576
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700577 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
578 auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
579 status_code = le_to_host16(mgmt->u.auth.status_code);
580 fc = le_to_host16(mgmt->frame_control);
581
582 if (len >= IEEE80211_HDRLEN + sizeof(mgmt->u.auth) +
583 2 + WLAN_AUTH_CHALLENGE_LEN &&
584 mgmt->u.auth.variable[0] == WLAN_EID_CHALLENGE &&
585 mgmt->u.auth.variable[1] == WLAN_AUTH_CHALLENGE_LEN)
586 challenge = &mgmt->u.auth.variable[2];
587
588 wpa_printf(MSG_DEBUG, "authentication: STA=" MACSTR " auth_alg=%d "
589 "auth_transaction=%d status_code=%d wep=%d%s",
590 MAC2STR(mgmt->sa), auth_alg, auth_transaction,
591 status_code, !!(fc & WLAN_FC_ISWEP),
592 challenge ? " challenge" : "");
593
594 if (hapd->tkip_countermeasures) {
595 resp = WLAN_REASON_MICHAEL_MIC_FAILURE;
596 goto fail;
597 }
598
599 if (!(((hapd->conf->auth_algs & WPA_AUTH_ALG_OPEN) &&
600 auth_alg == WLAN_AUTH_OPEN) ||
601#ifdef CONFIG_IEEE80211R
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800602 (hapd->conf->wpa && wpa_key_mgmt_ft(hapd->conf->wpa_key_mgmt) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700603 auth_alg == WLAN_AUTH_FT) ||
604#endif /* CONFIG_IEEE80211R */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800605#ifdef CONFIG_SAE
606 (hapd->conf->wpa && wpa_key_mgmt_sae(hapd->conf->wpa_key_mgmt) &&
607 auth_alg == WLAN_AUTH_SAE) ||
608#endif /* CONFIG_SAE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700609 ((hapd->conf->auth_algs & WPA_AUTH_ALG_SHARED) &&
610 auth_alg == WLAN_AUTH_SHARED_KEY))) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800611 wpa_printf(MSG_INFO, "Unsupported authentication algorithm (%d)",
612 auth_alg);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700613 resp = WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
614 goto fail;
615 }
616
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800617 if (!(auth_transaction == 1 || auth_alg == WLAN_AUTH_SAE ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700618 (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 3))) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800619 wpa_printf(MSG_INFO, "Unknown authentication transaction number (%d)",
620 auth_transaction);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700621 resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
622 goto fail;
623 }
624
625 if (os_memcmp(mgmt->sa, hapd->own_addr, ETH_ALEN) == 0) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800626 wpa_printf(MSG_INFO, "Station " MACSTR " not allowed to authenticate",
627 MAC2STR(mgmt->sa));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700628 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
629 goto fail;
630 }
631
632 res = hostapd_allowed_address(hapd, mgmt->sa, (u8 *) mgmt, len,
633 &session_timeout,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800634 &acct_interim_interval, &vlan_id,
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800635 &psk, &identity, &radius_cui);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800636
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700637 if (res == HOSTAPD_ACL_REJECT) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800638 wpa_printf(MSG_INFO, "Station " MACSTR " not allowed to authenticate",
639 MAC2STR(mgmt->sa));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700640 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
641 goto fail;
642 }
643 if (res == HOSTAPD_ACL_PENDING) {
644 wpa_printf(MSG_DEBUG, "Authentication frame from " MACSTR
645 " waiting for an external authentication",
646 MAC2STR(mgmt->sa));
647 /* Authentication code will re-send the authentication frame
648 * after it has received (and cached) information from the
649 * external source. */
650 return;
651 }
652
653 sta = ap_sta_add(hapd, mgmt->sa);
654 if (!sta) {
Dmitry Shmidt4b060592013-04-29 16:42:49 -0700655 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700656 goto fail;
657 }
658
659 if (vlan_id > 0) {
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700660 if (!hostapd_vlan_id_valid(hapd->conf->vlan, vlan_id)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700661 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
662 HOSTAPD_LEVEL_INFO, "Invalid VLAN ID "
663 "%d received from RADIUS server",
664 vlan_id);
665 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
666 goto fail;
667 }
668 sta->vlan_id = vlan_id;
669 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
670 HOSTAPD_LEVEL_INFO, "VLAN ID %d", sta->vlan_id);
671 }
672
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800673 hostapd_free_psk_list(sta->psk);
674 if (hapd->conf->wpa_psk_radius != PSK_RADIUS_IGNORED) {
675 sta->psk = psk;
676 psk = NULL;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800677 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800678 sta->psk = NULL;
679 }
680
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700681 sta->identity = identity;
682 identity = NULL;
683 sta->radius_cui = radius_cui;
684 radius_cui = NULL;
685
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700686 sta->flags &= ~WLAN_STA_PREAUTH;
687 ieee802_1x_notify_pre_auth(sta->eapol_sm, 0);
688
689 if (hapd->conf->acct_interim_interval == 0 && acct_interim_interval)
690 sta->acct_interim_interval = acct_interim_interval;
691 if (res == HOSTAPD_ACL_ACCEPT_TIMEOUT)
692 ap_sta_session_timeout(hapd, sta, session_timeout);
693 else
694 ap_sta_no_session_timeout(hapd, sta);
695
696 switch (auth_alg) {
697 case WLAN_AUTH_OPEN:
698 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
699 HOSTAPD_LEVEL_DEBUG,
700 "authentication OK (open system)");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700701 sta->flags |= WLAN_STA_AUTH;
702 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
703 sta->auth_alg = WLAN_AUTH_OPEN;
704 mlme_authenticate_indication(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700705 break;
706 case WLAN_AUTH_SHARED_KEY:
707 resp = auth_shared_key(hapd, sta, auth_transaction, challenge,
708 fc & WLAN_FC_ISWEP);
709 sta->auth_alg = WLAN_AUTH_SHARED_KEY;
710 mlme_authenticate_indication(hapd, sta);
711 if (sta->challenge && auth_transaction == 1) {
712 resp_ies[0] = WLAN_EID_CHALLENGE;
713 resp_ies[1] = WLAN_AUTH_CHALLENGE_LEN;
714 os_memcpy(resp_ies + 2, sta->challenge,
715 WLAN_AUTH_CHALLENGE_LEN);
716 resp_ies_len = 2 + WLAN_AUTH_CHALLENGE_LEN;
717 }
718 break;
719#ifdef CONFIG_IEEE80211R
720 case WLAN_AUTH_FT:
721 sta->auth_alg = WLAN_AUTH_FT;
722 if (sta->wpa_sm == NULL)
723 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700724 sta->addr, NULL);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700725 if (sta->wpa_sm == NULL) {
726 wpa_printf(MSG_DEBUG, "FT: Failed to initialize WPA "
727 "state machine");
728 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
729 goto fail;
730 }
731 wpa_ft_process_auth(sta->wpa_sm, mgmt->bssid,
732 auth_transaction, mgmt->u.auth.variable,
733 len - IEEE80211_HDRLEN -
734 sizeof(mgmt->u.auth),
735 handle_auth_ft_finish, hapd);
736 /* handle_auth_ft_finish() callback will complete auth. */
737 return;
738#endif /* CONFIG_IEEE80211R */
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800739#ifdef CONFIG_SAE
740 case WLAN_AUTH_SAE:
741 handle_auth_sae(hapd, sta, mgmt, len, auth_transaction);
742 return;
743#endif /* CONFIG_SAE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700744 }
745
746 fail:
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700747 os_free(identity);
748 os_free(radius_cui);
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800749 hostapd_free_psk_list(psk);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700750
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700751 send_auth_reply(hapd, mgmt->sa, mgmt->bssid, auth_alg,
752 auth_transaction + 1, resp, resp_ies, resp_ies_len);
753}
754
755
756static int hostapd_get_aid(struct hostapd_data *hapd, struct sta_info *sta)
757{
758 int i, j = 32, aid;
759
760 /* get a unique AID */
761 if (sta->aid > 0) {
762 wpa_printf(MSG_DEBUG, " old AID %d", sta->aid);
763 return 0;
764 }
765
766 for (i = 0; i < AID_WORDS; i++) {
767 if (hapd->sta_aid[i] == (u32) -1)
768 continue;
769 for (j = 0; j < 32; j++) {
770 if (!(hapd->sta_aid[i] & BIT(j)))
771 break;
772 }
773 if (j < 32)
774 break;
775 }
776 if (j == 32)
777 return -1;
778 aid = i * 32 + j + 1;
779 if (aid > 2007)
780 return -1;
781
782 sta->aid = aid;
783 hapd->sta_aid[i] |= BIT(j);
784 wpa_printf(MSG_DEBUG, " new AID %d", sta->aid);
785 return 0;
786}
787
788
789static u16 check_ssid(struct hostapd_data *hapd, struct sta_info *sta,
790 const u8 *ssid_ie, size_t ssid_ie_len)
791{
792 if (ssid_ie == NULL)
793 return WLAN_STATUS_UNSPECIFIED_FAILURE;
794
795 if (ssid_ie_len != hapd->conf->ssid.ssid_len ||
796 os_memcmp(ssid_ie, hapd->conf->ssid.ssid, ssid_ie_len) != 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700797 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
798 HOSTAPD_LEVEL_INFO,
799 "Station tried to associate with unknown SSID "
Dmitry Shmidt3c479372014-02-04 10:50:36 -0800800 "'%s'", wpa_ssid_txt(ssid_ie, ssid_ie_len));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700801 return WLAN_STATUS_UNSPECIFIED_FAILURE;
802 }
803
804 return WLAN_STATUS_SUCCESS;
805}
806
807
808static u16 check_wmm(struct hostapd_data *hapd, struct sta_info *sta,
809 const u8 *wmm_ie, size_t wmm_ie_len)
810{
811 sta->flags &= ~WLAN_STA_WMM;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800812 sta->qosinfo = 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700813 if (wmm_ie && hapd->conf->wmm_enabled) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800814 struct wmm_information_element *wmm;
815
816 if (!hostapd_eid_wmm_valid(hapd, wmm_ie, wmm_ie_len)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700817 hostapd_logger(hapd, sta->addr,
818 HOSTAPD_MODULE_WPA,
819 HOSTAPD_LEVEL_DEBUG,
820 "invalid WMM element in association "
821 "request");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800822 return WLAN_STATUS_UNSPECIFIED_FAILURE;
823 }
824
825 sta->flags |= WLAN_STA_WMM;
826 wmm = (struct wmm_information_element *) wmm_ie;
827 sta->qosinfo = wmm->qos_info;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700828 }
829 return WLAN_STATUS_SUCCESS;
830}
831
832
833static u16 copy_supp_rates(struct hostapd_data *hapd, struct sta_info *sta,
834 struct ieee802_11_elems *elems)
835{
836 if (!elems->supp_rates) {
837 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
838 HOSTAPD_LEVEL_DEBUG,
839 "No supported rates element in AssocReq");
840 return WLAN_STATUS_UNSPECIFIED_FAILURE;
841 }
842
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700843 if (elems->supp_rates_len + elems->ext_supp_rates_len >
844 sizeof(sta->supported_rates)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700845 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
846 HOSTAPD_LEVEL_DEBUG,
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700847 "Invalid supported rates element length %d+%d",
848 elems->supp_rates_len,
849 elems->ext_supp_rates_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700850 return WLAN_STATUS_UNSPECIFIED_FAILURE;
851 }
852
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700853 sta->supported_rates_len = merge_byte_arrays(
854 sta->supported_rates, sizeof(sta->supported_rates),
855 elems->supp_rates, elems->supp_rates_len,
856 elems->ext_supp_rates, elems->ext_supp_rates_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700857
858 return WLAN_STATUS_SUCCESS;
859}
860
861
Dmitry Shmidt051af732013-10-22 13:52:46 -0700862static u16 check_ext_capab(struct hostapd_data *hapd, struct sta_info *sta,
863 const u8 *ext_capab_ie, size_t ext_capab_ie_len)
864{
865#ifdef CONFIG_INTERWORKING
866 /* check for QoS Map support */
867 if (ext_capab_ie_len >= 5) {
868 if (ext_capab_ie[4] & 0x01)
869 sta->qos_map_enabled = 1;
870 }
871#endif /* CONFIG_INTERWORKING */
872
873 return WLAN_STATUS_SUCCESS;
874}
875
876
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700877static u16 check_assoc_ies(struct hostapd_data *hapd, struct sta_info *sta,
878 const u8 *ies, size_t ies_len, int reassoc)
879{
880 struct ieee802_11_elems elems;
881 u16 resp;
882 const u8 *wpa_ie;
883 size_t wpa_ie_len;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700884 const u8 *p2p_dev_addr = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700885
886 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed) {
887 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
888 HOSTAPD_LEVEL_INFO, "Station sent an invalid "
889 "association request");
890 return WLAN_STATUS_UNSPECIFIED_FAILURE;
891 }
892
893 resp = check_ssid(hapd, sta, elems.ssid, elems.ssid_len);
894 if (resp != WLAN_STATUS_SUCCESS)
895 return resp;
896 resp = check_wmm(hapd, sta, elems.wmm, elems.wmm_len);
897 if (resp != WLAN_STATUS_SUCCESS)
898 return resp;
Dmitry Shmidt051af732013-10-22 13:52:46 -0700899 resp = check_ext_capab(hapd, sta, elems.ext_capab, elems.ext_capab_len);
900 if (resp != WLAN_STATUS_SUCCESS)
901 return resp;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700902 resp = copy_supp_rates(hapd, sta, &elems);
903 if (resp != WLAN_STATUS_SUCCESS)
904 return resp;
905#ifdef CONFIG_IEEE80211N
906 resp = copy_sta_ht_capab(hapd, sta, elems.ht_capabilities,
907 elems.ht_capabilities_len);
908 if (resp != WLAN_STATUS_SUCCESS)
909 return resp;
910 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht &&
911 !(sta->flags & WLAN_STA_HT)) {
912 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
913 HOSTAPD_LEVEL_INFO, "Station does not support "
914 "mandatory HT PHY - reject association");
915 return WLAN_STATUS_ASSOC_DENIED_NO_HT;
916 }
917#endif /* CONFIG_IEEE80211N */
918
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700919#ifdef CONFIG_IEEE80211AC
920 resp = copy_sta_vht_capab(hapd, sta, elems.vht_capabilities,
921 elems.vht_capabilities_len);
922 if (resp != WLAN_STATUS_SUCCESS)
923 return resp;
Dmitry Shmidtbd14a572014-02-18 10:33:49 -0800924
925 resp = set_sta_vht_opmode(hapd, sta, elems.vht_opmode_notif);
926 if (resp != WLAN_STATUS_SUCCESS)
927 return resp;
928
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700929 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht &&
930 !(sta->flags & WLAN_STA_VHT)) {
931 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
932 HOSTAPD_LEVEL_INFO, "Station does not support "
933 "mandatory VHT PHY - reject association");
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800934 return WLAN_STATUS_ASSOC_DENIED_NO_VHT;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700935 }
936#endif /* CONFIG_IEEE80211AC */
937
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700938#ifdef CONFIG_P2P
939 if (elems.p2p) {
940 wpabuf_free(sta->p2p_ie);
941 sta->p2p_ie = ieee802_11_vendor_ie_concat(ies, ies_len,
942 P2P_IE_VENDOR_TYPE);
943 if (sta->p2p_ie)
944 p2p_dev_addr = p2p_get_go_dev_addr(sta->p2p_ie);
945 } else {
946 wpabuf_free(sta->p2p_ie);
947 sta->p2p_ie = NULL;
948 }
949#endif /* CONFIG_P2P */
950
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700951 if ((hapd->conf->wpa & WPA_PROTO_RSN) && elems.rsn_ie) {
952 wpa_ie = elems.rsn_ie;
953 wpa_ie_len = elems.rsn_ie_len;
954 } else if ((hapd->conf->wpa & WPA_PROTO_WPA) &&
955 elems.wpa_ie) {
956 wpa_ie = elems.wpa_ie;
957 wpa_ie_len = elems.wpa_ie_len;
958 } else {
959 wpa_ie = NULL;
960 wpa_ie_len = 0;
961 }
962
963#ifdef CONFIG_WPS
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800964 sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS | WLAN_STA_WPS2);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700965 if (hapd->conf->wps_state && elems.wps_ie) {
966 wpa_printf(MSG_DEBUG, "STA included WPS IE in (Re)Association "
967 "Request - assume WPS is used");
968 sta->flags |= WLAN_STA_WPS;
969 wpabuf_free(sta->wps_ie);
970 sta->wps_ie = ieee802_11_vendor_ie_concat(ies, ies_len,
971 WPS_IE_VENDOR_TYPE);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800972 if (sta->wps_ie && wps_is_20(sta->wps_ie)) {
973 wpa_printf(MSG_DEBUG, "WPS: STA supports WPS 2.0");
974 sta->flags |= WLAN_STA_WPS2;
975 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700976 wpa_ie = NULL;
977 wpa_ie_len = 0;
978 if (sta->wps_ie && wps_validate_assoc_req(sta->wps_ie) < 0) {
979 wpa_printf(MSG_DEBUG, "WPS: Invalid WPS IE in "
980 "(Re)Association Request - reject");
981 return WLAN_STATUS_INVALID_IE;
982 }
983 } else if (hapd->conf->wps_state && wpa_ie == NULL) {
984 wpa_printf(MSG_DEBUG, "STA did not include WPA/RSN IE in "
985 "(Re)Association Request - possible WPS use");
986 sta->flags |= WLAN_STA_MAYBE_WPS;
987 } else
988#endif /* CONFIG_WPS */
989 if (hapd->conf->wpa && wpa_ie == NULL) {
990 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
991 HOSTAPD_LEVEL_INFO,
992 "No WPA/RSN IE in association request");
993 return WLAN_STATUS_INVALID_IE;
994 }
995
996 if (hapd->conf->wpa && wpa_ie) {
997 int res;
998 wpa_ie -= 2;
999 wpa_ie_len += 2;
1000 if (sta->wpa_sm == NULL)
1001 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001002 sta->addr,
1003 p2p_dev_addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001004 if (sta->wpa_sm == NULL) {
1005 wpa_printf(MSG_WARNING, "Failed to initialize WPA "
1006 "state machine");
1007 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1008 }
1009 res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,
1010 wpa_ie, wpa_ie_len,
1011 elems.mdie, elems.mdie_len);
1012 if (res == WPA_INVALID_GROUP)
1013 resp = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
1014 else if (res == WPA_INVALID_PAIRWISE)
1015 resp = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
1016 else if (res == WPA_INVALID_AKMP)
1017 resp = WLAN_STATUS_AKMP_NOT_VALID;
1018 else if (res == WPA_ALLOC_FAIL)
1019 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1020#ifdef CONFIG_IEEE80211W
1021 else if (res == WPA_MGMT_FRAME_PROTECTION_VIOLATION)
1022 resp = WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION;
1023 else if (res == WPA_INVALID_MGMT_GROUP_CIPHER)
1024 resp = WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION;
1025#endif /* CONFIG_IEEE80211W */
1026 else if (res == WPA_INVALID_MDIE)
1027 resp = WLAN_STATUS_INVALID_MDIE;
1028 else if (res != WPA_IE_OK)
1029 resp = WLAN_STATUS_INVALID_IE;
1030 if (resp != WLAN_STATUS_SUCCESS)
1031 return resp;
1032#ifdef CONFIG_IEEE80211W
1033 if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
1034 sta->sa_query_count > 0)
1035 ap_check_sa_query_timeout(hapd, sta);
1036 if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
1037 (!reassoc || sta->auth_alg != WLAN_AUTH_FT)) {
1038 /*
1039 * STA has already been associated with MFP and SA
1040 * Query timeout has not been reached. Reject the
1041 * association attempt temporarily and start SA Query,
1042 * if one is not pending.
1043 */
1044
1045 if (sta->sa_query_count == 0)
1046 ap_sta_start_sa_query(hapd, sta);
1047
1048 return WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY;
1049 }
1050
1051 if (wpa_auth_uses_mfp(sta->wpa_sm))
1052 sta->flags |= WLAN_STA_MFP;
1053 else
1054 sta->flags &= ~WLAN_STA_MFP;
1055#endif /* CONFIG_IEEE80211W */
1056
1057#ifdef CONFIG_IEEE80211R
1058 if (sta->auth_alg == WLAN_AUTH_FT) {
1059 if (!reassoc) {
1060 wpa_printf(MSG_DEBUG, "FT: " MACSTR " tried "
1061 "to use association (not "
1062 "re-association) with FT auth_alg",
1063 MAC2STR(sta->addr));
1064 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1065 }
1066
1067 resp = wpa_ft_validate_reassoc(sta->wpa_sm, ies,
1068 ies_len);
1069 if (resp != WLAN_STATUS_SUCCESS)
1070 return resp;
1071 }
1072#endif /* CONFIG_IEEE80211R */
1073
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001074#ifdef CONFIG_SAE
1075 if (wpa_auth_uses_sae(sta->wpa_sm) &&
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001076 sta->auth_alg != WLAN_AUTH_SAE &&
1077 !(sta->auth_alg == WLAN_AUTH_FT &&
1078 wpa_auth_uses_ft_sae(sta->wpa_sm))) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001079 wpa_printf(MSG_DEBUG, "SAE: " MACSTR " tried to use "
1080 "SAE AKM after non-SAE auth_alg %u",
1081 MAC2STR(sta->addr), sta->auth_alg);
1082 return WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
1083 }
1084#endif /* CONFIG_SAE */
1085
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001086#ifdef CONFIG_IEEE80211N
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001087 if ((sta->flags & (WLAN_STA_HT | WLAN_STA_VHT)) &&
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001088 wpa_auth_get_pairwise(sta->wpa_sm) == WPA_CIPHER_TKIP) {
1089 hostapd_logger(hapd, sta->addr,
1090 HOSTAPD_MODULE_IEEE80211,
1091 HOSTAPD_LEVEL_INFO,
1092 "Station tried to use TKIP with HT "
1093 "association");
1094 return WLAN_STATUS_CIPHER_REJECTED_PER_POLICY;
1095 }
1096#endif /* CONFIG_IEEE80211N */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001097#ifdef CONFIG_HS20
1098 } else if (hapd->conf->osen) {
1099 if (elems.osen == NULL) {
1100 hostapd_logger(
1101 hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1102 HOSTAPD_LEVEL_INFO,
1103 "No HS 2.0 OSEN element in association request");
1104 return WLAN_STATUS_INVALID_IE;
1105 }
1106
1107 wpa_printf(MSG_DEBUG, "HS 2.0: OSEN association");
1108 if (sta->wpa_sm == NULL)
1109 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
1110 sta->addr, NULL);
1111 if (sta->wpa_sm == NULL) {
1112 wpa_printf(MSG_WARNING, "Failed to initialize WPA "
1113 "state machine");
1114 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1115 }
1116 if (wpa_validate_osen(hapd->wpa_auth, sta->wpa_sm,
1117 elems.osen - 2, elems.osen_len + 2) < 0)
1118 return WLAN_STATUS_INVALID_IE;
1119#endif /* CONFIG_HS20 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001120 } else
1121 wpa_auth_sta_no_wpa(sta->wpa_sm);
1122
1123#ifdef CONFIG_P2P
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001124 p2p_group_notif_assoc(hapd->p2p_group, sta->addr, ies, ies_len);
1125#endif /* CONFIG_P2P */
1126
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001127#ifdef CONFIG_HS20
1128 wpabuf_free(sta->hs20_ie);
1129 if (elems.hs20 && elems.hs20_len > 4) {
1130 sta->hs20_ie = wpabuf_alloc_copy(elems.hs20 + 4,
1131 elems.hs20_len - 4);
1132 } else
1133 sta->hs20_ie = NULL;
1134#endif /* CONFIG_HS20 */
1135
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001136 return WLAN_STATUS_SUCCESS;
1137}
1138
1139
1140static void send_deauth(struct hostapd_data *hapd, const u8 *addr,
1141 u16 reason_code)
1142{
1143 int send_len;
1144 struct ieee80211_mgmt reply;
1145
1146 os_memset(&reply, 0, sizeof(reply));
1147 reply.frame_control =
1148 IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_DEAUTH);
1149 os_memcpy(reply.da, addr, ETH_ALEN);
1150 os_memcpy(reply.sa, hapd->own_addr, ETH_ALEN);
1151 os_memcpy(reply.bssid, hapd->own_addr, ETH_ALEN);
1152
1153 send_len = IEEE80211_HDRLEN + sizeof(reply.u.deauth);
1154 reply.u.deauth.reason_code = host_to_le16(reason_code);
1155
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001156 if (hostapd_drv_send_mlme(hapd, &reply, send_len, 0) < 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001157 wpa_printf(MSG_INFO, "Failed to send deauth: %s",
1158 strerror(errno));
1159}
1160
1161
1162static void send_assoc_resp(struct hostapd_data *hapd, struct sta_info *sta,
1163 u16 status_code, int reassoc, const u8 *ies,
1164 size_t ies_len)
1165{
1166 int send_len;
1167 u8 buf[sizeof(struct ieee80211_mgmt) + 1024];
1168 struct ieee80211_mgmt *reply;
1169 u8 *p;
1170
1171 os_memset(buf, 0, sizeof(buf));
1172 reply = (struct ieee80211_mgmt *) buf;
1173 reply->frame_control =
1174 IEEE80211_FC(WLAN_FC_TYPE_MGMT,
1175 (reassoc ? WLAN_FC_STYPE_REASSOC_RESP :
1176 WLAN_FC_STYPE_ASSOC_RESP));
1177 os_memcpy(reply->da, sta->addr, ETH_ALEN);
1178 os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN);
1179 os_memcpy(reply->bssid, hapd->own_addr, ETH_ALEN);
1180
1181 send_len = IEEE80211_HDRLEN;
1182 send_len += sizeof(reply->u.assoc_resp);
1183 reply->u.assoc_resp.capab_info =
1184 host_to_le16(hostapd_own_capab_info(hapd, sta, 0));
1185 reply->u.assoc_resp.status_code = host_to_le16(status_code);
Dmitry Shmidt96be6222014-02-13 10:16:51 -08001186 reply->u.assoc_resp.aid = host_to_le16(sta->aid | BIT(14) | BIT(15));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001187 /* Supported rates */
1188 p = hostapd_eid_supp_rates(hapd, reply->u.assoc_resp.variable);
1189 /* Extended supported rates */
1190 p = hostapd_eid_ext_supp_rates(hapd, p);
1191
1192#ifdef CONFIG_IEEE80211R
1193 if (status_code == WLAN_STATUS_SUCCESS) {
1194 /* IEEE 802.11r: Mobility Domain Information, Fast BSS
1195 * Transition Information, RSN, [RIC Response] */
1196 p = wpa_sm_write_assoc_resp_ies(sta->wpa_sm, p,
1197 buf + sizeof(buf) - p,
1198 sta->auth_alg, ies, ies_len);
1199 }
1200#endif /* CONFIG_IEEE80211R */
1201
1202#ifdef CONFIG_IEEE80211W
1203 if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY)
1204 p = hostapd_eid_assoc_comeback_time(hapd, sta, p);
1205#endif /* CONFIG_IEEE80211W */
1206
1207#ifdef CONFIG_IEEE80211N
1208 p = hostapd_eid_ht_capabilities(hapd, p);
1209 p = hostapd_eid_ht_operation(hapd, p);
1210#endif /* CONFIG_IEEE80211N */
1211
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001212#ifdef CONFIG_IEEE80211AC
1213 p = hostapd_eid_vht_capabilities(hapd, p);
1214 p = hostapd_eid_vht_operation(hapd, p);
1215#endif /* CONFIG_IEEE80211AC */
1216
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001217 p = hostapd_eid_ext_capab(hapd, p);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001218 p = hostapd_eid_bss_max_idle_period(hapd, p);
Dmitry Shmidt051af732013-10-22 13:52:46 -07001219 if (sta->qos_map_enabled)
1220 p = hostapd_eid_qos_map_set(hapd, p);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001221
1222 if (sta->flags & WLAN_STA_WMM)
1223 p = hostapd_eid_wmm(hapd, p);
1224
1225#ifdef CONFIG_WPS
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001226 if ((sta->flags & WLAN_STA_WPS) ||
1227 ((sta->flags & WLAN_STA_MAYBE_WPS) && hapd->conf->wpa)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001228 struct wpabuf *wps = wps_build_assoc_resp_ie();
1229 if (wps) {
1230 os_memcpy(p, wpabuf_head(wps), wpabuf_len(wps));
1231 p += wpabuf_len(wps);
1232 wpabuf_free(wps);
1233 }
1234 }
1235#endif /* CONFIG_WPS */
1236
1237#ifdef CONFIG_P2P
1238 if (sta->p2p_ie) {
1239 struct wpabuf *p2p_resp_ie;
1240 enum p2p_status_code status;
1241 switch (status_code) {
1242 case WLAN_STATUS_SUCCESS:
1243 status = P2P_SC_SUCCESS;
1244 break;
1245 case WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA:
1246 status = P2P_SC_FAIL_LIMIT_REACHED;
1247 break;
1248 default:
1249 status = P2P_SC_FAIL_INVALID_PARAMS;
1250 break;
1251 }
1252 p2p_resp_ie = p2p_group_assoc_resp_ie(hapd->p2p_group, status);
1253 if (p2p_resp_ie) {
1254 os_memcpy(p, wpabuf_head(p2p_resp_ie),
1255 wpabuf_len(p2p_resp_ie));
1256 p += wpabuf_len(p2p_resp_ie);
1257 wpabuf_free(p2p_resp_ie);
1258 }
1259 }
1260#endif /* CONFIG_P2P */
1261
1262#ifdef CONFIG_P2P_MANAGER
1263 if (hapd->conf->p2p & P2P_MANAGE)
1264 p = hostapd_eid_p2p_manage(hapd, p);
1265#endif /* CONFIG_P2P_MANAGER */
1266
1267 send_len += p - reply->u.assoc_resp.variable;
1268
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001269 if (hostapd_drv_send_mlme(hapd, reply, send_len, 0) < 0)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001270 wpa_printf(MSG_INFO, "Failed to send assoc resp: %s",
1271 strerror(errno));
1272}
1273
1274
1275static void handle_assoc(struct hostapd_data *hapd,
1276 const struct ieee80211_mgmt *mgmt, size_t len,
1277 int reassoc)
1278{
1279 u16 capab_info, listen_interval;
1280 u16 resp = WLAN_STATUS_SUCCESS;
1281 const u8 *pos;
1282 int left, i;
1283 struct sta_info *sta;
1284
1285 if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_req) :
1286 sizeof(mgmt->u.assoc_req))) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001287 wpa_printf(MSG_INFO, "handle_assoc(reassoc=%d) - too short payload (len=%lu)",
1288 reassoc, (unsigned long) len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001289 return;
1290 }
1291
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001292#ifdef CONFIG_TESTING_OPTIONS
1293 if (reassoc) {
1294 if (hapd->iconf->ignore_reassoc_probability > 0.0d &&
1295 drand48() < hapd->iconf->ignore_reassoc_probability) {
1296 wpa_printf(MSG_INFO,
1297 "TESTING: ignoring reassoc request from "
1298 MACSTR, MAC2STR(mgmt->sa));
1299 return;
1300 }
1301 } else {
1302 if (hapd->iconf->ignore_assoc_probability > 0.0d &&
1303 drand48() < hapd->iconf->ignore_assoc_probability) {
1304 wpa_printf(MSG_INFO,
1305 "TESTING: ignoring assoc request from "
1306 MACSTR, MAC2STR(mgmt->sa));
1307 return;
1308 }
1309 }
1310#endif /* CONFIG_TESTING_OPTIONS */
1311
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001312 if (reassoc) {
1313 capab_info = le_to_host16(mgmt->u.reassoc_req.capab_info);
1314 listen_interval = le_to_host16(
1315 mgmt->u.reassoc_req.listen_interval);
1316 wpa_printf(MSG_DEBUG, "reassociation request: STA=" MACSTR
1317 " capab_info=0x%02x listen_interval=%d current_ap="
1318 MACSTR,
1319 MAC2STR(mgmt->sa), capab_info, listen_interval,
1320 MAC2STR(mgmt->u.reassoc_req.current_ap));
1321 left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.reassoc_req));
1322 pos = mgmt->u.reassoc_req.variable;
1323 } else {
1324 capab_info = le_to_host16(mgmt->u.assoc_req.capab_info);
1325 listen_interval = le_to_host16(
1326 mgmt->u.assoc_req.listen_interval);
1327 wpa_printf(MSG_DEBUG, "association request: STA=" MACSTR
1328 " capab_info=0x%02x listen_interval=%d",
1329 MAC2STR(mgmt->sa), capab_info, listen_interval);
1330 left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.assoc_req));
1331 pos = mgmt->u.assoc_req.variable;
1332 }
1333
1334 sta = ap_get_sta(hapd, mgmt->sa);
1335#ifdef CONFIG_IEEE80211R
1336 if (sta && sta->auth_alg == WLAN_AUTH_FT &&
1337 (sta->flags & WLAN_STA_AUTH) == 0) {
1338 wpa_printf(MSG_DEBUG, "FT: Allow STA " MACSTR " to associate "
1339 "prior to authentication since it is using "
1340 "over-the-DS FT", MAC2STR(mgmt->sa));
1341 } else
1342#endif /* CONFIG_IEEE80211R */
1343 if (sta == NULL || (sta->flags & WLAN_STA_AUTH) == 0) {
1344 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1345 HOSTAPD_LEVEL_INFO, "Station tried to "
1346 "associate before authentication "
1347 "(aid=%d flags=0x%x)",
1348 sta ? sta->aid : -1,
1349 sta ? sta->flags : 0);
1350 send_deauth(hapd, mgmt->sa,
1351 WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA);
1352 return;
1353 }
1354
1355 if (hapd->tkip_countermeasures) {
1356 resp = WLAN_REASON_MICHAEL_MIC_FAILURE;
1357 goto fail;
1358 }
1359
1360 if (listen_interval > hapd->conf->max_listen_interval) {
1361 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1362 HOSTAPD_LEVEL_DEBUG,
1363 "Too large Listen Interval (%d)",
1364 listen_interval);
1365 resp = WLAN_STATUS_ASSOC_DENIED_LISTEN_INT_TOO_LARGE;
1366 goto fail;
1367 }
1368
1369 /* followed by SSID and Supported rates; and HT capabilities if 802.11n
1370 * is used */
1371 resp = check_assoc_ies(hapd, sta, pos, left, reassoc);
1372 if (resp != WLAN_STATUS_SUCCESS)
1373 goto fail;
1374
1375 if (hostapd_get_aid(hapd, sta) < 0) {
1376 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1377 HOSTAPD_LEVEL_INFO, "No room for more AIDs");
1378 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
1379 goto fail;
1380 }
1381
1382 sta->capability = capab_info;
1383 sta->listen_interval = listen_interval;
1384
1385 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
1386 sta->flags |= WLAN_STA_NONERP;
1387 for (i = 0; i < sta->supported_rates_len; i++) {
1388 if ((sta->supported_rates[i] & 0x7f) > 22) {
1389 sta->flags &= ~WLAN_STA_NONERP;
1390 break;
1391 }
1392 }
1393 if (sta->flags & WLAN_STA_NONERP && !sta->nonerp_set) {
1394 sta->nonerp_set = 1;
1395 hapd->iface->num_sta_non_erp++;
1396 if (hapd->iface->num_sta_non_erp == 1)
1397 ieee802_11_set_beacons(hapd->iface);
1398 }
1399
1400 if (!(sta->capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) &&
1401 !sta->no_short_slot_time_set) {
1402 sta->no_short_slot_time_set = 1;
1403 hapd->iface->num_sta_no_short_slot_time++;
1404 if (hapd->iface->current_mode->mode ==
1405 HOSTAPD_MODE_IEEE80211G &&
1406 hapd->iface->num_sta_no_short_slot_time == 1)
1407 ieee802_11_set_beacons(hapd->iface);
1408 }
1409
1410 if (sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
1411 sta->flags |= WLAN_STA_SHORT_PREAMBLE;
1412 else
1413 sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
1414
1415 if (!(sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) &&
1416 !sta->no_short_preamble_set) {
1417 sta->no_short_preamble_set = 1;
1418 hapd->iface->num_sta_no_short_preamble++;
1419 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G
1420 && hapd->iface->num_sta_no_short_preamble == 1)
1421 ieee802_11_set_beacons(hapd->iface);
1422 }
1423
1424#ifdef CONFIG_IEEE80211N
1425 update_ht_state(hapd, sta);
1426#endif /* CONFIG_IEEE80211N */
1427
1428 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1429 HOSTAPD_LEVEL_DEBUG,
1430 "association OK (aid %d)", sta->aid);
1431 /* Station will be marked associated, after it acknowledges AssocResp
1432 */
1433 sta->flags |= WLAN_STA_ASSOC_REQ_OK;
1434
1435#ifdef CONFIG_IEEE80211W
1436 if ((sta->flags & WLAN_STA_MFP) && sta->sa_query_timed_out) {
1437 wpa_printf(MSG_DEBUG, "Allowing %sassociation after timed out "
1438 "SA Query procedure", reassoc ? "re" : "");
1439 /* TODO: Send a protected Disassociate frame to the STA using
1440 * the old key and Reason Code "Previous Authentication no
1441 * longer valid". Make sure this is only sent protected since
1442 * unprotected frame would be received by the STA that is now
1443 * trying to associate.
1444 */
1445 }
1446#endif /* CONFIG_IEEE80211W */
1447
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001448 /* Make sure that the previously registered inactivity timer will not
1449 * remove the STA immediately. */
1450 sta->timeout_next = STA_NULLFUNC;
1451
1452 fail:
1453 send_assoc_resp(hapd, sta, resp, reassoc, pos, left);
1454}
1455
1456
1457static void handle_disassoc(struct hostapd_data *hapd,
1458 const struct ieee80211_mgmt *mgmt, size_t len)
1459{
1460 struct sta_info *sta;
1461
1462 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.disassoc)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001463 wpa_printf(MSG_INFO, "handle_disassoc - too short payload (len=%lu)",
1464 (unsigned long) len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001465 return;
1466 }
1467
1468 wpa_printf(MSG_DEBUG, "disassocation: STA=" MACSTR " reason_code=%d",
1469 MAC2STR(mgmt->sa),
1470 le_to_host16(mgmt->u.disassoc.reason_code));
1471
1472 sta = ap_get_sta(hapd, mgmt->sa);
1473 if (sta == NULL) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001474 wpa_printf(MSG_INFO, "Station " MACSTR " trying to disassociate, but it is not associated",
1475 MAC2STR(mgmt->sa));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001476 return;
1477 }
1478
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001479 ap_sta_set_authorized(hapd, sta, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001480 sta->flags &= ~(WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001481 wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC);
1482 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1483 HOSTAPD_LEVEL_INFO, "disassociated");
1484 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
1485 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
1486 /* Stop Accounting and IEEE 802.1X sessions, but leave the STA
1487 * authenticated. */
1488 accounting_sta_stop(hapd, sta);
1489 ieee802_1x_free_station(sta);
1490 hostapd_drv_sta_remove(hapd, sta->addr);
1491
1492 if (sta->timeout_next == STA_NULLFUNC ||
1493 sta->timeout_next == STA_DISASSOC) {
1494 sta->timeout_next = STA_DEAUTH;
1495 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
1496 eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer,
1497 hapd, sta);
1498 }
1499
1500 mlme_disassociate_indication(
1501 hapd, sta, le_to_host16(mgmt->u.disassoc.reason_code));
1502}
1503
1504
1505static void handle_deauth(struct hostapd_data *hapd,
1506 const struct ieee80211_mgmt *mgmt, size_t len)
1507{
1508 struct sta_info *sta;
1509
1510 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.deauth)) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001511 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "handle_deauth - too short "
1512 "payload (len=%lu)", (unsigned long) len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001513 return;
1514 }
1515
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001516 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "deauthentication: STA=" MACSTR
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001517 " reason_code=%d",
1518 MAC2STR(mgmt->sa), le_to_host16(mgmt->u.deauth.reason_code));
1519
1520 sta = ap_get_sta(hapd, mgmt->sa);
1521 if (sta == NULL) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001522 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR " trying "
1523 "to deauthenticate, but it is not authenticated",
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001524 MAC2STR(mgmt->sa));
1525 return;
1526 }
1527
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001528 ap_sta_set_authorized(hapd, sta, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001529 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC |
1530 WLAN_STA_ASSOC_REQ_OK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001531 wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH);
1532 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1533 HOSTAPD_LEVEL_DEBUG, "deauthenticated");
1534 mlme_deauthenticate_indication(
1535 hapd, sta, le_to_host16(mgmt->u.deauth.reason_code));
1536 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
1537 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
1538 ap_free_sta(hapd, sta);
1539}
1540
1541
1542static void handle_beacon(struct hostapd_data *hapd,
1543 const struct ieee80211_mgmt *mgmt, size_t len,
1544 struct hostapd_frame_info *fi)
1545{
1546 struct ieee802_11_elems elems;
1547
1548 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.beacon)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001549 wpa_printf(MSG_INFO, "handle_beacon - too short payload (len=%lu)",
1550 (unsigned long) len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001551 return;
1552 }
1553
1554 (void) ieee802_11_parse_elems(mgmt->u.beacon.variable,
1555 len - (IEEE80211_HDRLEN +
1556 sizeof(mgmt->u.beacon)), &elems,
1557 0);
1558
1559 ap_list_process_beacon(hapd->iface, mgmt, &elems, fi);
1560}
1561
1562
1563#ifdef CONFIG_IEEE80211W
1564
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001565static int hostapd_sa_query_action(struct hostapd_data *hapd,
1566 const struct ieee80211_mgmt *mgmt,
1567 size_t len)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001568{
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001569 const u8 *end;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001570
1571 end = mgmt->u.action.u.sa_query_resp.trans_id +
1572 WLAN_SA_QUERY_TR_ID_LEN;
1573 if (((u8 *) mgmt) + len < end) {
1574 wpa_printf(MSG_DEBUG, "IEEE 802.11: Too short SA Query Action "
1575 "frame (len=%lu)", (unsigned long) len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001576 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001577 }
1578
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001579 ieee802_11_sa_query_action(hapd, mgmt->sa,
1580 mgmt->u.action.u.sa_query_resp.action,
1581 mgmt->u.action.u.sa_query_resp.trans_id);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001582 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001583}
1584
1585
1586static int robust_action_frame(u8 category)
1587{
1588 return category != WLAN_ACTION_PUBLIC &&
1589 category != WLAN_ACTION_HT;
1590}
1591#endif /* CONFIG_IEEE80211W */
1592
1593
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001594static int handle_action(struct hostapd_data *hapd,
1595 const struct ieee80211_mgmt *mgmt, size_t len)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001596{
1597 struct sta_info *sta;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001598 sta = ap_get_sta(hapd, mgmt->sa);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001599
1600 if (len < IEEE80211_HDRLEN + 1) {
1601 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1602 HOSTAPD_LEVEL_DEBUG,
1603 "handle_action - too short payload (len=%lu)",
1604 (unsigned long) len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001605 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001606 }
1607
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001608 if (mgmt->u.action.category != WLAN_ACTION_PUBLIC &&
1609 (sta == NULL || !(sta->flags & WLAN_STA_ASSOC))) {
1610 wpa_printf(MSG_DEBUG, "IEEE 802.11: Ignored Action "
1611 "frame (category=%u) from unassociated STA " MACSTR,
1612 MAC2STR(mgmt->sa), mgmt->u.action.category);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001613 return 0;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001614 }
1615
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001616#ifdef CONFIG_IEEE80211W
1617 if (sta && (sta->flags & WLAN_STA_MFP) &&
Dmitry Shmidt18463232014-01-24 12:29:41 -08001618 !(mgmt->frame_control & host_to_le16(WLAN_FC_ISWEP)) &&
1619 robust_action_frame(mgmt->u.action.category)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001620 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1621 HOSTAPD_LEVEL_DEBUG,
1622 "Dropped unprotected Robust Action frame from "
1623 "an MFP STA");
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001624 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001625 }
1626#endif /* CONFIG_IEEE80211W */
1627
1628 switch (mgmt->u.action.category) {
1629#ifdef CONFIG_IEEE80211R
1630 case WLAN_ACTION_FT:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001631 if (wpa_ft_action_rx(sta->wpa_sm, (u8 *) &mgmt->u.action,
1632 len - IEEE80211_HDRLEN))
1633 break;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001634 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001635#endif /* CONFIG_IEEE80211R */
1636 case WLAN_ACTION_WMM:
1637 hostapd_wmm_action(hapd, mgmt, len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001638 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001639#ifdef CONFIG_IEEE80211W
1640 case WLAN_ACTION_SA_QUERY:
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001641 return hostapd_sa_query_action(hapd, mgmt, len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001642#endif /* CONFIG_IEEE80211W */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001643#ifdef CONFIG_WNM
1644 case WLAN_ACTION_WNM:
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001645 ieee802_11_rx_wnm_action_ap(hapd, mgmt, len);
1646 return 1;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001647#endif /* CONFIG_WNM */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001648 case WLAN_ACTION_PUBLIC:
Dmitry Shmidt18463232014-01-24 12:29:41 -08001649 case WLAN_ACTION_PROTECTED_DUAL:
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001650 if (hapd->public_action_cb) {
1651 hapd->public_action_cb(hapd->public_action_cb_ctx,
1652 (u8 *) mgmt, len,
1653 hapd->iface->freq);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001654 }
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001655 if (hapd->public_action_cb2) {
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001656 hapd->public_action_cb2(hapd->public_action_cb2_ctx,
Dmitry Shmidt4b9d52f2013-02-05 17:44:43 -08001657 (u8 *) mgmt, len,
1658 hapd->iface->freq);
1659 }
1660 if (hapd->public_action_cb || hapd->public_action_cb2)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001661 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001662 break;
1663 case WLAN_ACTION_VENDOR_SPECIFIC:
1664 if (hapd->vendor_action_cb) {
1665 if (hapd->vendor_action_cb(hapd->vendor_action_cb_ctx,
1666 (u8 *) mgmt, len,
1667 hapd->iface->freq) == 0)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001668 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001669 }
1670 break;
1671 }
1672
1673 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1674 HOSTAPD_LEVEL_DEBUG,
1675 "handle_action - unknown action category %d or invalid "
1676 "frame",
1677 mgmt->u.action.category);
1678 if (!(mgmt->da[0] & 0x01) && !(mgmt->u.action.category & 0x80) &&
1679 !(mgmt->sa[0] & 0x01)) {
1680 struct ieee80211_mgmt *resp;
1681
1682 /*
1683 * IEEE 802.11-REVma/D9.0 - 7.3.1.11
1684 * Return the Action frame to the source without change
1685 * except that MSB of the Category set to 1.
1686 */
1687 wpa_printf(MSG_DEBUG, "IEEE 802.11: Return unknown Action "
1688 "frame back to sender");
1689 resp = os_malloc(len);
1690 if (resp == NULL)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001691 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001692 os_memcpy(resp, mgmt, len);
1693 os_memcpy(resp->da, resp->sa, ETH_ALEN);
1694 os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN);
1695 os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN);
1696 resp->u.action.category |= 0x80;
1697
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001698 if (hostapd_drv_send_mlme(hapd, resp, len, 0) < 0) {
1699 wpa_printf(MSG_ERROR, "IEEE 802.11: Failed to send "
1700 "Action frame");
1701 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001702 os_free(resp);
1703 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001704
1705 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001706}
1707
1708
1709/**
1710 * ieee802_11_mgmt - process incoming IEEE 802.11 management frames
1711 * @hapd: hostapd BSS data structure (the BSS to which the management frame was
1712 * sent to)
1713 * @buf: management frame data (starting from IEEE 802.11 header)
1714 * @len: length of frame data in octets
1715 * @fi: meta data about received frame (signal level, etc.)
1716 *
1717 * Process all incoming IEEE 802.11 management frames. This will be called for
1718 * each frame received from the kernel driver through wlan#ap interface. In
1719 * addition, it can be called to re-inserted pending frames (e.g., when using
1720 * external RADIUS server as an MAC ACL).
1721 */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001722int ieee802_11_mgmt(struct hostapd_data *hapd, const u8 *buf, size_t len,
1723 struct hostapd_frame_info *fi)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001724{
1725 struct ieee80211_mgmt *mgmt;
1726 int broadcast;
1727 u16 fc, stype;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001728 int ret = 0;
1729
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001730 if (len < 24)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001731 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001732
1733 mgmt = (struct ieee80211_mgmt *) buf;
1734 fc = le_to_host16(mgmt->frame_control);
1735 stype = WLAN_FC_GET_STYPE(fc);
1736
1737 if (stype == WLAN_FC_STYPE_BEACON) {
1738 handle_beacon(hapd, mgmt, len, fi);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001739 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001740 }
1741
1742 broadcast = mgmt->bssid[0] == 0xff && mgmt->bssid[1] == 0xff &&
1743 mgmt->bssid[2] == 0xff && mgmt->bssid[3] == 0xff &&
1744 mgmt->bssid[4] == 0xff && mgmt->bssid[5] == 0xff;
1745
1746 if (!broadcast &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001747#ifdef CONFIG_P2P
1748 /* Invitation responses can be sent with the peer MAC as BSSID */
1749 !((hapd->conf->p2p & P2P_GROUP_OWNER) &&
1750 stype == WLAN_FC_STYPE_ACTION) &&
1751#endif /* CONFIG_P2P */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001752 os_memcmp(mgmt->bssid, hapd->own_addr, ETH_ALEN) != 0) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001753 wpa_printf(MSG_INFO, "MGMT: BSSID=" MACSTR " not our address",
1754 MAC2STR(mgmt->bssid));
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001755 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001756 }
1757
1758
1759 if (stype == WLAN_FC_STYPE_PROBE_REQ) {
Dmitry Shmidt04949592012-07-19 12:16:46 -07001760 handle_probe_req(hapd, mgmt, len, fi->ssi_signal);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001761 return 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001762 }
1763
1764 if (os_memcmp(mgmt->da, hapd->own_addr, ETH_ALEN) != 0) {
1765 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1766 HOSTAPD_LEVEL_DEBUG,
1767 "MGMT: DA=" MACSTR " not our address",
1768 MAC2STR(mgmt->da));
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001769 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001770 }
1771
1772 switch (stype) {
1773 case WLAN_FC_STYPE_AUTH:
1774 wpa_printf(MSG_DEBUG, "mgmt::auth");
1775 handle_auth(hapd, mgmt, len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001776 ret = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001777 break;
1778 case WLAN_FC_STYPE_ASSOC_REQ:
1779 wpa_printf(MSG_DEBUG, "mgmt::assoc_req");
1780 handle_assoc(hapd, mgmt, len, 0);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001781 ret = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001782 break;
1783 case WLAN_FC_STYPE_REASSOC_REQ:
1784 wpa_printf(MSG_DEBUG, "mgmt::reassoc_req");
1785 handle_assoc(hapd, mgmt, len, 1);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001786 ret = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001787 break;
1788 case WLAN_FC_STYPE_DISASSOC:
1789 wpa_printf(MSG_DEBUG, "mgmt::disassoc");
1790 handle_disassoc(hapd, mgmt, len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001791 ret = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001792 break;
1793 case WLAN_FC_STYPE_DEAUTH:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001794 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "mgmt::deauth");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001795 handle_deauth(hapd, mgmt, len);
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001796 ret = 1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001797 break;
1798 case WLAN_FC_STYPE_ACTION:
1799 wpa_printf(MSG_DEBUG, "mgmt::action");
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001800 ret = handle_action(hapd, mgmt, len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001801 break;
1802 default:
1803 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
1804 HOSTAPD_LEVEL_DEBUG,
1805 "unknown mgmt frame subtype %d", stype);
1806 break;
1807 }
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001808
1809 return ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001810}
1811
1812
1813static void handle_auth_cb(struct hostapd_data *hapd,
1814 const struct ieee80211_mgmt *mgmt,
1815 size_t len, int ok)
1816{
1817 u16 auth_alg, auth_transaction, status_code;
1818 struct sta_info *sta;
1819
1820 if (!ok) {
1821 hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
1822 HOSTAPD_LEVEL_NOTICE,
1823 "did not acknowledge authentication response");
1824 return;
1825 }
1826
1827 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001828 wpa_printf(MSG_INFO, "handle_auth_cb - too short payload (len=%lu)",
1829 (unsigned long) len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001830 return;
1831 }
1832
1833 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
1834 auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
1835 status_code = le_to_host16(mgmt->u.auth.status_code);
1836
1837 sta = ap_get_sta(hapd, mgmt->da);
1838 if (!sta) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001839 wpa_printf(MSG_INFO, "handle_auth_cb: STA " MACSTR " not found",
1840 MAC2STR(mgmt->da));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001841 return;
1842 }
1843
1844 if (status_code == WLAN_STATUS_SUCCESS &&
1845 ((auth_alg == WLAN_AUTH_OPEN && auth_transaction == 2) ||
1846 (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 4))) {
1847 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1848 HOSTAPD_LEVEL_INFO, "authenticated");
1849 sta->flags |= WLAN_STA_AUTH;
1850 }
1851}
1852
1853
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07001854static void hostapd_set_wds_encryption(struct hostapd_data *hapd,
1855 struct sta_info *sta,
1856 char *ifname_wds)
1857{
1858 int i;
1859 struct hostapd_ssid *ssid = sta->ssid;
1860
1861 if (hapd->conf->ieee802_1x || hapd->conf->wpa)
1862 return;
1863
1864 for (i = 0; i < 4; i++) {
1865 if (ssid->wep.key[i] &&
1866 hostapd_drv_set_key(ifname_wds, hapd, WPA_ALG_WEP, NULL, i,
1867 i == ssid->wep.idx, NULL, 0,
1868 ssid->wep.key[i], ssid->wep.len[i])) {
1869 wpa_printf(MSG_WARNING,
1870 "Could not set WEP keys for WDS interface; %s",
1871 ifname_wds);
1872 break;
1873 }
1874 }
1875}
1876
1877
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001878static void handle_assoc_cb(struct hostapd_data *hapd,
1879 const struct ieee80211_mgmt *mgmt,
1880 size_t len, int reassoc, int ok)
1881{
1882 u16 status;
1883 struct sta_info *sta;
1884 int new_assoc = 1;
1885 struct ieee80211_ht_capabilities ht_cap;
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001886 struct ieee80211_vht_capabilities vht_cap;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001887
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001888 if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_resp) :
1889 sizeof(mgmt->u.assoc_resp))) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001890 wpa_printf(MSG_INFO, "handle_assoc_cb(reassoc=%d) - too short payload (len=%lu)",
1891 reassoc, (unsigned long) len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001892 return;
1893 }
1894
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001895 sta = ap_get_sta(hapd, mgmt->da);
1896 if (!sta) {
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001897 wpa_printf(MSG_INFO, "handle_assoc_cb: STA " MACSTR " not found",
1898 MAC2STR(mgmt->da));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001899 return;
1900 }
1901
Dmitry Shmidtaa532512012-09-24 10:35:31 -07001902 if (!ok) {
1903 hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
1904 HOSTAPD_LEVEL_DEBUG,
1905 "did not acknowledge association response");
1906 sta->flags &= ~WLAN_STA_ASSOC_REQ_OK;
1907 return;
1908 }
1909
1910 if (reassoc)
1911 status = le_to_host16(mgmt->u.reassoc_resp.status_code);
1912 else
1913 status = le_to_host16(mgmt->u.assoc_resp.status_code);
1914
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001915 if (status != WLAN_STATUS_SUCCESS)
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07001916 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001917
1918 /* Stop previous accounting session, if one is started, and allocate
1919 * new session id for the new session. */
1920 accounting_sta_stop(hapd, sta);
1921
1922 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1923 HOSTAPD_LEVEL_INFO,
1924 "associated (aid %d)",
1925 sta->aid);
1926
1927 if (sta->flags & WLAN_STA_ASSOC)
1928 new_assoc = 0;
1929 sta->flags |= WLAN_STA_ASSOC;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001930 sta->flags &= ~WLAN_STA_WNM_SLEEP_MODE;
Dmitry Shmidtf21452a2014-02-26 10:55:25 -08001931 if ((!hapd->conf->ieee802_1x && !hapd->conf->wpa && !hapd->conf->osen) ||
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001932 sta->auth_alg == WLAN_AUTH_FT) {
1933 /*
1934 * Open, static WEP, or FT protocol; no separate authorization
1935 * step.
1936 */
1937 ap_sta_set_authorized(hapd, sta, 1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001938 }
1939
1940 if (reassoc)
1941 mlme_reassociate_indication(hapd, sta);
1942 else
1943 mlme_associate_indication(hapd, sta);
1944
1945#ifdef CONFIG_IEEE80211W
1946 sta->sa_query_timed_out = 0;
1947#endif /* CONFIG_IEEE80211W */
1948
1949 /*
1950 * Remove the STA entry in order to make sure the STA PS state gets
1951 * cleared and configuration gets updated in case of reassociation back
1952 * to the same AP.
1953 */
1954 hostapd_drv_sta_remove(hapd, sta->addr);
1955
1956#ifdef CONFIG_IEEE80211N
1957 if (sta->flags & WLAN_STA_HT)
1958 hostapd_get_ht_capab(hapd, sta->ht_capabilities, &ht_cap);
1959#endif /* CONFIG_IEEE80211N */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001960#ifdef CONFIG_IEEE80211AC
1961 if (sta->flags & WLAN_STA_VHT)
1962 hostapd_get_vht_capab(hapd, sta->vht_capabilities, &vht_cap);
1963#endif /* CONFIG_IEEE80211AC */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001964
1965 if (hostapd_sta_add(hapd, sta->addr, sta->aid, sta->capability,
1966 sta->supported_rates, sta->supported_rates_len,
1967 sta->listen_interval,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001968 sta->flags & WLAN_STA_HT ? &ht_cap : NULL,
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -08001969 sta->flags & WLAN_STA_VHT ? &vht_cap : NULL,
Dmitry Shmidtbd14a572014-02-18 10:33:49 -08001970 sta->flags, sta->qosinfo, sta->vht_opmode)) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001971 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1972 HOSTAPD_LEVEL_NOTICE,
1973 "Could not add STA to kernel driver");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001974
1975 ap_sta_disconnect(hapd, sta, sta->addr,
1976 WLAN_REASON_DISASSOC_AP_BUSY);
1977
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07001978 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001979 }
1980
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07001981 if (sta->flags & WLAN_STA_WDS) {
1982 int ret;
1983 char ifname_wds[IFNAMSIZ + 1];
1984
1985 ret = hostapd_set_wds_sta(hapd, ifname_wds, sta->addr,
1986 sta->aid, 1);
1987 if (!ret)
1988 hostapd_set_wds_encryption(hapd, sta, ifname_wds);
1989 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001990
1991 if (sta->eapol_sm == NULL) {
1992 /*
1993 * This STA does not use RADIUS server for EAP authentication,
1994 * so bind it to the selected VLAN interface now, since the
1995 * interface selection is not going to change anymore.
1996 */
1997 if (ap_sta_bind_vlan(hapd, sta, 0) < 0)
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07001998 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001999 } else if (sta->vlan_id) {
2000 /* VLAN ID already set (e.g., by PMKSA caching), so bind STA */
2001 if (ap_sta_bind_vlan(hapd, sta, 0) < 0)
Dmitry Shmidtb36ed7c2014-03-17 10:57:26 -07002002 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002003 }
2004
2005 hostapd_set_sta_flags(hapd, sta);
2006
2007 if (sta->auth_alg == WLAN_AUTH_FT)
2008 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FT);
2009 else
2010 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC);
2011 hapd->new_assoc_sta_cb(hapd, sta, !new_assoc);
2012
2013 ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002014}
2015
2016
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002017static void handle_deauth_cb(struct hostapd_data *hapd,
2018 const struct ieee80211_mgmt *mgmt,
2019 size_t len, int ok)
2020{
2021 struct sta_info *sta;
2022 if (mgmt->da[0] & 0x01)
2023 return;
2024 sta = ap_get_sta(hapd, mgmt->da);
2025 if (!sta) {
2026 wpa_printf(MSG_DEBUG, "handle_deauth_cb: STA " MACSTR
2027 " not found", MAC2STR(mgmt->da));
2028 return;
2029 }
2030 if (ok)
2031 wpa_printf(MSG_DEBUG, "STA " MACSTR " acknowledged deauth",
2032 MAC2STR(sta->addr));
2033 else
2034 wpa_printf(MSG_DEBUG, "STA " MACSTR " did not acknowledge "
2035 "deauth", MAC2STR(sta->addr));
2036
2037 ap_sta_deauth_cb(hapd, sta);
2038}
2039
2040
2041static void handle_disassoc_cb(struct hostapd_data *hapd,
2042 const struct ieee80211_mgmt *mgmt,
2043 size_t len, int ok)
2044{
2045 struct sta_info *sta;
2046 if (mgmt->da[0] & 0x01)
2047 return;
2048 sta = ap_get_sta(hapd, mgmt->da);
2049 if (!sta) {
2050 wpa_printf(MSG_DEBUG, "handle_disassoc_cb: STA " MACSTR
2051 " not found", MAC2STR(mgmt->da));
2052 return;
2053 }
2054 if (ok)
2055 wpa_printf(MSG_DEBUG, "STA " MACSTR " acknowledged disassoc",
2056 MAC2STR(sta->addr));
2057 else
2058 wpa_printf(MSG_DEBUG, "STA " MACSTR " did not acknowledge "
2059 "disassoc", MAC2STR(sta->addr));
2060
2061 ap_sta_disassoc_cb(hapd, sta);
2062}
2063
2064
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002065/**
2066 * ieee802_11_mgmt_cb - Process management frame TX status callback
2067 * @hapd: hostapd BSS data structure (the BSS from which the management frame
2068 * was sent from)
2069 * @buf: management frame data (starting from IEEE 802.11 header)
2070 * @len: length of frame data in octets
2071 * @stype: management frame subtype from frame control field
2072 * @ok: Whether the frame was ACK'ed
2073 */
2074void ieee802_11_mgmt_cb(struct hostapd_data *hapd, const u8 *buf, size_t len,
2075 u16 stype, int ok)
2076{
2077 const struct ieee80211_mgmt *mgmt;
2078 mgmt = (const struct ieee80211_mgmt *) buf;
2079
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08002080#ifdef CONFIG_TESTING_OPTIONS
2081 if (hapd->ext_mgmt_frame_handling) {
2082 wpa_msg(hapd->msg_ctx, MSG_INFO, "MGMT-TX-STATUS stype=%u ok=%d",
2083 stype, ok);
2084 return;
2085 }
2086#endif /* CONFIG_TESTING_OPTIONS */
2087
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002088 switch (stype) {
2089 case WLAN_FC_STYPE_AUTH:
2090 wpa_printf(MSG_DEBUG, "mgmt::auth cb");
2091 handle_auth_cb(hapd, mgmt, len, ok);
2092 break;
2093 case WLAN_FC_STYPE_ASSOC_RESP:
2094 wpa_printf(MSG_DEBUG, "mgmt::assoc_resp cb");
2095 handle_assoc_cb(hapd, mgmt, len, 0, ok);
2096 break;
2097 case WLAN_FC_STYPE_REASSOC_RESP:
2098 wpa_printf(MSG_DEBUG, "mgmt::reassoc_resp cb");
2099 handle_assoc_cb(hapd, mgmt, len, 1, ok);
2100 break;
2101 case WLAN_FC_STYPE_PROBE_RESP:
2102 wpa_printf(MSG_EXCESSIVE, "mgmt::proberesp cb");
2103 break;
2104 case WLAN_FC_STYPE_DEAUTH:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002105 wpa_printf(MSG_DEBUG, "mgmt::deauth cb");
2106 handle_deauth_cb(hapd, mgmt, len, ok);
2107 break;
2108 case WLAN_FC_STYPE_DISASSOC:
2109 wpa_printf(MSG_DEBUG, "mgmt::disassoc cb");
2110 handle_disassoc_cb(hapd, mgmt, len, ok);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002111 break;
2112 case WLAN_FC_STYPE_ACTION:
2113 wpa_printf(MSG_DEBUG, "mgmt::action cb");
2114 break;
2115 default:
Dmitry Shmidtcce06662013-11-04 18:44:24 -08002116 wpa_printf(MSG_INFO, "unknown mgmt cb frame subtype %d", stype);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002117 break;
2118 }
2119}
2120
2121
2122int ieee802_11_get_mib(struct hostapd_data *hapd, char *buf, size_t buflen)
2123{
2124 /* TODO */
2125 return 0;
2126}
2127
2128
2129int ieee802_11_get_mib_sta(struct hostapd_data *hapd, struct sta_info *sta,
2130 char *buf, size_t buflen)
2131{
2132 /* TODO */
2133 return 0;
2134}
2135
2136
2137void hostapd_tx_status(struct hostapd_data *hapd, const u8 *addr,
2138 const u8 *buf, size_t len, int ack)
2139{
2140 struct sta_info *sta;
2141 struct hostapd_iface *iface = hapd->iface;
2142
2143 sta = ap_get_sta(hapd, addr);
2144 if (sta == NULL && iface->num_bss > 1) {
2145 size_t j;
2146 for (j = 0; j < iface->num_bss; j++) {
2147 hapd = iface->bss[j];
2148 sta = ap_get_sta(hapd, addr);
2149 if (sta)
2150 break;
2151 }
2152 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002153 if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC))
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002154 return;
2155 if (sta->flags & WLAN_STA_PENDING_POLL) {
2156 wpa_printf(MSG_DEBUG, "STA " MACSTR " %s pending "
2157 "activity poll", MAC2STR(sta->addr),
2158 ack ? "ACKed" : "did not ACK");
2159 if (ack)
2160 sta->flags &= ~WLAN_STA_PENDING_POLL;
2161 }
2162
2163 ieee802_1x_tx_status(hapd, sta, buf, len, ack);
2164}
2165
2166
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002167void hostapd_eapol_tx_status(struct hostapd_data *hapd, const u8 *dst,
2168 const u8 *data, size_t len, int ack)
2169{
2170 struct sta_info *sta;
2171 struct hostapd_iface *iface = hapd->iface;
2172
2173 sta = ap_get_sta(hapd, dst);
2174 if (sta == NULL && iface->num_bss > 1) {
2175 size_t j;
2176 for (j = 0; j < iface->num_bss; j++) {
2177 hapd = iface->bss[j];
2178 sta = ap_get_sta(hapd, dst);
2179 if (sta)
2180 break;
2181 }
2182 }
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002183 if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC)) {
2184 wpa_printf(MSG_DEBUG, "Ignore TX status for Data frame to STA "
2185 MACSTR " that is not currently associated",
2186 MAC2STR(dst));
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002187 return;
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08002188 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08002189
2190 ieee802_1x_eapol_tx_status(hapd, sta, data, len, ack);
2191}
2192
2193
2194void hostapd_client_poll_ok(struct hostapd_data *hapd, const u8 *addr)
2195{
2196 struct sta_info *sta;
2197 struct hostapd_iface *iface = hapd->iface;
2198
2199 sta = ap_get_sta(hapd, addr);
2200 if (sta == NULL && iface->num_bss > 1) {
2201 size_t j;
2202 for (j = 0; j < iface->num_bss; j++) {
2203 hapd = iface->bss[j];
2204 sta = ap_get_sta(hapd, addr);
2205 if (sta)
2206 break;
2207 }
2208 }
2209 if (sta == NULL)
2210 return;
2211 if (!(sta->flags & WLAN_STA_PENDING_POLL))
2212 return;
2213
2214 wpa_printf(MSG_DEBUG, "STA " MACSTR " ACKed pending "
2215 "activity poll", MAC2STR(sta->addr));
2216 sta->flags &= ~WLAN_STA_PENDING_POLL;
2217}
2218
2219
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002220void ieee802_11_rx_from_unknown(struct hostapd_data *hapd, const u8 *src,
2221 int wds)
2222{
2223 struct sta_info *sta;
2224
2225 sta = ap_get_sta(hapd, src);
2226 if (sta && (sta->flags & WLAN_STA_ASSOC)) {
Dmitry Shmidtaa532512012-09-24 10:35:31 -07002227 if (!hapd->conf->wds_sta)
2228 return;
2229
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002230 if (wds && !(sta->flags & WLAN_STA_WDS)) {
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002231 int ret;
2232 char ifname_wds[IFNAMSIZ + 1];
2233
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002234 wpa_printf(MSG_DEBUG, "Enable 4-address WDS mode for "
2235 "STA " MACSTR " (aid %u)",
2236 MAC2STR(sta->addr), sta->aid);
2237 sta->flags |= WLAN_STA_WDS;
Dmitry Shmidtc2ebb4b2013-07-24 12:57:51 -07002238 ret = hostapd_set_wds_sta(hapd, ifname_wds,
2239 sta->addr, sta->aid, 1);
2240 if (!ret)
2241 hostapd_set_wds_encryption(hapd, sta,
2242 ifname_wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002243 }
2244 return;
2245 }
2246
2247 wpa_printf(MSG_DEBUG, "Data/PS-poll frame from not associated STA "
2248 MACSTR, MAC2STR(src));
2249 if (src[0] & 0x01) {
2250 /* Broadcast bit set in SA?! Ignore the frame silently. */
2251 return;
2252 }
2253
2254 if (sta && (sta->flags & WLAN_STA_ASSOC_REQ_OK)) {
2255 wpa_printf(MSG_DEBUG, "Association Response to the STA has "
2256 "already been sent, but no TX status yet known - "
2257 "ignore Class 3 frame issue with " MACSTR,
2258 MAC2STR(src));
2259 return;
2260 }
2261
2262 if (sta && (sta->flags & WLAN_STA_AUTH))
2263 hostapd_drv_sta_disassoc(
2264 hapd, src,
2265 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
2266 else
2267 hostapd_drv_sta_deauth(
2268 hapd, src,
2269 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
2270}
2271
2272
2273#endif /* CONFIG_NATIVE_WINDOWS */