]> git.ipfire.org Git - thirdparty/hostap.git/blame - src/ap/ieee802_11.c
Add POLL_STA command to check connectivity in AP mode
[thirdparty/hostap.git] / src / ap / ieee802_11.c
CommitLineData
6fc6879b
JM
1/*
2 * hostapd / IEEE 802.11 Management
f2991170 3 * Copyright (c) 2002-2014, Jouni Malinen <j@w1.fi>
6fc6879b 4 *
0f3d578e
JM
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
6fc6879b
JM
7 */
8
1057d78e 9#include "utils/includes.h"
6fc6879b
JM
10
11#ifndef CONFIG_NATIVE_WINDOWS
12
1057d78e
JM
13#include "utils/common.h"
14#include "utils/eloop.h"
03da66bd 15#include "crypto/crypto.h"
d136c376
JM
16#include "crypto/sha256.h"
17#include "crypto/random.h"
81f4f619
JM
18#include "common/ieee802_11_defs.h"
19#include "common/ieee802_11_common.h"
03da66bd 20#include "common/wpa_ctrl.h"
98efcc41 21#include "common/sae.h"
03da66bd
JM
22#include "radius/radius.h"
23#include "radius/radius_client.h"
e44f8bf2 24#include "p2p/p2p.h"
ed7a09f9 25#include "wps/wps.h"
037378ff 26#include "fst/fst.h"
6fc6879b 27#include "hostapd.h"
6fc6879b 28#include "beacon.h"
6fc6879b
JM
29#include "ieee802_11_auth.h"
30#include "sta_info.h"
6fc6879b 31#include "ieee802_1x.h"
6226e38d 32#include "wpa_auth.h"
f2991170 33#include "pmksa_cache_auth.h"
1057d78e 34#include "wmm.h"
6fc6879b
JM
35#include "ap_list.h"
36#include "accounting.h"
6226e38d
JM
37#include "ap_config.h"
38#include "ap_mlme.h"
dce044cc 39#include "p2p_hostapd.h"
cee7d66b 40#include "ap_drv_ops.h"
c79938a5 41#include "wnm_ap.h"
0e2412d0 42#include "hw_features.h"
6226e38d 43#include "ieee802_11.h"
3d7ad2f6 44#include "dfs.h"
6332aaf3 45#include "mbo_ap.h"
6fc6879b
JM
46
47
48u8 * hostapd_eid_supp_rates(struct hostapd_data *hapd, u8 *eid)
49{
50 u8 *pos = eid;
51 int i, num, count;
52
53 if (hapd->iface->current_rates == NULL)
54 return eid;
55
56 *pos++ = WLAN_EID_SUPP_RATES;
57 num = hapd->iface->num_rates;
29448243
JM
58 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht)
59 num++;
202d97d4
JB
60 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht)
61 num++;
6fc6879b
JM
62 if (num > 8) {
63 /* rest of the rates are encoded in Extended supported
64 * rates element */
65 num = 8;
66 }
67
68 *pos++ = num;
6fc6879b
JM
69 for (i = 0, count = 0; i < hapd->iface->num_rates && count < num;
70 i++) {
71 count++;
72 *pos = hapd->iface->current_rates[i].rate / 5;
73 if (hapd->iface->current_rates[i].flags & HOSTAPD_RATE_BASIC)
74 *pos |= 0x80;
75 pos++;
76 }
77
202d97d4
JB
78 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht && count < 8) {
79 count++;
29448243 80 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY;
202d97d4
JB
81 }
82
83 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht && count < 8) {
84 count++;
85 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY;
86 }
29448243 87
6fc6879b
JM
88 return pos;
89}
90
91
92u8 * hostapd_eid_ext_supp_rates(struct hostapd_data *hapd, u8 *eid)
93{
94 u8 *pos = eid;
95 int i, num, count;
96
97 if (hapd->iface->current_rates == NULL)
98 return eid;
99
100 num = hapd->iface->num_rates;
29448243
JM
101 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht)
102 num++;
202d97d4
JB
103 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht)
104 num++;
6fc6879b
JM
105 if (num <= 8)
106 return eid;
107 num -= 8;
108
109 *pos++ = WLAN_EID_EXT_SUPP_RATES;
110 *pos++ = num;
6fc6879b
JM
111 for (i = 0, count = 0; i < hapd->iface->num_rates && count < num + 8;
112 i++) {
113 count++;
114 if (count <= 8)
115 continue; /* already in SuppRates IE */
116 *pos = hapd->iface->current_rates[i].rate / 5;
117 if (hapd->iface->current_rates[i].flags & HOSTAPD_RATE_BASIC)
118 *pos |= 0x80;
119 pos++;
120 }
121
202d97d4
JB
122 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht) {
123 count++;
124 if (count > 8)
125 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY;
126 }
127
128 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht) {
129 count++;
130 if (count > 8)
131 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY;
132 }
29448243 133
6fc6879b
JM
134 return pos;
135}
136
137
f41ded6f 138u16 hostapd_own_capab_info(struct hostapd_data *hapd)
6fc6879b
JM
139{
140 int capab = WLAN_CAPABILITY_ESS;
141 int privacy;
3d7ad2f6
C
142 int dfs;
143
144 /* Check if any of configured channels require DFS */
145 dfs = hostapd_is_dfs_required(hapd->iface);
146 if (dfs < 0) {
147 wpa_printf(MSG_WARNING, "Failed to check if DFS is required; ret=%d",
148 dfs);
149 dfs = 0;
150 }
6fc6879b
JM
151
152 if (hapd->iface->num_sta_no_short_preamble == 0 &&
153 hapd->iconf->preamble == SHORT_PREAMBLE)
154 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
155
156 privacy = hapd->conf->ssid.wep.keys_set;
157
158 if (hapd->conf->ieee802_1x &&
159 (hapd->conf->default_wep_key_len ||
160 hapd->conf->individual_wep_key_len))
161 privacy = 1;
162
163 if (hapd->conf->wpa)
164 privacy = 1;
165
a14896e8
JM
166#ifdef CONFIG_HS20
167 if (hapd->conf->osen)
168 privacy = 1;
169#endif /* CONFIG_HS20 */
170
6fc6879b
JM
171 if (privacy)
172 capab |= WLAN_CAPABILITY_PRIVACY;
173
174 if (hapd->iface->current_mode &&
175 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G &&
176 hapd->iface->num_sta_no_short_slot_time == 0)
177 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
178
3d7ad2f6
C
179 /*
180 * Currently, Spectrum Management capability bit is set when directly
181 * requested in configuration by spectrum_mgmt_required or when AP is
182 * running on DFS channel.
183 * TODO: Also consider driver support for TPC to set Spectrum Mgmt bit
184 */
185 if (hapd->iface->current_mode &&
186 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211A &&
187 (hapd->iconf->spectrum_mgmt_required || dfs))
188 capab |= WLAN_CAPABILITY_SPECTRUM_MGMT;
189
0629eeb4
JM
190 if (hapd->conf->radio_measurements)
191 capab |= IEEE80211_CAP_RRM;
192
6fc6879b
JM
193 return capab;
194}
195
196
7cb53ded 197#ifndef CONFIG_NO_RC4
6fc6879b 198static u16 auth_shared_key(struct hostapd_data *hapd, struct sta_info *sta,
b57e086c
JM
199 u16 auth_transaction, const u8 *challenge,
200 int iswep)
6fc6879b
JM
201{
202 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
203 HOSTAPD_LEVEL_DEBUG,
204 "authentication (shared key, transaction %d)",
205 auth_transaction);
206
207 if (auth_transaction == 1) {
208 if (!sta->challenge) {
209 /* Generate a pseudo-random challenge */
210 u8 key[8];
f441e5af 211
6fc6879b
JM
212 sta->challenge = os_zalloc(WLAN_AUTH_CHALLENGE_LEN);
213 if (sta->challenge == NULL)
214 return WLAN_STATUS_UNSPECIFIED_FAILURE;
215
f441e5af
NL
216 if (os_get_random(key, sizeof(key)) < 0) {
217 os_free(sta->challenge);
218 sta->challenge = NULL;
219 return WLAN_STATUS_UNSPECIFIED_FAILURE;
220 }
221
8ef16831
JM
222 rc4_skip(key, sizeof(key), 0,
223 sta->challenge, WLAN_AUTH_CHALLENGE_LEN);
6fc6879b
JM
224 }
225 return 0;
226 }
227
228 if (auth_transaction != 3)
229 return WLAN_STATUS_UNSPECIFIED_FAILURE;
230
231 /* Transaction 3 */
232 if (!iswep || !sta->challenge || !challenge ||
34ef46ce
JM
233 os_memcmp_const(sta->challenge, challenge,
234 WLAN_AUTH_CHALLENGE_LEN)) {
6fc6879b
JM
235 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
236 HOSTAPD_LEVEL_INFO,
237 "shared key authentication - invalid "
238 "challenge-response");
239 return WLAN_STATUS_CHALLENGE_FAIL;
240 }
241
242 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
243 HOSTAPD_LEVEL_DEBUG,
244 "authentication OK (shared key)");
6fc6879b
JM
245 sta->flags |= WLAN_STA_AUTH;
246 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
6fc6879b
JM
247 os_free(sta->challenge);
248 sta->challenge = NULL;
249
250 return 0;
251}
7cb53ded 252#endif /* CONFIG_NO_RC4 */
6fc6879b
JM
253
254
bb598c3b
AB
255static int send_auth_reply(struct hostapd_data *hapd,
256 const u8 *dst, const u8 *bssid,
257 u16 auth_alg, u16 auth_transaction, u16 resp,
258 const u8 *ies, size_t ies_len)
6fc6879b
JM
259{
260 struct ieee80211_mgmt *reply;
261 u8 *buf;
262 size_t rlen;
bb598c3b 263 int reply_res = WLAN_STATUS_UNSPECIFIED_FAILURE;
6fc6879b
JM
264
265 rlen = IEEE80211_HDRLEN + sizeof(reply->u.auth) + ies_len;
266 buf = os_zalloc(rlen);
267 if (buf == NULL)
bb598c3b 268 return -1;
6fc6879b
JM
269
270 reply = (struct ieee80211_mgmt *) buf;
271 reply->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
272 WLAN_FC_STYPE_AUTH);
6fc6879b
JM
273 os_memcpy(reply->da, dst, ETH_ALEN);
274 os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN);
275 os_memcpy(reply->bssid, bssid, ETH_ALEN);
276
277 reply->u.auth.auth_alg = host_to_le16(auth_alg);
278 reply->u.auth.auth_transaction = host_to_le16(auth_transaction);
279 reply->u.auth.status_code = host_to_le16(resp);
280
281 if (ies && ies_len)
282 os_memcpy(reply->u.auth.variable, ies, ies_len);
283
284 wpa_printf(MSG_DEBUG, "authentication reply: STA=" MACSTR
285 " auth_alg=%d auth_transaction=%d resp=%d (IE len=%lu)",
286 MAC2STR(dst), auth_alg, auth_transaction,
287 resp, (unsigned long) ies_len);
8cfa3527 288 if (hostapd_drv_send_mlme(hapd, reply, rlen, 0) < 0)
bb598c3b
AB
289 wpa_printf(MSG_INFO, "send_auth_reply: send failed");
290 else
291 reply_res = WLAN_STATUS_SUCCESS;
6fc6879b
JM
292
293 os_free(buf);
bb598c3b
AB
294
295 return reply_res;
6fc6879b
JM
296}
297
298
299#ifdef CONFIG_IEEE80211R
300static void handle_auth_ft_finish(void *ctx, const u8 *dst, const u8 *bssid,
301 u16 auth_transaction, u16 status,
302 const u8 *ies, size_t ies_len)
303{
304 struct hostapd_data *hapd = ctx;
305 struct sta_info *sta;
bb598c3b 306 int reply_res;
6fc6879b 307
bb598c3b
AB
308 reply_res = send_auth_reply(hapd, dst, bssid, WLAN_AUTH_FT,
309 auth_transaction, status, ies, ies_len);
6fc6879b
JM
310
311 sta = ap_get_sta(hapd, dst);
312 if (sta == NULL)
313 return;
314
bb598c3b
AB
315 if (sta->added_unassoc && (reply_res != WLAN_STATUS_SUCCESS ||
316 status != WLAN_STATUS_SUCCESS)) {
317 hostapd_drv_sta_remove(hapd, sta->addr);
318 sta->added_unassoc = 0;
319 return;
320 }
321
322 if (status != WLAN_STATUS_SUCCESS)
323 return;
324
6fc6879b
JM
325 hostapd_logger(hapd, dst, HOSTAPD_MODULE_IEEE80211,
326 HOSTAPD_LEVEL_DEBUG, "authentication OK (FT)");
327 sta->flags |= WLAN_STA_AUTH;
328 mlme_authenticate_indication(hapd, sta);
329}
330#endif /* CONFIG_IEEE80211R */
331
332
c10347f2 333#ifdef CONFIG_SAE
21af6d15 334
f3b8ad4d
BC
335#define dot11RSNASAESync 5 /* attempts */
336
337
e96da42b 338static struct wpabuf * auth_build_sae_commit(struct hostapd_data *hapd,
872b7545 339 struct sta_info *sta, int update)
21af6d15
JM
340{
341 struct wpabuf *buf;
342
146f6c9a
JM
343 if (hapd->conf->ssid.wpa_passphrase == NULL) {
344 wpa_printf(MSG_DEBUG, "SAE: No password available");
345 return NULL;
346 }
347
872b7545
MH
348 if (update &&
349 sae_prepare_commit(hapd->own_addr, sta->addr,
8e31e955
JM
350 (u8 *) hapd->conf->ssid.wpa_passphrase,
351 os_strlen(hapd->conf->ssid.wpa_passphrase),
352 sta->sae) < 0) {
353 wpa_printf(MSG_DEBUG, "SAE: Could not pick PWE");
21af6d15 354 return NULL;
8e31e955 355 }
21af6d15 356
8e31e955
JM
357 buf = wpabuf_alloc(SAE_COMMIT_MAX_LEN);
358 if (buf == NULL)
359 return NULL;
872b7545
MH
360 sae_write_commit(sta->sae, buf, sta->sae->tmp ?
361 sta->sae->tmp->anti_clogging_token : NULL);
21af6d15
JM
362
363 return buf;
364}
365
366
367static struct wpabuf * auth_build_sae_confirm(struct hostapd_data *hapd,
368 struct sta_info *sta)
369{
370 struct wpabuf *buf;
371
fb8fcc29 372 buf = wpabuf_alloc(SAE_CONFIRM_MAX_LEN);
21af6d15
JM
373 if (buf == NULL)
374 return NULL;
375
fb8fcc29 376 sae_write_confirm(sta->sae, buf);
21af6d15
JM
377
378 return buf;
379}
380
381
e96da42b
BC
382static int auth_sae_send_commit(struct hostapd_data *hapd,
383 struct sta_info *sta,
872b7545 384 const u8 *bssid, int update)
e96da42b
BC
385{
386 struct wpabuf *data;
bb598c3b 387 int reply_res;
e96da42b 388
872b7545 389 data = auth_build_sae_commit(hapd, sta, update);
e96da42b
BC
390 if (data == NULL)
391 return WLAN_STATUS_UNSPECIFIED_FAILURE;
392
bb598c3b
AB
393 reply_res = send_auth_reply(hapd, sta->addr, bssid, WLAN_AUTH_SAE, 1,
394 WLAN_STATUS_SUCCESS, wpabuf_head(data),
395 wpabuf_len(data));
e96da42b
BC
396
397 wpabuf_free(data);
398
bb598c3b 399 return reply_res;
e96da42b
BC
400}
401
402
403static int auth_sae_send_confirm(struct hostapd_data *hapd,
404 struct sta_info *sta,
405 const u8 *bssid)
406{
407 struct wpabuf *data;
bb598c3b 408 int reply_res;
e96da42b
BC
409
410 data = auth_build_sae_confirm(hapd, sta);
411 if (data == NULL)
412 return WLAN_STATUS_UNSPECIFIED_FAILURE;
413
bb598c3b
AB
414 reply_res = send_auth_reply(hapd, sta->addr, bssid, WLAN_AUTH_SAE, 2,
415 WLAN_STATUS_SUCCESS, wpabuf_head(data),
416 wpabuf_len(data));
e96da42b
BC
417
418 wpabuf_free(data);
419
bb598c3b 420 return reply_res;
e96da42b
BC
421}
422
423
d136c376
JM
424static int use_sae_anti_clogging(struct hostapd_data *hapd)
425{
426 struct sta_info *sta;
427 unsigned int open = 0;
428
429 if (hapd->conf->sae_anti_clogging_threshold == 0)
430 return 1;
431
432 for (sta = hapd->sta_list; sta; sta = sta->next) {
433 if (!sta->sae)
434 continue;
435 if (sta->sae->state != SAE_COMMITTED &&
436 sta->sae->state != SAE_CONFIRMED)
437 continue;
438 open++;
439 if (open >= hapd->conf->sae_anti_clogging_threshold)
440 return 1;
441 }
442
443 return 0;
444}
445
446
447static int check_sae_token(struct hostapd_data *hapd, const u8 *addr,
448 const u8 *token, size_t token_len)
449{
450 u8 mac[SHA256_MAC_LEN];
451
452 if (token_len != SHA256_MAC_LEN)
453 return -1;
454 if (hmac_sha256(hapd->sae_token_key, sizeof(hapd->sae_token_key),
455 addr, ETH_ALEN, mac) < 0 ||
0233dcac 456 os_memcmp_const(token, mac, SHA256_MAC_LEN) != 0)
d136c376
JM
457 return -1;
458
459 return 0;
460}
461
462
463static struct wpabuf * auth_build_token_req(struct hostapd_data *hapd,
a959a3b6 464 int group, const u8 *addr)
d136c376
JM
465{
466 struct wpabuf *buf;
467 u8 *token;
fe52c210 468 struct os_reltime now;
d136c376 469
fe52c210
JB
470 os_get_reltime(&now);
471 if (!os_reltime_initialized(&hapd->last_sae_token_key_update) ||
472 os_reltime_expired(&now, &hapd->last_sae_token_key_update, 60)) {
a50414c3
JM
473 if (random_get_bytes(hapd->sae_token_key,
474 sizeof(hapd->sae_token_key)) < 0)
475 return NULL;
d136c376
JM
476 wpa_hexdump(MSG_DEBUG, "SAE: Updated token key",
477 hapd->sae_token_key, sizeof(hapd->sae_token_key));
fe52c210 478 hapd->last_sae_token_key_update = now;
d136c376
JM
479 }
480
a959a3b6 481 buf = wpabuf_alloc(sizeof(le16) + SHA256_MAC_LEN);
d136c376
JM
482 if (buf == NULL)
483 return NULL;
484
a959a3b6
MH
485 wpabuf_put_le16(buf, group); /* Finite Cyclic Group */
486
d136c376
JM
487 token = wpabuf_put(buf, SHA256_MAC_LEN);
488 hmac_sha256(hapd->sae_token_key, sizeof(hapd->sae_token_key),
489 addr, ETH_ALEN, token);
490
491 return buf;
492}
493
494
f3b8ad4d
BC
495static int sae_check_big_sync(struct sta_info *sta)
496{
497 if (sta->sae->sync > dot11RSNASAESync) {
498 sta->sae->state = SAE_NOTHING;
499 sta->sae->sync = 0;
500 return -1;
501 }
502 return 0;
503}
504
505
506static void auth_sae_retransmit_timer(void *eloop_ctx, void *eloop_data)
507{
508 struct hostapd_data *hapd = eloop_ctx;
509 struct sta_info *sta = eloop_data;
510 int ret;
511
512 if (sae_check_big_sync(sta))
513 return;
514 sta->sae->sync++;
515
516 switch (sta->sae->state) {
517 case SAE_COMMITTED:
518 ret = auth_sae_send_commit(hapd, sta, hapd->own_addr, 0);
ecd40fef
MH
519 eloop_register_timeout(0,
520 hapd->dot11RSNASAERetransPeriod * 1000,
f3b8ad4d
BC
521 auth_sae_retransmit_timer, hapd, sta);
522 break;
523 case SAE_CONFIRMED:
524 ret = auth_sae_send_confirm(hapd, sta, hapd->own_addr);
ecd40fef
MH
525 eloop_register_timeout(0,
526 hapd->dot11RSNASAERetransPeriod * 1000,
f3b8ad4d
BC
527 auth_sae_retransmit_timer, hapd, sta);
528 break;
529 default:
530 ret = -1;
531 break;
532 }
533
534 if (ret != WLAN_STATUS_SUCCESS)
535 wpa_printf(MSG_INFO, "SAE: Failed to retransmit: ret=%d", ret);
536}
537
538
539void sae_clear_retransmit_timer(struct hostapd_data *hapd, struct sta_info *sta)
540{
541 eloop_cancel_timeout(auth_sae_retransmit_timer, hapd, sta);
542}
543
544
545static void sae_set_retransmit_timer(struct hostapd_data *hapd,
546 struct sta_info *sta)
547{
548 if (!(hapd->conf->mesh & MESH_ENABLED))
549 return;
550
551 eloop_cancel_timeout(auth_sae_retransmit_timer, hapd, sta);
ecd40fef 552 eloop_register_timeout(0, hapd->dot11RSNASAERetransPeriod * 1000,
f3b8ad4d
BC
553 auth_sae_retransmit_timer, hapd, sta);
554}
555
556
9f2cf23e
MH
557void sae_accept_sta(struct hostapd_data *hapd, struct sta_info *sta)
558{
559 sta->flags |= WLAN_STA_AUTH;
560 sta->auth_alg = WLAN_AUTH_SAE;
561 mlme_authenticate_indication(hapd, sta);
562 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
563 sta->sae->state = SAE_ACCEPTED;
564 wpa_auth_pmksa_add_sae(hapd->wpa_auth, sta->addr,
565 sta->sae->pmk, sta->sae->pmkid);
566}
567
568
e96da42b
BC
569static int sae_sm_step(struct hostapd_data *hapd, struct sta_info *sta,
570 const u8 *bssid, u8 auth_transaction)
571{
572 int ret;
573
574 if (auth_transaction != 1 && auth_transaction != 2)
575 return WLAN_STATUS_UNSPECIFIED_FAILURE;
576
577 switch (sta->sae->state) {
578 case SAE_NOTHING:
579 if (auth_transaction == 1) {
872b7545 580 ret = auth_sae_send_commit(hapd, sta, bssid, 1);
e96da42b
BC
581 if (ret)
582 return ret;
583 sta->sae->state = SAE_COMMITTED;
584
585 if (sae_process_commit(sta->sae) < 0)
586 return WLAN_STATUS_UNSPECIFIED_FAILURE;
587
588 /*
589 * In mesh case, both Commit and Confirm can be sent
590 * immediately. In infrastructure BSS, only a single
591 * Authentication frame (Commit) is expected from the AP
592 * here and the second one (Confirm) will be sent once
593 * the STA has sent its second Authentication frame
594 * (Confirm).
595 */
596 if (hapd->conf->mesh & MESH_ENABLED) {
597 /*
598 * Send both Commit and Confirm immediately
599 * based on SAE finite state machine
600 * Nothing -> Confirm transition.
601 */
602 ret = auth_sae_send_confirm(hapd, sta, bssid);
603 if (ret)
604 return ret;
605 sta->sae->state = SAE_CONFIRMED;
606 } else {
607 /*
608 * For infrastructure BSS, send only the Commit
609 * message now to get alternating sequence of
610 * Authentication frames between the AP and STA.
611 * Confirm will be sent in
612 * Commited -> Confirmed/Accepted transition
613 * when receiving Confirm from STA.
614 */
615 }
f3b8ad4d
BC
616 sta->sae->sync = 0;
617 sae_set_retransmit_timer(hapd, sta);
e96da42b
BC
618 } else {
619 hostapd_logger(hapd, sta->addr,
620 HOSTAPD_MODULE_IEEE80211,
621 HOSTAPD_LEVEL_DEBUG,
622 "SAE confirm before commit");
623 }
624 break;
625 case SAE_COMMITTED:
f3b8ad4d 626 sae_clear_retransmit_timer(hapd, sta);
e96da42b
BC
627 if (auth_transaction == 1) {
628 if (sae_process_commit(sta->sae) < 0)
629 return WLAN_STATUS_UNSPECIFIED_FAILURE;
630
631 ret = auth_sae_send_confirm(hapd, sta, bssid);
632 if (ret)
633 return ret;
634 sta->sae->state = SAE_CONFIRMED;
f3b8ad4d
BC
635 sta->sae->sync = 0;
636 sae_set_retransmit_timer(hapd, sta);
e96da42b
BC
637 } else if (hapd->conf->mesh & MESH_ENABLED) {
638 /*
639 * In mesh case, follow SAE finite state machine and
f3b8ad4d 640 * send Commit now, if sync count allows.
e96da42b 641 */
f3b8ad4d
BC
642 if (sae_check_big_sync(sta))
643 return WLAN_STATUS_SUCCESS;
644 sta->sae->sync++;
645
fabc6dd8 646 ret = auth_sae_send_commit(hapd, sta, bssid, 0);
e96da42b
BC
647 if (ret)
648 return ret;
f3b8ad4d
BC
649
650 sae_set_retransmit_timer(hapd, sta);
e96da42b
BC
651 } else {
652 /*
653 * For instructure BSS, send the postponed Confirm from
654 * Nothing -> Confirmed transition that was reduced to
655 * Nothing -> Committed above.
656 */
657 ret = auth_sae_send_confirm(hapd, sta, bssid);
658 if (ret)
659 return ret;
660
661 sta->sae->state = SAE_CONFIRMED;
662
663 /*
664 * Since this was triggered on Confirm RX, run another
665 * step to get to Accepted without waiting for
666 * additional events.
667 */
668 return sae_sm_step(hapd, sta, bssid, auth_transaction);
669 }
670 break;
671 case SAE_CONFIRMED:
f3b8ad4d 672 sae_clear_retransmit_timer(hapd, sta);
e96da42b 673 if (auth_transaction == 1) {
f3b8ad4d
BC
674 if (sae_check_big_sync(sta))
675 return WLAN_STATUS_SUCCESS;
676 sta->sae->sync++;
677
872b7545 678 ret = auth_sae_send_commit(hapd, sta, bssid, 1);
e96da42b
BC
679 if (ret)
680 return ret;
681
682 if (sae_process_commit(sta->sae) < 0)
683 return WLAN_STATUS_UNSPECIFIED_FAILURE;
684
685 ret = auth_sae_send_confirm(hapd, sta, bssid);
686 if (ret)
687 return ret;
f3b8ad4d
BC
688
689 sae_set_retransmit_timer(hapd, sta);
e96da42b 690 } else {
9f2cf23e 691 sae_accept_sta(hapd, sta);
e96da42b
BC
692 }
693 break;
694 case SAE_ACCEPTED:
695 if (auth_transaction == 1) {
696 wpa_printf(MSG_DEBUG, "SAE: remove the STA (" MACSTR
697 ") doing reauthentication",
698 MAC2STR(sta->addr));
699 ap_free_sta(hapd, sta);
9f2cf23e 700 wpa_auth_pmksa_remove(hapd->wpa_auth, sta->addr);
e96da42b 701 } else {
f3b8ad4d
BC
702 if (sae_check_big_sync(sta))
703 return WLAN_STATUS_SUCCESS;
704 sta->sae->sync++;
705
e96da42b
BC
706 ret = auth_sae_send_confirm(hapd, sta, bssid);
707 sae_clear_temp_data(sta->sae);
708 if (ret)
709 return ret;
710 }
711 break;
712 default:
713 wpa_printf(MSG_ERROR, "SAE: invalid state %d",
714 sta->sae->state);
715 return WLAN_STATUS_UNSPECIFIED_FAILURE;
716 }
717 return WLAN_STATUS_SUCCESS;
718}
719
720
c10347f2
JM
721static void handle_auth_sae(struct hostapd_data *hapd, struct sta_info *sta,
722 const struct ieee80211_mgmt *mgmt, size_t len,
afa2ffb4 723 u16 auth_transaction, u16 status_code)
c10347f2 724{
bb598c3b 725 int resp = WLAN_STATUS_SUCCESS;
750efe6e 726 struct wpabuf *data = NULL;
c10347f2 727
98efcc41 728 if (!sta->sae) {
bb598c3b
AB
729 if (auth_transaction != 1 ||
730 status_code != WLAN_STATUS_SUCCESS) {
731 resp = -1;
732 goto remove_sta;
733 }
98efcc41 734 sta->sae = os_zalloc(sizeof(*sta->sae));
bb598c3b
AB
735 if (!sta->sae) {
736 resp = -1;
737 goto remove_sta;
738 }
dd43026a 739 sta->sae->state = SAE_NOTHING;
f3b8ad4d 740 sta->sae->sync = 0;
98efcc41
JM
741 }
742
9f2cf23e
MH
743 if (sta->mesh_sae_pmksa_caching) {
744 wpa_printf(MSG_DEBUG,
745 "SAE: Cancel use of mesh PMKSA caching because peer starts SAE authentication");
746 wpa_auth_pmksa_remove(hapd->wpa_auth, sta->addr);
747 sta->mesh_sae_pmksa_caching = 0;
748 }
749
c10347f2 750 if (auth_transaction == 1) {
a959a3b6 751 const u8 *token = NULL, *pos, *end;
d136c376 752 size_t token_len = 0;
c10347f2
JM
753 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
754 HOSTAPD_LEVEL_DEBUG,
afa2ffb4
JM
755 "start SAE authentication (RX commit, status=%u)",
756 status_code);
872b7545
MH
757
758 if ((hapd->conf->mesh & MESH_ENABLED) &&
afa2ffb4
JM
759 status_code == WLAN_STATUS_ANTI_CLOGGING_TOKEN_REQ &&
760 sta->sae->tmp) {
a959a3b6
MH
761 pos = mgmt->u.auth.variable;
762 end = ((const u8 *) mgmt) + len;
763 if (pos + sizeof(le16) > end) {
764 wpa_printf(MSG_ERROR,
765 "SAE: Too short anti-clogging token request");
766 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
767 goto reply;
768 }
769 resp = sae_group_allowed(sta->sae,
770 hapd->conf->sae_groups,
771 WPA_GET_LE16(pos));
772 if (resp != WLAN_STATUS_SUCCESS) {
773 wpa_printf(MSG_ERROR,
774 "SAE: Invalid group in anti-clogging token request");
775 goto reply;
776 }
777 pos += sizeof(le16);
778
872b7545
MH
779 wpabuf_free(sta->sae->tmp->anti_clogging_token);
780 sta->sae->tmp->anti_clogging_token =
a959a3b6 781 wpabuf_alloc_copy(pos, end - pos);
872b7545
MH
782 if (sta->sae->tmp->anti_clogging_token == NULL) {
783 wpa_printf(MSG_ERROR,
784 "SAE: Failed to alloc for anti-clogging token");
bb598c3b
AB
785 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
786 goto remove_sta;
872b7545
MH
787 }
788
789 /*
790 * IEEE Std 802.11-2012, 11.3.8.6.4: If the Status code
791 * is 76, a new Commit Message shall be constructed
792 * with the Anti-Clogging Token from the received
793 * Authentication frame, and the commit-scalar and
794 * COMMIT-ELEMENT previously sent.
795 */
bb598c3b
AB
796 resp = auth_sae_send_commit(hapd, sta, mgmt->bssid, 0);
797 if (resp != WLAN_STATUS_SUCCESS) {
872b7545
MH
798 wpa_printf(MSG_ERROR,
799 "SAE: Failed to send commit message");
bb598c3b 800 goto remove_sta;
872b7545
MH
801 }
802 sta->sae->state = SAE_COMMITTED;
f3b8ad4d
BC
803 sta->sae->sync = 0;
804 sae_set_retransmit_timer(hapd, sta);
872b7545
MH
805 return;
806 }
807
afa2ffb4 808 if (status_code != WLAN_STATUS_SUCCESS)
bb598c3b 809 goto remove_sta;
afa2ffb4 810
146f6c9a
JM
811 resp = sae_parse_commit(sta->sae, mgmt->u.auth.variable,
812 ((const u8 *) mgmt) + len -
d136c376 813 mgmt->u.auth.variable, &token,
625f202a 814 &token_len, hapd->conf->sae_groups);
6a58444d
JM
815 if (resp == SAE_SILENTLY_DISCARD) {
816 wpa_printf(MSG_DEBUG,
817 "SAE: Drop commit message from " MACSTR " due to reflection attack",
818 MAC2STR(sta->addr));
bb598c3b 819 goto remove_sta;
6a58444d 820 }
d136c376
JM
821 if (token && check_sae_token(hapd, sta->addr, token, token_len)
822 < 0) {
823 wpa_printf(MSG_DEBUG, "SAE: Drop commit message with "
824 "incorrect token from " MACSTR,
825 MAC2STR(sta->addr));
bb598c3b
AB
826 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
827 goto remove_sta;
d136c376
JM
828 }
829
e96da42b
BC
830 if (resp != WLAN_STATUS_SUCCESS)
831 goto reply;
832
833 if (!token && use_sae_anti_clogging(hapd)) {
834 wpa_printf(MSG_DEBUG,
835 "SAE: Request anti-clogging token from "
836 MACSTR, MAC2STR(sta->addr));
a959a3b6
MH
837 data = auth_build_token_req(hapd, sta->sae->group,
838 sta->addr);
e96da42b 839 resp = WLAN_STATUS_ANTI_CLOGGING_TOKEN_REQ;
872b7545
MH
840 if (hapd->conf->mesh & MESH_ENABLED)
841 sta->sae->state = SAE_NOTHING;
e96da42b 842 goto reply;
750efe6e 843 }
e96da42b
BC
844
845 resp = sae_sm_step(hapd, sta, mgmt->bssid, auth_transaction);
c10347f2 846 } else if (auth_transaction == 2) {
c10347f2
JM
847 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
848 HOSTAPD_LEVEL_DEBUG,
afa2ffb4
JM
849 "SAE authentication (RX confirm, status=%u)",
850 status_code);
851 if (status_code != WLAN_STATUS_SUCCESS)
bb598c3b 852 goto remove_sta;
e96da42b
BC
853 if (sta->sae->state >= SAE_CONFIRMED ||
854 !(hapd->conf->mesh & MESH_ENABLED)) {
855 if (sae_check_confirm(sta->sae, mgmt->u.auth.variable,
856 ((u8 *) mgmt) + len -
857 mgmt->u.auth.variable) < 0) {
750efe6e 858 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
e96da42b 859 goto reply;
b4fd3613 860 }
21af6d15 861 }
e96da42b 862 resp = sae_sm_step(hapd, sta, mgmt->bssid, auth_transaction);
c10347f2
JM
863 } else {
864 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
865 HOSTAPD_LEVEL_DEBUG,
afa2ffb4
JM
866 "unexpected SAE authentication transaction %u (status=%u)",
867 auth_transaction, status_code);
868 if (status_code != WLAN_STATUS_SUCCESS)
bb598c3b 869 goto remove_sta;
c10347f2
JM
870 resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
871 }
872
e96da42b
BC
873reply:
874 if (resp != WLAN_STATUS_SUCCESS) {
875 send_auth_reply(hapd, mgmt->sa, mgmt->bssid, WLAN_AUTH_SAE,
876 auth_transaction, resp,
877 data ? wpabuf_head(data) : (u8 *) "",
878 data ? wpabuf_len(data) : 0);
879 }
bb598c3b
AB
880
881remove_sta:
882 if (sta->added_unassoc && (resp != WLAN_STATUS_SUCCESS ||
883 status_code != WLAN_STATUS_SUCCESS)) {
884 hostapd_drv_sta_remove(hapd, sta->addr);
885 sta->added_unassoc = 0;
886 }
21af6d15 887 wpabuf_free(data);
c10347f2 888}
a206e2a1
BC
889
890
891/**
892 * auth_sae_init_committed - Send COMMIT and start SAE in committed state
893 * @hapd: BSS data for the device initiating the authentication
894 * @sta: the peer to which commit authentication frame is sent
895 *
896 * This function implements Init event handling (IEEE Std 802.11-2012,
897 * 11.3.8.6.3) in which initial COMMIT message is sent. Prior to calling, the
898 * sta->sae structure should be initialized appropriately via a call to
899 * sae_prepare_commit().
900 */
901int auth_sae_init_committed(struct hostapd_data *hapd, struct sta_info *sta)
902{
903 int ret;
904
905 if (!sta->sae || !sta->sae->tmp)
906 return -1;
907
908 if (sta->sae->state != SAE_NOTHING)
909 return -1;
910
911 ret = auth_sae_send_commit(hapd, sta, hapd->own_addr, 0);
912 if (ret)
913 return -1;
914
915 sta->sae->state = SAE_COMMITTED;
f3b8ad4d
BC
916 sta->sae->sync = 0;
917 sae_set_retransmit_timer(hapd, sta);
a206e2a1
BC
918
919 return 0;
920}
921
c10347f2
JM
922#endif /* CONFIG_SAE */
923
924
b57e086c
JM
925static void handle_auth(struct hostapd_data *hapd,
926 const struct ieee80211_mgmt *mgmt, size_t len)
6fc6879b
JM
927{
928 u16 auth_alg, auth_transaction, status_code;
929 u16 resp = WLAN_STATUS_SUCCESS;
930 struct sta_info *sta = NULL;
bb598c3b 931 int res, reply_res;
6fc6879b 932 u16 fc;
b57e086c 933 const u8 *challenge = NULL;
6fc6879b 934 u32 session_timeout, acct_interim_interval;
1889af2e 935 struct vlan_description vlan_id;
2ad3e6c8 936 struct hostapd_sta_wpa_psk_short *psk = NULL;
6fc6879b
JM
937 u8 resp_ies[2 + WLAN_AUTH_CHALLENGE_LEN];
938 size_t resp_ies_len = 0;
2092597f
MB
939 char *identity = NULL;
940 char *radius_cui = NULL;
38cb0a2d 941 u16 seq_ctrl;
6fc6879b 942
1889af2e
MB
943 os_memset(&vlan_id, 0, sizeof(vlan_id));
944
6fc6879b 945 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
61323e70
JM
946 wpa_printf(MSG_INFO, "handle_auth - too short payload (len=%lu)",
947 (unsigned long) len);
6fc6879b
JM
948 return;
949 }
950
c2aff6b1 951#ifdef CONFIG_TESTING_OPTIONS
06df2aa6 952 if (hapd->iconf->ignore_auth_probability > 0.0 &&
c2aff6b1
JB
953 drand48() < hapd->iconf->ignore_auth_probability) {
954 wpa_printf(MSG_INFO,
955 "TESTING: ignoring auth frame from " MACSTR,
956 MAC2STR(mgmt->sa));
957 return;
958 }
959#endif /* CONFIG_TESTING_OPTIONS */
960
6fc6879b
JM
961 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
962 auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
963 status_code = le_to_host16(mgmt->u.auth.status_code);
964 fc = le_to_host16(mgmt->frame_control);
38cb0a2d 965 seq_ctrl = le_to_host16(mgmt->seq_ctrl);
6fc6879b
JM
966
967 if (len >= IEEE80211_HDRLEN + sizeof(mgmt->u.auth) +
968 2 + WLAN_AUTH_CHALLENGE_LEN &&
969 mgmt->u.auth.variable[0] == WLAN_EID_CHALLENGE &&
970 mgmt->u.auth.variable[1] == WLAN_AUTH_CHALLENGE_LEN)
971 challenge = &mgmt->u.auth.variable[2];
972
973 wpa_printf(MSG_DEBUG, "authentication: STA=" MACSTR " auth_alg=%d "
38cb0a2d
IP
974 "auth_transaction=%d status_code=%d wep=%d%s "
975 "seq_ctrl=0x%x%s",
6fc6879b
JM
976 MAC2STR(mgmt->sa), auth_alg, auth_transaction,
977 status_code, !!(fc & WLAN_FC_ISWEP),
38cb0a2d
IP
978 challenge ? " challenge" : "",
979 seq_ctrl, (fc & WLAN_FC_RETRY) ? " retry" : "");
6fc6879b 980
7cb53ded
JM
981#ifdef CONFIG_NO_RC4
982 if (auth_alg == WLAN_AUTH_SHARED_KEY) {
983 wpa_printf(MSG_INFO,
984 "Unsupported authentication algorithm (%d)",
985 auth_alg);
986 resp = WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
987 goto fail;
988 }
989#endif /* CONFIG_NO_RC4 */
990
6fc6879b
JM
991 if (hapd->tkip_countermeasures) {
992 resp = WLAN_REASON_MICHAEL_MIC_FAILURE;
993 goto fail;
994 }
995
996 if (!(((hapd->conf->auth_algs & WPA_AUTH_ALG_OPEN) &&
997 auth_alg == WLAN_AUTH_OPEN) ||
998#ifdef CONFIG_IEEE80211R
0bf927a0 999 (hapd->conf->wpa && wpa_key_mgmt_ft(hapd->conf->wpa_key_mgmt) &&
6fc6879b
JM
1000 auth_alg == WLAN_AUTH_FT) ||
1001#endif /* CONFIG_IEEE80211R */
c10347f2
JM
1002#ifdef CONFIG_SAE
1003 (hapd->conf->wpa && wpa_key_mgmt_sae(hapd->conf->wpa_key_mgmt) &&
1004 auth_alg == WLAN_AUTH_SAE) ||
1005#endif /* CONFIG_SAE */
6fc6879b
JM
1006 ((hapd->conf->auth_algs & WPA_AUTH_ALG_SHARED) &&
1007 auth_alg == WLAN_AUTH_SHARED_KEY))) {
61323e70
JM
1008 wpa_printf(MSG_INFO, "Unsupported authentication algorithm (%d)",
1009 auth_alg);
6fc6879b
JM
1010 resp = WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
1011 goto fail;
1012 }
1013
c10347f2 1014 if (!(auth_transaction == 1 || auth_alg == WLAN_AUTH_SAE ||
6fc6879b 1015 (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 3))) {
61323e70
JM
1016 wpa_printf(MSG_INFO, "Unknown authentication transaction number (%d)",
1017 auth_transaction);
6fc6879b
JM
1018 resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
1019 goto fail;
1020 }
1021
1022 if (os_memcmp(mgmt->sa, hapd->own_addr, ETH_ALEN) == 0) {
61323e70
JM
1023 wpa_printf(MSG_INFO, "Station " MACSTR " not allowed to authenticate",
1024 MAC2STR(mgmt->sa));
6fc6879b
JM
1025 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1026 goto fail;
1027 }
1028
0e2412d0
JM
1029 if (hapd->conf->no_auth_if_seen_on) {
1030 struct hostapd_data *other;
1031
1032 other = sta_track_seen_on(hapd->iface, mgmt->sa,
1033 hapd->conf->no_auth_if_seen_on);
1034 if (other) {
1035 u8 *pos;
1036 u32 info;
1037 u8 op_class, channel, phytype;
1038
1039 wpa_printf(MSG_DEBUG, "%s: Reject authentication from "
1040 MACSTR " since STA has been seen on %s",
1041 hapd->conf->iface, MAC2STR(mgmt->sa),
1042 hapd->conf->no_auth_if_seen_on);
1043
1044 resp = WLAN_STATUS_REJECTED_WITH_SUGGESTED_BSS_TRANSITION;
1045 pos = &resp_ies[0];
1046 *pos++ = WLAN_EID_NEIGHBOR_REPORT;
1047 *pos++ = 13;
1048 os_memcpy(pos, other->own_addr, ETH_ALEN);
1049 pos += ETH_ALEN;
1050 info = 0; /* TODO: BSSID Information */
1051 WPA_PUT_LE32(pos, info);
1052 pos += 4;
1053 if (other->iconf->hw_mode == HOSTAPD_MODE_IEEE80211AD)
1054 phytype = 8; /* dmg */
1055 else if (other->iconf->ieee80211ac)
1056 phytype = 9; /* vht */
1057 else if (other->iconf->ieee80211n)
1058 phytype = 7; /* ht */
1059 else if (other->iconf->hw_mode ==
1060 HOSTAPD_MODE_IEEE80211A)
1061 phytype = 4; /* ofdm */
1062 else if (other->iconf->hw_mode ==
1063 HOSTAPD_MODE_IEEE80211G)
1064 phytype = 6; /* erp */
1065 else
1066 phytype = 5; /* hrdsss */
1067 if (ieee80211_freq_to_channel_ext(
1068 hostapd_hw_get_freq(other,
1069 other->iconf->channel),
1070 other->iconf->secondary_channel,
1071 other->iconf->ieee80211ac,
1072 &op_class, &channel) == NUM_HOSTAPD_MODES) {
1073 op_class = 0;
1074 channel = other->iconf->channel;
1075 }
1076 *pos++ = op_class;
1077 *pos++ = channel;
1078 *pos++ = phytype;
1079 resp_ies_len = pos - &resp_ies[0];
1080 goto fail;
1081 }
1082 }
1083
6fc6879b
JM
1084 res = hostapd_allowed_address(hapd, mgmt->sa, (u8 *) mgmt, len,
1085 &session_timeout,
05ab9712 1086 &acct_interim_interval, &vlan_id,
2ad3e6c8 1087 &psk, &identity, &radius_cui);
05ab9712 1088
6fc6879b 1089 if (res == HOSTAPD_ACL_REJECT) {
61323e70
JM
1090 wpa_printf(MSG_INFO, "Station " MACSTR " not allowed to authenticate",
1091 MAC2STR(mgmt->sa));
6fc6879b
JM
1092 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1093 goto fail;
1094 }
1095 if (res == HOSTAPD_ACL_PENDING) {
1096 wpa_printf(MSG_DEBUG, "Authentication frame from " MACSTR
1097 " waiting for an external authentication",
1098 MAC2STR(mgmt->sa));
1099 /* Authentication code will re-send the authentication frame
1100 * after it has received (and cached) information from the
1101 * external source. */
1102 return;
1103 }
1104
38cb0a2d
IP
1105 sta = ap_get_sta(hapd, mgmt->sa);
1106 if (sta) {
1107 if ((fc & WLAN_FC_RETRY) &&
1108 sta->last_seq_ctrl != WLAN_INVALID_MGMT_SEQ &&
1109 sta->last_seq_ctrl == seq_ctrl &&
1110 sta->last_subtype == WLAN_FC_STYPE_AUTH) {
1111 hostapd_logger(hapd, sta->addr,
1112 HOSTAPD_MODULE_IEEE80211,
1113 HOSTAPD_LEVEL_DEBUG,
1114 "Drop repeated authentication frame seq_ctrl=0x%x",
1115 seq_ctrl);
1116 return;
1117 }
09d96de0
MH
1118#ifdef CONFIG_MESH
1119 if ((hapd->conf->mesh & MESH_ENABLED) &&
1120 sta->plink_state == PLINK_BLOCKED) {
1121 wpa_printf(MSG_DEBUG, "Mesh peer " MACSTR
1122 " is blocked - drop Authentication frame",
1123 MAC2STR(mgmt->sa));
1124 return;
1125 }
1126#endif /* CONFIG_MESH */
38cb0a2d 1127 } else {
c50d94f1 1128#ifdef CONFIG_MESH
38cb0a2d
IP
1129 if (hapd->conf->mesh & MESH_ENABLED) {
1130 /* if the mesh peer is not available, we don't do auth.
1131 */
3a322496 1132 wpa_printf(MSG_DEBUG, "Mesh peer " MACSTR
09d96de0 1133 " not yet known - drop Authentication frame",
3a322496
JM
1134 MAC2STR(mgmt->sa));
1135 /*
1136 * Save a copy of the frame so that it can be processed
1137 * if a new peer entry is added shortly after this.
1138 */
1139 wpabuf_free(hapd->mesh_pending_auth);
1140 hapd->mesh_pending_auth = wpabuf_alloc_copy(mgmt, len);
1141 os_get_reltime(&hapd->mesh_pending_auth_time);
c50d94f1 1142 return;
38cb0a2d 1143 }
c50d94f1 1144#endif /* CONFIG_MESH */
38cb0a2d 1145
c50d94f1
BC
1146 sta = ap_sta_add(hapd, mgmt->sa);
1147 if (!sta) {
1148 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
1149 goto fail;
1150 }
6fc6879b 1151 }
38cb0a2d
IP
1152 sta->last_seq_ctrl = seq_ctrl;
1153 sta->last_subtype = WLAN_FC_STYPE_AUTH;
6fc6879b 1154
8be640b7
MB
1155 if (vlan_id.notempty &&
1156 !hostapd_vlan_valid(hapd->conf->vlan, &vlan_id)) {
6fc6879b 1157 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
8be640b7
MB
1158 HOSTAPD_LEVEL_INFO,
1159 "Invalid VLAN %d%s received from RADIUS server",
1160 vlan_id.untagged,
1161 vlan_id.tagged[0] ? "+" : "");
1162 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1163 goto fail;
1164 }
1165 if (ap_sta_set_vlan(hapd, sta, &vlan_id) < 0) {
1166 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1167 goto fail;
6fc6879b 1168 }
8be640b7
MB
1169 if (sta->vlan_id)
1170 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
1171 HOSTAPD_LEVEL_INFO, "VLAN ID %d", sta->vlan_id);
6fc6879b 1172
f2a14be7 1173 hostapd_free_psk_list(sta->psk);
5ee56c4e
MB
1174 if (hapd->conf->wpa_psk_radius != PSK_RADIUS_IGNORED) {
1175 sta->psk = psk;
1176 psk = NULL;
05ab9712 1177 } else {
05ab9712
MB
1178 sta->psk = NULL;
1179 }
1180
2092597f
MB
1181 sta->identity = identity;
1182 identity = NULL;
1183 sta->radius_cui = radius_cui;
1184 radius_cui = NULL;
1185
6fc6879b
JM
1186 sta->flags &= ~WLAN_STA_PREAUTH;
1187 ieee802_1x_notify_pre_auth(sta->eapol_sm, 0);
1188
5843e1c9 1189 if (hapd->conf->acct_interim_interval == 0 && acct_interim_interval)
6fc6879b
JM
1190 sta->acct_interim_interval = acct_interim_interval;
1191 if (res == HOSTAPD_ACL_ACCEPT_TIMEOUT)
1192 ap_sta_session_timeout(hapd, sta, session_timeout);
1193 else
1194 ap_sta_no_session_timeout(hapd, sta);
1195
bb598c3b
AB
1196 /*
1197 * If the driver supports full AP client state, add a station to the
1198 * driver before sending authentication reply to make sure the driver
1199 * has resources, and not to go through the entire authentication and
1200 * association handshake, and fail it at the end.
1201 *
1202 * If this is not the first transaction, in a multi-step authentication
1203 * algorithm, the station already exists in the driver
1204 * (sta->added_unassoc = 1) so skip it.
1205 *
1206 * In mesh mode, the station was already added to the driver when the
1207 * NEW_PEER_CANDIDATE event is received.
1208 */
1209 if (FULL_AP_CLIENT_STATE_SUPP(hapd->iface->drv_flags) &&
1210 !(hapd->conf->mesh & MESH_ENABLED) &&
1211 !(sta->added_unassoc)) {
1212 /*
1213 * If a station that is already associated to the AP, is trying
1214 * to authenticate again, remove the STA entry, in order to make
1215 * sure the STA PS state gets cleared and configuration gets
1216 * updated. To handle this, station's added_unassoc flag is
1217 * cleared once the station has completed association.
1218 */
1219 hostapd_drv_sta_remove(hapd, sta->addr);
1220 sta->flags &= ~(WLAN_STA_ASSOC | WLAN_STA_AUTH |
1221 WLAN_STA_AUTHORIZED);
1222
1223 if (hostapd_sta_add(hapd, sta->addr, 0, 0, 0, 0, 0,
ae33239c 1224 NULL, NULL, sta->flags, 0, 0, 0, 0)) {
bb598c3b
AB
1225 hostapd_logger(hapd, sta->addr,
1226 HOSTAPD_MODULE_IEEE80211,
1227 HOSTAPD_LEVEL_NOTICE,
1228 "Could not add STA to kernel driver");
1229 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
1230 goto fail;
1231 }
1232
1233 sta->added_unassoc = 1;
1234 }
1235
6fc6879b
JM
1236 switch (auth_alg) {
1237 case WLAN_AUTH_OPEN:
1238 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1239 HOSTAPD_LEVEL_DEBUG,
1240 "authentication OK (open system)");
6fc6879b
JM
1241 sta->flags |= WLAN_STA_AUTH;
1242 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
1243 sta->auth_alg = WLAN_AUTH_OPEN;
1244 mlme_authenticate_indication(hapd, sta);
6fc6879b 1245 break;
7cb53ded 1246#ifndef CONFIG_NO_RC4
6fc6879b
JM
1247 case WLAN_AUTH_SHARED_KEY:
1248 resp = auth_shared_key(hapd, sta, auth_transaction, challenge,
1249 fc & WLAN_FC_ISWEP);
1250 sta->auth_alg = WLAN_AUTH_SHARED_KEY;
1251 mlme_authenticate_indication(hapd, sta);
1252 if (sta->challenge && auth_transaction == 1) {
1253 resp_ies[0] = WLAN_EID_CHALLENGE;
1254 resp_ies[1] = WLAN_AUTH_CHALLENGE_LEN;
1255 os_memcpy(resp_ies + 2, sta->challenge,
1256 WLAN_AUTH_CHALLENGE_LEN);
1257 resp_ies_len = 2 + WLAN_AUTH_CHALLENGE_LEN;
1258 }
1259 break;
7cb53ded 1260#endif /* CONFIG_NO_RC4 */
6fc6879b
JM
1261#ifdef CONFIG_IEEE80211R
1262 case WLAN_AUTH_FT:
1263 sta->auth_alg = WLAN_AUTH_FT;
1264 if (sta->wpa_sm == NULL)
1265 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
94ddef3e 1266 sta->addr, NULL);
6fc6879b
JM
1267 if (sta->wpa_sm == NULL) {
1268 wpa_printf(MSG_DEBUG, "FT: Failed to initialize WPA "
1269 "state machine");
1270 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1271 goto fail;
1272 }
1273 wpa_ft_process_auth(sta->wpa_sm, mgmt->bssid,
1274 auth_transaction, mgmt->u.auth.variable,
1275 len - IEEE80211_HDRLEN -
1276 sizeof(mgmt->u.auth),
1277 handle_auth_ft_finish, hapd);
1278 /* handle_auth_ft_finish() callback will complete auth. */
1279 return;
1280#endif /* CONFIG_IEEE80211R */
c10347f2
JM
1281#ifdef CONFIG_SAE
1282 case WLAN_AUTH_SAE:
c50d94f1 1283#ifdef CONFIG_MESH
afa2ffb4
JM
1284 if (status_code == WLAN_STATUS_SUCCESS &&
1285 hapd->conf->mesh & MESH_ENABLED) {
c50d94f1
BC
1286 if (sta->wpa_sm == NULL)
1287 sta->wpa_sm =
1288 wpa_auth_sta_init(hapd->wpa_auth,
1289 sta->addr, NULL);
1290 if (sta->wpa_sm == NULL) {
1291 wpa_printf(MSG_DEBUG,
1292 "SAE: Failed to initialize WPA state machine");
1293 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1294 goto fail;
1295 }
1296 }
1297#endif /* CONFIG_MESH */
afa2ffb4
JM
1298 handle_auth_sae(hapd, sta, mgmt, len, auth_transaction,
1299 status_code);
c10347f2
JM
1300 return;
1301#endif /* CONFIG_SAE */
6fc6879b
JM
1302 }
1303
1304 fail:
2092597f
MB
1305 os_free(identity);
1306 os_free(radius_cui);
f2a14be7 1307 hostapd_free_psk_list(psk);
2092597f 1308
bb598c3b
AB
1309 reply_res = send_auth_reply(hapd, mgmt->sa, mgmt->bssid, auth_alg,
1310 auth_transaction + 1, resp, resp_ies,
1311 resp_ies_len);
1312
1313 if (sta && sta->added_unassoc && (resp != WLAN_STATUS_SUCCESS ||
1314 reply_res != WLAN_STATUS_SUCCESS)) {
1315 hostapd_drv_sta_remove(hapd, sta->addr);
1316 sta->added_unassoc = 0;
1317 }
6fc6879b
JM
1318}
1319
1320
681753f2 1321int hostapd_get_aid(struct hostapd_data *hapd, struct sta_info *sta)
d42a62b3 1322{
2991469c
JM
1323 int i, j = 32, aid;
1324
d42a62b3
JM
1325 /* get a unique AID */
1326 if (sta->aid > 0) {
1327 wpa_printf(MSG_DEBUG, " old AID %d", sta->aid);
1328 return 0;
1329 }
1330
2991469c
JM
1331 for (i = 0; i < AID_WORDS; i++) {
1332 if (hapd->sta_aid[i] == (u32) -1)
1333 continue;
1334 for (j = 0; j < 32; j++) {
1335 if (!(hapd->sta_aid[i] & BIT(j)))
1336 break;
1337 }
1338 if (j < 32)
d42a62b3 1339 break;
d42a62b3 1340 }
2991469c
JM
1341 if (j == 32)
1342 return -1;
1343 aid = i * 32 + j + 1;
1344 if (aid > 2007)
1345 return -1;
d42a62b3 1346
2991469c
JM
1347 sta->aid = aid;
1348 hapd->sta_aid[i] |= BIT(j);
d42a62b3
JM
1349 wpa_printf(MSG_DEBUG, " new AID %d", sta->aid);
1350 return 0;
1351}
1352
1353
5586f500
JM
1354static u16 check_ssid(struct hostapd_data *hapd, struct sta_info *sta,
1355 const u8 *ssid_ie, size_t ssid_ie_len)
6fc6879b 1356{
5586f500
JM
1357 if (ssid_ie == NULL)
1358 return WLAN_STATUS_UNSPECIFIED_FAILURE;
6fc6879b 1359
5586f500
JM
1360 if (ssid_ie_len != hapd->conf->ssid.ssid_len ||
1361 os_memcmp(ssid_ie, hapd->conf->ssid.ssid, ssid_ie_len) != 0) {
5586f500
JM
1362 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1363 HOSTAPD_LEVEL_INFO,
1364 "Station tried to associate with unknown SSID "
b37d582e 1365 "'%s'", wpa_ssid_txt(ssid_ie, ssid_ie_len));
5586f500 1366 return WLAN_STATUS_UNSPECIFIED_FAILURE;
b0194fe0
JM
1367 }
1368
5586f500
JM
1369 return WLAN_STATUS_SUCCESS;
1370}
6fc6879b 1371
6fc6879b 1372
5586f500
JM
1373static u16 check_wmm(struct hostapd_data *hapd, struct sta_info *sta,
1374 const u8 *wmm_ie, size_t wmm_ie_len)
1375{
3ae0800c 1376 sta->flags &= ~WLAN_STA_WMM;
5d061637 1377 sta->qosinfo = 0;
5586f500 1378 if (wmm_ie && hapd->conf->wmm_enabled) {
5f32f79c 1379 struct wmm_information_element *wmm;
5f32f79c 1380
c84b868a 1381 if (!hostapd_eid_wmm_valid(hapd, wmm_ie, wmm_ie_len)) {
6fc6879b
JM
1382 hostapd_logger(hapd, sta->addr,
1383 HOSTAPD_MODULE_WPA,
1384 HOSTAPD_LEVEL_DEBUG,
3ae0800c 1385 "invalid WMM element in association "
6fc6879b 1386 "request");
5f32f79c
EP
1387 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1388 }
1389
1390 sta->flags |= WLAN_STA_WMM;
1391 wmm = (struct wmm_information_element *) wmm_ie;
5d061637 1392 sta->qosinfo = wmm->qos_info;
6fc6879b 1393 }
5586f500
JM
1394 return WLAN_STATUS_SUCCESS;
1395}
6fc6879b 1396
5586f500
JM
1397
1398static u16 copy_supp_rates(struct hostapd_data *hapd, struct sta_info *sta,
1399 struct ieee802_11_elems *elems)
1400{
1401 if (!elems->supp_rates) {
1402 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
6fc6879b
JM
1403 HOSTAPD_LEVEL_DEBUG,
1404 "No supported rates element in AssocReq");
5586f500 1405 return WLAN_STATUS_UNSPECIFIED_FAILURE;
6fc6879b
JM
1406 }
1407
3489cfb0
JM
1408 if (elems->supp_rates_len + elems->ext_supp_rates_len >
1409 sizeof(sta->supported_rates)) {
5586f500 1410 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
6fc6879b 1411 HOSTAPD_LEVEL_DEBUG,
3489cfb0
JM
1412 "Invalid supported rates element length %d+%d",
1413 elems->supp_rates_len,
1414 elems->ext_supp_rates_len);
5586f500 1415 return WLAN_STATUS_UNSPECIFIED_FAILURE;
6fc6879b
JM
1416 }
1417
3489cfb0
JM
1418 sta->supported_rates_len = merge_byte_arrays(
1419 sta->supported_rates, sizeof(sta->supported_rates),
1420 elems->supp_rates, elems->supp_rates_len,
1421 elems->ext_supp_rates, elems->ext_supp_rates_len);
6fc6879b 1422
5586f500
JM
1423 return WLAN_STATUS_SUCCESS;
1424}
1425
1426
c551700f
KP
1427static u16 check_ext_capab(struct hostapd_data *hapd, struct sta_info *sta,
1428 const u8 *ext_capab_ie, size_t ext_capab_ie_len)
1429{
1430#ifdef CONFIG_INTERWORKING
1431 /* check for QoS Map support */
1432 if (ext_capab_ie_len >= 5) {
1433 if (ext_capab_ie[4] & 0x01)
1434 sta->qos_map_enabled = 1;
1435 }
1436#endif /* CONFIG_INTERWORKING */
1437
98b05081
AO
1438 if (ext_capab_ie_len > 0)
1439 sta->ecsa_supported = !!(ext_capab_ie[0] & BIT(2));
1440
c551700f
KP
1441 return WLAN_STATUS_SUCCESS;
1442}
1443
1444
5586f500 1445static u16 check_assoc_ies(struct hostapd_data *hapd, struct sta_info *sta,
b57e086c 1446 const u8 *ies, size_t ies_len, int reassoc)
5586f500
JM
1447{
1448 struct ieee802_11_elems elems;
1449 u16 resp;
ba091c06 1450 const u8 *wpa_ie;
5586f500 1451 size_t wpa_ie_len;
94ddef3e 1452 const u8 *p2p_dev_addr = NULL;
5586f500
JM
1453
1454 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed) {
1455 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1456 HOSTAPD_LEVEL_INFO, "Station sent an invalid "
1457 "association request");
1458 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1459 }
1460
1461 resp = check_ssid(hapd, sta, elems.ssid, elems.ssid_len);
1462 if (resp != WLAN_STATUS_SUCCESS)
1463 return resp;
1464 resp = check_wmm(hapd, sta, elems.wmm, elems.wmm_len);
c551700f
KP
1465 if (resp != WLAN_STATUS_SUCCESS)
1466 return resp;
1467 resp = check_ext_capab(hapd, sta, elems.ext_capab, elems.ext_capab_len);
5586f500
JM
1468 if (resp != WLAN_STATUS_SUCCESS)
1469 return resp;
1470 resp = copy_supp_rates(hapd, sta, &elems);
1471 if (resp != WLAN_STATUS_SUCCESS)
1472 return resp;
d45354be 1473#ifdef CONFIG_IEEE80211N
baae4cb9 1474 resp = copy_sta_ht_capab(hapd, sta, elems.ht_capabilities);
5586f500
JM
1475 if (resp != WLAN_STATUS_SUCCESS)
1476 return resp;
29448243
JM
1477 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht &&
1478 !(sta->flags & WLAN_STA_HT)) {
1479 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1480 HOSTAPD_LEVEL_INFO, "Station does not support "
1481 "mandatory HT PHY - reject association");
1482 return WLAN_STATUS_ASSOC_DENIED_NO_HT;
1483 }
d45354be 1484#endif /* CONFIG_IEEE80211N */
5586f500 1485
de3cdf35 1486#ifdef CONFIG_IEEE80211AC
28ffd21c
ARN
1487 if (hapd->iconf->ieee80211ac) {
1488 resp = copy_sta_vht_capab(hapd, sta, elems.vht_capabilities);
1489 if (resp != WLAN_STATUS_SUCCESS)
1490 return resp;
8a458116 1491
28ffd21c
ARN
1492 resp = set_sta_vht_opmode(hapd, sta, elems.vht_opmode_notif);
1493 if (resp != WLAN_STATUS_SUCCESS)
1494 return resp;
1495 }
8a458116 1496
140e850a
MP
1497 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht &&
1498 !(sta->flags & WLAN_STA_VHT)) {
1499 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1500 HOSTAPD_LEVEL_INFO, "Station does not support "
1501 "mandatory VHT PHY - reject association");
13b24a76 1502 return WLAN_STATUS_ASSOC_DENIED_NO_VHT;
140e850a 1503 }
e7d0e97b
YL
1504
1505 if (hapd->conf->vendor_vht && !elems.vht_capabilities) {
1506 resp = copy_sta_vendor_vht(hapd, sta, elems.vendor_vht,
1507 elems.vendor_vht_len);
1508 if (resp != WLAN_STATUS_SUCCESS)
1509 return resp;
1510 }
de3cdf35
MP
1511#endif /* CONFIG_IEEE80211AC */
1512
94ddef3e
JM
1513#ifdef CONFIG_P2P
1514 if (elems.p2p) {
1515 wpabuf_free(sta->p2p_ie);
1516 sta->p2p_ie = ieee802_11_vendor_ie_concat(ies, ies_len,
1517 P2P_IE_VENDOR_TYPE);
1518 if (sta->p2p_ie)
1519 p2p_dev_addr = p2p_get_go_dev_addr(sta->p2p_ie);
1520 } else {
1521 wpabuf_free(sta->p2p_ie);
1522 sta->p2p_ie = NULL;
1523 }
1524#endif /* CONFIG_P2P */
1525
6fc6879b
JM
1526 if ((hapd->conf->wpa & WPA_PROTO_RSN) && elems.rsn_ie) {
1527 wpa_ie = elems.rsn_ie;
1528 wpa_ie_len = elems.rsn_ie_len;
1529 } else if ((hapd->conf->wpa & WPA_PROTO_WPA) &&
1530 elems.wpa_ie) {
1531 wpa_ie = elems.wpa_ie;
1532 wpa_ie_len = elems.wpa_ie_len;
1533 } else {
1534 wpa_ie = NULL;
1535 wpa_ie_len = 0;
1536 }
5586f500 1537
ad08c363 1538#ifdef CONFIG_WPS
17f6b900 1539 sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS | WLAN_STA_WPS2);
c47cf42e
JM
1540 if (hapd->conf->wps_state && elems.wps_ie) {
1541 wpa_printf(MSG_DEBUG, "STA included WPS IE in (Re)Association "
1542 "Request - assume WPS is used");
1543 sta->flags |= WLAN_STA_WPS;
1544 wpabuf_free(sta->wps_ie);
16e46ec0
JM
1545 sta->wps_ie = ieee802_11_vendor_ie_concat(ies, ies_len,
1546 WPS_IE_VENDOR_TYPE);
17f6b900
JM
1547 if (sta->wps_ie && wps_is_20(sta->wps_ie)) {
1548 wpa_printf(MSG_DEBUG, "WPS: STA supports WPS 2.0");
1549 sta->flags |= WLAN_STA_WPS2;
1550 }
c47cf42e
JM
1551 wpa_ie = NULL;
1552 wpa_ie_len = 0;
54f489be
JM
1553 if (sta->wps_ie && wps_validate_assoc_req(sta->wps_ie) < 0) {
1554 wpa_printf(MSG_DEBUG, "WPS: Invalid WPS IE in "
1555 "(Re)Association Request - reject");
1556 return WLAN_STATUS_INVALID_IE;
1557 }
c47cf42e
JM
1558 } else if (hapd->conf->wps_state && wpa_ie == NULL) {
1559 wpa_printf(MSG_DEBUG, "STA did not include WPA/RSN IE in "
1560 "(Re)Association Request - possible WPS use");
1561 sta->flags |= WLAN_STA_MAYBE_WPS;
ad08c363
JM
1562 } else
1563#endif /* CONFIG_WPS */
6fc6879b 1564 if (hapd->conf->wpa && wpa_ie == NULL) {
5586f500
JM
1565 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1566 HOSTAPD_LEVEL_INFO,
1567 "No WPA/RSN IE in association request");
1568 return WLAN_STATUS_INVALID_IE;
6fc6879b
JM
1569 }
1570
1571 if (hapd->conf->wpa && wpa_ie) {
1572 int res;
1573 wpa_ie -= 2;
1574 wpa_ie_len += 2;
1575 if (sta->wpa_sm == NULL)
1576 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
94ddef3e
JM
1577 sta->addr,
1578 p2p_dev_addr);
6fc6879b 1579 if (sta->wpa_sm == NULL) {
5586f500
JM
1580 wpa_printf(MSG_WARNING, "Failed to initialize WPA "
1581 "state machine");
1582 return WLAN_STATUS_UNSPECIFIED_FAILURE;
6fc6879b
JM
1583 }
1584 res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,
1585 wpa_ie, wpa_ie_len,
1586 elems.mdie, elems.mdie_len);
1587 if (res == WPA_INVALID_GROUP)
1588 resp = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
1589 else if (res == WPA_INVALID_PAIRWISE)
1590 resp = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
1591 else if (res == WPA_INVALID_AKMP)
1592 resp = WLAN_STATUS_AKMP_NOT_VALID;
1593 else if (res == WPA_ALLOC_FAIL)
1594 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1595#ifdef CONFIG_IEEE80211W
1596 else if (res == WPA_MGMT_FRAME_PROTECTION_VIOLATION)
9a9876bf 1597 resp = WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION;
6fc6879b 1598 else if (res == WPA_INVALID_MGMT_GROUP_CIPHER)
9a9876bf 1599 resp = WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION;
6fc6879b
JM
1600#endif /* CONFIG_IEEE80211W */
1601 else if (res == WPA_INVALID_MDIE)
1602 resp = WLAN_STATUS_INVALID_MDIE;
1603 else if (res != WPA_IE_OK)
1604 resp = WLAN_STATUS_INVALID_IE;
1605 if (resp != WLAN_STATUS_SUCCESS)
5586f500 1606 return resp;
f3f7540e 1607#ifdef CONFIG_IEEE80211W
45c94154
JM
1608 if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
1609 sta->sa_query_count > 0)
1610 ap_check_sa_query_timeout(hapd, sta);
8f4617c6
JM
1611 if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
1612 (!reassoc || sta->auth_alg != WLAN_AUTH_FT)) {
5d22a1d5 1613 /*
93b76319
JM
1614 * STA has already been associated with MFP and SA
1615 * Query timeout has not been reached. Reject the
1616 * association attempt temporarily and start SA Query,
1617 * if one is not pending.
5d22a1d5
JM
1618 */
1619
93b76319
JM
1620 if (sta->sa_query_count == 0)
1621 ap_sta_start_sa_query(hapd, sta);
5d22a1d5 1622
5586f500 1623 return WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY;
5d22a1d5
JM
1624 }
1625
f3f7540e
JM
1626 if (wpa_auth_uses_mfp(sta->wpa_sm))
1627 sta->flags |= WLAN_STA_MFP;
1628 else
1629 sta->flags &= ~WLAN_STA_MFP;
1630#endif /* CONFIG_IEEE80211W */
6fc6879b
JM
1631
1632#ifdef CONFIG_IEEE80211R
1633 if (sta->auth_alg == WLAN_AUTH_FT) {
1634 if (!reassoc) {
1635 wpa_printf(MSG_DEBUG, "FT: " MACSTR " tried "
1636 "to use association (not "
1637 "re-association) with FT auth_alg",
1638 MAC2STR(sta->addr));
5586f500 1639 return WLAN_STATUS_UNSPECIFIED_FAILURE;
6fc6879b
JM
1640 }
1641
5586f500
JM
1642 resp = wpa_ft_validate_reassoc(sta->wpa_sm, ies,
1643 ies_len);
6fc6879b 1644 if (resp != WLAN_STATUS_SUCCESS)
5586f500 1645 return resp;
6fc6879b
JM
1646 }
1647#endif /* CONFIG_IEEE80211R */
5586f500 1648
c10347f2
JM
1649#ifdef CONFIG_SAE
1650 if (wpa_auth_uses_sae(sta->wpa_sm) &&
f2991170
JM
1651 sta->auth_alg == WLAN_AUTH_OPEN) {
1652 struct rsn_pmksa_cache_entry *sa;
1653 sa = wpa_auth_sta_get_pmksa(sta->wpa_sm);
1654 if (!sa || sa->akmp != WPA_KEY_MGMT_SAE) {
1655 wpa_printf(MSG_DEBUG,
1656 "SAE: No PMKSA cache entry found for "
1657 MACSTR, MAC2STR(sta->addr));
1658 return WLAN_STATUS_INVALID_PMKID;
1659 }
1660 wpa_printf(MSG_DEBUG, "SAE: " MACSTR
1661 " using PMKSA caching", MAC2STR(sta->addr));
1662 } else if (wpa_auth_uses_sae(sta->wpa_sm) &&
1663 sta->auth_alg != WLAN_AUTH_SAE &&
1664 !(sta->auth_alg == WLAN_AUTH_FT &&
1665 wpa_auth_uses_ft_sae(sta->wpa_sm))) {
c10347f2
JM
1666 wpa_printf(MSG_DEBUG, "SAE: " MACSTR " tried to use "
1667 "SAE AKM after non-SAE auth_alg %u",
1668 MAC2STR(sta->addr), sta->auth_alg);
1669 return WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
1670 }
1671#endif /* CONFIG_SAE */
1672
ff36ff00 1673#ifdef CONFIG_IEEE80211N
f0c7a986 1674 if ((sta->flags & (WLAN_STA_HT | WLAN_STA_VHT)) &&
ff36ff00 1675 wpa_auth_get_pairwise(sta->wpa_sm) == WPA_CIPHER_TKIP) {
5586f500
JM
1676 hostapd_logger(hapd, sta->addr,
1677 HOSTAPD_MODULE_IEEE80211,
1678 HOSTAPD_LEVEL_INFO,
1679 "Station tried to use TKIP with HT "
1680 "association");
1681 return WLAN_STATUS_CIPHER_REJECTED_PER_POLICY;
ff36ff00
JM
1682 }
1683#endif /* CONFIG_IEEE80211N */
a14896e8
JM
1684#ifdef CONFIG_HS20
1685 } else if (hapd->conf->osen) {
1686 if (elems.osen == NULL) {
1687 hostapd_logger(
1688 hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1689 HOSTAPD_LEVEL_INFO,
1690 "No HS 2.0 OSEN element in association request");
1691 return WLAN_STATUS_INVALID_IE;
1692 }
1693
1694 wpa_printf(MSG_DEBUG, "HS 2.0: OSEN association");
1695 if (sta->wpa_sm == NULL)
1696 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
1697 sta->addr, NULL);
1698 if (sta->wpa_sm == NULL) {
1699 wpa_printf(MSG_WARNING, "Failed to initialize WPA "
1700 "state machine");
1701 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1702 }
1703 if (wpa_validate_osen(hapd->wpa_auth, sta->wpa_sm,
1704 elems.osen - 2, elems.osen_len + 2) < 0)
1705 return WLAN_STATUS_INVALID_IE;
1706#endif /* CONFIG_HS20 */
a8d05fca
JM
1707 } else
1708 wpa_auth_sta_no_wpa(sta->wpa_sm);
6fc6879b 1709
b305c684 1710#ifdef CONFIG_P2P
3f4ce13f 1711 p2p_group_notif_assoc(hapd->p2p_group, sta->addr, ies, ies_len);
b305c684
JM
1712#endif /* CONFIG_P2P */
1713
f403dcd6
JM
1714#ifdef CONFIG_HS20
1715 wpabuf_free(sta->hs20_ie);
1716 if (elems.hs20 && elems.hs20_len > 4) {
1717 sta->hs20_ie = wpabuf_alloc_copy(elems.hs20 + 4,
1718 elems.hs20_len - 4);
1719 } else
1720 sta->hs20_ie = NULL;
1721#endif /* CONFIG_HS20 */
1722
ae667c08
AN
1723#ifdef CONFIG_FST
1724 wpabuf_free(sta->mb_ies);
1725 if (hapd->iface->fst)
1726 sta->mb_ies = mb_ies_by_info(&elems.mb_ies);
1727 else
1728 sta->mb_ies = NULL;
1729#endif /* CONFIG_FST */
1730
4c572281 1731#ifdef CONFIG_MBO
6332aaf3
JM
1732 mbo_ap_check_sta_assoc(hapd, sta, &elems);
1733
4c572281
JM
1734 if (hapd->conf->mbo_enabled && (hapd->conf->wpa & 2) &&
1735 elems.mbo && sta->cell_capa && !(sta->flags & WLAN_STA_MFP) &&
1736 hapd->conf->ieee80211w != NO_MGMT_FRAME_PROTECTION) {
1737 wpa_printf(MSG_INFO,
1738 "MBO: Reject WPA2 association without PMF");
1739 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1740 }
1741#endif /* CONFIG_MBO */
1742
adf0478e
JM
1743 ap_copy_sta_supp_op_classes(sta, elems.supp_op_classes,
1744 elems.supp_op_classes_len);
1745
5586f500
JM
1746 return WLAN_STATUS_SUCCESS;
1747}
1748
1749
1750static void send_deauth(struct hostapd_data *hapd, const u8 *addr,
1751 u16 reason_code)
1752{
1753 int send_len;
1754 struct ieee80211_mgmt reply;
1755
1756 os_memset(&reply, 0, sizeof(reply));
1757 reply.frame_control =
1758 IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_DEAUTH);
1759 os_memcpy(reply.da, addr, ETH_ALEN);
1760 os_memcpy(reply.sa, hapd->own_addr, ETH_ALEN);
1761 os_memcpy(reply.bssid, hapd->own_addr, ETH_ALEN);
1762
1763 send_len = IEEE80211_HDRLEN + sizeof(reply.u.deauth);
1764 reply.u.deauth.reason_code = host_to_le16(reason_code);
1765
8cfa3527 1766 if (hostapd_drv_send_mlme(hapd, &reply, send_len, 0) < 0)
5586f500
JM
1767 wpa_printf(MSG_INFO, "Failed to send deauth: %s",
1768 strerror(errno));
1769}
1770
1771
3f81ac07
AO
1772static int add_associated_sta(struct hostapd_data *hapd,
1773 struct sta_info *sta)
1774{
1775 struct ieee80211_ht_capabilities ht_cap;
1776 struct ieee80211_vht_capabilities vht_cap;
1777
1778 /*
1779 * Remove the STA entry to ensure the STA PS state gets cleared and
1780 * configuration gets updated. This is relevant for cases, such as
1781 * FT-over-the-DS, where a station re-associates back to the same AP but
1782 * skips the authentication flow, or if working with a driver that
1783 * does not support full AP client state.
1784 */
1785 if (!sta->added_unassoc)
1786 hostapd_drv_sta_remove(hapd, sta->addr);
1787
1788#ifdef CONFIG_IEEE80211N
1789 if (sta->flags & WLAN_STA_HT)
1790 hostapd_get_ht_capab(hapd, sta->ht_capabilities, &ht_cap);
1791#endif /* CONFIG_IEEE80211N */
1792#ifdef CONFIG_IEEE80211AC
1793 if (sta->flags & WLAN_STA_VHT)
1794 hostapd_get_vht_capab(hapd, sta->vht_capabilities, &vht_cap);
1795#endif /* CONFIG_IEEE80211AC */
1796
1797 /*
1798 * Add the station with forced WLAN_STA_ASSOC flag. The sta->flags
1799 * will be set when the ACK frame for the (Re)Association Response frame
1800 * is processed (TX status driver event).
1801 */
1802 if (hostapd_sta_add(hapd, sta->addr, sta->aid, sta->capability,
1803 sta->supported_rates, sta->supported_rates_len,
1804 sta->listen_interval,
1805 sta->flags & WLAN_STA_HT ? &ht_cap : NULL,
1806 sta->flags & WLAN_STA_VHT ? &vht_cap : NULL,
1807 sta->flags | WLAN_STA_ASSOC, sta->qosinfo,
ae33239c
AB
1808 sta->vht_opmode, sta->p2p_ie ? 1 : 0,
1809 sta->added_unassoc)) {
3f81ac07
AO
1810 hostapd_logger(hapd, sta->addr,
1811 HOSTAPD_MODULE_IEEE80211, HOSTAPD_LEVEL_NOTICE,
1812 "Could not %s STA to kernel driver",
1813 sta->added_unassoc ? "set" : "add");
1814
1815 if (sta->added_unassoc) {
1816 hostapd_drv_sta_remove(hapd, sta->addr);
1817 sta->added_unassoc = 0;
1818 }
1819
1820 return -1;
1821 }
1822
1823 sta->added_unassoc = 0;
1824
1825 return 0;
1826}
1827
1828
bb598c3b
AB
1829static u16 send_assoc_resp(struct hostapd_data *hapd, struct sta_info *sta,
1830 u16 status_code, int reassoc, const u8 *ies,
1831 size_t ies_len)
5586f500
JM
1832{
1833 int send_len;
1834 u8 buf[sizeof(struct ieee80211_mgmt) + 1024];
1835 struct ieee80211_mgmt *reply;
1836 u8 *p;
1837
1838 os_memset(buf, 0, sizeof(buf));
1839 reply = (struct ieee80211_mgmt *) buf;
1840 reply->frame_control =
1841 IEEE80211_FC(WLAN_FC_TYPE_MGMT,
1842 (reassoc ? WLAN_FC_STYPE_REASSOC_RESP :
1843 WLAN_FC_STYPE_ASSOC_RESP));
1844 os_memcpy(reply->da, sta->addr, ETH_ALEN);
1845 os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN);
1846 os_memcpy(reply->bssid, hapd->own_addr, ETH_ALEN);
1847
1848 send_len = IEEE80211_HDRLEN;
1849 send_len += sizeof(reply->u.assoc_resp);
1850 reply->u.assoc_resp.capab_info =
f41ded6f 1851 host_to_le16(hostapd_own_capab_info(hapd));
5586f500 1852 reply->u.assoc_resp.status_code = host_to_le16(status_code);
93a1caec 1853 reply->u.assoc_resp.aid = host_to_le16(sta->aid | BIT(14) | BIT(15));
5586f500
JM
1854 /* Supported rates */
1855 p = hostapd_eid_supp_rates(hapd, reply->u.assoc_resp.variable);
1856 /* Extended supported rates */
1857 p = hostapd_eid_ext_supp_rates(hapd, p);
5586f500
JM
1858
1859#ifdef CONFIG_IEEE80211R
1860 if (status_code == WLAN_STATUS_SUCCESS) {
1861 /* IEEE 802.11r: Mobility Domain Information, Fast BSS
1862 * Transition Information, RSN, [RIC Response] */
1863 p = wpa_sm_write_assoc_resp_ies(sta->wpa_sm, p,
1864 buf + sizeof(buf) - p,
1865 sta->auth_alg, ies, ies_len);
1866 }
1867#endif /* CONFIG_IEEE80211R */
1868
1869#ifdef CONFIG_IEEE80211W
1870 if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY)
1871 p = hostapd_eid_assoc_comeback_time(hapd, sta, p);
1872#endif /* CONFIG_IEEE80211W */
1873
1bc774a1
JM
1874#ifdef CONFIG_IEEE80211N
1875 p = hostapd_eid_ht_capabilities(hapd, p);
1876 p = hostapd_eid_ht_operation(hapd, p);
1877#endif /* CONFIG_IEEE80211N */
1878
14708b50 1879#ifdef CONFIG_IEEE80211AC
e7d0e97b
YL
1880 if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac) {
1881 p = hostapd_eid_vht_capabilities(hapd, p);
1882 p = hostapd_eid_vht_operation(hapd, p);
1883 }
14708b50
MP
1884#endif /* CONFIG_IEEE80211AC */
1885
1161ff1e 1886 p = hostapd_eid_ext_capab(hapd, p);
b6668734 1887 p = hostapd_eid_bss_max_idle_period(hapd, p);
c551700f
KP
1888 if (sta->qos_map_enabled)
1889 p = hostapd_eid_qos_map_set(hapd, p);
1161ff1e 1890
347827ff
AN
1891#ifdef CONFIG_FST
1892 if (hapd->iface->fst_ies) {
1893 os_memcpy(p, wpabuf_head(hapd->iface->fst_ies),
1894 wpabuf_len(hapd->iface->fst_ies));
1895 p += wpabuf_len(hapd->iface->fst_ies);
1896 }
1897#endif /* CONFIG_FST */
1898
e7d0e97b
YL
1899#ifdef CONFIG_IEEE80211AC
1900 if (hapd->conf->vendor_vht && (sta->flags & WLAN_STA_VENDOR_VHT))
1901 p = hostapd_eid_vendor_vht(hapd, p);
1902#endif /* CONFIG_IEEE80211AC */
1903
1bc774a1
JM
1904 if (sta->flags & WLAN_STA_WMM)
1905 p = hostapd_eid_wmm(hapd, p);
1906
ed7a09f9 1907#ifdef CONFIG_WPS
71093e5e
JM
1908 if ((sta->flags & WLAN_STA_WPS) ||
1909 ((sta->flags & WLAN_STA_MAYBE_WPS) && hapd->conf->wpa)) {
ed7a09f9
JM
1910 struct wpabuf *wps = wps_build_assoc_resp_ie();
1911 if (wps) {
1912 os_memcpy(p, wpabuf_head(wps), wpabuf_len(wps));
1913 p += wpabuf_len(wps);
1914 wpabuf_free(wps);
1915 }
1916 }
1917#endif /* CONFIG_WPS */
1918
8ccbe415 1919#ifdef CONFIG_P2P
4f6cd3f4 1920 if (sta->p2p_ie && hapd->p2p_group) {
8ccbe415
JM
1921 struct wpabuf *p2p_resp_ie;
1922 enum p2p_status_code status;
1923 switch (status_code) {
1924 case WLAN_STATUS_SUCCESS:
1925 status = P2P_SC_SUCCESS;
1926 break;
1927 case WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA:
1928 status = P2P_SC_FAIL_LIMIT_REACHED;
1929 break;
1930 default:
1931 status = P2P_SC_FAIL_INVALID_PARAMS;
1932 break;
1933 }
1934 p2p_resp_ie = p2p_group_assoc_resp_ie(hapd->p2p_group, status);
1935 if (p2p_resp_ie) {
1936 os_memcpy(p, wpabuf_head(p2p_resp_ie),
1937 wpabuf_len(p2p_resp_ie));
1938 p += wpabuf_len(p2p_resp_ie);
1939 wpabuf_free(p2p_resp_ie);
1940 }
1941 }
1942#endif /* CONFIG_P2P */
1943
962473c1
JM
1944#ifdef CONFIG_P2P_MANAGER
1945 if (hapd->conf->p2p & P2P_MANAGE)
1946 p = hostapd_eid_p2p_manage(hapd, p);
1947#endif /* CONFIG_P2P_MANAGER */
1948
fb9a1c3e
AS
1949 p = hostapd_eid_mbo(hapd, p, buf + sizeof(buf) - p);
1950
5586f500
JM
1951 send_len += p - reply->u.assoc_resp.variable;
1952
bb598c3b 1953 if (hostapd_drv_send_mlme(hapd, reply, send_len, 0) < 0) {
5586f500
JM
1954 wpa_printf(MSG_INFO, "Failed to send assoc resp: %s",
1955 strerror(errno));
bb598c3b
AB
1956 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1957 }
1958
1959 return WLAN_STATUS_SUCCESS;
5586f500
JM
1960}
1961
1962
1963static void handle_assoc(struct hostapd_data *hapd,
b57e086c
JM
1964 const struct ieee80211_mgmt *mgmt, size_t len,
1965 int reassoc)
5586f500 1966{
38cb0a2d 1967 u16 capab_info, listen_interval, seq_ctrl, fc;
bb598c3b 1968 u16 resp = WLAN_STATUS_SUCCESS, reply_res;
b57e086c 1969 const u8 *pos;
5586f500
JM
1970 int left, i;
1971 struct sta_info *sta;
1972
1973 if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_req) :
1974 sizeof(mgmt->u.assoc_req))) {
61323e70
JM
1975 wpa_printf(MSG_INFO, "handle_assoc(reassoc=%d) - too short payload (len=%lu)",
1976 reassoc, (unsigned long) len);
5586f500
JM
1977 return;
1978 }
1979
c2aff6b1
JB
1980#ifdef CONFIG_TESTING_OPTIONS
1981 if (reassoc) {
06df2aa6 1982 if (hapd->iconf->ignore_reassoc_probability > 0.0 &&
c2aff6b1
JB
1983 drand48() < hapd->iconf->ignore_reassoc_probability) {
1984 wpa_printf(MSG_INFO,
1985 "TESTING: ignoring reassoc request from "
1986 MACSTR, MAC2STR(mgmt->sa));
1987 return;
1988 }
1989 } else {
06df2aa6 1990 if (hapd->iconf->ignore_assoc_probability > 0.0 &&
c2aff6b1
JB
1991 drand48() < hapd->iconf->ignore_assoc_probability) {
1992 wpa_printf(MSG_INFO,
1993 "TESTING: ignoring assoc request from "
1994 MACSTR, MAC2STR(mgmt->sa));
1995 return;
1996 }
1997 }
1998#endif /* CONFIG_TESTING_OPTIONS */
1999
38cb0a2d
IP
2000 fc = le_to_host16(mgmt->frame_control);
2001 seq_ctrl = le_to_host16(mgmt->seq_ctrl);
2002
5586f500
JM
2003 if (reassoc) {
2004 capab_info = le_to_host16(mgmt->u.reassoc_req.capab_info);
2005 listen_interval = le_to_host16(
2006 mgmt->u.reassoc_req.listen_interval);
2007 wpa_printf(MSG_DEBUG, "reassociation request: STA=" MACSTR
2008 " capab_info=0x%02x listen_interval=%d current_ap="
38cb0a2d 2009 MACSTR " seq_ctrl=0x%x%s",
5586f500 2010 MAC2STR(mgmt->sa), capab_info, listen_interval,
38cb0a2d
IP
2011 MAC2STR(mgmt->u.reassoc_req.current_ap),
2012 seq_ctrl, (fc & WLAN_FC_RETRY) ? " retry" : "");
5586f500
JM
2013 left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.reassoc_req));
2014 pos = mgmt->u.reassoc_req.variable;
2015 } else {
2016 capab_info = le_to_host16(mgmt->u.assoc_req.capab_info);
2017 listen_interval = le_to_host16(
2018 mgmt->u.assoc_req.listen_interval);
2019 wpa_printf(MSG_DEBUG, "association request: STA=" MACSTR
38cb0a2d
IP
2020 " capab_info=0x%02x listen_interval=%d "
2021 "seq_ctrl=0x%x%s",
2022 MAC2STR(mgmt->sa), capab_info, listen_interval,
2023 seq_ctrl, (fc & WLAN_FC_RETRY) ? " retry" : "");
5586f500
JM
2024 left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.assoc_req));
2025 pos = mgmt->u.assoc_req.variable;
2026 }
2027
2028 sta = ap_get_sta(hapd, mgmt->sa);
2029#ifdef CONFIG_IEEE80211R
2030 if (sta && sta->auth_alg == WLAN_AUTH_FT &&
2031 (sta->flags & WLAN_STA_AUTH) == 0) {
2032 wpa_printf(MSG_DEBUG, "FT: Allow STA " MACSTR " to associate "
2033 "prior to authentication since it is using "
2034 "over-the-DS FT", MAC2STR(mgmt->sa));
bb598c3b
AB
2035
2036 /*
2037 * Mark station as authenticated, to avoid adding station
2038 * entry in the driver as associated and not authenticated
2039 */
2040 sta->flags |= WLAN_STA_AUTH;
5586f500
JM
2041 } else
2042#endif /* CONFIG_IEEE80211R */
2043 if (sta == NULL || (sta->flags & WLAN_STA_AUTH) == 0) {
2044 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2045 HOSTAPD_LEVEL_INFO, "Station tried to "
2046 "associate before authentication "
2047 "(aid=%d flags=0x%x)",
2048 sta ? sta->aid : -1,
2049 sta ? sta->flags : 0);
2050 send_deauth(hapd, mgmt->sa,
2051 WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA);
2052 return;
2053 }
2054
38cb0a2d
IP
2055 if ((fc & WLAN_FC_RETRY) &&
2056 sta->last_seq_ctrl != WLAN_INVALID_MGMT_SEQ &&
2057 sta->last_seq_ctrl == seq_ctrl &&
2058 sta->last_subtype == reassoc ? WLAN_FC_STYPE_REASSOC_REQ :
2059 WLAN_FC_STYPE_ASSOC_REQ) {
2060 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2061 HOSTAPD_LEVEL_DEBUG,
2062 "Drop repeated association frame seq_ctrl=0x%x",
2063 seq_ctrl);
2064 return;
2065 }
2066 sta->last_seq_ctrl = seq_ctrl;
2067 sta->last_subtype = reassoc ? WLAN_FC_STYPE_REASSOC_REQ :
2068 WLAN_FC_STYPE_ASSOC_REQ;
2069
5586f500
JM
2070 if (hapd->tkip_countermeasures) {
2071 resp = WLAN_REASON_MICHAEL_MIC_FAILURE;
2072 goto fail;
2073 }
2074
2075 if (listen_interval > hapd->conf->max_listen_interval) {
2076 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2077 HOSTAPD_LEVEL_DEBUG,
2078 "Too large Listen Interval (%d)",
2079 listen_interval);
2080 resp = WLAN_STATUS_ASSOC_DENIED_LISTEN_INT_TOO_LARGE;
2081 goto fail;
2082 }
2083
fb9a1c3e
AS
2084#ifdef CONFIG_MBO
2085 if (hapd->conf->mbo_enabled && hapd->mbo_assoc_disallow) {
2086 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
2087 goto fail;
2088 }
2089#endif /* CONFIG_MBO */
2090
5586f500
JM
2091 /* followed by SSID and Supported rates; and HT capabilities if 802.11n
2092 * is used */
2093 resp = check_assoc_ies(hapd, sta, pos, left, reassoc);
2094 if (resp != WLAN_STATUS_SUCCESS)
2095 goto fail;
2096
2097 if (hostapd_get_aid(hapd, sta) < 0) {
2098 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2099 HOSTAPD_LEVEL_INFO, "No room for more AIDs");
2100 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
2101 goto fail;
2102 }
2103
2104 sta->capability = capab_info;
2105 sta->listen_interval = listen_interval;
2106
6fc6879b
JM
2107 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
2108 sta->flags |= WLAN_STA_NONERP;
2109 for (i = 0; i < sta->supported_rates_len; i++) {
2110 if ((sta->supported_rates[i] & 0x7f) > 22) {
2111 sta->flags &= ~WLAN_STA_NONERP;
2112 break;
2113 }
2114 }
2115 if (sta->flags & WLAN_STA_NONERP && !sta->nonerp_set) {
2116 sta->nonerp_set = 1;
2117 hapd->iface->num_sta_non_erp++;
2118 if (hapd->iface->num_sta_non_erp == 1)
2119 ieee802_11_set_beacons(hapd->iface);
2120 }
2121
2122 if (!(sta->capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) &&
2123 !sta->no_short_slot_time_set) {
2124 sta->no_short_slot_time_set = 1;
2125 hapd->iface->num_sta_no_short_slot_time++;
2126 if (hapd->iface->current_mode->mode ==
2127 HOSTAPD_MODE_IEEE80211G &&
2128 hapd->iface->num_sta_no_short_slot_time == 1)
2129 ieee802_11_set_beacons(hapd->iface);
2130 }
2131
2132 if (sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
2133 sta->flags |= WLAN_STA_SHORT_PREAMBLE;
2134 else
2135 sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
2136
2137 if (!(sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) &&
2138 !sta->no_short_preamble_set) {
2139 sta->no_short_preamble_set = 1;
2140 hapd->iface->num_sta_no_short_preamble++;
2141 if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G
2142 && hapd->iface->num_sta_no_short_preamble == 1)
2143 ieee802_11_set_beacons(hapd->iface);
2144 }
2145
d45354be 2146#ifdef CONFIG_IEEE80211N
5586f500 2147 update_ht_state(hapd, sta);
d45354be 2148#endif /* CONFIG_IEEE80211N */
de9289c8 2149
6fc6879b
JM
2150 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2151 HOSTAPD_LEVEL_DEBUG,
2152 "association OK (aid %d)", sta->aid);
2153 /* Station will be marked associated, after it acknowledges AssocResp
2154 */
b8281964 2155 sta->flags |= WLAN_STA_ASSOC_REQ_OK;
6fc6879b 2156
6f5c8dbd
JM
2157#ifdef CONFIG_IEEE80211W
2158 if ((sta->flags & WLAN_STA_MFP) && sta->sa_query_timed_out) {
2159 wpa_printf(MSG_DEBUG, "Allowing %sassociation after timed out "
2160 "SA Query procedure", reassoc ? "re" : "");
2161 /* TODO: Send a protected Disassociate frame to the STA using
2162 * the old key and Reason Code "Previous Authentication no
2163 * longer valid". Make sure this is only sent protected since
2164 * unprotected frame would be received by the STA that is now
2165 * trying to associate.
2166 */
2167 }
2168#endif /* CONFIG_IEEE80211W */
2169
6fc6879b
JM
2170 /* Make sure that the previously registered inactivity timer will not
2171 * remove the STA immediately. */
2172 sta->timeout_next = STA_NULLFUNC;
2173
2174 fail:
3f81ac07
AO
2175 /*
2176 * In case of a successful response, add the station to the driver.
2177 * Otherwise, the kernel may ignore Data frames before we process the
2178 * ACK frame (TX status). In case of a failure, this station will be
2179 * removed.
2180 *
2181 * Note that this is not compliant with the IEEE 802.11 standard that
2182 * states that a non-AP station should transition into the
2183 * authenticated/associated state only after the station acknowledges
2184 * the (Re)Association Response frame. However, still do this as:
2185 *
2186 * 1. In case the station does not acknowledge the (Re)Association
2187 * Response frame, it will be removed.
2188 * 2. Data frames will be dropped in the kernel until the station is
2189 * set into authorized state, and there are no significant known
2190 * issues with processing other non-Data Class 3 frames during this
2191 * window.
2192 */
2193 if (resp == WLAN_STATUS_SUCCESS && add_associated_sta(hapd, sta))
2194 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
2195
bb598c3b 2196 reply_res = send_assoc_resp(hapd, sta, resp, reassoc, pos, left);
3f81ac07
AO
2197
2198 /*
2199 * Remove the station in case tranmission of a success response fails
2200 * (the STA was added associated to the driver) or if the station was
2201 * previously added unassociated.
2202 */
2203 if ((reply_res != WLAN_STATUS_SUCCESS &&
2204 resp == WLAN_STATUS_SUCCESS) || sta->added_unassoc) {
bb598c3b
AB
2205 hostapd_drv_sta_remove(hapd, sta->addr);
2206 sta->added_unassoc = 0;
2207 }
6fc6879b
JM
2208}
2209
2210
6fc6879b 2211static void handle_disassoc(struct hostapd_data *hapd,
f8b1f695 2212 const struct ieee80211_mgmt *mgmt, size_t len)
6fc6879b
JM
2213{
2214 struct sta_info *sta;
2215
2216 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.disassoc)) {
61323e70
JM
2217 wpa_printf(MSG_INFO, "handle_disassoc - too short payload (len=%lu)",
2218 (unsigned long) len);
6fc6879b
JM
2219 return;
2220 }
2221
2222 wpa_printf(MSG_DEBUG, "disassocation: STA=" MACSTR " reason_code=%d",
2223 MAC2STR(mgmt->sa),
2224 le_to_host16(mgmt->u.disassoc.reason_code));
2225
6fc6879b
JM
2226 sta = ap_get_sta(hapd, mgmt->sa);
2227 if (sta == NULL) {
61323e70
JM
2228 wpa_printf(MSG_INFO, "Station " MACSTR " trying to disassociate, but it is not associated",
2229 MAC2STR(mgmt->sa));
6fc6879b
JM
2230 return;
2231 }
2232
ae055af4 2233 ap_sta_set_authorized(hapd, sta, 0);
38cb0a2d 2234 sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ;
b8281964 2235 sta->flags &= ~(WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK);
6fc6879b
JM
2236 wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC);
2237 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2238 HOSTAPD_LEVEL_INFO, "disassociated");
2239 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
2240 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
2241 /* Stop Accounting and IEEE 802.1X sessions, but leave the STA
2242 * authenticated. */
2243 accounting_sta_stop(hapd, sta);
d7c3347f 2244 ieee802_1x_free_station(hapd, sta);
7d597d46 2245 if (sta->ipaddr)
ed4ddb6d 2246 hostapd_drv_br_delete_ip_neigh(hapd, 4, (u8 *) &sta->ipaddr);
bd00c431 2247 ap_sta_ip6addr_del(hapd, sta);
51e2a27a 2248 hostapd_drv_sta_remove(hapd, sta->addr);
bb598c3b 2249 sta->added_unassoc = 0;
6fc6879b
JM
2250
2251 if (sta->timeout_next == STA_NULLFUNC ||
2252 sta->timeout_next == STA_DISASSOC) {
2253 sta->timeout_next = STA_DEAUTH;
2254 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
2255 eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer,
2256 hapd, sta);
2257 }
2258
2259 mlme_disassociate_indication(
2260 hapd, sta, le_to_host16(mgmt->u.disassoc.reason_code));
2261}
2262
2263
2264static void handle_deauth(struct hostapd_data *hapd,
f8b1f695 2265 const struct ieee80211_mgmt *mgmt, size_t len)
6fc6879b
JM
2266{
2267 struct sta_info *sta;
2268
2269 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.deauth)) {
3ec1e902
JM
2270 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "handle_deauth - too short "
2271 "payload (len=%lu)", (unsigned long) len);
6fc6879b
JM
2272 return;
2273 }
2274
3ec1e902 2275 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "deauthentication: STA=" MACSTR
24d75245
BG
2276 " reason_code=%d",
2277 MAC2STR(mgmt->sa), le_to_host16(mgmt->u.deauth.reason_code));
6fc6879b 2278
6fc6879b
JM
2279 sta = ap_get_sta(hapd, mgmt->sa);
2280 if (sta == NULL) {
3ec1e902
JM
2281 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR " trying "
2282 "to deauthenticate, but it is not authenticated",
24d75245 2283 MAC2STR(mgmt->sa));
6fc6879b
JM
2284 return;
2285 }
2286
ae055af4 2287 ap_sta_set_authorized(hapd, sta, 0);
38cb0a2d 2288 sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ;
b8281964
JM
2289 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC |
2290 WLAN_STA_ASSOC_REQ_OK);
6fc6879b
JM
2291 wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH);
2292 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2293 HOSTAPD_LEVEL_DEBUG, "deauthenticated");
2294 mlme_deauthenticate_indication(
2295 hapd, sta, le_to_host16(mgmt->u.deauth.reason_code));
2296 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
2297 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
2298 ap_free_sta(hapd, sta);
2299}
2300
2301
2302static void handle_beacon(struct hostapd_data *hapd,
b57e086c 2303 const struct ieee80211_mgmt *mgmt, size_t len,
6fc6879b
JM
2304 struct hostapd_frame_info *fi)
2305{
2306 struct ieee802_11_elems elems;
2307
2308 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.beacon)) {
61323e70
JM
2309 wpa_printf(MSG_INFO, "handle_beacon - too short payload (len=%lu)",
2310 (unsigned long) len);
6fc6879b
JM
2311 return;
2312 }
2313
3d536eb4 2314 (void) ieee802_11_parse_elems(mgmt->u.beacon.variable,
6fc6879b
JM
2315 len - (IEEE80211_HDRLEN +
2316 sizeof(mgmt->u.beacon)), &elems,
2317 0);
2318
6fc6879b
JM
2319 ap_list_process_beacon(hapd->iface, mgmt, &elems, fi);
2320}
2321
2322
5d22a1d5 2323#ifdef CONFIG_IEEE80211W
88b4b424 2324
912b34f0
JM
2325static int hostapd_sa_query_action(struct hostapd_data *hapd,
2326 const struct ieee80211_mgmt *mgmt,
2327 size_t len)
5d22a1d5 2328{
b57e086c 2329 const u8 *end;
5d22a1d5 2330
93b76319
JM
2331 end = mgmt->u.action.u.sa_query_resp.trans_id +
2332 WLAN_SA_QUERY_TR_ID_LEN;
5d22a1d5 2333 if (((u8 *) mgmt) + len < end) {
93b76319 2334 wpa_printf(MSG_DEBUG, "IEEE 802.11: Too short SA Query Action "
5d22a1d5 2335 "frame (len=%lu)", (unsigned long) len);
912b34f0 2336 return 0;
5d22a1d5
JM
2337 }
2338
d4370eac
MP
2339 ieee802_11_sa_query_action(hapd, mgmt->sa,
2340 mgmt->u.action.u.sa_query_resp.action,
2341 mgmt->u.action.u.sa_query_resp.trans_id);
912b34f0 2342 return 1;
5d22a1d5 2343}
5d22a1d5
JM
2344
2345
c4e281fd
JM
2346static int robust_action_frame(u8 category)
2347{
2348 return category != WLAN_ACTION_PUBLIC &&
2349 category != WLAN_ACTION_HT;
2350}
9f64b827 2351#endif /* CONFIG_IEEE80211W */
c4e281fd
JM
2352
2353
912b34f0
JM
2354static int handle_action(struct hostapd_data *hapd,
2355 const struct ieee80211_mgmt *mgmt, size_t len)
6fc6879b 2356{
c4e281fd 2357 struct sta_info *sta;
46eeedac 2358 sta = ap_get_sta(hapd, mgmt->sa);
c4e281fd 2359
6fc6879b
JM
2360 if (len < IEEE80211_HDRLEN + 1) {
2361 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2362 HOSTAPD_LEVEL_DEBUG,
2363 "handle_action - too short payload (len=%lu)",
2364 (unsigned long) len);
912b34f0 2365 return 0;
6fc6879b
JM
2366 }
2367
c79938a5
JM
2368 if (mgmt->u.action.category != WLAN_ACTION_PUBLIC &&
2369 (sta == NULL || !(sta->flags & WLAN_STA_ASSOC))) {
2370 wpa_printf(MSG_DEBUG, "IEEE 802.11: Ignored Action "
2371 "frame (category=%u) from unassociated STA " MACSTR,
2372 MAC2STR(mgmt->sa), mgmt->u.action.category);
912b34f0 2373 return 0;
c79938a5
JM
2374 }
2375
c4e281fd
JM
2376#ifdef CONFIG_IEEE80211W
2377 if (sta && (sta->flags & WLAN_STA_MFP) &&
7b2c42f8
JM
2378 !(mgmt->frame_control & host_to_le16(WLAN_FC_ISWEP)) &&
2379 robust_action_frame(mgmt->u.action.category)) {
c4e281fd
JM
2380 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2381 HOSTAPD_LEVEL_DEBUG,
2382 "Dropped unprotected Robust Action frame from "
2383 "an MFP STA");
912b34f0 2384 return 0;
c4e281fd
JM
2385 }
2386#endif /* CONFIG_IEEE80211W */
2387
38cb0a2d
IP
2388 if (sta) {
2389 u16 fc = le_to_host16(mgmt->frame_control);
2390 u16 seq_ctrl = le_to_host16(mgmt->seq_ctrl);
2391
2392 if ((fc & WLAN_FC_RETRY) &&
2393 sta->last_seq_ctrl != WLAN_INVALID_MGMT_SEQ &&
2394 sta->last_seq_ctrl == seq_ctrl &&
2395 sta->last_subtype == WLAN_FC_STYPE_ACTION) {
2396 hostapd_logger(hapd, sta->addr,
2397 HOSTAPD_MODULE_IEEE80211,
2398 HOSTAPD_LEVEL_DEBUG,
2399 "Drop repeated action frame seq_ctrl=0x%x",
2400 seq_ctrl);
2401 return 1;
2402 }
2403
2404 sta->last_seq_ctrl = seq_ctrl;
2405 sta->last_subtype = WLAN_FC_STYPE_ACTION;
2406 }
2407
6fc6879b
JM
2408 switch (mgmt->u.action.category) {
2409#ifdef CONFIG_IEEE80211R
2410 case WLAN_ACTION_FT:
d6c6b1fb
JM
2411 if (!sta ||
2412 wpa_ft_action_rx(sta->wpa_sm, (u8 *) &mgmt->u.action,
6fc6879b
JM
2413 len - IEEE80211_HDRLEN))
2414 break;
912b34f0 2415 return 1;
6fc6879b 2416#endif /* CONFIG_IEEE80211R */
c2a71408 2417 case WLAN_ACTION_WMM:
3ae0800c 2418 hostapd_wmm_action(hapd, mgmt, len);
912b34f0 2419 return 1;
5d22a1d5 2420#ifdef CONFIG_IEEE80211W
93b76319 2421 case WLAN_ACTION_SA_QUERY:
912b34f0 2422 return hostapd_sa_query_action(hapd, mgmt, len);
5d22a1d5 2423#endif /* CONFIG_IEEE80211W */
c79938a5
JM
2424#ifdef CONFIG_WNM
2425 case WLAN_ACTION_WNM:
dbfb8e82
JM
2426 ieee802_11_rx_wnm_action_ap(hapd, mgmt, len);
2427 return 1;
c79938a5 2428#endif /* CONFIG_WNM */
037378ff
AN
2429#ifdef CONFIG_FST
2430 case WLAN_ACTION_FST:
2431 if (hapd->iface->fst)
2432 fst_rx_action(hapd->iface->fst, mgmt, len);
94edea89
JM
2433 else
2434 wpa_printf(MSG_DEBUG,
2435 "FST: Ignore FST Action frame - no FST attached");
037378ff
AN
2436 return 1;
2437#endif /* CONFIG_FST */
c706d5aa 2438 case WLAN_ACTION_PUBLIC:
5ce00d09 2439 case WLAN_ACTION_PROTECTED_DUAL:
587d60d2 2440#ifdef CONFIG_IEEE80211N
fd66aa63
JM
2441 if (len >= IEEE80211_HDRLEN + 2 &&
2442 mgmt->u.action.u.public_action.action ==
587d60d2
PX
2443 WLAN_PA_20_40_BSS_COEX) {
2444 wpa_printf(MSG_DEBUG,
2445 "HT20/40 coex mgmt frame received from STA "
2446 MACSTR, MAC2STR(mgmt->sa));
2447 hostapd_2040_coex_action(hapd, mgmt, len);
2448 }
2449#endif /* CONFIG_IEEE80211N */
c706d5aa
JM
2450 if (hapd->public_action_cb) {
2451 hapd->public_action_cb(hapd->public_action_cb_ctx,
2452 (u8 *) mgmt, len,
2453 hapd->iface->freq);
c706d5aa 2454 }
2d9ffe1e 2455 if (hapd->public_action_cb2) {
8dabf4bb 2456 hapd->public_action_cb2(hapd->public_action_cb2_ctx,
2d9ffe1e
JM
2457 (u8 *) mgmt, len,
2458 hapd->iface->freq);
2459 }
2460 if (hapd->public_action_cb || hapd->public_action_cb2)
912b34f0 2461 return 1;
c706d5aa 2462 break;
e44f8bf2
JM
2463 case WLAN_ACTION_VENDOR_SPECIFIC:
2464 if (hapd->vendor_action_cb) {
2465 if (hapd->vendor_action_cb(hapd->vendor_action_cb_ctx,
2466 (u8 *) mgmt, len,
2467 hapd->iface->freq) == 0)
912b34f0 2468 return 1;
e44f8bf2
JM
2469 }
2470 break;
6fc6879b
JM
2471 }
2472
2473 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2474 HOSTAPD_LEVEL_DEBUG,
2475 "handle_action - unknown action category %d or invalid "
2476 "frame",
2477 mgmt->u.action.category);
2478 if (!(mgmt->da[0] & 0x01) && !(mgmt->u.action.category & 0x80) &&
2479 !(mgmt->sa[0] & 0x01)) {
b57e086c
JM
2480 struct ieee80211_mgmt *resp;
2481
6fc6879b
JM
2482 /*
2483 * IEEE 802.11-REVma/D9.0 - 7.3.1.11
2484 * Return the Action frame to the source without change
2485 * except that MSB of the Category set to 1.
2486 */
2487 wpa_printf(MSG_DEBUG, "IEEE 802.11: Return unknown Action "
2488 "frame back to sender");
b57e086c
JM
2489 resp = os_malloc(len);
2490 if (resp == NULL)
912b34f0 2491 return 0;
b57e086c
JM
2492 os_memcpy(resp, mgmt, len);
2493 os_memcpy(resp->da, resp->sa, ETH_ALEN);
2494 os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN);
2495 os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN);
2496 resp->u.action.category |= 0x80;
2497
41fe8b42
JM
2498 if (hostapd_drv_send_mlme(hapd, resp, len, 0) < 0) {
2499 wpa_printf(MSG_ERROR, "IEEE 802.11: Failed to send "
2500 "Action frame");
2501 }
b57e086c 2502 os_free(resp);
6fc6879b 2503 }
912b34f0
JM
2504
2505 return 1;
6fc6879b
JM
2506}
2507
2508
2509/**
2510 * ieee802_11_mgmt - process incoming IEEE 802.11 management frames
2511 * @hapd: hostapd BSS data structure (the BSS to which the management frame was
2512 * sent to)
2513 * @buf: management frame data (starting from IEEE 802.11 header)
2514 * @len: length of frame data in octets
a17df5fb 2515 * @fi: meta data about received frame (signal level, etc.)
6fc6879b
JM
2516 *
2517 * Process all incoming IEEE 802.11 management frames. This will be called for
2518 * each frame received from the kernel driver through wlan#ap interface. In
2519 * addition, it can be called to re-inserted pending frames (e.g., when using
2520 * external RADIUS server as an MAC ACL).
2521 */
912b34f0
JM
2522int ieee802_11_mgmt(struct hostapd_data *hapd, const u8 *buf, size_t len,
2523 struct hostapd_frame_info *fi)
6fc6879b 2524{
f8b1f695 2525 struct ieee80211_mgmt *mgmt;
6fc6879b 2526 int broadcast;
f8b1f695 2527 u16 fc, stype;
912b34f0 2528 int ret = 0;
f8b1f695 2529
cbcf92b4 2530 if (len < 24)
912b34f0 2531 return 0;
cbcf92b4 2532
f8b1f695
JM
2533 mgmt = (struct ieee80211_mgmt *) buf;
2534 fc = le_to_host16(mgmt->frame_control);
2535 stype = WLAN_FC_GET_STYPE(fc);
6fc6879b
JM
2536
2537 if (stype == WLAN_FC_STYPE_BEACON) {
2538 handle_beacon(hapd, mgmt, len, fi);
912b34f0 2539 return 1;
6fc6879b
JM
2540 }
2541
6fc6879b
JM
2542 broadcast = mgmt->bssid[0] == 0xff && mgmt->bssid[1] == 0xff &&
2543 mgmt->bssid[2] == 0xff && mgmt->bssid[3] == 0xff &&
2544 mgmt->bssid[4] == 0xff && mgmt->bssid[5] == 0xff;
2545
2546 if (!broadcast &&
3eeee931
AN
2547#ifdef CONFIG_P2P
2548 /* Invitation responses can be sent with the peer MAC as BSSID */
2549 !((hapd->conf->p2p & P2P_GROUP_OWNER) &&
2550 stype == WLAN_FC_STYPE_ACTION) &&
2551#endif /* CONFIG_P2P */
f3e9899e
BC
2552#ifdef CONFIG_MESH
2553 !(hapd->conf->mesh & MESH_ENABLED) &&
2554#endif /* CONFIG_MESH */
fe2c5241 2555 os_memcmp(mgmt->bssid, hapd->own_addr, ETH_ALEN) != 0) {
61323e70
JM
2556 wpa_printf(MSG_INFO, "MGMT: BSSID=" MACSTR " not our address",
2557 MAC2STR(mgmt->bssid));
912b34f0 2558 return 0;
6fc6879b
JM
2559 }
2560
2561
2562 if (stype == WLAN_FC_STYPE_PROBE_REQ) {
baf513d6 2563 handle_probe_req(hapd, mgmt, len, fi->ssi_signal);
912b34f0 2564 return 1;
6fc6879b
JM
2565 }
2566
2567 if (os_memcmp(mgmt->da, hapd->own_addr, ETH_ALEN) != 0) {
2568 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2569 HOSTAPD_LEVEL_DEBUG,
2570 "MGMT: DA=" MACSTR " not our address",
2571 MAC2STR(mgmt->da));
912b34f0 2572 return 0;
6fc6879b
JM
2573 }
2574
b308a304
JM
2575 if (hapd->iconf->track_sta_max_num)
2576 sta_track_add(hapd->iface, mgmt->sa);
2577
6fc6879b
JM
2578 switch (stype) {
2579 case WLAN_FC_STYPE_AUTH:
2580 wpa_printf(MSG_DEBUG, "mgmt::auth");
2581 handle_auth(hapd, mgmt, len);
912b34f0 2582 ret = 1;
6fc6879b
JM
2583 break;
2584 case WLAN_FC_STYPE_ASSOC_REQ:
2585 wpa_printf(MSG_DEBUG, "mgmt::assoc_req");
2586 handle_assoc(hapd, mgmt, len, 0);
912b34f0 2587 ret = 1;
6fc6879b 2588 break;
6fc6879b
JM
2589 case WLAN_FC_STYPE_REASSOC_REQ:
2590 wpa_printf(MSG_DEBUG, "mgmt::reassoc_req");
2591 handle_assoc(hapd, mgmt, len, 1);
912b34f0 2592 ret = 1;
6fc6879b
JM
2593 break;
2594 case WLAN_FC_STYPE_DISASSOC:
2595 wpa_printf(MSG_DEBUG, "mgmt::disassoc");
2596 handle_disassoc(hapd, mgmt, len);
912b34f0 2597 ret = 1;
6fc6879b
JM
2598 break;
2599 case WLAN_FC_STYPE_DEAUTH:
3ec1e902 2600 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "mgmt::deauth");
6fc6879b 2601 handle_deauth(hapd, mgmt, len);
912b34f0 2602 ret = 1;
6fc6879b
JM
2603 break;
2604 case WLAN_FC_STYPE_ACTION:
2605 wpa_printf(MSG_DEBUG, "mgmt::action");
912b34f0 2606 ret = handle_action(hapd, mgmt, len);
6fc6879b
JM
2607 break;
2608 default:
2609 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
2610 HOSTAPD_LEVEL_DEBUG,
2611 "unknown mgmt frame subtype %d", stype);
2612 break;
2613 }
912b34f0
JM
2614
2615 return ret;
6fc6879b
JM
2616}
2617
2618
2619static void handle_auth_cb(struct hostapd_data *hapd,
f8b1f695 2620 const struct ieee80211_mgmt *mgmt,
6fc6879b
JM
2621 size_t len, int ok)
2622{
2623 u16 auth_alg, auth_transaction, status_code;
2624 struct sta_info *sta;
2625
bb598c3b
AB
2626 sta = ap_get_sta(hapd, mgmt->da);
2627 if (!sta) {
2628 wpa_printf(MSG_INFO, "handle_auth_cb: STA " MACSTR " not found",
2629 MAC2STR(mgmt->da));
2630 return;
2631 }
2632
2633 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
2634 auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
2635 status_code = le_to_host16(mgmt->u.auth.status_code);
2636
6fc6879b
JM
2637 if (!ok) {
2638 hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
2639 HOSTAPD_LEVEL_NOTICE,
2640 "did not acknowledge authentication response");
bb598c3b 2641 goto fail;
6fc6879b
JM
2642 }
2643
2644 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
61323e70
JM
2645 wpa_printf(MSG_INFO, "handle_auth_cb - too short payload (len=%lu)",
2646 (unsigned long) len);
bb598c3b 2647 goto fail;
6fc6879b
JM
2648 }
2649
2650 if (status_code == WLAN_STATUS_SUCCESS &&
2651 ((auth_alg == WLAN_AUTH_OPEN && auth_transaction == 2) ||
2652 (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 4))) {
2653 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2654 HOSTAPD_LEVEL_INFO, "authenticated");
2655 sta->flags |= WLAN_STA_AUTH;
bb598c3b
AB
2656 if (sta->added_unassoc)
2657 hostapd_set_sta_flags(hapd, sta);
2658 return;
2659 }
2660
2661fail:
2662 if (status_code != WLAN_STATUS_SUCCESS && sta->added_unassoc) {
2663 hostapd_drv_sta_remove(hapd, sta->addr);
2664 sta->added_unassoc = 0;
6fc6879b
JM
2665 }
2666}
2667
2668
69dd2967
SM
2669static void hostapd_set_wds_encryption(struct hostapd_data *hapd,
2670 struct sta_info *sta,
2671 char *ifname_wds)
2672{
2673 int i;
f41ded6f 2674 struct hostapd_ssid *ssid = &hapd->conf->ssid;
69dd2967
SM
2675
2676 if (hapd->conf->ieee802_1x || hapd->conf->wpa)
2677 return;
2678
2679 for (i = 0; i < 4; i++) {
2680 if (ssid->wep.key[i] &&
2681 hostapd_drv_set_key(ifname_wds, hapd, WPA_ALG_WEP, NULL, i,
2682 i == ssid->wep.idx, NULL, 0,
2683 ssid->wep.key[i], ssid->wep.len[i])) {
2684 wpa_printf(MSG_WARNING,
2685 "Could not set WEP keys for WDS interface; %s",
2686 ifname_wds);
2687 break;
2688 }
2689 }
2690}
2691
2692
6fc6879b 2693static void handle_assoc_cb(struct hostapd_data *hapd,
f8b1f695 2694 const struct ieee80211_mgmt *mgmt,
6fc6879b
JM
2695 size_t len, int reassoc, int ok)
2696{
2697 u16 status;
2698 struct sta_info *sta;
2699 int new_assoc = 1;
2700
6fc6879b
JM
2701 sta = ap_get_sta(hapd, mgmt->da);
2702 if (!sta) {
61323e70
JM
2703 wpa_printf(MSG_INFO, "handle_assoc_cb: STA " MACSTR " not found",
2704 MAC2STR(mgmt->da));
6fc6879b
JM
2705 return;
2706 }
2707
bb598c3b
AB
2708 if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_resp) :
2709 sizeof(mgmt->u.assoc_resp))) {
2710 wpa_printf(MSG_INFO,
2711 "handle_assoc_cb(reassoc=%d) - too short payload (len=%lu)",
2712 reassoc, (unsigned long) len);
3f81ac07
AO
2713 hostapd_drv_sta_remove(hapd, sta->addr);
2714 return;
bb598c3b
AB
2715 }
2716
3f81ac07
AO
2717 if (reassoc)
2718 status = le_to_host16(mgmt->u.reassoc_resp.status_code);
2719 else
2720 status = le_to_host16(mgmt->u.assoc_resp.status_code);
2721
22b42372
FF
2722 if (!ok) {
2723 hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
2724 HOSTAPD_LEVEL_DEBUG,
2725 "did not acknowledge association response");
2726 sta->flags &= ~WLAN_STA_ASSOC_REQ_OK;
3f81ac07
AO
2727 /* The STA is added only in case of SUCCESS */
2728 if (status == WLAN_STATUS_SUCCESS)
2729 hostapd_drv_sta_remove(hapd, sta->addr);
22b42372 2730
3f81ac07
AO
2731 return;
2732 }
22b42372 2733
6fc6879b 2734 if (status != WLAN_STATUS_SUCCESS)
5bdac4ab 2735 return;
6fc6879b
JM
2736
2737 /* Stop previous accounting session, if one is started, and allocate
2738 * new session id for the new session. */
2739 accounting_sta_stop(hapd, sta);
6fc6879b
JM
2740
2741 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2742 HOSTAPD_LEVEL_INFO,
2fc98d02
JM
2743 "associated (aid %d)",
2744 sta->aid);
6fc6879b
JM
2745
2746 if (sta->flags & WLAN_STA_ASSOC)
2747 new_assoc = 0;
2748 sta->flags |= WLAN_STA_ASSOC;
3578e665 2749 sta->flags &= ~WLAN_STA_WNM_SLEEP_MODE;
a14896e8 2750 if ((!hapd->conf->ieee802_1x && !hapd->conf->wpa && !hapd->conf->osen) ||
ef580012
JM
2751 sta->auth_alg == WLAN_AUTH_FT) {
2752 /*
2753 * Open, static WEP, or FT protocol; no separate authorization
2754 * step.
2755 */
6905dcb1 2756 ap_sta_set_authorized(hapd, sta, 1);
515cf93f 2757 }
6fc6879b
JM
2758
2759 if (reassoc)
2760 mlme_reassociate_indication(hapd, sta);
2761 else
2762 mlme_associate_indication(hapd, sta);
2763
5d22a1d5 2764#ifdef CONFIG_IEEE80211W
93b76319 2765 sta->sa_query_timed_out = 0;
5d22a1d5
JM
2766#endif /* CONFIG_IEEE80211W */
2767
69dd2967
SM
2768 if (sta->flags & WLAN_STA_WDS) {
2769 int ret;
2770 char ifname_wds[IFNAMSIZ + 1];
2771
2772 ret = hostapd_set_wds_sta(hapd, ifname_wds, sta->addr,
2773 sta->aid, 1);
2774 if (!ret)
2775 hostapd_set_wds_encryption(hapd, sta, ifname_wds);
2776 }
7826ceae 2777
6fc6879b
JM
2778 if (sta->eapol_sm == NULL) {
2779 /*
2780 * This STA does not use RADIUS server for EAP authentication,
2781 * so bind it to the selected VLAN interface now, since the
2782 * interface selection is not going to change anymore.
2783 */
c8e6beab 2784 if (ap_sta_bind_vlan(hapd, sta) < 0)
5bdac4ab 2785 return;
6fc6879b
JM
2786 } else if (sta->vlan_id) {
2787 /* VLAN ID already set (e.g., by PMKSA caching), so bind STA */
c8e6beab 2788 if (ap_sta_bind_vlan(hapd, sta) < 0)
5bdac4ab 2789 return;
6fc6879b 2790 }
eddd8010 2791
0e8a96a9 2792 hostapd_set_sta_flags(hapd, sta);
6fc6879b
JM
2793
2794 if (sta->auth_alg == WLAN_AUTH_FT)
2795 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FT);
2796 else
2797 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC);
d24df7c3 2798 hapd->new_assoc_sta_cb(hapd, sta, !new_assoc);
6fc6879b 2799 ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
f2accfe7
EP
2800
2801 if (sta->pending_eapol_rx) {
2802 struct os_reltime now, age;
2803
2804 os_get_reltime(&now);
2805 os_reltime_sub(&now, &sta->pending_eapol_rx->rx_time, &age);
2806 if (age.sec == 0 && age.usec < 200000) {
2807 wpa_printf(MSG_DEBUG,
2808 "Process pending EAPOL frame that was received from " MACSTR " just before association notification",
2809 MAC2STR(sta->addr));
2810 ieee802_1x_receive(
2811 hapd, mgmt->da,
2812 wpabuf_head(sta->pending_eapol_rx->buf),
2813 wpabuf_len(sta->pending_eapol_rx->buf));
2814 }
2815 wpabuf_free(sta->pending_eapol_rx->buf);
2816 os_free(sta->pending_eapol_rx);
2817 sta->pending_eapol_rx = NULL;
2818 }
6fc6879b
JM
2819}
2820
2821
4dc03726
JM
2822static void handle_deauth_cb(struct hostapd_data *hapd,
2823 const struct ieee80211_mgmt *mgmt,
2824 size_t len, int ok)
2825{
2826 struct sta_info *sta;
2827 if (mgmt->da[0] & 0x01)
2828 return;
2829 sta = ap_get_sta(hapd, mgmt->da);
2830 if (!sta) {
2831 wpa_printf(MSG_DEBUG, "handle_deauth_cb: STA " MACSTR
2832 " not found", MAC2STR(mgmt->da));
2833 return;
2834 }
2835 if (ok)
2836 wpa_printf(MSG_DEBUG, "STA " MACSTR " acknowledged deauth",
2837 MAC2STR(sta->addr));
2838 else
2839 wpa_printf(MSG_DEBUG, "STA " MACSTR " did not acknowledge "
2840 "deauth", MAC2STR(sta->addr));
2841
2842 ap_sta_deauth_cb(hapd, sta);
2843}
2844
2845
2846static void handle_disassoc_cb(struct hostapd_data *hapd,
2847 const struct ieee80211_mgmt *mgmt,
2848 size_t len, int ok)
2849{
2850 struct sta_info *sta;
2851 if (mgmt->da[0] & 0x01)
2852 return;
2853 sta = ap_get_sta(hapd, mgmt->da);
2854 if (!sta) {
2855 wpa_printf(MSG_DEBUG, "handle_disassoc_cb: STA " MACSTR
2856 " not found", MAC2STR(mgmt->da));
2857 return;
2858 }
2859 if (ok)
2860 wpa_printf(MSG_DEBUG, "STA " MACSTR " acknowledged disassoc",
2861 MAC2STR(sta->addr));
2862 else
2863 wpa_printf(MSG_DEBUG, "STA " MACSTR " did not acknowledge "
2864 "disassoc", MAC2STR(sta->addr));
2865
2866 ap_sta_disassoc_cb(hapd, sta);
2867}
2868
2869
1c6e69cc
JM
2870/**
2871 * ieee802_11_mgmt_cb - Process management frame TX status callback
2872 * @hapd: hostapd BSS data structure (the BSS from which the management frame
2873 * was sent from)
2874 * @buf: management frame data (starting from IEEE 802.11 header)
2875 * @len: length of frame data in octets
2876 * @stype: management frame subtype from frame control field
2877 * @ok: Whether the frame was ACK'ed
2878 */
f8b1f695 2879void ieee802_11_mgmt_cb(struct hostapd_data *hapd, const u8 *buf, size_t len,
6fc6879b
JM
2880 u16 stype, int ok)
2881{
f8b1f695
JM
2882 const struct ieee80211_mgmt *mgmt;
2883 mgmt = (const struct ieee80211_mgmt *) buf;
6fc6879b 2884
93827f45
JM
2885#ifdef CONFIG_TESTING_OPTIONS
2886 if (hapd->ext_mgmt_frame_handling) {
2887 wpa_msg(hapd->msg_ctx, MSG_INFO, "MGMT-TX-STATUS stype=%u ok=%d",
2888 stype, ok);
2889 return;
2890 }
2891#endif /* CONFIG_TESTING_OPTIONS */
2892
6fc6879b
JM
2893 switch (stype) {
2894 case WLAN_FC_STYPE_AUTH:
2895 wpa_printf(MSG_DEBUG, "mgmt::auth cb");
2896 handle_auth_cb(hapd, mgmt, len, ok);
2897 break;
2898 case WLAN_FC_STYPE_ASSOC_RESP:
2899 wpa_printf(MSG_DEBUG, "mgmt::assoc_resp cb");
2900 handle_assoc_cb(hapd, mgmt, len, 0, ok);
2901 break;
2902 case WLAN_FC_STYPE_REASSOC_RESP:
2903 wpa_printf(MSG_DEBUG, "mgmt::reassoc_resp cb");
2904 handle_assoc_cb(hapd, mgmt, len, 1, ok);
2905 break;
2906 case WLAN_FC_STYPE_PROBE_RESP:
077dcfb8 2907 wpa_printf(MSG_EXCESSIVE, "mgmt::proberesp cb ok=%d", ok);
6fc6879b
JM
2908 break;
2909 case WLAN_FC_STYPE_DEAUTH:
4dc03726
JM
2910 wpa_printf(MSG_DEBUG, "mgmt::deauth cb");
2911 handle_deauth_cb(hapd, mgmt, len, ok);
2912 break;
2913 case WLAN_FC_STYPE_DISASSOC:
2914 wpa_printf(MSG_DEBUG, "mgmt::disassoc cb");
2915 handle_disassoc_cb(hapd, mgmt, len, ok);
6fc6879b 2916 break;
5d22a1d5 2917 case WLAN_FC_STYPE_ACTION:
077dcfb8 2918 wpa_printf(MSG_DEBUG, "mgmt::action cb ok=%d", ok);
5d22a1d5 2919 break;
6fc6879b 2920 default:
61323e70 2921 wpa_printf(MSG_INFO, "unknown mgmt cb frame subtype %d", stype);
6fc6879b
JM
2922 break;
2923 }
2924}
2925
2926
6fc6879b
JM
2927int ieee802_11_get_mib(struct hostapd_data *hapd, char *buf, size_t buflen)
2928{
2929 /* TODO */
2930 return 0;
2931}
2932
2933
2934int ieee802_11_get_mib_sta(struct hostapd_data *hapd, struct sta_info *sta,
2935 char *buf, size_t buflen)
2936{
2937 /* TODO */
2938 return 0;
2939}
2940
f8b1f695
JM
2941
2942void hostapd_tx_status(struct hostapd_data *hapd, const u8 *addr,
2943 const u8 *buf, size_t len, int ack)
2944{
2945 struct sta_info *sta;
2946 struct hostapd_iface *iface = hapd->iface;
2947
2948 sta = ap_get_sta(hapd, addr);
2949 if (sta == NULL && iface->num_bss > 1) {
2950 size_t j;
2951 for (j = 0; j < iface->num_bss; j++) {
2952 hapd = iface->bss[j];
2953 sta = ap_get_sta(hapd, addr);
2954 if (sta)
2955 break;
2956 }
2957 }
0c01d65d 2958 if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC))
f8b1f695
JM
2959 return;
2960 if (sta->flags & WLAN_STA_PENDING_POLL) {
2961 wpa_printf(MSG_DEBUG, "STA " MACSTR " %s pending "
2962 "activity poll", MAC2STR(sta->addr),
2963 ack ? "ACKed" : "did not ACK");
2964 if (ack)
2965 sta->flags &= ~WLAN_STA_PENDING_POLL;
2966 }
2967
2968 ieee802_1x_tx_status(hapd, sta, buf, len, ack);
2969}
2970
2971
dd840f79
JB
2972void hostapd_eapol_tx_status(struct hostapd_data *hapd, const u8 *dst,
2973 const u8 *data, size_t len, int ack)
2974{
2975 struct sta_info *sta;
2976 struct hostapd_iface *iface = hapd->iface;
2977
2978 sta = ap_get_sta(hapd, dst);
2979 if (sta == NULL && iface->num_bss > 1) {
2980 size_t j;
2981 for (j = 0; j < iface->num_bss; j++) {
2982 hapd = iface->bss[j];
2983 sta = ap_get_sta(hapd, dst);
2984 if (sta)
2985 break;
2986 }
2987 }
d9a38716
JM
2988 if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC)) {
2989 wpa_printf(MSG_DEBUG, "Ignore TX status for Data frame to STA "
2990 MACSTR " that is not currently associated",
2991 MAC2STR(dst));
dd840f79 2992 return;
d9a38716 2993 }
dd840f79
JB
2994
2995 ieee802_1x_eapol_tx_status(hapd, sta, data, len, ack);
2996}
2997
2998
bcf24348
JB
2999void hostapd_client_poll_ok(struct hostapd_data *hapd, const u8 *addr)
3000{
3001 struct sta_info *sta;
3002 struct hostapd_iface *iface = hapd->iface;
3003
3004 sta = ap_get_sta(hapd, addr);
3005 if (sta == NULL && iface->num_bss > 1) {
3006 size_t j;
3007 for (j = 0; j < iface->num_bss; j++) {
3008 hapd = iface->bss[j];
3009 sta = ap_get_sta(hapd, addr);
3010 if (sta)
3011 break;
3012 }
3013 }
3014 if (sta == NULL)
3015 return;
1854eeca
JM
3016 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_POLL_OK MACSTR,
3017 MAC2STR(sta->addr));
bcf24348
JB
3018 if (!(sta->flags & WLAN_STA_PENDING_POLL))
3019 return;
3020
3021 wpa_printf(MSG_DEBUG, "STA " MACSTR " ACKed pending "
3022 "activity poll", MAC2STR(sta->addr));
3023 sta->flags &= ~WLAN_STA_PENDING_POLL;
3024}
3025
3026
fbbfcbac
FF
3027void ieee802_11_rx_from_unknown(struct hostapd_data *hapd, const u8 *src,
3028 int wds)
f8b1f695
JM
3029{
3030 struct sta_info *sta;
3031
3032 sta = ap_get_sta(hapd, src);
fbbfcbac 3033 if (sta && (sta->flags & WLAN_STA_ASSOC)) {
99743811
FF
3034 if (!hapd->conf->wds_sta)
3035 return;
3036
fbbfcbac 3037 if (wds && !(sta->flags & WLAN_STA_WDS)) {
69dd2967
SM
3038 int ret;
3039 char ifname_wds[IFNAMSIZ + 1];
3040
fbbfcbac
FF
3041 wpa_printf(MSG_DEBUG, "Enable 4-address WDS mode for "
3042 "STA " MACSTR " (aid %u)",
3043 MAC2STR(sta->addr), sta->aid);
3044 sta->flags |= WLAN_STA_WDS;
69dd2967
SM
3045 ret = hostapd_set_wds_sta(hapd, ifname_wds,
3046 sta->addr, sta->aid, 1);
3047 if (!ret)
3048 hostapd_set_wds_encryption(hapd, sta,
3049 ifname_wds);
fbbfcbac 3050 }
f8b1f695 3051 return;
fbbfcbac 3052 }
f8b1f695
JM
3053
3054 wpa_printf(MSG_DEBUG, "Data/PS-poll frame from not associated STA "
3055 MACSTR, MAC2STR(src));
1df492df
JM
3056 if (src[0] & 0x01) {
3057 /* Broadcast bit set in SA?! Ignore the frame silently. */
3058 return;
3059 }
3060
b8281964
JM
3061 if (sta && (sta->flags & WLAN_STA_ASSOC_REQ_OK)) {
3062 wpa_printf(MSG_DEBUG, "Association Response to the STA has "
3063 "already been sent, but no TX status yet known - "
3064 "ignore Class 3 frame issue with " MACSTR,
3065 MAC2STR(src));
3066 return;
3067 }
3068
f8b1f695 3069 if (sta && (sta->flags & WLAN_STA_AUTH))
51e2a27a 3070 hostapd_drv_sta_disassoc(
f8b1f695
JM
3071 hapd, src,
3072 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
3073 else
51e2a27a 3074 hostapd_drv_sta_deauth(
f8b1f695
JM
3075 hapd, src,
3076 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
3077}
3078
3079
6fc6879b 3080#endif /* CONFIG_NATIVE_WINDOWS */