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