]> git.ipfire.org Git - thirdparty/hostap.git/blob - src/ap/ieee802_11.c
FILS: Add RSNE into (Re)Association Response frame
[thirdparty/hostap.git] / src / ap / ieee802_11.c
1 /*
2 * hostapd / IEEE 802.11 Management
3 * Copyright (c) 2002-2017, Jouni Malinen <j@w1.fi>
4 *
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
7 */
8
9 #include "utils/includes.h"
10
11 #ifndef CONFIG_NATIVE_WINDOWS
12
13 #include "utils/common.h"
14 #include "utils/eloop.h"
15 #include "crypto/crypto.h"
16 #include "crypto/sha256.h"
17 #include "crypto/sha384.h"
18 #include "crypto/sha512.h"
19 #include "crypto/random.h"
20 #include "common/ieee802_11_defs.h"
21 #include "common/ieee802_11_common.h"
22 #include "common/wpa_ctrl.h"
23 #include "common/sae.h"
24 #include "common/dpp.h"
25 #include "common/ocv.h"
26 #include "radius/radius.h"
27 #include "radius/radius_client.h"
28 #include "p2p/p2p.h"
29 #include "wps/wps.h"
30 #include "fst/fst.h"
31 #include "hostapd.h"
32 #include "beacon.h"
33 #include "ieee802_11_auth.h"
34 #include "sta_info.h"
35 #include "ieee802_1x.h"
36 #include "wpa_auth.h"
37 #include "pmksa_cache_auth.h"
38 #include "wmm.h"
39 #include "ap_list.h"
40 #include "accounting.h"
41 #include "ap_config.h"
42 #include "ap_mlme.h"
43 #include "p2p_hostapd.h"
44 #include "ap_drv_ops.h"
45 #include "wnm_ap.h"
46 #include "hw_features.h"
47 #include "ieee802_11.h"
48 #include "dfs.h"
49 #include "mbo_ap.h"
50 #include "rrm.h"
51 #include "taxonomy.h"
52 #include "fils_hlp.h"
53 #include "dpp_hostapd.h"
54 #include "gas_query_ap.h"
55
56
57 #ifdef CONFIG_FILS
58 static struct wpabuf *
59 prepare_auth_resp_fils(struct hostapd_data *hapd,
60 struct sta_info *sta, u16 *resp,
61 struct rsn_pmksa_cache_entry *pmksa,
62 struct wpabuf *erp_resp,
63 const u8 *msk, size_t msk_len,
64 int *is_pub);
65 #endif /* CONFIG_FILS */
66 static void handle_auth(struct hostapd_data *hapd,
67 const struct ieee80211_mgmt *mgmt, size_t len,
68 int rssi, int from_queue);
69
70
71 u8 * hostapd_eid_multi_ap(struct hostapd_data *hapd, u8 *eid)
72 {
73 u8 multi_ap_val = 0;
74
75 if (!hapd->conf->multi_ap)
76 return eid;
77 if (hapd->conf->multi_ap & BACKHAUL_BSS)
78 multi_ap_val |= MULTI_AP_BACKHAUL_BSS;
79 if (hapd->conf->multi_ap & FRONTHAUL_BSS)
80 multi_ap_val |= MULTI_AP_FRONTHAUL_BSS;
81
82 return eid + add_multi_ap_ie(eid, 9, multi_ap_val);
83 }
84
85
86 u8 * hostapd_eid_supp_rates(struct hostapd_data *hapd, u8 *eid)
87 {
88 u8 *pos = eid;
89 int i, num, count;
90
91 if (hapd->iface->current_rates == NULL)
92 return eid;
93
94 *pos++ = WLAN_EID_SUPP_RATES;
95 num = hapd->iface->num_rates;
96 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht)
97 num++;
98 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht)
99 num++;
100 if (num > 8) {
101 /* rest of the rates are encoded in Extended supported
102 * rates element */
103 num = 8;
104 }
105
106 *pos++ = num;
107 for (i = 0, count = 0; i < hapd->iface->num_rates && count < num;
108 i++) {
109 count++;
110 *pos = hapd->iface->current_rates[i].rate / 5;
111 if (hapd->iface->current_rates[i].flags & HOSTAPD_RATE_BASIC)
112 *pos |= 0x80;
113 pos++;
114 }
115
116 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht && count < 8) {
117 count++;
118 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY;
119 }
120
121 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht && count < 8) {
122 count++;
123 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY;
124 }
125
126 return pos;
127 }
128
129
130 u8 * hostapd_eid_ext_supp_rates(struct hostapd_data *hapd, u8 *eid)
131 {
132 u8 *pos = eid;
133 int i, num, count;
134
135 if (hapd->iface->current_rates == NULL)
136 return eid;
137
138 num = hapd->iface->num_rates;
139 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht)
140 num++;
141 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht)
142 num++;
143 if (num <= 8)
144 return eid;
145 num -= 8;
146
147 *pos++ = WLAN_EID_EXT_SUPP_RATES;
148 *pos++ = num;
149 for (i = 0, count = 0; i < hapd->iface->num_rates && count < num + 8;
150 i++) {
151 count++;
152 if (count <= 8)
153 continue; /* already in SuppRates IE */
154 *pos = hapd->iface->current_rates[i].rate / 5;
155 if (hapd->iface->current_rates[i].flags & HOSTAPD_RATE_BASIC)
156 *pos |= 0x80;
157 pos++;
158 }
159
160 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht) {
161 count++;
162 if (count > 8)
163 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY;
164 }
165
166 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht) {
167 count++;
168 if (count > 8)
169 *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY;
170 }
171
172 return pos;
173 }
174
175
176 u16 hostapd_own_capab_info(struct hostapd_data *hapd)
177 {
178 int capab = WLAN_CAPABILITY_ESS;
179 int privacy;
180 int dfs;
181 int i;
182
183 /* Check if any of configured channels require DFS */
184 dfs = hostapd_is_dfs_required(hapd->iface);
185 if (dfs < 0) {
186 wpa_printf(MSG_WARNING, "Failed to check if DFS is required; ret=%d",
187 dfs);
188 dfs = 0;
189 }
190
191 if (hapd->iface->num_sta_no_short_preamble == 0 &&
192 hapd->iconf->preamble == SHORT_PREAMBLE)
193 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
194
195 privacy = hapd->conf->ssid.wep.keys_set;
196
197 if (hapd->conf->ieee802_1x &&
198 (hapd->conf->default_wep_key_len ||
199 hapd->conf->individual_wep_key_len))
200 privacy = 1;
201
202 if (hapd->conf->wpa)
203 privacy = 1;
204
205 #ifdef CONFIG_HS20
206 if (hapd->conf->osen)
207 privacy = 1;
208 #endif /* CONFIG_HS20 */
209
210 if (privacy)
211 capab |= WLAN_CAPABILITY_PRIVACY;
212
213 if (hapd->iface->current_mode &&
214 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G &&
215 hapd->iface->num_sta_no_short_slot_time == 0)
216 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
217
218 /*
219 * Currently, Spectrum Management capability bit is set when directly
220 * requested in configuration by spectrum_mgmt_required or when AP is
221 * running on DFS channel.
222 * TODO: Also consider driver support for TPC to set Spectrum Mgmt bit
223 */
224 if (hapd->iface->current_mode &&
225 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211A &&
226 (hapd->iconf->spectrum_mgmt_required || dfs))
227 capab |= WLAN_CAPABILITY_SPECTRUM_MGMT;
228
229 for (i = 0; i < RRM_CAPABILITIES_IE_LEN; i++) {
230 if (hapd->conf->radio_measurements[i]) {
231 capab |= IEEE80211_CAP_RRM;
232 break;
233 }
234 }
235
236 return capab;
237 }
238
239
240 #ifndef CONFIG_NO_RC4
241 static u16 auth_shared_key(struct hostapd_data *hapd, struct sta_info *sta,
242 u16 auth_transaction, const u8 *challenge,
243 int iswep)
244 {
245 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
246 HOSTAPD_LEVEL_DEBUG,
247 "authentication (shared key, transaction %d)",
248 auth_transaction);
249
250 if (auth_transaction == 1) {
251 if (!sta->challenge) {
252 /* Generate a pseudo-random challenge */
253 u8 key[8];
254
255 sta->challenge = os_zalloc(WLAN_AUTH_CHALLENGE_LEN);
256 if (sta->challenge == NULL)
257 return WLAN_STATUS_UNSPECIFIED_FAILURE;
258
259 if (os_get_random(key, sizeof(key)) < 0) {
260 os_free(sta->challenge);
261 sta->challenge = NULL;
262 return WLAN_STATUS_UNSPECIFIED_FAILURE;
263 }
264
265 rc4_skip(key, sizeof(key), 0,
266 sta->challenge, WLAN_AUTH_CHALLENGE_LEN);
267 }
268 return 0;
269 }
270
271 if (auth_transaction != 3)
272 return WLAN_STATUS_UNSPECIFIED_FAILURE;
273
274 /* Transaction 3 */
275 if (!iswep || !sta->challenge || !challenge ||
276 os_memcmp_const(sta->challenge, challenge,
277 WLAN_AUTH_CHALLENGE_LEN)) {
278 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
279 HOSTAPD_LEVEL_INFO,
280 "shared key authentication - invalid "
281 "challenge-response");
282 return WLAN_STATUS_CHALLENGE_FAIL;
283 }
284
285 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
286 HOSTAPD_LEVEL_DEBUG,
287 "authentication OK (shared key)");
288 sta->flags |= WLAN_STA_AUTH;
289 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
290 os_free(sta->challenge);
291 sta->challenge = NULL;
292
293 return 0;
294 }
295 #endif /* CONFIG_NO_RC4 */
296
297
298 static int send_auth_reply(struct hostapd_data *hapd,
299 const u8 *dst, const u8 *bssid,
300 u16 auth_alg, u16 auth_transaction, u16 resp,
301 const u8 *ies, size_t ies_len, const char *dbg)
302 {
303 struct ieee80211_mgmt *reply;
304 u8 *buf;
305 size_t rlen;
306 int reply_res = WLAN_STATUS_UNSPECIFIED_FAILURE;
307
308 rlen = IEEE80211_HDRLEN + sizeof(reply->u.auth) + ies_len;
309 buf = os_zalloc(rlen);
310 if (buf == NULL)
311 return -1;
312
313 reply = (struct ieee80211_mgmt *) buf;
314 reply->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
315 WLAN_FC_STYPE_AUTH);
316 os_memcpy(reply->da, dst, ETH_ALEN);
317 os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN);
318 os_memcpy(reply->bssid, bssid, ETH_ALEN);
319
320 reply->u.auth.auth_alg = host_to_le16(auth_alg);
321 reply->u.auth.auth_transaction = host_to_le16(auth_transaction);
322 reply->u.auth.status_code = host_to_le16(resp);
323
324 if (ies && ies_len)
325 os_memcpy(reply->u.auth.variable, ies, ies_len);
326
327 wpa_printf(MSG_DEBUG, "authentication reply: STA=" MACSTR
328 " auth_alg=%d auth_transaction=%d resp=%d (IE len=%lu) (dbg=%s)",
329 MAC2STR(dst), auth_alg, auth_transaction,
330 resp, (unsigned long) ies_len, dbg);
331 if (hostapd_drv_send_mlme(hapd, reply, rlen, 0) < 0)
332 wpa_printf(MSG_INFO, "send_auth_reply: send failed");
333 else
334 reply_res = WLAN_STATUS_SUCCESS;
335
336 os_free(buf);
337
338 return reply_res;
339 }
340
341
342 #ifdef CONFIG_IEEE80211R_AP
343 static void handle_auth_ft_finish(void *ctx, const u8 *dst, const u8 *bssid,
344 u16 auth_transaction, u16 status,
345 const u8 *ies, size_t ies_len)
346 {
347 struct hostapd_data *hapd = ctx;
348 struct sta_info *sta;
349 int reply_res;
350
351 reply_res = send_auth_reply(hapd, dst, bssid, WLAN_AUTH_FT,
352 auth_transaction, status, ies, ies_len,
353 "auth-ft-finish");
354
355 sta = ap_get_sta(hapd, dst);
356 if (sta == NULL)
357 return;
358
359 if (sta->added_unassoc && (reply_res != WLAN_STATUS_SUCCESS ||
360 status != WLAN_STATUS_SUCCESS)) {
361 hostapd_drv_sta_remove(hapd, sta->addr);
362 sta->added_unassoc = 0;
363 return;
364 }
365
366 if (status != WLAN_STATUS_SUCCESS)
367 return;
368
369 hostapd_logger(hapd, dst, HOSTAPD_MODULE_IEEE80211,
370 HOSTAPD_LEVEL_DEBUG, "authentication OK (FT)");
371 sta->flags |= WLAN_STA_AUTH;
372 mlme_authenticate_indication(hapd, sta);
373 }
374 #endif /* CONFIG_IEEE80211R_AP */
375
376
377 #ifdef CONFIG_SAE
378
379 static void sae_set_state(struct sta_info *sta, enum sae_state state,
380 const char *reason)
381 {
382 wpa_printf(MSG_DEBUG, "SAE: State %s -> %s for peer " MACSTR " (%s)",
383 sae_state_txt(sta->sae->state), sae_state_txt(state),
384 MAC2STR(sta->addr), reason);
385 sta->sae->state = state;
386 }
387
388
389 static struct wpabuf * auth_build_sae_commit(struct hostapd_data *hapd,
390 struct sta_info *sta, int update)
391 {
392 struct wpabuf *buf;
393 const char *password = NULL;
394 struct sae_password_entry *pw;
395 const char *rx_id = NULL;
396
397 if (sta->sae->tmp)
398 rx_id = sta->sae->tmp->pw_id;
399
400 for (pw = hapd->conf->sae_passwords; pw; pw = pw->next) {
401 if (!is_broadcast_ether_addr(pw->peer_addr) &&
402 os_memcmp(pw->peer_addr, sta->addr, ETH_ALEN) != 0)
403 continue;
404 if ((rx_id && !pw->identifier) || (!rx_id && pw->identifier))
405 continue;
406 if (rx_id && pw->identifier &&
407 os_strcmp(rx_id, pw->identifier) != 0)
408 continue;
409 password = pw->password;
410 break;
411 }
412 if (!password)
413 password = hapd->conf->ssid.wpa_passphrase;
414 if (!password) {
415 wpa_printf(MSG_DEBUG, "SAE: No password available");
416 return NULL;
417 }
418
419 if (update &&
420 sae_prepare_commit(hapd->own_addr, sta->addr,
421 (u8 *) password, os_strlen(password), rx_id,
422 sta->sae) < 0) {
423 wpa_printf(MSG_DEBUG, "SAE: Could not pick PWE");
424 return NULL;
425 }
426
427 if (pw && pw->vlan_id) {
428 if (!sta->sae->tmp) {
429 wpa_printf(MSG_INFO,
430 "SAE: No temporary data allocated - cannot store VLAN ID");
431 return NULL;
432 }
433 sta->sae->tmp->vlan_id = pw->vlan_id;
434 }
435
436 buf = wpabuf_alloc(SAE_COMMIT_MAX_LEN +
437 (rx_id ? 3 + os_strlen(rx_id) : 0));
438 if (buf == NULL)
439 return NULL;
440 sae_write_commit(sta->sae, buf, sta->sae->tmp ?
441 sta->sae->tmp->anti_clogging_token : NULL, rx_id);
442
443 return buf;
444 }
445
446
447 static struct wpabuf * auth_build_sae_confirm(struct hostapd_data *hapd,
448 struct sta_info *sta)
449 {
450 struct wpabuf *buf;
451
452 buf = wpabuf_alloc(SAE_CONFIRM_MAX_LEN);
453 if (buf == NULL)
454 return NULL;
455
456 sae_write_confirm(sta->sae, buf);
457
458 return buf;
459 }
460
461
462 static int auth_sae_send_commit(struct hostapd_data *hapd,
463 struct sta_info *sta,
464 const u8 *bssid, int update)
465 {
466 struct wpabuf *data;
467 int reply_res;
468
469 data = auth_build_sae_commit(hapd, sta, update);
470 if (!data && sta->sae->tmp && sta->sae->tmp->pw_id)
471 return WLAN_STATUS_UNKNOWN_PASSWORD_IDENTIFIER;
472 if (data == NULL)
473 return WLAN_STATUS_UNSPECIFIED_FAILURE;
474
475 reply_res = send_auth_reply(hapd, sta->addr, bssid, WLAN_AUTH_SAE, 1,
476 WLAN_STATUS_SUCCESS, wpabuf_head(data),
477 wpabuf_len(data), "sae-send-commit");
478
479 wpabuf_free(data);
480
481 return reply_res;
482 }
483
484
485 static int auth_sae_send_confirm(struct hostapd_data *hapd,
486 struct sta_info *sta,
487 const u8 *bssid)
488 {
489 struct wpabuf *data;
490 int reply_res;
491
492 data = auth_build_sae_confirm(hapd, sta);
493 if (data == NULL)
494 return WLAN_STATUS_UNSPECIFIED_FAILURE;
495
496 reply_res = send_auth_reply(hapd, sta->addr, bssid, WLAN_AUTH_SAE, 2,
497 WLAN_STATUS_SUCCESS, wpabuf_head(data),
498 wpabuf_len(data), "sae-send-confirm");
499
500 wpabuf_free(data);
501
502 return reply_res;
503 }
504
505
506 static int use_sae_anti_clogging(struct hostapd_data *hapd)
507 {
508 struct sta_info *sta;
509 unsigned int open = 0;
510
511 if (hapd->conf->sae_anti_clogging_threshold == 0)
512 return 1;
513
514 for (sta = hapd->sta_list; sta; sta = sta->next) {
515 if (!sta->sae)
516 continue;
517 if (sta->sae->state != SAE_COMMITTED &&
518 sta->sae->state != SAE_CONFIRMED)
519 continue;
520 open++;
521 if (open >= hapd->conf->sae_anti_clogging_threshold)
522 return 1;
523 }
524
525 /* In addition to already existing open SAE sessions, check whether
526 * there are enough pending commit messages in the processing queue to
527 * potentially result in too many open sessions. */
528 if (open + dl_list_len(&hapd->sae_commit_queue) >=
529 hapd->conf->sae_anti_clogging_threshold)
530 return 1;
531
532 return 0;
533 }
534
535
536 static u8 sae_token_hash(struct hostapd_data *hapd, const u8 *addr)
537 {
538 u8 hash[SHA256_MAC_LEN];
539
540 hmac_sha256(hapd->sae_token_key, sizeof(hapd->sae_token_key),
541 addr, ETH_ALEN, hash);
542 return hash[0];
543 }
544
545
546 static int check_sae_token(struct hostapd_data *hapd, const u8 *addr,
547 const u8 *token, size_t token_len)
548 {
549 u8 mac[SHA256_MAC_LEN];
550 const u8 *addrs[2];
551 size_t len[2];
552 u16 token_idx;
553 u8 idx;
554
555 if (token_len != SHA256_MAC_LEN)
556 return -1;
557 idx = sae_token_hash(hapd, addr);
558 token_idx = hapd->sae_pending_token_idx[idx];
559 if (token_idx == 0 || token_idx != WPA_GET_BE16(token)) {
560 wpa_printf(MSG_DEBUG, "SAE: Invalid anti-clogging token from "
561 MACSTR " - token_idx 0x%04x, expected 0x%04x",
562 MAC2STR(addr), WPA_GET_BE16(token), token_idx);
563 return -1;
564 }
565
566 addrs[0] = addr;
567 len[0] = ETH_ALEN;
568 addrs[1] = token;
569 len[1] = 2;
570 if (hmac_sha256_vector(hapd->sae_token_key, sizeof(hapd->sae_token_key),
571 2, addrs, len, mac) < 0 ||
572 os_memcmp_const(token + 2, &mac[2], SHA256_MAC_LEN - 2) != 0)
573 return -1;
574
575 hapd->sae_pending_token_idx[idx] = 0; /* invalidate used token */
576
577 return 0;
578 }
579
580
581 static struct wpabuf * auth_build_token_req(struct hostapd_data *hapd,
582 int group, const u8 *addr)
583 {
584 struct wpabuf *buf;
585 u8 *token;
586 struct os_reltime now;
587 u8 idx[2];
588 const u8 *addrs[2];
589 size_t len[2];
590 u8 p_idx;
591 u16 token_idx;
592
593 os_get_reltime(&now);
594 if (!os_reltime_initialized(&hapd->last_sae_token_key_update) ||
595 os_reltime_expired(&now, &hapd->last_sae_token_key_update, 60) ||
596 hapd->sae_token_idx == 0xffff) {
597 if (random_get_bytes(hapd->sae_token_key,
598 sizeof(hapd->sae_token_key)) < 0)
599 return NULL;
600 wpa_hexdump(MSG_DEBUG, "SAE: Updated token key",
601 hapd->sae_token_key, sizeof(hapd->sae_token_key));
602 hapd->last_sae_token_key_update = now;
603 hapd->sae_token_idx = 0;
604 os_memset(hapd->sae_pending_token_idx, 0,
605 sizeof(hapd->sae_pending_token_idx));
606 }
607
608 buf = wpabuf_alloc(sizeof(le16) + SHA256_MAC_LEN);
609 if (buf == NULL)
610 return NULL;
611
612 wpabuf_put_le16(buf, group); /* Finite Cyclic Group */
613
614 p_idx = sae_token_hash(hapd, addr);
615 token_idx = hapd->sae_pending_token_idx[p_idx];
616 if (!token_idx) {
617 hapd->sae_token_idx++;
618 token_idx = hapd->sae_token_idx;
619 hapd->sae_pending_token_idx[p_idx] = token_idx;
620 }
621 WPA_PUT_BE16(idx, token_idx);
622 token = wpabuf_put(buf, SHA256_MAC_LEN);
623 addrs[0] = addr;
624 len[0] = ETH_ALEN;
625 addrs[1] = idx;
626 len[1] = sizeof(idx);
627 if (hmac_sha256_vector(hapd->sae_token_key, sizeof(hapd->sae_token_key),
628 2, addrs, len, token) < 0) {
629 wpabuf_free(buf);
630 return NULL;
631 }
632 WPA_PUT_BE16(token, token_idx);
633
634 return buf;
635 }
636
637
638 static int sae_check_big_sync(struct hostapd_data *hapd, struct sta_info *sta)
639 {
640 if (sta->sae->sync > hapd->conf->sae_sync) {
641 sae_set_state(sta, SAE_NOTHING, "Sync > dot11RSNASAESync");
642 sta->sae->sync = 0;
643 return -1;
644 }
645 return 0;
646 }
647
648
649 static void auth_sae_retransmit_timer(void *eloop_ctx, void *eloop_data)
650 {
651 struct hostapd_data *hapd = eloop_ctx;
652 struct sta_info *sta = eloop_data;
653 int ret;
654
655 if (sae_check_big_sync(hapd, sta))
656 return;
657 sta->sae->sync++;
658 wpa_printf(MSG_DEBUG, "SAE: Auth SAE retransmit timer for " MACSTR
659 " (sync=%d state=%s)",
660 MAC2STR(sta->addr), sta->sae->sync,
661 sae_state_txt(sta->sae->state));
662
663 switch (sta->sae->state) {
664 case SAE_COMMITTED:
665 ret = auth_sae_send_commit(hapd, sta, hapd->own_addr, 0);
666 eloop_register_timeout(0,
667 hapd->dot11RSNASAERetransPeriod * 1000,
668 auth_sae_retransmit_timer, hapd, sta);
669 break;
670 case SAE_CONFIRMED:
671 ret = auth_sae_send_confirm(hapd, sta, hapd->own_addr);
672 eloop_register_timeout(0,
673 hapd->dot11RSNASAERetransPeriod * 1000,
674 auth_sae_retransmit_timer, hapd, sta);
675 break;
676 default:
677 ret = -1;
678 break;
679 }
680
681 if (ret != WLAN_STATUS_SUCCESS)
682 wpa_printf(MSG_INFO, "SAE: Failed to retransmit: ret=%d", ret);
683 }
684
685
686 void sae_clear_retransmit_timer(struct hostapd_data *hapd, struct sta_info *sta)
687 {
688 eloop_cancel_timeout(auth_sae_retransmit_timer, hapd, sta);
689 }
690
691
692 static void sae_set_retransmit_timer(struct hostapd_data *hapd,
693 struct sta_info *sta)
694 {
695 if (!(hapd->conf->mesh & MESH_ENABLED))
696 return;
697
698 eloop_cancel_timeout(auth_sae_retransmit_timer, hapd, sta);
699 eloop_register_timeout(0, hapd->dot11RSNASAERetransPeriod * 1000,
700 auth_sae_retransmit_timer, hapd, sta);
701 }
702
703
704 static void sae_sme_send_external_auth_status(struct hostapd_data *hapd,
705 struct sta_info *sta, u16 status)
706 {
707 struct external_auth params;
708
709 os_memset(&params, 0, sizeof(params));
710 params.status = status;
711 params.bssid = sta->addr;
712 if (status == WLAN_STATUS_SUCCESS && sta->sae)
713 params.pmkid = sta->sae->pmkid;
714
715 hostapd_drv_send_external_auth_status(hapd, &params);
716 }
717
718
719 void sae_accept_sta(struct hostapd_data *hapd, struct sta_info *sta)
720 {
721 #ifndef CONFIG_NO_VLAN
722 struct vlan_description vlan_desc;
723
724 if (sta->sae->tmp && sta->sae->tmp->vlan_id > 0) {
725 wpa_printf(MSG_DEBUG, "SAE: Assign STA " MACSTR
726 " to VLAN ID %d",
727 MAC2STR(sta->addr), sta->sae->tmp->vlan_id);
728
729 os_memset(&vlan_desc, 0, sizeof(vlan_desc));
730 vlan_desc.notempty = 1;
731 vlan_desc.untagged = sta->sae->tmp->vlan_id;
732 if (!hostapd_vlan_valid(hapd->conf->vlan, &vlan_desc)) {
733 wpa_printf(MSG_INFO,
734 "Invalid VLAN ID %d in sae_password",
735 sta->sae->tmp->vlan_id);
736 return;
737 }
738
739 if (ap_sta_set_vlan(hapd, sta, &vlan_desc) < 0 ||
740 ap_sta_bind_vlan(hapd, sta) < 0) {
741 wpa_printf(MSG_INFO,
742 "Failed to assign VLAN ID %d from sae_password to "
743 MACSTR, sta->sae->tmp->vlan_id,
744 MAC2STR(sta->addr));
745 return;
746 }
747 }
748 #endif /* CONFIG_NO_VLAN */
749
750 sta->flags |= WLAN_STA_AUTH;
751 sta->auth_alg = WLAN_AUTH_SAE;
752 mlme_authenticate_indication(hapd, sta);
753 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
754 sae_set_state(sta, SAE_ACCEPTED, "Accept Confirm");
755 wpa_auth_pmksa_add_sae(hapd->wpa_auth, sta->addr,
756 sta->sae->pmk, sta->sae->pmkid);
757 sae_sme_send_external_auth_status(hapd, sta, WLAN_STATUS_SUCCESS);
758 }
759
760
761 static int sae_sm_step(struct hostapd_data *hapd, struct sta_info *sta,
762 const u8 *bssid, u8 auth_transaction, int allow_reuse,
763 int *sta_removed)
764 {
765 int ret;
766
767 *sta_removed = 0;
768
769 if (auth_transaction != 1 && auth_transaction != 2)
770 return WLAN_STATUS_UNSPECIFIED_FAILURE;
771
772 wpa_printf(MSG_DEBUG, "SAE: Peer " MACSTR " state=%s auth_trans=%u",
773 MAC2STR(sta->addr), sae_state_txt(sta->sae->state),
774 auth_transaction);
775 switch (sta->sae->state) {
776 case SAE_NOTHING:
777 if (auth_transaction == 1) {
778 ret = auth_sae_send_commit(hapd, sta, bssid,
779 !allow_reuse);
780 if (ret)
781 return ret;
782 sae_set_state(sta, SAE_COMMITTED, "Sent Commit");
783
784 if (sae_process_commit(sta->sae) < 0)
785 return WLAN_STATUS_UNSPECIFIED_FAILURE;
786
787 /*
788 * In mesh case, both Commit and Confirm can be sent
789 * immediately. In infrastructure BSS, only a single
790 * Authentication frame (Commit) is expected from the AP
791 * here and the second one (Confirm) will be sent once
792 * the STA has sent its second Authentication frame
793 * (Confirm).
794 */
795 if (hapd->conf->mesh & MESH_ENABLED) {
796 /*
797 * Send both Commit and Confirm immediately
798 * based on SAE finite state machine
799 * Nothing -> Confirm transition.
800 */
801 ret = auth_sae_send_confirm(hapd, sta, bssid);
802 if (ret)
803 return ret;
804 sae_set_state(sta, SAE_CONFIRMED,
805 "Sent Confirm (mesh)");
806 } else {
807 /*
808 * For infrastructure BSS, send only the Commit
809 * message now to get alternating sequence of
810 * Authentication frames between the AP and STA.
811 * Confirm will be sent in
812 * Committed -> Confirmed/Accepted transition
813 * when receiving Confirm from STA.
814 */
815 }
816 sta->sae->sync = 0;
817 sae_set_retransmit_timer(hapd, sta);
818 } else {
819 hostapd_logger(hapd, sta->addr,
820 HOSTAPD_MODULE_IEEE80211,
821 HOSTAPD_LEVEL_DEBUG,
822 "SAE confirm before commit");
823 }
824 break;
825 case SAE_COMMITTED:
826 sae_clear_retransmit_timer(hapd, sta);
827 if (auth_transaction == 1) {
828 if (sae_process_commit(sta->sae) < 0)
829 return WLAN_STATUS_UNSPECIFIED_FAILURE;
830
831 ret = auth_sae_send_confirm(hapd, sta, bssid);
832 if (ret)
833 return ret;
834 sae_set_state(sta, SAE_CONFIRMED, "Sent Confirm");
835 sta->sae->sync = 0;
836 sae_set_retransmit_timer(hapd, sta);
837 } else if (hapd->conf->mesh & MESH_ENABLED) {
838 /*
839 * In mesh case, follow SAE finite state machine and
840 * send Commit now, if sync count allows.
841 */
842 if (sae_check_big_sync(hapd, sta))
843 return WLAN_STATUS_SUCCESS;
844 sta->sae->sync++;
845
846 ret = auth_sae_send_commit(hapd, sta, bssid, 0);
847 if (ret)
848 return ret;
849
850 sae_set_retransmit_timer(hapd, sta);
851 } else {
852 /*
853 * For instructure BSS, send the postponed Confirm from
854 * Nothing -> Confirmed transition that was reduced to
855 * Nothing -> Committed above.
856 */
857 ret = auth_sae_send_confirm(hapd, sta, bssid);
858 if (ret)
859 return ret;
860
861 sae_set_state(sta, SAE_CONFIRMED, "Sent Confirm");
862
863 /*
864 * Since this was triggered on Confirm RX, run another
865 * step to get to Accepted without waiting for
866 * additional events.
867 */
868 return sae_sm_step(hapd, sta, bssid, auth_transaction,
869 0, sta_removed);
870 }
871 break;
872 case SAE_CONFIRMED:
873 sae_clear_retransmit_timer(hapd, sta);
874 if (auth_transaction == 1) {
875 if (sae_check_big_sync(hapd, sta))
876 return WLAN_STATUS_SUCCESS;
877 sta->sae->sync++;
878
879 ret = auth_sae_send_commit(hapd, sta, bssid, 1);
880 if (ret)
881 return ret;
882
883 if (sae_process_commit(sta->sae) < 0)
884 return WLAN_STATUS_UNSPECIFIED_FAILURE;
885
886 ret = auth_sae_send_confirm(hapd, sta, bssid);
887 if (ret)
888 return ret;
889
890 sae_set_retransmit_timer(hapd, sta);
891 } else {
892 sta->sae->send_confirm = 0xffff;
893 sae_accept_sta(hapd, sta);
894 }
895 break;
896 case SAE_ACCEPTED:
897 if (auth_transaction == 1 &&
898 (hapd->conf->mesh & MESH_ENABLED)) {
899 wpa_printf(MSG_DEBUG, "SAE: remove the STA (" MACSTR
900 ") doing reauthentication",
901 MAC2STR(sta->addr));
902 wpa_auth_pmksa_remove(hapd->wpa_auth, sta->addr);
903 ap_free_sta(hapd, sta);
904 *sta_removed = 1;
905 } else if (auth_transaction == 1) {
906 wpa_printf(MSG_DEBUG, "SAE: Start reauthentication");
907 ret = auth_sae_send_commit(hapd, sta, bssid, 1);
908 if (ret)
909 return ret;
910 sae_set_state(sta, SAE_COMMITTED, "Sent Commit");
911
912 if (sae_process_commit(sta->sae) < 0)
913 return WLAN_STATUS_UNSPECIFIED_FAILURE;
914 sta->sae->sync = 0;
915 sae_set_retransmit_timer(hapd, sta);
916 } else {
917 if (sae_check_big_sync(hapd, sta))
918 return WLAN_STATUS_SUCCESS;
919 sta->sae->sync++;
920
921 ret = auth_sae_send_confirm(hapd, sta, bssid);
922 sae_clear_temp_data(sta->sae);
923 if (ret)
924 return ret;
925 }
926 break;
927 default:
928 wpa_printf(MSG_ERROR, "SAE: invalid state %d",
929 sta->sae->state);
930 return WLAN_STATUS_UNSPECIFIED_FAILURE;
931 }
932 return WLAN_STATUS_SUCCESS;
933 }
934
935
936 static void sae_pick_next_group(struct hostapd_data *hapd, struct sta_info *sta)
937 {
938 struct sae_data *sae = sta->sae;
939 int i, *groups = hapd->conf->sae_groups;
940 int default_groups[] = { 19, 0 };
941
942 if (sae->state != SAE_COMMITTED)
943 return;
944
945 wpa_printf(MSG_DEBUG, "SAE: Previously selected group: %d", sae->group);
946
947 if (!groups)
948 groups = default_groups;
949 for (i = 0; groups[i] > 0; i++) {
950 if (sae->group == groups[i])
951 break;
952 }
953
954 if (groups[i] <= 0) {
955 wpa_printf(MSG_DEBUG,
956 "SAE: Previously selected group not found from the current configuration");
957 return;
958 }
959
960 for (;;) {
961 i++;
962 if (groups[i] <= 0) {
963 wpa_printf(MSG_DEBUG,
964 "SAE: No alternative group enabled");
965 return;
966 }
967
968 if (sae_set_group(sae, groups[i]) < 0)
969 continue;
970
971 break;
972 }
973 wpa_printf(MSG_DEBUG, "SAE: Selected new group: %d", groups[i]);
974 }
975
976
977 static void handle_auth_sae(struct hostapd_data *hapd, struct sta_info *sta,
978 const struct ieee80211_mgmt *mgmt, size_t len,
979 u16 auth_transaction, u16 status_code)
980 {
981 int resp = WLAN_STATUS_SUCCESS;
982 struct wpabuf *data = NULL;
983 int *groups = hapd->conf->sae_groups;
984 int default_groups[] = { 19, 0 };
985 const u8 *pos, *end;
986 int sta_removed = 0;
987
988 if (!groups)
989 groups = default_groups;
990
991 #ifdef CONFIG_TESTING_OPTIONS
992 if (hapd->conf->sae_reflection_attack && auth_transaction == 1) {
993 wpa_printf(MSG_DEBUG, "SAE: TESTING - reflection attack");
994 pos = mgmt->u.auth.variable;
995 end = ((const u8 *) mgmt) + len;
996 send_auth_reply(hapd, mgmt->sa, mgmt->bssid, WLAN_AUTH_SAE,
997 auth_transaction, resp, pos, end - pos,
998 "auth-sae-reflection-attack");
999 goto remove_sta;
1000 }
1001
1002 if (hapd->conf->sae_commit_override && auth_transaction == 1) {
1003 wpa_printf(MSG_DEBUG, "SAE: TESTING - commit override");
1004 send_auth_reply(hapd, mgmt->sa, mgmt->bssid, WLAN_AUTH_SAE,
1005 auth_transaction, resp,
1006 wpabuf_head(hapd->conf->sae_commit_override),
1007 wpabuf_len(hapd->conf->sae_commit_override),
1008 "sae-commit-override");
1009 goto remove_sta;
1010 }
1011 #endif /* CONFIG_TESTING_OPTIONS */
1012 if (!sta->sae) {
1013 if (auth_transaction != 1 ||
1014 status_code != WLAN_STATUS_SUCCESS) {
1015 resp = -1;
1016 goto remove_sta;
1017 }
1018 sta->sae = os_zalloc(sizeof(*sta->sae));
1019 if (!sta->sae) {
1020 resp = -1;
1021 goto remove_sta;
1022 }
1023 sae_set_state(sta, SAE_NOTHING, "Init");
1024 sta->sae->sync = 0;
1025 }
1026
1027 if (sta->mesh_sae_pmksa_caching) {
1028 wpa_printf(MSG_DEBUG,
1029 "SAE: Cancel use of mesh PMKSA caching because peer starts SAE authentication");
1030 wpa_auth_pmksa_remove(hapd->wpa_auth, sta->addr);
1031 sta->mesh_sae_pmksa_caching = 0;
1032 }
1033
1034 if (auth_transaction == 1) {
1035 const u8 *token = NULL;
1036 size_t token_len = 0;
1037 int allow_reuse = 0;
1038
1039 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1040 HOSTAPD_LEVEL_DEBUG,
1041 "start SAE authentication (RX commit, status=%u (%s))",
1042 status_code, status2str(status_code));
1043
1044 if ((hapd->conf->mesh & MESH_ENABLED) &&
1045 status_code == WLAN_STATUS_ANTI_CLOGGING_TOKEN_REQ &&
1046 sta->sae->tmp) {
1047 pos = mgmt->u.auth.variable;
1048 end = ((const u8 *) mgmt) + len;
1049 if (pos + sizeof(le16) > end) {
1050 wpa_printf(MSG_ERROR,
1051 "SAE: Too short anti-clogging token request");
1052 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1053 goto reply;
1054 }
1055 resp = sae_group_allowed(sta->sae, groups,
1056 WPA_GET_LE16(pos));
1057 if (resp != WLAN_STATUS_SUCCESS) {
1058 wpa_printf(MSG_ERROR,
1059 "SAE: Invalid group in anti-clogging token request");
1060 goto reply;
1061 }
1062 pos += sizeof(le16);
1063
1064 wpabuf_free(sta->sae->tmp->anti_clogging_token);
1065 sta->sae->tmp->anti_clogging_token =
1066 wpabuf_alloc_copy(pos, end - pos);
1067 if (sta->sae->tmp->anti_clogging_token == NULL) {
1068 wpa_printf(MSG_ERROR,
1069 "SAE: Failed to alloc for anti-clogging token");
1070 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1071 goto remove_sta;
1072 }
1073
1074 /*
1075 * IEEE Std 802.11-2012, 11.3.8.6.4: If the Status code
1076 * is 76, a new Commit Message shall be constructed
1077 * with the Anti-Clogging Token from the received
1078 * Authentication frame, and the commit-scalar and
1079 * COMMIT-ELEMENT previously sent.
1080 */
1081 resp = auth_sae_send_commit(hapd, sta, mgmt->bssid, 0);
1082 if (resp != WLAN_STATUS_SUCCESS) {
1083 wpa_printf(MSG_ERROR,
1084 "SAE: Failed to send commit message");
1085 goto remove_sta;
1086 }
1087 sae_set_state(sta, SAE_COMMITTED,
1088 "Sent Commit (anti-clogging token case in mesh)");
1089 sta->sae->sync = 0;
1090 sae_set_retransmit_timer(hapd, sta);
1091 return;
1092 }
1093
1094 if ((hapd->conf->mesh & MESH_ENABLED) &&
1095 status_code ==
1096 WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED &&
1097 sta->sae->tmp) {
1098 wpa_printf(MSG_DEBUG,
1099 "SAE: Peer did not accept our SAE group");
1100 sae_pick_next_group(hapd, sta);
1101 goto remove_sta;
1102 }
1103
1104 if (status_code != WLAN_STATUS_SUCCESS)
1105 goto remove_sta;
1106
1107 if (!(hapd->conf->mesh & MESH_ENABLED) &&
1108 sta->sae->state == SAE_COMMITTED) {
1109 /* This is needed in the infrastructure BSS case to
1110 * address a sequence where a STA entry may remain in
1111 * hostapd across two attempts to do SAE authentication
1112 * by the same STA. The second attempt may end up trying
1113 * to use a different group and that would not be
1114 * allowed if we remain in Committed state with the
1115 * previously set parameters. */
1116 pos = mgmt->u.auth.variable;
1117 end = ((const u8 *) mgmt) + len;
1118 if (end - pos >= (int) sizeof(le16) &&
1119 sae_group_allowed(sta->sae, groups,
1120 WPA_GET_LE16(pos)) ==
1121 WLAN_STATUS_SUCCESS) {
1122 /* Do not waste resources deriving the same PWE
1123 * again since the same group is reused. */
1124 sae_set_state(sta, SAE_NOTHING,
1125 "Allow previous PWE to be reused");
1126 allow_reuse = 1;
1127 } else {
1128 sae_set_state(sta, SAE_NOTHING,
1129 "Clear existing state to allow restart");
1130 sae_clear_data(sta->sae);
1131 }
1132 }
1133
1134 resp = sae_parse_commit(sta->sae, mgmt->u.auth.variable,
1135 ((const u8 *) mgmt) + len -
1136 mgmt->u.auth.variable, &token,
1137 &token_len, groups);
1138 if (resp == SAE_SILENTLY_DISCARD) {
1139 wpa_printf(MSG_DEBUG,
1140 "SAE: Drop commit message from " MACSTR " due to reflection attack",
1141 MAC2STR(sta->addr));
1142 goto remove_sta;
1143 }
1144
1145 if (resp == WLAN_STATUS_UNKNOWN_PASSWORD_IDENTIFIER) {
1146 wpa_msg(hapd->msg_ctx, MSG_INFO,
1147 WPA_EVENT_SAE_UNKNOWN_PASSWORD_IDENTIFIER
1148 MACSTR, MAC2STR(sta->addr));
1149 sae_clear_retransmit_timer(hapd, sta);
1150 sae_set_state(sta, SAE_NOTHING,
1151 "Unknown Password Identifier");
1152 goto remove_sta;
1153 }
1154
1155 if (token && check_sae_token(hapd, sta->addr, token, token_len)
1156 < 0) {
1157 wpa_printf(MSG_DEBUG, "SAE: Drop commit message with "
1158 "incorrect token from " MACSTR,
1159 MAC2STR(sta->addr));
1160 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1161 goto remove_sta;
1162 }
1163
1164 if (resp != WLAN_STATUS_SUCCESS)
1165 goto reply;
1166
1167 if (!token && use_sae_anti_clogging(hapd) && !allow_reuse) {
1168 wpa_printf(MSG_DEBUG,
1169 "SAE: Request anti-clogging token from "
1170 MACSTR, MAC2STR(sta->addr));
1171 data = auth_build_token_req(hapd, sta->sae->group,
1172 sta->addr);
1173 resp = WLAN_STATUS_ANTI_CLOGGING_TOKEN_REQ;
1174 if (hapd->conf->mesh & MESH_ENABLED)
1175 sae_set_state(sta, SAE_NOTHING,
1176 "Request anti-clogging token case in mesh");
1177 goto reply;
1178 }
1179
1180 resp = sae_sm_step(hapd, sta, mgmt->bssid, auth_transaction,
1181 allow_reuse, &sta_removed);
1182 } else if (auth_transaction == 2) {
1183 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1184 HOSTAPD_LEVEL_DEBUG,
1185 "SAE authentication (RX confirm, status=%u (%s))",
1186 status_code, status2str(status_code));
1187 if (status_code != WLAN_STATUS_SUCCESS)
1188 goto remove_sta;
1189 if (sta->sae->state >= SAE_CONFIRMED ||
1190 !(hapd->conf->mesh & MESH_ENABLED)) {
1191 const u8 *var;
1192 size_t var_len;
1193 u16 peer_send_confirm;
1194
1195 var = mgmt->u.auth.variable;
1196 var_len = ((u8 *) mgmt) + len - mgmt->u.auth.variable;
1197 if (var_len < 2) {
1198 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1199 goto reply;
1200 }
1201
1202 peer_send_confirm = WPA_GET_LE16(var);
1203
1204 if (sta->sae->state == SAE_ACCEPTED &&
1205 (peer_send_confirm <= sta->sae->rc ||
1206 peer_send_confirm == 0xffff)) {
1207 wpa_printf(MSG_DEBUG,
1208 "SAE: Silently ignore unexpected Confirm from peer "
1209 MACSTR
1210 " (peer-send-confirm=%u Rc=%u)",
1211 MAC2STR(sta->addr),
1212 peer_send_confirm, sta->sae->rc);
1213 return;
1214 }
1215
1216 if (sae_check_confirm(sta->sae, var, var_len) < 0) {
1217 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1218 goto reply;
1219 }
1220 sta->sae->rc = peer_send_confirm;
1221 }
1222 resp = sae_sm_step(hapd, sta, mgmt->bssid, auth_transaction, 0,
1223 &sta_removed);
1224 } else {
1225 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1226 HOSTAPD_LEVEL_DEBUG,
1227 "unexpected SAE authentication transaction %u (status=%u (%s))",
1228 auth_transaction, status_code,
1229 status2str(status_code));
1230 if (status_code != WLAN_STATUS_SUCCESS)
1231 goto remove_sta;
1232 resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
1233 }
1234
1235 reply:
1236 if (!sta_removed && resp != WLAN_STATUS_SUCCESS) {
1237 pos = mgmt->u.auth.variable;
1238 end = ((const u8 *) mgmt) + len;
1239
1240 /* Copy the Finite Cyclic Group field from the request if we
1241 * rejected it as unsupported group. */
1242 if (resp == WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED &&
1243 !data && end - pos >= 2)
1244 data = wpabuf_alloc_copy(pos, 2);
1245
1246 sae_sme_send_external_auth_status(hapd, sta, resp);
1247 send_auth_reply(hapd, mgmt->sa, mgmt->bssid, WLAN_AUTH_SAE,
1248 auth_transaction, resp,
1249 data ? wpabuf_head(data) : (u8 *) "",
1250 data ? wpabuf_len(data) : 0, "auth-sae");
1251 }
1252
1253 remove_sta:
1254 if (!sta_removed && sta->added_unassoc &&
1255 (resp != WLAN_STATUS_SUCCESS ||
1256 status_code != WLAN_STATUS_SUCCESS)) {
1257 hostapd_drv_sta_remove(hapd, sta->addr);
1258 sta->added_unassoc = 0;
1259 }
1260 wpabuf_free(data);
1261 }
1262
1263
1264 /**
1265 * auth_sae_init_committed - Send COMMIT and start SAE in committed state
1266 * @hapd: BSS data for the device initiating the authentication
1267 * @sta: the peer to which commit authentication frame is sent
1268 *
1269 * This function implements Init event handling (IEEE Std 802.11-2012,
1270 * 11.3.8.6.3) in which initial COMMIT message is sent. Prior to calling, the
1271 * sta->sae structure should be initialized appropriately via a call to
1272 * sae_prepare_commit().
1273 */
1274 int auth_sae_init_committed(struct hostapd_data *hapd, struct sta_info *sta)
1275 {
1276 int ret;
1277
1278 if (!sta->sae || !sta->sae->tmp)
1279 return -1;
1280
1281 if (sta->sae->state != SAE_NOTHING)
1282 return -1;
1283
1284 ret = auth_sae_send_commit(hapd, sta, hapd->own_addr, 0);
1285 if (ret)
1286 return -1;
1287
1288 sae_set_state(sta, SAE_COMMITTED, "Init and sent commit");
1289 sta->sae->sync = 0;
1290 sae_set_retransmit_timer(hapd, sta);
1291
1292 return 0;
1293 }
1294
1295
1296 void auth_sae_process_commit(void *eloop_ctx, void *user_ctx)
1297 {
1298 struct hostapd_data *hapd = eloop_ctx;
1299 struct hostapd_sae_commit_queue *q;
1300 unsigned int queue_len;
1301
1302 q = dl_list_first(&hapd->sae_commit_queue,
1303 struct hostapd_sae_commit_queue, list);
1304 if (!q)
1305 return;
1306 wpa_printf(MSG_DEBUG,
1307 "SAE: Process next available message from queue");
1308 dl_list_del(&q->list);
1309 handle_auth(hapd, (const struct ieee80211_mgmt *) q->msg, q->len,
1310 q->rssi, 1);
1311 os_free(q);
1312
1313 if (eloop_is_timeout_registered(auth_sae_process_commit, hapd, NULL))
1314 return;
1315 queue_len = dl_list_len(&hapd->sae_commit_queue);
1316 eloop_register_timeout(0, queue_len * 10000, auth_sae_process_commit,
1317 hapd, NULL);
1318 }
1319
1320
1321 static void auth_sae_queue(struct hostapd_data *hapd,
1322 const struct ieee80211_mgmt *mgmt, size_t len,
1323 int rssi)
1324 {
1325 struct hostapd_sae_commit_queue *q, *q2;
1326 unsigned int queue_len;
1327 const struct ieee80211_mgmt *mgmt2;
1328
1329 queue_len = dl_list_len(&hapd->sae_commit_queue);
1330 if (queue_len >= 15) {
1331 wpa_printf(MSG_DEBUG,
1332 "SAE: No more room in message queue - drop the new frame from "
1333 MACSTR, MAC2STR(mgmt->sa));
1334 return;
1335 }
1336
1337 wpa_printf(MSG_DEBUG, "SAE: Queue Authentication message from "
1338 MACSTR " for processing (queue_len %u)", MAC2STR(mgmt->sa),
1339 queue_len);
1340 q = os_zalloc(sizeof(*q) + len);
1341 if (!q)
1342 return;
1343 q->rssi = rssi;
1344 q->len = len;
1345 os_memcpy(q->msg, mgmt, len);
1346
1347 /* Check whether there is already a queued Authentication frame from the
1348 * same station with the same transaction number and if so, replace that
1349 * queue entry with the new one. This avoids issues with a peer that
1350 * sends multiple times (e.g., due to frequent SAE retries). There is no
1351 * point in us trying to process the old attempts after a new one has
1352 * obsoleted them. */
1353 dl_list_for_each(q2, &hapd->sae_commit_queue,
1354 struct hostapd_sae_commit_queue, list) {
1355 mgmt2 = (const struct ieee80211_mgmt *) q2->msg;
1356 if (os_memcmp(mgmt->sa, mgmt2->sa, ETH_ALEN) == 0 &&
1357 mgmt->u.auth.auth_transaction ==
1358 mgmt2->u.auth.auth_transaction) {
1359 wpa_printf(MSG_DEBUG,
1360 "SAE: Replace queued message from same STA with same transaction number");
1361 dl_list_add(&q2->list, &q->list);
1362 dl_list_del(&q2->list);
1363 os_free(q2);
1364 goto queued;
1365 }
1366 }
1367
1368 /* No pending identical entry, so add to the end of the queue */
1369 dl_list_add_tail(&hapd->sae_commit_queue, &q->list);
1370
1371 queued:
1372 if (eloop_is_timeout_registered(auth_sae_process_commit, hapd, NULL))
1373 return;
1374 eloop_register_timeout(0, queue_len * 10000, auth_sae_process_commit,
1375 hapd, NULL);
1376 }
1377
1378
1379 static int auth_sae_queued_addr(struct hostapd_data *hapd, const u8 *addr)
1380 {
1381 struct hostapd_sae_commit_queue *q;
1382 const struct ieee80211_mgmt *mgmt;
1383
1384 dl_list_for_each(q, &hapd->sae_commit_queue,
1385 struct hostapd_sae_commit_queue, list) {
1386 mgmt = (const struct ieee80211_mgmt *) q->msg;
1387 if (os_memcmp(addr, mgmt->sa, ETH_ALEN) == 0)
1388 return 1;
1389 }
1390
1391 return 0;
1392 }
1393
1394 #endif /* CONFIG_SAE */
1395
1396
1397 static u16 wpa_res_to_status_code(int res)
1398 {
1399 if (res == WPA_INVALID_GROUP)
1400 return WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
1401 if (res == WPA_INVALID_PAIRWISE)
1402 return WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
1403 if (res == WPA_INVALID_AKMP)
1404 return WLAN_STATUS_AKMP_NOT_VALID;
1405 if (res == WPA_ALLOC_FAIL)
1406 return WLAN_STATUS_UNSPECIFIED_FAILURE;
1407 #ifdef CONFIG_IEEE80211W
1408 if (res == WPA_MGMT_FRAME_PROTECTION_VIOLATION)
1409 return WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION;
1410 if (res == WPA_INVALID_MGMT_GROUP_CIPHER)
1411 return WLAN_STATUS_CIPHER_REJECTED_PER_POLICY;
1412 #endif /* CONFIG_IEEE80211W */
1413 if (res == WPA_INVALID_MDIE)
1414 return WLAN_STATUS_INVALID_MDIE;
1415 if (res == WPA_INVALID_PMKID)
1416 return WLAN_STATUS_INVALID_PMKID;
1417 if (res != WPA_IE_OK)
1418 return WLAN_STATUS_INVALID_IE;
1419 return WLAN_STATUS_SUCCESS;
1420 }
1421
1422
1423 #ifdef CONFIG_FILS
1424
1425 static void handle_auth_fils_finish(struct hostapd_data *hapd,
1426 struct sta_info *sta, u16 resp,
1427 struct wpabuf *data, int pub);
1428
1429 void handle_auth_fils(struct hostapd_data *hapd, struct sta_info *sta,
1430 const u8 *pos, size_t len, u16 auth_alg,
1431 u16 auth_transaction, u16 status_code,
1432 void (*cb)(struct hostapd_data *hapd,
1433 struct sta_info *sta, u16 resp,
1434 struct wpabuf *data, int pub))
1435 {
1436 u16 resp = WLAN_STATUS_SUCCESS;
1437 const u8 *end;
1438 struct ieee802_11_elems elems;
1439 int res;
1440 struct wpa_ie_data rsn;
1441 struct rsn_pmksa_cache_entry *pmksa = NULL;
1442
1443 if (auth_transaction != 1 || status_code != WLAN_STATUS_SUCCESS)
1444 return;
1445
1446 end = pos + len;
1447
1448 wpa_hexdump(MSG_DEBUG, "FILS: Authentication frame fields",
1449 pos, end - pos);
1450
1451 /* TODO: FILS PK */
1452 #ifdef CONFIG_FILS_SK_PFS
1453 if (auth_alg == WLAN_AUTH_FILS_SK_PFS) {
1454 u16 group;
1455 struct wpabuf *pub;
1456 size_t elem_len;
1457
1458 /* Using FILS PFS */
1459
1460 /* Finite Cyclic Group */
1461 if (end - pos < 2) {
1462 wpa_printf(MSG_DEBUG,
1463 "FILS: No room for Finite Cyclic Group");
1464 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1465 goto fail;
1466 }
1467 group = WPA_GET_LE16(pos);
1468 pos += 2;
1469 if (group != hapd->conf->fils_dh_group) {
1470 wpa_printf(MSG_DEBUG,
1471 "FILS: Unsupported Finite Cyclic Group: %u (expected %u)",
1472 group, hapd->conf->fils_dh_group);
1473 resp = WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED;
1474 goto fail;
1475 }
1476
1477 crypto_ecdh_deinit(sta->fils_ecdh);
1478 sta->fils_ecdh = crypto_ecdh_init(group);
1479 if (!sta->fils_ecdh) {
1480 wpa_printf(MSG_INFO,
1481 "FILS: Could not initialize ECDH with group %d",
1482 group);
1483 resp = WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED;
1484 goto fail;
1485 }
1486
1487 pub = crypto_ecdh_get_pubkey(sta->fils_ecdh, 1);
1488 if (!pub) {
1489 wpa_printf(MSG_DEBUG,
1490 "FILS: Failed to derive ECDH public key");
1491 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1492 goto fail;
1493 }
1494 elem_len = wpabuf_len(pub);
1495 wpabuf_free(pub);
1496
1497 /* Element */
1498 if ((size_t) (end - pos) < elem_len) {
1499 wpa_printf(MSG_DEBUG, "FILS: No room for Element");
1500 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1501 goto fail;
1502 }
1503
1504 wpabuf_free(sta->fils_g_sta);
1505 sta->fils_g_sta = wpabuf_alloc_copy(pos, elem_len);
1506 wpabuf_clear_free(sta->fils_dh_ss);
1507 sta->fils_dh_ss = crypto_ecdh_set_peerkey(sta->fils_ecdh, 1,
1508 pos, elem_len);
1509 if (!sta->fils_dh_ss) {
1510 wpa_printf(MSG_DEBUG, "FILS: ECDH operation failed");
1511 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1512 goto fail;
1513 }
1514 wpa_hexdump_buf_key(MSG_DEBUG, "FILS: DH_SS", sta->fils_dh_ss);
1515 pos += elem_len;
1516 } else {
1517 crypto_ecdh_deinit(sta->fils_ecdh);
1518 sta->fils_ecdh = NULL;
1519 wpabuf_clear_free(sta->fils_dh_ss);
1520 sta->fils_dh_ss = NULL;
1521 }
1522 #endif /* CONFIG_FILS_SK_PFS */
1523
1524 wpa_hexdump(MSG_DEBUG, "FILS: Remaining IEs", pos, end - pos);
1525 if (ieee802_11_parse_elems(pos, end - pos, &elems, 1) == ParseFailed) {
1526 wpa_printf(MSG_DEBUG, "FILS: Could not parse elements");
1527 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1528 goto fail;
1529 }
1530
1531 /* RSNE */
1532 wpa_hexdump(MSG_DEBUG, "FILS: RSN element",
1533 elems.rsn_ie, elems.rsn_ie_len);
1534 if (!elems.rsn_ie ||
1535 wpa_parse_wpa_ie_rsn(elems.rsn_ie - 2, elems.rsn_ie_len + 2,
1536 &rsn) < 0) {
1537 wpa_printf(MSG_DEBUG, "FILS: No valid RSN element");
1538 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1539 goto fail;
1540 }
1541
1542 if (!sta->wpa_sm)
1543 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth, sta->addr,
1544 NULL);
1545 if (!sta->wpa_sm) {
1546 wpa_printf(MSG_DEBUG,
1547 "FILS: Failed to initialize RSN state machine");
1548 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1549 goto fail;
1550 }
1551
1552 res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,
1553 hapd->iface->freq,
1554 elems.rsn_ie - 2, elems.rsn_ie_len + 2,
1555 elems.mdie, elems.mdie_len, NULL, 0);
1556 resp = wpa_res_to_status_code(res);
1557 if (resp != WLAN_STATUS_SUCCESS)
1558 goto fail;
1559
1560 if (!elems.fils_nonce) {
1561 wpa_printf(MSG_DEBUG, "FILS: No FILS Nonce field");
1562 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1563 goto fail;
1564 }
1565 wpa_hexdump(MSG_DEBUG, "FILS: SNonce", elems.fils_nonce,
1566 FILS_NONCE_LEN);
1567 os_memcpy(sta->fils_snonce, elems.fils_nonce, FILS_NONCE_LEN);
1568
1569 /* PMKID List */
1570 if (rsn.pmkid && rsn.num_pmkid > 0) {
1571 u8 num;
1572 const u8 *pmkid;
1573
1574 wpa_hexdump(MSG_DEBUG, "FILS: PMKID List",
1575 rsn.pmkid, rsn.num_pmkid * PMKID_LEN);
1576
1577 pmkid = rsn.pmkid;
1578 num = rsn.num_pmkid;
1579 while (num) {
1580 wpa_hexdump(MSG_DEBUG, "FILS: PMKID", pmkid, PMKID_LEN);
1581 pmksa = wpa_auth_pmksa_get(hapd->wpa_auth, sta->addr,
1582 pmkid);
1583 if (pmksa)
1584 break;
1585 pmksa = wpa_auth_pmksa_get_fils_cache_id(hapd->wpa_auth,
1586 sta->addr,
1587 pmkid);
1588 if (pmksa)
1589 break;
1590 pmkid += PMKID_LEN;
1591 num--;
1592 }
1593 }
1594 if (pmksa && wpa_auth_sta_key_mgmt(sta->wpa_sm) != pmksa->akmp) {
1595 wpa_printf(MSG_DEBUG,
1596 "FILS: Matching PMKSA cache entry has different AKMP (0x%x != 0x%x) - ignore",
1597 wpa_auth_sta_key_mgmt(sta->wpa_sm), pmksa->akmp);
1598 pmksa = NULL;
1599 }
1600 if (pmksa)
1601 wpa_printf(MSG_DEBUG, "FILS: Found matching PMKSA cache entry");
1602
1603 /* FILS Session */
1604 if (!elems.fils_session) {
1605 wpa_printf(MSG_DEBUG, "FILS: No FILS Session element");
1606 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1607 goto fail;
1608 }
1609 wpa_hexdump(MSG_DEBUG, "FILS: FILS Session", elems.fils_session,
1610 FILS_SESSION_LEN);
1611 os_memcpy(sta->fils_session, elems.fils_session, FILS_SESSION_LEN);
1612
1613 /* FILS Wrapped Data */
1614 if (elems.fils_wrapped_data) {
1615 wpa_hexdump(MSG_DEBUG, "FILS: Wrapped Data",
1616 elems.fils_wrapped_data,
1617 elems.fils_wrapped_data_len);
1618 if (!pmksa) {
1619 #ifndef CONFIG_NO_RADIUS
1620 if (!sta->eapol_sm) {
1621 sta->eapol_sm =
1622 ieee802_1x_alloc_eapol_sm(hapd, sta);
1623 }
1624 wpa_printf(MSG_DEBUG,
1625 "FILS: Forward EAP-Initiate/Re-auth to authentication server");
1626 ieee802_1x_encapsulate_radius(
1627 hapd, sta, elems.fils_wrapped_data,
1628 elems.fils_wrapped_data_len);
1629 sta->fils_pending_cb = cb;
1630 wpa_printf(MSG_DEBUG,
1631 "FILS: Will send Authentication frame once the response from authentication server is available");
1632 sta->flags |= WLAN_STA_PENDING_FILS_ERP;
1633 /* Calculate pending PMKID here so that we do not need
1634 * to maintain a copy of the EAP-Initiate/Reauth
1635 * message. */
1636 if (fils_pmkid_erp(wpa_auth_sta_key_mgmt(sta->wpa_sm),
1637 elems.fils_wrapped_data,
1638 elems.fils_wrapped_data_len,
1639 sta->fils_erp_pmkid) == 0)
1640 sta->fils_erp_pmkid_set = 1;
1641 return;
1642 #else /* CONFIG_NO_RADIUS */
1643 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1644 goto fail;
1645 #endif /* CONFIG_NO_RADIUS */
1646 }
1647 }
1648
1649 fail:
1650 if (cb) {
1651 struct wpabuf *data;
1652 int pub = 0;
1653
1654 data = prepare_auth_resp_fils(hapd, sta, &resp, pmksa, NULL,
1655 NULL, 0, &pub);
1656 if (!data) {
1657 wpa_printf(MSG_DEBUG,
1658 "%s: prepare_auth_resp_fils() returned failure",
1659 __func__);
1660 }
1661
1662 cb(hapd, sta, resp, data, pub);
1663 }
1664 }
1665
1666
1667 static struct wpabuf *
1668 prepare_auth_resp_fils(struct hostapd_data *hapd,
1669 struct sta_info *sta, u16 *resp,
1670 struct rsn_pmksa_cache_entry *pmksa,
1671 struct wpabuf *erp_resp,
1672 const u8 *msk, size_t msk_len,
1673 int *is_pub)
1674 {
1675 u8 fils_nonce[FILS_NONCE_LEN];
1676 size_t ielen;
1677 struct wpabuf *data = NULL;
1678 const u8 *ie;
1679 u8 *ie_buf = NULL;
1680 const u8 *pmk = NULL;
1681 size_t pmk_len = 0;
1682 u8 pmk_buf[PMK_LEN_MAX];
1683 struct wpabuf *pub = NULL;
1684
1685 if (*resp != WLAN_STATUS_SUCCESS)
1686 goto fail;
1687
1688 ie = wpa_auth_get_wpa_ie(hapd->wpa_auth, &ielen);
1689 if (!ie) {
1690 *resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1691 goto fail;
1692 }
1693
1694 if (pmksa) {
1695 /* Add PMKID of the selected PMKSA into RSNE */
1696 ie_buf = os_malloc(ielen + 2 + 2 + PMKID_LEN);
1697 if (!ie_buf) {
1698 *resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1699 goto fail;
1700 }
1701
1702 os_memcpy(ie_buf, ie, ielen);
1703 if (wpa_insert_pmkid(ie_buf, &ielen, pmksa->pmkid) < 0) {
1704 *resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1705 goto fail;
1706 }
1707 ie = ie_buf;
1708 }
1709
1710 if (random_get_bytes(fils_nonce, FILS_NONCE_LEN) < 0) {
1711 *resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1712 goto fail;
1713 }
1714 wpa_hexdump(MSG_DEBUG, "RSN: Generated FILS Nonce",
1715 fils_nonce, FILS_NONCE_LEN);
1716
1717 #ifdef CONFIG_FILS_SK_PFS
1718 if (sta->fils_dh_ss && sta->fils_ecdh) {
1719 pub = crypto_ecdh_get_pubkey(sta->fils_ecdh, 1);
1720 if (!pub) {
1721 *resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1722 goto fail;
1723 }
1724 }
1725 #endif /* CONFIG_FILS_SK_PFS */
1726
1727 data = wpabuf_alloc(1000 + ielen + (pub ? wpabuf_len(pub) : 0));
1728 if (!data) {
1729 *resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1730 goto fail;
1731 }
1732
1733 /* TODO: FILS PK */
1734 #ifdef CONFIG_FILS_SK_PFS
1735 if (pub) {
1736 /* Finite Cyclic Group */
1737 wpabuf_put_le16(data, hapd->conf->fils_dh_group);
1738
1739 /* Element */
1740 wpabuf_put_buf(data, pub);
1741 }
1742 #endif /* CONFIG_FILS_SK_PFS */
1743
1744 /* RSNE */
1745 wpabuf_put_data(data, ie, ielen);
1746
1747 /* MDE when using FILS+FT (already included in ie,ielen with RSNE) */
1748
1749 #ifdef CONFIG_IEEE80211R_AP
1750 if (wpa_key_mgmt_ft(wpa_auth_sta_key_mgmt(sta->wpa_sm))) {
1751 /* FTE[R1KH-ID,R0KH-ID] when using FILS+FT */
1752 int res;
1753 int use_sha384 = wpa_key_mgmt_sha384(
1754 wpa_auth_sta_key_mgmt(sta->wpa_sm));
1755
1756 res = wpa_auth_write_fte(hapd->wpa_auth, use_sha384,
1757 wpabuf_put(data, 0),
1758 wpabuf_tailroom(data));
1759 if (res < 0) {
1760 *resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1761 goto fail;
1762 }
1763 wpabuf_put(data, res);
1764 }
1765 #endif /* CONFIG_IEEE80211R_AP */
1766
1767 /* FILS Nonce */
1768 wpabuf_put_u8(data, WLAN_EID_EXTENSION); /* Element ID */
1769 wpabuf_put_u8(data, 1 + FILS_NONCE_LEN); /* Length */
1770 /* Element ID Extension */
1771 wpabuf_put_u8(data, WLAN_EID_EXT_FILS_NONCE);
1772 wpabuf_put_data(data, fils_nonce, FILS_NONCE_LEN);
1773
1774 /* FILS Session */
1775 wpabuf_put_u8(data, WLAN_EID_EXTENSION); /* Element ID */
1776 wpabuf_put_u8(data, 1 + FILS_SESSION_LEN); /* Length */
1777 /* Element ID Extension */
1778 wpabuf_put_u8(data, WLAN_EID_EXT_FILS_SESSION);
1779 wpabuf_put_data(data, sta->fils_session, FILS_SESSION_LEN);
1780
1781 /* FILS Wrapped Data */
1782 if (!pmksa && erp_resp) {
1783 wpabuf_put_u8(data, WLAN_EID_EXTENSION); /* Element ID */
1784 wpabuf_put_u8(data, 1 + wpabuf_len(erp_resp)); /* Length */
1785 /* Element ID Extension */
1786 wpabuf_put_u8(data, WLAN_EID_EXT_FILS_WRAPPED_DATA);
1787 wpabuf_put_buf(data, erp_resp);
1788
1789 if (fils_rmsk_to_pmk(wpa_auth_sta_key_mgmt(sta->wpa_sm),
1790 msk, msk_len, sta->fils_snonce, fils_nonce,
1791 sta->fils_dh_ss ?
1792 wpabuf_head(sta->fils_dh_ss) : NULL,
1793 sta->fils_dh_ss ?
1794 wpabuf_len(sta->fils_dh_ss) : 0,
1795 pmk_buf, &pmk_len)) {
1796 wpa_printf(MSG_DEBUG, "FILS: Failed to derive PMK");
1797 *resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1798 wpabuf_free(data);
1799 data = NULL;
1800 goto fail;
1801 }
1802 pmk = pmk_buf;
1803
1804 /* Don't use DHss in PTK derivation if PMKSA caching is not
1805 * used. */
1806 wpabuf_clear_free(sta->fils_dh_ss);
1807 sta->fils_dh_ss = NULL;
1808
1809 if (sta->fils_erp_pmkid_set) {
1810 /* TODO: get PMKLifetime from WPA parameters */
1811 unsigned int dot11RSNAConfigPMKLifetime = 43200;
1812 int session_timeout;
1813
1814 session_timeout = dot11RSNAConfigPMKLifetime;
1815 if (sta->session_timeout_set) {
1816 struct os_reltime now, diff;
1817
1818 os_get_reltime(&now);
1819 os_reltime_sub(&sta->session_timeout, &now,
1820 &diff);
1821 session_timeout = diff.sec;
1822 }
1823
1824 sta->fils_erp_pmkid_set = 0;
1825 wpa_auth_add_fils_pmk_pmkid(sta->wpa_sm, pmk, pmk_len,
1826 sta->fils_erp_pmkid);
1827 if (!hapd->conf->disable_pmksa_caching &&
1828 wpa_auth_pmksa_add2(
1829 hapd->wpa_auth, sta->addr,
1830 pmk, pmk_len,
1831 sta->fils_erp_pmkid,
1832 session_timeout,
1833 wpa_auth_sta_key_mgmt(sta->wpa_sm)) < 0) {
1834 wpa_printf(MSG_ERROR,
1835 "FILS: Failed to add PMKSA cache entry based on ERP");
1836 }
1837 }
1838 } else if (pmksa) {
1839 pmk = pmksa->pmk;
1840 pmk_len = pmksa->pmk_len;
1841 }
1842
1843 if (!pmk) {
1844 wpa_printf(MSG_DEBUG, "FILS: No PMK available");
1845 *resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1846 wpabuf_free(data);
1847 data = NULL;
1848 goto fail;
1849 }
1850
1851 if (fils_auth_pmk_to_ptk(sta->wpa_sm, pmk, pmk_len,
1852 sta->fils_snonce, fils_nonce,
1853 sta->fils_dh_ss ?
1854 wpabuf_head(sta->fils_dh_ss) : NULL,
1855 sta->fils_dh_ss ?
1856 wpabuf_len(sta->fils_dh_ss) : 0,
1857 sta->fils_g_sta, pub) < 0) {
1858 *resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1859 wpabuf_free(data);
1860 data = NULL;
1861 goto fail;
1862 }
1863
1864 fail:
1865 if (is_pub)
1866 *is_pub = pub != NULL;
1867 os_free(ie_buf);
1868 wpabuf_free(pub);
1869 wpabuf_clear_free(sta->fils_dh_ss);
1870 sta->fils_dh_ss = NULL;
1871 #ifdef CONFIG_FILS_SK_PFS
1872 crypto_ecdh_deinit(sta->fils_ecdh);
1873 sta->fils_ecdh = NULL;
1874 #endif /* CONFIG_FILS_SK_PFS */
1875 return data;
1876 }
1877
1878
1879 static void handle_auth_fils_finish(struct hostapd_data *hapd,
1880 struct sta_info *sta, u16 resp,
1881 struct wpabuf *data, int pub)
1882 {
1883 u16 auth_alg;
1884
1885 auth_alg = (pub ||
1886 resp == WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED) ?
1887 WLAN_AUTH_FILS_SK_PFS : WLAN_AUTH_FILS_SK;
1888 send_auth_reply(hapd, sta->addr, hapd->own_addr, auth_alg, 2, resp,
1889 data ? wpabuf_head(data) : (u8 *) "",
1890 data ? wpabuf_len(data) : 0, "auth-fils-finish");
1891 wpabuf_free(data);
1892
1893 if (resp == WLAN_STATUS_SUCCESS) {
1894 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1895 HOSTAPD_LEVEL_DEBUG,
1896 "authentication OK (FILS)");
1897 sta->flags |= WLAN_STA_AUTH;
1898 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
1899 sta->auth_alg = pub ? WLAN_AUTH_FILS_SK_PFS : WLAN_AUTH_FILS_SK;
1900 mlme_authenticate_indication(hapd, sta);
1901 }
1902 }
1903
1904
1905 void ieee802_11_finish_fils_auth(struct hostapd_data *hapd,
1906 struct sta_info *sta, int success,
1907 struct wpabuf *erp_resp,
1908 const u8 *msk, size_t msk_len)
1909 {
1910 struct wpabuf *data;
1911 int pub = 0;
1912 u16 resp;
1913
1914 sta->flags &= ~WLAN_STA_PENDING_FILS_ERP;
1915
1916 if (!sta->fils_pending_cb)
1917 return;
1918 resp = success ? WLAN_STATUS_SUCCESS : WLAN_STATUS_UNSPECIFIED_FAILURE;
1919 data = prepare_auth_resp_fils(hapd, sta, &resp, NULL, erp_resp,
1920 msk, msk_len, &pub);
1921 if (!data) {
1922 wpa_printf(MSG_DEBUG,
1923 "%s: prepare_auth_resp_fils() returned failure",
1924 __func__);
1925 }
1926 sta->fils_pending_cb(hapd, sta, resp, data, pub);
1927 }
1928
1929 #endif /* CONFIG_FILS */
1930
1931
1932 int
1933 ieee802_11_allowed_address(struct hostapd_data *hapd, const u8 *addr,
1934 const u8 *msg, size_t len, u32 *session_timeout,
1935 u32 *acct_interim_interval,
1936 struct vlan_description *vlan_id,
1937 struct hostapd_sta_wpa_psk_short **psk,
1938 char **identity, char **radius_cui, int is_probe_req)
1939 {
1940 int res;
1941
1942 os_memset(vlan_id, 0, sizeof(*vlan_id));
1943 res = hostapd_allowed_address(hapd, addr, msg, len,
1944 session_timeout, acct_interim_interval,
1945 vlan_id, psk, identity, radius_cui,
1946 is_probe_req);
1947
1948 if (res == HOSTAPD_ACL_REJECT) {
1949 if (!is_probe_req)
1950 wpa_printf(MSG_DEBUG,
1951 "Station " MACSTR
1952 " not allowed to authenticate",
1953 MAC2STR(addr));
1954 return HOSTAPD_ACL_REJECT;
1955 }
1956
1957 if (res == HOSTAPD_ACL_PENDING) {
1958 wpa_printf(MSG_DEBUG, "Authentication frame from " MACSTR
1959 " waiting for an external authentication",
1960 MAC2STR(addr));
1961 /* Authentication code will re-send the authentication frame
1962 * after it has received (and cached) information from the
1963 * external source. */
1964 return HOSTAPD_ACL_PENDING;
1965 }
1966
1967 return res;
1968 }
1969
1970
1971 static int
1972 ieee802_11_set_radius_info(struct hostapd_data *hapd, struct sta_info *sta,
1973 int res, u32 session_timeout,
1974 u32 acct_interim_interval,
1975 struct vlan_description *vlan_id,
1976 struct hostapd_sta_wpa_psk_short **psk,
1977 char **identity, char **radius_cui)
1978 {
1979 if (vlan_id->notempty &&
1980 !hostapd_vlan_valid(hapd->conf->vlan, vlan_id)) {
1981 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
1982 HOSTAPD_LEVEL_INFO,
1983 "Invalid VLAN %d%s received from RADIUS server",
1984 vlan_id->untagged,
1985 vlan_id->tagged[0] ? "+" : "");
1986 return -1;
1987 }
1988 if (ap_sta_set_vlan(hapd, sta, vlan_id) < 0)
1989 return -1;
1990 if (sta->vlan_id)
1991 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
1992 HOSTAPD_LEVEL_INFO, "VLAN ID %d", sta->vlan_id);
1993
1994 hostapd_free_psk_list(sta->psk);
1995 if (hapd->conf->wpa_psk_radius != PSK_RADIUS_IGNORED) {
1996 sta->psk = *psk;
1997 *psk = NULL;
1998 } else {
1999 sta->psk = NULL;
2000 }
2001
2002 os_free(sta->identity);
2003 sta->identity = *identity;
2004 *identity = NULL;
2005
2006 os_free(sta->radius_cui);
2007 sta->radius_cui = *radius_cui;
2008 *radius_cui = NULL;
2009
2010 if (hapd->conf->acct_interim_interval == 0 && acct_interim_interval)
2011 sta->acct_interim_interval = acct_interim_interval;
2012 if (res == HOSTAPD_ACL_ACCEPT_TIMEOUT) {
2013 sta->session_timeout_set = 1;
2014 os_get_reltime(&sta->session_timeout);
2015 sta->session_timeout.sec += session_timeout;
2016 ap_sta_session_timeout(hapd, sta, session_timeout);
2017 } else {
2018 sta->session_timeout_set = 0;
2019 ap_sta_no_session_timeout(hapd, sta);
2020 }
2021
2022 return 0;
2023 }
2024
2025
2026 static void handle_auth(struct hostapd_data *hapd,
2027 const struct ieee80211_mgmt *mgmt, size_t len,
2028 int rssi, int from_queue)
2029 {
2030 u16 auth_alg, auth_transaction, status_code;
2031 u16 resp = WLAN_STATUS_SUCCESS;
2032 struct sta_info *sta = NULL;
2033 int res, reply_res;
2034 u16 fc;
2035 const u8 *challenge = NULL;
2036 u32 session_timeout, acct_interim_interval;
2037 struct vlan_description vlan_id;
2038 struct hostapd_sta_wpa_psk_short *psk = NULL;
2039 u8 resp_ies[2 + WLAN_AUTH_CHALLENGE_LEN];
2040 size_t resp_ies_len = 0;
2041 char *identity = NULL;
2042 char *radius_cui = NULL;
2043 u16 seq_ctrl;
2044
2045 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
2046 wpa_printf(MSG_INFO, "handle_auth - too short payload (len=%lu)",
2047 (unsigned long) len);
2048 return;
2049 }
2050
2051 #ifdef CONFIG_TESTING_OPTIONS
2052 if (hapd->iconf->ignore_auth_probability > 0.0 &&
2053 drand48() < hapd->iconf->ignore_auth_probability) {
2054 wpa_printf(MSG_INFO,
2055 "TESTING: ignoring auth frame from " MACSTR,
2056 MAC2STR(mgmt->sa));
2057 return;
2058 }
2059 #endif /* CONFIG_TESTING_OPTIONS */
2060
2061 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
2062 auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
2063 status_code = le_to_host16(mgmt->u.auth.status_code);
2064 fc = le_to_host16(mgmt->frame_control);
2065 seq_ctrl = le_to_host16(mgmt->seq_ctrl);
2066
2067 if (len >= IEEE80211_HDRLEN + sizeof(mgmt->u.auth) +
2068 2 + WLAN_AUTH_CHALLENGE_LEN &&
2069 mgmt->u.auth.variable[0] == WLAN_EID_CHALLENGE &&
2070 mgmt->u.auth.variable[1] == WLAN_AUTH_CHALLENGE_LEN)
2071 challenge = &mgmt->u.auth.variable[2];
2072
2073 wpa_printf(MSG_DEBUG, "authentication: STA=" MACSTR " auth_alg=%d "
2074 "auth_transaction=%d status_code=%d wep=%d%s "
2075 "seq_ctrl=0x%x%s%s",
2076 MAC2STR(mgmt->sa), auth_alg, auth_transaction,
2077 status_code, !!(fc & WLAN_FC_ISWEP),
2078 challenge ? " challenge" : "",
2079 seq_ctrl, (fc & WLAN_FC_RETRY) ? " retry" : "",
2080 from_queue ? " (from queue)" : "");
2081
2082 #ifdef CONFIG_NO_RC4
2083 if (auth_alg == WLAN_AUTH_SHARED_KEY) {
2084 wpa_printf(MSG_INFO,
2085 "Unsupported authentication algorithm (%d)",
2086 auth_alg);
2087 resp = WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
2088 goto fail;
2089 }
2090 #endif /* CONFIG_NO_RC4 */
2091
2092 if (hapd->tkip_countermeasures) {
2093 wpa_printf(MSG_DEBUG,
2094 "Ongoing TKIP countermeasures (Michael MIC failure) - reject authentication");
2095 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
2096 goto fail;
2097 }
2098
2099 if (!(((hapd->conf->auth_algs & WPA_AUTH_ALG_OPEN) &&
2100 auth_alg == WLAN_AUTH_OPEN) ||
2101 #ifdef CONFIG_IEEE80211R_AP
2102 (hapd->conf->wpa && wpa_key_mgmt_ft(hapd->conf->wpa_key_mgmt) &&
2103 auth_alg == WLAN_AUTH_FT) ||
2104 #endif /* CONFIG_IEEE80211R_AP */
2105 #ifdef CONFIG_SAE
2106 (hapd->conf->wpa && wpa_key_mgmt_sae(hapd->conf->wpa_key_mgmt) &&
2107 auth_alg == WLAN_AUTH_SAE) ||
2108 #endif /* CONFIG_SAE */
2109 #ifdef CONFIG_FILS
2110 (hapd->conf->wpa && wpa_key_mgmt_fils(hapd->conf->wpa_key_mgmt) &&
2111 auth_alg == WLAN_AUTH_FILS_SK) ||
2112 (hapd->conf->wpa && wpa_key_mgmt_fils(hapd->conf->wpa_key_mgmt) &&
2113 hapd->conf->fils_dh_group &&
2114 auth_alg == WLAN_AUTH_FILS_SK_PFS) ||
2115 #endif /* CONFIG_FILS */
2116 ((hapd->conf->auth_algs & WPA_AUTH_ALG_SHARED) &&
2117 auth_alg == WLAN_AUTH_SHARED_KEY))) {
2118 wpa_printf(MSG_INFO, "Unsupported authentication algorithm (%d)",
2119 auth_alg);
2120 resp = WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
2121 goto fail;
2122 }
2123
2124 if (!(auth_transaction == 1 || auth_alg == WLAN_AUTH_SAE ||
2125 (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 3))) {
2126 wpa_printf(MSG_INFO, "Unknown authentication transaction number (%d)",
2127 auth_transaction);
2128 resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
2129 goto fail;
2130 }
2131
2132 if (os_memcmp(mgmt->sa, hapd->own_addr, ETH_ALEN) == 0) {
2133 wpa_printf(MSG_INFO, "Station " MACSTR " not allowed to authenticate",
2134 MAC2STR(mgmt->sa));
2135 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
2136 goto fail;
2137 }
2138
2139 if (hapd->conf->no_auth_if_seen_on) {
2140 struct hostapd_data *other;
2141
2142 other = sta_track_seen_on(hapd->iface, mgmt->sa,
2143 hapd->conf->no_auth_if_seen_on);
2144 if (other) {
2145 u8 *pos;
2146 u32 info;
2147 u8 op_class, channel, phytype;
2148
2149 wpa_printf(MSG_DEBUG, "%s: Reject authentication from "
2150 MACSTR " since STA has been seen on %s",
2151 hapd->conf->iface, MAC2STR(mgmt->sa),
2152 hapd->conf->no_auth_if_seen_on);
2153
2154 resp = WLAN_STATUS_REJECTED_WITH_SUGGESTED_BSS_TRANSITION;
2155 pos = &resp_ies[0];
2156 *pos++ = WLAN_EID_NEIGHBOR_REPORT;
2157 *pos++ = 13;
2158 os_memcpy(pos, other->own_addr, ETH_ALEN);
2159 pos += ETH_ALEN;
2160 info = 0; /* TODO: BSSID Information */
2161 WPA_PUT_LE32(pos, info);
2162 pos += 4;
2163 if (other->iconf->hw_mode == HOSTAPD_MODE_IEEE80211AD)
2164 phytype = 8; /* dmg */
2165 else if (other->iconf->ieee80211ac)
2166 phytype = 9; /* vht */
2167 else if (other->iconf->ieee80211n)
2168 phytype = 7; /* ht */
2169 else if (other->iconf->hw_mode ==
2170 HOSTAPD_MODE_IEEE80211A)
2171 phytype = 4; /* ofdm */
2172 else if (other->iconf->hw_mode ==
2173 HOSTAPD_MODE_IEEE80211G)
2174 phytype = 6; /* erp */
2175 else
2176 phytype = 5; /* hrdsss */
2177 if (ieee80211_freq_to_channel_ext(
2178 hostapd_hw_get_freq(other,
2179 other->iconf->channel),
2180 other->iconf->secondary_channel,
2181 other->iconf->ieee80211ac,
2182 &op_class, &channel) == NUM_HOSTAPD_MODES) {
2183 op_class = 0;
2184 channel = other->iconf->channel;
2185 }
2186 *pos++ = op_class;
2187 *pos++ = channel;
2188 *pos++ = phytype;
2189 resp_ies_len = pos - &resp_ies[0];
2190 goto fail;
2191 }
2192 }
2193
2194 res = ieee802_11_allowed_address(
2195 hapd, mgmt->sa, (const u8 *) mgmt, len, &session_timeout,
2196 &acct_interim_interval, &vlan_id, &psk, &identity, &radius_cui,
2197 0);
2198 if (res == HOSTAPD_ACL_REJECT) {
2199 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
2200 "Ignore Authentication frame from " MACSTR
2201 " due to ACL reject", MAC2STR(mgmt->sa));
2202 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
2203 goto fail;
2204 }
2205 if (res == HOSTAPD_ACL_PENDING)
2206 return;
2207
2208 #ifdef CONFIG_SAE
2209 if (auth_alg == WLAN_AUTH_SAE && !from_queue &&
2210 (auth_transaction == 1 ||
2211 (auth_transaction == 2 && auth_sae_queued_addr(hapd, mgmt->sa)))) {
2212 /* Handle SAE Authentication commit message through a queue to
2213 * provide more control for postponing the needed heavy
2214 * processing under a possible DoS attack scenario. In addition,
2215 * queue SAE Authentication confirm message if there happens to
2216 * be a queued commit message from the same peer. This is needed
2217 * to avoid reordering Authentication frames within the same
2218 * SAE exchange. */
2219 auth_sae_queue(hapd, mgmt, len, rssi);
2220 return;
2221 }
2222 #endif /* CONFIG_SAE */
2223
2224 sta = ap_get_sta(hapd, mgmt->sa);
2225 if (sta) {
2226 sta->flags &= ~WLAN_STA_PENDING_FILS_ERP;
2227 sta->ft_over_ds = 0;
2228 if ((fc & WLAN_FC_RETRY) &&
2229 sta->last_seq_ctrl != WLAN_INVALID_MGMT_SEQ &&
2230 sta->last_seq_ctrl == seq_ctrl &&
2231 sta->last_subtype == WLAN_FC_STYPE_AUTH) {
2232 hostapd_logger(hapd, sta->addr,
2233 HOSTAPD_MODULE_IEEE80211,
2234 HOSTAPD_LEVEL_DEBUG,
2235 "Drop repeated authentication frame seq_ctrl=0x%x",
2236 seq_ctrl);
2237 return;
2238 }
2239 #ifdef CONFIG_MESH
2240 if ((hapd->conf->mesh & MESH_ENABLED) &&
2241 sta->plink_state == PLINK_BLOCKED) {
2242 wpa_printf(MSG_DEBUG, "Mesh peer " MACSTR
2243 " is blocked - drop Authentication frame",
2244 MAC2STR(mgmt->sa));
2245 return;
2246 }
2247 #endif /* CONFIG_MESH */
2248 } else {
2249 #ifdef CONFIG_MESH
2250 if (hapd->conf->mesh & MESH_ENABLED) {
2251 /* if the mesh peer is not available, we don't do auth.
2252 */
2253 wpa_printf(MSG_DEBUG, "Mesh peer " MACSTR
2254 " not yet known - drop Authentication frame",
2255 MAC2STR(mgmt->sa));
2256 /*
2257 * Save a copy of the frame so that it can be processed
2258 * if a new peer entry is added shortly after this.
2259 */
2260 wpabuf_free(hapd->mesh_pending_auth);
2261 hapd->mesh_pending_auth = wpabuf_alloc_copy(mgmt, len);
2262 os_get_reltime(&hapd->mesh_pending_auth_time);
2263 return;
2264 }
2265 #endif /* CONFIG_MESH */
2266
2267 sta = ap_sta_add(hapd, mgmt->sa);
2268 if (!sta) {
2269 wpa_printf(MSG_DEBUG, "ap_sta_add() failed");
2270 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
2271 goto fail;
2272 }
2273 }
2274 sta->last_seq_ctrl = seq_ctrl;
2275 sta->last_subtype = WLAN_FC_STYPE_AUTH;
2276 #ifdef CONFIG_MBO
2277 sta->auth_rssi = rssi;
2278 #endif /* CONFIG_MBO */
2279
2280 res = ieee802_11_set_radius_info(
2281 hapd, sta, res, session_timeout, acct_interim_interval,
2282 &vlan_id, &psk, &identity, &radius_cui);
2283 if (res) {
2284 wpa_printf(MSG_DEBUG, "ieee802_11_set_radius_info() failed");
2285 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
2286 goto fail;
2287 }
2288
2289 sta->flags &= ~WLAN_STA_PREAUTH;
2290 ieee802_1x_notify_pre_auth(sta->eapol_sm, 0);
2291
2292 /*
2293 * If the driver supports full AP client state, add a station to the
2294 * driver before sending authentication reply to make sure the driver
2295 * has resources, and not to go through the entire authentication and
2296 * association handshake, and fail it at the end.
2297 *
2298 * If this is not the first transaction, in a multi-step authentication
2299 * algorithm, the station already exists in the driver
2300 * (sta->added_unassoc = 1) so skip it.
2301 *
2302 * In mesh mode, the station was already added to the driver when the
2303 * NEW_PEER_CANDIDATE event is received.
2304 *
2305 * If PMF was negotiated for the existing association, skip this to
2306 * avoid dropping the STA entry and the associated keys. This is needed
2307 * to allow the original connection work until the attempt can complete
2308 * (re)association, so that unprotected Authentication frame cannot be
2309 * used to bypass PMF protection.
2310 */
2311 if (FULL_AP_CLIENT_STATE_SUPP(hapd->iface->drv_flags) &&
2312 (!(sta->flags & WLAN_STA_MFP) || !ap_sta_is_authorized(sta)) &&
2313 !(hapd->conf->mesh & MESH_ENABLED) &&
2314 !(sta->added_unassoc)) {
2315 /*
2316 * If a station that is already associated to the AP, is trying
2317 * to authenticate again, remove the STA entry, in order to make
2318 * sure the STA PS state gets cleared and configuration gets
2319 * updated. To handle this, station's added_unassoc flag is
2320 * cleared once the station has completed association.
2321 */
2322 ap_sta_set_authorized(hapd, sta, 0);
2323 hostapd_drv_sta_remove(hapd, sta->addr);
2324 sta->flags &= ~(WLAN_STA_ASSOC | WLAN_STA_AUTH |
2325 WLAN_STA_AUTHORIZED);
2326
2327 if (hostapd_sta_add(hapd, sta->addr, 0, 0, NULL, 0, 0,
2328 NULL, NULL, sta->flags, 0, 0, 0, 0)) {
2329 hostapd_logger(hapd, sta->addr,
2330 HOSTAPD_MODULE_IEEE80211,
2331 HOSTAPD_LEVEL_NOTICE,
2332 "Could not add STA to kernel driver");
2333 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
2334 goto fail;
2335 }
2336
2337 sta->added_unassoc = 1;
2338 }
2339
2340 switch (auth_alg) {
2341 case WLAN_AUTH_OPEN:
2342 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2343 HOSTAPD_LEVEL_DEBUG,
2344 "authentication OK (open system)");
2345 sta->flags |= WLAN_STA_AUTH;
2346 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
2347 sta->auth_alg = WLAN_AUTH_OPEN;
2348 mlme_authenticate_indication(hapd, sta);
2349 break;
2350 #ifndef CONFIG_NO_RC4
2351 case WLAN_AUTH_SHARED_KEY:
2352 resp = auth_shared_key(hapd, sta, auth_transaction, challenge,
2353 fc & WLAN_FC_ISWEP);
2354 if (resp != 0)
2355 wpa_printf(MSG_DEBUG,
2356 "auth_shared_key() failed: status=%d", resp);
2357 sta->auth_alg = WLAN_AUTH_SHARED_KEY;
2358 mlme_authenticate_indication(hapd, sta);
2359 if (sta->challenge && auth_transaction == 1) {
2360 resp_ies[0] = WLAN_EID_CHALLENGE;
2361 resp_ies[1] = WLAN_AUTH_CHALLENGE_LEN;
2362 os_memcpy(resp_ies + 2, sta->challenge,
2363 WLAN_AUTH_CHALLENGE_LEN);
2364 resp_ies_len = 2 + WLAN_AUTH_CHALLENGE_LEN;
2365 }
2366 break;
2367 #endif /* CONFIG_NO_RC4 */
2368 #ifdef CONFIG_IEEE80211R_AP
2369 case WLAN_AUTH_FT:
2370 sta->auth_alg = WLAN_AUTH_FT;
2371 if (sta->wpa_sm == NULL)
2372 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
2373 sta->addr, NULL);
2374 if (sta->wpa_sm == NULL) {
2375 wpa_printf(MSG_DEBUG, "FT: Failed to initialize WPA "
2376 "state machine");
2377 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
2378 goto fail;
2379 }
2380 wpa_ft_process_auth(sta->wpa_sm, mgmt->bssid,
2381 auth_transaction, mgmt->u.auth.variable,
2382 len - IEEE80211_HDRLEN -
2383 sizeof(mgmt->u.auth),
2384 handle_auth_ft_finish, hapd);
2385 /* handle_auth_ft_finish() callback will complete auth. */
2386 return;
2387 #endif /* CONFIG_IEEE80211R_AP */
2388 #ifdef CONFIG_SAE
2389 case WLAN_AUTH_SAE:
2390 #ifdef CONFIG_MESH
2391 if (status_code == WLAN_STATUS_SUCCESS &&
2392 hapd->conf->mesh & MESH_ENABLED) {
2393 if (sta->wpa_sm == NULL)
2394 sta->wpa_sm =
2395 wpa_auth_sta_init(hapd->wpa_auth,
2396 sta->addr, NULL);
2397 if (sta->wpa_sm == NULL) {
2398 wpa_printf(MSG_DEBUG,
2399 "SAE: Failed to initialize WPA state machine");
2400 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
2401 goto fail;
2402 }
2403 }
2404 #endif /* CONFIG_MESH */
2405 handle_auth_sae(hapd, sta, mgmt, len, auth_transaction,
2406 status_code);
2407 return;
2408 #endif /* CONFIG_SAE */
2409 #ifdef CONFIG_FILS
2410 case WLAN_AUTH_FILS_SK:
2411 case WLAN_AUTH_FILS_SK_PFS:
2412 handle_auth_fils(hapd, sta, mgmt->u.auth.variable,
2413 len - IEEE80211_HDRLEN - sizeof(mgmt->u.auth),
2414 auth_alg, auth_transaction, status_code,
2415 handle_auth_fils_finish);
2416 return;
2417 #endif /* CONFIG_FILS */
2418 }
2419
2420 fail:
2421 os_free(identity);
2422 os_free(radius_cui);
2423 hostapd_free_psk_list(psk);
2424
2425 reply_res = send_auth_reply(hapd, mgmt->sa, mgmt->bssid, auth_alg,
2426 auth_transaction + 1, resp, resp_ies,
2427 resp_ies_len, "handle-auth");
2428
2429 if (sta && sta->added_unassoc && (resp != WLAN_STATUS_SUCCESS ||
2430 reply_res != WLAN_STATUS_SUCCESS)) {
2431 hostapd_drv_sta_remove(hapd, sta->addr);
2432 sta->added_unassoc = 0;
2433 }
2434 }
2435
2436
2437 int hostapd_get_aid(struct hostapd_data *hapd, struct sta_info *sta)
2438 {
2439 int i, j = 32, aid;
2440
2441 /* get a unique AID */
2442 if (sta->aid > 0) {
2443 wpa_printf(MSG_DEBUG, " old AID %d", sta->aid);
2444 return 0;
2445 }
2446
2447 if (TEST_FAIL())
2448 return -1;
2449
2450 for (i = 0; i < AID_WORDS; i++) {
2451 if (hapd->sta_aid[i] == (u32) -1)
2452 continue;
2453 for (j = 0; j < 32; j++) {
2454 if (!(hapd->sta_aid[i] & BIT(j)))
2455 break;
2456 }
2457 if (j < 32)
2458 break;
2459 }
2460 if (j == 32)
2461 return -1;
2462 aid = i * 32 + j + 1;
2463 if (aid > 2007)
2464 return -1;
2465
2466 sta->aid = aid;
2467 hapd->sta_aid[i] |= BIT(j);
2468 wpa_printf(MSG_DEBUG, " new AID %d", sta->aid);
2469 return 0;
2470 }
2471
2472
2473 static u16 check_ssid(struct hostapd_data *hapd, struct sta_info *sta,
2474 const u8 *ssid_ie, size_t ssid_ie_len)
2475 {
2476 if (ssid_ie == NULL)
2477 return WLAN_STATUS_UNSPECIFIED_FAILURE;
2478
2479 if (ssid_ie_len != hapd->conf->ssid.ssid_len ||
2480 os_memcmp(ssid_ie, hapd->conf->ssid.ssid, ssid_ie_len) != 0) {
2481 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2482 HOSTAPD_LEVEL_INFO,
2483 "Station tried to associate with unknown SSID "
2484 "'%s'", wpa_ssid_txt(ssid_ie, ssid_ie_len));
2485 return WLAN_STATUS_UNSPECIFIED_FAILURE;
2486 }
2487
2488 return WLAN_STATUS_SUCCESS;
2489 }
2490
2491
2492 static u16 check_wmm(struct hostapd_data *hapd, struct sta_info *sta,
2493 const u8 *wmm_ie, size_t wmm_ie_len)
2494 {
2495 sta->flags &= ~WLAN_STA_WMM;
2496 sta->qosinfo = 0;
2497 if (wmm_ie && hapd->conf->wmm_enabled) {
2498 struct wmm_information_element *wmm;
2499
2500 if (!hostapd_eid_wmm_valid(hapd, wmm_ie, wmm_ie_len)) {
2501 hostapd_logger(hapd, sta->addr,
2502 HOSTAPD_MODULE_WPA,
2503 HOSTAPD_LEVEL_DEBUG,
2504 "invalid WMM element in association "
2505 "request");
2506 return WLAN_STATUS_UNSPECIFIED_FAILURE;
2507 }
2508
2509 sta->flags |= WLAN_STA_WMM;
2510 wmm = (struct wmm_information_element *) wmm_ie;
2511 sta->qosinfo = wmm->qos_info;
2512 }
2513 return WLAN_STATUS_SUCCESS;
2514 }
2515
2516 static u16 check_multi_ap(struct hostapd_data *hapd, struct sta_info *sta,
2517 const u8 *multi_ap_ie, size_t multi_ap_len)
2518 {
2519 u8 multi_ap_value = 0;
2520
2521 sta->flags &= ~WLAN_STA_MULTI_AP;
2522
2523 if (!hapd->conf->multi_ap)
2524 return WLAN_STATUS_SUCCESS;
2525
2526 if (multi_ap_ie) {
2527 const u8 *multi_ap_subelem;
2528
2529 multi_ap_subelem = get_ie(multi_ap_ie + 4,
2530 multi_ap_len - 4,
2531 MULTI_AP_SUB_ELEM_TYPE);
2532 if (multi_ap_subelem && multi_ap_subelem[1] == 1) {
2533 multi_ap_value = multi_ap_subelem[2];
2534 } else {
2535 hostapd_logger(hapd, sta->addr,
2536 HOSTAPD_MODULE_IEEE80211,
2537 HOSTAPD_LEVEL_INFO,
2538 "Multi-AP IE has missing or invalid Multi-AP subelement");
2539 return WLAN_STATUS_INVALID_IE;
2540 }
2541 }
2542
2543 if (multi_ap_value && multi_ap_value != MULTI_AP_BACKHAUL_STA)
2544 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2545 HOSTAPD_LEVEL_INFO,
2546 "Multi-AP IE with unexpected value 0x%02x",
2547 multi_ap_value);
2548
2549 if (!(multi_ap_value & MULTI_AP_BACKHAUL_STA)) {
2550 if (hapd->conf->multi_ap & FRONTHAUL_BSS)
2551 return WLAN_STATUS_SUCCESS;
2552
2553 hostapd_logger(hapd, sta->addr,
2554 HOSTAPD_MODULE_IEEE80211,
2555 HOSTAPD_LEVEL_INFO,
2556 "Non-Multi-AP STA tries to associate with backhaul-only BSS");
2557 return WLAN_STATUS_ASSOC_DENIED_UNSPEC;
2558 }
2559
2560 if (!(hapd->conf->multi_ap & BACKHAUL_BSS))
2561 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2562 HOSTAPD_LEVEL_DEBUG,
2563 "Backhaul STA tries to associate with fronthaul-only BSS");
2564
2565 sta->flags |= WLAN_STA_MULTI_AP;
2566 return WLAN_STATUS_SUCCESS;
2567 }
2568
2569
2570 static u16 copy_supp_rates(struct hostapd_data *hapd, struct sta_info *sta,
2571 struct ieee802_11_elems *elems)
2572 {
2573 /* Supported rates not used in IEEE 802.11ad/DMG */
2574 if (hapd->iface->current_mode &&
2575 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211AD)
2576 return WLAN_STATUS_SUCCESS;
2577
2578 if (!elems->supp_rates) {
2579 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2580 HOSTAPD_LEVEL_DEBUG,
2581 "No supported rates element in AssocReq");
2582 return WLAN_STATUS_UNSPECIFIED_FAILURE;
2583 }
2584
2585 if (elems->supp_rates_len + elems->ext_supp_rates_len >
2586 sizeof(sta->supported_rates)) {
2587 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2588 HOSTAPD_LEVEL_DEBUG,
2589 "Invalid supported rates element length %d+%d",
2590 elems->supp_rates_len,
2591 elems->ext_supp_rates_len);
2592 return WLAN_STATUS_UNSPECIFIED_FAILURE;
2593 }
2594
2595 sta->supported_rates_len = merge_byte_arrays(
2596 sta->supported_rates, sizeof(sta->supported_rates),
2597 elems->supp_rates, elems->supp_rates_len,
2598 elems->ext_supp_rates, elems->ext_supp_rates_len);
2599
2600 return WLAN_STATUS_SUCCESS;
2601 }
2602
2603
2604 static u16 check_ext_capab(struct hostapd_data *hapd, struct sta_info *sta,
2605 const u8 *ext_capab_ie, size_t ext_capab_ie_len)
2606 {
2607 #ifdef CONFIG_INTERWORKING
2608 /* check for QoS Map support */
2609 if (ext_capab_ie_len >= 5) {
2610 if (ext_capab_ie[4] & 0x01)
2611 sta->qos_map_enabled = 1;
2612 }
2613 #endif /* CONFIG_INTERWORKING */
2614
2615 if (ext_capab_ie_len > 0) {
2616 sta->ecsa_supported = !!(ext_capab_ie[0] & BIT(2));
2617 os_free(sta->ext_capability);
2618 sta->ext_capability = os_malloc(1 + ext_capab_ie_len);
2619 if (sta->ext_capability) {
2620 sta->ext_capability[0] = ext_capab_ie_len;
2621 os_memcpy(sta->ext_capability + 1, ext_capab_ie,
2622 ext_capab_ie_len);
2623 }
2624 }
2625
2626 return WLAN_STATUS_SUCCESS;
2627 }
2628
2629
2630 #ifdef CONFIG_OWE
2631
2632 static int owe_group_supported(struct hostapd_data *hapd, u16 group)
2633 {
2634 int i;
2635 int *groups = hapd->conf->owe_groups;
2636
2637 if (group != 19 && group != 20 && group != 21)
2638 return 0;
2639
2640 if (!groups)
2641 return 1;
2642
2643 for (i = 0; groups[i] > 0; i++) {
2644 if (groups[i] == group)
2645 return 1;
2646 }
2647
2648 return 0;
2649 }
2650
2651
2652 static u16 owe_process_assoc_req(struct hostapd_data *hapd,
2653 struct sta_info *sta, const u8 *owe_dh,
2654 u8 owe_dh_len)
2655 {
2656 struct wpabuf *secret, *pub, *hkey;
2657 int res;
2658 u8 prk[SHA512_MAC_LEN], pmkid[SHA512_MAC_LEN];
2659 const char *info = "OWE Key Generation";
2660 const u8 *addr[2];
2661 size_t len[2];
2662 u16 group;
2663 size_t hash_len, prime_len;
2664
2665 if (wpa_auth_sta_get_pmksa(sta->wpa_sm)) {
2666 wpa_printf(MSG_DEBUG, "OWE: Using PMKSA caching");
2667 return WLAN_STATUS_SUCCESS;
2668 }
2669
2670 group = WPA_GET_LE16(owe_dh);
2671 if (!owe_group_supported(hapd, group)) {
2672 wpa_printf(MSG_DEBUG, "OWE: Unsupported DH group %u", group);
2673 return WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED;
2674 }
2675 if (group == 19)
2676 prime_len = 32;
2677 else if (group == 20)
2678 prime_len = 48;
2679 else if (group == 21)
2680 prime_len = 66;
2681 else
2682 return WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED;
2683
2684 crypto_ecdh_deinit(sta->owe_ecdh);
2685 sta->owe_ecdh = crypto_ecdh_init(group);
2686 if (!sta->owe_ecdh)
2687 return WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED;
2688 sta->owe_group = group;
2689
2690 secret = crypto_ecdh_set_peerkey(sta->owe_ecdh, 0, owe_dh + 2,
2691 owe_dh_len - 2);
2692 secret = wpabuf_zeropad(secret, prime_len);
2693 if (!secret) {
2694 wpa_printf(MSG_DEBUG, "OWE: Invalid peer DH public key");
2695 return WLAN_STATUS_UNSPECIFIED_FAILURE;
2696 }
2697 wpa_hexdump_buf_key(MSG_DEBUG, "OWE: DH shared secret", secret);
2698
2699 /* prk = HKDF-extract(C | A | group, z) */
2700
2701 pub = crypto_ecdh_get_pubkey(sta->owe_ecdh, 0);
2702 if (!pub) {
2703 wpabuf_clear_free(secret);
2704 return WLAN_STATUS_UNSPECIFIED_FAILURE;
2705 }
2706
2707 /* PMKID = Truncate-128(Hash(C | A)) */
2708 addr[0] = owe_dh + 2;
2709 len[0] = owe_dh_len - 2;
2710 addr[1] = wpabuf_head(pub);
2711 len[1] = wpabuf_len(pub);
2712 if (group == 19) {
2713 res = sha256_vector(2, addr, len, pmkid);
2714 hash_len = SHA256_MAC_LEN;
2715 } else if (group == 20) {
2716 res = sha384_vector(2, addr, len, pmkid);
2717 hash_len = SHA384_MAC_LEN;
2718 } else if (group == 21) {
2719 res = sha512_vector(2, addr, len, pmkid);
2720 hash_len = SHA512_MAC_LEN;
2721 } else {
2722 wpabuf_free(pub);
2723 wpabuf_clear_free(secret);
2724 return WLAN_STATUS_UNSPECIFIED_FAILURE;
2725 }
2726 pub = wpabuf_zeropad(pub, prime_len);
2727 if (res < 0 || !pub) {
2728 wpabuf_free(pub);
2729 wpabuf_clear_free(secret);
2730 return WLAN_STATUS_UNSPECIFIED_FAILURE;
2731 }
2732
2733 hkey = wpabuf_alloc(owe_dh_len - 2 + wpabuf_len(pub) + 2);
2734 if (!hkey) {
2735 wpabuf_free(pub);
2736 wpabuf_clear_free(secret);
2737 return WLAN_STATUS_UNSPECIFIED_FAILURE;
2738 }
2739
2740 wpabuf_put_data(hkey, owe_dh + 2, owe_dh_len - 2); /* C */
2741 wpabuf_put_buf(hkey, pub); /* A */
2742 wpabuf_free(pub);
2743 wpabuf_put_le16(hkey, group); /* group */
2744 if (group == 19)
2745 res = hmac_sha256(wpabuf_head(hkey), wpabuf_len(hkey),
2746 wpabuf_head(secret), wpabuf_len(secret), prk);
2747 else if (group == 20)
2748 res = hmac_sha384(wpabuf_head(hkey), wpabuf_len(hkey),
2749 wpabuf_head(secret), wpabuf_len(secret), prk);
2750 else if (group == 21)
2751 res = hmac_sha512(wpabuf_head(hkey), wpabuf_len(hkey),
2752 wpabuf_head(secret), wpabuf_len(secret), prk);
2753 wpabuf_clear_free(hkey);
2754 wpabuf_clear_free(secret);
2755 if (res < 0)
2756 return WLAN_STATUS_UNSPECIFIED_FAILURE;
2757
2758 wpa_hexdump_key(MSG_DEBUG, "OWE: prk", prk, hash_len);
2759
2760 /* PMK = HKDF-expand(prk, "OWE Key Generation", n) */
2761
2762 os_free(sta->owe_pmk);
2763 sta->owe_pmk = os_malloc(hash_len);
2764 if (!sta->owe_pmk) {
2765 os_memset(prk, 0, SHA512_MAC_LEN);
2766 return WLAN_STATUS_UNSPECIFIED_FAILURE;
2767 }
2768
2769 if (group == 19)
2770 res = hmac_sha256_kdf(prk, hash_len, NULL, (const u8 *) info,
2771 os_strlen(info), sta->owe_pmk, hash_len);
2772 else if (group == 20)
2773 res = hmac_sha384_kdf(prk, hash_len, NULL, (const u8 *) info,
2774 os_strlen(info), sta->owe_pmk, hash_len);
2775 else if (group == 21)
2776 res = hmac_sha512_kdf(prk, hash_len, NULL, (const u8 *) info,
2777 os_strlen(info), sta->owe_pmk, hash_len);
2778 os_memset(prk, 0, SHA512_MAC_LEN);
2779 if (res < 0) {
2780 os_free(sta->owe_pmk);
2781 sta->owe_pmk = NULL;
2782 return WLAN_STATUS_UNSPECIFIED_FAILURE;
2783 }
2784 sta->owe_pmk_len = hash_len;
2785
2786 wpa_hexdump_key(MSG_DEBUG, "OWE: PMK", sta->owe_pmk, sta->owe_pmk_len);
2787 wpa_hexdump(MSG_DEBUG, "OWE: PMKID", pmkid, PMKID_LEN);
2788 wpa_auth_pmksa_add2(hapd->wpa_auth, sta->addr, sta->owe_pmk,
2789 sta->owe_pmk_len, pmkid, 0, WPA_KEY_MGMT_OWE);
2790
2791 return WLAN_STATUS_SUCCESS;
2792 }
2793
2794 #endif /* CONFIG_OWE */
2795
2796
2797 static u16 check_assoc_ies(struct hostapd_data *hapd, struct sta_info *sta,
2798 const u8 *ies, size_t ies_len, int reassoc)
2799 {
2800 struct ieee802_11_elems elems;
2801 u16 resp;
2802 const u8 *wpa_ie;
2803 size_t wpa_ie_len;
2804 const u8 *p2p_dev_addr = NULL;
2805
2806 if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed) {
2807 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2808 HOSTAPD_LEVEL_INFO, "Station sent an invalid "
2809 "association request");
2810 return WLAN_STATUS_UNSPECIFIED_FAILURE;
2811 }
2812
2813 resp = check_ssid(hapd, sta, elems.ssid, elems.ssid_len);
2814 if (resp != WLAN_STATUS_SUCCESS)
2815 return resp;
2816 resp = check_wmm(hapd, sta, elems.wmm, elems.wmm_len);
2817 if (resp != WLAN_STATUS_SUCCESS)
2818 return resp;
2819 resp = check_ext_capab(hapd, sta, elems.ext_capab, elems.ext_capab_len);
2820 if (resp != WLAN_STATUS_SUCCESS)
2821 return resp;
2822 resp = copy_supp_rates(hapd, sta, &elems);
2823 if (resp != WLAN_STATUS_SUCCESS)
2824 return resp;
2825
2826 resp = check_multi_ap(hapd, sta, elems.multi_ap, elems.multi_ap_len);
2827 if (resp != WLAN_STATUS_SUCCESS)
2828 return resp;
2829
2830 #ifdef CONFIG_IEEE80211N
2831 resp = copy_sta_ht_capab(hapd, sta, elems.ht_capabilities);
2832 if (resp != WLAN_STATUS_SUCCESS)
2833 return resp;
2834 if (hapd->iconf->ieee80211n && hapd->iconf->require_ht &&
2835 !(sta->flags & WLAN_STA_HT)) {
2836 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2837 HOSTAPD_LEVEL_INFO, "Station does not support "
2838 "mandatory HT PHY - reject association");
2839 return WLAN_STATUS_ASSOC_DENIED_NO_HT;
2840 }
2841 #endif /* CONFIG_IEEE80211N */
2842
2843 #ifdef CONFIG_IEEE80211AC
2844 if (hapd->iconf->ieee80211ac) {
2845 resp = copy_sta_vht_capab(hapd, sta, elems.vht_capabilities);
2846 if (resp != WLAN_STATUS_SUCCESS)
2847 return resp;
2848
2849 resp = copy_sta_vht_oper(hapd, sta, elems.vht_operation);
2850 if (resp != WLAN_STATUS_SUCCESS)
2851 return resp;
2852
2853 resp = set_sta_vht_opmode(hapd, sta, elems.vht_opmode_notif);
2854 if (resp != WLAN_STATUS_SUCCESS)
2855 return resp;
2856 }
2857
2858 if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht &&
2859 !(sta->flags & WLAN_STA_VHT)) {
2860 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2861 HOSTAPD_LEVEL_INFO, "Station does not support "
2862 "mandatory VHT PHY - reject association");
2863 return WLAN_STATUS_ASSOC_DENIED_NO_VHT;
2864 }
2865
2866 if (hapd->conf->vendor_vht && !elems.vht_capabilities) {
2867 resp = copy_sta_vendor_vht(hapd, sta, elems.vendor_vht,
2868 elems.vendor_vht_len);
2869 if (resp != WLAN_STATUS_SUCCESS)
2870 return resp;
2871 }
2872 #endif /* CONFIG_IEEE80211AC */
2873
2874 #ifdef CONFIG_P2P
2875 if (elems.p2p) {
2876 wpabuf_free(sta->p2p_ie);
2877 sta->p2p_ie = ieee802_11_vendor_ie_concat(ies, ies_len,
2878 P2P_IE_VENDOR_TYPE);
2879 if (sta->p2p_ie)
2880 p2p_dev_addr = p2p_get_go_dev_addr(sta->p2p_ie);
2881 } else {
2882 wpabuf_free(sta->p2p_ie);
2883 sta->p2p_ie = NULL;
2884 }
2885 #endif /* CONFIG_P2P */
2886
2887 if ((hapd->conf->wpa & WPA_PROTO_RSN) && elems.rsn_ie) {
2888 wpa_ie = elems.rsn_ie;
2889 wpa_ie_len = elems.rsn_ie_len;
2890 } else if ((hapd->conf->wpa & WPA_PROTO_WPA) &&
2891 elems.wpa_ie) {
2892 wpa_ie = elems.wpa_ie;
2893 wpa_ie_len = elems.wpa_ie_len;
2894 } else {
2895 wpa_ie = NULL;
2896 wpa_ie_len = 0;
2897 }
2898
2899 #ifdef CONFIG_WPS
2900 sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS | WLAN_STA_WPS2);
2901 if (hapd->conf->wps_state && elems.wps_ie) {
2902 wpa_printf(MSG_DEBUG, "STA included WPS IE in (Re)Association "
2903 "Request - assume WPS is used");
2904 sta->flags |= WLAN_STA_WPS;
2905 wpabuf_free(sta->wps_ie);
2906 sta->wps_ie = ieee802_11_vendor_ie_concat(ies, ies_len,
2907 WPS_IE_VENDOR_TYPE);
2908 if (sta->wps_ie && wps_is_20(sta->wps_ie)) {
2909 wpa_printf(MSG_DEBUG, "WPS: STA supports WPS 2.0");
2910 sta->flags |= WLAN_STA_WPS2;
2911 }
2912 wpa_ie = NULL;
2913 wpa_ie_len = 0;
2914 if (sta->wps_ie && wps_validate_assoc_req(sta->wps_ie) < 0) {
2915 wpa_printf(MSG_DEBUG, "WPS: Invalid WPS IE in "
2916 "(Re)Association Request - reject");
2917 return WLAN_STATUS_INVALID_IE;
2918 }
2919 } else if (hapd->conf->wps_state && wpa_ie == NULL) {
2920 wpa_printf(MSG_DEBUG, "STA did not include WPA/RSN IE in "
2921 "(Re)Association Request - possible WPS use");
2922 sta->flags |= WLAN_STA_MAYBE_WPS;
2923 } else
2924 #endif /* CONFIG_WPS */
2925 if (hapd->conf->wpa && wpa_ie == NULL) {
2926 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
2927 HOSTAPD_LEVEL_INFO,
2928 "No WPA/RSN IE in association request");
2929 return WLAN_STATUS_INVALID_IE;
2930 }
2931
2932 if (hapd->conf->wpa && wpa_ie) {
2933 int res;
2934 wpa_ie -= 2;
2935 wpa_ie_len += 2;
2936 if (sta->wpa_sm == NULL)
2937 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
2938 sta->addr,
2939 p2p_dev_addr);
2940 if (sta->wpa_sm == NULL) {
2941 wpa_printf(MSG_WARNING, "Failed to initialize WPA "
2942 "state machine");
2943 return WLAN_STATUS_UNSPECIFIED_FAILURE;
2944 }
2945 wpa_auth_set_auth_alg(sta->wpa_sm, sta->auth_alg);
2946 res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,
2947 hapd->iface->freq,
2948 wpa_ie, wpa_ie_len,
2949 elems.mdie, elems.mdie_len,
2950 elems.owe_dh, elems.owe_dh_len);
2951 resp = wpa_res_to_status_code(res);
2952 if (resp != WLAN_STATUS_SUCCESS)
2953 return resp;
2954 #ifdef CONFIG_IEEE80211W
2955 if ((sta->flags & (WLAN_STA_ASSOC | WLAN_STA_MFP)) ==
2956 (WLAN_STA_ASSOC | WLAN_STA_MFP) &&
2957 !sta->sa_query_timed_out &&
2958 sta->sa_query_count > 0)
2959 ap_check_sa_query_timeout(hapd, sta);
2960 if ((sta->flags & (WLAN_STA_ASSOC | WLAN_STA_MFP)) ==
2961 (WLAN_STA_ASSOC | WLAN_STA_MFP) &&
2962 !sta->sa_query_timed_out &&
2963 (!reassoc || sta->auth_alg != WLAN_AUTH_FT)) {
2964 /*
2965 * STA has already been associated with MFP and SA
2966 * Query timeout has not been reached. Reject the
2967 * association attempt temporarily and start SA Query,
2968 * if one is not pending.
2969 */
2970
2971 if (sta->sa_query_count == 0)
2972 ap_sta_start_sa_query(hapd, sta);
2973
2974 return WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY;
2975 }
2976
2977 if (wpa_auth_uses_mfp(sta->wpa_sm))
2978 sta->flags |= WLAN_STA_MFP;
2979 else
2980 sta->flags &= ~WLAN_STA_MFP;
2981 #endif /* CONFIG_IEEE80211W */
2982
2983 #ifdef CONFIG_IEEE80211R_AP
2984 if (sta->auth_alg == WLAN_AUTH_FT) {
2985 if (!reassoc) {
2986 wpa_printf(MSG_DEBUG, "FT: " MACSTR " tried "
2987 "to use association (not "
2988 "re-association) with FT auth_alg",
2989 MAC2STR(sta->addr));
2990 return WLAN_STATUS_UNSPECIFIED_FAILURE;
2991 }
2992
2993 resp = wpa_ft_validate_reassoc(sta->wpa_sm, ies,
2994 ies_len);
2995 if (resp != WLAN_STATUS_SUCCESS)
2996 return resp;
2997 }
2998 #endif /* CONFIG_IEEE80211R_AP */
2999
3000 #ifdef CONFIG_SAE
3001 if (wpa_auth_uses_sae(sta->wpa_sm) && sta->sae &&
3002 sta->sae->state == SAE_ACCEPTED)
3003 wpa_auth_add_sae_pmkid(sta->wpa_sm, sta->sae->pmkid);
3004
3005 if (wpa_auth_uses_sae(sta->wpa_sm) &&
3006 sta->auth_alg == WLAN_AUTH_OPEN) {
3007 struct rsn_pmksa_cache_entry *sa;
3008 sa = wpa_auth_sta_get_pmksa(sta->wpa_sm);
3009 if (!sa || sa->akmp != WPA_KEY_MGMT_SAE) {
3010 wpa_printf(MSG_DEBUG,
3011 "SAE: No PMKSA cache entry found for "
3012 MACSTR, MAC2STR(sta->addr));
3013 return WLAN_STATUS_INVALID_PMKID;
3014 }
3015 wpa_printf(MSG_DEBUG, "SAE: " MACSTR
3016 " using PMKSA caching", MAC2STR(sta->addr));
3017 } else if (wpa_auth_uses_sae(sta->wpa_sm) &&
3018 sta->auth_alg != WLAN_AUTH_SAE &&
3019 !(sta->auth_alg == WLAN_AUTH_FT &&
3020 wpa_auth_uses_ft_sae(sta->wpa_sm))) {
3021 wpa_printf(MSG_DEBUG, "SAE: " MACSTR " tried to use "
3022 "SAE AKM after non-SAE auth_alg %u",
3023 MAC2STR(sta->addr), sta->auth_alg);
3024 return WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
3025 }
3026 #endif /* CONFIG_SAE */
3027
3028 #ifdef CONFIG_OWE
3029 if ((hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_OWE) &&
3030 wpa_auth_sta_key_mgmt(sta->wpa_sm) == WPA_KEY_MGMT_OWE &&
3031 elems.owe_dh) {
3032 resp = owe_process_assoc_req(hapd, sta, elems.owe_dh,
3033 elems.owe_dh_len);
3034 if (resp != WLAN_STATUS_SUCCESS)
3035 return resp;
3036 }
3037 #endif /* CONFIG_OWE */
3038
3039 #ifdef CONFIG_DPP2
3040 dpp_pfs_free(sta->dpp_pfs);
3041 sta->dpp_pfs = NULL;
3042
3043 if ((hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_DPP) &&
3044 hapd->conf->dpp_netaccesskey && sta->wpa_sm &&
3045 wpa_auth_sta_key_mgmt(sta->wpa_sm) == WPA_KEY_MGMT_DPP &&
3046 elems.owe_dh) {
3047 sta->dpp_pfs = dpp_pfs_init(
3048 wpabuf_head(hapd->conf->dpp_netaccesskey),
3049 wpabuf_len(hapd->conf->dpp_netaccesskey));
3050 if (!sta->dpp_pfs) {
3051 wpa_printf(MSG_DEBUG,
3052 "DPP: Could not initialize PFS");
3053 /* Try to continue without PFS */
3054 goto pfs_fail;
3055 }
3056
3057 if (dpp_pfs_process(sta->dpp_pfs, elems.owe_dh,
3058 elems.owe_dh_len) < 0) {
3059 dpp_pfs_free(sta->dpp_pfs);
3060 sta->dpp_pfs = NULL;
3061 return WLAN_STATUS_UNSPECIFIED_FAILURE;
3062 }
3063 }
3064
3065 wpa_auth_set_dpp_z(sta->wpa_sm, sta->dpp_pfs ?
3066 sta->dpp_pfs->secret : NULL);
3067 pfs_fail:
3068 #endif /* CONFIG_DPP2 */
3069
3070 #ifdef CONFIG_IEEE80211N
3071 if ((sta->flags & (WLAN_STA_HT | WLAN_STA_VHT)) &&
3072 wpa_auth_get_pairwise(sta->wpa_sm) == WPA_CIPHER_TKIP) {
3073 hostapd_logger(hapd, sta->addr,
3074 HOSTAPD_MODULE_IEEE80211,
3075 HOSTAPD_LEVEL_INFO,
3076 "Station tried to use TKIP with HT "
3077 "association");
3078 return WLAN_STATUS_CIPHER_REJECTED_PER_POLICY;
3079 }
3080 #endif /* CONFIG_IEEE80211N */
3081 #ifdef CONFIG_HS20
3082 } else if (hapd->conf->osen) {
3083 if (elems.osen == NULL) {
3084 hostapd_logger(
3085 hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
3086 HOSTAPD_LEVEL_INFO,
3087 "No HS 2.0 OSEN element in association request");
3088 return WLAN_STATUS_INVALID_IE;
3089 }
3090
3091 wpa_printf(MSG_DEBUG, "HS 2.0: OSEN association");
3092 if (sta->wpa_sm == NULL)
3093 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
3094 sta->addr, NULL);
3095 if (sta->wpa_sm == NULL) {
3096 wpa_printf(MSG_WARNING, "Failed to initialize WPA "
3097 "state machine");
3098 return WLAN_STATUS_UNSPECIFIED_FAILURE;
3099 }
3100 if (wpa_validate_osen(hapd->wpa_auth, sta->wpa_sm,
3101 elems.osen - 2, elems.osen_len + 2) < 0)
3102 return WLAN_STATUS_INVALID_IE;
3103 #endif /* CONFIG_HS20 */
3104 } else
3105 wpa_auth_sta_no_wpa(sta->wpa_sm);
3106
3107 #ifdef CONFIG_P2P
3108 p2p_group_notif_assoc(hapd->p2p_group, sta->addr, ies, ies_len);
3109 #endif /* CONFIG_P2P */
3110
3111 #ifdef CONFIG_HS20
3112 wpabuf_free(sta->hs20_ie);
3113 if (elems.hs20 && elems.hs20_len > 4) {
3114 int release;
3115
3116 sta->hs20_ie = wpabuf_alloc_copy(elems.hs20 + 4,
3117 elems.hs20_len - 4);
3118 release = ((elems.hs20[4] >> 4) & 0x0f) + 1;
3119 if (release >= 2 && !wpa_auth_uses_mfp(sta->wpa_sm)) {
3120 wpa_printf(MSG_DEBUG,
3121 "HS 2.0: PMF not negotiated by release %d station "
3122 MACSTR, release, MAC2STR(sta->addr));
3123 return WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION;
3124 }
3125 } else {
3126 sta->hs20_ie = NULL;
3127 }
3128
3129 wpabuf_free(sta->roaming_consortium);
3130 if (elems.roaming_cons_sel)
3131 sta->roaming_consortium = wpabuf_alloc_copy(
3132 elems.roaming_cons_sel + 4,
3133 elems.roaming_cons_sel_len - 4);
3134 else
3135 sta->roaming_consortium = NULL;
3136 #endif /* CONFIG_HS20 */
3137
3138 #ifdef CONFIG_FST
3139 wpabuf_free(sta->mb_ies);
3140 if (hapd->iface->fst)
3141 sta->mb_ies = mb_ies_by_info(&elems.mb_ies);
3142 else
3143 sta->mb_ies = NULL;
3144 #endif /* CONFIG_FST */
3145
3146 #ifdef CONFIG_MBO
3147 mbo_ap_check_sta_assoc(hapd, sta, &elems);
3148
3149 if (hapd->conf->mbo_enabled && (hapd->conf->wpa & 2) &&
3150 elems.mbo && sta->cell_capa && !(sta->flags & WLAN_STA_MFP) &&
3151 hapd->conf->ieee80211w != NO_MGMT_FRAME_PROTECTION) {
3152 wpa_printf(MSG_INFO,
3153 "MBO: Reject WPA2 association without PMF");
3154 return WLAN_STATUS_UNSPECIFIED_FAILURE;
3155 }
3156 #endif /* CONFIG_MBO */
3157
3158 #if defined(CONFIG_FILS) && defined(CONFIG_OCV)
3159 if (wpa_auth_uses_ocv(sta->wpa_sm) &&
3160 (sta->auth_alg == WLAN_AUTH_FILS_SK ||
3161 sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
3162 sta->auth_alg == WLAN_AUTH_FILS_PK)) {
3163 struct wpa_channel_info ci;
3164 int tx_chanwidth;
3165 int tx_seg1_idx;
3166
3167 if (hostapd_drv_channel_info(hapd, &ci) != 0) {
3168 wpa_printf(MSG_WARNING,
3169 "Failed to get channel info to validate received OCI in FILS (Re)Association Request frame");
3170 return WLAN_STATUS_UNSPECIFIED_FAILURE;
3171 }
3172
3173 if (get_sta_tx_parameters(sta->wpa_sm,
3174 channel_width_to_int(ci.chanwidth),
3175 ci.seg1_idx, &tx_chanwidth,
3176 &tx_seg1_idx) < 0)
3177 return WLAN_STATUS_UNSPECIFIED_FAILURE;
3178
3179 if (ocv_verify_tx_params(elems.oci, elems.oci_len, &ci,
3180 tx_chanwidth, tx_seg1_idx) != 0) {
3181 wpa_printf(MSG_WARNING, "FILS: %s", ocv_errorstr);
3182 return WLAN_STATUS_UNSPECIFIED_FAILURE;
3183 }
3184 }
3185 #endif /* CONFIG_FILS && CONFIG_OCV */
3186
3187 ap_copy_sta_supp_op_classes(sta, elems.supp_op_classes,
3188 elems.supp_op_classes_len);
3189
3190 if ((sta->capability & WLAN_CAPABILITY_RADIO_MEASUREMENT) &&
3191 elems.rrm_enabled &&
3192 elems.rrm_enabled_len >= sizeof(sta->rrm_enabled_capa))
3193 os_memcpy(sta->rrm_enabled_capa, elems.rrm_enabled,
3194 sizeof(sta->rrm_enabled_capa));
3195
3196 if (elems.power_capab) {
3197 sta->min_tx_power = elems.power_capab[0];
3198 sta->max_tx_power = elems.power_capab[1];
3199 sta->power_capab = 1;
3200 } else {
3201 sta->power_capab = 0;
3202 }
3203
3204 return WLAN_STATUS_SUCCESS;
3205 }
3206
3207
3208 static void send_deauth(struct hostapd_data *hapd, const u8 *addr,
3209 u16 reason_code)
3210 {
3211 int send_len;
3212 struct ieee80211_mgmt reply;
3213
3214 os_memset(&reply, 0, sizeof(reply));
3215 reply.frame_control =
3216 IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_DEAUTH);
3217 os_memcpy(reply.da, addr, ETH_ALEN);
3218 os_memcpy(reply.sa, hapd->own_addr, ETH_ALEN);
3219 os_memcpy(reply.bssid, hapd->own_addr, ETH_ALEN);
3220
3221 send_len = IEEE80211_HDRLEN + sizeof(reply.u.deauth);
3222 reply.u.deauth.reason_code = host_to_le16(reason_code);
3223
3224 if (hostapd_drv_send_mlme(hapd, &reply, send_len, 0) < 0)
3225 wpa_printf(MSG_INFO, "Failed to send deauth: %s",
3226 strerror(errno));
3227 }
3228
3229
3230 static int add_associated_sta(struct hostapd_data *hapd,
3231 struct sta_info *sta, int reassoc)
3232 {
3233 struct ieee80211_ht_capabilities ht_cap;
3234 struct ieee80211_vht_capabilities vht_cap;
3235 int set = 1;
3236
3237 /*
3238 * Remove the STA entry to ensure the STA PS state gets cleared and
3239 * configuration gets updated. This is relevant for cases, such as
3240 * FT-over-the-DS, where a station re-associates back to the same AP but
3241 * skips the authentication flow, or if working with a driver that
3242 * does not support full AP client state.
3243 *
3244 * Skip this if the STA has already completed FT reassociation and the
3245 * TK has been configured since the TX/RX PN must not be reset to 0 for
3246 * the same key.
3247 *
3248 * FT-over-the-DS has a special case where the STA entry (and as such,
3249 * the TK) has not yet been configured to the driver depending on which
3250 * driver interface is used. For that case, allow add-STA operation to
3251 * be used (instead of set-STA). This is needed to allow mac80211-based
3252 * drivers to accept the STA parameter configuration. Since this is
3253 * after a new FT-over-DS exchange, a new TK has been derived, so key
3254 * reinstallation is not a concern for this case.
3255 */
3256 wpa_printf(MSG_DEBUG, "Add associated STA " MACSTR
3257 " (added_unassoc=%d auth_alg=%u ft_over_ds=%u reassoc=%d authorized=%d ft_tk=%d fils_tk=%d)",
3258 MAC2STR(sta->addr), sta->added_unassoc, sta->auth_alg,
3259 sta->ft_over_ds, reassoc,
3260 !!(sta->flags & WLAN_STA_AUTHORIZED),
3261 wpa_auth_sta_ft_tk_already_set(sta->wpa_sm),
3262 wpa_auth_sta_fils_tk_already_set(sta->wpa_sm));
3263
3264 if (!sta->added_unassoc &&
3265 (!(sta->flags & WLAN_STA_AUTHORIZED) ||
3266 (reassoc && sta->ft_over_ds && sta->auth_alg == WLAN_AUTH_FT) ||
3267 (!wpa_auth_sta_ft_tk_already_set(sta->wpa_sm) &&
3268 !wpa_auth_sta_fils_tk_already_set(sta->wpa_sm)))) {
3269 hostapd_drv_sta_remove(hapd, sta->addr);
3270 wpa_auth_sm_event(sta->wpa_sm, WPA_DRV_STA_REMOVED);
3271 set = 0;
3272
3273 /* Do not allow the FT-over-DS exception to be used more than
3274 * once per authentication exchange to guarantee a new TK is
3275 * used here */
3276 sta->ft_over_ds = 0;
3277 }
3278
3279 #ifdef CONFIG_IEEE80211N
3280 if (sta->flags & WLAN_STA_HT)
3281 hostapd_get_ht_capab(hapd, sta->ht_capabilities, &ht_cap);
3282 #endif /* CONFIG_IEEE80211N */
3283 #ifdef CONFIG_IEEE80211AC
3284 if (sta->flags & WLAN_STA_VHT)
3285 hostapd_get_vht_capab(hapd, sta->vht_capabilities, &vht_cap);
3286 #endif /* CONFIG_IEEE80211AC */
3287
3288 /*
3289 * Add the station with forced WLAN_STA_ASSOC flag. The sta->flags
3290 * will be set when the ACK frame for the (Re)Association Response frame
3291 * is processed (TX status driver event).
3292 */
3293 if (hostapd_sta_add(hapd, sta->addr, sta->aid, sta->capability,
3294 sta->supported_rates, sta->supported_rates_len,
3295 sta->listen_interval,
3296 sta->flags & WLAN_STA_HT ? &ht_cap : NULL,
3297 sta->flags & WLAN_STA_VHT ? &vht_cap : NULL,
3298 sta->flags | WLAN_STA_ASSOC, sta->qosinfo,
3299 sta->vht_opmode, sta->p2p_ie ? 1 : 0,
3300 set)) {
3301 hostapd_logger(hapd, sta->addr,
3302 HOSTAPD_MODULE_IEEE80211, HOSTAPD_LEVEL_NOTICE,
3303 "Could not %s STA to kernel driver",
3304 set ? "set" : "add");
3305
3306 if (sta->added_unassoc) {
3307 hostapd_drv_sta_remove(hapd, sta->addr);
3308 sta->added_unassoc = 0;
3309 }
3310
3311 return -1;
3312 }
3313
3314 sta->added_unassoc = 0;
3315
3316 return 0;
3317 }
3318
3319
3320 static u16 send_assoc_resp(struct hostapd_data *hapd, struct sta_info *sta,
3321 const u8 *addr, u16 status_code, int reassoc,
3322 const u8 *ies, size_t ies_len, int rssi)
3323 {
3324 int send_len;
3325 u8 *buf;
3326 size_t buflen;
3327 struct ieee80211_mgmt *reply;
3328 u8 *p;
3329 u16 res = WLAN_STATUS_SUCCESS;
3330
3331 buflen = sizeof(struct ieee80211_mgmt) + 1024;
3332 #ifdef CONFIG_FILS
3333 if (sta && sta->fils_hlp_resp)
3334 buflen += wpabuf_len(sta->fils_hlp_resp);
3335 if (sta)
3336 buflen += 150;
3337 #endif /* CONFIG_FILS */
3338 #ifdef CONFIG_OWE
3339 if (sta && (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_OWE))
3340 buflen += 150;
3341 #endif /* CONFIG_OWE */
3342 #ifdef CONFIG_DPP2
3343 if (sta && sta->dpp_pfs)
3344 buflen += 5 + sta->dpp_pfs->curve->prime_len;
3345 #endif /* CONFIG_DPP2 */
3346 buf = os_zalloc(buflen);
3347 if (!buf) {
3348 res = WLAN_STATUS_UNSPECIFIED_FAILURE;
3349 goto done;
3350 }
3351 reply = (struct ieee80211_mgmt *) buf;
3352 reply->frame_control =
3353 IEEE80211_FC(WLAN_FC_TYPE_MGMT,
3354 (reassoc ? WLAN_FC_STYPE_REASSOC_RESP :
3355 WLAN_FC_STYPE_ASSOC_RESP));
3356 os_memcpy(reply->da, addr, ETH_ALEN);
3357 os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN);
3358 os_memcpy(reply->bssid, hapd->own_addr, ETH_ALEN);
3359
3360 send_len = IEEE80211_HDRLEN;
3361 send_len += sizeof(reply->u.assoc_resp);
3362 reply->u.assoc_resp.capab_info =
3363 host_to_le16(hostapd_own_capab_info(hapd));
3364 reply->u.assoc_resp.status_code = host_to_le16(status_code);
3365
3366 reply->u.assoc_resp.aid = host_to_le16((sta ? sta->aid : 0) |
3367 BIT(14) | BIT(15));
3368 /* Supported rates */
3369 p = hostapd_eid_supp_rates(hapd, reply->u.assoc_resp.variable);
3370 /* Extended supported rates */
3371 p = hostapd_eid_ext_supp_rates(hapd, p);
3372
3373 #ifdef CONFIG_MBO
3374 if (status_code == WLAN_STATUS_DENIED_POOR_CHANNEL_CONDITIONS &&
3375 rssi != 0) {
3376 int delta = hapd->iconf->rssi_reject_assoc_rssi - rssi;
3377
3378 p = hostapd_eid_mbo_rssi_assoc_rej(hapd, p, buf + buflen - p,
3379 delta);
3380 }
3381 #endif /* CONFIG_MBO */
3382
3383 #ifdef CONFIG_IEEE80211R_AP
3384 if (sta && status_code == WLAN_STATUS_SUCCESS) {
3385 /* IEEE 802.11r: Mobility Domain Information, Fast BSS
3386 * Transition Information, RSN, [RIC Response] */
3387 p = wpa_sm_write_assoc_resp_ies(sta->wpa_sm, p,
3388 buf + buflen - p,
3389 sta->auth_alg, ies, ies_len);
3390 if (!p) {
3391 wpa_printf(MSG_DEBUG,
3392 "FT: Failed to write AssocResp IEs");
3393 res = WLAN_STATUS_UNSPECIFIED_FAILURE;
3394 goto done;
3395 }
3396 }
3397 #endif /* CONFIG_IEEE80211R_AP */
3398 #ifdef CONFIG_FILS
3399 if (sta && status_code == WLAN_STATUS_SUCCESS &&
3400 (sta->auth_alg == WLAN_AUTH_FILS_SK ||
3401 sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
3402 sta->auth_alg == WLAN_AUTH_FILS_PK))
3403 p = wpa_auth_write_assoc_resp_fils(sta->wpa_sm, p,
3404 buf + buflen - p,
3405 ies, ies_len);
3406 #endif /* CONFIG_FILS */
3407
3408 #ifdef CONFIG_OWE
3409 if (sta && status_code == WLAN_STATUS_SUCCESS &&
3410 (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_OWE))
3411 p = wpa_auth_write_assoc_resp_owe(sta->wpa_sm, p,
3412 buf + buflen - p,
3413 ies, ies_len);
3414 #endif /* CONFIG_OWE */
3415
3416 #ifdef CONFIG_IEEE80211W
3417 if (sta && status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY)
3418 p = hostapd_eid_assoc_comeback_time(hapd, sta, p);
3419 #endif /* CONFIG_IEEE80211W */
3420
3421 #ifdef CONFIG_IEEE80211N
3422 p = hostapd_eid_ht_capabilities(hapd, p);
3423 p = hostapd_eid_ht_operation(hapd, p);
3424 #endif /* CONFIG_IEEE80211N */
3425
3426 #ifdef CONFIG_IEEE80211AC
3427 if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac) {
3428 u32 nsts = 0, sta_nsts;
3429
3430 if (sta && hapd->conf->use_sta_nsts && sta->vht_capabilities) {
3431 struct ieee80211_vht_capabilities *capa;
3432
3433 nsts = (hapd->iface->conf->vht_capab >>
3434 VHT_CAP_BEAMFORMEE_STS_OFFSET) & 7;
3435 capa = sta->vht_capabilities;
3436 sta_nsts = (le_to_host32(capa->vht_capabilities_info) >>
3437 VHT_CAP_BEAMFORMEE_STS_OFFSET) & 7;
3438
3439 if (nsts < sta_nsts)
3440 nsts = 0;
3441 else
3442 nsts = sta_nsts;
3443 }
3444 p = hostapd_eid_vht_capabilities(hapd, p, nsts);
3445 p = hostapd_eid_vht_operation(hapd, p);
3446 }
3447 #endif /* CONFIG_IEEE80211AC */
3448
3449 p = hostapd_eid_ext_capab(hapd, p);
3450 p = hostapd_eid_bss_max_idle_period(hapd, p);
3451 if (sta && sta->qos_map_enabled)
3452 p = hostapd_eid_qos_map_set(hapd, p);
3453
3454 #ifdef CONFIG_FST
3455 if (hapd->iface->fst_ies) {
3456 os_memcpy(p, wpabuf_head(hapd->iface->fst_ies),
3457 wpabuf_len(hapd->iface->fst_ies));
3458 p += wpabuf_len(hapd->iface->fst_ies);
3459 }
3460 #endif /* CONFIG_FST */
3461
3462 #ifdef CONFIG_OWE
3463 if ((hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_OWE) &&
3464 sta && sta->owe_ecdh && status_code == WLAN_STATUS_SUCCESS &&
3465 wpa_auth_sta_key_mgmt(sta->wpa_sm) == WPA_KEY_MGMT_OWE) {
3466 struct wpabuf *pub;
3467
3468 pub = crypto_ecdh_get_pubkey(sta->owe_ecdh, 0);
3469 if (!pub) {
3470 res = WLAN_STATUS_UNSPECIFIED_FAILURE;
3471 goto done;
3472 }
3473 /* OWE Diffie-Hellman Parameter element */
3474 *p++ = WLAN_EID_EXTENSION; /* Element ID */
3475 *p++ = 1 + 2 + wpabuf_len(pub); /* Length */
3476 *p++ = WLAN_EID_EXT_OWE_DH_PARAM; /* Element ID Extension */
3477 WPA_PUT_LE16(p, sta->owe_group);
3478 p += 2;
3479 os_memcpy(p, wpabuf_head(pub), wpabuf_len(pub));
3480 p += wpabuf_len(pub);
3481 wpabuf_free(pub);
3482 }
3483 #endif /* CONFIG_OWE */
3484
3485 #ifdef CONFIG_DPP2
3486 if ((hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_DPP) &&
3487 sta && sta->dpp_pfs && status_code == WLAN_STATUS_SUCCESS &&
3488 wpa_auth_sta_key_mgmt(sta->wpa_sm) == WPA_KEY_MGMT_DPP) {
3489 os_memcpy(p, wpabuf_head(sta->dpp_pfs->ie),
3490 wpabuf_len(sta->dpp_pfs->ie));
3491 p += wpabuf_len(sta->dpp_pfs->ie);
3492 }
3493 #endif /* CONFIG_DPP2 */
3494
3495 #ifdef CONFIG_IEEE80211AC
3496 if (sta && hapd->conf->vendor_vht && (sta->flags & WLAN_STA_VENDOR_VHT))
3497 p = hostapd_eid_vendor_vht(hapd, p);
3498 #endif /* CONFIG_IEEE80211AC */
3499
3500 if (sta && (sta->flags & WLAN_STA_WMM))
3501 p = hostapd_eid_wmm(hapd, p);
3502
3503 #ifdef CONFIG_WPS
3504 if (sta &&
3505 ((sta->flags & WLAN_STA_WPS) ||
3506 ((sta->flags & WLAN_STA_MAYBE_WPS) && hapd->conf->wpa))) {
3507 struct wpabuf *wps = wps_build_assoc_resp_ie();
3508 if (wps) {
3509 os_memcpy(p, wpabuf_head(wps), wpabuf_len(wps));
3510 p += wpabuf_len(wps);
3511 wpabuf_free(wps);
3512 }
3513 }
3514 #endif /* CONFIG_WPS */
3515
3516 if (sta && (sta->flags & WLAN_STA_MULTI_AP))
3517 p = hostapd_eid_multi_ap(hapd, p);
3518
3519 #ifdef CONFIG_P2P
3520 if (sta && sta->p2p_ie && hapd->p2p_group) {
3521 struct wpabuf *p2p_resp_ie;
3522 enum p2p_status_code status;
3523 switch (status_code) {
3524 case WLAN_STATUS_SUCCESS:
3525 status = P2P_SC_SUCCESS;
3526 break;
3527 case WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA:
3528 status = P2P_SC_FAIL_LIMIT_REACHED;
3529 break;
3530 default:
3531 status = P2P_SC_FAIL_INVALID_PARAMS;
3532 break;
3533 }
3534 p2p_resp_ie = p2p_group_assoc_resp_ie(hapd->p2p_group, status);
3535 if (p2p_resp_ie) {
3536 os_memcpy(p, wpabuf_head(p2p_resp_ie),
3537 wpabuf_len(p2p_resp_ie));
3538 p += wpabuf_len(p2p_resp_ie);
3539 wpabuf_free(p2p_resp_ie);
3540 }
3541 }
3542 #endif /* CONFIG_P2P */
3543
3544 #ifdef CONFIG_P2P_MANAGER
3545 if (hapd->conf->p2p & P2P_MANAGE)
3546 p = hostapd_eid_p2p_manage(hapd, p);
3547 #endif /* CONFIG_P2P_MANAGER */
3548
3549 p = hostapd_eid_mbo(hapd, p, buf + buflen - p);
3550
3551 if (hapd->conf->assocresp_elements &&
3552 (size_t) (buf + buflen - p) >=
3553 wpabuf_len(hapd->conf->assocresp_elements)) {
3554 os_memcpy(p, wpabuf_head(hapd->conf->assocresp_elements),
3555 wpabuf_len(hapd->conf->assocresp_elements));
3556 p += wpabuf_len(hapd->conf->assocresp_elements);
3557 }
3558
3559 send_len += p - reply->u.assoc_resp.variable;
3560
3561 #ifdef CONFIG_FILS
3562 if (sta &&
3563 (sta->auth_alg == WLAN_AUTH_FILS_SK ||
3564 sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
3565 sta->auth_alg == WLAN_AUTH_FILS_PK) &&
3566 status_code == WLAN_STATUS_SUCCESS) {
3567 struct ieee802_11_elems elems;
3568
3569 if (ieee802_11_parse_elems(ies, ies_len, &elems, 0) ==
3570 ParseFailed || !elems.fils_session) {
3571 res = WLAN_STATUS_UNSPECIFIED_FAILURE;
3572 goto done;
3573 }
3574
3575 /* FILS Session */
3576 *p++ = WLAN_EID_EXTENSION; /* Element ID */
3577 *p++ = 1 + FILS_SESSION_LEN; /* Length */
3578 *p++ = WLAN_EID_EXT_FILS_SESSION; /* Element ID Extension */
3579 os_memcpy(p, elems.fils_session, FILS_SESSION_LEN);
3580 send_len += 2 + 1 + FILS_SESSION_LEN;
3581
3582 send_len = fils_encrypt_assoc(sta->wpa_sm, buf, send_len,
3583 buflen, sta->fils_hlp_resp);
3584 if (send_len < 0) {
3585 res = WLAN_STATUS_UNSPECIFIED_FAILURE;
3586 goto done;
3587 }
3588 }
3589 #endif /* CONFIG_FILS */
3590
3591 if (hostapd_drv_send_mlme(hapd, reply, send_len, 0) < 0) {
3592 wpa_printf(MSG_INFO, "Failed to send assoc resp: %s",
3593 strerror(errno));
3594 res = WLAN_STATUS_UNSPECIFIED_FAILURE;
3595 }
3596
3597 done:
3598 os_free(buf);
3599 return res;
3600 }
3601
3602
3603 #ifdef CONFIG_OWE
3604 u8 * owe_assoc_req_process(struct hostapd_data *hapd, struct sta_info *sta,
3605 const u8 *owe_dh, u8 owe_dh_len,
3606 u8 *owe_buf, size_t owe_buf_len, u16 *reason)
3607 {
3608 #ifdef CONFIG_TESTING_OPTIONS
3609 if (hapd->conf->own_ie_override) {
3610 wpa_printf(MSG_DEBUG, "OWE: Using IE override");
3611 *reason = WLAN_STATUS_SUCCESS;
3612 return wpa_auth_write_assoc_resp_owe(sta->wpa_sm, owe_buf,
3613 owe_buf_len, NULL, 0);
3614 }
3615 #endif /* CONFIG_TESTING_OPTIONS */
3616
3617 if (wpa_auth_sta_get_pmksa(sta->wpa_sm)) {
3618 wpa_printf(MSG_DEBUG, "OWE: Using PMKSA caching");
3619 owe_buf = wpa_auth_write_assoc_resp_owe(sta->wpa_sm, owe_buf,
3620 owe_buf_len, NULL, 0);
3621 *reason = WLAN_STATUS_SUCCESS;
3622 return owe_buf;
3623 }
3624
3625 *reason = owe_process_assoc_req(hapd, sta, owe_dh, owe_dh_len);
3626 if (*reason != WLAN_STATUS_SUCCESS)
3627 return NULL;
3628
3629 owe_buf = wpa_auth_write_assoc_resp_owe(sta->wpa_sm, owe_buf,
3630 owe_buf_len, NULL, 0);
3631
3632 if (sta->owe_ecdh && owe_buf) {
3633 struct wpabuf *pub;
3634
3635 pub = crypto_ecdh_get_pubkey(sta->owe_ecdh, 0);
3636 if (!pub) {
3637 *reason = WLAN_STATUS_UNSPECIFIED_FAILURE;
3638 return owe_buf;
3639 }
3640
3641 /* OWE Diffie-Hellman Parameter element */
3642 *owe_buf++ = WLAN_EID_EXTENSION; /* Element ID */
3643 *owe_buf++ = 1 + 2 + wpabuf_len(pub); /* Length */
3644 *owe_buf++ = WLAN_EID_EXT_OWE_DH_PARAM; /* Element ID Extension
3645 */
3646 WPA_PUT_LE16(owe_buf, sta->owe_group);
3647 owe_buf += 2;
3648 os_memcpy(owe_buf, wpabuf_head(pub), wpabuf_len(pub));
3649 owe_buf += wpabuf_len(pub);
3650 wpabuf_free(pub);
3651 }
3652
3653 return owe_buf;
3654 }
3655 #endif /* CONFIG_OWE */
3656
3657
3658 #ifdef CONFIG_FILS
3659
3660 void fils_hlp_finish_assoc(struct hostapd_data *hapd, struct sta_info *sta)
3661 {
3662 u16 reply_res;
3663
3664 wpa_printf(MSG_DEBUG, "FILS: Finish association with " MACSTR,
3665 MAC2STR(sta->addr));
3666 eloop_cancel_timeout(fils_hlp_timeout, hapd, sta);
3667 if (!sta->fils_pending_assoc_req)
3668 return;
3669 reply_res = send_assoc_resp(hapd, sta, sta->addr, WLAN_STATUS_SUCCESS,
3670 sta->fils_pending_assoc_is_reassoc,
3671 sta->fils_pending_assoc_req,
3672 sta->fils_pending_assoc_req_len, 0);
3673 os_free(sta->fils_pending_assoc_req);
3674 sta->fils_pending_assoc_req = NULL;
3675 sta->fils_pending_assoc_req_len = 0;
3676 wpabuf_free(sta->fils_hlp_resp);
3677 sta->fils_hlp_resp = NULL;
3678 wpabuf_free(sta->hlp_dhcp_discover);
3679 sta->hlp_dhcp_discover = NULL;
3680
3681 /*
3682 * Remove the station in case transmission of a success response fails.
3683 * At this point the station was already added associated to the driver.
3684 */
3685 if (reply_res != WLAN_STATUS_SUCCESS)
3686 hostapd_drv_sta_remove(hapd, sta->addr);
3687 }
3688
3689
3690 void fils_hlp_timeout(void *eloop_ctx, void *eloop_data)
3691 {
3692 struct hostapd_data *hapd = eloop_ctx;
3693 struct sta_info *sta = eloop_data;
3694
3695 wpa_printf(MSG_DEBUG,
3696 "FILS: HLP response timeout - continue with association response for "
3697 MACSTR, MAC2STR(sta->addr));
3698 if (sta->fils_drv_assoc_finish)
3699 hostapd_notify_assoc_fils_finish(hapd, sta);
3700 else
3701 fils_hlp_finish_assoc(hapd, sta);
3702 }
3703
3704 #endif /* CONFIG_FILS */
3705
3706
3707 static void handle_assoc(struct hostapd_data *hapd,
3708 const struct ieee80211_mgmt *mgmt, size_t len,
3709 int reassoc, int rssi)
3710 {
3711 u16 capab_info, listen_interval, seq_ctrl, fc;
3712 u16 resp = WLAN_STATUS_SUCCESS, reply_res;
3713 const u8 *pos;
3714 int left, i;
3715 struct sta_info *sta;
3716 u8 *tmp = NULL;
3717 struct hostapd_sta_wpa_psk_short *psk = NULL;
3718 char *identity = NULL;
3719 char *radius_cui = NULL;
3720 #ifdef CONFIG_FILS
3721 int delay_assoc = 0;
3722 #endif /* CONFIG_FILS */
3723
3724 if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_req) :
3725 sizeof(mgmt->u.assoc_req))) {
3726 wpa_printf(MSG_INFO, "handle_assoc(reassoc=%d) - too short payload (len=%lu)",
3727 reassoc, (unsigned long) len);
3728 return;
3729 }
3730
3731 #ifdef CONFIG_TESTING_OPTIONS
3732 if (reassoc) {
3733 if (hapd->iconf->ignore_reassoc_probability > 0.0 &&
3734 drand48() < hapd->iconf->ignore_reassoc_probability) {
3735 wpa_printf(MSG_INFO,
3736 "TESTING: ignoring reassoc request from "
3737 MACSTR, MAC2STR(mgmt->sa));
3738 return;
3739 }
3740 } else {
3741 if (hapd->iconf->ignore_assoc_probability > 0.0 &&
3742 drand48() < hapd->iconf->ignore_assoc_probability) {
3743 wpa_printf(MSG_INFO,
3744 "TESTING: ignoring assoc request from "
3745 MACSTR, MAC2STR(mgmt->sa));
3746 return;
3747 }
3748 }
3749 #endif /* CONFIG_TESTING_OPTIONS */
3750
3751 fc = le_to_host16(mgmt->frame_control);
3752 seq_ctrl = le_to_host16(mgmt->seq_ctrl);
3753
3754 if (reassoc) {
3755 capab_info = le_to_host16(mgmt->u.reassoc_req.capab_info);
3756 listen_interval = le_to_host16(
3757 mgmt->u.reassoc_req.listen_interval);
3758 wpa_printf(MSG_DEBUG, "reassociation request: STA=" MACSTR
3759 " capab_info=0x%02x listen_interval=%d current_ap="
3760 MACSTR " seq_ctrl=0x%x%s",
3761 MAC2STR(mgmt->sa), capab_info, listen_interval,
3762 MAC2STR(mgmt->u.reassoc_req.current_ap),
3763 seq_ctrl, (fc & WLAN_FC_RETRY) ? " retry" : "");
3764 left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.reassoc_req));
3765 pos = mgmt->u.reassoc_req.variable;
3766 } else {
3767 capab_info = le_to_host16(mgmt->u.assoc_req.capab_info);
3768 listen_interval = le_to_host16(
3769 mgmt->u.assoc_req.listen_interval);
3770 wpa_printf(MSG_DEBUG, "association request: STA=" MACSTR
3771 " capab_info=0x%02x listen_interval=%d "
3772 "seq_ctrl=0x%x%s",
3773 MAC2STR(mgmt->sa), capab_info, listen_interval,
3774 seq_ctrl, (fc & WLAN_FC_RETRY) ? " retry" : "");
3775 left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.assoc_req));
3776 pos = mgmt->u.assoc_req.variable;
3777 }
3778
3779 sta = ap_get_sta(hapd, mgmt->sa);
3780 #ifdef CONFIG_IEEE80211R_AP
3781 if (sta && sta->auth_alg == WLAN_AUTH_FT &&
3782 (sta->flags & WLAN_STA_AUTH) == 0) {
3783 wpa_printf(MSG_DEBUG, "FT: Allow STA " MACSTR " to associate "
3784 "prior to authentication since it is using "
3785 "over-the-DS FT", MAC2STR(mgmt->sa));
3786
3787 /*
3788 * Mark station as authenticated, to avoid adding station
3789 * entry in the driver as associated and not authenticated
3790 */
3791 sta->flags |= WLAN_STA_AUTH;
3792 } else
3793 #endif /* CONFIG_IEEE80211R_AP */
3794 if (sta == NULL || (sta->flags & WLAN_STA_AUTH) == 0) {
3795 if (hapd->iface->current_mode &&
3796 hapd->iface->current_mode->mode ==
3797 HOSTAPD_MODE_IEEE80211AD) {
3798 int acl_res;
3799 u32 session_timeout, acct_interim_interval;
3800 struct vlan_description vlan_id;
3801
3802 acl_res = ieee802_11_allowed_address(
3803 hapd, mgmt->sa, (const u8 *) mgmt, len,
3804 &session_timeout, &acct_interim_interval,
3805 &vlan_id, &psk, &identity, &radius_cui, 0);
3806 if (acl_res == HOSTAPD_ACL_REJECT) {
3807 wpa_msg(hapd->msg_ctx, MSG_DEBUG,
3808 "Ignore Association Request frame from "
3809 MACSTR " due to ACL reject",
3810 MAC2STR(mgmt->sa));
3811 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
3812 goto fail;
3813 }
3814 if (acl_res == HOSTAPD_ACL_PENDING)
3815 return;
3816
3817 /* DMG/IEEE 802.11ad does not use authentication.
3818 * Allocate sta entry upon association. */
3819 sta = ap_sta_add(hapd, mgmt->sa);
3820 if (!sta) {
3821 hostapd_logger(hapd, mgmt->sa,
3822 HOSTAPD_MODULE_IEEE80211,
3823 HOSTAPD_LEVEL_INFO,
3824 "Failed to add STA");
3825 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
3826 goto fail;
3827 }
3828
3829 acl_res = ieee802_11_set_radius_info(
3830 hapd, sta, acl_res, session_timeout,
3831 acct_interim_interval, &vlan_id, &psk,
3832 &identity, &radius_cui);
3833 if (acl_res) {
3834 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
3835 goto fail;
3836 }
3837
3838 hostapd_logger(hapd, sta->addr,
3839 HOSTAPD_MODULE_IEEE80211,
3840 HOSTAPD_LEVEL_DEBUG,
3841 "Skip authentication for DMG/IEEE 802.11ad");
3842 sta->flags |= WLAN_STA_AUTH;
3843 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
3844 sta->auth_alg = WLAN_AUTH_OPEN;
3845 } else {
3846 hostapd_logger(hapd, mgmt->sa,
3847 HOSTAPD_MODULE_IEEE80211,
3848 HOSTAPD_LEVEL_INFO,
3849 "Station tried to associate before authentication (aid=%d flags=0x%x)",
3850 sta ? sta->aid : -1,
3851 sta ? sta->flags : 0);
3852 send_deauth(hapd, mgmt->sa,
3853 WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA);
3854 return;
3855 }
3856 }
3857
3858 if ((fc & WLAN_FC_RETRY) &&
3859 sta->last_seq_ctrl != WLAN_INVALID_MGMT_SEQ &&
3860 sta->last_seq_ctrl == seq_ctrl &&
3861 sta->last_subtype == (reassoc ? WLAN_FC_STYPE_REASSOC_REQ :
3862 WLAN_FC_STYPE_ASSOC_REQ)) {
3863 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
3864 HOSTAPD_LEVEL_DEBUG,
3865 "Drop repeated association frame seq_ctrl=0x%x",
3866 seq_ctrl);
3867 return;
3868 }
3869 sta->last_seq_ctrl = seq_ctrl;
3870 sta->last_subtype = reassoc ? WLAN_FC_STYPE_REASSOC_REQ :
3871 WLAN_FC_STYPE_ASSOC_REQ;
3872
3873 if (hapd->tkip_countermeasures) {
3874 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
3875 goto fail;
3876 }
3877
3878 if (listen_interval > hapd->conf->max_listen_interval) {
3879 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
3880 HOSTAPD_LEVEL_DEBUG,
3881 "Too large Listen Interval (%d)",
3882 listen_interval);
3883 resp = WLAN_STATUS_ASSOC_DENIED_LISTEN_INT_TOO_LARGE;
3884 goto fail;
3885 }
3886
3887 #ifdef CONFIG_MBO
3888 if (hapd->conf->mbo_enabled && hapd->mbo_assoc_disallow) {
3889 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
3890 goto fail;
3891 }
3892
3893 if (hapd->iconf->rssi_reject_assoc_rssi && rssi &&
3894 rssi < hapd->iconf->rssi_reject_assoc_rssi &&
3895 (sta->auth_rssi == 0 ||
3896 sta->auth_rssi < hapd->iconf->rssi_reject_assoc_rssi)) {
3897 resp = WLAN_STATUS_DENIED_POOR_CHANNEL_CONDITIONS;
3898 goto fail;
3899 }
3900 #endif /* CONFIG_MBO */
3901
3902 /*
3903 * sta->capability is used in check_assoc_ies() for RRM enabled
3904 * capability element.
3905 */
3906 sta->capability = capab_info;
3907
3908 #ifdef CONFIG_FILS
3909 if (sta->auth_alg == WLAN_AUTH_FILS_SK ||
3910 sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
3911 sta->auth_alg == WLAN_AUTH_FILS_PK) {
3912 int res;
3913
3914 /* The end of the payload is encrypted. Need to decrypt it
3915 * before parsing. */
3916
3917 tmp = os_memdup(pos, left);
3918 if (!tmp) {
3919 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
3920 goto fail;
3921 }
3922
3923 res = fils_decrypt_assoc(sta->wpa_sm, sta->fils_session, mgmt,
3924 len, tmp, left);
3925 if (res < 0) {
3926 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
3927 goto fail;
3928 }
3929 pos = tmp;
3930 left = res;
3931 }
3932 #endif /* CONFIG_FILS */
3933
3934 /* followed by SSID and Supported rates; and HT capabilities if 802.11n
3935 * is used */
3936 resp = check_assoc_ies(hapd, sta, pos, left, reassoc);
3937 if (resp != WLAN_STATUS_SUCCESS)
3938 goto fail;
3939
3940 if (hostapd_get_aid(hapd, sta) < 0) {
3941 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
3942 HOSTAPD_LEVEL_INFO, "No room for more AIDs");
3943 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
3944 goto fail;
3945 }
3946
3947 sta->listen_interval = listen_interval;
3948
3949 if (hapd->iface->current_mode &&
3950 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
3951 sta->flags |= WLAN_STA_NONERP;
3952 for (i = 0; i < sta->supported_rates_len; i++) {
3953 if ((sta->supported_rates[i] & 0x7f) > 22) {
3954 sta->flags &= ~WLAN_STA_NONERP;
3955 break;
3956 }
3957 }
3958 if (sta->flags & WLAN_STA_NONERP && !sta->nonerp_set) {
3959 sta->nonerp_set = 1;
3960 hapd->iface->num_sta_non_erp++;
3961 if (hapd->iface->num_sta_non_erp == 1)
3962 ieee802_11_set_beacons(hapd->iface);
3963 }
3964
3965 if (!(sta->capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) &&
3966 !sta->no_short_slot_time_set) {
3967 sta->no_short_slot_time_set = 1;
3968 hapd->iface->num_sta_no_short_slot_time++;
3969 if (hapd->iface->current_mode &&
3970 hapd->iface->current_mode->mode ==
3971 HOSTAPD_MODE_IEEE80211G &&
3972 hapd->iface->num_sta_no_short_slot_time == 1)
3973 ieee802_11_set_beacons(hapd->iface);
3974 }
3975
3976 if (sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
3977 sta->flags |= WLAN_STA_SHORT_PREAMBLE;
3978 else
3979 sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
3980
3981 if (!(sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) &&
3982 !sta->no_short_preamble_set) {
3983 sta->no_short_preamble_set = 1;
3984 hapd->iface->num_sta_no_short_preamble++;
3985 if (hapd->iface->current_mode &&
3986 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G
3987 && hapd->iface->num_sta_no_short_preamble == 1)
3988 ieee802_11_set_beacons(hapd->iface);
3989 }
3990
3991 #ifdef CONFIG_IEEE80211N
3992 update_ht_state(hapd, sta);
3993 #endif /* CONFIG_IEEE80211N */
3994
3995 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
3996 HOSTAPD_LEVEL_DEBUG,
3997 "association OK (aid %d)", sta->aid);
3998 /* Station will be marked associated, after it acknowledges AssocResp
3999 */
4000 sta->flags |= WLAN_STA_ASSOC_REQ_OK;
4001
4002 #ifdef CONFIG_IEEE80211W
4003 if ((sta->flags & WLAN_STA_MFP) && sta->sa_query_timed_out) {
4004 wpa_printf(MSG_DEBUG, "Allowing %sassociation after timed out "
4005 "SA Query procedure", reassoc ? "re" : "");
4006 /* TODO: Send a protected Disassociate frame to the STA using
4007 * the old key and Reason Code "Previous Authentication no
4008 * longer valid". Make sure this is only sent protected since
4009 * unprotected frame would be received by the STA that is now
4010 * trying to associate.
4011 */
4012 }
4013 #endif /* CONFIG_IEEE80211W */
4014
4015 /* Make sure that the previously registered inactivity timer will not
4016 * remove the STA immediately. */
4017 sta->timeout_next = STA_NULLFUNC;
4018
4019 #ifdef CONFIG_TAXONOMY
4020 taxonomy_sta_info_assoc_req(hapd, sta, pos, left);
4021 #endif /* CONFIG_TAXONOMY */
4022
4023 sta->pending_wds_enable = 0;
4024
4025 #ifdef CONFIG_FILS
4026 if (sta->auth_alg == WLAN_AUTH_FILS_SK ||
4027 sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
4028 sta->auth_alg == WLAN_AUTH_FILS_PK) {
4029 if (fils_process_hlp(hapd, sta, pos, left) > 0)
4030 delay_assoc = 1;
4031 }
4032 #endif /* CONFIG_FILS */
4033
4034 fail:
4035 os_free(identity);
4036 os_free(radius_cui);
4037 hostapd_free_psk_list(psk);
4038
4039 /*
4040 * In case of a successful response, add the station to the driver.
4041 * Otherwise, the kernel may ignore Data frames before we process the
4042 * ACK frame (TX status). In case of a failure, this station will be
4043 * removed.
4044 *
4045 * Note that this is not compliant with the IEEE 802.11 standard that
4046 * states that a non-AP station should transition into the
4047 * authenticated/associated state only after the station acknowledges
4048 * the (Re)Association Response frame. However, still do this as:
4049 *
4050 * 1. In case the station does not acknowledge the (Re)Association
4051 * Response frame, it will be removed.
4052 * 2. Data frames will be dropped in the kernel until the station is
4053 * set into authorized state, and there are no significant known
4054 * issues with processing other non-Data Class 3 frames during this
4055 * window.
4056 */
4057 if (resp == WLAN_STATUS_SUCCESS && sta &&
4058 add_associated_sta(hapd, sta, reassoc))
4059 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
4060
4061 #ifdef CONFIG_FILS
4062 if (sta && delay_assoc && resp == WLAN_STATUS_SUCCESS &&
4063 eloop_is_timeout_registered(fils_hlp_timeout, hapd, sta) &&
4064 sta->fils_pending_assoc_req) {
4065 /* Do not reschedule fils_hlp_timeout in case the station
4066 * retransmits (Re)Association Request frame while waiting for
4067 * the previously started FILS HLP wait, so that the timeout can
4068 * be determined from the first pending attempt. */
4069 wpa_printf(MSG_DEBUG,
4070 "FILS: Continue waiting for HLP processing before sending (Re)Association Response frame to "
4071 MACSTR, MAC2STR(sta->addr));
4072 os_free(tmp);
4073 return;
4074 }
4075 if (sta) {
4076 eloop_cancel_timeout(fils_hlp_timeout, hapd, sta);
4077 os_free(sta->fils_pending_assoc_req);
4078 sta->fils_pending_assoc_req = NULL;
4079 sta->fils_pending_assoc_req_len = 0;
4080 wpabuf_free(sta->fils_hlp_resp);
4081 sta->fils_hlp_resp = NULL;
4082 }
4083 if (sta && delay_assoc && resp == WLAN_STATUS_SUCCESS) {
4084 sta->fils_pending_assoc_req = tmp;
4085 sta->fils_pending_assoc_req_len = left;
4086 sta->fils_pending_assoc_is_reassoc = reassoc;
4087 sta->fils_drv_assoc_finish = 0;
4088 wpa_printf(MSG_DEBUG,
4089 "FILS: Waiting for HLP processing before sending (Re)Association Response frame to "
4090 MACSTR, MAC2STR(sta->addr));
4091 eloop_cancel_timeout(fils_hlp_timeout, hapd, sta);
4092 eloop_register_timeout(0, hapd->conf->fils_hlp_wait_time * 1024,
4093 fils_hlp_timeout, hapd, sta);
4094 return;
4095 }
4096 #endif /* CONFIG_FILS */
4097
4098 reply_res = send_assoc_resp(hapd, sta, mgmt->sa, resp, reassoc, pos,
4099 left, rssi);
4100 os_free(tmp);
4101
4102 /*
4103 * Remove the station in case tranmission of a success response fails
4104 * (the STA was added associated to the driver) or if the station was
4105 * previously added unassociated.
4106 */
4107 if (sta && ((reply_res != WLAN_STATUS_SUCCESS &&
4108 resp == WLAN_STATUS_SUCCESS) || sta->added_unassoc)) {
4109 hostapd_drv_sta_remove(hapd, sta->addr);
4110 sta->added_unassoc = 0;
4111 }
4112 }
4113
4114
4115 static void handle_disassoc(struct hostapd_data *hapd,
4116 const struct ieee80211_mgmt *mgmt, size_t len)
4117 {
4118 struct sta_info *sta;
4119
4120 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.disassoc)) {
4121 wpa_printf(MSG_INFO, "handle_disassoc - too short payload (len=%lu)",
4122 (unsigned long) len);
4123 return;
4124 }
4125
4126 wpa_printf(MSG_DEBUG, "disassocation: STA=" MACSTR " reason_code=%d",
4127 MAC2STR(mgmt->sa),
4128 le_to_host16(mgmt->u.disassoc.reason_code));
4129
4130 sta = ap_get_sta(hapd, mgmt->sa);
4131 if (sta == NULL) {
4132 wpa_printf(MSG_INFO, "Station " MACSTR " trying to disassociate, but it is not associated",
4133 MAC2STR(mgmt->sa));
4134 return;
4135 }
4136
4137 ap_sta_set_authorized(hapd, sta, 0);
4138 sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ;
4139 sta->flags &= ~(WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK);
4140 wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC);
4141 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
4142 HOSTAPD_LEVEL_INFO, "disassociated");
4143 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
4144 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
4145 /* Stop Accounting and IEEE 802.1X sessions, but leave the STA
4146 * authenticated. */
4147 accounting_sta_stop(hapd, sta);
4148 ieee802_1x_free_station(hapd, sta);
4149 if (sta->ipaddr)
4150 hostapd_drv_br_delete_ip_neigh(hapd, 4, (u8 *) &sta->ipaddr);
4151 ap_sta_ip6addr_del(hapd, sta);
4152 hostapd_drv_sta_remove(hapd, sta->addr);
4153 sta->added_unassoc = 0;
4154
4155 if (sta->timeout_next == STA_NULLFUNC ||
4156 sta->timeout_next == STA_DISASSOC) {
4157 sta->timeout_next = STA_DEAUTH;
4158 eloop_cancel_timeout(ap_handle_timer, hapd, sta);
4159 eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer,
4160 hapd, sta);
4161 }
4162
4163 mlme_disassociate_indication(
4164 hapd, sta, le_to_host16(mgmt->u.disassoc.reason_code));
4165
4166 /* DMG/IEEE 802.11ad does not use deauthication. Deallocate sta upon
4167 * disassociation. */
4168 if (hapd->iface->current_mode &&
4169 hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211AD) {
4170 sta->flags &= ~WLAN_STA_AUTH;
4171 wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH);
4172 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
4173 HOSTAPD_LEVEL_DEBUG, "deauthenticated");
4174 ap_free_sta(hapd, sta);
4175 }
4176 }
4177
4178
4179 static void handle_deauth(struct hostapd_data *hapd,
4180 const struct ieee80211_mgmt *mgmt, size_t len)
4181 {
4182 struct sta_info *sta;
4183
4184 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.deauth)) {
4185 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "handle_deauth - too short "
4186 "payload (len=%lu)", (unsigned long) len);
4187 return;
4188 }
4189
4190 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "deauthentication: STA=" MACSTR
4191 " reason_code=%d",
4192 MAC2STR(mgmt->sa), le_to_host16(mgmt->u.deauth.reason_code));
4193
4194 sta = ap_get_sta(hapd, mgmt->sa);
4195 if (sta == NULL) {
4196 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR " trying "
4197 "to deauthenticate, but it is not authenticated",
4198 MAC2STR(mgmt->sa));
4199 return;
4200 }
4201
4202 ap_sta_set_authorized(hapd, sta, 0);
4203 sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ;
4204 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC |
4205 WLAN_STA_ASSOC_REQ_OK);
4206 wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH);
4207 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
4208 HOSTAPD_LEVEL_DEBUG, "deauthenticated");
4209 mlme_deauthenticate_indication(
4210 hapd, sta, le_to_host16(mgmt->u.deauth.reason_code));
4211 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
4212 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
4213 ap_free_sta(hapd, sta);
4214 }
4215
4216
4217 static void handle_beacon(struct hostapd_data *hapd,
4218 const struct ieee80211_mgmt *mgmt, size_t len,
4219 struct hostapd_frame_info *fi)
4220 {
4221 struct ieee802_11_elems elems;
4222
4223 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.beacon)) {
4224 wpa_printf(MSG_INFO, "handle_beacon - too short payload (len=%lu)",
4225 (unsigned long) len);
4226 return;
4227 }
4228
4229 (void) ieee802_11_parse_elems(mgmt->u.beacon.variable,
4230 len - (IEEE80211_HDRLEN +
4231 sizeof(mgmt->u.beacon)), &elems,
4232 0);
4233
4234 ap_list_process_beacon(hapd->iface, mgmt, &elems, fi);
4235 }
4236
4237
4238 #ifdef CONFIG_IEEE80211W
4239 static int robust_action_frame(u8 category)
4240 {
4241 return category != WLAN_ACTION_PUBLIC &&
4242 category != WLAN_ACTION_HT;
4243 }
4244 #endif /* CONFIG_IEEE80211W */
4245
4246
4247 static int handle_action(struct hostapd_data *hapd,
4248 const struct ieee80211_mgmt *mgmt, size_t len,
4249 unsigned int freq)
4250 {
4251 struct sta_info *sta;
4252 u8 *action __maybe_unused;
4253
4254 if (len < IEEE80211_HDRLEN + 2 + 1) {
4255 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
4256 HOSTAPD_LEVEL_DEBUG,
4257 "handle_action - too short payload (len=%lu)",
4258 (unsigned long) len);
4259 return 0;
4260 }
4261
4262 action = (u8 *) &mgmt->u.action.u;
4263 wpa_printf(MSG_DEBUG, "RX_ACTION category %u action %u sa " MACSTR
4264 " da " MACSTR " len %d freq %u",
4265 mgmt->u.action.category, *action,
4266 MAC2STR(mgmt->sa), MAC2STR(mgmt->da), (int) len, freq);
4267
4268 sta = ap_get_sta(hapd, mgmt->sa);
4269
4270 if (mgmt->u.action.category != WLAN_ACTION_PUBLIC &&
4271 (sta == NULL || !(sta->flags & WLAN_STA_ASSOC))) {
4272 wpa_printf(MSG_DEBUG, "IEEE 802.11: Ignored Action "
4273 "frame (category=%u) from unassociated STA " MACSTR,
4274 mgmt->u.action.category, MAC2STR(mgmt->sa));
4275 return 0;
4276 }
4277
4278 #ifdef CONFIG_IEEE80211W
4279 if (sta && (sta->flags & WLAN_STA_MFP) &&
4280 !(mgmt->frame_control & host_to_le16(WLAN_FC_ISWEP)) &&
4281 robust_action_frame(mgmt->u.action.category)) {
4282 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
4283 HOSTAPD_LEVEL_DEBUG,
4284 "Dropped unprotected Robust Action frame from "
4285 "an MFP STA");
4286 return 0;
4287 }
4288 #endif /* CONFIG_IEEE80211W */
4289
4290 if (sta) {
4291 u16 fc = le_to_host16(mgmt->frame_control);
4292 u16 seq_ctrl = le_to_host16(mgmt->seq_ctrl);
4293
4294 if ((fc & WLAN_FC_RETRY) &&
4295 sta->last_seq_ctrl != WLAN_INVALID_MGMT_SEQ &&
4296 sta->last_seq_ctrl == seq_ctrl &&
4297 sta->last_subtype == WLAN_FC_STYPE_ACTION) {
4298 hostapd_logger(hapd, sta->addr,
4299 HOSTAPD_MODULE_IEEE80211,
4300 HOSTAPD_LEVEL_DEBUG,
4301 "Drop repeated action frame seq_ctrl=0x%x",
4302 seq_ctrl);
4303 return 1;
4304 }
4305
4306 sta->last_seq_ctrl = seq_ctrl;
4307 sta->last_subtype = WLAN_FC_STYPE_ACTION;
4308 }
4309
4310 switch (mgmt->u.action.category) {
4311 #ifdef CONFIG_IEEE80211R_AP
4312 case WLAN_ACTION_FT:
4313 if (!sta ||
4314 wpa_ft_action_rx(sta->wpa_sm, (u8 *) &mgmt->u.action,
4315 len - IEEE80211_HDRLEN))
4316 break;
4317 return 1;
4318 #endif /* CONFIG_IEEE80211R_AP */
4319 case WLAN_ACTION_WMM:
4320 hostapd_wmm_action(hapd, mgmt, len);
4321 return 1;
4322 #ifdef CONFIG_IEEE80211W
4323 case WLAN_ACTION_SA_QUERY:
4324 ieee802_11_sa_query_action(hapd, mgmt, len);
4325 return 1;
4326 #endif /* CONFIG_IEEE80211W */
4327 #ifdef CONFIG_WNM_AP
4328 case WLAN_ACTION_WNM:
4329 ieee802_11_rx_wnm_action_ap(hapd, mgmt, len);
4330 return 1;
4331 #endif /* CONFIG_WNM_AP */
4332 #ifdef CONFIG_FST
4333 case WLAN_ACTION_FST:
4334 if (hapd->iface->fst)
4335 fst_rx_action(hapd->iface->fst, mgmt, len);
4336 else
4337 wpa_printf(MSG_DEBUG,
4338 "FST: Ignore FST Action frame - no FST attached");
4339 return 1;
4340 #endif /* CONFIG_FST */
4341 case WLAN_ACTION_PUBLIC:
4342 case WLAN_ACTION_PROTECTED_DUAL:
4343 #ifdef CONFIG_IEEE80211N
4344 if (len >= IEEE80211_HDRLEN + 2 &&
4345 mgmt->u.action.u.public_action.action ==
4346 WLAN_PA_20_40_BSS_COEX) {
4347 hostapd_2040_coex_action(hapd, mgmt, len);
4348 return 1;
4349 }
4350 #endif /* CONFIG_IEEE80211N */
4351 #ifdef CONFIG_DPP
4352 if (len >= IEEE80211_HDRLEN + 6 &&
4353 mgmt->u.action.u.vs_public_action.action ==
4354 WLAN_PA_VENDOR_SPECIFIC &&
4355 WPA_GET_BE24(mgmt->u.action.u.vs_public_action.oui) ==
4356 OUI_WFA &&
4357 mgmt->u.action.u.vs_public_action.variable[0] ==
4358 DPP_OUI_TYPE) {
4359 const u8 *pos, *end;
4360
4361 pos = mgmt->u.action.u.vs_public_action.oui;
4362 end = ((const u8 *) mgmt) + len;
4363 hostapd_dpp_rx_action(hapd, mgmt->sa, pos, end - pos,
4364 freq);
4365 return 1;
4366 }
4367 if (len >= IEEE80211_HDRLEN + 2 &&
4368 (mgmt->u.action.u.public_action.action ==
4369 WLAN_PA_GAS_INITIAL_RESP ||
4370 mgmt->u.action.u.public_action.action ==
4371 WLAN_PA_GAS_COMEBACK_RESP)) {
4372 const u8 *pos, *end;
4373
4374 pos = &mgmt->u.action.u.public_action.action;
4375 end = ((const u8 *) mgmt) + len;
4376 gas_query_ap_rx(hapd->gas, mgmt->sa,
4377 mgmt->u.action.category,
4378 pos, end - pos, hapd->iface->freq);
4379 return 1;
4380 }
4381 #endif /* CONFIG_DPP */
4382 if (hapd->public_action_cb) {
4383 hapd->public_action_cb(hapd->public_action_cb_ctx,
4384 (u8 *) mgmt, len,
4385 hapd->iface->freq);
4386 }
4387 if (hapd->public_action_cb2) {
4388 hapd->public_action_cb2(hapd->public_action_cb2_ctx,
4389 (u8 *) mgmt, len,
4390 hapd->iface->freq);
4391 }
4392 if (hapd->public_action_cb || hapd->public_action_cb2)
4393 return 1;
4394 break;
4395 case WLAN_ACTION_VENDOR_SPECIFIC:
4396 if (hapd->vendor_action_cb) {
4397 if (hapd->vendor_action_cb(hapd->vendor_action_cb_ctx,
4398 (u8 *) mgmt, len,
4399 hapd->iface->freq) == 0)
4400 return 1;
4401 }
4402 break;
4403 case WLAN_ACTION_RADIO_MEASUREMENT:
4404 hostapd_handle_radio_measurement(hapd, (const u8 *) mgmt, len);
4405 return 1;
4406 }
4407
4408 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
4409 HOSTAPD_LEVEL_DEBUG,
4410 "handle_action - unknown action category %d or invalid "
4411 "frame",
4412 mgmt->u.action.category);
4413 if (!is_multicast_ether_addr(mgmt->da) &&
4414 !(mgmt->u.action.category & 0x80) &&
4415 !is_multicast_ether_addr(mgmt->sa)) {
4416 struct ieee80211_mgmt *resp;
4417
4418 /*
4419 * IEEE 802.11-REVma/D9.0 - 7.3.1.11
4420 * Return the Action frame to the source without change
4421 * except that MSB of the Category set to 1.
4422 */
4423 wpa_printf(MSG_DEBUG, "IEEE 802.11: Return unknown Action "
4424 "frame back to sender");
4425 resp = os_memdup(mgmt, len);
4426 if (resp == NULL)
4427 return 0;
4428 os_memcpy(resp->da, resp->sa, ETH_ALEN);
4429 os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN);
4430 os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN);
4431 resp->u.action.category |= 0x80;
4432
4433 if (hostapd_drv_send_mlme(hapd, resp, len, 0) < 0) {
4434 wpa_printf(MSG_ERROR, "IEEE 802.11: Failed to send "
4435 "Action frame");
4436 }
4437 os_free(resp);
4438 }
4439
4440 return 1;
4441 }
4442
4443
4444 /**
4445 * ieee802_11_mgmt - process incoming IEEE 802.11 management frames
4446 * @hapd: hostapd BSS data structure (the BSS to which the management frame was
4447 * sent to)
4448 * @buf: management frame data (starting from IEEE 802.11 header)
4449 * @len: length of frame data in octets
4450 * @fi: meta data about received frame (signal level, etc.)
4451 *
4452 * Process all incoming IEEE 802.11 management frames. This will be called for
4453 * each frame received from the kernel driver through wlan#ap interface. In
4454 * addition, it can be called to re-inserted pending frames (e.g., when using
4455 * external RADIUS server as an MAC ACL).
4456 */
4457 int ieee802_11_mgmt(struct hostapd_data *hapd, const u8 *buf, size_t len,
4458 struct hostapd_frame_info *fi)
4459 {
4460 struct ieee80211_mgmt *mgmt;
4461 u16 fc, stype;
4462 int ret = 0;
4463 unsigned int freq;
4464 int ssi_signal = fi ? fi->ssi_signal : 0;
4465
4466 if (len < 24)
4467 return 0;
4468
4469 if (fi && fi->freq)
4470 freq = fi->freq;
4471 else
4472 freq = hapd->iface->freq;
4473
4474 mgmt = (struct ieee80211_mgmt *) buf;
4475 fc = le_to_host16(mgmt->frame_control);
4476 stype = WLAN_FC_GET_STYPE(fc);
4477
4478 if (stype == WLAN_FC_STYPE_BEACON) {
4479 handle_beacon(hapd, mgmt, len, fi);
4480 return 1;
4481 }
4482
4483 if (!is_broadcast_ether_addr(mgmt->bssid) &&
4484 #ifdef CONFIG_P2P
4485 /* Invitation responses can be sent with the peer MAC as BSSID */
4486 !((hapd->conf->p2p & P2P_GROUP_OWNER) &&
4487 stype == WLAN_FC_STYPE_ACTION) &&
4488 #endif /* CONFIG_P2P */
4489 #ifdef CONFIG_MESH
4490 !(hapd->conf->mesh & MESH_ENABLED) &&
4491 #endif /* CONFIG_MESH */
4492 os_memcmp(mgmt->bssid, hapd->own_addr, ETH_ALEN) != 0) {
4493 wpa_printf(MSG_INFO, "MGMT: BSSID=" MACSTR " not our address",
4494 MAC2STR(mgmt->bssid));
4495 return 0;
4496 }
4497
4498
4499 if (stype == WLAN_FC_STYPE_PROBE_REQ) {
4500 handle_probe_req(hapd, mgmt, len, ssi_signal);
4501 return 1;
4502 }
4503
4504 if ((!is_broadcast_ether_addr(mgmt->da) ||
4505 stype != WLAN_FC_STYPE_ACTION) &&
4506 os_memcmp(mgmt->da, hapd->own_addr, ETH_ALEN) != 0) {
4507 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
4508 HOSTAPD_LEVEL_DEBUG,
4509 "MGMT: DA=" MACSTR " not our address",
4510 MAC2STR(mgmt->da));
4511 return 0;
4512 }
4513
4514 if (hapd->iconf->track_sta_max_num)
4515 sta_track_add(hapd->iface, mgmt->sa, ssi_signal);
4516
4517 switch (stype) {
4518 case WLAN_FC_STYPE_AUTH:
4519 wpa_printf(MSG_DEBUG, "mgmt::auth");
4520 handle_auth(hapd, mgmt, len, ssi_signal, 0);
4521 ret = 1;
4522 break;
4523 case WLAN_FC_STYPE_ASSOC_REQ:
4524 wpa_printf(MSG_DEBUG, "mgmt::assoc_req");
4525 handle_assoc(hapd, mgmt, len, 0, ssi_signal);
4526 ret = 1;
4527 break;
4528 case WLAN_FC_STYPE_REASSOC_REQ:
4529 wpa_printf(MSG_DEBUG, "mgmt::reassoc_req");
4530 handle_assoc(hapd, mgmt, len, 1, ssi_signal);
4531 ret = 1;
4532 break;
4533 case WLAN_FC_STYPE_DISASSOC:
4534 wpa_printf(MSG_DEBUG, "mgmt::disassoc");
4535 handle_disassoc(hapd, mgmt, len);
4536 ret = 1;
4537 break;
4538 case WLAN_FC_STYPE_DEAUTH:
4539 wpa_msg(hapd->msg_ctx, MSG_DEBUG, "mgmt::deauth");
4540 handle_deauth(hapd, mgmt, len);
4541 ret = 1;
4542 break;
4543 case WLAN_FC_STYPE_ACTION:
4544 wpa_printf(MSG_DEBUG, "mgmt::action");
4545 ret = handle_action(hapd, mgmt, len, freq);
4546 break;
4547 default:
4548 hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
4549 HOSTAPD_LEVEL_DEBUG,
4550 "unknown mgmt frame subtype %d", stype);
4551 break;
4552 }
4553
4554 return ret;
4555 }
4556
4557
4558 static void handle_auth_cb(struct hostapd_data *hapd,
4559 const struct ieee80211_mgmt *mgmt,
4560 size_t len, int ok)
4561 {
4562 u16 auth_alg, auth_transaction, status_code;
4563 struct sta_info *sta;
4564
4565 sta = ap_get_sta(hapd, mgmt->da);
4566 if (!sta) {
4567 wpa_printf(MSG_DEBUG, "handle_auth_cb: STA " MACSTR
4568 " not found",
4569 MAC2STR(mgmt->da));
4570 return;
4571 }
4572
4573 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
4574 auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
4575 status_code = le_to_host16(mgmt->u.auth.status_code);
4576
4577 if (!ok) {
4578 hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
4579 HOSTAPD_LEVEL_NOTICE,
4580 "did not acknowledge authentication response");
4581 goto fail;
4582 }
4583
4584 if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
4585 wpa_printf(MSG_INFO, "handle_auth_cb - too short payload (len=%lu)",
4586 (unsigned long) len);
4587 goto fail;
4588 }
4589
4590 if (status_code == WLAN_STATUS_SUCCESS &&
4591 ((auth_alg == WLAN_AUTH_OPEN && auth_transaction == 2) ||
4592 (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 4))) {
4593 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
4594 HOSTAPD_LEVEL_INFO, "authenticated");
4595 sta->flags |= WLAN_STA_AUTH;
4596 if (sta->added_unassoc)
4597 hostapd_set_sta_flags(hapd, sta);
4598 return;
4599 }
4600
4601 fail:
4602 if (status_code != WLAN_STATUS_SUCCESS && sta->added_unassoc) {
4603 hostapd_drv_sta_remove(hapd, sta->addr);
4604 sta->added_unassoc = 0;
4605 }
4606 }
4607
4608
4609 static void hostapd_set_wds_encryption(struct hostapd_data *hapd,
4610 struct sta_info *sta,
4611 char *ifname_wds)
4612 {
4613 int i;
4614 struct hostapd_ssid *ssid = &hapd->conf->ssid;
4615
4616 if (hapd->conf->ieee802_1x || hapd->conf->wpa)
4617 return;
4618
4619 for (i = 0; i < 4; i++) {
4620 if (ssid->wep.key[i] &&
4621 hostapd_drv_set_key(ifname_wds, hapd, WPA_ALG_WEP, NULL, i,
4622 i == ssid->wep.idx, NULL, 0,
4623 ssid->wep.key[i], ssid->wep.len[i])) {
4624 wpa_printf(MSG_WARNING,
4625 "Could not set WEP keys for WDS interface; %s",
4626 ifname_wds);
4627 break;
4628 }
4629 }
4630 }
4631
4632
4633 static void handle_assoc_cb(struct hostapd_data *hapd,
4634 const struct ieee80211_mgmt *mgmt,
4635 size_t len, int reassoc, int ok)
4636 {
4637 u16 status;
4638 struct sta_info *sta;
4639 int new_assoc = 1;
4640
4641 sta = ap_get_sta(hapd, mgmt->da);
4642 if (!sta) {
4643 wpa_printf(MSG_INFO, "handle_assoc_cb: STA " MACSTR " not found",
4644 MAC2STR(mgmt->da));
4645 return;
4646 }
4647
4648 if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_resp) :
4649 sizeof(mgmt->u.assoc_resp))) {
4650 wpa_printf(MSG_INFO,
4651 "handle_assoc_cb(reassoc=%d) - too short payload (len=%lu)",
4652 reassoc, (unsigned long) len);
4653 hostapd_drv_sta_remove(hapd, sta->addr);
4654 return;
4655 }
4656
4657 if (reassoc)
4658 status = le_to_host16(mgmt->u.reassoc_resp.status_code);
4659 else
4660 status = le_to_host16(mgmt->u.assoc_resp.status_code);
4661
4662 if (!ok) {
4663 hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
4664 HOSTAPD_LEVEL_DEBUG,
4665 "did not acknowledge association response");
4666 sta->flags &= ~WLAN_STA_ASSOC_REQ_OK;
4667 /* The STA is added only in case of SUCCESS */
4668 if (status == WLAN_STATUS_SUCCESS)
4669 hostapd_drv_sta_remove(hapd, sta->addr);
4670
4671 return;
4672 }
4673
4674 if (status != WLAN_STATUS_SUCCESS)
4675 return;
4676
4677 /* Stop previous accounting session, if one is started, and allocate
4678 * new session id for the new session. */
4679 accounting_sta_stop(hapd, sta);
4680
4681 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
4682 HOSTAPD_LEVEL_INFO,
4683 "associated (aid %d)",
4684 sta->aid);
4685
4686 if (sta->flags & WLAN_STA_ASSOC)
4687 new_assoc = 0;
4688 sta->flags |= WLAN_STA_ASSOC;
4689 sta->flags &= ~WLAN_STA_WNM_SLEEP_MODE;
4690 if ((!hapd->conf->ieee802_1x && !hapd->conf->wpa &&
4691 !hapd->conf->osen) ||
4692 sta->auth_alg == WLAN_AUTH_FILS_SK ||
4693 sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
4694 sta->auth_alg == WLAN_AUTH_FILS_PK ||
4695 sta->auth_alg == WLAN_AUTH_FT) {
4696 /*
4697 * Open, static WEP, FT protocol, or FILS; no separate
4698 * authorization step.
4699 */
4700 ap_sta_set_authorized(hapd, sta, 1);
4701 }
4702
4703 if (reassoc)
4704 mlme_reassociate_indication(hapd, sta);
4705 else
4706 mlme_associate_indication(hapd, sta);
4707
4708 #ifdef CONFIG_IEEE80211W
4709 sta->sa_query_timed_out = 0;
4710 #endif /* CONFIG_IEEE80211W */
4711
4712 if (sta->eapol_sm == NULL) {
4713 /*
4714 * This STA does not use RADIUS server for EAP authentication,
4715 * so bind it to the selected VLAN interface now, since the
4716 * interface selection is not going to change anymore.
4717 */
4718 if (ap_sta_bind_vlan(hapd, sta) < 0)
4719 return;
4720 } else if (sta->vlan_id) {
4721 /* VLAN ID already set (e.g., by PMKSA caching), so bind STA */
4722 if (ap_sta_bind_vlan(hapd, sta) < 0)
4723 return;
4724 }
4725
4726 hostapd_set_sta_flags(hapd, sta);
4727
4728 if (!(sta->flags & WLAN_STA_WDS) && sta->pending_wds_enable) {
4729 wpa_printf(MSG_DEBUG, "Enable 4-address WDS mode for STA "
4730 MACSTR " based on pending request",
4731 MAC2STR(sta->addr));
4732 sta->pending_wds_enable = 0;
4733 sta->flags |= WLAN_STA_WDS;
4734 }
4735
4736 if (sta->flags & (WLAN_STA_WDS | WLAN_STA_MULTI_AP)) {
4737 int ret;
4738 char ifname_wds[IFNAMSIZ + 1];
4739
4740 wpa_printf(MSG_DEBUG, "Reenable 4-address WDS mode for STA "
4741 MACSTR " (aid %u)",
4742 MAC2STR(sta->addr), sta->aid);
4743 ret = hostapd_set_wds_sta(hapd, ifname_wds, sta->addr,
4744 sta->aid, 1);
4745 if (!ret)
4746 hostapd_set_wds_encryption(hapd, sta, ifname_wds);
4747 }
4748
4749 if (sta->auth_alg == WLAN_AUTH_FT)
4750 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FT);
4751 else
4752 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC);
4753 hapd->new_assoc_sta_cb(hapd, sta, !new_assoc);
4754 ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
4755
4756 #ifdef CONFIG_FILS
4757 if ((sta->auth_alg == WLAN_AUTH_FILS_SK ||
4758 sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
4759 sta->auth_alg == WLAN_AUTH_FILS_PK) &&
4760 fils_set_tk(sta->wpa_sm) < 0) {
4761 wpa_printf(MSG_DEBUG, "FILS: TK configuration failed");
4762 ap_sta_disconnect(hapd, sta, sta->addr,
4763 WLAN_REASON_UNSPECIFIED);
4764 return;
4765 }
4766 #endif /* CONFIG_FILS */
4767
4768 if (sta->pending_eapol_rx) {
4769 struct os_reltime now, age;
4770
4771 os_get_reltime(&now);
4772 os_reltime_sub(&now, &sta->pending_eapol_rx->rx_time, &age);
4773 if (age.sec == 0 && age.usec < 200000) {
4774 wpa_printf(MSG_DEBUG,
4775 "Process pending EAPOL frame that was received from " MACSTR " just before association notification",
4776 MAC2STR(sta->addr));
4777 ieee802_1x_receive(
4778 hapd, mgmt->da,
4779 wpabuf_head(sta->pending_eapol_rx->buf),
4780 wpabuf_len(sta->pending_eapol_rx->buf));
4781 }
4782 wpabuf_free(sta->pending_eapol_rx->buf);
4783 os_free(sta->pending_eapol_rx);
4784 sta->pending_eapol_rx = NULL;
4785 }
4786 }
4787
4788
4789 static void handle_deauth_cb(struct hostapd_data *hapd,
4790 const struct ieee80211_mgmt *mgmt,
4791 size_t len, int ok)
4792 {
4793 struct sta_info *sta;
4794 if (is_multicast_ether_addr(mgmt->da))
4795 return;
4796 sta = ap_get_sta(hapd, mgmt->da);
4797 if (!sta) {
4798 wpa_printf(MSG_DEBUG, "handle_deauth_cb: STA " MACSTR
4799 " not found", MAC2STR(mgmt->da));
4800 return;
4801 }
4802 if (ok)
4803 wpa_printf(MSG_DEBUG, "STA " MACSTR " acknowledged deauth",
4804 MAC2STR(sta->addr));
4805 else
4806 wpa_printf(MSG_DEBUG, "STA " MACSTR " did not acknowledge "
4807 "deauth", MAC2STR(sta->addr));
4808
4809 ap_sta_deauth_cb(hapd, sta);
4810 }
4811
4812
4813 static void handle_disassoc_cb(struct hostapd_data *hapd,
4814 const struct ieee80211_mgmt *mgmt,
4815 size_t len, int ok)
4816 {
4817 struct sta_info *sta;
4818 if (is_multicast_ether_addr(mgmt->da))
4819 return;
4820 sta = ap_get_sta(hapd, mgmt->da);
4821 if (!sta) {
4822 wpa_printf(MSG_DEBUG, "handle_disassoc_cb: STA " MACSTR
4823 " not found", MAC2STR(mgmt->da));
4824 return;
4825 }
4826 if (ok)
4827 wpa_printf(MSG_DEBUG, "STA " MACSTR " acknowledged disassoc",
4828 MAC2STR(sta->addr));
4829 else
4830 wpa_printf(MSG_DEBUG, "STA " MACSTR " did not acknowledge "
4831 "disassoc", MAC2STR(sta->addr));
4832
4833 ap_sta_disassoc_cb(hapd, sta);
4834 }
4835
4836
4837 static void handle_action_cb(struct hostapd_data *hapd,
4838 const struct ieee80211_mgmt *mgmt,
4839 size_t len, int ok)
4840 {
4841 struct sta_info *sta;
4842 const struct rrm_measurement_report_element *report;
4843
4844 if (is_multicast_ether_addr(mgmt->da))
4845 return;
4846 #ifdef CONFIG_DPP
4847 if (len >= IEEE80211_HDRLEN + 6 &&
4848 mgmt->u.action.category == WLAN_ACTION_PUBLIC &&
4849 mgmt->u.action.u.vs_public_action.action ==
4850 WLAN_PA_VENDOR_SPECIFIC &&
4851 WPA_GET_BE24(mgmt->u.action.u.vs_public_action.oui) ==
4852 OUI_WFA &&
4853 mgmt->u.action.u.vs_public_action.variable[0] ==
4854 DPP_OUI_TYPE) {
4855 const u8 *pos, *end;
4856
4857 pos = &mgmt->u.action.u.vs_public_action.variable[1];
4858 end = ((const u8 *) mgmt) + len;
4859 hostapd_dpp_tx_status(hapd, mgmt->da, pos, end - pos, ok);
4860 return;
4861 }
4862 if (len >= IEEE80211_HDRLEN + 2 &&
4863 mgmt->u.action.category == WLAN_ACTION_PUBLIC &&
4864 (mgmt->u.action.u.public_action.action ==
4865 WLAN_PA_GAS_INITIAL_REQ ||
4866 mgmt->u.action.u.public_action.action ==
4867 WLAN_PA_GAS_COMEBACK_REQ)) {
4868 const u8 *pos, *end;
4869
4870 pos = mgmt->u.action.u.public_action.variable;
4871 end = ((const u8 *) mgmt) + len;
4872 gas_query_ap_tx_status(hapd->gas, mgmt->da, pos, end - pos, ok);
4873 return;
4874 }
4875 #endif /* CONFIG_DPP */
4876 sta = ap_get_sta(hapd, mgmt->da);
4877 if (!sta) {
4878 wpa_printf(MSG_DEBUG, "handle_action_cb: STA " MACSTR
4879 " not found", MAC2STR(mgmt->da));
4880 return;
4881 }
4882
4883 if (len < 24 + 5 + sizeof(*report))
4884 return;
4885 report = (const struct rrm_measurement_report_element *)
4886 &mgmt->u.action.u.rrm.variable[2];
4887 if (mgmt->u.action.category == WLAN_ACTION_RADIO_MEASUREMENT &&
4888 mgmt->u.action.u.rrm.action == WLAN_RRM_RADIO_MEASUREMENT_REQUEST &&
4889 report->eid == WLAN_EID_MEASURE_REQUEST &&
4890 report->len >= 3 &&
4891 report->type == MEASURE_TYPE_BEACON)
4892 hostapd_rrm_beacon_req_tx_status(hapd, mgmt, len, ok);
4893 }
4894
4895
4896 /**
4897 * ieee802_11_mgmt_cb - Process management frame TX status callback
4898 * @hapd: hostapd BSS data structure (the BSS from which the management frame
4899 * was sent from)
4900 * @buf: management frame data (starting from IEEE 802.11 header)
4901 * @len: length of frame data in octets
4902 * @stype: management frame subtype from frame control field
4903 * @ok: Whether the frame was ACK'ed
4904 */
4905 void ieee802_11_mgmt_cb(struct hostapd_data *hapd, const u8 *buf, size_t len,
4906 u16 stype, int ok)
4907 {
4908 const struct ieee80211_mgmt *mgmt;
4909 mgmt = (const struct ieee80211_mgmt *) buf;
4910
4911 #ifdef CONFIG_TESTING_OPTIONS
4912 if (hapd->ext_mgmt_frame_handling) {
4913 size_t hex_len = 2 * len + 1;
4914 char *hex = os_malloc(hex_len);
4915
4916 if (hex) {
4917 wpa_snprintf_hex(hex, hex_len, buf, len);
4918 wpa_msg(hapd->msg_ctx, MSG_INFO,
4919 "MGMT-TX-STATUS stype=%u ok=%d buf=%s",
4920 stype, ok, hex);
4921 os_free(hex);
4922 }
4923 return;
4924 }
4925 #endif /* CONFIG_TESTING_OPTIONS */
4926
4927 switch (stype) {
4928 case WLAN_FC_STYPE_AUTH:
4929 wpa_printf(MSG_DEBUG, "mgmt::auth cb");
4930 handle_auth_cb(hapd, mgmt, len, ok);
4931 break;
4932 case WLAN_FC_STYPE_ASSOC_RESP:
4933 wpa_printf(MSG_DEBUG, "mgmt::assoc_resp cb");
4934 handle_assoc_cb(hapd, mgmt, len, 0, ok);
4935 break;
4936 case WLAN_FC_STYPE_REASSOC_RESP:
4937 wpa_printf(MSG_DEBUG, "mgmt::reassoc_resp cb");
4938 handle_assoc_cb(hapd, mgmt, len, 1, ok);
4939 break;
4940 case WLAN_FC_STYPE_PROBE_RESP:
4941 wpa_printf(MSG_EXCESSIVE, "mgmt::proberesp cb ok=%d", ok);
4942 break;
4943 case WLAN_FC_STYPE_DEAUTH:
4944 wpa_printf(MSG_DEBUG, "mgmt::deauth cb");
4945 handle_deauth_cb(hapd, mgmt, len, ok);
4946 break;
4947 case WLAN_FC_STYPE_DISASSOC:
4948 wpa_printf(MSG_DEBUG, "mgmt::disassoc cb");
4949 handle_disassoc_cb(hapd, mgmt, len, ok);
4950 break;
4951 case WLAN_FC_STYPE_ACTION:
4952 wpa_printf(MSG_DEBUG, "mgmt::action cb ok=%d", ok);
4953 handle_action_cb(hapd, mgmt, len, ok);
4954 break;
4955 default:
4956 wpa_printf(MSG_INFO, "unknown mgmt cb frame subtype %d", stype);
4957 break;
4958 }
4959 }
4960
4961
4962 int ieee802_11_get_mib(struct hostapd_data *hapd, char *buf, size_t buflen)
4963 {
4964 /* TODO */
4965 return 0;
4966 }
4967
4968
4969 int ieee802_11_get_mib_sta(struct hostapd_data *hapd, struct sta_info *sta,
4970 char *buf, size_t buflen)
4971 {
4972 /* TODO */
4973 return 0;
4974 }
4975
4976
4977 void hostapd_tx_status(struct hostapd_data *hapd, const u8 *addr,
4978 const u8 *buf, size_t len, int ack)
4979 {
4980 struct sta_info *sta;
4981 struct hostapd_iface *iface = hapd->iface;
4982
4983 sta = ap_get_sta(hapd, addr);
4984 if (sta == NULL && iface->num_bss > 1) {
4985 size_t j;
4986 for (j = 0; j < iface->num_bss; j++) {
4987 hapd = iface->bss[j];
4988 sta = ap_get_sta(hapd, addr);
4989 if (sta)
4990 break;
4991 }
4992 }
4993 if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC))
4994 return;
4995 if (sta->flags & WLAN_STA_PENDING_POLL) {
4996 wpa_printf(MSG_DEBUG, "STA " MACSTR " %s pending "
4997 "activity poll", MAC2STR(sta->addr),
4998 ack ? "ACKed" : "did not ACK");
4999 if (ack)
5000 sta->flags &= ~WLAN_STA_PENDING_POLL;
5001 }
5002
5003 ieee802_1x_tx_status(hapd, sta, buf, len, ack);
5004 }
5005
5006
5007 void hostapd_eapol_tx_status(struct hostapd_data *hapd, const u8 *dst,
5008 const u8 *data, size_t len, int ack)
5009 {
5010 struct sta_info *sta;
5011 struct hostapd_iface *iface = hapd->iface;
5012
5013 sta = ap_get_sta(hapd, dst);
5014 if (sta == NULL && iface->num_bss > 1) {
5015 size_t j;
5016 for (j = 0; j < iface->num_bss; j++) {
5017 hapd = iface->bss[j];
5018 sta = ap_get_sta(hapd, dst);
5019 if (sta)
5020 break;
5021 }
5022 }
5023 if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC)) {
5024 wpa_printf(MSG_DEBUG, "Ignore TX status for Data frame to STA "
5025 MACSTR " that is not currently associated",
5026 MAC2STR(dst));
5027 return;
5028 }
5029
5030 ieee802_1x_eapol_tx_status(hapd, sta, data, len, ack);
5031 }
5032
5033
5034 void hostapd_client_poll_ok(struct hostapd_data *hapd, const u8 *addr)
5035 {
5036 struct sta_info *sta;
5037 struct hostapd_iface *iface = hapd->iface;
5038
5039 sta = ap_get_sta(hapd, addr);
5040 if (sta == NULL && iface->num_bss > 1) {
5041 size_t j;
5042 for (j = 0; j < iface->num_bss; j++) {
5043 hapd = iface->bss[j];
5044 sta = ap_get_sta(hapd, addr);
5045 if (sta)
5046 break;
5047 }
5048 }
5049 if (sta == NULL)
5050 return;
5051 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_POLL_OK MACSTR,
5052 MAC2STR(sta->addr));
5053 if (!(sta->flags & WLAN_STA_PENDING_POLL))
5054 return;
5055
5056 wpa_printf(MSG_DEBUG, "STA " MACSTR " ACKed pending "
5057 "activity poll", MAC2STR(sta->addr));
5058 sta->flags &= ~WLAN_STA_PENDING_POLL;
5059 }
5060
5061
5062 void ieee802_11_rx_from_unknown(struct hostapd_data *hapd, const u8 *src,
5063 int wds)
5064 {
5065 struct sta_info *sta;
5066
5067 sta = ap_get_sta(hapd, src);
5068 if (sta &&
5069 ((sta->flags & WLAN_STA_ASSOC) ||
5070 ((sta->flags & WLAN_STA_ASSOC_REQ_OK) && wds))) {
5071 if (!hapd->conf->wds_sta)
5072 return;
5073
5074 if ((sta->flags & (WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK)) ==
5075 WLAN_STA_ASSOC_REQ_OK) {
5076 wpa_printf(MSG_DEBUG,
5077 "Postpone 4-address WDS mode enabling for STA "
5078 MACSTR " since TX status for AssocResp is not yet known",
5079 MAC2STR(sta->addr));
5080 sta->pending_wds_enable = 1;
5081 return;
5082 }
5083
5084 if (wds && !(sta->flags & WLAN_STA_WDS)) {
5085 int ret;
5086 char ifname_wds[IFNAMSIZ + 1];
5087
5088 wpa_printf(MSG_DEBUG, "Enable 4-address WDS mode for "
5089 "STA " MACSTR " (aid %u)",
5090 MAC2STR(sta->addr), sta->aid);
5091 sta->flags |= WLAN_STA_WDS;
5092 ret = hostapd_set_wds_sta(hapd, ifname_wds,
5093 sta->addr, sta->aid, 1);
5094 if (!ret)
5095 hostapd_set_wds_encryption(hapd, sta,
5096 ifname_wds);
5097 }
5098 return;
5099 }
5100
5101 wpa_printf(MSG_DEBUG, "Data/PS-poll frame from not associated STA "
5102 MACSTR, MAC2STR(src));
5103 if (is_multicast_ether_addr(src)) {
5104 /* Broadcast bit set in SA?! Ignore the frame silently. */
5105 return;
5106 }
5107
5108 if (sta && (sta->flags & WLAN_STA_ASSOC_REQ_OK)) {
5109 wpa_printf(MSG_DEBUG, "Association Response to the STA has "
5110 "already been sent, but no TX status yet known - "
5111 "ignore Class 3 frame issue with " MACSTR,
5112 MAC2STR(src));
5113 return;
5114 }
5115
5116 if (sta && (sta->flags & WLAN_STA_AUTH))
5117 hostapd_drv_sta_disassoc(
5118 hapd, src,
5119 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
5120 else
5121 hostapd_drv_sta_deauth(
5122 hapd, src,
5123 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
5124 }
5125
5126
5127 #endif /* CONFIG_NATIVE_WINDOWS */